[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/KDE/4.1/kdepimlibs/kabc
From:       Kevin Krammer <kevin.krammer () gmx ! at>
Date:       2008-12-07 12:09:59
Message-ID: 1228651799.856849.29295.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 893737 by krake:

Initialize the addressbook instance outside the constructor, so it does not try to \
load any resources. Resources might use nested event loops to simulate synchronous \
load and result in re-entry of ::self() causing multiple instance of a class supposed \
to be a singleton.

Backport of Revision 889879


 M  +26 -22    stdaddressbook.cpp  
 M  +5 -0      stdaddressbook.h  


--- branches/KDE/4.1/kdepimlibs/kabc/stdaddressbook.cpp #893736:893737
@@ -75,36 +75,31 @@
 {
   kDebug();
 
+  // delegate to other self() method since the only difference
+  // was the constructor being used and their only difference is
+  // what they pass to Private::init()
+  return self( false );
+}
+
+StdAddressBook *StdAddressBook::self( bool asynchronous )
+{
+  kDebug() << "asynchronous=" << asynchronous;
+
   if ( !s_gStdAddressBook ) {
-    s_gStdAddressBook = new StdAddressBook();
+    s_gStdAddressBook = new StdAddressBook( asynchronous, false );
 
-    // We don't use a global static here for two reasons:
+    // We don't use a global static here for this reason:
     //
-    // 1. The K_GLOBAL_STATIC does not allow two different constructor calls,
-    //    which we need because there are two self() methods
+    // There are problems with the destruction order: The destructor of
+    // StdAddressBook calls save(), which for LDAP address books, needs KIO
+    // (more specific: KProtocolInfo) to be still alive. However, with a global
+    // static, KProtocolInfo is already deleted, and the app will crash.
     //
-    // 2. There are problems with the destruction order: The destructor of
-    //    StdAddressBook calls save(), which for LDAP address books, needs KIO
-    //    (more specific: KProtocolInfo) to be still alive. However, with a global
-    //    static, KProtocolInfo is already deleted, and the app will crash.
-    //
     // qAddPostRoutine deletes the objects when the QApplication is destroyed,
     // which is earlier than the global statics, so this will work.
     qAddPostRoutine( deleteGlobalStdAddressBook );
-  }
 
-  return s_gStdAddressBook;
-}
-
-StdAddressBook *StdAddressBook::self( bool asynchronous )
-{
-  kDebug();
-
-  if ( !s_gStdAddressBook ) {
-    s_gStdAddressBook = new StdAddressBook( asynchronous );
-
-    // See comment in the other self() method for this.
-    qAddPostRoutine( deleteGlobalStdAddressBook );
+    s_gStdAddressBook->d->init( asynchronous );
   }
 
   return s_gStdAddressBook;
@@ -126,6 +121,15 @@
   d->init( asynchronous );
 }
 
+StdAddressBook::StdAddressBook( bool asynchronous, bool doInit )
+  : AddressBook( "" ), d( new Private( this ) )
+{
+  kDebug();
+
+  if ( doInit )
+    d->init( asynchronous );
+}
+
 StdAddressBook::~StdAddressBook()
 {
   if ( Private::mAutomaticSave ) {
--- branches/KDE/4.1/kdepimlibs/kabc/stdaddressbook.h #893736:893737
@@ -135,6 +135,11 @@
     StdAddressBook( bool asynchronous );
 
   private:
+    // needed another constructor for delaying Private::init() to right
+    // after the instance creation. Cannot change the other two since they
+    // are protected and might be called by subclasses
+    StdAddressBook( bool asynchronous, bool doInit );
+
     class Private;
     Private *const d;
 };


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic