Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2003:
[Freeciv-Dev] (PR#6223) improved die()
Home

[Freeciv-Dev] (PR#6223) improved die()

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#6223) improved die()
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Sun, 21 Sep 2003 03:51:32 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This improves the die() call so that file and line where die() was called
is printed on exit. This is very useful for debugging and bug reports. I
hope the use of variadic macros is portable. I think they are C99 safe, at
least.

  - Per

Index: common/shared.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/shared.h,v
retrieving revision 1.116
diff -u -r1.116 shared.h
--- common/shared.h     15 Aug 2003 02:39:59 -0000      1.116
+++ common/shared.h     21 Sep 2003 10:49:05 -0000
@@ -175,8 +175,9 @@
 int cat_snprintf(char *str, size_t n, const char *format, ...)
      fc__attribute((format (printf, 3, 4)));
 
-void die(const char *format, ...)
-     fc__attribute((format (printf, 1, 2)));
+#define die(...) real_die(__FILE__, __LINE__, __VA_ARGS__)
+void real_die(const char *file, int line, const char *format, ...)
+      fc__attribute((format (printf, 3, 4)));
 
 char *user_home_dir(void);
 char *user_username(void);
Index: common/shared.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/shared.c,v
retrieving revision 1.102
diff -u -r1.102 shared.c
--- common/shared.c     20 Apr 2003 19:26:17 -0000      1.102
+++ common/shared.c     21 Sep 2003 10:49:06 -0000
@@ -651,10 +651,11 @@
   should only be called for code errors - user errors (like not being able
   to find a tileset) should just exit rather than dumping core.
 ***************************************************************************/
-void die(const char *format, ...)
+void real_die(const char *file, int line, const char *format, ...)
 {
   va_list ap;
 
+  freelog(LOG_FATAL, "Detected fatal error in %s line %d:", file, line);
   va_start(ap, format);
   vreal_freelog(LOG_FATAL, format, ap);
   va_end(ap);

[Prev in Thread] Current Thread [Next in Thread]