[PyQt] pylupdate bug: infinite loop

Giovanni Bajo rasky at develer.com
Mon Jun 18 15:39:08 BST 2007


Hi Phil,

I found a bug in pylupdate. Try feeding it with the following file:

crasher.py:
=====================
def foo():
    """
    infinite loop trigger!
    """
=====================

and the following project file:

crasher.pro:
=====================
CODECFORSRC = UTF-8
CODECFORTR = UTF-8
SOURCES = crasher.py
=====================

pylupdate enters an infinite loop. By doing some debugging, I think it's 
related to this while loop, in fetchtr.cpp:


     if (!yyCodecForSource) {
        [...]
     } else {
         QByteArray originalBytes;
         while ( yyCh != EOF && yyCh != '\n' && yyCh != '"' && yyCh != 
'\\' ) {
             if ( yyParsingUtf8 && yyCh >= 0x80 && !quiet) {
                 qWarning( "%s:%d: Non-ASCII character detected in 
trUtf8 string",
                         (const char *) yyFileName, yyLineNo );
                 quiet = true;
             }
             originalBytes += (char)yyCh;
             yyCh = getChar();
         }

         QString unicodeStr = yyCodecForSource->toUnicode(originalBytes);
         QByteArray convertedBytes;


The while() loop is supposed to keep fetching bytes until it finds a 
special character that needs to be handled differently. The problem is 
that, within triple-quoted strings, '\n' is not a special character.

I tried fixing it (by guarding the \n check with a check to 
singleQuote), but it didn't work out. I'm sure you know how to fix it.

(BTW: too bad you can't simply import ast/compiler and be done with the 
lexer...)
-- 
Giovanni Bajo


More information about the PyQt mailing list