8000 gh-102471: Change PyLongWriter_Discard(NULL) to do nothing (#129339) · python/cpython@7ec1742 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ec1742

Browse files
authored
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.
1 parent 11148e9 commit 7ec1742

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Doc/c-api/long.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,6 @@ The :c:type:`PyLongWriter` API can be used to import an integer.
824824
825825
Discard a :c:type:`PyLongWriter` created by :c:func:`PyLongWriter_Create`.
826826
827-
*writer* must not be ``NULL``.
827+
If *writer* is ``NULL``, no operation is performed.
828828
829829
The writer instance and the *digits* array are invalid after the call.

Objects/longobject.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6953,6 +6953,10 @@ PyLongWriter_Create(int negative, Py_ssize_t ndigits, void **digits)
69536953
void
69546954
PyLongWriter_Discard(PyLongWriter *writer)
69556955
{
6956+
if (writer == NULL) {
6957+
return;
6958+
}
6959+
69566960
PyLongObject *obj = (PyLongObject *)writer;
69576961
assert(Py_REFCNT(obj) == 1);
69586962
Py_DECREF(obj);

0 commit comments

Comments
 (0)
0