Move version compatibility to the consumer; name libdpm-core explicitly
dpm_require no longer takes a minimum version and applies no version criterion of its own. A handle now means the module is valid, not that it suits the caller. dpm_module_info_of is added alongside it, reporting the name, version, description, and minimum-libdpm-core version read at load, so a consuming module can judge a dependency's version for itself. The one rule still enforced is the minimum-version handshake, where libdpm-core is the host and refuses a module that demands a newer library than the one running. dpm_module_info_of joins the version script, so the exported surface is now fourteen symbols under DPM_CORE_1.0. Separately, the bare word "core" is gone from prose everywhere. It named both the command-line tool and the library, so every use forced the reader to guess which. Text now says "the dpm binary" or "libdpm-core". Identifiers keep their spelling: libdpm-core, core.h, core.conf, the "core" configuration namespace, dpm_core_version, core_min, DPM_CORE_1.0, the dpmcore namespace, test_core, core_api. Three user-visible strings changed with it: the load-refusal message now reads "requires libdpm-core >= X, running libdpm-core is Y — update libdpm-core", and the info module's description and help text name the library. The test asserting on the refusal text was updated to match. DESIGN.md's terminology line no longer defines "DPM Core" as the CLI, which was the source of the ambiguity. OVERVIEW.md is restructured around the three layers a reader meets DPM at — user, developer, filesystem — so a code-level symbol never appears without saying whose layer it is. MODULES.md describes the bundled info module as testing and demonstrating full DPM system functionality rather than as a reference implementation. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* @file modules.cpp
|
||||
* @brief Module discovery, load-time validation, routing, enumeration
|
||||
*
|
||||
* Implements the load-time enforcement sequence: core is the sole
|
||||
* Implements the load-time enforcement sequence: libdpm-core is the sole
|
||||
* authority on module validity. A module is either fully valid or not
|
||||
* loaded — no partial states.
|
||||
*
|
||||
@@ -119,7 +119,7 @@ std::unique_ptr<dpm_module> validate_and_load(dpm_ctx* ctx,
|
||||
auto core_min_f = reinterpret_cast<string_fn>(resolve(handle, "dpm_module_core_min"));
|
||||
auto manifest_f = reinterpret_cast<manifest_fn>(resolve(handle, "dpm_module_manifest"));
|
||||
|
||||
/* Step 2: core-minimum handshake. */
|
||||
/* Step 2: minimum-version handshake. */
|
||||
const char* core_min = core_min_f();
|
||||
long parsed[3];
|
||||
if (!core_min || !parse_version(core_min, parsed)) {
|
||||
@@ -128,8 +128,9 @@ std::unique_ptr<dpm_module> validate_and_load(dpm_ctx* ctx,
|
||||
return nullptr;
|
||||
}
|
||||
if (compare_versions(core_min, DPM_CORE_VERSION_STR) > 0) {
|
||||
reason = std::string("requires core >= ") + core_min +
|
||||
", running core is " DPM_CORE_VERSION_STR " — update core";
|
||||
reason = std::string("requires libdpm-core >= ") + core_min +
|
||||
", running libdpm-core is " DPM_CORE_VERSION_STR
|
||||
" — update libdpm-core";
|
||||
dlclose(handle);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -212,47 +213,43 @@ std::unique_ptr<dpm_module> validate_and_load(dpm_ctx* ctx,
|
||||
|
||||
extern "C" {
|
||||
|
||||
dpm_module* dpm_require(dpm_ctx* ctx, const char* name,
|
||||
const char* min_version)
|
||||
dpm_module* dpm_require(dpm_ctx* ctx, const char* name)
|
||||
{
|
||||
if (!ctx || !name || !*name) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
long parsed[3];
|
||||
if (min_version && !dpmcore::parse_version(min_version, parsed)) {
|
||||
dpmcore::set_error(ctx, std::string("malformed minimum version: ") +
|
||||
min_version);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
dpm_module* mod = nullptr;
|
||||
auto it = ctx->modules.find(name);
|
||||
if (it != ctx->modules.end()) {
|
||||
mod = it->second.get();
|
||||
} else {
|
||||
std::string reason;
|
||||
auto loaded = dpmcore::validate_and_load(ctx, name, reason);
|
||||
if (!loaded) {
|
||||
dpmcore::set_error(ctx, std::string("module '") + name +
|
||||
"': " + reason);
|
||||
return nullptr;
|
||||
}
|
||||
mod = loaded.get();
|
||||
ctx->modules[name] = std::move(loaded);
|
||||
return it->second.get();
|
||||
}
|
||||
|
||||
if (min_version &&
|
||||
dpmcore::compare_versions(mod->version.c_str(), min_version) < 0) {
|
||||
std::string reason;
|
||||
auto loaded = dpmcore::validate_and_load(ctx, name, reason);
|
||||
if (!loaded) {
|
||||
dpmcore::set_error(ctx, std::string("module '") + name +
|
||||
"' is version " + mod->version +
|
||||
", below required minimum " + min_version);
|
||||
"': " + reason);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
dpm_module* mod = loaded.get();
|
||||
ctx->modules[name] = std::move(loaded);
|
||||
return mod;
|
||||
}
|
||||
|
||||
int dpm_module_info_of(dpm_ctx* ctx, dpm_module* mod, dpm_module_info* out)
|
||||
{
|
||||
if (!ctx || !mod || !out) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const void* dpm_get_api(dpm_ctx* ctx, dpm_module* mod,
|
||||
const char* api_name, int table_version)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user