@@ -845,13 +845,15 @@ math_gcd(PyObject *module, PyObject * const *args, Py_ssize_t nargs)
845
845
Py_SETREF (res , PyNumber_Absolute (res ));
846
846
return res ;
847
847
}
848
+
849
+ PyObject * one = _PyLong_GetOne (); // borrowed ref
848
850
for (i = 1 ; i < nargs ; i ++ ) {
849
851
x = _PyNumber_Index (args [i ]);
850
852
if (x == NULL ) {
851
853
Py_DECREF (res );
852
854
return NULL ;
853
855
}
854
- if (res == _PyLong_GetOne () ) {
856
+ if (res == one ) {
855
857
/* Fast path: just check arguments.
856
858
It is okay to use identity comparison here. */
857
859
Py_DECREF (x );
@@ -918,13 +920,15 @@ math_lcm(PyObject *module, PyObject * const *args, Py_ssize_t nargs)
918
920
Py_SETREF (res , PyNumber_Absolute (res ));
919
921
return res ;
920
922
}
923
+
924
+ PyObject * zero = _PyLong_GetZero (); // borrowed ref
921
925
for (i = 1 ; i < nargs ; i ++ ) {
922
926
x = PyNumber_Index (args [i ]);
923
927
if (x == NULL ) {
924
928
Py_DECREF (res );
925
929
return NULL ;
926
930
}
927
- if (res == _PyLong_GetZero () ) {
931
+ if (res == zero ) {
928
932
/* Fast path: just check arguments.
929
933
It is okay to use identity comparison here. */
930
934
Py_DECREF (x );
@@ -3293,10 +3297,10 @@ math_perm_impl(PyObject *module, PyObject *n, PyObject *k)
3293
3297
goto done ;
3294
3298
}
3295
3299
3296
- factor = n ;
3297
- Py_INCREF ( factor );
3300
+ factor = Py_NewRef ( n ) ;
3301
+ PyObject * one = _PyLong_GetOne (); // borrowed ref
3298
3302
for (i = 1 ; i < factors ; ++ i ) {
3299
- Py_SETREF (factor , PyNumber_Subtract (factor , _PyLong_GetOne () ));
3303
+ Py_SETREF (factor , PyNumber_Subtract (factor , one ));
3300
3304
if (factor == NULL ) {
3301
3305
goto error ;
3302
3306
}
@@ -3415,10 +3419,10 @@ math_comb_impl(PyObject *module, PyObject *n, PyObject *k)
3415
3419
goto done ;
3416
3420
}
3417
3421
3418
- factor = n ;
3419
- Py_INCREF ( factor );
3422
+ factor = Py_NewRef ( n ) ;
3423
+ PyObject * one = _PyLong_GetOne (); // borrowed ref
3420
3424
for (i = 1 ; i < factors ; ++ i ) {
3421
- Py_SETREF (factor , PyNumber_Subtract (factor , _PyLong_GetOne () ));
3425
+ Py_SETREF (factor , PyNumber_Subtract (factor , one ));
3422
3426
if (factor == NULL ) {
3423
3427
goto error ;
3424
3428
}
0 commit comments