comparison Python/pythonrun.c @ 28174:3f90d21debe9 legacy-trunk

Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize, and not as a side effect of setlocale. Expose it as sys.getfilesystemencoding. Adjust test case.
author Martin v. Löwis <martin@v.loewis.de>
date Wed, 05 Mar 2003 15:13:47 +0000
parents c61ef183ce2f
children 04df965d675b
comparison
equal deleted inserted replaced
28173:5776fd188f20 28174:3f90d21debe9
13 #include "eval.h" 13 #include "eval.h"
14 #include "marshal.h" 14 #include "marshal.h"
15 15
16 #ifdef HAVE_SIGNAL_H 16 #ifdef HAVE_SIGNAL_H
17 #include <signal.h> 17 #include <signal.h>
18 #endif
19
20 #ifdef HAVE_LANGINFO_H
21 #include <locale.h>
22 #include <langinfo.h>
18 #endif 23 #endif
19 24
20 #ifdef MS_WINDOWS 25 #ifdef MS_WINDOWS
21 #undef BYTE 26 #undef BYTE
22 #include "windows.h" 27 #include "windows.h"
179 initmain(); /* Module __main__ */ 184 initmain(); /* Module __main__ */
180 if (!Py_NoSiteFlag) 185 if (!Py_NoSiteFlag)
181 initsite(); /* Module site */ 186 initsite(); /* Module site */
182 187
183 PyModule_WarningsModule = PyImport_ImportModule("warnings"); 188 PyModule_WarningsModule = PyImport_ImportModule("warnings");
189
190 #if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET)
191 /* On Unix, set the file system encoding according to the
192 user's preference, if the CODESET names a well-known
193 Python codec, and Py_FileSystemDefaultEncoding isn't
194 initialized by other means. */
195 if (!Py_FileSystemDefaultEncoding) {
196 char *saved_locale = setlocale(LC_CTYPE, NULL);
197 char *codeset;
198 setlocale(LC_CTYPE, "");
199 codeset = nl_langinfo(CODESET);
200 PyObject *enc = NULL;
201 if (*codeset) {
202 enc = PyCodec_Encoder(codeset);
203 if (enc) {
204 Py_FileSystemDefaultEncoding = strdup(codeset);
205 Py_DECREF(enc);
206 } else
207 PyErr_Clear();
208 }
209 setlocale(LC_CTYPE, saved_locale);
210 }
211 #endif
184 } 212 }
185 213
186 #ifdef COUNT_ALLOCS 214 #ifdef COUNT_ALLOCS
187 extern void dump_counts(void); 215 extern void dump_counts(void);
188 #endif 216 #endif