chiark / gitweb /
catacomb-python.h, *.c: Fix how Python `pgen' handlers handle exceptions.
[catacomb-python] / rand.c
diff --git a/rand.c b/rand.c
index 7e091b02464c8503907126cd7fa22fa6d03c35ef..ddec6ffb7f8ce62ed69df2364bc2fd6a4458648b 100644 (file)
--- a/rand.c
+++ b/rand.c
@@ -1364,18 +1364,20 @@ 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;
   char *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;
@@ -1384,7 +1386,6 @@ static PyObject *meth__BBSPriv_generate(PyObject *me,
   rc->bp.n = MP_COPY(bp.n);
 end:
   mp_drop(bp.p); mp_drop(bp.q); mp_drop(bp.n); mp_drop(x);
-  droppgev(&evt);
   return ((PyObject *)rc);
 }