From 3f3ac5f7ef545f17050aa3b10e53d897f9893f9e Mon Sep 17 00:00:00 2001 From: ccgargantua Date: Sat, 6 Jan 2024 15:44:49 -0500 Subject: [PATCH] Deprecated 'ARENA_SUPPRESS_MALLOC_WARN' --- README.md | 13 ++++++------- arena.h | 23 +++++++++++------------ code_examples/example.c | 1 - code_examples/example_aligned.c | 1 - code_examples/example_debug.c | 1 - 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index c506970..aef2c87 100644 --- a/README.md +++ b/README.md @@ -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 // defaults to stdlib malloc -#define ARENA_FREE // 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 +#define ARENA_FREE +#define ARENA_MEMCPY -#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"`. diff --git a/arena.h b/arena.h index f48098b..082c7ee 100644 --- a/arena.h +++ b/arena.h @@ -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 #define ARENA_FREE -// ... or just this -#define ARENA_SUPPRESS_MALLOC_WARN // alternatively using compiler flag -D with same name +#define ARENA_MEMCPY // for debug functionality, you can also do: #define ARENA_DEBUG @@ -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 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 #define ARENA_MALLOC malloc +#endif + +#ifndef ARENA_FREE + #include #define ARENA_FREE free +#endif +#ifndef ARENA_MEMCPY #include #define ARENA_MEMCPY memcpy - -#endif /* !defined ARENA_MALLOC, ARENA_FREE */ +#endif Arena* arena_create(size_t size) diff --git a/code_examples/example.c b/code_examples/example.c index f05990e..a5592ef 100644 --- a/code_examples/example.c +++ b/code_examples/example.c @@ -2,7 +2,6 @@ #include // memcpy #define ARENA_IMPLEMENTATION -#define ARENA_SUPPRESS_MALLOC_WARN #include "../arena.h" int main(void) diff --git a/code_examples/example_aligned.c b/code_examples/example_aligned.c index 855a6bd..9b5390b 100644 --- a/code_examples/example_aligned.c +++ b/code_examples/example_aligned.c @@ -1,7 +1,6 @@ #include // printf #define ARENA_IMPLEMENTATION -#define ARENA_SUPPRESS_MALLOC_WARN #include "../arena.h" int main(void) diff --git a/code_examples/example_debug.c b/code_examples/example_debug.c index d36488f..91af8e9 100644 --- a/code_examples/example_debug.c +++ b/code_examples/example_debug.c @@ -3,7 +3,6 @@ #define ARENA_DEBUG #define ARENA_IMPLEMENTATION -#define ARENA_SUPPRESS_MALLOC_WARN #include "../arena.h" int main(void)