assert((p->tok->fp == NULL && p->tok->str != NULL) || p->tok->fp == stdin);
char *cur_line = p->tok->fp_interactive ? p->tok->interactive_src_start : p->tok->str;
- assert(cur_line != NULL);
+ if (cur_line == NULL) {
+ assert(p->tok->fp_interactive);
+ // We can reach this point if the tokenizer buffers for interactive source have not been
+ // initialized because we failed to decode the original source with the given locale.
+ return PyUnicode_FromStringAndSize("", 0);
+ }
Py_ssize_t relative_lineno = p->starting_lineno ? lineno - p->starting_lineno + 1 : lineno;
const char* buf_end = p->tok->fp_interactive ? p->tok->interactive_src_end : p->tok->inp;
goto error;
}
- if (p->tok->fp_interactive) {
+ if (p->tok->fp_interactive && p->tok->interactive_src_start != NULL) {
error_line = get_error_line_from_tokenizer_buffers(p, lineno);
}
else if (p->start_rule == Py_file_input) {