Add a format specifier %R to PyUnicode_FromFormat(), which embeds
the result of a call to PyObject_Repr() into the string. This makes
it possible to simplify many repr implementations.
PyUnicode_FromFormat() uses two steps to create the final string: A first
pass through the format string determines the size of the final string and
a second pass creates the string. To avoid calling PyObject_Repr() twice
for each %R specifier, PyObject_Repr() is called during the size
calculation step and the results are stored in an array (whose size is
determined at the start by counting %R specifiers).
diff --git a/Objects/intobject.c b/Objects/intobject.c
index 6c9745a..ab64f79 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -431,9 +431,7 @@
static PyObject *
int_repr(PyIntObject *v)
{
- char buf[64];
- PyOS_snprintf(buf, sizeof(buf), "%ld", v->ob_ival);
- return PyUnicode_FromString(buf);
+ return PyUnicode_FromFormat("%ld", v->ob_ival);
}
static int