mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
PyObject_Repr() ensures that the result is a ready Unicode string
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.
This commit is contained in:
parent
59bb0e077f
commit
db88ae5d66
1 changed files with 8 additions and 0 deletions
|
@ -385,6 +385,10 @@ PyObject_Repr(PyObject *v)
|
||||||
Py_DECREF(res);
|
Py_DECREF(res);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#ifndef Py_DEBUG
|
||||||
|
if (PyUnicode_READY(res) < 0)
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,8 +407,10 @@ 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)) {
|
||||||
|
#ifndef Py_DEBUG
|
||||||
if (PyUnicode_READY(v) < 0)
|
if (PyUnicode_READY(v) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#endif
|
||||||
Py_INCREF(v);
|
Py_INCREF(v);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
@ -426,8 +432,10 @@ PyObject_Str(PyObject *v)
|
||||||
Py_DECREF(res);
|
Py_DECREF(res);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#ifndef Py_DEBUG
|
||||||
if (PyUnicode_READY(res) < 0)
|
if (PyUnicode_READY(res) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#endif
|
||||||
assert(_PyUnicode_CheckConsistency(res, 1));
|
assert(_PyUnicode_CheckConsistency(res, 1));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue