Projet

Général

Profil

0001-Clear-Python-error-indicator-after-logging-56572.patch

Benjamin Dauvergne, 04 septembre 2021 10:50

Télécharger (1,75 ko)

Voir les différences:

Subject: [PATCH] Clear Python error indicator after logging (#56572)

Lasso log using the GLib logging API and the Python binding install a
hook to delegate logging to a Python logger named "lasso".

During the logging call the error indicator can be set to signal an
exception. The indicator will still be set when we return from the Lasso
API call, and is not handled by the Python wrapping of the C functions.
If our function returns a non-NULL value, the Python interpreter will
raise because this situation is forbidden.

To prevent it, if we detect that an exception occurred during logging
calls, we print it to stderr, clear the error indicator and return
immediately.
 bindings/python/wrapper_top.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
bindings/python/wrapper_top.c
739 739
		G_GNUC_UNUSED gpointer user_data)
740 740
{
741 741
	PyObject *logger_object = get_logger_object(domain), *result;
742

  
743
	if (PyErr_Occurred()) {
744
		PyErr_Print();
745
		PyErr_Clear();
746
		return;
747
	}
748

  
742 749
	char *method = NULL;
743 750

  
744 751
	if (! logger_object) {
......
773 780
	} else {
774 781
		PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "lasso could not call method %s on its logger", method);
775 782
	}
783
	/* clear any exception emitted during log call */
784
	if (PyErr_Occurred()) {
785
		PyErr_Print();
786
	}
787
	PyErr_Clear();
776 788
}
777
-