*.c: Use the new `Py_hash_t' type.
[catacomb-python] / rand.c
diff --git a/rand.c b/rand.c
index 58c851c..ed421e1 100644 (file)
--- a/rand.c
+++ b/rand.c
@@ -65,7 +65,8 @@ PyObject *grand_pywrap(grand *r, unsigned f)
   else if (STRCMP(r->ops->name, ==, "sslprf")) ty = sslprf_pytype;
   else if (STRCMP(r->ops->name, ==, "tlsdx")) ty = tlsdx_pytype;
   else if (STRCMP(r->ops->name, ==, "tlsprf")) ty = tlsprf_pytype;
-  else if ((ob = PyDict_GetItemString(gccrands_dict, r->ops->name)) != 0)
+  else if ((ob = PyMapping_GetItemString
+                  (gccrands_dict, (/*unconst*/ char *)r->ops->name)) != 0)
     ty = (PyTypeObject *)ob;
   return (grand_dopywrap(ty, r, f));
 }
@@ -282,8 +283,8 @@ static const PyMethodDef grand_pymethods[] = {
   { 0 }
 };
 
-static PyTypeObject grand_pytype_skel = {
-  PyObject_HEAD_INIT(0) 0,             /* Header */
+static const PyTypeObject grand_pytype_skel = {
+  PyVarObject_HEAD_INIT(0, 0)          /* Header */
   "GRand",                             /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
@@ -339,8 +340,8 @@ 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 = {
-  PyObject_HEAD_INIT(0) 0,             /* Header */
+static const PyTypeObject lcrand_pytype_skel = {
+  PyVarObject_HEAD_INIT(0, 0)          /* Header */
   "LCRand",                            /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
@@ -396,8 +397,8 @@ 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 = {
-  PyObject_HEAD_INIT(0) 0,             /* Header */
+static const PyTypeObject fibrand_pytype_skel = {
+  PyVarObject_HEAD_INIT(0, 0)          /* Header */
   "FibRand",                           /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
@@ -526,8 +527,8 @@ static const PyGetSetDef truerand_pygetset[] = {
   { 0 }
 };
 
-static PyTypeObject truerand_pytype_skel = {
-  PyObject_HEAD_INIT(0) 0,             /* Header */
+static const PyTypeObject truerand_pytype_skel = {
+  PyVarObject_HEAD_INIT(0, 0)          /* Header */
   "TrueRand",                          /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
@@ -774,8 +775,8 @@ static const PyMethodDef gclatinrand_pymethods[] = {
   { 0 }
 };
 
-static PyTypeObject gccrand_pytype_skel = {
-  PyObject_HEAD_INIT(0) 0,             /* Header */
+static const PyTypeObject gccrand_pytype_skel = {
+  PyVarObject_HEAD_INIT(0, 0)          /* Header */
   "GCCRand",                           /* @tp_name@ */
   sizeof(gccrand_pyobj),               /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
@@ -822,8 +823,8 @@ static PyTypeObject gccrand_pytype_skel = {
   0                                    /* @tp_is_gc@ */
 };
 
-static PyTypeObject gcrand_pytype_skel = {
-  PyObject_HEAD_INIT(0) 0,             /* Header */
+static const PyTypeObject gcrand_pytype_skel = {
+  PyVarObject_HEAD_INIT(0, 0)          /* Header */
   "GCRand",                            /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
@@ -870,8 +871,8 @@ static PyTypeObject gcrand_pytype_skel = {
   0                                    /* @tp_is_gc@ */
 };
 
-static PyTypeObject gclatinrand_pytype_skel = {
-  PyObject_HEAD_INIT(0) 0,             /* Header */
+static const PyTypeObject gclatinrand_pytype_skel = {
+  PyVarObject_HEAD_INIT(0, 0)          /* Header */
   "GCLatinRand",                       /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
@@ -971,8 +972,8 @@ end:
   return (rc);
 }
 
-static PyTypeObject sslprf_pytype_skel = {
-  PyObject_HEAD_INIT(0) 0,             /* Header */
+static const PyTypeObject sslprf_pytype_skel = {
+  PyVarObject_HEAD_INIT(0, 0)          /* Header */
   "SSLRand",                           /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
@@ -1020,8 +1021,8 @@ static PyTypeObject sslprf_pytype_skel = {
   0                                    /* @tp_is_gc@ */
 };
 
-static PyTypeObject tlsdx_pytype_skel = {
-  PyObject_HEAD_INIT(0) 0,             /* Header */
+static const PyTypeObject tlsdx_pytype_skel = {
+  PyVarObject_HEAD_INIT(0, 0)          /* Header */
   "TLSDataExpansion",                  /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
@@ -1069,8 +1070,8 @@ static PyTypeObject tlsdx_pytype_skel = {
   0                                    /* @tp_is_gc@ */
 };
 
-static PyTypeObject tlsprf_pytype_skel = {
-  PyObject_HEAD_INIT(0) 0,             /* Header */
+static const PyTypeObject tlsprf_pytype_skel = {
+  PyVarObject_HEAD_INIT(0, 0)          /* Header */
   "TLSPRF",                            /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
@@ -1150,8 +1151,8 @@ static const PyGetSetDef dsarand_pygetset[] = {
   { 0 }
 };
 
-static PyTypeObject dsarand_pytype_skel = {
-  PyObject_HEAD_INIT(0) 0,             /* Header */
+static const PyTypeObject dsarand_pytype_skel = {
+  PyVarObject_HEAD_INIT(0, 0)          /* Header */
   "DSARand",                           /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
@@ -1276,8 +1277,8 @@ static const PyGetSetDef bbs_pygetset[] = {
   { 0 }
 };
 
-static PyTypeObject bbs_pytype_skel = {
-  PyObject_HEAD_INIT(0) 0,             /* Header */
+static const PyTypeObject bbs_pytype_skel = {
+  PyVarObject_HEAD_INIT(0, 0)          /* Header */
   "BlumBlumShub",                      /* @tp_name@ */
   sizeof(grand_pyobj),                 /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
@@ -1438,8 +1439,8 @@ static const PyGetSetDef bbspriv_pygetset[] = {
   { 0 }
 };
 
-static PyTypeObject bbspriv_pytype_skel = {
-  PyObject_HEAD_INIT(0) 0,             /* Header */
+static const PyTypeObject bbspriv_pytype_skel = {
+  PyVarObject_HEAD_INIT(0, 0)          /* Header */
   "BBSPriv",                           /* @tp_name@ */
   sizeof(bbspriv_pyobj),               /* @tp_basicsize@ */
   0,                                   /* @tp_itemsize@ */
@@ -1489,6 +1490,11 @@ static PyTypeObject bbspriv_pytype_skel = {
 
 /*----- Global stuff ------------------------------------------------------*/
 
+static const struct nameval consts[] = {
+  CONST(RAND_IBITS),
+  { 0 }
+};
+
 void rand_pyinit(void)
 {
   INITTYPE(grand, root);
@@ -1508,8 +1514,10 @@ void rand_pyinit(void)
   rand_seed(RAND_GLOBAL, 160);
 }
 
-#define gccrand gccrand_info
-GEN(gccrands, crand)
+static const char *crand_namefn(const void *p)
+  { const gccrand_info *const *cls = p; return (*cls ? (*cls)->name : 0); }
+static PyObject *crand_valfn(const void *p)
+  { const gccrand_info *const *cls = p; return (gccrand_pywrap(*cls)); }
 
 void rand_pyinsert(PyObject *mod)
 {
@@ -1527,9 +1535,11 @@ void rand_pyinsert(PyObject *mod)
   INSERT("GCRand", gcrand_pytype);
   INSERT("GCLatinRand", gclatinrand_pytype);
   rand_pyobj = grand_pywrap(&rand_global, 0); Py_INCREF(rand_pyobj);
-  gccrands_dict = gccrands(); Py_INCREF(gccrands_dict);
-  INSERT("gccrands", gccrands_dict);
+  gccrands_dict = make_algtab(gcrandtab, sizeof(gccrand_info *),
+                             crand_namefn, crand_valfn);
+  INSERT("gccrands", gccrands_dict); Py_INCREF(gccrands_dict);
   INSERT("rand", rand_pyobj);
+  setconstants(mod, consts);
 }
 
 /*----- That's all, folks -------------------------------------------------*/