diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2022-02-22 12:57:05 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2022-02-22 12:57:05 (GMT) |
commit | fbde6e0ebfc5b0203eda1c5fe3c6ba72d1427896 (patch) | |
tree | f825dde8617b9efa0e77124785e8afa3f9d1a031 /plugins/pychrysalide/helpers.c | |
parent | 8bf77ba6e5ef40d8bb936dc952ac2c8cc30aab3e (diff) |
Introduce a generic way to subclass Python analysis clients.
Diffstat (limited to 'plugins/pychrysalide/helpers.c')
-rw-r--r-- | plugins/pychrysalide/helpers.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/plugins/pychrysalide/helpers.c b/plugins/pychrysalide/helpers.c index 320e40a..b04c801 100644 --- a/plugins/pychrysalide/helpers.c +++ b/plugins/pychrysalide/helpers.c @@ -37,6 +37,7 @@ #include <i18n.h> #include <common/extstr.h> +#include <plugins/dt.h> #include "access.h" @@ -509,6 +510,63 @@ bool register_python_module_object(PyObject *module, PyTypeObject *type) * args = éventuelle liste d'arguments. * * kwds = éventuel dictionnaire de valeurs mises à disposition. * * * +* Description : Accompagne la création d'une instance dérivée en Python. * +* * +* Retour : Nouvel objet Python mis en place ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *python_constructor_with_dynamic_gtype(PyTypeObject *type, PyObject *args, PyObject *kwds, PyTypeObject *base, GType base_gtype) +{ + PyObject *result; /* Objet à retourner */ + bool first_time; /* Evite les multiples passages*/ + GType gtype; /* Nouveau type de processeur */ + bool status; /* Bilan d'un enregistrement */ + + /* Validations diverses */ + + if (type == base) + goto simple_way; + + /* Mise en place d'un type dédié */ + + first_time = (g_type_from_name(type->tp_name) == 0); + + gtype = build_dynamic_type(base_gtype, type->tp_name, NULL, NULL, NULL); + + if (first_time) + { + status = register_class_for_dynamic_pygobject(gtype, type, base); + + if (!status) + { + result = NULL; + goto exit; + } + + } + + /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */ + + simple_way: + + result = PyType_GenericNew(type, args, kwds); + + exit: + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : type = type du nouvel objet à mettre en place. * +* args = éventuelle liste d'arguments. * +* kwds = éventuel dictionnaire de valeurs mises à disposition. * +* * * Description : Marque l'interdiction d'une instanciation depuis Python. * * * * Retour : NULL pour la levée d'exception. * |