Mercurial > cpython-lru_cache-weakref
diff Python/pythonrun.c @ 65399:55ed5c524428
Issue #9713, #10114: Parser functions (eg. PyParser_ASTFromFile) expects
filenames encoded to the filesystem encoding with surrogateescape error handler
(to support undecodable bytes), instead of UTF-8 in strict mode.
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Sat, 16 Oct 2010 13:14:10 +0000 |
| parents | 453fd8182c2f |
| children | 9ed68dd6b71f |
line wrap: on
line diff
--- a/Python/pythonrun.c Sat Oct 16 11:29:07 2010 +0000 +++ b/Python/pythonrun.c Sat Oct 16 13:14:10 2010 +0000 @@ -1213,7 +1213,7 @@ d = PyModule_GetDict(m); if (PyDict_GetItemString(d, "__file__") == NULL) { PyObject *f; - f = PyUnicode_FromString(filename); + f = PyUnicode_DecodeFSDefault(filename); if (f == NULL) return -1; if (PyDict_SetItemString(d, "__file__", f) < 0) { @@ -1968,7 +1968,9 @@ { PyObject *v, *w, *errtype, *errtext; PyObject *msg_obj = NULL; + PyObject *filename; char *msg = NULL; + errtype = PyExc_SyntaxError; switch (err->error) { case E_ERROR: @@ -2052,8 +2054,12 @@ errtext = PyUnicode_DecodeUTF8(err->text, strlen(err->text), "replace"); } - v = Py_BuildValue("(ziiN)", err->filename, - err->lineno, err->offset, errtext); + filename = PyUnicode_DecodeFSDefault(err->filename); + if (filename != NULL) + v = Py_BuildValue("(NiiN)", filename, + err->lineno, err->offset, errtext); + else + v = NULL; if (v != NULL) { if (msg_obj) w = Py_BuildValue("(OO)", msg_obj, v);
