diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-12-17 04:45:09 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-12-17 04:45:09 +0100 |
commit | 1f33f2b0c381337d5991c227652d65eadd168209 (patch) | |
tree | 4f2303936f90a15a9d7a132a3d5f57c238eba38d /Objects/unicodeobject.c | |
parent | f2ea71fcc8986101512265b685d8d3dfdf7b7bdb (diff) | |
download | cpython-git-1f33f2b0c381337d5991c227652d65eadd168209.tar.gz |
Issue #13560: os.strerror() now uses the current locale encoding instead of UTF-8
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r-- | Objects/unicodeobject.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index a2c3227df0..2fea30b37f 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3132,6 +3132,7 @@ PyUnicode_EncodeLocale(PyObject *unicode, int surrogateescape) wchar_t *wstr; PyObject *bytes = NULL; char *errmsg; + PyObject *reason; PyObject *exc; size_t error_pos; @@ -3193,17 +3194,28 @@ PyUnicode_EncodeLocale(PyObject *unicode, int surrogateescape) encode_error: errmsg = strerror(errno); assert(errmsg != NULL); - if (errmsg == NULL) - errmsg = "wcstombs() encountered an unencodable wide character"; PyMem_Free(wstr); Py_XDECREF(bytes); - exc = NULL; - raise_encode_exception(&exc, - "locale", unicode, - error_pos, error_pos+1, - errmsg); - Py_XDECREF(exc); + if (errmsg != NULL) + reason = PyUnicode_DecodeLocale(errmsg, 1); + else + reason = PyUnicode_FromString( + "wcstombs() encountered an unencodable " + "wide character"); + if (reason == NULL) + return NULL; + + exc = PyObject_CallFunction(PyExc_UnicodeEncodeError, "sOnnO", + "locale", unicode, + (Py_ssize_t)error_pos, + (Py_ssize_t)(error_pos+1), + reason); + Py_DECREF(reason); + if (exc != NULL) { + PyCodec_StrictErrors(exc); + Py_XDECREF(exc); + } return NULL; } |