One more question to kstaticdelter

Thiago Macieira thiago at kde.org
Mon Apr 30 22:15:04 BST 2007


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.

Can someone explain what the code intends to do?

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20070430/b4e10aa1/attachment.sig>


More information about the kde-core-devel mailing list