Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2002:
[Freeciv-Dev] Re: (PR#2333) Add function die()
Home

[Freeciv-Dev] Re: (PR#2333) Add function die()

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#2333) Add function die()
From: "Raimar Falke via RT" <rt@xxxxxxxxxxxxxx>
Date: Sun, 8 Dec 2002 02:33:07 -0800
Reply-to: rt@xxxxxxxxxxxxxx

On Thu, Nov 14, 2002 at 09:41:44AM -0800, Raimar Falke via RT wrote:
> 
> 
> The patch replaces code like below:
> 
>      if (team_id == TEAM_NONE) {
> -      freelog(LOG_ERROR, "Impossible: Too many teams!");
> -      assert(FALSE);
> -      exit(EXIT_FAILURE);
> +      die("Impossible: Too many teams!");
>      }
> 
> with 
> +  vreal_freelog(LOG_FATAL, format, ap);
> +  assert(FALSE);
> +  exit(EXIT_FAILURE);
> 
> It simplifies the code (no longer the questions "is it LOG_ERROR or
> LOG_FATAL" "exit or abort"). And it removes one dependency for
> stdlib.h.

An updated version is attached. I removed all cases which are
user-controlled. So a user shouldn't able to cause a die if he
supplied the wrong parameter, has a wrong installation or an invalid
ruleset. If however a program error occurs, or the user changed a
savegame the function will be called.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
  +#if defined(__alpha__) && defined(CONFIG_PCI)
  +       /*
  +        * The meaning of life, the universe, and everything. Plus
  +        * this makes the year come out right.
  +        */
  +       year -= 42;
  +#endif
    -- Patch for 1.3.2 (kernel/time.c) from Marcus Meissner

Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.232
diff -u -u -r1.232 aiunit.c
--- ai/aiunit.c 2002/12/04 13:34:26     1.232
+++ ai/aiunit.c 2002/12/08 09:44:36
@@ -228,10 +228,8 @@
      break;
  
   default:
-    freelog(LOG_FATAL, "In ai/aiunit.c: function unit_move_turns");
-    freelog(LOG_FATAL, "Illegal move type %d", unit_type(punit)->move_type);
-    assert(FALSE);
-    exit(EXIT_FAILURE);
+    die("ai/aiunit.c:unit_move_turns: illegal move type %d",
+       unit_type(punit)->move_type);
   }
   return move_time;
 }
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.87
diff -u -u -r1.87 control.c
--- client/control.c    2002/11/22 18:52:12     1.87
+++ client/control.c    2002/12/08 09:44:42
@@ -1228,7 +1228,7 @@
   if (punit && hover_state != HOVER_NONE) {
     switch (hover_state) {
     case HOVER_NONE:
-      abort(); /* well; shouldn't get here :) */
+      die("well; shouldn't get here :)");
     case HOVER_GOTO:
       do_unit_goto(xtile, ytile);
       break;
Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.42
diff -u -u -r1.42 goto.c
--- client/goto.c       2002/12/06 22:25:11     1.42
+++ client/goto.c       2002/12/08 09:44:42
@@ -435,8 +435,7 @@
 
       default:
        move_cost = 0;  /* silence compiler warning */
-       freelog(LOG_FATAL, "Bad move_type in create_goto_map().");
-       abort();
+       die("Bad move_type in create_goto_map().");
       } /****** end switch ******/
 
       /* Add the route to our warmap if it is worth keeping */
Index: client/helpdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/helpdata.c,v
retrieving revision 1.56
diff -u -u -r1.56 helpdata.c
--- client/helpdata.c   2002/11/07 16:04:52     1.56
+++ client/helpdata.c   2002/12/08 09:44:43
@@ -311,8 +311,7 @@
            }
          } impr_type_iterate_end;
        } else {
-         freelog(LOG_FATAL, "Bad current_type %d", current_type);
-         exit(EXIT_FAILURE);
+         die("Bad current_type %d", current_type);
        }
        genlist_sort(&category_nodes, help_item_compar);
        help_list_iterate(category_nodes, ptmp) {
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.263
diff -u -u -r1.263 packhand.c
--- client/packhand.c   2002/11/23 02:55:42     1.263
+++ client/packhand.c   2002/12/08 09:44:48
@@ -794,9 +794,7 @@
 **************************************************************************/
 void handle_move_unit()
 {
-  /* this packet should never get sent to a client */
-  assert(0);
-  exit(EXIT_FAILURE);
+  die("this packet should never get sent to a client");
 }
 
 /**************************************************************************
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.92
diff -u -u -r1.92 tilespec.c
--- client/tilespec.c   2002/12/07 09:59:18     1.92
+++ client/tilespec.c   2002/12/08 09:44:52
@@ -847,9 +847,7 @@
   
   /* (should get sprite_hash before connection) */
   if (!sprite_hash) {
-    freelog(LOG_FATAL, "attempt to lookup for %s %s before sprite_hash setup",
-           what, name);
-    exit(EXIT_FAILURE);
+    die("attempt to lookup for %s %s before sprite_hash setup", what, name);
   }
 
   sp = hash_lookup_data(sprite_hash, tag);
Index: client/agents/cma_core.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_core.c,v
retrieving revision 1.37
diff -u -u -r1.37 cma_core.c
--- client/agents/cma_core.c    2002/11/01 18:11:42     1.37
+++ client/agents/cma_core.c    2002/12/08 09:44:56
@@ -1298,12 +1298,10 @@
 
   /* Insert the given combination. */
   if (invalid_slot_for_insert == NULL) {
-    freelog(LOG_FATAL,
-           "No more free combinations left. You may increase "
-           "MAX_COMBINATIONS or \nreport this error to "
-           "freeciv-dev@xxxxxxxxxxx.\nCurrent MAX_COMBINATIONS=%d",
-           MAX_COMBINATIONS);
-    exit(EXIT_FAILURE);
+    die("No more free combinations left. You may increase "
+       "MAX_COMBINATIONS or \nreport this error to "
+       "freeciv-dev@xxxxxxxxxxx.\nCurrent MAX_COMBINATIONS=%d",
+       MAX_COMBINATIONS);
   }
 
   memcpy(invalid_slot_for_insert, combination, sizeof(struct combination));
@@ -1823,12 +1821,10 @@
     cma_release_city(pcity);
 
 #if (IS_DEVEL_VERSION || IS_BETA_VERSION)
-    freelog(LOG_ERROR, _("CMA: %s has changed multiple times. This may be "
-                        "an error in freeciv or bad luck. Please contact "
-                        "<freeciv-dev@xxxxxxxxxxx>. The CMA will detach "
-                        "itself from the city now."), pcity->name);
-    assert(0);
-    exit(EXIT_FAILURE);
+    die(_("CMA: %s has changed multiple times. This may be "
+         "an error in freeciv or bad luck. Please contact "
+         "<freeciv-dev@xxxxxxxxxxx>. The CMA will detach "
+         "itself from the city now."), pcity->name);
 #endif
   }
 
