X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/204416123385794c92b7767e7702c0d4fd387468..740847afe208bb8f33e7d6cf642acaf4aa739f6a:/rand.c diff --git a/rand.c b/rand.c index 964a6a2..37ab5e4 100644 --- a/rand.c +++ b/rand.c @@ -508,7 +508,7 @@ static PyObject *truerand_pynew(PyTypeObject *ty, static const char *const kwlist[] = { 0 }; grand *r; PyObject *rc = 0; - if (PyArg_ParseTupleAndKeywords(arg, kw, ":new", KWLIST)) goto end; + if (!PyArg_ParseTupleAndKeywords(arg, kw, ":new", KWLIST)) goto end; r = rand_create(); r->ops->misc(r, RAND_NOISESRC, &noise_source); r->ops->misc(r, RAND_SEED, 160); @@ -1269,7 +1269,7 @@ static PyObject *bbsget_x(PyObject *me, void *hunoz) static int bbsset_x(PyObject *me, PyObject *val, void *hunoz) { - mp *x = 0; grand *r = GRAND_R(me); int rc = -1; if (!x) NIERR("__del__"); + mp *x = 0; grand *r = GRAND_R(me); int rc = -1; if (!val) NIERR("__del__"); if ((x = getmp(val)) == 0) goto end; r->ops->misc(r, BBS_SET, x); rc = 0; end: mp_drop(x); return (rc); @@ -1385,19 +1385,21 @@ static PyObject *meth__BBSPriv_generate(PyObject *me, { bbs_priv bp = { 0 }; mp *x = MP_TWO; - pgev evt = { 0 }; + struct excinfo exc = EXCINFO_INIT; + pypgev evt = { { 0 } }; unsigned nbits, n = 0; grand *r = &rand_global; static const char *const kwlist[] = { "class", "nbits", "event", "rng", "nsteps", "seed", 0 }; bbspriv_pyobj *rc = 0; + evt.exc = &exc; if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&|O&O&O&O&:generate", KWLIST, &me, convuint, &nbits, convpgev, &evt, convgrand, &r, convuint, &n, convmp, &x)) goto end; - if (bbs_gen(&bp, nbits, r, n, evt.proc, evt.ctx)) - VALERR("prime genration failed"); + if (bbs_gen(&bp, nbits, r, n, evt.ev.proc, evt.ev.ctx)) + PGENERR(&exc); rc = PyObject_New(bbspriv_pyobj, bbspriv_pytype); rc->gr.r = bbs_rand(bp.n, x); rc->gr.f = f_freeme; @@ -1483,7 +1485,7 @@ static PyTypeObject bbspriv_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"BBSPriv(..., seed = 2]): Blum-Blum-Shub, with private key.\n\ +"BBSPriv(..., [seed = 2]): Blum-Blum-Shub, with private key.\n\ Keywords: n, p, q; must provide at least two", 0, /* @tp_traverse@ */ @@ -1512,7 +1514,8 @@ static PyTypeObject bbspriv_pytype_skel = { static PyMethodDef methods[] = { #define METHNAME(name) meth_##name KWMETH(_BBSPriv_generate, "\ -generate(NBITS, [event = pgen_nullev, rng = rand, nsteps = 0, seed = 2])") +generate(NBITS, [event = pgen_nullev], [rng = rand],\n\ + [nsteps = 0], [seed = 2]) -> R") #undef METHNAME { 0 } };