Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0.0 migration docs inaccuracy #3441

Closed
rachel-bousfield opened this issue Dec 21, 2022 · 3 comments
Closed

3.0.0 migration docs inaccuracy #3441

rachel-bousfield opened this issue Dec 21, 2022 · 3 comments
Labels
📚 documentation Do you like to read? 🥇 good first issue Good for newcomers 📦 lib-api About wasmer priority-medium Medium priority issue
Milestone

Comments

@rachel-bousfield
Copy link

Right here in the 2.3 to 3.0.0 migration docs we have the following excerpt

pub struct MyEnv {
    pub memory: Option<Memory>,
    pub alloc_guest_memory: Option<TypedFunction<i32, i32>>,
    pub multiply_by: u32,
}

let env = FunctionEnv::new(&mut store, MyEnv {
  memory: None,
  alloc_guest_memory: None,
  multiply_by: 10,
});

let instance = Instance::new(&module, &imports);
let mut env_mut = env.as_mut(&mut store);
env_mut.memory = Some(instance.exports.get_memory("memory"));
env_mut.alloc_guest_memory = Some(instance.exports.get_typed_function("__alloc"));

Observe that Instance::new, however, requires a &mut store as the first argument.
Unfortunately doing so now means two mutable references to store are alive at the same time, so the example will have to be reworked beyond the straightforward

let instance = Instance::new(&mut store, &module, &imports);
@syrusakbary
Copy link
Member

That's a great catch. We need to fix this

@Michael-F-Bryan Michael-F-Bryan added 🥇 good first issue Good for newcomers 📚 documentation Do you like to read? 📦 lib-api About wasmer priority-medium Medium priority issue labels Dec 27, 2022
@Michael-F-Bryan Michael-F-Bryan added this to the v3.2 milestone Dec 27, 2022
@w-flo
Copy link

w-flo commented Dec 31, 2022

Also, this sets the memory: Option<Memory> field in the MyEnv struct to Some(instance.exports.get_memory("memory")), which is a Result<>, so something like unwrap is needed. Even after the unwrap, it's &Memory instead of Memory so that won't work.

I came to this bug report to find out how to access linear memory in a host function, and it looks like I need a different approach. :-)

Edit: My comment is actually bug #3399 , so the fix is easy: clone the Memory from its reference.

@Michael-F-Bryan Michael-F-Bryan modified the milestones: v3.2, v3.3 Apr 12, 2023
@ptitSeb ptitSeb closed this as completed Apr 20, 2023
@ptitSeb ptitSeb reopened this Apr 20, 2023
@ptitSeb ptitSeb modified the milestones: v3.3, v4.x, v4.0 Apr 20, 2023
@ptitSeb ptitSeb modified the milestones: v4.0, v3.2.1 Apr 21, 2023
@ptitSeb
Copy link
Contributor

ptitSeb commented Apr 24, 2023

Fixed in 3.2.1.

@ptitSeb ptitSeb closed this as completed Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 documentation Do you like to read? 🥇 good first issue Good for newcomers 📦 lib-api About wasmer priority-medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

5 participants