kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdcry...@apache.org
Subject [1/4] kudu git commit: gutil: remove use of deprecated headers
Date Thu, 17 Aug 2017 17:30:56 GMT
Repository: kudu
Updated Branches:
  refs/heads/master 18d6f7f4c -> a15f1863e


gutil: remove use of deprecated headers

We've been on C++11 for a long time now. This commit removes usage of
ext/hash_map and ext/hash_set headers in favor of the now-standardized
unordered_map and unordered_set.

Additionally, it removes our specializations of __gnucxx::hash<> and
instead changes to specializing std::hash<> where appropriate. Some of
those specializations are now part of the standard and have been removed
as necessary to fix compilation.

This does not yet remove the -Wno-deprecated setting in the top-level
CMakeLists.txt, since it appears we have a lot of usage of our own
internal deprecated functions.

Change-Id: Ie088f77aa3f70d386a00166e783c66200fce781b
Reviewed-on: http://gerrit.cloudera.org:8080/7684
Tested-by: Todd Lipcon <todd@apache.org>
Reviewed-by: Alexey Serbin <aserbin@cloudera.com>


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

Branch: refs/heads/master
Commit: 88d15116be4fab0d30081d3f92c60ecc32b3c819
Parents: 18d6f7f
Author: Todd Lipcon <todd@apache.org>
Authored: Tue Aug 15 17:38:13 2017 -0700
Committer: Todd Lipcon <todd@apache.org>
Committed: Thu Aug 17 02:16:25 2017 +0000

----------------------------------------------------------------------
 CMakeLists.txt                      |  3 +-
 src/kudu/gutil/CMakeLists.txt       |  2 +-
 src/kudu/gutil/endian.h             |  2 +-
 src/kudu/gutil/hash/hash.cc         | 13 -----
 src/kudu/gutil/hash/hash.h          | 86 +++-----------------------------
 src/kudu/gutil/strings/serialize.cc | 16 +++---
 src/kudu/gutil/strings/serialize.h  | 14 +++---
 src/kudu/gutil/strings/split.cc     | 20 ++++----
 src/kudu/gutil/strings/split.h      | 10 ++--
 9 files changed, 40 insertions(+), 126 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/88d15116/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e377025..05a63ce 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -132,7 +132,8 @@ set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wall")
 #  - Wno-sign-compare: suppress warnings for comparison between signed and unsigned
 #    integers
 set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-sign-compare")
-#  -Wno-deprecated: some of the gutil code includes old things like ext/hash_set, ignore
that
+#  -Wno-deprecated: we currently have a number of places using deprecated functions
+#     (mostly our own functions). TODO(todd) remove or individually suppress call sites.
 set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-deprecated")
 #  - pthread: enable multithreaded malloc
 set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -pthread")

http://git-wip-us.apache.org/repos/asf/kudu/blob/88d15116/src/kudu/gutil/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/CMakeLists.txt b/src/kudu/gutil/CMakeLists.txt
index e0e2eb1..1c61267 100644
--- a/src/kudu/gutil/CMakeLists.txt
+++ b/src/kudu/gutil/CMakeLists.txt
@@ -66,6 +66,6 @@ ADD_EXPORTABLE_LIBRARY(gutil
   SRCS ${GUTIL_SRCS}
   DEPS ${GUTIL_LIBS}
   # Disable warnings which trigger a lot in the Google code:
-  COMPILE_FLAGS "-funsigned-char -Wno-deprecated -Wno-char-subscripts")
+  COMPILE_FLAGS "-funsigned-char -Wno-char-subscripts")
 
 add_kudu_test(strings/string_util-test)

