Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit db88ae5

Browse files
author
Victor Stinner
committed
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.
1 parent 59bb0e0 commit db88ae5

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

Objects/object.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ PyObject_Repr(PyObject *v)
385385
Py_DECREF(res);
386386
return NULL;
387387
}
388+
#ifndef Py_DEBUG
389+
if (PyUnicode_READY(res) < 0)
390+
return NULL;
391+
#endif
388392
return res;
389393
}
390394

@@ -403,8 +407,10 @@ PyObject_Str(PyObject *v)
403407
if (v == NULL)
404408
return PyUnicode_FromString("<NULL>");
405409
if (PyUnicode_CheckExact(v)) {
410+
#ifndef Py_DEBUG
406411
if (PyUnicode_READY(v) < 0)
407412
return NULL;
413+
#endif
408414
Py_INCREF(v);
409415
return v;
410416
}
@@ -426,8 +432,10 @@ PyObject_Str(PyObject *v)
426432
Py_DECREF(res);
427433
return NULL;
428434
}
435+
#ifndef Py_DEBUG
429436
if (PyUnicode_READY(res) < 0)
430437
return NULL;
438+
#endif
431439
assert(_PyUnicode_CheckConsistency(res, 1));
432440
return res;
433441
}

0 commit comments

Comments
 (0)