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

Function py_dictitem_as_str

libsigrokdecode4DSL/util.c:177–202  ·  view source on GitHub ↗

* Get the value of a Python dictionary item, returned as a newly * allocated char *. * * @param[in] py_obj The dictionary to probe. * @param[in] key Key of the 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. * *

Source from the content-addressed store, hash-verified

175 * @private
176 */
177SRD_PRIV int py_dictitem_as_str(PyObject *py_obj, const char *key,
178 char **outstr)
179{
180 PyObject *py_value;
181 PyGILState_STATE gstate;
182
183 gstate = PyGILState_Ensure();
184
185 if (!PyDict_Check(py_obj)) {
186 srd_dbg("Object is not a dictionary.");
187 goto err;
188 }
189
190 if (!(py_value = PyDict_GetItemString(py_obj, key))) {
191 goto err;
192 }
193
194 PyGILState_Release(gstate);
195
196 return py_str_as_str(py_value, outstr);
197
198err:
199 PyGILState_Release(gstate);
200
201 return SRD_ERR_PYTHON;
202}
203
204/**
205 * Get the value of a Python dictionary item, returned as a int.

Callers 1

get_channelsFunction · 0.85

Calls 1

py_str_as_strFunction · 0.85

Tested by

no test coverage detected