* 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. * *
| 175 | * @private |
| 176 | */ |
| 177 | SRD_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 | |
| 198 | err: |
| 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. |
no test coverage detected