C API

Session inputs

Attach fixed-vocabulary retained input to a session in caller-owned storage.

Retained input is an opt-in alternative to solving a complete request snapshot. Attach a fixed vocabulary before the first solve, then publish replacement facts or addition/removal batches against the current base. Ordinary session_solve() is unavailable while an attachment is live.

Handle: session_inputs_t

C · handleSince v0.16.0
session_inputs_t

#include <maelys/datalog_inputs.h>

typedef struct maelys_datalog_session_inputs maelys_datalog_session_inputs_t;
Opt-in retained dynamic input attached to one session with a fixed symbol vocabulary. Compiled policy facts remain separate. Initialize before the session’s first solve; release every result and prepared explanation before changing or releasing the attachment.

Creation

session_inputs_storage_requirements()

C · functionSince v0.16.0
session_inputs_storage_requirements()

#include <maelys/datalog_inputs.h>

maelys_datalog_status_t
maelys_datalog_session_inputs_storage_requirements(
const maelys_datalog_session_t *session,
const maelys_datalog_input_options_t *options,
size_t *out_bytes,
size_t *out_alignment
);
Measures the aligned caller storage needed to attach fixed-vocabulary retained input to a session. No engine allocation is performed. Query the requirements at runtime rather than hard-coding a platform-dependent size or alignment.
Arguments
sessionconst maelys_datalog_session_t *in
Session to which retained input will be attached, before its first solve.
Initialized input options declaring capacities and fixed vocabulary.
Outputs

Written on success.

out_bytessize_t *out
Receives the required number of caller-storage bytes.
out_alignmentsize_t *out
Receives the required alignment of caller storage.
Return status

maelys_datalog_status_t — OK on success.

OK on success. A sizing error leaves the caller responsible for not initializing an attachment from invalid requirements.

Example
size_t bytes = 0, alignment = 0;
maelys_datalog_status_t status = maelys_datalog_session_inputs_storage_requirements(
    session, &options, &bytes, &alignment);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("storage required: %s\n", bytes > 0 ? "yes" : "no");
printf("alignment is a power of two: %s\n",
    alignment > 0 && (alignment & (alignment - 1u)) == 0 ? "yes" : "no");
status: ok
storage required: yes
alignment is a power of two: yes

session_inputs_init()

C · functionSince v0.16.0
session_inputs_init()

#include <maelys/datalog_inputs.h>

maelys_datalog_status_t
maelys_datalog_session_inputs_init(
maelys_datalog_session_t *session,
const maelys_datalog_input_options_t *options,
void *storage,
size_t storage_bytes,
maelys_datalog_session_inputs_t **out_inputs
);
Initializes retained dynamic input in caller-owned storage before the session’s first solve. Copies the options and vocabulary, performs no engine allocation and borrows the supplied aligned, nonoverlapping arena for the attachment lifetime.
Arguments
Session to attach before its first solve.
Initialized capacities and fixed vocabulary, copied by this call.
storagevoid *in/out
Caller-provided aligned arena, disjoint from every live engine object and retained until release.
storage_bytessize_tin
Capacity of storage in bytes, obtained from storage_requirements.
Outputs

Written on success.

Receives the retained-input attachment.
Return status

maelys_datalog_status_t — OK on success.

OK on success; the caller retains ownership of the arena and must keep it alive until the attachment is released.

Example
size_t bytes = 0, alignment = 0;
check_status(maelys_datalog_session_inputs_storage_requirements(
    session, &options, &bytes, &alignment));
storage = allocate_storage(bytes, alignment);
maelys_datalog_status_t status = maelys_datalog_session_inputs_init(session, &options, storage, bytes, &inputs);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("attachment created: %s\n", inputs != NULL ? "yes" : "no");
status: ok
attachment created: yes

Functions

session_inputs_base()

C · functionSince v0.16.0
session_inputs_base()

#include <maelys/datalog_inputs.h>

maelys_datalog_status_t
maelys_datalog_session_inputs_base(
const maelys_datalog_session_inputs_t *inputs,
maelys_datalog_input_base_t *out_base
);
Reads the current incarnation and generation used to guard a retained-input update.
Arguments
inputsconst maelys_datalog_session_inputs_t *handleread
Live attachment whose current base is read.
Outputs

Written on success.

Receives this attachment’s current incarnation and generation.
Return status

maelys_datalog_status_t — OK on success.

OK on success, with a base that belongs to this live attachment.

