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

Side by Side Diff: Python/pythonrun.c

Issue 11619: On Windows, don't encode filenames in the import machinery
Patch Set: Created 8 years, 4 months 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:
View unified diff | Download patch
« no previous file with comments | « Python/import.c ('k') | Python/symtable.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 1840
1841 /* For use in Py_LIMITED_API */ 1841 /* For use in Py_LIMITED_API */
1842 #undef Py_CompileString 1842 #undef Py_CompileString
1843 PyObject * 1843 PyObject *
1844 PyCompileString(const char *str, const char *filename, int start) 1844 PyCompileString(const char *str, const char *filename, int start)
1845 { 1845 {
1846 return Py_CompileStringFlags(str, filename, start, NULL); 1846 return Py_CompileStringFlags(str, filename, start, NULL);
1847 } 1847 }
1848 1848
1849 struct symtable * 1849 struct symtable *
1850 Py_SymtableString(const char *str, const char *filename, int start) 1850 Py_SymtableStringObject(const char *str, PyObject *filename, int start)
1851 { 1851 {
1852 struct symtable *st; 1852 struct symtable *st;
1853 mod_ty mod; 1853 mod_ty mod;
1854 PyCompilerFlags flags; 1854 PyCompilerFlags flags;
1855 PyArena *arena = PyArena_New(); 1855 PyArena *arena;
1856
1857 arena = PyArena_New();
1856 if (arena == NULL) 1858 if (arena == NULL)
1857 return NULL; 1859 return NULL;
1858 1860
1859 flags.cf_flags = 0; 1861 flags.cf_flags = 0;
1860 mod = PyParser_ASTFromString(str, filename, start, &flags, arena); 1862 mod = PyParser_ASTFromStringObject(str, filename, start, &flags, arena);
1861 if (mod == NULL) { 1863 if (mod == NULL) {
1864 Py_DECREF(filename);
1862 PyArena_Free(arena); 1865 PyArena_Free(arena);
1863 return NULL; 1866 return NULL;
1864 } 1867 }
1865 st = PySymtable_Build(mod, filename, 0); 1868 st = PySymtable_BuildObject(mod, filename, 0);
1869 Py_DECREF(filename);
1866 PyArena_Free(arena); 1870 PyArena_Free(arena);
1871 return st;
1872 }
1873
1874 struct symtable *
1875 Py_SymtableString(const char *str, const char *filename_str, int start)
1876 {
1877 PyObject *filename;
1878 struct symtable *st;
1879
1880 filename = PyUnicode_DecodeFSDefault(filename_str);
1881 if (filename == NULL)
1882 return NULL;
1883 st = Py_SymtableStringObject(str, filename, start);
1884 Py_DECREF(filename);
1867 return st; 1885 return st;
1868 } 1886 }
1869 1887
1870 /* Preferred access to parser is through AST. */ 1888 /* Preferred access to parser is through AST. */
1871 mod_ty 1889 mod_ty
1872 PyParser_ASTFromString(const char *s, const char *filename, int start, 1890 PyParser_ASTFromStringObject(const char *s, PyObject *filename, int start,
1873 PyCompilerFlags *flags, PyArena *arena) 1891 PyCompilerFlags *flags, PyArena *arena)
1874 { 1892 {
1875 mod_ty mod; 1893 mod_ty mod;
1876 PyCompilerFlags localflags; 1894 PyCompilerFlags localflags;
1877 perrdetail err; 1895 perrdetail err;
1878 int iflags = PARSER_FLAGS(flags); 1896 int iflags = PARSER_FLAGS(flags);
1879 1897
1880 node *n = PyParser_ParseStringFlagsFilenameEx(s, filename, 1898 node *n = PyParser_ParseStringObject(s, filename,
1881 &_PyParser_Grammar, start, &err, 1899 &_PyParser_Grammar, start, &err,
1882 &iflags); 1900 &iflags);
1883 if (flags == NULL) { 1901 if (flags == NULL) {
1884 localflags.cf_flags = 0; 1902 localflags.cf_flags = 0;
1885 flags = &localflags; 1903 flags = &localflags;
1886 } 1904 }
1887 if (n) { 1905 if (n) {
1888 flags->cf_flags |= iflags & PyCF_MASK; 1906 flags->cf_flags |= iflags & PyCF_MASK;
1889 mod = PyAST_FromNode(n, flags, filename, arena); 1907 mod = PyAST_FromNodeObject(n, flags, filename, arena);
1890 PyNode_Free(n); 1908 PyNode_Free(n);
1891 } 1909 }
1892 else { 1910 else {
1893 err_input(&err); 1911 err_input(&err);
1894 mod = NULL; 1912 mod = NULL;
1895 } 1913 }
1896 err_free(&err); 1914 err_free(&err);
1897 return mod; 1915 return mod;
1898 } 1916 }
1899 1917
1900 mod_ty 1918 mod_ty
1901 PyParser_ASTFromFile(FILE *fp, const char *filename, const char* enc, 1919 PyParser_ASTFromString(const char *s, const char *filename_str, int start,
1902 int start, char *ps1, 1920 PyCompilerFlags *flags, PyArena *arena)
1903 char *ps2, PyCompilerFlags *flags, int *errcode, 1921 {
1904 PyArena *arena) 1922 PyObject *filename;
1923 mod_ty mod;
1924 filename = PyUnicode_DecodeFSDefault(filename_str);
1925 if (filename == NULL)
1926 return NULL;
1927 mod = PyParser_ASTFromStringObject(s, filename, start, flags, arena);
1928 Py_DECREF(filename);
1929 return mod;
1930 }
1931
1932 mod_ty
1933 PyParser_ASTFromFileObject(FILE *fp, PyObject *filename, const char* enc,
1934 int start, char *ps1,
1935 char *ps2, PyCompilerFlags *flags, int *errcode,
1936 PyArena *arena)
1905 { 1937 {
1906 mod_ty mod; 1938 mod_ty mod;
1907 PyCompilerFlags localflags; 1939 PyCompilerFlags localflags;
1908 perrdetail err; 1940 perrdetail err;
1909 int iflags = PARSER_FLAGS(flags); 1941 int iflags = PARSER_FLAGS(flags);
1910 1942
1911 node *n = PyParser_ParseFileFlagsEx(fp, filename, enc, 1943 node *n = PyParser_ParseFileObject(fp, filename, enc,
1912 &_PyParser_Grammar, 1944 &_PyParser_Grammar,
1913 start, ps1, ps2, &err, &iflags); 1945 start, ps1, ps2, &err, &iflags);
1914 if (flags == NULL) { 1946 if (flags == NULL) {
1915 localflags.cf_flags = 0; 1947 localflags.cf_flags = 0;
1916 flags = &localflags; 1948 flags = &localflags;
1917 } 1949 }
1918 if (n) { 1950 if (n) {
1919 flags->cf_flags |= iflags & PyCF_MASK; 1951 flags->cf_flags |= iflags & PyCF_MASK;
1920 mod = PyAST_FromNode(n, flags, filename, arena); 1952 mod = PyAST_FromNodeObject(n, flags, filename, arena);
1921 PyNode_Free(n); 1953 PyNode_Free(n);
1922 } 1954 }
1923 else { 1955 else {
1924 err_input(&err); 1956 err_input(&err);
1925 if (errcode) 1957 if (errcode)
1926 *errcode = err.error; 1958 *errcode = err.error;
1927 mod = NULL; 1959 mod = NULL;
1928 } 1960 }
1929 err_free(&err); 1961 err_free(&err);
1962 return mod;
1963 }
1964
1965 mod_ty
1966 PyParser_ASTFromFile(FILE *fp, const char *filename_str, const char* enc,
1967 int start, char *ps1,
1968 char *ps2, PyCompilerFlags *flags, int *errcode,
1969 PyArena *arena)
1970 {
1971 mod_ty mod;
1972 PyObject *filename;
1973 filename = PyUnicode_DecodeFSDefault(filename_str);
1974 if (filename == NULL)
1975 return NULL;
1976 mod = PyParser_ASTFromFileObject(fp, filename, enc, start, ps1, ps2,
1977 flags, errcode, arena);
1978 Py_DECREF(filename);
1930 return mod; 1979 return mod;
1931 } 1980 }
1932 1981
1933 /* Simplified interface to parsefile -- return node or set exception */ 1982 /* Simplified interface to parsefile -- return node or set exception */
1934 1983
1935 node * 1984 node *
1936 PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int fla gs) 1985 PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int fla gs)
1937 { 1986 {
1938 perrdetail err; 1987 perrdetail err;
1939 node *n = PyParser_ParseFileFlags(fp, filename, NULL, 1988 node *n = PyParser_ParseFileFlags(fp, filename, NULL,
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
2512 #undef PyRun_InteractiveLoop 2561 #undef PyRun_InteractiveLoop
2513 PyAPI_FUNC(int) 2562 PyAPI_FUNC(int)
2514 PyRun_InteractiveLoop(FILE *f, const char *p) 2563 PyRun_InteractiveLoop(FILE *f, const char *p)
2515 { 2564 {
2516 return PyRun_InteractiveLoopFlags(f, p, NULL); 2565 return PyRun_InteractiveLoopFlags(f, p, NULL);
2517 } 2566 }
2518 2567
2519 #ifdef __cplusplus 2568 #ifdef __cplusplus
2520 } 2569 }
2521 #endif 2570 #endif
OLDNEW
« no previous file with comments | « Python/import.c ('k') | Python/symtable.c » ('j') | no next file with comments »

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