summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-10-16 13:14:10 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-10-16 13:14:10 (GMT)
commit4c7c8c30235e42c47500b91549c2b6154b61f883 (patch)
tree649a94a99ea257c19a3e5ba17fc05a8044459243 /Python/pythonrun.c
parent5a7913eb3bf390a2f3fd28116fc789bf2c7e4b64 (diff)
downloadcpython-4c7c8c30235e42c47500b91549c2b6154b61f883.zip
cpython-4c7c8c30235e42c47500b91549c2b6154b61f883.tar.gz
cpython-4c7c8c30235e42c47500b91549c2b6154b61f883.tar.bz2
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.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 73fef75..8c535fd 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1213,7 +1213,7 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
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 @@ err_input(perrdetail *err)
{
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 @@ err_input(perrdetail *err)
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);