aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2022-10-22 15:14:22 +0200
committerAndre Weissflog <floooh@gmail.com>2022-10-22 15:14:22 +0200
commit1eebe4c0d755d0c7f899be21007282321c4dc373 (patch)
treebd40da7c19cef44a0d13b6de5ff4c8d7d626587e
parente4b2aad7f27929b6ca58777c4f6884a23b1b0fbb (diff)
simplify logging preprocessor macros
-rw-r--r--sokol_app.h35
-rw-r--r--sokol_args.h2
-rw-r--r--sokol_audio.h35
-rw-r--r--sokol_fetch.h37
-rw-r--r--sokol_gfx.h40
-rw-r--r--util/sokol_debugtext.h37
-rw-r--r--util/sokol_fontstash.h2
-rw-r--r--util/sokol_gl.h37
-rw-r--r--util/sokol_imgui.h2
-rw-r--r--util/sokol_memtrack.h2
-rw-r--r--util/sokol_nuklear.h2
11 files changed, 74 insertions, 157 deletions
diff --git a/sokol_app.h b/sokol_app.h
index 2759898c..45acba81 100644
--- a/sokol_app.h
+++ b/sokol_app.h
@@ -1468,7 +1468,7 @@ typedef struct sapp_allocator {
sapp_logger
Used in sapp_desc to provide custom log callbacks to sokol_app.h.
- Default behavior is SAPP_LOG_DEFAULT(message).
+ Default behavior is SOKOL_LOG(message).
*/
typedef struct sapp_logger {
void (*log_cb)(const char* message, void* user_data);
@@ -1799,7 +1799,7 @@ inline void sapp_run(const sapp_desc& desc) { return sapp_run(&desc); }
#endif
#ifndef SOKOL_DEBUG
#ifndef NDEBUG
- #define SOKOL_DEBUG (1)
+ #define SOKOL_DEBUG
#endif
#endif
#ifndef SOKOL_ASSERT
@@ -1810,32 +1810,19 @@ inline void sapp_run(const sapp_desc& desc) { return sapp_run(&desc); }
#define SOKOL_UNREACHABLE SOKOL_ASSERT(false)
#endif
-#if defined(SOKOL_LOG)
-#error "SOKOL_LOG macro is no longer supported, please use sg_desc.logger to override log functions"
-#endif
-#ifndef SOKOL_NO_LOG
- #ifdef SOKOL_DEBUG
- #define SOKOL_NO_LOG 0
- #else
- #define SOKOL_NO_LOG 1
- #endif
-#endif
-#if !SOKOL_NO_LOG
- #define SAPP_LOG(s) { SOKOL_ASSERT(s); _sapp_log(s); }
- #ifndef SAPP_LOG_DEFAULT
+#if !defined(SOKOL_DEBUG)
+ #define SAPP_LOG(s)
+#else
+ #define SAPP_LOG(s) _sapp_log(s)
+ #ifndef SOKOL_LOG
#if defined(__ANDROID__)
#include <android/log.h>
- #define SAPP_LOG_DEFAULT(s) __android_log_write(ANDROID_LOG_INFO, "SOKOL_APP", s)
+ #define SOKOL_LOG(s) __android_log_write(ANDROID_LOG_INFO, "SOKOL_APP", s)
#else
#include <stdio.h>
- #define SAPP_LOG_DEFAULT(s) puts(s)
+ #define SOKOL_LOG(s) puts(s)
#endif
#endif
-#else
- #define SAPP_LOG(s)
-#endif
-#ifndef SAPP_LOG_DEFAULT
- #define SAPP_LOG_DEFAULT(s)
#endif
#ifndef SOKOL_ABORT
@@ -2787,14 +2774,14 @@ _SOKOL_PRIVATE void _sapp_free(void* ptr) {
}
}
-#if !SOKOL_NO_LOG
+#if defined(SOKOL_DEBUG)
_SOKOL_PRIVATE void _sapp_log(const char* msg) {
SOKOL_ASSERT(msg);
if (_sapp.desc.logger.log_cb) {
_sapp.desc.logger.log_cb(msg, _sapp.desc.logger.user_data);
}
else {
- SAPP_LOG_DEFAULT(msg);
+ SOKOL_LOG(msg);
}
}
#endif
diff --git a/sokol_args.h b/sokol_args.h
index e6bfc983..4d37907c 100644
--- a/sokol_args.h
+++ b/sokol_args.h
@@ -373,7 +373,7 @@ inline void sargs_setup(const sargs_desc& desc) { return sargs_setup(&desc); }
#endif
#ifndef SOKOL_DEBUG
#ifndef NDEBUG
- #define SOKOL_DEBUG (1)
+ #define SOKOL_DEBUG
#endif
#endif
#ifndef SOKOL_ASSERT
diff --git a/sokol_audio.h b/sokol_audio.h
index eed1e311..3f85408f 100644
--- a/sokol_audio.h
+++ b/sokol_audio.h
@@ -484,7 +484,7 @@ typedef struct saudio_allocator {
saudio_logger
Used in saudio_desc to provide custom log callbacks to sokol_audio.h.
- Default behavior is SAUDIO_LOG_DEFAULT(message).
+ Default behavior is SOKOL_LOG(message).
*/
typedef struct saudio_logger {
void (*log_cb)(const char* message, void* user_data);
@@ -553,7 +553,7 @@ inline void saudio_setup(const saudio_desc& desc) { return saudio_setup(&desc);
#endif
#ifndef SOKOL_DEBUG
#ifndef NDEBUG
- #define SOKOL_DEBUG (1)
+ #define SOKOL_DEBUG
#endif
#endif
#ifndef SOKOL_ASSERT
@@ -561,32 +561,19 @@ inline void saudio_setup(const saudio_desc& desc) { return saudio_setup(&desc);
#define SOKOL_ASSERT(c) assert(c)
#endif
-#if defined(SOKOL_LOG)
-#error "SOKOL_LOG macro is no longer supported, please use saudio_desc.logger to override log functions"
-#endif
-#ifndef SOKOL_NO_LOG
- #ifdef SOKOL_DEBUG
- #define SOKOL_NO_LOG 0
- #else
- #define SOKOL_NO_LOG 1
- #endif
-#endif
-#if !SOKOL_NO_LOG
- #define SAUDIO_LOG(s) { SOKOL_ASSERT(s); _saudio_log(s); }
- #ifndef SAUDIO_LOG_DEFAULT
+#if !defined(SOKOL_DEBUG)
+ #define SAUDIO_LOG(s)
+#else
+ #define SAUDIO_LOG(s) _saudio_log(s)
+ #ifndef SOKOL_LOG
#if defined(__ANDROID__)
#include <android/log.h>
- #define SAUDIO_LOG_DEFAULT(s) __android_log_write(ANDROID_LOG_INFO, "SOKOL_AUDIO", s)
+ #define SOKOL_LOG(s) __android_log_write(ANDROID_LOG_INFO, "SOKOL_AUDIO", s)
#else
#include <stdio.h>
- #define SAUDIO_LOG_DEFAULT(s) puts(s)
+ #define SOKOL_LOG(s) puts(s)
#endif
#endif
-#else
- #define SAUDIO_LOG(s)
-#endif
-#ifndef SAUDIO_LOG_DEFAULT
- #define SAUDIO_LOG_DEFAULT(s)
#endif
#ifndef _SOKOL_PRIVATE
@@ -1037,13 +1024,13 @@ _SOKOL_PRIVATE void _saudio_free(void* ptr) {
}
}
-#if !SOKOL_NO_LOG
+#if defined(SOKOL_DEBUG)
_SOKOL_PRIVATE void _saudio_log(const char* msg) {
SOKOL_ASSERT(msg);
if (_saudio.desc.logger.log_cb) {
_saudio.desc.logger.log_cb(msg, _saudio.desc.logger.user_data);
} else {
- SAUDIO_LOG_DEFAULT(msg);
+ SOKOL_LOG(msg);
}
}
#endif
diff --git a/sokol_fetch.h b/sokol_fetch.h
index 0c2e12e6..5194f08b 100644
--- a/sokol_fetch.h
+++ b/sokol_fetch.h
@@ -928,7 +928,7 @@ typedef struct sfetch_allocator_t {
sfetch_logger_t
Used in sfetch_desc_t to provide custom log callbacks to sokol_fetch.h.
- Default behavior is SFETCH_LOG_DEFAULT(message).
+ Default behavior is SOKOL_LOG(message).
*/
typedef struct sfetch_logger_t {
void (*log_cb)(const char* message, void* user_data);
@@ -941,7 +941,7 @@ typedef struct sfetch_desc_t {
uint32_t num_channels; /* number of channels to fetch requests in parallel (default: 1) */
uint32_t num_lanes; /* max number of requests active on the same channel (default: 1) */
sfetch_allocator_t allocator; /* optional memory allocation overrides (default: malloc/free) */
- sfetch_logger_t logger; /* optional log function overrides (default: SFETCH_LOG_DEFAULT(message)) */
+ sfetch_logger_t logger; /* optional log function overrides (default: SOKOL_LOG(message)) */
} sfetch_desc_t;
/* a request handle to identify an active fetch request, returned by sfetch_send() */
@@ -1060,7 +1060,7 @@ inline sfetch_handle_t sfetch_send(const sfetch_request_t& request) { return sfe
#endif
#ifndef SOKOL_DEBUG
#ifndef NDEBUG
- #define SOKOL_DEBUG (1)
+ #define SOKOL_DEBUG
#endif
#endif
#ifndef SOKOL_ASSERT
@@ -1068,32 +1068,19 @@ inline sfetch_handle_t sfetch_send(const sfetch_request_t& request) { return sfe
#define SOKOL_ASSERT(c) assert(c)
#endif
-#if defined(SOKOL_LOG)
-#error "SOKOL_LOG macro is no longer supported, please use sfetch_desc.logger to override log functions"
-#endif
-#ifndef SOKOL_NO_LOG
- #ifdef SOKOL_DEBUG
- #define SOKOL_NO_LOG 0
- #else
- #define SOKOL_NO_LOG 1
- #endif
-#endif
-#if !SOKOL_NO_LOG
- #define SFETCH_LOG(s) { SOKOL_ASSERT(s); _sfetch_log(s); }
- #ifndef SFETCH_LOG_DEFAULT
+#if !defined(SOKOL_DEBUG)
+ #define SFETCH_LOG(s)
+#else
+ #define SFETCH_LOG(s) _sfetch_log(s)
+ #ifndef SOKOL_LOG
#if defined(__ANDROID__)
#include <android/log.h>
- #define SFETCH_LOG_DEFAULT(s) __android_log_write(ANDROID_LOG_INFO, "SOKOL_FETCH", s)
+ #define SOKOL_LOG(s) __android_log_write(ANDROID_LOG_INFO, "SOKOL_FETCH", s)
#else
#include <stdio.h>
- #define SFETCH_LOG_DEFAULT(s) puts(s)
+ #define SOKOL_LOG(s) puts(s)
#endif
#endif
-#else
- #define SFETCH_LOG(s)
-#endif
-#ifndef SFETCH_LOG_DEFAULT
- #define SFETCH_LOG_DEFAULT(s)
#endif
#ifndef _SOKOL_PRIVATE
@@ -1340,13 +1327,13 @@ _SOKOL_PRIVATE void _sfetch_free(void* ptr) {
}
}
-#if !SOKOL_NO_LOG
+#if defined(SOKOL_DEBUG)
_SOKOL_PRIVATE void _sfetch_log(const char* msg) {
if (_sfetch->desc.logger.log_cb) {
_sfetch->desc.logger.log_cb(msg, _sfetch->desc.logger.user_data);
}
else {
- SFETCH_LOG_DEFAULT(msg);
+ SOKOL_LOG(msg);
}
}
#endif
diff --git a/sokol_gfx.h b/sokol_gfx.h
index f3bd048b..0d65dfeb 100644
--- a/sokol_gfx.h
+++ b/sokol_gfx.h
@@ -2478,7 +2478,7 @@ typedef struct sg_allocator {
sg_logger
Used in sg_desc to provide custom log callbacks to sokol_gfx.h.
- Default behavior is SG_LOG_DEFAULT(message).
+ Default behavior is SOKOL_LOG(message).
*/
typedef struct sg_logger {
void (*log_cb)(const char* message, void* user_data);
@@ -2671,7 +2671,7 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_
#endif
#ifndef SOKOL_DEBUG
#ifndef NDEBUG
- #define SOKOL_DEBUG (1)
+ #define SOKOL_DEBUG
#endif
#endif
#ifndef SOKOL_ASSERT
@@ -2691,37 +2691,19 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_
#define SOKOL_UNREACHABLE SOKOL_ASSERT(false)
#endif
-#if defined(SOKOL_LOG)
-#error "SOKOL_LOG macro is no longer supported, please use sg_desc.logger to override log functions"
-#endif
-#ifndef SOKOL_NO_LOG
- #ifdef SOKOL_DEBUG
- #define SOKOL_NO_LOG 0
- #else
- #define SOKOL_NO_LOG 1
- #endif
-#endif
-#if !SOKOL_NO_LOG
- #if defined(__ANDROID__)
- #include <android/log.h> // __android_log_write
- #else
- #include <stdio.h> // puts
- #endif
- #define SG_LOG(s) { SOKOL_ASSERT(s); _sg_log(s); }
- #ifndef SG_LOG_DEFAULT
+#if !defined(SOKOL_DEBUG)
+ #define SG_LOG(s)
+#else
+ #define SG_LOG(s) _sg_log(s)
+ #ifndef SOKOL_LOG
#if defined(__ANDROID__)
#include <android/log.h>
- #define SG_LOG_DEFAULT(s) __android_log_write(ANDROID_LOG_INFO, "SOKOL_GFX", s)
+ #define SOKOL_LOG(s) __android_log_write(ANDROID_LOG_INFO, "SOKOL_GFX", s)
#else
#include <stdio.h>
- #define SG_LOG_DEFAULT(s) puts(s)
+ #define SOKOL_LOG(s) puts(s)
#endif
#endif
-#else
- #define SG_LOG(s)
-#endif
-#ifndef SG_LOG_DEFAULT
- #define SG_LOG_DEFAULT(s)
#endif
#ifndef _SOKOL_PRIVATE
@@ -4380,13 +4362,13 @@ _SOKOL_PRIVATE void _sg_free(void* ptr) {
}
}
-#if !SOKOL_NO_LOG
+#if defined(SOKOL_DEBUG)
_SOKOL_PRIVATE void _sg_log(const char* msg) {
SOKOL_ASSERT(msg);
if (_sg.desc.logger.log_cb) {
_sg.desc.logger.log_cb(msg, _sg.desc.logger.user_data);
} else {
- SG_LOG_DEFAULT(msg);
+ SOKOL_LOG(msg);
}
}
#endif
diff --git a/util/sokol_debugtext.h b/util/sokol_debugtext.h
index 3201d9e3..89f141db 100644
--- a/util/sokol_debugtext.h
+++ b/util/sokol_debugtext.h
@@ -567,7 +567,7 @@ typedef struct sdtx_allocator_t {
sdtx_logger_t
Used in sdtx_desc_t to provide custom log callbacks to sokol_debugtext.h.
- Default behavior is SDTX_LOG_DEFAULT(message).
+ Default behavior is SOKOL_LOG(message).
*/
typedef struct sdtx_logger_t {
void (*log_cb)(const char* message, void* user_data);
@@ -596,7 +596,7 @@ typedef struct sdtx_desc_t {
sdtx_font_desc_t fonts[SDTX_MAX_FONTS]; // up to 8 fonts descriptions
sdtx_context_desc_t context; // the default context creation parameters
sdtx_allocator_t allocator; // optional memory allocation overrides (default: malloc/free)
- sdtx_logger_t logger; // optional log override functions (default: SDTX_LOG_DEFAULT(message))
+ sdtx_logger_t logger; // optional log override functions (default: SOKOL_LOG(message))
} sdtx_desc_t;
/* initialization/shutdown */
@@ -680,7 +680,7 @@ inline sdtx_context sdtx_make_context(const sdtx_context_desc_t& desc) { return
#endif
#ifndef SOKOL_DEBUG
#ifndef NDEBUG
- #define SOKOL_DEBUG (1)
+ #define SOKOL_DEBUG
#endif
#endif
#ifndef SOKOL_ASSERT
@@ -688,32 +688,19 @@ inline sdtx_context sdtx_make_context(const sdtx_context_desc_t& desc) { return
#define SOKOL_ASSERT(c) assert(c)
#endif
-#if defined(SOKOL_LOG)
-#error "SOKOL_LOG macro is no longer supported, please use sg_desc.logger to override log functions"
-#endif
-#ifndef SOKOL_NO_LOG
- #ifdef SOKOL_DEBUG
- #define SOKOL_NO_LOG 0
- #else
- #define SOKOL_NO_LOG 1
- #endif
-#endif
-#if !SOKOL_NO_LOG
- #define SDTX_LOG(s) { SOKOL_ASSERT(s); _sdtx_log(s); }
- #ifndef SDTX_LOG_DEFAULT
+#if !defined(SOKOL_DEBUG)
+ #define SDTX_LOG(s)
+#else
+ #define SDTX_LOG(s) _sdtx_log(s)
+ #ifndef SOKOL_LOG
#if defined(__ANDROID__)
#include <android/log.h>
- #define SDTX_LOG_DEFAULT(s) __android_log_write(ANDROID_LOG_INFO, "SOKOL_DEBUGTEXT", s)
+ #define SOKOL_LOG(s) __android_log_write(ANDROID_LOG_INFO, "SOKOL_DEBUGTEXT", s)
#else
#include <stdio.h>
- #define SDTX_LOG_DEFAULT(s) puts(s)
+ #define SOKOL_LOG(s) puts(s)
#endif
#endif
-#else
- #define SDTX_LOG(s)
-#endif
-#ifndef SDTX_LOG_DEFAULT
- #define SDTX_LOG_DEFAULT(s)
#endif
#ifndef SOKOL_UNREACHABLE
@@ -3563,13 +3550,13 @@ static void _sdtx_free(void* ptr) {
}
}
-#if !SOKOL_NO_LOG
+#if defined(SOKOL_DEBUG)
static void _sdtx_log(const char* msg) {
SOKOL_ASSERT(msg);
if (_sdtx.desc.logger.log_cb) {
_sdtx.desc.logger.log_cb(msg, _sdtx.desc.logger.user_data);
} else {
- SDTX_LOG_DEFAULT(msg);
+ SOKOL_LOG(msg);
}
}
#endif
diff --git a/util/sokol_fontstash.h b/util/sokol_fontstash.h
index 16d288ab..049d5e11 100644
--- a/util/sokol_fontstash.h
+++ b/util/sokol_fontstash.h
@@ -265,7 +265,7 @@ SOKOL_FONTSTASH_API_DECL uint32_t sfons_rgba(uint8_t r, uint8_t g, uint8_t b, ui
#endif
#ifndef SOKOL_DEBUG
#ifndef NDEBUG
- #define SOKOL_DEBUG (1)
+ #define SOKOL_DEBUG
#endif
#endif
#ifndef SOKOL_ASSERT
diff --git a/util/sokol_gl.h b/util/sokol_gl.h
index 1f4f4d05..e5233d0a 100644
--- a/util/sokol_gl.h
+++ b/util/sokol_gl.h
@@ -700,7 +700,7 @@ typedef struct sgl_allocator_t {
sgl_logger_t
Used in sgl_desc_t to provide custom log callbacks to sokol_gl.h.
- Default behavior is SGL_LOG_DEFAULT(message).
+ Default behavior is SOKOL_LOG(message).
*/
typedef struct sgl_logger_t {
void (*log_cb)(const char* message, void* user_data);
@@ -717,7 +717,7 @@ typedef struct sgl_desc_t {
int sample_count;
sg_face_winding face_winding; // default: SG_FACEWINDING_CCW
sgl_allocator_t allocator; // optional memory allocation overrides (default: malloc/free)
- sgl_logger_t logger; // optional memory allocation overrides (default: SGL_LOG_DEFAULT(message))
+ sgl_logger_t logger; // optional memory allocation overrides (default: SOKOL_LOG(message))
} sgl_desc_t;
/* the default context handle */
@@ -856,7 +856,7 @@ inline sgl_pipeline sgl_context_make_pipeline(sgl_context ctx, const sg_pipeline
#endif
#ifndef SOKOL_DEBUG
#ifndef NDEBUG
- #define SOKOL_DEBUG (1)
+ #define SOKOL_DEBUG
#endif
#endif
#ifndef SOKOL_ASSERT
@@ -864,32 +864,19 @@ inline sgl_pipeline sgl_context_make_pipeline(sgl_context ctx, const sg_pipeline
#define SOKOL_ASSERT(c) assert(c)
#endif
-#if defined(SOKOL_LOG)
-#error "SOKOL_LOG macro is no longer supported, please use sgl_desc_t.logger to override log functions"
-#endif
-#ifndef SOKOL_NO_LOG
- #ifdef SOKOL_DEBUG
- #define SOKOL_NO_LOG 0
- #else
- #define SOKOL_NO_LOG 1
- #endif
-#endif
-#if !SOKOL_NO_LOG
- #define SGL_LOG(s) { SOKOL_ASSERT(s); _sgl_log(s); }
- #ifndef SGL_LOG_DEFAULT
+#if !defined(SOKOL_DEBUG)
+ #define SGL_LOG(s)
+#else
+ #define SGL_LOG(s) _sgl_log(s)
+ #ifndef SOKOL_LOG
#if defined(__ANDROID__)
#include <android/log.h>
- #define SGL_LOG_DEFAULT(s) __android_log_write(ANDROID_LOG_INFO, "SOKOL_GL", s)
+ #define SOKOL_LOG(s) __android_log_write(ANDROID_LOG_INFO, "SOKOL_GL", s)
#else
#include <stdio.h>
- #define SGL_LOG_DEFAULT(s) puts(s)
+ #define SOKOL_LOG(s) puts(s)
#endif
#endif
-#else
- #define SGL_LOG(s)
-#endif
-#ifndef SGL_LOG_DEFAULT
- #define SGL_LOG_DEFAULT(s)
#endif
#define _sgl_def(val, def) (((val) == 0) ? (def) : (val))
@@ -2390,13 +2377,13 @@ static void _sgl_free(void* ptr) {
}
}
-#if !SOKOL_NO_LOG
+#if defined(SOKOL_DEBUG)
static void _sgl_log(const char* msg) {
SOKOL_ASSERT(msg);
if (_sgl.desc.logger.log_cb) {
_sgl.desc.logger.log_cb(msg, _sgl.desc.logger.user_data);
} else {
- SGL_LOG_DEFAULT(msg);
+ SOKOL_LOG(msg);
}
}
#endif
diff --git a/util/sokol_imgui.h b/util/sokol_imgui.h
index 74421c87..df12ccfa 100644
--- a/util/sokol_imgui.h
+++ b/util/sokol_imgui.h
@@ -379,7 +379,7 @@ inline void simgui_new_frame(const simgui_frame_desc_t& desc) { return simgui_ne
#endif
#ifndef SOKOL_DEBUG
#ifndef NDEBUG
- #define SOKOL_DEBUG (1)
+ #define SOKOL_DEBUG
#endif
#endif
#ifndef SOKOL_ASSERT
diff --git a/util/sokol_memtrack.h b/util/sokol_memtrack.h
index 82d0b219..dc0b469f 100644
--- a/util/sokol_memtrack.h
+++ b/util/sokol_memtrack.h
@@ -115,7 +115,7 @@ SOKOL_MEMTRACK_API_DECL void smemtrack_free(void* ptr, void* user_data);
#endif
#ifndef SOKOL_DEBUG
#ifndef NDEBUG
- #define SOKOL_DEBUG (1)
+ #define SOKOL_DEBUG
#endif
#endif
#ifndef _SOKOL_PRIVATE
diff --git a/util/sokol_nuklear.h b/util/sokol_nuklear.h
index 0824a964..3d996061 100644
--- a/util/sokol_nuklear.h
+++ b/util/sokol_nuklear.h
@@ -267,7 +267,7 @@ inline void snk_setup(const snk_desc_t& desc) { return snk_setup(&desc); }
#endif
#ifndef SOKOL_DEBUG
#ifndef NDEBUG
- #define SOKOL_DEBUG (1)
+ #define SOKOL_DEBUG
#endif
#endif
#ifndef SOKOL_ASSERT