|
1 | 1 | #![cfg(not(miri))] |
2 | 2 |
|
3 | 3 | use super::{ApiStyle, REALLOC_AND_FREE}; |
4 | | -use std::sync::Arc; |
| 4 | +use std::sync::{ |
| 5 | + Arc, |
| 6 | + atomic::{AtomicBool, Ordering::SeqCst}, |
| 7 | +}; |
5 | 8 | use wasmtime::Result; |
6 | 9 | use wasmtime::component::*; |
7 | 10 | use wasmtime::{Config, Engine, Store, StoreContextMut, Trap}; |
@@ -3771,5 +3774,75 @@ async fn drop_call_async_future() -> Result<()> { |
3771 | 3774 | _ = result; |
3772 | 3775 | } |
3773 | 3776 | } |
| 3777 | + |
| 3778 | + Ok(()) |
| 3779 | +} |
| 3780 | + |
| 3781 | +#[test] |
| 3782 | +fn host_call_with_concurrency_disabled() -> Result<()> { |
| 3783 | + let mut config = Config::default(); |
| 3784 | + config.concurrency_support(false); |
| 3785 | + |
| 3786 | + struct MyResource; |
| 3787 | + |
| 3788 | + let engine = Engine::new(&config)?; |
| 3789 | + let mut store = Store::new(&engine, ()); |
| 3790 | + let mut linker = Linker::<()>::new(&engine); |
| 3791 | + |
| 3792 | + linker |
| 3793 | + .root() |
| 3794 | + .resource("r", ResourceType::host::<MyResource>(), |_, _| Ok(()))?; |
| 3795 | + |
| 3796 | + let f_called = Arc::new(AtomicBool::new(false)); |
| 3797 | + linker.root().func_wrap("f", { |
| 3798 | + let f_called = f_called.clone(); |
| 3799 | + move |_ctx, _: (Resource<MyResource>,)| -> Result<()> { |
| 3800 | + f_called.store(true, SeqCst); |
| 3801 | + Ok(()) |
| 3802 | + } |
| 3803 | + })?; |
| 3804 | + |
| 3805 | + let component = Component::new( |
| 3806 | + &engine, |
| 3807 | + r#" |
| 3808 | + (component |
| 3809 | + (import "r" (type $r (sub resource))) |
| 3810 | + (import "f" (func $f (param "r" (borrow $r)))) |
| 3811 | +
|
| 3812 | + (core func $f' (canon lower (func $f))) |
| 3813 | + (core func $drop (canon resource.drop $r)) |
| 3814 | +
|
| 3815 | + (core module $m |
| 3816 | + (import "" "f" (func $f (param i32))) |
| 3817 | + (import "" "drop" (func $drop (param i32))) |
| 3818 | + (func (export "g") (param i32) |
| 3819 | + (call $f (local.get 0)) |
| 3820 | + (call $drop (local.get 0)) |
| 3821 | + ) |
| 3822 | + ) |
| 3823 | +
|
| 3824 | + (core instance $i (instantiate $m (with |
| 3825 | + "" (instance |
| 3826 | + (export "f" (func $f')) |
| 3827 | + (export "drop" (func $drop)) |
| 3828 | + ) |
| 3829 | + ))) |
| 3830 | +
|
| 3831 | + (func (export "g") (param "r" (borrow $r)) |
| 3832 | + (canon lift (core func $i "g")) |
| 3833 | + ) |
| 3834 | + ) |
| 3835 | + "# |
| 3836 | + .as_bytes(), |
| 3837 | + )?; |
| 3838 | + |
| 3839 | + let instance = linker.instantiate(&mut store, &component)?; |
| 3840 | + let g = instance.get_typed_func::<(&Resource<MyResource>,), ()>(&mut store, "g")?; |
| 3841 | + |
| 3842 | + let resource = Resource::new_own(100); |
| 3843 | + g.call(&mut store, (&resource,))?; |
| 3844 | + |
| 3845 | + assert!(f_called.load(SeqCst)); |
| 3846 | + |
3774 | 3847 | Ok(()) |
3775 | 3848 | } |
0 commit comments