From 3a540b5cae1c0f6d92b60c9c42d5807893e34c84 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Tue, 24 Apr 2018 00:04:07 +0200 Subject: Cleaned the Python plugin wrapper a little bit. --- plugins/pychrysalide/plugin.c | 66 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/plugins/pychrysalide/plugin.c b/plugins/pychrysalide/plugin.c index 4689d0c..db1c9f3 100644 --- a/plugins/pychrysalide/plugin.c +++ b/plugins/pychrysalide/plugin.c @@ -67,6 +67,12 @@ static void g_python_plugin_class_init(GPythonPluginClass *); /* Initialise l'instance d'un greffon Python. */ static void g_python_plugin_init(GPythonPlugin *); +/* Supprime toutes les références externes. */ +static void g_python_plugin_dispose(GPythonPlugin *); + +/* Description : Procède à la libération totale de la mémoire. */ +static void g_python_plugin_finalize(GPythonPlugin *); + /* Reconstruit la déclaration d'interface à partir de lectures. */ static bool g_python_plugin_read_interface(GPythonPlugin *); @@ -118,6 +124,12 @@ G_DEFINE_TYPE(GPythonPlugin, g_python_plugin, G_TYPE_PLUGIN_MODULE); static void g_python_plugin_class_init(GPythonPluginClass *klass) { + GObjectClass *object; /* Autre version de la classe */ + + object = G_OBJECT_CLASS(klass); + + object->dispose = (GObjectFinalizeFunc/* ! */)g_python_plugin_dispose; + object->finalize = (GObjectFinalizeFunc)g_python_plugin_finalize; } @@ -142,6 +154,47 @@ static void g_python_plugin_init(GPythonPlugin *plugin) /****************************************************************************** * * +* Paramètres : plugin = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_python_plugin_dispose(GPythonPlugin *plugin) +{ + G_OBJECT_CLASS(g_python_plugin_parent_class)->dispose(G_OBJECT(plugin)); + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_python_plugin_finalize(GPythonPlugin *plugin) +{ + Py_DECREF(plugin->instance); + Py_DECREF(plugin->module); + + G_OBJECT_CLASS(g_python_plugin_parent_class)->finalize(G_OBJECT(plugin)); + +} + + +/****************************************************************************** +* * * Paramètres : modname = nom du module à charger. * * filename = chemin d'accès au code Python à charger. * * * @@ -225,10 +278,7 @@ GPluginModule *g_python_plugin_new(const char *modname, const char *filename) result->instance = instance; if (!g_python_plugin_read_interface(result)) - { - printf("bad interface------------\n"); goto gppn_interface_error; - } /* Localisation des différents points d'entrée déclarés */ @@ -369,11 +419,6 @@ GPluginModule *g_python_plugin_new(const char *modname, const char *filename) /* Conclusion */ - /* - if (!g_plugin_module_load(G_PLUGIN_MODULE(result))) - goto gppn_bad_plugin; - */ - return G_PLUGIN_MODULE(result); gppn_bad_plugin: @@ -382,17 +427,16 @@ GPluginModule *g_python_plugin_new(const char *modname, const char *filename) g_object_unref(G_OBJECT(result)); - //Py_DECREF(instance); + return NULL; gppn_no_instance: gppn_no_class: - //Py_DECREF(module); + Py_DECREF(module); gppn_bad_exit: - printf("bad exit :(\n"); return NULL; } -- cgit v0.11.2-87-g4458