From 5d9a36f1d1ff3135958012d701a746c9d0fc0dd6 Mon Sep 17 00:00:00 2001 From: Olivier Martin Date: Tue, 26 Mar 2024 15:53:36 +0100 Subject: [PATCH] logging_backend/python: Do not call 'GATTLIB_LOG(GATTLIB_ERROR, ...)' on error to avoid recursion --- common/logging_backend/python/gattlib_logging.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/common/logging_backend/python/gattlib_logging.c b/common/logging_backend/python/gattlib_logging.c index ad7a182..182f1ad 100644 --- a/common/logging_backend/python/gattlib_logging.c +++ b/common/logging_backend/python/gattlib_logging.c @@ -42,13 +42,14 @@ void gattlib_log(int level, const char *format, ...) { #else result = PyEval_CallObject(m_logging_func, arglist); #endif - Py_DECREF(arglist); - if (result == NULL) { - GATTLIB_LOG(GATTLIB_ERROR, "Python notification handler has raised an exception."); + // We do not call GATTLIB_LOG(GATTLIB_ERROR, "") in case of error to avoid recursion + fprintf(stderr, "Failed to call Python logging function for this logging: %s\n", format); PyErr_Print(); } + Py_DECREF(arglist); + PyGILState_Release(d_gstate); }