]> granicus.if.org Git - python/commitdiff
Change PyUnicode_EncodeUTF7() to return a bytes object.
authorWalter Dörwald <walter@livinglogic.de>
Sat, 5 May 2007 14:43:36 +0000 (14:43 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Sat, 5 May 2007 14:43:36 +0000 (14:43 +0000)
Objects/unicodeobject.c

index aed07ee2b8ec8db8c5f47e2cbca9e1e63d3a9522..af98a90efbd99d1628b241c2a965eaf29638e84e 100644 (file)
@@ -1149,13 +1149,13 @@ PyObject *PyUnicode_EncodeUTF7(const Py_UNICODE *s,
     char * start;
 
     if (size == 0)
-               return PyString_FromStringAndSize(NULL, 0);
+       return PyBytes_FromStringAndSize(NULL, 0);
 
-    v = PyString_FromStringAndSize(NULL, cbAllocated);
+    v = PyBytes_FromStringAndSize(NULL, cbAllocated);
     if (v == NULL)
         return NULL;
 
-    start = out = PyString_AS_STRING(v);
+    start = out = PyBytes_AS_STRING(v);
     for (;i < size; ++i) {
         Py_UNICODE ch = s[i];
 
@@ -1221,7 +1221,10 @@ PyObject *PyUnicode_EncodeUTF7(const Py_UNICODE *s,
         *out++ = '-';
     }
 
-    _PyString_Resize(&v, out - start);
+    if (PyBytes_Resize(v, out - start)) {
+        Py_DECREF(v);
+        return NULL;
+    }
     return v;
 }