You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by mp...@apache.org on 2018/02/10 02:07:50 UTC

[2/3] kudu git commit: Fix client comaptibility with gcc 4.4

Fix client comaptibility with gcc 4.4

We expect the client lib to work with gcc 4.4 and C++98.
When the int128 type was added this broke compatibility
because __int128 support didn’t exist until gcc 4.6.

To work around this and still allow gcc 4.6+ and C++11
compilation to support int128, a preprocessor check
was added to define KUDU_INT128_SUPPORTED
which is used to exclude the incompatible client code.

Additionally the int128 insertion operator definitions
were moved to their own file to ensure they are not
required when working with Kudu’s int128 types.
This ensures there aren’t compatibily issues with clients
that define their own __int128 insertion operator.

Change-Id: I59b40a9718b321df1a5878160ac845d4cf3d9170
Reviewed-on: http://gerrit.cloudera.org:8080/9257
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <to...@apache.org>


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

Branch: refs/heads/master
Commit: ba33f0346877c8d606ae97a42a6403a001e384bb
Parents: 526ee84
Author: Grant Henke <gr...@gmail.com>
Authored: Tue Feb 6 15:03:39 2018 -0600
Committer: Todd Lipcon <to...@apache.org>
Committed: Sat Feb 10 00:26:59 2018 +0000

----------------------------------------------------------------------
 src/kudu/cfile/cfile-test.cc     |  1 +
 src/kudu/cfile/encoding-test.cc  |  3 ++-
 src/kudu/client/scan_batch.h     |  4 ++++
 src/kudu/client/value.cc         |  1 -
 src/kudu/client/value.h          |  2 ++
 src/kudu/common/key_encoder.h    |  2 +-
 src/kudu/common/partial_row.h    | 12 +++++++++--
 src/kudu/tools/kudu-tool-test.cc |  1 +
 src/kudu/util/CMakeLists.txt     |  1 -
 src/kudu/util/int128-test.cc     |  1 +
 src/kudu/util/int128.cc          | 36 --------------------------------
 src/kudu/util/int128.h           | 22 ++++++++++----------
 src/kudu/util/int128_util.h      | 39 +++++++++++++++++++++++++++++++++++
 13 files changed, 72 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/ba33f034/src/kudu/cfile/cfile-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/cfile-test.cc b/src/kudu/cfile/cfile-test.cc
index afbdd17..526dde5 100644
--- a/src/kudu/cfile/cfile-test.cc
+++ b/src/kudu/cfile/cfile-test.cc
@@ -65,6 +65,7 @@
 #include "kudu/util/compression/compression.pb.h"
 #include "kudu/util/env.h"
 #include "kudu/util/int128.h"
+#include "kudu/util/int128_util.h"
 #include "kudu/util/mem_tracker.h"
 #include "kudu/util/memory/arena.h"
 #include "kudu/util/metrics.h"

http://git-wip-us.apache.org/repos/asf/kudu/blob/ba33f034/src/kudu/cfile/encoding-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/encoding-test.cc b/src/kudu/cfile/encoding-test.cc
index e13b6c7..9bffc8f 100644
--- a/src/kudu/cfile/encoding-test.cc
+++ b/src/kudu/cfile/encoding-test.cc
@@ -48,9 +48,10 @@
 #include "kudu/gutil/port.h"
 #include "kudu/gutil/stringprintf.h"
 #include "kudu/gutil/strings/substitute.h"
-#include "kudu/util/int128.h"
 #include "kudu/util/group_varint-inl.h"
 #include "kudu/util/hexdump.h"
+#include "kudu/util/int128.h"
+#include "kudu/util/int128_util.h" // IWYU pragma: keep
 #include "kudu/util/memory/arena.h"
 #include "kudu/util/random.h"
 #include "kudu/util/random_util.h"

