about summary refs log tree commit diff stats
path: root/src/plugins
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-07-09 23:13:36 +0100
committerJames Booth <boothj5@gmail.com>2016-07-09 23:13:36 +0100
commit7776c1494ad83f6094e4997fd3f647cb413b538e (patch)
tree2b5c2f63fe58fb52d67d0ed60ed1f1a404d9012f /src/plugins
parent1926ceea3d11cdf83fc2323aa512861e342e1eba (diff)
downloadprofani-tty-7776c1494ad83f6094e4997fd3f647cb413b538e.tar.gz
Reaload python module if previous loaded on /plugin load
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/python_plugins.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/plugins/python_plugins.c b/src/plugins/python_plugins.c
index efd225b0..69c40eca 100644
--- a/src/plugins/python_plugins.c
+++ b/src/plugins/python_plugins.c
@@ -43,6 +43,7 @@
 #include "ui/ui.h"
 
 static PyThreadState *thread_state;
+static GHashTable *unloaded_modules;
 
 void
 allow_python_threads()
@@ -59,6 +60,8 @@ disable_python_threads()
 void
 python_env_init(void)
 {
+    unloaded_modules = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
+
     Py_Initialize();
     PyEval_InitThreads();
     python_api_init();
@@ -81,7 +84,15 @@ python_plugin_create(const char *const filename)
 {
     disable_python_threads();
     gchar *module_name = g_strndup(filename, strlen(filename) - 3);
-    PyObject *p_module = PyImport_ImportModule(module_name);
+
+    PyObject *p_module = g_hash_table_lookup(unloaded_modules, filename);
+    if (p_module) {
+        p_module = PyImport_ReloadModule(p_module);
+        g_hash_table_remove(unloaded_modules, filename);
+    } else {
+        p_module = PyImport_ImportModule(module_name);
+    }
+
     python_check_error();
     if (p_module) {
         ProfPlugin *plugin = malloc(sizeof(ProfPlugin));
@@ -910,8 +921,9 @@ python_plugin_destroy(ProfPlugin *plugin)
 {
     disable_python_threads();
     callbacks_remove(plugin->name);
+    g_hash_table_insert(unloaded_modules, strdup(plugin->name), plugin->module);
+//    Py_XDECREF(plugin->module);
     free(plugin->name);
-    Py_XDECREF(plugin->module);
     free(plugin);
     allow_python_threads();
 }