Correctly unpack &mut [T] into *mut T and usize

This commit is contained in:
Jakub Konka
2019-05-14 16:52:01 +02:00
committed by Dan Gohman
parent 006198eb92
commit 52eda1498a
7 changed files with 52 additions and 11 deletions

View File

@@ -0,0 +1,20 @@
extern crate wasi_common_cbindgen;
pub use wasi_common_cbindgen::wasi_common_cbindgen;
#[wasi_common_cbindgen]
fn array_args(a: &mut [u8]) {
a[0] = 1;
}
fn main() {
let mut expected: &mut [u8] = &mut [0, 0];
array_args(&mut expected);
let given: &mut [u8] = &mut [0, 0];
unsafe {
__wasi_array_args(given.as_mut_ptr(), given.len());
}
assert_eq!(given, expected);
}

View File

@@ -17,4 +17,4 @@ fn main() {
Box::from_raw(raw)
};
assert_eq!(*given, *expected);
}
}

View File

@@ -17,4 +17,4 @@ fn main() {
res
};
assert_eq!(given, expected);
}
}

View File

@@ -5,4 +5,5 @@ fn tests() {
t.pass("tests/val_args.rs");
t.pass("tests/ref_args.rs");
t.pass("tests/mut_args.rs");
}
t.pass("tests/array_args.rs");
}

View File

@@ -9,4 +9,4 @@ fn val_args(a: usize, b: usize) -> usize {
fn main() {
assert_eq!(unsafe { __wasi_val_args(1, 2) }, val_args(1, 2));
}
}