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

Side by Side Diff: Python/pythonrun.c

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 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/Python-ast.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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 return NULL; 161 return NULL;
162 } 162 }
163 return name_str; 163 return name_str;
164 164
165 error: 165 error:
166 Py_XDECREF(codec); 166 Py_XDECREF(codec);
167 Py_XDECREF(name); 167 Py_XDECREF(name);
168 return NULL; 168 return NULL;
169 } 169 }
170 170
171 #if defined(HAVE_LANGINFO_H) && defined(CODESET)
171 static char* 172 static char*
172 get_locale_encoding(void) 173 get_codeset(void)
173 { 174 {
174 #ifdef MS_WINDOWS
175 char codepage[100];
176 PyOS_snprintf(codepage, sizeof(codepage), "cp%d", GetACP());
177 return get_codec_name(codepage);
178 #elif defined(HAVE_LANGINFO_H) && defined(CODESET)
179 char* codeset = nl_langinfo(CODESET); 175 char* codeset = nl_langinfo(CODESET);
180 if (!codeset || codeset[0] == '\0') { 176 if (!codeset || codeset[0] == '\0') {
181 PyErr_SetString(PyExc_ValueError, "CODESET is not set or empty"); 177 PyErr_SetString(PyExc_ValueError, "CODESET is not set or empty");
182 return NULL; 178 return NULL;
183 } 179 }
184 return get_codec_name(codeset); 180 return get_codec_name(codeset);
185 #else 181 }
186 PyErr_SetNone(PyExc_NotImplementedError);
187 return NULL;
188 #endif 182 #endif
189 }
190 183
191 void 184 void
192 Py_InitializeEx(int install_sigs) 185 Py_InitializeEx(int install_sigs)
193 { 186 {
194 PyInterpreterState *interp; 187 PyInterpreterState *interp;
195 PyThreadState *tstate; 188 PyThreadState *tstate;
196 PyObject *bimod, *sysmod, *pstderr; 189 PyObject *bimod, *sysmod, *pstderr;
197 char *p; 190 char *p;
198 extern void _Py_ReadyTypes(void); 191 extern void _Py_ReadyTypes(void);
199 192
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 PyDict_SetItemString(d, "__builtins__", bimod) != 0) 739 PyDict_SetItemString(d, "__builtins__", bimod) != 0)
747 Py_FatalError("can't add __builtins__ to __main__"); 740 Py_FatalError("can't add __builtins__ to __main__");
748 Py_DECREF(bimod); 741 Py_DECREF(bimod);
749 } 742 }
750 } 743 }
751 744
752 static int 745 static int
753 initfsencoding(PyInterpreterState *interp) 746 initfsencoding(PyInterpreterState *interp)
754 { 747 {
755 PyObject *codec; 748 PyObject *codec;
749 #if defined(HAVE_LANGINFO_H) && defined(CODESET)
750 char *codeset = NULL;
756 751
757 if (Py_FileSystemDefaultEncoding == NULL) 752 if (Py_FileSystemDefaultEncoding == NULL) {
758 { 753 /* On Unix, set the file system encoding according to the
759 Py_FileSystemDefaultEncoding = get_locale_encoding(); 754 user's preference, if the CODESET names a well-known
760 if (Py_FileSystemDefaultEncoding == NULL) 755 Python codec, and Py_FileSystemDefaultEncoding isn't
756 initialized by other means. */
757 codeset = get_codeset();
758 if (codeset == NULL)
761 Py_FatalError("Py_Initialize: Unable to get the locale encoding"); 759 Py_FatalError("Py_Initialize: Unable to get the locale encoding");
762 760
761 Py_FileSystemDefaultEncoding = codeset;
763 Py_HasFileSystemDefaultEncoding = 0; 762 Py_HasFileSystemDefaultEncoding = 0;
764 interp->fscodec_initialized = 1; 763 interp->fscodec_initialized = 1;
765 return 0; 764 return 0;
766 } 765 }
766 #endif
767 767
768 /* the encoding is mbcs, utf-8 or ascii */ 768 /* the encoding is mbcs, utf-8 or ascii */
769 codec = _PyCodec_Lookup(Py_FileSystemDefaultEncoding); 769 codec = _PyCodec_Lookup(Py_FileSystemDefaultEncoding);
770 if (!codec) { 770 if (!codec) {
771 /* Such error can only occurs in critical situations: no more 771 /* Such error can only occurs in critical situations: no more
772 * memory, import a module of the standard library failed, 772 * memory, import a module of the standard library failed,
773 * etc. */ 773 * etc. */
774 return -1; 774 return -1;
775 } 775 }
776 Py_DECREF(codec); 776 Py_DECREF(codec);
(...skipping 1749 matching lines...) Expand 10 before | Expand all | Expand 10 after
2526 #undef PyRun_InteractiveLoop 2526 #undef PyRun_InteractiveLoop
2527 PyAPI_FUNC(int) 2527 PyAPI_FUNC(int)
2528 PyRun_InteractiveLoop(FILE *f, const char *p) 2528 PyRun_InteractiveLoop(FILE *f, const char *p)
2529 { 2529 {
2530 return PyRun_InteractiveLoopFlags(f, p, NULL); 2530 return PyRun_InteractiveLoopFlags(f, p, NULL);
2531 } 2531 }
2532 2532
2533 #ifdef __cplusplus 2533 #ifdef __cplusplus
2534 } 2534 }
2535 #endif 2535 #endif
OLDNEW
« no previous file with comments | « Python/Python-ast.c ('k') | Python/symtable.c » ('j') | no next file with comments »

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