https://github.com/python/cpython/commit/7ec17429d462aee071c067e3b84c8a7e4fcf7263
commit: 7ec17429d462aee071c067e3b84c8a7e4fcf7263
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2025-01-27T10:51:16Z
summary:
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.
files:
M Doc/c-api/long.rst
M Objects/longobject.c
diff --git a/Doc/c-api/long.rst b/Doc/c-api/long.rst
index 084ba513493ffe..25d9e62e387279 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 905c4695f60d4f..43be1ab056e0fe 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -6953,6 +6953,10 @@ PyLongWriter_Create(int negative, Py_ssize_t ndigits,
void **digits)
void
PyLongWriter_Discard(PyLongWriter *writer)
{
+ if (writer == NULL) {
+ return;
+ }
+
PyLongObject *obj = (PyLongObject *)writer;
assert(Py_REFCNT(obj) == 1);
Py_DECREF(obj);
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]