From: Victor Stinner Date: Mon, 27 Jan 2025 10:51:16 +0000 (+0100) Subject: gh-102471: Change PyLongWriter_Discard(NULL) to do nothing (#129339) X-Git-Tag: v3.14.0a5~223 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ec17429d462aee071c067e3b84c8a7e4fcf7263;p=thirdparty%2FPython%2Fcpython.git gh-102471: Change PyLongWriter_Discard(NULL) to do nothing (#129339) It's convenient to be able to call PyLongWriter_Discard(NULL) in error handling code. --- diff --git a/Doc/c-api/long.rst b/Doc/c-api/long.rst index 084ba513493f..25d9e62e3872 100644 --- a/Doc/c-api/long.rst +++ b/Doc/c-api/long.rst @@ -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. diff --git a/Objects/longobject.c b/Objects/longobject.c index 905c4695f60d..43be1ab056e0 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -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);