mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
test(ext/ffi): add test for multiple buffers (#12373)
This commit is contained in:
parent
29f9e14457
commit
76de56091b
3 changed files with 22 additions and 2 deletions
|
@ -15,6 +15,19 @@ pub extern "C" fn print_buffer(ptr: *const u8, len: usize) {
|
|||
println!("{:?}", buf);
|
||||
}
|
||||
|
||||
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn print_buffer2(
|
||||
ptr1: *const u8,
|
||||
len1: usize,
|
||||
ptr2: *const u8,
|
||||
len2: usize,
|
||||
) {
|
||||
let buf1 = unsafe { std::slice::from_raw_parts(ptr1, len1) };
|
||||
let buf2 = unsafe { std::slice::from_raw_parts(ptr2, len2) };
|
||||
println!("{:?} {:?}", buf1, buf2);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn add_u32(a: u32, b: u32) -> u32 {
|
||||
a + b
|
||||
|
|
|
@ -40,6 +40,7 @@ fn basic() {
|
|||
dlopen doesn't panic\n\
|
||||
something\n\
|
||||
[1, 2, 3, 4, 5, 6, 7, 8]\n\
|
||||
[1, 2, 3, 4, 5, 6, 7, 8] [9, 10]\n\
|
||||
579\n\
|
||||
579\n\
|
||||
579\n\
|
||||
|
|
|
@ -21,6 +21,10 @@ try {
|
|||
const dylib = Deno.dlopen(libPath, {
|
||||
"print_something": { parameters: [], result: "void" },
|
||||
"print_buffer": { parameters: ["buffer", "usize"], result: "void" },
|
||||
"print_buffer2": {
|
||||
parameters: ["buffer", "usize", "buffer", "usize"],
|
||||
result: "void",
|
||||
},
|
||||
"add_u32": { parameters: ["u32", "u32"], result: "u32" },
|
||||
"add_i32": { parameters: ["i32", "i32"], result: "i32" },
|
||||
"add_u64": { parameters: ["u64", "u64"], result: "u64" },
|
||||
|
@ -39,7 +43,9 @@ const dylib = Deno.dlopen(libPath, {
|
|||
|
||||
dylib.symbols.print_something();
|
||||
const buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
const buffer2 = new Uint8Array([9, 10]);
|
||||
dylib.symbols.print_buffer(buffer, buffer.length);
|
||||
dylib.symbols.print_buffer2(buffer, buffer.length, buffer2, buffer2.length);
|
||||
console.log(dylib.symbols.add_u32(123, 456));
|
||||
console.log(dylib.symbols.add_i32(123, 456));
|
||||
console.log(dylib.symbols.add_u64(123, 456));
|
||||
|
@ -68,8 +74,8 @@ function deferred() {
|
|||
}
|
||||
|
||||
const promise = deferred();
|
||||
const buffer2 = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
dylib.symbols.nonblocking_buffer(buffer2, buffer2.length).then(() => {
|
||||
const buffer3 = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
dylib.symbols.nonblocking_buffer(buffer3, buffer3.length).then(() => {
|
||||
promise.resolve();
|
||||
});
|
||||
await promise;
|
||||
|
|
Loading…
Reference in a new issue