[pygobject/gsoc2009: 94/160] Refactor _wrap_g_enum_info_get_values
- From: Simon van der Linden <svdlinden src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygobject/gsoc2009: 94/160] Refactor _wrap_g_enum_info_get_values
- Date: Fri, 14 Aug 2009 21:30:59 +0000 (UTC)
commit 71451a69dd0e5b6aaf637526c0509cdb9ff9b4a8
Author: Simon van der Linden <svdlinden src gnome org>
Date: Mon Aug 3 14:29:08 2009 +0200
Refactor _wrap_g_enum_info_get_values
gi/pygiinfo.c | 45 +++++++++++++++++++++++++++++++--------------
1 files changed, 31 insertions(+), 14 deletions(-)
---
diff --git a/gi/pygiinfo.c b/gi/pygiinfo.c
index c838c16..9cac53b 100644
--- a/gi/pygiinfo.c
+++ b/gi/pygiinfo.c
@@ -1148,28 +1148,44 @@ static PyMethodDef _PyGIStructInfo_methods[] = {
{ NULL, NULL, 0 }
};
+
/* EnumInfo */
PYGIINFO_DEFINE_TYPE("EnumInfo", GIEnumInfo, PyGIRegisteredTypeInfo_Type);
static PyObject *
_wrap_g_enum_info_get_values(PyGIBaseInfo *self)
{
- int n_values, i;
- GIValueInfo *value;
- PyObject *list;
+ gssize n_infos;
+ PyObject *infos;
+ gssize i;
- g_base_info_ref(self->info);
- n_values = g_enum_info_get_n_values((GIEnumInfo*)self->info);
- list = PyList_New(n_values);
- for (i = 0; i < n_values; i++)
- {
- value = g_enum_info_get_value((GIEnumInfo*)self->info, i);
- PyList_SetItem(list, i, pyg_info_new(value));
- g_base_info_unref((GIBaseInfo*)value);
+ n_infos = g_enum_info_get_n_values((GIEnumInfo *)self->info);
+
+ infos = PyTuple_New(n_infos);
+ if (infos == NULL) {
+ return NULL;
+ }
+
+ for (i = 0; i < n_infos; i++) {
+ GIBaseInfo *info;
+ PyObject *py_info;
+
+ info = (GIBaseInfo *)g_enum_info_get_value((GIEnumInfo *)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;
}
- g_base_info_unref(self->info);
- return list;
+ PyTuple_SET_ITEM(infos, i, py_info);
+ }
+
+ return infos;
}
static PyMethodDef _PyGIEnumInfo_methods[] = {
@@ -1177,6 +1193,7 @@ static PyMethodDef _PyGIEnumInfo_methods[] = {
{ NULL, NULL, 0 }
};
+
/* ObjectInfo */
PYGIINFO_DEFINE_TYPE("ObjectInfo", GIObjectInfo, PyGIRegisteredTypeInfo_Type);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]