8000 Ensure the str member of the tokenizer is always initialized · python/cpython@9296d0d · GitHub
[go: up one dir, main page]

Skip to content

Commit 9296d0d

Browse files
committed
Ensure the str member of the tokenizer is always initialized
1 parent c9c4444 commit 9296d0d

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

Parser/pegen_errors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ get_error_line_from_tokenizer_buffers(Parser *p, Py_ssize_t lineno)
245245
* (multi-line) statement are stored in p->tok->interactive_src_start.
246246
* If not, we're parsing from a string, which means that the whole source
247247
* is stored in p->tok->str. */
248-
assert(p->tok->fp == NULL || p->tok->fp == stdin);
248+
assert((p->tok->fp == NULL && p->tok->str != NULL) || p->tok->fp == stdin);
249249

250250
char *cur_line = p->tok->fp_interactive ? p->tok->interactive_src_start : p->tok->str;
251251
assert(cur_line != NULL);

Parser/tokenizer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ tok_new(void)
8787
tok->async_def_indent = 0;
8888
tok->async_def_nl = 0;
8989
tok->interactive_underflow = IUNDERFLOW_NORMAL;
90-
90+
tok->str = NULL;
9191
return tok;
9292
}
9393

Parser/tokenizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct tok_state {
7171
PyObject *decoding_readline; /* open(...).readline */
7272
PyObject *decoding_buffer;
7373
const char* enc; /* Encoding for the current str. */
74-
char* str;
74+
char* str; /* Source string being tokenized (if tokenizing from a string)*/
7575
char* input; /* Tokenizer's newline translated copy of the string. */
7676

7777
int type_comments; /* Whether to look for type comments */

0 commit comments

Comments
 (0)
0