-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-30647: Check nl_langinfo(CODESET) in locale coercion #2374
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
bpo-30647: Check nl_langinfo(CODESET) in locale coercion #2374
Conversation
- 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, thanks for your PR! By analyzing the history of the files in this pull request, we identified @ericsnowcurrently, @vadmium and @zooba to be potential reviewers. |
Custom builds of most relevance to this change: FreeBSD: http://buildbot.python.org/all/builders/AMD64%20FreeBSD%2010.x%20Shared%20custom/builds/15 |
The test condition aimed at determining whether or not FreeBSD: http://buildbot.python.org/all/builders/AMD64%20FreeBSD%2010.x%20Shared%20custom/builds/16 |
OK, this is looking reasonably promising now: However, the adaptive nature of the tests mean they're also quite vulnerable to nominally passing without actually testing anything, so I'm going to adjust the test case to skip the |
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.
This looks good on Mac OS X now, but I'm not going to merge it until the FreeBSD 10 custom builder is back online: https://mail.python.org/pipermail/python-buildbots/2017-June/000121.html |
The FreeBSD 10 bot is back, and still showing the |
I'm finally setting up a local FreeBSD 10 box in Vagrant, so hopefully I'll be able to work out a sensible way to handle FreeBSD's current behaviour (and hopefully whatever I come up with generalise reasonably to other BSD variants) Current status: the unexpectedly failing tests turned out to be due to the VM having neither a hostname nor a local timezone set. The symptoms were a bit cryptic - the former resulted in an empty string from |
Experimenting locally, I was able to confirm that the following sequence of commands triggers the
The same failure also occurs if the second call uses a normal locale like However, I'm also seeing a behaviour where if I print |
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)
While the save-and-restore approach proved fruitless, it occurred to me that we haven't modified the environment at this point, so we can use that to restore the original locale settings. Custom FreeBSD buildbot run for the latest variant: http://buildbot.python.org/all/builders/AMD64%20FreeBSD%2010.x%20Shared%20custom/builds/19/steps/test/logs/stdio |
succeeds, but a subsequent "nl_langinfo(CODESET)" fails
coercion will happen on systems where this check succeeds,
and will be skipped otherwise
platform behaviour, rather than needing a new release to
enable coercion at build time
target, restoring the locale coercion behaviour on Mac OS X