| 25 | #include "log.h" |
| 26 | |
| 27 | static char *py_stringify(PyObject *py_obj) |
| 28 | { |
| 29 | PyObject *py_str, *py_bytes; |
| 30 | char *str = NULL; |
| 31 | |
| 32 | /* Note: Caller already ran PyGILState_Ensure(). */ |
| 33 | |
| 34 | if (!py_obj) |
| 35 | return NULL; |
| 36 | |
| 37 | py_str = PyObject_Str(py_obj); |
| 38 | if (!py_str || !PyUnicode_Check(py_str)) |
| 39 | goto cleanup; |
| 40 | |
| 41 | py_bytes = PyUnicode_AsUTF8String(py_str); |
| 42 | if (!py_bytes) |
| 43 | goto cleanup; |
| 44 | |
| 45 | str = g_strdup(PyBytes_AsString(py_bytes)); |
| 46 | Py_DECREF(py_bytes); |
| 47 | |
| 48 | cleanup: |
| 49 | Py_XDECREF(py_str); |
| 50 | if (!str) { |
| 51 | PyErr_Clear(); |
| 52 | srd_err("Failed to stringify object."); |
| 53 | } |
| 54 | |
| 55 | return str; |
| 56 | } |
| 57 | |
| 58 | static char *py_get_string_attr(PyObject *py_obj, const char *attr) |
| 59 | { |
no outgoing calls
no test coverage detected