key.c: Make `None' be the default report-function designator.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 22 Oct 2019 11:34:48 +0000 (12:34 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 25 Nov 2019 17:43:08 +0000 (17:43 +0000)
Now we can pass it in from Python as an explicit argument.

key.c

diff --git a/key.c b/key.c
index d820cfa..50c5321 100644 (file)
--- a/key.c
+++ b/key.c
@@ -1619,7 +1619,7 @@ static void pythonreporter(const char *file, int line,
 
   if (ri->stop)
     return;
-  if (!ri->func)
+  if (ri->func == Py_None)
     key_moan(file, line, msg, 0);
   else if ((res = PyObject_CallFunction(ri->func, "sis",
                                        file, line, msg)) == 0)
@@ -1631,7 +1631,7 @@ static void pythonreporter(const char *file, int line,
 static PyObject *keyfile_pynew(PyTypeObject *ty,
                               PyObject *arg, PyObject *kw)
 {
-  struct reportinfo ri = { 0, 0 };
+  struct reportinfo ri = { Py_None, 0 };
   char *file = 0;
   unsigned how = KOPEN_READ;
   keyfile_pyobj *rc = 0;
@@ -1641,7 +1641,7 @@ static PyObject *keyfile_pynew(PyTypeObject *ty,
   if (!PyArg_ParseTupleAndKeywords(arg, kw, "s|iO:new", KWLIST,
                                   &file, &how, &ri.func))
     goto end;
-  if (ri.func && !PyCallable_Check(ri.func))
+  if (ri.func != Py_None && !PyCallable_Check(ri.func))
     TYERR("reporter function not callable");
   if ((rc = (keyfile_pyobj *)ty->tp_alloc(ty, 0)) == 0)
     goto end;
@@ -1688,7 +1688,7 @@ end:
 
 static PyObject *kfmeth_merge(PyObject *me, PyObject *arg, PyObject *kw)
 {
-  struct reportinfo ri = { 0, 0 };
+  struct reportinfo ri = { Py_None, 0 };
   char *name;
   PyObject *x = 0;
   FILE *fp = 0;
@@ -1699,7 +1699,7 @@ static PyObject *kfmeth_merge(PyObject *me, PyObject *arg, PyObject *kw)
   if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!|O:merge", KWLIST,
                                   &PyFile_Type, &x, &ri.func))
     goto end;
-  if (ri.func && !PyCallable_Check(ri.func))
+  if (ri.func != Py_None && !PyCallable_Check(ri.func))
     TYERR("reporter function not callable");
   if ((fp = PyFile_AsFile(x)) == 0)
     goto end;