X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=exception.c;h=8f15ff22a520550a519dfb343d30ad8b2826933e;hp=aa7ab616d58df4a949e8cf0c814ca06118c9a73a;hb=22630a3d54361f083877a68724e8b823d5e063a7;hpb=7a1712c4fd07f64222079acd5ec3fa3348a5cb15 diff --git a/exception.c b/exception.c index aa7ab61..8f15ff2 100644 --- a/exception.c +++ b/exception.c @@ -1,5 +1,5 @@ /* - * This file is part of the sigrok project. + * This file is part of the libsigrokdecode project. * * Copyright (C) 2012 Bert Vermeulen * @@ -17,15 +17,15 @@ * along with this program. If not, see . */ -#include "sigrokdecode.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */ -#include "sigrokdecode-internal.h" +#include "libsigrokdecode-internal.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */ +#include "libsigrokdecode.h" #include "config.h" #include #include #include /* Python header not pulled in by default. */ - -void catch_exception(const char *format, ...) +/** @private */ +SRD_PRIV void srd_exception_catch(const char *format, ...) { PyObject *etype, *evalue, *etb, *py_str; PyTracebackObject *py_tb; @@ -46,21 +46,20 @@ void catch_exception(const char *format, ...) return; } - msg = g_string_sized_new(128); - va_start(args, format); - g_string_vprintf(msg, format, args); - va_end(args); - - /* Can be NULL. */ + /* Send the exception error message(s) to srd_err(). */ if (evalue) ename = (char *)Py_TYPE(evalue)->tp_name; else + /* Can be NULL. */ ename = "(unknown exception)"; - /* Send the exception error message(s) to srd_err(). */ - py_str_as_str(py_str, &str); + msg = g_string_sized_new(128); g_string_append(msg, ename); g_string_append(msg, ": "); + va_start(args, format); + g_string_append_vprintf(msg, format, args); + va_end(args); + py_str_as_str(py_str, &str); g_string_append(msg, str); Py_DecRef(py_str); srd_err(msg->str); @@ -68,10 +67,11 @@ void catch_exception(const char *format, ...) /* Send a more precise error location to srd_dbg(), if we have it. */ if (etb && etb != Py_None) { tracestr = NULL; - py_tb = (PyTracebackObject *) etb; + py_tb = (PyTracebackObject *)etb; py_str = PyUnicode_FromFormat("%U:%d in %U", - py_tb->tb_frame->f_code->co_filename, py_tb->tb_frame->f_lineno, - py_tb->tb_frame->f_code->co_name); + py_tb->tb_frame->f_code->co_filename, + py_tb->tb_frame->f_lineno, + py_tb->tb_frame->f_code->co_name); py_str_as_str(py_str, &tracestr); Py_DecRef(py_str); g_string_printf(msg, "%s in %s: %s", ename, tracestr, str); @@ -87,8 +87,4 @@ void catch_exception(const char *format, ...) /* Just in case. */ PyErr_Clear(); - - return; } - -