summaryrefslogtreecommitdiff
path: root/sqlite.zig
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2020-12-21 01:13:53 +0100
committerGravatar Vincent Rischmann2020-12-21 01:13:53 +0100
commitf644975ffd338a1799fad15a8ea4b7107788972f (patch)
treec8acf9538f3219cfe230394061893e6eb5195b20 /sqlite.zig
parentadd a weight real column to the test table (diff)
downloadzig-sqlite-f644975ffd338a1799fad15a8ea4b7107788972f.tar.gz
zig-sqlite-f644975ffd338a1799fad15a8ea4b7107788972f.tar.xz
zig-sqlite-f644975ffd338a1799fad15a8ea4b7107788972f.zip
make readArray return an array instead of taking a pointer
Diffstat (limited to 'sqlite.zig')
-rw-r--r--sqlite.zig14
1 files changed, 7 insertions, 7 deletions
diff --git a/sqlite.zig b/sqlite.zig
index c2ec86d..12e9781 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -231,9 +231,7 @@ pub fn Iterator(comptime Type: type) type {
231 }, 231 },
232 .Array => { 232 .Array => {
233 debug.assert(columns == 1); 233 debug.assert(columns == 1);
234 var ret: Type = undefined; 234 return try self.readArray(Type, 0);
235 try self.readArray(Type, 0, &ret);
236 return ret;
237 }, 235 },
238 .Struct => { 236 .Struct => {
239 std.debug.assert(columns == TypeInfo.Struct.fields.len); 237 std.debug.assert(columns == TypeInfo.Struct.fields.len);
@@ -243,10 +241,11 @@ pub fn Iterator(comptime Type: type) type {
243 } 241 }
244 } 242 }
245 243
246 fn readArray(self: *Self, comptime ArrayType: type, _i: usize, array: anytype) !void { 244 fn readArray(self: *Self, comptime ArrayType: type, _i: usize) !ArrayType {
247 const i = @intCast(c_int, _i); 245 const i = @intCast(c_int, _i);
248 const array_type_info = @typeInfo(ArrayType); 246 const array_type_info = @typeInfo(ArrayType);
249 247
248 var ret: ArrayType = undefined;
250 switch (array_type_info) { 249 switch (array_type_info) {
251 .Array => |arr| { 250 .Array => |arr| {
252 comptime if (arr.sentinel == null) { 251 comptime if (arr.sentinel == null) {
@@ -262,14 +261,15 @@ pub fn Iterator(comptime Type: type) type {
262 261
263 const ptr = @ptrCast([*c]const u8, data)[0..size]; 262 const ptr = @ptrCast([*c]const u8, data)[0..size];
264 263
265 mem.copy(u8, array[0..], ptr); 264 mem.copy(u8, ret[0..], ptr);
266 array[size] = arr.sentinel.?; 265 ret[size] = arr.sentinel.?;
267 }, 266 },
268 else => @compileError("cannot populate field " ++ field.name ++ " of type array of " ++ @typeName(arr.child)), 267 else => @compileError("cannot populate field " ++ field.name ++ " of type array of " ++ @typeName(arr.child)),
269 } 268 }
270 }, 269 },
271 else => @compileError("cannot populate field " ++ field.name ++ " of type array of " ++ @typeName(arr.child)), 270 else => @compileError("cannot populate field " ++ field.name ++ " of type array of " ++ @typeName(arr.child)),
272 } 271 }
272 return ret;
273 } 273 }
274 274
275 fn readInt(self: *Self, comptime IntType: type, i: usize, options: anytype) !IntType { 275 fn readInt(self: *Self, comptime IntType: type, i: usize, options: anytype) !IntType {
@@ -347,7 +347,7 @@ pub fn Iterator(comptime Type: type) type {
347 @field(value, field.name) = {}; 347 @field(value, field.name) = {};
348 }, 348 },
349 .Array => { 349 .Array => {
350 try self.readArray(field.field_type, i, &@field(value, field.name)); 350 @field(value, field.name) = try self.readArray(field.field_type, i);
351 }, 351 },
352 else => @compileError("cannot populate field " ++ field.name ++ " of type " ++ @typeName(field.field_type)), 352 else => @compileError("cannot populate field " ++ field.name ++ " of type " ++ @typeName(field.field_type)),
353 }, 353 },