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

Skip to content

Commit c049982

Browse files
author
Victor Stinner
committed
compiler_error(): use PyUnicode_DecodeFSDefault() to decode the filename,
instead of utf-8 in strict mode.
1 parent 15a71cd commit c049982

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

Python/compile.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3361,15 +3361,24 @@ compiler_in_loop(struct compiler *c) {
33613361
static int
33623362
compiler_error(struct compiler *c, const char *errstr)
33633363
{
3364-
PyObject *loc;
3364+
PyObject *loc, *filename;
33653365
PyObject *u = NULL, *v = NULL;
33663366

33673367
loc = PyErr_ProgramText(c->c_filename, c->u->u_lineno);
33683368
if (!loc) {
33693369
Py_INCREF(Py_None);
33703370
loc = Py_None;
33713371
}
3372-
u = Py_BuildValue("(ziiO)", c->c_filename, c->u->u_lineno,
3372+
if (c->c_filename != NULL) {
3373+
filename = PyUnicode_DecodeFSDefault(c->c_filename);
3374+
if (!filename)
3375+
goto exit;
3376+
}
3377+
else {
3378+
Py_INCREF(Py_None);
3379+
filename = Py_None;
3380+
}
3381+
u = Py_BuildValue("(NiiO)", filename, c->u->u_lineno,
33733382
c->u->u_col_offset, loc);
33743383
if (!u)
33753384
goto exit;

0 commit comments

Comments
 (0)