Use gmodule instead of dl. This is much more platform agnostic.

Also drop some API version 1 compatibility code.
This commit is contained in:
Sebastian Ramacher 2012-04-27 22:26:49 +02:00
parent 9472a3d076
commit db859f3996
4 changed files with 48 additions and 59 deletions

View File

@ -21,6 +21,16 @@ ifneq ($(wildcard ${VALGRIND_SUPPRESSION_FILE}),)
VALGRIND_ARGUMENTS += --suppressions=${VALGRIND_SUPPRESSION_FILE}
endif
ifeq (,$(findstring -DZATHURA_PLUGINDIR,${CPPFLAGS}))
CPPFLAGS += -DZATHURA_PLUGINDIR=\"${PLUGINDIR}\"
endif
ifeq (,$(findstring -DGETTEXT_PACKAGE,${CPPFLAGS}))
CPPFLAGS += -DGETTEXT_PACKAGE=\"${PROJECT}\"
endif
ifeq (,$(findstring -DLOCALEDIR,${CPPFLAGS}))
CPPFLAGS += -DLOCALEDIR=\"${LOCALEDIR}\"
endif
OBJECTS = $(patsubst %.c, %.o, $(SOURCE))
DOBJECTS = $(patsubst %.c, %.do, $(SOURCE))

View File

@ -45,6 +45,9 @@ GTK_LIB ?= $(shell pkg-config --libs gtk+-${ZATHURA_GTK_VERSION}.0)
GTHREAD_INC ?= $(shell pkg-config --cflags gthread-2.0)
GTHREAD_LIB ?= $(shell pkg-config --libs gthread-2.0)
GMODULE_INC ?= $(shell pkg-config --cflags gmodule-no-export-2.0)
GMODULE_LIB ?= $(shell pkg-config --libs gmodule-no-export-2.0)
GIRARA_INC ?= $(shell pkg-config --cflags girara-gtk${ZATHURA_GTK_VERSION})
GIRARA_LIB ?= $(shell pkg-config --libs girara-gtk${ZATHURA_GTK_VERSION})
@ -53,25 +56,12 @@ SQLITE_INC ?= $(shell pkg-config --cflags sqlite3)
SQLITE_LIB ?= $(shell pkg-config --libs sqlite3)
endif
#set it to an empty value if you don't need to link against ld for dlopen and friends
DL_LIB ?= -ldl
INCS = ${GIRARA_INC} ${GTK_INC} ${GTHREAD_INC}
LIBS = ${GIRARA_LIB} ${GTK_LIB} ${GTHREAD_LIB} ${DL_LIB} -lpthread -lm
INCS = ${GIRARA_INC} ${GTK_INC} ${GTHREAD_INC} ${GMODULE_INC}
LIBS = ${GIRARA_LIB} ${GTK_LIB} ${GTHREAD_LIB} ${GMODULE_LIB} -lpthread -lm
# flags
CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length -Wextra $(INCS)
ifeq (,$(findstring -DZATHURA_PLUGINDIR,${CPPFLAGS}))
CPPFLAGS += -DZATHURA_PLUGINDIR=\"${PLUGINDIR}\"
endif
ifeq (,$(findstring -DGETTEXT_PACKAGE,${CPPFLAGS}))
CPPFLAGS += -DGETTEXT_PACKAGE=\"${PROJECT}\"
endif
ifeq (,$(findstring -DLOCALEDIR,${CPPFLAGS}))
CPPFLAGS += -DLOCALEDIR=\"${LOCALEDIR}\"
endif
# debug
DFLAGS ?= -g

View File

