diff options
author | Victor Stinner <vstinner@python.org> | 2024-10-07 17:54:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-07 17:54:42 (GMT) |
commit | 03775472cc69e150ced22dc30334a7a202fc0380 (patch) | |
tree | 62bfbd1ba8499b1105794e00dcd0baaa0fdaa6f4 | |
parent | 3287c834e5370294e310450115290979aac06efa (diff) | |
download | cpython-03775472cc69e150ced22dc30334a7a202fc0380.zip cpython-03775472cc69e150ced22dc30334a7a202fc0380.tar.gz cpython-03775472cc69e150ced22dc30334a7a202fc0380.tar.bz2 |
Use _PyLong_GetOne() and _PyLong_GetZero() in long_invmod() (#125044)
These functions cannot fail.
-rw-r--r-- | Objects/longobject.c | 13 |
1 files changed, 2 insertions, 11 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index 6ca8d44..4e94894 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -4828,21 +4828,12 @@ long_divmod(PyObject *a, PyObject *b) static PyLongObject * long_invmod(PyLongObject *a, PyLongObject *n) { - PyLongObject *b, *c; - /* Should only ever be called for positive n */ assert(_PyLong_IsPositive(n)); - b = (PyLongObject *)PyLong_FromLong(1L); - if (b == NULL) { - return NULL; - } - c = (PyLongObject *)PyLong_FromLong(0L); - if (c == NULL) { - Py_DECREF(b); - return NULL; - } Py_INCREF(a); + PyLongObject *b = (PyLongObject *)Py_NewRef(_PyLong_GetOne()); + PyLongObject *c = (PyLongObject *)Py_NewRef(_PyLong_GetZero()); Py_INCREF(n); /* references now owned: a, b, c, n */ |