]> git.puffer.fish Git - matthieu/frr.git/commitdiff
[lib] hash compare function arguments ought to be const qualified
authorStephen Hemminger <stephen.hemminger@vyatta.com>
Thu, 14 Aug 2008 15:25:25 +0000 (16:25 +0100)
committerPaul Jakma <paul@quagga.net>
Fri, 22 Aug 2008 18:52:58 +0000 (19:52 +0100)
2008-08-14 Stephen Hemminger <stephen.hemminger@vyatta.com>

* lib/hash.h: (struct hash) Hash comparator callback really
  ought to treat storage behind arguments as constant - a compare
  function with side-effects would be evil.
* */*.c: Adjust comparator functions similarly, thus fixing at least
  a few compiler warnings about const qualifier being dropped.

Signed-off-by: Paul Jakma <paul@quagga.net>
13 files changed:
bgpd/bgp_advertise.c
bgpd/bgp_aspath.c
bgpd/bgp_aspath.h
bgpd/bgp_attr.c
bgpd/bgp_attr.h
bgpd/bgp_community.c
bgpd/bgp_ecommunity.c
bgpd/bgp_ecommunity.h
lib/distribute.c
lib/hash.c
lib/hash.h
lib/if_rmap.c
lib/thread.c

index 870aab134d13248bbffdcb7b447e59549386c5e4..b9f4a85b2f2de7a8736fbfca9bee038a5cc3af92 100644 (file)
@@ -72,10 +72,10 @@ baa_hash_key (void *p)
 }
 
 static int
-baa_hash_cmp (void *p1, void *p2)
+baa_hash_cmp (const void *p1, const void *p2)
 {
-  struct bgp_advertise_attr * baa1 = (struct bgp_advertise_attr *) p1;
-  struct bgp_advertise_attr * baa2 = (struct bgp_advertise_attr *) p2;
+  const struct bgp_advertise_attr * baa1 = p1;
+  const struct bgp_advertise_attr * baa2 = p2;
 
   return attrhash_cmp (baa1->attr, baa2->attr);
 }
index 38c9caa661ce48a1c9aa2d41e0b7bc65752ae637..006fc917460a9fbbf5e8d12e7c1040b42d6b6f5a 100644 (file)
@@ -1347,10 +1347,10 @@ aspath_add_seq (struct aspath *aspath, as_t asno)
 /* Compare leftmost AS value for MED check.  If as1's leftmost AS and
    as2's leftmost AS is same return 1. */
 int
-aspath_cmp_left (struct aspath *aspath1, struct aspath *aspath2)
+aspath_cmp_left (const struct aspath *aspath1, const struct aspath *aspath2)
 {
-  struct assegment *seg1 = NULL;
-  struct assegment *seg2 = NULL;
+  const struct assegment *seg1 = NULL;
+  const struct assegment *seg2 = NULL;
 
   if (!(aspath1 && aspath2))
     return 0;
@@ -1484,7 +1484,7 @@ aspath_reconcile_as4 ( struct aspath *aspath, struct aspath *as4path)
    as2's leftmost AS is same return 1. (confederation as-path
    only).  */
 int
