Commit 9c334cc6 authored by Sebastian Ramacher's avatar Sebastian Ramacher
Browse files

Add ABI versioning.

parent 8b63def8
......@@ -43,7 +43,8 @@ version.h: version.h.in config.mk
$(QUIET)sed 's/ZVMAJOR/${ZATHURA_VERSION_MAJOR}/' < version.h.in | \
sed 's/ZVMINOR/${ZATHURA_VERSION_MINOR}/' | \
sed 's/ZVREV/${ZATHURA_VERSION_REV}/' | \
sed 's/ZVAPI/${ZATHURA_API_VERSION}/' > version.h
sed 's/ZVAPI/${ZATHURA_API_VERSION}/' | \
sed 's/ZVABI/${ZATHURA_ABI_VERSION}/' > version.h
%.o: %.c
$(ECHO) CC $<
......@@ -80,6 +81,7 @@ ${PROJECT}.pc: ${PROJECT}.pc.in config.mk
$(QUIET)echo project=${PROJECT} > ${PROJECT}.pc
$(QUIET)echo version=${VERSION} >> ${PROJECT}.pc
$(QUIET)echo apiversion=${ZATHURA_API_VERSION} >> ${PROJECT}.pc
$(QUIET)echo abiversion=${ZATHURA_ABI_VERSION} >> ${PROJECT}.pc
$(QUIET)echo includedir=${INCLUDEDIR} >> ${PROJECT}.pc
$(QUIET)echo plugindir=${PLUGINDIR} >> ${PROJECT}.pc
$(QUIET)echo GTK_VERSION=${ZATHURA_GTK_VERSION} >> ${PROJECT}.pc
......
......@@ -4,7 +4,10 @@
ZATHURA_VERSION_MAJOR = 0
ZATHURA_VERSION_MINOR = 1
ZATHURA_VERSION_REV = 1
# If the API changes, the API version and the ABI version have to be bumped.
ZATHURA_API_VERSION = 1
# If the ABI breaks for any reason, this has to be bumped.
ZATHURA_ABI_VERSION = 1
VERSION = ${ZATHURA_VERSION_MAJOR}.${ZATHURA_VERSION_MINOR}.${ZATHURA_VERSION_REV}
# the GTK+ version to use
......
......@@ -63,7 +63,7 @@ zathura_document_plugins_load(zathura_t* zathura)
continue;
}
/* resolve symbol and check API version*/
/* 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) {
......@@ -75,7 +75,35 @@ zathura_document_plugins_load(zathura_t* zathura)
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);
g_free(path);
dlclose(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
girara_error("could not find '%s' function in plugin %s", PLUGIN_ABI_VERSION_FUNCTION, path);
g_free(path);
dlclose(handle);
continue;
#endif
}
zathura_plugin_register_service_t register_plugin;
......
......@@ -13,6 +13,7 @@
#define PLUGIN_REGISTER_FUNCTION "plugin_register"
#define PLUGIN_API_VERSION_FUNCTION "plugin_api_version"
#define PLUGIN_ABI_VERSION_FUNCTION "plugin_abi_version"
/**
* Register a plugin.
......@@ -29,6 +30,7 @@
unsigned int plugin_version_minor() { return minor; } \
unsigned int plugin_version_revision() { return rev; } \
unsigned int plugin_api_version() { return ZATHURA_API_VERSION; } \
unsigned int plugin_abi_version() { return ZATHURA_ABI_VERSION; } \
\
void plugin_register(zathura_document_plugin_t* plugin) \
{ \
......@@ -119,6 +121,14 @@ typedef void (*zathura_plugin_register_service_t)(zathura_document_plugin_t*);
*/
typedef unsigned int (*zathura_plugin_api_version_t)();
/**
* Function prototype that is called to get the ABI version the plugin is built
* against.
*
* @return plugin's ABI version
*/
typedef unsigned int (*zathura_plugin_abi_version_t)();
/**
* Image buffer
*/
......
......@@ -8,5 +8,6 @@
#define ZATHURA_VERSION_REV ZVREV
#define ZATHURA_VERSION "ZVMAJOR.ZVMINOR.ZVREV"
#define ZATHURA_API_VERSION ZVAPI
#define ZATHURA_ABI_VERSION ZVABI
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment