pyke/mapping.c, key.c: Make the mapping code more intrusive and complete.
[catacomb-python] / group.c
diff --git a/group.c b/group.c
index 5d7c34b..d02f356 100644 (file)
--- a/group.c
+++ b/group.c
@@ -94,8 +94,7 @@ static void fginfo_pydealloc(PyObject *me)
   FREEOBJ(me);
 }
 
-static PyObject *meth__DHInfo_generate(PyObject *me,
-                                      PyObject *arg, PyObject *kw)
+static PyObject *dimeth_generate(PyObject *me, PyObject *arg, PyObject *kw)
 {
   dh_param dp;
   unsigned ql = 0, pl;
@@ -104,12 +103,12 @@ static PyObject *meth__DHInfo_generate(PyObject *me,
   struct excinfo exc = EXCINFO_INIT;
   pypgev evt = { { 0 } };
   static const char *const kwlist[] =
-    { "class", "pbits", "qbits", "event", "rng", "nsteps", 0 };
+    { "pbits", "qbits", "event", "rng", "nsteps", 0 };
   PyObject *rc = 0;
 
   evt.exc = &exc;
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&|O&O&O&O&:generate", KWLIST,
-                                  &me, convuint, &pl, convuint, &ql,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|O&O&O&O&:generate", KWLIST,
+                                  convuint, &pl, convuint, &ql,
                                   convpgev, &evt, convgrand, &r,
                                   convuint, &steps))
     goto end;
@@ -121,8 +120,7 @@ end:
   return (rc);
 }
 
