[pygobject/gsoc2009: 107/160] Refactor _wrap_g_irepository_get_infos
- From: Simon van der Linden <svdlinden src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygobject/gsoc2009: 107/160] Refactor _wrap_g_irepository_get_infos
- Date: Fri, 14 Aug 2009 21:32:44 +0000 (UTC)
commit 9c3b8e66429e7bd97356561bcc207211f855f22a
Author: Simon van der Linden <svdlinden src gnome org>
Date: Mon Aug 3 23:34:17 2009 +0200
Refactor _wrap_g_irepository_get_infos
gi/module.py | 2 --
gi/pygirepository.c | 48 +++++++++++++++++++++++++++++++++---------------
2 files changed, 33 insertions(+), 17 deletions(-)
---
diff --git a/gi/module.py b/gi/module.py
index a4d2663..7311dbd 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -134,8 +134,6 @@ class DynamicModule(object):
def __members__(self):
r = []
for type_info in repository.get_infos(self.__namespace__):
- if type_info is None:
- continue
r.append(type_info.get_name())
return r
diff --git a/gi/pygirepository.c b/gi/pygirepository.c
index ed490e8..33bc887 100644
--- a/gi/pygirepository.c
+++ b/gi/pygirepository.c
@@ -169,30 +169,48 @@ return_:
}
static PyObject *
-_wrap_g_irepository_get_infos(PyGIRepository *self,
- PyObject *args,
- PyObject *kwargs)
+_wrap_g_irepository_get_infos(PyGIRepository *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "namespace", NULL };
- char *namespace;
- int i, length;
- PyObject *retval;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "s:Repository.get_infos",
- kwlist, &namespace))
+ const char *namespace_;
+ gssize n_infos;
+ PyObject *infos;
+ gssize i;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:Repository.get_infos",
+ kwlist, &namespace_)) {
+ return NULL;
+ }
+
+ n_infos = g_irepository_get_n_infos(self->repository, namespace_);
+ if (n_infos < 0) {
+ PyErr_Format(PyExc_RuntimeError, "Namespace '%s' not loaded", namespace_);
return NULL;
+ }
+
+ infos = PyTuple_New(n_infos);
+
+ for (i = 0; i < n_infos; i++) {
+ GIBaseInfo *info;
+ PyObject *py_info;
- length = g_irepository_get_n_infos(self->repository, namespace);
+ info = g_irepository_get_info(self->repository, namespace_, i);
+ g_assert(info != NULL);
- retval = PyTuple_New(length);
+ py_info = pyg_info_new(info);
+
+ g_base_info_unref(info);
+
+ if (py_info == NULL) {
+ Py_CLEAR(infos);
+ break;
+ }
- for (i = 0; i < length; i++) {
- GIBaseInfo *info = g_irepository_get_info(self->repository, namespace, i);
- PyTuple_SetItem(retval, i, pyg_info_new(info));
+ PyTuple_SET_ITEM(infos, i, py_info);
}
- return retval;
+ return infos;
}
static PyObject *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]