-
- Py_XDECREF(py_res);
-
-
- /* Get the 'Decoder' class as Python object. */
- py_res = PyObject_GetAttrString(py_mod, "Decoder"); /* NEWREF */
- if (!py_res) {
- if (PyErr_Occurred())
- PyErr_Print(); /* Returns void. */
- //Py_XDECREF(py_mod);
- fprintf(stderr, "Decoder class not found in PD module %s\n", name);
- //return SRD_ERR_PYTHON; /* TODO: More specific error? */
-
-
- /* Get the 'decode' function name as Python callable object. */
- py_func = PyObject_GetAttrString(py_mod, "decode"); /* NEWREF */
- if (!py_func || !PyCallable_Check(py_func)) {
- if (PyErr_Occurred())
- PyErr_Print(); /* Returns void. */
- Py_XDECREF(py_mod);
- return SRD_ERR_PYTHON; /* TODO: More specific error? */
- }
- } else {
- PyObject_Print(py_res, stdout, Py_PRINT_RAW);
- fprintf(stdout, "\n");
-
- /* Create a Python tuple of size 1. */
- if (!(py_args = PyTuple_New(1))) { /* NEWREF */
- if (PyErr_Occurred())
- PyErr_Print(); /* Returns void. */
-
- Py_XDECREF(py_res);
- Py_XDECREF(py_mod);
-
- return SRD_ERR_PYTHON; /* TODO: More specific error? */
- }
-
- py_value = Py_BuildValue("{sssisd}",
- "driver", "demo",
- "unitsize", _unitsize, //FIXME: Pass in a unitsize that matches the selected LA
- "starttime", 129318231823.0 //TODO: Fill with something reasonable.
- );
- /*
- * IMPORTANT: PyTuple_SetItem() "steals" a reference to py_value!
- * That means we are no longer responsible for Py_XDECREF()'ing it.
- * It will automatically be free'd when the 'py_args' tuple is free'd.
- */
- if (PyTuple_SetItem(py_args, 0, py_value) != 0) { /* STEAL */
- Py_XDECREF(py_value); /* TODO: Ref. stolen upon error? */
- Py_XDECREF(py_res);
- Py_XDECREF(py_mod);
- return SRD_ERR_PYTHON; /* TODO: More specific error? */
- }
-
- /* Create an instance of the Decoder class */
- py_instance = PyObject_CallObject(py_res, py_args);
- if (!py_instance) {
- if (PyErr_Occurred())
- PyErr_Print(); /* Returns void. */
- Py_XDECREF(py_value); /* TODO: Ref. stolen upon error? */
- Py_XDECREF(py_res);
- Py_XDECREF(py_mod);
- fprintf(stderr, "Unable to create instance of Decoder class in PD module %s\n", name);
- return SRD_ERR_PYTHON; /* TODO: More specific error? */
- } else {
- /* OK, we have successfully created an instance of the Decoder object */
-
- /* Get the 'decode' function name as Python callable object. */
- py_func = PyObject_GetAttrString(py_instance, "decode"); /* NEWREF */
- if (!py_func || !PyCallable_Check(py_func)) {
- if (PyErr_Occurred())
- PyErr_Print(); /* Returns void. */
- fprintf(stderr, "Unable to find decode function in instance of Decoder class in PD module %s\n", name);
- Py_XDECREF(py_instance);
- Py_XDECREF(py_mod);
- return SRD_ERR_PYTHON; /* TODO: More specific error? */
- }
- }
- }
-
- d->py_decodefunc = py_func;