with_borrow macros

this allows for scope-based heap allocations. There is one limitation.
You cannot use the return keyword inside the following block. This trick
uses dark macro magic :)
This commit is contained in:
2025-10-10 20:13:15 +02:00
parent 6e3211ab49
commit 3e80bd2cfd
2 changed files with 20 additions and 0 deletions
+9
View File
@@ -12,3 +12,12 @@ Test(borrow_allocator, test) {
cr_assert_eq(0, borrow_allocator_count_allocations(&balloc));
borrow_allocator_assert_all_freed(&balloc);
}
Test(borrow_allocator, with) {
with_borrow(foo) {
allocator_alloc(foo, 1000);
allocator_alloc(foo, 100);
allocator_alloc(foo, 90);
}
}