module scheme import arena #flag -I @VMODROOT/scheme/testdata/unicode_scratch #include "allocations.h" fn C.unicode_scratch_begin() fn C.unicode_scratch_end() int fn C.unicode_scratch_first() voidptr fn attempt_unicode_scratch(words bool, mut result BoundedResult) { defer { if message := recover() { result.exhausted = arena.allocation_failure() or { panic(message) } } } if words { mut storage, _ := unicode_temp_words(1) storage.free() } else { mut storage, _ := unicode_temp_bytes(1) storage.free() } } fn check_unicode_scratch_failure(words bool) { $if gcboehm ? { return } mut owner := arena.new(limits: arena.ChunkLimits{ max_live_bytes: 0 }) defer { owner.free() } mut result := BoundedResult{} owner.push() C.unicode_scratch_begin() attempt_unicode_scratch(words, mut result) outstanding := C.unicode_scratch_end() restored := owner.is_current() owner.pop() // The old helper leaves one unpublished arena control block. Release it // after measuring the leak so a failed baseline test keeps its owner valid. if outstanding == 1 { unsafe { v_arena_free(C.unicode_scratch_first()) } } assert restored assert (result.exhausted or { panic('expected scratch denial') }) == .chunk_limit assert outstanding == 0 } fn test_denied_unicode_byte_scratch_releases_its_unpublished_arena() { check_unicode_scratch_failure(false) } fn test_denied_unicode_word_scratch_releases_its_unpublished_arena() { check_unicode_scratch_failure(true) }