Skip to content

Commit

Permalink
Deprecated 'ARENA_SUPPRESS_MALLOC_WARN'
Browse files Browse the repository at this point in the history
  • Loading branch information
ccgargantua committed Jan 6, 2024
1 parent 1252afa commit 3f3ac5f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ For one file in one translation unit, you need to define some macros before incl
```c
#define ARENA_IMPLEMENTATION

// You will get a warning if you don't specify:
// either both of these...
#define ARENA_MALLOC <stdlib_malloc_like_allocator> // defaults to stdlib malloc
#define ARENA_FREE <stdlib_free_like_deallocator> // defaults to stdlib free
// ... or just this
#define ARENA_SUPPRESS_MALLOC_WARN // Alternatively use compiler flag -DARENA_SUPPRESS_MALLOC_WARN
// All of these are optional
#define ARENA_MALLOC <stdlib_malloc_like_allocator>
#define ARENA_FREE <stdlib_free_like_deallocator>
#define ARENA_MEMCPY <stdlib_memcpy_like_copier>

#include "arena.h"
// for debug functionality, you can also do:
#define ARENA_DEBUG
```

After doing this in **one** file in **one** translation unit, for **any other file** you can include normally with a lone `#include "arena.h"`.
Expand Down
23 changes: 11 additions & 12 deletions arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ example.
QUICK USAGE:
One file in one translation unit must have the
following before including "arena.h", replacing
the macro values appropriately when needed.
the macro values appropriately when desired.
```
#define ARENA_IMPLEMENTATION
// Either both of these...
// All of these are optional
#define ARENA_MALLOC <stdlib_malloc_like_allocator>
#define ARENA_FREE <stdlib_free_like_deallocator>
// ... or just this
#define ARENA_SUPPRESS_MALLOC_WARN // alternatively using compiler flag -D with same name
#define ARENA_MEMCPY <stdlib_memcpy_like_copier>
// for debug functionality, you can also do:
#define ARENA_DEBUG
Expand Down Expand Up @@ -183,20 +182,20 @@ Arena_Allocation* arena_get_allocation_struct(Arena *arena, void *ptr);
#ifdef ARENA_IMPLEMENTATION


#if !defined(ARENA_MALLOC) || !defined(ARENA_FREE) || !defined(ARENA_MEMCPY)

#ifndef ARENA_SUPPRESS_MALLOC_WARN
#warning "Using <stdlib.h> malloc and free, because a replacement for one or both was not specified before including 'arena.h'."
#endif /* !ARENA_SUPPRESS_MALLOC_WARN */

#ifndef ARENA_MALLOC
#include <stdlib.h>
#define ARENA_MALLOC malloc
#endif

#ifndef ARENA_FREE
#include <stdlib.h>
#define ARENA_FREE free
#endif

#ifndef ARENA_MEMCPY
#include <string.h>
#define ARENA_MEMCPY memcpy

#endif /* !defined ARENA_MALLOC, ARENA_FREE */
#endif


Arena* arena_create(size_t size)
Expand Down
1 change: 0 additions & 1 deletion code_examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <string.h> // memcpy

#define ARENA_IMPLEMENTATION
#define ARENA_SUPPRESS_MALLOC_WARN
#include "../arena.h"

int main(void)
Expand Down
1 change: 0 additions & 1 deletion code_examples/example_aligned.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <stdio.h> // printf

#define ARENA_IMPLEMENTATION
#define ARENA_SUPPRESS_MALLOC_WARN
#include "../arena.h"

int main(void)
Expand Down
1 change: 0 additions & 1 deletion code_examples/example_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#define ARENA_DEBUG
#define ARENA_IMPLEMENTATION
#define ARENA_SUPPRESS_MALLOC_WARN
#include "../arena.h"

int main(void)
Expand Down

0 comments on commit 3f3ac5f

Please sign in to comment.