rework public header structure (#1012)

Promote generated headers to regular headers. This enables direct
editing of corresponding files and running automatic source code
formatting and static analysis tools, such as clang-format and
clang-tidy on the whole project which previously was not
straightforward.
This commit is contained in:
Sergiu Deitsch 2023-12-30 19:05:26 +01:00 committed by GitHub
parent 80d7fa3863
commit e3f5398aa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 784 additions and 945 deletions

View File

@ -130,12 +130,6 @@ jobs:
gcovr -r .. . -s --xml coverage.xml
cd ..
for file in src/glog/*.h.in; do
name=$(basename ${file})
name_we=${name%.h.in}
sed -i "s|build_${{matrix.build_type}}/glog/${name_we}.h|${file}|g" build_${{matrix.build_type}}/coverage.xml
done
- name: Upload Coverage to Codecov
if: matrix.build_type == 'Debug'
uses: codecov/codecov-action@v3

View File

@ -66,12 +66,6 @@ jobs:
gcovr -r .. . -s --cobertura coverage.xml
cd ..
for file in src/glog/*.h.in; do
name=$(basename ${file})
name_we=${name%.h.in}
sed -i "" "s|build_${{matrix.build_type}}/glog/${name_we}.h|${file}|g" build_${{matrix.build_type}}/coverage.xml
done
- name: Upload Coverage to Codecov
if: matrix.build_type == 'Debug'
uses: codecov/codecov-action@v3

View File

@ -233,12 +233,6 @@ jobs:
gcovr -r .. . -s --cobertura coverage.xml
cd ..
for file in src/glog/*.h.in; do
name=$(basename ${file})
name_we=${name%.h.in}
sed -i "s|build_${{matrix.build_type}}/glog/${name_we}.h|${file}|g" build_${{matrix.build_type}}/coverage.xml
done
- name: Upload Coverage to Codecov
if: matrix.build_type == 'Debug'
uses: codecov/codecov-action@v3

View File

@ -133,10 +133,7 @@ endif (Unwind_FOUND)
check_include_file_cxx (dlfcn.h HAVE_DLFCN_H)
check_include_file_cxx (glob.h HAVE_GLOB_H)
check_include_file_cxx (memory.h HAVE_MEMORY_H)
check_include_file_cxx (pwd.h HAVE_PWD_H)
check_include_file_cxx (strings.h HAVE_STRINGS_H)
check_include_file_cxx (sys/stat.h HAVE_SYS_STAT_H)
check_include_file_cxx (sys/syscall.h HAVE_SYS_SYSCALL_H)
check_include_file_cxx (sys/time.h HAVE_SYS_TIME_H)
check_include_file_cxx (sys/types.h HAVE_SYS_TYPES_H)
@ -190,28 +187,6 @@ set (CMAKE_REQUIRED_LIBRARIES dbghelp)
check_cxx_symbol_exists (UnDecorateSymbolName "windows.h;dbghelp.h" HAVE_DBGHELP)
cmake_pop_check_state ()
check_cxx_source_compiles ("
#include <cstdlib>
static void foo(void) __attribute__ ((unused));
int main(void) { return 0; }
" HAVE___ATTRIBUTE__)
check_cxx_source_compiles ("
#include <cstdlib>
static void foo(void) __attribute__ ((visibility(\"default\")));
int main(void) { return 0; }
" HAVE___ATTRIBUTE__VISIBILITY_DEFAULT)
check_cxx_source_compiles ("
#include <cstdlib>
static void foo(void) __attribute__ ((visibility(\"hidden\")));
int main(void) { return 0; }
" HAVE___ATTRIBUTE__VISIBILITY_HIDDEN)
check_cxx_source_compiles ("
int main(void) { if (__builtin_expect(0, 0)) return 1; return 0; }
" HAVE___BUILTIN_EXPECT)
check_cxx_source_compiles ("
int main(void)
{
@ -285,58 +260,6 @@ if (HAVE_UCONTEXT_H AND NOT DEFINED PC_FROM_UCONTEXT)
cmake_pop_check_state ()
endif (HAVE_UCONTEXT_H AND NOT DEFINED PC_FROM_UCONTEXT)
set (GOOGLE_NAMESPACE google)
set (_START_GOOGLE_NAMESPACE_ "namespace ${GOOGLE_NAMESPACE} {")
set (_END_GOOGLE_NAMESPACE_ "}")
set (ac_cv_have_glog_export 1)
if (HAVE_LIB_GFLAGS)
set (ac_cv_have_libgflags 1)
else (HAVE_LIB_GFLAGS)
set (ac_cv_have_libgflags 0)
endif (HAVE_LIB_GFLAGS)
if (HAVE_SYS_TYPES_H)
set (ac_cv_have_systypes_h 1)
else (HAVE_SYS_TYPES_H)
set (ac_cv_have_systypes_h 0)
endif (HAVE_SYS_TYPES_H)
if (HAVE_SSIZE_T)
set (ac_cv_have_ssize_t 1)
else (HAVE_SSIZE_T)
set (ac_cv_have_ssize_t 0)
endif (HAVE_SSIZE_T)
if (HAVE_MODE_T)
set (ac_cv_have_mode_t 1)
else (HAVE_MODE_T)
set (ac_cv_have_mode_t 0)
endif (HAVE_MODE_T)
if (HAVE_UNISTD_H)
set (ac_cv_have_unistd_h 1)
else (HAVE_UNISTD_H)
set (ac_cv_have_unistd_h 0)
endif (HAVE_UNISTD_H)
set (ac_google_namespace ${GOOGLE_NAMESPACE})
set (ac_google_end_namespace ${_END_GOOGLE_NAMESPACE_})
set (ac_google_start_namespace ${_START_GOOGLE_NAMESPACE_})
if (HAVE___ATTRIBUTE__)
set (ac_cv___attribute___noinline "__attribute__((noinline))")
set (ac_cv___attribute___printf_4_5 "__attribute__((__format__(__printf__, 4, 5)))")
elseif (HAVE___DECLSPEC)
#set (ac_cv___attribute___noinline "__declspec(noinline)")
endif (HAVE___ATTRIBUTE__)
if (HAVE___BUILTIN_EXPECT)
set (ac_cv_have___builtin_expect 1)
else (HAVE___BUILTIN_EXPECT)
set (ac_cv_have___builtin_expect 0)
endif (HAVE___BUILTIN_EXPECT)
if (HAVE_EXECINFO_BACKTRACE AND HAVE_EXECINFO_BACKTRACE_SYMBOLS)
set (HAVE_STACKTRACE 1)
endif (HAVE_EXECINFO_BACKTRACE AND HAVE_EXECINFO_BACKTRACE_SYMBOLS)
@ -414,10 +337,6 @@ else (CYGWIN)
endif (CYGWIN)
configure_file (src/config.h.cmake.in config.h)
configure_file (src/glog/logging.h.in glog/logging.h @ONLY)
configure_file (src/glog/raw_logging.h.in glog/raw_logging.h @ONLY)
configure_file (src/glog/stl_logging.h.in glog/stl_logging.h @ONLY)
configure_file (src/glog/vlog_is_on.h.in glog/vlog_is_on.h @ONLY)
set (_glog_CMake_BINDIR ${CMAKE_INSTALL_BINDIR})
set (_glog_CMake_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR})
@ -459,12 +378,12 @@ endif (_glog_CMake_MODULES)
set (GLOG_PUBLIC_H
${glog_BINARY_DIR}/glog/export.h
${glog_BINARY_DIR}/glog/logging.h
${glog_BINARY_DIR}/glog/raw_logging.h
${glog_BINARY_DIR}/glog/stl_logging.h
${glog_BINARY_DIR}/glog/vlog_is_on.h
src/glog/log_severity.h
src/glog/logging.h
src/glog/platform.h
src/glog/raw_logging.h
src/glog/stl_logging.h
src/glog/vlog_is_on.h
)
set (GLOG_SRCS
@ -517,6 +436,13 @@ add_library (glog::glog ALIAS glog)
set (glog_libraries_options_for_static_linking)
# CMake always uses the generated export header
target_compile_definitions (glog PUBLIC GLOG_USE_GLOG_EXPORT)
if (HAVE_LIB_GFLAGS)
target_compile_definitions (glog PUBLIC GLOG_USE_GFLAGS)
endif (HAVE_LIB_GFLAGS)
if (Unwind_FOUND)
target_link_libraries (glog PRIVATE unwind::unwind)
set (glog_libraries_options_for_static_linking "${glog_libraries_options_for_static_linking} -lunwind")

View File

@ -25,13 +25,7 @@ expand_template = rule(
},
)
def dict_union(x, y):
z = {}
z.update(x)
z.update(y)
return z
def glog_library(namespace = "google", with_gflags = 1, **kwargs):
def glog_library(with_gflags = 1, **kwargs):
if native.repository_name() != "@":
repo_name = native.repository_name()[1:] # Strip the first leading @
gendir = "$(GENDIR)/external/" + repo_name
@ -55,11 +49,9 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
common_copts = [
"-std=c++14",
"-DGLOG_BAZEL_BUILD",
# Inject a C++ namespace.
"-DGOOGLE_NAMESPACE='%s'" % namespace,
"-DHAVE_STRING_H",
"-I%s/glog_internal" % gendir,
] + (["-DHAVE_LIB_GFLAGS"] if with_gflags else [])
] + (["-DGLOG_USE_GFLAGS"] if with_gflags else [])
wasm_copts = [
# Disable warnings that exists in glog.
@ -78,11 +70,13 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
"-DHAVE_SIGACTION",
# For logging.cc.
"-DHAVE_PREAD",
"-DHAVE___ATTRIBUTE__",
]
linux_or_darwin_copts = wasm_copts + [
"-DGLOG_EXPORT=__attribute__((visibility(\\\"default\\\")))",
"-DHAVE_MODE_T",
"-DHAVE_SSIZE_T",
"-DHAVE_SYS_TYPES_H",
# For src/utilities.cc.
"-DHAVE_SYS_SYSCALL_H",
# For src/logging.cc to create symlinks.
@ -194,11 +188,11 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
}),
hdrs = [
"src/glog/log_severity.h",
"src/glog/logging.h",
"src/glog/platform.h",
":logging_h",
":raw_logging_h",
":stl_logging_h",
":vlog_is_on_h",
"src/glog/raw_logging.h",
"src/glog/stl_logging.h",
"src/glog/vlog_is_on.h",
],
# https://github.com/google/glog/issues/837: Replacing
# `strip_include_prefix` with `includes` would avoid spamming
@ -261,10 +255,10 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
name = "strip_include_prefix_hack",
hdrs = [
"src/glog/log_severity.h",
":logging_h",
":raw_logging_h",
":stl_logging_h",
":vlog_is_on_h",
"src/glog/logging.h",
"src/glog/raw_logging.h",
"src/glog/stl_logging.h",
"src/glog/vlog_is_on.h",
],
)
@ -274,51 +268,3 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
out = "glog_internal/config.h",
substitutions = {"#cmakedefine": "//cmakedefine"},
)
common_config = {
"@ac_cv_have_u_int16_t@": "0",
"@ac_cv_have_glog_export@": "0",
"@ac_google_start_namespace@": "namespace google {",
"@ac_google_end_namespace@": "}",
"@ac_google_namespace@": "google",
}
posix_config = dict_union(common_config, {
"@ac_cv___attribute___noinline@": "__attribute__((noinline))",
"@ac_cv___attribute___printf_4_5@": "__attribute__((__format__(__printf__, 4, 5)))",
"@ac_cv_have___builtin_expect@": "1",
"@ac_cv_have_libgflags@": "1" if with_gflags else "0",
"@ac_cv_have_mode_t@": "1",
"@ac_cv_have_ssize_t@": "1",
"@ac_cv_have_systypes_h@": "1",
"@ac_cv_have_unistd_h@": "1",
})
windows_config = dict_union(common_config, {
"@ac_cv___attribute___noinline@": "",
"@ac_cv___attribute___printf_4_5@": "",
"@ac_cv_have___builtin_expect@": "0",
"@ac_cv_have_libgflags@": "0",
"@ac_cv_have_mode_t@": "0",
"@ac_cv_have_ssize_t@": "0",
"@ac_cv_have_systypes_h@": "0",
"@ac_cv_have_unistd_h@": "0",
})
[
expand_template(
name = "%s_h" % f,
template = "src/glog/%s.h.in" % f,
out = "src/glog/%s.h" % f,
substitutions = select({
"@bazel_tools//src/conditions:windows": windows_config,
"//conditions:default": posix_config,
}),
)
for f in [
"vlog_is_on",
"stl_logging",
"raw_logging",
"logging",
]
]

View File

@ -53,7 +53,7 @@
#include <cstring> // for memchr
#include <string>
#ifdef HAVE_LIB_GFLAGS
#ifdef GLOG_USE_GFLAGS
#include <gflags/gflags.h>
@ -80,18 +80,16 @@
DEFINE_VARIABLE(bool, B, name, value, meaning, bool)
// int32 specialization
#define DECLARE_int32(name) \
DECLARE_VARIABLE(GOOGLE_NAMESPACE::int32, I, name, int32)
#define DECLARE_int32(name) DECLARE_VARIABLE(google::int32, I, name, int32)
#define DEFINE_int32(name, value, meaning) \
DEFINE_VARIABLE(GOOGLE_NAMESPACE::int32, I, name, value, meaning, int32)
DEFINE_VARIABLE(google::int32, I, name, value, meaning, int32)
// uint32 specialization
#ifndef DECLARE_uint32
#define DECLARE_uint32(name) \
DECLARE_VARIABLE(GOOGLE_NAMESPACE::uint32, U, name, uint32)
#define DECLARE_uint32(name) DECLARE_VARIABLE(google::uint32, U, name, uint32)
#endif // DECLARE_uint64
#define DEFINE_uint32(name, value, meaning) \
DEFINE_VARIABLE(GOOGLE_NAMESPACE::uint32, U, name, value, meaning, uint32)
DEFINE_VARIABLE(google::uint32, U, name, value, meaning, uint32)
// Special case for string, because we have to specify the namespace
// std::string, which doesn't play nicely with our FLAG__namespace hackery.
@ -108,7 +106,7 @@
} \
using fLS::FLAGS_##name
#endif // HAVE_LIB_GFLAGS
#endif // GLOG_USE_GFLAGS
// Define GLOG_DEFINE_* using DEFINE_* . By using these macros, we
// have GLOG_* environ variables even if we have gflags installed.

View File

@ -32,7 +32,7 @@
#include "glog/raw_logging.h"
#include "googletest.h"
#ifdef HAVE_LIB_GFLAGS
#ifdef GLOG_USE_GFLAGS
#include <gflags/gflags.h>
using namespace GFLAGS_NAMESPACE;
#endif
@ -42,7 +42,7 @@ using namespace GFLAGS_NAMESPACE;
#include "mock-log.h"
// Introduce several symbols from gmock.
using GOOGLE_NAMESPACE::glog_testing::ScopedMockLog;
using google::glog_testing::ScopedMockLog;
using testing::_;
using testing::AllOf;
using testing::AnyNumber;
@ -52,7 +52,7 @@ using testing::StrictMock;
using testing::StrNe;
#endif
using namespace GOOGLE_NAMESPACE;
using namespace google;
TEST(CleanImmediately, logging) {
google::SetLogFilenameExtension(".foobar");
@ -68,7 +68,7 @@ TEST(CleanImmediately, logging) {
int main(int argc, char **argv) {
FLAGS_colorlogtostderr = false;
FLAGS_timestamp_in_logfile_name = true;
#ifdef HAVE_LIB_GFLAGS
#ifdef GLOG_USE_GFLAGS
ParseCommandLineFlags(&argc, &argv, true);
#endif
// Make sure stderr is not buffered as stderr seems to be buffered

View File

@ -32,7 +32,7 @@
#include "glog/raw_logging.h"
#include "googletest.h"
#ifdef HAVE_LIB_GFLAGS
#ifdef GLOG_USE_GFLAGS
#include <gflags/gflags.h>
using namespace GFLAGS_NAMESPACE;
#endif
@ -42,7 +42,7 @@ using namespace GFLAGS_NAMESPACE;
#include "mock-log.h"
// Introduce several symbols from gmock.
using GOOGLE_NAMESPACE::glog_testing::ScopedMockLog;
using google::glog_testing::ScopedMockLog;
using testing::_;
using testing::AllOf;
using testing::AnyNumber;
@ -52,7 +52,7 @@ using testing::StrictMock;
using testing::StrNe;
#endif
using namespace GOOGLE_NAMESPACE;
using namespace google;
TEST(CleanImmediatelyWithAbsolutePrefix, logging) {
google::EnableLogCleaner(0);
@ -73,7 +73,7 @@ TEST(CleanImmediatelyWithAbsolutePrefix, logging) {
int main(int argc, char **argv) {
FLAGS_colorlogtostderr = false;
FLAGS_timestamp_in_logfile_name = true;
#ifdef HAVE_LIB_GFLAGS
#ifdef GLOG_USE_GFLAGS
ParseCommandLineFlags(&argc, &argv, true);
#endif
// Make sure stderr is not buffered as stderr seems to be buffered

View File

@ -32,7 +32,7 @@
#include "glog/raw_logging.h"
#include "googletest.h"
#ifdef HAVE_LIB_GFLAGS
#ifdef GLOG_USE_GFLAGS
#include <gflags/gflags.h>
using namespace GFLAGS_NAMESPACE;
#endif
@ -42,7 +42,7 @@ using namespace GFLAGS_NAMESPACE;
#include "mock-log.h"
// Introduce several symbols from gmock.
using GOOGLE_NAMESPACE::glog_testing::ScopedMockLog;
using google::glog_testing::ScopedMockLog;
using testing::_;
using testing::AllOf;
using testing::AnyNumber;
@ -52,7 +52,7 @@ using testing::StrictMock;
using testing::StrNe;
#endif
using namespace GOOGLE_NAMESPACE;
using namespace google;
TEST(CleanImmediatelyWithRelativePrefix, logging) {
google::EnableLogCleaner(0);
@ -69,7 +69,7 @@ TEST(CleanImmediatelyWithRelativePrefix, logging) {
int main(int argc, char **argv) {
FLAGS_colorlogtostderr = false;
FLAGS_timestamp_in_logfile_name = true;
#ifdef HAVE_LIB_GFLAGS
#ifdef GLOG_USE_GFLAGS
ParseCommandLineFlags(&argc, &argv, true);
#endif
// Make sure stderr is not buffered as stderr seems to be buffered

View File

@ -1,9 +1,6 @@
#ifndef GLOG_CONFIG_H
#define GLOG_CONFIG_H
/* Namespace for Google classes */
#cmakedefine GOOGLE_NAMESPACE ${GOOGLE_NAMESPACE}
/* Define if you have the `dladdr' function */
#cmakedefine HAVE_DLADDR
@ -25,9 +22,6 @@
/* Define to 1 if you have the `pthread' library (-lpthread). */
#cmakedefine HAVE_LIBPTHREAD
/* define if you have google gflags library */
#cmakedefine HAVE_LIB_GFLAGS
/* define if you have google gmock library */
#cmakedefine HAVE_LIB_GMOCK
@ -37,9 +31,6 @@
/* define if you have dbghelp library */
#cmakedefine HAVE_DBGHELP
/* Define to 1 if you have the <memory.h> header file. */
#cmakedefine HAVE_MEMORY_H
/* define to disable multithreading support. */
#cmakedefine NO_THREADS
@ -64,18 +55,12 @@
/* Define if you have the `sigaltstack' function */
#cmakedefine HAVE_SIGALTSTACK
/* Define to 1 if you have the <strings.h> header file. */
#cmakedefine HAVE_STRINGS_H
/* Define to 1 if you have the <syscall.h> header file. */
#cmakedefine HAVE_SYSCALL_H
/* Define to 1 if you have the <syslog.h> header file. */
#cmakedefine HAVE_SYSLOG_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#cmakedefine HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/syscall.h> header file. */
#cmakedefine HAVE_SYS_SYSCALL_H
@ -83,7 +68,7 @@
#cmakedefine HAVE_SYS_TIME_H
/* Define to 1 if you have the <sys/types.h> header file. */
#cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H}
#cmakedefine HAVE_SYS_TYPES_H
/* Define to 1 if you have the <sys/ucontext.h> header file. */
#cmakedefine HAVE_SYS_UCONTEXT_H
@ -106,12 +91,6 @@
/* define if you have libunwind */
#cmakedefine HAVE_LIBUNWIND
/* define if your compiler has __attribute__ */
#cmakedefine HAVE___ATTRIBUTE__
/* define if your compiler has __builtin_expect */
#cmakedefine HAVE___BUILTIN_EXPECT ${HAVE___BUILTIN_EXPECT}
/* define if your compiler has __sync_val_compare_and_swap */
#cmakedefine HAVE___SYNC_VAL_COMPARE_AND_SWAP
@ -127,9 +106,11 @@
/* define if _chsize_s is available in io.h */
#cmakedefine HAVE__CHSIZE_S
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#cmakedefine LT_OBJDIR
/* define if ssize_t is defined */
#cmakedefine HAVE_SSIZE_T
/* define if mode_t is defined */
#cmakedefine HAVE_MODE_T
/* How to access the PC from a struct ucontext */
#cmakedefine PC_FROM_UCONTEXT ${PC_FROM_UCONTEXT}
@ -150,24 +131,6 @@
/* Define if thread-local storage is enabled. */
#cmakedefine GLOG_THREAD_LOCAL_STORAGE
#ifdef GLOG_BAZEL_BUILD
/* TODO(rodrigoq): remove this workaround once bazel#3979 is resolved:
* https://github.com/bazelbuild/bazel/issues/3979 */
#define _START_GOOGLE_NAMESPACE_ namespace GOOGLE_NAMESPACE {
#define _END_GOOGLE_NAMESPACE_ }
#else
/* Stops putting the code inside the Google namespace */
#cmakedefine _END_GOOGLE_NAMESPACE_ ${_END_GOOGLE_NAMESPACE_}
/* Puts following code inside the Google namespace */
#cmakedefine _START_GOOGLE_NAMESPACE_ ${_START_GOOGLE_NAMESPACE_}
#endif
/* Replacement for deprecated syscall(SYS_gettid) on macOS. */
#cmakedefine HAVE_PTHREAD_THREADID_NP ${HAVE_PTHREAD_THREADID_NP}

View File

@ -46,7 +46,7 @@
#include <dbghelp.h>
#endif
_START_GOOGLE_NAMESPACE_
namespace google {
#if !defined(GLOG_OS_WINDOWS)
struct AbbrevPair {
@ -1371,4 +1371,4 @@ bool Demangle(const char *mangled, char *out, size_t out_size) {
#endif
}
_END_GOOGLE_NAMESPACE_
} // namespace google

View File

@ -73,13 +73,13 @@
#include "config.h"
#include "glog/logging.h"
_START_GOOGLE_NAMESPACE_
namespace google {
// Demangle "mangled". On success, return true and write the
// demangled symbol name to "out". Otherwise, return false.
// "out" is modified even if demangling is unsuccessful.
bool GLOG_EXPORT Demangle(const char *mangled, char *out, size_t out_size);
_END_GOOGLE_NAMESPACE_
} // namespace google
#endif // BASE_DEMANGLE_H_

View File

@ -42,7 +42,7 @@
#include "googletest.h"
#include "utilities.h"
#ifdef HAVE_LIB_GFLAGS
#ifdef GLOG_USE_GFLAGS
#include <gflags/gflags.h>
using namespace GFLAGS_NAMESPACE;
#endif
@ -51,7 +51,7 @@ GLOG_DEFINE_bool(demangle_filter, false,
"Run demangle_unittest in filter mode");
using namespace std;
using namespace GOOGLE_NAMESPACE;
using namespace google;
// A wrapper function for Demangle() to make the unit test simple.
static const char *DemangleIt(const char * const mangled) {
@ -148,7 +148,7 @@ TEST(Demangle, FromFile) {
#endif
int main(int argc, char **argv) {
#ifdef HAVE_LIB_GFLAGS
#ifdef GLOG_USE_GFLAGS
ParseCommandLineFlags(&argc, &argv, true);
#endif
InitGoogleTest(&argc, argv);

View File

@ -46,15 +46,12 @@
#include <ostream>
#include <sstream>
#include <string>
#if @ac_cv_have_unistd_h@
# include <unistd.h>
#endif
#include <vector>
#include <utility>
#include <vector>
#if defined(_MSC_VER)
#define GLOG_MSVC_PUSH_DISABLE_WARNING(n) __pragma(warning(push)) \
__pragma(warning(disable:n))
#define GLOG_MSVC_PUSH_DISABLE_WARNING(n) \
__pragma(warning(push)) __pragma(warning(disable : n))
#define GLOG_MSVC_POP_WARNING() __pragma(warning(pop))
#else
#define GLOG_MSVC_PUSH_DISABLE_WARNING(n)
@ -73,7 +70,7 @@
#define GLOG_USED
#endif // !defined(GLOG_USED)
#if @ac_cv_have_glog_export@
#if defined(GLOG_USE_GLOG_EXPORT)
#include "glog/export.h"
#endif
@ -84,31 +81,20 @@
// that's because they were constructed that way at ./configure time.
// Look at logging.h.in to see how they're calculated (based on your config).
#include <cstdint> // the normal place uint16_t is defined
#if @ac_cv_have_systypes_h@
#include <sys/types.h> // the normal place u_int16_t is defined
#endif
#if @ac_cv_have_libgflags@
#if defined(GLOG_USE_GFLAGS)
#include <gflags/gflags.h>
#endif
#include <atomic>
@ac_google_start_namespace@
namespace google {
typedef std::int32_t int32;
typedef std::uint32_t uint32;
typedef std::int64_t int64;
typedef std::uint64_t uint64;
#if !(@ac_cv_have_ssize_t@)
typedef ptrdiff_t ssize_t;
#endif
#if !(@ac_cv_have_mode_t@)
typedef int mode_t;
#endif
typedef double WallTime;
struct GLOG_EXPORT LogMessageTime {
@ -142,13 +128,13 @@ struct GLOG_EXPORT LogMessageTime {
struct LogMessageInfo {
explicit LogMessageInfo(const char* const severity_,
const char* const filename_,
const int& line_number_,
const int& thread_id_,
const LogMessageTime& time_):
severity(severity_), filename(filename_), line_number(line_number_),
thread_id(thread_id_), time(time_)
{}
const char* const filename_, const int& line_number_,
const int& thread_id_, const LogMessageTime& time_)
: severity(severity_),
filename(filename_),
line_number(line_number_),
thread_id(thread_id_),
time(time_) {}
const char* const severity;
const char* const filename;
@ -157,10 +143,10 @@ struct LogMessageInfo {
const LogMessageTime& time;
};
typedef void(*CustomPrefixCallback)(std::ostream& s, const LogMessageInfo& l, void* data);
@ac_google_end_namespace@
typedef void (*CustomPrefixCallback)(std::ostream& s, const LogMessageInfo& l,
void* data);
} // namespace google
// The global value of GOOGLE_STRIP_LOG. All the messages logged to
// LOG(XXX) with severity less than GOOGLE_STRIP_LOG will not be displayed.
@ -180,30 +166,48 @@ typedef void(*CustomPrefixCallback)(std::ostream& s, const LogMessageInfo& l, vo
// Giving it this information can help it optimize for the common case in
// the absence of better information (ie. -fprofile-arcs).
//
#ifndef GOOGLE_PREDICT_BRANCH_NOT_TAKEN
#if @ac_cv_have___builtin_expect@
#define GOOGLE_PREDICT_BRANCH_NOT_TAKEN(x) (__builtin_expect(x, 0))
#else
#define GOOGLE_PREDICT_BRANCH_NOT_TAKEN(x) x
#if defined(__has_builtin)
#if __has_builtin(__builtin_expect)
#define GLOG_BUILTIN_EXPECT_PRESENT
#endif
#endif
#if !defined(GLOG_BUILTIN_EXPECT_PRESENT) && defined(__GNUG__)
// __has_builtin is not available prior to GCC 10
#define GLOG_BUILTIN_EXPECT_PRESENT
#endif
#if defined(GLOG_BUILTIN_EXPECT_PRESENT)
#ifndef GOOGLE_PREDICT_BRANCH_NOT_TAKEN
#define GOOGLE_PREDICT_BRANCH_NOT_TAKEN(x) (__builtin_expect(x, 0))
#endif
#ifndef GOOGLE_PREDICT_FALSE
#if @ac_cv_have___builtin_expect@
#define GOOGLE_PREDICT_FALSE(x) (__builtin_expect(x, 0))
#else
#define GOOGLE_PREDICT_FALSE(x) x
#endif
#endif
#ifndef GOOGLE_PREDICT_TRUE
#if @ac_cv_have___builtin_expect@
#define GOOGLE_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
#else
#define GOOGLE_PREDICT_TRUE(x) x
#endif
#endif
#else
#ifndef GOOGLE_PREDICT_BRANCH_NOT_TAKEN
#define GOOGLE_PREDICT_BRANCH_NOT_TAKEN(x) x
#endif
#ifndef GOOGLE_PREDICT_TRUE
#define GOOGLE_PREDICT_FALSE(x) x
#endif
#ifndef GOOGLE_PREDICT_TRUE
#define GOOGLE_PREDICT_TRUE(x) x
#endif
#endif
#undef GLOG_BUILTIN_EXPECT_PRESENT
// Make a bunch of macros for logging. The way to log things is to stream
// things to LOG(<a particular severity level>). E.g.,
@ -393,18 +397,15 @@ typedef void(*CustomPrefixCallback)(std::ostream& s, const LogMessageInfo& l, vo
using fL##shorttype::FLAGS_##name
// bool specialization
#define DECLARE_bool(name) \
DECLARE_VARIABLE(bool, B, name, bool)
#define DECLARE_bool(name) DECLARE_VARIABLE(bool, B, name, bool)
// int32 specialization
#define DECLARE_int32(name) \
DECLARE_VARIABLE(@ac_google_namespace@::int32, I, name, int32)
#define DECLARE_int32(name) DECLARE_VARIABLE(google::int32, I, name, int32)
#if !defined(DECLARE_uint32)
// uint32 specialization
#define DECLARE_uint32(name) \
DECLARE_VARIABLE(@ac_google_namespace@::uint32, U, name, uint32)
#endif // !defined(DECLARE_uint32) && !(@ac_cv_have_libgflags@)
#define DECLARE_uint32(name) DECLARE_VARIABLE(google::uint32, U, name, uint32)
#endif // !defined(DECLARE_uint32) && !defined(GLOG_USE_GFLAGS)
// Special case for string, because we have to specify the namespace
// std::string, which doesn't play nicely with our FLAG__namespace hackery.
@ -492,43 +493,41 @@ DECLARE_string(logmailer);
// better to have compact code for these operations.
#if GOOGLE_STRIP_LOG == 0
#define COMPACT_GOOGLE_LOG_INFO @ac_google_namespace@::LogMessage( \
__FILE__, __LINE__)
#define LOG_TO_STRING_INFO(message) @ac_google_namespace@::LogMessage( \
__FILE__, __LINE__, @ac_google_namespace@::GLOG_INFO, message)
#define COMPACT_GOOGLE_LOG_INFO google::LogMessage(__FILE__, __LINE__)
#define LOG_TO_STRING_INFO(message) \
google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, message)
#else
#define COMPACT_GOOGLE_LOG_INFO @ac_google_namespace@::NullStream()
#define LOG_TO_STRING_INFO(message) @ac_google_namespace@::NullStream()
#define COMPACT_GOOGLE_LOG_INFO google::NullStream()
#define LOG_TO_STRING_INFO(message) google::NullStream()
#endif
#if GOOGLE_STRIP_LOG <= 1
#define COMPACT_GOOGLE_LOG_WARNING @ac_google_namespace@::LogMessage( \
__FILE__, __LINE__, @ac_google_namespace@::GLOG_WARNING)
#define LOG_TO_STRING_WARNING(message) @ac_google_namespace@::LogMessage( \
__FILE__, __LINE__, @ac_google_namespace@::GLOG_WARNING, message)
#define COMPACT_GOOGLE_LOG_WARNING \
google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING)
#define LOG_TO_STRING_WARNING(message) \
google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, message)
#else
#define COMPACT_GOOGLE_LOG_WARNING @ac_google_namespace@::NullStream()
#define LOG_TO_STRING_WARNING(message) @ac_google_namespace@::NullStream()
#define COMPACT_GOOGLE_LOG_WARNING google::NullStream()
#define LOG_TO_STRING_WARNING(message) google::NullStream()
#endif
#if GOOGLE_STRIP_LOG <= 2
#define COMPACT_GOOGLE_LOG_ERROR @ac_google_namespace@::LogMessage( \
__FILE__, __LINE__, @ac_google_namespace@::GLOG_ERROR)
#define LOG_TO_STRING_ERROR(message) @ac_google_namespace@::LogMessage( \
__FILE__, __LINE__, @ac_google_namespace@::GLOG_ERROR, message)
#define COMPACT_GOOGLE_LOG_ERROR \
google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR)
#define LOG_TO_STRING_ERROR(message) \
google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, message)
#else
#define COMPACT_GOOGLE_LOG_ERROR @ac_google_namespace@::NullStream()
#define LOG_TO_STRING_ERROR(message) @ac_google_namespace@::NullStream()
#define COMPACT_GOOGLE_LOG_ERROR google::NullStream()
#define LOG_TO_STRING_ERROR(message) google::NullStream()
#endif
#if GOOGLE_STRIP_LOG <= 3
#define COMPACT_GOOGLE_LOG_FATAL @ac_google_namespace@::LogMessageFatal( \
__FILE__, __LINE__)
#define LOG_TO_STRING_FATAL(message) @ac_google_namespace@::LogMessage( \
__FILE__, __LINE__, @ac_google_namespace@::GLOG_FATAL, message)
#define COMPACT_GOOGLE_LOG_FATAL google::LogMessageFatal(__FILE__, __LINE__)
#define LOG_TO_STRING_FATAL(message) \
google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, message)
#else
#define COMPACT_GOOGLE_LOG_FATAL @ac_google_namespace@::NullStreamFatal()
#define LOG_TO_STRING_FATAL(message) @ac_google_namespace@::NullStreamFatal()
#define COMPACT_GOOGLE_LOG_FATAL google::NullStreamFatal()
#define LOG_TO_STRING_FATAL(message) google::NullStreamFatal()
#endif
#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
@ -542,42 +541,45 @@ DECLARE_string(logmailer);
#if !DCHECK_IS_ON()
#define COMPACT_GOOGLE_LOG_DFATAL COMPACT_GOOGLE_LOG_ERROR
#elif GOOGLE_STRIP_LOG <= 3
#define COMPACT_GOOGLE_LOG_DFATAL @ac_google_namespace@::LogMessage( \
__FILE__, __LINE__, @ac_google_namespace@::GLOG_FATAL)
#define COMPACT_GOOGLE_LOG_DFATAL \
google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL)
#else
#define COMPACT_GOOGLE_LOG_DFATAL @ac_google_namespace@::NullStreamFatal()
#define COMPACT_GOOGLE_LOG_DFATAL google::NullStreamFatal()
#endif
#define GOOGLE_LOG_INFO(counter) @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_INFO, counter, &@ac_google_namespace@::LogMessage::SendToLog)
#define GOOGLE_LOG_INFO(counter) \
google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, \
&google::LogMessage::SendToLog)
#define SYSLOG_INFO(counter) \
@ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_INFO, counter, \
&@ac_google_namespace@::LogMessage::SendToSyslogAndLog)
google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, \
&google::LogMessage::SendToSyslogAndLog)
#define GOOGLE_LOG_WARNING(counter) \
@ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_WARNING, counter, \
&@ac_google_namespace@::LogMessage::SendToLog)
google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \
&google::LogMessage::SendToLog)
#define SYSLOG_WARNING(counter) \
@ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_WARNING, counter, \
&@ac_google_namespace@::LogMessage::SendToSyslogAndLog)
google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \
&google::LogMessage::SendToSyslogAndLog)
#define GOOGLE_LOG_ERROR(counter) \
@ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_ERROR, counter, \
&@ac_google_namespace@::LogMessage::SendToLog)
google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \
&google::LogMessage::SendToLog)
#define SYSLOG_ERROR(counter) \
@ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_ERROR, counter, \
&@ac_google_namespace@::LogMessage::SendToSyslogAndLog)
google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \
&google::LogMessage::SendToSyslogAndLog)
#define GOOGLE_LOG_FATAL(counter) \
@ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_FATAL, counter, \
&@ac_google_namespace@::LogMessage::SendToLog)
google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \
&google::LogMessage::SendToLog)
#define SYSLOG_FATAL(counter) \
@ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_FATAL, counter, \
&@ac_google_namespace@::LogMessage::SendToSyslogAndLog)
google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \
&google::LogMessage::SendToSyslogAndLog)
#define GOOGLE_LOG_DFATAL(counter) \
@ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::DFATAL_LEVEL, counter, \
&@ac_google_namespace@::LogMessage::SendToLog)
google::LogMessage(__FILE__, __LINE__, google::DFATAL_LEVEL, counter, \
&google::LogMessage::SendToLog)
#define SYSLOG_DFATAL(counter) \
@ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::DFATAL_LEVEL, counter, \
&@ac_google_namespace@::LogMessage::SendToSyslogAndLog)
google::LogMessage(__FILE__, __LINE__, google::DFATAL_LEVEL, counter, \
&google::LogMessage::SendToSyslogAndLog)
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) || defined(__CYGWIN32__)
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || \
defined(__CYGWIN__) || defined(__CYGWIN32__)
// A very useful logging macro to log windows errors:
#define LOG_SYSRESULT(result) \
if (FAILED(HRESULT_FROM_WIN32(result))) { \
@ -588,8 +590,9 @@ DECLARE_string(logmailer);
FORMAT_MESSAGE_IGNORE_INSERTS, \
0, result, 0, msg, 100, nullptr); \
if (message_length > 0) { \
@ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_ERROR, 0, \
&@ac_google_namespace@::LogMessage::SendToLog).stream() \
google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, 0, \
&google::LogMessage::SendToLog) \
.stream() \
<< reinterpret_cast<const char*>(message); \
LocalFree(message); \
} \
@ -607,7 +610,7 @@ DECLARE_string(logmailer);
#define LOG(severity) COMPACT_GOOGLE_LOG_##severity.stream()
#define SYSLOG(severity) SYSLOG_##severity(0).stream()
@ac_google_start_namespace@
namespace google {
// They need the definitions of integer types.
#include "glog/log_severity.h"
@ -652,21 +655,18 @@ class LogSink; // defined below
// LogSeverity severity;
// The cast is to disambiguate nullptr arguments.
#define LOG_TO_SINK(sink, severity) \
@ac_google_namespace@::LogMessage( \
__FILE__, __LINE__, \
@ac_google_namespace@::GLOG_ ## severity, \
static_cast<@ac_google_namespace@::LogSink*>(sink), true).stream()
google::LogMessage(__FILE__, __LINE__, google::GLOG_##severity, \
static_cast<google::LogSink*>(sink), true) \
.stream()
#define LOG_TO_SINK_BUT_NOT_TO_LOGFILE(sink, severity) \
@ac_google_namespace@::LogMessage( \
__FILE__, __LINE__, \
@ac_google_namespace@::GLOG_ ## severity, \
static_cast<@ac_google_namespace@::LogSink*>(sink), false).stream()
google::LogMessage(__FILE__, __LINE__, google::GLOG_##severity, \
static_cast<google::LogSink*>(sink), false) \
.stream()
// If a non-nullptr string pointer is given, we write this message to that string.
// We then do normal LOG(severity) logging as well.
// This is useful for capturing messages and storing them somewhere more
// specific than the global log of the process.
// Argument types:
// If a non-nullptr string pointer is given, we write this message to that
// string. We then do normal LOG(severity) logging as well. This is useful for
// capturing messages and storing them somewhere more specific than the global
// log of the process. Argument types:
// string* message;
// LogSeverity severity;
// The cast is to disambiguate nullptr arguments.
@ -684,14 +684,15 @@ class LogSink; // defined below
// vector<string> *outvec;
// The cast is to disambiguate nullptr arguments.
#define LOG_STRING(severity, outvec) \
LOG_TO_STRING_##severity(static_cast<std::vector<std::string>*>(outvec)).stream()
LOG_TO_STRING_##severity(static_cast<std::vector<std::string>*>(outvec)) \
.stream()
#define LOG_IF(severity, condition) \
static_cast<void>(0), \
!(condition) ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity)
!(condition) ? (void)0 : google::LogMessageVoidify() & LOG(severity)
#define SYSLOG_IF(severity, condition) \
static_cast<void>(0), \
!(condition) ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & SYSLOG(severity)
!(condition) ? (void)0 : google::LogMessageVoidify() & SYSLOG(severity)
#define LOG_ASSERT(condition) \
LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition
@ -722,7 +723,9 @@ struct CheckOpString {
// integrals declared in classes and not defined to be used as arguments to
// CHECK* macros. It's not encouraged though.
template <class T>
inline const T& GetReferenceableValue(const T& t) { return t; }
inline const T& GetReferenceableValue(const T& t) {
return t;
}
inline char GetReferenceableValue(char t) { return t; }
inline unsigned char GetReferenceableValue(unsigned char t) { return t; }
inline signed char GetReferenceableValue(signed char t) { return t; }
@ -740,17 +743,17 @@ inline unsigned long long GetReferenceableValue(unsigned long long t) {
// This is a dummy class to define the following operator.
struct DummyClassToDefineOperator {};
@ac_google_end_namespace@
} // namespace google
// Define global operator<< to declare using ::operator<<.
// This declaration will allow use to use CHECK macros for user
// defined classes which have operator<< (e.g., stl_logging.h).
inline std::ostream& operator<<(
std::ostream& out, const google::DummyClassToDefineOperator&) {
inline std::ostream& operator<<(std::ostream& out,
const google::DummyClassToDefineOperator&) {
return out;
}
@ac_google_start_namespace@
namespace google {
// This formats a value for a failing CHECK_XX statement. Ordinarily,
// it uses the definition for operator<<, with a few special cases below.
@ -761,12 +764,13 @@ inline void MakeCheckOpValueString(std::ostream* os, const T& v) {
// Overrides for char types provide readable values for unprintable
// characters.
template <> GLOG_EXPORT
void MakeCheckOpValueString(std::ostream* os, const char& v);
template <> GLOG_EXPORT
void MakeCheckOpValueString(std::ostream* os, const signed char& v);
template <> GLOG_EXPORT
void MakeCheckOpValueString(std::ostream* os, const unsigned char& v);
template <>
GLOG_EXPORT void MakeCheckOpValueString(std::ostream* os, const char& v);
template <>
GLOG_EXPORT void MakeCheckOpValueString(std::ostream* os, const signed char& v);
template <>
GLOG_EXPORT void MakeCheckOpValueString(std::ostream* os,
const unsigned char& v);
// Provide printable value for nullptr_t
template <>
@ -776,7 +780,12 @@ GLOG_EXPORT void MakeCheckOpValueString(std::ostream* os,
// Build the error message string. Specify no inlining for code size.
template <typename T1, typename T2>
std::string* MakeCheckOpString(const T1& v1, const T2& v2, const char* exprtext)
@ac_cv___attribute___noinline@;
#if defined(__has_attribute)
#if __has_attribute(used)
__attribute__((noinline))
#endif
#endif
;
namespace base {
namespace internal {
@ -814,7 +823,8 @@ class GLOG_EXPORT CheckOpMessageBuilder {
} // namespace base
template <typename T1, typename T2>
std::string* MakeCheckOpString(const T1& v1, const T2& v2, const char* exprtext) {
std::string* MakeCheckOpString(const T1& v1, const T2& v2,
const char* exprtext) {
base::CheckOpMessageBuilder comb(exprtext);
MakeCheckOpValueString(comb.ForVar1(), v1);
MakeCheckOpValueString(comb.ForVar2(), v2);
@ -829,8 +839,10 @@ std::string* MakeCheckOpString(const T1& v1, const T2& v2, const char* exprtext)
template <typename T1, typename T2> \
inline std::string* name##Impl(const T1& v1, const T2& v2, \
const char* exprtext) { \
if (GOOGLE_PREDICT_TRUE(v1 op v2)) return nullptr; \
else return MakeCheckOpString(v1, v2, exprtext); \
if (GOOGLE_PREDICT_TRUE(v1 op v2)) \
return nullptr; \
else \
return MakeCheckOpString(v1, v2, exprtext); \
} \
inline std::string* name##Impl(int v1, int v2, const char* exprtext) { \
return name##Impl<int, int>(v1, v2, exprtext); \
@ -840,7 +852,8 @@ std::string* MakeCheckOpString(const T1& v1, const T2& v2, const char* exprtext)
// base/logging.h provides its own #defines for the simpler names EQ, NE, etc.
// This happens if, for example, those are used as token names in a
// yacc grammar.
DEFINE_CHECK_OP_IMPL(Check_EQ, ==) // Compilation error with CHECK_EQ(nullptr, x)?
DEFINE_CHECK_OP_IMPL(Check_EQ,
==) // Compilation error with CHECK_EQ(nullptr, x)?
DEFINE_CHECK_OP_IMPL(Check_NE, !=) // Use CHECK(x == nullptr) instead.
DEFINE_CHECK_OP_IMPL(Check_LE, <=)
DEFINE_CHECK_OP_IMPL(Check_LT, <)
@ -866,31 +879,26 @@ DEFINE_CHECK_OP_IMPL(Check_GT, > )
// in the macro.
typedef std::string _Check_string;
#define CHECK_OP_LOG(name, op, val1, val2, log) \
while (@ac_google_namespace@::_Check_string* _result = \
@ac_google_namespace@::Check##name##Impl( \
@ac_google_namespace@::GetReferenceableValue(val1), \
@ac_google_namespace@::GetReferenceableValue(val2), \
#val1 " " #op " " #val2)) \
log(__FILE__, __LINE__, \
@ac_google_namespace@::CheckOpString(_result)).stream()
while (google::_Check_string* _result = google::Check##name##Impl( \
google::GetReferenceableValue(val1), \
google::GetReferenceableValue(val2), #val1 " " #op " " #val2)) \
log(__FILE__, __LINE__, google::CheckOpString(_result)).stream()
#else
// In optimized mode, use CheckOpString to hint to compiler that
// the while condition is unlikely.
#define CHECK_OP_LOG(name, op, val1, val2, log) \
while (@ac_google_namespace@::CheckOpString _result = \
@ac_google_namespace@::Check##name##Impl( \
@ac_google_namespace@::GetReferenceableValue(val1), \
@ac_google_namespace@::GetReferenceableValue(val2), \
#val1 " " #op " " #val2)) \
while (google::CheckOpString _result = google::Check##name##Impl( \
google::GetReferenceableValue(val1), \
google::GetReferenceableValue(val2), #val1 " " #op " " #val2)) \
log(__FILE__, __LINE__, _result).stream()
#endif // STATIC_ANALYSIS, DCHECK_IS_ON()
#if GOOGLE_STRIP_LOG <= 3
#define CHECK_OP(name, op, val1, val2) \
CHECK_OP_LOG(name, op, val1, val2, @ac_google_namespace@::LogMessageFatal)
CHECK_OP_LOG(name, op, val1, val2, google::LogMessageFatal)
#else
#define CHECK_OP(name, op, val1, val2) \
CHECK_OP_LOG(name, op, val1, val2, @ac_google_namespace@::NullStreamFatal)
CHECK_OP_LOG(name, op, val1, val2, google::NullStreamFatal)
#endif // STRIP_LOG <= 3
// Equality/Inequality checks - compare two values, and log a FATAL message
@ -908,8 +916,8 @@ typedef std::string _Check_string;
// CHECK_EQ(string("abc")[1], 'b');
//
// WARNING: These don't compile correctly if one of the arguments is a pointer
// and the other is nullptr. To work around this, simply static_cast nullptr to the
// type of the desired pointer.
// and the other is nullptr. To work around this, simply static_cast nullptr to
// the type of the desired pointer.
#define CHECK_EQ(val1, val2) CHECK_OP(_EQ, ==, val1, val2)
#define CHECK_NE(val1, val2) CHECK_OP(_NE, !=, val1, val2)
@ -922,7 +930,8 @@ typedef std::string _Check_string;
// initializer lists.
#define CHECK_NOTNULL(val) \
@ac_google_namespace@::CheckNotNull(__FILE__, __LINE__, "'" #val "' Must be non nullptr", (val))
google::CheckNotNull(__FILE__, __LINE__, "'" #val "' Must be non nullptr", \
(val))
// Helper functions for string comparisons.
// To avoid bloat, the definitions are in logging.cc.
@ -938,12 +947,10 @@ DECLARE_CHECK_STROP_IMPL(strcasecmp, false)
// Helper macro for string comparisons.
// Don't use this macro directly in your code, use CHECK_STREQ et al below.
#define CHECK_STROP(func, op, expected, s1, s2) \
while (@ac_google_namespace@::CheckOpString _result = \
@ac_google_namespace@::Check##func##expected##Impl((s1), (s2), \
#s1 " " #op " " #s2)) \
while (google::CheckOpString _result = google::Check##func##expected##Impl( \
(s1), (s2), #s1 " " #op " " #s2)) \
LOG(FATAL) << *_result.str_
// String (char*) equality/inequality checks.
// CASE versions are case-insensitive.
//
@ -980,13 +987,12 @@ DECLARE_CHECK_STROP_IMPL(strcasecmp, false)
#define PLOG(severity) GOOGLE_PLOG(severity, 0).stream()
#define GOOGLE_PLOG(severity, counter) \
@ac_google_namespace@::ErrnoLogMessage( \
__FILE__, __LINE__, @ac_google_namespace@::GLOG_ ## severity, counter, \
&@ac_google_namespace@::LogMessage::SendToLog)
google::ErrnoLogMessage(__FILE__, __LINE__, google::GLOG_##severity, \
counter, &google::LogMessage::SendToLog)
#define PLOG_IF(severity, condition) \
static_cast<void>(0), \
!(condition) ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & PLOG(severity)
!(condition) ? (void)0 : google::LogMessageVoidify() & PLOG(severity)
// A CHECK() macro that postpends errno if the condition is false. E.g.
//
@ -1027,7 +1033,8 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \
#endif
#endif
#if !defined(GLOG_SANITIZE_THREAD) && defined(__SANITIZE_THREAD__) && __SANITIZE_THREAD__
#if !defined(GLOG_SANITIZE_THREAD) && defined(__SANITIZE_THREAD__) && \
__SANITIZE_THREAD__
#define GLOG_SANITIZE_THREAD 1
#endif
@ -1042,11 +1049,8 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \
// We need to identify the static variables as "benign" races
// to avoid noisy reports from TSAN.
extern "C" void AnnotateBenignRaceSized(
const char *file,
int line,
const volatile void *mem,
size_t size,
extern "C" void AnnotateBenignRaceSized(const char* file, int line,
const volatile void* mem, size_t size,
const char* description);
namespace google {
@ -1056,13 +1060,11 @@ namespace google {
constexpr std::chrono::nanoseconds LOG_TIME_PERIOD = \
std::chrono::duration_cast<std::chrono::nanoseconds>( \
std::chrono::duration<double>(seconds)); \
static std::atomic<@ac_google_namespace@::int64> LOG_PREVIOUS_TIME_RAW; \
GLOG_IFDEF_THREAD_SANITIZER( \
AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_TIME_PERIOD, \
sizeof(@ac_google_namespace@::int64), "")); \
GLOG_IFDEF_THREAD_SANITIZER( \
AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_PREVIOUS_TIME_RAW, \
sizeof(@ac_google_namespace@::int64), "")); \
static std::atomic<google::int64> LOG_PREVIOUS_TIME_RAW; \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized( \
__FILE__, __LINE__, &LOG_TIME_PERIOD, sizeof(google::int64), "")); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized( \
__FILE__, __LINE__, &LOG_PREVIOUS_TIME_RAW, sizeof(google::int64), "")); \
const auto LOG_CURRENT_TIME = \
std::chrono::duration_cast<std::chrono::nanoseconds>( \
std::chrono::steady_clock::now().time_since_epoch()); \
@ -1076,57 +1078,60 @@ namespace google {
.count(), \
std::memory_order_relaxed); \
if (LOG_TIME_DELTA > LOG_TIME_PERIOD) \
@ac_google_namespace@::LogMessage( \
__FILE__, __LINE__, @ac_google_namespace@::GLOG_##severity) \
.stream()
google::LogMessage(__FILE__, __LINE__, google::GLOG_##severity).stream()
#define SOME_KIND_OF_LOG_EVERY_N(severity, n, what_to_do) \
static std::atomic<int> LOG_OCCURRENCES(0), LOG_OCCURRENCES_MOD_N(0); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES_MOD_N, sizeof(int), "")); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized( \
__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized( \
__FILE__, __LINE__, &LOG_OCCURRENCES_MOD_N, sizeof(int), "")); \
++LOG_OCCURRENCES; \
if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \
if (LOG_OCCURRENCES_MOD_N == 1) \
@ac_google_namespace@::LogMessage( \
__FILE__, __LINE__, @ac_google_namespace@::GLOG_ ## severity, LOG_OCCURRENCES, \
&what_to_do).stream()
google::LogMessage(__FILE__, __LINE__, google::GLOG_##severity, \
LOG_OCCURRENCES, &what_to_do) \
.stream()
#define SOME_KIND_OF_LOG_IF_EVERY_N(severity, condition, n, what_to_do) \
static std::atomic<int> LOG_OCCURRENCES(0), LOG_OCCURRENCES_MOD_N(0); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES_MOD_N, sizeof(int), "")); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized( \
__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized( \
__FILE__, __LINE__, &LOG_OCCURRENCES_MOD_N, sizeof(int), "")); \
++LOG_OCCURRENCES; \
if ((condition) && \
((LOG_OCCURRENCES_MOD_N = (LOG_OCCURRENCES_MOD_N + 1) % n) == (1 % n))) \
@ac_google_namespace@::LogMessage( \
__FILE__, __LINE__, @ac_google_namespace@::GLOG_ ## severity, LOG_OCCURRENCES, \
&what_to_do).stream()
google::LogMessage(__FILE__, __LINE__, google::GLOG_##severity, \
LOG_OCCURRENCES, &what_to_do) \
.stream()
#define SOME_KIND_OF_PLOG_EVERY_N(severity, n, what_to_do) \
static std::atomic<int> LOG_OCCURRENCES(0), LOG_OCCURRENCES_MOD_N(0); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES_MOD_N, sizeof(int), "")); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized( \
__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized( \
__FILE__, __LINE__, &LOG_OCCURRENCES_MOD_N, sizeof(int), "")); \
++LOG_OCCURRENCES; \
if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \
if (LOG_OCCURRENCES_MOD_N == 1) \
@ac_google_namespace@::ErrnoLogMessage( \
__FILE__, __LINE__, @ac_google_namespace@::GLOG_ ## severity, LOG_OCCURRENCES, \
&what_to_do).stream()
google::ErrnoLogMessage(__FILE__, __LINE__, google::GLOG_##severity, \
LOG_OCCURRENCES, &what_to_do) \
.stream()
#define SOME_KIND_OF_LOG_FIRST_N(severity, n, what_to_do) \
static std::atomic<int> LOG_OCCURRENCES(0); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized( \
__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \
if (LOG_OCCURRENCES <= n) ++LOG_OCCURRENCES; \
if (LOG_OCCURRENCES <= n) \
++LOG_OCCURRENCES; \
if (LOG_OCCURRENCES <= n) \
@ac_google_namespace@::LogMessage( \
__FILE__, __LINE__, @ac_google_namespace@::GLOG_ ## severity, LOG_OCCURRENCES, \
&what_to_do).stream()
google::LogMessage(__FILE__, __LINE__, google::GLOG_##severity, \
LOG_OCCURRENCES, &what_to_do) \
.stream()
namespace glog_internal_namespace_ {
template <bool>
struct CompileAssert {
};
struct CompileAssert {};
struct CrashReason;
// Returns true if FailureSignalHandler is installed.
@ -1135,21 +1140,23 @@ GLOG_EXPORT bool IsFailureSignalHandlerInstalled();
} // namespace glog_internal_namespace_
#define LOG_EVERY_N(severity, n) \
SOME_KIND_OF_LOG_EVERY_N(severity, (n), @ac_google_namespace@::LogMessage::SendToLog)
SOME_KIND_OF_LOG_EVERY_N(severity, (n), google::LogMessage::SendToLog)
#define LOG_EVERY_T(severity, T) SOME_KIND_OF_LOG_EVERY_T(severity, (T))
#define SYSLOG_EVERY_N(severity, n) \
SOME_KIND_OF_LOG_EVERY_N(severity, (n), @ac_google_namespace@::LogMessage::SendToSyslogAndLog)
SOME_KIND_OF_LOG_EVERY_N(severity, (n), \
google::LogMessage::SendToSyslogAndLog)
#define PLOG_EVERY_N(severity, n) \
SOME_KIND_OF_PLOG_EVERY_N(severity, (n), @ac_google_namespace@::LogMessage::SendToLog)
SOME_KIND_OF_PLOG_EVERY_N(severity, (n), google::LogMessage::SendToLog)
#define LOG_FIRST_N(severity, n) \
SOME_KIND_OF_LOG_FIRST_N(severity, (n), @ac_google_namespace@::LogMessage::SendToLog)
SOME_KIND_OF_LOG_FIRST_N(severity, (n), google::LogMessage::SendToLog)
#define LOG_IF_EVERY_N(severity, condition, n) \
SOME_KIND_OF_LOG_IF_EVERY_N(severity, (condition), (n), @ac_google_namespace@::LogMessage::SendToLog)
SOME_KIND_OF_LOG_IF_EVERY_N(severity, (condition), (n), \
google::LogMessage::SendToLog)
// We want the special COUNTER value available for LOG_EVERY_X()'ed messages
enum PRIVATE_Counter { COUNTER };
@ -1169,7 +1176,8 @@ const LogSeverity GLOG_0 = GLOG_ERROR;
// GLOG_NO_ABBREVIATED_SEVERITIES nor WIN32_LEAN_AND_MEAN.
// For this case, we cannot detect if ERROR is defined before users
// actually use ERROR. Let's make an undefined symbol to warn users.
# define GLOG_ERROR_MSG ERROR_macro_is_defined_Define_GLOG_NO_ABBREVIATED_SEVERITIES_before_including_logging_h_See_the_document_for_detail
#define GLOG_ERROR_MSG \
ERROR_macro_is_defined_Define_GLOG_NO_ABBREVIATED_SEVERITIES_before_including_logging_h_See_the_document_for_detail
#define COMPACT_GOOGLE_LOG_0 GLOG_ERROR_MSG
#define SYSLOG_0 GLOG_ERROR_MSG
#define LOG_TO_STRING_0 GLOG_ERROR_MSG
@ -1208,72 +1216,66 @@ const LogSeverity GLOG_0 = GLOG_ERROR;
#define DLOG(severity) \
static_cast<void>(0), \
true ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity)
true ? (void)0 : google::LogMessageVoidify() & LOG(severity)
#define DVLOG(verboselevel) \
static_cast<void>(0), \
(true || !VLOG_IS_ON(verboselevel)) ? \
(void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(INFO)
static_cast<void>(0), (true || !VLOG_IS_ON(verboselevel)) \
? (void)0 \
: google::LogMessageVoidify() & LOG(INFO)
#define DLOG_IF(severity, condition) \
static_cast<void>(0), \
(true || !(condition)) ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity)
static_cast<void>(0), (true || !(condition)) \
? (void)0 \
: google::LogMessageVoidify() & LOG(severity)
#define DLOG_EVERY_N(severity, n) \
static_cast<void>(0), \
true ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity)
true ? (void)0 : google::LogMessageVoidify() & LOG(severity)
#define DLOG_IF_EVERY_N(severity, condition, n) \
static_cast<void>(0), \
(true || !(condition))? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity)
static_cast<void>(0), (true || !(condition)) \
? (void)0 \
: google::LogMessageVoidify() & LOG(severity)
#define DLOG_FIRST_N(severity, n) \
static_cast<void>(0), \
true ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity)
true ? (void)0 : google::LogMessageVoidify() & LOG(severity)
#define DLOG_EVERY_T(severity, T) \
static_cast<void>(0), \
true ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity)
true ? (void)0 : google::LogMessageVoidify() & LOG(severity)
#define DLOG_ASSERT(condition) \
static_cast<void>(0), \
true ? (void) 0 : LOG_ASSERT(condition)
static_cast<void>(0), true ? (void)0 : LOG_ASSERT(condition)
// MSVC warning C4127: conditional expression is constant
#define DCHECK(condition) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \
GLOG_MSVC_POP_WARNING() CHECK(condition)
while (false) GLOG_MSVC_POP_WARNING() CHECK(condition)
#define DCHECK_EQ(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \
GLOG_MSVC_POP_WARNING() CHECK_EQ(val1, val2)
while (false) GLOG_MSVC_POP_WARNING() CHECK_EQ(val1, val2)
#define DCHECK_NE(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \
GLOG_MSVC_POP_WARNING() CHECK_NE(val1, val2)
while (false) GLOG_MSVC_POP_WARNING() CHECK_NE(val1, val2)
#define DCHECK_LE(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \
GLOG_MSVC_POP_WARNING() CHECK_LE(val1, val2)
while (false) GLOG_MSVC_POP_WARNING() CHECK_LE(val1, val2)
#define DCHECK_LT(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \
GLOG_MSVC_POP_WARNING() CHECK_LT(val1, val2)
while (false) GLOG_MSVC_POP_WARNING() CHECK_LT(val1, val2)
#define DCHECK_GE(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \
GLOG_MSVC_POP_WARNING() CHECK_GE(val1, val2)
while (false) GLOG_MSVC_POP_WARNING() CHECK_GE(val1, val2)
#define DCHECK_GT(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \
GLOG_MSVC_POP_WARNING() CHECK_GT(val1, val2)
while (false) GLOG_MSVC_POP_WARNING() CHECK_GT(val1, val2)
// You may see warnings in release mode if you don't use the return
// value of DCHECK_NOTNULL. Please just use DCHECK for such cases.
@ -1281,23 +1283,19 @@ const LogSeverity GLOG_0 = GLOG_ERROR;
#define DCHECK_STREQ(str1, str2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \
GLOG_MSVC_POP_WARNING() CHECK_STREQ(str1, str2)
while (false) GLOG_MSVC_POP_WARNING() CHECK_STREQ(str1, str2)
#define DCHECK_STRCASEEQ(str1, str2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \
GLOG_MSVC_POP_WARNING() CHECK_STRCASEEQ(str1, str2)
while (false) GLOG_MSVC_POP_WARNING() CHECK_STRCASEEQ(str1, str2)
#define DCHECK_STRNE(str1, str2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \
GLOG_MSVC_POP_WARNING() CHECK_STRNE(str1, str2)
while (false) GLOG_MSVC_POP_WARNING() CHECK_STRNE(str1, str2)
#define DCHECK_STRCASENE(str1, str2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \
GLOG_MSVC_POP_WARNING() CHECK_STRCASENE(str1, str2)
while (false) GLOG_MSVC_POP_WARNING() CHECK_STRCASENE(str1, str2)
#endif // DCHECK_IS_ON()
@ -1322,14 +1320,10 @@ namespace base_logging {
class GLOG_EXPORT LogStreamBuf : public std::streambuf {
public:
// REQUIREMENTS: "len" must be >= 2 to account for the '\n' and '\0'.
LogStreamBuf(char *buf, int len) {
setp(buf, buf + len - 2);
}
LogStreamBuf(char* buf, int len) { setp(buf, buf + len - 2); }
// This effectively ignores overflow.
int_type overflow(int_type ch) {
return ch;
}
int_type overflow(int_type ch) { return ch; }
// Legacy public ostrstream method.
size_t pcount() const { return static_cast<size_t>(pptr() - pbase()); }
@ -1537,7 +1531,8 @@ inline void LogAtLevel(int const severity, std::string const &msg) {
// version since there are two advantages: 1. this version outputs the
// file name and the line number where this macro is put like other
// LOG macros, 2. this macro can be used as C++ stream.
#define LOG_AT_LEVEL(severity) @ac_google_namespace@::LogMessage(__FILE__, __LINE__, severity).stream()
#define LOG_AT_LEVEL(severity) \
google::LogMessage(__FILE__, __LINE__, severity).stream()
// Helper for CHECK_NOTNULL().
//
@ -1558,9 +1553,7 @@ T CheckNotNull(const char* file, int line, const char* names, T&& t) {
// Allow folks to put a counter in the LOG_EVERY_X()'ed messages. This
// only works if ostream is a LogStream. If the ostream is not a
// LogStream you'll get an assert saying as much at runtime.
GLOG_EXPORT std::ostream& operator<<(std::ostream &os,
const PRIVATE_Counter&);
GLOG_EXPORT std::ostream& operator<<(std::ostream& os, const PRIVATE_Counter&);
// Derived class for PLOG*() above.
class GLOG_EXPORT ErrnoLogMessage : public LogMessage {
@ -1576,7 +1569,6 @@ class GLOG_EXPORT ErrnoLogMessage : public LogMessage {
void operator=(const ErrnoLogMessage&);
};
// This class is used to explicitly ignore values in the conditional
// logging macros. This avoids compiler warnings like "value computed
// is not used" and "statement has no effect".
@ -1589,7 +1581,6 @@ class GLOG_EXPORT LogMessageVoidify {
void operator&(std::ostream&) {}
};
// Flushes all log files that contains messages that are at least of
// the specified severity level. Thread-safe.
GLOG_EXPORT void FlushLogFiles(LogSeverity min_severity);
@ -1670,8 +1661,7 @@ GLOG_EXPORT void RemoveLogSink(LogSink *destination);
// often used to append the port we're listening on to the logfile
// name. Thread-safe.
//
GLOG_EXPORT void SetLogFilenameExtension(
const char* filename_extension);
GLOG_EXPORT void SetLogFilenameExtension(const char* filename_extension);
//
// Make it so that all log messages of at least a particular severity
@ -1709,8 +1699,7 @@ void TestOnly_ClearLoggingDirectoriesList();
// Returns a set of existing temporary directories, which will be a
// subset of the directories returned by GetLoggingDirectories().
// Thread-safe.
GLOG_EXPORT void GetExistingTempDirectories(
std::vector<std::string>* list);
GLOG_EXPORT void GetExistingTempDirectories(std::vector<std::string>* list);
// Print any fatal message again -- useful to call from signal handler
// so that the last thing in the output is the fatal message.
@ -1760,9 +1749,7 @@ class GLOG_EXPORT Logger {
// appropriate by the higher level logging facility. For example,
// textual log messages already contain timestamps, and the
// file:linenumber header.
virtual void Write(bool force_flush,
time_t timestamp,
const char* message,
virtual void Write(bool force_flush, time_t timestamp, const char* message,
size_t message_len) = 0;
// Flush any buffered messages
@ -1784,7 +1771,7 @@ extern GLOG_EXPORT Logger* GetLogger(LogSeverity level);
// be deleted by the caller. Thread-safe.
extern GLOG_EXPORT void SetLogger(LogSeverity level, Logger* logger);
}
} // namespace base
// glibc has traditionally implemented two incompatible versions of
// strerror_r(). There is a poorly defined convention for picking the
@ -1829,7 +1816,9 @@ class GLOG_EXPORT NullStream : public LogMessage::LogStream {
// converted to LogStream and the message will be computed and then
// quietly discarded.
template <class T>
inline NullStream& operator<<(NullStream &str, const T &) { return str; }
inline NullStream& operator<<(NullStream& str, const T&) {
return str;
}
// Similar to NullStream, but aborts the program (without stack
// trace), like LogMessageFatal.
@ -1863,10 +1852,10 @@ GLOG_EXPORT void InstallFailureSignalHandler();
// is the pointer to the beginning of a message to be written, and "size"
// is the size of the message. You should not expect the data is
// terminated with '\0'.
GLOG_EXPORT void InstallFailureWriter(
void (*writer)(const char* data, size_t size));
GLOG_EXPORT void InstallFailureWriter(void (*writer)(const char* data,
size_t size));
@ac_google_end_namespace@
} // namespace google
#pragma pop_macro("DECLARE_VARIABLE")
#pragma pop_macro("DECLARE_bool")

View File

@ -38,7 +38,7 @@
#include <ctime>
@ac_google_start_namespace@
namespace google {
#include "glog/log_severity.h"
#include "glog/logging.h"
#include "glog/vlog_is_on.h"
@ -64,7 +64,7 @@
// I20200821 211317 file.cc:142] RAW: status is 20
#define RAW_LOG(severity, ...) \
do { \
switch (@ac_google_namespace@::GLOG_ ## severity) { \
switch (google::GLOG_##severity) { \
case 0: \
RAW_LOG_INFO(__VA_ARGS__); \
break; \
@ -96,33 +96,33 @@
#endif // STRIP_LOG == 0
#if !defined(STRIP_LOG) || STRIP_LOG == 0
#define RAW_LOG_INFO(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_INFO, \
__FILE__, __LINE__, __VA_ARGS__)
#define RAW_LOG_INFO(...) \
google::RawLog__(google::GLOG_INFO, __FILE__, __LINE__, __VA_ARGS__)
#else
#define RAW_LOG_INFO(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
#define RAW_LOG_INFO(...) google::RawLogStub__(0, __VA_ARGS__)
#endif // STRIP_LOG == 0
#if !defined(STRIP_LOG) || STRIP_LOG <= 1
#define RAW_LOG_WARNING(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_WARNING, \
__FILE__, __LINE__, __VA_ARGS__)
#define RAW_LOG_WARNING(...) \
google::RawLog__(google::GLOG_WARNING, __FILE__, __LINE__, __VA_ARGS__)
#else
#define RAW_LOG_WARNING(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
#define RAW_LOG_WARNING(...) google::RawLogStub__(0, __VA_ARGS__)
#endif // STRIP_LOG <= 1
#if !defined(STRIP_LOG) || STRIP_LOG <= 2
#define RAW_LOG_ERROR(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_ERROR, \
__FILE__, __LINE__, __VA_ARGS__)
#define RAW_LOG_ERROR(...) \
google::RawLog__(google::GLOG_ERROR, __FILE__, __LINE__, __VA_ARGS__)
#else
#define RAW_LOG_ERROR(...) @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__)
#define RAW_LOG_ERROR(...) google::RawLogStub__(0, __VA_ARGS__)
#endif // STRIP_LOG <= 2
#if !defined(STRIP_LOG) || STRIP_LOG <= 3
#define RAW_LOG_FATAL(...) @ac_google_namespace@::RawLog__(@ac_google_namespace@::GLOG_FATAL, \
__FILE__, __LINE__, __VA_ARGS__)
#define RAW_LOG_FATAL(...) \
google::RawLog__(google::GLOG_FATAL, __FILE__, __LINE__, __VA_ARGS__)
#else
#define RAW_LOG_FATAL(...) \
do { \
@ac_google_namespace@::RawLogStub__(0, __VA_ARGS__); \
google::RawLogStub__(0, __VA_ARGS__); \
exit(EXIT_FAILURE); \
} while (0)
#endif // STRIP_LOG <= 3
@ -148,11 +148,9 @@
#else // NDEBUG
#define RAW_DLOG(severity, ...) \
while (false) \
RAW_LOG(severity, __VA_ARGS__)
while (false) RAW_LOG(severity, __VA_ARGS__)
#define RAW_DCHECK(condition, message) \
while (false) \
RAW_CHECK(condition, message)
while (false) RAW_CHECK(condition, message)
#endif // NDEBUG
@ -162,8 +160,7 @@
// Stub log function used to work around for unused variable warnings when
// building with STRIP_LOG > 0.
static inline void RawLogStub__(int /* ignored */, ...) {
}
static inline void RawLogStub__(int /* ignored */, ...) {}
// Helper function to implement RAW_LOG and RAW_VLOG
// Logs format... at "severity" level, reporting it
@ -171,8 +168,12 @@ static inline void RawLogStub__(int /* ignored */, ...) {
// This does not allocate memory or acquire locks.
GLOG_EXPORT void RawLog__(LogSeverity severity, const char* file, int line,
const char* format, ...)
@ac_cv___attribute___printf_4_5@;
@ac_google_end_namespace@
#if defined(__has_attribute)
#if __has_attribute(used)
__attribute__((__format__(__printf__, 4, 5)))
#endif
#endif
;
} // namespace google
#endif // GLOG_RAW_LOGGING_H

View File

@ -55,35 +55,35 @@
template <class First, class Second>
std::ostream& operator<<(std::ostream& out, const std::pair<First, Second>& p);
@ac_google_start_namespace@
namespace google {
template <class Iter>
void PrintSequence(std::ostream& out, Iter begin, Iter end);
@ac_google_end_namespace@
}
#define OUTPUT_TWO_ARG_CONTAINER(Sequence) \
template <class T1, class T2> \
inline std::ostream& operator<<(std::ostream& out, \
const Sequence<T1, T2>& seq) { \
@ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \
google::PrintSequence(out, seq.begin(), seq.end()); \
return out; \
}
OUTPUT_TWO_ARG_CONTAINER(std::vector) OUTPUT_TWO_ARG_CONTAINER(std::deque)
OUTPUT_TWO_ARG_CONTAINER(std::vector)
OUTPUT_TWO_ARG_CONTAINER(std::deque)
OUTPUT_TWO_ARG_CONTAINER(std::list)
#undef OUTPUT_TWO_ARG_CONTAINER
#define OUTPUT_THREE_ARG_CONTAINER(Sequence) \
template <class T1, class T2, class T3> \
inline std::ostream& operator<<(std::ostream& out, \
const Sequence<T1, T2, T3>& seq) { \
@ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \
google::PrintSequence(out, seq.begin(), seq.end()); \
return out; \
}
OUTPUT_THREE_ARG_CONTAINER(std::set) OUTPUT_THREE_ARG_CONTAINER(
std::multiset)
OUTPUT_THREE_ARG_CONTAINER(std::set)
OUTPUT_THREE_ARG_CONTAINER(std::multiset)
#undef OUTPUT_THREE_ARG_CONTAINER
@ -91,21 +91,21 @@ inline std::ostream& operator<<(std::ostream& out, \
template <class T1, class T2, class T3, class T4> \
inline std::ostream& operator<<(std::ostream& out, \
const Sequence<T1, T2, T3, T4>& seq) { \
@ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \
google::PrintSequence(out, seq.begin(), seq.end()); \
return out; \
}
OUTPUT_FOUR_ARG_CONTAINER(std::map) OUTPUT_FOUR_ARG_CONTAINER(
std::multimap) OUTPUT_FOUR_ARG_CONTAINER(std::unordered_set)
OUTPUT_FOUR_ARG_CONTAINER(std::map)
OUTPUT_FOUR_ARG_CONTAINER(std::multimap)
OUTPUT_FOUR_ARG_CONTAINER(std::unordered_set)
OUTPUT_FOUR_ARG_CONTAINER(std::unordered_multiset)
#undef OUTPUT_FOUR_ARG_CONTAINER
#define OUTPUT_FIVE_ARG_CONTAINER(Sequence) \
template <class T1, class T2, class T3, class T4, class T5> \
inline std::ostream& operator<<(std::ostream& out, \
const Sequence<T1, T2, T3, T4, T5>& seq) { \
@ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \
google::PrintSequence(out, seq.begin(), seq.end()); \
return out; \
}
@ -115,14 +115,13 @@ inline std::ostream& operator<<(std::ostream& out, \
#undef OUTPUT_FIVE_ARG_CONTAINER
template <class First, class Second>
inline std::ostream& operator<<(
std::ostream& out,
inline std::ostream& operator<<(std::ostream& out,
const std::pair<First, Second>& p) {
out << '(' << p.first << ", " << p.second << ')';
return out;
}
@ac_google_start_namespace@
namespace google {
template <class Iter>
inline void PrintSequence(std::ostream& out, Iter begin, Iter end) {
@ -136,7 +135,7 @@ inline void PrintSequence(std::ostream& out, Iter begin, Iter end) {
}
}
@ac_google_end_namespace@
} // namespace google
// Note that this is technically undefined behavior! We are adding things into
// the std namespace for a reason though -- we are providing new operations on
@ -162,6 +161,8 @@ inline void PrintSequence(std::ostream& out, Iter begin, Iter end) {
// move all of the *definitions* into namespace std, bet we need to ensure no
// one references them first. This lets us take that step. We cannot define them
// in both because that would create ambiguous overloads when both are found.
namespace std { using ::operator<<; }
namespace std {
using ::operator<<;
}
#endif // UTIL_GTL_STL_LOGGING_INL_H_

View File

@ -73,13 +73,14 @@
// matching the current source file that represents results of
// parsing of --vmodule flag and/or SetVLOGLevel calls.
#define VLOG_IS_ON(verboselevel) \
__extension__ \
({ static @ac_google_namespace@::SiteFlag vlocal__ = {nullptr, nullptr, 0, nullptr}; \
GLOG_IFDEF_THREAD_SANITIZER( \
AnnotateBenignRaceSized(__FILE__, __LINE__, &vlocal__, sizeof(@ac_google_namespace@::SiteFlag), "")); \
@ac_google_namespace@::int32 verbose_level__ = (verboselevel); \
(vlocal__.level == nullptr ? @ac_google_namespace@::InitVLOG3__(&vlocal__, &FLAGS_v, \
__FILE__, verbose_level__) : *vlocal__.level >= verbose_level__); \
__extension__({ \
static google::SiteFlag vlocal__ = {nullptr, nullptr, 0, nullptr}; \
GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized( \
__FILE__, __LINE__, &vlocal__, sizeof(google::SiteFlag), "")); \
google::int32 verbose_level__ = (verboselevel); \
(vlocal__.level == nullptr \
? google::InitVLOG3__(&vlocal__, &FLAGS_v, __FILE__, verbose_level__) \
: *vlocal__.level >= verbose_level__); \
})
#else
// GNU extensions not available, so we do not support --vmodule.
@ -100,7 +101,7 @@ extern GLOG_EXPORT int SetVLOGLevel(const char* module_pattern, int log_level);
// Various declarations needed for VLOG_IS_ON above: =========================
struct SiteFlag {
@ac_google_namespace@::int32* level;
google::int32* level;
const char* base_name;
std::size_t base_len;
SiteFlag* next;
@ -114,9 +115,9 @@ struct SiteFlag {
// verbose_level is the argument to VLOG_IS_ON
// We will return the return value for VLOG_IS_ON
// and if possible set *site_flag appropriately.
extern GLOG_EXPORT bool InitVLOG3__(
@ac_google_namespace@::SiteFlag* site_flag,
@ac_google_namespace@::int32* site_default, const char* fname,
@ac_google_namespace@::int32 verbose_level);
extern GLOG_EXPORT bool InitVLOG3__(google::SiteFlag* site_flag,
google::int32* site_default,
const char* fname,
google::int32 verbose_level);
#endif // BASE_VLOG_IS_ON_H_

View File

@ -68,11 +68,11 @@ using std::map;
using std::string;
using std::vector;
_START_GOOGLE_NAMESPACE_
namespace google {
extern GLOG_EXPORT void (*g_logging_fail_func)();
_END_GOOGLE_NAMESPACE_
}
#undef GLOG_EXPORT
#define GLOG_EXPORT
@ -119,7 +119,7 @@ DEFINE_int32(benchmark_iters, 100000, "Number of iterations per benchmark");
using testing::InitGoogleTest;
#else
_START_GOOGLE_NAMESPACE_
namespace google {
void InitGoogleTest(int*, char**);
@ -213,11 +213,11 @@ static inline int RUN_ALL_TESTS() {
return 0;
}
_END_GOOGLE_NAMESPACE_
} // namespace google
#endif // ! HAVE_LIB_GTEST
_START_GOOGLE_NAMESPACE_
namespace google {
static bool g_called_abort;
static jmp_buf g_jmp_buf;
@ -556,7 +556,7 @@ static inline bool MungeAndDiffTestStdout(const string& golden_filename) {
}
// Save flags used from logging_unittest.cc.
#ifndef HAVE_LIB_GFLAGS
#ifndef GLOG_USE_GFLAGS
struct FlagSaver {
FlagSaver()
: v_(FLAGS_v),
@ -638,11 +638,11 @@ static inline void SleepForMilliseconds(unsigned t) {
void (*g_new_hook)() = nullptr;
_END_GOOGLE_NAMESPACE_
} // namespace google
void* operator new(size_t size, const std::nothrow_t&) noexcept {
if (GOOGLE_NAMESPACE::g_new_hook) {
GOOGLE_NAMESPACE::g_new_hook();
if (google::g_new_hook) {
google::g_new_hook();
}
return malloc(size);
}

View File

@ -29,7 +29,7 @@
#define _GNU_SOURCE 1 // needed for O_NOFOLLOW and pread()/pwrite()
#include "utilities.h"
#include "glog/logging.h"
#include <algorithm>
#include <cassert>
@ -38,53 +38,65 @@
#include <iterator>
#include <string>
#ifdef HAVE_UNISTD_H
# include <unistd.h> // For _exit.
#endif
#include <climits>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_SYS_UTSNAME_H
# include <sys/utsname.h> // For uname.
#endif
#include <ctime>
#include <fcntl.h>
#include <cstdio>
#include <iostream>
#include <cstdarg>
#include <cstdlib>
#ifdef HAVE_PWD_H
# include <pwd.h>
#endif
#ifdef HAVE_SYSLOG_H
# include <syslog.h>
#endif
#ifdef HAVE__CHSIZE_S
#include <io.h> // for truncate log file
#endif
#include <vector>
#include <cerrno> // for errno
#include <sstream>
#include <regex>
#include <cctype> // for std::isspace
#ifdef GLOG_OS_WINDOWS
#include "windows/dirent.h"
#else
#include <dirent.h> // for automatic removal of old logs
#endif
#include "base/commandlineflags.h" // to get the program name
#include "base/googleinit.h"
#include "glog/logging.h"
#include "config.h"
#include "glog/raw_logging.h"
#include "utilities.h"
#ifdef HAVE_STACKTRACE
#include "stacktrace.h"
#endif
#ifdef GLOG_OS_WINDOWS
#include "windows/dirent.h"
#else
#include <dirent.h> // for automatic removal of old logs
#endif
#include <fcntl.h>
#include <sys/stat.h>
#include <cctype> // for std::isspace
#include <cerrno> // for errno
#include <climits>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <regex>
#include <sstream>
#include <vector>
#ifdef HAVE__CHSIZE_S
#include <io.h> // for truncate log file
#endif
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#ifdef HAVE_SYS_UTSNAME_H
#include <sys/utsname.h> // For uname.
#endif
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif
#ifdef __ANDROID__
#include <android/log.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifndef HAVE_MODE_T
typedef int mode_t;
#endif
using std::string;
using std::vector;
using std::setw;
@ -146,8 +158,7 @@ GLOG_DEFINE_bool(drop_log_memory, true, "Drop in-memory buffers of log contents.
//
// The default is ERROR instead of FATAL so that users can see problems
// when they run a program without having to look in another file.
DEFINE_int32(stderrthreshold,
GOOGLE_NAMESPACE::GLOG_ERROR,
DEFINE_int32(stderrthreshold, google::GLOG_ERROR,
"log messages at or above this level are copied to stderr in "
"addition to logfiles. This flag obsoletes --alsologtostderr.");
@ -218,10 +229,6 @@ GLOG_DEFINE_bool(log_utc_time, false,
enum { PATH_SEPARATOR = '/' };
#ifndef HAVE_PREAD
#if defined(GLOG_OS_WINDOWS)
#include <basetsd.h>
#define ssize_t SSIZE_T
#endif
static ssize_t pread(int fd, void* buf, size_t count, off_t offset) {
off_t orig_offset = lseek(fd, 0, SEEK_CUR);
if (orig_offset == (off_t)-1)
@ -302,7 +309,7 @@ static bool TerminalSupportsColor() {
return term_supports_color;
}
_START_GOOGLE_NAMESPACE_
namespace google {
enum GLogColor {
COLOR_DEFAULT,
@ -2766,4 +2773,4 @@ void LogMessageTime::CalcGmtOffset() {
gmtoffset_ = static_cast<long int>(timestamp_ - gmt_sec + (isDst ? hour_secs : 0) ) ;
}
_END_GOOGLE_NAMESPACE_
} // namespace google

View File

@ -62,7 +62,7 @@
DECLARE_string(log_backtrace_at); // logging.cc
#ifdef HAVE_LIB_GFLAGS
#ifdef GLOG_USE_GFLAGS
#include <gflags/gflags.h>
using namespace GFLAGS_NAMESPACE;
#endif
@ -71,28 +71,28 @@ using namespace GFLAGS_NAMESPACE;
#include <gmock/gmock.h>
#include "mock-log.h"
// Introduce several symbols from gmock.
using google::glog_testing::ScopedMockLog;
using testing::_;
using testing::AllOf;
using testing::AnyNumber;
using testing::HasSubstr;
using testing::AllOf;
using testing::StrNe;
using testing::StrictMock;
using testing::InitGoogleMock;
using GOOGLE_NAMESPACE::glog_testing::ScopedMockLog;
using testing::StrictMock;
using testing::StrNe;
#endif
using namespace std;
using namespace GOOGLE_NAMESPACE;
using namespace google;
// Some non-advertised functions that we want to test or use.
_START_GOOGLE_NAMESPACE_
namespace google {
namespace base {
namespace internal {
bool GetExitOnDFatal();
void SetExitOnDFatal(bool value);
} // namespace internal
} // namespace base
_END_GOOGLE_NAMESPACE_
} // namespace google
static void TestLogging(bool check_counts);
static void TestRawLogging();
@ -239,7 +239,7 @@ int main(int argc, char **argv) {
InitGoogleMock(&argc, argv);
#endif
#ifdef HAVE_LIB_GFLAGS
#ifdef GLOG_USE_GFLAGS
ParseCommandLineFlags(&argc, &argv, true);
#endif
@ -1104,14 +1104,14 @@ static void TestLogPeriodically() {
}
}
_START_GOOGLE_NAMESPACE_
namespace google {
namespace glog_internal_namespace_ {
extern // in logging.cc
bool SafeFNMatch_(const char* pattern, size_t patt_len,
const char* str, size_t str_len);
} // namespace glog_internal_namespace_
using glog_internal_namespace_::SafeFNMatch_;
_END_GOOGLE_NAMESPACE_
} // namespace google
static bool WrapSafeFNMatch(string pattern, string str) {
pattern += "abc";

View File

@ -35,7 +35,7 @@
#ifndef GLOG_SRC_MOCK_LOG_H_
#define GLOG_SRC_MOCK_LOG_H_
// For GOOGLE_NAMESPACE. This must go first so we get _XOPEN_SOURCE.
// For google. This must go first so we get _XOPEN_SOURCE.
#include <gmock/gmock.h>
#include <string>
@ -43,7 +43,7 @@
#include "glog/logging.h"
#include "utilities.h"
_START_GOOGLE_NAMESPACE_
namespace google {
namespace glog_testing {
// A ScopedMockLog object intercepts LOG() messages issued during its
@ -64,7 +64,7 @@ namespace glog_testing {
//
// Foo(); // Exercises the code under test.
// }
class ScopedMockLog : public GOOGLE_NAMESPACE::LogSink {
class ScopedMockLog : public google::LogSink {
public:
// When a ScopedMockLog object is constructed, it starts to
// intercept logs.
@ -86,8 +86,8 @@ class ScopedMockLog : public GOOGLE_NAMESPACE::LogSink {
// for messages from different threads. In fact, if the same or multiple
// expectations are matched on two threads concurrently, their actions will
// be executed concurrently as well and may interleave.
MOCK_METHOD3(Log, void(GOOGLE_NAMESPACE::LogSeverity severity,
const std::string& file_path,
MOCK_METHOD3(Log,
void(google::LogSeverity severity, const std::string& file_path,
const std::string& message));
private:
@ -112,7 +112,7 @@ class ScopedMockLog : public GOOGLE_NAMESPACE::LogSink {
// be running simultaneously, we ensure thread-safety of the exchange between
// send() and WaitTillSent(), and that for each message, LOG(), send(),
// WaitTillSent() and Log() are executed in the same thread.
void send(GOOGLE_NAMESPACE::LogSeverity severity, const char* full_filename,
void send(google::LogSeverity severity, const char* full_filename,
const char* /*base_filename*/, int /*line*/,
const LogMessageTime& /*logmsgtime*/, const char* message,
size_t message_len) override {
@ -141,7 +141,7 @@ class ScopedMockLog : public GOOGLE_NAMESPACE::LogSink {
// All relevant information about a logged message that needs to be passed
// from send() to WaitTillSent().
struct MessageInfo {
GOOGLE_NAMESPACE::LogSeverity severity;
google::LogSeverity severity;
std::string file_path;
std::string message;
};
@ -149,6 +149,6 @@ class ScopedMockLog : public GOOGLE_NAMESPACE::LogSink {
};
} // namespace glog_testing
_END_GOOGLE_NAMESPACE_
} // namespace google
#endif // GLOG_SRC_MOCK_LOG_H_

View File

@ -40,10 +40,10 @@
namespace {
using GOOGLE_NAMESPACE::GLOG_ERROR;
using GOOGLE_NAMESPACE::GLOG_INFO;
using GOOGLE_NAMESPACE::GLOG_WARNING;
using GOOGLE_NAMESPACE::glog_testing::ScopedMockLog;
using google::GLOG_ERROR;
using google::GLOG_INFO;
using google::GLOG_WARNING;
using google::glog_testing::ScopedMockLog;
using std::string;
using testing::_;
using testing::EndsWith;
@ -100,7 +100,7 @@ TEST(ScopedMockLogTest, LogDuringIntercept) {
} // namespace
int main(int argc, char **argv) {
GOOGLE_NAMESPACE::InitGoogleLogging(argv[0]);
google::InitGoogleLogging(argv[0]);
testing::InitGoogleTest(&argc, argv);
testing::InitGoogleMock(&argc, argv);

View File

@ -70,7 +70,7 @@
#define safe_write(fd, s, len) write(fd, s, len)
#endif
_START_GOOGLE_NAMESPACE_
namespace google {
#if defined(__GNUC__)
#define GLOG_ATTRIBUTE_FORMAT(archetype, stringIndex, firstToCheck) \
@ -179,4 +179,4 @@ void RawLog__(LogSeverity severity, const char* file, int line,
}
}
_END_GOOGLE_NAMESPACE_
} // namespace google

View File

@ -1,4 +1,4 @@
// Copyright (c) 2008, Google Inc.
// Copyright (c) 2023, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@ -31,6 +31,7 @@
//
// Implementation of InstallFailureSignalHandler().
#include <algorithm>
#include <csignal>
#include <ctime>
@ -38,15 +39,18 @@
#include "stacktrace.h"
#include "symbolize.h"
#include "utilities.h"
#ifdef HAVE_UCONTEXT_H
# include <ucontext.h>
#endif
#ifdef HAVE_SYS_UCONTEXT_H
# include <sys/ucontext.h>
#endif
#include <algorithm>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
_START_GOOGLE_NAMESPACE_
namespace google {
namespace {
@ -409,4 +413,4 @@ void InstallFailureWriter(void (*writer)(const char* data, size_t size)) {
#endif // HAVE_SIGACTION
}
_END_GOOGLE_NAMESPACE_
} // namespace google

View File

@ -44,12 +44,12 @@
#include "glog/logging.h"
#ifdef HAVE_LIB_GFLAGS
#ifdef GLOG_USE_GFLAGS
#include <gflags/gflags.h>
using namespace GFLAGS_NAMESPACE;
#endif
using namespace GOOGLE_NAMESPACE;
using namespace google;
static void* DieInThread(void*) {
// We assume pthread_t is an integral number or a pointer, rather
@ -75,7 +75,7 @@ static void WriteToStdout(const char* data, size_t size) {
int main(int argc, char **argv) {
#if defined(HAVE_STACKTRACE) && defined(HAVE_SYMBOLIZE)
InitGoogleLogging(argv[0]);
#ifdef HAVE_LIB_GFLAGS
#ifdef GLOG_USE_GFLAGS
ParseCommandLineFlags(&argc, &argv, true);
#endif
InstallFailureSignalHandler();

View File

@ -36,7 +36,7 @@
#include "config.h"
#include "glog/logging.h"
_START_GOOGLE_NAMESPACE_
namespace google {
// This is similar to the GetStackFrames routine, except that it returns
// the stack trace only, and not the stack frame sizes as well.
@ -56,6 +56,6 @@ _START_GOOGLE_NAMESPACE_
// "result" must not be nullptr.
GLOG_EXPORT int GetStackTrace(void** result, int max_depth, int skip_count);
_END_GOOGLE_NAMESPACE_
} // namespace google
#endif // BASE_STACKTRACE_H_

View File

@ -37,7 +37,7 @@
#include "stacktrace.h"
_START_GOOGLE_NAMESPACE_
namespace google {
// If you change this function, also change GetStackFrames below.
int GetStackTrace(void** result, int max_depth, int skip_count) {
@ -61,4 +61,4 @@ int GetStackTrace(void** result, int max_depth, int skip_count) {
return result_count;
}
_END_GOOGLE_NAMESPACE_
} // namespace google

View File

@ -40,7 +40,7 @@ extern "C" {
#include "glog/raw_logging.h"
#include "stacktrace.h"
_START_GOOGLE_NAMESPACE_
namespace google {
// Sometimes, we can try to get a stack trace from within a stack
// trace, because libunwind can call mmap (maybe indirectly via an
@ -90,4 +90,4 @@ int GetStackTrace(void** result, int max_depth, int skip_count) {
return n;
}
_END_GOOGLE_NAMESPACE_
} // namespace google

View File

@ -40,7 +40,7 @@
#include "stacktrace.h"
_START_GOOGLE_NAMESPACE_
namespace google {
// Given a pointer to a stack frame, locate and return the calling
// stackframe, or return nullptr if no stackframe can be found. Perform sanity
@ -130,4 +130,4 @@ int GetStackTrace(void** result, int max_depth, int skip_count) {
return n;
}
_END_GOOGLE_NAMESPACE_
} // namespace google

View File

@ -41,7 +41,7 @@
# include <execinfo.h>
#endif
using namespace GOOGLE_NAMESPACE;
using namespace google;
#ifdef HAVE_STACKTRACE

View File

@ -35,7 +35,7 @@
#include "stacktrace.h"
_START_GOOGLE_NAMESPACE_
namespace google {
struct trace_arg_t {
void **result;
@ -101,4 +101,4 @@ int GetStackTrace(void** result, int max_depth, int skip_count) {
return targ.count;
}
_END_GOOGLE_NAMESPACE_
} // namespace google

View File

@ -36,7 +36,7 @@
#include "stacktrace.h"
#include <dbghelp.h>
_START_GOOGLE_NAMESPACE_
namespace google {
int GetStackTrace(void** result, int max_depth, int skip_count) {
if (max_depth > 64) {
@ -48,4 +48,4 @@ int GetStackTrace(void** result, int max_depth, int skip_count) {
static_cast<DWORD>(max_depth), result, nullptr);
}
_END_GOOGLE_NAMESPACE_
} // namespace google

View File

@ -42,7 +42,7 @@
#include "stacktrace.h"
_START_GOOGLE_NAMESPACE_
namespace google {
// Given a pointer to a stack frame, locate and return the calling
// stackframe, or return nullptr if no stackframe can be found. Perform sanity
@ -156,4 +156,4 @@ int GetStackTrace(void** result, int max_depth, int skip_count) {
return n;
}
_END_GOOGLE_NAMESPACE_
} // namespace google

View File

@ -44,7 +44,7 @@
GLOG_DEFINE_bool(check_mode, false, "Prints 'opt' or 'dbg'");
using std::string;
using namespace GOOGLE_NAMESPACE;
using namespace google;
int CheckNoReturn(bool b) {
string s;

View File

@ -1,4 +1,4 @@
// Copyright (c) 2006, Google Inc.
// Copyright (c) 2023, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@ -64,7 +64,7 @@
#include "symbolize.h"
#include "demangle.h"
_START_GOOGLE_NAMESPACE_
namespace google {
// We don't use assert() since it's not guaranteed to be
// async-signal-safe. Instead we define a minimal assertion
@ -106,7 +106,7 @@ static ATTRIBUTE_NOINLINE void DemangleInplace(char *out, size_t out_size) {
}
}
_END_GOOGLE_NAMESPACE_
} // namespace google
#if defined(__ELF__)
@ -138,7 +138,7 @@ _END_GOOGLE_NAMESPACE_
// Re-runs fn until it doesn't cause EINTR.
#define NO_INTR(fn) do {} while ((fn) < 0 && errno == EINTR)
_START_GOOGLE_NAMESPACE_
namespace google {
// Read up to "count" bytes from "offset" in the file pointed by file
// descriptor "fd" into the buffer starting at "buf" while handling short reads
@ -833,14 +833,14 @@ static ATTRIBUTE_NOINLINE bool SymbolizeAndDemangle(void *pc, char *out,
return true;
}
_END_GOOGLE_NAMESPACE_
} // namespace google
#elif defined(GLOG_OS_MACOSX) && defined(HAVE_DLADDR)
#include <dlfcn.h>
#include <cstring>
_START_GOOGLE_NAMESPACE_
namespace google {
static ATTRIBUTE_NOINLINE bool SymbolizeAndDemangle(void *pc, char *out,
size_t out_size) {
@ -858,7 +858,7 @@ static ATTRIBUTE_NOINLINE bool SymbolizeAndDemangle(void *pc, char *out,
return false;
}
_END_GOOGLE_NAMESPACE_
} // namespace google
#elif defined(GLOG_OS_WINDOWS) || defined(GLOG_OS_CYGWIN)
@ -869,7 +869,7 @@ _END_GOOGLE_NAMESPACE_
#pragma comment(lib, "dbghelp")
#endif
_START_GOOGLE_NAMESPACE_
namespace google {
class SymInitializer {
public:
@ -923,19 +923,19 @@ static ATTRIBUTE_NOINLINE bool SymbolizeAndDemangle(void *pc, char *out,
return false;
}
_END_GOOGLE_NAMESPACE_
} // namespace google
#else
# error BUG: HAVE_SYMBOLIZE was wrongly set
#endif
_START_GOOGLE_NAMESPACE_
namespace google {
bool Symbolize(void *pc, char *out, size_t out_size) {
return SymbolizeAndDemangle(pc, out, out_size);
}
_END_GOOGLE_NAMESPACE_
} // namespace google
#else /* HAVE_SYMBOLIZE */
@ -943,7 +943,7 @@ _END_GOOGLE_NAMESPACE_
#include "config.h"
_START_GOOGLE_NAMESPACE_
namespace google {
// TODO: Support other environments.
bool Symbolize(void* /*pc*/, char* /*out*/, size_t /*out_size*/) {
@ -951,6 +951,6 @@ bool Symbolize(void* /*pc*/, char* /*out*/, size_t /*out_size*/) {
return false;
}
_END_GOOGLE_NAMESPACE_
} // namespace google
#endif

View File

@ -92,18 +92,18 @@
# endif
#endif
_START_GOOGLE_NAMESPACE_
namespace google {
// Gets the section header for the given name, if it exists. Returns true on
// success. Otherwise, returns false.
bool GetSectionHeaderByName(int fd, const char *name, size_t name_len,
ElfW(Shdr) *out);
_END_GOOGLE_NAMESPACE_
} // namespace google
#endif /* __ELF__ */
_START_GOOGLE_NAMESPACE_
namespace google {
// Restrictions on the callbacks that follow:
// - The callbacks must not use heaps but only use stacks.
@ -135,11 +135,11 @@ using SymbolizeOpenObjectFileCallback = int (*)(uint64_t, uint64_t &,
void InstallSymbolizeOpenObjectFileCallback(
SymbolizeOpenObjectFileCallback callback);
_END_GOOGLE_NAMESPACE_
} // namespace google
#endif
_START_GOOGLE_NAMESPACE_
namespace google {
// Symbolizes a program counter. On success, returns true and write the
// symbol name to "out". The symbol name is demangled if possible
@ -147,6 +147,6 @@ _START_GOOGLE_NAMESPACE_
// returns false.
GLOG_EXPORT bool Symbolize(void* pc, char* out, size_t out_size);
_END_GOOGLE_NAMESPACE_
} // namespace google
#endif // BASE_SYMBOLIZE_H_

View File

@ -41,13 +41,13 @@
#include "googletest.h"
#include "utilities.h"
#ifdef HAVE_LIB_GFLAGS
#ifdef GLOG_USE_GFLAGS
#include <gflags/gflags.h>
using namespace GFLAGS_NAMESPACE;
#endif
using namespace std;
using namespace GOOGLE_NAMESPACE;
using namespace google;
// Avoid compile error due to "cast between pointer-to-function and
// pointer-to-object is an extension" warnings.

View File

@ -62,7 +62,7 @@
using std::string;
_START_GOOGLE_NAMESPACE_
namespace google {
static const char* g_program_invocation_short_name = nullptr;
@ -70,7 +70,7 @@ bool IsGoogleLoggingInitialized() {
return g_program_invocation_short_name != nullptr;
}
_END_GOOGLE_NAMESPACE_
} // namespace google
// The following APIs are all internal.
#ifdef HAVE_STACKTRACE
@ -82,7 +82,7 @@ _END_GOOGLE_NAMESPACE_
GLOG_DEFINE_bool(symbolize_stacktrace, true,
"Symbolize the stack trace in the tombstone");
_START_GOOGLE_NAMESPACE_
namespace google {
using DebugWriter = void(const char*, void*);
@ -177,11 +177,11 @@ DumpStackTraceAndExit() {
abort();
}
_END_GOOGLE_NAMESPACE_
} // namespace google
#endif // HAVE_STACKTRACE
_START_GOOGLE_NAMESPACE_
namespace google {
namespace glog_internal_namespace_ {
@ -386,7 +386,7 @@ void ShutdownGoogleLoggingUtilities() {
} // namespace glog_internal_namespace_
_END_GOOGLE_NAMESPACE_
} // namespace google
// Make an implementation of stacktrace compiled.
#ifdef STACKTRACE_H

View File

@ -63,6 +63,19 @@
#include "config.h"
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#if !defined(HAVE_SSIZE_T)
#if defined(GLOG_OS_WINDOWS)
#include <basetsd.h>
using ssize_t = SSIZE_T;
#else
using ssize_t = std::ptrdiff_t;
#endif
#endif
// There are three different ways we can try to get the stack trace:
//
// 1) The libunwind library. This is still in development, and as a
@ -127,17 +140,25 @@
# define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a)))
#endif
_START_GOOGLE_NAMESPACE_
namespace google {
namespace glog_internal_namespace_ {
#ifdef HAVE___ATTRIBUTE__
#if defined(__has_attribute)
#if __has_attribute(noinline)
# define ATTRIBUTE_NOINLINE __attribute__ ((noinline))
# define HAVE_ATTRIBUTE_NOINLINE
#elif defined(GLOG_OS_WINDOWS)
#endif
#endif
#if !defined(HAVE_ATTRIBUTE_NOINLINE)
#if defined(GLOG_OS_WINDOWS)
# define ATTRIBUTE_NOINLINE __declspec(noinline)
# define HAVE_ATTRIBUTE_NOINLINE
#else
#endif
#endif
#if !defined(HAVE_ATTRIBUTE_NOINLINE)
# define ATTRIBUTE_NOINLINE
#endif
@ -209,8 +230,8 @@ void ShutdownGoogleLoggingUtilities();
} // namespace glog_internal_namespace_
_END_GOOGLE_NAMESPACE_
} // namespace google
using namespace GOOGLE_NAMESPACE::glog_internal_namespace_;
using namespace google::glog_internal_namespace_;
#endif // UTILITIES_H__

View File

@ -33,12 +33,12 @@
#include "glog/logging.h"
#include "googletest.h"
#ifdef HAVE_LIB_GFLAGS
#ifdef GLOG_USE_GFLAGS
#include <gflags/gflags.h>
using namespace GFLAGS_NAMESPACE;
#endif
using namespace GOOGLE_NAMESPACE;
using namespace google;
TEST(utilities, sync_val_compare_and_swap) {
bool now_entering = false;

View File

@ -58,7 +58,7 @@ GLOG_DEFINE_string(vmodule, "", "per-module verbose level."
" (that is, name ignoring .cc/.h./-inl.h)."
" <log level> overrides any value given by --v.");
_START_GOOGLE_NAMESPACE_
namespace google {
namespace glog_internal_namespace_ {
@ -291,4 +291,4 @@ bool InitVLOG3__(SiteFlag* site_flag, int32* level_default,
return *site_flag_value >= verbose_level;
}
_END_GOOGLE_NAMESPACE_
} // namespace google