Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2003:
[Freeciv-Dev] Re: (PR#3801) use of "malloc" attribute in mem.h
Home

[Freeciv-Dev] Re: (PR#3801) use of "malloc" attribute in mem.h

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] Re: (PR#3801) use of "malloc" attribute in mem.h
From: "Rafa³ Bursig" <bursig@xxxxxxxxx>
Date: Wed, 26 Mar 2003 17:43:27 -0800
Reply-to: rt@xxxxxxxxxxxxxx

Dnia 2003.03.26 22:25 Raimar Falke napisa³(a):
> On Wed, Mar 26, 2003 at 12:04:09PM -0800, Rafa? Bursig wrote:
> >
> > Hi
> >
> > This code allow us use "malloc" attribute with
> > fc_(malloc,calloc,realloc).
> > Problem is that this attribute is avilable in gcc >= 3.x then we
> must
> > have new fc_attribute_3x macro which check gcc version.
> >
> > I don't check it with gcc < 3.x then some good peoples could do it.
> 
> With gcc 3.2 I'm not able to produce a different asm output on the
> files in common/, ai/ and server/. So this is a nop. I don't see a
> reason for applying this change before the gcc folks make their home
> work and really implement this optimization.
> 
Here is the same patch + using "pure"/"const" attribute.
I build 2 tree one with and secound without this patch. Both was 
compile with -O3 -fomit-frame-poiter.

With patch tree have smaller common *.a file and biger gui-sdl *.a file 
than without patch.
Totaly with pach tree has bigger "civclient" executable file.

I have not time check rest becouse current my destiny is... bed :)

Raimar could you look on it closer, please.

Rafal

----------------------------------------------------------------------
Kochasz pilke nozna? Zagraj i wygraj! >>> http://link.interia.pl/f16fb

diff -u -r fcc/common/city.h fc2/common/city.h
--- fcc/common/city.h   Wed Feb  5 17:41:34 2003
+++ fc2/common/city.h   Thu Mar 27 00:28:47 2003
@@ -319,8 +316,8 @@
 
 /* properties */
 
-struct player *city_owner(struct city *pcity);
-int city_population(struct city *pcity);
+struct player *city_owner(struct city *pcity)  fc__attribute_3x((pure));
+int city_population(struct city *pcity)        fc__attribute_3x((pure));
 int city_gold_surplus(struct city *pcity);
 int city_buy_cost(struct city *pcity);
 bool city_happy(struct city *pcity);  /* generally use celebrating instead */
@@ -362,7 +359,7 @@
 /* city map functions */
 
 bool is_valid_city_coords(const int city_x, const int city_y);
-bool is_city_center(int city_x, int city_y);
+bool is_city_center(int city_x, int city_y)    fc__attribute_3x((const));
 bool map_to_city_map(int *city_map_x, int *city_map_y,
                    const struct city *const pcity, int map_x, int map_y);
 
@@ -430,7 +427,7 @@
 bool city_exists_within_city_radius(int x, int y, bool may_be_on_center);
 
 /* granary size as a function of city size */
-int city_granary_size(int city_size);
+int city_granary_size(int city_size)   fc__attribute_3x((pure));
 
 void city_add_improvement(struct city *pcity,Impr_Type_id impr);
 void city_remove_improvement(struct city *pcity,Impr_Type_id impr);
diff -u -r fcc/common/game.h fc2/common/game.h
--- fcc/common/game.h   Thu Feb 13 16:48:21 2003
+++ fc2/common/game.h   Thu Mar 27 00:17:26 2003
@@ -248,8 +250,8 @@
 
 void translate_data_names(void);
 
-struct player *get_player(int player_id);
-int get_num_human_and_ai_players(void);
+struct player *get_player(int player_id)       fc__attribute_3x((pure));
+int get_num_human_and_ai_players(void)         fc__attribute_3x((pure));
 
 extern struct civ_game game;
 extern bool is_server;
diff -u -r fcc/common/improvement.c fc2/common/improvement.c
--- fcc/common/improvement.c    Thu Feb 13 16:48:21 2003
+++ fc2/common/improvement.c    Thu Mar 27 00:06:37 2003
@@ -306,7 +306,7 @@
 **************************************************************************/
 const char *get_improvement_name(Impr_Type_id id)
 {
-  return get_improvement_type(id)->name; 
+  return (improvement_types[id].name); 
 }
 
 /**************************************************************************
diff -u -r fcc/common/improvement.h fc2/common/improvement.h
--- fcc/common/improvement.h    Sun Feb 16 23:59:17 2003
+++ fc2/common/improvement.h    Thu Mar 27 00:12:23 2003
@@ -226,14 +226,14 @@
 
 /* improvement functions */
 void improvements_free(void);
-struct impr_type *get_improvement_type(Impr_Type_id id);
+struct impr_type *get_improvement_type(Impr_Type_id id) 
fc__attribute_3x((pure));
 bool improvement_exists(Impr_Type_id id);
-int improvement_value(Impr_Type_id id);
-bool is_wonder(Impr_Type_id id);
-const char *get_improvement_name(Impr_Type_id id);
+int improvement_value(Impr_Type_id id)                 
fc__attribute_3x((pure));
+bool is_wonder(Impr_Type_id id)                        
fc__attribute_3x((pure));
+const char *get_improvement_name(Impr_Type_id id)      
fc__attribute_3x((pure));
 
 /* FIXME: remove improvement_variant() when gen-impr obsoletes */
-int improvement_variant(Impr_Type_id id);  
+int improvement_variant(Impr_Type_id id)       fc__attribute_3x((pure));
 
 bool improvement_obsolete(struct player *pplayer, Impr_Type_id id);
 bool improvement_redundant(struct player *pplayer,struct city *pcity,
diff -u -r fcc/common/map.h fc2/common/map.h
--- fcc/common/map.h    Thu Mar 13 12:53:07 2003
+++ fc2/common/map.h    Thu Mar 27 00:40:36 2003
@@ -155,10 +159,17 @@
 };
 
 struct civ_map { 
+  bool fixed_start_positions;
+  bool have_specials;
+  bool have_huts;
+  bool have_rivers_overlay;    /* only applies if !have_specials */
+  bool is_earth;
+  bool tinyisles;
+  bool separatepoles;
+  
   int xsize, ysize;
   int seed;
   int riches;
-  bool is_earth;
   int huts;
   int landpercent;
   int grasssize;
@@ -168,26 +179,20 @@
   int riverlength;
   int forestsize;
   int generator;
-  bool tinyisles;
-  bool separatepoles;
   int num_start_positions;
-  bool fixed_start_positions;
-  bool have_specials;
-  bool have_huts;
-  bool have_rivers_overlay;    /* only applies if !have_specials */
   int num_continents;
   struct tile *tiles;
   struct map_position start_positions[MAX_NUM_NATIONS];
 };
 
-bool map_is_empty(void);
+bool map_is_empty(void)        fc__attribute_3x((pure));
 void map_init(void);
 void map_allocate(void);
 void map_free(void);
 
 const char *map_get_tile_info_text(int x, int y);
 const char *map_get_tile_fpt_text(int x, int y);
-struct tile *map_get_tile(int x, int y);
+struct tile *map_get_tile(int x, int y)        fc__attribute_3x((pure));
 
 int map_distance(int x0, int y0, int x1, int y1);
 int real_map_distance(int x0, int y0, int x1, int y1);
@@ -198,7 +203,7 @@
 int get_direction_for_step(int start_x, int start_y, int end_x, int end_y);
 
 void map_set_continent(int x, int y, int val);
-unsigned short map_get_continent(int x, int y);
+unsigned short map_get_continent(int x, int y) fc__attribute_3x((pure));
 
 void initialize_move_costs(void);
 void reset_move_costs(int x, int y);
@@ -252,14 +257,14 @@
      (dest_y) = (src_y) + DIR_DY[(dir)],               \
      normalize_map_pos(&(dest_x), &(dest_y)))
 
