summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-07-04 11:48:30 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-07-04 11:48:30 (GMT)
commitd64e8a75e5138d5e5970f0c70995ae5cc377c421 (patch)
tree6265672e911ab4e728984d811fe63069b930d6bb /Python/pythonrun.c
parentc5ee7f213e048ae20005eb6e5a09c76f9d8ec7f0 (diff)
downloadcpython-d64e8a75e5138d5e5970f0c70995ae5cc377c421.zip
cpython-d64e8a75e5138d5e5970f0c70995ae5cc377c421.tar.gz
cpython-d64e8a75e5138d5e5970f0c70995ae5cc377c421.tar.bz2
Issue #9642: Fix filesystem encoding initialization: use the ANSI code page on
Windows if the mbcs codec is not available, and fail with a fatal error if we cannot get the locale encoding (if nl_langinfo(CODESET) is not available) instead of using UTF-8.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 232d7be..5649e86 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -168,18 +168,25 @@ error:
return NULL;
}
-#if defined(HAVE_LANGINFO_H) && defined(CODESET)
static char*
-get_codeset(void)
+get_locale_encoding(void)
{
+#ifdef MS_WINDOWS
+ char codepage[100];
+ PyOS_snprintf(codepage, sizeof(codepage), "cp%d", GetACP());
+ return get_codec_name(codepage);
+#elif defined(HAVE_LANGINFO_H) && defined(CODESET)
char* codeset = nl_langinfo(CODESET);
if (!codeset || codeset[0] == '\0') {
PyErr_SetString(PyExc_ValueError, "CODESET is not set or empty");
return NULL;
}
return get_codec_name(codeset);
-}
+#else
+ PyErr_SetNone(PyExc_NotImplementedError);
+ return NULL;
#endif
+}
void
Py_InitializeEx(int install_sigs)
@@ -746,24 +753,17 @@ static int
initfsencoding(PyInterpreterState *interp)
{
PyObject *codec;
-#if defined(HAVE_LANGINFO_H) && defined(CODESET)
- char *codeset = NULL;
-
- if (Py_FileSystemDefaultEncoding == NULL) {
- /* On Unix, set the file system encoding according to the
- user's preference, if the CODESET names a well-known
- Python codec, and Py_FileSystemDefaultEncoding isn't
- initialized by other means. */
- codeset = get_codeset();
- if (codeset == NULL)
+
+ if (Py_FileSystemDefaultEncoding == NULL)
+ {
+ Py_FileSystemDefaultEncoding = get_locale_encoding();
+ if (Py_FileSystemDefaultEncoding == NULL)
Py_FatalError("Py_Initialize: Unable to get the locale encoding");
- Py_FileSystemDefaultEncoding = codeset;
Py_HasFileSystemDefaultEncoding = 0;
interp->fscodec_initialized = 1;
return 0;
}
-#endif
/* the encoding is mbcs, utf-8 or ascii */
codec = _PyCodec_Lookup(Py_FileSystemDefaultEncoding);