summaryrefslogtreecommitdiffstats
path: root/gobject/pygobject.c
diff options
context:
space:
mode:
authorJohan Dahlin <johan@src.gnome.org>2005-07-05 17:16:40 +0000
committerJohan Dahlin <johan@src.gnome.org>2005-07-05 17:16:40 +0000
commit4dd8caf2aae815a22e07f035839bf43739d03feb (patch)
tree46cb5e5d7c978fb8745769469bc9530fccabfd4b /gobject/pygobject.c
parent53a2982568439dcd103bd8c302256daef4400c68 (diff)
downloadpygobject-4dd8caf2aae815a22e07f035839bf43739d03feb.tar.gz
pygobject-4dd8caf2aae815a22e07f035839bf43739d03feb.tar.xz
pygobject-4dd8caf2aae815a22e07f035839bf43739d03feb.zip
Add support for specifying name for a GObject subclass, using
* gobject/gobjectmodule.c: (_wrap_pyg_type_register), (get_type_name_for_class), (pyg_type_register): * gobject/pygobject-private.h: * gobject/pygobject.c: (pygobjectmeta_register), (pygobjectmeta_init): * tests/test_gtype.py: Add support for specifying name for a GObject subclass, using __gtype_name__. Add a unittest. Fixes #169498
Diffstat (limited to 'gobject/pygobject.c')
-rw-r--r--gobject/pygobject.c35
1 files changed, 28 insertions, 7 deletions
diff --git a/gobject/pygobject.c b/gobject/pygobject.c
index 2c7913d..2b2b2c4 100644
--- a/gobject/pygobject.c
+++ b/gobject/pygobject.c
@@ -1244,21 +1244,42 @@ PyTypeObject PyGObject_Type = {
};
+static int
+pygobjectmeta_register(PyTypeObject *subtype, PyObject *instance_dict)
+{
+ PyObject *pytype_name;
+ char *type_name = NULL;
+ int retval = 0;
+
+ if (!instance_dict) {
+ PyErr_Clear();
+ goto out;
+ }
+
+ /* If it's already registered, skip registration */
+ if (PyDict_GetItemString(instance_dict, "__gtype__"))
+ goto out;
+
+ pytype_name = PyDict_GetItemString(instance_dict, "__gtype_name__");
+ if (pytype_name)
+ type_name = g_strdup(PyString_AsString(pytype_name));
+ retval = pyg_type_register(subtype, type_name);
- /* -------- GObject MetaClass -----------*/
+out:
+ return retval;
+}
+
+/* -------- GObject MetaClass -----------*/
static int
pygobjectmeta_init(PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
{
PyObject *instance_dict;
+
if (PyType_Type.tp_init((PyObject *) subtype, args, kwargs))
return -1;
+
instance_dict = PyTuple_GetItem(args, 2);
- if (instance_dict) {
- if (PyDict_GetItemString(instance_dict, "__gtype__") == NULL)
- return pyg_type_register(subtype);
- } else
- PyErr_Clear();
- return 0;
+ return pygobjectmeta_register(subtype, instance_dict);
}