chiark
/
gitweb
/
~mdw
/
catacomb-python
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rand.c: Show keyword argument as optional.
[catacomb-python]
/
field.c
diff --git
a/field.c
b/field.c
index 2807c1ccbfb6cb491fb5902868548af47f6b203a..c23f3119ce6af8199e1a67377b91b9130fa22895 100644
(file)
--- a/
field.c
+++ b/
field.c
@@
-42,9
+42,9
@@
static PyObject *fe_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
{
PyObject *x;
mp *z;
{
PyObject *x;
mp *z;
-
char *
kwlist[] = { "x", 0 };
+
static const char *const
kwlist[] = { "x", 0 };
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:fe",
kwlist
, &x))
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:fe",
KWLIST
, &x))
return (0);
if (FE_PYCHECK(x) && FE_F(x) == FIELD_F(ty)) RETURN_OBJ(x);
if ((z = getmp(x)) == 0) return (0);
return (0);
if (FE_PYCHECK(x) && FE_F(x) == FIELD_F(ty)) RETURN_OBJ(x);
if ((z = getmp(x)) == 0) return (0);
@@
-126,16
+126,6
@@
static mp *tofe(field *f, PyObject *o)
return (y);
}
return (y);
}
-mp *getfe(field *f, PyObject *o)
-{
- mp *x = 0;
- if ((x = tofe(f, o)) == 0) {
- PyErr_Format(PyExc_TypeError, "can't convert %.100s to fe",
- o->ob_type->tp_name);
- }
- return (x);
-}
-
/*----- Field elements ----------------------------------------------------*/
static int febinop(PyObject *x, PyObject *y,
/*----- Field elements ----------------------------------------------------*/
static int febinop(PyObject *x, PyObject *y,
@@
-229,15
+219,7
@@
end:
}
static long fe_pyhash(PyObject *me)
}
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 int fe_pycoerce(PyObject **x, PyObject **y)
{
@@
-263,10
+245,12
@@
end:
static PyObject *fe_pyint(PyObject *x)
{
long l;
static PyObject *fe_pyint(PyObject *x)
{
long l;
+ PyObject *rc;
mp *xx = F_OUT(FE_F(x), MP_NEW, FE_X(x));
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);
MP_DROP(xx);
- return (
PyInt_FromLong(l)
);
+ return (
rc
);
}
static PyObject *fe_pylong(PyObject *x)
}
static PyObject *fe_pylong(PyObject *x)
@@
-280,7
+264,7
@@
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)); \
#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); \
}
MP_DROP(xx); \
return (rc); \
}
@@
-343,8
+327,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")
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 }
};
#undef GETSETNAME
{ 0 }
};
@@
-472,10
+456,10
@@
end:
static PyObject *fmeth_rand(PyObject *me, PyObject *arg, PyObject *kw)
{
static PyObject *fmeth_rand(PyObject *me, PyObject *arg, PyObject *kw)
{
-
char *
kwlist[] = { "rng", 0 };
+
static const char *const
kwlist[] = { "rng", 0 };
grand *r = &rand_global;
grand *r = &rand_global;
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:rand",
kwlist
,
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:rand",
KWLIST
,
convgrand, &r))
return (0);
return (fe_pywrap(me, F_RAND(FIELD_F(me), MP_NEW, r)));
convgrand, &r))
return (0);
return (fe_pywrap(me, F_RAND(FIELD_F(me), MP_NEW, r)));
@@
-531,7
+515,7
@@
static PyGetSetDef field_pygetset[] = {
static PyMethodDef field_pymethods[] = {
#define METHNAME(name) fmeth_##name
METH (_adopt, "F._adopt(X) -> FE")
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 }
};
#undef METHNAME
{ 0 }
};
@@
-591,9
+575,9
@@
static PyObject *primefield_pynew(PyTypeObject *ty,
{
mp *xx = 0;
field *f;
{
mp *xx = 0;
field *f;
-
char *
kwlist[] = { "p", 0 };
+
static const char *const
kwlist[] = { "p", 0 };
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:primefield",
kwlist
,
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:primefield",
KWLIST
,
convmp, &xx))
goto end;
if ((f = field_prime(xx)) == 0)
convmp, &xx))
goto end;
if ((f = field_prime(xx)) == 0)
@@
-639,7
+623,7
@@
static PyTypeObject primefield_pytype_skel = {
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-
"P
rime fields.",
+
"PrimeField(P): p
rime fields.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
@@
-667,10
+651,10
@@
static PyObject *niceprimefield_pynew(PyTypeObject *ty,
{
mp *xx = 0;
field *f;
{
mp *xx = 0;
field *f;
-
char *
kwlist[] = { "p", 0 };
+
static const char *const
kwlist[] = { "p", 0 };
if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:niceprimefield",
if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:niceprimefield",
-
kwlist
, convmp, &xx))
+
KWLIST
, convmp, &xx))
goto end;
if ((f = field_niceprime(xx)) == 0)
VALERR("bad prime for niceprimefield");
goto end;
if ((f = field_niceprime(xx)) == 0)
VALERR("bad prime for niceprimefield");
@@
-706,7
+690,7
@@
static PyTypeObject niceprimefield_pytype_skel = {
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-
"Nice prime fields
.",
+
"NicePrimeField(P): prime field using Solinas reduction
.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
@@
-766,7
+750,7
@@
static PyTypeObject binfield_pytype_skel = {
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-
"Binary fields. Abstract class.",
+"Binary fields. Abstract class.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
@@
-794,9
+778,9
@@
static PyObject *binpolyfield_pynew(PyTypeObject *ty,
{
mp *xx = 0;
field *f;
{
mp *xx = 0;
field *f;
-
char *
kwlist[] = { "p", 0 };
+
static const char *const
kwlist[] = { "p", 0 };
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:binpolyfield",
kwlist
,
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:binpolyfield",
KWLIST
,
convgf, &xx))
goto end;
if ((f = field_binpoly(xx)) == 0) VALERR("bad poly for binpolyfield");
convgf, &xx))
goto end;
if ((f = field_binpoly(xx)) == 0) VALERR("bad poly for binpolyfield");
@@
-807,8
+791,11
@@
end:
return (0);
}
return (0);
}
+static PyObject *bfget_p(PyObject *me, void *hunoz)
+ { return (gf_pywrap(MP_COPY(FIELD_F(me)->m))); }
+
static PyGetSetDef binpolyfield_pygetset[] = {
static PyGetSetDef binpolyfield_pygetset[] = {
-#define GETSETNAME(op, name)
p
f##op##_##name
+#define GETSETNAME(op, name)
b
f##op##_##name
GET (p, "F.p -> field polynomial")
#undef GETSETNAME
{ 0 }
GET (p, "F.p -> field polynomial")
#undef GETSETNAME
{ 0 }
@@
-839,7
+826,7
@@
static PyTypeObject binpolyfield_pytype_skel = {
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-
"B
inary fields with polynomial basis representation.",
+
"BinPolyField(P): b
inary fields with polynomial basis representation.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
@@
-867,10
+854,10
@@
static PyObject *binnormfield_pynew(PyTypeObject *ty,
{
mp *xx = 0, *yy = 0;
field *f;
{
mp *xx = 0, *yy = 0;
field *f;
-
char *
kwlist[] = { "p", "beta", 0 };
+
static const char *const
kwlist[] = { "p", "beta", 0 };
if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&:binnormfield",
if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&:binnormfield",
-
kwlist
, convgf, &xx, convgf, &yy))
+
KWLIST
, convgf, &xx, convgf, &yy))
goto end;
if ((f = field_binnorm(xx, yy)) == 0) VALERR("bad args for binnormfield");
MP_DROP(xx); MP_DROP(yy);
goto end;
if ((f = field_binnorm(xx, yy)) == 0) VALERR("bad args for binnormfield");
MP_DROP(xx); MP_DROP(yy);
@@
-887,7
+874,7
@@
static PyObject *bnfget_beta(PyObject *me, void *hunoz)
}
static PyGetSetDef binnormfield_pygetset[] = {
}
static PyGetSetDef binnormfield_pygetset[] = {
-#define GETSETNAME(op, name)
p
f##op##_##name
+#define GETSETNAME(op, name)
b
f##op##_##name
GET (p, "F.p -> field polynomial")
#undef GETSETNAME
#define GETSETNAME(op, name) bnf##op##_##name
GET (p, "F.p -> field polynomial")
#undef GETSETNAME
#define GETSETNAME(op, name) bnf##op##_##name
@@
-921,7
+908,7
@@
static PyTypeObject binnormfield_pytype_skel = {
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-
"B
inary fields with normal basis representation.",
+
"BinNormField(P, BETA): b
inary fields with normal basis representation.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
0, /* @tp_traverse@ */
0, /* @tp_clear@ */