pub struct Cif { /* private fields */ }
Expand description
Describes the calling convention and types for calling a function.
This is the middle
layer’s wrapping of the low
and raw
layers’
ffi_cif
. An initialized CIF contains
references to an array of argument types and a result type, each of
which may be allocated on the heap. Cif
manages the memory of
those referenced objects.
Construct with Cif::new
or
Cif::from_type_array
.
§Examples
extern "C" fn add(x: f64, y: &f64) -> f64 {
return x + y;
}
use deno_libffi::middle::*;
let args = vec![Type::f64(), Type::pointer()];
let cif = Cif::new(args.into_iter(), Type::f64());
let n = unsafe { cif.call(CodePtr(add as *mut _), &[arg(&5f64), arg(&&6f64)]) };
assert_eq!(11f64, n);
Implementations§
Source§impl Cif
impl Cif
Sourcepub unsafe fn call<R>(&self, fun: CodePtr, args: &[Arg]) -> R
pub unsafe fn call<R>(&self, fun: CodePtr, args: &[Arg]) -> R
Calls a function with the given arguments.
In particular, this method invokes function fun
passing it
arguments args
, and returns the result.
§Safety
There is no checking that the calling convention and types
in the Cif
match the actual calling convention and types of
fun
, nor that they match the types of args
.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Cif
impl RefUnwindSafe for Cif
impl !Send for Cif
impl !Sync for Cif
impl Unpin for Cif
impl UnwindSafe for Cif
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more