Skip to content

bpo-34523: Fix C locale coercion on FreeBSD CURRENT #10672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 23, 2018
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
8 changes: 8 additions & 0 deletions Include/internal/pycore_fileutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ PyAPI_FUNC(wchar_t*) _Py_DecodeUTF8_surrogateescape(

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(
struct lconv *lc,
PyObject **decimal_point,
Expand Down
13 changes: 13 additions & 0 deletions Python/fileutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ _Py_GetForceASCII(void)
}


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


static int
encode_ascii(const wchar_t *text, char **str,
size_t *error_pos, const char **reason,
Expand Down Expand Up @@ -296,6 +303,12 @@ _Py_GetForceASCII(void)
{
return 0;
}

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


Expand Down
12 changes: 8 additions & 4 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Python-ast.h"
#undef Yield /* undefine macro conflicting with <winbase.h> */
#include "pycore_context.h"
#include "pycore_fileutils.h"
#include "pycore_hamt.h"
#include "pycore_pathconfig.h"
#include "pycore_pylifecycle.h"
Expand Down Expand Up @@ -394,6 +395,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 @@ -440,10 +442,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