X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/0e29d9164d5cc4e3cafa509cda19de2e025446c1..67ac03c93a1ad6aa969887bfa380ca29dc6b510f:/field.c diff --git a/field.c b/field.c index 2807c1c..d35f1b8 100644 --- a/field.c +++ b/field.c @@ -229,15 +229,7 @@ end: } static long fe_pyhash(PyObject *me) -{ - size_t sz = FE_F(me)->noctets; - uint32 h = 0xe0c127ca + FE_F(me)->ops->ty; - octet *p = xmalloc(sz); - mp_storeb(FE_X(me), p, sz); - h = unihash_hash(&unihash_global, h, p, sz); - xfree(p); - return (h % LONG_MAX); -} + { return (mphash(FE_X(me))); } static int fe_pycoerce(PyObject **x, PyObject **y) { @@ -263,10 +255,12 @@ end: static PyObject *fe_pyint(PyObject *x) { long l; + PyObject *rc; mp *xx = F_OUT(FE_F(x), MP_NEW, FE_X(x)); - if (mp_tolong_checked(xx, &l)) { MP_DROP(xx); return (0); } + if (!mp_tolong_checked(xx, &l, 0)) rc = PyInt_FromLong(l); + else rc = mp_topylong(xx); MP_DROP(xx); - return (PyInt_FromLong(l)); + return (rc); } static PyObject *fe_pylong(PyObject *x) @@ -343,8 +337,8 @@ static PyObject *feget__value(PyObject *me, void *hunoz) static PyGetSetDef fe_pygetset[] = { #define GETSETNAME(op, name) fe##op##_##name GET (field, "X.field -> field containing X") - GET (value, "X.value -> `natural' integer representation of X") - GET (_value, "X._value -> internal integer representation of X") + GET (value, "X.value -> `natural' MP/GF representation of X") + GET (_value, "X._value -> internal MP/GF representation of X") #undef GETSETNAME { 0 } }; @@ -531,7 +525,7 @@ static PyGetSetDef field_pygetset[] = { static PyMethodDef field_pymethods[] = { #define METHNAME(name) fmeth_##name METH (_adopt, "F._adopt(X) -> FE") - KWMETH(rand, "F.rand(rng = rand) -> FE, uniformly distributed") + KWMETH(rand, "F.rand([rng = rand]) -> FE, uniformly distributed") #undef METHNAME { 0 } };