summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-08-26 20:28:21 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-08-26 20:28:21 (GMT)
commit14e461d5b92000ec4e89182fa25ab0d5b5b31234 (patch)
tree21e37d8661cbe50e7ddbedc1b35a486adc1eae87 /Modules
parent33824f6fd70f89dd39fcb7ed1651e8097c57d340 (diff)
downloadcpython-14e461d5b92000ec4e89182fa25ab0d5b5b31234.zip
cpython-14e461d5b92000ec4e89182fa25ab0d5b5b31234.tar.gz
cpython-14e461d5b92000ec4e89182fa25ab0d5b5b31234.tar.bz2
Close #11619: The parser and the import machinery do not encode Unicode
filenames anymore on Windows.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/parsermodule.c49
-rw-r--r--Modules/symtablemodule.c10
2 files changed, 37 insertions, 22 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 7a6e455..537a2e9 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -477,33 +477,46 @@ parser_st2list(PyST_Object *self, PyObject *args, PyObject *kw)
static PyObject*
parser_compilest(PyST_Object *self, PyObject *args, PyObject *kw)
{
- PyObject* res = 0;
- PyArena* arena;
+ PyObject* res = NULL;
+ PyArena* arena = NULL;
mod_ty mod;
- char* str = "<syntax-tree>";
+ PyObject* filename = NULL;
int ok;
static char *keywords[] = {"st", "filename", NULL};
if (self == NULL || PyModule_Check(self))
- ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|s:compilest", keywords,
- &PyST_Type, &self, &str);
+ ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|O&:compilest", keywords,
+ &PyST_Type, &self,
+ PyUnicode_FSDecoder, &filename);
else
- ok = PyArg_ParseTupleAndKeywords(args, kw, "|s:compile", &keywords[1],
- &str);
-
- if (ok) {
- arena = PyArena_New();
- if (arena) {
- mod = PyAST_FromNode(self->st_node, &(self->st_flags), str, arena);
- if (mod) {
- res = (PyObject *)PyAST_Compile(mod, str, &(self->st_flags), arena);
- }
- PyArena_Free(arena);
- }
+ ok = PyArg_ParseTupleAndKeywords(args, kw, "|O&:compile", &keywords[1],
+ PyUnicode_FSDecoder, &filename);
+ if (!ok)
+ goto error;
+
+ if (filename == NULL) {
+ filename = PyUnicode_FromString("<syntax-tree>");
+ if (filename == NULL)
+ goto error;
}
- return (res);
+ arena = PyArena_New();
+ if (!arena)
+ goto error;
+
+ mod = PyAST_FromNodeObject(self->st_node, &self->st_flags,
+ filename, arena);
+ if (!mod)
+ goto error;
+
+ res = (PyObject *)PyAST_CompileObject(mod, filename,
+ &self->st_flags, -1, arena);
+error:
+ Py_XDECREF(filename);
+ if (arena != NULL)
+ PyArena_Free(arena);
+ return res;
}
diff --git a/Modules/symtablemodule.c b/Modules/symtablemodule.c
index fbc1ff6..036fdb9 100644
--- a/Modules/symtablemodule.c
+++ b/Modules/symtablemodule.c
@@ -11,12 +11,12 @@ symtable_symtable(PyObject *self, PyObject *args)
PyObject *t;
char *str;
- char *filename;
+ PyObject *filename;
char *startstr;
int start;
- if (!PyArg_ParseTuple(args, "sss:symtable", &str, &filename,
- &startstr))
+ if (!PyArg_ParseTuple(args, "sO&s:symtable",
+ &str, PyUnicode_FSDecoder, &filename, &startstr))
return NULL;
if (strcmp(startstr, "exec") == 0)
start = Py_file_input;
@@ -27,9 +27,11 @@ symtable_symtable(PyObject *self, PyObject *args)
else {
PyErr_SetString(PyExc_ValueError,
"symtable() arg 3 must be 'exec' or 'eval' or 'single'");
+ Py_DECREF(filename);
return NULL;
}
- st = Py_SymtableString(str, filename, start);
+ st = Py_SymtableStringObject(str, filename, start);
+ Py_DECREF(filename);
if (st == NULL)
return NULL;
t = st->st_blocks;