@@ -783,45 +783,6 @@ to_bool(PyObject *self)
783783 return !zz_iszero (& ((MPZ_Object * )self )-> z );
784784}
785785
786- #define BINOP_INT (suff ) \
787- static PyObject * \
788- nb_##suff(PyObject *self, PyObject *other) \
789- { \
790- MPZ_Object *u = NULL, *v = NULL, *res = NULL; \
791- \
792- CHECK_OP(u, self); \
793- CHECK_OP(v, other); \
794- \
795- res = MPZ_new(0); \
796- zz_err ret = ZZ_OK; \
797- \
798- if (!res || (ret = zz_##suff(&u->z, &v->z, &res->z))) { \
799- /* LCOV_EXCL_START */ \
800- Py_CLEAR (res ); \
801- if (ret == ZZ_VAL ) { \
802- PyErr_SetString (PyExc_ValueError , \
803- "negative shift count" ); \
804- } \
805- else if (ret == ZZ_BUF ) { \
806- PyErr_SetString (PyExc_OverflowError , \
807- "too many digits in integer" ); \
808- } \
809- else { \
810- PyErr_NoMemory (); \
811- } \
812- /* LCOV_EXCL_STOP */ \
813- } \
814- end : \
815- Py_XDECREF (u ); \
816- Py_XDECREF (v ); \
817- return (PyObject * )res ; \
818- fallback : \
819- numbers : \
820- Py_XDECREF (u ); \
821- Py_XDECREF (v ); \
822- Py_RETURN_NOTIMPLEMENTED ; \
823- }
824-
825786#define BINOP (suff , slot ) \
826787 static PyObject * \
827788 nb_##suff(PyObject *self, PyObject *other) \
@@ -1038,6 +999,56 @@ nb_truediv(PyObject *self, PyObject *other)
1038999 return res ;
10391000}
10401001
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+
1014+ #define BINOP_INT (suff ) \
1015+ static PyObject * \
1016+ nb_##suff(PyObject *self, PyObject *other) \
1017+ { \
1018+ MPZ_Object *u = NULL, *v = NULL, *res = NULL; \
1019+ \
1020+ CHECK_OP_INT(u, self); \
1021+ CHECK_OP_INT(v, other); \
1022+ \
1023+ res = MPZ_new(0); \
1024+ zz_err ret = ZZ_OK; \
1025+ \
1026+ if (!res || (ret = zz_##suff(&u->z, &v->z, &res->z))) { \
1027+ /* LCOV_EXCL_START */ \
1028+ Py_CLEAR (res ); \
1029+ if (ret == ZZ_VAL ) { \
1030+ PyErr_SetString (PyExc_ValueError , \
1031+ "negative shift count" ); \
1032+ } \
1033+ else if (ret == ZZ_BUF ) { \
1034+ PyErr_SetString (PyExc_OverflowError , \
1035+ "too many digits in integer" ); \
1036+ } \
1037+ else { \
1038+ PyErr_NoMemory (); \
1039+ } \
1040+ /* LCOV_EXCL_STOP */ \
1041+ } \
1042+ end : \
1043+ Py_XDECREF (u ); \
1044+ Py_XDECREF (v ); \
1045+ return (PyObject * )res ; \
1046+ }
1047+
1048+ BINOP_INT (and )
1049+ BINOP_INT (or )
1050+ BINOP_INT (xor )
1051+
10411052static zz_err
10421053zz_lshift (const zz_t * u , const zz_t * v , zz_t * w )
10431054{
@@ -1064,21 +1075,6 @@ zz_rshift(const zz_t *u, const zz_t *v, zz_t *w)
10641075
10651076BINOP_INT (lshift )
10661077BINOP_INT (rshift )
1067- BINOP_INT (and )
1068- BINOP_INT (or )
1069- BINOP_INT (xor )
1070-
1071- #define CHECK_OP_INT (u , a ) \
1072- if (MPZ_Check (a )) { \
1073- u = (MPZ_Object * )a ; \
1074- Py_INCREF (u ); \
1075- } \
1076- else { \
1077- u = MPZ_from_int (a ); \
1078- if (!u ) { \
1079- goto end ; \
1080- } \
1081- } \
10821078
10831079static PyObject *
10841080power (PyObject * self , PyObject * other , PyObject * module )
0 commit comments