*.c: Split the constant definitions into the various submodules.
[catacomb-python] / rand.c
diff --git a/rand.c b/rand.c
index 8ec3318..2f69336 100644 (file)
--- a/rand.c
+++ b/rand.c
@@ -80,16 +80,14 @@ end:
   return (-1);
 }
 
-static PyObject *grmeth_byte(PyObject *me, PyObject *arg)
+static PyObject *grmeth_byte(PyObject *me)
 {
-  if (!PyArg_ParseTuple(arg, ":byte")) return (0);
   if (grand_check(me)) return (0);
   return (PyInt_FromLong(grand_byte(GRAND_R(me))));
 }
 
-static PyObject *grmeth_word(PyObject *me, PyObject *arg)
+static PyObject *grmeth_word(PyObject *me)
 {
-  if (!PyArg_ParseTuple(arg, ":word")) return (0);
   if (grand_check(me)) return (0);
   return (getulong(grand_word(GRAND_R(me))));
 }
@@ -269,8 +267,8 @@ static const PyGetSetDef grand_pygetset[] = {
 
 static const PyMethodDef grand_pymethods[] = {
 #define METHNAME(name) grmeth_##name
-  METH (byte,          "R.byte() -> BYTE")
-  METH (word,          "R.word() -> WORD")
+  NAMETH(byte,         "R.byte() -> BYTE")
+  NAMETH(word,         "R.word() -> WORD")
   METH (block,         "R.block(N) -> STRING")
   KWMETH(mp,           "R.mp(bits, [or = 0]) -> MP")
   METH (range,         "R.range(MAX) -> INT")
@@ -284,7 +282,7 @@ static const PyMethodDef grand_pymethods[] = {
   { 0 }
 };
 
-static PyTypeObject grand_pytype_skel = {
+static const PyTypeObject grand_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "GRand",                             /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
@@ -341,7 +339,7 @@ static PyObject *lcrand_pynew(PyTypeObject *me, PyObject *arg, PyObject *kw)
   return (grand_dopywrap(lcrand_pytype, lcrand_create(n), f_freeme));
 }
 
-static PyTypeObject lcrand_pytype_skel = {
+static const PyTypeObject lcrand_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "LCRand",                            /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
@@ -398,7 +396,7 @@ static PyObject *fibrand_pynew(PyTypeObject *me, PyObject *arg, PyObject *kw)
   return (grand_dopywrap(fibrand_pytype, fibrand_create(n), f_freeme));
 }
 
-static PyTypeObject fibrand_pytype_skel = {
+static const PyTypeObject fibrand_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "FibRand",                           /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
@@ -448,21 +446,11 @@ static PyTypeObject fibrand_pytype_skel = {
 
 /*----- True random generator ---------------------------------------------*/
 
-static PyObject *trmeth_gate(PyObject *me, PyObject *arg)
-{
-  grand *r = GRAND_R(me);
-  if (!PyArg_ParseTuple(arg, ":gate")) return (0);
-  r->ops->misc(r, RAND_GATE);
-  RETURN_ME;
-}
+static PyObject *trmeth_gate(PyObject *me)
+  { grand *r = GRAND_R(me); r->ops->misc(GRAND_R(me), RAND_GATE); RETURN_ME; }
 
-static PyObject *trmeth_stretch(PyObject *me, PyObject *arg)
-{
-  grand *r = GRAND_R(me);
-  if (!PyArg_ParseTuple(arg, ":stretch")) return (0);
-  r->ops->misc(r, RAND_STRETCH);
-  RETURN_ME;
-}
+static PyObject *trmeth_stretch(PyObject *me)
+  { grand *r = GRAND_R(me); r->ops->misc(r, RAND_STRETCH); RETURN_ME; }
 
 static PyObject *trmeth_add(PyObject *me, PyObject *arg)
 {
@@ -495,13 +483,8 @@ end:
   return (0);
 }
 
-static PyObject *trmeth_timer(PyObject *me, PyObject *arg)
-{
-  grand *r = GRAND_R(me);
-  if (!PyArg_ParseTuple(arg, ":timer")) return (0);
-  r->ops->misc(r, RAND_TIMER);
-  RETURN_ME;
-}
+static PyObject *trmeth_timer(PyObject *me)
+  { grand *r = GRAND_R(me); r->ops->misc(r, RAND_TIMER); RETURN_ME; }
 
 static PyObject *truerand_pynew(PyTypeObject *ty,
                                PyObject *arg, PyObject *kw)
@@ -520,12 +503,12 @@ end:
 
 static const PyMethodDef truerand_pymethods[] = {
 #define METHNAME(name) trmeth_##name
-  METH (gate,          "R.gate()")
-  METH (stretch,       "R.stretch()")
+  NAMETH(gate,         "R.gate()")
+  NAMETH(stretch,      "R.stretch()")
   METH (key,           "R.key(BYTES)")
   METH (seed,          "R.seed(NBITS)")
   METH (add,           "R.add(BYTES, GOODBITS")
-  METH (timer,         "R.timer()")
+  NAMETH(timer,                "R.timer()")
 #undef METHNAME
   { 0 }
 };
@@ -543,7 +526,7 @@ static const PyGetSetDef truerand_pygetset[] = {
   { 0 }
 };
 
-static PyTypeObject truerand_pytype_skel = {
+static const PyTypeObject truerand_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "TrueRand",                          /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
@@ -754,13 +737,12 @@ static PyObject *gccrget_name(PyObject *me, void *hunoz)
 static PyObject *gccrget_keysz(PyObject *me, void *hunoz)
   { return (keysz_pywrap(GCCRAND_INFO(me)->keysz)); }
 
-static PyObject *gclrmeth_tell(PyObject *me, PyObject *arg)
+static PyObject *gclrmeth_tell(PyObject *me)
 {
   grand *r = GRAND_R(me);
   PyObject *rc = 0;
   kludge64 off;
 
-  if (!PyArg_ParseTuple(arg, ":tell")) return (0);
   r->ops->misc(r, SALSA20_TELLU64, &off);
   rc = getk64(off);
   return (rc);
@@ -786,13 +768,13 @@ static const PyGetSetDef gccrand_pygetset[] = {
 
 static const PyMethodDef gclatinrand_pymethods[] = {
 #define METHNAME(name) gclrmeth_##name
-  METH (tell,          "R.tell() -> OFF")
+  NAMETH(tell,         "R.tell() -> OFF")
   METH (seek,          "R.seek(OFF)")
 #undef METHNAME
   { 0 }
 };
 
-static PyTypeObject gccrand_pytype_skel = {
+static const PyTypeObject gccrand_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "GCCRand",                           /* @tp_name@ */
   sizeof(gccrand_pyobj),               /* @tp_basicsize@ */
@@ -840,7 +822,7 @@ static PyTypeObject gccrand_pytype_skel = {
   0                                    /* @tp_is_gc@ */
 };
 
-static PyTypeObject gcrand_pytype_skel = {
+static const PyTypeObject gcrand_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "GCRand",                            /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
@@ -888,7 +870,7 @@ static PyTypeObject gcrand_pytype_skel = {
   0                                    /* @tp_is_gc@ */
 };
 
-static PyTypeObject gclatinrand_pytype_skel = {
+static const PyTypeObject gclatinrand_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "GCLatinRand",                       /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
@@ -989,7 +971,7 @@ end:
   return (rc);
 }
 
-static PyTypeObject sslprf_pytype_skel = {
+static const PyTypeObject sslprf_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "SSLRand",                           /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
@@ -1038,7 +1020,7 @@ static PyTypeObject sslprf_pytype_skel = {
   0                                    /* @tp_is_gc@ */
 };
 
-static PyTypeObject tlsdx_pytype_skel = {
+static const PyTypeObject tlsdx_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "TLSDataExpansion",                  /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
@@ -1087,7 +1069,7 @@ static PyTypeObject tlsdx_pytype_skel = {
   0                                    /* @tp_is_gc@ */
 };
 
-static PyTypeObject tlsprf_pytype_skel = {
+static const PyTypeObject tlsprf_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "TLSPRF",                            /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
@@ -1168,7 +1150,7 @@ static const PyGetSetDef dsarand_pygetset[] = {
   { 0 }
 };
 
-static PyTypeObject dsarand_pytype_skel = {
+static const PyTypeObject dsarand_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "DSARand",                           /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
@@ -1234,11 +1216,8 @@ end:
   return (rc);
 }
 
-static PyObject *bbsmeth_step(PyObject *me, PyObject *arg)
-{
-  grand *r = GRAND_R(me); if (!PyArg_ParseTuple(arg, ":step")) return (0);
-  r->ops->misc(r, BBS_STEP); RETURN_ME;
-}
+static PyObject *bbsmeth_step(PyObject *me)
+  { grand *r = GRAND_R(me); r->ops->misc(r, BBS_STEP); RETURN_ME; }
 
 static PyObject *bbsmeth_bits(PyObject *me, PyObject *arg)
 {
@@ -1250,11 +1229,8 @@ end:
   return (0);
 }
 
-static PyObject *bbsmeth_wrap(PyObject *me, PyObject *arg)
-{
-  grand *r = GRAND_R(me); if (!PyArg_ParseTuple(arg, ":wrap")) return (0);
-  r->ops->misc(r, BBS_WRAP); RETURN_ME;
-}
+static PyObject *bbsmeth_wrap(PyObject *me)
+  { grand *r = GRAND_R(me); r->ops->misc(r, BBS_WRAP); RETURN_ME; }
 
 static PyObject *bbsget_n(PyObject *me, void *hunoz)
 {
@@ -1284,9 +1260,9 @@ static PyObject *bbsget_stepsz(PyObject *me, void *hunoz)
 
 static const PyMethodDef bbs_pymethods[] = {
 #define METHNAME(name) bbsmeth_##name
-  METH (step,          "R.step(): steps the generator (not useful)")
+  NAMETH(step,         "R.step(): steps the generator (not useful)")
   METH (bits,   "R.bits(N) -> W: returns N bits (<= 32) from the generator")
-  METH (wrap,          "R.wrap(): flushes unused bits in internal buffer")
+  NAMETH(wrap,         "R.wrap(): flushes unused bits in internal buffer")
 #undef METHNAME
   { 0 }
 };
@@ -1300,7 +1276,7 @@ static const PyGetSetDef bbs_pygetset[] = {
   { 0 }
 };
 
-static PyTypeObject bbs_pytype_skel = {
+static const PyTypeObject bbs_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "BlumBlumShub",                      /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
@@ -1462,7 +1438,7 @@ static const PyGetSetDef bbspriv_pygetset[] = {
   { 0 }
 };
 
-static PyTypeObject bbspriv_pytype_skel = {
+static const PyTypeObject bbspriv_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "BBSPriv",                           /* @tp_name@ */
   sizeof(bbspriv_pyobj),               /* @tp_basicsize@ */
@@ -1513,6 +1489,11 @@ static PyTypeObject bbspriv_pytype_skel = {
 
 /*----- Global stuff ------------------------------------------------------*/
 
+static const struct nameval consts[] = {
+  CONST(RAND_IBITS),
+  { 0 }
+};
+
 void rand_pyinit(void)
 {
   INITTYPE(grand, root);
@@ -1554,6 +1535,7 @@ void rand_pyinsert(PyObject *mod)
   gccrands_dict = gccrands(); Py_INCREF(gccrands_dict);
   INSERT("gccrands", gccrands_dict);
   INSERT("rand", rand_pyobj);
+  setconstants(mod, consts);
 }
 
 /*----- That's all, folks -------------------------------------------------*/