[eggheads-patches] PATCH1.5: assert_fix_1.5.patch

Fabian Knittel fknittel at gmx.de
Mon Oct 23 16:32:06 CST 2000


[ assert_fix_1.5.patch ]

This patch changes the assert statement to do the actual assert
check in the macro, instead of the function, which avoids a
function call (why was this changed in the first place?).

Fabian

--
Fabian Knittel <fknittel at gmx.de> -- http://www.esc-web.de/fabian/
Signed or encrypted mail preferred.    PGP DSA key ID: 0x838B4D20
-------------- next part --------------
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/doc/UPDATES1.5 eggdrop1.5/doc/UPDATES1.5
--- eggdrop1.5~/doc/UPDATES1.5	Fri Oct 20 15:16:22 2000
+++ eggdrop1.5/doc/UPDATES1.5	Mon Oct 23 22:38:48 2000
@@ -4,6 +4,8 @@
 
 1.5.5
 Found by  Fixed by  What...
+          Fabian    Move actual assert check back into macro, saving a
+                    function call.
 NigtHuntr Fabian    Removed small compile warning about ambigious if/else.
           Looser^   Fixed typo in irc.mod/irc.h me_op export macro.
           Eule      Made the bot recognise modes during CHAN_PEND. Allows us to
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/eggdrop.h eggdrop1.5/src/eggdrop.h
--- eggdrop1.5~/src/eggdrop.h	Thu Oct 19 19:25:38 2000
+++ eggdrop1.5/src/eggdrop.h	Mon Oct 23 22:38:01 2000
@@ -183,9 +183,12 @@
 #endif
 
 #ifdef DEBUG_ASSERT
-#  define Assert(expr)	eggAssert(__FILE__, __LINE__, NULL, (int)(expr))
+#  define Assert(expr)	do {						\
+	if (!(expr))							\
+		eggAssert(__FILE__, __LINE__, NULL);			\
+} while (0)
 #else
-#  define Assert(expr)	{}
+#  define Assert(expr)	do {	} while (0)
 #endif
 
 #ifndef COMPILING_MEM
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/main.c eggdrop1.5/src/main.c
--- eggdrop1.5~/src/main.c	Thu Oct 19 19:25:38 2000
+++ eggdrop1.5/src/main.c	Mon Oct 23 22:38:01 2000
@@ -154,7 +154,7 @@
 #endif
 
 
-void fatal(char *s, int recoverable)
+void fatal(const char *s, int recoverable)
 {
   int i;
 
@@ -177,7 +177,7 @@
 
 /* For mem.c : calculate memory we SHOULD be using
  */
-int expected_memory()
+int expected_memory(void)
 {
   int tot;
 
@@ -371,7 +371,7 @@
 
 #ifdef DEBUG_CONTEXT
 /* Context */
-void eggContext(char *file, int line, char *module)
+void eggContext(const char *file, int line, const char *module)
 {
   char x[31], *p;
 
@@ -389,7 +389,8 @@
 
 /* Called from the ContextNote macro.
  */
-void eggContextNote(char *file, int line, char *module, char *note)
+void eggContextNote(const char *file, int line, const char *module,
+		    const char *note)
 {
   char x[31], *p;
 
@@ -410,19 +411,16 @@
 #ifdef DEBUG_ASSERT
 /* Called from the Assert macro.
  */
-void eggAssert(char *file, int line, char *module, int expr)
+void eggAssert(const char *file, int line, const char *module)
 {
-  if (!(expr)) {
 #ifdef DEBUG_CONTEXT
-    write_debug();
+  write_debug();
 #endif
-    if (!module) {
-      putlog(LOG_MISC, "*", "* In file %s, line %u", file, line);
-    } else {
-      putlog(LOG_MISC, "*", "* In file %s:%s, line %u", module, file, line);
-    }
-    fatal("ASSERT FAILED -- CRASHING!", 1);
-  }
+  if (!module)
+    putlog(LOG_MISC, "*", "* In file %s, line %u", file, line);
+  else
+    putlog(LOG_MISC, "*", "* In file %s:%s, line %u", module, file, line);
+  fatal("ASSERT FAILED -- CRASHING!", 1);
 }
 #endif
 
@@ -467,7 +465,7 @@
     strcpy(configfile, s);
 }
 
-void backup_userfile()
+void backup_userfile(void)
 {
   char s[150];
 
@@ -645,7 +643,7 @@
  init_net(), init_modules(), init_tcl(int, char **),
  init_language(int);
 
-void patch(char *str)
+void patch(const char *str)
 {
   char *p = strchr(egg_version, '+');
 
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/module.h eggdrop1.5/src/mod/module.h
--- eggdrop1.5~/src/mod/module.h	Thu Oct 19 19:25:39 2000
+++ eggdrop1.5/src/mod/module.h	Mon Oct 23 22:38:01 2000
@@ -380,13 +380,15 @@
 #ifdef DEBUG_CONTEXT
 #  define ContextNote(note) (global[232](__FILE__, __LINE__, MODULE_NAME, note))
 #else
-#  define ContextNote(note) {}
+#  define ContextNote(note)	do {	} while (0)
 #endif
 #ifdef DEBUG_ASSERT
-#  define Assert(expr)							\
-	(global[233](__FILE__, __LINE__, MODULE_NAME, (int)(expr)))
+#  define Assert(expr)		do {					\
+	if (!(expr))							\
+		(global[233](__FILE__, __LINE__, MODULE_NAME));		\
+} while (0)
 #else
-#  define Assert(expr) {}
+#  define Assert(expr)	do {	} while (0)
 #endif
 #define allocsock ((int(*)(int sock,int options))global[234])
 #define call_hostbyip ((void(*)(IP, char *, int))global[235])
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/proto.h eggdrop1.5/src/proto.h
--- eggdrop1.5~/src/proto.h	Thu Oct 19 19:25:38 2000
+++ eggdrop1.5/src/proto.h	Mon Oct 23 22:38:01 2000
@@ -174,13 +174,13 @@
 int exist_lang_section(char *);
 
 /* main.c */
-void fatal(char *, int);
-int expected_memory();
-void patch(char *);
-void eggContext(char *, int, char *);
-void eggContextNote(char *, int, char *, char *);
-void eggAssert(char *, int, char *, int);
-void backup_userfile();
+void fatal(const char *, int);
+int expected_memory(void);
+void patch(const char *);
+void eggContext(const char *, int, const char *);
+void eggContextNote(const char *, int, const char *, const char *);
+void eggAssert(const char *, int, const char *);
+void backup_userfile(void);
 
 /* match.c */
 int _wild_match(register unsigned char *, register unsigned char *);




More information about the Patches mailing list