Skip to content

Commit eb22d5c

Browse files
committed
Add ABI version symbol to plugins
1 parent db95796 commit eb22d5c

5 files changed

Lines changed: 18 additions & 0 deletions

File tree

library/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ SET_PROPERTY(TARGET dfhack-version APPEND PROPERTY COMPILE_DEFINITIONS
301301
DFHACK_VERSION="${DFHACK_VERSION}"
302302
DF_VERSION="${DF_VERSION}"
303303
DFHACK_RELEASE="${DFHACK_RELEASE}"
304+
DFHACK_ABI_VERSION=${DFHACK_ABI_VERSION}
304305
)
305306
IF(DFHACK_PRERELEASE)
306307
SET_PROPERTY(TARGET dfhack-version APPEND PROPERTY COMPILE_DEFINITIONS

library/DFHackVersion.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include "git-describe.h"
44
namespace DFHack {
55
namespace Version {
6+
int dfhack_abi_version()
7+
{
8+
return DFHACK_ABI_VERSION;
9+
}
610
const char *dfhack_version()
711
{
812
return DFHACK_VERSION;

library/PluginManager.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ bool Plugin::load(color_ostream &con)
276276

277277
plugin_check_symbol("plugin_name")
278278
plugin_check_symbol("plugin_version")
279+
plugin_check_symbol("plugin_abi_version")
279280
plugin_check_symbol("plugin_self")
280281
plugin_check_symbol("plugin_init")
281282
plugin_check_symbol("plugin_globals")
@@ -287,11 +288,19 @@ bool Plugin::load(color_ostream &con)
287288
return false;
288289
}
289290
const char ** plug_version =(const char ** ) LookupPlugin(plug, "plugin_version");
291+
const int *plugin_abi_version = (int*) LookupPlugin(plug, "plugin_abi_version");
290292
const char ** plug_git_desc_ptr = (const char**) LookupPlugin(plug, "plugin_git_description");
291293
Plugin **plug_self = (Plugin**)LookupPlugin(plug, "plugin_self");
292294
const char *dfhack_version = Version::dfhack_version();
293295
const char *dfhack_git_desc = Version::git_description();
294296
const char *plug_git_desc = plug_git_desc_ptr ? *plug_git_desc_ptr : "unknown";
297+
if (*plugin_abi_version != Version::dfhack_abi_version())
298+
{
299+
con.printerr("Plugin %s: ABI version mismatch (Plugin: %i, DFHack: %i)\n",
300+
*plug_name, *plugin_abi_version, Version::dfhack_abi_version());
301+
plugin_abort_load;
302+
return false;
303+
}
295304
if (strcmp(dfhack_version, *plug_version) != 0)
296305
{
297306
con.printerr("Plugin %s was not built for this version of DFHack.\n"

library/include/DFHackVersion.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace DFHack {
44
const char *dfhack_version();
55
const char *df_version();
66
const char *dfhack_release();
7+
int dfhack_abi_version();
78
const char *git_description();
89
const char *git_commit();
910
const char *git_xml_commit();
@@ -18,6 +19,7 @@ namespace DFHack {
1819
#define DF_VERSION (DFHack::Version::df_version())
1920
#define DFHACK_RELEASE (DFHack::Version::dfhack_release())
2021
#define DFHACK_VERSION (DFHack::Version::dfhack_version())
22+
#define DFHACK_ABI_VERSION (DFHack::Version::dfhack_abi_version())
2123
#define DFHACK_GIT_DESCRIPTION (DFHack::Version::git_description())
2224
#define DFHACK_GIT_COMMIT (DFHack::Version::git_commit())
2325
#define DFHACK_GIT_XML_COMMIT (DFHack::Version::git_xml_commit())

library/include/PluginManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ namespace DFHack
6161
namespace Version {
6262
const char *dfhack_version();
6363
const char *git_description();
64+
int dfhack_abi_version();
6465
}
6566

6667
// anon type, pretty much
@@ -296,6 +297,7 @@ namespace DFHack
296297
DFhackDataExport const char * plugin_name = m_plugin_name;\
297298
DFhackDataExport const char * plugin_version = DFHack::Version::dfhack_version();\
298299
DFhackDataExport const char * plugin_git_description = DFHack::Version::git_description();\
300+
DFhackDataExport int plugin_abi_version = DFHack::Version::dfhack_abi_version();\
299301
DFhackDataExport DFHack::Plugin *plugin_self = NULL;\
300302
std::vector<std::string> _plugin_globals;\
301303
DFhackDataExport std::vector<std::string>* plugin_globals = &_plugin_globals; \

0 commit comments

Comments
 (0)