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
#include <maelys/datalog_resources.h>
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
#include <maelys/datalog_resources.h>
#define MAELYS_DATALOG_RESOURCE_REQUEST_INITStarting 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().
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.
| Field | Initial value | Meaning |
|---|---|---|
struct_size | MAELYS_DATALOG_RESOURCE_REQUEST_V1_SIZE | Size of the supplied descriptor; initialize it with the matching public initializer when one exists.set automatically |
contract_version | MAELYS_DATALOG_RESOURCE_CONTRACT_VERSION | Published contract version for this descriptor.set automatically |
memory_mode | MAELYS_DATALOG_MEMORY_FIXED | Fixed or backend-elastic memory mode. |
required_features | UINT64_C(0) | Resource-feature bits carried by this descriptor; distinct from language/execution capability bits. |
capacity_mask | UINT64_C(0) | Selects the capacities explicitly present; an absent capacity uses the loaded profile default. |
input_facts | 0 | Maximum raw input-snapshot facts before deduplication. |
derived_facts | 0 | Capacity for the complete derived database, including helper facts. |
symbols | 0 | Capacity for dictionary entries, including program roots. |
text_bytes | 0 | Capacity 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 }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
#define MAELYS_DATALOG_CAPACITY_ALL UINT64_C(15)Mask containing all four capacity-presence bits.
15
CAPACITY_DERIVED_FACTS
#define MAELYS_DATALOG_CAPACITY_DERIVED_FACTS (UINT64_C(1) << 1)Presence bit for the complete derived-fact capacity.
2
CAPACITY_INPUT_FACTS
#define MAELYS_DATALOG_CAPACITY_INPUT_FACTS (UINT64_C(1) << 0)Presence bit for the raw input-fact capacity.
1
CAPACITY_SYMBOLS
#define MAELYS_DATALOG_CAPACITY_SYMBOLS (UINT64_C(1) << 2)Presence bit for the symbol-dictionary capacity.
4
CAPACITY_TEXT_BYTES
#define MAELYS_DATALOG_CAPACITY_TEXT_BYTES (UINT64_C(1) << 3)Presence bit for the interned-text capacity.
8
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.
1
MEMORY_FIXED
#define MAELYS_DATALOG_MEMORY_FIXED UINT32_C(0)Selects fixed-memory execution.
0
RESOURCE_CALLER_ALLOCATOR
#define MAELYS_DATALOG_RESOURCE_CALLER_ALLOCATOR (UINT64_C(1) << 1)Resource-feature bit required for caller allocation.
2
RESOURCE_SESSION_CAPACITIES
#define MAELYS_DATALOG_RESOURCE_SESSION_CAPACITIES (UINT64_C(1) << 0)Resource-feature bit for explicit session capacities.
1
RESOURCE_SUPPORTED
#define MAELYS_DATALOG_RESOURCE_SUPPORTED \
(MAELYS_DATALOG_RESOURCE_SUPPORTED_014 | MAELYS_DATALOG_RESOURCE_CALLER_ALLOCATOR)Supported resource-feature mask, including caller allocation.
3
Versioning
Initialize with the RESOURCE_REQUEST_INIT macro; these values identify the structure version and are not set by hand.
RESOURCE_CONTRACT_VERSION
#define MAELYS_DATALOG_RESOURCE_CONTRACT_VERSION 1uVersion of the resource-request and normalized-resources contract.
1
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.
(offsetof(maelys_datalog_session_resource_request_t, required_features) + sizeof(uint64_t))platform-dependent
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.
sizeof(maelys_datalog_session_resource_request_t)platform-dependent
RESOURCE_SUPPORTED_014
#define MAELYS_DATALOG_RESOURCE_SUPPORTED_014 \
MAELYS_DATALOG_RESOURCE_SESSION_CAPACITIESHistorical supported-resource mask retained for older compiled consumers.
1
| Used by | backend_v6_t — prepare · backend_v6_t — storage_requirements · backend_v7_t — prepare · backend_v7_t — storage_requirements · session_allocation_resources_t — base |
|---|
Struct: session_resources_t
#include <maelys/datalog_resources.h>
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
#include <maelys/datalog_resources.h>
#define MAELYS_DATALOG_RESOURCES_INITStarting value for reading a session's capacities: pass it to session_get_resources(), which fills in the capacities granted to the session.
Prepares the output descriptor for session_get_resources; the getter supplies the admitted capacities. An aggregate initializer for maelys_datalog_session_resources_t.
| Field | Initial value | Meaning |
|---|---|---|
struct_size | MAELYS_DATALOG_RESOURCES_V1_SIZE | Size of the supplied descriptor; initialize it with the matching public initializer when one exists.set automatically |
contract_version | MAELYS_DATALOG_RESOURCE_CONTRACT_VERSION | Published contract version for this descriptor.set automatically |
memory_mode | MAELYS_DATALOG_MEMORY_FIXED | Fixed or backend-elastic memory mode. |
required_features | UINT64_C(0) | Resource-feature bits carried by this descriptor; distinct from language/execution capability bits. |
input_facts | 0 | Maximum raw input-snapshot facts before deduplication. |
derived_facts | 0 | Capacity for the complete derived database, including helper facts. |
symbols | 0 | Capacity for dictionary entries, including program roots. |
text_bytes | 0 | Capacity 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 }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
#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.
(offsetof(maelys_datalog_session_resources_t, required_features) + sizeof(uint64_t))platform-dependent
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.
sizeof(maelys_datalog_session_resources_t)platform-dependent
Struct: caller_allocator_t
#include <maelys/datalog_resources.h>
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
#include <maelys/datalog_resources.h>
#define MAELYS_DATALOG_CALLER_ALLOCATOR_INITInitializes an allocator descriptor with no context or callbacks.
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.
| Field | Initial value | Meaning |
|---|---|---|
struct_size | MAELYS_DATALOG_CALLER_ALLOCATOR_V1_SIZE | Size of the supplied descriptor; initialize it with the matching public initializer when one exists.set automatically |
contract_version | MAELYS_DATALOG_CALLER_ALLOCATOR_VERSION | Published contract version for this descriptor.set automatically |
reserved | UINT32_C(0) | Reserved; keep zero. |
required_features | UINT64_C(0) | Resource-feature bits carried by this descriptor; distinct from language/execution capability bits. |
context | NULL | Borrowed callback context, live through destruction and the last release, including failed preparation. |
acquire | NULL | Borrowed callback that supplies storage for the requested byte count and alignment. |
release | NULL | Borrowed 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 }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
#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.
(offsetof(maelys_datalog_caller_allocator_t, required_features) + sizeof(uint64_t))platform-dependent
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.
sizeof(maelys_datalog_caller_allocator_t)platform-dependent
CALLER_ALLOCATOR_VERSION
#define MAELYS_DATALOG_CALLER_ALLOCATOR_VERSION 1uVersion of the caller-allocator descriptor contract.
1
Struct: session_allocation_request_t
#include <maelys/datalog_resources.h>
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
#include <maelys/datalog_resources.h>
#define MAELYS_DATALOG_ALLOCATION_REQUEST_INITInitializes an elastic request that requires a caller allocator.
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.
| Field | Initial value | Meaning |
|---|---|---|
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_cap | 0 | Maximum bytes charged to elastic execution. |
allocator | NULL | Borrowed 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 }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
#define MAELYS_DATALOG_ALLOCATION_REQUEST_PREFIX_SIZE MAELYS_DATALOG_RESOURCE_REQUEST_PREFIX_SIZEMinimum readable contract prefix, expressed from the published structure layout.
((offsetof(maelys_datalog_session_resource_request_t, required_features) + sizeof(uint64_t)))platform-dependent
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.
sizeof(maelys_datalog_session_allocation_request_t)platform-dependent
Struct: session_allocation_stats_t
#include <maelys/datalog_resources.h>
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
#include <maelys/datalog_resources.h>
#define MAELYS_DATALOG_ALLOCATION_STATS_INITInitializes the size and version of an allocation-statistics output.
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.
| Field | Initial value | Meaning |
|---|---|---|
struct_size | MAELYS_DATALOG_ALLOCATION_STATS_V1_SIZE | Size of the supplied descriptor; initialize it with the matching public initializer when one exists.set automatically |
contract_version | MAELYS_DATALOG_ALLOCATION_STATS_VERSION | Published contract version for this descriptor.set automatically |
reserved | UINT32_C(0) | Reserved; keep zero. |
required_features | UINT64_C(0) | Resource-feature bits carried by this descriptor; distinct from language/execution capability bits. |
cap_bytes | 0 | Admitted execution byte cap. |
current_bytes | 0 | Current charged execution bytes. |
remaining_bytes | 0 | Uncharged bytes remaining below the cap. |
operation_peak_bytes | 0 | Peak 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 }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
#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.
(offsetof(maelys_datalog_session_allocation_stats_t, required_features) + sizeof(uint64_t))platform-dependent
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.
sizeof(maelys_datalog_session_allocation_stats_t)platform-dependent
ALLOCATION_STATS_VERSION
#define MAELYS_DATALOG_ALLOCATION_STATS_VERSION 1uVersion of the elastic allocation-statistics contract.
1
Struct: session_storage_plan_t
#include <maelys/datalog_resources.h>
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
#include <maelys/datalog_resources.h>
#define MAELYS_DATALOG_SESSION_PLAN_INITInitializes the size and version of a session storage plan.
Prepares the complete V1 output descriptor; session_storage_requirements_configured supplies the actual requirements. An aggregate initializer for maelys_datalog_session_storage_plan_t.
| Field | Initial value | Meaning |
|---|---|---|
struct_size | MAELYS_DATALOG_SESSION_PLAN_V1_SIZE | Size of the supplied descriptor; initialize it with the matching public initializer when one exists.set automatically |
plan_version | MAELYS_DATALOG_SESSION_PLAN_VERSION | Published version of this session storage plan.set automatically |
reserved | UINT32_C(0) | Reserved; keep zero. |
required_features | UINT64_C(0) | Resource-feature bits carried by this descriptor; distinct from language/execution capability bits. |
arena_bytes | 0 | Required caller-owned session arena size. |
arena_alignment | 0 | Required arena alignment, queried at runtime rather than hard-coded. |
host_bytes | 0 | Host component of the session arena. |
backend_bytes | 0 | Backend component of the session arena. |
explanation_bytes | 0 | Explanation component of the session arena. |
padding_bytes | 0 | Alignment padding within the session arena. |
external_backend_bytes | 0 | Required slice of external backend storage, counted once. |
external_explanation_bytes | 0 | Required slice of external explanation storage, counted once. |
total_execution_bytes | 0 | Total 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 }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
#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.
(offsetof(maelys_datalog_session_storage_plan_t, required_features) + sizeof(uint64_t))platform-dependent
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.
sizeof(maelys_datalog_session_storage_plan_t)platform-dependent
SESSION_PLAN_VERSION
#define MAELYS_DATALOG_SESSION_PLAN_VERSION 1uVersion of the configured-session storage-plan contract.
1
Struct: backend_storage_t
#include <maelys/datalog_resources.h>
Typedef
typedef struct {
size_t struct_size;
void *bytes;
size_t size;
size_t alignment;
} maelys_datalog_backend_storage_t;| Used by | backend_t — prepare · backend_v6_t — prepare · backend_v7_t — prepare · session_config_set_backend_storage() |
|---|
Handle: session_config_t ↗
Functions
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
);maelys_datalog_status_t — OK on success.
OK on success. Handle any returned failure before using the output.
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()
#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
);Written on success.
out_diagnostic: optional diagnostic details on failure; pass NULL when not needed.
maelys_datalog_status_t — OK on success.
OK on success. Handle any returned failure before using the output.
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()
#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
);Written on success.
out_diagnostic: optional diagnostic details on failure; pass NULL when not needed.
maelys_datalog_status_t — OK on success.
OK on success. Handle any returned failure before using the output.
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()
#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
);Written on success.
maelys_datalog_status_t — OK on success.
OK for supported elastic accounting. UNSUPPORTED for fixed memory, with unchanged output. Failed output validation writes nothing.
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()
#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
);Written on success.
maelys_datalog_status_t — OK on success.
OK on success. Handle any returned failure before using the output.
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()
#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
);Written on success.
out_diagnostic: optional diagnostic details on failure; pass NULL when not needed.
maelys_datalog_status_t — OK on success.
OK on success. Handle any returned failure before using the output.
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()
#include <maelys/datalog_resources.h>
maelys_datalog_status_t
maelys_datalog_policy_storage_requirements(
size_t *out_bytes,
size_t *out_alignment
);Written on success.
maelys_datalog_status_t — OK on success.
OK on success. Handle any returned failure before using the output.
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