* 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
| 250 | * @private |
| 251 | */ |
| 252 | SRD_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 | |
| 274 | err: |
| 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 |
no test coverage detected