Skip to content

Commit

Permalink
keep using SmartPtr for now
Browse files Browse the repository at this point in the history
  • Loading branch information
iFrostizz committed Apr 26, 2024
1 parent b01177f commit 795ff58
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 26 deletions.
7 changes: 3 additions & 4 deletions x/programs/examples/imports/program/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ func (i *Import) Register(link *host.Link, callContext program.Context) error {
}

// callProgramFn makes a call to an entry function of a program in the context of another program's ID.
func (i *Import) callProgramFn(callContext program.Context) func(*wasmtime.Caller, int64, int64, int32, int32, int64) int64 {
func (i *Import) callProgramFn(callContext program.Context) func(*wasmtime.Caller, int64, int64, int64, int64) int64 {
return func(
wasmCaller *wasmtime.Caller,
programID int64,
function int64,
argsPtr int32,
argsLen int32,
args int64,
maxUnits int64,
) int64 {
ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -144,7 +143,7 @@ func (i *Import) callProgramFn(callContext program.Context) func(*wasmtime.Calle
}
}()

argsBytes, err := memory.Range(uint32(argsPtr), uint32(argsLen))
argsBytes, err := program.SmartPtr(args).Bytes(memory)
if err != nil {
i.log.Error("failed to read program args from memory",
zap.Error(err),
Expand Down
1 change: 0 additions & 1 deletion x/programs/rust/examples/counter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ mod tests {
);
}

// #[ignore = "external function calls are broken"]
#[test]
fn external_call() {
let simulator = simulator::Client::new();
Expand Down
8 changes: 2 additions & 6 deletions x/programs/rust/wasmlanche-sdk/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ pub struct Param(Vec<u8>);
pub struct Params(Vec<u8>);

impl Params {
pub(crate) fn into_host_ptr(self) -> Result<(*const u8, usize), StateError> {
let ptr = self.0.as_ptr();
if ptr.is_null() {
panic!();
}
Ok((ptr, self.0.len()))
pub(crate) fn into_host_ptr(self) -> Result<HostPtr, StateError> {
to_host_ptr(&self.0)
}
}

Expand Down
18 changes: 3 additions & 15 deletions x/programs/rust/wasmlanche-sdk/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,14 @@ impl Program {
// flatten the args into a single byte vector
let target = to_host_ptr(self.id())?;
let function = to_host_ptr(function_name.as_bytes())?;
let (args_ptr, args_len) = args.into_host_ptr()?;
let args = args.into_host_ptr()?;

Ok(unsafe { _call_program(target, function, args_ptr, args_len, max_units) })
Ok(unsafe { _call_program(target, function, args, max_units) })
}
}

// TODO how to pass a tuple to a go func ?
// #[repr(C)]
// pub struct CTUple(*const u8, usize);

#[link(wasm_import_module = "program")]
extern "C" {
#[link_name = "call_program"]
// TODO see above
// fn _call_program(target_id: i64, function: i64, args_ptr: CTUple, max_units: i64) -> i64;
fn _call_program(
target_id: i64,
function: i64,
args_ptr: *const u8,
args_len: usize,
max_units: i64,
) -> i64;
fn _call_program(target_id: i64, function: i64, args_ptr: i64, max_units: i64) -> i64;
}
Binary file modified x/programs/tests/fixture/counter.wasm
Binary file not shown.

0 comments on commit 795ff58

Please sign in to comment.