mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
bpo-34523: Fix C locale coercion on FreeBSD CURRENT (GH-10672)
bpo-34523, bpo-35290: C locale coercion now resets the Python internal "force ASCII" mode. This change fix the filesystem encoding on FreeBSD CURRENT, which has a new "C.UTF-8" locale, when the UTF-8 mode is disabled. Add _Py_ResetForceASCII(): _Py_SetLocaleFromEnv() now calls it.
This commit is contained in:
parent
e89607c0fc
commit
353933e712
3 changed files with 29 additions and 4 deletions
|
@ -32,6 +32,14 @@ PyAPI_FUNC(wchar_t*) _Py_DecodeUTF8_surrogateescape(
|
||||||
|
|
||||||
PyAPI_FUNC(int) _Py_GetForceASCII(void);
|
PyAPI_FUNC(int) _Py_GetForceASCII(void);
|
||||||
|
|
||||||
|
/* Reset "force ASCII" mode (if it was initialized).
|
||||||
|
|
||||||
|
This function should be called when Python changes the LC_CTYPE locale,
|
||||||
|
so the "force ASCII" mode can be detected again on the new locale
|
||||||
|
encoding. */
|
||||||
|
PyAPI_FUNC(void) _Py_ResetForceASCII(void);
|
||||||
|
|
||||||
|
|
||||||
PyAPI_FUNC(int) _Py_GetLocaleconvNumeric(
|
PyAPI_FUNC(int) _Py_GetLocaleconvNumeric(
|
||||||
struct lconv *lc,
|
struct lconv *lc,
|
||||||
PyObject **decimal_point,
|
PyObject **decimal_point,
|
||||||
|
|
|
@ -231,6 +231,13 @@ _Py_GetForceASCII(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
_Py_ResetForceASCII(void)
|
||||||
|
{
|
||||||
|
force_ascii = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
encode_ascii(const wchar_t *text, char **str,
|
encode_ascii(const wchar_t *text, char **str,
|
||||||
size_t *error_pos, const char **reason,
|
size_t *error_pos, const char **reason,
|
||||||
|
@ -296,6 +303,12 @@ _Py_GetForceASCII(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_Py_ResetForceASCII(void)
|
||||||
|
{
|
||||||
|
/* nothing to do */
|
||||||
|
}
|
||||||
#endif /* !defined(__APPLE__) && !defined(__ANDROID__) && !defined(MS_WINDOWS) */
|
#endif /* !defined(__APPLE__) && !defined(__ANDROID__) && !defined(MS_WINDOWS) */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "Python-ast.h"
|
#include "Python-ast.h"
|
||||||
#undef Yield /* undefine macro conflicting with <winbase.h> */
|
#undef Yield /* undefine macro conflicting with <winbase.h> */
|
||||||
#include "pycore_context.h"
|
#include "pycore_context.h"
|
||||||
|
#include "pycore_fileutils.h"
|
||||||
#include "pycore_hamt.h"
|
#include "pycore_hamt.h"
|
||||||
#include "pycore_pathconfig.h"
|
#include "pycore_pathconfig.h"
|
||||||
#include "pycore_pylifecycle.h"
|
#include "pycore_pylifecycle.h"
|
||||||
|
@ -394,6 +395,7 @@ done:
|
||||||
char *
|
char *
|
||||||
_Py_SetLocaleFromEnv(int category)
|
_Py_SetLocaleFromEnv(int category)
|
||||||
{
|
{
|
||||||
|
char *res;
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
const char *locale;
|
const char *locale;
|
||||||
const char **pvar;
|
const char **pvar;
|
||||||
|
@ -440,10 +442,12 @@ _Py_SetLocaleFromEnv(int category)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return setlocale(category, utf8_locale);
|
res = setlocale(category, utf8_locale);
|
||||||
#else /* __ANDROID__ */
|
#else /* !defined(__ANDROID__) */
|
||||||
return setlocale(category, "");
|
res = setlocale(category, "");
|
||||||
#endif /* __ANDROID__ */
|
#endif
|
||||||
|
_Py_ResetForceASCII();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue