You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2014/11/11 18:56:34 UTC

trafficserver git commit: TS-2959 Fix gcc 4.9.2 compiler warning. This closes #137.

Repository: trafficserver
Updated Branches:
  refs/heads/master 378a5b53f -> aba98345d


TS-2959 Fix gcc 4.9.2 compiler warning. This closes #137.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/aba98345
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/aba98345
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/aba98345

Branch: refs/heads/master
Commit: aba98345dd86e923a42f36105564196ad8cad302
Parents: 378a5b5
Author: shinrich <sh...@network-geographics.com>
Authored: Mon Nov 10 09:20:28 2014 -0600
Committer: Alan M. Carroll <so...@yahoo-inc.com>
Committed: Tue Nov 11 11:55:45 2014 -0600

----------------------------------------------------------------------
 CHANGES                      |  2 ++
 iocore/hostdb/MultiCache.cc  | 12 ++++++++----
 iocore/hostdb/P_MultiCache.h | 38 ++++++++++++++++++++------------------
 3 files changed, 30 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/aba98345/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 8895bfb..0a9efaf 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 5.2.0
 
+  *) [TS-2959] Fix compiler issue for MultiCache.
+
   *) [TS-3155] Added value_get_index to MimeField.
 
   *) [TS-3184] spdy window_update not triggered correctly

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/aba98345/iocore/hostdb/MultiCache.cc
----------------------------------------------------------------------
diff --git a/iocore/hostdb/MultiCache.cc b/iocore/hostdb/MultiCache.cc
index 65efbfd..aa0aecf 100644
--- a/iocore/hostdb/MultiCache.cc
+++ b/iocore/hostdb/MultiCache.cc
@@ -82,12 +82,12 @@ bytes_to_blocks(int64_t b)
 }
 
 inline int
