Add PyUnicode_DecodeLocaleAndSize() and PyUnicode_DecodeLocale()
* PyUnicode_DecodeLocaleAndSize() and PyUnicode_DecodeLocale() decode a string
from the current locale encoding
* _Py_char2wchar() writes an "error code" in the size argument to indicate
if the function failed because of memory allocation failure or because of a
decoding error. The function doesn't write the error message directly to
stderr.
* Fix time.strftime() (if wcsftime() is missing): decode strftime() result
from the current locale encoding, not from the filesystem encoding.
diff --git a/Modules/main.c b/Modules/main.c
index d4c3314..4899378 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -495,16 +495,13 @@
/* Use utf-8 on Mac OS X */
unicode = PyUnicode_FromString(p);
#else
- wchar_t *wchar;
- size_t len;
- wchar = _Py_char2wchar(p, &len);
- if (wchar == NULL)
- continue;
- unicode = PyUnicode_FromWideChar(wchar, len);
- PyMem_Free(wchar);
+ unicode = PyUnicode_DecodeLocale(p, 1);
#endif
- if (unicode == NULL)
+ if (unicode == NULL) {
+ /* ignore errors */
+ PyErr_Clear();
continue;
+ }
PySys_AddWarnOptionUnicode(unicode);
Py_DECREF(unicode);
}