From ce7a6a7b657e4c8f9514d4181230068bd45823e2 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sun, 2 Jul 2023 15:28:30 +0200 Subject: update for latest zig --- errors.zig | 4 +-- helpers.zig | 14 ++++----- sqlite.zig | 95 +++++++++++++++++++++++++++++-------------------------------- vtab.zig | 36 +++++++++++------------ 4 files changed, 72 insertions(+), 77 deletions(-) diff --git a/errors.zig b/errors.zig index add4b37..59293c4 100644 --- a/errors.zig +++ b/errors.zig @@ -286,7 +286,7 @@ pub const DetailedError = struct { pub fn getDetailedErrorFromResultCode(code: c_int) DetailedError { return .{ - .code = @intCast(usize, code), + .code = @intCast(code), .near = -1, .message = blk: { const msg = c.sqlite3_errstr(code); @@ -304,7 +304,7 @@ pub fn getErrorOffset(db: *c.sqlite3) i32 { pub fn getLastDetailedErrorFromDb(db: *c.sqlite3) DetailedError { return .{ - .code = @intCast(usize, c.sqlite3_extended_errcode(db)), + .code = @intCast(c.sqlite3_extended_errcode(db)), .near = getErrorOffset(db), .message = blk: { const msg = c.sqlite3_errmsg(db); diff --git a/helpers.zig b/helpers.zig index 7bcbabe..1a56231 100644 --- a/helpers.zig +++ b/helpers.zig @@ -13,8 +13,8 @@ pub fn setResult(ctx: ?*c.sqlite3_context, result: anytype) void { const ResultType = @TypeOf(result); switch (ResultType) { - Text => c.sqlite3_result_text(ctx, result.data.ptr, @intCast(c_int, result.data.len), c.SQLITE_TRANSIENT), - Blob => c.sqlite3_result_blob(ctx, result.data.ptr, @intCast(c_int, result.data.len), c.SQLITE_TRANSIENT), + Text => c.sqlite3_result_text(ctx, result.data.ptr, @intCast(result.data.len), c.SQLITE_TRANSIENT), + Blob => c.sqlite3_result_blob(ctx, result.data.ptr, @intCast(result.data.len), c.SQLITE_TRANSIENT), else => switch (@typeInfo(ResultType)) { .Int => |info| if ((info.bits + if (info.signedness == .unsigned) 1 else 0) <= 32) { c.sqlite3_result_int(ctx, result); @@ -31,7 +31,7 @@ pub fn setResult(ctx: ?*c.sqlite3_context, result: anytype) void { }, .Pointer => |ptr| switch (ptr.size) { .Slice => switch (ptr.child) { - u8 => c.sqlite3_result_text(ctx, result.ptr, @intCast(c_int, result.len), c.SQLITE_TRANSIENT), + u8 => c.sqlite3_result_text(ctx, result.ptr, @intCast(result.len), c.SQLITE_TRANSIENT), else => @compileError("cannot use a result of type " ++ @typeName(ResultType)), }, else => @compileError("cannot use a result of type " ++ @typeName(ResultType)), @@ -51,16 +51,16 @@ pub fn setTypeFromValue(comptime ArgType: type, arg: *ArgType, sqlite_value: *c. else => switch (@typeInfo(ArgType)) { .Int => |info| if ((info.bits + if (info.signedness == .unsigned) 1 else 0) <= 32) { const value = c.sqlite3_value_int(sqlite_value); - arg.* = @intCast(ArgType, value); + arg.* = @intCast(value); } else if ((info.bits + if (info.signedness == .unsigned) 1 else 0) <= 64) { const value = c.sqlite3_value_int64(sqlite_value); - arg.* = @intCast(ArgType, value); + arg.* = @intCast(value); } else { @compileError("integer " ++ @typeName(ArgType) ++ " is not representable in sqlite"); }, .Float => { const value = c.sqlite3_value_double(sqlite_value); - arg.* = @floatCast(ArgType, value); + arg.* = @floatCast(value); }, .Bool => { const value = c.sqlite3_value_int(sqlite_value); @@ -79,7 +79,7 @@ pub fn setTypeFromValue(comptime ArgType: type, arg: *ArgType, sqlite_value: *c. } fn sliceFromValue(sqlite_value: *c.sqlite3_value) []const u8 { - const size = @intCast(usize, c.sqlite3_value_bytes(sqlite_value)); + const size: usize = @intCast(c.sqlite3_value_bytes(sqlite_value)); const value = c.sqlite3_value_text(sqlite_value); debug.assert(value != null); // TODO(vincent): how do we handle this properly ? diff --git a/sqlite.zig b/sqlite.zig index 4bd90c9..5c98790 100644 --- a/sqlite.zig +++ b/sqlite.zig @@ -107,21 +107,21 @@ pub const Blob = struct { } var tmp_buffer = blk: { - const remaining = @intCast(usize, self.size) - @intCast(usize, self.offset); + const remaining: usize = @as(usize, @intCast(self.size)) - @as(usize, @intCast(self.offset)); break :blk if (buffer.len > remaining) buffer[0..remaining] else buffer; }; const result = c.sqlite3_blob_read( self.handle, tmp_buffer.ptr, - @intCast(c_int, tmp_buffer.len), + @intCast(tmp_buffer.len), self.offset, ); if (result != c.SQLITE_OK) { return errors.errorFromResultCode(result); } - self.offset += @intCast(c_int, tmp_buffer.len); + self.offset += @intCast(tmp_buffer.len); return tmp_buffer.len; } @@ -137,14 +137,14 @@ pub const Blob = struct { const result = c.sqlite3_blob_write( self.handle, data.ptr, - @intCast(c_int, data.len), + @intCast(data.len), self.offset, ); if (result != c.SQLITE_OK) { return errors.errorFromResultCode(result); } - self.offset += @intCast(c_int, data.len); + self.offset += @intCast(data.len); return data.len; } @@ -191,7 +191,7 @@ pub const Blob = struct { column, row, open_flags, - @ptrCast([*c]?*c.sqlite3_blob, &blob.handle), + @ptrCast(&blob.handle), ); if (result == c.SQLITE_MISUSE) debug.panic("sqlite misuse while opening a blob", .{}); if (result != c.SQLITE_OK) { @@ -528,7 +528,7 @@ pub const Db = struct { /// rowsAffected returns the number of rows affected by the last statement executed. pub fn rowsAffected(self: *Self) usize { - return @intCast(usize, c.sqlite3_changes(self.db)); + return @intCast(c.sqlite3_changes(self.db)); } /// openBlob opens a blob for incremental i/o. @@ -825,12 +825,10 @@ pub const FunctionContext = struct { pub fn userContext(self: FunctionContext, comptime Type: type) ?Type { const Types = splitPtrTypes(Type); + _ = Types; if (c.sqlite3_user_data(self.ctx)) |value| { - return @ptrCast( - Types.PointerType, - @alignCast(@alignOf(Types.ValueType), value), - ); + return @ptrCast(@alignCast(value)); } return null; } @@ -839,10 +837,7 @@ pub const FunctionContext = struct { const Types = splitPtrTypes(Type); if (c.sqlite3_aggregate_context(self.ctx, @sizeOf(Types.ValueType))) |value| { - return @ptrCast( - Types.PointerType, - @alignCast(@alignOf(Types.ValueType), value), - ); + return @ptrCast(@alignCast(value)); } return null; } @@ -1073,7 +1068,7 @@ pub fn Iterator(comptime Type: type) type { if (@typeInfo(Type.BaseType) == .Int) { const inner_value = try self.readField(Type.BaseType, options, 0); - return @enumFromInt(Type, @intCast(TI.tag_type, inner_value)); + return @enumFromInt(@as(TI.tag_type, @intCast(inner_value))); } @compileError("enum column " ++ @typeName(Type) ++ " must have a BaseType of either string or int"); @@ -1157,7 +1152,7 @@ pub fn Iterator(comptime Type: type) type { return std.meta.stringToEnum(Type, inner_value) orelse unreachable; } if (@typeInfo(Type.BaseType) == .Int) { - return @enumFromInt(Type, @intCast(TI.tag_type, inner_value)); + return @enumFromInt(@as(TI.tag_type, @intCast(inner_value))); } @compileError("enum column " ++ @typeName(Type) ++ " must have a BaseType of either string or int"); }, @@ -1178,7 +1173,7 @@ pub fn Iterator(comptime Type: type) type { // // If the array is too small for the data an error will be returned. fn readArray(self: *Self, comptime ArrayType: type, _i: usize) !ArrayType { - const i = @intCast(c_int, _i); + const i: c_int = @intCast(_i); const type_info = @typeInfo(ArrayType); var ret: ArrayType = undefined; @@ -1186,7 +1181,7 @@ pub fn Iterator(comptime Type: type) type { .Array => |arr| { switch (arr.child) { u8 => { - const size = @intCast(usize, c.sqlite3_column_bytes(self.stmt, i)); + const size: usize = @intCast(c.sqlite3_column_bytes(self.stmt, i)); if (arr.sentinel) |sentinel_ptr| { // An array with a sentinel need to be as big as the data, + 1 byte for the sentinel. @@ -1195,7 +1190,7 @@ pub fn Iterator(comptime Type: type) type { } // Set the sentinel in the result at the correct position. - const sentinel = @ptrCast(*const arr.child, sentinel_ptr).*; + const sentinel = @as(*const arr.child, @ptrCast(sentinel_ptr)).*; ret[size] = sentinel; } else if (size != arr.len) { // An array without a sentinel must have the exact same size as the data because we can't @@ -1205,7 +1200,7 @@ pub fn Iterator(comptime Type: type) type { const data = c.sqlite3_column_blob(self.stmt, i); if (data != null) { - const ptr = @ptrCast([*c]const u8, data)[0..size]; + const ptr = @as([*c]const u8, @ptrCast(data))[0..size]; mem.copy(u8, ret[0..], ptr); } @@ -1220,19 +1215,19 @@ pub fn Iterator(comptime Type: type) type { // readInt reads a sqlite INTEGER column into an integer. fn readInt(self: *Self, comptime IntType: type, i: usize) error{Workaround}!IntType { // TODO remove the workaround once https://github.com/ziglang/zig/issues/5149 is resolved or if we actually return an error - const n = c.sqlite3_column_int64(self.stmt, @intCast(c_int, i)); - return @intCast(IntType, n); + const n = c.sqlite3_column_int64(self.stmt, @intCast(i)); + return @intCast(n); } // readFloat reads a sqlite REAL column into a float. fn readFloat(self: *Self, comptime FloatType: type, i: usize) error{Workaround}!FloatType { // TODO remove the workaround once https://github.com/ziglang/zig/issues/5149 is resolved or if we actually return an error - const d = c.sqlite3_column_double(self.stmt, @intCast(c_int, i)); - return @floatCast(FloatType, d); + const d = c.sqlite3_column_double(self.stmt, @intCast(i)); + return @floatCast(d); } // readFloat reads a sqlite INTEGER column into a bool (true is anything > 0, false is anything <= 0). fn readBool(self: *Self, i: usize) error{Workaround}!bool { // TODO remove the workaround once https://github.com/ziglang/zig/issues/5149 is resolved or if we actually return an error - const d = c.sqlite3_column_int64(self.stmt, @intCast(c_int, i)); + const d = c.sqlite3_column_int64(self.stmt, @intCast(i)); return d > 0; } @@ -1246,7 +1241,7 @@ pub fn Iterator(comptime Type: type) type { switch (@typeInfo(SliceType)) { .Pointer => |ptr_info| { if (ptr_info.sentinel) |sentinel_ptr| { - const sentinel = @ptrCast(*const ptr_info.child, sentinel_ptr).*; + const sentinel = @as(*const ptr_info.child, @ptrCast(sentinel_ptr)).*; const slice = try allocator.alloc(u8, data.len + 1); mem.copy(u8, slice, data); @@ -1272,7 +1267,7 @@ pub fn Iterator(comptime Type: type) type { // // The options must contain an `allocator` field which will be used to create a copy of the data. fn readBytes(self: *Self, comptime BytesType: type, allocator: mem.Allocator, _i: usize, comptime mode: ReadBytesMode) !BytesType { - const i = @intCast(c_int, _i); + const i: c_int = @intCast(_i); switch (mode) { .Blob => { @@ -1284,8 +1279,8 @@ pub fn Iterator(comptime Type: type) type { }; } - const size = @intCast(usize, c.sqlite3_column_bytes(self.stmt, i)); - const ptr = @ptrCast([*c]const u8, data)[0..size]; + const size: usize = @intCast(c.sqlite3_column_bytes(self.stmt, i)); + const ptr = @as([*c]const u8, @ptrCast(data))[0..size]; if (BytesType == Blob) { return Blob{ .data = try allocator.dupe(u8, ptr) }; @@ -1301,8 +1296,8 @@ pub fn Iterator(comptime Type: type) type { }; } - const size = @intCast(usize, c.sqlite3_column_bytes(self.stmt, i)); - const ptr = @ptrCast([*c]const u8, data)[0..size]; + const size: usize = @intCast(c.sqlite3_column_bytes(self.stmt, i)); + const ptr = @as([*c]const u8, @ptrCast(data))[0..size]; if (BytesType == Text) { return Text{ .data = try allocator.dupe(u8, ptr) }; @@ -1352,7 +1347,7 @@ pub fn Iterator(comptime Type: type) type { switch (@typeInfo(OptionalType)) { .Optional => |opt| { // Easy way to know if the column represents a null value. - const value = c.sqlite3_column_value(self.stmt, @intCast(c_int, _i)); + const value = c.sqlite3_column_value(self.stmt, @intCast(_i)); const datatype = c.sqlite3_value_type(value); if (datatype == c.SQLITE_NULL) { @@ -1445,7 +1440,7 @@ pub fn Iterator(comptime Type: type) type { return std.meta.stringToEnum(FieldType, inner_value) orelse unreachable; } if (@typeInfo(FieldType.BaseType) == .Int) { - return @enumFromInt(FieldType, @intCast(TI.tag_type, inner_value)); + return @enumFromInt(@as(TI.tag_type, @intCast(inner_value))); } @compileError("enum column " ++ @typeName(FieldType) ++ " must have a BaseType of either string or int"); }, @@ -1526,7 +1521,7 @@ pub const DynamicStatement = struct { const result = c.sqlite3_prepare_v3( db.db, query.ptr, - @intCast(c_int, query.len), + @intCast(query.len), flags, &tmp, options.sql_tail_ptr, @@ -1588,11 +1583,11 @@ pub const DynamicStatement = struct { switch (FieldType) { Text => { - const result = c.sqlite3_bind_text(self.stmt, column, field.data.ptr, @intCast(c_int, field.data.len), null); + const result = c.sqlite3_bind_text(self.stmt, column, field.data.ptr, @intCast(field.data.len), null); return convertResultToError(result); }, Blob => { - const result = c.sqlite3_bind_blob(self.stmt, column, field.data.ptr, @intCast(c_int, field.data.len), null); + const result = c.sqlite3_bind_blob(self.stmt, column, field.data.ptr, @intCast(field.data.len), null); return convertResultToError(result); }, ZeroBlob => { @@ -1601,7 +1596,7 @@ pub const DynamicStatement = struct { }, else => switch (field_type_info) { .Int, .ComptimeInt => { - const result = c.sqlite3_bind_int64(self.stmt, column, @intCast(c_longlong, field)); + const result = c.sqlite3_bind_int64(self.stmt, column, @intCast(field)); return convertResultToError(result); }, .Float, .ComptimeFloat => { @@ -1619,7 +1614,7 @@ pub const DynamicStatement = struct { .Slice => switch (ptr.child) { u8 => { // NOTE(vincent): The slice must live until after the prepared statement is finaliuzed, therefore we use SQLITE_STATIC to avoid a copy - const result = c.sqlite3_bind_text(self.stmt, column, field.ptr, @intCast(c_int, field.len), c.SQLITE_STATIC); + const result = c.sqlite3_bind_text(self.stmt, column, field.ptr, @intCast(field.len), c.SQLITE_STATIC); return convertResultToError(result); }, else => @compileError("cannot bind field " ++ field_name ++ " of type " ++ @typeName(FieldType)), @@ -1631,7 +1626,7 @@ pub const DynamicStatement = struct { const data: []const u8 = field[0..field.len]; // NOTE(vincent): The array is temporary and must be copied, therefore we use SQLITE_TRANSIENT - const result = c.sqlite3_bind_text(self.stmt, column, data.ptr, @intCast(c_int, data.len), c.SQLITE_TRANSIENT); + const result = c.sqlite3_bind_text(self.stmt, column, data.ptr, @intCast(data.len), c.SQLITE_TRANSIENT); return convertResultToError(result); }, else => @compileError("cannot bind field " ++ field_name ++ " of type array of " ++ @typeName(arr.child)), @@ -1738,7 +1733,7 @@ pub const DynamicStatement = struct { switch (PointerTypeInfo.size) { .Slice => { for (values, 0..) |value_to_bind, index| { - try self.bindField(PointerTypeInfo.child, options, "unknown", @intCast(c_int, index), value_to_bind); + try self.bindField(PointerTypeInfo.child, options, "unknown", @intCast(index), value_to_bind); } }, else => @compileError("TODO support pointer size " ++ @tagName(PointerTypeInfo.size)), @@ -1746,7 +1741,7 @@ pub const DynamicStatement = struct { }, .Array => |ArrayTypeInfo| { for (values, 0..) |value_to_bind, index| { - try self.bindField(ArrayTypeInfo.child, options, "unknown", @intCast(c_int, index), value_to_bind); + try self.bindField(ArrayTypeInfo.child, options, "unknown", @intCast(index), value_to_bind); } }, else => @compileError("Unsupported type for values: " ++ @typeName(Type)), @@ -2541,7 +2536,7 @@ test "sqlite: read in an anonymous struct" { try testing.expectEqualStrings(exp.name, mem.sliceTo(&row.?.name_2, 0xAD)); try testing.expectEqual(exp.age, row.?.age); try testing.expect(row.?.is_id); - try testing.expectEqual(exp.weight, @floatCast(f32, row.?.weight)); + try testing.expectEqual(exp.weight, @as(f32, @floatCast(row.?.weight))); } test "sqlite: read in a Text struct" { @@ -2621,7 +2616,7 @@ test "sqlite: read a single text value" { try testing.expectEqualStrings("Vincent", name.?); }, .Array => |arr| if (arr.sentinel) |sentinel_ptr| { - const sentinel = @ptrCast(*const arr.child, sentinel_ptr).*; + const sentinel = @as(*const arr.child, @ptrCast(sentinel_ptr)).*; const res = mem.sliceTo(&name.?, sentinel); try testing.expectEqualStrings("Vincent", res); } else { @@ -2969,7 +2964,7 @@ test "sqlite: statement iterator" { var i: usize = 0; while (i < 20) : (i += 1) { const name = try std.fmt.allocPrint(allocator, "Vincent {d}", .{i}); - const user = TestUser{ .id = i, .name = name, .age = i + 200, .weight = @floatFromInt(f32, i + 200), .favorite_color = .indigo }; + const user = TestUser{ .id = i, .name = name, .age = i + 200, .weight = @floatFromInt(i + 200), .favorite_color = .indigo }; try expected_rows.append(user); @@ -3360,7 +3355,7 @@ test "sqlite: bind custom type" { var i: usize = 0; while (i < 20) : (i += 1) { var my_data: MyData = undefined; - @memset(&my_data.data, @intCast(u8, i)); + @memset(&my_data.data, @as(u8, @intCast(i))); var arena = heap.ArenaAllocator.init(testing.allocator); defer arena.deinit(); @@ -3390,7 +3385,7 @@ test "sqlite: bind custom type" { for (rows, 0..) |row, i| { var exp_data: MyData = undefined; - @memset(&exp_data.data, @intCast(u8, i)); + @memset(&exp_data.data, @as(u8, @intCast(i))); try testing.expectEqualSlices(u8, &exp_data.data, &row.data.data); } @@ -3567,7 +3562,7 @@ test "sqlite: create scalar function" { "myInteger64", struct { fn run(input: i64) i64 { - return @intCast(i64, input) * 2; + return @as(i64, @intCast(input)) * 2; } }.run, .{}, @@ -3693,7 +3688,7 @@ test "sqlite: create aggregate function with no aggregate context" { var db = try getTestDb(); defer db.deinit(); - var rand = std.rand.DefaultPrng.init(@intCast(u64, std.time.milliTimestamp())); + var rand = std.rand.DefaultPrng.init(@intCast(std.time.milliTimestamp())); // Create an aggregate function working with a MyContext @@ -3754,7 +3749,7 @@ test "sqlite: create aggregate function with an aggregate context" { var db = try getTestDb(); defer db.deinit(); - var rand = std.rand.DefaultPrng.init(@intCast(u64, std.time.milliTimestamp())); + var rand = std.rand.DefaultPrng.init(@intCast(std.time.milliTimestamp())); try db.createAggregateFunction( "mySum", diff --git a/vtab.zig b/vtab.zig index a7645c3..d871d01 100644 --- a/vtab.zig +++ b/vtab.zig @@ -24,7 +24,7 @@ pub const ModuleContext = struct { }; fn dupeToSQLiteString(s: []const u8) [*c]const u8 { - var buffer = @ptrCast([*c]u8, c.sqlite3_malloc(@intCast(c_int, s.len) + 1)); + var buffer: [*c]u8 = @ptrCast(c.sqlite3_malloc(@intCast(s.len + 1))); mem.copy(u8, buffer[0..s.len], s); buffer[s.len] = 0; @@ -202,15 +202,15 @@ pub const BestIndexBuilder = struct { .allocator = allocator, .index_info = index_info, .id_str_buffer = std.ArrayList(u8).init(allocator), - .constraints = try allocator.alloc(Constraint, @intCast(usize, index_info.nConstraint)), - .columns_used = @intCast(u64, index_info.colUsed), + .constraints = try allocator.alloc(Constraint, @intCast(index_info.nConstraint)), + .columns_used = @intCast(index_info.colUsed), .id = .{}, }; for (res.constraints, 0..) |*constraint, i| { const raw_constraint = index_info.aConstraint[i]; - constraint.column = @intCast(isize, raw_constraint.iColumn); + constraint.column = @intCast(raw_constraint.iColumn); constraint.op = try constraintOpFromCode(raw_constraint.op); constraint.usable = if (raw_constraint.usable == 1) true else false; constraint.usage = .{}; @@ -239,10 +239,10 @@ pub const BestIndexBuilder = struct { } // Identifiers - index_info.idxNum = @intCast(c_int, self.id.num); + index_info.idxNum = @intCast(self.id.num); if (self.id.str.len > 0) { // Must always be NULL-terminated so add 1 - const tmp = @ptrCast([*c]u8, c.sqlite3_malloc(@intCast(c_int, self.id.str.len + 1))); + const tmp: [*c]u8 = @ptrCast(c.sqlite3_malloc(@intCast(self.id.str.len + 1))); mem.copy(u8, tmp[0..self.id.str.len], self.id.str); tmp[self.id.str.len] = 0; @@ -278,7 +278,7 @@ pub const IndexIdentifier = struct { fn fromC(idx_num: c_int, idx_str: [*c]const u8) IndexIdentifier { return IndexIdentifier{ - .num = @intCast(i32, idx_num), + .num = @intCast(idx_num), .str = if (idx_str != null) mem.sliceTo(idx_str, 0) else "", }; } @@ -538,7 +538,7 @@ pub const ModuleArgument = union(enum) { const ParseModuleArgumentsError = error{} || mem.Allocator.Error; fn parseModuleArguments(allocator: mem.Allocator, argc: c_int, argv: [*c]const [*c]const u8) ParseModuleArgumentsError![]ModuleArgument { - var res = try allocator.alloc(ModuleArgument, @intCast(usize, argc)); + var res = try allocator.alloc(ModuleArgument, @intCast(argc)); errdefer allocator.free(res); for (res, 0..) |*marg, i| { @@ -695,7 +695,7 @@ pub fn VirtualTable( table: Table, fn getModuleContext(ptr: ?*anyopaque) *ModuleContext { - return @ptrCast(*ModuleContext, @alignCast(@alignOf(ModuleContext), ptr.?)); + return @ptrCast(@alignCast(ptr.?)); } fn createState(allocator: mem.Allocator, diags: *VTabDiagnostics, module_context: *ModuleContext, args: []const ModuleArgument) !*State { @@ -742,9 +742,9 @@ pub fn VirtualTable( err_str.* = dupeToSQLiteString(diags.error_message); return c.SQLITE_ERROR; }; - vtab.* = @ptrCast(*c.sqlite3_vtab, state); + vtab.* = @ptrCast(state); - const res = c.sqlite3_declare_vtab(db, @ptrCast([*c]const u8, state.table.schema)); + const res = c.sqlite3_declare_vtab(db, @ptrCast(state.table.schema)); if (res != c.SQLITE_OK) { return c.SQLITE_ERROR; } @@ -800,7 +800,7 @@ pub fn VirtualTable( logger.err("unable to create cursor state, err: {!}", .{err}); return c.SQLITE_ERROR; }; - vtab_cursor.* = @ptrCast(*c.sqlite3_vtab_cursor, cursor_state); + vtab_cursor.* = @ptrCast(cursor_state); return c.SQLITE_OK; } @@ -837,7 +837,7 @@ pub fn VirtualTable( const FilterArgsFromCPointerError = error{} || mem.Allocator.Error; fn filterArgsFromCPointer(allocator: mem.Allocator, argc: c_int, argv: [*c]?*c.sqlite3_value) FilterArgsFromCPointerError![]FilterArg { - const size = @intCast(usize, argc); + const size: usize = @intCast(argc); var res = try allocator.alloc(FilterArg, size); for (res, 0..) |*item, i| { @@ -902,7 +902,7 @@ pub fn VirtualTable( // var diags = VTabDiagnostics{ .allocator = arena.allocator() }; - const column = cursor.column(&diags, @intCast(i32, n)) catch { + const column = cursor.column(&diags, @intCast(n)) catch { logger.err("unable to call Table.Cursor.column: {s}", .{diags.error_message}); return c.SQLITE_ERROR; }; @@ -1214,7 +1214,7 @@ const TestVirtualTableCursor = struct { pub fn rowId(cursor: *TestVirtualTableCursor, diags: *VTabDiagnostics) RowIDError!i64 { _ = diags; - return @intCast(i64, cursor.iterator.pos); + return @intCast(cursor.iterator.pos); } }; @@ -1278,13 +1278,13 @@ test "parse module arguments" { var args = try allocator.alloc([*c]const u8, 20); for (args, 0..) |*arg, i| { const tmp = try fmt.allocPrintZ(allocator, "arg={d}", .{i}); - arg.* = @ptrCast([*c]const u8, tmp); + arg.* = @ptrCast(tmp); } const res = try parseModuleArguments( allocator, - @intCast(c_int, args.len), - @ptrCast([*c]const [*c]const u8, args), + @intCast(args.len), + @ptrCast(args), ); try testing.expectEqual(@as(usize, 20), res.len); -- cgit v1.2.3