Index: common/hash.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/hash.c,v
retrieving revision 1.21
diff -u -u -r1.21 hash.c
--- common/hash.c       2002/11/14 09:15:02     1.21
+++ common/hash.c       2002/12/08 09:45:00
@@ -452,9 +452,7 @@
       }
       break;
     default:
-      freelog(LOG_FATAL, "Bad value %d in switch(bucket->used)",
-             (int)bucket->used);
-      exit(EXIT_FAILURE);
+      die("Bad value %d in switch(bucket->used)", (int) bucket->used);
     }
     i++;
     if (i==h->num_buckets) {
@@ -465,8 +463,7 @@
   if (deleted) {
     return deleted;
   }
-  freelog(LOG_FATAL, "Full hash table -- and somehow did not resize!!");
-  exit(EXIT_FAILURE);
+  die("Full hash table -- and somehow did not resize!!");
 }
 
 /**************************************************************************
@@ -615,9 +612,7 @@
       return bucket->key;
     counter++;
   }
-  /* never reached */
-  assert(0);
-  exit(EXIT_FAILURE);
+  die("never reached");
 }
 
 /**************************************************************************
Index: common/idex.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/idex.c,v
retrieving revision 1.9
diff -u -u -r1.9 idex.c
--- common/idex.c       2002/11/14 09:15:02     1.9
+++ common/idex.c       2002/12/08 09:45:00
@@ -90,7 +90,9 @@
     freelog(LOG_IDEX_ERR, "IDEX: city collision: new %d %p %s, old %d %p %s",
            pcity->id, (void*)pcity, pcity->name,
            old->id, (void*)old, old->name);
-    if (IDEX_DIE) abort();
+    if (IDEX_DIE) {
+      die("byebye");
+    }
   }
 }
 
@@ -107,7 +109,9 @@
     freelog(LOG_IDEX_ERR, "IDEX: unit collision: new %d %p %s, old %d %p %s",
            punit->id, (void*)punit, unit_name(punit->type),
            old->id, (void*)old, unit_name(old->type));
-    if (IDEX_DIE) abort();
+    if (IDEX_DIE) {
+      die("byebye");
+    }
   }
 }
 
@@ -123,14 +127,18 @@
     /* error */
     freelog(LOG_IDEX_ERR, "IDEX: city unreg missing: %d %p %s",
            pcity->id, (void*)pcity, pcity->name);
