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.
This commit is contained in:
Victor Stinner 2010-10-16 13:14:10 +00:00
parent 5a7913eb3b
commit 4c7c8c3023
7 changed files with 69 additions and 28 deletions

View file

@ -102,6 +102,7 @@ static void
ast_error_finish(const char *filename)
{
PyObject *type, *value, *tback, *errstr, *offset, *loc, *tmp;
PyObject *filename_obj;
long lineno;
assert(PyErr_Occurred());
@ -130,7 +131,11 @@ ast_error_finish(const char *filename)
Py_INCREF(Py_None);
loc = Py_None;
}
tmp = Py_BuildValue("(zlOO)", filename, lineno, offset, loc);
filename_obj = PyUnicode_DecodeFSDefault(filename);
if (filename_obj != NULL)
tmp = Py_BuildValue("(NlOO)", filename_obj, lineno, offset, loc);
else
tmp = NULL;
Py_DECREF(loc);
if (!tmp) {
Py_DECREF(errstr);