Skip to content

Commit 0351a08

Browse files
committed
If poll_oneoff fails part-way through, clean up properly.
Fix the `Drop` implementation for pollables to only drop the pollables that have been successfully added to the list. This fixes the poll_oneoff_files failure and removes a FIXME.
1 parent e677820 commit 0351a08

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

crates/test-programs/wasi-tests/src/bin/poll_oneoff_files.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ unsafe fn test_poll_oneoff(dir_fd: wasi::Fd) {
261261
test_sleep();
262262
test_empty_poll();
263263
test_fd_readwrite_valid_fd(dir_fd);
264-
//test_fd_readwrite_invalid_fd(); // FIXME: This traps now, rather than failing
264+
test_fd_readwrite_invalid_fd();
265265
}
266266
fn main() {
267267
let mut args = env::args();

crates/wasi-preview1-component-adapter/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1645,9 +1645,10 @@ impl Pollables {
16451645
// after the call.
16461646
impl Drop for Pollables {
16471647
fn drop(&mut self) {
1648-
for i in 0..self.length {
1648+
while self.index != 0 {
1649+
self.index -= 1;
16491650
unsafe {
1650-
core::ptr::drop_in_place(self.pointer.add(i));
1651+
core::ptr::drop_in_place(self.pointer.add(self.index));
16511652
}
16521653
}
16531654
}

crates/wasi-preview1-component-adapter/src/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
//! We're avoiding static initializers, so we can't have things like string
44
//! literals. Replace the standard assert macros with simpler implementations.
55
6-
use crate::bindings::wasi::io::streams;
76
use crate::bindings::wasi::cli::stderr::get_stderr;
7+
use crate::bindings::wasi::io::streams;
88

99
#[allow(dead_code)]
1010
#[doc(hidden)]

0 commit comments

Comments
 (0)