C Extension API

Extension registration guide

Register a document-access frontend, filter and planner in one context.

Package trusted native components under names your application chooses. This example installs a one-command frontend, a file-suffix filter and a join planner in a separate context, then evaluates document access with the built-in backend. See the Extension registration reference for the descriptor and selection contracts.

Policy produced by the frontend

The command grants Alice access to one PDF; blocked users are refused, and the registered filter checks the document suffix.

DATALOG
approved("alice", "roadmap.pdf").
allow(User, Doc) :- approved(User, Doc), not(blocked(User)), document_suffix(Doc, ".pdf").

1. Write the frontend that produces the policy

Recognize exactly grant alice roadmap.pdf, then submit its approval fact and rule through the builder. The rule requires that approval, rejects a blocked user, and checks the document suffix; propagate every builder failure.

Example
CODE
static const char grant_command[] = "grant alice roadmap.pdf";
static const maelys_datalog_ir_atom_t approved_fact = {
    .predicate = "approved", .arity = 2,
    .terms = {{.kind = MAELYS_DATALOG_IR_SYMBOL, .as.symbol = "alice"},
              {.kind = MAELYS_DATALOG_IR_SYMBOL, .as.symbol = "roadmap.pdf"}}
};
static const maelys_datalog_ir_rule_t allow_rule = {
    .head = {.predicate = "allow", .arity = 2,
        .terms = {{.kind = MAELYS_DATALOG_IR_VARIABLE, .as.variable = 0},
                  {.kind = MAELYS_DATALOG_IR_VARIABLE, .as.variable = 1}}},
    .body_count = 3,
    .body = {
        {.kind = MAELYS_DATALOG_IR_ATOM, .atom = {.predicate = "approved", .arity = 2,
            .terms = {{.kind = MAELYS_DATALOG_IR_VARIABLE, .as.variable = 0},
                      {.kind = MAELYS_DATALOG_IR_VARIABLE, .as.variable = 1}}}},
        {.kind = MAELYS_DATALOG_IR_NEGATION, .atom = {.predicate = "blocked", .arity = 1,
            .terms = {{.kind = MAELYS_DATALOG_IR_VARIABLE, .as.variable = 0}}}},
        {.kind = MAELYS_DATALOG_IR_FILTER,
            .filter_name = "document_suffix",
            .filter_semantic_id = "example.document-suffix.bytes-v1.cost-pattern-plus-one",
            .pattern = (const unsigned char *)".pdf", .pattern_length = 4,
            .filter_value = {.kind = MAELYS_DATALOG_IR_VARIABLE, .as.variable = 1}}
    }
};
/* Accept one command and propagate every builder failure. */
static maelys_datalog_status_t lower_grant(const char *text, size_t length,
    maelys_datalog_program_builder_t *builder, maelys_datalog_diagnostic_t *diagnostic) {
    (void)diagnostic;
    if (length != sizeof(grant_command) - 1 || memcmp(text, grant_command, length) != 0)
        return MAELYS_DATALOG_STATUS_INVALID_ARGUMENT;
    maelys_datalog_status_t status = maelys_datalog_program_add_fact(builder, &approved_fact);
    if (status != MAELYS_DATALOG_STATUS_OK) return status;
    return maelys_datalog_program_add_rule(builder, &allow_rule);
}
static const maelys_datalog_frontend_t grant_frontend = {
    .abi_version = MAELYS_DATALOG_PROGRAM_ABI_VERSION,
    .struct_size = sizeof(grant_frontend),
    .name = "grant_command", .semantic_id = "example.grant-command.pdf.v1",
    .lower = lower_grant
};
static void describe_frontend(void) {
    printf("frontend: %s\n", grant_frontend.name);
}

2. Write the filter and planner callbacks

The filter validates and prices its pattern before testing the supplied bytes. The planner chooses only among safe candidates supplied by the core; neither callback keeps borrowed pointers or reenters the engine.

