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

Function py_attr_as_str

libsigrokdecode4DSL/util.c:71–100  ·  view source on GitHub ↗

* Get the value of a Python object's attribute, returned as a newly * allocated char *. * * @param[in] py_obj The object to probe. * @param[in] attr Name of the attribute to retrieve. * @param[out] outstr ptr 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

69 * @private
70 */
71SRD_PRIV int py_attr_as_str(PyObject *py_obj, const char *attr, char **outstr)
72{
73 PyObject *py_str;
74 int ret;
75 PyGILState_STATE gstate;
76
77 gstate = PyGILState_Ensure();
78
79 if (!PyObject_HasAttrString(py_obj, attr)) {
80 srd_dbg("Object has no attribute '%s'.", attr);
81 goto err;
82 }
83
84 if (!(py_str = PyObject_GetAttrString(py_obj, attr))) {
85 srd_exception_catch(NULL, "Failed to get attribute '%s'", attr);
86 goto err;
87 }
88
89 ret = py_str_as_str(py_str, outstr);
90 Py_DECREF(py_str);
91
92 PyGILState_Release(gstate);
93
94 return ret;
95
96err:
97 PyGILState_Release(gstate);
98
99 return SRD_ERR_PYTHON;
100}
101
102/**
103 * Get the value of a Python object's attribute, returned as a newly

Callers 1

srd_decoder_loadFunction · 0.85

Calls 2

srd_exception_catchFunction · 0.85
py_str_as_strFunction · 0.85

Tested by

no test coverage detected