mirror of
https://github.com/fluencelabs/wasmer
synced 2025-07-31 23:32:04 +00:00
fix(runtime-c-api) Remove unsafe blocks inside unsafe function.
This patch removes `unsafe { … }` blocks inside `unsafe` functions. This patch also removes some warnings about camel case. All structures with a C representation are automatically not mangle, and allow non camel case.
This commit is contained in:
@@ -17,23 +17,23 @@ use wasmer_runtime_core::module::{ExportIndex, ImportName};
|
|||||||
use wasmer_runtime_core::types::{ElementType, FuncSig, MemoryDescriptor, TableDescriptor, Type};
|
use wasmer_runtime_core::types::{ElementType, FuncSig, MemoryDescriptor, TableDescriptor, Type};
|
||||||
use wasmer_runtime_core::units::{Bytes, Pages};
|
use wasmer_runtime_core::units::{Bytes, Pages};
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[repr(C)]
|
||||||
pub struct wasmer_module_t();
|
pub struct wasmer_module_t;
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct wasmer_instance_t;
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct wasmer_instance_context_t;
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
pub struct wasmer_instance_t();
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
pub struct wasmer_instance_context_t();
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
#[no_mangle]
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub enum wasmer_result_t {
|
pub enum wasmer_result_t {
|
||||||
WASMER_OK = 1,
|
WASMER_OK = 1,
|
||||||
WASMER_ERROR = 2,
|
WASMER_ERROR = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum wasmer_value_tag {
|
pub enum wasmer_value_tag {
|
||||||
@@ -68,23 +68,23 @@ pub struct wasmer_global_descriptor_t {
|
|||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct wasmer_memory_t();
|
pub struct wasmer_memory_t;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct wasmer_table_t();
|
pub struct wasmer_table_t;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct wasmer_import_func_t();
|
pub struct wasmer_import_func_t;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct wasmer_export_func_t();
|
pub struct wasmer_export_func_t;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct wasmer_global_t();
|
pub struct wasmer_global_t;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct wasmer_limits_t {
|
pub struct wasmer_limits_t {
|
||||||
@@ -130,6 +130,7 @@ pub struct wasmer_export_descriptor_t;
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct wasmer_export_descriptors_t;
|
pub struct wasmer_export_descriptors_t;
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum wasmer_import_export_kind {
|
pub enum wasmer_import_export_kind {
|
||||||
@@ -164,8 +165,7 @@ pub unsafe extern "C" fn wasmer_validate(
|
|||||||
if wasm_bytes.is_null() {
|
if wasm_bytes.is_null() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let bytes: &[u8] =
|
let bytes: &[u8] = ::std::slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize);
|
||||||
unsafe { ::std::slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize) };
|
|
||||||
wasmer_runtime_core::validate(bytes)
|
wasmer_runtime_core::validate(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +201,7 @@ pub unsafe extern "C" fn wasmer_memory_new(
|
|||||||
return wasmer_result_t::WASMER_ERROR;
|
return wasmer_result_t::WASMER_ERROR;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
unsafe { *memory = Box::into_raw(Box::new(new_memory)) as *mut wasmer_memory_t };
|
*memory = Box::into_raw(Box::new(new_memory)) as *mut wasmer_memory_t;
|
||||||
wasmer_result_t::WASMER_OK
|
wasmer_result_t::WASMER_OK
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,7 +269,7 @@ pub unsafe extern "C" fn wasmer_table_new(
|
|||||||
return wasmer_result_t::WASMER_ERROR;
|
return wasmer_result_t::WASMER_ERROR;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
unsafe { *table = Box::into_raw(Box::new(new_table)) as *mut wasmer_table_t };
|
*table = Box::into_raw(Box::new(new_table)) as *mut wasmer_table_t;
|
||||||
wasmer_result_t::WASMER_OK
|
wasmer_result_t::WASMER_OK
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,7 +326,7 @@ pub unsafe extern "C" fn wasmer_global_new(
|
|||||||
} else {
|
} else {
|
||||||
Global::new(value.into())
|
Global::new(value.into())
|
||||||
};
|
};
|
||||||
unsafe { Box::into_raw(Box::new(global)) as *mut wasmer_global_t }
|
Box::into_raw(Box::new(global)) as *mut wasmer_global_t
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the value stored by the given Global
|
/// Gets the value stored by the given Global
|
||||||
@@ -392,8 +392,7 @@ pub unsafe extern "C" fn wasmer_compile(
|
|||||||
wasm_bytes: *mut uint8_t,
|
wasm_bytes: *mut uint8_t,
|
||||||
wasm_bytes_len: uint32_t,
|
wasm_bytes_len: uint32_t,
|
||||||
) -> wasmer_result_t {
|
) -> wasmer_result_t {
|
||||||
let bytes: &[u8] =
|
let bytes: &[u8] = ::std::slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize);
|
||||||
unsafe { ::std::slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize) };
|
|
||||||
let result = wasmer_runtime::compile(bytes);
|
let result = wasmer_runtime::compile(bytes);
|
||||||
let new_module = match result {
|
let new_module = match result {
|
||||||
Ok(instance) => instance,
|
Ok(instance) => instance,
|
||||||
@@ -402,7 +401,7 @@ pub unsafe extern "C" fn wasmer_compile(
|
|||||||
return wasmer_result_t::WASMER_ERROR;
|
return wasmer_result_t::WASMER_ERROR;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
unsafe { *module = Box::into_raw(Box::new(new_module)) as *mut wasmer_module_t };
|
*module = Box::into_raw(Box::new(new_module)) as *mut wasmer_module_t;
|
||||||
wasmer_result_t::WASMER_OK
|
wasmer_result_t::WASMER_OK
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,7 +476,7 @@ pub unsafe extern "C" fn wasmer_module_instantiate(
|
|||||||
import_object.register(module_name, namespace);
|
import_object.register(module_name, namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
let module = unsafe { &*(module as *mut Module) };
|
let module = &*(module as *mut Module);
|
||||||
let new_instance = if let Ok(res) = module.instantiate(&import_object) {
|
let new_instance = if let Ok(res) = module.instantiate(&import_object) {
|
||||||
res
|
res
|
||||||
} else {
|
} else {
|
||||||
@@ -486,7 +485,7 @@ pub unsafe extern "C" fn wasmer_module_instantiate(
|
|||||||
});
|
});
|
||||||
return wasmer_result_t::WASMER_ERROR;
|
return wasmer_result_t::WASMER_ERROR;
|
||||||
};
|
};
|
||||||
unsafe { *instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t };
|
*instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t;
|
||||||
wasmer_result_t::WASMER_OK
|
wasmer_result_t::WASMER_OK
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,15 +498,12 @@ pub unsafe extern "C" fn wasmer_export_descriptors(
|
|||||||
module: *mut wasmer_module_t,
|
module: *mut wasmer_module_t,
|
||||||
export_descriptors: *mut *mut wasmer_export_descriptors_t,
|
export_descriptors: *mut *mut wasmer_export_descriptors_t,
|
||||||
) {
|
) {
|
||||||
let mut module = unsafe { &*(module as *mut Module) };
|
let mut module = &*(module as *mut Module);
|
||||||
|
|
||||||
let named_export_descriptors: Box<NamedExportDescriptors> = Box::new(NamedExportDescriptors(
|
let named_export_descriptors: Box<NamedExportDescriptors> = Box::new(NamedExportDescriptors(
|
||||||
module.info().exports.iter().map(|e| e.into()).collect(),
|
module.info().exports.iter().map(|e| e.into()).collect(),
|
||||||
));
|
));
|
||||||
unsafe {
|
*export_descriptors = Box::into_raw(named_export_descriptors) as *mut wasmer_export_descriptors_t;
|
||||||
*export_descriptors =
|
|
||||||
Box::into_raw(named_export_descriptors) as *mut wasmer_export_descriptors_t
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct NamedExportDescriptors(Vec<NamedExportDescriptor>);
|
pub struct NamedExportDescriptors(Vec<NamedExportDescriptor>);
|
||||||
@@ -519,7 +515,7 @@ pub unsafe extern "C" fn wasmer_export_descriptors_destroy(
|
|||||||
export_descriptors: *mut wasmer_export_descriptors_t,
|
export_descriptors: *mut wasmer_export_descriptors_t,
|
||||||
) {
|
) {
|
||||||
if !export_descriptors.is_null() {
|
if !export_descriptors.is_null() {
|
||||||
drop(unsafe { Box::from_raw(export_descriptors as *mut NamedExportDescriptors) });
|
drop(Box::from_raw(export_descriptors as *mut NamedExportDescriptors));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -546,7 +542,7 @@ pub unsafe extern "C" fn wasmer_export_descriptors_get(
|
|||||||
return ptr::null_mut();
|
return ptr::null_mut();
|
||||||
}
|
}
|
||||||
let mut named_export_descriptors =
|
let mut named_export_descriptors =
|
||||||
unsafe { &mut *(export_descriptors as *mut NamedExportDescriptors) };
|
&mut *(export_descriptors as *mut NamedExportDescriptors);
|
||||||
let ptr = &mut (*named_export_descriptors).0[idx as usize] as *mut NamedExportDescriptor
|
let ptr = &mut (*named_export_descriptors).0[idx as usize] as *mut NamedExportDescriptor
|
||||||
as *mut wasmer_export_descriptor_t;
|
as *mut wasmer_export_descriptor_t;
|
||||||
ptr
|
ptr
|
||||||
@@ -593,7 +589,7 @@ pub unsafe extern "C" fn wasmer_import_descriptors(
|
|||||||
module: *mut wasmer_module_t,
|
module: *mut wasmer_module_t,
|
||||||
import_descriptors: *mut *mut wasmer_import_descriptors_t,
|
import_descriptors: *mut *mut wasmer_import_descriptors_t,
|
||||||
) {
|
) {
|
||||||
let mut module = unsafe { &*(module as *mut Module) };
|
let mut module = &*(module as *mut Module);
|
||||||
let total_imports = module.info().imported_functions.len()
|
let total_imports = module.info().imported_functions.len()
|
||||||
+ module.info().imported_tables.len()
|
+ module.info().imported_tables.len()
|
||||||
+ module.info().imported_globals.len()
|
+ module.info().imported_globals.len()
|
||||||
@@ -601,7 +597,7 @@ pub unsafe extern "C" fn wasmer_import_descriptors(
|
|||||||
let mut descriptors: Vec<NamedImportDescriptor> = Vec::with_capacity(total_imports);
|
let mut descriptors: Vec<NamedImportDescriptor> = Vec::with_capacity(total_imports);
|
||||||
|
|
||||||
for (
|
for (
|
||||||
index,
|
_index,
|
||||||
ImportName {
|
ImportName {
|
||||||
namespace_index,
|
namespace_index,
|
||||||
name_index,
|
name_index,
|
||||||
@@ -618,7 +614,7 @@ pub unsafe extern "C" fn wasmer_import_descriptors(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (
|
for (
|
||||||
index,
|
_index,
|
||||||
(
|
(
|
||||||
ImportName {
|
ImportName {
|
||||||
namespace_index,
|
namespace_index,
|
||||||
@@ -638,7 +634,7 @@ pub unsafe extern "C" fn wasmer_import_descriptors(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (
|
for (
|
||||||
index,
|
_index,
|
||||||
(
|
(
|
||||||
ImportName {
|
ImportName {
|
||||||
namespace_index,
|
namespace_index,
|
||||||
@@ -658,7 +654,7 @@ pub unsafe extern "C" fn wasmer_import_descriptors(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (
|
for (
|
||||||
index,
|
_index,
|
||||||
(
|
(
|
||||||
ImportName {
|
ImportName {
|
||||||
namespace_index,
|
namespace_index,
|
||||||
@@ -679,10 +675,8 @@ pub unsafe extern "C" fn wasmer_import_descriptors(
|
|||||||
|
|
||||||
let named_import_descriptors: Box<NamedImportDescriptors> =
|
let named_import_descriptors: Box<NamedImportDescriptors> =
|
||||||
Box::new(NamedImportDescriptors(descriptors));
|
Box::new(NamedImportDescriptors(descriptors));
|
||||||
unsafe {
|
*import_descriptors =
|
||||||
*import_descriptors =
|
Box::into_raw(named_import_descriptors) as *mut wasmer_import_descriptors_t;
|
||||||
Box::into_raw(named_import_descriptors) as *mut wasmer_import_descriptors_t
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct NamedImportDescriptors(Vec<NamedImportDescriptor>);
|
pub struct NamedImportDescriptors(Vec<NamedImportDescriptor>);
|
||||||
@@ -694,7 +688,7 @@ pub unsafe extern "C" fn wasmer_import_descriptors_destroy(
|
|||||||
import_descriptors: *mut wasmer_import_descriptors_t,
|
import_descriptors: *mut wasmer_import_descriptors_t,
|
||||||
) {
|
) {
|
||||||
if !import_descriptors.is_null() {
|
if !import_descriptors.is_null() {
|
||||||
drop(unsafe { Box::from_raw(import_descriptors as *mut NamedImportDescriptors) });
|
drop(Box::from_raw(import_descriptors as *mut NamedImportDescriptors));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -721,7 +715,7 @@ pub unsafe extern "C" fn wasmer_import_descriptors_get(
|
|||||||
return ptr::null_mut();
|
return ptr::null_mut();
|
||||||
}
|
}
|
||||||
let mut named_import_descriptors =
|
let mut named_import_descriptors =
|
||||||
unsafe { &mut *(import_descriptors as *mut NamedImportDescriptors) };
|
&mut *(import_descriptors as *mut NamedImportDescriptors);
|
||||||
let ptr = &mut (*named_import_descriptors).0[idx as usize] as *mut NamedImportDescriptor
|
let ptr = &mut (*named_import_descriptors).0[idx as usize] as *mut NamedImportDescriptor
|
||||||
as *mut wasmer_import_descriptor_t;
|
as *mut wasmer_import_descriptor_t;
|
||||||
ptr
|
ptr
|
||||||
@@ -835,18 +829,17 @@ pub unsafe extern "C" fn wasmer_instantiate(
|
|||||||
Export::Table((&*table).clone())
|
Export::Table((&*table).clone())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
namespace.insert(import_name, unsafe { export });
|
namespace.insert(import_name, export);
|
||||||
}
|
}
|
||||||
for (module_name, namespace) in namespaces.into_iter() {
|
for (module_name, namespace) in namespaces.into_iter() {
|
||||||
import_object.register(module_name, namespace);
|
import_object.register(module_name, namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
let bytes: &[u8] =
|
let bytes: &[u8] = ::std::slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize);
|
||||||
unsafe { ::std::slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize) };
|
|
||||||
let result = wasmer_runtime::instantiate(bytes, &import_object);
|
let result = wasmer_runtime::instantiate(bytes, &import_object);
|
||||||
let new_instance = match result {
|
let new_instance = match result {
|
||||||
Ok(instance) => instance,
|
Ok(instance) => instance,
|
||||||
Err(error) => {
|
Err(_error) => {
|
||||||
// TODO the trait bound `wasmer_runtime::error::Error: std::error::Error` is not satisfied
|
// TODO the trait bound `wasmer_runtime::error::Error: std::error::Error` is not satisfied
|
||||||
//update_last_error(error);
|
//update_last_error(error);
|
||||||
update_last_error(CApiError {
|
update_last_error(CApiError {
|
||||||
@@ -855,7 +848,7 @@ pub unsafe extern "C" fn wasmer_instantiate(
|
|||||||
return wasmer_result_t::WASMER_ERROR;
|
return wasmer_result_t::WASMER_ERROR;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
unsafe { *instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t };
|
*instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t;
|
||||||
wasmer_result_t::WASMER_OK
|
wasmer_result_t::WASMER_OK
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -898,7 +891,7 @@ pub unsafe extern "C" fn wasmer_instance_call(
|
|||||||
let params: &[wasmer_value_t] = slice::from_raw_parts(params, params_len as usize);
|
let params: &[wasmer_value_t] = slice::from_raw_parts(params, params_len as usize);
|
||||||
let params: Vec<Value> = params.iter().cloned().map(|x| x.into()).collect();
|
let params: Vec<Value> = params.iter().cloned().map(|x| x.into()).collect();
|
||||||
|
|
||||||
let func_name_c = unsafe { CStr::from_ptr(name) };
|
let func_name_c = CStr::from_ptr(name);
|
||||||
let func_name_r = func_name_c.to_str().unwrap();
|
let func_name_r = func_name_c.to_str().unwrap();
|
||||||
|
|
||||||
let results: &mut [wasmer_value_t] = slice::from_raw_parts_mut(results, results_len as usize);
|
let results: &mut [wasmer_value_t] = slice::from_raw_parts_mut(results, results_len as usize);
|
||||||
@@ -945,7 +938,7 @@ pub unsafe extern "C" fn wasmer_instance_exports(
|
|||||||
instance: *mut wasmer_instance_t,
|
instance: *mut wasmer_instance_t,
|
||||||
exports: *mut *mut wasmer_exports_t,
|
exports: *mut *mut wasmer_exports_t,
|
||||||
) {
|
) {
|
||||||
let mut instance_ref = unsafe { &mut *(instance as *mut Instance) };
|
let mut instance_ref = &mut *(instance as *mut Instance);
|
||||||
let mut exports_vec: Vec<NamedExport> = Vec::with_capacity(instance_ref.exports().count());
|
let mut exports_vec: Vec<NamedExport> = Vec::with_capacity(instance_ref.exports().count());
|
||||||
for (name, export) in instance_ref.exports() {
|
for (name, export) in instance_ref.exports() {
|
||||||
exports_vec.push(NamedExport {
|
exports_vec.push(NamedExport {
|
||||||
@@ -955,7 +948,7 @@ pub unsafe extern "C" fn wasmer_instance_exports(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
let named_exports: Box<NamedExports> = Box::new(NamedExports(exports_vec));
|
let named_exports: Box<NamedExports> = Box::new(NamedExports(exports_vec));
|
||||||
unsafe { *exports = Box::into_raw(named_exports) as *mut wasmer_exports_t };
|
*exports = Box::into_raw(named_exports) as *mut wasmer_exports_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct NamedExports(Vec<NamedExport>);
|
pub struct NamedExports(Vec<NamedExport>);
|
||||||
@@ -965,7 +958,7 @@ pub struct NamedExports(Vec<NamedExport>);
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn wasmer_exports_destroy(exports: *mut wasmer_exports_t) {
|
pub unsafe extern "C" fn wasmer_exports_destroy(exports: *mut wasmer_exports_t) {
|
||||||
if !exports.is_null() {
|
if !exports.is_null() {
|
||||||
drop(unsafe { Box::from_raw(exports as *mut NamedExports) });
|
drop(Box::from_raw(exports as *mut NamedExports));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -989,7 +982,7 @@ pub unsafe extern "C" fn wasmer_exports_get(
|
|||||||
if exports.is_null() {
|
if exports.is_null() {
|
||||||
return ptr::null_mut();
|
return ptr::null_mut();
|
||||||
}
|
}
|
||||||
let mut named_exports = unsafe { &mut *(exports as *mut NamedExports) };
|
let mut named_exports = &mut *(exports as *mut NamedExports);
|
||||||
let ptr = &mut (*named_exports).0[idx as usize] as *mut NamedExport as *mut wasmer_export_t;
|
let ptr = &mut (*named_exports).0[idx as usize] as *mut NamedExport as *mut wasmer_export_t;
|
||||||
ptr
|
ptr
|
||||||
}
|
}
|
||||||
@@ -1021,10 +1014,10 @@ pub unsafe extern "C" fn wasmer_export_func_params_arity(
|
|||||||
func: *mut wasmer_export_func_t,
|
func: *mut wasmer_export_func_t,
|
||||||
result: *mut uint32_t,
|
result: *mut uint32_t,
|
||||||
) -> wasmer_result_t {
|
) -> wasmer_result_t {
|
||||||
let mut named_export = unsafe { &*(func as *mut NamedExport) };
|
let mut named_export = &*(func as *mut NamedExport);
|
||||||
let mut export = &named_export.export;
|
let mut export = &named_export.export;
|
||||||
let result = if let Export::Function { ref signature, .. } = *export {
|
let result = if let Export::Function { ref signature, .. } = *export {
|
||||||
unsafe { *result = signature.params().len() as uint32_t };
|
*result = signature.params().len() as uint32_t;
|
||||||
wasmer_result_t::WASMER_OK
|
wasmer_result_t::WASMER_OK
|
||||||
} else {
|
} else {
|
||||||
update_last_error(CApiError {
|
update_last_error(CApiError {
|
||||||
@@ -1048,7 +1041,7 @@ pub unsafe extern "C" fn wasmer_export_func_params(
|
|||||||
params: *mut wasmer_value_tag,
|
params: *mut wasmer_value_tag,
|
||||||
params_len: c_int,
|
params_len: c_int,
|
||||||
) -> wasmer_result_t {
|
) -> wasmer_result_t {
|
||||||
let mut named_export = unsafe { &*(func as *mut NamedExport) };
|
let mut named_export = &*(func as *mut NamedExport);
|
||||||
let mut export = &named_export.export;
|
let mut export = &named_export.export;
|
||||||
let result = if let Export::Function { ref signature, .. } = *export {
|
let result = if let Export::Function { ref signature, .. } = *export {
|
||||||
let params: &mut [wasmer_value_tag] =
|
let params: &mut [wasmer_value_tag] =
|
||||||
@@ -1079,7 +1072,7 @@ pub unsafe extern "C" fn wasmer_export_func_returns(
|
|||||||
returns: *mut wasmer_value_tag,
|
returns: *mut wasmer_value_tag,
|
||||||
returns_len: c_int,
|
returns_len: c_int,
|
||||||
) -> wasmer_result_t {
|
) -> wasmer_result_t {
|
||||||
let mut named_export = unsafe { &*(func as *mut NamedExport) };
|
let mut named_export = &*(func as *mut NamedExport);
|
||||||
let mut export = &named_export.export;
|
let mut export = &named_export.export;
|
||||||
let result = if let Export::Function { ref signature, .. } = *export {
|
let result = if let Export::Function { ref signature, .. } = *export {
|
||||||
let returns: &mut [wasmer_value_tag] =
|
let returns: &mut [wasmer_value_tag] =
|
||||||
@@ -1109,10 +1102,10 @@ pub unsafe extern "C" fn wasmer_export_func_returns_arity(
|
|||||||
func: *mut wasmer_export_func_t,
|
func: *mut wasmer_export_func_t,
|
||||||
result: *mut uint32_t,
|
result: *mut uint32_t,
|
||||||
) -> wasmer_result_t {
|
) -> wasmer_result_t {
|
||||||
let mut named_export = unsafe { &*(func as *mut NamedExport) };
|
let mut named_export = &*(func as *mut NamedExport);
|
||||||
let mut export = &named_export.export;
|
let mut export = &named_export.export;
|
||||||
let result = if let Export::Function { ref signature, .. } = *export {
|
let result = if let Export::Function { ref signature, .. } = *export {
|
||||||
unsafe { *result = signature.returns().len() as uint32_t };
|
*result = signature.returns().len() as uint32_t;
|
||||||
wasmer_result_t::WASMER_OK
|
wasmer_result_t::WASMER_OK
|
||||||
} else {
|
} else {
|
||||||
update_last_error(CApiError {
|
update_last_error(CApiError {
|
||||||
@@ -1135,9 +1128,9 @@ pub unsafe extern "C" fn wasmer_import_func_params_arity(
|
|||||||
func: *mut wasmer_import_func_t,
|
func: *mut wasmer_import_func_t,
|
||||||
result: *mut uint32_t,
|
result: *mut uint32_t,
|
||||||
) -> wasmer_result_t {
|
) -> wasmer_result_t {
|
||||||
let mut export = unsafe { &mut *(func as *mut Export) };
|
let mut export = &mut *(func as *mut Export);
|
||||||
let result = if let Export::Function { ref signature, .. } = *export {
|
let result = if let Export::Function { ref signature, .. } = *export {
|
||||||
unsafe { *result = signature.params().len() as uint32_t };
|
*result = signature.params().len() as uint32_t;
|
||||||
wasmer_result_t::WASMER_OK
|
wasmer_result_t::WASMER_OK
|
||||||
} else {
|
} else {
|
||||||
update_last_error(CApiError {
|
update_last_error(CApiError {
|
||||||
@@ -1166,7 +1159,7 @@ pub unsafe extern "C" fn wasmer_import_func_new(
|
|||||||
let returns: Vec<Type> = returns.iter().cloned().map(|x| x.into()).collect();
|
let returns: Vec<Type> = returns.iter().cloned().map(|x| x.into()).collect();
|
||||||
|
|
||||||
let export = Box::new(Export::Function {
|
let export = Box::new(Export::Function {
|
||||||
func: unsafe { FuncPointer::new(func as _) },
|
func: FuncPointer::new(func as _),
|
||||||
ctx: Context::Internal,
|
ctx: Context::Internal,
|
||||||
signature: Arc::new(FuncSig::new(params, returns)),
|
signature: Arc::new(FuncSig::new(params, returns)),
|
||||||
});
|
});
|
||||||
@@ -1186,7 +1179,7 @@ pub unsafe extern "C" fn wasmer_import_func_params(
|
|||||||
params: *mut wasmer_value_tag,
|
params: *mut wasmer_value_tag,
|
||||||
params_len: c_int,
|
params_len: c_int,
|
||||||
) -> wasmer_result_t {
|
) -> wasmer_result_t {
|
||||||
let mut export = unsafe { &mut *(func as *mut Export) };
|
let mut export = &mut *(func as *mut Export);
|
||||||
let result = if let Export::Function { ref signature, .. } = *export {
|
let result = if let Export::Function { ref signature, .. } = *export {
|
||||||
let params: &mut [wasmer_value_tag] =
|
let params: &mut [wasmer_value_tag] =
|
||||||
slice::from_raw_parts_mut(params, params_len as usize);
|
slice::from_raw_parts_mut(params, params_len as usize);
|
||||||
@@ -1216,7 +1209,7 @@ pub unsafe extern "C" fn wasmer_import_func_returns(
|
|||||||
returns: *mut wasmer_value_tag,
|
returns: *mut wasmer_value_tag,
|
||||||
returns_len: c_int,
|
returns_len: c_int,
|
||||||
) -> wasmer_result_t {
|
) -> wasmer_result_t {
|
||||||
let mut export = unsafe { &mut *(func as *mut Export) };
|
let mut export = &mut *(func as *mut Export);
|
||||||
let result = if let Export::Function { ref signature, .. } = *export {
|
let result = if let Export::Function { ref signature, .. } = *export {
|
||||||
let returns: &mut [wasmer_value_tag] =
|
let returns: &mut [wasmer_value_tag] =
|
||||||
slice::from_raw_parts_mut(returns, returns_len as usize);
|
slice::from_raw_parts_mut(returns, returns_len as usize);
|
||||||
@@ -1245,9 +1238,9 @@ pub unsafe extern "C" fn wasmer_import_func_returns_arity(
|
|||||||
func: *mut wasmer_import_func_t,
|
func: *mut wasmer_import_func_t,
|
||||||
result: *mut uint32_t,
|
result: *mut uint32_t,
|
||||||
) -> wasmer_result_t {
|
) -> wasmer_result_t {
|
||||||
let mut export = unsafe { &*(func as *mut Export) };
|
let mut export = &*(func as *mut Export);
|
||||||
let result = if let Export::Function { ref signature, .. } = *export {
|
let result = if let Export::Function { ref signature, .. } = *export {
|
||||||
unsafe { *result = signature.returns().len() as uint32_t };
|
*result = signature.returns().len() as uint32_t;
|
||||||
wasmer_result_t::WASMER_OK
|
wasmer_result_t::WASMER_OK
|
||||||
} else {
|
} else {
|
||||||
update_last_error(CApiError {
|
update_last_error(CApiError {
|
||||||
@@ -1319,7 +1312,7 @@ pub unsafe extern "C" fn wasmer_export_func_call(
|
|||||||
let params: &[wasmer_value_t] = slice::from_raw_parts(params, params_len as usize);
|
let params: &[wasmer_value_t] = slice::from_raw_parts(params, params_len as usize);
|
||||||
let params: Vec<Value> = params.iter().cloned().map(|x| x.into()).collect();
|
let params: Vec<Value> = params.iter().cloned().map(|x| x.into()).collect();
|
||||||
|
|
||||||
let named_export = unsafe { &*(func as *mut NamedExport) };
|
let named_export = &*(func as *mut NamedExport);
|
||||||
|
|
||||||
let results: &mut [wasmer_value_t] = slice::from_raw_parts_mut(results, results_len as usize);
|
let results: &mut [wasmer_value_t] = slice::from_raw_parts_mut(results, results_len as usize);
|
||||||
|
|
||||||
@@ -1363,7 +1356,7 @@ pub unsafe extern "C" fn wasmer_export_func_call(
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasmer_instance_context_memory(
|
pub extern "C" fn wasmer_instance_context_memory(
|
||||||
ctx: *mut wasmer_instance_context_t,
|
ctx: *mut wasmer_instance_context_t,
|
||||||
memory_idx: uint32_t,
|
_memory_idx: uint32_t,
|
||||||
) -> *const wasmer_memory_t {
|
) -> *const wasmer_memory_t {
|
||||||
let mut ctx = unsafe { &mut *(ctx as *mut Ctx) };
|
let mut ctx = unsafe { &mut *(ctx as *mut Ctx) };
|
||||||
let memory = ctx.memory(0);
|
let memory = ctx.memory(0);
|
||||||
@@ -1402,19 +1395,19 @@ impl From<wasmer_value_t> for Value {
|
|||||||
unsafe {
|
unsafe {
|
||||||
match v {
|
match v {
|
||||||
wasmer_value_t {
|
wasmer_value_t {
|
||||||
tag: WASM_I32,
|
tag: wasmer_value_tag::WASM_I32,
|
||||||
value: wasmer_value { I32 },
|
value: wasmer_value { I32 },
|
||||||
} => Value::I32(I32),
|
} => Value::I32(I32),
|
||||||
wasmer_value_t {
|
wasmer_value_t {
|
||||||
tag: WASM_I64,
|
tag: wasmer_value_tag::WASM_I64,
|
||||||
value: wasmer_value { I64 },
|
value: wasmer_value { I64 },
|
||||||
} => Value::I64(I64),
|
} => Value::I64(I64),
|
||||||
wasmer_value_t {
|
wasmer_value_t {
|
||||||
tag: WASM_F32,
|
tag: wasmer_value_tag::WASM_F32,
|
||||||
value: wasmer_value { F32 },
|
value: wasmer_value { F32 },
|
||||||
} => Value::F32(F32),
|
} => Value::F32(F32),
|
||||||
wasmer_value_t {
|
wasmer_value_t {
|
||||||
tag: WASM_F64,
|
tag: wasmer_value_tag::WASM_F64,
|
||||||
value: wasmer_value { F64 },
|
value: wasmer_value { F64 },
|
||||||
} => Value::F64(F64),
|
} => Value::F64(F64),
|
||||||
_ => panic!("not implemented"),
|
_ => panic!("not implemented"),
|
||||||
@@ -1460,14 +1453,12 @@ impl From<Type> for wasmer_value_tag {
|
|||||||
|
|
||||||
impl From<wasmer_value_tag> for Type {
|
impl From<wasmer_value_tag> for Type {
|
||||||
fn from(v: wasmer_value_tag) -> Self {
|
fn from(v: wasmer_value_tag) -> Self {
|
||||||
unsafe {
|
match v {
|
||||||
match v {
|
wasmer_value_tag::WASM_I32 => Type::I32,
|
||||||
wasmer_value_tag::WASM_I32 => Type::I32,
|
wasmer_value_tag::WASM_I64 => Type::I64,
|
||||||
wasmer_value_tag::WASM_I64 => Type::I64,
|
wasmer_value_tag::WASM_F32 => Type::F32,
|
||||||
wasmer_value_tag::WASM_F32 => Type::F32,
|
wasmer_value_tag::WASM_F64 => Type::F64,
|
||||||
wasmer_value_tag::WASM_F64 => Type::F64,
|
_ => panic!("not implemented"),
|
||||||
_ => panic!("not implemented"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user