Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] (PR#8842) preprocessor and sanity checking
Home

[Freeciv-Dev] (PR#8842) preprocessor and sanity checking

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8842) preprocessor and sanity checking
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 25 May 2004 22:55:29 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8842 >

The current sanity_check preprocessor checks are annoying and not really 
correct.

- Annoyingly, you have to use an #ifdef around the call to sanity_check. 
  At least it looks like you do at first glance.  In reality you don't 
*have* to.  But you will end up with an empty function call.

- It's not clear what even controlls whether the sanity check is done. 
In sanitycheck.c there is an #ifndef NDEBUG.  In srv_main.c there is an 
if IS_DEVELOPMENT_VERSION || IS_BETA_VERSION.  In fact both of these 
have to be met for the sanity check to be done.  Very haphazard.

This patch introduces a new #define into sanitycheck.h.  If DEBUG is 
set, or we're in a development/beta version and NDEBUG isn't set, then 
SANITY_CHECKING will be defined.  Only if this is done will the 
sanity_check and sanity_check_city functions exist.  The same check is 
used in sanitycheck.h and sanitycheck.c so it is consistent.  And the 
caller doesn't have to worry about putting in any #if checks.

jason

Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.40
diff -u -r1.40 sanitycheck.c
--- server/sanitycheck.c        25 Jan 2004 08:04:53 -0000      1.40
+++ server/sanitycheck.c        26 May 2004 04:31:30 -0000
@@ -30,7 +30,7 @@
 #include "sanitycheck.h"
 #include "unittools.h"
 
-#ifndef NDEBUG
+#ifdef SANITY_CHECKING
 
 /**************************************************************************
 ...
@@ -360,14 +360,11 @@
   }
 }
 
-#endif /* !NDEBUG */
-
 /**************************************************************************
 ...
 **************************************************************************/
 void sanity_check(void)
 {
-#ifndef NDEBUG
   check_specials();
   check_fow();
   check_misc();
@@ -375,5 +372,6 @@
   check_cities();
   check_units();
   check_players();
-#endif /* !NDEBUG */
 }
+
+#endif /* SANITY_CHECKING */
Index: server/sanitycheck.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.h,v
retrieving revision 1.4
diff -u -r1.4 sanitycheck.h
--- server/sanitycheck.h        22 Oct 2003 14:03:32 -0000      1.4
+++ server/sanitycheck.h        26 May 2004 04:31:30 -0000
@@ -15,13 +15,24 @@
 
 struct city;
 
-#ifndef NDEBUG
+#if ((IS_BETA_VERSION || IS_DEVEL_VERSION) && !defined NDEBUG) \
+  || defined DEBUG
+#  define SANITY_CHECKING
+#endif
+
+#ifdef SANITY_CHECKING
+
 #  define sanity_check_city(x) real_sanity_check_city(x, __FILE__, __LINE__)
 void real_sanity_check_city(struct city *pcity, const char *file, int line);
-#else /* NDEBUG */
-#  define sanity_check_city(x) (void)0
-#endif /* NDEBUG */
 
 void sanity_check(void);
 
+#else /* SANITY_CHECKING */
+
+#  define sanity_check_city(x) (void)0
+#  define sanity_check() (void)0
+
+#endif /* SANITY_CHECKING */
+
+
 #endif  /* FC__SANITYCHECK_H */
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.161
diff -u -r1.161 srv_main.c
--- server/srv_main.c   25 May 2004 00:33:16 -0000      1.161
+++ server/srv_main.c   26 May 2004 04:31:30 -0000
@@ -1341,9 +1341,7 @@
     freelog(LOG_DEBUG, "Begin turn");
     begin_turn();
 
-#if (IS_DEVEL_VERSION || IS_BETA_VERSION)
     sanity_check();
-#endif
 
     force_end_of_sniff = FALSE;
 
@@ -1383,9 +1381,7 @@
     
     conn_list_do_buffer(&game.game_connections);
 
-#if (IS_DEVEL_VERSION || IS_BETA_VERSION)
     sanity_check();
-#endif
 
     /* 
      * This empties the client Messages window; put this before

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#8842) preprocessor and sanity checking, Jason Short <=