Don't use wxSharedPtr<> in factory registration code

Shared ownership semantics again seems inappropriate here as we're not
actually sharing the pointers here, so just use raw pointers instead
(with C++11 we could use std::unique_ptr<>, but this is impossible with
our own map and scoped pointer implementations).

No real changes.
This commit is contained in:
Vadim Zeitlin
2021-01-04 02:06:10 +01:00
parent 989cafe535
commit 6e546a3d4b
2 changed files with 17 additions and 10 deletions

View File

@@ -16,7 +16,6 @@
#include "wx/event.h" #include "wx/event.h"
#include "wx/object.h" #include "wx/object.h"
#include "wx/sharedptr.h"
#include "wx/stream.h" #include "wx/stream.h"
#include "wx/versioninfo.h" #include "wx/versioninfo.h"
@@ -216,7 +215,7 @@ public:
private: private:
static void RegisterFactory(const wxString& backend, static void RegisterFactory(const wxString& backend,
const wxSharedPtr<wxWebSessionFactory>& factory); wxWebSessionFactory* factory);
static void InitFactoryMap(); static void InitFactoryMap();

View File

@@ -752,7 +752,7 @@ wxString wxWebResponse::GetFileName() const
// wxWebSessionImpl // wxWebSessionImpl
// //
WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxWebSessionFactory>, wxStringWebSessionFactoryMap); WX_DECLARE_STRING_HASH_MAP(wxWebSessionFactory*, wxStringWebSessionFactoryMap);
namespace namespace
{ {
@@ -833,8 +833,12 @@ wxWebSession wxWebSession::New(const wxString& backend)
// static // static
void void
wxWebSession::RegisterFactory(const wxString& backend, wxWebSession::RegisterFactory(const wxString& backend,
const wxSharedPtr<wxWebSessionFactory>& factory) wxWebSessionFactory* factory)
{ {
// Note that we don't have to check here that there is no registered
// backend with the same name yet because we're only called from
// InitFactoryMap() below. If this function becomes public, we'd need to
// free the previous pointer stored for this backend first here.
gs_factoryMap[backend] = factory; gs_factoryMap[backend] = factory;
} }
@@ -842,16 +846,13 @@ wxWebSession::RegisterFactory(const wxString& backend,
void wxWebSession::InitFactoryMap() void wxWebSession::InitFactoryMap()
{ {
#if wxUSE_WEBREQUEST_WINHTTP #if wxUSE_WEBREQUEST_WINHTTP
RegisterFactory(wxWebSessionBackendWinHTTP, RegisterFactory(wxWebSessionBackendWinHTTP, new wxWebSessionFactoryWinHTTP());
wxSharedPtr<wxWebSessionFactory>(new wxWebSessionFactoryWinHTTP()));
#endif #endif
#if wxUSE_WEBREQUEST_URLSESSION #if wxUSE_WEBREQUEST_URLSESSION
RegisterFactory(wxWebSessionBackendURLSession, RegisterFactory(wxWebSessionBackendURLSession, new wxWebSessionFactoryURLSession());
wxSharedPtr<wxWebSessionFactory>(new wxWebSessionFactoryURLSession()));
#endif #endif
#if wxUSE_WEBREQUEST_CURL #if wxUSE_WEBREQUEST_CURL
RegisterFactory(wxWebSessionBackendCURL, RegisterFactory(wxWebSessionBackendCURL, new wxWebSessionFactoryCURL());
wxSharedPtr<wxWebSessionFactory>(new wxWebSessionFactoryCURL()));
#endif #endif
} }
@@ -929,6 +930,13 @@ public:
virtual void OnExit() wxOVERRIDE virtual void OnExit() wxOVERRIDE
{ {
for ( wxStringWebSessionFactoryMap::iterator it = gs_factoryMap.begin();
it != gs_factoryMap.end();
++it )
{
delete it->second;
}
gs_factoryMap.clear(); gs_factoryMap.clear();
gs_defaultSession.Close(); gs_defaultSession.Close();
} }