flan/test/programs/destroy-region.flan

27 lines
1.0 KiB
Plaintext

;;;; stale-region.flan's trap, reached through arena-destroy rather than
;;;; free-all. The difference is what the check reads: free-all keeps the
;;;; allocator and bumps its epoch, while arena-destroy hands the arena back,
;;;; and a container made from it still points at the allocator to read the
;;;; epoch from. The allocator therefore outlives its arena, so that read is of
;;;; memory that is still there and the trap names the site.
;;;;
;;;; Argument 1 is the other use of a destroyed arena: a new container made
;;;; from it, which has no stale epoch to catch and reaches the allocator
;;;; itself.
(defn main [args [string]] i32
(let [a (arena-new 4096)
which (if (> (length args) 1) (i32 (bytes->i64 (bytes-view (at args 1)))) 0)]
(if (= which 1)
(do
(arena-destroy a)
(let [w (vec-new i32 a)]
(push w 1)
(println (length w))))
(let [v (vec-new i32 a)]
(push v 1)
(push v 2)
(println (at v 1))
(arena-destroy a)
(println (at v 1)))))
0)