-    if (IDEX_DIE) abort();
+    if (IDEX_DIE) {
+      die("byebye");
+    }
   } else if (old != pcity) {
     /* error */
     freelog(LOG_IDEX_ERR,
            "IDEX: city unreg mismatch: unreg %d %p %s, old %d %p %s",
            pcity->id, (void*)pcity, pcity->name,
            old->id, (void*)old, old->name);
-    if (IDEX_DIE) abort();
+    if (IDEX_DIE) {
+      die("byebye");
+    }
   }
 }
 
@@ -146,14 +154,18 @@
     /* error */
     freelog(LOG_IDEX_ERR, "IDEX: unit unreg missing: %d %p %s",
            punit->id, (void*)punit, unit_name(punit->type));
-    if (IDEX_DIE) abort();
+    if (IDEX_DIE) {
+      die("byebye");
+    }
   } else if (old != punit) {
     /* error */
     freelog(LOG_IDEX_ERR,
            "IDEX: unit unreg mismatch: unreg %d %p %s, old %d %p %s",
            punit->id, (void*)punit, unit_name(punit->type),
            old->id, (void*)old, unit_name(old->type));
-    if (IDEX_DIE) abort();
+    if (IDEX_DIE) {
+      die("byebye");
+    }
   }
 }
 
Index: common/inputfile.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/inputfile.c,v
retrieving revision 1.30
diff -u -u -r1.30 inputfile.c
--- common/inputfile.c  2002/12/06 15:13:32     1.30
+++ common/inputfile.c  2002/12/08 09:45:02
@@ -562,7 +562,7 @@
 void inf_die(struct inputfile *inf, const char *message)
 {
   inf_log(inf, LOG_FATAL, message);
-  exit(EXIT_FAILURE);
+  die(message);
 }
 
 void inf_warn(struct inputfile *inf, const char *message)
Index: common/ioz.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/ioz.c,v
retrieving revision 1.14
diff -u -u -r1.14 ioz.c
--- common/ioz.c        2002/12/06 15:13:32     1.14
+++ common/ioz.c        2002/12/08 09:45:02
@@ -128,8 +128,7 @@
     break;
   default:
     /* Should never happen */
-    freelog(LOG_FATAL, "Internal error: Bad fz_fromFile method: %d", 
fp->method);
-    abort();
+    die("Internal error: Bad fz_fromFile method: %d", fp->method);
   }
   return fp;
 }
@@ -177,8 +176,7 @@
     break;
   default:
     /* Should never happen */
-    freelog(LOG_FATAL, "Internal error: Bad fz_fclose method: %d", fp->method);
-    abort();
+    die("Internal error: Bad fz_fclose method: %d", fp->method);
   }
   free(fp);
   return retval;
@@ -204,8 +202,7 @@
     break;
   default:
     /* Should never happen */
-    freelog(LOG_FATAL, "Internal error: Bad fz_fgets method: %d", fp->method);
-    abort();
+    die("Internal error: Bad fz_fgets method: %d", fp->method);
   }
   return retval;
 }
