mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Add _PyUnicodeWriter_WriteASCIIString() function
This commit is contained in:
parent
4d3f109ad3
commit
4a58707a34
4 changed files with 96 additions and 38 deletions
|
@ -339,19 +339,12 @@ list_repr(PyListObject *v)
|
|||
{
|
||||
Py_ssize_t i;
|
||||
PyObject *s;
|
||||
static PyObject *sep = NULL;
|
||||
_PyUnicodeWriter writer;
|
||||
|
||||
if (Py_SIZE(v) == 0) {
|
||||
return PyUnicode_FromString("[]");
|
||||
}
|
||||
|
||||
if (sep == NULL) {
|
||||
sep = PyUnicode_FromString(", ");
|
||||
if (sep == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
i = Py_ReprEnter((PyObject*)v);
|
||||
if (i != 0) {
|
||||
return i > 0 ? PyUnicode_FromString("[...]") : NULL;
|
||||
|
@ -369,7 +362,7 @@ list_repr(PyListObject *v)
|
|||
so must refetch the list size on each iteration. */
|
||||
for (i = 0; i < Py_SIZE(v); ++i) {
|
||||
if (i > 0) {
|
||||
if (_PyUnicodeWriter_WriteStr(&writer, sep) < 0)
|
||||
if (_PyUnicodeWriter_WriteASCIIString(&writer, ", ", 2) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue