summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/freetype/include/dlg/dlg.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/freetype/include/dlg/dlg.h')
-rw-r--r--src/3rdparty/freetype/include/dlg/dlg.h190
1 files changed, 105 insertions, 85 deletions
diff --git a/src/3rdparty/freetype/include/dlg/dlg.h b/src/3rdparty/freetype/include/dlg/dlg.h
index 3a7abf8f05..fa10730e83 100644
--- a/src/3rdparty/freetype/include/dlg/dlg.h
+++ b/src/3rdparty/freetype/include/dlg/dlg.h
@@ -85,6 +85,13 @@
#endif
#endif
+// This macro is used when an assertion fails. It gets the source expression
+// and can return an alternative (that must stay alive).
+// Mainly useful to execute something on failed assertion.
+#ifndef DLG_FAILED_ASSERTION_TEXT
+ #define DLG_FAILED_ASSERTION_TEXT(x) x
+#endif
+
// - utility -
// two methods needed since cplusplus does not support compound literals
// and c does not support uniform initialization/initializer lists
@@ -131,83 +138,12 @@ struct dlg_origin {
// Type of the output handler, see dlg_set_handler.
typedef void(*dlg_handler)(const struct dlg_origin* origin, const char* string, void* data);
-#ifdef DLG_DISABLE
+#ifndef DLG_DISABLE
// Tagged/Untagged logging with variable level
// Tags must always be in the format `("tag1", "tag2")` (including brackets)
- #define dlg_log(level, ...)
- #define dlg_logt(level, tags, ...)
-
- // Dynamic level assert macros in various versions for additional arguments
- #define dlg_assertl(level, expr) // assert without tags/message
- #define dlg_assertlt(level, tags, expr) // assert with tags
- #define dlg_assertlm(level, expr, ...) // assert with message
- #define dlg_assertltm(level, tags, expr, ...) // assert with tags & message
-
- // Sets the handler that is responsible for formatting and outputting log calls.
- // This function is not thread safe and the handler is set globally.
- // The handler itself must not change dlg tags or call a dlg macro (if it
- // does so, the provided string or tags array in 'origin' might get invalid).
- // The handler can also be used for various other things such as dealing
- // with failed assertions or filtering calls based on the passed tags.
- // The default handler is dlg_default_output (see its doc for more info).
- // If using c++ make sure the registered handler cannot throw e.g. by
- // wrapping everything into a try-catch blog.
- inline void dlg_set_handler(dlg_handler handler, void* data) {
- (void) handler;
- (void) data;
- }
-
- // Returns the currently active dlg handler and sets `data` to
- // its user data pointer. `data` must not be NULL.
- // Useful to create handler chains.
- // This function is not threadsafe, i.e. retrieving the handler while
- // changing it from another thread is unsafe.
- // See `dlg_set_handler`.
- inline dlg_handler dlg_get_handler(void** data) {
- *data = NULL;
- return NULL;
- }
-
- // The default output handler.
- // Only use this to reset the output handler, prefer to use
- // dlg_generic_output (from output.h) which this function simply calls.
- // It also flushes the stream used and correctly outputs even from multiple threads.
- inline void dlg_default_output(const struct dlg_origin* o, const char* str, void* data) {
- (void) o;
- (void) str;
- (void) data;
- }
-
- // Adds the given tag associated with the given function to the thread specific list.
- // If func is not NULL the tag will only applied to calls from the same function.
- // Remove the tag again calling dlg_remove_tag (with exactly the same pointers!).
- // Does not check if the tag is already present.
- inline void dlg_add_tag(const char* tag, const char* func) {
- (void) tag;
- (void) func;
- }
-
- // Removes a tag added with dlg_add_tag (has no effect for tags no present).
- // The pointers must be exactly the same pointers that were supplied to dlg_add_tag,
- // this function will not check using strcmp. When the same tag/func combination
- // is added multiple times, this function remove exactly one candidate, it is
- // undefined which. Returns whether a tag was found (and removed).
- inline bool dlg_remove_tag(const char* tag, const char* func) {
- (void) tag;
- (void) func;
- return true;
- }
-
- // Returns the thread-specific buffer and its size for dlg.
- // The buffer should only be used by formatting functions.
- // The buffer can be reallocated and the size changed, just make sure
- // to update both values correctly.
- inline char** dlg_thread_buffer(size_t** size) {
- (void) size;
- return NULL;
- }
-
-#else // DLG_DISABLE
+ // Example usages:
+ // dlg_log(dlg_level_warning, "test 1")
+ // dlg_logt(("tag1, "tag2"), dlg_level_debug, "test %d", 2)
#define dlg_log(level, ...) if(level >= DLG_LOG_LEVEL) \
dlg__do_log(level, DLG_CREATE_TAGS(NULL), DLG_FILE, __LINE__, __func__, \
DLG_FMT_FUNC(__VA_ARGS__), NULL)
@@ -215,23 +151,31 @@ typedef void(*dlg_handler)(const struct dlg_origin* origin, const char* string,
dlg__do_log(level, DLG_CREATE_TAGS tags, DLG_FILE, __LINE__, __func__, \
DLG_FMT_FUNC(__VA_ARGS__), NULL)
+ // Dynamic level assert macros in various versions for additional arguments
+ // Example usages:
+ // dlg_assertl(dlg_level_warning, data != nullptr);
+ // dlg_assertlt(("tag1, "tag2"), dlg_level_trace, data != nullptr);
+ // dlg_asserttlm(("tag1), dlg_level_warning, data != nullptr, "Data must not be null");
+ // dlg_assertlm(dlg_level_error, data != nullptr, "Data must not be null");
#define dlg_assertl(level, expr) if(level >= DLG_ASSERT_LEVEL && !(expr)) \
- dlg__do_log(level, DLG_CREATE_TAGS(NULL), DLG_FILE, __LINE__, __func__, NULL, #expr)
+ dlg__do_log(level, DLG_CREATE_TAGS(NULL), DLG_FILE, __LINE__, __func__, NULL, \
+ DLG_FAILED_ASSERTION_TEXT(#expr))
#define dlg_assertlt(level, tags, expr) if(level >= DLG_ASSERT_LEVEL && !(expr)) \
- dlg__do_log(level, DLG_CREATE_TAGS tags, DLG_FILE, __LINE__, __func__, NULL, #expr)
+ dlg__do_log(level, DLG_CREATE_TAGS tags, DLG_FILE, __LINE__, __func__, NULL, \
+ DLG_FAILED_ASSERTION_TEXT(#expr))
#define dlg_assertlm(level, expr, ...) if(level >= DLG_ASSERT_LEVEL && !(expr)) \
dlg__do_log(level, DLG_CREATE_TAGS(NULL), DLG_FILE, __LINE__, __func__, \
- DLG_FMT_FUNC(__VA_ARGS__), #expr)
+ DLG_FMT_FUNC(__VA_ARGS__), DLG_FAILED_ASSERTION_TEXT(#expr))
#define dlg_assertltm(level, tags, expr, ...) if(level >= DLG_ASSERT_LEVEL && !(expr)) \
dlg__do_log(level, DLG_CREATE_TAGS tags, DLG_FILE, __LINE__, \
- __func__, DLG_FMT_FUNC(__VA_ARGS__), #expr)
+ __func__, DLG_FMT_FUNC(__VA_ARGS__), DLG_FAILED_ASSERTION_TEXT(#expr))
- DLG_API void dlg_set_handler(dlg_handler handler, void* data);
- DLG_API dlg_handler dlg_get_handler(void** data);
- DLG_API void dlg_default_output(const struct dlg_origin*, const char* string, void*);
- DLG_API void dlg_add_tag(const char* tag, const char* func);
- DLG_API bool dlg_remove_tag(const char* tag, const char* func);
- DLG_API char** dlg_thread_buffer(size_t** size);
+ #define dlg__assert_or(level, tags, expr, code, msg) if(!(expr)) {\
+ if(level >= DLG_ASSERT_LEVEL) \
+ dlg__do_log(level, tags, DLG_FILE, __LINE__, __func__, msg, \
+ DLG_FAILED_ASSERTION_TEXT(#expr)); \
+ code; \
+ } (void) NULL
// - Private interface: not part of the abi/api but needed in macros -
// Formats the given format string and arguments as printf would, uses the thread buffer.
@@ -239,8 +183,66 @@ typedef void(*dlg_handler)(const struct dlg_origin* origin, const char* string,
DLG_API void dlg__do_log(enum dlg_level lvl, const char* const*, const char*, int,
const char*, const char*, const char*);
DLG_API const char* dlg__strip_root_path(const char* file, const char* base);
+
+#else // DLG_DISABLE
+
+ #define dlg_log(level, ...)
+ #define dlg_logt(level, tags, ...)
+
+ #define dlg_assertl(level, expr) // assert without tags/message
+ #define dlg_assertlt(level, tags, expr) // assert with tags
+ #define dlg_assertlm(level, expr, ...) // assert with message
+ #define dlg_assertltm(level, tags, expr, ...) // assert with tags & message
+
+ #define dlg__assert_or(level, tags, expr, code, msg) if(!(expr)) { code; } (void) NULL
#endif // DLG_DISABLE
+// The API below is independent from DLG_DISABLE
+
+// Sets the handler that is responsible for formatting and outputting log calls.
+// This function is not thread safe and the handler is set globally.
+// The handler itself must not change dlg tags or call a dlg macro (if it
+// does so, the provided string or tags array in 'origin' might get invalid).
+// The handler can also be used for various other things such as dealing
+// with failed assertions or filtering calls based on the passed tags.
+// The default handler is dlg_default_output (see its doc for more info).
+// If using c++ make sure the registered handler cannot throw e.g. by
+// wrapping everything into a try-catch blog.
+DLG_API void dlg_set_handler(dlg_handler handler, void* data);
+
+// The default output handler.
+// Only use this to reset the output handler, prefer to use
+// dlg_generic_output (from output.h) which this function simply calls.
+// It also flushes the stream used and correctly outputs even from multiple threads.
+DLG_API void dlg_default_output(const struct dlg_origin*, const char* string, void*);
+
+// Returns the currently active dlg handler and sets `data` to
+// its user data pointer. `data` must not be NULL.
+// Useful to create handler chains.
+// This function is not threadsafe, i.e. retrieving the handler while
+// changing it from another thread is unsafe.
+// See `dlg_set_handler`.
+DLG_API dlg_handler dlg_get_handler(void** data);
+
+// Adds the given tag associated with the given function to the thread specific list.
+// If func is not NULL the tag will only applied to calls from the same function.
+// Remove the tag again calling dlg_remove_tag (with exactly the same pointers!).
+// Does not check if the tag is already present.
+DLG_API void dlg_add_tag(const char* tag, const char* func);
+
+// Removes a tag added with dlg_add_tag (has no effect for tags no present).
+// The pointers must be exactly the same pointers that were supplied to dlg_add_tag,
+// this function will not check using strcmp. When the same tag/func combination
+// is added multiple times, this function remove exactly one candidate, it is
+// undefined which. Returns whether a tag was found (and removed).
+DLG_API bool dlg_remove_tag(const char* tag, const char* func);
+
+// Returns the thread-specific buffer and its size for dlg.
+// The buffer should only be used by formatting functions.
+// The buffer can be reallocated and the size changed, just make sure
+// to update both values correctly.
+DLG_API char** dlg_thread_buffer(size_t** size);
+
// Untagged leveled logging
#define dlg_trace(...) dlg_log(dlg_level_trace, __VA_ARGS__)
#define dlg_debug(...) dlg_log(dlg_level_debug, __VA_ARGS__)
@@ -263,6 +265,24 @@ typedef void(*dlg_handler)(const struct dlg_origin* origin, const char* string,
#define dlg_assertm(expr, ...) dlg_assertlm(DLG_DEFAULT_ASSERT, expr, __VA_ARGS__)
#define dlg_asserttm(tags, expr, ...) dlg_assertltm(DLG_DEFAULT_ASSERT, tags, expr, __VA_ARGS__)
+// If (expr) does not evaluate to true, always executes 'code' (no matter what
+// DLG_ASSERT_LEVEL is or if dlg is disabled or not).
+// When dlg is enabled and the level is greater or equal to DLG_ASSERT_LEVEL,
+// logs the failed assertion.
+// Example usages:
+// dlg_assertl_or(dlg_level_warn, data != nullptr, return);
+// dlg_assertlm_or(dlg_level_fatal, data != nullptr, return, "Data must not be null");
+// dlg_assert_or(data != nullptr, logError(); return false);
+#define dlg_assertltm_or(level, tags, expr, code, ...) dlg__assert_or(level, \
+ DLG_CREATE_TAGS tags, expr, code, DLG_FMT_FUNC(__VA_ARGS__))
+#define dlg_assertlm_or(level, expr, code, ...) dlg__assert_or(level, \
+ DLG_CREATE_TAGS(NULL), expr, code, DLG_FMT_FUNC(__VA_ARGS__))
+#define dlg_assertl_or(level, expr, code) dlg__assert_or(level, \
+ DLG_CREATE_TAGS(NULL), expr, code, NULL)
+
+#define dlg_assert_or(expr, code) dlg_assertl_or(DLG_DEFAULT_ASSERT, expr, code)
+#define dlg_assertm_or(expr, code, ...) dlg_assertlm_or(DLG_DEFAULT_ASSERT, expr, code, __VA_ARGS__)
+
#ifdef __cplusplus
}
#endif