about summary refs log tree commit diff
path: root/src/root.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/root.zig')
-rw-r--r--src/root.zig28
1 files changed, 8 insertions, 20 deletions
diff --git a/src/root.zig b/src/root.zig
index fc4472f..0e26e33 100644
--- a/src/root.zig
+++ b/src/root.zig
@@ -190,14 +190,9 @@ pub fn wrap(x: anytype) !Value {
             .many, .c => janet.wrapPointer(@constCast(@ptrCast(x))),
             .slice => y: {
                 const len: i32 = @intCast(x.len * @sizeOf(info.child));
-                if (info.is_const) {
-                    const string = janet.string(@ptrCast(x.ptr), len);
-                    break :y janet.wrapString(string);
-                } else {
-                    const memory: *anyopaque = @ptrCast(x.ptr);
-                    const buffer = janet.pointerBufferUnsafe(memory, len, len);
-                    break :y janet.wrapBuffer(buffer);
-                }
+                const memory: *anyopaque = @constCast(@ptrCast(x.ptr));
+                const buffer = janet.pointerBufferUnsafe(memory, len, len);
+                break :y janet.wrapBuffer(buffer);
             },
         },
         .@"struct" => |info| janet.wrapStruct(y: {
@@ -271,21 +266,14 @@ pub fn unwrap(T: type, x: Value) !T {
                 break :y @alignCast(@ptrCast(janet.unwrapPointer(ptr)));
             } else @alignCast(@ptrCast(janet.unwrapPointer(x))),
             .many, .c => @alignCast(@ptrCast(janet.unwrapPointer(x))),
-            .slice => slice: {
-                const ptr = if (info.is_const)
-                    janet.unwrapString(x)
-                else
-                    janet.unwrapBuffer(x).*.data;
+            .slice => y: {
                 comptime var many_info = info;
                 many_info.size = .many;
                 const Many = @Type(.{ .pointer = many_info });
-                const many: Many = @alignCast(@ptrCast(ptr));
-                const size = if (info.is_const)
-                    janet.stringLength(ptr)
-                else
-                    janet.unwrapBuffer(x).*.count;
-                const len = @divExact(size, @sizeOf(info.child));
-                break :slice if (info.sentinel()) |sentinel|
+                const buffer = janet.unwrapBuffer(x);
+                const many: Many = @alignCast(@ptrCast(buffer.*.data));
+                const len = @divExact(buffer.*.count, @sizeOf(info.child));
+                break :y if (info.sentinel()) |sentinel|
                     many[0..@intCast(len):sentinel]
                 else
                     many[0..@intCast(len)];