From 9c334cc6a6685201ffe912655d701321976d1cfd Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Wed, 21 Mar 2012 16:23:29 +0100 Subject: [PATCH] Add ABI versioning. --- Makefile | 4 +++- config.mk | 3 +++ document.c | 30 +++++++++++++++++++++++++++++- document.h | 10 ++++++++++ version.h.in | 1 + 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d62a71d..1cf8093 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/config.mk b/config.mk index d5535dd..921c1f7 100644 --- a/config.mk +++ b/config.mk @@ -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 diff --git a/document.c b/document.c index 8bf8ea7..263b90a 100644 --- a/document.c +++ b/document.c @@ -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; diff --git a/document.h b/document.h index b6d4f01..398191c 100644 --- a/document.h +++ b/document.h @@ -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 */ diff --git a/version.h.in b/version.h.in index 891eb47..91fbe70 100644 --- a/version.h.in +++ b/version.h.in @@ -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