-struct city *map_get_city(int x, int y);
+struct city *map_get_city(int x, int y)        fc__attribute_3x((pure));
 void map_set_city(int x, int y, struct city *pcity);
-enum tile_terrain_type map_get_terrain(int x, int y);
-enum tile_special_type map_get_special(int x, int y);
+enum tile_terrain_type map_get_terrain(int x, int y)   
fc__attribute_3x((pure));
+enum tile_special_type map_get_special(int x, int y)   
fc__attribute_3x((pure));
 void map_set_terrain(int x, int y, enum tile_terrain_type ter);
 void map_set_special(int x, int y, enum tile_special_type spe);
 void map_clear_special(int x, int y, enum tile_special_type spe);
-bool is_real_map_pos(int x, int y);
+bool is_real_map_pos(int x, int y)     fc__attribute_3x((pure));
 bool is_normal_map_pos(int x, int y);
 
 /* implemented in server/maphand.c and client/climisc.c */
@@ -288,10 +293,10 @@
   ((x) < (dist) || (x) >= map.xsize - (dist)                  \
    || (y) < (dist) || (y) >= map.ysize - (dist))
 
-bool normalize_map_pos(int *x, int *y);
+bool normalize_map_pos(int *x, int *y) fc__attribute_3x((pure));
 void nearest_real_pos(int *x, int *y);
 void map_distance_vector(int *dx, int *dy, int x0, int y0, int x1, int y1);
