Rather than catching a Python error at runtime when trying to
call an object that wasn't callable, just ignore that object
up front when loading the plugin.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
Various examples on calling Python functions from C recommend
doing this filtering check.
plugins/python/python.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/plugins/python/python.c b/plugins/python/python.c
index 0206b80..35e8df2 100644
--- a/plugins/python/python.c
+++ b/plugins/python/python.c
@@ -94,6 +94,11 @@ callback_defined (const char *name, PyObject **obj_rtn)
obj = PyObject_GetAttrString (module, name);
if (!obj)
return 0;
+ if (!PyCallable_Check (obj)) {
+ nbdkit_debug ("object %s isn't callable", name);
+ Py_DECREF (obj);
+ return 0;
+ }
if (obj_rtn != NULL)
*obj_rtn = obj;
--
2.14.3