From ddd4d54b2b4955ee44a50736a38177011c207464 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 12 Apr 2023 00:10:21 +0200 Subject: [PATCH] Stop using wxList in wxZipOutputStream Use a vector of std::unique_ptr<> instead for simplicity and safety. As wxZipEntryList_ was never exposed in the public API, it should be safe to just remove it, as this commit does. --- include/wx/zipstrm.h | 7 ++++--- src/common/zipstrm.cpp | 14 ++++---------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/include/wx/zipstrm.h b/include/wx/zipstrm.h index 584c3ac95c..c5140f9519 100644 --- a/include/wx/zipstrm.h +++ b/include/wx/zipstrm.h @@ -16,6 +16,9 @@ #include "wx/archive.h" #include "wx/filename.h" +#include +#include + // some methods from wxZipInputStream and wxZipOutputStream stream do not get // exported/imported when compiled with Mingw versions before 3.4.2. So they // are imported/exported individually as a workaround @@ -287,8 +290,6 @@ private: ///////////////////////////////////////////////////////////////////////////// // wxZipOutputStream -WX_DECLARE_LIST_WITH_DECL(wxZipEntry, wxZipEntryList_, class WXDLLIMPEXP_BASE); - class WXDLLIMPEXP_BASE wxZipOutputStream : public wxArchiveOutputStream { public: @@ -354,7 +355,7 @@ private: class wxStoredOutputStream *m_store; class wxZlibOutputStream2 *m_deflate; class wxZipStreamLink *m_backlink; - wxZipEntryList_ m_entries; + std::vector> m_entries; char *m_initialData; size_t m_initialSize; wxZipEntry *m_pending; diff --git a/src/common/zipstrm.cpp b/src/common/zipstrm.cpp index 3da939dba4..e56824fbab 100644 --- a/src/common/zipstrm.cpp +++ b/src/common/zipstrm.cpp @@ -2151,9 +2151,6 @@ size_t wxZipInputStream::OnSysRead(void *buffer, size_t size) ///////////////////////////////////////////////////////////////////////////// // Output stream -#include "wx/listimpl.cpp" -WX_DEFINE_LIST(wxZipEntryList_) - wxZipOutputStream::wxZipOutputStream(wxOutputStream& stream, int level /*=-1*/, wxMBConv& conv /*=wxConvUTF8*/) @@ -2192,7 +2189,6 @@ void wxZipOutputStream::Init(int level) wxZipOutputStream::~wxZipOutputStream() { Close(); - WX_CLEAR_LIST(wxZipEntryList_, m_entries); delete m_store; delete m_deflate; delete m_pending; @@ -2419,7 +2415,7 @@ void wxZipOutputStream::CreatePendingEntry(const void *buffer, size_t size) m_lasterror = m_parent_o_stream->GetLastError(); if (IsOk()) { - m_entries.push_back(spPending.release()); + m_entries.push_back(std::move(spPending)); OnSysWrite(m_initialData, m_initialSize); } @@ -2471,7 +2467,7 @@ void wxZipOutputStream::CreatePendingEntry() m_headerSize = spPending->WriteLocal(*m_parent_o_stream, GetConv(), m_format); if (m_parent_o_stream->IsOk()) { - m_entries.push_back(spPending.release()); + m_entries.push_back(std::move(spPending)); m_comp = m_store; m_store->Write(m_initialData, m_initialSize); } @@ -2500,12 +2496,10 @@ bool wxZipOutputStream::Close() endrec.SetOffset(m_headerOffset); endrec.SetComment(m_Comment); - wxZipEntryList_::iterator it; wxFileOffset size = 0; - for (it = m_entries.begin(); it != m_entries.end(); ++it) { - size += (*it)->WriteCentral(*m_parent_o_stream, GetConv()); - delete *it; + for (const auto& it : m_entries) { + size += it->WriteCentral(*m_parent_o_stream, GetConv()); } m_entries.clear();