Example
CODE
/* A native filter validates its pattern, prices its work, and tests the bytes. */
static maelys_datalog_status_t validate_suffix(const unsigned char *pattern, size_t length) {
    if (!pattern || !length || length > 63) return MAELYS_DATALOG_STATUS_INVALID_FIELD;
    return MAELYS_DATALOG_STATUS_OK;
}
static maelys_datalog_status_t suffix_cost(size_t value_length, size_t pattern_length, size_t *out_cost) {
    (void)value_length;
    if (!out_cost) return MAELYS_DATALOG_STATUS_INVALID_ARGUMENT;
    if (pattern_length == SIZE_MAX) return MAELYS_DATALOG_STATUS_PAYLOAD_TOO_LARGE;
    *out_cost = pattern_length + 1;
    return MAELYS_DATALOG_STATUS_OK;
}
static maelys_datalog_status_t evaluate_suffix(const unsigned char *value, size_t value_length,
    const unsigned char *pattern, size_t pattern_length, int *out_matched) {
    if (!value || !pattern || !out_matched) return MAELYS_DATALOG_STATUS_INVALID_ARGUMENT;
    *out_matched = value_length >= pattern_length &&
        memcmp(value + value_length - pattern_length, pattern, pattern_length) == 0;
    return MAELYS_DATALOG_STATUS_OK;
}
static const maelys_datalog_filter_module_t suffix_module = {
    MAELYS_DATALOG_MODULE_ABI_VERSION, sizeof(maelys_datalog_filter_module_t),
    "document_suffix", "example.document-suffix.bytes-v1.cost-pattern-plus-one",
    validate_suffix, suffix_cost, evaluate_suffix
};
/* Select only among the safe candidates supplied by the core. */
static maelys_datalog_status_t choose_join(const maelys_datalog_join_candidate_t *candidates,
    size_t count, size_t *out_index) {
    if (!candidates || !count || !out_index) return MAELYS_DATALOG_STATUS_INVALID_ARGUMENT;
    size_t best = 0;
    for (size_t i = 1; i < count; ++i)
        if (candidates[i].default_score > candidates[best].default_score ||
            (candidates[i].default_score == candidates[best].default_score &&
             candidates[i].body_index < candidates[best].body_index)) best = i;
    *out_index = best;
    return MAELYS_DATALOG_STATUS_OK;
}
static const maelys_datalog_planner_module_t document_planner = {
    MAELYS_DATALOG_MODULE_ABI_VERSION, sizeof(maelys_datalog_planner_module_t),
    "document_join", "example.document-join.score-then-body-v1", choose_join
};
static void describe_modules(void) {
    printf("filter: %s\n", suffix_module.name);
    printf("planner: %s\n", document_planner.name);
}
filter: document_suffix
planner: document_join

3. Register one bundle and seal its context

Bundle the descriptors, create a mutable context, then register the bundle atomically. Seal the catalog once, selecting document_join by its registered name; registration itself runs no callback.

Example
CODE
/* This bundle declares components; registering it does not execute callbacks. */
static const maelys_datalog_extension_t document_components = {
    .abi_version = MAELYS_DATALOG_EXTENSION_ABI_VERSION,
    .struct_size = sizeof(document_components),
    .name = "document_components", .semantic_id = "example.document-components.v1",
    .frontends = &grant_frontend, .frontend_count = 1,
    .filters = &suffix_module, .filter_count = 1,
    .planners = &document_planner, .planner_count = 1
};
static void register_components(void) {
    maelys_datalog_status_t status = maelys_datalog_context_create(&context);
    printf("context status: %s\n", maelys_datalog_status_name(status));
    check_status(status);
    status = maelys_datalog_context_register(context, &document_components);
    printf("registration status: %s\n", maelys_datalog_status_name(status));
    check_status(status);
    /* Seal once and select this context's join planner by its registered name. */
    status = maelys_datalog_context_seal(context, document_planner.name);
    printf("seal status: %s\n", maelys_datalog_status_name(status));
    check_status(status);
}
context status: ok
registration status: ok
seal status: ok