http://git-wip-us.apache.org/repos/asf/kudu/blob/ba33f034/src/kudu/client/scan_batch.h
----------------------------------------------------------------------
diff --git a/src/kudu/client/scan_batch.h b/src/kudu/client/scan_batch.h
index b89264b..30fe2b1 100644
--- a/src/kudu/client/scan_batch.h
+++ b/src/kudu/client/scan_batch.h
@@ -196,7 +196,9 @@ class KUDU_EXPORT KuduScanBatch::RowPtr {
   Status GetFloat(const Slice& col_name, float* val) const WARN_UNUSED_RESULT;
   Status GetDouble(const Slice& col_name, double* val) const WARN_UNUSED_RESULT;
 
+#if KUDU_INT128_SUPPORTED
   Status GetUnscaledDecimal(const Slice& col_name, int128_t* val) const WARN_UNUSED_RESULT;
+#endif
   ///@}
 
   /// @name Getters for integral type columns by column index.
@@ -228,7 +230,9 @@ class KUDU_EXPORT KuduScanBatch::RowPtr {
   Status GetFloat(int col_idx, float* val) const WARN_UNUSED_RESULT;
   Status GetDouble(int col_idx, double* val) const WARN_UNUSED_RESULT;
 
+#if KUDU_INT128_SUPPORTED
   Status GetUnscaledDecimal(int col_idx, int128_t* val) const WARN_UNUSED_RESULT;
+#endif
   ///@}
 
   /// @name Getters for string/binary column by column name.

http://git-wip-us.apache.org/repos/asf/kudu/blob/ba33f034/src/kudu/client/value.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/value.cc b/src/kudu/client/value.cc
index 7314ed4..479c625 100644
--- a/src/kudu/client/value.cc
+++ b/src/kudu/client/value.cc
@@ -257,7 +257,6 @@ const Slice KuduValue::Data::GetSlice() {
     case DECIMAL:
       return Slice(reinterpret_cast<uint8_t*>(&decimal_val_),
                    sizeof(int128_t));
-
     case SLICE:
       return slice_val_;
   }

http://git-wip-us.apache.org/repos/asf/kudu/blob/ba33f034/src/kudu/client/value.h
----------------------------------------------------------------------
diff --git a/src/kudu/client/value.h b/src/kudu/client/value.h
index 4e146c4..4d76fa8 100644
--- a/src/kudu/client/value.h
+++ b/src/kudu/client/value.h
@@ -52,6 +52,7 @@ class KUDU_EXPORT KuduValue {
   static KuduValue* FromBool(bool b);
   ///@}
 
+#if KUDU_INT128_SUPPORTED
   /// Construct a decimal KuduValue from the raw value and scale.
   ///
   /// The validity of the decimal value is not checked until the
@@ -65,6 +66,7 @@ class KUDU_EXPORT KuduValue {
   ///@{
   static KuduValue* FromDecimal(int128_t dv, int8_t scale);
 ///@}
+#endif
 
   /// Construct a KuduValue by copying the value of the given Slice.
   ///

http://git-wip-us.apache.org/repos/asf/kudu/blob/ba33f034/src/kudu/common/key_encoder.h
----------------------------------------------------------------------
diff --git a/src/kudu/common/key_encoder.h b/src/kudu/common/key_encoder.h
index 0211ee9..92b9bac 100644
--- a/src/kudu/common/key_encoder.h
+++ b/src/kudu/common/key_encoder.h
@@ -74,7 +74,7 @@ struct KeyEncoderTraits<Type,
       case 4: return BigEndian::FromHost32(x);
       case 8: return BigEndian::FromHost64(x);
       case 16: return BigEndian::FromHost128(x);
-      default: LOG(FATAL) << "bad type: " << x;
+      default: LOG(FATAL) << "bad type size of: " << sizeof(x);
     }
     return 0;
   }

http://git-wip-us.apache.org/repos/asf/kudu/blob/ba33f034/src/kudu/common/partial_row.h
----------------------------------------------------------------------
diff --git a/src/kudu/common/partial_row.h b/src/kudu/common/partial_row.h
index 68fd0f4..36e0c78 100644
--- a/src/kudu/common/partial_row.h
+++ b/src/kudu/common/partial_row.h
@@ -105,7 +105,9 @@ class KUDU_EXPORT KuduPartialRow {
 
   Status SetFloat(const Slice& col_name, float val) WARN_UNUSED_RESULT;
   Status SetDouble(const Slice& col_name, double val) WARN_UNUSED_RESULT;
+#if KUDU_INT128_SUPPORTED
   Status SetUnscaledDecimal(const Slice& col_name, int128_t val) WARN_UNUSED_RESULT;
+#endif
   ///@}
 
   /// @name Setters for integral type columns by index.
@@ -134,7 +136,9 @@ class KUDU_EXPORT KuduPartialRow {
 
   Status SetFloat(int col_idx, float val) WARN_UNUSED_RESULT;
   Status SetDouble(int col_idx, double val) WARN_UNUSED_RESULT;
+#if KUDU_INT128_SUPPORTED
   Status SetUnscaledDecimal(int col_idx, int128_t val) WARN_UNUSED_RESULT;
+#endif
   ///@}
 
   /// @name Setters for binary/string columns by name (copying).
@@ -356,7 +360,9 @@ class KUDU_EXPORT KuduPartialRow {
 
   Status GetFloat(const Slice& col_name, float* val) const WARN_UNUSED_RESULT;
   Status GetDouble(const Slice& col_name, double* val) const WARN_UNUSED_RESULT;
-  Status GetUnscaledDecimal(const Slice& col_name, int128_t* val);
+#if KUDU_INT128_SUPPORTED
+  Status GetUnscaledDecimal(const Slice& col_name, int128_t* val) WARN_UNUSED_RESULT;
+#endif
   ///@}
 
   /// @name Getters for column of integral type by column index.
@@ -387,7 +393,9 @@ class KUDU_EXPORT KuduPartialRow {
 
   Status GetFloat(int col_idx, float* val) const WARN_UNUSED_RESULT;
   Status GetDouble(int col_idx, double* val) const WARN_UNUSED_RESULT;
-  Status GetUnscaledDecimal(int col_idx, int128_t* val);
+#if KUDU_INT128_SUPPORTED
+  Status GetUnscaledDecimal(int col_idx, int128_t* val) WARN_UNUSED_RESULT;
+#endif
   ///@}
 
   /// @name Getters for string/binary column by column name.

http://git-wip-us.apache.org/repos/asf/kudu/blob/ba33f034/src/kudu/tools/kudu-tool-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/kudu-tool-test.cc b/src/kudu/tools/kudu-tool-test.cc
index bec122a..c8cb27f 100644
--- a/src/kudu/tools/kudu-tool-test.cc
+++ b/src/kudu/tools/kudu-tool-test.cc
@@ -98,6 +98,7 @@
 #include "kudu/tserver/tserver_admin.proxy.h"
 #include "kudu/util/async_util.h"
 #include "kudu/util/env.h"
+#include "kudu/util/int128_util.h" // IWYU pragma: keep
 #include "kudu/util/metrics.h"
 #include "kudu/util/monotime.h"
 #include "kudu/util/net/net_util.h"

http://git-wip-us.apache.org/repos/asf/kudu/blob/ba33f034/src/kudu/util/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/kudu/util/CMakeLists.txt b/src/kudu/util/CMakeLists.txt
index 82a5a02..e7d856b 100644
--- a/src/kudu/util/CMakeLists.txt
+++ b/src/kudu/util/CMakeLists.txt
@@ -146,7 +146,6 @@ set(UTIL_SRCS
   hdr_histogram.cc
   hexdump.cc
   init.cc
-  int128.cc
   jsonreader.cc
   jsonwriter.cc
   kernel_stack_watchdog.cc

http://git-wip-us.apache.org/repos/asf/kudu/blob/ba33f034/src/kudu/util/int128-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/int128-test.cc b/src/kudu/util/int128-test.cc
index 30b84f4..cc1e174 100644
--- a/src/kudu/util/int128-test.cc
+++ b/src/kudu/util/int128-test.cc
@@ -24,6 +24,7 @@
 
 #include "kudu/gutil/macros.h"
 #include "kudu/util/int128.h"
+#include "kudu/util/int128_util.h"
 
 using std::string;
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/ba33f034/src/kudu/util/int128.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/int128.cc b/src/kudu/util/int128.cc
deleted file mode 100644
index cbd0621..0000000
--- a/src/kudu/util/int128.cc
+++ /dev/null
@@ -1,36 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#include "kudu/util/int128.h"
-
-#include <string>
-
-#include "kudu/gutil/strings/numbers.h"
-
-namespace std {
-
-std::ostream& operator<<(std::ostream& os, const __int128& val) {
-  os << SimpleItoa(val);
-  return os;
-}
-
-std::ostream& operator<<(std::ostream& os, const unsigned __int128& val) {
-  os << SimpleItoa(val);
-  return os;
-}
-
-} // namespace std

http://git-wip-us.apache.org/repos/asf/kudu/blob/ba33f034/src/kudu/util/int128.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/int128.h b/src/kudu/util/int128.h
index 96e51a8..ac35d08 100644
--- a/src/kudu/util/int128.h
+++ b/src/kudu/util/int128.h
@@ -20,8 +20,16 @@
 // as choices and standards around int128 change.
 #pragma once
 
-#include <iostream>
-
+// __int128 is not supported before gcc 4.6
+#if defined(__clang__) || \
+  (defined(__GNUC__) && \
+  (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= 40600)
+#define KUDU_INT128_SUPPORTED 1
+#else
+#define KUDU_INT128_SUPPORTED 0
+#endif
+
+#if KUDU_INT128_SUPPORTED
 namespace kudu {
 
 typedef unsigned __int128 uint128_t;
@@ -35,12 +43,4 @@ static const int128_t INT128_MAX = ((int128_t)(UINT128_MAX >> 1));
 static const int128_t INT128_MIN = (-INT128_MAX - 1);
 
 } // namespace kudu
-
-namespace std {
-
-  // Support the << operator on int128_t and uint128_t types.
-  // We use __int128 here because these are not in the Kudu namespace.
-  std::ostream& operator<<(std::ostream& os, const __int128& val);
-  std::ostream& operator<<(std::ostream& os, const unsigned __int128& val);
-
-} // namespace std
+#endif

http://git-wip-us.apache.org/repos/asf/kudu/blob/ba33f034/src/kudu/util/int128_util.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/int128_util.h b/src/kudu/util/int128_util.h
new file mode 100644
index 0000000..2d01de7
--- /dev/null
+++ b/src/kudu/util/int128_util.h
@@ -0,0 +1,39 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "kudu/util/int128.h"
+
+#include <iostream>
+#include <string>
+
+#include "kudu/gutil/strings/numbers.h"
+
+namespace std {
+
+// Support the << operator on int128_t and uint128_t types.
+//
+inline std::ostream& operator<<(std::ostream& os, const __int128& val) {
+  os << SimpleItoa(val);
+  return os;
+}
+inline std::ostream& operator<<(std::ostream& os, const unsigned __int128& val) {
+  os << SimpleItoa(val);
+  return os;
+}
+
+} // namespace std
+