mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Issue #8589: surrogateescape error handler is not available at startup
Py_Main() uses _Py_wchar2char() + PyUnicode_FromWideChar() instead of PyUnicode_DecodeFSDefault(), because the PyCodec machinery is not ready yet.
This commit is contained in:
parent
d2be5b4fe4
commit
c2d76fd339
1 changed files with 11 additions and 6 deletions
|
@ -488,7 +488,8 @@ Py_Main(int argc, wchar_t **argv)
|
||||||
#else
|
#else
|
||||||
if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') {
|
if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') {
|
||||||
char *buf, *oldloc;
|
char *buf, *oldloc;
|
||||||
PyObject *warning;
|
wchar_t *wchar;
|
||||||
|
PyObject *unicode;
|
||||||
|
|
||||||
/* settle for strtok here as there's no one standard
|
/* settle for strtok here as there's no one standard
|
||||||
C89 wcstok */
|
C89 wcstok */
|
||||||
|
@ -500,11 +501,15 @@ Py_Main(int argc, wchar_t **argv)
|
||||||
oldloc = strdup(setlocale(LC_ALL, NULL));
|
oldloc = strdup(setlocale(LC_ALL, NULL));
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
for (p = strtok(buf, ","); p != NULL; p = strtok(NULL, ",")) {
|
for (p = strtok(buf, ","); p != NULL; p = strtok(NULL, ",")) {
|
||||||
warning = PyUnicode_DecodeFSDefault(p);
|
wchar = _Py_char2wchar(p);
|
||||||
if (warning != NULL) {
|
if (wchar == NULL)
|
||||||
PySys_AddWarnOptionUnicode(warning);
|
continue;
|
||||||
Py_DECREF(warning);
|
unicode = PyUnicode_FromWideChar(wchar, wcslen(wchar));
|
||||||
}
|
PyMem_Free(wchar);
|
||||||
|
if (unicode == NULL)
|
||||||
|
continue;
|
||||||
|
PySys_AddWarnOptionUnicode(unicode);
|
||||||
|
Py_DECREF(unicode);
|
||||||
}
|
}
|
||||||
setlocale(LC_ALL, oldloc);
|
setlocale(LC_ALL, oldloc);
|
||||||
free(oldloc);
|
free(oldloc);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue