X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e4db172a3b318df9aff178eb6c5da149d56e0859..0bbe61b8c18a1795189f0cf73cc61c14a0fb846d:/src/gtk/gnome/gvfs.cpp diff --git a/src/gtk/gnome/gvfs.cpp b/src/gtk/gnome/gvfs.cpp index aa25c84098..aa96cc629f 100644 --- a/src/gtk/gnome/gvfs.cpp +++ b/src/gtk/gnome/gvfs.cpp @@ -15,56 +15,49 @@ #pragma hdrstop #endif -#include "wx/gtk/gnome/gvfs.h" - #if wxUSE_MIMETYPE && wxUSE_LIBGNOMEVFS +#include "wx/gtk/gnome/gvfs.h" + #ifndef WX_PRECOMP #include "wx/log.h" + #include "wx/module.h" #endif #include "wx/mimetype.h" -#include "wx/gtk/private.h" -#include "wx/module.h" #include "wx/dynlib.h" #include -#include "wx/html/forcelnk.h" -FORCE_LINK_ME(gnome_vfs) +#include "wx/link.h" +wxFORCE_LINK_THIS_MODULE(gnome_vfs) //---------------------------------------------------------------------------- // wxGnomeVFSLibrary //---------------------------------------------------------------------------- -#define wxDL_METHOD_DEFINE( rettype, name, args, shortargs, defret ) \ - typedef rettype (* name ## Type) args ; \ - name ## Type pfn_ ## name; \ - rettype name args \ - { if (m_ok) return pfn_ ## name shortargs ; return defret; } - -#define wxDL_METHOD_LOAD( lib, name, success ) \ - pfn_ ## name = (name ## Type) lib->GetSymbol( wxT(#name), &success ); \ - if (!success) return; - class wxGnomeVFSLibrary { public: wxGnomeVFSLibrary(); ~wxGnomeVFSLibrary(); - bool IsOk(); - void InitializeMethods(); private: - bool m_ok; - wxDynamicLibrary *m_gnome_vfs_lib; + bool InitializeMethods(); + + wxDynamicLibrary m_libGnomeVFS; + + // only true if we successfully loaded the library above + // + // don't rename this field, it's used by wxDL_XXX macros internally + bool m_ok; public: wxDL_METHOD_DEFINE( gboolean, gnome_vfs_init, (), (), FALSE ) - wxDL_METHOD_DEFINE( void, gnome_vfs_shutdown, - (), (), /**/ ) + wxDL_VOIDMETHOD_DEFINE( gnome_vfs_shutdown, + (), () ) wxDL_METHOD_DEFINE( GnomeVFSResult, gnome_vfs_mime_set_icon, (const char *mime_type, const char *filename), (mime_type, filename), GNOME_VFS_OK ) @@ -72,21 +65,20 @@ public: wxGnomeVFSLibrary::wxGnomeVFSLibrary() { - m_gnome_vfs_lib = NULL; - wxLogNull log; - m_gnome_vfs_lib = new wxDynamicLibrary( wxT("libgnomevfs-2.so.0") ); - m_ok = m_gnome_vfs_lib->IsLoaded(); - if (!m_ok) return; - - InitializeMethods(); + m_libGnomeVFS.Load("libgnomevfs-2.so.0"); + m_ok = m_libGnomeVFS.IsLoaded() && InitializeMethods(); } wxGnomeVFSLibrary::~wxGnomeVFSLibrary() { - if (m_gnome_vfs_lib) - delete m_gnome_vfs_lib; + // we crash on exit later (i.e. after main() finishes) if we unload this + // library, apparently it inserts some hooks in other libraries to which we + // link implicitly (GTK+ itself?) which are not uninstalled when it's + // unloaded resulting in this crash, so just leave it in memory -- it's a + // lesser evil + m_libGnomeVFS.Detach(); } bool wxGnomeVFSLibrary::IsOk() @@ -94,15 +86,12 @@ bool wxGnomeVFSLibrary::IsOk() return m_ok; } -void wxGnomeVFSLibrary::InitializeMethods() +bool wxGnomeVFSLibrary::InitializeMethods() { - m_ok = false; - bool success; + wxDL_METHOD_LOAD( m_libGnomeVFS, gnome_vfs_init ); + wxDL_METHOD_LOAD( m_libGnomeVFS, gnome_vfs_shutdown ); - wxDL_METHOD_LOAD( m_gnome_vfs_lib, gnome_vfs_init, success ) - wxDL_METHOD_LOAD( m_gnome_vfs_lib, gnome_vfs_shutdown, success ) - - m_ok = true; + return true; } static wxGnomeVFSLibrary* gs_lgvfs = NULL; @@ -162,7 +151,7 @@ bool wxGnomeVFSModule::OnInit() if (gs_lgvfs->IsOk()) { if (gs_lgvfs->gnome_vfs_init()) - wxMimeTypesManagerFactory::SetFactory( new wxGnomeVFSMimeTypesManagerFactory ); + wxMimeTypesManagerFactory::Set( new wxGnomeVFSMimeTypesManagerFactory ); } return true; } @@ -177,6 +166,4 @@ void wxGnomeVFSModule::OnExit() IMPLEMENT_DYNAMIC_CLASS(wxGnomeVFSModule, wxModule) -#endif - // wxUSE_LIBGNOMEVS - // wxUSE_MIMETYPE +#endif // wxUSE_LIBGNOMEVFS && wxUSE_MIMETYPE