@@ -248,8 +245,7 @@
     break;
   default:
     /* Should never happen */
-    freelog(LOG_FATAL, "Internal error: Bad fz_fprintf method: %d", 
fp->method);
-    abort();
+    die("Internal error: Bad fz_fprintf method: %d", fp->method);
   }
   va_end(ap);
   return retval;
@@ -277,8 +273,7 @@
     break;
   default:
     /* Should never happen */
-    freelog(LOG_FATAL, "Internal error: Bad fz_ferror method: %d", fp->method);
-    abort();
+    die("Internal error: Bad fz_ferror method: %d", fp->method);
   }
   return retval;
 }
@@ -314,8 +309,7 @@
     break;
   default:
     /* Should never happen */
-    freelog(LOG_FATAL, "Internal error: Bad fz_strerror method: %d", 
fp->method);
-    abort();
+    die("Internal error: Bad fz_strerror method: %d", fp->method);
   }
   return retval;
 }
Index: common/mem.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/mem.c,v
retrieving revision 1.7
diff -u -u -r1.7 mem.c
--- common/mem.c        2002/02/12 04:49:52     1.7
+++ common/mem.c        2002/12/08 09:45:03
@@ -37,12 +37,8 @@
 static void handle_alloc_failure(size_t size, const char *called_as,
                                 int line, const char *file)
 {
-  freelog(LOG_FATAL, _("Out of memory trying to %s %lu bytes at line %d of 
%s."),
-         called_as, (unsigned long)size, line, file);
-  /*
-   * Do anything else here (cleanups? safe-save??)
-   */
-  exit(EXIT_FAILURE);
+  die(_("Out of memory trying to %s %lu bytes at line %d of %s."), called_as,
+      (unsigned long) size, line, file);
 }
 
 /**********************************************************************
Index: common/nation.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/nation.c,v
retrieving revision 1.28
diff -u -u -r1.28 nation.c
--- common/nation.c     2002/11/14 09:15:02     1.28
+++ common/nation.c     2002/12/08 09:45:03
@@ -89,7 +89,7 @@
 char **get_nation_leader_names(Nation_Type_id nation, int *dim)
 {
   if (!bounds_check_nation_id(nation, LOG_FATAL, "get_nation_leader_names")) {
-    exit(EXIT_FAILURE);
+    die("wrong nation %d", nation);
   }
   *dim = nations[nation].leader_count;
   return nations[nation].leader_name;
@@ -152,7 +152,7 @@
 {
   assert(plr != NULL);
   if (!bounds_check_nation_id(plr->nation, LOG_FATAL, "get_nation_by_plr")) {
-    exit(EXIT_FAILURE);
+    die("wrong nation %d", plr->nation);
   }
   return &nations[plr->nation];
 }
@@ -163,7 +163,7 @@
 struct nation_type *get_nation_by_idx(Nation_Type_id nation)
 {
   if (!bounds_check_nation_id(nation, LOG_FATAL, "get_nation_by_idx")) {
-    exit(EXIT_FAILURE);
+    die("wrong nation %d", nation);
   }
   return &nations[nation];
 }
@@ -240,7 +240,7 @@
 int get_nation_city_style(Nation_Type_id nation)
 {
   if (!bounds_check_nation_id(nation, LOG_FATAL, "get_nation_city_style")) {
-    exit(EXIT_FAILURE);
+    die("wrong nation %d", nation);
   }
   return nations[nation].city_style;
 }
@@ -316,9 +316,7 @@
     }
     /* check if too many teams */
     if (team_id == TEAM_NONE) {
-      freelog(LOG_ERROR, "Impossible: Too many teams!");
-      assert(FALSE);
-      exit(EXIT_FAILURE);
+      die("Impossible: Too many teams!");
     }
     /* add another team */
     teams[team_id].id = team_id;
Index: common/packets.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v
retrieving revision 1.226
diff -u -u -r1.226 packets.c
--- common/packets.c    2002/11/14 09:15:02     1.226
+++ common/packets.c    2002/12/08 09:45:10
@@ -2885,7 +2885,7 @@
       dio_put_uint8(&dout, PACKET_PATROL_ROUTE);
       break;
     default:
-      abort();
+      die("unknown type %d", type);
     }
 
     chunk_pos = 0;
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.103
diff -u -u -r1.103 player.c
--- common/player.c     2002/11/18 12:19:51     1.103
+++ common/player.c     2002/12/08 09:45:11
@@ -406,7 +406,7 @@
     } else if (pplayer->economic.luxury < maxrate) {
       pplayer->economic.luxury += 10;
     } else {
-      abort();
+      die("byebye");
     }
     surplus -= 10;
   }
