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 {
993993 /// Idempotent. Not threadsafe.
994994 pub fn cancel(f: *@This(), io: Io) Result {
995995 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));
997997 f.any_future = null;
998998 return f.result;
999999 }
......@@ -1001,7 +1001,7 @@ pub fn Future(Result: type) type {
10011001 /// Idempotent. Not threadsafe.
10021002 pub fn await(f: *@This(), io: Io) Result {
10031003 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));
10051005 f.any_future = null;
10061006 return f.result;
10071007 }
......@@ -1037,7 +1037,7 @@ pub const Group = struct {
10371037 @call(.auto, function, args_casted.*);
10381038 }
10391039 };
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);
10411041 }
10421042
10431043 /// Blocks until all tasks of the group finish. During this time,
......@@ -1114,7 +1114,7 @@ pub fn Select(comptime U: type) type {
11141114 }
11151115 };
11161116 _ = @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);
11181118 }
11191119
11201120 /// Blocks until another task of the select finishes.
......@@ -1542,9 +1542,9 @@ pub fn async(
15421542 var future: Future(Result) = undefined;
15431543 future.any_future = io.vtable.async(
15441544 io.userdata,
1545 @ptrCast((&future.result)[0..1]),
1545 @ptrCast(&future.result),
15461546 .of(Result),
1547 @ptrCast((&args)[0..1]),
1547 @ptrCast(&args),
15481548 .of(Args),
15491549 TypeErased.start,
15501550 );
......@@ -1583,7 +1583,7 @@ pub fn concurrent(
15831583 io.userdata,
15841584 @sizeOf(Result),
15851585 .of(Result),
1586 @ptrCast((&args)[0..1]),
1586 @ptrCast(&args),
15871587 .of(Args),
15881588 TypeErased.start,
15891589 );
lib/std/Io/Threaded/test.zig+14
......@@ -115,3 +115,17 @@ test "Group.async context alignment" {
115115 group.wait(io);
116116 try std.testing.expectEqualSlices(u8, &expected.x, &result.x);
117117}
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}