Lazy load the python plugin provider
[babeltrace.git] / lib / plugin / plugin.c
index b11931474ac6cfce5330400d8009e8eeb2fb5d5a..3ff50de62161fb89464fb6df038ac7e8ba045c32 100644 (file)
 static
 struct bt_plugin_set *(*bt_plugin_python_create_all_from_file_sym)(const char *path) =
        bt_plugin_python_create_all_from_file;
+
+static
+void init_python_plugin_provider(void) {}
 #else /* BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT */
 static GModule *python_plugin_provider_module;
 static
 struct bt_plugin_set *(*bt_plugin_python_create_all_from_file_sym)(const char *path);
 
-__attribute__((constructor)) static
+static
 void init_python_plugin_provider(void) {
+       if (bt_plugin_python_create_all_from_file_sym != NULL) {
+               return;
+       }
+
        BT_LOGD_STR("Loading Python plugin provider module.");
        python_plugin_provider_module =
-               g_module_open(PYTHON_PLUGIN_PROVIDER_FILENAME,
-                       G_MODULE_BIND_LOCAL);
+               g_module_open(PYTHON_PLUGIN_PROVIDER_FILENAME, 0);
        if (!python_plugin_provider_module) {
-               BT_LOGI("Cannot find `%s`: continuing without Python plugin support.",
-                       PYTHON_PLUGIN_PROVIDER_FILENAME);
+               BT_LOGI("Cannot open `%s`: %s: continuing without Python plugin support.",
+                       PYTHON_PLUGIN_PROVIDER_FILENAME, g_module_error());
                return;
        }
 
@@ -170,6 +176,7 @@ struct bt_plugin_set *bt_plugin_create_all_from_file(const char *path)
        }
 
        /* Try Python plugins if support is available */
+       init_python_plugin_provider();
        if (bt_plugin_python_create_all_from_file_sym) {
                plugin_set = bt_plugin_python_create_all_from_file_sym(path);
                if (plugin_set) {
@@ -406,13 +413,16 @@ int nftw_append_all_from_dir(const char *file, const struct stat *sb, int flag,
 
        switch (flag) {
        case FTW_F:
+       {
+               struct bt_plugin_set *plugins_from_file;
+
                if (name[0] == '.') {
                        /* Skip hidden files */
                        BT_LOGV("Skipping hidden file: path=\"%s\"", file);
                        goto end;
                }
-               struct bt_plugin_set *plugins_from_file =
-                       bt_plugin_create_all_from_file(file);
+
+               plugins_from_file = bt_plugin_create_all_from_file(file);
 
                if (plugins_from_file) {
                        size_t j;
@@ -430,6 +440,7 @@ int nftw_append_all_from_dir(const char *file, const struct stat *sb, int flag,
                        bt_put(plugins_from_file);
                }
                break;
+       }
        case FTW_DNR:
                /* Continue to next file / directory. */
                BT_LOGW("Cannot enter directory: continuing: path=\"%s\"", file);
This page took 0.038363 seconds and 4 git commands to generate.