diff Objects/stringobject.c @ 32552:3706a3704aea legacy-trunk

.encode()/.decode() patch part 2.
author Marc-André Lemburg <mal@egenix.com>
date Thu, 08 Jul 2004 19:13:55 +0000
parents f46d49e2e0f0
children 5218bff56449
line wrap: on
line diff
--- a/Objects/stringobject.c	Thu Jul 08 17:57:32 2004 +0000
+++ b/Objects/stringobject.c	Thu Jul 08 19:13:55 2004 +0000
@@ -2678,6 +2678,8 @@
     if (!PyArg_ParseTuple(args, "|ss:encode", &encoding, &errors))
         return NULL;
     v = PyString_AsEncodedObject((PyObject *)self, encoding, errors);
+    if (v == NULL)
+        goto onError;
     if (!PyString_Check(v) && !PyUnicode_Check(v)) {
         PyErr_Format(PyExc_TypeError,
                      "encoder did not return a string/unicode object "
@@ -2687,6 +2689,9 @@
         return NULL;
     }
     return v;
+
+ onError:
+    return NULL;
 }
 
 
@@ -2710,6 +2715,8 @@
     if (!PyArg_ParseTuple(args, "|ss:decode", &encoding, &errors))
         return NULL;
     v = PyString_AsDecodedObject((PyObject *)self, encoding, errors);
+    if (v == NULL)
+        goto onError;
     if (!PyString_Check(v) && !PyUnicode_Check(v)) {
         PyErr_Format(PyExc_TypeError,
                      "decoder did not return a string/unicode object "
@@ -2719,6 +2726,9 @@
         return NULL;
     }
     return v;
+
+ onError:
+    return NULL;
 }