C API

Session resources

Explicit session capacities, caller-owned storage and caller allocation.

Choose session capacities and supply the memory used by a session with <maelys/datalog_resources.h>. The Session resources guide shows the configuration, storage and release steps.

Struct: session_resource_request_t

C · structSince v0.14.0
session_resource_request_t

#include <maelys/datalog_resources.h>

Selects session memory mode, required resources and optional capacities. Initialize the complete descriptor, then set capacity-mask bits for explicit capacities. An absent capacity uses the loaded profile default; a present zero capacity is an exact quota, not a default sentinel.
Fields
struct_sizesize_t
Size of the supplied descriptor; initialize it with the matching public initializer when one exists.
contract_versionuint32_t
Published contract version for this descriptor.
memory_modeuint32_t
Fixed or backend-elastic memory mode.
required_featuresuint64_t
Resource-feature bits carried by this descriptor; distinct from language/execution capability bits.
capacity_maskuint64_t
Selects the capacities explicitly present; an absent capacity uses the loaded profile default.
input_factssize_t
Maximum raw input-snapshot facts before deduplication.
derived_factssize_t
Capacity for the complete derived database, including helper facts.
symbolssize_t
Capacity for dictionary entries, including program roots.
text_bytessize_t
Capacity for interned dictionary text, including NUL terminators.
Typedef
typedef struct {
    size_t struct_size;
    uint32_t contract_version;
    uint32_t memory_mode;
    uint64_t required_features;
    uint64_t capacity_mask;
    size_t input_facts;   /* E: raw snapshot count before deduplication */
    size_t derived_facts; /* D: complete IDB, helpers included */
    size_t symbols;       /* S: dictionary entries, program roots included */
    size_t text_bytes;    /* T: interned dictionary text including NULs */
} maelys_datalog_session_resource_request_t;

Creation

RESOURCE_REQUEST_INIT

C · macroSince v0.14.0
RESOURCE_REQUEST_INIT

#include <maelys/datalog_resources.h>

#define MAELYS_DATALOG_RESOURCE_REQUEST_INIT

Starting value for a capacity request: every field is set so the session uses the profile's default capacities. Change only the capacities you need, then pass the request to session_config_set_resources().

Effect

Sets a complete V1 descriptor with no required resource features and no explicit capacities. Assign selected capacities before configuring a session. An aggregate initializer for maelys_datalog_session_resource_request_t.

Initial values
FieldInitial valueMeaning
struct_sizeMAELYS_DATALOG_RESOURCE_REQUEST_V1_SIZESize of the supplied descriptor; initialize it with the matching public initializer when one exists.set automatically
contract_versionMAELYS_DATALOG_RESOURCE_CONTRACT_VERSIONPublished contract version for this descriptor.set automatically
memory_modeMAELYS_DATALOG_MEMORY_FIXEDFixed or backend-elastic memory mode.
required_featuresUINT64_C(0)Resource-feature bits carried by this descriptor; distinct from language/execution capability bits.
capacity_maskUINT64_C(0)Selects the capacities explicitly present; an absent capacity uses the loaded profile default.
input_facts0Maximum raw input-snapshot facts before deduplication.
derived_facts0Capacity for the complete derived database, including helper facts.
symbols0Capacity for dictionary entries, including program roots.
text_bytes0Capacity for interned dictionary text, including NUL terminators.
Expansion
{ MAELYS_DATALOG_RESOURCE_REQUEST_V1_SIZE,        MAELYS_DATALOG_RESOURCE_CONTRACT_VERSION, MAELYS_DATALOG_MEMORY_FIXED,        UINT64_C(0), UINT64_C(0), 0, 0, 0, 0 }
Example
maelys_datalog_session_resource_request_t request = MAELYS_DATALOG_RESOURCE_REQUEST_INIT;
printf("fixed memory: %s\n", request.memory_mode == MAELYS_DATALOG_MEMORY_FIXED ? "yes" : "no");
printf("profile defaults: %s\n", request.capacity_mask == 0 ? "yes" : "no");
fixed memory: yes
profile defaults: yes

Constants

CAPACITY_ALL

C · constantSince v0.14.0
CAPACITY_ALL
#define MAELYS_DATALOG_CAPACITY_ALL           UINT64_C(15)

Mask containing all four capacity-presence bits.

Value

15

CAPACITY_DERIVED_FACTS

C · constantSince v0.14.0
CAPACITY_DERIVED_FACTS
#define MAELYS_DATALOG_CAPACITY_DERIVED_FACTS (UINT64_C(1) << 1)

Presence bit for the complete derived-fact capacity.

Value

2

CAPACITY_INPUT_FACTS

C · constantSince v0.14.0
CAPACITY_INPUT_FACTS
#define MAELYS_DATALOG_CAPACITY_INPUT_FACTS   (UINT64_C(1) << 0)

Presence bit for the raw input-fact capacity.

Value

1

CAPACITY_SYMBOLS

C · constantSince v0.14.0
CAPACITY_SYMBOLS
#define MAELYS_DATALOG_CAPACITY_SYMBOLS       (UINT64_C(1) << 2)

Presence bit for the symbol-dictionary capacity.

Value

4

CAPACITY_TEXT_BYTES

C · constantSince v0.14.0
CAPACITY_TEXT_BYTES
#define MAELYS_DATALOG_CAPACITY_TEXT_BYTES    (UINT64_C(1) << 3)

