[pygobject] Move child info retrieval into generic function
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Move child info retrieval into generic function
- Date: Mon, 7 Oct 2013 22:06:34 +0000 (UTC)
commit d2aef364de778da966bc1cfffe184d649f9ebb21
Author: Simon Feltman <sfeltman src gnome org>
Date: Tue Sep 24 06:26:17 2013 -0700
Move child info retrieval into generic function
Add a generic function for bindings which return a single child info.
This trivializes binding methods like PyGIObjectInfo.get_parent and
fixes leaks in PyGIObjectInfo.get_class_struct and
PyGIVFuncInfo.get_invoker.
https://bugzilla.gnome.org/show_bug.cgi?id=709008
gi/pygi-info.c | 56 +++++++++++++++++++++++---------------------------------
1 files changed, 23 insertions(+), 33 deletions(-)
---
diff --git a/gi/pygi-info.c b/gi/pygi-info.c
index fa5a492..636b16d 100644
--- a/gi/pygi-info.c
+++ b/gi/pygi-info.c
@@ -53,6 +53,23 @@ _generate_doc_string(PyGIBaseInfo *self)
return PyObject_CallFunctionObjArgs (_py_generate_doc_string, self, NULL);
}
+static PyObject *
+_get_child_info (PyGIBaseInfo *self,
+ GIBaseInfo* (*get_child_info)(GIBaseInfo*))
+{
+ GIBaseInfo *info;
+ PyObject *py_info;
+
+ info = get_child_info ((GIBaseInfo*)self->info);
+ if (info == NULL) {
+ Py_RETURN_NONE;
+ }
+
+ py_info = _pygi_info_new (info);
+ g_base_info_unref (info);
+ return py_info;
+}
+
/* _make_infos_tuple
*
@@ -222,6 +239,9 @@ _wrap_g_base_info_get_namespace (PyGIBaseInfo *self)
static PyObject *
_wrap_g_base_info_get_container (PyGIBaseInfo *self)
{
+ /* Note: don't use _get_child_info because g_base_info_get_container
+ * is marked as [transfer none] and therefore returns a borrowed ref.
+ */
GIBaseInfo *info;
info = g_base_info_get_container (self->info);
@@ -1108,20 +1128,7 @@ PYGLIB_DEFINE_TYPE ("ObjectInfo", PyGIObjectInfo_Type, PyGIBaseInfo);
static PyObject *
_wrap_g_object_info_get_parent (PyGIBaseInfo *self)
{
- GIBaseInfo *info;
- PyObject *py_info;
-
- info = (GIBaseInfo *) g_object_info_get_parent ( (GIObjectInfo*) self->info);
-
- if (info == NULL) {
- Py_RETURN_NONE;
- }
-
- py_info = _pygi_info_new (info);
-
- g_base_info_unref (info);
-
- return py_info;
+ return _get_child_info (self, g_object_info_get_parent);
}
static PyObject *
@@ -1164,15 +1171,7 @@ _wrap_g_object_info_get_abstract (PyGIBaseInfo *self)
static PyObject *
_wrap_g_object_info_get_class_struct (PyGIBaseInfo *self)
{
- GIBaseInfo *info;
-
- info = g_object_info_get_class_struct ((GIObjectInfo*)self->info);
-
- if (info == NULL) {
- Py_RETURN_NONE;
- }
-
- return _pygi_info_new (info);
+ return _get_child_info (self, g_object_info_get_class_struct);
}
static PyMethodDef _PyGIObjectInfo_methods[] = {
@@ -1557,16 +1556,7 @@ PYGLIB_DEFINE_TYPE ("gi.VFuncInfo", PyGIVFuncInfo_Type, PyGICallableInfo);
static PyObject *
_wrap_g_vfunc_info_get_invoker (PyGIBaseInfo *self)
{
- PyObject *result = Py_None;
- GIBaseInfo *info;
-
- info = (GIBaseInfo *) g_vfunc_info_get_invoker ( (GIVFuncInfo *) self->info );
- if (info)
- result = _pygi_info_new(info);
- else
- Py_INCREF(Py_None);
-
- return result;
+ return _get_child_info (self, g_vfunc_info_get_invoker);
}
static PyMethodDef _PyGIVFuncInfo_methods[] = {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]