[pygobject/gsoc2009: 98/160] Refactor _wrap_g_object_info_get_interfaces



commit 604ed2f9213981d6b3b0076541363b04df50305e
Author: Simon van der Linden <svdlinden src gnome org>
Date:   Mon Aug 3 15:54:38 2009 +0200

    Refactor _wrap_g_object_info_get_interfaces

 gi/pygiinfo.c |   40 +++++++++++++++++++++++++++-------------
 1 files changed, 27 insertions(+), 13 deletions(-)
---
diff --git a/gi/pygiinfo.c b/gi/pygiinfo.c
index 6d65d1f..3c3e1a6 100644
--- a/gi/pygiinfo.c
+++ b/gi/pygiinfo.c
@@ -1291,22 +1291,37 @@ _wrap_g_object_info_get_fields(PyGIBaseInfo *self)
 static PyObject *
 _wrap_g_object_info_get_interfaces(PyGIBaseInfo *self)
 {
-    int i, length;
-    PyObject *retval;
+    gssize n_infos;
+    PyObject *infos;
+    gssize i;
 
-    g_base_info_ref(self->info);
-    length = g_object_info_get_n_interfaces((GIObjectInfo*)self->info);
-    retval = PyTuple_New(length);
+    n_infos = g_object_info_get_n_interfaces((GIObjectInfo *)self->info);
 
-    for (i = 0; i < length; i++) {
-        GIInterfaceInfo *interface;
-        interface = g_object_info_get_interface((GIObjectInfo*)self->info, i);
-        PyTuple_SetItem(retval, i, pyg_info_new(interface));
-        g_base_info_unref((GIBaseInfo*)interface);
+    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_object_info_get_interface((GIObjectInfo *)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 PyMethodDef _PyGIObjectInfo_methods[] = {
@@ -1318,7 +1333,6 @@ static PyMethodDef _PyGIObjectInfo_methods[] = {
 };
 
 
-
 /* GIInterfaceInfo */
 PYGIINFO_DEFINE_TYPE("InterfaceInfo", GIInterfaceInfo, PyGIRegisteredTypeInfo_Type);
 



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