@ -3,7 +3,6 @@
#include "plugin.h"
#include <stdlib.h>
#include <dlfcn.h>
#include <glib/gi18n.h>
#include <girara/datastructures.h>
@ -81,67 +80,57 @@ zathura_plugin_manager_load(zathura_plugin_manager_t* plugin_manager)
continue;
}
void* handle = NULL;
zathura_plugin_t* plugin = NULL;
/* load plugin */
handle = dlopen(path, RTLD_NOW);
GModule* handle = g_module_open(path, G_MODULE_BIND_LOCAL);
if (handle == NULL) {
girara_error("could not load plugin %s (%s)", path, dlerror());
girara_error("could not load plugin %s (%s)", path, g_module_error());
g_free(path);
continue;
}
/* resolve symbols and check API and ABI version*/
zathura_plugin_api_version_t api_version;
*(void**)(&api_version) = dlsym(handle, PLUGIN_API_VERSION_FUNCTION);
if (api_version != NULL) {
if (api_version() != ZATHURA_API_VERSION) {
girara_error("plugin %s has been built againt zathura with a different API version (plugin: %d, zathura: %d)",
path, api_version(), ZATHURA_API_VERSION);
g_free(path);
dlclose(handle);
continue;
}
} else {
#if ZATHURA_API_VERSION == 1
girara_warning("could not find '%s' function in plugin %s ... loading anyway", PLUGIN_API_VERSION_FUNCTION, path);
#else
zathura_plugin_api_version_t api_version = NULL;
if (g_module_symbol(handle, PLUGIN_API_VERSION_FUNCTION, (gpointer*) &api_version) == FALSE || !api_version)
{
girara_error("could not find '%s' function in plugin %s", PLUGIN_API_VERSION_FUNCTION, path);
g_free(path);
dlclose(handle);
g_module_close(handle);
continue;
#endif
}
zathura_plugin_abi_version_t abi_version;
*(void**)(&abi_version) = dlsym(handle, PLUGIN_ABI_VERSION_FUNCTION);
if (abi_version != NULL) {
if (abi_version() != ZATHURA_ABI_VERSION) {
girara_error("plugin %s has been built againt zathura with a different ABI version (plugin: %d, zathura: %d)",
path, abi_version(), ZATHURA_ABI_VERSION);
g_free(path);
dlclose(handle);
continue;
}
} else {
#if ZATHURA_API_VERSION == 1
girara_warning("could not find '%s' function in plugin %s ... loading anyway", PLUGIN_ABI_VERSION_FUNCTION, path);
#else
if (api_version() != ZATHURA_API_VERSION) {
girara_error("plugin %s has been built againt zathura with a different API version (plugin: %d, zathura: %d)",
path, api_version(), ZATHURA_API_VERSION);
g_free(path);
g_module_close(handle);
continue;
}
zathura_plugin_abi_version_t abi_version = NULL;
if (g_module_symbol(handle, PLUGIN_ABI_VERSION_FUNCTION, (gpointer*) &abi_version) == FALSE || !abi_version)
{
girara_error("could not find '%s' function in plugin %s", PLUGIN_ABI_VERSION_FUNCTION, path);
g_free(path);
dlclose(handle);
g_module_close(handle);
continue;
#endif
}
zathura_plugin_register_service_t register_service;
*(void**)(&register_service) = dlsym(handle, PLUGIN_REGISTER_FUNCTION);
if (abi_version() != ZATHURA_ABI_VERSION) {
girara_error("plugin %s has been built againt zathura with a different ABI version (plugin: %d, zathura: %d)",
path, abi_version(), ZATHURA_ABI_VERSION);
g_free(path);
g_module_close(handle);
continue;
}
if (register_service == NULL) {
zathura_plugin_register_service_t register_service = NULL;
if (g_module_symbol(handle, PLUGIN_REGISTER_FUNCTION, (gpointer*) &register_service) == FALSE || !register_service)
{
girara_error("could not find '%s' function in plugin %s", PLUGIN_REGISTER_FUNCTION, path);
g_free(path);
dlclose(handle);
g_module_close(handle);
continue;
}
@ -155,14 +144,13 @@ zathura_plugin_manager_load(zathura_plugin_manager_t* plugin_manager)
if (plugin->register_function == NULL) {
girara_error("plugin has no document functions register function");
g_free(path);
dlclose(handle);
g_module_close(handle);
continue;
}
plugin->register_function(&(plugin->functions));
bool ret = register_plugin(plugin_manager, plugin);
if (ret == false) {
girara_error("could not register plugin %s", path);
zathura_plugin_free(plugin);
@ -284,7 +272,7 @@ zathura_plugin_free(zathura_plugin_t* plugin)
return;
}
dlclose(plugin->handle);
g_module_close(plugin->handle);
girara_list_free(plugin->content_types);
g_free(plugin);
}

View File

@ -4,6 +4,7 @@
#define PLUGIN_H
#include <girara/types.h>
#include <gmodule.h>
#include "types.h"
#include "plugin-api.h"
@ -22,7 +23,7 @@ struct zathura_plugin_s
girara_list_t* content_types; /**< List of supported content types */
zathura_plugin_register_function_t register_function; /**< Document open function */
zathura_plugin_functions_t functions; /**< Document functions */
void* handle; /**< DLL handle */
GModule* handle; /**< DLL handle */
};
/**