4. Load through the selected frontend

Name grant_command for this load, rather than changing a global frontend selection. The loader invokes its lower callback, resolves document_suffix in this context, and validates the completed program against the host domain.

Example
CODE
static void load_registered_policy(void) {
    maelys_datalog_status_t status = maelys_datalog_context_load_inline(
        context, grant_frontend.name, "registration_documents", "document-access",
        grant_command, sizeof(grant_command) - 1, &policy, &diagnostic);
    printf("load status: %s\n", maelys_datalog_status_name(status));
    check_status(status);
    printf("selected frontend: %s\n", grant_frontend.name);
}
load status: ok
selected frontend: grant_command

5. Select the backend and evaluate two requests

NULL explicitly selects the built-in reference backend. The first solve permits Alice to open the PDF; after releasing that result and adding blocked(alice), the next solve refuses the same request.

Example
CODE
static void print_decision(const char *label) {
    const maelys_datalog_value_t query[] = {
        MAELYS_DATALOG_SYMBOL("alice"), MAELYS_DATALOG_SYMBOL("roadmap.pdf")
    };
    int allowed = 0;
    check_status(maelys_datalog_result_query(result, "allow", query, 2, &allowed));
    printf("%s: %s\n", label, allowed ? "yes" : "no");
}
static void evaluate_registered_policy(void) {
    /* NULL selects the built-in reference backend, not a fallback on failure. */
    maelys_datalog_status_t status = maelys_datalog_context_session_create(
        context, policy, 0, NULL, 0, 0, &session);
    printf("session status: %s\n", maelys_datalog_status_name(status));
    check_status(status);
    check_status(maelys_datalog_input_edb_create(&edb));
    check_status(maelys_datalog_session_solve_edb(session, edb, &result, &diagnostic));
    print_decision("alice allowed");
    check_status(maelys_datalog_result_free(result)); result = NULL;
    const maelys_datalog_value_t blocked[] = {MAELYS_DATALOG_SYMBOL("alice")};
    check_status(maelys_datalog_input_edb_add_fact(edb, "blocked", blocked, 1, &diagnostic));
    check_status(maelys_datalog_session_solve_edb(session, edb, &result, &diagnostic));
    print_decision("blocked alice allowed");
}
session status: ok
alice allowed: yes
blocked alice allowed: no

6. Check explicit selection and release the owners

A sealed catalog rejects further registration, and an unknown frontend returns an error without a fallback policy. Release the live result before its session, and release the policy and context handles after their users.

Example
CODE
static void check_selection_and_release(void) {
    maelys_datalog_status_t status = maelys_datalog_context_register(context, &document_components);
    printf("registration after sealing: %s\n", maelys_datalog_status_name(status));
    if (status == MAELYS_DATALOG_STATUS_OK) exit(EXIT_FAILURE);
    maelys_datalog_policy_t *missing = NULL;
    status = maelys_datalog_context_load_inline(context, "missing_frontend",
        "registration_documents", "missing-selection", grant_command,
        sizeof(grant_command) - 1, &missing, &diagnostic);
    printf("missing frontend: %s\n", maelys_datalog_status_name(status));
    printf("fallback policy returned: %s\n", missing ? "yes" : "no");
    if (status == MAELYS_DATALOG_STATUS_OK || missing) exit(EXIT_FAILURE);
    check_status(maelys_datalog_result_free(result)); result = NULL;
    check_status(maelys_datalog_input_edb_free(edb)); edb = NULL;
    check_status(maelys_datalog_session_free(session)); session = NULL;
    check_status(maelys_datalog_policy_free(policy)); policy = NULL;
    check_status(maelys_datalog_context_free(context)); context = NULL;
    printf("released: result, inputs, session, policy and context\n");
}
registration after sealing: invalid_state
missing frontend: not_found
fallback policy returned: no
released: result, inputs, session, policy and context