Presence bit for the interned-text capacity.

Value

8

MEMORY_BACKEND_ELASTIC

C · constantSince v0.19.0
MEMORY_BACKEND_ELASTIC

Declared as reserved (rejected) from v0.14.0 to v0.18.0.

#define MAELYS_DATALOG_MEMORY_BACKEND_ELASTIC UINT32_C(1)

Selects backend-elastic execution with caller allocation.

Value

1

MEMORY_FIXED

C · constantSince v0.14.0
MEMORY_FIXED
#define MAELYS_DATALOG_MEMORY_FIXED           UINT32_C(0)

Selects fixed-memory execution.

Value

0

RESOURCE_CALLER_ALLOCATOR

C · constantSince v0.14.0
RESOURCE_CALLER_ALLOCATOR
#define MAELYS_DATALOG_RESOURCE_CALLER_ALLOCATOR   (UINT64_C(1) << 1)

Resource-feature bit required for caller allocation.

Value

2

RESOURCE_SESSION_CAPACITIES

C · constantSince v0.14.0
RESOURCE_SESSION_CAPACITIES
#define MAELYS_DATALOG_RESOURCE_SESSION_CAPACITIES (UINT64_C(1) << 0)

Resource-feature bit for explicit session capacities.

Value

1

RESOURCE_SUPPORTED

C · constantSince v0.19.0
RESOURCE_SUPPORTED
#define MAELYS_DATALOG_RESOURCE_SUPPORTED \
    (MAELYS_DATALOG_RESOURCE_SUPPORTED_014 | MAELYS_DATALOG_RESOURCE_CALLER_ALLOCATOR)

Supported resource-feature mask, including caller allocation.

Value

3

Versioning

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

RESOURCE_CONTRACT_VERSION

C · constantSince v0.14.0
RESOURCE_CONTRACT_VERSION
#define MAELYS_DATALOG_RESOURCE_CONTRACT_VERSION 1u

Version of the resource-request and normalized-resources contract.

Value

1

RESOURCE_REQUEST_PREFIX_SIZE

C · constantSince v0.14.0
RESOURCE_REQUEST_PREFIX_SIZE
#define MAELYS_DATALOG_RESOURCE_REQUEST_PREFIX_SIZE \
    (offsetof(maelys_datalog_session_resource_request_t, required_features) + sizeof(uint64_t))

Minimum readable contract prefix, expressed from the published structure layout.

Value

(offsetof(maelys_datalog_session_resource_request_t, required_features) + sizeof(uint64_t))platform-dependent

RESOURCE_REQUEST_V1_SIZE

C · constantSince v0.14.0
RESOURCE_REQUEST_V1_SIZE
#define MAELYS_DATALOG_RESOURCE_REQUEST_V1_SIZE \
    sizeof(maelys_datalog_session_resource_request_t)

Complete V1 structure size; use the expression rather than a hard-coded platform size.

Value

sizeof(maelys_datalog_session_resource_request_t)platform-dependent

RESOURCE_SUPPORTED_014

C · constantSince v0.14.0
RESOURCE_SUPPORTED_014
#define MAELYS_DATALOG_RESOURCE_SUPPORTED_014 \
    MAELYS_DATALOG_RESOURCE_SESSION_CAPACITIES

Historical supported-resource mask retained for older compiled consumers.

Value

1

Struct: session_resources_t

C · structSince v0.14.0
session_resources_t

#include <maelys/datalog_resources.h>

Reports the normalized resource capacities admitted for a session. All four capacities are normalized without presence/default sentinels. Requirements and preparation use the same values. Retain scalar copies rather than borrowed callback-scoped descriptors.
Fields
struct_sizesize_t
Size of the supplied descriptor; initialize it with the matching public initializer when one exists.
contract_versionuint32_t
Published contract version for this descriptor.
memory_modeuint32_t
Fixed or backend-elastic memory mode.
required_featuresuint64_t
Resource-feature bits carried by this descriptor; distinct from language/execution capability bits.
input_factssize_t
Maximum raw input-snapshot facts before deduplication.
derived_factssize_t
Capacity for the complete derived database, including helper facts.
symbolssize_t
Capacity for dictionary entries, including program roots.
text_bytessize_t
Capacity for interned dictionary text, including NUL terminators.
Typedef
typedef struct {
    size_t struct_size;
    uint32_t contract_version;
    uint32_t memory_mode;
    uint64_t required_features;
    size_t input_facts;
    size_t derived_facts;
    size_t symbols;
    size_t text_bytes;
} maelys_datalog_session_resources_t;

Creation

RESOURCES_INIT

C · macroSince v0.14.0
RESOURCES_INIT

#include <maelys/datalog_resources.h>

#define MAELYS_DATALOG_RESOURCES_INIT

Starting value for reading a session's capacities: pass it to session_get_resources(), which fills in the capacities granted to the session.

Effect

Prepares the output descriptor for session_get_resources; the getter supplies the admitted capacities. An aggregate initializer for maelys_datalog_session_resources_t.

