From 3ed16ce3e1b50da2a4b18637d40775a52b3a2c74 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Tue, 19 Nov 2019 08:29:49 +0000 Subject: [PATCH] algorithms.c, ec.c, field.c: Replace properties by member access. --- algorithms.c | 51 ++++++++++++++++----------------------------------- ec.c | 14 +++++++++----- field.c | 14 +++++++++----- pubkey.c | 2 +- 4 files changed, 35 insertions(+), 46 deletions(-) diff --git a/algorithms.c b/algorithms.c index 465da45..858597a 100644 --- a/algorithms.c +++ b/algorithms.c @@ -2905,30 +2905,10 @@ static PyObject *kxvikmeth_step(PyObject *me) RETURN_ME; } -static PyObject *kxvikget_nround(PyObject *me, void *hunoz) -{ - kxvik_pyobj *k = (kxvik_pyobj *)me; - return (PyInt_FromLong(k->n)); -} - -static int kxvikset_nround(PyObject *me, PyObject *val, void *hunoz) -{ - kxvik_pyobj *k = (kxvik_pyobj *)me; - unsigned n; - int rc = -1; - - if (!val) NIERR("__del__"); - if (!convuint(val, &n)) goto end; - k->n = n; - rc = 0; -end: - return (rc); -} - -static const PyGetSetDef kxvik_pygetset[] = { -#define GETSETNAME(op, name) kxvik##op##_##name - GETSET(nround, "KECCAK.nround -> number of rounds") -#undef GETSETNAME +static const PyMemberDef kxvik_pymembers[] = { +#define MEMBERSTRUCT kxvik_pyobj + MEMRNM(nround, T_UINT, n, 0, "KECCAC.nround -> number of rounds") +#undef MEMBERSTRUCT { 0 } }; @@ -2976,8 +2956,8 @@ static PyTypeObject kxvik_pytype_skel = { 0, /* @tp_iter@ */ 0, /* @tp_iternext@ */ PYMETHODS(kxvik), /* @tp_methods@ */ - 0, /* @tp_members@ */ - PYGETSET(kxvik), /* @tp_getset@ */ + PYMEMBERS(kxvik), /* @tp_members@ */ + 0, /* @tp_getset@ */ 0, /* @tp_base@ */ 0, /* @tp_dict@ */ 0, /* @tp_descr_get@ */ @@ -3145,12 +3125,6 @@ end: return (rc); } -static PyObject *shakeget_rate(PyObject *me, void *hunoz) - { return (PyInt_FromLong(SHAKE_H(me)->h.r)); } - -static PyObject *shakeget_buffered(PyObject *me, void *hunoz) - { return (PyInt_FromLong(SHAKE_H(me)->h.n)); } - static PyObject *shakeget_state(PyObject *me, void *hunoz) { int st = SHAKE_ST(me); @@ -3158,10 +3132,17 @@ static PyObject *shakeget_state(PyObject *me, void *hunoz) st == 1 ? "squeeze" : "dead")); } +static const PyMemberDef shake_pymembers[] = { +#define MEMBERSTRUCT shake_pyobj + MEMRNM(rate, T_UINT, h.h.r, READONLY, "S.rate -> rate, in bytes") + MEMRNM(buffered, T_UINT, h.h.n, READONLY, + "S.buffered -> amount currently buffered") +#undef MEMBERSTRUCT + { 0 } +}; + static const PyGetSetDef shake_pygetset[] = { #define GETSETNAME(op, name) shake##op##_##name - GET (rate, "S.rate -> rate, in bytes") - GET (buffered, "S.buffered -> amount currently buffered") GET (state, "S.state -> `absorb', `squeeze', `dead'") #undef GETSETNAME { 0 } @@ -3220,7 +3201,7 @@ static PyTypeObject shake_pytype_skel = { 0, /* @tp_iter@ */ 0, /* @tp_iternext@ */ PYMETHODS(shake), /* @tp_methods@ */ - 0, /* @tp_members@ */ + PYMEMBERS(shake), /* @tp_members@ */ PYGETSET(shake), /* @tp_getset@ */ 0, /* @tp_base@ */ 0, /* @tp_dict@ */ diff --git a/ec.c b/ec.c index 03e9d16..b023fa5 100644 --- a/ec.c +++ b/ec.c @@ -308,9 +308,6 @@ end: return (rc); } -static PyObject *epget_curve(PyObject *me, void *hunoz) - { RETURN_OBJ(ECPT_COBJ(me)); } - static PyObject *epmeth_frombuf(PyObject *me, PyObject *arg) { buf b; @@ -738,9 +735,16 @@ static PyTypeObject ecpt_pytype_skel = { 0 /* @tp_is_gc@ */ }; +static const PyMemberDef ecpt_pymembers[] = { +#define MEMBERSTRUCT ecpt_pyobj + MEMRNM(curve, T_OBJECT, ob_type, READONLY, + "P.curve -> elliptic curve containing P") +#undef MEMBERSTRUCT + { 0 } +}; + static const PyGetSetDef ecpt_pygetset[] = { #define GETSETNAME(op, name) ep##op##_##name - GET (curve, "P.curve -> elliptic curve containing P") GET (point, "P.point -> standalone curve point") GET (x, "P.x -> Cartesian x coordinate of P") GET (y, "P.y -> Cartesian y coordinate of P") @@ -841,7 +845,7 @@ static PyTypeObject ecptcurve_pytype_skel = { 0, /* @tp_iter@ */ 0, /* @tp_iternext@ */ PYMETHODS(ecpt), /* @tp_methods@ */ - 0, /* @tp_members@ */ + PYMEMBERS(ecpt), /* @tp_members@ */ PYGETSET(ecpt), /* @tp_getset@ */ 0, /* @tp_base@ */ 0, /* @tp_dict@ */ diff --git a/field.c b/field.c index 987b47d..1ff5ed2 100644 --- a/field.c +++ b/field.c @@ -301,9 +301,6 @@ UNOP(qdl, ; ) UNOP(hlv, ; ) #undef UNOP -static PyObject *feget_field(PyObject *me, void *hunoz) - { RETURN_OBJ(FE_FOBJ(me)); } - static PyObject *feget_value(PyObject *me, void *hunoz) { mp *x = F_OUT(FE_F(me), MP_NEW, FE_X(me)); @@ -323,9 +320,16 @@ static PyObject *feget__value(PyObject *me, void *hunoz) return (mp_pywrap(x)); } +static const PyMemberDef fe_pymembers[] = { +#define MEMBERSTRUCT fe_pyobj + MEMRNM(field, T_OBJECT, ob_type, READONLY, + "X.field -> field containing X") +#undef MEMBERSTRUCT + { 0 } +}; + static const PyGetSetDef fe_pygetset[] = { #define GETSETNAME(op, name) fe##op##_##name - GET (field, "X.field -> field containing X") GET (value, "X.value -> `natural' MP/GF representation of X") GET (_value, "X._value -> internal MP/GF representation of X") #undef GETSETNAME @@ -424,7 +428,7 @@ static PyTypeObject fe_pytype_skel = { 0, /* @tp_iter@ */ 0, /* @tp_iternext@ */ PYMETHODS(fe), /* @tp_methods@ */ - 0, /* @tp_members@ */ + PYMEMBERS(fe), /* @tp_members@ */ PYGETSET(fe), /* @tp_getset@ */ 0, /* @tp_base@ */ 0, /* @tp_dict@ */ diff --git a/pubkey.c b/pubkey.c index 2c906cd..d7201c6 100644 --- a/pubkey.c +++ b/pubkey.c @@ -780,7 +780,7 @@ static const PyGetSetDef rsapriv_pygetset[] = { static const PyMethodDef rsapriv_pymethods[] = { #define METHNAME(name) rsameth_##name - KWMETH(privop, "R.privop(X, [rng = None]) -> X^D (mod N)") + KWMETH(privop, "R.privop(X, [rng = None]) -> X^D (mod N)") KWSMTH(generate, "generate(NBITS, [event = pgen_nullev], [rng = rand], " "[nsteps = 0]) -> R") #undef METHNAME -- 2.11.0