]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-125196: PyUnicodeWriter_Discard(NULL) does nothing (#125222)
authorVictor Stinner <vstinner@python.org>
Wed, 9 Oct 2024 23:32:02 +0000 (01:32 +0200)
committerGitHub <noreply@github.com>
Wed, 9 Oct 2024 23:32:02 +0000 (23:32 +0000)
Doc/c-api/unicode.rst
Objects/listobject.c
Objects/unicodeobject.c

index f5704cffa199a583389187e9bced0cd2acd53e22..4daf9e9fdbf2f106f7992130cfead342aa04a807 100644 (file)
@@ -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*.
index e7090f20001a39fe5b58d09f9f95f90e7f47d028..930aefde325a7c57a9478d39da2d7beb7f5ca791 100644 (file)
@@ -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;
 }
index a9b332481638800d4afe00e056b8804450d03896..93c1025b6a3cae0c120453a366e191e5732cd142 100644 (file)
@@ -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);
 }