1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-06 02:23:03 +00:00

Add API version checking for modules.

Checking now actively implemented for dynamic modules
in a fully backwards compatible way.
This commit is contained in:
Calvin Rose
2019-05-29 21:57:03 -04:00
parent c8c6419013
commit bcbe42ab23
5 changed files with 66 additions and 25 deletions

View File

@@ -26,14 +26,15 @@
#include "fiber.h"
#endif
static JanetBuildConfig *api_build_config = &(JanetBuildConfig) {
.api_version = JANET_API_VERSION,
.single_threaded = JANET_SINGLE_THREADED_BIT,
.nanbox = JANET_NANBOX_BIT
static const JanetBuildConfig api_build_config = (JanetBuildConfig) {
JANET_VERSION_MAJOR,
JANET_VERSION_MINOR,
JANET_VERSION_PATCH,
JANET_CURRENT_CONFIG_BITS
};
const JanetBuildConfig *janet_build_config() {
return api_build_config;
const JanetBuildConfig *janet_config_host(void) {
return &api_build_config;
}
void janet_panicv(Janet message) {

View File

@@ -63,7 +63,30 @@ JanetModule janet_native(const char *name, const uint8_t **error) {
}
init = (JanetModule) symbol_clib(lib, "_janet_init");
if (!init) {
*error = janet_cstring("could not find _janet_init symbol");
*error = janet_cstring("could not find the _janet_init symbol");
return NULL;
}
JanetBuildConfig(*modconf_getter)(void) = symbol_clib(lib, "_janet_mod_config");
if (!modconf_getter) {
*error = janet_cstring("could not find the _janet_mod_config symbol");
return NULL;
}
JanetBuildConfig modconf = modconf_getter();
JanetBuildConfig host = janet_config_current();
if (host.major != modconf.major ||
host.minor < modconf.minor ||
host.bits != modconf.bits) {
char errbuf[128];
sprintf(errbuf, "config mismatch - host %d.%.d.%d(%.4x) vs. module %d.%d.%d(%.4x)",
host.major,
host.minor,
host.patch,
host.bits,
modconf.major,
modconf.minor,
modconf.patch,
modconf.bits);
*error = janet_cstring(errbuf);
return NULL;
}
return init;
@@ -830,6 +853,9 @@ JanetTable *janet_core_env(JanetTable *replacements) {
JDOC("The version number of the running janet program."));
janet_def(env, "janet/build", janet_cstringv(JANET_BUILD),
JDOC("The build identifier of the running janet program."));
janet_def(env, "janet/config-bits", janet_wrap_integer(JANET_CURRENT_CONFIG_BITS),
JDOC("The flag set of config options from janetconf.h which is used to check "
"if native modules are compatible with the host program."));
/* Allow references to the environment */
janet_def(env, "_env", janet_wrap_table(env), JDOC("The environment table for the current scope."));