Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a849b83

Browse files
committed
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
* tokenizer.[ch]: allow continuation without \ inside () [] {}.
1 parent b2c6556 commit a849b83

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

Modules/selectmodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ list2set(list, set, fd2obj)
4949
v = getintvalue(o);
5050
} else if ( (filenomethod = getattr(o, "fileno")) != NULL ) {
5151
fno = call_object(filenomethod, NULL);
52+
DECREF(filenomethod);
5253
if ( fno == NULL )
5354
return -1;
5455
if ( !is_intobject(fno) ) {
5556
err_badarg();
57+
DECREF(fno);
5658
return -1;
5759
}
5860
v = getintvalue(fno);

Parser/tokenizer.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ tok_new()
109109
tok->pendin = 0;
110110
tok->prompt = tok->nextprompt = NULL;
111111
tok->lineno = 0;
112+
tok->level = 0;
112113
return tok;
113114
}
114115

@@ -390,7 +391,7 @@ tok_get(tok, p_start, p_end)
390391
/* We can't jump back right here since we still
391392
may need to skip to the end of a comment */
392393
}
393-
if (!blankline) {
394+
if (!blankline && tok->level == 0) {
394395
if (col == tok->indstack[tok->indent]) {
395396
/* No change */
396397
}
@@ -483,7 +484,7 @@ tok_get(tok, p_start, p_end)
483484
/* Newline */
484485
if (c == '\n') {
485486
tok->atbol = 1;
486-
if (blankline)
487+
if (blankline || tok->level > 0)
487488
goto nextline;
488489
*p_end = tok->cur - 1; /* Leave '\n' out of the string */
489490
return NEWLINE;
@@ -612,6 +613,20 @@ tok_get(tok, p_start, p_end)
612613
tok_backup(tok, c2);
613614
}
614615

616+
/* Keep track of parenteses nesting level */
617+
switch (c) {
618+
case '(':
619+
case '[':
620+
case '{':
621+
tok->level++;
622+
break;
623+
case ')':
624+
case ']':
625+
case '}':
626+
tok->level--;
627+
break;
628+
}
629+
615630
/* Punctuation character */
616631
*p_end = tok->cur;
617632
return tok_1char(c);

Parser/tokenizer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ struct tok_state {
4646
int pendin; /* Pending indents (if > 0) or dedents (if < 0) */
4747
char *prompt, *nextprompt; /* For interactive prompting */
4848
int lineno; /* Current line number */
49+
int level; /* () [] {} Parentheses nesting level */
50+
/* Used to allow free continuations inside them */
4951
};
5052

5153
extern struct tok_state *tok_setups PROTO((char *));

0 commit comments

Comments
 (0)