Recorded merge of revisions 85569-85570 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r85569 | victor.stinner | 2010-10-16 15:14:10 +0200 (sam., 16 oct. 2010) | 4 lines

  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.
........
  r85570 | victor.stinner | 2010-10-16 15:42:53 +0200 (sam., 16 oct. 2010) | 4 lines

  Fix ast_error_finish() and err_input(): filename can be NULL

  Fix my previous commit (r85569).
........
This commit is contained in:
Victor Stinner 2010-10-19 01:22:07 +00:00
parent 089144e511
commit 15244f7b12
7 changed files with 81 additions and 27 deletions

View file

@ -536,6 +536,7 @@ static PyObject *
builtin_compile(PyObject *self, PyObject *args, PyObject *kwds)
{
char *str;
PyObject *filename_obj;
char *filename;
char *startstr;
int mode = -1;
@ -547,12 +548,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 &
@ -560,7 +565,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? */
@ -577,14 +582,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;
@ -597,20 +601,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,