X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/catacomb-python/blobdiff_plain/0040152918b6695e73807fd479024db8a27a83fb..183e9cd31b1ac2f14b86c5de6ac2643b8a4364a2:/field.c diff --git a/field.c b/field.c index eafa42f..35cd452 100644 --- a/field.c +++ b/field.c @@ -66,7 +66,7 @@ static PyObject *field_dopywrap(PyTypeObject *ty, field *f) fobj->ty.ht_type.tp_alloc = PyType_GenericAlloc; fobj->ty.ht_type.tp_free = 0; fobj->ty.ht_type.tp_new = fe_pynew; - PyType_Ready(&fobj->ty.ht_type); + typeready(&fobj->ty.ht_type); return ((PyObject *)fobj); } @@ -230,11 +230,13 @@ end: static long fe_pyhash(PyObject *me) { - long i = mp_tolong(FE_X(me)); - i ^= 0xdcf62d6c; /* random perturbance */ - if (i == -1) - i = -2; - return (i); + 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); } static int fe_pycoerce(PyObject **x, PyObject **y) @@ -261,10 +263,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) @@ -406,7 +410,7 @@ static PyNumberMethods fe_pynumber = { static PyTypeObject fe_pytype_skel = { PyObject_HEAD_INIT(0) 0, /* Header */ - "catacomb.FE", /* @tp_name@ */ + "FE", /* @tp_name@ */ sizeof(fe_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -536,7 +540,7 @@ static PyMethodDef field_pymethods[] = { static PyTypeObject field_pytype_skel = { PyObject_HEAD_INIT(0) 0, /* Header */ - "catacomb.Field", /* @tp_name@ */ + "Field", /* @tp_name@ */ sizeof(field_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -614,7 +618,7 @@ static PyGetSetDef primefield_pygetset[] = { static PyTypeObject primefield_pytype_skel = { PyObject_HEAD_INIT(0) 0, /* Header */ - "catacomb.PrimeField", /* @tp_name@ */ + "PrimeField", /* @tp_name@ */ sizeof(field_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -637,7 +641,7 @@ static PyTypeObject primefield_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ - "Prime fields.", +"PrimeField(P): prime fields.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -681,7 +685,7 @@ end: static PyTypeObject niceprimefield_pytype_skel = { PyObject_HEAD_INIT(0) 0, /* Header */ - "catacomb.NicePrimeField", /* @tp_name@ */ + "NicePrimeField", /* @tp_name@ */ sizeof(field_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -704,7 +708,7 @@ static PyTypeObject niceprimefield_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ - "Nice prime fields.", +"NicePrimeField(P): prime field using Solinas reduction.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -741,7 +745,7 @@ static PyGetSetDef binfield_pygetset[] = { static PyTypeObject binfield_pytype_skel = { PyObject_HEAD_INIT(0) 0, /* Header */ - "catacomb.BinField", /* @tp_name@ */ + "BinField", /* @tp_name@ */ sizeof(field_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -764,7 +768,7 @@ static PyTypeObject binfield_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ - "Binary fields. Abstract class.", +"Binary fields. Abstract class.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -814,7 +818,7 @@ static PyGetSetDef binpolyfield_pygetset[] = { static PyTypeObject binpolyfield_pytype_skel = { PyObject_HEAD_INIT(0) 0, /* Header */ - "catacomb.BinPolyField", /* @tp_name@ */ + "BinPolyField", /* @tp_name@ */ sizeof(field_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -837,7 +841,7 @@ static PyTypeObject binpolyfield_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ - "Binary fields with polynomial basis representation.", +"BinPolyField(P): binary fields with polynomial basis representation.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -896,7 +900,7 @@ static PyGetSetDef binnormfield_pygetset[] = { static PyTypeObject binnormfield_pytype_skel = { PyObject_HEAD_INIT(0) 0, /* Header */ - "catacomb.BinNormField", /* @tp_name@ */ + "BinNormField", /* @tp_name@ */ sizeof(field_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -919,7 +923,7 @@ static PyTypeObject binnormfield_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ - "Binary fields with normal basis representation.", +"BinNormField(P, BETA): binary fields with normal basis representation.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -956,7 +960,7 @@ static PyObject *meth__Field_parse(PyObject *me, PyObject *arg) qd.p = p; qd.e = 0; if ((f = field_parse(&qd)) == 0) - SYNERR(qd.e); + VALERR(qd.e); rc = Py_BuildValue("(Ns)", field_pywrap(f), qd.p); end: return (rc);