X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/c263b05cca879ab1bdca5823df0413604d39d4c6..2a448f86048c26a24288d310b3bb70e8ae7e7528:/mp.c?ds=sidebyside diff --git a/mp.c b/mp.c index fbafcee..1513974 100644 --- a/mp.c +++ b/mp.c @@ -45,12 +45,12 @@ mp *mp_frompylong(PyObject *obj) mp *x; mpw *p; - sz = l->ob_size; + sz = Py_SIZE(l); if (sz < 0) sz = -sz; assert(MPW_BITS >= SHIFT); bits = (unsigned long)sz * SHIFT; w = (bits + MPW_BITS - 1)/MPW_BITS; - x = mp_new(w, l->ob_size < 0 ? MP_NEG : 0); + x = mp_new(w, Py_SIZE(l) < 0 ? MP_NEG : 0); p = x->v; for (i = 0; i < sz; i++) { r |= (mpd)l->ob_digit[i] << b; @@ -94,7 +94,7 @@ PyObject *mp_topylong(mp *x) l->ob_digit[i++] = r & MASK; r >>= SHIFT; } - l->ob_size = (x->f & MP_NEG) ? -sz : sz; + Py_SIZE(l) = (x->f & MP_NEG) ? -sz : sz; return ((PyObject *)l); } @@ -238,7 +238,7 @@ mp *getmp(PyObject *o) if (!o) return (0); if ((x = tomp(o)) == 0) { PyErr_Format(PyExc_TypeError, "can't convert %.100s to mp", - o->ob_type->tp_name); + Py_TYPE(o)->tp_name); } return (x); } @@ -257,7 +257,7 @@ mp *getgf(PyObject *o) if (!o) return (0); if ((x = tomp(o)) == 0) { PyErr_Format(PyExc_TypeError, "can't convert %.100s to gf", - o->ob_type->tp_name); + Py_TYPE(o)->tp_name); } return (x); } @@ -536,7 +536,7 @@ static PyObject *mp_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) if (!good_radix_p(radix, 1)) VALERR("bad radix"); if ((z = mp_frompyobject(x, radix)) == 0) { PyErr_Format(PyExc_TypeError, "can't convert %.100s to mp", - x->ob_type->tp_name); + Py_TYPE(x)->tp_name); goto end; } zz = (mp_pyobj *)ty->tp_alloc(ty, 0); @@ -1907,7 +1907,7 @@ static PyObject *gf_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) if (!good_radix_p(radix, 1)) VALERR("radix out of range"); if ((z = mp_frompyobject(x, radix)) == 0) { PyErr_Format(PyExc_TypeError, "can't convert %.100s to gf", - x->ob_type->tp_name); + Py_TYPE(x)->tp_name); goto end; } if (MP_NEGP(z)) { @@ -2504,6 +2504,11 @@ static const PyTypeObject gfn_pytype_skel = { /*----- Glue --------------------------------------------------------------*/ +static const struct nameval consts[] = { + CONST(MPW_MAX), + { 0 } +}; + void mp_pyinit(void) { INITTYPE(mp, root); @@ -2528,6 +2533,7 @@ void mp_pyinsert(PyObject *mod) INSERT("GF", gf_pytype); INSERT("GFReduce", gfreduce_pytype); INSERT("GFN", gfn_pytype); + setconstants(mod, consts); } /*----- That's all, folks -------------------------------------------------*/