Repository: arrow
Updated Branches:
  refs/heads/master 65db0da80 -> a4002c6e2


ARROW-70: Add adapt 'lite' DCHECK macros from Kudu as also used in Parquet

Also added a null pointer DCHECK to show that it works. cc @emkornfield

Author: Wes McKinney <w...@apache.org>

Closes #33 from wesm/ARROW-70 and squashes the following commits:

258d77b [Wes McKinney] Add adapt 'lite' DCHECK macros from Kudu as also used in 
Parquet


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

Branch: refs/heads/master
Commit: a4002c6e217bf1e74895dc11ab76f0c8befbfe2a
Parents: 65db0da
Author: Wes McKinney <w...@apache.org>
Authored: Wed Mar 23 10:59:31 2016 -0700
Committer: Wes McKinney <w...@apache.org>
Committed: Wed Mar 23 10:59:31 2016 -0700

----------------------------------------------------------------------
 cpp/src/arrow/ipc/adapter.cc |   2 +
 cpp/src/arrow/util/logging.h | 109 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 111 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/a4002c6e/cpp/src/arrow/ipc/adapter.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/ipc/adapter.cc b/cpp/src/arrow/ipc/adapter.cc
index 7cdb965..8a7d818 100644
--- a/cpp/src/arrow/ipc/adapter.cc
+++ b/cpp/src/arrow/ipc/adapter.cc
@@ -32,6 +32,7 @@
 #include "arrow/types/construct.h"
 #include "arrow/types/primitive.h"
 #include "arrow/util/buffer.h"
+#include "arrow/util/logging.h"
 #include "arrow/util/status.h"
 
 namespace arrow {
@@ -41,6 +42,7 @@ namespace flatbuf = apache::arrow::flatbuf;
 namespace ipc {
 
 static bool IsPrimitive(const DataType* type) {
+  DCHECK(type != nullptr);
   switch (type->type) {
     // NA is null type or "no type", considered primitive for now
     case Type::NA:

http://git-wip-us.apache.org/repos/asf/arrow/blob/a4002c6e/cpp/src/arrow/util/logging.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/util/logging.h b/cpp/src/arrow/util/logging.h
new file mode 100644
index 0000000..3ce4ccc
--- /dev/null
+++ b/cpp/src/arrow/util/logging.h
@@ -0,0 +1,109 @@
+// 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.
+
+#ifndef ARROW_UTIL_LOGGING_H
+#define ARROW_UTIL_LOGGING_H
+
+#include <iostream>
+
+namespace arrow {
+
+// Stubbed versions of macros defined in glog/logging.h, intended for
+// environments where glog headers aren't available.
+//
+// Add more as needed.
+
+// Log levels. LOG ignores them, so their values are abitrary.
+
+#define ARROW_INFO 0
+#define ARROW_WARNING 1
+#define ARROW_ERROR 2
+#define ARROW_FATAL 3
+
+#define ARROW_LOG_INTERNAL(level) arrow::internal::CerrLog(level)
+#define ARROW_LOG(level) ARROW_LOG_INTERNAL(ARROW_##level)
+
+#define ARROW_CHECK(condition) \
+  (condition) ? 0 : ARROW_LOG(FATAL) << "Check failed: " #condition " "
+
+#ifdef NDEBUG
+#define ARROW_DFATAL ARROW_WARNING
+
+#define DCHECK(condition) while (false) arrow::internal::NullLog()
+#define DCHECK_EQ(val1, val2) while (false) arrow::internal::NullLog()
+#define DCHECK_NE(val1, val2) while (false) arrow::internal::NullLog()
+#define DCHECK_LE(val1, val2) while (false) arrow::internal::NullLog()
+#define DCHECK_LT(val1, val2) while (false) arrow::internal::NullLog()
+#define DCHECK_GE(val1, val2) while (false) arrow::internal::NullLog()
+#define DCHECK_GT(val1, val2) while (false) arrow::internal::NullLog()
+
+#else
+#define ARROW_DFATAL ARROW_FATAL
+
+#define DCHECK(condition) ARROW_CHECK(condition)
+#define DCHECK_EQ(val1, val2) ARROW_CHECK((val1) == (val2))
+#define DCHECK_NE(val1, val2) ARROW_CHECK((val1) != (val2))
+#define DCHECK_LE(val1, val2) ARROW_CHECK((val1) <= (val2))
+#define DCHECK_LT(val1, val2) ARROW_CHECK((val1) < (val2))
+#define DCHECK_GE(val1, val2) ARROW_CHECK((val1) >= (val2))
+#define DCHECK_GT(val1, val2) ARROW_CHECK((val1) > (val2))
+
+#endif // NDEBUG
+
+namespace internal {
+
+class NullLog {
+ public:
+  template<class T>
+  NullLog& operator<<(const T& t) {
+    return *this;
+  }
+};
+
+class CerrLog {
+ public:
+  CerrLog(int severity) // NOLINT(runtime/explicit)
+    : severity_(severity),
+      has_logged_(false) {
+  }
+
+  ~CerrLog() {
+    if (has_logged_) {
+      std::cerr << std::endl;
+    }
+    if (severity_ == ARROW_FATAL) {
+      exit(1);
+    }
+  }
+
+  template<class T>
+  CerrLog& operator<<(const T& t) {
+    has_logged_ = true;
+    std::cerr << t;
+    return *this;
+  }
+
+ private:
+  const int severity_;
+  bool has_logged_;
+};
+
+} // namespace internal
+
+} // namespace arrow
+
+#endif // ARROW_UTIL_LOGGING_H

Reply via email to