@@ -534,8 +534,7 @@
 
   if (type < DS_LAST)
     return Q_(ds_names[type]);
-  freelog(LOG_FATAL, "Bad diplstate_type in diplstate_text: %d", type);
-  abort();
+  die("Bad diplstate_type in diplstate_text: %d", type);
 }
 
 /***************************************************************
Index: common/shared.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/shared.c,v
retrieving revision 1.96
diff -u -u -r1.96 shared.c
--- common/shared.c     2002/11/14 09:15:03     1.96
+++ common/shared.c     2002/12/08 09:45:13
@@ -646,6 +646,19 @@
   return (int) (ret + len);
 }
 
+void die(const char *format, ...)
+{
+  va_list ap;
+
+  va_start(ap, format);
+  vreal_freelog(LOG_FATAL, format, ap);
+  va_end(ap);
+
+  assert(FALSE);
+
+  exit(EXIT_FAILURE);
+}
+
 /***************************************************************************
   Returns string which gives users home dir, as specified by $HOME.
   Gets value once, and then caches result.
Index: common/shared.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/shared.h,v
retrieving revision 1.106
diff -u -u -r1.106 shared.h
--- common/shared.h     2002/11/21 13:35:31     1.106
+++ common/shared.h     2002/12/08 09:45:14
@@ -147,6 +147,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))) fc__attribute((noreturn));
+
 char *user_home_dir(void);
 char *user_username(void);
 const char **datafilelist(const char *suffix);
Index: common/tech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.c,v
retrieving revision 1.51
diff -u -u -r1.51 tech.c
--- common/tech.c       2002/11/14 09:15:03     1.51
+++ common/tech.c       2002/12/08 09:45:15
@@ -388,10 +388,8 @@
        GAME_DEFAULT_RESEARCHCOST;
     break;
   default:
-    freelog(LOG_ERROR, "Invalid tech_cost_style %d %d",
-           game.rgame.tech_cost_style, tech_cost_style);
-    assert(0);
-    exit(EXIT_FAILURE);
+    die("Invalid tech_cost_style %d %d", game.rgame.tech_cost_style,
+       tech_cost_style);
   }
 
   /* Research becomes more expensive. */
@@ -454,9 +452,7 @@
     break;
 
   default:
-    freelog(LOG_ERROR, "Invalid tech_leakage %d", game.rgame.tech_leakage);
-    assert(0);
-    exit(EXIT_FAILURE);
+    die("Invalid tech_leakage %d", game.rgame.tech_leakage);
   }
 
   /* If we have many players, tech cost may drop to 0.  */
Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.165
diff -u -u -r1.165 unit.c
--- common/unit.c       2002/11/15 21:24:30     1.165
+++ common/unit.c       2002/12/08 09:45:18
@@ -76,10 +76,8 @@
     break;
 
   default:
-    freelog(LOG_FATAL, "In common/unit.c: function unit_move_rate");
-    freelog(LOG_FATAL, "Illegal move type %d", unit_type(punit)->move_type);
-    assert(0);
-    exit(EXIT_FAILURE);
+    die("In common/unit.c:unit_move_rate: illegal move type %d",
+       unit_type(punit)->move_type);
   }
   
   if (move_rate < SINGLE_MOVE && unit_type(punit)->move_rate > 0) {
@@ -936,9 +934,7 @@
        return (text);
      }
    default:
-    freelog(LOG_FATAL, "Unknown unit activity %d in unit_activity_text()",
-           punit->activity);
-    exit(EXIT_FAILURE);
+    die("Unknown unit activity %d in unit_activity_text()", punit->activity);
   }
 }
 
