summaryrefslogtreecommitdiff
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-10-30 21:40:04 +0000
committerChristian Heimes <christian@cheimes.de>2008-10-30 21:40:04 +0000
commit6c83e3da5f20ef73db1306e6ae3ac0acdf557f52 (patch)
tree861dfc883759bb7fc80f58b3e5c6d79213433a23 /Python/pythonrun.c
parentd3eb8749e96a9ab488d45a57c769ab613072b99f (diff)
downloadcpython-6c83e3da5f20ef73db1306e6ae3ac0acdf557f52.tar.gz
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Patch created by Victor and reviewed by me. The change is required for proper initialization of subinterpreters.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 3e40d51fc0..4fb2b3e40d 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -126,6 +126,37 @@ add_flag(int flag, const char *envs)
return flag;
}
+#if defined(HAVE_LANGINFO_H) && defined(CODESET)
+static char*
+get_codeset(void)
+{
+ char* codeset;
+ PyObject *codec, *name;
+
+ codeset = nl_langinfo(CODESET);
+ if (!codeset || codeset[0] == '\0')
+ return NULL;
+
+ codec = _PyCodec_Lookup(codeset);
+ if (!codec)
+ goto error;
+
+ name = PyObject_GetAttrString(codec, "name");
+ Py_CLEAR(codec);
+ if (!name)
+ goto error;
+
+ codeset = strdup(_PyUnicode_AsString(name));
+ Py_DECREF(name);
+ return codeset;
+
+error:
+ Py_XDECREF(codec);
+ PyErr_Clear();
+ return NULL;
+}
+#endif
+
void
Py_InitializeEx(int install_sigs)
{
@@ -257,15 +288,7 @@ Py_InitializeEx(int install_sigs)
initialized by other means. Also set the encoding of
stdin and stdout if these are terminals. */
- codeset = nl_langinfo(CODESET);
- if (codeset && *codeset) {
- if (PyCodec_KnownEncoding(codeset))
- codeset = strdup(codeset);
- else
- codeset = NULL;
- } else
- codeset = NULL;
-
+ codeset = get_codeset();
if (codeset) {
if (!Py_FileSystemDefaultEncoding)
Py_FileSystemDefaultEncoding = codeset;