From: Michael Tremer Date: Mon, 16 Oct 2023 10:37:27 +0000 (+0000) Subject: _pakfire: Drop the old Python logging callback X-Git-Tag: 0.9.30~1491 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfed4a7fe70371aec0b433f24b84dfc5f790b22e;p=pakfire.git _pakfire: Drop the old Python logging callback Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index 74d82ce28..27df75610 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -56,85 +56,6 @@ static PyObject* Pakfire_new(PyTypeObject* type, PyObject* args, PyObject* kwds) return (PyObject *)self; } -static void Pakfire_log_callback(void* data, int priority, const char* file, int line, - const char* fn, const char* format, va_list args) { - PyObject* callback = (PyObject*)data; - PyObject* exception = NULL; - PyObject* type = NULL; - PyObject* value = NULL; - PyObject* traceback = NULL; - - // Do nothing if callback isn't set - if (!callback) - return; - - PyGILState_STATE state = PyGILState_Ensure(); - - // Translate priority to Python logging priorities - switch (priority) { - case LOG_DEBUG: - priority = 10; - break; - - case LOG_INFO: - priority = 20; - break; - - case LOG_ERR: - priority = 40; - break; - - // Drop messages of an unknown priority - default: - return; - } - - PyObject* tuple = NULL; - PyObject* result = NULL; - char* buffer = NULL; - - // Make line - int r = vasprintf(&buffer, format, args); - if (r < 0) - goto ERROR; - - // Build a tuple with the priority and the log message - tuple = Py_BuildValue("(is)", priority, buffer); - if (!tuple) - goto ERROR; - - // Call the callback - result = PyObject_CallObject(callback, tuple); - -ERROR: - /* - We cannot really catch any Python errors here, since we cannot send - any error codes up the chain. - - So, in order to debug the problem, We will check if an exception has - occurred and if so, print it to the console. - */ - exception = PyErr_Occurred(); - if (exception) { - PyErr_Print(); - - // Fetch the exception and destroy it - PyErr_Fetch(&type, &value, &traceback); - - Py_XDECREF(type); - Py_XDECREF(value); - Py_XDECREF(traceback); - } - - if (buffer) - free(buffer); - Py_XDECREF(tuple); - Py_XDECREF(result); - - // Release the GIL - PyGILState_Release(state); -} - static int Pakfire_confirm_callback(struct pakfire* pakfire, void* data, const char* message, const char* question) { PyObject* callback = (PyObject*)data; @@ -197,16 +118,10 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { FILE* fconf = NULL; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzOpOO", kwlist, - &path, &arch, &self->callbacks.log, &offline, &conf, &self->callbacks.confirm)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzpOO", kwlist, + &path, &arch, &offline, &conf, &self->callbacks.confirm)) goto ERROR; - // Check if log callback is callable - if (self->callbacks.log && !PyCallable_Check(self->callbacks.log)) { - PyErr_SetString(PyExc_TypeError, "logger must be callable\n"); - goto ERROR; - } - // Check if confirm callback is callable if (self->callbacks.confirm && !PyCallable_Check(self->callbacks.confirm)) { PyErr_SetString(PyExc_TypeError, "Confirm callback is not callable"); @@ -226,10 +141,6 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { if (offline) flags |= PAKFIRE_FLAGS_OFFLINE; - // Configure callbacks - if (self->callbacks.log) - Py_INCREF(self->callbacks.log); - Py_BEGIN_ALLOW_THREADS // Create a new Pakfire instance diff --git a/src/_pakfire/pakfire.h b/src/_pakfire/pakfire.h index 5a37fabe0..5927e6aae 100644 --- a/src/_pakfire/pakfire.h +++ b/src/_pakfire/pakfire.h @@ -31,7 +31,6 @@ typedef struct { // Callbacks struct callbacks { - PyObject* log; PyObject* confirm; } callbacks; } PakfireObject;