Skip to content

Commit 719c9dd

Browse files
authored
gh-119182: Use public PyUnicodeWriter in time_strftime() (#129207)
Replace the private _PyUnicodeWriter API with the public PyUnicodeWriter API.
1 parent 960936f commit 719c9dd

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Modules/timemodule.c

Lines changed: 8 additions & 7 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy