diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2016-07-30 10:57:08 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2016-07-30 10:57:08 (GMT) |
commit | fb1d26845908d131b1c92d7d7cd1bc402b656ca4 (patch) | |
tree | a6c6a30482ce97dfe7b985116877bb0ce8b7b0a0 /plugins/pychrysa/helpers.c | |
parent | 7b8eed3f8207fe9b629165f8230e38ee620900ea (diff) |
Registered properly the PyGObject wrappers for Python classes.
Diffstat (limited to 'plugins/pychrysa/helpers.c')
-rw-r--r-- | plugins/pychrysa/helpers.c | 55 |
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; + +} |