diff options
Diffstat (limited to 'test_ffi/src')
-rw-r--r-- | test_ffi/src/lib.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test_ffi/src/lib.rs b/test_ffi/src/lib.rs index c91d05e05..cc6063ca3 100644 --- a/test_ffi/src/lib.rs +++ b/test_ffi/src/lib.rs @@ -1,3 +1,5 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. + use std::thread::sleep; use std::time::Duration; @@ -6,6 +8,13 @@ pub extern "C" fn print_something() { println!("something"); } +#[allow(clippy::not_unsafe_ptr_arg_deref)] +#[no_mangle] +pub extern "C" fn print_buffer(ptr: *const u8, len: usize) { + let buf = unsafe { std::slice::from_raw_parts(ptr, len) }; + println!("{:?}", buf); +} + #[no_mangle] pub extern "C" fn add_u32(a: u32, b: u32) -> u32 { a + b @@ -51,3 +60,10 @@ pub extern "C" fn sleep_blocking(ms: u64) { let duration = Duration::from_millis(ms); sleep(duration); } + +#[allow(clippy::not_unsafe_ptr_arg_deref)] +#[no_mangle] +pub extern "C" fn nonblocking_buffer(ptr: *const u8, len: usize) { + let buf = unsafe { std::slice::from_raw_parts(ptr, len) }; + assert_eq!(buf, vec![1, 2, 3, 4, 5, 6, 7, 8]); +} |