From 04a523ac27618c29ff140bc746675e29e257894a Mon Sep 17 00:00:00 2001 From: "alexey.stratulat" <alexey.stratulat@demlabs.net> Date: Sun, 5 Apr 2020 17:10:05 +0700 Subject: [PATCH] [*] Fixed procedure deinitialization plugins. --- src/dap_chain_plugins.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/dap_chain_plugins.c b/src/dap_chain_plugins.c index 98a8822..e3ed1e3 100644 --- a/src/dap_chain_plugins.c +++ b/src/dap_chain_plugins.c @@ -36,9 +36,6 @@ int dap_chain_plugins_init(dap_config_t *config){ } return 0; } -void dap_chain_plugins_deinit(){ - Py_Finalize(); -} void dap_chain_plugins_loading(){ log_it(L_NOTICE, "Loading plugins"); @@ -123,3 +120,23 @@ void dap_chain_plugins_load_plugin(const char *dir_path, const char *name){ } } +void dap_chain_plugins_deinit(){ + log_it(L_NOTICE, "Deinit python plugins"); + dap_chain_plugin_list_module_t *plugins = dap_chain_plugins_list_get(); + dap_chain_plugin_list_module_t *plugin; + dap_chain_plugin_list_module_t *tmp; + PyObject *res_int = NULL; + LL_FOREACH_SAFE(plugins, plugin, tmp){ + PyObject *func_deinit = PyObject_GetAttrString(plugin->obj_module, "deinit"); + if (func_deinit != NULL || PyCallable_Check(func_deinit)){ + res_int = PyEval_CallObject(func_deinit, NULL); + } else { + log_it(L_WARNING, "For plugin %s can't callable function deinit", plugin->name); + } + DAP_FREE(plugin->name); + Py_XDECREF(plugin->obj_module); + LL_DELETE(plugins, plugin); + } + Py_Finalize(); +} + -- GitLab