bpo-30647: Check nl_langinfo(CODESET) in locale coercion by ncoghlan · Pull Request #2374 · python/cpython

@ncoghlan

- On some versions of FreeBSD, setting the "UTF-8" locale
  succeeds, but a subsequent "nl_langinfo(CODESET)" fails
- adding a check for this in the coercion logic means that
  coercion will happen on systems where this check succeeds,
  and will be skipped otherwise
- that way CPython should automatically adapt to changes in
  platform behaviour, rather than needing a new release to
  enable coercion at build time
- this also allows UTF-8 to be re-enabled as a coercion
  target, restoring the locale coercion behaviour on Mac OS X

@ncoghlan

@ncoghlan ncoghlan changed the title bpo-30647: Check nl_langinfo(CODESET) in locale coercion WIP: bpo-30647: Check nl_langinfo(CODESET) in locale coercion

Jun 24, 2017
The problem with dynamically adaptive tests is that they
can sometimes pass without actually testing anything useful.

On Linux and Mac OS X, if setlocale works, we also expect
nl_langinfo(CODESET) to *always* work for the coercion target
locales. The tests now reflect this by always assuming the
target locale will work if setlocale succeeds when running
on Linux or Mac OS X.

@ncoghlan

@ncoghlan

@ncoghlan

Saving and restoring the environment when nl_langinfo
fails doesn't work as intended on at least FreeBSD,
and potentially other systems as well.

Configuring the locale from the environment in this
case does the right thing (since we make the exact
same call later on in Py_Initialize anyway)

@ncoghlan ncoghlan changed the title WIP: bpo-30647: Check nl_langinfo(CODESET) in locale coercion bpo-30647: Check nl_langinfo(CODESET) in locale coercion

Jun 29, 2017

yan12125 added a commit to yan12125/python3-android that referenced this pull request

Jun 30, 2017

@ncoghlan ncoghlan deleted the bpo-30647-skip-coercion-if-nl-langinfo-fails branch

March 30, 2018 07:49