From b7bbb6938db95b8c302a5afa0f7360519c0ac132 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 19 Jun 2020 21:02:56 +0200 Subject: [PATCH 02/21] python: remove deprecated PyErr_Warn (#44287) --- bindings/python/wrapper_top.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/bindings/python/wrapper_top.c b/bindings/python/wrapper_top.c index e6ba00f1..89cb00e4 100644 --- a/bindings/python/wrapper_top.c +++ b/bindings/python/wrapper_top.c @@ -61,6 +61,16 @@ static char *get_pystring(PyObject *string, Py_ssize_t *size) { return ret; } #define PyStringFree(string) ; +void PyErr_WarnFormat(PyObject *category, int stacklevel, const char *format, ...) { + + va_list ap; + char s[1024]; + + va_start(ap, format); + g_vsnprintf(s, 1024, format, ap); + va_end(ap); + PyErr_WarnEx(category, s, stacklevel); +} #endif GQuark lasso_wrapper_key; @@ -120,7 +130,7 @@ get_dict_from_hashtable_of_objects(GHashTable *value) PyDict_SetItemString(dict, (char*)keys->data, item); Py_DECREF(item); } else { - PyErr_Warn(PyExc_RuntimeWarning, "hashtable contains a null value"); + PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "hashtable contains a null value"); } } g_list_free(begin); @@ -149,7 +159,7 @@ get_dict_from_hashtable_of_strings(GHashTable *value) PyDict_SetItemString(dict, (char*)keys->data, item); Py_DECREF(item); } else { - PyErr_Warn(PyExc_RuntimeWarning, "hashtable contains a null value"); + PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "hashtable contains a null value"); } } g_list_free(begin); @@ -424,8 +434,7 @@ get_list_of_strings(const GList *a_list) { PyTuple_SetItem(a_tuple, i, str); i++; } else { - PyErr_Warn(PyExc_RuntimeWarning, - "list contains a NULL value"); + PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "list contains a NULL value"); } a_list = a_list->next; } @@ -457,12 +466,10 @@ get_list_of_xml_nodes(const GList *a_list) { PyTuple_SetItem(a_tuple, i, str); i++; } else { - PyErr_Warn(PyExc_RuntimeWarning, - "could not convert an xmlNode to a string"); + PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "could not convert an xmlNode to a string"); } } else { - PyErr_Warn(PyExc_RuntimeWarning, - "list contains a NULL value"); + PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "list contains a NULL value"); } a_list = a_list->next; } @@ -495,12 +502,10 @@ get_list_of_pygobject(const GList *a_list) { PyTuple_SetItem(a_tuple, i, pygobject); i++; } else { - PyErr_Warn(PyExc_RuntimeWarning, - "could not convert a GObject to a PyGobject"); + PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "could not convert a GObject to a PyGobject"); } } else { - PyErr_Warn(PyExc_RuntimeWarning, - "list contains a NULL value"); + PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "list contains a NULL value"); } a_list = a_list->next; } -- 2.26.2