[Python-checkins] cpython: Use PyUnicode_EncodeCodePage() instead of PyUnicode_EncodeMBCS() with

victor.stinner python-checkins at python.org
Sun Nov 20 22:53:18 CET 2011


http://hg.python.org/cpython/rev/8e0f91448d36
changeset:   73630:8e0f91448d36
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Sun Nov 20 18:27:03 2011 +0100
summary:
  Use PyUnicode_EncodeCodePage() instead of PyUnicode_EncodeMBCS() with
PyUnicode_AsUnicodeAndSize()

files:
  Objects/unicodeobject.c |  19 +++----------------
  1 files changed, 3 insertions(+), 16 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -3051,13 +3051,7 @@
 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 @@
                  (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);

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list