Initial values
FieldInitial valueMeaning
struct_sizeMAELYS_DATALOG_RESOURCES_V1_SIZESize of the supplied descriptor; initialize it with the matching public initializer when one exists.set automatically
contract_versionMAELYS_DATALOG_RESOURCE_CONTRACT_VERSIONPublished contract version for this descriptor.set automatically
memory_modeMAELYS_DATALOG_MEMORY_FIXEDFixed or backend-elastic memory mode.
required_featuresUINT64_C(0)Resource-feature bits carried by this descriptor; distinct from language/execution capability bits.
input_facts0Maximum raw input-snapshot facts before deduplication.
derived_facts0Capacity for the complete derived database, including helper facts.
symbols0Capacity for dictionary entries, including program roots.
text_bytes0Capacity for interned dictionary text, including NUL terminators.
Expansion
{ MAELYS_DATALOG_RESOURCES_V1_SIZE, MAELYS_DATALOG_RESOURCE_CONTRACT_VERSION,        MAELYS_DATALOG_MEMORY_FIXED, UINT64_C(0), 0, 0, 0, 0 }
Example
maelys_datalog_session_resources_t admitted = MAELYS_DATALOG_RESOURCES_INIT;
printf("contract initialized: %s\n", admitted.contract_version == MAELYS_DATALOG_RESOURCE_CONTRACT_VERSION ? "yes" : "no");
printf("size initialized: %s\n", admitted.struct_size == sizeof(admitted) ? "yes" : "no");
contract initialized: yes
size initialized: yes
Versioning

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

RESOURCES_PREFIX_SIZE

C · constantSince v0.14.0
RESOURCES_PREFIX_SIZE
#define MAELYS_DATALOG_RESOURCES_PREFIX_SIZE \
    (offsetof(maelys_datalog_session_resources_t, required_features) + sizeof(uint64_t))

Minimum readable contract prefix, expressed from the published structure layout.

Value

(offsetof(maelys_datalog_session_resources_t, required_features) + sizeof(uint64_t))platform-dependent

RESOURCES_V1_SIZE

C · constantSince v0.14.0
RESOURCES_V1_SIZE
#define MAELYS_DATALOG_RESOURCES_V1_SIZE sizeof(maelys_datalog_session_resources_t)

Complete V1 structure size; use the expression rather than a hard-coded platform size.

Value

sizeof(maelys_datalog_session_resources_t)platform-dependent

Struct: caller_allocator_t

C · structSince v0.19.0
caller_allocator_t

#include <maelys/datalog_resources.h>

Supplies borrowed allocation callbacks and their context for elastic execution. Context and callback code are borrowed through destruction and the last release, including failed preparation. Keep reserved and required_features zero in V1.
Fields
struct_sizesize_t
Size of the supplied descriptor; initialize it with the matching public initializer when one exists.
contract_versionuint32_t
Published contract version for this descriptor.
reserveduint32_t
Reserved; keep zero.
required_featuresuint64_t
Resource-feature bits carried by this descriptor; distinct from language/execution capability bits.
contextvoid *
Borrowed callback context, live through destruction and the last release, including failed preparation.
acquirevoid *(*)(void *, size_t, size_t)
Borrowed callback that supplies storage for the requested byte count and alignment.
releasevoid (*)(void *, void *, size_t, size_t)
Borrowed callback that releases a supplied pointer with its original byte count and alignment.
Typedef
typedef struct {
    size_t struct_size;
    uint32_t contract_version;
    uint32_t reserved; /* zero */
    uint64_t required_features; /* zero in V1 */
    void *context;
    void *(*acquire)(void *context, size_t bytes, size_t alignment);
    void (*release)(void *context, void *pointer, size_t bytes, size_t alignment);
} maelys_datalog_caller_allocator_t;

Creation

CALLER_ALLOCATOR_INIT

C · macroSince v0.19.0
CALLER_ALLOCATOR_INIT

#include <maelys/datalog_resources.h>

#define MAELYS_DATALOG_CALLER_ALLOCATOR_INIT

Initializes an allocator descriptor with no context or callbacks.

Effect

Sets the complete descriptor size and version, with reserved fields, context and both callbacks zero. Supply callbacks before requesting allocation. An aggregate initializer for maelys_datalog_caller_allocator_t.

Initial values
FieldInitial valueMeaning
struct_sizeMAELYS_DATALOG_CALLER_ALLOCATOR_V1_SIZESize of the supplied descriptor; initialize it with the matching public initializer when one exists.set automatically
contract_versionMAELYS_DATALOG_CALLER_ALLOCATOR_VERSIONPublished contract version for this descriptor.set automatically
reservedUINT32_C(0)Reserved; keep zero.
required_featuresUINT64_C(0)Resource-feature bits carried by this descriptor; distinct from language/execution capability bits.
contextNULLBorrowed callback context, live through destruction and the last release, including failed preparation.
acquireNULLBorrowed callback that supplies storage for the requested byte count and alignment.
releaseNULLBorrowed callback that releases a supplied pointer with its original byte count and alignment.
Expansion
{ MAELYS_DATALOG_CALLER_ALLOCATOR_V1_SIZE,        MAELYS_DATALOG_CALLER_ALLOCATOR_VERSION, UINT32_C(0), UINT64_C(0),        NULL, NULL, NULL }
Example
maelys_datalog_caller_allocator_t allocator = MAELYS_DATALOG_CALLER_ALLOCATOR_INIT;
printf("callbacks unset: %s\n", allocator.acquire == NULL && allocator.release == NULL ? "yes" : "no");
printf("contract initialized: %s\n", allocator.contract_version == MAELYS_DATALOG_CALLER_ALLOCATOR_VERSION ? "yes" : "no");
callbacks unset: yes
contract initialized: yes
Versioning

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

CALLER_ALLOCATOR_PREFIX_SIZE

