mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
and not as a side effect of setlocale. Expose it as sys.getfilesystemencoding. Adjust test case.
This commit is contained in:
parent
620c0837bd
commit
73d538b9c6
6 changed files with 67 additions and 22 deletions
|
@ -161,10 +161,6 @@ fixup_ulcase(void)
|
|||
Py_DECREF(ulo);
|
||||
}
|
||||
|
||||
#if defined(HAVE_LANGINFO_H) && defined(CODESET)
|
||||
static int fileencoding_uses_locale = 0;
|
||||
#endif
|
||||
|
||||
static PyObject*
|
||||
PyLocale_setlocale(PyObject* self, PyObject* args)
|
||||
{
|
||||
|
@ -213,22 +209,6 @@ PyLocale_setlocale(PyObject* self, PyObject* args)
|
|||
fixup_ulcase();
|
||||
/* things that got wrong up to here are ignored */
|
||||
PyErr_Clear();
|
||||
#if defined(HAVE_LANGINFO_H) && defined(CODESET)
|
||||
if (Py_FileSystemDefaultEncoding == NULL)
|
||||
fileencoding_uses_locale = 1;
|
||||
if (fileencoding_uses_locale) {
|
||||
char *codeset = nl_langinfo(CODESET);
|
||||
PyObject *enc = NULL;
|
||||
if (*codeset && (enc = PyCodec_Encoder(codeset))) {
|
||||
/* Release previous file encoding */
|
||||
if (Py_FileSystemDefaultEncoding)
|
||||
free((char *)Py_FileSystemDefaultEncoding);
|
||||
Py_FileSystemDefaultEncoding = strdup(codeset);
|
||||
Py_DECREF(enc);
|
||||
} else
|
||||
PyErr_Clear();
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
/* get locale */
|
||||
/* restore LC_NUMERIC first, if appropriate */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue