]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Use _PyLong_GetOne() and _PyLong_GetZero() in long_invmod() (#125044)
authorVictor Stinner <vstinner@python.org>
Mon, 7 Oct 2024 17:54:42 +0000 (19:54 +0200)
committerGitHub <noreply@github.com>
Mon, 7 Oct 2024 17:54:42 +0000 (19:54 +0200)
These functions cannot fail.

Objects/longobject.c

index 6ca8d449bcf4a26605f645ef463b11cdf8d0ae5c..4e94894048573097c53ead5d1411c3aa0f578b28 100644 (file)
@@ -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 */