Added arena free macro for cleanup and clarity
This commit is contained in:
@@ -44,5 +44,6 @@ extern void *mem_arena_alloc(int flags, Arena *a,
|
||||
mem_arena_new((flags), (nbytes), __FILE__, __LINE__)
|
||||
#define ARENA_ALLOC(flags, a, nbytes, align, count) \
|
||||
mem_arena_alloc((flags), (a), (nbytes), (align), (count), __FILE__, __LINE__)
|
||||
#define ARENA_FREE(a) mem_free(a.beg, __FILE__, __LINE__)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,6 +7,6 @@ int main(void){
|
||||
Arena a = ARENA(0,nbytes);
|
||||
ASSERTED(a.beg != NULL);
|
||||
ASSERTED( mem_is_zero(a.beg, nbytes));
|
||||
FREE(a.beg);
|
||||
ARENA_FREE(a);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ int main(void){
|
||||
Arena a = ARENA(NOZERO,nbytes);
|
||||
ASSERTED(a.beg != NULL);
|
||||
ASSERTED( !mem_is_zero(a.beg, nbytes));
|
||||
FREE(a.beg);
|
||||
ARENA_FREE(a);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ int main(void){
|
||||
a = ARENA(0,nbytes); /* try 1GB */
|
||||
if (!a.beg)
|
||||
RAISE(OOM);
|
||||
free(a.beg);
|
||||
ARENA_FREE(a);
|
||||
}
|
||||
EXCEPT(OOM) {
|
||||
/* handle memory failure gracefully */
|
||||
@@ -20,7 +20,7 @@ int main(void){
|
||||
}
|
||||
FINALLY {
|
||||
/* cleanup if needed, runs always */
|
||||
if (a.beg) free(a.beg);
|
||||
if (a.beg) ARENA_FREE(a);
|
||||
}
|
||||
END_TRY;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user