-int map_num_tiles(void);
+int map_num_tiles(void)        fc__attribute_3x((pure));
 
 void rand_neighbour(int x0, int y0, int *x, int *y);
 void rand_map_pos(int *x, int *y);
@@ -300,10 +305,10 @@
 bool is_tiles_adjacent(int x0, int y0, int x1, int y1);
 bool is_move_cardinal(int start_x, int start_y, int end_x, int end_y);
 int map_move_cost(struct unit *punit, int x, int y);
-struct tile_type *get_tile_type(enum tile_terrain_type type);
+struct tile_type *get_tile_type(enum tile_terrain_type type)   
fc__attribute_3x((pure));
 void tile_types_free(void);
 enum tile_terrain_type get_terrain_by_name(const char * name);
-const char *get_terrain_name(enum tile_terrain_type type);
+const char *get_terrain_name(enum tile_terrain_type type) 
fc__attribute_3x((pure));
 enum tile_special_type get_special_by_name(const char * name);
 const char *get_special_name(enum tile_special_type type);
 bool is_terrain_near_tile(int x, int y, enum tile_terrain_type t);
@@ -321,7 +326,7 @@
 int get_tile_food_base(struct tile * ptile);
 int get_tile_shield_base(struct tile * ptile);
 int get_tile_trade_base(struct tile * ptile);
-int get_tile_infrastructure_set(struct tile * ptile);
+int get_tile_infrastructure_set(struct tile * ptile)   
fc__attribute_3x((pure));
 const char *map_get_infrastructure_text(int spe);
 int map_get_infrastructure_prerequisite(int spe);
 enum tile_special_type get_preferred_pillage(int pset);
@@ -331,15 +336,15 @@
 void change_terrain(int x, int y, enum tile_terrain_type type);
 void map_transform_tile(int x, int y);
 
-int map_build_road_time(int x, int y);
-int map_build_irrigation_time(int x, int y);
-int map_build_mine_time(int x, int y);
-int map_transform_time(int x, int y);
-int map_build_rail_time(int x, int y);
-int map_build_airbase_time(int x, int y);
-int map_build_fortress_time(int x, int y);
-int map_clean_pollution_time(int x, int y);
-int map_clean_fallout_time(int x, int y);
+int map_build_road_time(int x, int y)          fc__attribute_3x((pure));
+int map_build_irrigation_time(int x, int y)    fc__attribute_3x((pure));
+int map_build_mine_time(int x, int y)          fc__attribute_3x((pure));
+int map_transform_time(int x, int y)           fc__attribute_3x((pure));
+int map_build_rail_time(int x, int y)          fc__attribute_3x((const));
+int map_build_airbase_time(int x, int y)       fc__attribute_3x((const));
+int map_build_fortress_time(int x, int y)      fc__attribute_3x((const));
+int map_clean_pollution_time(int x, int y)     fc__attribute_3x((const));
+int map_clean_fallout_time(int x, int y)       fc__attribute_3x((const));
 int map_activity_time(enum unit_activity activity, int x, int y);
 
 bool can_channel_land(int x, int y);
diff -u -r fcc/common/mem.h fc2/common/mem.h
--- fcc/common/mem.h    Sat May  1 05:57:23 1999
+++ fc2/common/mem.h    Wed Mar 26 20:44:32 2003
@@ -16,6 +16,7 @@
 
 #include <stdlib.h>            /* size_t; actually stddef.h, but stdlib.h
                                   might be more reliable? --dwp */
+#include "shared.h"            /* fc_attribute_3x */
 
 /* fc_malloc, fc_realloc, fc_calloc:
  * fc_ stands for freeciv; the return value is checked,
@@ -39,13 +40,13 @@
  * use the macros above instead.
  */
 void *fc_real_malloc(size_t size,
-                    const char *called_as, int line, const char *file);
+    const char *called_as, int line, const char *file) 
fc__attribute_3x((malloc));
 void *fc_real_realloc(void *ptr, size_t size,
-                     const char *called_as, int line, const char *file);
+    const char *called_as, int line, const char *file) 
fc__attribute_3x((malloc));
 void *fc_real_calloc(size_t nelem, size_t elsize,
-                    const char *called_as, int line, const char *file);
+    const char *called_as, int line, const char *file) 
fc__attribute_3x((malloc));
 
 char *real_mystrdup(const char *str, 
-                   const char *called_as, int line, const char *file);
+    const char *called_as, int line, const char *file) 
fc__attribute_3x((malloc));
 
 #endif /* FC__MEM_H */
