[pygobject/gsoc2009: 144/160] Register introspected boxed types
- From: Simon van der Linden <svdlinden src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygobject/gsoc2009: 144/160] Register introspected boxed types
- Date: Fri, 14 Aug 2009 21:35:50 +0000 (UTC)
commit becd2e33f7e06174834d3745456f682356c49603
Author: Simon van der Linden <svdlinden src gnome org>
Date: Wed Aug 12 16:52:40 2009 +0200
Register introspected boxed types
gi/pygi-info.c | 32 ++++++++++++++++++++++++++++++++
gi/types.py | 3 +++
gobject/gobjectmodule.c | 4 +++-
gobject/pygboxed.c | 13 +++++++++++--
gobject/pygboxed.h | 3 +++
gobject/pygobject.h | 5 +++++
6 files changed, 57 insertions(+), 3 deletions(-)
---
diff --git a/gi/pygi-info.c b/gi/pygi-info.c
index d1c9fee..d3fc32f 100644
--- a/gi/pygi-info.c
+++ b/gi/pygi-info.c
@@ -1100,9 +1100,41 @@ _wrap_g_struct_info_get_methods (PyGIBaseInfo *self)
return infos;
}
+static PyObject *
+_wrap_g_struct_info_register_type (PyGIBaseInfo *self,
+ PyObject *args,
+ PyObject *kwargs)
+{
+ static char *kwlist[] = { "type", NULL };
+ PyTypeObject *type;
+ GType g_type;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O!:StructInfo.register_type",
+ kwlist, &PyType_Type, &type)) {
+ return NULL;
+ }
+
+ if (!PyType_IsSubtype(type, &PyGBoxed_Type)) {
+ PyErr_SetString(PyExc_TypeError, "argument 1: Must be a subtype of gobject.GBoxed");
+ return NULL;
+ }
+
+ g_type = g_registered_type_info_get_g_type((GIRegisteredTypeInfo *)self->info);
+ if (!g_type_is_a(g_type, G_TYPE_BOXED)) {
+ PyErr_Format(PyExc_TypeError, "unable to register type; %s is not a boxed type", g_type_name(g_type));
+ return NULL;
+ }
+
+ pyg_register_boxed_type(g_type, type);
+
+ Py_RETURN_NONE;
+}
+
static PyMethodDef _PyGIStructInfo_methods[] = {
{ "get_fields", (PyCFunction)_wrap_g_struct_info_get_fields, METH_NOARGS },
{ "get_methods", (PyCFunction)_wrap_g_struct_info_get_methods, METH_NOARGS },
+ { "register_type", (PyCFunction)_wrap_g_struct_info_register_type, METH_VARARGS | METH_KEYWORDS },
{ NULL, NULL, 0 }
};
diff --git a/gi/types.py b/gi/types.py
index ecd3469..4e47302 100644
--- a/gi/types.py
+++ b/gi/types.py
@@ -111,3 +111,6 @@ class StructMeta(type, MetaClassHelper):
cls._setup_fields()
cls._setup_methods()
+ if cls.__gtype__.is_a(gobject.GBoxed):
+ cls.__info__.register_type(cls)
+
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index aeebb8c..293f011 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -2580,7 +2580,9 @@ struct _PyGObject_Functions pygobject_api_functions = {
pygobject_new_from_type,
&PyGInterface_Type,
- pyg_register_interface_type
+ pyg_register_interface_type,
+
+ pyg_register_boxed_type
};
/* for addon libraries ... */
diff --git a/gobject/pygboxed.c b/gobject/pygboxed.c
index c3dc744..71ec9e9 100644
--- a/gobject/pygboxed.c
+++ b/gobject/pygboxed.c
@@ -87,13 +87,20 @@ pyg_boxed_copy(PyGBoxed *self)
}
-
static PyMethodDef pygboxed_methods[] = {
{ "copy", (PyCFunction) pyg_boxed_copy, METH_NOARGS },
{ NULL, NULL, 0 }
};
+void
+pyg_register_boxed_type (GType g_type,
+ PyTypeObject *type)
+{
+ Py_INCREF((PyObject *)type);
+ g_type_set_qdata(g_type, pygboxed_type_key, type);
+}
+
/**
* pyg_register_boxed:
* @dict: the module dictionary to store the wrapper class.
@@ -129,9 +136,11 @@ pyg_register_boxed(PyObject *dict, const gchar *class_name,
o=pyg_type_wrapper_new(boxed_type));
Py_DECREF(o);
- g_type_set_qdata(boxed_type, pygboxed_type_key, type);
+ pyg_register_boxed_type (boxed_type, type);
PyDict_SetItemString(dict, (char *)class_name, (PyObject *)type);
+
+ Py_DECREF((PyObject *)type);
}
/**
diff --git a/gobject/pygboxed.h b/gobject/pygboxed.h
index 8433b9d..f719967 100644
--- a/gobject/pygboxed.h
+++ b/gobject/pygboxed.h
@@ -22,6 +22,9 @@
#ifndef __PYGOBJECT_BOXED_H__
#define __PYGOBJECT_BOXED_H__
+void pyg_register_boxed_type (GType g_type,
+ PyTypeObject *type);
+
void pygobject_boxed_register_types(PyObject *d);
#endif /* __PYGOBJECT_BOXED_H__ */
diff --git a/gobject/pygobject.h b/gobject/pygobject.h
index 2ec96fb..1b15d9c 100644
--- a/gobject/pygobject.h
+++ b/gobject/pygobject.h
@@ -211,6 +211,9 @@ struct _PyGObject_Functions {
PyTypeObject *interface_type;
void (*register_interface_type) (GType g_type,
PyTypeObject *type);
+
+ void (*register_boxed_type) (GType g_type,
+ PyTypeObject *type);
};
#ifndef _INSIDE_PYGOBJECT_
@@ -286,6 +289,8 @@ struct _PyGObject_Functions *_PyGObject_API;
#define PyGInterface_Type (*_PyGObject_API->interface_type)
#define pyg_register_interface_type (_PyGObject_API->register_interface_type)
+#define pyg_register_boxed_type (_PyGObject_API->register_boxed_type)
+
#define pyg_block_threads() G_STMT_START { \
if (_PyGObject_API->block_threads != NULL) \
(* _PyGObject_API->block_threads)(); \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]