[pygobject/pygobject-3-32] pygi_error_marshal_to_py: Fix error return handling. Fixes #315
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/pygobject-3-32] pygi_error_marshal_to_py: Fix error return handling. Fixes #315
- Date: Fri, 19 Apr 2019 18:24:44 +0000 (UTC)
commit f4043503065d73bdf75839e83cfbcfd4b124b606
Author: Christoph Reiter <reiter christoph gmail com>
Date: Sun Mar 24 09:14:43 2019 +0100
pygi_error_marshal_to_py: Fix error return handling. Fixes #315
It returned NULL in case no error was set or if creating the error
result failed and this wasn't checked by the callers.
Change it to return Py_None in case no error was set and NULL in
case of an error. In pygi_error_check() we can't really forward the
error, so just print it and raise RuntimeError instead.
gi/pygi-error.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
---
diff --git a/gi/pygi-error.c b/gi/pygi-error.c
index 8e4a7934..b0eeccd1 100644
--- a/gi/pygi-error.c
+++ b/gi/pygi-error.c
@@ -36,8 +36,10 @@ PyObject *PyGError = NULL;
*
* Checks to see if @error has been set. If @error has been set, then a
* GLib.GError Python exception object is returned (but not raised).
+ * If not error is set returns Py_None.
*
- * Returns: a GLib.GError Python exception object, or NULL.
+ * Returns: a GLib.GError Python exception object, or Py_None,
+ * or NULL and sets an error if creating the exception object fails.
*/
PyObject *
pygi_error_marshal_to_py (GError **error)
@@ -50,7 +52,7 @@ pygi_error_marshal_to_py (GError **error)
g_return_val_if_fail(error != NULL, NULL);
if (*error == NULL)
- return NULL;
+ Py_RETURN_NONE;
state = PyGILState_Ensure();
@@ -93,8 +95,13 @@ pygi_error_check (GError **error)
state = PyGILState_Ensure();
exc_instance = pygi_error_marshal_to_py (error);
- PyErr_SetObject(PyGError, exc_instance);
- Py_DECREF(exc_instance);
+ if (exc_instance != NULL) {
+ PyErr_SetObject(PyGError, exc_instance);
+ Py_DECREF(exc_instance);
+ } else {
+ PyErr_Print ();
+ PyErr_SetString (PyExc_RuntimeError, "Converting the GError failed");
+ }
g_clear_error(error);
PyGILState_Release(state);
@@ -266,11 +273,7 @@ _pygi_marshal_to_py_gerror (PyGIInvokeState *state,
g_error_free (error);
}
- if (py_obj != NULL) {
- return py_obj;
- } else {
- Py_RETURN_NONE;
- }
+ return py_obj;
}
static gboolean
@@ -330,11 +333,7 @@ pygerror_from_gvalue (const GValue *value)
{
GError *gerror = (GError *) g_value_get_boxed (value);
PyObject *pyerr = pygi_error_marshal_to_py (&gerror);
- if (pyerr == NULL) {
- Py_RETURN_NONE;
- } else {
- return pyerr;
- }
+ return pyerr;
}
static int
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]