From ff4dddc0b78398459738c454b51c9d1452080fa2 Mon Sep 17 00:00:00 2001 From: Martin Fouilleul Date: Tue, 18 Apr 2023 18:36:06 +0200 Subject: [PATCH] moved assert to platform layer --- src/graphics.c | 1 + src/mp_app.c | 2 +- src/platform/platform_assert.h | 35 ++++++++++++++++++++++++++++++++++ src/ui.c | 1 + src/util/lists.h | 1 + src/util/macro_helpers.h | 26 ------------------------- src/util/strings.c | 2 +- 7 files changed, 40 insertions(+), 28 deletions(-) create mode 100644 src/platform/platform_assert.h diff --git a/src/graphics.c b/src/graphics.c index 5c95c28..72914f6 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -17,6 +17,7 @@ #include"stb_image.h" #include"platform_log.h" +#include"platform_assert.h" #include"graphics_internal.h" typedef struct mg_glyph_map_entry diff --git a/src/mp_app.c b/src/mp_app.c index fd475dd..da9affa 100644 --- a/src/mp_app.c +++ b/src/mp_app.c @@ -6,7 +6,7 @@ * @revision: * *****************************************************************/ - +#include"platform_assert.h" #include"mp_app_internal.h" mp_app __mpApp = {0}; diff --git a/src/platform/platform_assert.h b/src/platform/platform_assert.h new file mode 100644 index 0000000..39ff43c --- /dev/null +++ b/src/platform/platform_assert.h @@ -0,0 +1,35 @@ +/************************************************************//** +* +* @file: platform_assert.h +* @author: Martin Fouilleul +* @date: 18/04/2023 +* +*****************************************************************/ +#ifndef __PLATFORM_ASSERT_H_ +#define __PLATFORM_ASSERT_H_ + +#include"platform.h" + +//NOTE: assert macros +#ifndef NO_ASSERT + #ifdef PLATFORM_ORCA + extern int orca_assert(const char* file, const char* function, int line, const char* src, const char* msg); + #define _ASSERT_(x, msg) ((x) || orca_assert(__FILE__, __FUNCTION__, __LINE__, #x, msg)) + #else + #include + #define _ASSERT_(x, msg) assert(x && msg) + #endif + + #define ASSERT(x, ...) _ASSERT_(x, #__VA_ARGS__) + + #ifdef DEBUG + #define DEBUG_ASSERT(x, ...) ASSERT(x, ##__VA_ARGS__ ) + #else + #define DEBUG_ASSERT(x, ...) + #endif +#else + #define ASSERT(x, ...) + #define DEBUG_ASSERT(x, ...) +#endif + +#endif //__PLATFORM_ASSERT_H_ diff --git a/src/ui.c b/src/ui.c index 547633a..ed3cdc0 100644 --- a/src/ui.c +++ b/src/ui.c @@ -7,6 +7,7 @@ * *****************************************************************/ #include"platform.h" +#include"platform_assert.h" #include"memory.h" #include"hash.h" #include"platform_clock.h" diff --git a/src/util/lists.h b/src/util/lists.h index 451a95e..53f3661 100644 --- a/src/util/lists.h +++ b/src/util/lists.h @@ -10,6 +10,7 @@ #define __CONTAINERS_H_ #include"macro_helpers.h" +#include"platform_assert.h" #ifdef __cplusplus extern "C" { diff --git a/src/util/macro_helpers.h b/src/util/macro_helpers.h index 0c48f1a..006f602 100644 --- a/src/util/macro_helpers.h +++ b/src/util/macro_helpers.h @@ -120,30 +120,4 @@ static inline u64 next_pow2_u64(u64 x) #define defer_loop(begin, end) begin; for(int __i__=0; __i__<1; __i__++, end) -//NOTE: assert macros - -#ifndef NO_ASSERT - #ifdef PLATFORM_ORCA - extern int orca_assert(const char* file, const char* function, int line, const char* src, const char* msg); - - #define ORCA_ASSERT(x, msg) ((x) || orca_assert(__FILE__, __FUNCTION__, __LINE__, #x, msg)) - #define _ASSERT_(x, msg) ORCA_ASSERT(x, msg) - #else - #include - #define _ASSERT_(x, msg) assert(x && msg) - #endif - - #define ASSERT(x, ...) _ASSERT_(x, #__VA_ARGS__) - - #ifdef DEBUG - #define DEBUG_ASSERT(x, ...) ASSERT(x, ##__VA_ARGS__ ) - #else - #define DEBUG_ASSERT(x, ...) - #endif -#else - #define ASSERT(x, ...) - #define DEBUG_ASSERT(x, ...) -#endif - - #endif //__MACRO_HELPERS_H_ diff --git a/src/util/strings.c b/src/util/strings.c index 0fbbf8f..41553f2 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -6,7 +6,7 @@ * @revision: * *****************************************************************/ -#include"macro_helpers.h" +#include"platform_assert.h" #include"strings.h" //----------------------------------------------------------------------------------