cpython: PyObject_Repr() ensures that the result is a ready Unicode string

http://hg.python.org/cpython/rev/c5d2ce38b0d3 changeset: 73799:c5d2ce38b0d3 user: Victor Stinner <victor.stinner@haypocalc.com> date: Thu Dec 01 02:15:00 2011 +0100 summary: 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. files: Objects/object.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/Objects/object.c b/Objects/object.c --- a/Objects/object.c +++ b/Objects/object.c @@ -385,6 +385,10 @@ Py_DECREF(res); return NULL; } +#ifndef Py_DEBUG + if (PyUnicode_READY(res) < 0) + return NULL; +#endif return res; } @@ -403,8 +407,10 @@ 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 @@ Py_DECREF(res); return NULL; } +#ifndef Py_DEBUG if (PyUnicode_READY(res) < 0) return NULL; +#endif assert(_PyUnicode_CheckConsistency(res, 1)); return res; } -- Repository URL: http://hg.python.org/cpython
participants (1)
-
victor.stinner