Coverage Report

Created: 2025-08-28 07:58

/src/duckdb/third_party/re2/util/logging.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2009 The RE2 Authors.  All Rights Reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
5
#ifndef UTIL_LOGGING_H_
6
#define UTIL_LOGGING_H_
7
8
// Simplified version of Google's logging.
9
10
#include <assert.h>
11
#include <stdio.h>
12
#include <stdlib.h>
13
#include <ostream>
14
#include <sstream>
15
#include <stdexcept>
16
17
#include "util/util.h"
18
19
// Debug-only checking.
20
119M
#define DCHECK(condition) assert(condition)
21
284M
#define DCHECK_EQ(val1, val2) assert((val1) == (val2))
22
127M
#define DCHECK_NE(val1, val2) assert((val1) != (val2))
23
258M
#define DCHECK_LE(val1, val2) assert((val1) <= (val2))
24
#define DCHECK_LT(val1, val2) assert((val1) < (val2))
25
226M
#define DCHECK_GE(val1, val2) assert((val1) >= (val2))
26
#define DCHECK_GT(val1, val2) assert((val1) > (val2))
27
28
// Always-on checking
29
#define CHECK(x)  if(x){}else LogMessageFatal(__FILE__, __LINE__).stream() << "Check failed: " #x
30
#define CHECK_LT(x, y)  CHECK((x) < (y))
31
#define CHECK_GT(x, y)  CHECK((x) > (y))
32
#define CHECK_LE(x, y)  CHECK((x) <= (y))
33
#define CHECK_GE(x, y)  CHECK((x) >= (y))
34
#define CHECK_EQ(x, y)  CHECK((x) == (y))
35
#define CHECK_NE(x, y)  CHECK((x) != (y))
36
37
#define RE2_LOG_INFO LogMessage(__FILE__, __LINE__)
38
#define RE2_LOG_WARNING LogMessage(__FILE__, __LINE__)
39
0
#define RE2_LOG_ERROR LogMessage(__FILE__, __LINE__)
40
#define RE2_LOG_FATAL LogMessageFatal(__FILE__, __LINE__)
41
#define RE2_LOG_QFATAL RE2_LOG_FATAL
42
43
// It seems that one of the Windows header files defines ERROR as 0.
44
#ifdef _WIN32
45
#define LOG_0 RE2_LOG_INFO
46
#endif
47
48
#ifdef NDEBUG
49
0
#define RE2_LOG_DFATAL RE2_LOG_ERROR
50
#else
51
#define RE2_LOG_DFATAL RE2_LOG_FATAL
52
#endif
53
54
0
#define LOG(severity) RE2_LOG_ ## severity.stream()
55
56
#define VLOG(x) if((x)>0){}else RE2_LOG_INFO.stream()
57
58
class LogMessage {
59
 public:
60
  LogMessage(const char* file, int line)
61
0
      : flushed_(false) {
62
//    stream() << file << ":" << line << ": ";
63
0
  }
64
0
  void Flush() {
65
//    stream() << "\n";
66
//    std::string s = str_.str();
67
//    size_t n = s.size();
68
//    if (fwrite(s.data(), 1, n, stderr) < n) {}  // shut up gcc
69
//    flushed_ = true;
70
0
  }
71
0
  ~LogMessage() {
72
0
    if (!flushed_) {
73
0
      Flush();
74
0
    }
75
0
  }
76
0
  std::ostream& stream() { return str_; }
77
78
 private:
79
  bool flushed_;
80
  std::ostringstream str_;
81
82
  LogMessage(const LogMessage&) = delete;
83
  LogMessage& operator=(const LogMessage&) = delete;
84
};
85
86
// Silence "destructor never returns" warning for ~LogMessageFatal().
87
// Since this is a header file, push and then pop to limit the scope.
88
#ifdef _MSC_VER
89
#pragma warning(push)
90
#pragma warning(disable: 4722)
91
#endif
92
93
class LogMessageFatal : public LogMessage {
94
 public:
95
  LogMessageFatal(const char* file, int line)
96
0
      : LogMessage(file, line) {
97
0
    throw std::runtime_error("RE2 Fatal Error");
98
0
  }
99
0
  ~LogMessageFatal() {
100
0
    Flush();
101
0
  }
102
 private:
103
  LogMessageFatal(const LogMessageFatal&) = delete;
104
  LogMessageFatal& operator=(const LogMessageFatal&) = delete;
105
};
106
107
#ifdef _MSC_VER
108
#pragma warning(pop)
109
#endif
110
111
#endif  // UTIL_LOGGING_H_