From 08056bb65bb9d1cfa4ccb1cd0b9cb67554d560a3 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Fri, 25 Sep 2026 11:57:33 +0100 Subject: Allow drafts without a stored base Runtime-owned values such as an app's text need the same extent tree as stored documents without a store file. pure_draft_new creates such a draft; it edits, lends versions and reclaims like any draft but refuses to commit. pure_draft_restore returns a held draft to an earlier version, so a failed event can abandon its edits. A test runs 4,000 random edits with a fifth abandoned against a flat oracle under ASan/UBSan. --- prototypes/connections/state.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'prototypes/connections/state.h') diff --git a/prototypes/connections/state.h b/prototypes/connections/state.h index d0b386c..461f71a 100644 --- a/prototypes/connections/state.h +++ b/prototypes/connections/state.h @@ -12,6 +12,9 @@ * appends only the draft's new extents. One owner thread per draft. */ typedef struct PureDraft PureDraft; +/* A working value with no stored base, for runtime-owned state such as an + * app's text. It edits and reads like any draft but cannot be committed. */ +PureDraft *pure_draft_new(void); /* A missing key opens as an empty draft at revision 0; commit creates it. */ PureResult pure_draft_open(const char *path, const char *key, PureDraft **out); /* Memory only. Fails without change on a bad range or when memory runs out. */ @@ -32,6 +35,8 @@ PureResult pure_draft_read_version(const PureDraft *, PureVersion, size_t offset bool (*visit)(void *, PureSpan), void *context); /* While held, edits keep every earlier version's nodes (one transaction). */ void pure_draft_hold(PureDraft *, bool held); +/* Abandon edits made since version was taken; the draft was held since then. */ +void pure_draft_restore(PureDraft *, PureVersion); /* Publish if the key is still at the draft's base revision. On success the * draft continues from the new revision; on any failure it is unchanged. */ PureResult pure_draft_commit(PureDraft *, int64_t *revision); -- cgit v1.2.3