Index: server/barbarian.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/barbarian.c,v
retrieving revision 1.56
diff -u -u -r1.56 barbarian.c
--- server/barbarian.c  2002/11/13 00:06:49     1.56
+++ server/barbarian.c  2002/12/08 09:45:20
@@ -100,8 +100,7 @@
   } players_iterate_end;
 
   if( newplayer >= MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS ) {
-    freelog( LOG_FATAL, "Too many players?");
-    abort();
+    die("Too many players?");
   }
 
   barbarians = &game.players[newplayer];
Index: server/diplomats.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplomats.c,v
retrieving revision 1.32
diff -u -u -r1.32 diplomats.c
--- server/diplomats.c  2002/11/14 09:15:04     1.32
+++ server/diplomats.c  2002/12/08 09:45:23
@@ -1226,8 +1226,7 @@
     y = victim_unit->y;
     victim_player = unit_owner(victim_unit);
   } else {
-    freelog(LOG_FATAL, "No victim in call to maybe_cause_incident()");
-    abort();
+    die("No victim in call to maybe_cause_incident()");
   }
 
   if (!pplayers_at_war(offender, victim_player) &&
@@ -1277,8 +1276,7 @@
     case DIPLOMAT_SABOTAGE:
       /* You can only do these when you are at war, so we should never
         get inside this "if" */
-      freelog(LOG_FATAL, "Bug in maybe_cause_incident()");
-      abort();
+      die("Bug in maybe_cause_incident()");
     }
     switch (ds) {
     case DS_WAR:
@@ -1297,8 +1295,7 @@
       punishment = GAME_MAX_REPUTATION/5;
       break;
     default:
-      freelog(LOG_FATAL, "Illegal diplstate in maybe_cause_incident.");
-      abort();
+      die("Illegal diplstate in maybe_cause_incident.");
     }
     offender->reputation = MAX(offender->reputation - punishment, 0);
     victim_player->diplstates[offender->player_no].has_reason_to_cancel = 2;
Index: server/gotohand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v
retrieving revision 1.157
diff -u -u -r1.157 gotohand.c
--- server/gotohand.c   2002/11/14 09:15:04     1.157
+++ server/gotohand.c   2002/12/08 09:45:27
@@ -336,8 +336,7 @@
        break;
       default:
        move_cost = 0; /* silence compiler warning */
-       freelog(LOG_FATAL, "Bad/unimplemented move_type in 
really_generate_warmap().");
-       abort();
+       die("Bad/unimplemented move_type in really_generate_warmap().");
       }
     } adjc_dir_iterate_end;
   }
@@ -762,8 +761,7 @@
 
       default:
        move_cost = MAXCOST;    /* silence compiler warning */
-       freelog(LOG_FATAL, "Bad move_type in find_the_shortest_path().");
-       abort();
+       die("Bad move_type in find_the_shortest_path().");
       } /****** end switch ******/
 
       /* Add the route to our warmap if it is worth keeping */
Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.100
diff -u -u -r1.100 mapgen.c
--- server/mapgen.c     2002/11/14 09:15:04     1.100
+++ server/mapgen.c     2002/12/08 09:45:31
@@ -1159,11 +1159,9 @@
     }
     counter++;
     if (counter > MAXTRIES) {
-      freelog(LOG_FATAL,
-             "The server appears to have gotten into an infinite loop "
-             "in the allocation of starting positions, and will abort.\n"
-             "Please report this bug at " WEBSITE_URL);
-      abort();
+      die("The server appears to have gotten into an infinite loop "
+         "in the allocation of starting positions, and will abort.\n"
+         "Please report this bug at " WEBSITE_URL);
     }
   }
   map.num_start_positions = game.nplayers;
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.250
diff -u -u -r1.250 plrhand.c
--- server/plrhand.c    2002/11/14 09:15:04     1.250
+++ server/plrhand.c    2002/12/08 09:45:35
@@ -1337,8 +1337,7 @@
   /* Not allowed after a game has started */
   if (!(game.is_new_game && (server_state==PRE_GAME_STATE ||
                             server_state==SELECT_RACES_STATE))) {
-    freelog(LOG_FATAL, "You can't remove players after the game has started!");
-    abort();
+    die("You can't remove players after the game has started!");
   }
 
   freelog(LOG_NORMAL, _("Removing player %s."), pplayer->name);