C · constantSince v0.19.0
CALLER_ALLOCATOR_PREFIX_SIZE
#define MAELYS_DATALOG_CALLER_ALLOCATOR_PREFIX_SIZE \
    (offsetof(maelys_datalog_caller_allocator_t, required_features) + sizeof(uint64_t))

Minimum readable contract prefix, expressed from the published structure layout.

Value

(offsetof(maelys_datalog_caller_allocator_t, required_features) + sizeof(uint64_t))platform-dependent

CALLER_ALLOCATOR_V1_SIZE

C · constantSince v0.19.0
CALLER_ALLOCATOR_V1_SIZE
#define MAELYS_DATALOG_CALLER_ALLOCATOR_V1_SIZE \
    sizeof(maelys_datalog_caller_allocator_t)

Complete V1 structure size; use the expression rather than a hard-coded platform size.

Value

sizeof(maelys_datalog_caller_allocator_t)platform-dependent

CALLER_ALLOCATOR_VERSION

C · constantSince v0.19.0
CALLER_ALLOCATOR_VERSION
#define MAELYS_DATALOG_CALLER_ALLOCATOR_VERSION 1u

Version of the caller-allocator descriptor contract.

Value

1

Struct: session_allocation_request_t

C · structSince v0.19.0
session_allocation_request_t

#include <maelys/datalog_resources.h>

Extends a resource request with an execution byte cap and caller allocator. Initialize the complete extended request. Its base selects backend-elastic memory and requires caller allocation; older hosts reject this required feature before reading the tail.
Fields
basemaelys_datalog_session_resource_request_t
Complete resource-request prefix, initialized for backend-elastic execution and caller allocation.
execution_byte_capsize_t
Maximum bytes charged to elastic execution.
allocatorconst maelys_datalog_caller_allocator_t *
Borrowed descriptor of caller allocation callbacks; provide it before requesting elastic execution.
Typedef
typedef struct {
    maelys_datalog_session_resource_request_t base;
    size_t execution_byte_cap;
    const maelys_datalog_caller_allocator_t *allocator;
} maelys_datalog_session_allocation_request_t;

Creation

ALLOCATION_REQUEST_INIT

C · macroSince v0.19.0
ALLOCATION_REQUEST_INIT

#include <maelys/datalog_resources.h>

#define MAELYS_DATALOG_ALLOCATION_REQUEST_INIT

Initializes an elastic request that requires a caller allocator.

Effect

Sets the complete extended size and required caller-allocation feature; assign its allocator and execution byte cap before configuring a session. An aggregate initializer for maelys_datalog_session_allocation_request_t.

Initial values
FieldInitial valueMeaning
base{ MAELYS_DATALOG_ALLOCATION_REQUEST_V1_SIZE, MAELYS_DATALOG_RESOURCE_CONTRACT_VERSION, MAELYS_DATALOG_MEMORY_BACKEND_ELASTIC, MAELYS_DATALOG_RESOURCE_CALLER_ALLOCATOR, UINT64_C(0), 0, 0, 0, 0 }Complete resource-request prefix, initialized for backend-elastic execution and caller allocation.
execution_byte_cap0Maximum bytes charged to elastic execution.
allocatorNULLBorrowed descriptor of caller allocation callbacks; provide it before requesting elastic execution.
Expansion
{ { MAELYS_DATALOG_ALLOCATION_REQUEST_V1_SIZE, MAELYS_DATALOG_RESOURCE_CONTRACT_VERSION,          MAELYS_DATALOG_MEMORY_BACKEND_ELASTIC, MAELYS_DATALOG_RESOURCE_CALLER_ALLOCATOR,          UINT64_C(0), 0, 0, 0, 0 }, 0, NULL }
Example
maelys_datalog_session_allocation_request_t request = MAELYS_DATALOG_ALLOCATION_REQUEST_INIT;
printf("elastic memory: %s\n", request.base.memory_mode == MAELYS_DATALOG_MEMORY_BACKEND_ELASTIC ? "yes" : "no");
printf("caller allocation required: %s\n", (request.base.required_features & MAELYS_DATALOG_RESOURCE_CALLER_ALLOCATOR) != 0 ? "yes" : "no");
elastic memory: yes
caller allocation required: yes
Versioning

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

ALLOCATION_REQUEST_PREFIX_SIZE

C · constantSince v0.19.0
ALLOCATION_REQUEST_PREFIX_SIZE
#define MAELYS_DATALOG_ALLOCATION_REQUEST_PREFIX_SIZE MAELYS_DATALOG_RESOURCE_REQUEST_PREFIX_SIZE

Minimum readable contract prefix, expressed from the published structure layout.

Value

((offsetof(maelys_datalog_session_resource_request_t, required_features) + sizeof(uint64_t)))platform-dependent

ALLOCATION_REQUEST_V1_SIZE

C · constantSince v0.19.0
ALLOCATION_REQUEST_V1_SIZE
#define MAELYS_DATALOG_ALLOCATION_REQUEST_V1_SIZE \
    sizeof(maelys_datalog_session_allocation_request_t)

Complete V1 structure size; use the expression rather than a hard-coded platform size.

Value

sizeof(maelys_datalog_session_allocation_request_t)platform-dependent

Struct: session_allocation_stats_t

C · structSince v0.19.0
session_allocation_stats_t

#include <maelys/datalog_resources.h>