Example
create_inputs();
maelys_datalog_input_base_t base;
maelys_datalog_status_t status = maelys_datalog_session_inputs_base(inputs, &base);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
maelys_datalog_input_base_t again;
check_status(maelys_datalog_session_inputs_base(inputs, &again));
printf("base unchanged: %s\n",
    base.incarnation == again.incarnation && base.generation == again.generation ? "yes" : "no");
status: ok
base unchanged: yes

session_inputs_replace()

C · functionSince v0.16.0
session_inputs_replace()

#include <maelys/datalog_inputs.h>

maelys_datalog_status_t
maelys_datalog_session_inputs_replace(
maelys_datalog_session_inputs_t *inputs,
maelys_datalog_input_base_t base,
const maelys_datalog_fact_t *facts,
size_t fact_count,
maelys_datalog_result_t **out_result,
maelys_datalog_diagnostic_t *out_diagnostic
);
Replaces retained facts against the current base and returns a leased result. Raw record limits apply before deduplication. Unknown replacement symbols are INVALID_FIELD. A successful no-op also publishes a new base; live results or explanations forbid the next update.
Arguments
inputsmaelys_datalog_session_inputs_t *handlemodified
Live attachment to update.
Current base returned by this attachment.
factsconst maelys_datalog_fact_t *in
Caller-provided replacement facts, borrowed only during this call.
fact_countsize_tin
Number of raw replacement records, bounded by fact_capacity.
Outputs

Written on success.

out_resultmaelys_datalog_result_t **out
Receives the leased result; NULL on failure.

out_diagnostic: optional diagnostic details on failure; pass NULL when not needed.

Return status

maelys_datalog_status_t — OK on success.

OK publishes retained facts, a new base and an ordinary leased result. Failure preserves the committed facts and base and sets the output result to NULL; scratch storage may change.

Example
create_inputs();
maelys_datalog_input_base_t base;
check_status(maelys_datalog_session_inputs_base(inputs, &base));
maelys_datalog_status_t status = maelys_datalog_session_inputs_replace(
    inputs, base, facts, sizeof(facts) / sizeof(facts[0]), &result, &diagnostic);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
int present = 0;
check_status(MAELYS_DATALOG_QUERY(result, &present, "allow", "alice", "roadmap.pdf"));
printf("allowed: %s\n", present ? "yes" : "no");

session_inputs_apply()

C · functionSince v0.16.0
session_inputs_apply()

#include <maelys/datalog_inputs.h>

maelys_datalog_status_t
maelys_datalog_session_inputs_apply(
maelys_datalog_session_inputs_t *inputs,
maelys_datalog_input_base_t base,
const maelys_datalog_fact_t *added,
size_t added_count,
const maelys_datalog_fact_t *removed,
size_t removed_count,
maelys_datalog_result_t **out_result,
maelys_datalog_diagnostic_t *out_diagnostic
);
Applies an addition/removal batch against the current base and returns a leased result. Raw addition and removal counts are independently bounded before deduplication. Additions win over removals and absent removals are no-ops. Unknown added symbols are INVALID_FIELD; unknown removed symbols denote absent facts after raw validation.
Arguments
inputsmaelys_datalog_session_inputs_t *handlemodified
Live attachment to update.
Current base returned by this attachment.
addedconst maelys_datalog_fact_t *in
Caller-provided facts to add, borrowed only during this call.
added_countsize_tin
Raw addition count, bounded by addition_capacity.
removedconst maelys_datalog_fact_t *in
Caller-provided facts to remove, borrowed only during this call.
removed_countsize_tin
Raw removal count, bounded by removal_capacity.
Outputs

Written on success.

out_resultmaelys_datalog_result_t **out
Receives the leased result; NULL on failure.

out_diagnostic: optional diagnostic details on failure; pass NULL when not needed.

Return status

maelys_datalog_status_t — OK on success.

OK publishes the new facts, base and an ordinary leased result, even for a no-op. Failure preserves the committed facts and base and sets the output result to NULL; scratch storage may change.

Example
create_inputs();
maelys_datalog_input_base_t base;
check_status(maelys_datalog_session_inputs_base(inputs, &base));
maelys_datalog_status_t status = maelys_datalog_session_inputs_apply(
    inputs, base, facts, sizeof(facts) / sizeof(facts[0]), NULL, 0, &result, &diagnostic);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
int present = 0;
check_status(MAELYS_DATALOG_QUERY(result, &present, "allow", "alice", "roadmap.pdf"));
printf("allowed: %s\n", present ? "yes" : "no");

Release

session_inputs_free()

C · functionSince v0.16.0
session_inputs_free()

#include <maelys/datalog_inputs.h>

