Mercurial > cpython-lru_cache-weakref
diff Python/ast.c @ 85417:df2fdd42b375
Close #11619: The parser and the import machinery do not encode Unicode
filenames anymore on Windows.
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Mon, 26 Aug 2013 22:28:21 +0200 |
| parents | 96d817f41c4c |
| children | 142c62a490ce |
line wrap: on
line diff
--- a/Python/ast.c Mon Aug 26 14:05:19 2013 +0200 +++ b/Python/ast.c Mon Aug 26 22:28:21 2013 +0200 @@ -491,7 +491,7 @@ struct compiling { char *c_encoding; /* source encoding */ PyArena *c_arena; /* arena for allocating memeory */ - const char *c_filename; /* filename */ + PyObject *c_filename; /* filename */ PyObject *c_normalize; /* Normalization function from unicodedata. */ PyObject *c_normalize_args; /* Normalization argument tuple. */ }; @@ -573,24 +573,13 @@ ast_error(struct compiling *c, const node *n, const char *errmsg) { PyObject *value, *errstr, *loc, *tmp; - PyObject *filename_obj; - - loc = PyErr_ProgramText(c->c_filename, LINENO(n)); + + loc = PyErr_ProgramTextObject(c->c_filename, LINENO(n)); if (!loc) { Py_INCREF(Py_None); loc = Py_None; } - if (c->c_filename) { - filename_obj = PyUnicode_DecodeFSDefault(c->c_filename); - if (!filename_obj) { - Py_DECREF(loc); - return 0; - } - } else { - Py_INCREF(Py_None); - filename_obj = Py_None; - } - tmp = Py_BuildValue("(NiiN)", filename_obj, LINENO(n), n->n_col_offset, loc); + tmp = Py_BuildValue("(OiiN)", c->c_filename, LINENO(n), n->n_col_offset, loc); if (!tmp) return 0; errstr = PyUnicode_FromString(errmsg); @@ -673,8 +662,8 @@ */ mod_ty -PyAST_FromNode(const node *n, PyCompilerFlags *flags, const char *filename, - PyArena *arena) +PyAST_FromNodeObject(const node *n, PyCompilerFlags *flags, + PyObject *filename, PyArena *arena) { int i, j, k, num; asdl_seq *stmts = NULL; @@ -684,6 +673,7 @@ mod_ty res = NULL; c.c_arena = arena; + /* borrowed reference */ c.c_filename = filename; c.c_normalize = c.c_normalize_args = NULL; if (flags && flags->cf_flags & PyCF_SOURCE_IS_UTF8) { @@ -797,6 +787,21 @@ return res; } +mod_ty +PyAST_FromNode(const node *n, PyCompilerFlags *flags, const char *filename_str, + PyArena *arena) +{ + mod_ty mod; + PyObject *filename; + filename = PyUnicode_DecodeFSDefault(filename_str); + if (filename == NULL) + return NULL; + mod = PyAST_FromNodeObject(n, flags, filename, arena); + Py_DECREF(filename); + return mod; + +} + /* Return the AST repr. of the operator represented as syntax (|, ^, etc.) */