Contexts isolate component catalogs, not process-global domain declarations, and are not a sandbox. Registration copies descriptors and identities; keep their native callback code loaded while any context, policy or session can use it. Sealed catalogs are immutable, and policies and sessions retain their context references.

Reference context

Insert the six numbered fragments at API_REFERENCE_EXAMPLE, in order. The context supplies the domain, shared status checks and error-path cleanup; the callbacks and registration remain in the visible steps. Each isolated step is executed with the preceding state prepared by its context.

CODE
#include <maelys/datalog.h>
#include <maelys/datalog_builders.h>
#include <maelys/datalog_extension.h>
#include <maelys/datalog_frontend.h>
#include <maelys/datalog_module.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static maelys_datalog_context_t *context = NULL;
static maelys_datalog_policy_t *policy = NULL;
static maelys_datalog_session_t *session = NULL;
static maelys_datalog_input_edb_t *edb = NULL;
static maelys_datalog_result_t *result = NULL;
static maelys_datalog_diagnostic_t diagnostic;
static int cleanup_failed = 0;
static void check_status(maelys_datalog_status_t status) {
    if (status != MAELYS_DATALOG_STATUS_OK) {
        fprintf(stderr, "API call failed: %s\n", maelys_datalog_status_name(status));
        exit(EXIT_FAILURE);
    }
}
/* Error-path cleanup; the visible last step releases the successful program. */
static void cleanup_context(void) {
    if (result) { if (maelys_datalog_result_free(result)) cleanup_failed = 1; result = NULL; }
    if (edb) { if (maelys_datalog_input_edb_free(edb)) cleanup_failed = 1; edb = NULL; }
    if (session) { if (maelys_datalog_session_free(session)) cleanup_failed = 1; session = NULL; }
    if (policy) { if (maelys_datalog_policy_free(policy)) cleanup_failed = 1; policy = NULL; }
    if (context) { if (maelys_datalog_context_free(context)) cleanup_failed = 1; context = NULL; }
}
static void register_domain(void) {
    const maelys_datalog_predicate_t predicates[] = {
        MAELYS_DATALOG_POLICY_FACT("approved", 2),
        MAELYS_DATALOG_EDB("blocked", 1), MAELYS_DATALOG_IDB_QUERY("allow", 2)
    };
    const char *const atoms[] = {"alice", "roadmap.pdf"};
    const maelys_datalog_domain_t domain =
        MAELYS_DATALOG_DOMAIN_WITH_ATOMS("registration_documents", predicates, atoms);
    check_status(maelys_datalog_domain_register(&domain));
}
/* API_REFERENCE_EXAMPLE */
int main(void) {
    if (atexit(cleanup_context) != 0) return EXIT_FAILURE;
    diagnostic = MAELYS_DATALOG_DIAGNOSTIC_INIT;
    register_domain();
    describe_frontend();
    describe_modules();
    register_components();
    load_registered_policy();
    evaluate_registered_policy();
    check_selection_and_release();
    cleanup_context();
    return cleanup_failed ? EXIT_FAILURE : EXIT_SUCCESS;
}
Full program
CODE
#include <maelys/datalog.h>
#include <maelys/datalog_builders.h>
#include <maelys/datalog_extension.h>
#include <maelys/datalog_frontend.h>
#include <maelys/datalog_module.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static maelys_datalog_context_t *context = NULL;
static maelys_datalog_policy_t *policy = NULL;
static maelys_datalog_session_t *session = NULL;
static maelys_datalog_input_edb_t *edb = NULL;
static maelys_datalog_result_t *result = NULL;
static maelys_datalog_diagnostic_t diagnostic;
static int cleanup_failed = 0;
static void check_status(maelys_datalog_status_t status) {
    if (status != MAELYS_DATALOG_STATUS_OK) {
        fprintf(stderr, "API call failed: %s\n", maelys_datalog_status_name(status));
        exit(EXIT_FAILURE);
    }
}
/* Error-path cleanup; the visible last step releases the successful program. */
static void cleanup_context(void) {
    if (result) { if (maelys_datalog_result_free(result)) cleanup_failed = 1; result = NULL; }
    if (edb) { if (maelys_datalog_input_edb_free(edb)) cleanup_failed = 1; edb = NULL; }
    if (session) { if (maelys_datalog_session_free(session)) cleanup_failed = 1; session = NULL; }
    if (policy) { if (maelys_datalog_policy_free(policy)) cleanup_failed = 1; policy = NULL; }
    if (context) { if (maelys_datalog_context_free(context)) cleanup_failed = 1; context = NULL; }
}
static void register_domain(void) {
    const maelys_datalog_predicate_t predicates[] = {
        MAELYS_DATALOG_POLICY_FACT("approved", 2),
        MAELYS_DATALOG_EDB("blocked", 1), MAELYS_DATALOG_IDB_QUERY("allow", 2)
    };
    const char *const atoms[] = {"alice", "roadmap.pdf"};
    const maelys_datalog_domain_t domain =
        MAELYS_DATALOG_DOMAIN_WITH_ATOMS("registration_documents", predicates, atoms);
    check_status(maelys_datalog_domain_register(&domain));
}
static const char grant_command[] = "grant alice roadmap.pdf";
static const maelys_datalog_ir_atom_t approved_fact = {
    .predicate = "approved", .arity = 2,
    .terms = {{.kind = MAELYS_DATALOG_IR_SYMBOL, .as.symbol = "alice"},
              {.kind = MAELYS_DATALOG_IR_SYMBOL, .as.symbol = "roadmap.pdf"}}
};
static const maelys_datalog_ir_rule_t allow_rule = {
    .head = {.predicate = "allow", .arity = 2,
        .terms = {{.kind = MAELYS_DATALOG_IR_VARIABLE, .as.variable = 0},
                  {.kind = MAELYS_DATALOG_IR_VARIABLE, .as.variable = 1}}},
    .body_count = 3,
    .body = {
        {.kind = MAELYS_DATALOG_IR_ATOM, .atom = {.predicate = "approved", .arity = 2,
            .terms = {{.kind = MAELYS_DATALOG_IR_VARIABLE, .as.variable = 0},
                      {.kind = MAELYS_DATALOG_IR_VARIABLE, .as.variable = 1}}}},
        {.kind = MAELYS_DATALOG_IR_NEGATION, .atom = {.predicate = "blocked", .arity = 1,
            .terms = {{.kind = MAELYS_DATALOG_IR_VARIABLE, .as.variable = 0}}}},
        {.kind = MAELYS_DATALOG_IR_FILTER,
            .filter_name = "document_suffix",
            .filter_semantic_id = "example.document-suffix.bytes-v1.cost-pattern-plus-one",
            .pattern = (const unsigned char *)".pdf", .pattern_length = 4,
            .filter_value = {.kind = MAELYS_DATALOG_IR_VARIABLE, .as.variable = 1}}
    }
};
/* Accept one command and propagate every builder failure. */
static maelys_datalog_status_t lower_grant(const char *text, size_t length,
    maelys_datalog_program_builder_t *builder, maelys_datalog_diagnostic_t *diagnostic) {
    (void)diagnostic;
    if (length != sizeof(grant_command) - 1 || memcmp(text, grant_command, length) != 0)
        return MAELYS_DATALOG_STATUS_INVALID_ARGUMENT;
    maelys_datalog_status_t status = maelys_datalog_program_add_fact(builder, &approved_fact);
    if (status != MAELYS_DATALOG_STATUS_OK) return status;
    return maelys_datalog_program_add_rule(builder, &allow_rule);
}
static const maelys_datalog_frontend_t grant_frontend = {
    .abi_version = MAELYS_DATALOG_PROGRAM_ABI_VERSION,
    .struct_size = sizeof(grant_frontend),
    .name = "grant_command", .semantic_id = "example.grant-command.pdf.v1",
    .lower = lower_grant
};
static void describe_frontend(void) {
    printf("frontend: %s\n", grant_frontend.name);
}
/* A native filter validates its pattern, prices its work, and tests the bytes. */
static maelys_datalog_status_t validate_suffix(const unsigned char *pattern, size_t length) {
    if (!pattern || !length || length > 63) return MAELYS_DATALOG_STATUS_INVALID_FIELD;
    return MAELYS_DATALOG_STATUS_OK;
}
static maelys_datalog_status_t suffix_cost(size_t value_length, size_t pattern_length, size_t *out_cost) {
    (void)value_length;
    if (!out_cost) return MAELYS_DATALOG_STATUS_INVALID_ARGUMENT;
    if (pattern_length == SIZE_MAX) return MAELYS_DATALOG_STATUS_PAYLOAD_TOO_LARGE;
    *out_cost = pattern_length + 1;
    return MAELYS_DATALOG_STATUS_OK;
}
static maelys_datalog_status_t evaluate_suffix(const unsigned char *value, size_t value_length,
    const unsigned char *pattern, size_t pattern_length, int *out_matched) {
    if (!value || !pattern || !out_matched) return MAELYS_DATALOG_STATUS_INVALID_ARGUMENT;
    *out_matched = value_length >= pattern_length &&
        memcmp(value + value_length - pattern_length, pattern, pattern_length) == 0;
    return MAELYS_DATALOG_STATUS_OK;
}
static const maelys_datalog_filter_module_t suffix_module = {
    MAELYS_DATALOG_MODULE_ABI_VERSION, sizeof(maelys_datalog_filter_module_t),
    "document_suffix", "example.document-suffix.bytes-v1.cost-pattern-plus-one",
    validate_suffix, suffix_cost, evaluate_suffix
};
/* Select only among the safe candidates supplied by the core. */
static maelys_datalog_status_t choose_join(const maelys_datalog_join_candidate_t *candidates,
    size_t count, size_t *out_index) {
    if (!candidates || !count || !out_index) return MAELYS_DATALOG_STATUS_INVALID_ARGUMENT;
    size_t best = 0;
    for (size_t i = 1; i < count; ++i)
        if (candidates[i].default_score > candidates[best].default_score ||
            (candidates[i].default_score == candidates[best].default_score &&
             candidates[i].body_index < candidates[best].body_index)) best = i;
    *out_index = best;
    return MAELYS_DATALOG_STATUS_OK;
}
static const maelys_datalog_planner_module_t document_planner = {
    MAELYS_DATALOG_MODULE_ABI_VERSION, sizeof(maelys_datalog_planner_module_t),
    "document_join", "example.document-join.score-then-body-v1", choose_join
};
static void describe_modules(void) {
    printf("filter: %s\n", suffix_module.name);
    printf("planner: %s\n", document_planner.name);
}
/* This bundle declares components; registering it does not execute callbacks. */
static const maelys_datalog_extension_t document_components = {
    .abi_version = MAELYS_DATALOG_EXTENSION_ABI_VERSION,
    .struct_size = sizeof(document_components),
    .name = "document_components", .semantic_id = "example.document-components.v1",
    .frontends = &grant_frontend, .frontend_count = 1,
    .filters = &suffix_module, .filter_count = 1,
    .planners = &document_planner, .planner_count = 1
};
static void register_components(void) {
    maelys_datalog_status_t status = maelys_datalog_context_create(&context);
    printf("context status: %s\n", maelys_datalog_status_name(status));
    check_status(status);
    status = maelys_datalog_context_register(context, &document_components);
    printf("registration status: %s\n", maelys_datalog_status_name(status));
    check_status(status);
    /* Seal once and select this context's join planner by its registered name. */
    status = maelys_datalog_context_seal(context, document_planner.name);
    printf("seal status: %s\n", maelys_datalog_status_name(status));
    check_status(status);
}
static void load_registered_policy(void) {
    maelys_datalog_status_t status = maelys_datalog_context_load_inline(
        context, grant_frontend.name, "registration_documents", "document-access",
        grant_command, sizeof(grant_command) - 1, &policy, &diagnostic);
    printf("load status: %s\n", maelys_datalog_status_name(status));
    check_status(status);
    printf("selected frontend: %s\n", grant_frontend.name);
}
static void print_decision(const char *label) {
    const maelys_datalog_value_t query[] = {
        MAELYS_DATALOG_SYMBOL("alice"), MAELYS_DATALOG_SYMBOL("roadmap.pdf")
    };
    int allowed = 0;
    check_status(maelys_datalog_result_query(result, "allow", query, 2, &allowed));
    printf("%s: %s\n", label, allowed ? "yes" : "no");
}
static void evaluate_registered_policy(void) {
    /* NULL selects the built-in reference backend, not a fallback on failure. */
    maelys_datalog_status_t status = maelys_datalog_context_session_create(
        context, policy, 0, NULL, 0, 0, &session);
    printf("session status: %s\n", maelys_datalog_status_name(status));
    check_status(status);
    check_status(maelys_datalog_input_edb_create(&edb));
    check_status(maelys_datalog_session_solve_edb(session, edb, &result, &diagnostic));
    print_decision("alice allowed");
    check_status(maelys_datalog_result_free(result)); result = NULL;
    const maelys_datalog_value_t blocked[] = {MAELYS_DATALOG_SYMBOL("alice")};
    check_status(maelys_datalog_input_edb_add_fact(edb, "blocked", blocked, 1, &diagnostic));
    check_status(maelys_datalog_session_solve_edb(session, edb, &result, &diagnostic));
    print_decision("blocked alice allowed");
}
static void check_selection_and_release(void) {
    maelys_datalog_status_t status = maelys_datalog_context_register(context, &document_components);
    printf("registration after sealing: %s\n", maelys_datalog_status_name(status));
    if (status == MAELYS_DATALOG_STATUS_OK) exit(EXIT_FAILURE);
    maelys_datalog_policy_t *missing = NULL;
    status = maelys_datalog_context_load_inline(context, "missing_frontend",
        "registration_documents", "missing-selection", grant_command,
        sizeof(grant_command) - 1, &missing, &diagnostic);
    printf("missing frontend: %s\n", maelys_datalog_status_name(status));
    printf("fallback policy returned: %s\n", missing ? "yes" : "no");
    if (status == MAELYS_DATALOG_STATUS_OK || missing) exit(EXIT_FAILURE);
    check_status(maelys_datalog_result_free(result)); result = NULL;
    check_status(maelys_datalog_input_edb_free(edb)); edb = NULL;
    check_status(maelys_datalog_session_free(session)); session = NULL;
    check_status(maelys_datalog_policy_free(policy)); policy = NULL;
    check_status(maelys_datalog_context_free(context)); context = NULL;
    printf("released: result, inputs, session, policy and context\n");
}
int main(void) {
    if (atexit(cleanup_context) != 0) return EXIT_FAILURE;
    diagnostic = MAELYS_DATALOG_DIAGNOSTIC_INIT;
    register_domain();
    describe_frontend();
    describe_modules();
    register_components();
    load_registered_policy();
    evaluate_registered_policy();
    check_selection_and_release();
    cleanup_context();
    return cleanup_failed ? EXIT_FAILURE : EXIT_SUCCESS;
}