-MultiCacheBase::blocks_in_level(int level)
+MultiCacheBase::blocks_in_level(unsigned int level)
 {
   int64_t sumbytes = 0;
   int prevblocks = 0;
   int b = 0;
-  for (int i = 0; i <= level; i++) {
+  for (unsigned int i = 0; i <= level; i++) {
     sumbytes += buckets * ((int64_t) bucketsize[i]);
     int sumblocks = bytes_to_blocks(sumbytes);
     b = sumblocks - prevblocks;
@@ -103,14 +103,18 @@ MultiCacheBase::blocks_in_level(int level)
 //
 int
 MultiCacheBase::initialize(Store *astore, char *afilename,
-                           int aelements, int abuckets, int alevels,
+                           int aelements, int abuckets, unsigned int alevels,
                            int level0_elements_per_bucket,
                            int level1_elements_per_bucket, int level2_elements_per_bucket)
 {
   int64_t size = 0;
 
   Debug("multicache", "initializing %s with %d elements, %d buckets and %d levels", afilename, aelements, abuckets, alevels);
-  ink_assert(alevels < 4);
+  ink_assert(alevels <= MULTI_CACHE_MAX_LEVELS);
+  if (alevels > MULTI_CACHE_MAX_LEVELS) {
+    Warning("Alevels too large %d, cannot initialize MultiCache", MULTI_CACHE_MAX_LEVELS);
+    return -1;
+  }
   levels = alevels;
   elementsize = get_elementsize();
   totalelements = 0;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/aba98345/iocore/hostdb/P_MultiCache.h
----------------------------------------------------------------------
diff --git a/iocore/hostdb/P_MultiCache.h b/iocore/hostdb/P_MultiCache.h
index c6bdd82..283f8ec 100644
--- a/iocore/hostdb/P_MultiCache.h
+++ b/iocore/hostdb/P_MultiCache.h
@@ -121,7 +121,7 @@ struct MultiCacheHeader
   unsigned int magic;
   VersionNumber version;
 
-  int levels;
+  unsigned int levels;
 
   int tag_bits;
   int max_hits;
@@ -222,16 +222,16 @@ struct MultiCacheBase: public MultiCacheHeader
   int hit_stat[MULTI_CACHE_MAX_LEVELS];
   int miss_stat;
 
-  int lowest_level_data_size()
+  unsigned int lowest_level_data_size()
   {
     return (buckets + 3) / 4;
   }
-  int lowest_level(int bucket)
+  unsigned int lowest_level(unsigned int bucket)
   {
-    int i = (unsigned char) lowest_level_data[bucket / 4];
+    unsigned int i = (unsigned char) lowest_level_data[bucket / 4];
     return 3 & (i >> (buckets % 4));
   }
-  void set_lowest_level(int bucket, int lowest)
+  void set_lowest_level(unsigned int bucket, unsigned int lowest)
   {
     unsigned char p = (unsigned char) lowest_level_data[bucket / 4];
     p &= ~(3 << (buckets % 4));
@@ -266,12 +266,12 @@ struct MultiCacheBase: public MultiCacheHeader
   int read_config(const char *config_filename, Store & store, char *fn = NULL, int *pi = NULL, int *pbuckets = NULL);
   int write_config(const char *config_filename, int nominal_size, int buckets);
   int initialize(Store * store, char *filename, int elements,
-                 int buckets = 0, int levels = 2,
+                 int buckets = 0, unsigned int levels = 2,
                  int level0_elements_per_bucket = 4,
                  int level1_elements_per_bucket = 32, int level2_elements_per_bucket = 1);
   int mmap_data(bool private_flag = false, bool zero_fill = false);
   char *mmap_region(int blocks, int *fds, char *cur, size_t& total_length, bool private_flag, int zero_fill = 0);
-  int blocks_in_level(int level);
+  int blocks_in_level(unsigned int level);
 
   bool verify_header();
 
@@ -438,11 +438,11 @@ template<class C> struct MultiCache: public MultiCacheBase
   //
   int level_of_block(C * b);
   bool match(uint64_t folded_md5, C * block);
-  C *cache_bucket(uint64_t folded_md5, int level);
-  C *insert_block(uint64_t folded_md5, C * new_block, int level);
-  void flush(C * b, int bucket, int level);
+  C *cache_bucket(uint64_t folded_md5, unsigned int level);
+  C *insert_block(uint64_t folded_md5, C * new_block, unsigned int level);
+  void flush(C * b, int bucket, unsigned int level);
   void delete_block(C * block);
-  C *lookup_block(uint64_t folded_md5, int level);
+  C *lookup_block(uint64_t folded_md5, unsigned int level);
   void copy_heap(int paritition, MultiCacheHeapGC *);
 };
 
@@ -462,7 +462,7 @@ template<class C> inline int MultiCache<C>::level_of_block(C * b)
   return 0;
 }
 
-template<class C> inline C * MultiCache<C>::cache_bucket(uint64_t folded_md5, int level)
+template<class C> inline C * MultiCache<C>::cache_bucket(uint64_t folded_md5, unsigned int level)
 {
   int bucket = (int) (folded_md5 % buckets);
   char *offset = data + level_offset[level] + bucketsize[level] * bucket;
@@ -472,7 +472,7 @@ template<class C> inline C * MultiCache<C>::cache_bucket(uint64_t folded_md5, in
 //
 // Insert an entry
 //
-template<class C> inline C * MultiCache<C>::insert_block(uint64_t folded_md5, C * new_block, int level)
+template<class C> inline C * MultiCache<C>::insert_block(uint64_t folded_md5, C * new_block, unsigned int level)
 {
   C *b = cache_bucket(folded_md5, level);
   C *block = NULL, *empty = NULL;
@@ -543,10 +543,12 @@ Lfound:
 //
 // This function ejects some number of entries.
 //
-template<class C> inline void MultiCache<C>::flush(C * b, int bucket, int level)
+template<class C> inline void MultiCache<C>::flush(C * b, int bucket, unsigned int level)
 {
   C *block = NULL;
-  if (level < levels - 1) {
+  // The comparison against the constant is redundant, but it 
+  // quiets the array_bounds error generated by g++ 4.9.2
+  if (level < levels - 1 && level < (MULTI_CACHE_MAX_LEVELS - 1)) {
     if (level >= lowest_level(bucket))
       set_lowest_level(bucket, level + 1);
     for (block = b; block < b + elements[level]; block++) {
@@ -575,7 +577,7 @@ template<class C> inline bool MultiCache<C>::match(uint64_t folded_md5, C * bloc
 template<class C> inline void MultiCache<C>::delete_block(C * b)
 {
   if (b->backed) {
-    int l = level_of_block(b);
+    unsigned int l = level_of_block(b);
     if (l < levels - 1) {
       int bucket = (((char *) b - data) - level_offset[l]) / bucketsize[l];
       C *x = (C *) (data + level_offset[l + 1] + bucket * bucketsize[l + 1]);
@@ -590,7 +592,7 @@ template<class C> inline void MultiCache<C>::delete_block(C * b)
 //
 // Lookup an entry up to some level in the cache
 //
-template<class C> inline C * MultiCache<C>::lookup_block(uint64_t folded_md5, int level)
+template<class C> inline C * MultiCache<C>::lookup_block(uint64_t folded_md5, unsigned int level)
 {
   C *b = cache_bucket(folded_md5, 0);
   uint64_t tag = make_tag(folded_md5);
@@ -645,7 +647,7 @@ template<class C> inline void MultiCache<C>::copy_heap(int partition, MultiCache
 {
   int b = first_bucket_of_partition(partition);
   int n = buckets_of_partition(partition);
-  for (int level = 0; level < levels; level++) {
+  for (unsigned int level = 0; level < levels; level++) {
     int e = n * elements[level];
     char *d = data + level_offset[level] + b * bucketsize[level];
     C *x = (C *) d;