mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-25 22:51:32 +00:00
fix(runtime-c-api) Fix imports, and check for null pointer.
This commit is contained in:
@ -3,15 +3,14 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
error::{update_last_error, CApiError},
|
error::{update_last_error, CApiError},
|
||||||
export::{wasmer_exports_t, wasmer_import_export_kind, NamedExport, NamedExports},
|
export::{wasmer_exports_t, wasmer_import_export_kind, NamedExport, NamedExports},
|
||||||
import::{wasmer_import_object_t, wasmer_import_t},
|
import::wasmer_import_t,
|
||||||
memory::wasmer_memory_t,
|
memory::wasmer_memory_t,
|
||||||
module::wasmer_module_t,
|
|
||||||
value::{wasmer_value, wasmer_value_t, wasmer_value_tag},
|
value::{wasmer_value, wasmer_value_t, wasmer_value_tag},
|
||||||
wasmer_result_t,
|
wasmer_result_t,
|
||||||
};
|
};
|
||||||
use libc::{c_char, c_int, c_void};
|
use libc::{c_char, c_int, c_void};
|
||||||
use std::{collections::HashMap, ffi::CStr, slice};
|
use std::{collections::HashMap, ffi::CStr, ptr, slice};
|
||||||
use wasmer_runtime::{Ctx, Global, Instance, Memory, Module, Table, Value};
|
use wasmer_runtime::{Ctx, Global, Instance, Memory, Table, Value};
|
||||||
use wasmer_runtime_core::{
|
use wasmer_runtime_core::{
|
||||||
export::Export,
|
export::Export,
|
||||||
import::{ImportObject, Namespace},
|
import::{ImportObject, Namespace},
|
||||||
@ -187,14 +186,17 @@ pub unsafe extern "C" fn wasmer_instantiate(
|
|||||||
/// It is often useful with `wasmer_instance_context_data_set()`.
|
/// It is often useful with `wasmer_instance_context_data_set()`.
|
||||||
#[allow(clippy::cast_ptr_alignment)]
|
#[allow(clippy::cast_ptr_alignment)]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn wasmer_instance_context_get(
|
pub extern "C" fn wasmer_instance_context_get(
|
||||||
instance: *mut wasmer_instance_t,
|
instance: *mut wasmer_instance_t,
|
||||||
) -> *const wasmer_instance_context_t {
|
) -> *const wasmer_instance_context_t {
|
||||||
let instance_ref = &*(instance as *const Instance);
|
if instance.is_null() {
|
||||||
|
return ptr::null() as _;
|
||||||
|
}
|
||||||
|
|
||||||
let ctx: *const Ctx = instance_ref.context() as *const _;
|
let instance = unsafe { &*(instance as *const Instance) };
|
||||||
|
let context: *const Ctx = instance.context() as *const _;
|
||||||
|
|
||||||
ctx as *const wasmer_instance_context_t
|
context as *const wasmer_instance_context_t
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calls an instances exported function by `name` with the provided parameters.
|
/// Calls an instances exported function by `name` with the provided parameters.
|
||||||
|
@ -3,13 +3,15 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
error::{update_last_error, CApiError},
|
error::{update_last_error, CApiError},
|
||||||
export::wasmer_import_export_kind,
|
export::wasmer_import_export_kind,
|
||||||
import::wasmer_import_t,
|
import::{wasmer_import_object_t, wasmer_import_t},
|
||||||
instance::wasmer_instance_t,
|
instance::wasmer_instance_t,
|
||||||
wasmer_byte_array, wasmer_result_t,
|
wasmer_byte_array, wasmer_result_t,
|
||||||
};
|
};
|
||||||
use libc::c_int;
|
use libc::c_int;
|
||||||
use std::{collections::HashMap, slice};
|
use std::{collections::HashMap, slice};
|
||||||
use wasmer_runtime::{compile, default_compiler, Global, ImportObject, Memory, Module, Table};
|
use wasmer_runtime::{
|
||||||
|
compile, default_compiler, Global, ImportObject, Instance, Memory, Module, Table,
|
||||||
|
};
|
||||||
use wasmer_runtime_core::{cache::Artifact, export::Export, import::Namespace, load_cache_with};
|
use wasmer_runtime_core::{cache::Artifact, export::Export, import::Namespace, load_cache_with};
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
Reference in New Issue
Block a user