Reports elastic execution charges and the peak for the current or last operation. Accounting is read-only and does not allocate or call the allocator. A fixed-memory session returns UNSUPPORTED with the output unchanged. Reading is allowed while a result or explanation lease is live, but not reentrantly during an operation.
Fields
struct_sizesize_t
Size of the supplied descriptor; initialize it with the matching public initializer when one exists.
contract_versionuint32_t
Published contract version for this descriptor.
reserveduint32_t
Reserved; keep zero.
required_featuresuint64_t
Resource-feature bits carried by this descriptor; distinct from language/execution capability bits.
cap_bytessize_t
Admitted execution byte cap.
current_bytessize_t
Current charged execution bytes.
remaining_bytessize_t
Uncharged bytes remaining below the cap.
operation_peak_bytessize_t
Peak charge since the operation started; abort and cleanup retain this peak.
Typedef
typedef struct {
    size_t struct_size;
    uint32_t contract_version;
    uint32_t reserved;
    uint64_t required_features;
    size_t cap_bytes;
    size_t current_bytes;
    size_t remaining_bytes;
    size_t operation_peak_bytes;
} maelys_datalog_session_allocation_stats_t;

Creation

ALLOCATION_STATS_INIT

C · macroSince v0.19.0
ALLOCATION_STATS_INIT

#include <maelys/datalog_resources.h>

#define MAELYS_DATALOG_ALLOCATION_STATS_INIT

Initializes the size and version of an allocation-statistics output.

Effect

Prepares the output descriptor for session_get_allocation_stats; its zero fields are initialization, not measured accounting. An aggregate initializer for maelys_datalog_session_allocation_stats_t.

Initial values
FieldInitial valueMeaning
struct_sizeMAELYS_DATALOG_ALLOCATION_STATS_V1_SIZESize of the supplied descriptor; initialize it with the matching public initializer when one exists.set automatically
contract_versionMAELYS_DATALOG_ALLOCATION_STATS_VERSIONPublished contract version for this descriptor.set automatically
reservedUINT32_C(0)Reserved; keep zero.
required_featuresUINT64_C(0)Resource-feature bits carried by this descriptor; distinct from language/execution capability bits.
cap_bytes0Admitted execution byte cap.
current_bytes0Current charged execution bytes.
remaining_bytes0Uncharged bytes remaining below the cap.
operation_peak_bytes0Peak charge since the operation started; abort and cleanup retain this peak.
Expansion
{ MAELYS_DATALOG_ALLOCATION_STATS_V1_SIZE, MAELYS_DATALOG_ALLOCATION_STATS_VERSION,        UINT32_C(0), UINT64_C(0), 0, 0, 0, 0 }
Example
maelys_datalog_session_allocation_stats_t stats = MAELYS_DATALOG_ALLOCATION_STATS_INIT;
printf("contract initialized: %s\n", stats.contract_version == MAELYS_DATALOG_ALLOCATION_STATS_VERSION ? "yes" : "no");
printf("size initialized: %s\n", stats.struct_size == sizeof(stats) ? "yes" : "no");
contract initialized: yes
size initialized: yes
Versioning

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

ALLOCATION_STATS_PREFIX_SIZE

C · constantSince v0.19.0
ALLOCATION_STATS_PREFIX_SIZE
#define MAELYS_DATALOG_ALLOCATION_STATS_PREFIX_SIZE \
    (offsetof(maelys_datalog_session_allocation_stats_t, required_features) + sizeof(uint64_t))

Minimum readable contract prefix, expressed from the published structure layout.

Value

(offsetof(maelys_datalog_session_allocation_stats_t, required_features) + sizeof(uint64_t))platform-dependent

ALLOCATION_STATS_V1_SIZE

C · constantSince v0.19.0
ALLOCATION_STATS_V1_SIZE
#define MAELYS_DATALOG_ALLOCATION_STATS_V1_SIZE \
    sizeof(maelys_datalog_session_allocation_stats_t)

Complete V1 structure size; use the expression rather than a hard-coded platform size.

Value

sizeof(maelys_datalog_session_allocation_stats_t)platform-dependent

ALLOCATION_STATS_VERSION

C · constantSince v0.19.0
ALLOCATION_STATS_VERSION
#define MAELYS_DATALOG_ALLOCATION_STATS_VERSION 1u

Version of the elastic allocation-statistics contract.

Value

1

Struct: session_storage_plan_t

C · structSince v0.14.0
session_storage_plan_t

#include <maelys/datalog_resources.h>

Describes the caller-owned arena and external slices required by a configured session. Requirements allocate no prepared state. The first four internal components sum to arena_bytes. External storage contributes only its required slice, counted once; init recomputes the plan rather than trusting stale sizes.
Fields
struct_sizesize_t
Size of the supplied descriptor; initialize it with the matching public initializer when one exists.
plan_versionuint32_t
Published version of this session storage plan.
reserveduint32_t
Reserved; keep zero.
required_featuresuint64_t
Resource-feature bits carried by this descriptor; distinct from language/execution capability bits.
arena_bytessize_t
Required caller-owned session arena size.
arena_alignmentsize_t
Required arena alignment, queried at runtime rather than hard-coded.
host_bytessize_t
Host component of the session arena.
backend_bytessize_t
Backend component of the session arena.
explanation_bytessize_t
Explanation component of the session arena.
padding_bytessize_t
Alignment padding within the session arena.
external_backend_bytessize_t
Required slice of external backend storage, counted once.
external_explanation_bytessize_t
Required slice of external explanation storage, counted once.
total_execution_bytessize_t
Total execution-storage requirement, including required external slices.
Typedef
typedef struct {
    size_t struct_size;
    uint32_t plan_version;
    uint32_t reserved; /* zero */
    uint64_t required_features;
    size_t arena_bytes;
    size_t arena_alignment;
    size_t host_bytes;
    size_t backend_bytes;
    size_t explanation_bytes;
    size_t padding_bytes;
    size_t external_backend_bytes;
    size_t external_explanation_bytes;
    size_t total_execution_bytes;
} maelys_datalog_session_storage_plan_t;

