KStringHandler: stateless/reentrant/thread-safe?

David Faure faure at kde.org
Tue Oct 30 11:10:41 GMT 2012


On Sunday 28 October 2012 09:22:39 Thiago Macieira wrote:
> On domingo, 28 de outubro de 2012 17.12.31, Frank Reininghaus wrote:
> > The functions with statics are:
> > 
> > 1. KStringHandler::isUtf8(const char *)
> > 
> > http://api.kde.org/4.9-api/kdelibs-apidocs/kdecore/html/kstringhandler_8cp
> > p_ source.html#l00204
> 
> Do notice that it's static const POD. Since it's not modifying anything,
> it's thread-safe. And stateless.
> 
> > 2. KStringHandler::from8Bit(const char *)
> > 
> > http://api.kde.org/4.9-api/kdelibs-apidocs/kdecore/html/kstringhandler_8cp
> > p_ source.html#l00289
> > 
> > The first one contains a static array of chars, which looks safe to
> > me. The second has a static reference to a QString which is generated
> > using KGlobal::staticQString(const char*). I'm not entirely sure if
> > that is safe as well.
> 
> That's a static const non-POD created by a non-constexpr. That means it's
> initialised on the first run.
> 
> It's thread-safe on GCC and C++11, but not on other conditions.

Just get rid of the staticQString, IMHO. This is an artefact from before the 
QLatin1String times -- and we got rid of it in KF5 already.
Heh this one is even about an empty string, for a corner case (empty char* as 
input), not worth the trouble IMHO.

And then the documentation will be correct.

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE, in particular KDE Frameworks 5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20121030/92b170cc/attachment.sig>


More information about the kde-core-devel mailing list