mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
gh-119182: Use public PyUnicodeWriter in time_strftime() (#129207)
Replace the private _PyUnicodeWriter API with the public PyUnicodeWriter API.
This commit is contained in:
parent
960936fe90
commit
719c9dd72f
1 changed files with 8 additions and 7 deletions
|
@ -913,9 +913,10 @@ time_strftime(PyObject *module, PyObject *args)
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
_PyUnicodeWriter writer;
|
PyUnicodeWriter *writer = PyUnicodeWriter_Create(0);
|
||||||
_PyUnicodeWriter_Init(&writer);
|
if (writer == NULL) {
|
||||||
writer.overallocate = 1;
|
goto error;
|
||||||
|
}
|
||||||
Py_ssize_t i = 0;
|
Py_ssize_t i = 0;
|
||||||
while (i < format_size) {
|
while (i < format_size) {
|
||||||
fmtlen = 0;
|
fmtlen = 0;
|
||||||
|
@ -933,7 +934,7 @@ time_strftime(PyObject *module, PyObject *args)
|
||||||
if (unicode == NULL) {
|
if (unicode == NULL) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (_PyUnicodeWriter_WriteStr(&writer, unicode) < 0) {
|
if (PyUnicodeWriter_WriteStr(writer, unicode) < 0) {
|
||||||
Py_DECREF(unicode);
|
Py_DECREF(unicode);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -947,18 +948,18 @@ time_strftime(PyObject *module, PyObject *args)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_PyUnicodeWriter_WriteSubstring(&writer, format_arg, start, i) < 0) {
|
if (PyUnicodeWriter_WriteSubstring(writer, format_arg, start, i) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PyMem_Free(outbuf);
|
PyMem_Free(outbuf);
|
||||||
PyMem_Free(format);
|
PyMem_Free(format);
|
||||||
return _PyUnicodeWriter_Finish(&writer);
|
return PyUnicodeWriter_Finish(writer);
|
||||||
error:
|
error:
|
||||||
PyMem_Free(outbuf);
|
PyMem_Free(outbuf);
|
||||||
PyMem_Free(format);
|
PyMem_Free(format);
|
||||||
_PyUnicodeWriter_Dealloc(&writer);
|
PyUnicodeWriter_Discard(writer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue