MCPcopy Create free account
hub / github.com/DreamSourceLab/DSView / py_listitem_as_str

Function py_listitem_as_str

libsigrokdecode4DSL/util.c:252–278  ·  view source on GitHub ↗

* Get the value of a Python list item, returned as a newly * allocated char *. * * @param[in] py_obj The list to probe. * @param[in] idx Index of the list item to retrieve. * @param[out] outstr Pointer to char * storage to be filled in. * * @return SRD_OK upon success, a (negative) error code otherwise. * The 'outstr' argument points to a malloc()ed string upon success. * * @priv

Source from the content-addressed store, hash-verified

250 * @private
251 */
252SRD_PRIV int py_listitem_as_str(PyObject *py_obj, int idx,
253 char **outstr)
254{
255 PyObject *py_value;
256 PyGILState_STATE gstate;
257
258 gstate = PyGILState_Ensure();
259
260 if (!PyList_Check(py_obj)) {
261 srd_dbg("Object is not a list.");
262 goto err;
263 }
264
265 if (!(py_value = PyList_GetItem(py_obj, idx))) {
266 srd_dbg("Couldn't get list item %d.", idx);
267 goto err;
268 }
269
270 PyGILState_Release(gstate);
271
272 return py_str_as_str(py_value, outstr);
273
274err:
275 PyGILState_Release(gstate);
276
277 return SRD_ERR_PYTHON;
278}
279
280/**
281 * Get the value of a Python dictionary item, returned as a newly

Callers 2

srd_exception_catchFunction · 0.85
py_attr_as_strlistFunction · 0.85

Calls 1

py_str_as_strFunction · 0.85

Tested by

no test coverage detected