mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-28 08:01:33 +00:00
doc(runtime-core) Write more documentation.
This commit is contained in:
@ -547,6 +547,7 @@ impl ImportBacking {
|
|||||||
|
|
||||||
impl Drop for ImportBacking {
|
impl Drop for ImportBacking {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
|
// Properly drop the `vm::FuncCtx` in `vm::ImportedFunc`.
|
||||||
for (_imported_func_index, imported_func) in (*self.vm_functions).iter_mut() {
|
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()) };
|
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 {
|
functions.push(vm::ImportedFunc {
|
||||||
func: func.inner(),
|
func: func.inner(),
|
||||||
func_ctx: NonNull::new(Box::into_raw(Box::new(vm::FuncCtx {
|
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."),
|
vmctx: NonNull::new(vmctx).expect("`vmctx` must not be null."),
|
||||||
func_env: match ctx {
|
func_env: match ctx {
|
||||||
Context::External(ctx) => {
|
Context::External(ctx) => {
|
||||||
NonNull::new(ctx).map(|pointer| {
|
NonNull::new(ctx).map(NonNull::cast)
|
||||||
pointer.cast() // `*mut vm::FuncEnv` was casted to `*mut vm::Ctx` to fit in `Context::External`. Cast it back.
|
// ^^^^^^^^^^^^^
|
||||||
})
|
// `*mut vm::FuncEnv` was casted to
|
||||||
|
// `*mut vm::Ctx` to fit in
|
||||||
|
// `Context::External`. Cast it back.
|
||||||
}
|
}
|
||||||
Context::Internal => None,
|
Context::Internal => None,
|
||||||
},
|
},
|
||||||
|
@ -725,6 +725,10 @@ where
|
|||||||
let func = unsafe { FuncPointer::new(self.func.as_ptr()) };
|
let func = unsafe { FuncPointer::new(self.func.as_ptr()) };
|
||||||
let ctx = match self.func_env {
|
let ctx = match self.func_env {
|
||||||
Some(func_env) => Context::External(func_env.cast().as_ptr()),
|
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,
|
None => Context::Internal,
|
||||||
};
|
};
|
||||||
let signature = Arc::new(FuncSig::new(Args::types(), Rets::types()));
|
let signature = Arc::new(FuncSig::new(Args::types(), Rets::types()));
|
||||||
|
Reference in New Issue
Block a user