diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 4d4a4e9f1..9171c59f0 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -301,6 +301,7 @@ SET_PROPERTY(TARGET dfhack-version APPEND PROPERTY COMPILE_DEFINITIONS DFHACK_VERSION="${DFHACK_VERSION}" DF_VERSION="${DF_VERSION}" DFHACK_RELEASE="${DFHACK_RELEASE}" + DFHACK_ABI_VERSION=${DFHACK_ABI_VERSION} ) IF(DFHACK_PRERELEASE) SET_PROPERTY(TARGET dfhack-version APPEND PROPERTY COMPILE_DEFINITIONS diff --git a/library/DFHackVersion.cpp b/library/DFHackVersion.cpp index 9d367ae64..f4f0cf242 100644 --- a/library/DFHackVersion.cpp +++ b/library/DFHackVersion.cpp @@ -3,6 +3,10 @@ #include "git-describe.h" namespace DFHack { namespace Version { + int dfhack_abi_version() + { + return DFHACK_ABI_VERSION; + } const char *dfhack_version() { return DFHACK_VERSION; diff --git a/library/PluginManager.cpp b/library/PluginManager.cpp index b6d1dcc92..8e3f436cb 100644 --- a/library/PluginManager.cpp +++ b/library/PluginManager.cpp @@ -276,6 +276,7 @@ bool Plugin::load(color_ostream &con) plugin_check_symbol("plugin_name") plugin_check_symbol("plugin_version") + plugin_check_symbol("plugin_abi_version") plugin_check_symbol("plugin_self") plugin_check_symbol("plugin_init") plugin_check_symbol("plugin_globals") @@ -287,11 +288,19 @@ bool Plugin::load(color_ostream &con) return false; } const char ** plug_version =(const char ** ) LookupPlugin(plug, "plugin_version"); + const int *plugin_abi_version = (int*) LookupPlugin(plug, "plugin_abi_version"); const char ** plug_git_desc_ptr = (const char**) LookupPlugin(plug, "plugin_git_description"); Plugin **plug_self = (Plugin**)LookupPlugin(plug, "plugin_self"); const char *dfhack_version = Version::dfhack_version(); const char *dfhack_git_desc = Version::git_description(); const char *plug_git_desc = plug_git_desc_ptr ? *plug_git_desc_ptr : "unknown"; + if (*plugin_abi_version != Version::dfhack_abi_version()) + { + con.printerr("Plugin %s: ABI version mismatch (Plugin: %i, DFHack: %i)\n", + *plug_name, *plugin_abi_version, Version::dfhack_abi_version()); + plugin_abort_load; + return false; + } if (strcmp(dfhack_version, *plug_version) != 0) { con.printerr("Plugin %s was not built for this version of DFHack.\n" diff --git a/library/include/DFHackVersion.h b/library/include/DFHackVersion.h index afe8a03a0..c89b94ba5 100644 --- a/library/include/DFHackVersion.h +++ b/library/include/DFHackVersion.h @@ -4,6 +4,7 @@ namespace DFHack { const char *dfhack_version(); const char *df_version(); const char *dfhack_release(); + int dfhack_abi_version(); const char *git_description(); const char *git_commit(); const char *git_xml_commit(); @@ -18,6 +19,7 @@ namespace DFHack { #define DF_VERSION (DFHack::Version::df_version()) #define DFHACK_RELEASE (DFHack::Version::dfhack_release()) #define DFHACK_VERSION (DFHack::Version::dfhack_version()) + #define DFHACK_ABI_VERSION (DFHack::Version::dfhack_abi_version()) #define DFHACK_GIT_DESCRIPTION (DFHack::Version::git_description()) #define DFHACK_GIT_COMMIT (DFHack::Version::git_commit()) #define DFHACK_GIT_XML_COMMIT (DFHack::Version::git_xml_commit()) diff --git a/library/include/PluginManager.h b/library/include/PluginManager.h index f7a8a7d87..c8776d8ed 100644 --- a/library/include/PluginManager.h +++ b/library/include/PluginManager.h @@ -61,6 +61,7 @@ namespace DFHack namespace Version { const char *dfhack_version(); const char *git_description(); + int dfhack_abi_version(); } // anon type, pretty much @@ -296,6 +297,7 @@ namespace DFHack DFhackDataExport const char * plugin_name = m_plugin_name;\ DFhackDataExport const char * plugin_version = DFHack::Version::dfhack_version();\ DFhackDataExport const char * plugin_git_description = DFHack::Version::git_description();\ + DFhackDataExport int plugin_abi_version = DFHack::Version::dfhack_abi_version();\ DFhackDataExport DFHack::Plugin *plugin_self = NULL;\ std::vector _plugin_globals;\ DFhackDataExport std::vector* plugin_globals = &_plugin_globals; \