Index: server/report.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/report.c,v
retrieving revision 1.39
diff -u -u -r1.39 report.c
--- server/report.c     2002/11/27 18:36:37     1.39
+++ server/report.c     2002/12/08 09:45:37
@@ -530,9 +530,7 @@
   static char buf[64];
 
   if (my_snprintf(buf, sizeof(buf), "%s%s", int_to_text(val), uni) == -1) {
-    freelog(LOG_ERROR, "String truncated in value_units()!");
-    assert(0);
-    exit(EXIT_FAILURE);
+    die("String truncated in value_units()!");
   }
 
   return buf;
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.99
diff -u -u -r1.99 savegame.c
--- server/savegame.c   2002/11/19 13:35:31     1.99
+++ server/savegame.c   2002/12/08 09:45:42
@@ -72,10 +72,8 @@
       if (regular_map_pos_is_normal(x, y)) {            \
        line[x] = get_xy_char;                          \
         if(!my_isprint(line[x] & 0x7f)) {               \
-          freelog(LOG_FATAL, _("Trying to write invalid"\
-                 " map data: '%c' %d"),                \
-                 line[x], line[x]);                    \
-          exit(EXIT_FAILURE);                           \
+          die(_("Trying to write invalid map "          \
+                 "data: '%c' %d"), line[x], line[x]);   \
         }                                               \
       } else {                                          \
         /* skipped over in loading */                   \
@@ -193,8 +191,7 @@
   pch = strchr(hex_chars, ch);
 
   if (!pch || ch == '\0') {
-    freelog(LOG_FATAL, "Unknown hex value: '%c' %d", ch, ch);
-    exit(EXIT_FAILURE);
+    die("Unknown hex value: '%c' %d", ch, ch);
   }
   return (pch - hex_chars) << (halfbyte * 4);
 }
@@ -208,8 +205,7 @@
   char *pch = strchr(terrain_chars, ch);
 
   if (!pch || ch == '\0') {
-    freelog(LOG_FATAL, "Unknown terrain type: '%c' %d", ch, ch);
-    exit(EXIT_FAILURE);
+    die("Unknown terrain type: '%c' %d", ch, ch);
   }
   return pch - terrain_chars;
 }
@@ -1000,12 +996,14 @@
        goto_buf = secfile_lookup_str(file, "player%d.u%d.goto_route_x", plrno, 
i);
        goto_buf_ptr = goto_buf;
        for (j = 0; j < len; j++) {
-         if (sscanf(goto_buf_ptr, "%d", &pgr->pos[j].x) == 0)
-           abort();
+         if (sscanf(goto_buf_ptr, "%d", &pgr->pos[j].x) == 0) {
+           die("not an int");
+         }
          while (*goto_buf_ptr != ',') {
            goto_buf_ptr++;
-           if (*goto_buf_ptr == '\0')
-             abort();
+           if (*goto_buf_ptr == '\0') {
+             die("byebye");
+           }
          }
          goto_buf_ptr++;
        }
@@ -1013,12 +1011,14 @@
        goto_buf = secfile_lookup_str(file, "player%d.u%d.goto_route_y", plrno, 
i);
        goto_buf_ptr = goto_buf;
        for (j = 0; j < len; j++) {
-         if (sscanf(goto_buf_ptr, "%d", &pgr->pos[j].y) == 0)
-           abort();
+         if (sscanf(goto_buf_ptr, "%d", &pgr->pos[j].y) == 0) {
+           die("not an int");
+         }
          while (*goto_buf_ptr != ',') {
            goto_buf_ptr++;
-           if (*goto_buf_ptr == '\0')
-             abort();
+           if (*goto_buf_ptr == '\0') {
+             die("byebye");
+           }
          }
          goto_buf_ptr++;
        }
