From: Victor Stinner Date: Sun, 20 Nov 2011 17:27:03 +0000 (+0100) Subject: Use PyUnicode_EncodeCodePage() instead of PyUnicode_EncodeMBCS() with X-Git-Tag: v3.3.0a1~802 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ac931b1e5bf86bb3ad3e2abee2cfd740df8f13bf;p=python Use PyUnicode_EncodeCodePage() instead of PyUnicode_EncodeMBCS() with PyUnicode_AsUnicodeAndSize() --- diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index b0b9528be5..90a4fcb62f 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3051,13 +3051,7 @@ PyObject * PyUnicode_EncodeFSDefault(PyObject *unicode) { #ifdef HAVE_MBCS - const Py_UNICODE *wstr; - Py_ssize_t wlen; - - wstr = PyUnicode_AsUnicodeAndSize(unicode, &wlen); - if (wstr == NULL) - return NULL; - return PyUnicode_EncodeMBCS(wstr, wlen, NULL); + return PyUnicode_EncodeCodePage(CP_ACP, unicode, NULL); #elif defined(__APPLE__) return _PyUnicode_AsUTF8String(unicode, "surrogateescape"); #else @@ -3141,15 +3135,8 @@ PyUnicode_AsEncodedString(PyObject *unicode, (strcmp(lower, "iso-8859-1") == 0)) return _PyUnicode_AsLatin1String(unicode, errors); #ifdef HAVE_MBCS - else if (strcmp(lower, "mbcs") == 0) { - const Py_UNICODE *wstr; - Py_ssize_t wlen; - - wstr = PyUnicode_AsUnicodeAndSize(unicode, &wlen); - if (wstr == NULL) - return NULL; - return PyUnicode_EncodeMBCS(wstr, wlen, errors); - } + else if (strcmp(lower, "mbcs") == 0) + return PyUnicode_EncodeCodePage(CP_ACP, unicode, errors); #endif else if (strcmp(lower, "ascii") == 0) return _PyUnicode_AsASCIIString(unicode, errors);