8000 Use _PyLong_GetOne() and _PyLong_GetZero() in long_invmod() (#125044) · python/cpython@0377547 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0377547

Browse files
authored
Use _PyLong_GetOne() and _PyLong_GetZero() in long_invmod() (#125044)
These functions cannot fail.
1 parent 3287c83 commit 0377547

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

Objects/longobject.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4828,21 +4828,12 @@ long_divmod(PyObject *a, PyObject *b)
48284828
static PyLongObject *
48294829
long_invmod(PyLongObject *a, PyLongObject *n)
48304830
{
4831-
PyLongObject *b, *c;
4832-
48334831
/* Should only ever be called for positive n */
48344832
assert(_PyLong_IsPositive(n));
48354833

4836-
b = (PyLongObject *)PyLong_FromLong(1L);
4837-
if (b == NULL) {
4838-
return NULL;
4839-
}
4840-
c = (PyLongObject *)PyLong_FromLong(0L);
4841-
if (c == NULL) {
4842-
Py_DECREF(b);
4843-
return NULL;
4844-
}
48454834
Py_INCREF(a);
4835+
PyLongObject *b = (PyLongObject *)Py_NewRef(_PyLong_GetOne());
4836+
PyLongObject *c = (PyLongObject *)Py_NewRef(_PyLong_GetZero());
48464837
Py_INCREF(n);
48474838

48484839
/* references now owned: a, b, c, n */

0 commit comments

Comments
 (0)
0