Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QString::utf8() - is it re-entrant or not?



  • In accordance with the Qt documentation for QString class

    bq. All functions in this class are reentrant, except for ascii(), latin1(), utf8(), and local8Bit(), which are non-reentrant.

    But the implementation of QString::utf8() is the following:

    @ inline QT3_SUPPORT QByteArray utf8() const{ return toUtf8(); }
    @

    So, the toUtf8() should be also non-reentrant.

    The same situation with local8Bit().

    My current understanding is that the documentation is incorrect. utf8() (and local8Bit()) should be removed from the list of non-reentrant functions.

    Please confirm or provide additional clarifications.

    Thanks



  • Right -- did you try to download the sources for Qt 4.0 or similar and see if the implementation was different? (Maybe it used a global, non locked cache).



  • The warning has been introduced with "Qt 4.2.0":http://doc.qt.nokia.com/4.2/qstring.html. Both in "Qt 4.0.x":http://doc.qt.nokia.com/4.0/qstring-qt3.html and "4.1.x":http://doc.qt.nokia.com/4.1/qstring.html no method was marked as being not reentrant. I don't know the reason, the change logs for the release do not mention the change and I do not have a git log or something similar that could give a comment on it.



  • Ok, point settled down -- utf8() is reentrant, ascii is not(). Documentation bug.

    (Thanks to Thiago for telling :) )



  • @peppe
    Did you check the other methods with Thiago too?

    I would expect the following situation to be true:

    @
    // NOT reentrant:
    inline QT3_SUPPORT const char *ascii() const { return ascii_helper(); }
    inline QT3_SUPPORT const char *latin1() const { return latin1_helper(); }

    // actually reentrant but wrong in the docs
    // these are just aliases for reentrant Qt4 methods
    inline QT3_SUPPORT QByteArray utf8() const { return toUtf8(); }
    inline QT3_SUPPORT QByteArray local8Bit() const{ return toLocal8Bit(); }
    @



  • That's exactly the case -- notice that the helper()s methods store stuff in a non-locked, global hash.



  • Thanx for clarifying. I've added a "DocNote":/doc/qt-4.7/qstring.html#note-104 to [[Doc:QString]]'s online docs.


Log in to reply