Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] (PR#12740) remove some side effects in tileset_read_toplev
Home

[Freeciv-Dev] (PR#12740) remove some side effects in tileset_read_toplev

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12740) remove some side effects in tileset_read_toplevel
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 7 Apr 2005 23:21:42 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch removes two side effects in tileset_read_toplevel.

1.  Don't set the tileset (global) variable.  This is now done by the 
callers.

2.  Don't crash if a specfile isn't present - instead just return NULL.

Once all side effects are gone it is possible to call 
tileset_read_toplevel to "check" if we can load a tileset, without 
completely failing if the load fails.  See PR#12488.

-jason

Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.285
diff -u -r1.285 tilespec.c
--- client/tilespec.c   6 Apr 2005 17:36:14 -0000       1.285
+++ client/tilespec.c   8 Apr 2005 06:19:12 -0000
@@ -1142,7 +1142,6 @@
   enum direction8 dir;
   struct tileset *t = tileset_new();
 
-  tileset = t; /* HACK: because some functions still use the global value. */
   fname = tilespec_fullname(tileset_name);
   freelog(LOG_VERBOSE, "tilespec file is %s", fname);
 
@@ -1443,11 +1442,17 @@
   t->sprite_hash = hash_new(hash_fval_string, hash_fcmp_string);
   for (i = 0; i < num_spec_files; i++) {
     struct specfile *sf = fc_malloc(sizeof(*sf));
+    char *dname;
 
     freelog(LOG_DEBUG, "spec file %s", spec_filenames[i]);
     
     sf->big_sprite = NULL;
-    sf->file_name = mystrdup(datafilename_required(spec_filenames[i]));
+    dname = datafilename(spec_filenames[i]);
+    if (!dname) {
+      tileset_free(t);
+      return NULL;
+    }
+    sf->file_name = mystrdup(dname);
     scan_specfile(t, sf, duplicates_ok);
 
     specfile_list_prepend(t->specfiles, sf);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12740) remove some side effects in tileset_read_toplevel, Jason Short <=