@@ -1656,18 +1656,7 @@ fn select_gc_ref_stack_map() -> Result<()> {
16561656 (type $pair (struct (field (mut i32))))
16571657 (type $arr (array (mut i8)))
16581658
1659- ;; Allocate many objects to fill the GC heap and trigger
1660- ;; collection. After GC frees everything, subsequent
1661- ;; allocations reuse the freed memory.
1662- (func $force_gc
1663- (local i32)
1664- (local.set 0 (i32.const 64))
1665- (loop $l
1666- (drop (array.new $arr (i32.const 0) (i32.const 1024)))
1667- (local.set 0 (i32.sub (local.get 0) (i32.const 1)))
1668- (br_if $l (local.get 0))
1669- )
1670- )
1659+ (import "" "" (func $force_gc))
16711660
16721661 (func (export "test") (param $cond i32) (result i32)
16731662 ;; The select result stays on the Wasm operand stack (never
@@ -1687,6 +1676,8 @@ fn select_gc_ref_stack_map() -> Result<()> {
16871676 ;; overwrite the freed memory.
16881677 (call $force_gc)
16891678
1679+ (drop (struct.new $pair (i32.const 222)))
1680+
16901681 ;; Use the select result. If it was incorrectly freed, then
16911682 ;; this will have the wrong value.
16921683 (struct.get $pair 0)
@@ -1696,15 +1687,15 @@ fn select_gc_ref_stack_map() -> Result<()> {
16961687 ) ?;
16971688
16981689 let mut store = Store :: new ( & engine, ( ) ) ;
1699- let instance = Instance :: new ( & mut store, & module, & [ ] ) ?;
1690+ let force_gc = Func :: wrap ( & mut store, |mut caller : Caller < ' _ , _ > | {
1691+ caller. gc ( None ) ?;
1692+ Ok ( ( ) )
1693+ } ) ;
1694+ let instance = Instance :: new ( & mut store, & module, & [ force_gc. into ( ) ] ) ?;
17001695 let test = instance. get_typed_func :: < ( i32 , ) , i32 > ( & mut store, "test" ) ?;
17011696
1702- // Run multiple times to increase chance of triggering GC at the right
1703- // moment.
1704- for _ in 0 ..30 {
1705- let result = test. call ( & mut store, ( 1 , ) ) ?;
1706- assert_eq ! ( result, 111 ) ;
1707- }
1697+ let result = test. call ( & mut store, ( 1 , ) ) ?;
1698+ assert_eq ! ( result, 111 ) ;
17081699
17091700 Ok ( ( ) )
17101701}
0 commit comments