K_GLOBAL_STATIC and other macros

Matthias Kretz kretz at kde.org
Fri Apr 13 19:10:06 BST 2007


On Friday 13 April 2007 18:49, Thiago Macieira wrote:
> David Faure wrote:
> >Yes, and if the destructor calls e.g. KConfig::sync() then it will
> > crash, since it's too late then to use QTemporaryFile (since Qt-4.3).
>
> Can't we get TT to consider that a bug?

Actually the change that triggered the problem

-static QThreadStorage<uint *> randTLS;
+typedef QThreadStorage<uint *> SeedStorage;
+Q_GLOBAL_STATIC(SeedStorage, randTLS);

 int qrand()
 {
-    if (!randTLS.hasLocalData()) {
-        randTLS.setLocalData(new uint);
-        *randTLS.localData() = 1;
+    if (!randTLS()->hasLocalData()) {
+        randTLS()->setLocalData(new uint);
+        *randTLS()->localData() = 1;
     }

was a bugfix. The change implies that now qrand() cannot be used in global 
dtors anymore. That's what I was saying in my other mail: if it works without 
crashes in one version you cannot assume it will still work in the next 
version - which might introduce new global statics that are destructed before 
your object.

-- 
________________________________________________________
Matthias Kretz (Germany)                            <><
http://Vir.homelinux.org/
MatthiasKretz at gmx.net, kretz at kde.org,
Matthias.Kretz at urz.uni-heidelberg.de




More information about the kde-core-devel mailing list