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

Function py_attr_as_strlist

libsigrokdecode4DSL/util.c:116–162  ·  view source on GitHub ↗

* Get the value of a Python object's attribute, returned as a newly * allocated GSList of char *. * * @param[in] py_obj The object to probe. * @param[in] attr Name of the attribute to retrieve. * @param[out] outstrlist ptr to GSList of char * storage to be filled in. * * @return SRD_OK upon success, a (negative) error code otherwise. * The 'outstrlist' argument points to a GSList o

Source from the content-addressed store, hash-verified

114 * @private
115 */
116SRD_PRIV int py_attr_as_strlist(PyObject *py_obj, const char *attr, GSList **outstrlist)
117{
118 PyObject *py_list;
119 int i;
120 int ret;
121 char *outstr;
122 PyGILState_STATE gstate;
123
124 gstate = PyGILState_Ensure();
125
126 if (!PyObject_HasAttrString(py_obj, attr)) {
127 srd_dbg("Object has no attribute '%s'.", attr);
128 goto err;
129 }
130
131 if (!(py_list = PyObject_GetAttrString(py_obj, attr))) {
132 srd_exception_catch(NULL, "Failed to get attribute '%s'", attr);
133 goto err;
134 }
135
136 if (!PyList_Check(py_list)) {
137 srd_dbg("Object is not a list.");
138 goto err;
139 }
140
141 *outstrlist = NULL;
142
143 for (i = 0; i < PyList_Size(py_list); i++) {
144 ret = py_listitem_as_str(py_list, i, &outstr);
145 if (ret < 0) {
146 srd_dbg("Couldn't get item %d.", i);
147 goto err;
148 }
149 *outstrlist = g_slist_append(*outstrlist, outstr);
150 }
151
152 Py_DECREF(py_list);
153
154 PyGILState_Release(gstate);
155
156 return SRD_OK;
157
158err:
159 PyGILState_Release(gstate);
160
161 return SRD_ERR_PYTHON;
162}
163
164/**
165 * Get the value of a Python dictionary item, returned as a newly

Callers 1

srd_decoder_loadFunction · 0.85

Calls 2

srd_exception_catchFunction · 0.85
py_listitem_as_strFunction · 0.85

Tested by

no test coverage detected