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

Delta Between Two Patch Sets: Python/pythonrun.c

Issue 11619: On Windows, don't encode filenames in the import machinery
Left Patch Set: Created 8 years, 5 months ago
Right Patch Set: Created 6 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « Python/future.c ('k') | Python/symtable.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 1
2 /* Python interpreter top-level routines, including init/exit */ 2 /* Python interpreter top-level routines, including init/exit */
3 3
4 #include "Python.h" 4 #include "Python.h"
5 5
6 #include "Python-ast.h" 6 #include "Python-ast.h"
7 #undef Yield /* undefine macro conflicting with winbase.h */ 7 #undef Yield /* undefine macro conflicting with winbase.h */
8 #include "grammar.h" 8 #include "grammar.h"
9 #include "node.h" 9 #include "node.h"
10 #include "token.h" 10 #include "token.h"
(...skipping 2066 matching lines...) Expand 10 before | Expand all | Expand 10 after
2077 2077
2078 /* For use in Py_LIMITED_API */ 2078 /* For use in Py_LIMITED_API */
2079 #undef Py_CompileString 2079 #undef Py_CompileString
2080 PyObject * 2080 PyObject *
2081 PyCompileString(const char *str, const char *filename, int start) 2081 PyCompileString(const char *str, const char *filename, int start)
2082 { 2082 {
2083 return Py_CompileStringFlags(str, filename, start, NULL); 2083 return Py_CompileStringFlags(str, filename, start, NULL);
2084 } 2084 }
2085 2085
2086 struct symtable * 2086 struct symtable *
2087 Py_SymtableString(const char *str, const char *filename, int start) 2087 Py_SymtableStringObject(const char *str, PyObject *filename, int start)
2088 { 2088 {
2089 struct symtable *st; 2089 struct symtable *st;
2090 mod_ty mod; 2090 mod_ty mod;
2091 PyCompilerFlags flags; 2091 PyCompilerFlags flags;
2092 PyArena *arena = PyArena_New(); 2092 PyArena *arena;
2093
2094 arena = PyArena_New();
2093 if (arena == NULL) 2095 if (arena == NULL)
2094 return NULL; 2096 return NULL;
2095 2097
2096 flags.cf_flags = 0; 2098 flags.cf_flags = 0;
2097 mod = PyParser_ASTFromString(str, filename, start, &flags, arena); 2099 mod = PyParser_ASTFromStringObject(str, filename, start, &flags, arena);
2098 if (mod == NULL) { 2100 if (mod == NULL) {
2099 PyArena_Free(arena); 2101 PyArena_Free(arena);
2100 return NULL; 2102 return NULL;
2101 } 2103 }
2102 st = PySymtable_Build(mod, filename, 0); 2104 st = PySymtable_BuildObject(mod, filename, 0);
2103 PyArena_Free(arena); 2105 PyArena_Free(arena);
2104 return st; 2106 return st;
2105 } 2107 }
2106 2108
2109 struct symtable *
2110 Py_SymtableString(const char *str, const char *filename_str, int start)
2111 {
2112 PyObject *filename;
2113 struct symtable *st;
2114
2115 filename = PyUnicode_DecodeFSDefault(filename_str);
2116 if (filename == NULL)
2117 return NULL;
2118 st = Py_SymtableStringObject(str, filename, start);
2119 Py_DECREF(filename);
2120 return st;
2121 }
2122
2107 /* Preferred access to parser is through AST. */ 2123 /* Preferred access to parser is through AST. */
2108 mod_ty 2124 mod_ty
2109 PyParser_ASTFromString(const char *s, const char *filename, int start, 2125 PyParser_ASTFromStringObject(const char *s, PyObject *filename, int start,
2110 PyCompilerFlags *flags, PyArena *arena) 2126 PyCompilerFlags *flags, PyArena *arena)
2111 { 2127 {
2112 mod_ty mod; 2128 mod_ty mod;
2113 PyCompilerFlags localflags; 2129 PyCompilerFlags localflags;
2114 perrdetail err; 2130 perrdetail err;
2115 int iflags = PARSER_FLAGS(flags); 2131 int iflags = PARSER_FLAGS(flags);
2116 2132
2117 node *n = PyParser_ParseStringFlagsFilenameEx(s, filename, 2133 node *n = PyParser_ParseStringObject(s, filename,
2118 &_PyParser_Grammar, start, &err, 2134 &_PyParser_Grammar, start, &err,
2119 &iflags); 2135 &iflags);
2120 if (flags == NULL) { 2136 if (flags == NULL) {
2121 localflags.cf_flags = 0; 2137 localflags.cf_flags = 0;
2122 flags = &localflags; 2138 flags = &localflags;
2123 } 2139 }
2124 if (n) { 2140 if (n) {
2125 flags->cf_flags |= iflags & PyCF_MASK; 2141 flags->cf_flags |= iflags & PyCF_MASK;
2126 mod = PyAST_FromNode(n, flags, filename, arena); 2142 mod = PyAST_FromNodeObject(n, flags, filename, arena);
2127 PyNode_Free(n); 2143 PyNode_Free(n);
2128 } 2144 }
2129 else { 2145 else {
2130 err_input(&err); 2146 err_input(&err);
2131 mod = NULL; 2147 mod = NULL;
2132 } 2148 }
2133 err_free(&err); 2149 err_free(&err);
2134 return mod; 2150 return mod;
2135 } 2151 }
2136 2152
2137 mod_ty 2153 mod_ty
2138 PyParser_ASTFromFile(FILE *fp, const char *filename, const char* enc, 2154 PyParser_ASTFromString(const char *s, const char *filename_str, int start,
2139 int start, char *ps1, 2155 PyCompilerFlags *flags, PyArena *arena)
2140 char *ps2, PyCompilerFlags *flags, int *errcode, 2156 {
2141 PyArena *arena) 2157 PyObject *filename;
2158 mod_ty mod;
2159 filename = PyUnicode_DecodeFSDefault(filename_str);
2160 if (filename == NULL)
2161 return NULL;
2162 mod = PyParser_ASTFromStringObject(s, filename, start, flags, arena);
2163 Py_DECREF(filename);
2164 return mod;
2165 }
2166
2167 mod_ty
2168 PyParser_ASTFromFileObject(FILE *fp, PyObject *filename, const char* enc,
2169 int start, char *ps1,
2170 char *ps2, PyCompilerFlags *flags, int *errcode,
2171 PyArena *arena)
2142 { 2172 {
2143 mod_ty mod; 2173 mod_ty mod;
2144 PyCompilerFlags localflags; 2174 PyCompilerFlags localflags;
2145 perrdetail err; 2175 perrdetail err;
2146 int iflags = PARSER_FLAGS(flags); 2176 int iflags = PARSER_FLAGS(flags);
2147 2177
2148 node *n = PyParser_ParseFileFlagsEx(fp, filename, enc, 2178 node *n = PyParser_ParseFileObject(fp, filename, enc,
2149 &_PyParser_Grammar, 2179 &_PyParser_Grammar,
2150 start, ps1, ps2, &err, &iflags); 2180 start, ps1, ps2, &err, &iflags);
2151 if (flags == NULL) { 2181 if (flags == NULL) {
2152 localflags.cf_flags = 0; 2182 localflags.cf_flags = 0;
2153 flags = &localflags; 2183 flags = &localflags;
2154 } 2184 }
2155 if (n) { 2185 if (n) {
2156 flags->cf_flags |= iflags & PyCF_MASK; 2186 flags->cf_flags |= iflags & PyCF_MASK;
2157 mod = PyAST_FromNode(n, flags, filename, arena); 2187 mod = PyAST_FromNodeObject(n, flags, filename, arena);
2158 PyNode_Free(n); 2188 PyNode_Free(n);
2159 } 2189 }
2160 else { 2190 else {
2161 err_input(&err); 2191 err_input(&err);
2162 if (errcode) 2192 if (errcode)
2163 *errcode = err.error; 2193 *errcode = err.error;
2164 mod = NULL; 2194 mod = NULL;
2165 } 2195 }
2166 err_free(&err); 2196 err_free(&err);
2197 return mod;
2198 }
2199
2200 mod_ty
2201 PyParser_ASTFromFile(FILE *fp, const char *filename_str, const char* enc,
2202 int start, char *ps1,
2203 char *ps2, PyCompilerFlags *flags, int *errcode,
2204 PyArena *arena)
2205 {
2206 mod_ty mod;
2207 PyObject *filename;
2208 filename = PyUnicode_DecodeFSDefault(filename_str);
2209 if (filename == NULL)
2210 return NULL;
2211 mod = PyParser_ASTFromFileObject(fp, filename, enc, start, ps1, ps2,
2212 flags, errcode, arena);
2213 Py_DECREF(filename);
2167 return mod; 2214 return mod;
2168 } 2215 }
2169 2216
2170 /* Simplified interface to parsefile -- return node or set exception */ 2217 /* Simplified interface to parsefile -- return node or set exception */
2171 2218
2172 node * 2219 node *
2173 PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int fla gs) 2220 PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int fla gs)
2174 { 2221 {
2175 perrdetail err; 2222 perrdetail err;
2176 node *n = PyParser_ParseFileFlags(fp, filename, NULL, 2223 node *n = PyParser_ParseFileFlags(fp, filename, NULL,
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
2756 #undef PyRun_InteractiveLoop 2803 #undef PyRun_InteractiveLoop
2757 PyAPI_FUNC(int) 2804 PyAPI_FUNC(int)
2758 PyRun_InteractiveLoop(FILE *f, const char *p) 2805 PyRun_InteractiveLoop(FILE *f, const char *p)
2759 { 2806 {
2760 return PyRun_InteractiveLoopFlags(f, p, NULL); 2807 return PyRun_InteractiveLoopFlags(f, p, NULL);
2761 } 2808 }
2762 2809
2763 #ifdef __cplusplus 2810 #ifdef __cplusplus
2764 } 2811 }
2765 #endif 2812 #endif
LEFTRIGHT

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