summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 09:00:02 -0300
committerGabriel Schneider <[email protected]>2026-11-23 09:15:57 -0300
commit0733d0a0d89bacb64f45d71b06ffbcf1abe6ffb3 (patch)
tree3ba66f09cae28d443502bfb66ae13c45e966c8bb
parent4faf94b72b60ecb0656e7e90ca693b63b1fde71c (diff)
downloadpardes-0733d0a0d89bacb64f45d71b06ffbcf1abe6ffb3.tar.gz
pardes-0733d0a0d89bacb64f45d71b06ffbcf1abe6ffb3.zip
pdf, build: the test of a PDF searched for what its page has not and asked the sections it has not, and the C-backed addons' own Zig built with the checks a release keeps: on the installed ReleaseSafe build (4faf94b72b60) a session with docs/design.pdf open aborts at the keys `/zzqxv<Enter>` (a search for a pattern page 1 does not have: the page's job asks the bridge for its hits, pardes_pdf_search_page answers OK with quads NULL and a count of 0, and pdf.zig:762 slices the NULL: "attempt to use null value" on a worker, the whole session gone), and at `f` on test/pdf-fixtures/tall.pdf (no outline: items NULL, count 0, sliced in sections()); no Debug run ever saw either because a Debug build compiled pdf.zig and image.zig at c_optimize, ReleaseFast, without the checks; now core.zig's `addon_optimize` (ReleaseSafe in Debug, c_optimize otherwise) builds the two addons' modules (their Zig and their bridge's C) as the user's build does, MuPDF, FreeType, zlib and stb staying at c_optimize; the test (test/behaviour/addons_pdf.zig, through 9P: `/zzqxv` on design.pdf, its `:1:1` a miss, `f` on tall.pdf said to have no outline) fails in Debug with the abort at pdf.zig:762 (logs/t1-dbg-filter.log: 1/2, 1 crashed)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
-rw-r--r--build/addons.zig9
-rw-r--r--build/core.zig9
-rw-r--r--test/behaviour/addons_pdf.zig16
3 files changed, 30 insertions, 4 deletions
diff --git a/build/addons.zig b/build/addons.zig
index 38b02dff..a1bdb43b 100644
--- a/build/addons.zig
+++ b/build/addons.zig
@@ -52,6 +52,9 @@ pub const Pdf = struct {
/// `pardes_addon` alone.
pub fn pdf(b: *std.Build, c: struct {
addon_mod: *std.Build.Module,
+ /// pdf.zig's and the bridge's (core.zig's `addon_optimize`); MuPDF's
+ /// and the rest of the C's `c_optimize`.
+ addon_optimize: std.lang.Optimize,
c_optimize: std.lang.Optimize,
enable_jpx: bool,
freetype: ?*std.Build.Step.Compile,
@@ -83,7 +86,7 @@ pub fn pdf(b: *std.Build, c: struct {
// The bridge's header translated here for pdf.zig (Zig 0.17 has no
// @cImport), as the kinds' header is for the core.
const bridge_mod = b.addTranslateC(.{ .root_source_file = b.path("addons/pdf/pdf_bridge.h"), .target = c.target, .optimize = c.c_optimize }).createModule();
- const pdf_mod = b.createModule(.{ .root_source_file = b.path("addons/pdf/pdf.zig"), .target = c.target, .optimize = c.c_optimize, .link_libc = true, .imports = &.{ .{ .name = "addon", .module = c.addon_mod }, .{ .name = "pdf_bridge", .module = bridge_mod } } });
+ const pdf_mod = b.createModule(.{ .root_source_file = b.path("addons/pdf/pdf.zig"), .target = c.target, .optimize = c.addon_optimize, .link_libc = true, .imports = &.{ .{ .name = "addon", .module = c.addon_mod }, .{ .name = "pdf_bridge", .module = bridge_mod } } });
mupdf.linkTo(pdf_mod);
pdf_mod.addIncludePath(b.path("addons/pdf"));
pdf_mod.addCSourceFile(.{ .file = b.path("addons/pdf/pdf_bridge.c"), .flags = &.{"-std=gnu11"} });
@@ -105,8 +108,8 @@ pub fn pdf(b: *std.Build, c: struct {
/// The image addon (addons/image/image.zig over stb_image, stb.c),
/// installed by its step and handed by path to every test that opens a
/// picture.
-pub fn image(b: *std.Build, target: std.Build.ResolvedTarget, c_optimize: std.lang.Optimize, addon_mod: *std.Build.Module, zstbi_dep: *std.Build.Dependency) *std.Build.Step.Compile {
- const image_mod = b.createModule(.{ .root_source_file = b.path("addons/image/image.zig"), .target = target, .optimize = c_optimize, .link_libc = true, .imports = &.{.{ .name = "addon", .module = addon_mod }} });
+pub fn image(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.lang.Optimize, addon_mod: *std.Build.Module, zstbi_dep: *std.Build.Dependency) *std.Build.Step.Compile {
+ const image_mod = b.createModule(.{ .root_source_file = b.path("addons/image/image.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{.{ .name = "addon", .module = addon_mod }} });
image_mod.addIncludePath(zstbi_dep.path("libs/stbi"));
image_mod.addCSourceFile(.{ .file = b.path("addons/image/stb.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
const image_addon = b.addLibrary(.{ .name = "image", .linkage = .dynamic, .root_module = image_mod });
diff --git a/build/core.zig b/build/core.zig
index e8150843..32228ab2 100644
--- a/build/core.zig
+++ b/build/core.zig
@@ -514,8 +514,15 @@ pub fn assemble(b: *std.Build, c: struct {
const kind_mod = b.addTranslateC(.{ .root_source_file = b.path("abi/pardes_addon.h"), .target = target, .optimize = optimize }).createModule();
// ...and what an addon in Zig imports over it (abi/addon.zig).
const addon_mod = b.createModule(.{ .root_source_file = b.path("abi/addon.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "pardes_addon", .module = kind_mod }} });
+ // The C-backed addons' own Zig and bridge at the C's speed, with the
+ // checks a release keeps: ReleaseSafe in a Debug build, as in the
+ // user's (a page's search without a hit sliced a NULL: only a release
+ // build aborted, Debug's addons ran ReleaseFast); MuPDF and stb stay
+ // at c_optimize.
+ const addon_optimize: std.lang.Optimize = if (optimize == .debug) .safe else c_optimize;
const pdf_built = addons.pdf(b, .{
.addon_mod = addon_mod,
+ .addon_optimize = addon_optimize,
.c_optimize = c_optimize,
.enable_jpx = c.enable_jpx,
.freetype = freetype,
@@ -602,7 +609,7 @@ pub fn assemble(b: *std.Build, c: struct {
// library and no allocator hook of its own (it takes Zig allocators).
const xitdb_mod = b.dependency("xitdb", .{ .target = target, .optimize = optimize }).module("xitdb");
- const image_addon = addons.image(b, target, c_optimize, addon_mod, zstbi_dep);
+ const image_addon = addons.image(b, target, addon_optimize, addon_mod, zstbi_dep);
// The records the core and the terminal both name (abi/plain.zig).
const plain_mod = b.createModule(.{ .root_source_file = b.path("abi/plain.zig"), .target = target, .optimize = optimize });
// The terminal, a module of its own (core/term/term.zig): the emulator and
diff --git a/test/behaviour/addons_pdf.zig b/test/behaviour/addons_pdf.zig
index cf5c8009..18fa503c 100644
--- a/test/behaviour/addons_pdf.zig
+++ b/test/behaviour/addons_pdf.zig
@@ -132,6 +132,22 @@ test "addons: a PDF's / lists its hits as file.pdf:P:H rows in a +Search, n walk
try std.testing.expect(try s.focused() != n);
}
+test "addons: a PDF's / of what its page has not, and f on a PDF with no outline, each say so and the session goes on (the bridge's none is a NULL with a count of 0: a safe build's abort before)" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const n = try s.lookFile("docs/design.pdf");
+ // No page has it: page 1's hits of it asked, none; a hit of it a miss.
+ try s.keys("/zzqxv\r");
+ try std.testing.expectEqual(@as(u32, 1), (try s.pdfPage(n))[0]);
+ _ = try s.refused(s.at("/pane/{d}/look", .{n}), ":1:1\n");
+ try std.testing.expect(has(try s.read("/log"), "design.pdf has no search hit 1 on page 1"));
+ // tall.pdf has no outline.
+ const t = try s.lookFile("test/pdf-fixtures/tall.pdf");
+ try s.keys("f");
+ try std.testing.expect(has(try s.read("/log"), "PdfSections: this PDF has no outline"));
+ try std.testing.expectEqual(t, try s.focused());
+}
+
test "addons: a PDF's f is its PdfSections, its outline as places a Look in it goes to (none once the PDF is gone), and a jump back over a far one is Ctrl-o's, Forward's on, two places on a page a window apart two" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();