maelys_datalog_status_t
maelys_datalog_session_inputs_free(
maelys_datalog_session_inputs_t *inputs
);
Releases an attachment after all results have been released, without freeing caller storage. Session destruction is refused while an attachment remains live. Released storage may be reused with a fresh session; its old base is never valid for another attachment.
Arguments
inputsmaelys_datalog_session_inputs_t *handlereleased
Attachment to release after its results and prepared explanations.
Return status

maelys_datalog_status_t — OK on success.

OK on success; release is allowed only with no live result.

Example
create_inputs();
maelys_datalog_status_t status = maelys_datalog_session_inputs_free(inputs);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
inputs = NULL;

Struct: input_options_t

C · structSince v0.16.0
input_options_t

#include <maelys/datalog_inputs.h>

Caller-specified capacities and fixed vocabulary for a retained-input attachment. Initialize with MAELYS_DATALOG_INPUT_OPTIONS_INIT before assigning capacities and symbols. The attachment copies these options and vocabulary.
Fields
struct_sizesize_t
Size of this public options structure; set by MAELYS_DATALOG_INPUT_OPTIONS_INIT.
contract_versionuint32_t
Published input contract version; set by MAELYS_DATALOG_INPUT_OPTIONS_INIT.
reserveduint32_t
Reserved; leave zero.
fact_capacitysize_t
Maximum retained fact records accepted by replacement, before deduplication.
addition_capacitysize_t
Maximum raw addition records accepted by one apply call, before deduplication.
removal_capacitysize_t
Maximum raw removal records accepted by one apply call, before deduplication.
symbolsconst char *const *
Fixed vocabulary strings borrowed during initialization and copied by the attachment.
symbol_countsize_t
Number of strings in the fixed vocabulary.
Typedef
typedef struct {
    size_t struct_size;
    uint32_t contract_version, reserved;
    size_t fact_capacity, addition_capacity, removal_capacity;
    const char *const *symbols;
    size_t symbol_count;
} maelys_datalog_input_options_t;

Creation

INPUT_OPTIONS_INIT

C · macroSince v0.16.0
INPUT_OPTIONS_INIT

#include <maelys/datalog_inputs.h>

#define MAELYS_DATALOG_INPUT_OPTIONS_INIT

Initializes the retained-input options structure to the public contract size and version, with zero capacities and no vocabulary.

Effect

Produces an input_options_t aggregate initializer. Set capacities and vocabulary before sizing or initializing an attachment. An aggregate initializer for maelys_datalog_input_options_t.

Initial values
FieldInitial valueMeaning
struct_sizesizeof(maelys_datalog_input_options_t)Size of this public options structure; set by MAELYS_DATALOG_INPUT_OPTIONS_INIT.set automatically
contract_versionMAELYS_DATALOG_INPUT_CONTRACT_VERSIONPublished input contract version; set by MAELYS_DATALOG_INPUT_OPTIONS_INIT.set automatically
reserved0Reserved; leave zero.
fact_capacity0Maximum retained fact records accepted by replacement, before deduplication.
addition_capacity0Maximum raw addition records accepted by one apply call, before deduplication.
removal_capacity0Maximum raw removal records accepted by one apply call, before deduplication.
symbolsNULLFixed vocabulary strings borrowed during initialization and copied by the attachment.
symbol_count0Number of strings in the fixed vocabulary.
Expansion
{sizeof(maelys_datalog_input_options_t), MAELYS_DATALOG_INPUT_CONTRACT_VERSION, 0, 0, 0, 0, NULL, 0}
Example
maelys_datalog_input_options_t defaults = MAELYS_DATALOG_INPUT_OPTIONS_INIT;
printf("contract version: %u\n", defaults.contract_version);
printf("empty vocabulary: %s\n", defaults.symbol_count == 0 ? "yes" : "no");
contract version: 1
empty vocabulary: yes
Versioning

Initialize with the INPUT_OPTIONS_INIT macro; these values identify the structure version and are not set by hand.

Input contract version
NameValueMeaning
INPUT_CONTRACT_VERSION
Since v0.16.0
1Version of the published input_options_t initialization contract.

Struct: input_base_t

C · structSince v0.16.0
input_base_t

#include <maelys/datalog_inputs.h>

Incarnation and generation of one retained-input attachment. Pass its current base to replace or apply; even a successful no-op publishes a new base, and an old base never becomes valid for a fresh attachment.
Fields
incarnationuint64_t
Identifies the attachment incarnation.
generationuint64_t
Identifies the committed generation within this incarnation.
Typedef
typedef struct { uint64_t incarnation, generation; } maelys_datalog_input_base_t;

Usage guides