algorithms.c (ShakeNN constructor): Support `None' for func/perso args.
[catacomb-python] / algorithms.c
index 4e22a54..dd0bd0a 100644 (file)
@@ -2976,12 +2976,14 @@ static PyObject *shake_dopynew(void (*initfn)(shake_ctx *,
                               PyObject *arg, PyObject *kw)
 {
   shake_pyobj *rc = 0;
+  PyObject *pobj = Py_None, *fobj = Py_None;
   struct bin p = { 0, 0 }, f = { 0, 0 };
   static const char *const kwlist[] = { "perso", "func", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&O&:new", KWLIST,
-                                  convbin, &p, convbin, &f))
-    goto end;
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "|OO:new", KWLIST, &pobj, &fobj))
+      goto end;
+  if (pobj != Py_None && !convbin(pobj, &p)) goto end;
+  if (fobj != Py_None && !convbin(fobj, &f)) goto end;
   rc = (shake_pyobj *)ty->tp_alloc(ty, 0);
   initfn(&rc->h, f.p, f.sz, p.p, p.sz);
   rc->st = 0;