On Thu, Jan 1, 2009 at 3:39 PM, Per Inge Mathisen
wrote:
> 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.
As requested by gerard_, a command-line option to disable asserts was added.
- 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)
@@ -21,6 +21,7 @@
#ifndef __INCLUDED_SRC_KEYBIND_H__
#define __INCLUDED_SRC_KEYBIND_H__
+#include "console.h"
#include "lib/ivis_common/piefixedpoint.h"
// --- All those keyboard mappable functions */
@@ -234,6 +235,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: src/clparse.c
===
--- src/clparse.c (revision 6523)
+++ src/clparse.c (working copy)
@@ -43,6 +43,7 @@
#include "wrappers.h"
#include "cheat.h"
#include "init.h"
+#include "keybind.h"
// To set the shadow config:
#include "display.h"
#include "version.h"
@@ -86,6 +87,7 @@
CLI_SELFTEST,
CLI_CONNECTTOIP,
CLI_HOSTLAUNCH,
+ CLI_NOASSERT,
} CLI_OPTIONS;
static const struct poptOption* getOptionsTable(void)
@@ -104,6 +106,7 @@
{ "mod",'\0', POPT_ARG_STRING, NULL, CLI_MOD_GLOB, N_("Enable a global mod"), N_("mod") },
{ "mod_ca", '\0', POPT_ARG_STRING, NULL, CLI_MOD_CA, N_("Enable a campaign only mod"),N_("mod") },
{ "mod_mp", '\0', POPT_ARG_STRING, NULL, CLI_MOD_MP, N_("Enable a multiplay only mod"), N_("mod") },
+ { "noassert", '\0', POPT_ARG_NONE, NULL, CLI_NOASSERT, N_("Disable asserts"), NULL },
{ "savegame", '\0', POPT_ARG_STRING, NULL, CLI_SAVEGAME, N_("Load a saved game"), N_("savegame") },
{ "usage", '\0', POPT_ARG_NONE
| POPT_ARGFLAG_DOC_HIDDEN, NULL, CLI_USAGE, NULL,NULL, },
@@ -283,6 +286,10 @@
// These options are parsed in ParseCommandLineEarly() already, so ignore them
break;
+ case CLI_NOASSERT:
+kf_NoAssert();
+break;
+
case CLI_CHEAT:
printf(" ** DEBUG MODE UNLOCKED! **\n");
bAllowDebugMode = true;
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