summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-09-10 23:13:52 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-09-10 23:13:52 (GMT)
commitc2d76fd339f5fcc4f0051696e5e57c979289a9c3 (patch)
tree56a6fb0231f07711dcf0970eddf54dba5b1c5334
parentd2be5b4fe4cbca197d27e853a08e6339945c879a (diff)
downloadcpython-c2d76fd339f5fcc4f0051696e5e57c979289a9c3.zip
cpython-c2d76fd339f5fcc4f0051696e5e57c979289a9c3.tar.gz
cpython-c2d76fd339f5fcc4f0051696e5e57c979289a9c3.tar.bz2
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.
-rw-r--r--Modules/main.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/Modules/main.c b/Modules/main.c
index dc8d84c..71fb6fa 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -488,7 +488,8 @@ Py_Main(int argc, wchar_t **argv)
#else
if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') {
char *buf, *oldloc;
- PyObject *warning;
+ wchar_t *wchar;
+ PyObject *unicode;
/* settle for strtok here as there's no one standard
C89 wcstok */
@@ -500,11 +501,15 @@ Py_Main(int argc, wchar_t **argv)
oldloc = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "");
for (p = strtok(buf, ","); p != NULL; p = strtok(NULL, ",")) {
- warning = PyUnicode_DecodeFSDefault(p);
- if (warning != NULL) {
- PySys_AddWarnOptionUnicode(warning);
- Py_DECREF(warning);
- }
+ wchar = _Py_char2wchar(p);
+ if (wchar == NULL)
+ continue;
+ unicode = PyUnicode_FromWideChar(wchar, wcslen(wchar));
+ PyMem_Free(wchar);
+ if (unicode == NULL)
+ continue;
+ PySys_AddWarnOptionUnicode(unicode);
+ Py_DECREF(unicode);
}
setlocale(LC_ALL, oldloc);
free(oldloc);