From fdc159ad6fd03d0e179e7dde7fe47e592936573c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 21 Aug 2009 18:00:10 +0200 Subject: Revert "Remove a global destructor from QtDBus." This reverts commit 3ed5b5ebf5b360dedbba14c03f6ca5701b3b9290. That was a well-intentioned commit and technically correct, but it breaks when there are static QDBusConnection objects in something that is loaded before QtDBus (like libraries that depend on QtDBus or applications like qdbus) Since QDBusConnection is ref-counted, the last instance is supposed to disconnect. However, if we have already unloaded libdbus-1, we can't do that. Q_GLOBAL_STATICs are destroyed too soon. --- src/dbus/qdbus_symbols.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/dbus/qdbus_symbols.cpp b/src/dbus/qdbus_symbols.cpp index 356b14c..ca0147a 100644 --- a/src/dbus/qdbus_symbols.cpp +++ b/src/dbus/qdbus_symbols.cpp @@ -39,7 +39,6 @@ ** ****************************************************************************/ -#include "qdbus_symbols_p.h" #include #include #include @@ -53,7 +52,7 @@ void *qdbus_resolve_me(const char *name); static QLibrary *qdbus_libdbus = 0; -static void qdbus_unloadLibDBus() +void qdbus_unloadLibDBus() { delete qdbus_libdbus; qdbus_libdbus = 0; @@ -77,11 +76,8 @@ bool qdbus_loadLibDBus() lib->setFileName(QLatin1String("dbus-1")); for (uint i = 0; i < sizeof(majorversions) / sizeof(majorversions[0]); ++i) { lib->setFileNameAndVersion(lib->fileName(), majorversions[i]); - if (lib->load() && lib->resolve("dbus_connection_open_private")) { - struct Unloader { ~Unloader() { qdbus_unloadLibDBus(); } }; - static Unloader unloader; + if (lib->load() && lib->resolve("dbus_connection_open_private")) return true; - } lib->unload(); } @@ -111,6 +107,8 @@ void *qdbus_resolve_me(const char *name) return ptr; } +Q_DESTRUCTOR_FUNCTION(qdbus_unloadLibDBus) + QT_END_NAMESPACE #endif -- cgit v0.12