This patch adds a new cheat "noassert" which turns off asserts. ASSERT
calls will still generate log entries, but not take down the program.
This is meant for testing that code hit by an assert bug has
sufficient error handling that it can survive when compiled without
assertions. Which it always should.

Sending it directly to list because trac stuff is down.

  - Per
Index: src/keybind.c
===================================================================
--- src/keybind.c	(revision 6523)
+++ src/keybind.c	(working copy)
@@ -2599,3 +2599,10 @@
 		}
 	}
 }
+
+void kf_NoAssert()
+{
+	debugDisableAssert();
+	console("Asserts turned off");
+	debug(LOG_ERROR, "Asserts turned off");
+}
Index: src/keybind.h
===================================================================
--- src/keybind.h	(revision 6523)
+++ src/keybind.h	(working copy)
@@ -234,6 +234,8 @@
 
 void kf_TileInfo(void);
 
+void kf_NoAssert(void);
+
 extern void	kf_ToggleWatchWindow( void );
 
 bool runningMultiplayer(void);
Index: src/cheat.c
===================================================================
--- src/cheat.c	(revision 6523)
+++ src/cheat.c	(working copy)
@@ -44,6 +44,7 @@
 //	{"PJKSVQZ,",kf_ToggleOutline},
 //	{"L\\MZZQ[JRO",kf_ScreenDump},	//screendump
 
+	{"noassert", kf_NoAssert}, // turn off asserts
 	{"count me", kf_ShowNumObjects}, // give a count of objects in the world
 	{"give all", kf_AllAvailable},	// give all
 	{"research all", kf_FinishAllResearch}, // research everything at once
Index: lib/framework/debug.c
===================================================================
--- lib/framework/debug.c	(revision 6523)
+++ lib/framework/debug.c	(working copy)
@@ -41,6 +41,7 @@
 
 static debug_callback * callbackRegistry = NULL;
 BOOL enabled_debug[LOG_LAST]; // global
+bool assertEnabled = true;
 
 /*
  * This list _must_ match the enum in debug.h!
@@ -382,3 +383,8 @@
 {
 	return enabled_debug[codePart];
 }
+
+void debugDisableAssert()
+{
+	assertEnabled = false;
+}
Index: lib/framework/debug.h
===================================================================
--- lib/framework/debug.h	(revision 6523)
+++ lib/framework/debug.h	(working copy)
@@ -51,6 +51,9 @@
 /** Stores name of the last function or event called by scripts. */
 extern char last_called_script_event[MAX_EVENT_NAME_LEN];
 
+/** Whether asserts are currently enabled. */
+extern bool assertEnabled;
+
 /**
  * ASSERT helper macro to allow some debug functions to use an alternate
  * calling location.
@@ -78,7 +81,7 @@
 		                                  location_description, (#expr), last_called_script_event) \
 		) \
 	), \
-	assert(expr) \
+	assertEnabled ? assert(expr) : (void)0 \
 )
 
 /**
@@ -226,4 +229,6 @@
 /** Checks if a particular debub flag was enabled */
 extern bool debugPartEnabled(code_part codePart);
 
+void debugDisableAssert(void);
+
 #endif // __INCLUDED_LIB_FRAMEWORK_DEBUG_H__
_______________________________________________
Warzone-dev mailing list
Warzone-dev@gna.org
https://mail.gna.org/listinfo/warzone-dev

Reply via email to