summaryrefslogtreecommitdiff
path: root/abi
diff options
context:
space:
mode:
Diffstat (limited to 'abi')
-rw-r--r--abi/addon.zig24
-rw-r--r--abi/wire.zig12
2 files changed, 23 insertions, 13 deletions
diff --git a/abi/addon.zig b/abi/addon.zig
index 1fa2279a..059e016d 100644
--- a/abi/addon.zig
+++ b/abi/addon.zig
@@ -248,8 +248,14 @@ pub fn loadBytes(s: anytype, bytes: []const u8, version: u32) bool {
pub const body_max = 4096;
var body_cut = false;
-fn span(p: [*c]const u8, n: u64) []const u8 {
- return if (p == null) "" else p[0..n];
+/// A C pointer and its count as a slice; NULL is none, whatever the count:
+/// C says none with a NULL (a page's search without a hit, a selection
+/// over no text, an outline of no entries), and a NULL C pointer sliced
+/// is a safety panic even at length 0 (a release build's abort). Every
+/// pointer a C struct or a C caller hands with its count is read through
+/// it: pdf.zig's test holds the bridge's to it.
+pub fn cSlice(ptr: anytype, n: usize) []const std.meta.Child(@TypeOf(ptr)) {
+ return if (ptr == null) &.{} else ptr[0..n];
}
/// `pardes_addon` exported, when built as a library alone: the kind is its
@@ -282,7 +288,7 @@ pub fn ops(comptime T: type) c.pa_ops {
fn open(path: [*c]const u8, bytes: [*c]const u8, len: u64) callconv(.c) ?*anyopaque {
const s = arena.create(T) catch return null;
s.* = std.mem.zeroInit(T, .{});
- if (@hasDecl(T, "open")) T.open(s, if (path == null) null else std.mem.span(path), if (bytes == null) null else bytes[0..len]);
+ if (@hasDecl(T, "open")) T.open(s, if (path == null) null else std.mem.span(path), if (bytes == null) null else cSlice(bytes, len));
return s;
}
fn close(st: ?*anyopaque) callconv(.c) void {
@@ -329,7 +335,7 @@ pub fn ops(comptime T: type) c.pa_ops {
return @intCast(from.len);
}
fn address(st: ?*anyopaque, t: [*c]const u8, n: u32) callconv(.c) c_int {
- return @intFromBool(T.address(self(st) orelse return 0, span(t, n)));
+ return @intFromBool(T.address(self(st) orelse return 0, cSlice(t, n)));
}
fn where(st: ?*anyopaque, buf: [*c]u8, n: u32) callconv(.c) u32 {
return write(T.where, self(st) orelse return 0, buf, n);
@@ -337,26 +343,26 @@ pub fn ops(comptime T: type) c.pa_ops {
fn ctl(st: ?*anyopaque, line: [*c]const u8, n: u32, reply: [*c]u8, cap: u32) callconv(.c) c_int {
var w: std.Io.Writer = .fixed(reply[0..cap -| 1]);
defer reply[w.end] = 0;
- return if (T.ctl(self(st) orelse return 1, span(line, n), &w)) c.PA_OK else 1;
+ return if (T.ctl(self(st) orelse return 1, cSlice(line, n), &w)) c.PA_OK else 1;
}
fn ctl_read(st: ?*anyopaque, buf: [*c]u8, n: u32) callconv(.c) u32 {
return write(T.ctlRead, self(st) orelse return 0, buf, n);
}
fn job_run(in: [*c]const u8, n: u32, out: [*c]c.pa_out) callconv(.c) u32 {
const gpa: Allocator = .{ .ptr = out, .vtable = &.{ .alloc = jobAlloc, .resize = Allocator.noResize, .remap = Allocator.noRemap, .free = Allocator.noFree } };
- return @intCast((T.jobRun(span(in, n), gpa) orelse return 0).len);
+ return @intCast((T.jobRun(cSlice(in, n), gpa) orelse return 0).len);
}
fn job_done(st: ?*anyopaque, token: u32, out: [*c]const u8, n: u32) callconv(.c) void {
- T.jobDone(self(st) orelse return, token, span(out, n));
+ T.jobDone(self(st) orelse return, token, cSlice(out, n));
}
fn dump(st: ?*anyopaque, buf: [*c]u8, n: u32) callconv(.c) u32 {
return @intCast(T.dump(self(st) orelse return 0, buf[0..n]));
}
fn load(st: ?*anyopaque, buf: [*c]const u8, n: u32, version: u32) callconv(.c) c_int {
- return @intFromBool(!T.load(self(st) orelse return 1, span(buf, n), version));
+ return @intFromBool(!T.load(self(st) orelse return 1, cSlice(buf, n), version));
}
fn search(st: ?*anyopaque, pat: [*c]const u8, n: u32) callconv(.c) void {
- T.search(self(st) orelse return, span(pat, n));
+ T.search(self(st) orelse return, cSlice(pat, n));
}
};
if (T.head.name.len > 15) @compileError(@typeName(T) ++ "'s name " ++ T.head.name ++ " is over 15 bytes");
diff --git a/abi/wire.zig b/abi/wire.zig
index 8949edff..7b6a22f1 100644
--- a/abi/wire.zig
+++ b/abi/wire.zig
@@ -12,9 +12,12 @@ const build_info = @import("build_info");
/// 31: where a view stands in a terminal's history is the view's: a pane's
/// `scrolled_to` (and its share's in each view) in the dump and the digest,
-/// the emulator's own view out of both (its `Parts.view` gone); and the
+/// the emulator's own view out of both (its `Parts.view` gone); the
/// core's count of its emulators' writes (`outside`) in both, which the
-/// replica engine's one question of a unit reads;
+/// replica engine's one question of a unit reads; and a client whose link
+/// is up joins again over it (its bye's `again`, then its hello there:
+/// core/replica.zig `Peers.joinAgain`), as one whose load was refused asks
+/// once more;
/// 30: the terminals' one road: the screen-state messages are retired (a
/// replica's `screen_ack`, 0x04, and the session's `screen`, 0x06: gaps),
/// a welcome says no road (its `bytes` byte gone), and a pane's
@@ -324,8 +327,9 @@ pub fn helloVersion(payload: []const u8) Error!u16 {
/// one call and no longer.
pub const ClientMsg = union(enum) {
hello: Hello,
- /// The client's end: `again`, it joins again for its view at once;
- /// `close`, its window was closed (a pair's session ends at its last).
+ /// The client's end: `again`, it joins again for its view at once (its
+ /// hello next, on this link while it is up); `close`, its window was
+ /// closed (a pair's session ends at its last).
bye: struct { again: bool = false, close: bool = false },
/// A round trip's probe, answered `pong` with the same value.
ping: u64,