Skip to content

Commit 2b32aa7

Browse files
author
christian.heimes
committed
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. git-svn-id: http://svn.python.org/projects/python/branches/py3k@67055 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 5202b56 commit 2b32aa7

2 files changed

Lines changed: 35 additions & 9 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ What's New in Python 3.0 beta 5
1515
Core and Builtins
1616
-----------------
1717

18+
- Issue #4213: The file system encoding is now normalized by the
19+
codec subsystem, for example UTF-8 is turned into utf-8.
20+
1821
- Issue #4200: Changed the atexit module to store its state in its
1922
PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters.
2023

Python/pythonrun.c

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,37 @@ add_flag(int flag, const char *envs)
126126
return flag;
127127
}
128128

129+
#if defined(HAVE_LANGINFO_H) && defined(CODESET)
130+
static char*
131+
get_codeset(void)
132+
{
133+
char* codeset;
134+
PyObject *codec, *name;
135+
136+
codeset = nl_langinfo(CODESET);
137+
if (!codeset || codeset[0] == '\0')
138+
return NULL;
139+
140+
codec = _PyCodec_Lookup(codeset);
141+
if (!codec)
142+
goto error;
143+
144+
name = PyObject_GetAttrString(codec, "name");
145+
Py_CLEAR(codec);
146+
if (!name)
147+
goto error;
148+
149+
codeset = strdup(_PyUnicode_AsString(name));
150+
Py_DECREF(name);
151+
return codeset;
152+
153+
error:
154+
Py_XDECREF(codec);
155+
PyErr_Clear();
156+
return NULL;
157+
}
158+
#endif
159+
129160
void
130161
Py_InitializeEx(int install_sigs)
131162
{
@@ -257,15 +288,7 @@ Py_InitializeEx(int install_sigs)
257288
initialized by other means. Also set the encoding of
258289
stdin and stdout if these are terminals. */
259290

260-
codeset = nl_langinfo(CODESET);
261-
if (codeset && *codeset) {
262-
if (PyCodec_KnownEncoding(codeset))
263-
codeset = strdup(codeset);
264-
else
265-
codeset = NULL;
266-
} else
267-
codeset = NULL;
268-
291+
codeset = get_codeset();
269292
if (codeset) {
270293
if (!Py_FileSystemDefaultEncoding)
271294
Py_FileSystemDefaultEncoding = codeset;

0 commit comments

Comments
 (0)