return (1);
}
+static mp *implicitmp(PyObject *o)
+{
+ if (!o ||
+ GF_PYCHECK(o) ||
+ ECPT_PYCHECK(o) ||
+ FE_PYCHECK(o) ||
+ GE_PYCHECK(o))
+ return (0);
+ return (tomp(o));
+}
+
+static mp *implicitgf(PyObject *o)
+{
+ if (!o ||
+ MP_PYCHECK(o) ||
+ ECPT_PYCHECK(o) ||
+ FE_PYCHECK(o) ||
+ GE_PYCHECK(o))
+ return (0);
+ return (tomp(o));
+}
+
static int mpbinop(PyObject *x, PyObject *y, mp **xx, mp **yy)
{
- if ((*xx = tomp(x)) == 0)
+ if ((*xx = implicitmp(x)) == 0)
+ return (-1);
+ if ((*yy = implicitmp(y)) == 0) {
+ MP_DROP(*xx);
+ return (-1);
+ }
+ return (0);
+}
+
+static int gfbinop(PyObject *x, PyObject *y, mp **xx, mp **yy)
+{
+ if ((*xx = implicitgf(x)) == 0)
return (-1);
- if ((*yy = tomp(y)) == 0) {
+ if ((*yy = implicitgf(y)) == 0) {
MP_DROP(*xx);
return (-1);
}
#define BINOP(pre, name) \
static PyObject *pre##_py##name(PyObject *x, PyObject *y) { \
mp *xx, *yy, *zz; \
- if (mpbinop(x, y, &xx, &yy)) RETURN_NOTIMPL; \
+ if (pre##binop(x, y, &xx, &yy)) RETURN_NOTIMPL; \
zz = pre##_##name(MP_NEW, xx, yy); \
MP_DROP(xx); MP_DROP(yy); \
return (pre##_pywrap(zz)); \
mp *xx, *yy; \
PyObject *z = 0; \
long n; \
- if (mpbinop(x, y, &xx, &yy)) RETURN_NOTIMPL; \
+ if (pre##binop(x, y, &xx, &yy)) RETURN_NOTIMPL; \
if (mp_tolong_checked(yy, &n)) goto end; \
if (n < 0) \
z = pre##_pywrap(mp_##rname(MP_NEW, xx, -n)); \
mp *xx, *yy; \
PyObject *z = 0; \
INIT_##qq(q) INIT_##rr(r) \
- if (mpbinop(x, y, &xx, &yy)) RETURN_NOTIMPL; \
+ if (pre##binop(x, y, &xx, &yy)) RETURN_NOTIMPL; \
if (MP_ZEROP(yy)) \
ZDIVERR("division by zero"); \
pre##_div(ARG_##qq(q), ARG_##rr(r), xx, yy); \
mp *r = 0;
PyObject *rc = 0;
- if ((xx = tomp(x)) == 0 || (yy = tomp(y)) == 0 ||
+ if ((xx = implicitmp(x)) == 0 || (yy = implicitmp(y)) == 0 ||
(z && z != Py_None && (zz = tomp(z)) == 0)) {
mp_drop(xx); mp_drop(yy); mp_drop(zz);
RETURN_NOTIMPL;
};
static PyObject *meth__MP_fromstring(PyObject *me,
- PyObject *arg, PyObject *kw)
+ PyObject *arg, PyObject *kw)
{
int r = 0;
char *p;
int xl, yl;
int b;
- if (mpbinop(x, y, &xx, &yy)) RETURN_NOTIMPL;
+ if (gfbinop(x, y, &xx, &yy)) RETURN_NOTIMPL;
switch (op) {
case Py_EQ: b = MP_EQ(xx, yy); break;
case Py_NE: b = !MP_EQ(xx, yy); break;