]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
authorGuido van Rossum <guido@python.org>
Wed, 12 May 1993 11:35:44 +0000 (11:35 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 12 May 1993 11:35:44 +0000 (11:35 +0000)
* tokenizer.[ch]: allow continuation without \ inside () [] {}.

Modules/selectmodule.c
Parser/tokenizer.c
Parser/tokenizer.h

index de80b826599d051b4ef0c85068dd5b97931d458c..81fedd51956c17d79584629823ab7b43226c7326 100644 (file)
@@ -49,10 +49,12 @@ list2set(list, set, fd2obj)
            v = getintvalue(o);
        } else if ( (filenomethod = getattr(o, "fileno")) != NULL ) {
            fno = call_object(filenomethod, NULL);
+           DECREF(filenomethod);
            if ( fno == NULL )
                return -1;
            if ( !is_intobject(fno) ) {
                err_badarg();
+               DECREF(fno);
                return -1;
            }
            v = getintvalue(fno);
index 38a9e9ad9f626dbcae7c7b79e6fd3e74f5966110..725a2f1221b03d02cbf329b9426c8557d4b80fc9 100644 (file)
@@ -109,6 +109,7 @@ tok_new()
        tok->pendin = 0;
        tok->prompt = tok->nextprompt = NULL;
        tok->lineno = 0;
+       tok->level = 0;
        return tok;
 }
 
@@ -390,7 +391,7 @@ tok_get(tok, p_start, p_end)
                        /* We can't jump back right here since we still
                           may need to skip to the end of a comment */
                }
-               if (!blankline) {
+               if (!blankline && tok->level == 0) {
                        if (col == tok->indstack[tok->indent]) {
                                /* No change */
                        }
@@ -483,7 +484,7 @@ tok_get(tok, p_start, p_end)
        /* Newline */
        if (c == '\n') {
                tok->atbol = 1;
-               if (blankline)
+               if (blankline || tok->level > 0)
                        goto nextline;
                *p_end = tok->cur - 1; /* Leave '\n' out of the string */
                return NEWLINE;
@@ -612,6 +613,20 @@ tok_get(tok, p_start, p_end)
                tok_backup(tok, c2);
        }
        
+       /* Keep track of parenteses nesting level */
+       switch (c) {
+       case '(':
+       case '[':
+       case '{':
+               tok->level++;
+               break;
+       case ')':
+       case ']':
+       case '}':
+               tok->level--;
+               break;
+       }
+       
        /* Punctuation character */
        *p_end = tok->cur;
        return tok_1char(c);
index 9abc59878fc1d67f1ebefae7526e25967de2c7b9..bdef859ce7b5cf9224b7cd4b0ddfe7ccb8df3485 100644 (file)
@@ -46,6 +46,8 @@ struct tok_state {
        int pendin;     /* Pending indents (if > 0) or dedents (if < 0) */
        char *prompt, *nextprompt;      /* For interactive prompting */
        int lineno;     /* Current line number */
+       int level;      /* () [] {} Parentheses nesting level */
+                       /* Used to allow free continuations inside them */
 };
 
 extern struct tok_state *tok_setups PROTO((char *));