diff -u -r fcc/common/player.c fc2/common/player.c
--- fcc/common/player.c Thu Mar 13 12:53:07 2003
+++ fc2/common/player.c Wed Mar 26 23:36:57 2003
@@ -156,6 +156,7 @@
 static const char *pname_accessor(int i) {
   return game.players[i].name;
 }
+
 struct player *find_player_by_name_prefix(const char *name,
                                          enum m_pre_result *result)
 {
diff -u -r fcc/common/player.h fc2/common/player.h
--- fcc/common/player.h Thu Mar  6 00:59:06 2003
+++ fc2/common/player.h Wed Mar 26 23:41:49 2003
@@ -219,7 +222,7 @@
                                      struct unit *punit, 
                                      int x, int y);
 
-bool player_owns_city(struct player *pplayer, struct city *pcity);
+bool player_owns_city(struct player *pplayer, struct city *pcity)      
fc__attribute_3x((pure));
 
 struct city *player_find_city_by_id(struct player *pplayer, int city_id);
 struct unit *player_find_unit_by_id(struct player *pplayer, int unit_id);
@@ -231,8 +234,9 @@
 bool player_knows_improvement_tech(struct player *pplayer,
                                   Impr_Type_id id);
 bool player_knows_techs_with_flag(struct player *pplayer,
-                                enum tech_flag_id flag);
-int num_known_tech_with_flag(struct player *pplayer, enum tech_flag_id flag);
+                                enum tech_flag_id flag) 
fc__attribute_3x((pure));
+int num_known_tech_with_flag(struct player *pplayer, enum tech_flag_id flag)
+                                               fc__attribute_3x((pure));
 int player_get_expected_income(struct player *pplayer);
 
 void player_limit_to_government_rates(struct player *pplayer);
@@ -250,7 +254,8 @@
 const struct player_diplstate *pplayer_get_diplstate(const struct player
                                                     *pplayer,
                                                     const struct player
-                                                    *pplayer2);
+                                                    *pplayer2)
+                                                    fc__attribute_3x((pure));
 bool pplayers_at_war(const struct player *pplayer,
                    const struct player *pplayer2);
 bool pplayers_allied(const struct player *pplayer,
@@ -258,7 +263,7 @@
 bool pplayers_non_attack(const struct player *pplayer,
                        const struct player *pplayer2);
 
-bool is_barbarian(const struct player *pplayer);
+bool is_barbarian(const struct player *pplayer)        
fc__attribute_3x((pure));
 
 bool gives_shared_vision(struct player *me, struct player *them);
 
diff -u -r fcc/common/shared.h fc2/common/shared.h
--- fcc/common/shared.h Thu Mar 13 12:53:07 2003
+++ fc2/common/shared.h Wed Mar 26 20:16:44 2003
@@ -47,6 +47,12 @@
 #define fc__attribute_3x(x)
 #endif
 
+/* for gcc >= 3.x attributes */
+#if defined(__GNUC__) && (__GNUC__ >= 3)
+#define fc__attribute_3x(x)  __attribute__(x)
+#else
+#define fc__attribute_3x(x)
+#endif
 
 /* Note: the capability string is now in capstr.c --dwp */
 /* Version stuff is now in version.h --dwp */
diff -u -r fcc/common/tech.h fc2/common/tech.h
--- fcc/common/tech.h   Tue Jan 14 14:51:01 2003
+++ fc2/common/tech.h   Wed Mar 26 23:32:26 2003
@@ -101,7 +101,8 @@
   int num_reqs;
 };
 
-enum tech_state get_invention(struct player *pplayer, Tech_Type_id tech);
+enum tech_state get_invention(struct player *pplayer, Tech_Type_id tech)
+                                               fc__attribute_3x((pure));
 void set_invention(struct player *pplayer, Tech_Type_id tech,
                   enum tech_state value);
 void update_research(struct player *pplayer);
@@ -116,15 +117,17 @@
 
 int tech_turns_to_advance(struct player *pplayer);
 
-int total_bulbs_required(struct player *pplayer);
+int total_bulbs_required(struct player *pplayer)       
fc__attribute_3x((pure));
 int base_total_bulbs_required(struct player *pplayer,Tech_Type_id tech);
 bool techs_have_fixed_costs(void);
 
