From c8f0d65a69274dc8a072c35a6c13cb07a6770007 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 23 Nov 2026 09:15:57 -0300 Subject: pdf, abi, core: the pointer and count a C struct or a C caller hands over read through one helper, `addon.cSlice` (abi/addon.zig), NULL being none whatever the count: the bridge says none with a NULL (pardes_pdf_search_page with no hit, pardes_pdf_select over no text, pardes_pdf_load_outline of no entries: each OK with a NULL and a count of 0), and Zig slices a NULL C pointer with a safety panic even at length 0; every site in pdf.zig (jobRun's page text and hits, pageText, hitsOf, selectHere, probeAt, follow, the outline's usable, resolve, sections and section, its bytes now bounded by bytes_len), abi/addon.zig's own (its private `span` was that helper for bytes alone; open's bytes), and the core's kind-ABI callbacks (Kind.zig look, say, text, exec, select, found; Addon.zig loadedOf's words), the core taking the addons' module (`addon`) for it; what holds the next site: pdf.zig's test (run by addon-test, which now runs the pdf module's tests) takes every typed pointer field of the bridge's structs from the translated header at comptime and fails on any `.field[` in pdf.zig, naming the line (shown by putting one site back: "pdf.zig:1014: pardes_pdf_text.data read bare"); the test of the change before passes, with every PDF behaviour test (8/8, Debug) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/Addon.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/Addon.zig') diff --git a/core/Addon.zig b/core/Addon.zig index aa3195f9..e93a43dc 100644 --- a/core/Addon.zig +++ b/core/Addon.zig @@ -532,7 +532,7 @@ pub const LoadedWord = struct { name: []const u8, leader: []const u8 = "", arg: /// `ops`'s head as a `Loaded` (its words borrowed from it, in `words`). pub fn loadedOf(ops: *const Kind.Ops, path: []const u8, hash: [32]u8, words: *[64]LoadedWord) Loaded { const h = &ops.head; - const head_words = if (h.nwords == 0 or h.words == null) &.{} else h.words[0..@min(h.nwords, words.len)]; + const head_words = @import("addon").cSlice(h.words, @min(h.nwords, words.len)); for (head_words, words[0..head_words.len]) |*w, *out| out.* = .{ .name = if (w.name == null) "" else std.mem.span(w.name), .leader = if (w.leader == null) "" else std.mem.span(w.leader), -- cgit v1.3