One more question to kstaticdelter

Christian Ehrlicher Ch.Ehrlicher at gmx.de
Tue May 1 10:04:09 BST 2007


Ingo Klöcker schrieb:
> On Monday 30 April 2007 23:15, Thiago Macieira wrote:
>> Christian Ehrlicher wrote:
>>> Hi,
>>>
>>> kconfig_compiler creates code like this:
>>>
>>> Settings *Settings::mSelf = 0;
>>> static KStaticDeleter<Settings> staticSettingsDeleter;
>>>
>>> Settings *Settings::self()
>>> {
>>>   if ( !mSelf ) {
>>>     staticSettingsDeleter.setObject( mSelf, new Settings() );
>>>     mSelf->readConfig();
>>>   }
>>>
>>>   return mSelf;
>>> }
>>>
>>> Settings::Settings(  )
>>>
>>>   : KConfigSkeleton( QLatin1String( "kgetrc" ) )
>>>
>>> {
>>>   mSelf = this;
>>>   ..
>>>
>>> }
>>>
>>> Settings::~Settings()
>>> {
>>>   if ( mSelf == this )
>>>     staticSettingsDeleter.setObject( mSelf, 0, false );
>>> }
>>>
>>> What's the best way to replace this? I would use a
>>> QBasicAtomicPointer and qAddPostRoutine()... but I won't break
>>> kconfig_compiler so I ask you
>>>
>>> :)
>> Yes, that looks like it's the best option.
>>
>> However, if someone calls the constructor twice, it leaks memory. So,
>> something is wrong.
> 
> The constructor is not supposed to be called directly, but only through 
> self().
> 
But this can't be guaranteed because the ctor is not private.
>> Can someone explain what the code intends to do?
> 
> Provide a KConfigXT settings singleton.


Christian

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 250 bytes
Desc: OpenPGP digital signature
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20070501/4d23f2fb/attachment.sig>


More information about the kde-core-devel mailing list