Skip to content

Commit 3d61cc7

Browse files
committed
all: fix for latest zig
1 parent ef5a327 commit 3d61cc7

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

helpers.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn setResult(ctx: ?*c.sqlite3_context, result: anytype) void {
3030
else => @compileError("cannot use a result of type " ++ @typeName(ResultType)),
3131
},
3232
.pointer => |ptr| switch (ptr.size) {
33-
.Slice => switch (ptr.child) {
33+
.slice => switch (ptr.child) {
3434
u8 => c.sqlite3_result_text(ctx, result.ptr, @intCast(result.len), c.sqliteTransientAsDestructor()),
3535
else => @compileError("cannot use a result of type " ++ @typeName(ResultType)),
3636
},
@@ -67,7 +67,7 @@ pub fn setTypeFromValue(comptime ArgType: type, arg: *ArgType, sqlite_value: *c.
6767
arg.* = value > 0;
6868
},
6969
.pointer => |ptr| switch (ptr.size) {
70-
.Slice => switch (ptr.child) {
70+
.slice => switch (ptr.child) {
7171
u8 => arg.* = sliceFromValue(sqlite_value),
7272
else => @compileError("cannot use an argument of type " ++ @typeName(ArgType)),
7373
},

sqlite.zig

+11-15
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ fn isZigString(comptime T: type) bool {
5050
if (ptr.is_volatile or ptr.is_allowzero) break :blk false;
5151

5252
// If it's already a slice, simple check.
53-
if (ptr.size == .Slice) {
53+
if (ptr.size == .slice) {
5454
break :blk ptr.child == u8;
5555
}
5656

5757
// Otherwise check if it's an array type that coerces to slice.
58-
if (ptr.size == .One) {
58+
if (ptr.size == .one) {
5959
const child = @typeInfo(ptr.child);
6060
if (child == .array) {
6161
const arr = &child.array;
@@ -880,7 +880,7 @@ pub const FunctionContext = struct {
880880
fn splitPtrTypes(comptime Type: type) SplitPtrTypes {
881881
switch (@typeInfo(Type)) {
882882
.pointer => |ptr_info| switch (ptr_info.size) {
883-
.One => return SplitPtrTypes{
883+
.one => return SplitPtrTypes{
884884
.ValueType = ptr_info.child,
885885
.PointerType = Type,
886886
},
@@ -1211,14 +1211,13 @@ pub fn Iterator(comptime Type: type) type {
12111211
u8 => {
12121212
const size: usize = @intCast(c.sqlite3_column_bytes(self.stmt, i));
12131213

1214-
if (arr.sentinel) |sentinel_ptr| {
1214+
if (arr.sentinel()) |sentinel| {
12151215
// An array with a sentinel need to be as big as the data, + 1 byte for the sentinel.
12161216
if (size >= @as(usize, arr.len)) {
12171217
return error.ArrayTooSmall;
12181218
}
12191219

12201220
// Set the sentinel in the result at the correct position.
1221-
const sentinel = @as(*const arr.child, @ptrCast(sentinel_ptr)).*;
12221221
ret[size] = sentinel;
12231222
} else if (size != arr.len) {
12241223
// An array without a sentinel must have the exact same size as the data because we can't
@@ -1268,9 +1267,7 @@ pub fn Iterator(comptime Type: type) type {
12681267
fn dupeWithSentinel(comptime SliceType: type, allocator: mem.Allocator, data: []const u8) !SliceType {
12691268
switch (@typeInfo(SliceType)) {
12701269
.pointer => |ptr_info| {
1271-
if (ptr_info.sentinel) |sentinel_ptr| {
1272-
const sentinel = @as(*const ptr_info.child, @ptrCast(sentinel_ptr)).*;
1273-
1270+
if (ptr_info.sentinel()) |sentinel| {
12741271
const slice = try allocator.alloc(u8, data.len + 1);
12751272
mem.copyForwards(u8, slice, data);
12761273
slice[data.len] = sentinel;
@@ -1347,13 +1344,13 @@ pub fn Iterator(comptime Type: type) type {
13471344
switch (@typeInfo(PointerType)) {
13481345
.pointer => |ptr| {
13491346
switch (ptr.size) {
1350-
.One => {
1347+
.one => {
13511348
ret = try options.allocator.create(ptr.child);
13521349
errdefer options.allocator.destroy(ret);
13531350

13541351
ret.* = try self.readField(ptr.child, options, i);
13551352
},
1356-
.Slice => switch (ptr.child) {
1353+
.slice => switch (ptr.child) {
13571354
u8 => ret = try self.readBytes(PointerType, options.allocator, i, .Text),
13581355
else => @compileError("cannot read pointer of type " ++ @typeName(PointerType)),
13591356
},
@@ -1647,10 +1644,10 @@ pub const DynamicStatement = struct {
16471644
return convertResultToError(result);
16481645
},
16491646
.pointer => |ptr| switch (ptr.size) {
1650-
.One => {
1647+
.one => {
16511648
try self.bindField(ptr.child, options, field_name, i, field.*);
16521649
},
1653-
.Slice => switch (ptr.child) {
1650+
.slice => switch (ptr.child) {
16541651
u8 => {
16551652
// NOTE(vincent): The slice must live until after the prepared statement is finaliuzed, therefore we use SQLITE_STATIC to avoid a copy
16561653
const result = c.sqlite3_bind_text(self.stmt, column, field.ptr, @intCast(field.len), c.SQLITE_STATIC);
@@ -1779,7 +1776,7 @@ pub const DynamicStatement = struct {
17791776
},
17801777
.pointer => |PointerTypeInfo| {
17811778
switch (PointerTypeInfo.size) {
1782-
.Slice => {
1779+
.slice => {
17831780
for (values, 0..) |value_to_bind, index| {
17841781
try self.bindField(PointerTypeInfo.child, options, "unknown", @intCast(index), value_to_bind);
17851782
}
@@ -2679,8 +2676,7 @@ test "sqlite: read a single text value" {
26792676
.pointer => {
26802677
try testing.expectEqualStrings("Vincent", name.?);
26812678
},
2682-
.array => |arr| if (arr.sentinel) |sentinel_ptr| {
2683-
const sentinel = @as(*const arr.child, @ptrCast(sentinel_ptr)).*;
2679+
.array => |arr| if (arr.sentinel()) |sentinel| {
26842680
const res = mem.sliceTo(&name.?, sentinel);
26852681
try testing.expectEqualStrings("Vincent", res);
26862682
} else {

0 commit comments

Comments
 (0)