()
| 709 | } |
| 710 | |
| 711 | bad := Arena_alloc(&a, 8, 3) |
| 712 | match bad { |
| 713 | Ok(value) -> { return 7 } |
| 714 | Err(error) -> { |
| 715 | match error { |
| 716 | InvalidAlignment -> {} |
| 717 | OutOfMemory -> { return 8 } |
| 718 | SizeOverflow -> { return 9 } |
| 719 | } |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | ; Reset keeps the chunks: the next allocation reuses their storage. |
| 724 | Arena_reset(&a) |
| 725 | reused: u8* = null |
| 726 | reused_result := Arena_alloc(&a, 24, 8) |
| 727 | match reused_result { |
| 728 | Ok(value) -> { reused = value } |
| 729 | Err(error) -> { return 10 } |
| 730 | } |
| 731 | if reused == null { return 11 } |
| 732 | |
| 733 | Arena_deinit(&a) |
| 734 | if a.head != null { return 12 } |
| 735 | return 0 |
| 736 | } |
| 737 | "#, |
| 738 | ); |
| 739 | assert_eq!(exit, Some(0)); |
| 740 | } |
| 741 | |
| 742 | #[test] |
| 743 | fn hosted_pool_allocates_releases_and_rejects_invalid() { |
| 744 | let (_, exit) = run_hll( |
| 745 | r#" |
| 746 | memory_allocator := import("memory_allocator") |
| 747 | |
| 748 | main: () -> i32 { |
| 749 | p: Pool<i64> = { .chunks = null } |
| 750 | Pool_init<i64>(&p) |
| 751 | |
| 752 | a: i64* = null |
| 753 | a_result := Pool_alloc<i64>(&p) |
| 754 | match a_result { |
| 755 | Ok(value) -> { a = value } |
| 756 | Err(error) -> { return 1 } |
| 757 | } |
| 758 | b: i64* = null |
| 759 | b_result := Pool_alloc<i64>(&p) |
| 760 | match b_result { |
| 761 | Ok(value) -> { b = value } |
| 762 | Err(error) -> { return 2 } |
| 763 | } |
| 764 | if a == b { return 3 } |
nothing calls this directly
no test coverage detected