authorgravatar for techatrix@mailbox.orgTechatrix <techatrix@mailbox.org> 2025-11-09 21:43:20+01:00
committergravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2025-11-11 01:11:51+01:00
log8887346b530e1a3499407a580324f81b1b6caac9
tree28d4429ad945e6de01978f0d9bf7b7ee2fbf6081
parentcca2d0995099fc37ac792e6322cad88cc67ac056

std.Io: fix calls on functions that return an array type


2 files changed, 21 insertions(+), 7 deletions(-)

lib/std/Io.zig+7-7
...@@ -993,7 +993,7 @@ pub fn Future(Result: type) type {...@@ -993,7 +993,7 @@ pub fn Future(Result: type) type {
993 /// Idempotent. Not threadsafe.993 /// Idempotent. Not threadsafe.
994 pub fn cancel(f: *@This(), io: Io) Result {994 pub fn cancel(f: *@This(), io: Io) Result {
995 const any_future = f.any_future orelse return f.result;995 const any_future = f.any_future orelse return f.result;
996 io.vtable.cancel(io.userdata, any_future, @ptrCast((&f.result)[0..1]), .of(Result));996 io.vtable.cancel(io.userdata, any_future, @ptrCast(&f.result), .of(Result));
997 f.any_future = null;997 f.any_future = null;
998 return f.result;998 return f.result;
999 }999 }
...@@ -1001,7 +1001,7 @@ pub fn Future(Result: type) type {...@@ -1001,7 +1001,7 @@ pub fn Future(Result: type) type {
1001 /// Idempotent. Not threadsafe.1001 /// Idempotent. Not threadsafe.
1002 pub fn await(f: *@This(), io: Io) Result {1002 pub fn await(f: *@This(), io: Io) Result {
1003 const any_future = f.any_future orelse return f.result;1003 const any_future = f.any_future orelse return f.result;
1004 io.vtable.await(io.userdata, any_future, @ptrCast((&f.result)[0..1]), .of(Result));1004 io.vtable.await(io.userdata, any_future, @ptrCast(&f.result), .of(Result));
1005 f.any_future = null;1005 f.any_future = null;
1006 return f.result;1006 return f.result;
1007 }1007 }
...@@ -1037,7 +1037,7 @@ pub const Group = struct {...@@ -1037,7 +1037,7 @@ pub const Group = struct {
1037 @call(.auto, function, args_casted.*);1037 @call(.auto, function, args_casted.*);
1038 }1038 }
1039 };1039 };
1040 io.vtable.groupAsync(io.userdata, g, @ptrCast((&args)[0..1]), .of(Args), TypeErased.start);1040 io.vtable.groupAsync(io.userdata, g, @ptrCast(&args), .of(Args), TypeErased.start);
1041 }1041 }
10421042
1043 /// Blocks until all tasks of the group finish. During this time,1043 /// Blocks until all tasks of the group finish. During this time,
...@@ -1114,7 +1114,7 @@ pub fn Select(comptime U: type) type {...@@ -1114,7 +1114,7 @@ pub fn Select(comptime U: type) type {
1114 }1114 }
1115 };1115 };
1116 _ = @atomicRmw(usize, &s.outstanding, .Add, 1, .monotonic);1116 _ = @atomicRmw(usize, &s.outstanding, .Add, 1, .monotonic);
1117 s.io.vtable.groupAsync(s.io.userdata, &s.group, @ptrCast((&args)[0..1]), .of(Args), TypeErased.start);1117 s.io.vtable.groupAsync(s.io.userdata, &s.group, @ptrCast(&args), .of(Args), TypeErased.start);
1118 }1118 }
11191119
1120 /// Blocks until another task of the select finishes.1120 /// Blocks until another task of the select finishes.
...@@ -1542,9 +1542,9 @@ pub fn async(...@@ -1542,9 +1542,9 @@ pub fn async(
1542 var future: Future(Result) = undefined;1542 var future: Future(Result) = undefined;
1543 future.any_future = io.vtable.async(1543 future.any_future = io.vtable.async(
1544 io.userdata,1544 io.userdata,
1545 @ptrCast((&future.result)[0..1]),1545 @ptrCast(&future.result),
1546 .of(Result),1546 .of(Result),
1547 @ptrCast((&args)[0..1]),1547 @ptrCast(&args),
1548 .of(Args),1548 .of(Args),
1549 TypeErased.start,1549 TypeErased.start,
1550 );1550 );
...@@ -1583,7 +1583,7 @@ pub fn concurrent(...@@ -1583,7 +1583,7 @@ pub fn concurrent(
1583 io.userdata,1583 io.userdata,
1584 @sizeOf(Result),1584 @sizeOf(Result),
1585 .of(Result),1585 .of(Result),
1586 @ptrCast((&args)[0..1]),1586 @ptrCast(&args),
1587 .of(Args),1587 .of(Args),
1588 TypeErased.start,1588 TypeErased.start,
1589 );1589 );
lib/std/Io/Threaded/test.zig+14
...@@ -115,3 +115,17 @@ test "Group.async context alignment" {...@@ -115,3 +115,17 @@ test "Group.async context alignment" {
115 group.wait(io);115 group.wait(io);
116 try std.testing.expectEqualSlices(u8, &expected.x, &result.x);116 try std.testing.expectEqualSlices(u8, &expected.x, &result.x);
117}117}
118
119fn returnArray() [32]u8 {
120 return @splat(5);
121}
122
123test "async with array return type" {
124 var threaded: std.Io.Threaded = .init(std.testing.allocator);
125 defer threaded.deinit();
126 const io = threaded.io();
127
128 var future = io.async(returnArray, .{});
129 const result = future.await(io);
130 try std.testing.expectEqualSlices(u8, &@as([32]u8, @splat(5)), &result);
131}