()
| 587 | #[test] |
| 588 | #[cfg_attr(miri, ignore)] |
| 589 | fn deserialize_raw_avoids_copy() { |
| 590 | // target pulley; executing code directly requires virtual memory |
| 591 | let mut config = Config::new(); |
| 592 | let target = format!("{}", Triple::pulley_host()); |
| 593 | config.target(&target).unwrap(); |
| 594 | let engine = Engine::new(&config).unwrap(); |
| 595 | let wat = String::from( |
| 596 | r#" |
| 597 | (module |
| 598 | (func (export "add") (param $lhs i32) (param $rhs i32) (result i32) |
| 599 | (i32.add (local.get $lhs) (local.get $rhs)) |
| 600 | ) |
| 601 | ) |
| 602 | "#, |
| 603 | ); |
| 604 | let module = Module::new(&engine, &wat).unwrap(); |
| 605 | let mut serialized = module.serialize().expect("Serialize failed"); |
| 606 | let serialized_ptr = std::ptr::slice_from_raw_parts(serialized.as_mut_ptr(), serialized.len()); |
| 607 | let module_memory = std::ptr::NonNull::new(serialized_ptr.cast_mut()).unwrap(); |
| 608 | let deserialized_module = |
| 609 | unsafe { Module::deserialize_raw(&engine, module_memory).expect("Deserialize Failed") }; |
| 610 | |
| 611 | // assert that addresses haven't changed, no full copy |
| 612 | // TODO: haven't been able to find a pub way of doing this |
| 613 | |
| 614 | // basic verification that the loaded module works |
| 615 | let mut store = Store::new(&engine, ()); |
| 616 | let instance = Instance::new(&mut store, &deserialized_module, &[]).unwrap(); |
| 617 | let f = instance |
| 618 | .get_typed_func::<(i32, i32), i32>(&mut store, "add") |
| 619 | .unwrap(); |
| 620 | assert_eq!(f.call(&mut store, (26, 50)).unwrap(), 76); |
| 621 | } |
| 622 | |
| 623 | #[test] |
| 624 | #[cfg_attr(miri, ignore)] |
nothing calls this directly
no test coverage detected