diff --git a/src/modules/app_python3/python_exec.c b/src/modules/app_python3/python_exec.c index 12a8008d660..55f40c1e47e 100644 --- a/src/modules/app_python3/python_exec.c +++ b/src/modules/app_python3/python_exec.c @@ -142,7 +142,7 @@ int apy_exec(sip_msg_t *_msg, char *fname, char *fparam, int emode) Py_DECREF(pFunc); if (PyErr_Occurred()) { Py_XDECREF(pResult); - python_handle_exception("python_exec2"); + python_handle_exception("apy_exec: %s(%s)", fname, fparam); _sr_apy_env.msg = bmsg; goto err; } diff --git a/src/modules/app_python3/python_support.c b/src/modules/app_python3/python_support.c index a08cd9ee119..2ad522901ac 100644 --- a/src/modules/app_python3/python_support.c +++ b/src/modules/app_python3/python_support.c @@ -29,6 +29,8 @@ #include "app_python_mod.h" #include "python_support.h" +static char *make_message(const char *fmt, va_list args); + void python_handle_exception(const char *fmt, ...) { PyObject *pResult; @@ -40,6 +42,7 @@ void python_handle_exception(const char *fmt, ...) int i; char *srcbuf; int exc_exit = 0; + va_list ap; // We don't want to generate traceback when no errors occurred if (!PyErr_Occurred()) @@ -47,8 +50,11 @@ void python_handle_exception(const char *fmt, ...) if (fmt == NULL) srcbuf = NULL; - else - srcbuf = make_message(fmt); + else { + va_start(ap, fmt); + srcbuf = make_message(fmt, ap); + va_end(ap); + } PyErr_Fetch(&exception, &v, &tb); PyErr_Clear(); @@ -184,12 +190,11 @@ PyObject *InitTracebackModule() } -char *make_message(const char *fmt, ...) +static char *make_message(const char *fmt, va_list ap) { int n; size_t size; char *p, *np; - va_list ap; size = 100; /* Guess we need no more than 100 bytes. */ p = (char *)pkg_realloc(NULL, size * sizeof(char)); @@ -203,9 +208,7 @@ char *make_message(const char *fmt, ...) while (1) { - va_start(ap, fmt); n = vsnprintf(p, size, fmt, ap); - va_end(ap); if (n > -1 && n < size) return p; diff --git a/src/modules/app_python3/python_support.h b/src/modules/app_python3/python_support.h index 032340dcdde..4d255641197 100644 --- a/src/modules/app_python3/python_support.h +++ b/src/modules/app_python3/python_support.h @@ -28,7 +28,6 @@ PyObject *format_exc_obj; void python_handle_exception(const char *, ...); -char *make_message(const char *fmt, ...); PyObject *InitTracebackModule(void); char *get_class_name(PyObject *);