summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-08-11 14:02:14 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2007-08-11 14:02:14 (GMT)
commitd1cd4d41762ba55bfa121875fbcbde19fb6a35f1 (patch)
treeefc776f69cdf44259a96e12ada8ea14dbe9e0362 /Python/pythonrun.c
parent79c320898d43eaafa28c1c67a105a17cb9b233bf (diff)
downloadcpython-d1cd4d41762ba55bfa121875fbcbde19fb6a35f1.zip
cpython-d1cd4d41762ba55bfa121875fbcbde19fb6a35f1.tar.gz
cpython-d1cd4d41762ba55bfa121875fbcbde19fb6a35f1.tar.bz2
Set sys.stdout.encoding properly.
Always set LC_CTYPE on interpreter startup. Add device_encoding function.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index bb69b19..cc0926a 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -154,7 +154,6 @@ Py_InitializeEx(int install_sigs)
char *p;
#if defined(HAVE_LANGINFO_H) && defined(CODESET)
char *codeset;
- char *saved_locale;
#endif
extern void _Py_ReadyTypes(void);
@@ -162,6 +161,13 @@ Py_InitializeEx(int install_sigs)
return;
initialized = 1;
+#ifdef HAVE_SETLOCALE
+ /* Set up the LC_CTYPE locale, so we can obtain
+ the locale's charset without having to switch
+ locales. */
+ setlocale(LC_CTYPE, "");
+#endif
+
if ((p = Py_GETENV("PYTHONDEBUG")) && *p != '\0')
Py_DebugFlag = add_flag(Py_DebugFlag, p);
if ((p = Py_GETENV("PYTHONVERBOSE")) && *p != '\0')
@@ -254,8 +260,6 @@ Py_InitializeEx(int install_sigs)
initialized by other means. Also set the encoding of
stdin and stdout if these are terminals. */
- saved_locale = strdup(setlocale(LC_CTYPE, NULL));
- setlocale(LC_CTYPE, "");
codeset = nl_langinfo(CODESET);
if (codeset && *codeset) {
PyObject *enc = PyCodec_Encoder(codeset);
@@ -268,8 +272,6 @@ Py_InitializeEx(int install_sigs)
}
} else
codeset = NULL;
- setlocale(LC_CTYPE, saved_locale);
- free(saved_locale);
if (codeset) {
if (!Py_FileSystemDefaultEncoding)