Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(262386)

Unified Diff: Python/pythonrun.c

Issue 11619: On Windows, don't encode filenames in the import machinery
Patch Set: Created 5 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Python/future.c ('k') | Python/symtable.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Python/pythonrun.c Mon Aug 26 14:05:19 2013 +0200
+++ b/Python/pythonrun.c Mon Aug 26 16:10:52 2013 +0200
@@ -2084,46 +2084,62 @@ PyCompileString(const char *str, const c
}
struct symtable *
-Py_SymtableString(const char *str, const char *filename, int start)
+Py_SymtableStringObject(const char *str, PyObject *filename, int start)
{
struct symtable *st;
mod_ty mod;
PyCompilerFlags flags;
- PyArena *arena = PyArena_New();
+ PyArena *arena;
+
+ arena = PyArena_New();
if (arena == NULL)
return NULL;
flags.cf_flags = 0;
- mod = PyParser_ASTFromString(str, filename, start, &flags, arena);
+ mod = PyParser_ASTFromStringObject(str, filename, start, &flags, arena);
if (mod == NULL) {
PyArena_Free(arena);
return NULL;
}
- st = PySymtable_Build(mod, filename, 0);
+ st = PySymtable_BuildObject(mod, filename, 0);
PyArena_Free(arena);
return st;
}
+struct symtable *
+Py_SymtableString(const char *str, const char *filename_str, int start)
+{
+ PyObject *filename;
+ struct symtable *st;
+
+ filename = PyUnicode_DecodeFSDefault(filename_str);
+ if (filename == NULL)
+ return NULL;
+ st = Py_SymtableStringObject(str, filename, start);
+ Py_DECREF(filename);
+ return st;
+}
+
/* Preferred access to parser is through AST. */
mod_ty
-PyParser_ASTFromString(const char *s, const char *filename, int start,
- PyCompilerFlags *flags, PyArena *arena)
+PyParser_ASTFromStringObject(const char *s, PyObject *filename, int start,
+ PyCompilerFlags *flags, PyArena *arena)
{
mod_ty mod;
PyCompilerFlags localflags;
perrdetail err;
int iflags = PARSER_FLAGS(flags);
- node *n = PyParser_ParseStringFlagsFilenameEx(s, filename,
- &_PyParser_Grammar, start, &err,
- &iflags);
+ node *n = PyParser_ParseStringObject(s, filename,
+ &_PyParser_Grammar, start, &err,
+ &iflags);
if (flags == NULL) {
localflags.cf_flags = 0;
flags = &localflags;
}
if (n) {
flags->cf_flags |= iflags & PyCF_MASK;
- mod = PyAST_FromNode(n, flags, filename, arena);
+ mod = PyAST_FromNodeObject(n, flags, filename, arena);
PyNode_Free(n);
}
else {
@@ -2135,26 +2151,40 @@ PyParser_ASTFromString(const char *s, co
}
mod_ty
-PyParser_ASTFromFile(FILE *fp, const char *filename, const char* enc,
- int start, char *ps1,
- char *ps2, PyCompilerFlags *flags, int *errcode,
- PyArena *arena)
+PyParser_ASTFromString(const char *s, const char *filename_str, int start,
+ PyCompilerFlags *flags, PyArena *arena)
+{
+ PyObject *filename;
+ mod_ty mod;
+ filename = PyUnicode_DecodeFSDefault(filename_str);
+ if (filename == NULL)
+ return NULL;
+ mod = PyParser_ASTFromStringObject(s, filename, start, flags, arena);
+ Py_DECREF(filename);
+ return mod;
+}
+
+mod_ty
+PyParser_ASTFromFileObject(FILE *fp, PyObject *filename, const char* enc,
+ int start, char *ps1,
+ char *ps2, PyCompilerFlags *flags, int *errcode,
+ PyArena *arena)
{
mod_ty mod;
PyCompilerFlags localflags;
perrdetail err;
int iflags = PARSER_FLAGS(flags);
- node *n = PyParser_ParseFileFlagsEx(fp, filename, enc,
- &_PyParser_Grammar,
- start, ps1, ps2, &err, &iflags);
+ node *n = PyParser_ParseFileObject(fp, filename, enc,
+ &_PyParser_Grammar,
+ start, ps1, ps2, &err, &iflags);
if (flags == NULL) {
localflags.cf_flags = 0;
flags = &localflags;
}
if (n) {
flags->cf_flags |= iflags & PyCF_MASK;
- mod = PyAST_FromNode(n, flags, filename, arena);
+ mod = PyAST_FromNodeObject(n, flags, filename, arena);
PyNode_Free(n);
}
else {
@@ -2167,6 +2197,23 @@ PyParser_ASTFromFile(FILE *fp, const cha
return mod;
}
+mod_ty
+PyParser_ASTFromFile(FILE *fp, const char *filename_str, const char* enc,
+ int start, char *ps1,
+ char *ps2, PyCompilerFlags *flags, int *errcode,
+ PyArena *arena)
+{
+ mod_ty mod;
+ PyObject *filename;
+ filename = PyUnicode_DecodeFSDefault(filename_str);
+ if (filename == NULL)
+ return NULL;
+ mod = PyParser_ASTFromFileObject(fp, filename, enc, start, ps1, ps2,
+ flags, errcode, arena);
+ Py_DECREF(filename);
+ return mod;
+}
+
/* Simplified interface to parsefile -- return node or set exception */
node *
« no previous file with comments | « Python/future.c ('k') | Python/symtable.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+