summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/host_io.zig11
-rw-r--r--src/kinds/pardes_addon.h4
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;