Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QString::utf8() - is it re-entrant or not?

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

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    blex
    wrote on last edited by
    #1

    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


    Oleksiy Balabay

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      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).

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        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.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dangelog
          wrote on last edited by
          #4

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

          (Thanks to Thiago for telling :) )

          Software Engineer
          KDAB (UK) Ltd., a KDAB Group company

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            @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(); }
            @

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dangelog
              wrote on last edited by
              #6

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

              Software Engineer
              KDAB (UK) Ltd., a KDAB Group company

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

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

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved