[pybank] Improve error reporting in invoke() and return None when function has no return value.
- From: Johan Dahlin <johan src gnome org>
- To: svn-commits-list gnome org
- Subject: [pybank] Improve error reporting in invoke() and return None when function has no return value.
- Date: Tue, 2 Jun 2009 10:44:02 -0400 (EDT)
commit a01cbc4204f20e37f45a413c233bb55ecdb70c0d
Author: Tomeu Vizoso <tomeu sugarlabs org>
Date: Fri May 8 11:50:35 2009 +0200
Improve error reporting in invoke() and return None when function has no return value.
---
bank/bank-info.c | 32 +++++++++++++++++---------------
1 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/bank/bank-info.c b/bank/bank-info.c
index e751584..21ecd6c 100644
--- a/bank/bank-info.c
+++ b/bank/bank-info.c
@@ -400,8 +400,10 @@ _wrap_g_function_info_invoke(PyGIBaseInfo *self, PyObject *args)
GIInfoType type = g_base_info_get_type(container);
py_arg = PyTuple_GetItem(args, 0);
- if (!py_arg)
+ if (!py_arg) {
+ PyErr_SetString(PyExc_ValueError, "Calling a method without passing an instance");
return NULL;
+ }
if (py_arg == Py_None)
in_args[0].v_pointer = NULL;
else if (type == GI_INFO_TYPE_STRUCT || type == GI_INFO_TYPE_BOXED) {
@@ -456,7 +458,7 @@ _wrap_g_function_info_invoke(PyGIBaseInfo *self, PyObject *args)
}
if (failed) {
- g_error("Failed to convert all args.");
+ PyErr_SetString(PyExc_ValueError, "Failed to convert all args.");
return NULL;
}
@@ -470,11 +472,6 @@ _wrap_g_function_info_invoke(PyGIBaseInfo *self, PyObject *args)
&return_arg,
&error);
- /* Return value and out arguments are valid only if invocation doesn't
- * return error. In arguments need to be released always.
- */
- failed = FALSE;
-
return_info = g_callable_info_get_return_type( (GICallableInfo*) self->info);
g_assert(return_info != NULL);
@@ -563,18 +560,23 @@ _wrap_g_function_info_invoke(PyGIBaseInfo *self, PyObject *args)
g_base_info_unref( (GIBaseInfo*) return_info);
if (invoke_ok) {
- return failed ? NULL : retval;
+ if (retval == NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ } else
+ return retval;
} else {
+ char buf[256];
+ snprintf(buf, sizeof(buf), "Error invoking %s.%s: %s",
+ g_base_info_get_namespace( (GIBaseInfo*) self->info),
+ g_base_info_get_name( (GIBaseInfo*) self->info),
+ error->message);
+
g_assert(error != NULL);
- g_error("Error invoking %s.%s: %s",
- g_base_info_get_namespace( (GIBaseInfo*) self->info),
- g_base_info_get_name( (GIBaseInfo*) self->info),
- error->message);
+ PyErr_SetString(PyExc_RuntimeError, buf);
g_error_free(error);
- retval = Py_None;
- Py_INCREF(retval);
- return retval;
+ return NULL;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]