You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2012/11/24 07:07:51 UTC

[3/3] git commit: TS-1583: Fix clang build with ext/hash_map

TS-1583: Fix clang build with ext/hash_map

Clang on OS X doesn't end up with std::hash so logstats doesn't
build. Rather than hacking the std namespace, just use the unqualified
symbols that we need. GCC >= 4.7 gets the std::hash version from
<functional>.

Tested with clang on OS X and gcc 4.4, 4.6 and 4.7 on Ubuntu.


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

Branch: refs/heads/master
Commit: 81f9f4187d284c7a55341106aa16bb7648d741e4
Parents: e4e02fa
Author: James Peach <jp...@apache.org>
Authored: Fri Nov 23 21:37:46 2012 -0800
Committer: James Peach <jp...@apache.org>
Committed: Fri Nov 23 21:37:46 2012 -0800

----------------------------------------------------------------------
 proxy/logstats.cc |   31 ++++++++++++++++++++-----------
 1 files changed, 20 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/81f9f418/proxy/logstats.cc
----------------------------------------------------------------------
diff --git a/proxy/logstats.cc b/proxy/logstats.cc
index 0e69c0c..48707e5 100644
--- a/proxy/logstats.cc
+++ b/proxy/logstats.cc
@@ -50,30 +50,39 @@
 #include <algorithm>
 #include <vector>
 #include <list>
+#include <functional>
+#include <fcntl.h>
+
 #if (__GNUC__ >= 3)
 #define _BACKWARD_BACKWARD_WARNING_H    // needed for gcc 4.3
 #include <ext/hash_map>
 #include <ext/hash_set>
 #undef _BACKWARD_BACKWARD_WARNING_H
-#  if (__GNUC__ <= 4 && __GNUC_MINOR__ < 7)  && !defined(__clang__)
-    // hash was added to namespace std in gcc 4.7 so we use std:: for
-    // forward compatibility and import hash to std for backwards
-    // compatibility.
-     namespace std { using __gnu_cxx::hash; }
-#  endif
 #else
 #include <hash_map>
 #include <hash_set>
 #include <map>
 #endif
+
 #ifndef _XOPEN_SOURCE
 #define _XOPEN_SOURCE 600
 #endif
-#include <fcntl.h>
 
 #if defined(__GNUC__)
-using namespace __gnu_cxx;
+using __gnu_cxx::hash_map;
+using __gnu_cxx::hash_set;
+
+// GCC 4.7 appears to want the std::hash implementation from <functional>, whereas previous gcc versions
+// use the __gnu_cxx::hash GNU extension. Clang (at least on OS X) is happy with the GNU extension as long
+// as it is using the GNU libstdc++.
+#if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 7)
+using std::hash;
+#else
+using __gnu_cxx::hash;
+#endif
+
 #endif
+
 using namespace std;
 
 // Constants, please update the VERSION number when you make a new build!!!
@@ -352,8 +361,8 @@ struct eqstr
   }
 };
 
-typedef hash_map <const char *, OriginStats *, std::hash <const char *>, eqstr> OriginStorage;
-typedef hash_set <const char *, std::hash <const char *>, eqstr> OriginSet;
+typedef hash_map <const char *, OriginStats *, hash <const char *>, eqstr> OriginStorage;
+typedef hash_set <const char *, hash <const char *>, eqstr> OriginSet;
 
 
 // LRU class for the URL data
@@ -362,7 +371,7 @@ void  update_elapsed(ElapsedStats &stat, const int elapsed, const StatsCounter &
 class UrlLru
 {
   typedef list<UrlStats> LruStack;
-  typedef hash_map<const char *, LruStack::iterator, std::hash <const char *>, eqstr> LruHash;
+  typedef hash_map<const char *, LruStack::iterator, hash <const char *>, eqstr> LruHash;
 
 public:
   UrlLru(int size=1000000, int show_urls=0)