[sr-dev] git:master:8c1f1c16: app_python3: improve exception debugging

AnthonyA ascanio.alba7 at gmail.com
Sat Mar 3 15:00:21 CET 2018


Module: kamailio
Branch: master
Commit: 8c1f1c16c1d054cbc01dc26341f6770934d46ead
URL: https://github.com/kamailio/kamailio/commit/8c1f1c16c1d054cbc01dc26341f6770934d46ead

Author: AnthonyA <ascanio.alba7 at gmail.com>
Committer: AnthonyA <ascanio.alba7 at gmail.com>
Date: 2018-03-03T21:57:28+08:00

app_python3: improve exception debugging

- print method name and arg on error

---

Modified: src/modules/app_python3/python_exec.c
Modified: src/modules/app_python3/python_support.c
Modified: src/modules/app_python3/python_support.h

---

Diff:  https://github.com/kamailio/kamailio/commit/8c1f1c16c1d054cbc01dc26341f6770934d46ead.diff
Patch: https://github.com/kamailio/kamailio/commit/8c1f1c16c1d054cbc01dc26341f6770934d46ead.patch

---

diff --git a/src/modules/app_python3/python_exec.c b/src/modules/app_python3/python_exec.c
index 12a8008d66..55f40c1e47 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 a08cd9ee11..2ad522901a 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 032340dcdd..4d25564119 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 *);




More information about the sr-dev mailing list