http://git-wip-us.apache.org/repos/asf/kudu/blob/88d15116/src/kudu/gutil/endian.h
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/endian.h b/src/kudu/gutil/endian.h
index 5ed8f38..db06410 100644
--- a/src/kudu/gutil/endian.h
+++ b/src/kudu/gutil/endian.h
@@ -42,7 +42,7 @@ inline uint64 gbswap_64(uint64 host_int) {
   if (__builtin_constant_p(host_int)) {
     return __bswap_constant_64(host_int);
   } else {
-    register uint64 result;
+    uint64 result;
     __asm__("bswap %0" : "=r" (result) : "0" (host_int));
     return result;
   }

http://git-wip-us.apache.org/repos/asf/kudu/blob/88d15116/src/kudu/gutil/hash/hash.cc
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/hash/hash.cc b/src/kudu/gutil/hash/hash.cc
index 71141c0..24fc310 100644
--- a/src/kudu/gutil/hash/hash.cc
+++ b/src/kudu/gutil/hash/hash.cc
@@ -182,16 +182,3 @@ uint64 FingerprintInterleavedImplementation(const char *s, uint32 len)
{
   mix(d, e, f);
   return CombineFingerprintHalves(c, f);
 }
-
-// Extern template definitions.
-
-#if defined(__GNUC__)
-#include <ext/hash_set>
-namespace __gnu_cxx { // NOLINT(*)
-
-template class hash_set<std::string>;
-template class hash_map<std::string, std::string>;
-
-}  // namespace __gnu_cxx
-
-#endif

http://git-wip-us.apache.org/repos/asf/kudu/blob/88d15116/src/kudu/gutil/hash/hash.h
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/hash/hash.h b/src/kudu/gutil/hash/hash.h
index 6fb61aa..299a8e2 100644
--- a/src/kudu/gutil/hash/hash.h
+++ b/src/kudu/gutil/hash/hash.h
@@ -77,8 +77,8 @@
 #include <stdint.h>     // for uintptr_t
 #include <string.h>
 #include <algorithm>
-#include <ext/hash_map>
-#include <ext/hash_set>
+#include <unordered_map>
+#include <unordered_set>
 #include <string>
 #include <utility>
 
@@ -94,32 +94,6 @@
 #include "kudu/gutil/hash/legacy_hash.h"
 #include "kudu/gutil/hash/string_hash.h"
 
-namespace __gnu_cxx {
-
-
-// STLport and MSVC 10.0 above already define these.
-#if !defined(_STLP_LONG_LONG) && !(defined(_MSC_VER) && _MSC_VER >= 1600)
-
-#if defined(_MSC_VER)
-// MSVC's stl implementation with _MSC_VER less than 1600 doesn't have
-// this hash struct. STLport already defines this.
-template <typename T>
-struct hash {
-  size_t operator()(const T& t) const;
-};
-#endif  // defined(_MSC_VER)
-
-#endif  // !defined(_STLP_LONG_LONG) && !(defined(_MSC_VER) && _MSC_VER >=
1600)
-
-template<> struct hash<bool> {
-  size_t operator()(bool x) const { return static_cast<size_t>(x); }
-};
-
-
-}  // namespace __gnu_cxx
-
-
-
 // ----------------------------------------------------------------------
 // Fingerprint()
 //   Not recommended for new code.  Instead, use Fingerprint2011(),
@@ -209,7 +183,7 @@ inline uint64 FingerprintCat(uint64 fp1, uint64 fp2) {
   return Hash64NumWithSeed(fp1, fp2);
 }
 
