summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/helpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysa/helpers.c')
-rw-r--r--plugins/pychrysa/helpers.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/plugins/pychrysa/helpers.c b/plugins/pychrysa/helpers.c
index 5ba2fb4..d2047df 100644
--- a/plugins/pychrysa/helpers.c
+++ b/plugins/pychrysa/helpers.c
@@ -24,6 +24,10 @@
#include "helpers.h"
+#include <assert.h>
+#include <pygobject.h>
+
+
/******************************************************************************
* *
@@ -181,3 +185,54 @@ bool PyDict_AddStringConstant(PyTypeObject *obj_type, const char *key, const cha
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module où conserver une référence au type créé. *
+* gtype = type dans sa version GLib. *
+* type = type dans sa version Python. *
+* base = type de base de l'objet. *
+* *
+* Description : Enregistre correctement une surcouche de conversion GObject. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_class_for_pygobject(PyObject *dict, GType gtype, PyTypeObject *type, PyTypeObject *base)
+{
+ /**
+ * pygobject_register_class() définit type->tp_base à partir des arguments fournis,
+ * puis fait appel à PyType_Ready().
+ *
+ * PyType_Ready() complète la définition via inherit_special() :
+ *
+ * type->tp_basicsize = type->tp_base->tp_basicsize
+ *
+ * Cependant, il y a un appel à mro_internal() avant, qui mène à solid_base()
+ * puis à extra_ivars(). Et là :
+ *
+ * size_t t_size = type->tp_basicsize;
+ * size_t b_size = base->tp_basicsize;
+ *
+ * assert(t_size >= b_size);
+ *
+ * Si le type de base est spécifié, une taille doit être indiquée.
+ *
+ * Et quelqu'un doit se coller à la tâche. PyGObject ne fait rien, donc...
+ */
+
+ if (type->tp_basicsize < base->tp_basicsize)
+ {
+ assert(type->tp_basicsize == 0);
+ type->tp_basicsize = base->tp_basicsize;
+ }
+
+ pygobject_register_class(dict, NULL, gtype, type, Py_BuildValue("(O)", base));
+
+ return true;
+
+}