From d67565b24c0ac7d12e8b1d3385ba45e72a8c3863 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Tue, 9 Feb 2021 23:54:35 +0100 Subject: Assigned a Python type to native plugins. --- plugins/pychrysalide/core.c | 93 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/plugins/pychrysalide/core.c b/plugins/pychrysalide/core.c index 30d4259..f1191fb 100644 --- a/plugins/pychrysalide/core.c +++ b/plugins/pychrysalide/core.c @@ -107,6 +107,9 @@ static void extend_python_path(const char *); /* Charge autant de greffons composés en Python que possible. */ static void load_python_plugins(GPluginModule *); +/* Efface un type Python pour greffon de la mémoire. */ +static void free_native_plugin_type(PyTypeObject *); + /****************************************************************************** @@ -839,6 +842,28 @@ G_MODULE_EXPORT void chrysalide_plugin_exit(GPluginModule *plugin) /****************************************************************************** * * +* Paramètres : type = informations à libérer de la mémoire. * +* * +* Description : Efface un type Python pour greffon de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void free_native_plugin_type(PyTypeObject *type) +{ + free((char *)type->tp_name); + free((char *)type->tp_doc); + + free(type); + +} + + +/****************************************************************************** +* * * Paramètres : plugin = greffon à manipuler. * * action = type d'action attendue. * * * @@ -852,9 +877,77 @@ G_MODULE_EXPORT void chrysalide_plugin_exit(GPluginModule *plugin) G_MODULE_EXPORT void chrysalide_plugin_on_plugins_loaded(GPluginModule *plugin, PluginAction action) { + size_t count; /* Quantité de greffons chargés*/ + PyTypeObject *parent; /* Type Python pour greffon */ + PyObject *module; /* Module à recompléter */ + PyObject *dict; /* Dictionnaire du module */ + GPluginModule **list; /* Ensemble de ces greffons */ + size_t i; /* Boucle de parcours */ + char *name; /* Désignation complète */ + char *doc; /* Description adaptée */ + int ret; /* Bilan d'un appel */ + PyTypeObject *type; /* Nouveau type dynamique */ + if (action == PGA_NATIVE_PLUGINS_LOADED) + { + /* Intégration des greffons natifs en Python */ + + if (ensure_python_plugin_module_is_registered()) + { + parent = get_python_plugin_module_type(); + + module = get_access_to_python_module("pychrysalide.plugins"); + assert(module != NULL); + + dict = PyModule_GetDict(module); + + list = get_all_plugins(&count); + + for (i = 0; i < count; i++) + { + ret = asprintf(&name, "pychrysalide.plugins.%s", G_OBJECT_TYPE_NAME(list[i]) + 1); + if (ret == -1) + { + LOG_ERROR_N("asprintf"); + continue; + } + + ret = asprintf(&doc, "Place holder for the native plugin %s documentation", + G_OBJECT_TYPE_NAME(list[i]) + 1); + if (ret == -1) + { + LOG_ERROR_N("asprintf"); + free(name); + continue; + } + + type = calloc(1, sizeof(PyTypeObject)); + + type->tp_name = name; + type->tp_doc = doc; + type->tp_flags = Py_TPFLAGS_DEFAULT; + type->tp_new = no_python_constructor_allowed; + + if (register_class_for_pygobject(dict, G_OBJECT_TYPE(list[i]), type, parent)) + g_object_set_data_full(G_OBJECT(list[i]), "python_type", type, + (GDestroyNotify)free_native_plugin_type); + + else + free_native_plugin_type(type); + + } + + } + + if (list != NULL) + free(list); + + /* Chargement des extensions purement Python */ + load_python_plugins(plugin); + } + } -- cgit v0.11.2-87-g4458