Skip to content

Commit b569b33

Browse files
committed
pythongh-119182: Use public PyUnicodeWriter in wrap_strftime()
Replace the private _PyUnicodeWriter API with the public PyUnicodeWriter API.
1 parent 298dda5 commit b569b33

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Modules/timemodule.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -913,9 +913,10 @@ time_strftime(PyObject *module, PyObject *args)
913913
PyErr_NoMemory();
914914
return NULL;
915915
}
916-
_PyUnicodeWriter writer;
917-
_PyUnicodeWriter_Init(&writer);
918-
writer.overallocate = 1;
916+
PyUnicodeWriter *writer = PyUnicodeWriter_Create(0);
917+
if (writer == NULL) {
918+
goto error;
919+
}
919920
Py_ssize_t i = 0;
920921
while (i < format_size) {
921922
fmtlen = 0;
@@ -933,7 +934,7 @@ time_strftime(PyObject *module, PyObject *args)
933934
if (unicode == NULL) {
934935
goto error;
935936
}
936-
if (_PyUnicodeWriter_WriteStr(&writer, unicode) < 0) {
937+
if (PyUnicodeWriter_WriteStr(writer, unicode) < 0) {
937938
Py_DECREF(unicode);
938939
goto error;
939940
}
@@ -947,18 +948,18 @@ time_strftime(PyObject *module, PyObject *args)
947948
break;
948949
}
949950
}
950-
if (_PyUnicodeWriter_WriteSubstring(&writer, format_arg, start, i) < 0) {
951+
if (PyUnicodeWriter_WriteSubstring(writer, format_arg, start, i) < 0) {
951952
goto error;
952953
}
953954
}
954955

955956
PyMem_Free(outbuf);
956957
PyMem_Free(format);
957-
return _PyUnicodeWriter_Finish(&writer);
958+
return PyUnicodeWriter_Finish(writer);
958959
error:
959960
PyMem_Free(outbuf);
960961
PyMem_Free(format);
961-
_PyUnicodeWriter_Dealloc(&writer);
962+
PyUnicodeWriter_Discard(writer);
962963
return NULL;
963964
}
964965

0 commit comments

Comments
 (0)