Skip to content

Commit

Permalink
Use _PyLong_GetOne() and _PyLong_GetZero() in long_invmod() (python#1…
Browse files Browse the repository at this point in the history
…25044)

These functions cannot fail.
  • Loading branch information
vstinner authored Oct 7, 2024
1 parent 3287c83 commit 0377547
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 0377547

Please sign in to comment.