Skip to content

Commit d6a4486

Browse files
authored
Merge pull request #258 from skirpichev/misc
Misc fixes
2 parents 132034c + d1e6b00 commit d6a4486

File tree

2 files changed

+52
-54
lines changed

2 files changed

+52
-54
lines changed

gmp.c

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
10411052
static zz_err
10421053
zz_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

10651076
BINOP_INT(lshift)
10661077
BINOP_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

10831079
static PyObject *
10841080
power(PyObject *self, PyObject *other, PyObject *module)

scripts/dll-importexport.diff

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# https://gmplib.org/list-archives/gmp-devel/2025-August/006311.html
2+
#
13
--- gmp-h.in.orig 2025-08-15 13:37:06.328877394 +0300
24
+++ gmp-h.in 2025-08-15 13:40:01.036262673 +0300
35
@@ -101,8 +101,13 @@

0 commit comments

Comments
 (0)