-int num_unknown_techs_for_goal(struct player *pplayer, Tech_Type_id goal);
-int total_bulbs_required_for_goal(struct player *pplayer, Tech_Type_id goal);
+int num_unknown_techs_for_goal(struct player *pplayer, Tech_Type_id goal)
+                                               fc__attribute_3x((pure));
+int total_bulbs_required_for_goal(struct player *pplayer, Tech_Type_id goal)
+                                               fc__attribute_3x((pure));
 bool is_tech_a_req_for_goal(struct player *pplayer, Tech_Type_id tech,
                           Tech_Type_id goal);
-bool is_future_tech(Tech_Type_id tech);
+bool is_future_tech(Tech_Type_id tech) fc__attribute_3x((const));
 const char *get_tech_name(struct player *pplayer, Tech_Type_id tech);
 
 void precalc_tech_data(void);
diff -u -r fcc/common/unit.h fc2/common/unit.h
--- fcc/common/unit.h   Thu Mar 13 12:53:07 2003
+++ fc2/common/unit.h   Wed Mar 26 23:22:20 2003
@@ -230,7 +230,7 @@
 int airunit_carrier_capacity(int x, int y, struct player *pplayer,
                             bool count_units_with_extra_fuel);
 
-struct player *unit_owner(struct unit *punit);
+struct player *unit_owner(struct unit *punit)  fc__attribute_3x((pure));
 
 struct unit *is_allied_unit_tile(struct tile *ptile,
                                 struct player *pplayer);
diff -u -r fcc/common/unittype.h fc2/common/unittype.h
--- fcc/common/unittype.h       Sat Feb  1 11:24:29 2003
+++ fc2/common/unittype.h       Wed Mar 26 23:07:46 2003
@@ -194,31 +194,31 @@
 extern struct unit_type unit_types[U_LAST];
 
 bool unit_type_exists(Unit_Type_id id);
-struct unit_type *get_unit_type(Unit_Type_id id);
-struct unit_type *unit_type(struct unit *punit);
+struct unit_type *get_unit_type(Unit_Type_id id)       
fc__attribute_3x((pure));
+struct unit_type *unit_type(struct unit *punit)        
fc__attribute_3x((pure));
 
 bool unit_type_flag(Unit_Type_id id, int flag);
 bool unit_flag(struct unit *punit, enum unit_flag_id flag);
 bool unit_has_role(Unit_Type_id id, int role);
 
-bool is_water_unit(Unit_Type_id id);
-bool is_air_unittype(Unit_Type_id id);
-bool is_heli_unittype(Unit_Type_id id);
-bool is_ground_unittype(Unit_Type_id id);
+bool is_water_unit(Unit_Type_id id)            fc__attribute_3x((pure));
+bool is_air_unittype(Unit_Type_id id)          fc__attribute_3x((pure));
+bool is_heli_unittype(Unit_Type_id id)         fc__attribute_3x((pure));
+bool is_ground_unittype(Unit_Type_id id)       fc__attribute_3x((pure));
 
-int unit_value(Unit_Type_id id);
-int unit_pop_value(Unit_Type_id id);
+int unit_value(Unit_Type_id id)        fc__attribute_3x((pure));
+int unit_pop_value(Unit_Type_id id)    fc__attribute_3x((pure));
 
-const char *unit_name(Unit_Type_id id);
+const char *unit_name(Unit_Type_id id) fc__attribute_3x((pure));
 const char *unit_class_name(Unit_Class_id id);
 
 const char *get_unit_name(Unit_Type_id id);
 const char *get_units_with_flag_string(int flag);
 
 int utype_shield_cost(struct unit_type *ut, struct government *g);
-int utype_food_cost(struct unit_type *ut, struct government *g);
-int utype_happy_cost(struct unit_type *ut, struct government *g);
-int utype_gold_cost(struct unit_type *ut, struct government *g);
+int utype_food_cost(struct unit_type *ut, struct government *g)        
fc__attribute_3x((pure));
+int utype_happy_cost(struct unit_type *ut, struct government *g)       
fc__attribute_3x((pure));
+int utype_gold_cost(struct unit_type *ut, struct government *g)        
fc__attribute_3x((pure));
 
 int can_upgrade_unittype(struct player *pplayer, Unit_Type_id id);
 int unit_upgrade_price(const struct player * const pplayer,
@@ -236,7 +236,7 @@
 bool can_player_eventually_build_unit(struct player *p, Unit_Type_id id);
 
 void role_unit_precalcs(void);
-int num_role_units(int role);
+int num_role_units(int role)   fc__attribute_3x((pure));
 Unit_Type_id get_role_unit(int role, int index);
 Unit_Type_id best_role_unit(struct city *pcity, int role);
 Unit_Type_id best_role_unit_for_player(struct player *pplayer, int role);

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