Merge pull request #208 from wasmerio/feature/c-api-call-an-exported-func

Fix C API to allow calling an exported func
This commit is contained in:
Brandon Fish 2019-03-01 12:38:13 -06:00 committed by GitHub
commit 7ed6ae3d49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 445 additions and 265 deletions

View File

@ -17,9 +17,6 @@ use wasmer_runtime_core::module::ExportIndex;
use wasmer_runtime_core::types::{ElementType, FuncSig, MemoryDescriptor, TableDescriptor, Type};
use wasmer_runtime_core::units::{Bytes, Pages};
#[allow(non_camel_case_types)]
pub struct wasmer_import_object_t();
#[allow(non_camel_case_types)]
pub struct wasmer_module_t();
@ -79,7 +76,11 @@ pub struct wasmer_table_t();
#[repr(C)]
#[derive(Clone)]
pub struct wasmer_func_t();
pub struct wasmer_import_func_t();
#[repr(C)]
#[derive(Clone)]
pub struct wasmer_export_func_t();
#[repr(C)]
#[derive(Clone)]
@ -97,14 +98,6 @@ pub struct wasmer_limit_option_t {
pub some: uint32_t,
}
#[repr(C)]
pub struct wasmer_func_signature {
pub params: *const wasmer_value_tag,
pub params_len: c_int,
pub returns: *const wasmer_value_tag,
pub returns_len: c_int,
}
#[repr(C)]
pub struct wasmer_import_t {
module_name: wasmer_byte_array,
@ -141,7 +134,7 @@ pub enum wasmer_import_export_kind {
#[repr(C)]
#[derive(Clone, Copy)]
pub union wasmer_import_export_value {
func: *const wasmer_func_t,
func: *const wasmer_import_func_t,
table: *const wasmer_table_t,
memory: *const wasmer_memory_t,
global: *const wasmer_global_t,
@ -741,9 +734,16 @@ pub unsafe extern "C" fn wasmer_instance_exports(
instance: *mut wasmer_instance_t,
exports: *mut *mut wasmer_exports_t,
) {
let mut instance = unsafe { &mut *(instance as *mut Instance) };
let named_exports: Box<NamedExports> =
Box::new(NamedExports(instance.exports().map(|e| e.into()).collect()));
let mut instance_ref = unsafe { &mut *(instance as *mut Instance) };
let mut exports_vec: Vec<NamedExport> = Vec::with_capacity(instance_ref.exports().count());
for (name, export) in instance_ref.exports() {
exports_vec.push(NamedExport {
name: name.clone(),
export: export.clone(),
instance: instance as *mut Instance,
});
}
let named_exports: Box<NamedExports> = Box::new(NamedExports(exports_vec));
unsafe { *exports = Box::into_raw(named_exports) as *mut wasmer_exports_t };
}
@ -798,18 +798,157 @@ pub unsafe extern "C" fn wasmer_export_kind(
}
}
/// Creates new func
/// Sets the result parameter to the arity of the params of the wasmer_export_func_t
///
/// The caller owns the object and should call `wasmer_func_destroy` to free it.
/// Returns `wasmer_result_t::WASMER_OK` upon success.
///
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
#[no_mangle]
#[allow(clippy::cast_ptr_alignment)]
pub unsafe extern "C" fn wasmer_func_new(
pub unsafe extern "C" fn wasmer_export_func_params_arity(
func: *mut wasmer_export_func_t,
result: *mut uint32_t,
) -> wasmer_result_t {
let mut named_export = unsafe { &*(func as *mut NamedExport) };
let mut export = &named_export.export;
let result = if let Export::Function { ref signature, .. } = *export {
unsafe { *result = signature.params().len() as uint32_t };
wasmer_result_t::WASMER_OK
} else {
update_last_error(CApiError {
msg: "func ptr error in wasmer_export_func_params_arity".to_string(),
});
wasmer_result_t::WASMER_ERROR
};
result
}
/// Sets the params buffer to the parameter types of the given wasmer_export_func_t
///
/// Returns `wasmer_result_t::WASMER_OK` upon success.
///
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
#[no_mangle]
#[allow(clippy::cast_ptr_alignment)]
pub unsafe extern "C" fn wasmer_export_func_params(
func: *mut wasmer_export_func_t,
params: *mut wasmer_value_tag,
params_len: c_int,
) -> wasmer_result_t {
let mut named_export = unsafe { &*(func as *mut NamedExport) };
let mut export = &named_export.export;
let result = if let Export::Function { ref signature, .. } = *export {
let params: &mut [wasmer_value_tag] =
slice::from_raw_parts_mut(params, params_len as usize);
for (i, item) in signature.params().iter().enumerate() {
params[i] = item.into();
}
wasmer_result_t::WASMER_OK
} else {
update_last_error(CApiError {
msg: "func ptr error in wasmer_export_func_params".to_string(),
});
wasmer_result_t::WASMER_ERROR
};
result
}
/// Sets the returns buffer to the parameter types of the given wasmer_export_func_t
///
/// Returns `wasmer_result_t::WASMER_OK` upon success.
///
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
#[no_mangle]
#[allow(clippy::cast_ptr_alignment)]
pub unsafe extern "C" fn wasmer_export_func_returns(
func: *mut wasmer_export_func_t,
returns: *mut wasmer_value_tag,
returns_len: c_int,
) -> wasmer_result_t {
let mut named_export = unsafe { &*(func as *mut NamedExport) };
let mut export = &named_export.export;
let result = if let Export::Function { ref signature, .. } = *export {
let returns: &mut [wasmer_value_tag] =
slice::from_raw_parts_mut(returns, returns_len as usize);
for (i, item) in signature.returns().iter().enumerate() {
returns[i] = item.into();
}
wasmer_result_t::WASMER_OK
} else {
update_last_error(CApiError {
msg: "func ptr error in wasmer_export_func_returns".to_string(),
});
wasmer_result_t::WASMER_ERROR
};
result
}
/// Sets the result parameter to the arity of the returns of the wasmer_export_func_t
///
/// Returns `wasmer_result_t::WASMER_OK` upon success.
///
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
#[no_mangle]
#[allow(clippy::cast_ptr_alignment)]
pub unsafe extern "C" fn wasmer_export_func_returns_arity(
func: *mut wasmer_export_func_t,
result: *mut uint32_t,
) -> wasmer_result_t {
let mut named_export = unsafe { &*(func as *mut NamedExport) };
let mut export = &named_export.export;
let result = if let Export::Function { ref signature, .. } = *export {
unsafe { *result = signature.returns().len() as uint32_t };
wasmer_result_t::WASMER_OK
} else {
update_last_error(CApiError {
msg: "func ptr error in wasmer_export_func_results_arity".to_string(),
});
wasmer_result_t::WASMER_ERROR
};
result
}
/// Sets the result parameter to the arity of the params of the wasmer_import_func_t
///
/// Returns `wasmer_result_t::WASMER_OK` upon success.
///
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
#[no_mangle]
#[allow(clippy::cast_ptr_alignment)]
pub unsafe extern "C" fn wasmer_import_func_params_arity(
func: *mut wasmer_import_func_t,
result: *mut uint32_t,
) -> wasmer_result_t {
let mut export = unsafe { &mut *(func as *mut Export) };
let result = if let Export::Function { ref signature, .. } = *export {
unsafe { *result = signature.params().len() as uint32_t };
wasmer_result_t::WASMER_OK
} else {
update_last_error(CApiError {
msg: "func ptr error in wasmer_import_func_params_arity".to_string(),
});
wasmer_result_t::WASMER_ERROR
};
result
}
/// Creates new func
///
/// The caller owns the object and should call `wasmer_import_func_destroy` to free it.
#[no_mangle]
#[allow(clippy::cast_ptr_alignment)]
pub unsafe extern "C" fn wasmer_import_func_new(
func: extern "C" fn(data: *mut c_void),
params: *const wasmer_value_tag,
params_len: c_int,
returns: *const wasmer_value_tag,
returns_len: c_int,
) -> *const wasmer_func_t {
) -> *const wasmer_import_func_t {
let params: &[wasmer_value_tag] = slice::from_raw_parts(params, params_len as usize);
let params: Vec<Type> = params.iter().cloned().map(|x| x.into()).collect();
let returns: &[wasmer_value_tag] = slice::from_raw_parts(returns, returns_len as usize);
@ -820,10 +959,10 @@ pub unsafe extern "C" fn wasmer_func_new(
ctx: Context::Internal,
signature: Arc::new(FuncSig::new(params, returns)),
});
Box::into_raw(export) as *mut wasmer_func_t
Box::into_raw(export) as *mut wasmer_import_func_t
}
/// Sets the result parameter to the arity of the params of the wasmer_func_t
/// Sets the params buffer to the parameter types of the given wasmer_import_func_t
///
/// Returns `wasmer_result_t::WASMER_OK` upon success.
///
@ -831,33 +970,8 @@ pub unsafe extern "C" fn wasmer_func_new(
/// and `wasmer_last_error_message` to get an error message.
#[no_mangle]
#[allow(clippy::cast_ptr_alignment)]
pub unsafe extern "C" fn wasmer_func_params_arity(
func: *mut wasmer_func_t,
result: *mut uint32_t,
) -> wasmer_result_t {
let mut export = unsafe { &mut *(func as *mut Export) };
let result = if let Export::Function { ref signature, .. } = *export {
unsafe { *result = signature.params().len() as uint32_t };
wasmer_result_t::WASMER_OK
} else {
update_last_error(CApiError {
msg: "func ptr error in wasmer_func_params_arity".to_string(),
});
wasmer_result_t::WASMER_ERROR
};
result
}
/// Sets the params buffer to the parameter types of the given wasmer_func_t
///
/// Returns `wasmer_result_t::WASMER_OK` upon success.
///
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
#[no_mangle]
#[allow(clippy::cast_ptr_alignment)]
pub unsafe extern "C" fn wasmer_func_params(
func: *mut wasmer_func_t,
pub unsafe extern "C" fn wasmer_import_func_params(
func: *mut wasmer_import_func_t,
params: *mut wasmer_value_tag,
params_len: c_int,
) -> wasmer_result_t {
@ -871,14 +985,14 @@ pub unsafe extern "C" fn wasmer_func_params(
wasmer_result_t::WASMER_OK
} else {
update_last_error(CApiError {
msg: "func ptr error in wasmer_func_params".to_string(),
msg: "func ptr error in wasmer_import_func_params".to_string(),
});
wasmer_result_t::WASMER_ERROR
};
result
}
/// Sets the returns buffer to the parameter types of the given wasmer_func_t
/// Sets the returns buffer to the parameter types of the given wasmer_import_func_t
///
/// Returns `wasmer_result_t::WASMER_OK` upon success.
///
@ -886,8 +1000,8 @@ pub unsafe extern "C" fn wasmer_func_params(
/// and `wasmer_last_error_message` to get an error message.
#[no_mangle]
#[allow(clippy::cast_ptr_alignment)]
pub unsafe extern "C" fn wasmer_func_returns(
func: *mut wasmer_func_t,
pub unsafe extern "C" fn wasmer_import_func_returns(
func: *mut wasmer_import_func_t,
returns: *mut wasmer_value_tag,
returns_len: c_int,
) -> wasmer_result_t {
@ -901,14 +1015,14 @@ pub unsafe extern "C" fn wasmer_func_returns(
wasmer_result_t::WASMER_OK
} else {
update_last_error(CApiError {
msg: "func ptr error in wasmer_func_returns".to_string(),
msg: "func ptr error in wasmer_import_func_returns".to_string(),
});
wasmer_result_t::WASMER_ERROR
};
result
}
/// Sets the result parameter to the arity of the returns of the wasmer_func_t
/// Sets the result parameter to the arity of the returns of the wasmer_import_func_t
///
/// Returns `wasmer_result_t::WASMER_OK` upon success.
///
@ -916,8 +1030,8 @@ pub unsafe extern "C" fn wasmer_func_returns(
/// and `wasmer_last_error_message` to get an error message.
#[no_mangle]
#[allow(clippy::cast_ptr_alignment)]
pub unsafe extern "C" fn wasmer_func_returns_arity(
func: *mut wasmer_func_t,
pub unsafe extern "C" fn wasmer_import_func_returns_arity(
func: *mut wasmer_import_func_t,
result: *mut uint32_t,
) -> wasmer_result_t {
let mut export = unsafe { &*(func as *mut Export) };
@ -926,7 +1040,7 @@ pub unsafe extern "C" fn wasmer_func_returns_arity(
wasmer_result_t::WASMER_OK
} else {
update_last_error(CApiError {
msg: "func ptr error in wasmer_func_results_arity".to_string(),
msg: "func ptr error in wasmer_import_func_results_arity".to_string(),
});
wasmer_result_t::WASMER_ERROR
};
@ -936,20 +1050,19 @@ pub unsafe extern "C" fn wasmer_func_returns_arity(
/// Frees memory for the given Func
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub extern "C" fn wasmer_func_destroy(func: *mut wasmer_func_t) {
pub extern "C" fn wasmer_import_func_destroy(func: *mut wasmer_import_func_t) {
if !func.is_null() {
drop(unsafe { Box::from_raw(func as *mut Export) });
}
}
/// Gets func from wasm_export
/// Gets export func from export
#[no_mangle]
#[allow(clippy::cast_ptr_alignment)]
pub unsafe extern "C" fn wasmer_export_to_func(
export: *mut wasmer_export_t,
) -> *const wasmer_func_t {
let named_export = &*(export as *mut NamedExport);
&named_export.export as *const Export as *const wasmer_func_t
) -> *const wasmer_export_func_t {
export as *const wasmer_export_func_t
}
/// Gets name from wasmer_export
@ -972,8 +1085,8 @@ pub unsafe extern "C" fn wasmer_export_name(export: *mut wasmer_export_t) -> was
/// and `wasmer_last_error_message` to get an error message.
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub unsafe extern "C" fn wasmer_func_call(
func: *mut wasmer_func_t,
pub unsafe extern "C" fn wasmer_export_func_call(
func: *mut wasmer_export_func_t,
params: *const wasmer_value_t,
params_len: c_int,
results: *mut wasmer_value_t,
@ -995,46 +1108,42 @@ pub unsafe extern "C" fn wasmer_func_call(
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 export_func = unsafe { &*(func as *mut Export) };
let named_export = unsafe { &*(func as *mut NamedExport) };
let results: &mut [wasmer_value_t] = slice::from_raw_parts_mut(results, results_len as usize);
// TODO implement func.call
update_last_error(CApiError {
msg: "wasmer_func_call not yet implemented".to_string(),
});
wasmer_result_t::WASMER_ERROR
// let result = instance.call(func_name_r, &params[..]);
// Box::into_raw(export_func);
// match result {
// Ok(results_vec) => {
// if results_vec.len() > 0 {
// let ret = match results_vec[0] {
// Value::I32(x) => wasmer_value_t {
// tag: wasmer_value_tag::WASM_I32,
// value: wasmer_value { I32: x },
// },
// Value::I64(x) => wasmer_value_t {
// tag: wasmer_value_tag::WASM_I64,
// value: wasmer_value { I64: x },
// },
// Value::F32(x) => wasmer_value_t {
// tag: wasmer_value_tag::WASM_F32,
// value: wasmer_value { F32: x },
// },
// Value::F64(x) => wasmer_value_t {
// tag: wasmer_value_tag::WASM_F64,
// value: wasmer_value { F64: x },
// },
// };
// results[0] = ret;
// }
// wasmer_result_t::WASMER_OK
// }
// Err(err) => {
// update_last_error(err);
// wasmer_result_t::WASMER_ERROR
// }
// }
let instance = &*named_export.instance;
let result = instance.call(&named_export.name, &params[..]);
match result {
Ok(results_vec) => {
if results_vec.len() > 0 {
let ret = match results_vec[0] {
Value::I32(x) => wasmer_value_t {
tag: wasmer_value_tag::WASM_I32,
value: wasmer_value { I32: x },
},
Value::I64(x) => wasmer_value_t {
tag: wasmer_value_tag::WASM_I64,
value: wasmer_value { I64: x },
},
Value::F32(x) => wasmer_value_t {
tag: wasmer_value_tag::WASM_F32,
value: wasmer_value { F32: x },
},
Value::F64(x) => wasmer_value_t {
tag: wasmer_value_tag::WASM_F64,
value: wasmer_value { F64: x },
},
};
results[0] = ret;
}
wasmer_result_t::WASMER_OK
}
Err(err) => {
update_last_error(err);
wasmer_result_t::WASMER_ERROR
}
}
}
/// Gets the memory within the context at the index `memory_idx`.
@ -1152,12 +1261,6 @@ impl From<wasmer_value_tag> for Type {
}
}
impl From<(std::string::String, wasmer_runtime_core::export::Export)> for NamedExport {
fn from((name, export): (String, Export)) -> Self {
NamedExport { name, export }
}
}
impl From<&wasmer_runtime::wasm::Type> for wasmer_value_tag {
fn from(ty: &Type) -> Self {
match *ty {
@ -1281,6 +1384,7 @@ impl Error for CApiError {}
struct NamedExport {
name: String,
export: Export,
instance: *mut Instance,
}
struct NamedExportDescriptor {

View File

@ -31,7 +31,7 @@ int main()
wasmer_import_export_kind kind = wasmer_export_kind(export);
assert(kind == WASM_FUNCTION);
wasmer_func_t *func = wasmer_export_to_func(export);
wasmer_export_func_t *func = wasmer_export_to_func(export);
wasmer_byte_array name_bytes = wasmer_export_name(export);
assert(name_bytes.bytes_len == 3);
@ -42,40 +42,40 @@ int main()
}
uint32_t params_arity;
wasmer_func_params_arity(func, &params_arity);
wasmer_export_func_params_arity(func, &params_arity);
assert(params_arity == 2);
wasmer_value_tag *params_sig = malloc(sizeof(wasmer_value_tag) * params_arity);
wasmer_func_params(func, params_sig , params_arity);
wasmer_export_func_params(func, params_sig , params_arity);
assert(params_sig[0] == WASM_I32);
assert(params_sig[1] == WASM_I32);
free(params_sig);
uint32_t returns_arity;
wasmer_func_returns_arity(func, &returns_arity);
wasmer_export_func_returns_arity(func, &returns_arity);
assert(returns_arity == 1);
wasmer_value_tag *returns_sig = malloc(sizeof(wasmer_value_tag) * returns_arity);
wasmer_func_returns(func, returns_sig , returns_arity);
wasmer_export_func_returns(func, returns_sig , returns_arity);
assert(returns_sig[0] == WASM_I32);
free(returns_sig);
// wasmer_value_t param_one;
// param_one.tag = WASM_I32;
// param_one.value.I32 = 7;
// wasmer_value_t param_two;
// param_two.tag = WASM_I32;
// param_two.value.I32 = 8;
// wasmer_value_t params[] = {param_one, param_two};
// wasmer_value_t result_one;
// wasmer_value_t results[] = {result_one};
//
// wasmer_result_t call_result = wasmer_func_call(func, params, 2, results, 1);
// printf("Call result: %d\n", call_result);
// printf("Result: %d\n", results[0].value.I32);
// assert(results[0].value.I32 == 15);
// assert(call_result == WASMER_OK);
wasmer_value_t param_one;
param_one.tag = WASM_I32;
param_one.value.I32 = 7;
wasmer_value_t param_two;
param_two.tag = WASM_I32;
param_two.value.I32 = 8;
wasmer_value_t params[] = {param_one, param_two};
wasmer_value_t result_one;
wasmer_value_t results[] = {result_one};
wasmer_result_t call_result = wasmer_export_func_call(func, params, 2, results, 1);
printf("Call result: %d\n", call_result);
printf("Result: %d\n", results[0].value.I32);
assert(results[0].value.I32 == 15);
assert(call_result == WASMER_OK);
printf("Destroy instance\n");

View File

@ -31,7 +31,7 @@ int main()
wasmer_value_tag returns_sig[] = {};
printf("Creating new func\n");
wasmer_func_t *func = wasmer_func_new(print_str, params_sig, 2, returns_sig, 0);
wasmer_import_func_t *func = wasmer_import_func_new(print_str, params_sig, 2, returns_sig, 0);
wasmer_import_t import;
char *module_name = "env";
@ -84,7 +84,7 @@ int main()
assert(0 == strcmp(actual_str, "Hello, World!"));
printf("Destroying func\n");
wasmer_func_destroy(func);
wasmer_import_func_destroy(func);
printf("Destroy instance\n");
wasmer_instance_destroy(instance);
return 0;

View File

@ -48,15 +48,7 @@ typedef struct {
typedef struct {
} wasmer_export_t;
typedef struct {
} wasmer_func_t;
typedef struct {
} wasmer_exports_t;
} wasmer_export_func_t;
typedef union {
int32_t I32;
@ -72,6 +64,14 @@ typedef struct {
typedef struct {
} wasmer_export_t;
typedef struct {
} wasmer_exports_t;
typedef struct {
} wasmer_global_t;
typedef struct {
@ -81,6 +81,10 @@ typedef struct {
typedef struct {
} wasmer_import_func_t;
typedef struct {
} wasmer_memory_t;
typedef struct {
@ -88,7 +92,7 @@ typedef struct {
} wasmer_table_t;
typedef union {
const wasmer_func_t *func;
const wasmer_import_func_t *func;
const wasmer_table_t *table;
const wasmer_memory_t *memory;
const wasmer_global_t *global;
@ -154,6 +158,55 @@ wasmer_export_descriptor_t *wasmer_export_descriptors_get(wasmer_export_descript
*/
int wasmer_export_descriptors_len(wasmer_export_descriptors_t *exports);
/**
* Calls a `func` with the provided parameters.
* Results are set using the provided `results` pointer.
* Returns `wasmer_result_t::WASMER_OK` upon success.
* Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
* and `wasmer_last_error_message` to get an error message.
*/
wasmer_result_t wasmer_export_func_call(wasmer_export_func_t *func,
const wasmer_value_t *params,
int params_len,
wasmer_value_t *results,
int results_len);
/**
* Sets the params buffer to the parameter types of the given wasmer_export_func_t
* Returns `wasmer_result_t::WASMER_OK` upon success.
* Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
* and `wasmer_last_error_message` to get an error message.
*/
wasmer_result_t wasmer_export_func_params(wasmer_export_func_t *func,
wasmer_value_tag *params,
int params_len);
/**
* Sets the result parameter to the arity of the params of the wasmer_export_func_t
* Returns `wasmer_result_t::WASMER_OK` upon success.
* Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
* and `wasmer_last_error_message` to get an error message.
*/
wasmer_result_t wasmer_export_func_params_arity(wasmer_export_func_t *func, uint32_t *result);
/**
* Sets the returns buffer to the parameter types of the given wasmer_export_func_t
* Returns `wasmer_result_t::WASMER_OK` upon success.
* Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
* and `wasmer_last_error_message` to get an error message.
*/
wasmer_result_t wasmer_export_func_returns(wasmer_export_func_t *func,
wasmer_value_tag *returns,
int returns_len);
/**
* Sets the result parameter to the arity of the returns of the wasmer_export_func_t
* Returns `wasmer_result_t::WASMER_OK` upon success.
* Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
* and `wasmer_last_error_message` to get an error message.
*/
wasmer_result_t wasmer_export_func_returns_arity(wasmer_export_func_t *func, uint32_t *result);
/**
* Gets wasmer_export kind
*/
@ -165,9 +218,9 @@ wasmer_import_export_kind wasmer_export_kind(wasmer_export_t *export_);
wasmer_byte_array wasmer_export_name(wasmer_export_t *export_);
/**
* Gets func from wasm_export
* Gets export func from export
*/
const wasmer_func_t *wasmer_export_to_func(wasmer_export_t *export_);
const wasmer_export_func_t *wasmer_export_to_func(wasmer_export_t *export_);
/**
* Frees the memory for the given exports
@ -184,68 +237,6 @@ wasmer_export_t *wasmer_exports_get(wasmer_exports_t *exports, int idx);
*/
int wasmer_exports_len(wasmer_exports_t *exports);
/**
* Calls a `func` with the provided parameters.
* Results are set using the provided `results` pointer.
* Returns `wasmer_result_t::WASMER_OK` upon success.
* Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
* and `wasmer_last_error_message` to get an error message.
*/
wasmer_result_t wasmer_func_call(wasmer_func_t *func,
const wasmer_value_t *params,
int params_len,
wasmer_value_t *results,
int results_len);
/**
* Frees memory for the given Func
*/
void wasmer_func_destroy(wasmer_func_t *func);
/**
* Creates new func
* The caller owns the object and should call `wasmer_func_destroy` to free it.
*/
const wasmer_func_t *wasmer_func_new(void (*func)(void *data),
const wasmer_value_tag *params,
int params_len,
const wasmer_value_tag *returns,
int returns_len);
/**
* Sets the params buffer to the parameter types of the given wasmer_func_t
* Returns `wasmer_result_t::WASMER_OK` upon success.
* Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
* and `wasmer_last_error_message` to get an error message.
*/
wasmer_result_t wasmer_func_params(wasmer_func_t *func, wasmer_value_tag *params, int params_len);
/**
* Sets the result parameter to the arity of the params of the wasmer_func_t
* Returns `wasmer_result_t::WASMER_OK` upon success.
* Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
* and `wasmer_last_error_message` to get an error message.
*/
wasmer_result_t wasmer_func_params_arity(wasmer_func_t *func, uint32_t *result);
/**
* Sets the returns buffer to the parameter types of the given wasmer_func_t
* Returns `wasmer_result_t::WASMER_OK` upon success.
* Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
* and `wasmer_last_error_message` to get an error message.
*/
wasmer_result_t wasmer_func_returns(wasmer_func_t *func,
wasmer_value_tag *returns,
int returns_len);
/**
* Sets the result parameter to the arity of the returns of the wasmer_func_t
* Returns `wasmer_result_t::WASMER_OK` upon success.
* Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
* and `wasmer_last_error_message` to get an error message.
*/
wasmer_result_t wasmer_func_returns_arity(wasmer_func_t *func, uint32_t *result);
/**
* Frees memory for the given Global
*/
@ -272,6 +263,57 @@ wasmer_global_t *wasmer_global_new(wasmer_value_t value, bool mutable_);
*/
void wasmer_global_set(wasmer_global_t *global, wasmer_value_t value);
/**
* Frees memory for the given Func
*/
void wasmer_import_func_destroy(wasmer_import_func_t *func);
/**
* Creates new func
* The caller owns the object and should call `wasmer_import_func_destroy` to free it.
*/
const wasmer_import_func_t *wasmer_import_func_new(void (*func)(void *data),
const wasmer_value_tag *params,
int params_len,
const wasmer_value_tag *returns,
int returns_len);
/**
* Sets the params buffer to the parameter types of the given wasmer_import_func_t
* Returns `wasmer_result_t::WASMER_OK` upon success.
* Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
* and `wasmer_last_error_message` to get an error message.
*/
wasmer_result_t wasmer_import_func_params(wasmer_import_func_t *func,
wasmer_value_tag *params,
int params_len);
/**
* Sets the result parameter to the arity of the params of the wasmer_import_func_t
* Returns `wasmer_result_t::WASMER_OK` upon success.
* Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
* and `wasmer_last_error_message` to get an error message.
*/
wasmer_result_t wasmer_import_func_params_arity(wasmer_import_func_t *func, uint32_t *result);
/**
* Sets the returns buffer to the parameter types of the given wasmer_import_func_t
* Returns `wasmer_result_t::WASMER_OK` upon success.
* Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
* and `wasmer_last_error_message` to get an error message.
*/
wasmer_result_t wasmer_import_func_returns(wasmer_import_func_t *func,
wasmer_value_tag *returns,
int returns_len);
/**
* Sets the result parameter to the arity of the returns of the wasmer_import_func_t
* Returns `wasmer_result_t::WASMER_OK` upon success.
* Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
* and `wasmer_last_error_message` to get an error message.
*/
wasmer_result_t wasmer_import_func_returns_arity(wasmer_import_func_t *func, uint32_t *result);
/**
* Calls an instances exported function by `name` with the provided parameters.
* Results are set using the provided `results` pointer.

View File

@ -43,15 +43,7 @@ struct wasmer_export_descriptors_t {
};
struct wasmer_export_t {
};
struct wasmer_func_t {
};
struct wasmer_exports_t {
struct wasmer_export_func_t {
};
@ -67,6 +59,14 @@ struct wasmer_value_t {
wasmer_value value;
};
struct wasmer_export_t {
};
struct wasmer_exports_t {
};
struct wasmer_global_t {
};
@ -76,6 +76,10 @@ struct wasmer_global_descriptor_t {
wasmer_value_tag kind;
};
struct wasmer_import_func_t {
};
struct wasmer_memory_t {
};
@ -85,7 +89,7 @@ struct wasmer_table_t {
};
union wasmer_import_export_value {
const wasmer_func_t *func;
const wasmer_import_func_t *func;
const wasmer_table_t *table;
const wasmer_memory_t *memory;
const wasmer_global_t *global;
@ -139,14 +143,53 @@ wasmer_export_descriptor_t *wasmer_export_descriptors_get(wasmer_export_descript
/// Gets the length of the export descriptors
int wasmer_export_descriptors_len(wasmer_export_descriptors_t *exports);
/// Calls a `func` with the provided parameters.
/// Results are set using the provided `results` pointer.
/// Returns `wasmer_result_t::WASMER_OK` upon success.
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_export_func_call(wasmer_export_func_t *func,
const wasmer_value_t *params,
int params_len,
wasmer_value_t *results,
int results_len);
/// Sets the params buffer to the parameter types of the given wasmer_export_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_export_func_params(wasmer_export_func_t *func,
wasmer_value_tag *params,
int params_len);
/// Sets the result parameter to the arity of the params of the wasmer_export_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_export_func_params_arity(wasmer_export_func_t *func, uint32_t *result);
/// Sets the returns buffer to the parameter types of the given wasmer_export_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_export_func_returns(wasmer_export_func_t *func,
wasmer_value_tag *returns,
int returns_len);
/// Sets the result parameter to the arity of the returns of the wasmer_export_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_export_func_returns_arity(wasmer_export_func_t *func, uint32_t *result);
/// Gets wasmer_export kind
wasmer_import_export_kind wasmer_export_kind(wasmer_export_t *export_);
/// Gets name from wasmer_export
wasmer_byte_array wasmer_export_name(wasmer_export_t *export_);
/// Gets func from wasm_export
const wasmer_func_t *wasmer_export_to_func(wasmer_export_t *export_);
/// Gets export func from export
const wasmer_export_func_t *wasmer_export_to_func(wasmer_export_t *export_);
/// Frees the memory for the given exports
void wasmer_exports_destroy(wasmer_exports_t *exports);
@ -157,54 +200,6 @@ wasmer_export_t *wasmer_exports_get(wasmer_exports_t *exports, int idx);
/// Gets the length of the exports
int wasmer_exports_len(wasmer_exports_t *exports);
/// Calls a `func` with the provided parameters.
/// Results are set using the provided `results` pointer.
/// Returns `wasmer_result_t::WASMER_OK` upon success.
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_func_call(wasmer_func_t *func,
const wasmer_value_t *params,
int params_len,
wasmer_value_t *results,
int results_len);
/// Frees memory for the given Func
void wasmer_func_destroy(wasmer_func_t *func);
/// Creates new func
/// The caller owns the object and should call `wasmer_func_destroy` to free it.
const wasmer_func_t *wasmer_func_new(void (*func)(void *data),
const wasmer_value_tag *params,
int params_len,
const wasmer_value_tag *returns,
int returns_len);
/// Sets the params buffer to the parameter types of the given wasmer_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_func_params(wasmer_func_t *func, wasmer_value_tag *params, int params_len);
/// Sets the result parameter to the arity of the params of the wasmer_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_func_params_arity(wasmer_func_t *func, uint32_t *result);
/// Sets the returns buffer to the parameter types of the given wasmer_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_func_returns(wasmer_func_t *func,
wasmer_value_tag *returns,
int returns_len);
/// Sets the result parameter to the arity of the returns of the wasmer_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_func_returns_arity(wasmer_func_t *func, uint32_t *result);
/// Frees memory for the given Global
void wasmer_global_destroy(wasmer_global_t *global);
@ -221,6 +216,45 @@ wasmer_global_t *wasmer_global_new(wasmer_value_t value, bool mutable_);
/// Sets the value stored by the given Global
void wasmer_global_set(wasmer_global_t *global, wasmer_value_t value);
/// Frees memory for the given Func
void wasmer_import_func_destroy(wasmer_import_func_t *func);
/// Creates new func
/// The caller owns the object and should call `wasmer_import_func_destroy` to free it.
const wasmer_import_func_t *wasmer_import_func_new(void (*func)(void *data),
const wasmer_value_tag *params,
int params_len,
const wasmer_value_tag *returns,
int returns_len);
/// Sets the params buffer to the parameter types of the given wasmer_import_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_import_func_params(wasmer_import_func_t *func,
wasmer_value_tag *params,
int params_len);
/// Sets the result parameter to the arity of the params of the wasmer_import_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_import_func_params_arity(wasmer_import_func_t *func, uint32_t *result);
/// Sets the returns buffer to the parameter types of the given wasmer_import_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_import_func_returns(wasmer_import_func_t *func,
wasmer_value_tag *returns,
int returns_len);
/// Sets the result parameter to the arity of the returns of the wasmer_import_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_import_func_returns_arity(wasmer_import_func_t *func, uint32_t *result);
/// Calls an instances exported function by `name` with the provided parameters.
/// Results are set using the provided `results` pointer.
/// Returns `wasmer_result_t::WASMER_OK` upon success.