@@ -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,49 @@ nb_truediv(PyObject *self, PyObject *other)
1038999 return res ;
10391000}
10401001
1002+ #define BINOP_INT (suff ) \
1003+ static PyObject * \
1004+ nb_##suff(PyObject *self, PyObject *other) \
1005+ { \
1006+ MPZ_Object *u = NULL, *v = NULL, *res = NULL; \
1007+ \
1008+ CHECK_OP(u, self); \
1009+ CHECK_OP(v, other); \
1010+ \
1011+ res = MPZ_new(0); \
1012+ zz_err ret = ZZ_OK; \
1013+ \
1014+ if (!res || (ret = zz_##suff(&u->z, &v->z, &res->z))) { \
1015+ /* LCOV_EXCL_START */ \
1016+ Py_CLEAR (res ); \
1017+ if (ret == ZZ_VAL ) { \
1018+ PyErr_SetString (PyExc_ValueError , \
1019+ "negative shift count" ); \
1020+ } \
1021+ else if (ret == ZZ_BUF ) { \
1022+ PyErr_SetString (PyExc_OverflowError , \
1023+ "too many digits in integer" ); \
1024+ } \
1025+ else { \
1026+ PyErr_NoMemory (); \
1027+ } \
1028+ /* LCOV_EXCL_STOP */ \
1029+ } \
1030+ end : \
1031+ Py_XDECREF (u ); \
1032+ Py_XDECREF (v ); \
1033+ return (PyObject * )res ; \
1034+ fallback : \
1035+ numbers : \
1036+ Py_XDECREF (u ); \
1037+ Py_XDECREF (v ); \
1038+ Py_RETURN_NOTIMPLEMENTED ; \
1039+ }
1040+
1041+ BINOP_INT (and )
1042+ BINOP_INT (or )
1043+ BINOP_INT (xor )
1044+
10411045static zz_err
10421046zz_lshift (const zz_t * u , const zz_t * v , zz_t * w )
10431047{
@@ -1064,9 +1068,6 @@ zz_rshift(const zz_t *u, const zz_t *v, zz_t *w)
10641068
10651069BINOP_INT (lshift )
10661070BINOP_INT (rshift )
1067- BINOP_INT (and )
1068- BINOP_INT (or )
1069- BINOP_INT (xor )
10701071
10711072#define CHECK_OP_INT (u , a ) \
10721073 if (MPZ_Check(a)) { \
0 commit comments