-aspath_cmp_left_confed (struct aspath *aspath1, struct aspath *aspath2)
+aspath_cmp_left_confed (const struct aspath *aspath1, const struct aspath *aspath2)
 {
   if (! (aspath1 && aspath2) )
     return 0;
@@ -1769,10 +1769,10 @@ aspath_key_make (void *p)
 
 /* If two aspath have same value then return 1 else return 0 */
 static int
-aspath_cmp (void *arg1, void *arg2)
+aspath_cmp (const void *arg1, const void *arg2)
 {
-  struct assegment *seg1 = ((struct aspath *)arg1)->segments;
-  struct assegment *seg2 = ((struct aspath *)arg2)->segments;
+  const struct assegment *seg1 = ((struct aspath *)arg1)->segments;
+  const struct assegment *seg2 = ((struct aspath *)arg2)->segments;
   
   while (seg1 || seg2)
     {
index d8b41fa930946457a3804b63cc32b0e2c74bf865..2b4625c8fae6ffd6d594371389114e14cf116183 100644 (file)
@@ -72,8 +72,8 @@ extern struct aspath *aspath_prepend (struct aspath *, struct aspath *);
 extern struct aspath *aspath_filter_exclude (struct aspath *, struct aspath *);
 extern struct aspath *aspath_add_seq (struct aspath *, as_t);
 extern struct aspath *aspath_add_confed_seq (struct aspath *, as_t);
-extern int aspath_cmp_left (struct aspath *, struct aspath *);
-extern int aspath_cmp_left_confed (struct aspath *, struct aspath *);
+extern int aspath_cmp_left (const struct aspath *, const struct aspath *);
+extern int aspath_cmp_left_confed (const struct aspath *, const struct aspath *);
 extern struct aspath *aspath_delete_confed_seq (struct aspath *);
 extern struct aspath *aspath_empty (void);
 extern struct aspath *aspath_empty_get (void);
index 752099d1fc0df34807e740833e958bece5ebc669..6f139742020f3ae49d5f0794f150176f750df5c0 100644 (file)
@@ -131,15 +131,13 @@ cluster_hash_key_make (void *p)
 }
 
 static int
-cluster_hash_cmp (void *p1, void *p2)
+cluster_hash_cmp (const void *p1, const void *p2)
 {
-  struct cluster_list * cluster1 = (struct cluster_list *) p1;
-  struct cluster_list * cluster2 = (struct cluster_list *) p2;
+  const struct cluster_list * cluster1 = p1;
+  const struct cluster_list * cluster2 = p2;
 
-  if (cluster1->length == cluster2->length &&
-      memcmp (cluster1->list, cluster2->list, cluster1->length) == 0)
-    return 1;
-  return 0;
+  return (cluster1->length == cluster2->length &&
+         memcmp (cluster1->list, cluster2->list, cluster1->length) == 0);
 }
 
 static void
@@ -267,15 +265,13 @@ transit_hash_key_make (void *p)
 }
 
 static int
-transit_hash_cmp (void *p1, void *p2)
+transit_hash_cmp (const void *p1, const void *p2)
 {
-  struct transit * transit1 = (struct transit *) p1;
-  struct transit * transit2 = (struct transit *) p2;
+  const struct transit * transit1 = p1;
+  const struct transit * transit2 = p2;
 
-  if (transit1->length == transit2->length &&
-      memcmp (transit1->val, transit2->val, transit1->length) == 0)
-    return 1;
-  return 0;
+  return (transit1->length == transit2->length &&
+         memcmp (transit1->val, transit2->val, transit1->length) == 0);
 }
 
 static void
@@ -393,10 +389,10 @@ attrhash_key_make (void *p)
 }
 
 int
