summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChun-wei Fan <fanchunwei@src.gnome.org>2019-11-19 16:34:49 +0800
committerChun-wei Fan <fanchunwei@src.gnome.org>2020-10-09 09:32:27 +0800
commit37d70f4a282f990c19aee17ba838df6dd8602957 (patch)
treea2f313d3e838454ab91a936c3c893611a075f0f7
parentfd57c27fece4b9d4279d03948adb5a8d10e3b872 (diff)
downloadlibpeas-37d70f4a282f990c19aee17ba838df6dd8602957.tar.gz
peas-object-module.c: Add fallback module search for Windows
When we specify the plugin module name via a plugin file, g_module_build_path() will append a 'lib' prefix to the final filename of the module DLL, which may cause the module load to fail because the module DLL is not built with the 'lib' prefix for its filename, which is often the case for Meson builds with Visual Studio and also likely in other scenarios. Fix this by adding a fallback check for Windows, that we look for the module DLL without the 'lib' prefix by appending '.dll' to the module name that we pass into g_module_build_path(), if we can't find the module DLL with the 'lib' prefix.
-rw-r--r--libpeas/peas-object-module.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/libpeas/peas-object-module.c b/libpeas/peas-object-module.c
index 10e7d82..d48b6fb 100644
--- a/libpeas/peas-object-module.c
+++ b/libpeas/peas-object-module.c
@@ -108,8 +108,23 @@ peas_object_module_load (GTypeModule *gmodule)
{
gchar *path;
GModuleFlags flags = 0;
+ gchar *fallback_path = NULL;
- path = g_module_build_path (priv->path, priv->module_name);
+#ifdef G_OS_WIN32
+ if (!g_str_has_suffix (priv->module_name, "." G_MODULE_SUFFIX))
+ {
+ /* On Windows, g_module_build_path() will add a "lib" prefix,
+ * to the module_name unless a ".dll" suffix is appended to the
+ * module_name. So, we also try to look for a DLL whose filename
+ * is the module name in the case that lib<module_name>.dll is
+ * not found, as it is commonly the case on Meson builds and
+ * also likely in other cases.
+ */
+ gchar *mod_file = g_strconcat (priv->module_name, "." G_MODULE_SUFFIX, NULL);
+ fallback_path = g_module_build_path (priv->path, mod_file);
+ g_free (mod_file);
+ }
+#endif
/* g_module_build_path() will add G_MODULE_SUFFIX to the path,
* however g_module_open() will only try to load the libtool archive
@@ -117,6 +132,8 @@ peas_object_module_load (GTypeModule *gmodule)
* which allows uninstalled builds to load plugins as well, as there
* is only the .la file in the build directory.
*/
+ path = g_module_build_path (priv->path, priv->module_name);
+
if (G_MODULE_SUFFIX[0] != '\0' && g_str_has_suffix (path, "." G_MODULE_SUFFIX))
path[strlen (path) - strlen (G_MODULE_SUFFIX) - 1] = '\0';
@@ -125,6 +142,16 @@ peas_object_module_load (GTypeModule *gmodule)
/* Bind symbols immediately to avoid errors long after loading */
priv->library = g_module_open (path, flags);
+
+ /* Windows case if lib<module_name>.dll cannot be found */
+ if (fallback_path != NULL)
+ {
+ if (priv->library == NULL)
+ priv->library = g_module_open (fallback_path, flags);
+
+ g_free (fallback_path);
+ }
+
g_free (path);
}