MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / pointers_and_enums

Method pointers_and_enums

crates/wiggle/tests/pointers.rs:12–61  ·  view source on GitHub ↗
(
        &mut self,
        memory: &mut GuestMemory<'_>,
        input1: types::Excuse,
        input2_ptr: GuestPtr<types::Excuse>,
        input3_ptr: GuestPtr<types::Excuse>,
        input4_ptr_p

Source from the content-addressed store, hash-verified

10
11impl<'a> pointers::Pointers for WasiCtx<'a> {
12 fn pointers_and_enums(
13 &mut self,
14 memory: &mut GuestMemory<'_>,
15 input1: types::Excuse,
16 input2_ptr: GuestPtr<types::Excuse>,
17 input3_ptr: GuestPtr<types::Excuse>,
18 input4_ptr_ptr: GuestPtr<GuestPtr<types::Excuse>>,
19 ) -> Result<(), types::Errno> {
20 println!("BAZ input1 {input1:?}");
21 let input2: types::Excuse = memory.read(input2_ptr).map_err(|e| {
22 eprintln!("input2_ptr error: {e}");
23 types::Errno::InvalidArg
24 })?;
25 println!("input2 {input2:?}");
26
27 // Read enum value from immutable ptr:
28 let input3 = memory.read(input3_ptr).map_err(|e| {
29 eprintln!("input3_ptr error: {e}");
30 types::Errno::InvalidArg
31 })?;
32 println!("input3 {input3:?}");
33
34 // Write enum to mutable ptr:
35 memory.write(input2_ptr, input3).map_err(|e| {
36 eprintln!("input2_ptr error: {e}");
37 types::Errno::InvalidArg
38 })?;
39 println!("wrote to input2_ref {input3:?}");
40
41 // Read ptr value from mutable ptr:
42 let input4_ptr: GuestPtr<types::Excuse> = memory.read(input4_ptr_ptr).map_err(|e| {
43 eprintln!("input4_ptr_ptr error: {e}");
44 types::Errno::InvalidArg
45 })?;
46
47 // Read enum value from that ptr:
48 let input4: types::Excuse = memory.read(input4_ptr).map_err(|e| {
49 eprintln!("input4_ptr error: {e}");
50 types::Errno::InvalidArg
51 })?;
52 println!("input4 {input4:?}");
53
54 // Write ptr value to mutable ptr:
55 memory.write(input4_ptr_ptr, input2_ptr).map_err(|e| {
56 eprintln!("input4_ptr_ptr error: {e}");
57 types::Errno::InvalidArg
58 })?;
59
60 Ok(())
61 }
62}
63
64fn excuse_strat() -> impl Strategy<Value = types::Excuse> {

Callers

nothing calls this directly

Calls 3

OkFunction · 0.85
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected