@@ -729,22 +729,21 @@ str(PyObject *self)
729729
730730#define Number_Check (op ) (PyFloat_Check((op)) || PyComplex_Check((op)))
731731
732- #define CHECK_OP (u , a ) \
733- if (MPZ_Check(a)) { \
734- u = (MPZ_Object *)a; \
735- Py_INCREF(a); \
736- } \
737- else if (PyLong_Check(a)) { \
738- u = MPZ_from_int(a); \
739- if (!u) { \
740- goto end; \
741- } \
742- } \
743- else if (Number_Check(a)) { \
744- goto numbers; \
745- } \
746- else { \
747- goto fallback; \
732+ #define CHECK_OP (u , a ) \
733+ if (MPZ_Check(a)) { \
734+ u = (MPZ_Object *)Py_NewRef(a); \
735+ } \
736+ else if (PyLong_Check(a)) { \
737+ u = MPZ_from_int(a); \
738+ if (!u) { \
739+ goto end; \
740+ } \
741+ } \
742+ else if (Number_Check(a)) { \
743+ goto numbers; \
744+ } \
745+ else { \
746+ goto fallback; \
748747 }
749748
750749PyObject *
@@ -916,19 +915,18 @@ to_bool(PyObject *self)
916915 return !zz_iszero (& ((MPZ_Object * )self )-> z );
917916}
918917
919- #define CHECK_OPv2 (u , a ) \
920- if (MPZ_Check(a)) { \
921- u = (MPZ_Object *)a; \
922- Py_INCREF(a); \
923- } \
924- else if (PyLong_Check(a)) { \
925- ; \
926- } \
927- else if (Number_Check(a)) { \
928- goto numbers; \
929- } \
930- else { \
931- goto fallback; \
918+ #define CHECK_OPv2 (u , a ) \
919+ if (MPZ_Check(a)) { \
920+ u = (MPZ_Object *)Py_NewRef(a); \
921+ } \
922+ else if (PyLong_Check(a)) { \
923+ ; \
924+ } \
925+ else if (Number_Check(a)) { \
926+ goto numbers; \
927+ } \
928+ else { \
929+ goto fallback; \
932930 }
933931
934932#define BINOP (suff , slot ) \
@@ -1004,8 +1002,7 @@ done: \
10041002 PyObject *uf, *vf, *rf; \
10051003 \
10061004 if (Number_Check(self)) { \
1007- uf = self; \
1008- Py_INCREF(uf); \
1005+ uf = Py_NewRef(self); \
10091006 } \
10101007 else { \
10111008 uf = to_float(self); \
@@ -1014,8 +1011,7 @@ done: \
10141011 } \
10151012 } \
10161013 if (Number_Check(other)) { \
1017- vf = other; \
1018- Py_INCREF(vf); \
1014+ vf = Py_NewRef(other); \
10191015 } \
10201016 else { \
10211017 vf = to_float(other); \
@@ -1309,8 +1305,7 @@ nb_truediv(PyObject *self, PyObject *other)
13091305 PyObject * uf , * vf ;
13101306
13111307 if (Number_Check (self )) {
1312- uf = self ;
1313- Py_INCREF (uf );
1308+ uf = Py_NewRef (self );
13141309 }
13151310 else {
13161311 uf = to_float (self );
@@ -1319,8 +1314,7 @@ nb_truediv(PyObject *self, PyObject *other)
13191314 }
13201315 }
13211316 if (Number_Check (other )) {
1322- vf = other ;
1323- Py_INCREF (vf );
1317+ vf = Py_NewRef (other );
13241318 }
13251319 else {
13261320 vf = to_float (other );
@@ -1337,17 +1331,16 @@ nb_truediv(PyObject *self, PyObject *other)
13371331 return res ;
13381332}
13391333
1340- #define CHECK_OP_INT (u , a ) \
1341- if (MPZ_Check(a)) { \
1342- u = (MPZ_Object *)a; \
1343- Py_INCREF(a); \
1344- } \
1345- else { \
1346- u = MPZ_from_int(a); \
1347- if (!u) { \
1348- goto end; \
1349- } \
1350- } \
1334+ #define CHECK_OP_INT (u , a ) \
1335+ if (MPZ_Check(a)) { \
1336+ u = (MPZ_Object *)Py_NewRef(a); \
1337+ } \
1338+ else { \
1339+ u = MPZ_from_int(a); \
1340+ if (!u) { \
1341+ goto end; \
1342+ } \
1343+ } \
13511344
13521345#define BINOP_INT (suff ) \
13531346 static PyObject * \
@@ -1527,8 +1520,7 @@ power(PyObject *self, PyObject *other, PyObject *module)
15271520 PyObject * uf , * vf ;
15281521
15291522 if (Number_Check (self )) {
1530- uf = self ;
1531- Py_INCREF (uf );
1523+ uf = Py_NewRef (self );
15321524 }
15331525 else {
15341526 uf = to_float (self );
@@ -1537,8 +1529,7 @@ power(PyObject *self, PyObject *other, PyObject *module)
15371529 }
15381530 }
15391531 if (Number_Check (other )) {
1540- vf = other ;
1541- Py_INCREF (vf );
1532+ vf = Py_NewRef (other );
15421533 }
15431534 else {
15441535 vf = to_float (other );
0 commit comments