X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/a70a5a8079d70084c6c630071f22585228b2107f..7032ee7c4d3ed206be5b972a9274dab27bbd2936:/mp.c diff --git a/mp.c b/mp.c index 163e690..ce04819 100644 --- a/mp.c +++ b/mp.c @@ -289,24 +289,27 @@ int convgf(PyObject *o, void *p) mp *implicitmp(PyObject *o) { - if (!o || - GF_PYCHECK(o) || - ECPT_PYCHECK(o) || - FE_PYCHECK(o) || - GE_PYCHECK(o)) - return (0); - return (tomp(o)); + PyObject *l; + + if (!o || GF_PYCHECK(o) || FE_PYCHECK(o)) return (0); + else if (MP_PYCHECK(o)) return (MP_COPY(MP_X(o))); + else if (PFILT_PYCHECK(o)) return (MP_COPY(PFILT_F(o)->m)); +#ifdef PY2 + else if (PyInt_Check(o)) return (mp_fromlong(MP_NEW, PyInt_AS_LONG(o))); +#endif + else if ((l = PyNumber_Index(o)) != 0) { +#ifdef PY2 + if (PyInt_Check(o)) return (mp_fromlong(MP_NEW, PyInt_AS_LONG(o))); +#endif + if (PyLong_Check(o)) return (mp_frompylong(o)); + } + PyErr_Clear(); return (0); } mp *implicitgf(PyObject *o) { - if (!o || - MP_PYCHECK(o) || - ECPT_PYCHECK(o) || - FE_PYCHECK(o) || - GE_PYCHECK(o)) - return (0); - return (tomp(o)); + if (GF_PYCHECK(o)) return (MP_COPY(MP_X(o))); + return (0); } static int mpbinop(PyObject *x, PyObject *y, mp **xx, mp **yy)