https://github.com/python/cpython/commit/1b2a5485f94ccbe43a45eb9990a5649ae3d2499e
commit: 1b2a5485f94ccbe43a45eb9990a5649ae3d2499e
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2024-10-09T23:32:02Z
summary:
gh-125196: PyUnicodeWriter_Discard(NULL) does nothing (#125222)
files:
M Doc/c-api/unicode.rst
M Objects/listobject.c
M Objects/unicodeobject.c
diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst
index f5704cffa199a5..4daf9e9fdbf2f1 100644
--- a/Doc/c-api/unicode.rst
+++ b/Doc/c-api/unicode.rst
@@ -1600,6 +1600,8 @@ object.
Discard the internal Unicode buffer and destroy the writer instance.
+ If *writer* is ``NULL``, no operation is performed.
+
.. c:function:: int PyUnicodeWriter_WriteChar(PyUnicodeWriter *writer, Py_UCS4
ch)
Write the single Unicode character *ch* into *writer*.
diff --git a/Objects/listobject.c b/Objects/listobject.c
index e7090f20001a39..930aefde325a7c 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -563,9 +563,7 @@ list_repr_impl(PyListObject *v)
return PyUnicodeWriter_Finish(writer);
error:
- if (writer != NULL) {
- PyUnicodeWriter_Discard(writer);
- }
+ PyUnicodeWriter_Discard(writer);
Py_ReprLeave((PyObject *)v);
return NULL;
}
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index a9b33248163880..93c1025b6a3cae 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -13455,6 +13455,9 @@ PyUnicodeWriter_Create(Py_ssize_t length)
void PyUnicodeWriter_Discard(PyUnicodeWriter *writer)
{
+ if (writer == NULL) {
+ return;
+ }
_PyUnicodeWriter_Dealloc((_PyUnicodeWriter*)writer);
PyMem_Free(writer);
}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]