* 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. *
| 69 | * @private |
| 70 | */ |
| 71 | SRD_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 | |
| 96 | err: |
| 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 |
no test coverage detected