summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.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/bltinmodule.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/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 2e8d6e2..ece2a37 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -524,6 +524,7 @@ static PyObject *
builtin_compile(PyObject *self, PyObject *args, PyObject *kwds)
{
char *str;
+ PyObject *filename_obj;
char *filename;
char *startstr;
int mode = -1;
@@ -535,12 +536,16 @@ builtin_compile(PyObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"source", "filename", "mode", "flags",
"dont_inherit", NULL};
int start[] = {Py_file_input, Py_eval_input, Py_single_input};
+ PyObject *result;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "Oss|ii:compile",
- kwlist, &cmd, &filename, &startstr,
- &supplied_flags, &dont_inherit))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&s|ii:compile", kwlist,
+ &cmd,
+ PyUnicode_FSConverter, &filename_obj,
+ &startstr, &supplied_flags,
+ &dont_inherit))
return NULL;
+ filename = PyBytes_AS_STRING(filename_obj);
cf.cf_flags = supplied_flags | PyCF_SOURCE_IS_UTF8;
if (supplied_flags &
@@ -548,7 +553,7 @@ builtin_compile(PyObject *self, PyObject *args, PyObject *kwds)
{
PyErr_SetString(PyExc_ValueError,
"compile(): unrecognised flags");
- return NULL;
+ goto error;
}
/* XXX Warn if (supplied_flags & PyCF_MASK_OBSOLETE) != 0? */
@@ -565,14 +570,13 @@ builtin_compile(PyObject *self, PyObject *args, PyObject *kwds)
else {
PyErr_SetString(PyExc_ValueError,
"compile() arg 3 must be 'exec', 'eval' or 'single'");
- return NULL;
+ goto error;
}
is_ast = PyAST_Check(cmd);
if (is_ast == -1)
- return NULL;
+ goto error;
if (is_ast) {
- PyObject *result;
if (supplied_flags & PyCF_ONLY_AST) {
Py_INCREF(cmd);
result = cmd;
@@ -585,20 +589,27 @@ builtin_compile(PyObject *self, PyObject *args, PyObject *kwds)
mod = PyAST_obj2mod(cmd, arena, mode);
if (mod == NULL) {
PyArena_Free(arena);
- return NULL;
+ goto error;
}
result = (PyObject*)PyAST_Compile(mod, filename,
&cf, arena);
PyArena_Free(arena);
}
- return result;
+ goto finally;
}
str = source_as_string(cmd, "compile", "string, bytes, AST or code", &cf);
if (str == NULL)
- return NULL;
+ goto error;
- return Py_CompileStringFlags(str, filename, start[mode], &cf);
+ result = Py_CompileStringFlags(str, filename, start[mode], &cf);
+ goto finally;
+
+error:
+ result = NULL;
+finally:
+ Py_DECREF(filename_obj);
+ return result;
}
PyDoc_STRVAR(compile_doc,