diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-23 09:15:57 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-23 09:25:44 -0300 |
| commit | c8f0d65a69274dc8a072c35a6c13cb07a6770007 (patch) | |
| tree | b3e13754d99250ee596be3368d07539eb4437bfb /core | |
| parent | 0733d0a0d89bacb64f45d71b06ffbcf1abe6ffb3 (diff) | |
| download | pardes-c8f0d65a69274dc8a072c35a6c13cb07a6770007.tar.gz pardes-c8f0d65a69274dc8a072c35a6c13cb07a6770007.zip | |
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core')
| -rw-r--r-- | core/Addon.zig | 2 | ||||
| -rw-r--r-- | core/Kind.zig | 17 |
2 files changed, 10 insertions, 9 deletions
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), diff --git a/core/Kind.zig b/core/Kind.zig index 49076f78..5d2dcdb0 100644 --- a/core/Kind.zig +++ b/core/Kind.zig @@ -17,6 +17,7 @@ const std = @import("std"); const builtin = @import("builtin"); pub const c = @import("pardes_addon"); +const cSlice = @import("addon").cSlice; const pardes = @import("root.zig"); const walk = @import("walk.zig"); const surface = @import("surface.zig"); @@ -1130,7 +1131,7 @@ pub const api: c.pa_api = .{ .look = struct { fn f(text: [*c]const u8, n: u32) callconv(.c) void { const cl = current orelse return; - if (!cl.quiet and text != null) cl.look.set(text[0..n]); + if (!cl.quiet and text != null) cl.look.set(cSlice(text, n)); } }.f, .say = struct { @@ -1138,8 +1139,8 @@ pub const api: c.pa_api = .{ const cl = current orelse return; if (cl.quiet or text == null) return; // Refusing its open: the opener says why. - if (err != 0 and cl.opening) return cl.refused.set(text[0..n]); - cl.said.set(text[0..n]); + if (err != 0 and cl.opening) return cl.refused.set(cSlice(text, n)); + cl.said.set(cSlice(text, n)); cl.err = err != 0; } }.f, @@ -1149,8 +1150,8 @@ pub const api: c.pa_api = .{ const cl = current orelse return 0; const p = cl.p orelse return 0; if (cl.quiet or name == null or cl.pane_name.len > 0) return 0; - cl.pane_name.set(name[0..name_len]); - cl.pane_text = p.scratch.allocator().dupe(u8, if (bytes == null) "" else bytes[0..n]) catch ""; + cl.pane_name.set(cSlice(name, name_len)); + cl.pane_text = p.scratch.allocator().dupe(u8, cSlice(bytes, n)) catch ""; return p.next_serial + 1; } }.f, @@ -1181,7 +1182,7 @@ pub const api: c.pa_api = .{ .exec = struct { fn f(text: [*c]const u8, n: u32) callconv(.c) void { const cl = current orelse return; - if (!cl.quiet and text != null) cl.exec.set(text[0..n]); + if (!cl.quiet and text != null) cl.exec.set(cSlice(text, n)); } }.f, .select = struct { @@ -1189,7 +1190,7 @@ pub const api: c.pa_api = .{ const cl = current orelse return; if (cl.quiet) return; const p = cl.p orelse return; - cl.selected = p.scratch.allocator().dupe(u8, if (text == null) "" else text[0..n]) catch return; + cl.selected = p.scratch.allocator().dupe(u8, cSlice(text, n)) catch return; } }.f, .cancel = struct { @@ -1234,7 +1235,7 @@ pub const api: c.pa_api = .{ const cl = current orelse return; const p = cl.p orelse return; if (cl.quiet or rows == null) return; - cl.rows = std.mem.concat(p.scratch.allocator(), u8, &.{ cl.rows, rows[0..n] }) catch return; + cl.rows = std.mem.concat(p.scratch.allocator(), u8, &.{ cl.rows, cSlice(rows, n) }) catch return; } }.f, }; |
