[pybank] Handle errors in the invoked function
- From: Johan Dahlin <johan src gnome org>
- To: svn-commits-list gnome org
- Subject: [pybank] Handle errors in the invoked function
- Date: Tue, 2 Jun 2009 10:44:22 -0400 (EDT)
commit 2e5ce58779cb88a23712a2abcba3a27d4317bf68
Author: Tomeu Vizoso <tomeu sugarlabs org>
Date: Fri May 8 15:07:48 2009 +0200
Handle errors in the invoked function
---
bank/bank-info.c | 45 +++++++++++++++++++++------------------------
1 files changed, 21 insertions(+), 24 deletions(-)
diff --git a/bank/bank-info.c b/bank/bank-info.c
index 15956b0..d85ab09 100644
--- a/bank/bank-info.c
+++ b/bank/bank-info.c
@@ -478,6 +478,20 @@ _wrap_g_function_info_invoke(PyGIBaseInfo *self, PyObject *args)
return_info = g_callable_info_get_return_type( (GICallableInfo*) self->info);
g_assert(return_info != NULL);
+ if (!invoke_ok) {
+ 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);
+ PyErr_SetString(PyExc_RuntimeError, buf);
+ g_error_free(error);
+
+ return NULL;
+ }
+
return_tag = g_type_info_get_tag(return_info);
retval = NULL;
@@ -488,12 +502,8 @@ _wrap_g_function_info_invoke(PyGIBaseInfo *self, PyObject *args)
if (return_tag != GI_TYPE_TAG_VOID)
n_return_values += 1;
- return_values = NULL; /* Quiet gcc warning about initialization */
+ return_values = g_newa(PyObject*, n_return_values);
if (n_return_values > 0) {
- if (invoke_ok) {
- return_values = g_newa(PyObject*, n_return_values);
- }
-
if (return_tag != GI_TYPE_TAG_VOID) {
return_values[next_rval] = pyg_argument_to_pyobject(&return_arg, return_info);
@@ -546,7 +556,7 @@ _wrap_g_function_info_invoke(PyGIBaseInfo *self, PyObject *args)
g_assert(out_args_pos == expected_out_argc);
g_assert(in_args_pos == expected_in_argc);
- if (invoke_ok && n_return_values > 0) {
+ if (n_return_values > 0) {
if (n_return_values == 0) {
retval = Py_None;
Py_INCREF(retval);
@@ -562,25 +572,12 @@ _wrap_g_function_info_invoke(PyGIBaseInfo *self, PyObject *args)
g_base_info_unref( (GIBaseInfo*) return_info);
- if (invoke_ok) {
- 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);
- PyErr_SetString(PyExc_RuntimeError, buf);
- g_error_free(error);
-
- return NULL;
+ if (retval == NULL) {
+ Py_INCREF(Py_None);
+ retval = Py_None;
}
+
+ return retval;
}
static PyMethodDef _PyGIFunctionInfo_methods[] = {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]