File tree Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,14 @@ PyAPI_FUNC(wchar_t*) _Py_DecodeUTF8_surrogateescape(
3232
3333PyAPI_FUNC (int ) _Py_GetForceASCII (void );
3434
35+ /* Reset "force ASCII" mode (if it was initialized).
36+
37+ This function should be called when Python changes the LC_CTYPE locale,
38+ so the "force ASCII" mode can be detected again on the new locale
39+ encoding. */
40+ PyAPI_FUNC (void ) _Py_ResetForceASCII (void );
41+
42+
3543PyAPI_FUNC (int ) _Py_GetLocaleconvNumeric (
3644 struct lconv * lc ,
3745 PyObject * * decimal_point ,
Original file line number Diff line number Diff line change @@ -231,6 +231,13 @@ _Py_GetForceASCII(void)
231231}
232232
233233
234+ void
235+ _Py_ResetForceASCII (void )
236+ {
237+ force_ascii = -1 ;
238+ }
239+
240+
234241static int
235242encode_ascii (const wchar_t * text , char * * str ,
236243 size_t * error_pos , const char * * reason ,
@@ -296,6 +303,12 @@ _Py_GetForceASCII(void)
296303{
297304 return 0 ;
298305}
306+
307+ void
308+ _Py_ResetForceASCII (void )
309+ {
310+ /* nothing to do */
311+ }
299312#endif /* !defined(__APPLE__) && !defined(__ANDROID__) && !defined(MS_WINDOWS) */
300313
301314
Original file line number Diff line number Diff line change 55#include "Python-ast.h"
66#undef Yield /* undefine macro conflicting with <winbase.h> */
77#include "pycore_context.h"
8+ #include "pycore_fileutils.h"
89#include "pycore_hamt.h"
910#include "pycore_pathconfig.h"
1011#include "pycore_pylifecycle.h"
@@ -394,6 +395,7 @@ defined(HAVE_LANGINFO_H) && defined(CODESET)
394395char *
395396_Py_SetLocaleFromEnv (int category )
396397{
398+ char * res ;
397399#ifdef __ANDROID__
398400 const char * locale ;
399401 const char * * pvar ;
@@ -440,10 +442,12 @@ _Py_SetLocaleFromEnv(int category)
440442 }
441443 }
442444#endif
443- return setlocale (category , utf8_locale );
444- #else /* __ANDROID__ */
445- return setlocale (category , "" );
446- #endif /* __ANDROID__ */
445+ res = setlocale (category , utf8_locale );
446+ #else /* !defined(__ANDROID__) */
447+ res = setlocale (category , "" );
448+ #endif
449+ _Py_ResetForceASCII ();
450+ return res ;
447451}
448452
449453
You can’t perform that action at this time.
0 commit comments