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

Function py_dict_value_to_str

libsigrokdecode4DSL/util.c:293–327  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

291 * @private
292 */
293SRD_PRIV int py_dict_value_to_str(PyObject *py_obj, PyObject *py_key,
294 char **outstr)
295{
296 PyObject *py_value;
297 PyGILState_STATE gstate;
298
299 if (!py_obj || !py_key || !outstr)
300 return SRD_ERR_ARG;
301
302 gstate = PyGILState_Ensure();
303
304 if (!PyDict_Check(py_obj)) {
305 srd_dbg("Object is not a dictionary.");
306 goto err;
307 }
308
309 if (!(py_value = PyDict_GetItem(py_obj, py_key))) {
310 srd_dbg("Dictionary has no such key.");
311 goto err;
312 }
313
314 if (!PyUnicode_Check(py_value)) {
315 srd_dbg("Dictionary value should be a string.");
316 goto err;
317 }
318
319 PyGILState_Release(gstate);
320
321 return py_str_as_str(py_value, outstr);
322
323err:
324 PyGILState_Release(gstate);
325
326 return SRD_ERR_PYTHON;
327}
328
329/**
330 * Get the value of a Python dictionary item, returned as a newly

Callers

nothing calls this directly

Calls 1

py_str_as_strFunction · 0.85

Tested by

no test coverage detected