mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-18 17:10:52 +00:00
doc(runtime-core) Write more documentation.
This commit is contained in:
parent
0f82cd3c40
commit
293b71ac54
@ -547,6 +547,7 @@ impl ImportBacking {
|
||||
|
||||
impl Drop for ImportBacking {
|
||||
fn drop(&mut self) {
|
||||
// Properly drop the `vm::FuncCtx` in `vm::ImportedFunc`.
|
||||
for (_imported_func_index, imported_func) in (*self.vm_functions).iter_mut() {
|
||||
let _: Box<vm::FuncCtx> = unsafe { Box::from_raw(imported_func.func_ctx.as_ptr()) };
|
||||
}
|
||||
@ -587,12 +588,17 @@ fn import_functions(
|
||||
functions.push(vm::ImportedFunc {
|
||||
func: func.inner(),
|
||||
func_ctx: NonNull::new(Box::into_raw(Box::new(vm::FuncCtx {
|
||||
// ^^^^^^^^ `vm::FuncCtx` is purposely leaked.
|
||||
// It is dropped by the specific `Drop`
|
||||
// implementation of `ImportBacking`.
|
||||
vmctx: NonNull::new(vmctx).expect("`vmctx` must not be null."),
|
||||
func_env: match ctx {
|
||||
Context::External(ctx) => {
|
||||
NonNull::new(ctx).map(|pointer| {
|
||||
pointer.cast() // `*mut vm::FuncEnv` was casted to `*mut vm::Ctx` to fit in `Context::External`. Cast it back.
|
||||
})
|
||||
NonNull::new(ctx).map(NonNull::cast)
|
||||
// ^^^^^^^^^^^^^
|
||||
// `*mut vm::FuncEnv` was casted to
|
||||
// `*mut vm::Ctx` to fit in
|
||||
// `Context::External`. Cast it back.
|
||||
}
|
||||
Context::Internal => None,
|
||||
},
|
||||
|
@ -725,6 +725,10 @@ where
|
||||
let func = unsafe { FuncPointer::new(self.func.as_ptr()) };
|
||||
let ctx = match self.func_env {
|
||||
Some(func_env) => Context::External(func_env.cast().as_ptr()),
|
||||
// ^^^^^^
|
||||
// `Context::External` expects a `vm::Ctx`.
|
||||
// Casting to `vm::FuncCtx` happens in the
|
||||
// `backing` module.
|
||||
None => Context::Internal,
|
||||
};
|
||||
let signature = Arc::new(FuncSig::new(Args::types(), Rets::types()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user