-namespace __gnu_cxx {
+namespace std {
 
 
 // This intended to be a "good" hash function.  It may change from time to time.
@@ -237,36 +211,6 @@ template<> struct hash<uint128> {
   static const size_t min_buckets = 8;  // 4 and 8 are defaults.
 };
 
-// Avoid collision with definition in port_hash.h (via port.h).
-#ifndef HAVE_DEFINED_HASH_FOR_POINTERS
-#define HAVE_DEFINED_HASH_FOR_POINTERS
-// Hash pointers as if they were int's, but bring more entropy to
-// the lower bits.
-template<class T> struct hash<T*> {
-  size_t operator()(T *x) const {
-    size_t k = reinterpret_cast<size_t>(x);
-    return k + (k >> 6);
-  }
-};
-#endif  // HAVE_DEFINED_HASH_FOR_POINTERS
-
-#if defined(__GNUC__)
-// Use our nice hash function for strings
-template<class _CharT, class _Traits, class _Alloc>
-struct hash<std::basic_string<_CharT, _Traits, _Alloc> > {
-  size_t operator()(const std::basic_string<_CharT, _Traits, _Alloc>& k) const
{
-    return HashTo32(k.data(), static_cast<uint32>(k.length()));
-  }
-};
-
-// they don't define a hash for const string at all
-template<> struct hash<const std::string> {
-  size_t operator()(const std::string& k) const {
-    return HashTo32(k.data(), static_cast<uint32>(k.length()));
-  }
-};
-#endif  // defined(__GNUC__)
-
 // MSVC's STL requires an ever-so slightly different decl
 #if defined(STL_MSVC)
 template<> struct hash<char const*> {
@@ -302,8 +246,8 @@ template<> struct hash<std::string> {
 template<class First, class Second>
 struct hash<pair<First, Second> > {
   size_t operator()(const pair<First, Second>& p) const {
-    size_t h1 = __gnu_cxx::hash<First>()(p.first);
-    size_t h2 = __gnu_cxx::hash<Second>()(p.second);
+    size_t h1 = std::hash<First>()(p.first);
+    size_t h2 = std::hash<Second>()(p.second);
     // The decision below is at compile time
     return (sizeof(h1) <= sizeof(uint32)) ?
             Hash32NumWithSeed(h1, h2)
@@ -319,7 +263,7 @@ struct hash<pair<First, Second> > {
 };
 
 
-}  // namespace __gnu_cxx
+}  // namespace std
 
 
 // If you want an excellent string hash function, and you don't mind if it
@@ -391,22 +335,4 @@ struct GoodFastHash<const std::basic_string<_CharT, _Traits, _Alloc>
> {
   static const size_t min_buckets = 8;  // 4 and 8 are defaults.
 };
 
-// Extern template declarations.
-//
-// gcc only for now.  msvc and others: this technique is likely to work with
-// your compiler too.  changelists welcome.
-//
-// This technique is limited to template specializations whose hash key
-// functions are declared in this file.
-
-#if defined(__GNUC__)
-namespace __gnu_cxx {
-
-extern template class hash_set<std::string>;
-extern template class hash_map<std::string, std::string>;
-
-}  // namespace __gnu_cxx
-
-#endif  // defined(__GNUC__)
-
 #endif  // UTIL_HASH_HASH_H_

http://git-wip-us.apache.org/repos/asf/kudu/blob/88d15116/src/kudu/gutil/strings/serialize.cc
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/strings/serialize.cc b/src/kudu/gutil/strings/serialize.cc
index 1663d80..d0d8130 100644
--- a/src/kudu/gutil/strings/serialize.cc
+++ b/src/kudu/gutil/strings/serialize.cc
@@ -5,9 +5,9 @@
 #include <stddef.h>
 #include <stdlib.h>
 
-#include <ext/hash_map>
 #include <string>
 #include <utility>
+#include <unordered_map>
 #include <vector>
 
 #include "kudu/gutil/casts.h"
@@ -18,7 +18,7 @@
 #include "kudu/gutil/strings/split.h"
 #include "kudu/gutil/hash/hash.h"
 
-using __gnu_cxx::hash_map;
+using std::unordered_map;
 using std::make_pair;
 using std::pair;
 using std::string;
@@ -222,7 +222,7 @@ int64 ReverseOrderedStringToInt64(const StringPiece& key) {
 //   and commas to separate entries.
 // --------------------------------------------------------------------------
 
-string DictionaryInt32Encode(const hash_map<string, int32>* dictionary) {
+string DictionaryInt32Encode(const unordered_map<string, int32>* dictionary) {
   vector<string> entries;
   for (const auto& entry : *dictionary) {
     entries.push_back(StringPrintf("%s:%d", entry.first.c_str(), entry.second));
@@ -233,7 +233,7 @@ string DictionaryInt32Encode(const hash_map<string, int32>* dictionary)
{
   return result;
 }
 
-string DictionaryInt64Encode(const hash_map<string, int64>* dictionary) {
+string DictionaryInt64Encode(const unordered_map<string, int64>* dictionary) {
   vector<string> entries;
   for (const auto& entry : *dictionary) {
     entries.push_back(StringPrintf("%s:%" PRId64,
@@ -245,7 +245,7 @@ string DictionaryInt64Encode(const hash_map<string, int64>* dictionary)
{
   return result;
 }
 
-string DictionaryDoubleEncode(const hash_map<string, double>* dictionary) {
+string DictionaryDoubleEncode(const unordered_map<string, double>* dictionary) {
   vector<string> entries;
   for (const auto& entry : *dictionary) {
     entries.push_back(StringPrintf("%s:%g", entry.first.c_str(), entry.second));
@@ -270,7 +270,7 @@ bool DictionaryParse(const string& encoded_str,
   return true;
 }
 
-bool DictionaryInt32Decode(hash_map<string, int32>* dictionary,
+bool DictionaryInt32Decode(unordered_map<string, int32>* dictionary,
                            const string& encoded_str) {
   vector<pair<string, string> > items;
   if (!DictionaryParse(encoded_str, &items))
@@ -289,7 +289,7 @@ bool DictionaryInt32Decode(hash_map<string, int32>* dictionary,
   return true;
 }
 
-bool DictionaryInt64Decode(hash_map<string, int64>* dictionary,
+bool DictionaryInt64Decode(unordered_map<string, int64>* dictionary,
                            const string& encoded_str) {
   vector<pair<string, string> > items;
   if (!DictionaryParse(encoded_str, &items))
@@ -309,7 +309,7 @@ bool DictionaryInt64Decode(hash_map<string, int64>* dictionary,
 }
 
 
-bool DictionaryDoubleDecode(hash_map<string, double>* dictionary,
+bool DictionaryDoubleDecode(unordered_map<string, double>* dictionary,
                             const string& encoded_str) {
   vector<pair<string, string> > items;
   if (!DictionaryParse(encoded_str, &items))

http://git-wip-us.apache.org/repos/asf/kudu/blob/88d15116/src/kudu/gutil/strings/serialize.h
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/strings/serialize.h b/src/kudu/gutil/strings/serialize.h
index 282e9eb..a759059 100644
--- a/src/kudu/gutil/strings/serialize.h
+++ b/src/kudu/gutil/strings/serialize.h
@@ -9,8 +9,8 @@
 
 #include <string.h>
 
-#include <ext/hash_map>
 #include <string>
+#include <unordered_map>
 #include <utility>
 #include <vector>
 
@@ -323,15 +323,15 @@ bool DictionaryParse(const std::string& encoded_str,
 //   Note: these routines are not meant for use with very large dictionaries.
 //   They are written for convenience and not efficiency.
 // --------------------------------------------------------------------------
-std::string DictionaryInt32Encode(const __gnu_cxx::hash_map<std::string, int32>* dictionary);
-std::string DictionaryInt64Encode(const __gnu_cxx::hash_map<std::string, int64>* dictionary);
-std::string DictionaryDoubleEncode(const __gnu_cxx::hash_map<std::string, double>*
dictionary);
+std::string DictionaryInt32Encode(const std::unordered_map<std::string, int32>* dictionary);
+std::string DictionaryInt64Encode(const std::unordered_map<std::string, int64>* dictionary);
+std::string DictionaryDoubleEncode(const std::unordered_map<std::string, double>* dictionary);
 
-bool DictionaryInt32Decode(__gnu_cxx::hash_map<std::string, int32>* dictionary,
+bool DictionaryInt32Decode(std::unordered_map<std::string, int32>* dictionary,
                            const std::string& encoded_str);
-bool DictionaryInt64Decode(__gnu_cxx::hash_map<std::string, int64>* dictionary,
+bool DictionaryInt64Decode(std::unordered_map<std::string, int64>* dictionary,
                            const std::string& encoded_str);
-bool DictionaryDoubleDecode(__gnu_cxx::hash_map<std::string, double>* dictionary,
+bool DictionaryDoubleDecode(std::unordered_map<std::string, double>* dictionary,
                             const std::string& encoded_str);
 
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/88d15116/src/kudu/gutil/strings/split.cc
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/strings/split.cc b/src/kudu/gutil/strings/split.cc
index 3262e6b..4920a6c 100644
--- a/src/kudu/gutil/strings/split.cc
+++ b/src/kudu/gutil/strings/split.cc
@@ -19,8 +19,8 @@
 #include "kudu/gutil/strings/util.h"
 #include "kudu/gutil/hash/hash.h"
 
-using __gnu_cxx::hash_map;
-using __gnu_cxx::hash_set;
+using std::unordered_map;
+using std::unordered_set;
 using std::back_insert_iterator;
 using std::map;
 using std::numeric_limits;
@@ -125,7 +125,7 @@ namespace {
 // the following overloads:
 // - vector<string>           - for better performance
 // - map<string, string>      - to change append semantics
-// - hash_map<string, string> - to change append semantics
+// - unordered_map<string, string> - to change append semantics
 template <typename Container, typename Splitter>
 void AppendToImpl(Container* container, Splitter splitter) {
   Container c = splitter;  // Calls implicit conversion operator.
@@ -145,7 +145,7 @@ void AppendToImpl(vector<string>* container, Splitter splitter)
{
   }
 }
 
-// Here we define two AppendToImpl() overloads for map<> and hash_map<>. Both
of
+// Here we define two AppendToImpl() overloads for map<> and unordered_map<>.
Both of
 // these overloads call through to this AppendToMap() function. This is needed
 // because inserting a duplicate key into a map does NOT overwrite the previous
 // value, which was not the behavior of the split1 Split*() functions. Consider
@@ -157,7 +157,7 @@ void AppendToImpl(vector<string>* container, Splitter splitter)
{
 //   ASSERT_EQ(m["a"], "1");  // <-- "a" has value "1" not "2".
 //
 // Due to this behavior of map::insert, we can't rely on a normal std::inserter
-// for a maps. Instead, maps and hash_maps need to be special cased to implement
+// for a maps. Instead, maps and unordered_maps need to be special cased to implement
 // the desired append semantic of inserting an existing value overwrites the
 // previous value.
 //
@@ -179,7 +179,7 @@ void AppendToImpl(map<string, string>* map_container, Splitter splitter)
{
 }
 
 template <typename Splitter>
-void AppendToImpl(hash_map<string, string>* map_container, Splitter splitter) {
+void AppendToImpl(unordered_map<string, string>* map_container, Splitter splitter)
{
   AppendToMap(map_container, splitter);
 }
 
@@ -427,7 +427,7 @@ void SplitStringUsing(const string& full,
 }
 
 void SplitStringToHashsetUsing(const string& full, const char* delim,
-                               hash_set<string>* result) {
+                               unordered_set<string>* result) {
   AppendTo(result, strings::Split(full, AnyOf(delim), strings::SkipEmpty()));
 }
 
@@ -442,7 +442,7 @@ void SplitStringToMapUsing(const string& full, const char* delim,
 }
 
 void SplitStringToHashmapUsing(const string& full, const char* delim,
-                               hash_map<string, string>* result) {
+                               unordered_map<string, string>* result) {
   AppendTo(result, strings::Split(full, AnyOf(delim), strings::SkipEmpty()));
 }
 
@@ -595,8 +595,8 @@ void SplitStringWithEscapingToSet(const string &full,
 
 void SplitStringWithEscapingToHashset(const string &full,
                                       const strings::CharSet& delimiters,
-                                      hash_set<string> *result) {
-  std::insert_iterator< hash_set<string> > it(*result, result->end());
+                                      unordered_set<string> *result) {
+  std::insert_iterator< unordered_set<string> > it(*result, result->end());
   SplitStringWithEscapingToIterator(full, delimiters, false, &it);
 }
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/88d15116/src/kudu/gutil/strings/split.h
----------------------------------------------------------------------
diff --git a/src/kudu/gutil/strings/split.h b/src/kudu/gutil/strings/split.h
index 4b32c84..df36ede 100644
--- a/src/kudu/gutil/strings/split.h
+++ b/src/kudu/gutil/strings/split.h
@@ -23,12 +23,12 @@
 #include <stddef.h>
 
 #include <algorithm>
-#include <ext/hash_map>
-#include <ext/hash_set>
 #include <iterator>
 #include <map>
 #include <set>
 #include <string>
+#include <unordered_map>
+#include <unordered_set>
 #include <utility>
 #include <vector>
 
@@ -660,7 +660,7 @@ void SplitStringPieceToVector(const StringPiece& full,
 void SplitStringUsing(const std::string& full, const char* delimiters,
                       std::vector<std::string>* result);
 void SplitStringToHashsetUsing(const std::string& full, const char* delimiters,
-                               __gnu_cxx::hash_set<std::string>* result);
+                               std::unordered_set<std::string>* result);
 void SplitStringToSetUsing(const std::string& full, const char* delimiters,
                            std::set<std::string>* result);
 // The even-positioned (0-based) components become the keys for the
@@ -671,7 +671,7 @@ void SplitStringToSetUsing(const std::string& full, const char* delimiters,
 void SplitStringToMapUsing(const std::string& full, const char* delim,
                            std::map<std::string, std::string>* result);
 void SplitStringToHashmapUsing(const std::string& full, const char* delim,
-                               __gnu_cxx::hash_map<std::string, std::string>* result);
+                               std::unordered_map<std::string, std::string>* result);
 
 // ----------------------------------------------------------------------
 // SplitStringAllowEmpty()
@@ -725,7 +725,7 @@ void SplitStringWithEscapingToSet(const std::string& full,
                                   std::set<std::string>* result);
 void SplitStringWithEscapingToHashset(const std::string& full,
                                       const strings::CharSet& delimiters,
-                                      __gnu_cxx::hash_set<std::string>* result);
+                                      std::unordered_set<std::string>* result);
 
 // ----------------------------------------------------------------------
 // SplitStringIntoNPiecesAllowEmpty()


Mime
View raw message