C ABI

Create a parser, register sources, and request values through the opaque DIP handle.

Basic examples

Parse text and read one value. Link these C examples against snt-c:

#include <snt/c/dip.h>
#include <stdio.h>

int main(void) {
    snt_dip* parser = NULL;
    snt_dip_error error = {0};
    char value[128];
    int failed = snt_dip_parser_create(&parser, &error) ||
                 snt_dip_parser_add_string(parser, "steps int = 100", &error) ||
                 snt_dip_parser_parse(parser, &error) ||
                 snt_dip_parser_get(parser, "steps", value, sizeof(value), &error);
    if (failed) fprintf(stderr, "%s\n", error.message);
    else puts(value);  /* 100 */
    snt_dip_parser_free(parser);
    return failed;
}

Register an override before parsing:

#include <snt/c/dip.h>
#include <stdio.h>

int main(void) {
    snt_dip* parser = NULL;
    snt_dip_error error = {0};
    char value[128];
    int failed = snt_dip_parser_create(&parser, &error) ||
                 snt_dip_parser_add_string(parser, "steps int = 100", &error) ||
                 snt_dip_parser_add_override_string(parser, "steps = 200", &error) ||
                 snt_dip_parser_parse(parser, &error) ||
                 snt_dip_parser_get(parser, "steps", value, sizeof(value), &error);
    if (failed) fprintf(stderr, "%s\n", error.message);
    else puts(value);  /* 200 */
    snt_dip_parser_free(parser);
    return failed;
}

Common workflows

Task

Call chain

Result

Create and evaluate

snt_dip_parser_create; add_*; snt_dip_parser_parse

Owned snt_dip* and success status

Read a scalar as text

snt_dip_parser_get

Caller-owned buffer

Traverse a hierarchy

snt_dip_environment_get_node; get_size; get_entry

Owned snt_dip_node* handles

Read typed values or arrays

snt_dip_node_get_* and snt_dip_node_copy_*_array

C scalar or caller-owned array

Persist, export, or report

snt_dip_environment_save; generate; generate_report

DIPH5, generated source, or report file

Compare snapshots

snt_dip_compare_files; comparison_summary; comparison_get

Owned snt_dip_comparison* and borrowed entries

Release owned objects

snt_dip_node_free; snt_dip_comparison_free; snt_dip_parser_free

No result; free nodes before their parser

snt_dip* dip = NULL;
snt_dip_error error = {0};
int failed = snt_dip_parser_create(&dip, &error) ||
             snt_dip_parser_add_string(dip, "steps int = 100", &error) ||
             snt_dip_parser_parse(dip, &error) ||
             snt_dip_environment_save(dip, "run.diph5", &error);
if (failed) {
    fprintf(stderr, "%s\n", error.message);
} else {
    snt_dip_comparison* changes = NULL;
    size_t added = 0, removed = 0, changed = 0;
    if (snt_dip_compare_files("before.diph5", "run.diph5",
            SNT_DIP_COMPARE_EFFECTIVE, 3, &changes, &error) == 0) {
        snt_dip_comparison_summary(changes, &added, &removed, &changed, &error);
        printf("%zu changed\n", changed);
        snt_dip_comparison_free(changes);
    }
}
snt_dip_parser_free(dip);

Every node returned by snt_dip_node_get_child, get_item, get_element, or get_entry is independently owned. Free it with snt_dip_node_free before the parser. Comparison strings and index pointers borrow the comparison handle and remain valid only until snt_dip_comparison_free.

See the C binding guide and C API reference.

DIPL developer tools. The C ABI parses and evaluates DIPL and reports parser diagnostics through snt_dip_error. It does not currently expose formatter, validator, or linter entry points. Use the CLI or the C++ tools for those operations.

Current limitations and differences

Compared with the canonical C++ implementation:

  • The ABI exposes opaque parser and node handles, typed scalar/array getters, metadata, persistence, export, reports, and snapshot comparison. It does not expose host callbacks, adapters, semantic descriptions/previews, or the C++ editing, guided-setup, and experiment classes.

  • Dependency graphs can be recorded for persistence and reports, but the ABI has no graph-traversal interface.

  • Standalone formatter, validator, and linter entry points are absent; parsing reports validation errors. Use the CLI or C++ tooling API for source tools. Callers manage buffers and free handles; errors use return codes.

Binding reference

This is a lookup index, not a sequence to read from top to bottom. Use Common workflows above to choose a task, then find the exact C function below. Integer-returning calls return zero on success. Output handles and buffers are passed by pointer; a nonzero result reports code and message through snt_dip_error.

Parser and input registration

  • snt_dip_parser_create(&dip, &error) and snt_dip_parser_free(dip).

  • snt_dip_parser_add_string and snt_dip_parser_add_file.

  • snt_dip_parser_add_schema_string, snt_dip_parser_add_schema_file, snt_dip_parser_add_override_string, and snt_dip_parser_add_override_file.

  • snt_dip_parser_add_project, snt_dip_parser_parse, and snt_dip_parser_parse_with_graph.

  • snt_dip_parser_get(dip, path, buffer, capacity, &error) and snt_dip_environment_get_node(dip, path, &node, &error).

Node hierarchy and values

  • snt_dip_node_get_kind, snt_dip_node_get_node_type, snt_dip_node_get_path, and snt_dip_node_get_link_target.

  • snt_dip_node_get_child, snt_dip_node_get_item, snt_dip_node_get_key, snt_dip_node_get_element, and snt_dip_node_get_entry.

  • snt_dip_node_get_size, snt_dip_node_get_type, snt_dip_node_get_shape, and snt_dip_node_get_value_size.

  • snt_dip_node_get_bool, snt_dip_node_get_int64, snt_dip_node_get_uint64, snt_dip_node_get_double, and snt_dip_node_get_string.

  • snt_dip_node_get_bool_at, snt_dip_node_get_int64_at, snt_dip_node_get_uint64_at, snt_dip_node_get_double_at, and snt_dip_node_get_string_at.

  • snt_dip_node_copy_bool_array, snt_dip_node_copy_int64_array, snt_dip_node_copy_uint64_array, snt_dip_node_copy_double_array, and snt_dip_node_copy_string_array copy whole arrays.

  • snt_dip_node_get_provenance, snt_dip_node_get_metadata, snt_dip_node_has_metadata, snt_dip_node_get_metadata_list_size, and snt_dip_node_get_metadata_list_item.

  • snt_dip_node_has_units, snt_dip_node_get_units, snt_dip_node_is_overridden, and snt_dip_node_free.

Options, persistence, export, and comparison

  • snt_dip_node_get_option_count, snt_dip_node_get_option_value, snt_dip_node_get_option_label, and snt_dip_node_get_option_units.

  • snt_dip_parser_is_overridden, snt_dip_environment_load, and snt_dip_environment_save.

  • snt_dip_environment_get_source_count, snt_dip_environment_get_source_path, and snt_dip_environment_get_source_name.

  • snt_dip_environment_generate, snt_dip_environment_generate_report, and snt_dip_environment_generate_report_with_options.

  • snt_dip_compare_files, snt_dip_comparison_summary, snt_dip_comparison_count, snt_dip_comparison_get, snt_dip_comparison_render_text, and snt_dip_comparison_free.

Pass SNT_DIP_COMPARE_EFFECTIVE or SNT_DIP_COMPARE_FULL to comparisons. Generated parameter lists use the SNT_DIP_EXPORT_* constants and reports use the SNT_DIP_REPORT_* constants; snt_dip_difference.kind is one of SNT_DIP_DIFFERENCE_ADDED, REMOVED, or CHANGED.