christian.heimes
2008-10-30 23:47:41 UTC
Author: christian.heimes
Date: Thu Oct 30 22:40:04 2008
New Revision: 67055
Log:
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.
Modified:
python/branches/py3k/Misc/NEWS
python/branches/py3k/Python/pythonrun.c
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Thu Oct 30 22:40:04 2008
@@ -15,6 +15,9 @@
Core and Builtins
-----------------
+- Issue #4213: The file system encoding is now normalized by the
+ codec subsystem, for example UTF-8 is turned into utf-8.
+
- Issue #4200: Changed the atexit module to store its state in its
PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters.
Modified: python/branches/py3k/Python/pythonrun.c
==============================================================================
--- python/branches/py3k/Python/pythonrun.c (original)
+++ python/branches/py3k/Python/pythonrun.c Thu Oct 30 22:40:04 2008
@@ -126,6 +126,37 @@
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 @@
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;
Date: Thu Oct 30 22:40:04 2008
New Revision: 67055
Log:
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.
Modified:
python/branches/py3k/Misc/NEWS
python/branches/py3k/Python/pythonrun.c
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Thu Oct 30 22:40:04 2008
@@ -15,6 +15,9 @@
Core and Builtins
-----------------
+- Issue #4213: The file system encoding is now normalized by the
+ codec subsystem, for example UTF-8 is turned into utf-8.
+
- Issue #4200: Changed the atexit module to store its state in its
PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters.
Modified: python/branches/py3k/Python/pythonrun.c
==============================================================================
--- python/branches/py3k/Python/pythonrun.c (original)
+++ python/branches/py3k/Python/pythonrun.c Thu Oct 30 22:40:04 2008
@@ -126,6 +126,37 @@
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 @@
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;