summaryrefslogtreecommitdiff
path: root/src/host_io.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 05:18:01 -0300
committerGabriel Schneider <[email protected]>2026-11-06 05:55:49 -0300
commitde0447471febe1253b42a32fe9a1d6cdccc9d5b9 (patch)
treecacff70a9b976f621832e7b9d41bf24ee3e5c5ed /src/host_io.zig
parent3f4df1363d3051bf8c4665fdf4898d59ab365b27 (diff)
downloadpardes-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/host_io.zig')
-rw-r--r--src/host_io.zig11
1 files changed, 6 insertions, 5 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);
}