Use _PyLong_GetOne() and _PyLong_GetZero() in long_invmod() (#125044)

These functions cannot fail.
This commit is contained in:
Victor Stinner 2024-10-07 19:54:42 +02:00 committed by GitHub
parent 3287c834e5
commit 03775472cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 11 deletions

View File

@ -4828,21 +4828,12 @@ long_divmod(PyObject *a, PyObject *b)
static PyLongObject * static PyLongObject *
long_invmod(PyLongObject *a, PyLongObject *n) long_invmod(PyLongObject *a, PyLongObject *n)
{ {
PyLongObject *b, *c;
/* Should only ever be called for positive n */ /* Should only ever be called for positive n */
assert(_PyLong_IsPositive(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); Py_INCREF(a);
PyLongObject *b = (PyLongObject *)Py_NewRef(_PyLong_GetOne());
PyLongObject *c = (PyLongObject *)Py_NewRef(_PyLong_GetZero());
Py_INCREF(n); Py_INCREF(n);
/* references now owned: a, b, c, n */ /* references now owned: a, b, c, n */