diff options
author | Guido van Rossum <guido@python.org> | 1993-05-12 11:35:44 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1993-05-12 11:35:44 (GMT) |
commit | a849b834f1e86bec20027654c91bb4cc74de5c8d (patch) | |
tree | 9889abb429019cd73a52e225b1f9ddbc4d4b87ee | |
parent | b2c6556fb0d309a04e37c2c9937fed16284cd00f (diff) | |
download | cpython-a849b834f1e86bec20027654c91bb4cc74de5c8d.zip cpython-a849b834f1e86bec20027654c91bb4cc74de5c8d.tar.gz cpython-a849b834f1e86bec20027654c91bb4cc74de5c8d.tar.bz2 |
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
* tokenizer.[ch]: allow continuation without \ inside () [] {}.
-rw-r--r-- | Modules/selectmodule.c | 2 | ||||
-rw-r--r-- | Parser/tokenizer.c | 19 | ||||
-rw-r--r-- | Parser/tokenizer.h | 2 |
3 files changed, 21 insertions, 2 deletions
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index de80b82..81fedd5 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -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); diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 38a9e9a..725a2f1 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -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); diff --git a/Parser/tokenizer.h b/Parser/tokenizer.h index 9abc598..bdef859 100644 --- a/Parser/tokenizer.h +++ b/Parser/tokenizer.h @@ -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 *)); |