From 7ec17429d462aee071c067e3b84c8a7e4fcf7263 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 27 Jan 2025 11:51:16 +0100 Subject: 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. --- Doc/c-api/long.rst | 2 +- Objects/longobject.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Doc/c-api/long.rst b/Doc/c-api/long.rst index 084ba51..25d9e62 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 905c469..43be1ab 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); -- cgit v0.12