authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-05 02:17:53-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-05 02:17:53-07:00
log9292ded5a3b8c82ae731bb18d40c69b7e40177f8
tree154bceeaf82e3e96caab244932939dbc7e34a4d3
parente73257dec2d997e9d573419178695992790a9525

std.Io.Batch: fix add function

closes #31730 closes #31757

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

lib/std/Io.zig+2-2
......@@ -500,8 +500,8 @@ pub const Batch = struct {
500500 /// Returns the index that will be returned by `next` after the operation completes.
501501 /// Asserts that no more than `storage.len` operations are active at a time.
502502 pub fn add(batch: *Batch, operation: Operation) u32 {
503 const index = batch.unused.next;
504 batch.addAt(index.toIndex(), operation);
503 const index = batch.unused.head.toIndex();
504 batch.addAt(index, operation);
505505 return index;
506506 }
507507
lib/std/Io/test.zig+5-4
......@@ -692,14 +692,15 @@ test "read from a file using Batch.awaitAsync API" {
692692 var storage: [2]Io.Operation.Storage = undefined;
693693 var batch: Io.Batch = .init(&storage);
694694
695 batch.addAt(0, .{ .file_read_streaming = .{
695 // Tests add API because this provides coverage for both add and addAt.
696 try testing.expectEqual(0, batch.add(.{ .file_read_streaming = .{
696697 .file = eyes_file,
697698 .data = &.{&eyes_buf},
698 } });
699 batch.addAt(1, .{ .file_read_streaming = .{
699 } }));
700 try testing.expectEqual(1, batch.add(.{ .file_read_streaming = .{
700701 .file = saviour_file,
701702 .data = &.{&saviour_buf},
702 } });
703 } }));
703704
704705 // This API is supposed to *always* work even if the target has no
705706 // concurrency primitives available.