Skip to content

Commit d61d996

Browse files
committed
Use CHECK_OP_INT in BINOP_INT
1 parent 7cff150 commit d61d996

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

gmp.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -999,14 +999,26 @@ nb_truediv(PyObject *self, PyObject *other)
999999
return res;
10001000
}
10011001

1002+
#define CHECK_OP_INT(u, a) \
1003+
if (MPZ_Check(a)) { \
1004+
u = (MPZ_Object *)a; \
1005+
Py_INCREF(u); \
1006+
} \
1007+
else { \
1008+
u = MPZ_from_int(a); \
1009+
if (!u) { \
1010+
goto end; \
1011+
} \
1012+
} \
1013+
10021014
#define BINOP_INT(suff) \
10031015
static PyObject * \
10041016
nb_##suff(PyObject *self, PyObject *other) \
10051017
{ \
10061018
MPZ_Object *u = NULL, *v = NULL, *res = NULL; \
10071019
\
1008-
CHECK_OP(u, self); \
1009-
CHECK_OP(v, other); \
1020+
CHECK_OP_INT(u, self); \
1021+
CHECK_OP_INT(v, other); \
10101022
\
10111023
res = MPZ_new(0); \
10121024
zz_err ret = ZZ_OK; \
@@ -1031,11 +1043,6 @@ nb_truediv(PyObject *self, PyObject *other)
10311043
Py_XDECREF(u); \
10321044
Py_XDECREF(v); \
10331045
return (PyObject *)res; \
1034-
fallback: \
1035-
numbers: \
1036-
Py_XDECREF(u); \
1037-
Py_XDECREF(v); \
1038-
Py_RETURN_NOTIMPLEMENTED; \
10391046
}
10401047

10411048
BINOP_INT(and)
@@ -1069,18 +1076,6 @@ zz_rshift(const zz_t *u, const zz_t *v, zz_t *w)
10691076
BINOP_INT(lshift)
10701077
BINOP_INT(rshift)
10711078

1072-
#define CHECK_OP_INT(u, a) \
1073-
if (MPZ_Check(a)) { \
1074-
u = (MPZ_Object *)a; \
1075-
Py_INCREF(u); \
1076-
} \
1077-
else { \
1078-
u = MPZ_from_int(a); \
1079-
if (!u) { \
1080-
goto end; \
1081-
} \
1082-
} \
1083-
10841079
static PyObject *
10851080
power(PyObject *self, PyObject *other, PyObject *module)
10861081
{

0 commit comments

Comments
 (0)