summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-10-09 23:32:02 (GMT)
committerGitHub <noreply@github.com>2024-10-09 23:32:02 (GMT)
commit1b2a5485f94ccbe43a45eb9990a5649ae3d2499e (patch)
tree5d040d7b15cbd20640f6b60141be831e52835255
parent9ad55e85d78c5338b1ad170e614345652bd1b651 (diff)
downloadcpython-1b2a5485f94ccbe43a45eb9990a5649ae3d2499e.zip
cpython-1b2a5485f94ccbe43a45eb9990a5649ae3d2499e.tar.gz
cpython-1b2a5485f94ccbe43a45eb9990a5649ae3d2499e.tar.bz2
gh-125196: PyUnicodeWriter_Discard(NULL) does nothing (#125222)
-rw-r--r--Doc/c-api/unicode.rst2
-rw-r--r--Objects/listobject.c4
-rw-r--r--Objects/unicodeobject.c3
3 files changed, 6 insertions, 3 deletions
diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst
index f5704cf..4daf9e9 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 e7090f2..930aefd 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 a9b3324..93c1025 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);
}