tur/image_hooks
standard resource-reacquisition hooks for image dumps.
A small library of ready-made reload/finalize hooks for the most common OS-handle cases, so applications do not hand-roll the same reopen logic. Load this *after* stdlib/image.tur -- it builds on image/register-reload-hook! and image/register-finalize-hook!.
The marquee facility is a tracked-file table: declare the files an image cannot carry with image-hooks/track-file! during cold-start init, install the reopen hook once with image-hooks/use-reopen-tracked!, and after a warm resume read each file's fresh FILE* back via image-hooks/slot-handle.
Like image.tur's hook registry, the table lives in a single function's static storage (self-contained, no file-scope C global) and survives across the cold/warm boundary within one process.
Since: Phase AI (application-image-dumps-plan, AI5.4)
image-hooks/cstr->raw
(image-hooks/cstr->raw [s :cstr] :int)
reinterpret a :cstr as its raw int64 pointer (internal).
image-hooks/file-table
(image-hooks/file-table [op :int arg :int aux :int] :int)
backing store for tracked files (internal).
image-hooks/track-file!
(image-hooks/track-file! [path :cstr mode :cstr] :int)
register a file path to reopen on warm start.
Call this during cold-start init for each OS file the image cannot carry. The handle itself is never serialised; after a warm resume the reopen hook re-establishes it and you read it back via image-hooks/slot-handle.
| path | the file path to reopen | |
| mode | the fopen mode (e.g. "r", "a", "rb"); empty defaults to "r" |
The 0-based slot id, or -1 if the table is full.
Since: Phase AI (AI5.4)
image-hooks/reopen-tracked-files
(image-hooks/reopen-tracked-files :int)
the reload hook: reopen all tracked files.
Returns the number of files successfully reopened. Registered for you by image-hooks/use-reopen-tracked!; you rarely call it directly.
Since: Phase AI (AI5.4)
image-hooks/slot-handle
(image-hooks/slot-handle [id :int] :int)
the current FILE* for a tracked slot.
Returns 0 until the reopen hook has run; after a warm resume it is the fresh FILE* for that slot. Pass it to inline-C that does the actual reads/writes.
| id | the slot id returned by image-hooks/track-file! |
The cached FILE* as an int handle (cast to FILE* in your inline-C), or 0 if the slot has not been reopened yet.
Since: Phase AI (AI5.4)
image-hooks/tracked-count
(image-hooks/tracked-count :int)
number of tracked file slots.
image-hooks/use-reopen-tracked!
(image-hooks/use-reopen-tracked! :int)
install the tracked-file reopen reload hook.
Call once at the top of main (before the with-image-cache call) so the hook is present on warm starts. After this, any file declared with image-hooks/track-file! is reopened automatically on resume.
The number of reload hooks registered so far (from image.tur).
Since: Phase AI (AI5.4)
image-hooks/flush-stdio
(image-hooks/flush-stdio :int)
the finalize hook: flush stdout and stderr.
Ensures buffered output is on disk before the image is written. Returns 0.
Since: Phase AI (AI5.4)
image-hooks/use-flush-stdio!
(image-hooks/use-flush-stdio! :int)
install the stdout/stderr flush finalize hook.
Call once at the top of main. Returns the number of finalize hooks registered.
Since: Phase AI (AI5.4)