diff options
| author | 2023-07-02 15:28:30 +0200 | |
|---|---|---|
| committer | 2023-07-02 15:28:37 +0200 | |
| commit | ce7a6a7b657e4c8f9514d4181230068bd45823e2 (patch) | |
| tree | ba788b9916d5d879737959d4823af9fbd104b4df /vtab.zig | |
| parent | fuzz: fix for latest zig (diff) | |
| download | zig-sqlite-ce7a6a7b657e4c8f9514d4181230068bd45823e2.tar.gz zig-sqlite-ce7a6a7b657e4c8f9514d4181230068bd45823e2.tar.xz zig-sqlite-ce7a6a7b657e4c8f9514d4181230068bd45823e2.zip | |
update for latest zig
Diffstat (limited to '')
| -rw-r--r-- | vtab.zig | 36 |
1 files changed, 18 insertions, 18 deletions
| @@ -24,7 +24,7 @@ pub const ModuleContext = struct { | |||
| 24 | }; | 24 | }; |
| 25 | 25 | ||
| 26 | fn dupeToSQLiteString(s: []const u8) [*c]const u8 { | 26 | fn dupeToSQLiteString(s: []const u8) [*c]const u8 { |
| 27 | var buffer = @ptrCast([*c]u8, c.sqlite3_malloc(@intCast(c_int, s.len) + 1)); | 27 | var buffer: [*c]u8 = @ptrCast(c.sqlite3_malloc(@intCast(s.len + 1))); |
| 28 | 28 | ||
| 29 | mem.copy(u8, buffer[0..s.len], s); | 29 | mem.copy(u8, buffer[0..s.len], s); |
| 30 | buffer[s.len] = 0; | 30 | buffer[s.len] = 0; |
| @@ -202,15 +202,15 @@ pub const BestIndexBuilder = struct { | |||
| 202 | .allocator = allocator, | 202 | .allocator = allocator, |
| 203 | .index_info = index_info, | 203 | .index_info = index_info, |
| 204 | .id_str_buffer = std.ArrayList(u8).init(allocator), | 204 | .id_str_buffer = std.ArrayList(u8).init(allocator), |
| 205 | .constraints = try allocator.alloc(Constraint, @intCast(usize, index_info.nConstraint)), | 205 | .constraints = try allocator.alloc(Constraint, @intCast(index_info.nConstraint)), |
| 206 | .columns_used = @intCast(u64, index_info.colUsed), | 206 | .columns_used = @intCast(index_info.colUsed), |
| 207 | .id = .{}, | 207 | .id = .{}, |
| 208 | }; | 208 | }; |
| 209 | 209 | ||
| 210 | for (res.constraints, 0..) |*constraint, i| { | 210 | for (res.constraints, 0..) |*constraint, i| { |
| 211 | const raw_constraint = index_info.aConstraint[i]; | 211 | const raw_constraint = index_info.aConstraint[i]; |
| 212 | 212 | ||
| 213 | constraint.column = @intCast(isize, raw_constraint.iColumn); | 213 | constraint.column = @intCast(raw_constraint.iColumn); |
| 214 | constraint.op = try constraintOpFromCode(raw_constraint.op); | 214 | constraint.op = try constraintOpFromCode(raw_constraint.op); |
| 215 | constraint.usable = if (raw_constraint.usable == 1) true else false; | 215 | constraint.usable = if (raw_constraint.usable == 1) true else false; |
| 216 | constraint.usage = .{}; | 216 | constraint.usage = .{}; |
| @@ -239,10 +239,10 @@ pub const BestIndexBuilder = struct { | |||
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | // Identifiers | 241 | // Identifiers |
| 242 | index_info.idxNum = @intCast(c_int, self.id.num); | 242 | index_info.idxNum = @intCast(self.id.num); |
| 243 | if (self.id.str.len > 0) { | 243 | if (self.id.str.len > 0) { |
| 244 | // Must always be NULL-terminated so add 1 | 244 | // Must always be NULL-terminated so add 1 |
| 245 | const tmp = @ptrCast([*c]u8, c.sqlite3_malloc(@intCast(c_int, self.id.str.len + 1))); | 245 | const tmp: [*c]u8 = @ptrCast(c.sqlite3_malloc(@intCast(self.id.str.len + 1))); |
| 246 | 246 | ||
| 247 | mem.copy(u8, tmp[0..self.id.str.len], self.id.str); | 247 | mem.copy(u8, tmp[0..self.id.str.len], self.id.str); |
| 248 | tmp[self.id.str.len] = 0; | 248 | tmp[self.id.str.len] = 0; |
| @@ -278,7 +278,7 @@ pub const IndexIdentifier = struct { | |||
| 278 | 278 | ||
| 279 | fn fromC(idx_num: c_int, idx_str: [*c]const u8) IndexIdentifier { | 279 | fn fromC(idx_num: c_int, idx_str: [*c]const u8) IndexIdentifier { |
| 280 | return IndexIdentifier{ | 280 | return IndexIdentifier{ |
| 281 | .num = @intCast(i32, idx_num), | 281 | .num = @intCast(idx_num), |
| 282 | .str = if (idx_str != null) mem.sliceTo(idx_str, 0) else "", | 282 | .str = if (idx_str != null) mem.sliceTo(idx_str, 0) else "", |
| 283 | }; | 283 | }; |
| 284 | } | 284 | } |
| @@ -538,7 +538,7 @@ pub const ModuleArgument = union(enum) { | |||
| 538 | const ParseModuleArgumentsError = error{} || mem.Allocator.Error; | 538 | const ParseModuleArgumentsError = error{} || mem.Allocator.Error; |
| 539 | 539 | ||
| 540 | fn parseModuleArguments(allocator: mem.Allocator, argc: c_int, argv: [*c]const [*c]const u8) ParseModuleArgumentsError![]ModuleArgument { | 540 | fn parseModuleArguments(allocator: mem.Allocator, argc: c_int, argv: [*c]const [*c]const u8) ParseModuleArgumentsError![]ModuleArgument { |
| 541 | var res = try allocator.alloc(ModuleArgument, @intCast(usize, argc)); | 541 | var res = try allocator.alloc(ModuleArgument, @intCast(argc)); |
| 542 | errdefer allocator.free(res); | 542 | errdefer allocator.free(res); |
| 543 | 543 | ||
| 544 | for (res, 0..) |*marg, i| { | 544 | for (res, 0..) |*marg, i| { |
| @@ -695,7 +695,7 @@ pub fn VirtualTable( | |||
| 695 | table: Table, | 695 | table: Table, |
| 696 | 696 | ||
| 697 | fn getModuleContext(ptr: ?*anyopaque) *ModuleContext { | 697 | fn getModuleContext(ptr: ?*anyopaque) *ModuleContext { |
| 698 | return @ptrCast(*ModuleContext, @alignCast(@alignOf(ModuleContext), ptr.?)); | 698 | return @ptrCast(@alignCast(ptr.?)); |
| 699 | } | 699 | } |
| 700 | 700 | ||
| 701 | fn createState(allocator: mem.Allocator, diags: *VTabDiagnostics, module_context: *ModuleContext, args: []const ModuleArgument) !*State { | 701 | fn createState(allocator: mem.Allocator, diags: *VTabDiagnostics, module_context: *ModuleContext, args: []const ModuleArgument) !*State { |
| @@ -742,9 +742,9 @@ pub fn VirtualTable( | |||
| 742 | err_str.* = dupeToSQLiteString(diags.error_message); | 742 | err_str.* = dupeToSQLiteString(diags.error_message); |
| 743 | return c.SQLITE_ERROR; | 743 | return c.SQLITE_ERROR; |
| 744 | }; | 744 | }; |
| 745 | vtab.* = @ptrCast(*c.sqlite3_vtab, state); | 745 | vtab.* = @ptrCast(state); |
| 746 | 746 | ||
| 747 | const res = c.sqlite3_declare_vtab(db, @ptrCast([*c]const u8, state.table.schema)); | 747 | const res = c.sqlite3_declare_vtab(db, @ptrCast(state.table.schema)); |
| 748 | if (res != c.SQLITE_OK) { | 748 | if (res != c.SQLITE_OK) { |
| 749 | return c.SQLITE_ERROR; | 749 | return c.SQLITE_ERROR; |
| 750 | } | 750 | } |
| @@ -800,7 +800,7 @@ pub fn VirtualTable( | |||
| 800 | logger.err("unable to create cursor state, err: {!}", .{err}); | 800 | logger.err("unable to create cursor state, err: {!}", .{err}); |
| 801 | return c.SQLITE_ERROR; | 801 | return c.SQLITE_ERROR; |
| 802 | }; | 802 | }; |
| 803 | vtab_cursor.* = @ptrCast(*c.sqlite3_vtab_cursor, cursor_state); | 803 | vtab_cursor.* = @ptrCast(cursor_state); |
| 804 | 804 | ||
| 805 | return c.SQLITE_OK; | 805 | return c.SQLITE_OK; |
| 806 | } | 806 | } |
| @@ -837,7 +837,7 @@ pub fn VirtualTable( | |||
| 837 | const FilterArgsFromCPointerError = error{} || mem.Allocator.Error; | 837 | const FilterArgsFromCPointerError = error{} || mem.Allocator.Error; |
| 838 | 838 | ||
| 839 | fn filterArgsFromCPointer(allocator: mem.Allocator, argc: c_int, argv: [*c]?*c.sqlite3_value) FilterArgsFromCPointerError![]FilterArg { | 839 | fn filterArgsFromCPointer(allocator: mem.Allocator, argc: c_int, argv: [*c]?*c.sqlite3_value) FilterArgsFromCPointerError![]FilterArg { |
| 840 | const size = @intCast(usize, argc); | 840 | const size: usize = @intCast(argc); |
| 841 | 841 | ||
| 842 | var res = try allocator.alloc(FilterArg, size); | 842 | var res = try allocator.alloc(FilterArg, size); |
| 843 | for (res, 0..) |*item, i| { | 843 | for (res, 0..) |*item, i| { |
| @@ -902,7 +902,7 @@ pub fn VirtualTable( | |||
| 902 | // | 902 | // |
| 903 | 903 | ||
| 904 | var diags = VTabDiagnostics{ .allocator = arena.allocator() }; | 904 | var diags = VTabDiagnostics{ .allocator = arena.allocator() }; |
| 905 | const column = cursor.column(&diags, @intCast(i32, n)) catch { | 905 | const column = cursor.column(&diags, @intCast(n)) catch { |
| 906 | logger.err("unable to call Table.Cursor.column: {s}", .{diags.error_message}); | 906 | logger.err("unable to call Table.Cursor.column: {s}", .{diags.error_message}); |
| 907 | return c.SQLITE_ERROR; | 907 | return c.SQLITE_ERROR; |
| 908 | }; | 908 | }; |
| @@ -1214,7 +1214,7 @@ const TestVirtualTableCursor = struct { | |||
| 1214 | pub fn rowId(cursor: *TestVirtualTableCursor, diags: *VTabDiagnostics) RowIDError!i64 { | 1214 | pub fn rowId(cursor: *TestVirtualTableCursor, diags: *VTabDiagnostics) RowIDError!i64 { |
| 1215 | _ = diags; | 1215 | _ = diags; |
| 1216 | 1216 | ||
| 1217 | return @intCast(i64, cursor.iterator.pos); | 1217 | return @intCast(cursor.iterator.pos); |
| 1218 | } | 1218 | } |
| 1219 | }; | 1219 | }; |
| 1220 | 1220 | ||
| @@ -1278,13 +1278,13 @@ test "parse module arguments" { | |||
| 1278 | var args = try allocator.alloc([*c]const u8, 20); | 1278 | var args = try allocator.alloc([*c]const u8, 20); |
| 1279 | for (args, 0..) |*arg, i| { | 1279 | for (args, 0..) |*arg, i| { |
| 1280 | const tmp = try fmt.allocPrintZ(allocator, "arg={d}", .{i}); | 1280 | const tmp = try fmt.allocPrintZ(allocator, "arg={d}", .{i}); |
| 1281 | arg.* = @ptrCast([*c]const u8, tmp); | 1281 | arg.* = @ptrCast(tmp); |
| 1282 | } | 1282 | } |
| 1283 | 1283 | ||
| 1284 | const res = try parseModuleArguments( | 1284 | const res = try parseModuleArguments( |
| 1285 | allocator, | 1285 | allocator, |
| 1286 | @intCast(c_int, args.len), | 1286 | @intCast(args.len), |
| 1287 | @ptrCast([*c]const [*c]const u8, args), | 1287 | @ptrCast(args), |
| 1288 | ); | 1288 | ); |
| 1289 | try testing.expectEqual(@as(usize, 20), res.len); | 1289 | try testing.expectEqual(@as(usize, 20), res.len); |
| 1290 | 1290 | ||