- /* Create a Python tuple of size 1. */
- if (!(py_args = PyTuple_New(1))) { /* NEWREF */
- ret = SRD_ERR_PYTHON; /* TODO: More specific error? */
- goto err_run_decref_func;
- }
-
- while (inbuf_pos < inbuflen) {
- /* Get the input buffer as Python "string" (byte array). */
- /* TODO: int vs. uint64_t for 'inbuflen'? */
-
- py_value = Py_BuildValue("{sisiss#}",
- "time", inbuf_pos / _unitsize,
- "duration", 10,
- "data", &inbuf[inbuf_pos], _unitsize
- );
-
- /*
- * 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 */
- ret = SRD_ERR_PYTHON; /* TODO: More specific error? */
- Py_XDECREF(py_value); /* TODO: Ref. stolen upon error? */
- goto err_run_decref_args;
- }
-
- if (!(py_res = PyObject_CallObject(py_func, py_args))) { /* NEWREF */
- ret = SRD_ERR_PYTHON; /* TODO: More specific error? */
- goto err_run_decref_args;
- }
- inbuf_pos++;
- }
+ /* TODO: Error handling. */
+ py_instance = dec->py_instance;
+ Py_XINCREF(py_instance);
+
+ if (!(py_res = PyObject_CallMethod(py_instance, "decode",
+ "{s:i,s:i,s:s#}",
+ "time", _timehack,
+ "duration", 10,
+ "data", inbuf, inbuflen))) { /* NEWREF */
+ if (PyErr_Occurred())
+ PyErr_Print(); /* Returns void. */