PyObject_Str() ensures that the result string is ready
authorVictor Stinner <victor.stinner@haypocalc.com>
Sun, 20 Nov 2011 18:48:36 +0000 (19:48 +0100)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sun, 20 Nov 2011 18:48:36 +0000 (19:48 +0100)
and check the string consistency.

_PyUnicode_CheckConsistency() doesn't check the hash anymore. It should be
possible to call this function even if hash(str) was already called.

Objects/object.c
Objects/unicodeobject.c

index 51188b7862b7ea62dfa4918d9e46304f56bb839f..25e64e1e74a4d4574b942daa561bec1977c88669 100644 (file)
@@ -403,6 +403,8 @@ PyObject_Str(PyObject *v)
     if (v == NULL)
         return PyUnicode_FromString("<NULL>");
     if (PyUnicode_CheckExact(v)) {
+        if (PyUnicode_READY(v) < 0)
+            return NULL;
         Py_INCREF(v);
         return v;
     }
@@ -424,6 +426,9 @@ PyObject_Str(PyObject *v)
         Py_DECREF(res);
         return NULL;
     }
+    if (PyUnicode_READY(res) < 0)
+        return NULL;
+    assert(_PyUnicode_CheckConsistency(res, 1));
     return res;
 }
 
index 7aa5ff0e1a32f3511f5c41813096cffd8db52c41..1e44357c2fb0f71d38f39f77c2220e56b0211d93 100644 (file)
@@ -408,8 +408,6 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
             assert(maxchar <= 0x10FFFF);
         }
     }
-    if (check_content && !unicode_is_singleton(op))
-        assert(ascii->hash == -1);
     return 1;
 }
 #endif