summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Addon.zig2
-rw-r--r--core/Kind.zig17
2 files changed, 10 insertions, 9 deletions
diff --git a/core/Addon.zig b/core/Addon.zig
index aa3195f9..e93a43dc 100644
--- a/core/Addon.zig
+++ b/core/Addon.zig
@@ -532,7 +532,7 @@ pub const LoadedWord = struct { name: []const u8, leader: []const u8 = "", arg:
/// `ops`'s head as a `Loaded` (its words borrowed from it, in `words`).
pub fn loadedOf(ops: *const Kind.Ops, path: []const u8, hash: [32]u8, words: *[64]LoadedWord) Loaded {
const h = &ops.head;
- const head_words = if (h.nwords == 0 or h.words == null) &.{} else h.words[0..@min(h.nwords, words.len)];
+ const head_words = @import("addon").cSlice(h.words, @min(h.nwords, words.len));
for (head_words, words[0..head_words.len]) |*w, *out| out.* = .{
.name = if (w.name == null) "" else std.mem.span(w.name),
.leader = if (w.leader == null) "" else std.mem.span(w.leader),
diff --git a/core/Kind.zig b/core/Kind.zig
index 49076f78..5d2dcdb0 100644
--- a/core/Kind.zig
+++ b/core/Kind.zig
@@ -17,6 +17,7 @@
const std = @import("std");
const builtin = @import("builtin");
pub const c = @import("pardes_addon");
+const cSlice = @import("addon").cSlice;
const pardes = @import("root.zig");
const walk = @import("walk.zig");
const surface = @import("surface.zig");
@@ -1130,7 +1131,7 @@ pub const api: c.pa_api = .{
.look = struct {
fn f(text: [*c]const u8, n: u32) callconv(.c) void {
const cl = current orelse return;
- if (!cl.quiet and text != null) cl.look.set(text[0..n]);
+ if (!cl.quiet and text != null) cl.look.set(cSlice(text, n));
}
}.f,
.say = struct {
@@ -1138,8 +1139,8 @@ pub const api: c.pa_api = .{
const cl = current orelse return;
if (cl.quiet or text == null) return;
// Refusing its open: the opener says why.
- if (err != 0 and cl.opening) return cl.refused.set(text[0..n]);
- cl.said.set(text[0..n]);
+ if (err != 0 and cl.opening) return cl.refused.set(cSlice(text, n));
+ cl.said.set(cSlice(text, n));
cl.err = err != 0;
}
}.f,
@@ -1149,8 +1150,8 @@ pub const api: c.pa_api = .{
const cl = current orelse return 0;
const p = cl.p orelse return 0;
if (cl.quiet or name == null or cl.pane_name.len > 0) return 0;
- cl.pane_name.set(name[0..name_len]);
- cl.pane_text = p.scratch.allocator().dupe(u8, if (bytes == null) "" else bytes[0..n]) catch "";
+ cl.pane_name.set(cSlice(name, name_len));
+ cl.pane_text = p.scratch.allocator().dupe(u8, cSlice(bytes, n)) catch "";
return p.next_serial + 1;
}
}.f,
@@ -1181,7 +1182,7 @@ pub const api: c.pa_api = .{
.exec = struct {
fn f(text: [*c]const u8, n: u32) callconv(.c) void {
const cl = current orelse return;
- if (!cl.quiet and text != null) cl.exec.set(text[0..n]);
+ if (!cl.quiet and text != null) cl.exec.set(cSlice(text, n));
}
}.f,
.select = struct {
@@ -1189,7 +1190,7 @@ pub const api: c.pa_api = .{
const cl = current orelse return;
if (cl.quiet) return;
const p = cl.p orelse return;
- cl.selected = p.scratch.allocator().dupe(u8, if (text == null) "" else text[0..n]) catch return;
+ cl.selected = p.scratch.allocator().dupe(u8, cSlice(text, n)) catch return;
}
}.f,
.cancel = struct {
@@ -1234,7 +1235,7 @@ pub const api: c.pa_api = .{
const cl = current orelse return;
const p = cl.p orelse return;
if (cl.quiet or rows == null) return;
- cl.rows = std.mem.concat(p.scratch.allocator(), u8, &.{ cl.rows, rows[0..n] }) catch return;
+ cl.rows = std.mem.concat(p.scratch.allocator(), u8, &.{ cl.rows, cSlice(rows, n) }) catch return;
}
}.f,
};