C Advanced API

Policy storage

Supply aligned policy-object storage for advanced C loaders without claiming a zero-allocation load.

Use the _in() loaders when the application must own the policy object's memory. This is different from the input EDB's storage and from an explanation workspace. The regular loaders remain simpler when caller-owned policy memory is unnecessary.

Types

Used from other pages

These types are defined on the linked pages; this page uses them in the roles below.

TypeUse on this pageDefined in
maelys_datalog_policy_tOutput handle stored in caller-owned memory.Stable Manifests
maelys_datalog_diagnostic_tOptional output argument receiving loading details.Stable Errors

Functions

FunctionPurpose
maelys_datalog_policy_storage_requirements()Ask the installed profile for policy-object size and alignment.
maelys_datalog_policy_load_frontend_in()Load inline source through a selected frontend into caller storage.
maelys_datalog_policy_load_manifest_text_in()Load a manifest bundle into that storage.

Size the arena before loading

The size is a profile bound for up to eight policies, not an estimate from the current source. Ask once for both byte count and alignment. Pass an unused, aligned region of at least that size to an _in() loader; keep it alive until maelys_datalog_policy_free() closes the returned handle. After a failed load, the region may have been overwritten even though the output handle remains NULL.

C · function
Measure policy-object storage
maelys_datalog_status_t
maelys_datalog_policy_storage_requirements(
size_t *out_bytes,
size_t *out_alignment
);
Measures the size and alignment needed for a policy object in application-provided storage, before any loading takes place.
Arguments
out_bytessize_t *
Receives the required arena size for the installed profile.
out_alignmentsize_t *
Receives the required arena alignment.
Return value
maelys_datalog_status_t

OK with both measurements; otherwise no arena should be used for loading.

Load with a selected frontend

The frontend descriptor selects how source is lowered. Pass NULL for the built-in Datalog frontend. The domain must already be registered, just as with stable inline loading.

C · function
Load inline source into caller storage
maelys_datalog_status_t
maelys_datalog_policy_load_frontend_in(
void *storage,
size_t storage_bytes,
const char *domain,
const char *policy_id,
const char *source,
size_t source_len,
const maelys_datalog_frontend_t *frontend,
maelys_datalog_policy_t **out_policy,
maelys_datalog_diagnostic_t *diagnostic
);
Loads one inline policy into application-provided policy storage, using the built-in Datalog frontend or the selected frontend descriptor.
Arguments
storagevoid *
Unused arena aligned to the reported requirement.
storage_bytessize_t
Available bytes in that arena.
domainconst char *
Previously registered domain name.
policy_idconst char *
ID assigned to the one inline policy.
sourceconst char *
Borrowed source bytes.
source_lensize_t
Exact source byte length.
frontendconst maelys_datalog_frontend_t *
Selected frontend descriptor, or NULL for built-in Datalog.
out_policymaelys_datalog_policy_t **
Receives a policy handle on success; NULL on failure.
diagnosticmaelys_datalog_diagnostic_t *
Optional initialized parse/loading diagnostic.
Return value
maelys_datalog_status_t

OK after a successful load; STORAGE_TOO_SMALL, INVALID_ARGUMENT or another error otherwise. There is no heap fallback for the policy object.

Ownership boundary

CODE
static maelys_datalog_status_t policy_arena_shape(
    size_t *bytes, size_t *alignment) {
    return maelys_datalog_policy_storage_requirements(bytes, alignment);
}

The arena must not overlap source, manifest, output handle or diagnostic memory. policy_free() closes the handle but does not free caller storage. Sessions copy their prepared program; release policy handles according to the stable lifetime rules. This path removes an allocation for the policy object only. JSON parsing, contexts and extension callbacks may still allocate; it is not a zero-malloc guarantee for the whole load.