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

Function py_stringify

libsigrokdecode4DSL/exception.c:27–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25#include "log.h"
26
27static 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
48cleanup:
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
58static char *py_get_string_attr(PyObject *py_obj, const char *attr)
59{

Callers 1

srd_exception_catchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected