Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:27:09

0001 // Licensed to the Apache Software Foundation (ASF) under one
0002 // or more contributor license agreements.  See the NOTICE file
0003 // distributed with this work for additional information
0004 // regarding copyright ownership.  The ASF licenses this file
0005 // to you under the Apache License, Version 2.0 (the
0006 // "License"); you may not use this file except in compliance
0007 // with the License.  You may obtain a copy of the License at
0008 //
0009 //   http://www.apache.org/licenses/LICENSE-2.0
0010 //
0011 // Unless required by applicable law or agreed to in writing,
0012 // software distributed under the License is distributed on an
0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0014 // KIND, either express or implied.  See the License for the
0015 // specific language governing permissions and limitations
0016 // under the License.
0017 
0018 #pragma once
0019 
0020 #ifdef GANDIVA_IR
0021 
0022 // The LLVM IR code doesn't have an NDEBUG mode. And, it shouldn't include references to
0023 // streams or stdc++. So, making the DCHECK calls void in that case.
0024 
0025 #  define ARROW_IGNORE_EXPR(expr) ((void)(expr))
0026 
0027 #  define DCHECK(condition) ARROW_IGNORE_EXPR(condition)
0028 #  define DCHECK_OK(status) ARROW_IGNORE_EXPR(status)
0029 #  define DCHECK_EQ(val1, val2) ARROW_IGNORE_EXPR(val1)
0030 #  define DCHECK_NE(val1, val2) ARROW_IGNORE_EXPR(val1)
0031 #  define DCHECK_LE(val1, val2) ARROW_IGNORE_EXPR(val1)
0032 #  define DCHECK_LT(val1, val2) ARROW_IGNORE_EXPR(val1)
0033 #  define DCHECK_GE(val1, val2) ARROW_IGNORE_EXPR(val1)
0034 #  define DCHECK_GT(val1, val2) ARROW_IGNORE_EXPR(val1)
0035 
0036 #else  // !GANDIVA_IR
0037 
0038 #  include <memory>
0039 #  include <ostream>
0040 #  include <string>
0041 
0042 #  include "arrow/util/macros.h"
0043 #  include "arrow/util/visibility.h"
0044 
0045 namespace arrow {
0046 namespace util {
0047 
0048 enum class ArrowLogLevel : int {
0049   ARROW_TRACE = -2,
0050   ARROW_DEBUG = -1,
0051   ARROW_INFO = 0,
0052   ARROW_WARNING = 1,
0053   ARROW_ERROR = 2,
0054   ARROW_FATAL = 3
0055 };
0056 
0057 #  define ARROW_LOG_INTERNAL(level) ::arrow::util::ArrowLog(__FILE__, __LINE__, level)
0058 #  define ARROW_LOG(level) ARROW_LOG_INTERNAL(::arrow::util::ArrowLogLevel::ARROW_##level)
0059 
0060 #  define ARROW_IGNORE_EXPR(expr) ((void)(expr))
0061 
0062 #  define ARROW_CHECK_OR_LOG(condition, level) \
0063     ARROW_PREDICT_TRUE(condition)              \
0064     ? ARROW_IGNORE_EXPR(0)                     \
0065     : ::arrow::util::Voidify() & ARROW_LOG(level) << " Check failed: " #condition " "
0066 
0067 #  define ARROW_CHECK(condition) ARROW_CHECK_OR_LOG(condition, FATAL)
0068 
0069 // If 'to_call' returns a bad status, CHECK immediately with a logged message
0070 // of 'msg' followed by the status.
0071 #  define ARROW_CHECK_OK_PREPEND(to_call, msg, level)                 \
0072     do {                                                              \
0073       ::arrow::Status _s = (to_call);                                 \
0074       ARROW_CHECK_OR_LOG(_s.ok(), level)                              \
0075           << "Operation failed: " << ARROW_STRINGIFY(to_call) << "\n" \
0076           << (msg) << ": " << _s.ToString();                          \
0077     } while (false)
0078 
0079 // If the status is bad, CHECK immediately, appending the status to the
0080 // logged message.
0081 #  define ARROW_CHECK_OK(s) ARROW_CHECK_OK_PREPEND(s, "Bad status", FATAL)
0082 
0083 #  define ARROW_CHECK_EQ(val1, val2) ARROW_CHECK((val1) == (val2))
0084 #  define ARROW_CHECK_NE(val1, val2) ARROW_CHECK((val1) != (val2))
0085 #  define ARROW_CHECK_LE(val1, val2) ARROW_CHECK((val1) <= (val2))
0086 #  define ARROW_CHECK_LT(val1, val2) ARROW_CHECK((val1) < (val2))
0087 #  define ARROW_CHECK_GE(val1, val2) ARROW_CHECK((val1) >= (val2))
0088 #  define ARROW_CHECK_GT(val1, val2) ARROW_CHECK((val1) > (val2))
0089 
0090 #  ifdef NDEBUG
0091 #    define ARROW_DFATAL ::arrow::util::ArrowLogLevel::ARROW_WARNING
0092 
0093 // CAUTION: DCHECK_OK() always evaluates its argument, but other DCHECK*() macros
0094 // only do so in debug mode.
0095 
0096 #    define ARROW_DCHECK(condition)               \
0097       while (false) ARROW_IGNORE_EXPR(condition); \
0098       while (false) ::arrow::util::detail::NullLog()
0099 #    define ARROW_DCHECK_OK(s) \
0100       ARROW_IGNORE_EXPR(s);    \
0101       while (false) ::arrow::util::detail::NullLog()
0102 #    define ARROW_DCHECK_EQ(val1, val2)      \
0103       while (false) ARROW_IGNORE_EXPR(val1); \
0104       while (false) ARROW_IGNORE_EXPR(val2); \
0105       while (false) ::arrow::util::detail::NullLog()
0106 #    define ARROW_DCHECK_NE(val1, val2)      \
0107       while (false) ARROW_IGNORE_EXPR(val1); \
0108       while (false) ARROW_IGNORE_EXPR(val2); \
0109       while (false) ::arrow::util::detail::NullLog()
0110 #    define ARROW_DCHECK_LE(val1, val2)      \
0111       while (false) ARROW_IGNORE_EXPR(val1); \
0112       while (false) ARROW_IGNORE_EXPR(val2); \
0113       while (false) ::arrow::util::detail::NullLog()
0114 #    define ARROW_DCHECK_LT(val1, val2)      \
0115       while (false) ARROW_IGNORE_EXPR(val1); \
0116       while (false) ARROW_IGNORE_EXPR(val2); \
0117       while (false) ::arrow::util::detail::NullLog()
0118 #    define ARROW_DCHECK_GE(val1, val2)      \
0119       while (false) ARROW_IGNORE_EXPR(val1); \
0120       while (false) ARROW_IGNORE_EXPR(val2); \
0121       while (false) ::arrow::util::detail::NullLog()
0122 #    define ARROW_DCHECK_GT(val1, val2)      \
0123       while (false) ARROW_IGNORE_EXPR(val1); \
0124       while (false) ARROW_IGNORE_EXPR(val2); \
0125       while (false) ::arrow::util::detail::NullLog()
0126 
0127 #  else
0128 #    define ARROW_DFATAL ::arrow::util::ArrowLogLevel::ARROW_FATAL
0129 
0130 #    define ARROW_DCHECK ARROW_CHECK
0131 #    define ARROW_DCHECK_OK ARROW_CHECK_OK
0132 #    define ARROW_DCHECK_EQ ARROW_CHECK_EQ
0133 #    define ARROW_DCHECK_NE ARROW_CHECK_NE
0134 #    define ARROW_DCHECK_LE ARROW_CHECK_LE
0135 #    define ARROW_DCHECK_LT ARROW_CHECK_LT
0136 #    define ARROW_DCHECK_GE ARROW_CHECK_GE
0137 #    define ARROW_DCHECK_GT ARROW_CHECK_GT
0138 
0139 #  endif  // NDEBUG
0140 
0141 // These are internal-use macros and should not be used in public headers.
0142 #  ifndef DCHECK
0143 #    define DCHECK ARROW_DCHECK
0144 #  endif
0145 #  ifndef DCHECK_OK
0146 #    define DCHECK_OK ARROW_DCHECK_OK
0147 #  endif
0148 #  ifndef DCHECK_EQ
0149 #    define DCHECK_EQ ARROW_DCHECK_EQ
0150 #  endif
0151 #  ifndef DCHECK_NE
0152 #    define DCHECK_NE ARROW_DCHECK_NE
0153 #  endif
0154 #  ifndef DCHECK_LE
0155 #    define DCHECK_LE ARROW_DCHECK_LE
0156 #  endif
0157 #  ifndef DCHECK_LT
0158 #    define DCHECK_LT ARROW_DCHECK_LT
0159 #  endif
0160 #  ifndef DCHECK_GE
0161 #    define DCHECK_GE ARROW_DCHECK_GE
0162 #  endif
0163 #  ifndef DCHECK_GT
0164 #    define DCHECK_GT ARROW_DCHECK_GT
0165 #  endif
0166 
0167 // This code is adapted from
0168 // https://github.com/ray-project/ray/blob/master/src/ray/util/logging.h.
0169 
0170 // To make the logging lib pluggable with other logging libs and make
0171 // the implementation unawared by the user, ArrowLog is only a declaration
0172 // which hide the implementation into logging.cc file.
0173 // In logging.cc, we can choose different log libs using different macros.
0174 
0175 // This is also a null log which does not output anything.
0176 class ARROW_EXPORT ArrowLogBase {
0177  public:
0178   virtual ~ArrowLogBase() {}
0179 
0180   virtual bool IsEnabled() const { return false; }
0181 
0182   template <typename T>
0183   ArrowLogBase& operator<<(const T& t) {
0184     if (IsEnabled()) {
0185       Stream() << t;
0186     }
0187     return *this;
0188   }
0189 
0190  protected:
0191   virtual std::ostream& Stream() = 0;
0192 };
0193 
0194 class ARROW_EXPORT ArrowLog : public ArrowLogBase {
0195  public:
0196   ArrowLog(const char* file_name, int line_number, ArrowLogLevel severity);
0197   ~ArrowLog() override;
0198 
0199   /// Return whether or not current logging instance is enabled.
0200   ///
0201   /// \return True if logging is enabled and false otherwise.
0202   bool IsEnabled() const override;
0203 
0204   /// The init function of arrow log for a program which should be called only once.
0205   ///
0206   /// \param appName The app name which starts the log.
0207   /// \param severity_threshold Logging threshold for the program.
0208   /// \param logDir Logging output file name. If empty, the log won't output to file.
0209   static void StartArrowLog(const std::string& appName,
0210                             ArrowLogLevel severity_threshold = ArrowLogLevel::ARROW_INFO,
0211                             const std::string& logDir = "");
0212 
0213   /// The shutdown function of arrow log, it should be used with StartArrowLog as a pair.
0214   static void ShutDownArrowLog();
0215 
0216   /// Install the failure signal handler to output call stack when crash.
0217   /// If glog is not installed, this function won't do anything.
0218   static void InstallFailureSignalHandler();
0219 
0220   /// Uninstall the signal actions installed by InstallFailureSignalHandler.
0221   static void UninstallSignalAction();
0222 
0223   /// Return whether or not the log level is enabled in current setting.
0224   ///
0225   /// \param log_level The input log level to test.
0226   /// \return True if input log level is not lower than the threshold.
0227   static bool IsLevelEnabled(ArrowLogLevel log_level);
0228 
0229  private:
0230   ARROW_DISALLOW_COPY_AND_ASSIGN(ArrowLog);
0231 
0232   // Hide the implementation of log provider by void *.
0233   // Otherwise, lib user may define the same macro to use the correct header file.
0234   void* logging_provider_;
0235   /// True if log messages should be logged and false if they should be ignored.
0236   bool is_enabled_;
0237 
0238   static ArrowLogLevel severity_threshold_;
0239 
0240  protected:
0241   std::ostream& Stream() override;
0242 };
0243 
0244 // This class make ARROW_CHECK compilation pass to change the << operator to void.
0245 // This class is copied from glog.
0246 class ARROW_EXPORT Voidify {
0247  public:
0248   Voidify() {}
0249   // This has to be an operator with a precedence lower than << but
0250   // higher than ?:
0251   void operator&(ArrowLogBase&) {}
0252 };
0253 
0254 namespace detail {
0255 
0256 /// @brief A helper for the nil log sink.
0257 ///
0258 /// Using this helper is analogous to sending log messages to /dev/null:
0259 /// nothing gets logged.
0260 class NullLog {
0261  public:
0262   /// The no-op output operator.
0263   ///
0264   /// @param [in] t
0265   ///   The object to send into the nil sink.
0266   /// @return Reference to the updated object.
0267   template <class T>
0268   NullLog& operator<<(const T& t) {
0269     return *this;
0270   }
0271 };
0272 
0273 }  // namespace detail
0274 }  // namespace util
0275 }  // namespace arrow
0276 
0277 #endif  // GANDIVA_IR