diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 05:18:01 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 05:55:49 -0300 |
| commit | de0447471febe1253b42a32fe9a1d6cdccc9d5b9 (patch) | |
| tree | cacff70a9b976f621832e7b9d41bf24ee3e5c5ed /src | |
| parent | 3f4df1363d3051bf8c4665fdf4898d59ab365b27 (diff) | |
| download | pardes-de0447471febe1253b42a32fe9a1d6cdccc9d5b9.tar.gz pardes-de0447471febe1253b42a32fe9a1d6cdccc9d5b9.zip | |
kinds #8, image.so: addons/image/image.c (144 lines) is the image kind against ABI 2 over stb_image as zstbi vendors it (every format it decoded, HDR out, at most 1280 pixels a side, 64 Mpixels refused before decoding), its record the file's bytes, its decode a job, one placement fitted, its prefix img; stb's memory is the pane's arena at open and the job's on a worker, so pa_out's alloc may be called as often as a job needs (an arena a job, freed after its job_done, the last allocation the answer: what the header found wanting); the build makes it with -Wall -Wextra -Werror and installs it to <prefix>/lib/pardes/addons/image.so (a bare build to ~/.local/lib/pardes/addons too); the compiled-in image kind is still there, so the start scan lists the library refused as a second image
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
| -rw-r--r-- | src/host_io.zig | 11 | ||||
| -rw-r--r-- | src/kinds/pardes_addon.h | 4 |
2 files changed, 9 insertions, 6 deletions
diff --git a/src/host_io.zig b/src/host_io.zig index 19cc920f..2320077e 100644 --- a/src/host_io.zig +++ b/src/host_io.zig @@ -84,6 +84,8 @@ pub const KindJob = struct { gen: u32, ops: *const pardes.Kind.Ops, in: []u8, + /// What the job allocates (`pa_out`), freed with it; `out` the last. + arena: std.heap.ArenaAllocator, out: []u8 = &.{}, id: u32 = 0, @@ -96,7 +98,7 @@ pub const KindJob = struct { if (j.*) |job| if (job.token == token) break j; } else return null; const j = slot.gpa.create(KindJob) catch return null; - j.* = .{ .gpa = slot.gpa, .pane = pane, .serial = serial, .token = token, .gen = slot.gen, .ops = ops, .in = at.*.?.in }; + j.* = .{ .gpa = slot.gpa, .pane = pane, .serial = serial, .token = token, .gen = slot.gen, .ops = ops, .in = at.*.?.in, .arena = .init(slot.gpa) }; at.* = null; pardes.Addon.holdJob(ops, true); return j; @@ -106,9 +108,8 @@ pub const KindJob = struct { const Out = struct { fn alloc(out: [*c]pardes.Kind.c.pa_out, n: usize) callconv(.c) ?*anyopaque { const job: *KindJob = @ptrCast(@alignCast(out.*.ctx)); - if (job.out.len > 0) return null; - job.out = job.gpa.alloc(u8, n) catch return null; - return job.out.ptr; + job.out = job.arena.allocator().alignedAlloc(u8, .@"16", n) catch &.{}; + return if (job.out.len == n) job.out.ptr else null; } }; var out: pardes.Kind.c.pa_out = .{ .alloc = Out.alloc, .ctx = j }; @@ -125,7 +126,7 @@ pub const KindJob = struct { pub fn drop(j: *KindJob) void { pardes.Addon.holdJob(j.ops, false); j.gpa.free(j.in); - j.gpa.free(j.out); + j.arena.deinit(); j.gpa.destroy(j); } diff --git a/src/kinds/pardes_addon.h b/src/kinds/pardes_addon.h index c6aa448b..6241c6c0 100644 --- a/src/kinds/pardes_addon.h +++ b/src/kinds/pardes_addon.h @@ -167,7 +167,9 @@ typedef struct pa_api { uint64_t (*seed)(void); } pa_api; -/* A job's answer buffer: `alloc` it once, write it, return its length. */ +/* What a job allocates from, on its worker (pa_api is not there): as often + * as it needs, all of it freed after its job_done. The last it allocates + * is the answer, which the job writes and returns the length of. */ typedef struct pa_out { void *(*alloc)(struct pa_out *out, size_t n); void *ctx; |