Creation

SESSION_PLAN_INIT

C · macroSince v0.14.0
SESSION_PLAN_INIT

#include <maelys/datalog_resources.h>

#define MAELYS_DATALOG_SESSION_PLAN_INIT

Initializes the size and version of a session storage plan.

Effect

Prepares the complete V1 output descriptor; session_storage_requirements_configured supplies the actual requirements. An aggregate initializer for maelys_datalog_session_storage_plan_t.

Initial values
FieldInitial valueMeaning
struct_sizeMAELYS_DATALOG_SESSION_PLAN_V1_SIZESize of the supplied descriptor; initialize it with the matching public initializer when one exists.set automatically
plan_versionMAELYS_DATALOG_SESSION_PLAN_VERSIONPublished version of this session storage plan.set automatically
reservedUINT32_C(0)Reserved; keep zero.
required_featuresUINT64_C(0)Resource-feature bits carried by this descriptor; distinct from language/execution capability bits.
arena_bytes0Required caller-owned session arena size.
arena_alignment0Required arena alignment, queried at runtime rather than hard-coded.
host_bytes0Host component of the session arena.
backend_bytes0Backend component of the session arena.
explanation_bytes0Explanation component of the session arena.
padding_bytes0Alignment padding within the session arena.
external_backend_bytes0Required slice of external backend storage, counted once.
external_explanation_bytes0Required slice of external explanation storage, counted once.
total_execution_bytes0Total execution-storage requirement, including required external slices.
Expansion
{ MAELYS_DATALOG_SESSION_PLAN_V1_SIZE, MAELYS_DATALOG_SESSION_PLAN_VERSION,        UINT32_C(0), UINT64_C(0), 0, 0, 0, 0, 0, 0, 0, 0, 0 }
Example
maelys_datalog_session_storage_plan_t plan = MAELYS_DATALOG_SESSION_PLAN_INIT;
printf("plan version initialized: %s\n", plan.plan_version == MAELYS_DATALOG_SESSION_PLAN_VERSION ? "yes" : "no");
printf("size initialized: %s\n", plan.struct_size == sizeof(plan) ? "yes" : "no");
plan version initialized: yes
size initialized: yes
Versioning

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

SESSION_PLAN_PREFIX_SIZE

C · constantSince v0.14.0
SESSION_PLAN_PREFIX_SIZE
#define MAELYS_DATALOG_SESSION_PLAN_PREFIX_SIZE \
    (offsetof(maelys_datalog_session_storage_plan_t, required_features) + sizeof(uint64_t))

Minimum readable contract prefix, expressed from the published structure layout.

Value

(offsetof(maelys_datalog_session_storage_plan_t, required_features) + sizeof(uint64_t))platform-dependent

SESSION_PLAN_V1_SIZE

C · constantSince v0.14.0
SESSION_PLAN_V1_SIZE
#define MAELYS_DATALOG_SESSION_PLAN_V1_SIZE sizeof(maelys_datalog_session_storage_plan_t)

Complete V1 structure size; use the expression rather than a hard-coded platform size.

Value

sizeof(maelys_datalog_session_storage_plan_t)platform-dependent

SESSION_PLAN_VERSION

C · constantSince v0.14.0
SESSION_PLAN_VERSION
#define MAELYS_DATALOG_SESSION_PLAN_VERSION 1u

Version of the configured-session storage-plan contract.

Value

1

Struct: backend_storage_t

C · structSince v0.11.0
backend_storage_t

#include <maelys/datalog_resources.h>

Describes borrowed, aligned storage reserved for a backend. The buffer is aligned, immovable and disjoint from all other live storage, inputs and outputs. It lives through session destruction; the host copies the descriptor, never accesses or frees its contents.
Fields
struct_sizesize_t
Size of the supplied descriptor; initialize it with the matching public initializer when one exists.
bytesvoid *
Caller-owned aligned storage; may be NULL only for zero size and zero requirements.
sizesize_t
Available bytes in the borrowed storage.
alignmentsize_t
Nonzero power-of-two alignment, no larger than alignof(max_align_t).
Typedef
typedef struct {
    size_t struct_size;
    void *bytes;
    size_t size;
    size_t alignment;
} maelys_datalog_backend_storage_t;

Handle: session_config_t ↗

Functions

session_config_set_resources()

C · functionSince v0.14.0
session_config_set_resources()

#include <maelys/datalog_resources.h>

maelys_datalog_status_t
maelys_datalog_session_config_set_resources(
maelys_datalog_session_config_t *config,
const maelys_datalog_session_resource_request_t *resources
);
Copies a resource request into a session configuration. NULL restores defaults. The configuration copies known values and remains unchanged on failure. Policy-dependent normalization and admission occur during planning or creation.
Arguments
configmaelys_datalog_session_config_t *handlemodified
Session configuration that receives the copied resource request.
resourcesconst maelys_datalog_session_resource_request_t *in
Resource request to copy; NULL restores defaults.
Return status

