mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-10 16:53:46 +01:00
Use gmodule instead of dl. This is much more platform agnostic.
Also drop some API version 1 compatibility code.
This commit is contained in:
parent
9472a3d076
commit
db859f3996
10
Makefile
10
Makefile
@ -21,6 +21,16 @@ ifneq ($(wildcard ${VALGRIND_SUPPRESSION_FILE}),)
|
|||||||
VALGRIND_ARGUMENTS += --suppressions=${VALGRIND_SUPPRESSION_FILE}
|
VALGRIND_ARGUMENTS += --suppressions=${VALGRIND_SUPPRESSION_FILE}
|
||||||
endif
|
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))
|
OBJECTS = $(patsubst %.c, %.o, $(SOURCE))
|
||||||
DOBJECTS = $(patsubst %.c, %.do, $(SOURCE))
|
DOBJECTS = $(patsubst %.c, %.do, $(SOURCE))
|
||||||
|
|
||||||
|
20
config.mk
20
config.mk
@ -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_INC ?= $(shell pkg-config --cflags gthread-2.0)
|
||||||
GTHREAD_LIB ?= $(shell pkg-config --libs 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_INC ?= $(shell pkg-config --cflags girara-gtk${ZATHURA_GTK_VERSION})
|
||||||
GIRARA_LIB ?= $(shell pkg-config --libs 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)
|
SQLITE_LIB ?= $(shell pkg-config --libs sqlite3)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
#set it to an empty value if you don't need to link against ld for dlopen and friends
|
INCS = ${GIRARA_INC} ${GTK_INC} ${GTHREAD_INC} ${GMODULE_INC}
|
||||||
DL_LIB ?= -ldl
|
LIBS = ${GIRARA_LIB} ${GTK_LIB} ${GTHREAD_LIB} ${GMODULE_LIB} -lpthread -lm
|
||||||
|
|
||||||
INCS = ${GIRARA_INC} ${GTK_INC} ${GTHREAD_INC}
|
|
||||||
LIBS = ${GIRARA_LIB} ${GTK_LIB} ${GTHREAD_LIB} ${DL_LIB} -lpthread -lm
|
|
||||||
|
|
||||||
# flags
|
# flags
|
||||||
CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length -Wextra $(INCS)
|
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
|
# debug
|
||||||
DFLAGS ?= -g
|
DFLAGS ?= -g
|
||||||
|
|
||||||
|
74
plugin.c
74
plugin.c
@ -3,7 +3,6 @@
|
|||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
|
|
||||||
#include <girara/datastructures.h>
|
#include <girara/datastructures.h>
|
||||||
@ -81,67 +80,57 @@ zathura_plugin_manager_load(zathura_plugin_manager_t* plugin_manager)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* handle = NULL;
|
|
||||||
zathura_plugin_t* plugin = NULL;
|
zathura_plugin_t* plugin = NULL;
|
||||||
|
|
||||||
/* load plugin */
|
/* load plugin */
|
||||||
handle = dlopen(path, RTLD_NOW);
|
GModule* handle = g_module_open(path, G_MODULE_BIND_LOCAL);
|
||||||
if (handle == NULL) {
|
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);
|
g_free(path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* resolve symbols and check API and ABI version*/
|
/* resolve symbols and check API and ABI version*/
|
||||||
zathura_plugin_api_version_t api_version;
|
zathura_plugin_api_version_t api_version = NULL;
|
||||||
*(void**)(&api_version) = dlsym(handle, PLUGIN_API_VERSION_FUNCTION);
|
if (g_module_symbol(handle, PLUGIN_API_VERSION_FUNCTION, (gpointer*) &api_version) == FALSE || !api_version)
|
||||||
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
|
|
||||||
girara_error("could not find '%s' function in plugin %s", PLUGIN_API_VERSION_FUNCTION, path);
|
girara_error("could not find '%s' function in plugin %s", PLUGIN_API_VERSION_FUNCTION, path);
|
||||||
g_free(path);
|
g_free(path);
|
||||||
dlclose(handle);
|
g_module_close(handle);
|
||||||
continue;
|
continue;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zathura_plugin_abi_version_t abi_version;
|
if (api_version() != ZATHURA_API_VERSION) {
|
||||||
*(void**)(&abi_version) = dlsym(handle, PLUGIN_ABI_VERSION_FUNCTION);
|
girara_error("plugin %s has been built againt zathura with a different API version (plugin: %d, zathura: %d)",
|
||||||
if (abi_version != NULL) {
|
path, api_version(), ZATHURA_API_VERSION);
|
||||||
if (abi_version() != ZATHURA_ABI_VERSION) {
|
g_free(path);
|
||||||
girara_error("plugin %s has been built againt zathura with a different ABI version (plugin: %d, zathura: %d)",
|
g_module_close(handle);
|
||||||
path, abi_version(), ZATHURA_ABI_VERSION);
|
continue;
|
||||||
g_free(path);
|
}
|
||||||
dlclose(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)
|
||||||
} else {
|
{
|
||||||
#if ZATHURA_API_VERSION == 1
|
|
||||||
girara_warning("could not find '%s' function in plugin %s ... loading anyway", PLUGIN_ABI_VERSION_FUNCTION, path);
|
|
||||||
#else
|
|
||||||
girara_error("could not find '%s' function in plugin %s", PLUGIN_ABI_VERSION_FUNCTION, path);
|
girara_error("could not find '%s' function in plugin %s", PLUGIN_ABI_VERSION_FUNCTION, path);
|
||||||
g_free(path);
|
g_free(path);
|
||||||
dlclose(handle);
|
g_module_close(handle);
|
||||||
continue;
|
continue;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zathura_plugin_register_service_t register_service;
|
if (abi_version() != ZATHURA_ABI_VERSION) {
|
||||||
*(void**)(®ister_service) = dlsym(handle, PLUGIN_REGISTER_FUNCTION);
|
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*) ®ister_service) == FALSE || !register_service)
|
||||||
|
{
|
||||||
girara_error("could not find '%s' function in plugin %s", PLUGIN_REGISTER_FUNCTION, path);
|
girara_error("could not find '%s' function in plugin %s", PLUGIN_REGISTER_FUNCTION, path);
|
||||||
g_free(path);
|
g_free(path);
|
||||||
dlclose(handle);
|
g_module_close(handle);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,14 +144,13 @@ zathura_plugin_manager_load(zathura_plugin_manager_t* plugin_manager)
|
|||||||
if (plugin->register_function == NULL) {
|
if (plugin->register_function == NULL) {
|
||||||
girara_error("plugin has no document functions register function");
|
girara_error("plugin has no document functions register function");
|
||||||
g_free(path);
|
g_free(path);
|
||||||
dlclose(handle);
|
g_module_close(handle);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin->register_function(&(plugin->functions));
|
plugin->register_function(&(plugin->functions));
|
||||||
|
|
||||||
bool ret = register_plugin(plugin_manager, plugin);
|
bool ret = register_plugin(plugin_manager, plugin);
|
||||||
|
|
||||||
if (ret == false) {
|
if (ret == false) {
|
||||||
girara_error("could not register plugin %s", path);
|
girara_error("could not register plugin %s", path);
|
||||||
zathura_plugin_free(plugin);
|
zathura_plugin_free(plugin);
|
||||||
@ -284,7 +272,7 @@ zathura_plugin_free(zathura_plugin_t* plugin)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dlclose(plugin->handle);
|
g_module_close(plugin->handle);
|
||||||
girara_list_free(plugin->content_types);
|
girara_list_free(plugin->content_types);
|
||||||
g_free(plugin);
|
g_free(plugin);
|
||||||
}
|
}
|
||||||
|
3
plugin.h
3
plugin.h
@ -4,6 +4,7 @@
|
|||||||
#define PLUGIN_H
|
#define PLUGIN_H
|
||||||
|
|
||||||
#include <girara/types.h>
|
#include <girara/types.h>
|
||||||
|
#include <gmodule.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "plugin-api.h"
|
#include "plugin-api.h"
|
||||||
@ -22,7 +23,7 @@ struct zathura_plugin_s
|
|||||||
girara_list_t* content_types; /**< List of supported content types */
|
girara_list_t* content_types; /**< List of supported content types */
|
||||||
zathura_plugin_register_function_t register_function; /**< Document open function */
|
zathura_plugin_register_function_t register_function; /**< Document open function */
|
||||||
zathura_plugin_functions_t functions; /**< Document functions */
|
zathura_plugin_functions_t functions; /**< Document functions */
|
||||||
void* handle; /**< DLL handle */
|
GModule* handle; /**< DLL handle */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user