]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-102471: Change PyLongWriter_Discard(NULL) to do nothing (#129339)
authorVictor Stinner <vstinner@python.org>
Mon, 27 Jan 2025 10:51:16 +0000 (11:51 +0100)
committerGitHub <noreply@github.com>
Mon, 27 Jan 2025 10:51:16 +0000 (10:51 +0000)
It's convenient to be able to call PyLongWriter_Discard(NULL) in
error handling code.

Doc/c-api/long.rst
Objects/longobject.c

index 084ba513493ffec8524c4b1aeadc4792a42454db..25d9e62e3872797b87d0755fc4e21a4da564f7d6 100644 (file)
@@ -824,6 +824,6 @@ The :c:type:`PyLongWriter` API can be used to import an integer.
 
    Discard a :c:type:`PyLongWriter` created by :c:func:`PyLongWriter_Create`.
 
-   *writer* must not be ``NULL``.
+   If *writer* is ``NULL``, no operation is performed.
 
    The writer instance and the *digits* array are invalid after the call.
index 905c4695f60d4f3980440d7ead9836d1a8899458..43be1ab056e0fe98b6f5efed55225bf03d327d73 100644 (file)
@@ -6953,6 +6953,10 @@ error:
 void
 PyLongWriter_Discard(PyLongWriter *writer)
 {
+    if (writer == NULL) {
+        return;
+    }
+
     PyLongObject *obj = (PyLongObject *)writer;
     assert(Py_REFCNT(obj) == 1);
     Py_DECREF(obj);