+ struct sigrokdecode_decoder *d;
+ PyObject *py_name, *py_mod, *py_func, *py_res /* , *py_tuple */;
+ int r;
+
+ /* Get the name of the decoder module as Python string. */
+ if (!(py_name = PyString_FromString(name))) {
+ PyErr_Print();
+ return SIGROKDECODE_ERR_PYTHON; /* TODO: More specific error? */
+ }
+
+ /* "Import" the Python module. */
+ if (!(py_mod = PyImport_Import(py_name))) {
+ PyErr_Print();
+ Py_DECREF(py_name);
+ return SIGROKDECODE_ERR_PYTHON; /* TODO: More specific error? */
+ }
+ Py_DECREF(py_name);
+
+ /* Get the 'register' function name as Python callable object. */
+ py_func = PyObject_GetAttrString(py_mod, "register");
+ if (!py_func || !PyCallable_Check(py_func)) {
+ if (PyErr_Occurred())
+ PyErr_Print();
+ Py_DECREF(py_mod);
+ return SIGROKDECODE_ERR_PYTHON; /* TODO: More specific error? */
+ }
+
+ /* Call the 'register' function without arguments, get the result. */
+ if (!(py_res = PyObject_CallFunction(py_func, NULL))) {
+ PyErr_Print();
+ Py_DECREF(py_func);
+ Py_DECREF(py_mod);
+ return SIGROKDECODE_ERR_PYTHON; /* TODO: More specific error? */
+ }
+
+ if (!(d = malloc(sizeof(struct sigrokdecode_decoder))))
+ return SIGROKDECODE_ERR_MALLOC;