Correctly unpack &mut [T] into *mut T and usize
This commit is contained in:
20
wasi-common-cbindgen/tests/array_args.rs
Normal file
20
wasi-common-cbindgen/tests/array_args.rs
Normal 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);
|
||||
}
|
||||
@@ -17,4 +17,4 @@ fn main() {
|
||||
Box::from_raw(raw)
|
||||
};
|
||||
assert_eq!(*given, *expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,4 +17,4 @@ fn main() {
|
||||
res
|
||||
};
|
||||
assert_eq!(given, expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user