-attrhash_cmp (void *p1, void *p2)
+attrhash_cmp (const void *p1, const void *p2)
 {
-  struct attr * attr1 = (struct attr *) p1;
-  struct attr * attr2 = (struct attr *) p2;
+  const struct attr * attr1 = p1;
+  const struct attr * attr2 = p2;
 
   if (attr1->flag == attr2->flag
       && attr1->origin == attr2->origin
@@ -408,8 +404,8 @@ attrhash_cmp (void *p1, void *p2)
       && attr1->pathlimit.ttl == attr2->pathlimit.ttl
       && attr1->pathlimit.as == attr2->pathlimit.as)
     {
-      struct attr_extra *ae1 = attr1->extra;
-      struct attr_extra *ae2 = attr2->extra;
+      const struct attr_extra *ae1 = attr1->extra;
+      const struct attr_extra *ae2 = attr2->extra;
       
       if (ae1 && ae2
           && ae1->aggregator_as == ae2->aggregator_as
@@ -435,7 +431,7 @@ attrhash_cmp (void *p1, void *p2)
 }
 
 static void
-attrhash_init ()
+attrhash_init (void)
 {
   attrhash = hash_create (attrhash_key_make, attrhash_cmp);
 }
index 9647ccf8bf69688cffc921296c7c464224e3fc0d..12149a1777e27adfc650ae22355cbc78fef17ede 100644 (file)
@@ -163,7 +163,7 @@ extern bgp_size_t bgp_packet_withdraw (struct peer *peer, struct stream *s,
                                 struct prefix_rd *, u_char *);
 extern void bgp_dump_routes_attr (struct stream *, struct attr *,
                                  struct prefix *);
-extern int attrhash_cmp (void *, void *);
+extern int attrhash_cmp (const void *, const void *);
 extern unsigned int attrhash_key_make (void *);
 extern void attr_show_all (struct vty *);
 extern unsigned long int attr_count (void);
index 592b810d4c9a60959400fae1ee1da73a431b643c..1cafdb3e67caae38343d8887f84632f65575a89e 100644 (file)
@@ -633,5 +633,6 @@ community_hash (void)
 void
 community_init (void)
 {
-  comhash = hash_create (community_hash_make, community_cmp);
+  comhash = hash_create ((unsigned int (*) (void *))community_hash_make,
+                        (int (*) (const void *, const void *))community_cmp);
 }
index 9e7ae1b3e4bdeefb1ee2cf6c09dc8867b5725610..c08673ceb1c5a32106a871180c20606f26a02ae7 100644 (file)
@@ -247,15 +247,13 @@ ecommunity_hash_make (void *arg)
 
 /* Compare two Extended Communities Attribute structure.  */
 int
-ecommunity_cmp (void *arg1, void *arg2)
+ecommunity_cmp (const void *arg1, const void *arg2)
 {
   const struct ecommunity *ecom1 = arg1;
   const struct ecommunity *ecom2 = arg2;
   
-  if (ecom1->size == ecom2->size
-      && memcmp (ecom1->val, ecom2->val, ecom1->size * ECOMMUNITY_SIZE) == 0)
-    return 1;
-  return 0;
+  return (ecom1->size == ecom2->size
+         && memcmp (ecom1->val, ecom2->val, ecom1->size * ECOMMUNITY_SIZE) == 0);
 }
 
 /* Initialize Extended Comminities related hash. */
index 69014237d7fdeabb3d4b442302994cbd07eebb22..278721c86b9725d02ac94cb429dbd614a664672c 100644 (file)
@@ -72,7 +72,7 @@ extern struct ecommunity *ecommunity_parse (u_int8_t *, u_short);
 extern struct ecommunity *ecommunity_dup (struct ecommunity *);
 extern struct ecommunity *ecommunity_merge (struct ecommunity *, struct ecommunity *);
 extern struct ecommunity *ecommunity_intern (struct ecommunity *);
-extern int ecommunity_cmp (void *, void *);
+extern int ecommunity_cmp (const void *, const void *);
 extern void ecommunity_unintern (struct ecommunity *);
 extern unsigned int ecommunity_hash_make (void *);
 extern struct ecommunity *ecommunity_str2com (const char *, int, int);
index 3d61621103b333edf1a064c3334e4c2f5c272275..906e3f6d9c0df26631e144584e6a82461b6a0cdd 100644 (file)
@@ -134,7 +134,7 @@ distribute_hash_make (struct distribute *dist)
 /* If two distribute-list have same value then return 1 else return
    0. This function is used by hash package. */
 static int
-distribute_cmp (struct distribute *dist1, struct distribute *dist2)
+distribute_cmp (const struct distribute *dist1, const struct distribute *dist2)
 {
   if (dist1->ifname && dist2->ifname)
     if (strcmp (dist1->ifname, dist2->ifname) == 0)
@@ -769,7 +769,7 @@ void
 distribute_list_init (int node)
 {
   disthash = hash_create ((unsigned int (*) (void *)) distribute_hash_make,
-                          (int (*) (void *, void *)) distribute_cmp);
+                          (int (*) (const void *, const void *)) distribute_cmp);
 
   if(node==RIP_NODE) {
     install_element (RIP_NODE, &distribute_list_all_cmd);
index 76bf802a205b7d32dcbfedfbd0e7396989a6ee95..3884051f49b6e71f830e7cc3856e247fb20ef5a0 100644 (file)
@@ -27,7 +27,7 @@
 /* Allocate a new hash.  */
 struct hash *
 hash_create_size (unsigned int size, unsigned int (*hash_key) (void *),
-                                     int (*hash_cmp) (void *, void *))
+                                     int (*hash_cmp) (const void *, const void *))
 {
   struct hash *hash;
 
@@ -46,7 +46,7 @@ hash_create_size (unsigned int size, unsigned int (*hash_key) (void *),
 /* Allocate a new hash with default hash size.  */
 struct hash *
 hash_create (unsigned int (*hash_key) (void *), 
-             int (*hash_cmp) (void *, void *))
+             int (*hash_cmp) (const void *, const void *))
 {
   return hash_create_size (HASHTABSIZE, hash_key, hash_cmp);
 }
index a6e3d59ad78fc032b54d76bd8417c293cd8a4b31..f4b1c23eb5c0e63d9af687c0ea3f28b43e921a3a 100644 (file)
@@ -48,16 +48,16 @@ struct hash
   unsigned int (*hash_key) (void *);
 
   /* Data compare function. */
-  int (*hash_cmp) (void *, void *);
+  int (*hash_cmp) (const void *, const void *);
 
   /* Backet alloc. */
   unsigned long count;
 };
 
 extern struct hash *hash_create (unsigned int (*) (void *), 
-                          int (*) (void *, void *));
+                                int (*) (const void *, const void *));
 extern struct hash *hash_create_size (unsigned int, unsigned int (*) (void *), 
-                                             int (*) (void *, void *));
+                                             int (*) (const void *, const void *));
 
 extern void *hash_get (struct hash *, void *, void * (*) (void *));
 extern void *hash_alloc_intern (void *);
index e6f753c246bf6d91dbbcc02656c8a8517c643a9f..ddc62fd51b2ccc32d99fa7adfc7c3e98f3cface7 100644 (file)
@@ -120,13 +120,12 @@ if_rmap_hash_make (void *data)
 }
 
 static int
