Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ fn main() -> anyhow::Result<()> {
let mem_size: TypedFunction<(), i32> = instance
.exports
.get_typed_function(&mut store, "mem_size")?;
#[cfg(not(feature = "wamr"))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not in wamr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the code down below makes use of the functions only conditionally:

wasmer/examples/memory.rs

Lines 112 to 145 in b4bff3c

#[cfg(not(feature = "wamr"))]
{
// Here we are requesting two more pages for our memory.
memory.grow(&mut store, 2)?;
let memory_view = memory.view(&store);
assert_eq!(memory_view.size(), Pages::from(3));
assert_eq!(memory_view.data_size(), 65536 * 3);
// Now that we know how to query and adjust the size of the memory,
// let's see how wa can write to it or read from it.
//
// We'll only focus on how to do this using exported functions, the goal
// is to show how to work with memory addresses. Here we'll use absolute
// addresses to write and read a value.
let mem_addr = 0x2220;
let val = 0xFEFEFFE;
set_at.call(&mut store, mem_addr, val)?;
let result = get_at.call(&mut store, mem_addr)?;
println!("Value at {:#x?}: {:?}", mem_addr, result);
assert_eq!(result, val);
// Now instead of using hard coded memory addresses, let's try to write
// something at the end of the second memory page and read it.
let page_size = 0x1_0000;
let mem_addr = (page_size * 2) - mem::size_of_val(&val) as i32;
let val = 0xFEA09;
set_at.call(&mut store, mem_addr, val)?;
let result = get_at.call(&mut store, mem_addr)?;
println!("Value at {:#x?}: {:?}", mem_addr, result);
assert_eq!(result, val);
}

let get_at: TypedFunction<i32, i32> =
instance.exports.get_typed_function(&mut store, "get_at")?;
#[cfg(not(feature = "wamr"))]
let set_at: TypedFunction<(i32, i32), ()> =
instance.exports.get_typed_function(&mut store, "set_at")?;
let memory = instance.exports.get_memory("memory")?;
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/backend/v8/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl VMFuncRef {
}
}

pub(crate) struct VMExceptionRef(*mut wasm_ref_t);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be private. Why it needs to be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The place where the type is exposed to a public API is here:

warning: type `backend::v8::vm::VMExceptionRef` is more private than the item `vm::VMExceptionRef::V8::0`
   --> lib/api/src/vm/mod.rs:22:16
    |
22  |             V8(crate::backend::v8::vm::[<VM $name>]),
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `vm::VMExceptionRef::V8::0` is reachable at visibility `pub`
...
445 | define_vm_like!(ExceptionRef);
    | ----------------------------- in this macro invocation
    |
note: but type `backend::v8::vm::VMExceptionRef` is only usable at visibility `pub(crate)`

pub struct VMExceptionRef(*mut wasm_ref_t);
impl VMExceptionRef {
/// Converts the `VMExceptionRef` into a `RawValue`.
pub fn into_raw(self) -> RawValue {
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/backend/wasmi/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl VMFuncRef {
}
}

pub(crate) struct VMExceptionRef(*mut wasm_ref_t);
pub struct VMExceptionRef(*mut wasm_ref_t);
impl VMExceptionRef {
/// Converts the `VMExceptionRef` into a `RawValue`.
pub fn into_raw(self) -> RawValue {
Expand Down
5 changes: 1 addition & 4 deletions lib/swift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use wasmer_package::utils::from_bytes;
use wasmer_wasix::{
PluggableRuntime,
bin_factory::BinaryPackage,
runners::{
Runner,
wasi::{RuntimeOrEngine, WasiRunner},
},
runners::wasi::{RuntimeOrEngine, WasiRunner},
runtime::{package_loader::BuiltinPackageLoader, task_manager::tokio::TokioTaskManager},
};

Expand Down
Loading