[pygobject/gsoc2009: 93/160] Refactor _wrap_g_struct_info_get_methods



commit 6dbe86f208fe37c7ccead9ad22ea1ea10e71421f
Author: Simon van der Linden <svdlinden src gnome org>
Date:   Mon Aug 3 14:25:33 2009 +0200

    Refactor _wrap_g_struct_info_get_methods

 gi/pygiinfo.c |   43 +++++++++++++++++++++++++++++--------------
 1 files changed, 29 insertions(+), 14 deletions(-)
---
diff --git a/gi/pygiinfo.c b/gi/pygiinfo.c
index 7875291..c838c16 100644
--- a/gi/pygiinfo.c
+++ b/gi/pygiinfo.c
@@ -1099,22 +1099,37 @@ _wrap_g_struct_info_get_fields(PyGIBaseInfo *self)
 static PyObject *
 _wrap_g_struct_info_get_methods(PyGIBaseInfo *self)
 {
-    int i, length;
-    PyObject *retval;
+    gssize n_infos;
+    PyObject *infos;
+    gssize i;
 
-    g_base_info_ref(self->info);
-    length = g_struct_info_get_n_methods((GIStructInfo*)self->info);
-    retval = PyTuple_New(length);
+    n_infos = g_struct_info_get_n_methods((GIStructInfo *)self->info);
 
-    for (i = 0; i < length; i++) {
-        GIFunctionInfo *function;
-        function = g_struct_info_get_method((GIStructInfo*)self->info, i);
-        PyTuple_SetItem(retval, i, pyg_info_new(function));
-        g_base_info_unref((GIBaseInfo*)function);
+    infos = PyTuple_New(n_infos);
+    if (infos == NULL) {
+        return NULL;
     }
-    g_base_info_unref(self->info);
 
-    return retval;
+    for (i = 0; i < n_infos; i++) {
+        GIBaseInfo *info;
+        PyObject *py_info;
+
+        info = (GIBaseInfo *)g_struct_info_get_method((GIStructInfo *)self->info, i);
+        g_assert(info != NULL);
+
+        py_info = pyg_info_new(info);
+
+        g_base_info_unref(info);
+
+        if (py_info == NULL) {
+            Py_CLEAR(infos);
+            break;
+        }
+
+        PyTuple_SET_ITEM(infos, i, py_info);
+    }
+
+    return infos;
 }
 
 static PyObject *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]