Commit 4ead7c7b authored by Victor Stinner's avatar Victor Stinner

PyObject_Str() ensures that the result string is ready

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.
parent 2b979bfa
...@@ -403,6 +403,8 @@ PyObject_Str(PyObject *v) ...@@ -403,6 +403,8 @@ PyObject_Str(PyObject *v)
if (v == NULL) if (v == NULL)
return PyUnicode_FromString("<NULL>"); return PyUnicode_FromString("<NULL>");
if (PyUnicode_CheckExact(v)) { if (PyUnicode_CheckExact(v)) {
if (PyUnicode_READY(v) < 0)
return NULL;
Py_INCREF(v); Py_INCREF(v);
return v; return v;
} }
...@@ -424,6 +426,9 @@ PyObject_Str(PyObject *v) ...@@ -424,6 +426,9 @@ PyObject_Str(PyObject *v)
Py_DECREF(res); Py_DECREF(res);
return NULL; return NULL;
} }
if (PyUnicode_READY(res) < 0)
return NULL;
assert(_PyUnicode_CheckConsistency(res, 1));
return res; return res;
} }
......
...@@ -408,8 +408,6 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content) ...@@ -408,8 +408,6 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
assert(maxchar <= 0x10FFFF); assert(maxchar <= 0x10FFFF);
} }
} }
if (check_content && !unicode_is_singleton(op))
assert(ascii->hash == -1);
return 1; return 1;
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment