Modules determine their own compatibility with the library
A module is built against the system-installed libdpm-core.so and is responsible for being correct against it. Where it needs to act on the version it is running under, dpm_core_version() reports that and the module decides for itself. dpm_module_core_min() is removed. It was a declaration handed to the library to enforce on the module's behalf, and enforcement of that kind belongs nowhere in a library that routes and hosts. The contract is now three reserved symbols and load validation is two steps: the reserved symbols resolve, and the version and description probes return well-formed values. compare_versions had no remaining caller and is removed; parse_version stays for the well-formedness probe. The core_too_new fixture went with the handshake it existed to exercise.
This commit is contained in:
@@ -96,7 +96,6 @@ std::unique_ptr<dpm_module> validate_and_load(dpm_ctx* ctx,
|
||||
"dpm_module_execute",
|
||||
"dpm_module_version",
|
||||
"dpm_module_description",
|
||||
"dpm_module_core_min",
|
||||
};
|
||||
|
||||
std::string missing;
|
||||
@@ -114,28 +113,12 @@ std::unique_ptr<dpm_module> validate_and_load(dpm_ctx* ctx,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto exec_f = reinterpret_cast<execute_fn>(resolve(handle, "dpm_module_execute"));
|
||||
auto version_f = reinterpret_cast<string_fn>(resolve(handle, "dpm_module_version"));
|
||||
auto desc_f = reinterpret_cast<string_fn>(resolve(handle, "dpm_module_description"));
|
||||
auto core_min_f = reinterpret_cast<string_fn>(resolve(handle, "dpm_module_core_min"));
|
||||
auto exec_f = reinterpret_cast<execute_fn>(resolve(handle, "dpm_module_execute"));
|
||||
auto version_f = reinterpret_cast<string_fn>(resolve(handle, "dpm_module_version"));
|
||||
auto desc_f = reinterpret_cast<string_fn>(resolve(handle, "dpm_module_description"));
|
||||
|
||||
/* Step 2: minimum-version handshake. */
|
||||
const char* core_min = core_min_f();
|
||||
/* Step 2: probe the cheap calls. */
|
||||
long parsed[3];
|
||||
if (!core_min || !parse_version(core_min, parsed)) {
|
||||
reason = "dpm_module_core_min() returned a malformed version";
|
||||
dlclose(handle);
|
||||
return nullptr;
|
||||
}
|
||||
if (compare_versions(core_min, DPM_CORE_VERSION_STR) > 0) {
|
||||
reason = std::string("requires libdpm-core >= ") + core_min +
|
||||
", running libdpm-core is " DPM_CORE_VERSION_STR
|
||||
" — update libdpm-core";
|
||||
dlclose(handle);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* Step 3: probe the cheap calls. */
|
||||
const char* version = version_f();
|
||||
if (!version || !parse_version(version, parsed)) {
|
||||
reason = "dpm_module_version() returned a malformed version";
|
||||
@@ -154,7 +137,6 @@ std::unique_ptr<dpm_module> validate_and_load(dpm_ctx* ctx,
|
||||
mod->handle = handle;
|
||||
mod->version = version;
|
||||
mod->description = description;
|
||||
mod->core_min = core_min;
|
||||
mod->execute = exec_f;
|
||||
return mod;
|
||||
}
|
||||
@@ -196,7 +178,6 @@ int dpm_module_info_of(dpm_ctx* ctx, dpm_module* mod, dpm_module_info* out)
|
||||
out->name = mod->name.c_str();
|
||||
out->version = mod->version.c_str();
|
||||
out->description = mod->description.c_str();
|
||||
out->core_min = mod->core_min.c_str();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -264,7 +245,6 @@ dpm_cursor* dpm_list_modules(dpm_ctx* ctx)
|
||||
info.name = mod->name.c_str();
|
||||
info.version = mod->version.c_str();
|
||||
info.description = mod->description.c_str();
|
||||
info.core_min = mod->core_min.c_str();
|
||||
cur->infos.push_back(info);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user