-static PyObject *meth__DHInfo_genlimlee(PyObject *me,
-                                       PyObject *arg, PyObject *kw)
+static PyObject *dimeth_genlimlee(PyObject *me, PyObject *arg, PyObject *kw)
 {
   dh_param dp;
   unsigned ql, pl;
@@ -133,7 +131,7 @@ static PyObject *meth__DHInfo_genlimlee(PyObject *me,
   int subgroupp = 1;
   unsigned f = 0;
   static const char *const kwlist[] = {
-    "class", "pbits", "qbits", "event", "ievent",
+    "pbits", "qbits", "event", "ievent",
     "rng", "nsteps", "subgroupp", 0
   };
   size_t i, nf;
@@ -142,8 +140,8 @@ static PyObject *meth__DHInfo_genlimlee(PyObject *me,
 
   oe.exc = ie.exc = &exc;
   if (!PyArg_ParseTupleAndKeywords(arg, kw,
-                                  "OO&O&|O&O&O&O&O&:genlimlee", KWLIST,
-                                  &me, convuint, &pl, convuint, &ql,
+                                  "O&O&|O&O&O&O&O&:genlimlee", KWLIST,
+                                  convuint, &pl, convuint, &ql,
                                   convpgev, &oe, convpgev, &ie,
                                   convgrand, &r, convuint, &steps,
                                   convbool, &subgroupp))
@@ -162,8 +160,7 @@ end:
   return (rc);
 }
 
-static PyObject *meth__DHInfo_genkcdsa(PyObject *me,
-                                      PyObject *arg, PyObject *kw)
+static PyObject *dimeth_genkcdsa(PyObject *me, PyObject *arg, PyObject *kw)
 {
   dh_param dp;
   unsigned ql, pl;
@@ -172,13 +169,13 @@ static PyObject *meth__DHInfo_genkcdsa(PyObject *me,
   struct excinfo exc = EXCINFO_INIT;
   pypgev evt = { { 0 } };
   static const char *const kwlist[] =
-    { "class", "pbits", "qbits", "event", "rng", "nsteps", 0 };
+    { "pbits", "qbits", "event", "rng", "nsteps", 0 };
   mp *v = MP_NEW;
   PyObject *rc = 0;
 
   evt.exc = &exc;
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&O&|O&O&O&:genkcdsa", KWLIST,
-                                  &me, convuint, &pl, convuint, &ql,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&|O&O&O&:genkcdsa", KWLIST,
+                                  convuint, &pl, convuint, &ql,
                                   convpgev, &evt, convgrand, &r,
                                   convuint, &steps))
     goto end;
@@ -193,8 +190,7 @@ end:
   return (rc);
 }
 
-static PyObject *meth__DHInfo_gendsa(PyObject *me,
-                                    PyObject *arg, PyObject *kw)
+static PyObject *dimeth_gendsa(PyObject *me, PyObject *arg, PyObject *kw)
 {
   dsa_param dp;
   unsigned ql, pl;
@@ -205,12 +201,12 @@ static PyObject *meth__DHInfo_gendsa(PyObject *me,
   struct excinfo exc = EXCINFO_INIT;
   pypgev evt = { { 0 } };
   static const char *const kwlist[] =
-    { "class", "pbits", "qbits", "seed", "event", "nsteps", 0 };
+    { "pbits", "qbits", "seed", "event", "nsteps", 0 };
   PyObject *rc = 0;
 
   evt.exc = &exc;
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&O&s#|O&O&:gendsa", KWLIST,
-                                  &me, convuint, &pl, convuint, &ql,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&s#|O&O&:gendsa", KWLIST,
+                                  convuint, &pl, convuint, &ql,
                                   &k, &ksz, convpgev, &evt,
                                   convuint, &steps))
     goto end;
@@ -258,7 +254,7 @@ static PyObject *meth__groupn(PyObject *me, PyObject *arg,
   gprime_param gp;
   PyObject *rc = 0;
 
-  if (!PyArg_ParseTuple(arg, "Oi:_groupn", &me, &i)) goto end;
+  if (!PyArg_ParseTuple(arg, "i:_groupn", &i)) goto end;
   if (i < 0 || i >= ne) VALERR("group index out of range");
   dh_infofromdata(&gp, pp[i].data);
   rc = fginfo_pywrap(&gp, ty);
@@ -266,10 +262,10 @@ end:
   return (rc);
 }
 
-static PyObject *meth__DHInfo__groupn(PyObject *me, PyObject *arg)
+static PyObject *dimeth__groupn(PyObject *me, PyObject *arg)
   { return (meth__groupn(me, arg, dhinfo_pytype, ptab, npgroups)); }
 
-static PyObject *meth__BinDHInfo__groupn(PyObject *me, PyObject *arg)
+static PyObject *bimeth__groupn(PyObject *me, PyObject *arg)
   { return (meth__groupn(me, arg, bindhinfo_pytype, bintab, nbingroups)); }
 
 static PyObject *meth__parse(PyObject *me, PyObject *arg, PyTypeObject *ty,
@@ -280,46 +276,76 @@ static PyObject *meth__parse(PyObject *me, PyObject *arg, PyTypeObject *ty,
   gprime_param gp;
   PyObject *rc = 0;
 
-  if (!PyArg_ParseTuple(arg, "Os:parse", &me, &p)) goto end;
-  qd.p = p;
-  qd.e = 0;
+  if (!PyArg_ParseTuple(arg, "s:parse", &p)) goto end;
+  qd.p = p; qd.e = 0;
   if (parse(&qd, &gp)) VALERR(qd.e);
   rc = fginfo_pywrap(&gp, ty);
 end:
   return (rc);
 }
 
-static PyObject *meth__DHInfo_parse(PyObject *me, PyObject *arg)
+static PyObject *dimeth_parse(PyObject *me, PyObject *arg)
   { return (meth__parse(me, arg, dhinfo_pytype, dh_parse)); }
 
-static PyObject *meth__BinDHInfo_parse(PyObject *me, PyObject *arg)
+static PyObject *bimeth_parse(PyObject *me, PyObject *arg)
   { return (meth__parse(me, arg, bindhinfo_pytype, dhbin_parse)); }
 
-static PyGetSetDef fginfo_pygetset[] = {
+static const PyGetSetDef fginfo_pygetset[] = {
 #define GETSETNAME(op, name) fi##op##_##name
-  GET  (r,                     "I.r -> group order")
+  GET  (r,             "I.r -> group order")
 #undef GETSETNAME
   { 0 }
 };
 
-static PyGetSetDef dhinfo_pygetset[] = {
+static const PyGetSetDef dhinfo_pygetset[] = {
 #define GETSETNAME(op, name) di##op##_##name
-  GET  (p,                     "I.p -> prime")
-  GET  (g,                     "I.g -> generator")
+  GET  (p,             "I.p -> prime")
+  GET  (g,             "I.g -> generator")
 #undef GETSETNAME
   { 0 }
 };
 
-static PyGetSetDef bindhinfo_pygetset[] = {
+static const PyMethodDef dhinfo_pymethods[] = {
+#define METHNAME(name) dimeth_##name
+  SMTH (parse,         "parse(STR) -> D, REST")
+  SMTH (_groupn,       0)
+  KWSMTH(generate,
+       "generate(PBITS, [qbits = 0], [event = pgen_nullev],\n"
+       "        [rng = rand], [nsteps = 0]) -> D")
+  KWSMTH(genlimlee,
+       "genlimlee(PBITS, QBITS, [event = pgen_nullev], "
+                                                 "[ievent = pgen_nullev],\n"
+       "         [rng = rand], [nsteps = 0], [subgroupp = True]) "
+                                                         "-> (D, [Q, ...])")
+  KWSMTH(gendsa,
+       "gendsa(PBITS, QBITS, SEED, [event = pgen_nullev], [nsteps = 0])\n"
+       "  -> (D, SEED, COUNT)")
+  KWSMTH(genkcdsa,
+       "gendsa(PBITS, QBITS, [event = pgen_nullev], "
+                                             "[rng = rand], [nsteps = 0])\n"
+       "  -> (D, V)")
+#undef METHNAME
+  { 0 }
+};
+
+static const PyGetSetDef bindhinfo_pygetset[] = {
 #define GETSETNAME(op, name) bi##op##_##name
-  GET  (p,                     "I.p -> irreducible polynomial")
-  GET  (m,                     "I.m -> degree of polynomial")
-  GET  (g,                     "I.g -> generator")
+  GET  (p,             "I.p -> irreducible polynomial")
+  GET  (m,             "I.m -> degree of polynomial")
+  GET  (g,             "I.g -> generator")
 #undef GETSETNAME
   { 0 }
 };
 
-static PyTypeObject fginfo_pytype_skel = {
+static const PyMethodDef bindhinfo_pymethods[] = {
+#define METHNAME(name) bimeth_##name
+  SMTH (parse,         "parse(STR) -> D, REST")
+  SMTH (_groupn,       0)
+#undef METHNAME
+  { 0 }
+};
+
+static const PyTypeObject fginfo_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "FGInfo",                            /* @tp_name@ */
   sizeof(fginfo_pyobj),                        /* @tp_basicsize@ */
@@ -344,7 +370,7 @@ static PyTypeObject fginfo_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"Abstract base class for field-group information objects.",
+  "Abstract base class for field-group information objects.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -354,7 +380,7 @@ static PyTypeObject fginfo_pytype_skel = {
   0,                                   /* @tp_iternext@ */
   0,                                   /* @tp_methods@ */
   0,                                   /* @tp_members@ */
-  fginfo_pygetset,                     /* @tp_getset@ */
+  PYGETSET(fginfo),                    /* @tp_getset@ */
   0,                                   /* @tp_base@ */
   0,                                   /* @tp_dict@ */
   0,                                   /* @tp_descr_get@ */
@@ -367,7 +393,7 @@ static PyTypeObject fginfo_pytype_skel = {
   0                                    /* @tp_is_gc@ */
 };
 
-static PyTypeObject dhinfo_pytype_skel = {
+static const PyTypeObject dhinfo_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "DHInfo",                            /* @tp_name@ */
   sizeof(fginfo_pyobj),                        /* @tp_basicsize@ */
@@ -392,7 +418,7 @@ static PyTypeObject dhinfo_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"DHInfo(P, R, G): standard (integer) Diffie-Hellman group information.",
+  "DHInfo(P, R, G): standard (integer) Diffie-Hellman group information.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -400,9 +426,9 @@ static PyTypeObject dhinfo_pytype_skel = {
   0,                                   /* @tp_weaklistoffset@ */
   0,                                   /* @tp_iter@ */
   0,                                   /* @tp_iternext@ */
-  0,                                   /* @tp_methods@ */
+  PYMETHODS(dhinfo),                   /* @tp_methods@ */
   0,                                   /* @tp_members@ */
-  dhinfo_pygetset,                     /* @tp_getset@ */
+  PYGETSET(dhinfo),                    /* @tp_getset@ */
   0,                                   /* @tp_base@ */
   0,                                   /* @tp_dict@ */
   0,                                   /* @tp_descr_get@ */
@@ -415,7 +441,7 @@ static PyTypeObject dhinfo_pytype_skel = {
   0                                    /* @tp_is_gc@ */
 };
 
-static PyTypeObject bindhinfo_pytype_skel = {
+static const PyTypeObject bindhinfo_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "BinDHInfo",                         /* @tp_name@ */
   sizeof(fginfo_pyobj),                        /* @tp_basicsize@ */
@@ -440,7 +466,7 @@ static PyTypeObject bindhinfo_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"BinDHInfo(P, R, G): binary-field Diffie-Hellman group information.",
+  "BinDHInfo(P, R, G): binary-field Diffie-Hellman group information.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -448,9 +474,9 @@ static PyTypeObject bindhinfo_pytype_skel = {
   0,                                   /* @tp_weaklistoffset@ */
   0,                                   /* @tp_iter@ */
   0,                                   /* @tp_iternext@ */
-  0,                                   /* @tp_methods@ */
+  PYMETHODS(bindhinfo),                        /* @tp_methods@ */
   0,                                   /* @tp_members@ */
-  bindhinfo_pygetset,                  /* @tp_getset@ */
+  PYGETSET(bindhinfo),                 /* @tp_getset@ */
   0,                                   /* @tp_base@ */
   0,                                   /* @tp_dict@ */
   0,                                   /* @tp_descr_get@ */
@@ -596,11 +622,10 @@ BINOP(div)
 #undef BINOP
 
 #define UNOP(name)                                                     \
-  static PyObject *gemeth_##name(PyObject *me, PyObject *arg)          \
+  static PyObject *gemeth_##name(PyObject *me)                         \
   {                                                                    \
     group *g;                                                          \
     ge *z;                                                             \
-    if (!PyArg_ParseTuple(arg, ":" #name)) return (0);                 \
     g = GE_G(me);                                                      \
     z = G_CREATE(g);                                                   \
     g->ops->name(g, z, GE_X(me));                                      \
@@ -670,9 +695,8 @@ end:
   return (rc);
 }
 
-static PyObject *gemeth_check(PyObject *me, PyObject *arg)
+static PyObject *gemeth_check(PyObject *me)
 {
-  if (!PyArg_ParseTuple(arg, ":check")) goto end;
   if (group_check(GE_G(me), GE_X(me))) VALERR("bad group element");
   RETURN_OBJ(me);
 end:
@@ -721,11 +745,10 @@ end:
   return (rc);
 }
 
-static PyObject *gemeth_toint(PyObject *me, PyObject *arg)
+static PyObject *gemeth_toint(PyObject *me)
 {
   mp *x;
 
-  if (!PyArg_ParseTuple(arg, ":toint")) goto end;
   if ((x = G_TOINT(GE_G(me), MP_NEW, GE_X(me))) == 0)
     TYERR("can't convert to integer");
   return (mp_pywrap(x));
@@ -766,13 +789,12 @@ end:
   return (rc);
 }
 
-static PyObject *gemeth_tobuf(PyObject *me, PyObject *arg)
+static PyObject *gemeth_tobuf(PyObject *me)
 {
   buf b;
   PyObject *rc;
   size_t n;
 
-  if (!PyArg_ParseTuple(arg, ":tobuf")) return (0);
   n = GE_G(me)->noctets + 4;
   rc = bytestring_pywrap(0, n);
   buf_init(&b, PyString_AS_STRING(rc), n);
@@ -782,13 +804,12 @@ static PyObject *gemeth_tobuf(PyObject *me, PyObject *arg)
   return (rc);
 }
 
-static PyObject *gemeth_toraw(PyObject *me, PyObject *arg)
+static PyObject *gemeth_toraw(PyObject *me)
 {
   buf b;
   PyObject *rc;
   size_t n;
 
-  if (!PyArg_ParseTuple(arg, ":toraw")) return (0);
   n = GE_G(me)->noctets;
   rc = bytestring_pywrap(0, n);
   buf_init(&b, PyString_AS_STRING(rc), n);
@@ -846,7 +867,7 @@ end:
   return (0);
 }
 
-static PyObject *meth__GE_frombuf(PyObject *me, PyObject *arg)
+static PyObject *gemeth_frombuf(PyObject *me, PyObject *arg)
 {
   buf b;
   char *p;
@@ -854,20 +875,18 @@ static PyObject *meth__GE_frombuf(PyObject *me, PyObject *arg)
   group *g;
   ge *x = 0;
 
-  if (!PyArg_ParseTuple(arg, "Os#:frombuf", &me, &p, &n))
-    return (0);
+  if (!PyArg_ParseTuple(arg, "s#:frombuf", &p, &n)) return (0);
   g = GROUP_G(me);
   buf_init(&b, p, n);
   x = G_CREATE(g);
-  if (G_FROMBUF(g, &b, x))
-    VALERR("invalid data");
+  if (G_FROMBUF(g, &b, x)) VALERR("invalid data");
   return (Py_BuildValue("(NN)", ge_pywrap(me, x), bytestring_pywrapbuf(&b)));
 end:
   if (x) G_DESTROY(g, x);
   return (0);
 }
 
-static PyObject *meth__GE_fromraw(PyObject *me, PyObject *arg)
+static PyObject *gemeth_fromraw(PyObject *me, PyObject *arg)
 {
   buf b;
   char *p;
@@ -875,20 +894,18 @@ static PyObject *meth__GE_fromraw(PyObject *me, PyObject *arg)
   group *g;
   ge *x = 0;
 
-  if (!PyArg_ParseTuple(arg, "Os#:fromraw", &me, &p, &n))
-    return (0);
+  if (!PyArg_ParseTuple(arg, "s#:fromraw", &p, &n)) return (0);
   g = GROUP_G(me);
   buf_init(&b, p, n);
   x = G_CREATE(g);
-  if (G_FROMRAW(g, &b, x))
-    VALERR("invalid data");
+  if (G_FROMRAW(g, &b, x)) VALERR("invalid data");
   return (Py_BuildValue("(NN)", ge_pywrap(me, x), bytestring_pywrapbuf(&b)));
 end:
   if (x) G_DESTROY(g, x);
   return (0);
 }
 
-static PyObject *meth__GE_fromstring(PyObject *me, PyObject *arg)
+static PyObject *gemeth_fromstring(PyObject *me, PyObject *arg)
 {
   mptext_stringctx sc;
   char *p;
@@ -896,8 +913,7 @@ static PyObject *meth__GE_fromstring(PyObject *me, PyObject *arg)
   group *g;
   ge *x = 0;
 
-  if (!PyArg_ParseTuple(arg, "Os#:fromstring", &me, &p, &n))
-    return (0);
+  if (!PyArg_ParseTuple(arg, "s#:fromstring", &p, &n)) return (0);
   sc.buf = p;
   sc.lim = sc.buf + n;
   g = GROUP_G(me);
@@ -911,18 +927,15 @@ end:
   return (0);
 }
 
-static PyObject *meth__Group_parse(PyObject *me, PyObject *arg)
+static PyObject *gmeth_parse(PyObject *me, PyObject *arg)
 {
   char *p;
   qd_parse qd;
   group *g;
 
-  if (!PyArg_ParseTuple(arg, "Os:parse", &me, &p))
-    goto end;
-  qd.p = p;
-  qd.e = 0;
-  if ((g = group_parse(&qd)) == 0)
-    VALERR(qd.e);
+  if (!PyArg_ParseTuple(arg, "s:parse", &p)) goto end;
+  qd.p = p; qd.e = 0;
+  if ((g = group_parse(&qd)) == 0) VALERR(qd.e);
   return (group_pywrap(g));
 end:
   return (0);
@@ -969,28 +982,31 @@ static PyObject *gget_r(PyObject *me, void *hunoz)
 static PyObject *gget_h(PyObject *me, void *hunoz)
   { return (mp_pywrap(MP_COPY(GROUP_G(me)->h))); }
 
-static PyGetSetDef ge_pygetset[] = {
+static const PyGetSetDef ge_pygetset[] = {
 #define GETSETNAME(op, name) ge##op##_##name
   GET  (group,         "X.group -> group containing X")
 #undef GETSETNAME
   { 0 }
 };
 
-static PyMethodDef ge_pymethods[] = {
+static const PyMethodDef ge_pymethods[] = {
 #define METHNAME(name) gemeth_##name
-  METH (inv,           "X.inv() -> inverse element of X")
-  METH (sqr,           "X.sqr() -> X^2 = X * X")
-  METH (check,         "X.check() -> check X really belongs to its group")
-  METH (toint,         "X.toint() -> X converted to an integer")
-  KWMETH(toec,         "\
-X.toec([curve = ECPt]) -> X converted to elliptic curve point")
-  METH (tobuf,         "X.tobuf() -> X in buffer representation")
-  METH (toraw,         "X.toraw() -> X in raw representation")
+  NAMETH(inv,          "X.inv() -> inverse element of X")
+  NAMETH(sqr,          "X.sqr() -> X^2 = X * X")
+  NAMETH(check,                "X.check() -> check X really belongs to its group")
+  NAMETH(toint,                "X.toint() -> X converted to an integer")
+  KWMETH(toec,         "X.toec([curve = ECPt]) -> "
+                                      "X converted to elliptic curve point")
+  NAMETH(tobuf,                "X.tobuf() -> X in buffer representation")
+  NAMETH(toraw,                "X.toraw() -> X in raw representation")
+  CMTH (frombuf,       "frombuf(BUF) -> X, REST")
+  CMTH (fromraw,       "fromraw(BUF) -> X, REST")
+  CMTH (fromstring,    "fromstring(STR) -> X, REST")
 #undef METHNAME
   { 0 }
 };
 
-static PyNumberMethods ge_pynumber = {
+static const PyNumberMethods ge_pynumber = {
   0,                                   /* @nb_add@ */
   0,                                   /* @nb_subtract@ */
   ge_pymul,                            /* @nb_multiply@ */
@@ -1033,7 +1049,7 @@ static PyNumberMethods ge_pynumber = {
   0,                                   /* @nb_inplace_true_divide@ */
 };
 
-static PyTypeObject ge_pytype_skel = {
+static const PyTypeObject ge_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "GE",                                        /* @tp_name@ */
   sizeof(ge_pyobj),                    /* @tp_basicsize@ */
@@ -1045,7 +1061,7 @@ static PyTypeObject ge_pytype_skel = {
   0,                                   /* @tp_setattr@ */
   0,                                   /* @tp_compare@ */
   0,                                   /* @tp_repr@ */
-  &ge_pynumber,                                /* @tp_as_number@ */
+  PYNUMBER(ge),                                /* @tp_as_number@ */
   0,                                   /* @tp_as_sequence@ */
   0,                                   /* @tp_as_mapping@ */
   ge_pyhash,                           /* @tp_hash@ */
@@ -1059,7 +1075,7 @@ static PyTypeObject ge_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"Group elements, abstract base class.",
+  "Group elements, abstract base class.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -1067,9 +1083,9 @@ static PyTypeObject ge_pytype_skel = {
   0,                                   /* @tp_weaklistoffset@ */
   0,                                   /* @tp_iter@ */
   0,                                   /* @tp_iternext@ */
-  ge_pymethods,                                /* @tp_methods@ */
+  PYMETHODS(ge),                       /* @tp_methods@ */
   0,                                   /* @tp_members@ */
-  ge_pygetset,                         /* @tp_getset@ */
+  PYGETSET(ge),                                /* @tp_getset@ */
   0,                                   /* @tp_base@ */
   0,                                   /* @tp_dict@ */
   0,                                   /* @tp_descr_get@ */
@@ -1082,7 +1098,7 @@ static PyTypeObject ge_pytype_skel = {
   0                                    /* @tp_is_gc@ */
 };
 
-static PyGetSetDef group_pygetset[] = {
+static const PyGetSetDef group_pygetset[] = {
 #define GETSETNAME(op, name) g##op##_##name
   GET  (noctets,       "G.noctets -> size in octets of element")
   GET  (nbits,         "G.nbits -> size in bits of element")
@@ -1094,16 +1110,16 @@ static PyGetSetDef group_pygetset[] = {
   { 0 }
 };
 
-static PyMethodDef group_pymethods[] = {
+static const PyMethodDef group_pymethods[] = {
 #define METHNAME(name) gmeth_##name
-  METH (mexp,          "\
-G.mexp([(X0, N0), (X1, N1), ...]) -> X0^N0 X1^N1 ...")
+  METH (mexp,        "G.mexp([(X0, N0), (X1, N1), ...]) -> X0^N0 X1^N1 ...")
   KWMETH(checkgroup,   "G.checkgroup([rng = rand]): check group is good")
+  SMTH (parse,         "parse(STR) -> G, REST")
 #undef METHNAME
   { 0 }
 };
 
-static PyTypeObject group_pytype_skel = {
+static const PyTypeObject group_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "Group",                             /* @tp_name@ */
   sizeof(group_pyobj),                 /* @tp_basicsize@ */
@@ -1128,7 +1144,7 @@ static PyTypeObject group_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"Abstract base class for groups.",
+  "Abstract base class for groups.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -1136,9 +1152,9 @@ static PyTypeObject group_pytype_skel = {
   0,                                   /* @tp_weaklistoffset@ */
   0,                                   /* @tp_iter@ */
   0,                                   /* @tp_iternext@ */
-  group_pymethods,                     /* @tp_methods@ */
+  PYMETHODS(group),                    /* @tp_methods@ */
   0,                                   /* @tp_members@ */
-  group_pygetset,                      /* @tp_getset@ */
+  PYGETSET(group),                     /* @tp_getset@ */
   0,                                   /* @tp_base@ */
   0,                                   /* @tp_dict@ */
   0,                                   /* @tp_descr_get@ */
@@ -1161,7 +1177,7 @@ static PyObject *pgget_info(PyObject *me, void *hunoz)
   return (fginfo_pywrap(&dp, dhinfo_pytype));
 }
 
-static PyGetSetDef primegroup_pygetset[] = {
+static const PyGetSetDef primegroup_pygetset[] = {
 #define GETSETNAME(op, name) pg##op##_##name
   GET  (info,          "G.info -> information about the group")
 #undef GETSETNAME
@@ -1180,7 +1196,7 @@ static PyObject *primegroup_pynew(PyTypeObject *ty,
   return (group_dopywrap(ty, group_prime(FGINFO_DP(i))));
 }
 
-static PyTypeObject primegroup_pytype_skel = {
+static const PyTypeObject primegroup_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "PrimeGroup",                                /* @tp_name@ */
   sizeof(group_pyobj),                 /* @tp_basicsize@ */
@@ -1205,7 +1221,7 @@ static PyTypeObject primegroup_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"PrimeGroup(INFO): subgroups of prime fields.",
+  "PrimeGroup(INFO): subgroups of prime fields.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -1215,7 +1231,7 @@ static PyTypeObject primegroup_pytype_skel = {
   0,                                   /* @tp_iternext@ */
   0,                                   /* @tp_methods@ */
   0,                                   /* @tp_members@ */
-  primegroup_pygetset,                 /* @tp_getset@ */
+  PYGETSET(primegroup),                        /* @tp_getset@ */
   0,                                   /* @tp_base@ */
   0,                                   /* @tp_dict@ */
   0,                                   /* @tp_descr_get@ */
@@ -1238,7 +1254,7 @@ static PyObject *bgget_info(PyObject *me, void *hunoz)
   return (fginfo_pywrap(&dp, bindhinfo_pytype));
 }
 
-static PyGetSetDef bingroup_pygetset[] = {
+static const PyGetSetDef bingroup_pygetset[] = {
 #define GETSETNAME(op, name) bg##op##_##name
   GET  (info,          "G.info -> information about the group")
 #undef GETSETNAME
@@ -1257,7 +1273,7 @@ static PyObject *bingroup_pynew(PyTypeObject *ty,
   return (group_dopywrap(ty, group_binary(FGINFO_DP(i))));
 }
 
-static PyTypeObject bingroup_pytype_skel = {
+static const PyTypeObject bingroup_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "BinGroup",                          /* @tp_name@ */
   sizeof(group_pyobj),                 /* @tp_basicsize@ */
@@ -1282,7 +1298,7 @@ static PyTypeObject bingroup_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"BinGroup(INFO): subgroups of binary fields.",
+  "BinGroup(INFO): subgroups of binary fields.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -1292,7 +1308,7 @@ static PyTypeObject bingroup_pytype_skel = {
   0,                                   /* @tp_iternext@ */
   0,                                   /* @tp_methods@ */
   0,                                   /* @tp_members@ */
-  bingroup_pygetset,                   /* @tp_getset@ */
+  PYGETSET(bingroup),                  /* @tp_getset@ */
   0,                                   /* @tp_base@ */
   0,                                   /* @tp_dict@ */
   0,                                   /* @tp_descr_get@ */
@@ -1314,7 +1330,7 @@ static PyObject *egget_info(PyObject *me, void *hunoz)
   return (ecinfo_pywrap(&ei));
 }
 
-static PyGetSetDef ecgroup_pygetset[] = {
+static const PyGetSetDef ecgroup_pygetset[] = {
 #define GETSETNAME(op, name) eg##op##_##name
   GET  (info,          "G.info -> information about the group")
 #undef GETSETNAME
@@ -1335,7 +1351,7 @@ static PyObject *ecgroup_pynew(PyTypeObject *ty,
   return (group_dopywrap(ty, group_ec(&ei)));
 }
 
-static PyTypeObject ecgroup_pytype_skel = {
+static const PyTypeObject ecgroup_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "ECGroup",                           /* @tp_name@ */
   sizeof(group_pyobj),                 /* @tp_basicsize@ */
@@ -1360,7 +1376,7 @@ static PyTypeObject ecgroup_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"ECGroup(INFO): elliptic curve groups.",
+  "ECGroup(INFO): elliptic curve groups.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -1370,7 +1386,7 @@ static PyTypeObject ecgroup_pytype_skel = {
   0,                                   /* @tp_iternext@ */
   0,                                   /* @tp_methods@ */
   0,                                   /* @tp_members@ */
-  ecgroup_pygetset,                    /* @tp_getset@ */
+  PYGETSET(ecgroup),                   /* @tp_getset@ */
   0,                                   /* @tp_base@ */
   0,                                   /* @tp_dict@ */
   0,                                   /* @tp_descr_get@ */
@@ -1385,32 +1401,6 @@ static PyTypeObject ecgroup_pytype_skel = {
 
 /*----- Global stuff ------------------------------------------------------*/
 
-static PyMethodDef methods[] = {
-#define METHNAME(name) meth_##name
-  METH (_GE_frombuf,           "frombuf(BUF) -> X, REST")
-  METH (_GE_fromraw,           "fromraw(BUF) -> X, REST")
-  METH (_GE_fromstring,        "fromstring(STR) -> X, REST")
-  METH (_Group_parse,          "parse(STR) -> G, REST")
-  METH (_DHInfo_parse,         "parse(STR) -> D, REST")
-  METH (_BinDHInfo_parse,      "parse(STR) -> D, REST")
-  METH (_DHInfo__groupn,       0)
-  METH (_BinDHInfo__groupn,    0)
-  KWMETH(_DHInfo_generate,     "\
-generate(PBITS, [qbits = 0], [event = pgen_nullev],\n\
-        [rng = rand], [nsteps = 0]) -> D")
-  KWMETH(_DHInfo_genlimlee,    "\
-genlimlee(PBITS, QBITS, [event = pgen_nullev], [ievent = pgen_nullev],\n\
-         [rng = rand], [nsteps = 0], [subgroupp = True]) -> (D, [Q, ...])")
-  KWMETH(_DHInfo_gendsa,       "\
-gendsa(PBITS, QBITS, SEED, [event = pgen_nullev], [nsteps = 0])\n\
-  -> (D, SEED, COUNT)")
-  KWMETH(_DHInfo_genkcdsa,     "\
-gendsa(PBITS, QBITS, [event = pgen_nullev], [rng = rand], [nsteps = 0])\n\
-  -> (D, V)")
-#undef METHNAME
-  { 0 }
-};
-
 void group_pyinit(void)
 {
   INITTYPE(fginfo, root);
@@ -1421,7 +1411,6 @@ void group_pyinit(void)
   INITTYPE(primegroup, group);
   INITTYPE(bingroup, group);
   INITTYPE(ecgroup, group);
-  addmethods(methods);
 }
 
 void group_pyinsert(PyObject *mod)