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);
}
}
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)
{
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)
#define BASEOP(name, radix, pre) \
static PyObject *fe_py##name(PyObject *x) { \
mp *xx = F_OUT(FE_F(x), MP_NEW, FE_X(x)); \
- PyObject *rc = mp_topystring(FE_X(x), radix, 0, pre, 0); \
+ PyObject *rc = mp_topystring(xx, radix, 0, pre, 0); \
MP_DROP(xx); \
return (rc); \
}
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 }
};
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 }
};
return (0);
}
+static PyObject *bfget_p(PyObject *me, void *hunoz)
+ { return (gf_pywrap(MP_COPY(FIELD_F(me)->m))); }
+
static PyGetSetDef binpolyfield_pygetset[] = {
-#define GETSETNAME(op, name) pf##op##_##name
+#define GETSETNAME(op, name) bf##op##_##name
GET (p, "F.p -> field polynomial")
#undef GETSETNAME
{ 0 }
}
static PyGetSetDef binnormfield_pygetset[] = {
-#define GETSETNAME(op, name) pf##op##_##name
+#define GETSETNAME(op, name) bf##op##_##name
GET (p, "F.p -> field polynomial")
#undef GETSETNAME
#define GETSETNAME(op, name) bnf##op##_##name
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);