-if_rmap_hash_cmp (void *arg1, void* arg2)
+if_rmap_hash_cmp (const void *arg1, const void* arg2)
 {
-  struct if_rmap *if_rmap1 = arg1;
-  struct if_rmap *if_rmap2 = arg2;
-  if (strcmp (if_rmap1->ifname, if_rmap2->ifname) == 0)
-    return 1;
-  return 0;
+  const struct if_rmap *if_rmap1 = arg1;
+  const struct if_rmap *if_rmap2 = arg2;
+
+  return strcmp (if_rmap1->ifname, if_rmap2->ifname) == 0;
 }
 \f
 static struct if_rmap *
index 095dff4e2cb5f965d9b463ebf4981e2aec642ebb..260e8c8e492c39198e0ae61c491edff488ebfb61 100644 (file)
@@ -223,8 +223,8 @@ cpu_record_hash_key (struct cpu_thread_history *a)
 }
 
 static int 
-cpu_record_hash_cmp (struct cpu_thread_history *a,
-                    struct cpu_thread_history *b)
+cpu_record_hash_cmp (const struct cpu_thread_history *a,
+                    const struct cpu_thread_history *b)
 {
   return a->func == b->func;
 }
@@ -410,7 +410,7 @@ thread_master_create ()
   if (cpu_record == NULL) 
     cpu_record 
       = hash_create_size (1011, (unsigned int (*) (void *))cpu_record_hash_key, 
-                          (int (*) (void *, void *))cpu_record_hash_cmp);
+                          (int (*) (const void *, const void *))cpu_record_hash_cmp);
     
   return (struct thread_master *) XCALLOC (MTYPE_THREAD_MASTER,
                                           sizeof (struct thread_master));