~mdw
/
catacomb-python
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
*.c: Use the new `Py_hash_t' type.
[catacomb-python]
/
rand.c
diff --git
a/rand.c
b/rand.c
index
12ba834
..
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 (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));
}
ty = (PyTypeObject *)ob;
return (grand_dopywrap(ty, r, f));
}
@@
-80,16
+81,14
@@
end:
return (-1);
}
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))));
}
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))));
}
if (grand_check(me)) return (0);
return (getulong(grand_word(GRAND_R(me))));
}
@@
-259,7
+258,7
@@
static PyObject *grget_name(PyObject *me, void *hunoz)
static PyObject *grget_cryptop(PyObject *me, void *hunoz)
{ return (grand_check(me) ? 0 : getbool(GRAND_R(me)->ops->f & GRAND_CRYPTO)); }
static PyObject *grget_cryptop(PyObject *me, void *hunoz)
{ return (grand_check(me) ? 0 : getbool(GRAND_R(me)->ops->f & GRAND_CRYPTO)); }
-static PyGetSetDef grand_pygetset[] = {
+static
const
PyGetSetDef grand_pygetset[] = {
#define GETSETNAME(op, name) gr##op##_##name
GET (name, "R.name -> name of this kind of generator")
GET (cryptop, "R.cryptop -> flag: cryptographically strong?")
#define GETSETNAME(op, name) gr##op##_##name
GET (name, "R.name -> name of this kind of generator")
GET (cryptop, "R.cryptop -> flag: cryptographically strong?")
@@
-267,10
+266,10
@@
static PyGetSetDef grand_pygetset[] = {
{ 0 }
};
{ 0 }
};
-static PyMethodDef grand_pymethods[] = {
+static
const
PyMethodDef grand_pymethods[] = {
#define METHNAME(name) grmeth_##name
#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")
METH (block, "R.block(N) -> STRING")
KWMETH(mp, "R.mp(bits, [or = 0]) -> MP")
METH (range, "R.range(MAX) -> INT")
@@
-284,8
+283,8
@@
static PyMethodDef grand_pymethods[] = {
{ 0 }
};
{ 0 }
};
-static PyTypeObject grand_pytype_skel = {
- Py
Object_HEAD_INIT(0) 0,
/* Header */
+static
const
PyTypeObject grand_pytype_skel = {
+ Py
VarObject_HEAD_INIT(0, 0)
/* Header */
"GRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
"GRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
@@
-317,9
+316,9
@@
static PyTypeObject grand_pytype_skel = {
0, /* @tp_weaklistoffset@ */
0, /* @tp_iter@ */
0, /* @tp_iternext@ */
0, /* @tp_weaklistoffset@ */
0, /* @tp_iter@ */
0, /* @tp_iternext@ */
-
grand_pymethods,
/* @tp_methods@ */
+
PYMETHODS(grand),
/* @tp_methods@ */
0, /* @tp_members@ */
0, /* @tp_members@ */
-
grand_pygetset,
/* @tp_getset@ */
+
PYGETSET(grand),
/* @tp_getset@ */
0, /* @tp_base@ */
0, /* @tp_dict@ */
0, /* @tp_descr_get@ */
0, /* @tp_base@ */
0, /* @tp_dict@ */
0, /* @tp_descr_get@ */
@@
-341,8
+340,8
@@
static PyObject *lcrand_pynew(PyTypeObject *me, PyObject *arg, PyObject *kw)
return (grand_dopywrap(lcrand_pytype, lcrand_create(n), f_freeme));
}
return (grand_dopywrap(lcrand_pytype, lcrand_create(n), f_freeme));
}
-static PyTypeObject lcrand_pytype_skel = {
- Py
Object_HEAD_INIT(0) 0,
/* Header */
+static
const
PyTypeObject lcrand_pytype_skel = {
+ Py
VarObject_HEAD_INIT(0, 0)
/* Header */
"LCRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
"LCRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
@@
-398,8
+397,8
@@
static PyObject *fibrand_pynew(PyTypeObject *me, PyObject *arg, PyObject *kw)
return (grand_dopywrap(fibrand_pytype, fibrand_create(n), f_freeme));
}
return (grand_dopywrap(fibrand_pytype, fibrand_create(n), f_freeme));
}
-static PyTypeObject fibrand_pytype_skel = {
- Py
Object_HEAD_INIT(0) 0,
/* Header */
+static
const
PyTypeObject fibrand_pytype_skel = {
+ Py
VarObject_HEAD_INIT(0, 0)
/* Header */
"FibRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
"FibRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
@@
-448,21
+447,11
@@
static PyTypeObject fibrand_pytype_skel = {
/*----- True random generator ---------------------------------------------*/
/*----- 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)
{
static PyObject *trmeth_add(PyObject *me, PyObject *arg)
{
@@
-495,13
+484,8
@@
end:
return (0);
}
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)
static PyObject *truerand_pynew(PyTypeObject *ty,
PyObject *arg, PyObject *kw)
@@
-518,14
+502,14
@@
end:
return (rc);
}
return (rc);
}
-static PyMethodDef truerand_pymethods[] = {
+static
const
PyMethodDef truerand_pymethods[] = {
#define METHNAME(name) trmeth_##name
#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 (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 }
};
#undef METHNAME
{ 0 }
};
@@
-536,15
+520,15
@@
static PyObject *trget_goodbits(PyObject *me, void *hunoz)
return (PyInt_FromLong(r->ops->misc(r, RAND_GOODBITS)));
}
return (PyInt_FromLong(r->ops->misc(r, RAND_GOODBITS)));
}
-static PyGetSetDef truerand_pygetset[] = {
+static
const
PyGetSetDef truerand_pygetset[] = {
#define GETSETNAME(op, name) tr##op##_##name
GET (goodbits, "R.goodbits -> good bits of entropy remaining")
#undef GETSETNAME
{ 0 }
};
#define GETSETNAME(op, name) tr##op##_##name
GET (goodbits, "R.goodbits -> good bits of entropy remaining")
#undef GETSETNAME
{ 0 }
};
-static PyTypeObject truerand_pytype_skel = {
- Py
Object_HEAD_INIT(0) 0,
/* Header */
+static
const
PyTypeObject truerand_pytype_skel = {
+ Py
VarObject_HEAD_INIT(0, 0)
/* Header */
"TrueRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
"TrueRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
@@
-576,9
+560,9
@@
static PyTypeObject truerand_pytype_skel = {
0, /* @tp_weaklistoffset@ */
0, /* @tp_iter@ */
0, /* @tp_iternext@ */
0, /* @tp_weaklistoffset@ */
0, /* @tp_iter@ */
0, /* @tp_iternext@ */
-
truerand_pymethods,
/* @tp_methods@ */
+
PYMETHODS(truerand),
/* @tp_methods@ */
0, /* @tp_members@ */
0, /* @tp_members@ */
-
truerand_pygetset,
/* @tp_getset@ */
+
PYGETSET(truerand),
/* @tp_getset@ */
0, /* @tp_base@ */
0, /* @tp_dict@ */
0, /* @tp_descr_get@ */
0, /* @tp_base@ */
0, /* @tp_dict@ */
0, /* @tp_descr_get@ */
@@
-754,13
+738,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 *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;
{
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);
r->ops->misc(r, SALSA20_TELLU64, &off);
rc = getk64(off);
return (rc);
@@
-776,7
+759,7
@@
static PyObject *gclrmeth_seek(PyObject *me, PyObject *arg)
RETURN_ME;
}
RETURN_ME;
}
-static PyGetSetDef gccrand_pygetset[] = {
+static
const
PyGetSetDef gccrand_pygetset[] = {
#define GETSETNAME(op, name) gccr##op##_##name
GET (keysz, "CR.keysz -> acceptable key sizes")
GET (name, "CR.name -> name of this kind of generator")
#define GETSETNAME(op, name) gccr##op##_##name
GET (keysz, "CR.keysz -> acceptable key sizes")
GET (name, "CR.name -> name of this kind of generator")
@@
-784,16
+767,16
@@
static PyGetSetDef gccrand_pygetset[] = {
{ 0 }
};
{ 0 }
};
-static PyMethodDef gclatinrand_pymethods[] = {
+static
const
PyMethodDef gclatinrand_pymethods[] = {
#define METHNAME(name) gclrmeth_##name
#define METHNAME(name) gclrmeth_##name
-
METH (tell,
"R.tell() -> OFF")
+
NAMETH(tell,
"R.tell() -> OFF")
METH (seek, "R.seek(OFF)")
#undef METHNAME
{ 0 }
};
METH (seek, "R.seek(OFF)")
#undef METHNAME
{ 0 }
};
-static PyTypeObject gccrand_pytype_skel = {
- Py
Object_HEAD_INIT(0) 0,
/* Header */
+static
const
PyTypeObject gccrand_pytype_skel = {
+ Py
VarObject_HEAD_INIT(0, 0)
/* Header */
"GCCRand", /* @tp_name@ */
sizeof(gccrand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
"GCCRand", /* @tp_name@ */
sizeof(gccrand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
@@
-827,7
+810,7
@@
static PyTypeObject gccrand_pytype_skel = {
0, /* @tp_iternext@ */
0, /* @tp_methods@ */
0, /* @tp_members@ */
0, /* @tp_iternext@ */
0, /* @tp_methods@ */
0, /* @tp_members@ */
-
gccrand_pygetset,
/* @tp_getset@ */
+
PYGETSET(gccrand),
/* @tp_getset@ */
0, /* @tp_base@ */
0, /* @tp_dict@ */
0, /* @tp_descr_get@ */
0, /* @tp_base@ */
0, /* @tp_dict@ */
0, /* @tp_descr_get@ */
@@
-840,8
+823,8
@@
static PyTypeObject gccrand_pytype_skel = {
0 /* @tp_is_gc@ */
};
0 /* @tp_is_gc@ */
};
-static PyTypeObject gcrand_pytype_skel = {
- Py
Object_HEAD_INIT(0) 0,
/* Header */
+static
const
PyTypeObject gcrand_pytype_skel = {
+ Py
VarObject_HEAD_INIT(0, 0)
/* Header */
"GCRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
"GCRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
@@
-888,8
+871,8
@@
static PyTypeObject gcrand_pytype_skel = {
0 /* @tp_is_gc@ */
};
0 /* @tp_is_gc@ */
};
-static PyTypeObject gclatinrand_pytype_skel = {
- Py
Object_HEAD_INIT(0) 0,
/* Header */
+static
const
PyTypeObject gclatinrand_pytype_skel = {
+ Py
VarObject_HEAD_INIT(0, 0)
/* Header */
"GCLatinRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
"GCLatinRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
@@
-921,7
+904,7
@@
static PyTypeObject gclatinrand_pytype_skel = {
0, /* @tp_weaklistoffset@ */
0, /* @tp_iter@ */
0, /* @tp_iternext@ */
0, /* @tp_weaklistoffset@ */
0, /* @tp_iter@ */
0, /* @tp_iternext@ */
-
gclatinrand_pymethods,
/* @tp_methods@ */
+
PYMETHODS(gclatinrand),
/* @tp_methods@ */
0, /* @tp_members@ */
0, /* @tp_getset@ */
0, /* @tp_base@ */
0, /* @tp_members@ */
0, /* @tp_getset@ */
0, /* @tp_base@ */
@@
-989,8
+972,8
@@
end:
return (rc);
}
return (rc);
}
-static PyTypeObject sslprf_pytype_skel = {
- Py
Object_HEAD_INIT(0) 0,
/* Header */
+static
const
PyTypeObject sslprf_pytype_skel = {
+ Py
VarObject_HEAD_INIT(0, 0)
/* Header */
"SSLRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
"SSLRand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
@@
-1038,8
+1021,8
@@
static PyTypeObject sslprf_pytype_skel = {
0 /* @tp_is_gc@ */
};
0 /* @tp_is_gc@ */
};
-static PyTypeObject tlsdx_pytype_skel = {
- Py
Object_HEAD_INIT(0) 0,
/* Header */
+static
const
PyTypeObject tlsdx_pytype_skel = {
+ Py
VarObject_HEAD_INIT(0, 0)
/* Header */
"TLSDataExpansion", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
"TLSDataExpansion", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
@@
-1087,8
+1070,8
@@
static PyTypeObject tlsdx_pytype_skel = {
0 /* @tp_is_gc@ */
};
0 /* @tp_is_gc@ */
};
-static PyTypeObject tlsprf_pytype_skel = {
- Py
Object_HEAD_INIT(0) 0,
/* Header */
+static
const
PyTypeObject tlsprf_pytype_skel = {
+ Py
VarObject_HEAD_INIT(0, 0)
/* Header */
"TLSPRF", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
"TLSPRF", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
@@
-1161,15
+1144,15
@@
static PyObject *drget_seed(PyObject *me, void *hunoz)
return (rc);
}
return (rc);
}
-static PyGetSetDef dsarand_pygetset[] = {
+static
const
PyGetSetDef dsarand_pygetset[] = {
#define GETSETNAME(op, name) dr##op##_##name
GET (seed, "R.seed -> current generator seed")
#undef GETSETNAME
{ 0 }
};
#define GETSETNAME(op, name) dr##op##_##name
GET (seed, "R.seed -> current generator seed")
#undef GETSETNAME
{ 0 }
};
-static PyTypeObject dsarand_pytype_skel = {
- Py
Object_HEAD_INIT(0) 0,
/* Header */
+static
const
PyTypeObject dsarand_pytype_skel = {
+ Py
VarObject_HEAD_INIT(0, 0)
/* Header */
"DSARand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
"DSARand", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
@@
-1203,7
+1186,7
@@
static PyTypeObject dsarand_pytype_skel = {
0, /* @tp_iternext@ */
0, /* @tp_methods@ */
0, /* @tp_members@ */
0, /* @tp_iternext@ */
0, /* @tp_methods@ */
0, /* @tp_members@ */
-
dsarand_pygetset,
/* @tp_getset@ */
+
PYGETSET(dsarand),
/* @tp_getset@ */
0, /* @tp_base@ */
0, /* @tp_dict@ */
0, /* @tp_descr_get@ */
0, /* @tp_base@ */
0, /* @tp_dict@ */
0, /* @tp_descr_get@ */
@@
-1234,11
+1217,8
@@
end:
return (rc);
}
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)
{
static PyObject *bbsmeth_bits(PyObject *me, PyObject *arg)
{
@@
-1250,11
+1230,8
@@
end:
return (0);
}
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)
{
static PyObject *bbsget_n(PyObject *me, void *hunoz)
{
@@
-1282,16
+1259,16
@@
static PyObject *bbsget_stepsz(PyObject *me, void *hunoz)
return (PyInt_FromLong(r->ops->misc(r, BBS_STEPSZ)));
}
return (PyInt_FromLong(r->ops->misc(r, BBS_STEPSZ)));
}
-static PyMethodDef bbs_pymethods[] = {
+static
const
PyMethodDef bbs_pymethods[] = {
#define METHNAME(name) bbsmeth_##name
#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 (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 }
};
#undef METHNAME
{ 0 }
};
-static PyGetSetDef bbs_pygetset[] = {
+static
const
PyGetSetDef bbs_pygetset[] = {
#define GETSETNAME(op, name) bbs##op##_##name
GET (n, "R.n -> Blum modulus")
GETSET(x, "R.x -> current seed value")
#define GETSETNAME(op, name) bbs##op##_##name
GET (n, "R.n -> Blum modulus")
GETSET(x, "R.x -> current seed value")
@@
-1300,8
+1277,8
@@
static PyGetSetDef bbs_pygetset[] = {
{ 0 }
};
{ 0 }
};
-static PyTypeObject bbs_pytype_skel = {
- Py
Object_HEAD_INIT(0) 0,
/* Header */
+static
const
PyTypeObject bbs_pytype_skel = {
+ Py
VarObject_HEAD_INIT(0, 0)
/* Header */
"BlumBlumShub", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
"BlumBlumShub", /* @tp_name@ */
sizeof(grand_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
@@
-1333,9
+1310,9
@@
static PyTypeObject bbs_pytype_skel = {
0, /* @tp_weaklistoffset@ */
0, /* @tp_iter@ */
0, /* @tp_iternext@ */
0, /* @tp_weaklistoffset@ */
0, /* @tp_iter@ */
0, /* @tp_iternext@ */
-
bbs_pymethods,
/* @tp_methods@ */
+
PYMETHODS(bbs),
/* @tp_methods@ */
0, /* @tp_members@ */
0, /* @tp_members@ */
-
bbs_pygetset,
/* @tp_getset@ */
+
PYGETSET(bbs),
/* @tp_getset@ */
0, /* @tp_base@ */
0, /* @tp_dict@ */
0, /* @tp_descr_get@ */
0, /* @tp_base@ */
0, /* @tp_dict@ */
0, /* @tp_descr_get@ */
@@
-1381,8
+1358,7
@@
end:
return ((PyObject *)rc);
}
return ((PyObject *)rc);
}
-static PyObject *meth__BBSPriv_generate(PyObject *me,
- PyObject *arg, PyObject *kw)
+static PyObject *bpmeth_generate(PyObject *me, PyObject *arg, PyObject *kw)
{
bbs_priv bp = { 0 };
mp *x = MP_TWO;
{
bbs_priv bp = { 0 };
mp *x = MP_TWO;
@@
-1391,12
+1367,12
@@
static PyObject *meth__BBSPriv_generate(PyObject *me,
unsigned nbits, n = 0;
grand *r = &rand_global;
static const char *const kwlist[] =
unsigned nbits, n = 0;
grand *r = &rand_global;
static const char *const kwlist[] =
- { "
class", "
nbits", "event", "rng", "nsteps", "seed", 0 };
+ { "nbits", "event", "rng", "nsteps", "seed", 0 };
bbspriv_pyobj *rc = 0;
evt.exc = &exc;
bbspriv_pyobj *rc = 0;
evt.exc = &exc;
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O
O
&|O&O&O&O&:generate", KWLIST,
-
&me,
convuint, &nbits, convpgev, &evt,
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|O&O&O&O&:generate", KWLIST,
+ convuint, &nbits, convpgev, &evt,
convgrand, &r, convuint, &n, convmp, &x))
goto end;
if (bbs_gen(&bp, nbits, r, n, evt.ev.proc, evt.ev.ctx))
convgrand, &r, convuint, &n, convmp, &x))
goto end;
if (bbs_gen(&bp, nbits, r, n, evt.ev.proc, evt.ev.ctx))
@@
-1444,15
+1420,17
@@
static PyObject *bpget_p(PyObject *me, void *hunoz)
static PyObject *bpget_q(PyObject *me, void *hunoz)
{ return (mp_pywrap(MP_COPY(BBSPRIV_BP(me)->q))); }
static PyObject *bpget_q(PyObject *me, void *hunoz)
{ return (mp_pywrap(MP_COPY(BBSPRIV_BP(me)->q))); }
-static PyMethodDef bbspriv_pymethods[] = {
+static
const
PyMethodDef bbspriv_pymethods[] = {
#define METHNAME(name) bpmeth_##name
METH (ff, "R.ff(N): fast-forward N places")
METH (rew, "R.rew(N): rewind N places")
#define METHNAME(name) bpmeth_##name
METH (ff, "R.ff(N): fast-forward N places")
METH (rew, "R.rew(N): rewind N places")
+ KWSMTH(generate, "generate(NBITS, [event = pgen_nullev], "
+ "[rng = rand], [nsteps = 0], [seed = 2]) -> R")
#undef METHNAME
{ 0 }
};
#undef METHNAME
{ 0 }
};
-static PyGetSetDef bbspriv_pygetset[] = {
+static
const
PyGetSetDef bbspriv_pygetset[] = {
#define GETSETNAME(op, name) bp##op##_##name
GET (n, "R.n -> Blum modulus")
GET (p, "R.p -> one of the factors of the modulus")
#define GETSETNAME(op, name) bp##op##_##name
GET (n, "R.n -> Blum modulus")
GET (p, "R.p -> one of the factors of the modulus")
@@
-1461,8
+1439,8
@@
static PyGetSetDef bbspriv_pygetset[] = {
{ 0 }
};
{ 0 }
};
-static PyTypeObject bbspriv_pytype_skel = {
- Py
Object_HEAD_INIT(0) 0,
/* Header */
+static
const
PyTypeObject bbspriv_pytype_skel = {
+ Py
VarObject_HEAD_INIT(0, 0)
/* Header */
"BBSPriv", /* @tp_name@ */
sizeof(bbspriv_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
"BBSPriv", /* @tp_name@ */
sizeof(bbspriv_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
@@
-1495,9
+1473,9
@@
static PyTypeObject bbspriv_pytype_skel = {
0, /* @tp_weaklistoffset@ */
0, /* @tp_iter@ */
0, /* @tp_iternext@ */
0, /* @tp_weaklistoffset@ */
0, /* @tp_iter@ */
0, /* @tp_iternext@ */
-
bbspriv_pymethods,
/* @tp_methods@ */
+
PYMETHODS(bbspriv),
/* @tp_methods@ */
0, /* @tp_members@ */
0, /* @tp_members@ */
-
bbspriv_pygetset,
/* @tp_getset@ */
+
PYGETSET(bbspriv),
/* @tp_getset@ */
0, /* @tp_base@ */
0, /* @tp_dict@ */
0, /* @tp_descr_get@ */
0, /* @tp_base@ */
0, /* @tp_dict@ */
0, /* @tp_descr_get@ */
@@
-1512,11
+1490,8
@@
static PyTypeObject bbspriv_pytype_skel = {
/*----- Global stuff ------------------------------------------------------*/
/*----- Global stuff ------------------------------------------------------*/
-static PyMethodDef methods[] = {
-#define METHNAME(name) meth_##name
- KWMETH(_BBSPriv_generate, "generate(NBITS, [event = pgen_nullev], "
- "[rng = rand], [nsteps = 0], [seed = 2]) -> R")
-#undef METHNAME
+static const struct nameval consts[] = {
+ CONST(RAND_IBITS),
{ 0 }
};
{ 0 }
};
@@
-1537,11
+1512,12
@@
void rand_pyinit(void)
INITTYPE(gclatinrand, gcrand);
rand_noisesrc(RAND_GLOBAL, &noise_source);
rand_seed(RAND_GLOBAL, 160);
INITTYPE(gclatinrand, gcrand);
rand_noisesrc(RAND_GLOBAL, &noise_source);
rand_seed(RAND_GLOBAL, 160);
- addmethods(methods);
}
}
-#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)
{
void rand_pyinsert(PyObject *mod)
{
@@
-1559,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);
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);
INSERT("rand", rand_pyobj);
+ setconstants(mod, consts);
}
/*----- That's all, folks -------------------------------------------------*/
}
/*----- That's all, folks -------------------------------------------------*/