maelys_datalog_status_t — OK on success.

OK on success. Handle any returned failure before using the output.

Example
maelys_datalog_session_resource_request_t request = MAELYS_DATALOG_RESOURCE_REQUEST_INIT;
request.capacity_mask = MAELYS_DATALOG_CAPACITY_INPUT_FACTS;
request.input_facts = 32;
maelys_datalog_status_t status = maelys_datalog_session_config_set_resources(config, &request);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
create_session();
maelys_datalog_session_resources_t admitted = MAELYS_DATALOG_RESOURCES_INIT;
check_status(maelys_datalog_session_get_resources(session, &admitted));
printf("input capacity accepted: %s\n", admitted.input_facts == request.input_facts ? "yes" : "no");
status: ok
input capacity accepted: yes

Handle: session_t ↗

Creation

session_init_configured()

C · functionSince v0.14.0
session_init_configured()

#include <maelys/datalog_resources.h>

maelys_datalog_status_t
maelys_datalog_session_init_configured(
void *arena,
size_t arena_bytes,
const maelys_datalog_policy_t *policy,
size_t policy_index,
const maelys_datalog_session_config_t *config,
maelys_datalog_session_t **out_session,
maelys_datalog_diagnostic_t *out_diagnostic
);
Initializes a configured session in a caller-owned arena. Supply the aligned caller arena allocated to the size and alignment returned by the requirements query. Init recomputes its plan from the policy and configuration. Whole-session initialization rejects ABI 5; the convenience create_configured path retains its legacy ABI 5 default path.
Arguments
arenavoid *in/out
Aligned, disjoint caller storage, kept alive through session destruction.
arena_bytessize_tin
Available bytes in the caller-owned arena.
policyconst maelys_datalog_policy_t *in
Loaded policy from which to prepare the session.
policy_indexsize_tin
Index of the policy within the loaded manifest.
configconst maelys_datalog_session_config_t *in
Session configuration read to normalize and admit the requested resources.
Outputs

Written on success.

out_sessionmaelys_datalog_session_t **out
Receives the session initialized in caller storage.

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

Return status

maelys_datalog_status_t — OK on success.

OK on success. Handle any returned failure before using the output.

Example
maelys_datalog_session_storage_plan_t plan = MAELYS_DATALOG_SESSION_PLAN_INIT;
check_status(maelys_datalog_session_storage_requirements_configured(policy, 0, config, &plan, &diagnostic));
session_storage = allocate_storage(plan.arena_bytes, plan.arena_alignment);
maelys_datalog_status_t status = maelys_datalog_session_init_configured(
    session_storage, plan.arena_bytes, policy, 0, config, &session, &diagnostic);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("session created: %s\n", session != NULL ? "yes" : "no");
status: ok
session created: yes

session_storage_requirements_configured()

C · functionSince v0.14.0
session_storage_requirements_configured()

#include <maelys/datalog_resources.h>

maelys_datalog_status_t
maelys_datalog_session_storage_requirements_configured(
const maelys_datalog_policy_t *policy,
size_t policy_index,
const maelys_datalog_session_config_t *config,
maelys_datalog_session_storage_plan_t *out_plan,
maelys_datalog_diagnostic_t *out_diagnostic
);
Measures and describes the complete configured session arena. Query requirements at runtime rather than hard-coding platform-dependent sizes or alignment. No prepared state is allocated. Whole-session planning rejects ABI 5 backend selections; no provider is migrated automatically.
Arguments
policyconst maelys_datalog_policy_t *in
Loaded policy from which to prepare the session.
policy_indexsize_tin
Index of the policy within the loaded manifest.
configconst maelys_datalog_session_config_t *in
Session configuration read to normalize and admit the requested resources.
Outputs

Written on success.

out_planmaelys_datalog_session_storage_plan_t *out
Initialized storage-plan descriptor to receive requirements; it owns no prepared state.

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

Return status

maelys_datalog_status_t — OK on success.

OK on success. Handle any returned failure before using the output.

Example
maelys_datalog_session_storage_plan_t plan = MAELYS_DATALOG_SESSION_PLAN_INIT;
maelys_datalog_status_t status = maelys_datalog_session_storage_requirements_configured(
    policy, 0, config, &plan, &diagnostic);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("storage required: %s\n", plan.arena_bytes > 0 ? "yes" : "no");
printf("alignment is a power of two: %s\n",
    plan.arena_alignment > 0 && (plan.arena_alignment & (plan.arena_alignment - 1u)) == 0 ? "yes" : "no");
status: ok
storage required: yes
alignment is a power of two: yes

Functions

session_get_allocation_stats()

C · functionSince v0.19.0
session_get_allocation_stats()

#include <maelys/datalog_resources.h>

maelys_datalog_status_t
maelys_datalog_session_get_allocation_stats(
const maelys_datalog_session_t *session,
maelys_datalog_session_allocation_stats_t *out_stats
);
Reads elastic allocation accounting without allocating. The reference backend returns UNSUPPORTED for its fixed-memory sessions and leaves the initialized output unchanged. This is not a claim of zero memory use.
Arguments
sessionconst maelys_datalog_session_t *handleread
Live session to inspect.
Outputs

Written on success.

