<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39365 >

On Sat, 12 May 2007, William Allen Simpson wrote:
> Locally, I added a LOG_VERBOSE call with line numbers; found one problem,
> so far.  Could be LOG_DEBUG instead, should this be added to the source?

Attached patch committed. Hope this helps.

   - Per
Index: utility/rand.c
===================================================================
--- utility/rand.c      (revision 12943)
+++ utility/rand.c      (working copy)
@@ -42,6 +42,7 @@
 
 #include "rand.h"
 
+#define LOG_RAND LOG_DEBUG
 
 /* A global random state:
  * Initialized by mysrand(), updated by myrand(),
@@ -77,13 +78,17 @@
   directly representable in type RANDOM_TYPE, so we do instead:
          divisor = MAX_UINT32/size
 *************************************************************************/
-RANDOM_TYPE myrand(RANDOM_TYPE size) 
+RANDOM_TYPE myrand_debug(RANDOM_TYPE size, const char *called_as, int line,
+                         const char *file)
 {
   RANDOM_TYPE new_rand, divisor, max;
   int bailout = 0;
 
   assert(rand_state.is_init);
-    
+
+  freelog(LOG_RAND, "%s(%lu) at line %d of %s",
+          called_as, (unsigned long)size, line, file);
+
   if (size > 1) {
     divisor = MAX_UINT32 / size;
     max = size * divisor - 1;
@@ -108,7 +113,7 @@
     rand_state.v[rand_state.x] = new_rand;
 
     if (++bailout > 10000) {
-      freelog(LOG_ERROR, "Bailout in myrand(%u)", size);
+      freelog(LOG_ERROR, "Bailout in myrand(%lu)", (unsigned long)size);
       new_rand = 0;
       break;
     }
@@ -121,7 +126,7 @@
     new_rand = 0;
   }
 
-  /* freelog(LOG_DEBUG, "rand(%u) = %u", size, new_rand); */
+  freelog(LOG_RAND, "myrand(%lu) = %lu", (unsigned long)size, (unsigned 
long)new_rand);
 
   return new_rand;
 } 
@@ -179,6 +184,7 @@
 *************************************************************************/
 void set_myrand_state(RANDOM_STATE state)
 {
+  freelog(LOG_RAND, "set_myrand_state");
   rand_state = state;
 }
 
Index: utility/rand.h
===================================================================
--- utility/rand.h      (revision 12943)
+++ utility/rand.h      (working copy)
@@ -26,7 +26,12 @@
   bool is_init;                        /* initially 0 for static storage */
 } RANDOM_STATE;
 
-RANDOM_TYPE myrand(RANDOM_TYPE size);
+#define myrand(vsize)      myrand_debug((vsize), "myrand", \
+                                        __LINE__, __FILE__)
+
+RANDOM_TYPE myrand_debug(RANDOM_TYPE size, const char *called_as, 
+                         int line, const char *file);
+
 void mysrand(RANDOM_TYPE seed);
 
 bool myrand_is_init(void);
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to