Skip to content

Commit

Permalink
Try #756:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Sep 5, 2019
2 parents 1506655 + a67ce53 commit 968e1d5
Show file tree
Hide file tree
Showing 6 changed files with 635 additions and 74 deletions.
22 changes: 16 additions & 6 deletions lib/runtime-c-api/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
value::{wasmer_value, wasmer_value_t, wasmer_value_tag},
wasmer_byte_array, wasmer_result_t,
};
use libc::c_int;
use libc::{c_int, c_uint};
use std::{ptr, slice};
use wasmer_runtime::{Instance, Memory, Module, Value};
use wasmer_runtime_core::{export::Export, module::ExportIndex};
Expand Down Expand Up @@ -390,25 +390,35 @@ pub unsafe extern "C" fn wasmer_export_name(export: *mut wasmer_export_t) -> was
pub unsafe extern "C" fn wasmer_export_func_call(
func: *const wasmer_export_func_t,
params: *const wasmer_value_t,
params_len: c_int,
params_len: c_uint,
results: *mut wasmer_value_t,
results_len: c_int,
results_len: c_uint,
) -> wasmer_result_t {
if func.is_null() {
update_last_error(CApiError {
msg: "func ptr is null".to_string(),
});
return wasmer_result_t::WASMER_ERROR;
}
if params.is_null() {

if params_len > 0 && params.is_null() {
update_last_error(CApiError {
msg: "params ptr is null".to_string(),
});
return wasmer_result_t::WASMER_ERROR;
}

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> = {
if params_len <= 0 {
vec![]
} else {
slice::from_raw_parts::<wasmer_value_t>(params, params_len as usize)
.iter()
.cloned()
.map(|x| x.into())
.collect()
}
};

let named_export = &*(func as *mut NamedExport);

Expand Down
37 changes: 37 additions & 0 deletions lib/runtime-c-api/tests/assets/exports.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#[no_mangle]
pub extern "C" fn sum(x: i32, y: i32) -> i32 {
x + y
}

#[no_mangle]
pub extern "C" fn arity_0() -> i32 {
42
}

#[no_mangle]
pub extern "C" fn i32_i32(x: i32) -> i32 {
x
}

#[no_mangle]
pub extern "C" fn i64_i64(x: i64) -> i64 {
x
}

#[no_mangle]
pub extern "C" fn f32_f32(x: f32) -> f32 {
x
}

#[no_mangle]
pub extern "C" fn f64_f64(x: f64) -> f64 {
x
}

#[no_mangle]
pub extern "C" fn string() -> *const u8 {
b"Hello, World!\0".as_ptr()
}

#[no_mangle]
pub extern "C" fn void() {}
Binary file added lib/runtime-c-api/tests/assets/exports.wasm
Binary file not shown.
Loading

0 comments on commit 968e1d5

Please sign in to comment.