out_statsmaelys_datalog_session_allocation_stats_t *out
Initialized allocation-statistics descriptor to receive elastic accounting.
Return status

maelys_datalog_status_t — OK on success.

OK for supported elastic accounting. UNSUPPORTED for fixed memory, with unchanged output. Failed output validation writes nothing.

Example
create_session();
maelys_datalog_session_allocation_stats_t stats = MAELYS_DATALOG_ALLOCATION_STATS_INIT;
stats.cap_bytes = 11; stats.current_bytes = 7;
stats.remaining_bytes = 4; stats.operation_peak_bytes = 9;
const maelys_datalog_session_allocation_stats_t previous = stats;
maelys_datalog_status_t status = maelys_datalog_session_get_allocation_stats(session, &stats);
printf("status: %s\n", maelys_datalog_status_name(status));
if (status != MAELYS_DATALOG_STATUS_UNSUPPORTED) { check_status(status); return EXIT_FAILURE; }
printf("accounting unchanged: %s\n", allocation_stats_unchanged(&stats, &previous) ? "yes" : "no");
status: unsupported
accounting unchanged: yes

session_get_resources()

C · functionSince v0.14.0
session_get_resources()

#include <maelys/datalog_resources.h>

maelys_datalog_status_t
maelys_datalog_session_get_resources(
const maelys_datalog_session_t *session,
maelys_datalog_session_resources_t *out_resources
);
Reads the normalized resource capacities of a session. The output reports admitted capacities, not unresolved defaults or presence sentinels.
Arguments
sessionconst maelys_datalog_session_t *handleread
Live session to inspect.
Outputs

Written on success.

out_resourcesmaelys_datalog_session_resources_t *out
Initialized descriptor to receive all normalized resource capacities.
Return status

maelys_datalog_status_t — OK on success.

OK on success. Handle any returned failure before using the output.

Example
create_session();
maelys_datalog_session_resources_t admitted = MAELYS_DATALOG_RESOURCES_INIT;
maelys_datalog_status_t status = maelys_datalog_session_get_resources(session, &admitted);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("fixed memory: %s\n", admitted.memory_mode == MAELYS_DATALOG_MEMORY_FIXED ? "yes" : "no");
printf("input capacity available: %s\n", admitted.input_facts > 0 ? "yes" : "no");
status: ok
fixed memory: yes
input capacity available: yes

Handle: policy_t ↗

Creation

policy_load_manifest_text_in()

C · functionSince v0.10.0
policy_load_manifest_text_in()

#include <maelys/datalog_resources.h>

maelys_datalog_status_t
maelys_datalog_policy_load_manifest_text_in(
void *storage,
size_t storage_bytes,
const char *manifest_json,
size_t manifest_length,
const maelys_datalog_policy_bundle_entry_t *bundle,
size_t bundle_count,
unsigned flags,
maelys_datalog_policy_t **out_policy,
maelys_datalog_diagnostic_t *out_diagnostic
);
Loads a manifest using caller-owned policy storage. The policy object uses caller storage with no heap fallback. JSON parsing, contexts and extension callbacks may still allocate: this is not a whole-loader zero-allocation guarantee. Keep the arena alive until the policy is closed; policy_free closes it without freeing the arena. Failure may overwrite the arena.
Arguments
storagevoid *in/out
Aligned, unused caller storage for the policy handle, disjoint from inputs, outputs and diagnostics.
storage_bytessize_tin
Available bytes in caller policy storage.
manifest_jsonconst char *in
Manifest JSON text to load.
manifest_lengthsize_tin
Length of the manifest JSON text.
bundleconst maelys_datalog_policy_bundle_entry_t *in
In-memory source bundle used to resolve manifest policy sources.
bundle_countsize_tin
Number of bundle entries.
flagsunsigned intin
Loading-permission flags.
Outputs

Written on success.

out_policymaelys_datalog_policy_t **out
Receives the policy handle; remains 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 on success. Handle any returned failure before using the output.

Example
size_t bytes = 0, alignment = 0;
check_status(maelys_datalog_policy_storage_requirements(&bytes, &alignment));
policy_storage = allocate_storage(bytes, alignment);
maelys_datalog_status_t status = maelys_datalog_policy_load_manifest_text_in(
    policy_storage, bytes, manifest_json, strlen(manifest_json), bundle,
    sizeof(bundle) / sizeof(bundle[0]), MAELYS_DATALOG_PUBLIC_ALLOW_NONE, &caller_policy, &diagnostic);
printf("status: %s\n", maelys_datalog_status_name(status));
check_status(status);
printf("policy created: %s\n", caller_policy != NULL ? "yes" : "no");
status: ok
policy created: yes

policy_storage_requirements()

C · functionSince v0.10.0
policy_storage_requirements()

#include <maelys/datalog_resources.h>

maelys_datalog_status_t
maelys_datalog_policy_storage_requirements(
size_t *out_bytes,
size_t *out_alignment
);
Measures the caller storage needed by a policy handle. Query size and alignment at runtime; both depend on the platform. The fixed-profile policy arena holds up to eight policies.
Outputs

Written on success.

out_bytessize_t *out
Receives the required caller-storage size.
out_alignmentsize_t *out
Receives the required caller-storage alignment.
Return status

maelys_datalog_status_t — OK on success.

OK on success. Handle any returned failure before using the output.

Example
size_t bytes = 0, alignment = 0;
maelys_datalog_status_t status = maelys_datalog_policy_storage_requirements(&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

Usage guides