Artifact 8e9274fc6e6c2e77d30cb9d0b2278085eed3d84d13057cad17e79d388aacb4ff:
- File
src/conf.h
— part of check-in
[6d70dcc76a]
at
2026-11-12 19:36:41
on branch trunk
— Phase 1: the config parser, the no-change run and the speed bench
suit check parses suit.conf strictly and prints a canonical dump. Any unknown kind or key, duplicate, cycle or dangling name rejects the whole file with its line number.
suit run compares a stamp against the files it names and exits without writing, allocating or printing when nothing changed.
suit bench times suit run against an empty program built the same way and against /usr/bin/true, interleaved, and fails the build when the no-change run costs more than 1 ms over the empty program or 1 MiB more memory. It measured 0.65 to 0.94 ms over, quiet and under load. A system binary starts 0.6 to 1.5 ms faster than any built binary on macOS, so it is shown for information and is not the baseline.
94 unit checks, 100 shell cases and a libFuzzer target for the parser. (user: dmestas, size: 2191) [annotate] [blame] [check-ins using]
#ifndef SUIT_CONF_H #define SUIT_CONF_H #include <stddef.h> #include <stdint.h> #include <stdio.h> constexpr size_t CONF_LINE_MAX = 4096; constexpr size_t CONF_FILE_MAX = 1048576; constexpr size_t CONF_NAME_MAX = 128; constexpr uint32_t CONF_HARNESS_MAX = 64; constexpr uint32_t CONF_OUTFIT_MAX = 512; constexpr uint32_t CONF_WEAR_MAX = 256; constexpr uint32_t CONF_NEED_MAX = 256; constexpr uint32_t CONF_UPSTREAM_MAX = 128; constexpr uint32_t CONF_ENTRY_MAX = 8192; constexpr uint32_t CONF_SECTION_MAX = CONF_HARNESS_MAX + CONF_OUTFIT_MAX + CONF_WEAR_MAX + CONF_NEED_MAX + CONF_UPSTREAM_MAX; typedef enum { KIND_HARNESS, KIND_OUTFIT, KIND_WEAR, KIND_NEED, KIND_UPSTREAM, KIND_COUNT } Kind; // Every string points into Conf.buf. A list value is stored with its words // separated by single spaces; walk it with conf_list_next. typedef struct { const char *key; const char *val; int line; } Entry; // harness, outfit, upstream: arg[0] is the name. // need: arg[0] is the harness, arg[1] the name. // wear: arg[0] is the scope, arg[1] the target ("" if none), arg[2] the // machine name ("" if none). typedef struct { Kind kind; const char *arg[3]; int line; uint32_t first; uint32_t count; } Section; typedef struct { uint32_t nsections; uint32_t nentries; uint32_t kind_count[KIND_COUNT]; Section sections[CONF_SECTION_MAX]; Entry entries[CONF_ENTRY_MAX]; char buf[CONF_FILE_MAX + 1]; } Conf; // line is 0 when the error concerns the whole file. typedef struct { int line; char msg[256]; } ConfError; // Parse DATA (LEN bytes) into C. On failure C holds nothing usable and ERR // says what and where. [[nodiscard]] bool conf_parse(Conf *c, const char *data, size_t len, ConfError *err); [[nodiscard]] bool conf_load(Conf *c, const char *path, ConfError *err); // Write the canonical dump: sections and entries in stable order, one fact // per line. Reorders C in place. void conf_dump(Conf *c, FILE *out); const char *conf_kind_name(Kind kind); // Step through a list value. Returns false at the end. bool conf_list_next(const char **cursor, const char **word, size_t *len); #endif