Commit d455e607 authored by Guido van Rossum's avatar Guido van Rossum

* selectmodule.c: fix (another!) two memory leaks -- this time in list2set

* tokenizer.[ch]: allow continuation without \ inside () [] {}.
parent 045612f5
...@@ -49,10 +49,12 @@ list2set(list, set, fd2obj) ...@@ -49,10 +49,12 @@ list2set(list, set, fd2obj)
v = getintvalue(o); v = getintvalue(o);
} else if ( (filenomethod = getattr(o, "fileno")) != NULL ) { } else if ( (filenomethod = getattr(o, "fileno")) != NULL ) {
fno = call_object(filenomethod, NULL); fno = call_object(filenomethod, NULL);
DECREF(filenomethod);
if ( fno == NULL ) if ( fno == NULL )
return -1; return -1;
if ( !is_intobject(fno) ) { if ( !is_intobject(fno) ) {
err_badarg(); err_badarg();
DECREF(fno);
return -1; return -1;
} }
v = getintvalue(fno); v = getintvalue(fno);
......
...@@ -109,6 +109,7 @@ tok_new() ...@@ -109,6 +109,7 @@ tok_new()
tok->pendin = 0; tok->pendin = 0;
tok->prompt = tok->nextprompt = NULL; tok->prompt = tok->nextprompt = NULL;
tok->lineno = 0; tok->lineno = 0;
tok->level = 0;
return tok; return tok;
} }
...@@ -390,7 +391,7 @@ tok_get(tok, p_start, p_end) ...@@ -390,7 +391,7 @@ tok_get(tok, p_start, p_end)
/* We can't jump back right here since we still /* We can't jump back right here since we still
may need to skip to the end of a comment */ may need to skip to the end of a comment */
} }
if (!blankline) { if (!blankline && tok->level == 0) {
if (col == tok->indstack[tok->indent]) { if (col == tok->indstack[tok->indent]) {
/* No change */ /* No change */
} }
...@@ -483,7 +484,7 @@ tok_get(tok, p_start, p_end) ...@@ -483,7 +484,7 @@ tok_get(tok, p_start, p_end)
/* Newline */ /* Newline */
if (c == '\n') { if (c == '\n') {
tok->atbol = 1; tok->atbol = 1;
if (blankline) if (blankline || tok->level > 0)
goto nextline; goto nextline;
*p_end = tok->cur - 1; /* Leave '\n' out of the string */ *p_end = tok->cur - 1; /* Leave '\n' out of the string */
return NEWLINE; return NEWLINE;
...@@ -612,6 +613,20 @@ tok_get(tok, p_start, p_end) ...@@ -612,6 +613,20 @@ tok_get(tok, p_start, p_end)
tok_backup(tok, c2); 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 */ /* Punctuation character */
*p_end = tok->cur; *p_end = tok->cur;
return tok_1char(c); return tok_1char(c);
......
...@@ -46,6 +46,8 @@ struct tok_state { ...@@ -46,6 +46,8 @@ struct tok_state {
int pendin; /* Pending indents (if > 0) or dedents (if < 0) */ int pendin; /* Pending indents (if > 0) or dedents (if < 0) */
char *prompt, *nextprompt; /* For interactive prompting */ char *prompt, *nextprompt; /* For interactive prompting */
int lineno; /* Current line number */ 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 *)); extern struct tok_state *tok_setups PROTO((char *));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment