diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2021-10-06 00:27:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-06 00:27:05 +0200 |
commit | 3faf75aa883647dfa1f3be2bc13cf7bc463d92e1 (patch) | |
tree | edb141ebe411a348abe068c014828606e6614d93 /test_ffi/src | |
parent | 58bb63f355085bc8dbd845f1cae688e5ce453eec (diff) |
feat(ext/ffi): add support for buffer arguments (#12335)
This commit adds support for passing buffer arguments across
FFI boundary.
Co-authored-by: eliassjogreen <eliassjogreen1@gmail.com>
Co-authored-by: Bert Belder <bertbelder@gmail.com>
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]); +} |