Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Include/fileutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ PyAPI_FUNC(int) _Py_GetLocaleconvNumeric(

#ifdef Py_BUILD_CORE
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);
#endif

#ifdef __cplusplus
Expand Down
12 changes: 12 additions & 0 deletions Python/fileutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ _Py_GetForceASCII(void)
}


void
_Py_ResetForceASCII(void)
{
force_ascii = -1;
}


static int
encode_ascii(const wchar_t *text, char **str,
Expand Down Expand Up @@ -252,6 +258,12 @@ _Py_GetForceASCII(void)
{
return 0;
}

void
_Py_ResetForceASCII(void)
{
/* nothing to do */
}
#endif /* !defined(__APPLE__) && !defined(__ANDROID__) && !defined(MS_WINDOWS) */


Expand Down
11 changes: 7 additions & 4 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ defined(HAVE_LANGINFO_H) && defined(CODESET)
char *
_Py_SetLocaleFromEnv(int category)
{
char *res;
#ifdef __ANDROID__
const char *locale;
const char **pvar;
Expand Down Expand Up @@ -569,10 +570,12 @@ _Py_SetLocaleFromEnv(int category)
}
}
#endif
return setlocale(category, utf8_locale);
#else /* __ANDROID__ */
return setlocale(category, "");
#endif /* __ANDROID__ */
res = setlocale(category, utf8_locale);
#else /* !defined(__ANDROID__) */
res = setlocale(category, "");
#endif
_Py_ResetForceASCII();
return res;
}


Expand Down