mirror of
https://github.com/python/cpython.git
synced 2025-12-10 11:00:14 +00:00
Fix for issue 6393: Python crashes on OSX when $LANG is set to some (but
not all) invalid values due to an invalid result from nl_langinfo
This commit is contained in:
parent
5bbab3e64f
commit
6d77e07196
1 changed files with 13 additions and 1 deletions
|
|
@ -570,10 +570,22 @@ else:
|
||||||
except Error:
|
except Error:
|
||||||
pass
|
pass
|
||||||
result = nl_langinfo(CODESET)
|
result = nl_langinfo(CODESET)
|
||||||
|
if not result and sys.platform == 'darwin':
|
||||||
|
# nl_langinfo can return an empty string
|
||||||
|
# when the setting has an invalid value.
|
||||||
|
# Default to UTF-8 in that case because
|
||||||
|
# UTF-8 is the default charset on OSX and
|
||||||
|
# returning nothing will crash the
|
||||||
|
# interpreter.
|
||||||
|
result = 'UTF-8'
|
||||||
|
|
||||||
setlocale(LC_CTYPE, oldloc)
|
setlocale(LC_CTYPE, oldloc)
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
return nl_langinfo(CODESET)
|
result = nl_langinfo(CODESET)
|
||||||
|
if not result and sys.platform == 'darwin':
|
||||||
|
# See above for explanation
|
||||||
|
result = 'UTF-8'
|
||||||
|
|
||||||
|
|
||||||
### Database
|
### Database
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue