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));
}
};
static const PyTypeObject grand_pytype_skel = {
- PyObject_HEAD_INIT(0) 0, /* Header */
+ PyVarObject_HEAD_INIT(0, 0) /* Header */
"GRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
}
static const PyTypeObject lcrand_pytype_skel = {
- PyObject_HEAD_INIT(0) 0, /* Header */
+ PyVarObject_HEAD_INIT(0, 0) /* Header */
"LCRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
}
static const PyTypeObject fibrand_pytype_skel = {
- PyObject_HEAD_INIT(0) 0, /* Header */
+ PyVarObject_HEAD_INIT(0, 0) /* Header */
"FibRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
};
static const PyTypeObject truerand_pytype_skel = {
- PyObject_HEAD_INIT(0) 0, /* Header */
+ PyVarObject_HEAD_INIT(0, 0) /* Header */
"TrueRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
};
static const PyTypeObject gccrand_pytype_skel = {
- PyObject_HEAD_INIT(0) 0, /* Header */
+ PyVarObject_HEAD_INIT(0, 0) /* Header */
"GCCRand", /* @tp_name@ */
sizeof(gccrand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
};
static const PyTypeObject gcrand_pytype_skel = {
- PyObject_HEAD_INIT(0) 0, /* Header */
+ PyVarObject_HEAD_INIT(0, 0) /* Header */
"GCRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
};
static const PyTypeObject gclatinrand_pytype_skel = {
- PyObject_HEAD_INIT(0) 0, /* Header */
+ PyVarObject_HEAD_INIT(0, 0) /* Header */
"GCLatinRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
}
static const PyTypeObject sslprf_pytype_skel = {
- PyObject_HEAD_INIT(0) 0, /* Header */
+ PyVarObject_HEAD_INIT(0, 0) /* Header */
"SSLRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
};
static const PyTypeObject tlsdx_pytype_skel = {
- PyObject_HEAD_INIT(0) 0, /* Header */
+ PyVarObject_HEAD_INIT(0, 0) /* Header */
"TLSDataExpansion", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
};
static const PyTypeObject tlsprf_pytype_skel = {
- PyObject_HEAD_INIT(0) 0, /* Header */
+ PyVarObject_HEAD_INIT(0, 0) /* Header */
"TLSPRF", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
};
static const PyTypeObject dsarand_pytype_skel = {
- PyObject_HEAD_INIT(0) 0, /* Header */
+ PyVarObject_HEAD_INIT(0, 0) /* Header */
"DSARand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
};
static const PyTypeObject bbs_pytype_skel = {
- PyObject_HEAD_INIT(0) 0, /* Header */
+ PyVarObject_HEAD_INIT(0, 0) /* Header */
"BlumBlumShub", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
};
static const PyTypeObject bbspriv_pytype_skel = {
- PyObject_HEAD_INIT(0) 0, /* Header */
+ PyVarObject_HEAD_INIT(0, 0) /* Header */
"BBSPriv", /* @tp_name@ */
sizeof(bbspriv_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
/*----- Global stuff ------------------------------------------------------*/
+static const struct nameval consts[] = {
+ CONST(RAND_IBITS),
+ { 0 }
+};
+
void rand_pyinit(void)
{
INITTYPE(grand, root);
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)
{
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 -------------------------------------------------*/