Skip to content

Commit a00a915

Browse files
committed
std.Io: fix calls on functions that return an array type
1 parent 521daf4 commit a00a915

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

lib/std/Io.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -990,15 +990,15 @@ pub fn Future(Result: type) type {
990990
/// Idempotent. Not threadsafe.
991991
pub fn cancel(f: *@This(), io: Io) Result {
992992
const any_future = f.any_future orelse return f.result;
993-
io.vtable.cancel(io.userdata, any_future, @ptrCast((&f.result)[0..1]), .of(Result));
993+
io.vtable.cancel(io.userdata, any_future, @ptrCast(&f.result), .of(Result));
994994
f.any_future = null;
995995
return f.result;
996996
}
997997

998998
/// Idempotent. Not threadsafe.
999999
pub fn await(f: *@This(), io: Io) Result {
10001000
const any_future = f.any_future orelse return f.result;
1001-
io.vtable.await(io.userdata, any_future, @ptrCast((&f.result)[0..1]), .of(Result));
1001+
io.vtable.await(io.userdata, any_future, @ptrCast(&f.result), .of(Result));
10021002
f.any_future = null;
10031003
return f.result;
10041004
}
@@ -1034,7 +1034,7 @@ pub const Group = struct {
10341034
@call(.auto, function, args_casted.*);
10351035
}
10361036
};
1037-
io.vtable.groupAsync(io.userdata, g, @ptrCast((&args)[0..1]), .of(Args), TypeErased.start);
1037+
io.vtable.groupAsync(io.userdata, g, @ptrCast(&args), .of(Args), TypeErased.start);
10381038
}
10391039

10401040
/// Blocks until all tasks of the group finish. During this time,
@@ -1111,7 +1111,7 @@ pub fn Select(comptime U: type) type {
11111111
}
11121112
};
11131113
_ = @atomicRmw(usize, &s.outstanding, .Add, 1, .monotonic);
1114-
s.io.vtable.groupAsync(s.io.userdata, &s.group, @ptrCast((&args)[0..1]), .of(Args), TypeErased.start);
1114+
s.io.vtable.groupAsync(s.io.userdata, &s.group, @ptrCast(&args), .of(Args), TypeErased.start);
11151115
}
11161116

11171117
/// Blocks until another task of the select finishes.
@@ -1539,9 +1539,9 @@ pub fn async(
15391539
var future: Future(Result) = undefined;
15401540
future.any_future = io.vtable.async(
15411541
io.userdata,
1542-
@ptrCast((&future.result)[0..1]),
1542+
@ptrCast(&future.result),
15431543
.of(Result),
1544-
@ptrCast((&args)[0..1]),
1544+
@ptrCast(&args),
15451545
.of(Args),
15461546
TypeErased.start,
15471547
);
@@ -1580,7 +1580,7 @@ pub fn concurrent(
15801580
io.userdata,
15811581
@sizeOf(Result),
15821582
.of(Result),
1583-
@ptrCast((&args)[0..1]),
1583+
@ptrCast(&args),
15841584
.of(Args),
15851585
TypeErased.start,
15861586
);

lib/std/Io/Threaded/test.zig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,19 @@ test "group closure where context has extra alignment" {
106106

107107
group.async(io, paramWithExtraAlignment, .{.{ .data = 3 }});
108108
}
109+
110+
fn returnArray() [32]u8 {
111+
return @splat(5);
112+
}
113+
114+
test "async on function with array parameter or return type" {
115+
var threaded: std.Io.Threaded = .init(std.testing.allocator);
116+
defer threaded.deinit();
117+
const io = threaded.io();
118+
119+
var future = io.async(returnArray, .{});
120+
const result = future.await(io);
121+
for (result) |actual| {
122+
try std.testing.expectEqual(5, actual);
123+
}
124+
}

0 commit comments

Comments
 (0)