summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2018-04-20 23:30:58 +0200
committerUwe Hermann <uwe@hermann-uwe.de>2018-04-20 23:30:58 +0200
commit752086e9c8a0f7663f56a0a4ed65cc8f3591654b (patch)
tree659696d07be3696ab91de09a2686923dae8586d3
parentfb0b05e68352a55e1d8a212413df40d90a30202c (diff)
downloadlibsigrokdecode-752086e9c8a0f7663f56a0a4ed65cc8f3591654b.tar.gz
libsigrokdecode-752086e9c8a0f7663f56a0a4ed65cc8f3591654b.zip
srd_exception_catch(): Beautify traceback logging output.
-rw-r--r--exception.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/exception.c b/exception.c
index 8058fbf..8b50883 100644
--- a/exception.c
+++ b/exception.c
@@ -86,12 +86,14 @@ cleanup:
/** @private */
SRD_PRIV void srd_exception_catch(const char *format, ...)
{
+ int i, ret;
va_list args;
PyObject *py_etype, *py_evalue, *py_etraceback;
PyObject *py_mod, *py_func, *py_tracefmt;
- char *msg, *etype_name, *evalue_str, *tracefmt_str;
+ char *msg, *etype_name, *evalue_str, *outstr;
const char *etype_name_fallback;
PyGILState_STATE gstate;
+ GString *s;
py_etype = py_evalue = py_etraceback = py_mod = py_func = NULL;
@@ -136,17 +138,21 @@ SRD_PRIV void srd_exception_catch(const char *format, ...)
/* Call into Python to format the stack trace. */
py_tracefmt = PyObject_CallFunctionObjArgs(py_func,
py_etype, py_evalue, py_etraceback, NULL);
- if (!py_tracefmt)
+ if (!py_tracefmt || !PyList_Check(py_tracefmt))
goto cleanup;
- tracefmt_str = py_stringify(py_tracefmt);
- Py_DECREF(py_tracefmt);
-
- /* Log the detailed stack trace. */
- if (tracefmt_str) {
- srd_err("%s", tracefmt_str);
- g_free(tracefmt_str);
+ s = g_string_sized_new(128);
+ for (i = 0; i < PyList_Size(py_tracefmt); i++) {
+ ret = py_listitem_as_str(py_tracefmt, i, &outstr);
+ if (ret == 0) {
+ s = g_string_append(s, outstr);
+ g_free(outstr);
+ }
}
+ srd_err("%s", s->str);
+ g_string_free(s, TRUE);
+
+ Py_DECREF(py_tracefmt);
cleanup:
Py_XDECREF(py_func);