From: Mark Wooding Date: Tue, 15 Oct 2019 10:48:39 +0000 (+0100) Subject: field.c, mp.c: Hash `GF' and `FE' objects the same as `MP'. X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/commitdiff_plain/ab723d7332a553a47c78f33229e402a0b3618744 field.c, mp.c: Hash `GF' and `FE' objects the same as `MP'. They can be compared for equality, and so they must hash the same way. --- diff --git a/field.c b/field.c index 0a5d908..5b4c27d 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) { diff --git a/mp.c b/mp.c index 9330121..e4f5980 100644 --- a/mp.c +++ b/mp.c @@ -1887,15 +1887,6 @@ end: return ((PyObject *)zz); } -static long gf_pyhash(PyObject *me) -{ - long i = mp_tolong(MP_X(me)); - i ^= 0xc7ecd67c; /* random perturbance */ - if (i == -1) - i = -2; - return (i); -} - static PyObject *gf_pyexp(PyObject *x, PyObject *y, PyObject *z) { mp *xx = 0, *yy = 0, *zz = 0; @@ -2078,7 +2069,7 @@ static PyTypeObject gf_pytype_skel = { &gf_pynumber, /* @tp_as_number@ */ 0, /* @tp_as_sequence@ */ 0, /* @tp_as_mapping@ */ - gf_pyhash, /* @tp_hash@ */ + mp_pyhash, /* @tp_hash@ */ 0, /* @tp_call@ */ mp_pyhex, /* @tp_str@ */ 0, /* @tp_getattro@ */