chiark / gitweb /
algorithms.c, ec.c, field.c: Replace properties by member access.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 19 Nov 2019 08:29:49 +0000 (08:29 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 11 Apr 2020 11:44:14 +0000 (12:44 +0100)
algorithms.c
ec.c
field.c
pubkey.c

index 465da45d4f9c19bc0b680ab380e9ec1748086e1a..858597ac3a6be8d4a863809e87115606b94cb5eb 100644 (file)
@@ -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 b69dbf3ca5e768769ae8f95590c985aaee17b885..06ed4247f56d3d29c18cfac019037331f097210e 100644 (file)
--- 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 987b47d8d074a5e2269dc60be1e91c26b63740c4..1ff5ed288b3378197064df7fbdd4a89bc808f931 100644 (file)
--- 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@ */
index 2c906cd539541dfe61a6bf42432ca7b40345eceb..d7201c6cd2307d06ea248a22658f2ee34d91b052 100644 (file)
--- 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