Index: server/sernet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sernet.c,v
retrieving revision 1.101
diff -u -u -r1.101 sernet.c
--- server/sernet.c     2002/11/23 14:58:43     1.101
+++ server/sernet.c     2002/12/08 09:45:44
@@ -545,8 +545,7 @@
       char buf[BUF_SIZE+1];
       
       if((didget=read(0, buf, BUF_SIZE))==-1) {
-       freelog(LOG_FATAL, "read from stdin failed");
-       exit(EXIT_FAILURE);
+       die("read from stdin failed");
       }
 
       if(didget==0) {
@@ -758,8 +757,7 @@
   int opt;
 
   if((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
-    freelog(LOG_FATAL, "socket failed: %s", mystrerror(errno));
-    exit(EXIT_FAILURE);
+    die("socket failed: %s", mystrerror(errno));
   }
 
   opt=1; 
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.106
diff -u -u -r1.106 srv_main.c
--- server/srv_main.c   2002/11/14 09:15:05     1.106
+++ server/srv_main.c   2002/12/08 09:45:48
@@ -1703,9 +1703,8 @@
 *************************************************************************/
 static int mark_nation_as_used (int nation) 
 {
-  if(num_nations_avail <= 0) {/* no more unused nation */
-      freelog(LOG_FATAL, _("Argh! ran out of nations!"));
-      exit(EXIT_FAILURE);
+  if (num_nations_avail <= 0) {        /* no more unused nation */
+    die(_("Argh! ran out of nations!"));
   }
 
    nations_used[nations_avail[num_nations_avail-1]]=nations_used[nation];
Index: server/unithand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v
retrieving revision 1.242
diff -u -u -r1.242 unithand.c
--- server/unithand.c   2002/11/14 09:15:05     1.242
+++ server/unithand.c   2002/12/08 09:45:51
@@ -644,17 +644,13 @@
 
   /* Sanity checks */
   if (pplayers_non_attack(unit_owner(punit), unit_owner(pdefender))) {
-    freelog(LOG_FATAL,
-           "Trying to attack a unit with which you have peace or cease-fire at 
%i, %i",
-           def_x, def_y);
-    abort();
+    die("Trying to attack a unit with which you have peace "
+       "or cease-fire at %i, %i", def_x, def_y);
   }
   if (pplayers_allied(unit_owner(punit), unit_owner(pdefender))
       && !(unit_flag(punit, F_NUCLEAR) && punit == pdefender)) {
-    freelog(LOG_FATAL,
-           "Trying to attack a unit with which you have alliance at %i, %i",
-           def_x, def_y);
-    abort();
+    die("Trying to attack a unit with which you have alliance at %i, %i",
+       def_x, def_y);
   }
 
   if(unit_flag(punit, F_NUCLEAR)) {
@@ -944,8 +940,7 @@
       } else if (pdefender) {
        packet.target_id = pdefender->id;
       } else {
-       freelog(LOG_FATAL, "Bug in unithand.c: no diplomat target.");
-       abort();
+       die("Bug in unithand.c: no diplomat target.");
       }
       packet.diplomat_id = punit->id;
       packet.action_type = DIPLOMAT_CLIENT_POPUP_DIALOG;
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.199
diff -u -u -r1.199 unittools.c
--- server/unittools.c  2002/12/06 02:41:40     1.199
+++ server/unittools.c  2002/12/08 09:45:58
@@ -97,9 +97,7 @@
     /* Ruleset code should ensure there is at least one unit for each
      * possibly-required role, or check before calling this function.
      */
-    freelog(LOG_FATAL, "No unit types in find_a_unit_type(%d,%d)!",
-           role, role_tech);
-    abort();
+    die("No unit types in find_a_unit_type(%d,%d)!", role, role_tech);
   }
   return which[myrand(num)];
 }
@@ -1941,8 +1939,7 @@
   } else { /* unitcount > 1 */
     int i;
     if (!(unitcount > 1)) {
-      freelog(LOG_FATAL, "Error in kill_unit, unitcount is %i", unitcount);
-      abort();
+      die("Error in kill_unit, unitcount is %i", unitcount);
     }
     /* initialize */
     for (i = 0; i<MAX_NUM_PLAYERS+MAX_NUM_BARBARIANS; i++) {

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#2333) Add function die(), Raimar Falke via RT <=