[Scummvm-git-logs] scummvm master -> 8f6ab97f676db25dec15134cdc3e0279b975829e

bluegr noreply at scummvm.org
Fri Sep 20 16:56:36 UTC 2024


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
8f6ab97f67 COMMON: Add scumm_assert macro


Commit: 8f6ab97f676db25dec15134cdc3e0279b975829e
    https://github.com/scummvm/scummvm/commit/8f6ab97f676db25dec15134cdc3e0279b975829e
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2024-09-20T19:54:52+03:00

Commit Message:
COMMON: Add scumm_assert macro

This macro is similar to the assert macro but differs in two aspects.
First it is not disabled when NDEBUG is defined and thus remains
enabled in release builds. Secondly it uses error() for the error
message which ensures it is available to the user (e.g. shown on
screen, or at least logged) on all platforms.

Those differences make it more appropriate than assert() for sanity
checks that we want to keep in release builds, for example related
to reading content from game data files that may be corrupted.

Changed paths:
    common/textconsole.h


diff --git a/common/textconsole.h b/common/textconsole.h
index 5f829aea78a..65d539d4371 100644
--- a/common/textconsole.h
+++ b/common/textconsole.h
@@ -99,4 +99,16 @@ void warning(MSVC_PRINTF const char *s, ...) GCC_PRINTF(1, 2);
 #endif
 /** @} */
 
+/**
+ * Test the given expression and call error() with the file, line, and expression
+ * if it is false.
+ *
+ * Unlike assert(), scumm_assert() is not disabled when NDEBUG is defined. Also
+ * the message is visible to the user (or at least logged) on all platforms.
+ */
+#define scumm_assert(expr) \
+	if (expr) {} \
+	else \
+		error("Assertion \"%s\" failed: file \"%s\", line %d", #expr, __FILE__, __LINE__)
+
 #endif




More information about the Scummvm-git-logs mailing list