]> granicus.if.org Git - python/commitdiff
PyObject_Repr() ensures that the result is a ready Unicode string
authorVictor Stinner <victor.stinner@haypocalc.com>
Thu, 1 Dec 2011 01:15:00 +0000 (02:15 +0100)
committerVictor Stinner <victor.stinner@haypocalc.com>
Thu, 1 Dec 2011 01:15:00 +0000 (02:15 +0100)
And PyObject_Str() and PyObject_Repr() don't make strings ready in debug
mode to ensure that the caller makes the string ready before using it.

Objects/object.c

index 00f171633d4c788947a37bb31aeb042cf10c4729..eea55318ebcc379f75dea08d509486e9557ab40d 100644 (file)
@@ -385,6 +385,10 @@ PyObject_Repr(PyObject *v)
         Py_DECREF(res);
         return NULL;
     }
+#ifndef Py_DEBUG
+    if (PyUnicode_READY(res) < 0)
+        return NULL;
+#endif
     return res;
 }
 
@@ -403,8 +407,10 @@ PyObject_Str(PyObject *v)
     if (v == NULL)
         return PyUnicode_FromString("<NULL>");
     if (PyUnicode_CheckExact(v)) {
+#ifndef Py_DEBUG
         if (PyUnicode_READY(v) < 0)
             return NULL;
+#endif
         Py_INCREF(v);
         return v;
     }
@@ -426,8 +432,10 @@ PyObject_Str(PyObject *v)
         Py_DECREF(res);
         return NULL;
     }
+#ifndef Py_DEBUG
     if (PyUnicode_READY(res) < 0)
         return NULL;
+#endif
     assert(_PyUnicode_CheckConsistency(res, 1));
     return res;
 }