From ca803b6235c9f5988b4b8298aca74debe2443f3c Mon Sep 17 00:00:00 2001 From: Sergiu Deitsch Date: Fri, 29 Dec 2023 18:08:12 +0100 Subject: [PATCH] rework public header structure 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. --- .github/workflows/linux.yml | 6 - .github/workflows/macos.yml | 6 - .github/workflows/windows.yml | 6 - CMakeLists.txt | 96 +- bazel/glog.bzl | 79 +- src/base/commandlineflags.h | 14 +- src/cleanup_immediately_unittest.cc | 8 +- src/cleanup_with_absolute_prefix_unittest.cc | 8 +- src/cleanup_with_relative_prefix_unittest.cc | 8 +- src/config.h.cmake.in | 49 +- src/demangle.cc | 4 +- src/demangle.h | 4 +- src/demangle_unittest.cc | 6 +- src/glog/{logging.h.in => logging.h} | 883 +++++++++---------- src/glog/{raw_logging.h.in => raw_logging.h} | 115 +-- src/glog/{stl_logging.h.in => stl_logging.h} | 101 +-- src/glog/{vlog_is_on.h.in => vlog_is_on.h} | 27 +- src/googletest.h | 18 +- src/logging.cc | 87 +- src/logging_unittest.cc | 22 +- src/mock-log.h | 18 +- src/mock-log_unittest.cc | 10 +- src/raw_logging.cc | 4 +- src/signalhandler.cc | 12 +- src/signalhandler_unittest.cc | 6 +- src/stacktrace.h | 4 +- src/stacktrace_generic-inl.h | 4 +- src/stacktrace_libunwind-inl.h | 4 +- src/stacktrace_powerpc-inl.h | 4 +- src/stacktrace_unittest.cc | 2 +- src/stacktrace_unwind-inl.h | 4 +- src/stacktrace_windows-inl.h | 4 +- src/stacktrace_x86-inl.h | 4 +- src/striplog_unittest.cc | 2 +- src/symbolize.cc | 26 +- src/symbolize.h | 12 +- src/symbolize_unittest.cc | 4 +- src/utilities.cc | 12 +- src/utilities.h | 33 +- src/utilities_unittest.cc | 4 +- src/vlog_is_on.cc | 4 +- 41 files changed, 782 insertions(+), 942 deletions(-) rename src/glog/{logging.h.in => logging.h} (71%) rename src/glog/{raw_logging.h.in => raw_logging.h} (69%) rename src/glog/{stl_logging.h.in => stl_logging.h} (62%) rename src/glog/{vlog_is_on.h.in => vlog_is_on.h} (83%) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 54f7b865e..a2777feb8 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -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 diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index bcb8fd919..01e6e9f77 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -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 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index e33339e39..01d3f2950 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index f7f08fe0f..e8ff59e18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 -static void foo(void) __attribute__ ((unused)); -int main(void) { return 0; } -" HAVE___ATTRIBUTE__) - -check_cxx_source_compiles (" -#include -static void foo(void) __attribute__ ((visibility(\"default\"))); -int main(void) { return 0; } -" HAVE___ATTRIBUTE__VISIBILITY_DEFAULT) - -check_cxx_source_compiles (" -#include -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") diff --git a/bazel/glog.bzl b/bazel/glog.bzl index b92473b36..3afb38980 100644 --- a/bazel/glog.bzl +++ b/bazel/glog.bzl @@ -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. @@ -83,6 +75,9 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs): 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 +189,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 +256,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 +269,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", - ] - ] diff --git a/src/base/commandlineflags.h b/src/base/commandlineflags.h index 66c0dae09..e6ffd48e3 100644 --- a/src/base/commandlineflags.h +++ b/src/base/commandlineflags.h @@ -53,7 +53,7 @@ #include // for memchr #include -#ifdef HAVE_LIB_GFLAGS +#ifdef GLOG_USE_GFLAGS #include @@ -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. diff --git a/src/cleanup_immediately_unittest.cc b/src/cleanup_immediately_unittest.cc index b98b634e4..9d2823db9 100644 --- a/src/cleanup_immediately_unittest.cc +++ b/src/cleanup_immediately_unittest.cc @@ -32,7 +32,7 @@ #include "glog/raw_logging.h" #include "googletest.h" -#ifdef HAVE_LIB_GFLAGS +#ifdef GLOG_USE_GFLAGS #include 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 diff --git a/src/cleanup_with_absolute_prefix_unittest.cc b/src/cleanup_with_absolute_prefix_unittest.cc index c035a9e98..69b62d8f4 100644 --- a/src/cleanup_with_absolute_prefix_unittest.cc +++ b/src/cleanup_with_absolute_prefix_unittest.cc @@ -32,7 +32,7 @@ #include "glog/raw_logging.h" #include "googletest.h" -#ifdef HAVE_LIB_GFLAGS +#ifdef GLOG_USE_GFLAGS #include 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 diff --git a/src/cleanup_with_relative_prefix_unittest.cc b/src/cleanup_with_relative_prefix_unittest.cc index 194c8e685..70c3b537d 100644 --- a/src/cleanup_with_relative_prefix_unittest.cc +++ b/src/cleanup_with_relative_prefix_unittest.cc @@ -32,7 +32,7 @@ #include "glog/raw_logging.h" #include "googletest.h" -#ifdef HAVE_LIB_GFLAGS +#ifdef GLOG_USE_GFLAGS #include 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 diff --git a/src/config.h.cmake.in b/src/config.h.cmake.in index 752d76648..1dc8baabd 100644 --- a/src/config.h.cmake.in +++ b/src/config.h.cmake.in @@ -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 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 header file. */ -#cmakedefine HAVE_STRINGS_H - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYSCALL_H /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYSLOG_H -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_STAT_H - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_SYSCALL_H @@ -83,7 +68,7 @@ #cmakedefine HAVE_SYS_TIME_H /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H} +#cmakedefine HAVE_SYS_TYPES_H /* Define to 1 if you have the 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} diff --git a/src/demangle.cc b/src/demangle.cc index 74dff7062..1c619344d 100644 --- a/src/demangle.cc +++ b/src/demangle.cc @@ -46,7 +46,7 @@ #include #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 diff --git a/src/demangle.h b/src/demangle.h index 416f7ee15..db2fa262b 100644 --- a/src/demangle.h +++ b/src/demangle.h @@ -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_ diff --git a/src/demangle_unittest.cc b/src/demangle_unittest.cc index 21a407caf..869454fc0 100644 --- a/src/demangle_unittest.cc +++ b/src/demangle_unittest.cc @@ -42,7 +42,7 @@ #include "googletest.h" #include "utilities.h" -#ifdef HAVE_LIB_GFLAGS +#ifdef GLOG_USE_GFLAGS #include 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); diff --git a/src/glog/logging.h.in b/src/glog/logging.h similarity index 71% rename from src/glog/logging.h.in rename to src/glog/logging.h index f213c8837..326b77075 100644 --- a/src/glog/logging.h.in +++ b/src/glog/logging.h @@ -46,15 +46,12 @@ #include #include #include -#if @ac_cv_have_unistd_h@ -# include -#endif -#include #include +#include #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 // the normal place uint16_t is defined -#if @ac_cv_have_systypes_h@ -#include // the normal place u_int16_t is defined -#endif -#if @ac_cv_have_libgflags@ +#if defined(GLOG_USE_GFLAGS) #include #endif #include -@ac_google_start_namespace@ +namespace google { - typedef std::int32_t int32; +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,25 +128,25 @@ 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; - const int &line_number; - const int &thread_id; + const int& line_number; + const int& thread_id; 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). // +#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 -#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 -#endif #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)) +#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(). E.g., @@ -386,32 +390,29 @@ typedef void(*CustomPrefixCallback)(std::ostream& s, const LogMessageInfo& l, vo #endif #ifndef DECLARE_VARIABLE -#define DECLARE_VARIABLE(type, shorttype, name, tn) \ - namespace fL##shorttype { \ - extern GLOG_EXPORT type FLAGS_##name; \ - } \ +#define DECLARE_VARIABLE(type, shorttype, name, tn) \ + namespace fL##shorttype { \ + extern GLOG_EXPORT type FLAGS_##name; \ + } \ 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. -#define DECLARE_string(name) \ - namespace fLS { \ - extern GLOG_EXPORT std::string& FLAGS_##name; \ - } \ +#define DECLARE_string(name) \ + namespace fLS { \ + extern GLOG_EXPORT std::string& FLAGS_##name; \ + } \ using fLS::FLAGS_##name #endif @@ -470,7 +471,7 @@ DECLARE_string(log_link); DECLARE_int32(v); // in vlog_is_on.cc -DECLARE_string(vmodule); // also in vlog_is_on.cc +DECLARE_string(vmodule); // also in vlog_is_on.cc // Sets the maximum log file size (in MB). DECLARE_uint32(max_log_size); @@ -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,57 +541,61 @@ 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 SYSLOG_INFO(counter) \ - @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_INFO, counter, \ - &@ac_google_namespace@::LogMessage::SendToSyslogAndLog) -#define GOOGLE_LOG_WARNING(counter) \ - @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_WARNING, counter, \ - &@ac_google_namespace@::LogMessage::SendToLog) -#define SYSLOG_WARNING(counter) \ - @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_WARNING, counter, \ - &@ac_google_namespace@::LogMessage::SendToSyslogAndLog) -#define GOOGLE_LOG_ERROR(counter) \ - @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_ERROR, counter, \ - &@ac_google_namespace@::LogMessage::SendToLog) -#define SYSLOG_ERROR(counter) \ - @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_ERROR, counter, \ - &@ac_google_namespace@::LogMessage::SendToSyslogAndLog) -#define GOOGLE_LOG_FATAL(counter) \ - @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_FATAL, counter, \ - &@ac_google_namespace@::LogMessage::SendToLog) -#define SYSLOG_FATAL(counter) \ - @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::GLOG_FATAL, counter, \ - &@ac_google_namespace@::LogMessage::SendToSyslogAndLog) -#define GOOGLE_LOG_DFATAL(counter) \ - @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::DFATAL_LEVEL, counter, \ - &@ac_google_namespace@::LogMessage::SendToLog) -#define SYSLOG_DFATAL(counter) \ - @ac_google_namespace@::LogMessage(__FILE__, __LINE__, @ac_google_namespace@::DFATAL_LEVEL, counter, \ - &@ac_google_namespace@::LogMessage::SendToSyslogAndLog) - -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) || defined(__CYGWIN32__) +#define GOOGLE_LOG_INFO(counter) \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, \ + &google::LogMessage::SendToLog) +#define SYSLOG_INFO(counter) \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, \ + &google::LogMessage::SendToSyslogAndLog) +#define GOOGLE_LOG_WARNING(counter) \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \ + &google::LogMessage::SendToLog) +#define SYSLOG_WARNING(counter) \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \ + &google::LogMessage::SendToSyslogAndLog) +#define GOOGLE_LOG_ERROR(counter) \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \ + &google::LogMessage::SendToLog) +#define SYSLOG_ERROR(counter) \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \ + &google::LogMessage::SendToSyslogAndLog) +#define GOOGLE_LOG_FATAL(counter) \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \ + &google::LogMessage::SendToLog) +#define SYSLOG_FATAL(counter) \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \ + &google::LogMessage::SendToSyslogAndLog) +#define GOOGLE_LOG_DFATAL(counter) \ + google::LogMessage(__FILE__, __LINE__, google::DFATAL_LEVEL, counter, \ + &google::LogMessage::SendToLog) +#define SYSLOG_DFATAL(counter) \ + google::LogMessage(__FILE__, __LINE__, google::DFATAL_LEVEL, counter, \ + &google::LogMessage::SendToSyslogAndLog) + +#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))) { \ - LPSTR message = nullptr; \ - LPSTR msg = reinterpret_cast(&message); \ - DWORD message_length = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | \ - FORMAT_MESSAGE_FROM_SYSTEM | \ - 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() \ - << reinterpret_cast(message); \ - LocalFree(message); \ - } \ +#define LOG_SYSRESULT(result) \ + if (FAILED(HRESULT_FROM_WIN32(result))) { \ + LPSTR message = nullptr; \ + LPSTR msg = reinterpret_cast(&message); \ + DWORD message_length = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | \ + FORMAT_MESSAGE_FROM_SYSTEM | \ + FORMAT_MESSAGE_IGNORE_INSERTS, \ + 0, result, 0, msg, 100, nullptr); \ + if (message_length > 0) { \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, 0, \ + &google::LogMessage::SendToLog) \ + .stream() \ + << reinterpret_cast(message); \ + LocalFree(message); \ + } \ } #endif @@ -604,10 +607,10 @@ DECLARE_string(logmailer); // impossible to stream something like a string directly to an unnamed // ostream. We employ a neat hack by calling the stream() member // function of LogMessage which seems to avoid the problem. -#define LOG(severity) COMPACT_GOOGLE_LOG_ ## severity.stream() -#define SYSLOG(severity) SYSLOG_ ## severity(0).stream() +#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" @@ -651,22 +654,19 @@ class LogSink; // defined below // LogSink* sink; // 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() -#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() - -// 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: +#define LOG_TO_SINK(sink, severity) \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_##severity, \ + static_cast(sink), true) \ + .stream() +#define LOG_TO_SINK_BUT_NOT_TO_LOGFILE(sink, severity) \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_##severity, \ + static_cast(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: // string* message; // LogSeverity severity; // The cast is to disambiguate nullptr arguments. @@ -683,17 +683,18 @@ class LogSink; // defined below // LogSeverity severity; // vector *outvec; // The cast is to disambiguate nullptr arguments. -#define LOG_STRING(severity, outvec) \ - LOG_TO_STRING_##severity(static_cast*>(outvec)).stream() +#define LOG_STRING(severity, outvec) \ + LOG_TO_STRING_##severity(static_cast*>(outvec)) \ + .stream() #define LOG_IF(severity, condition) \ static_cast(0), \ - !(condition) ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity) + !(condition) ? (void)0 : google::LogMessageVoidify() & LOG(severity) #define SYSLOG_IF(severity, condition) \ static_cast(0), \ - !(condition) ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & SYSLOG(severity) + !(condition) ? (void)0 : google::LogMessageVoidify() & SYSLOG(severity) -#define LOG_ASSERT(condition) \ +#define LOG_ASSERT(condition) \ LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition #define SYSLOG_ASSERT(condition) \ SYSLOG_IF(FATAL, !(condition)) << "Assert failed: " #condition @@ -702,14 +703,14 @@ class LogSink; // defined below // controlled by DCHECK_IS_ON(), so the check will be executed regardless of // compilation mode. Therefore, it is safe to do things like: // CHECK(fp->Write(x) == 4) -#define CHECK(condition) \ - LOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN(!(condition))) \ - << "Check failed: " #condition " " +#define CHECK(condition) \ + LOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN(!(condition))) \ + << "Check failed: " #condition " " // A container for a string pointer which can be evaluated to a bool - // true iff the pointer is nullptr. struct CheckOpString { - CheckOpString(std::string* str) : str_(str) { } + CheckOpString(std::string* str) : str_(str) {} // No destructor: if str_ is non-nullptr, we're about to LOG(FATAL), // so there's no point in cleaning up str_. operator bool() const { @@ -722,17 +723,19 @@ struct CheckOpString { // integrals declared in classes and not defined to be used as arguments to // CHECK* macros. It's not encouraged though. template -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; } -inline short GetReferenceableValue(short t) { return t; } -inline unsigned short GetReferenceableValue(unsigned short t) { return t; } -inline int GetReferenceableValue(int t) { return t; } -inline unsigned int GetReferenceableValue(unsigned int t) { return t; } -inline long GetReferenceableValue(long 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; } +inline short GetReferenceableValue(short t) { return t; } +inline unsigned short GetReferenceableValue(unsigned short t) { return t; } +inline int GetReferenceableValue(int t) { return t; } +inline unsigned int GetReferenceableValue(unsigned int t) { return t; } +inline long GetReferenceableValue(long t) { return t; } inline unsigned long GetReferenceableValue(unsigned long t) { return t; } -inline long long GetReferenceableValue(long long t) { return t; } +inline long long GetReferenceableValue(long long t) { return t; } inline unsigned long long GetReferenceableValue(unsigned long long 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 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 { @@ -797,7 +806,7 @@ LogSeverity NormalizeSeverity(LogSeverity s); class GLOG_EXPORT CheckOpMessageBuilder { public: // Inserts "exprtext" and " (" to the stream. - explicit CheckOpMessageBuilder(const char *exprtext); + explicit CheckOpMessageBuilder(const char* exprtext); // Deletes "stream_". ~CheckOpMessageBuilder(); // For inserting the first variable. @@ -808,13 +817,14 @@ class GLOG_EXPORT CheckOpMessageBuilder { std::string* NewString(); private: - std::ostringstream *stream_; + std::ostringstream* stream_; }; } // namespace base template -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); @@ -825,27 +835,30 @@ std::string* MakeCheckOpString(const T1& v1, const T2& v2, const char* exprtext) // The (int, int) specialization works around the issue that the compiler // will not instantiate the template version of the function on values of // unnamed enum type - see comment below. -#define DEFINE_CHECK_OP_IMPL(name, op) \ - template \ - 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); \ - } \ +#define DEFINE_CHECK_OP_IMPL(name, op) \ + template \ + 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); \ + } \ inline std::string* name##Impl(int v1, int v2, const char* exprtext) { \ - return name##Impl(v1, v2, exprtext); \ + return name##Impl(v1, v2, exprtext); \ } // We use the full name Check_EQ, Check_NE, etc. in case the file including // 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, < ) +DEFINE_CHECK_OP_IMPL(Check_LT, <) DEFINE_CHECK_OP_IMPL(Check_GE, >=) -DEFINE_CHECK_OP_IMPL(Check_GT, > ) +DEFINE_CHECK_OP_IMPL(Check_GT, >) #undef DEFINE_CHECK_OP_IMPL // Helper macro for binary operators. @@ -853,7 +866,7 @@ DEFINE_CHECK_OP_IMPL(Check_GT, > ) #if defined(STATIC_ANALYSIS) // Only for static analysis tool to know that it is equivalent to assert -#define CHECK_OP_LOG(name, op, val1, val2, log) CHECK((val1) op (val2)) +#define CHECK_OP_LOG(name, op, val1, val2, log) CHECK((val1)op(val2)) #elif DCHECK_IS_ON() // In debug mode, avoid constructing CheckOpStrings if possible, // to reduce the overhead of CHECK statements by 2x. @@ -865,33 +878,28 @@ DEFINE_CHECK_OP_IMPL(Check_GT, > ) // file is included). Save the current meaning now and use it // 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() +#define CHECK_OP_LOG(name, op, val1, val2, log) \ + 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)) \ - log(__FILE__, __LINE__, _result).stream() +#define CHECK_OP_LOG(name, op, val1, val2, log) \ + 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) -#endif // STRIP_LOG <= 3 + CHECK_OP_LOG(name, op, val1, val2, google::NullStreamFatal) +#endif // STRIP_LOG <= 3 // Equality/Inequality checks - compare two values, and log a FATAL message // including the two values when the result is not as expected. The values @@ -908,25 +916,26 @@ 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) #define CHECK_LE(val1, val2) CHECK_OP(_LE, <=, val1, val2) -#define CHECK_LT(val1, val2) CHECK_OP(_LT, < , val1, val2) +#define CHECK_LT(val1, val2) CHECK_OP(_LT, <, val1, val2) #define CHECK_GE(val1, val2) CHECK_OP(_GE, >=, val1, val2) -#define CHECK_GT(val1, val2) CHECK_OP(_GT, > , val1, val2) +#define CHECK_GT(val1, val2) CHECK_OP(_GT, >, val1, val2) // Check that the input is non nullptr. This very useful in constructor // initializer lists. -#define CHECK_NOTNULL(val) \ - @ac_google_namespace@::CheckNotNull(__FILE__, __LINE__, "'" #val "' Must be non nullptr", (val)) +#define CHECK_NOTNULL(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. -#define DECLARE_CHECK_STROP_IMPL(func, expected) \ +#define DECLARE_CHECK_STROP_IMPL(func, expected) \ GLOG_EXPORT std::string* Check##func##expected##Impl( \ const char* s1, const char* s2, const char* names); DECLARE_CHECK_STROP_IMPL(strcmp, true) @@ -937,12 +946,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)) \ - LOG(FATAL) << *_result.str_ - +#define CHECK_STROP(func, op, expected, s1, 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. @@ -956,19 +963,19 @@ DECLARE_CHECK_STROP_IMPL(strcasecmp, false) #define CHECK_STRCASEEQ(s1, s2) CHECK_STROP(strcasecmp, ==, true, s1, s2) #define CHECK_STRCASENE(s1, s2) CHECK_STROP(strcasecmp, !=, false, s1, s2) -#define CHECK_INDEX(I,A) CHECK(I < (sizeof(A)/sizeof(A[0]))) -#define CHECK_BOUND(B,A) CHECK(B <= (sizeof(A)/sizeof(A[0]))) +#define CHECK_INDEX(I, A) CHECK(I < (sizeof(A) / sizeof(A[0]))) +#define CHECK_BOUND(B, A) CHECK(B <= (sizeof(A) / sizeof(A[0]))) -#define CHECK_DOUBLE_EQ(val1, val2) \ - do { \ - CHECK_LE((val1), (val2)+0.000000000000001L); \ - CHECK_GE((val1), (val2)-0.000000000000001L); \ +#define CHECK_DOUBLE_EQ(val1, val2) \ + do { \ + CHECK_LE((val1), (val2) + 0.000000000000001L); \ + CHECK_GE((val1), (val2)-0.000000000000001L); \ } while (0) -#define CHECK_NEAR(val1, val2, margin) \ - do { \ - CHECK_LE((val1), (val2)+(margin)); \ - CHECK_GE((val1), (val2)-(margin)); \ +#define CHECK_NEAR(val1, val2, margin) \ + do { \ + CHECK_LE((val1), (val2) + (margin)); \ + CHECK_GE((val1), (val2) - (margin)); \ } while (0) // perror()..googly style! @@ -979,21 +986,20 @@ 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) +#define GOOGLE_PLOG(severity, counter) \ + google::ErrnoLogMessage(__FILE__, __LINE__, google::GLOG_##severity, \ + counter, &google::LogMessage::SendToLog) #define PLOG_IF(severity, condition) \ static_cast(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. // // if (poll(fds, nfds, timeout) == -1) { PCHECK(errno == EINTR); ... } -#define PCHECK(condition) \ - PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN(!(condition))) \ - << "Check failed: " #condition " " +#define PCHECK(condition) \ + PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN(!(condition))) \ + << "Check failed: " #condition " " // A CHECK() macro that lets you assert the success of a function that // returns -1 and sets errno in case of an error. E.g. @@ -1003,14 +1009,14 @@ DECLARE_CHECK_STROP_IMPL(strcasecmp, false) // or // // int fd = open(filename, flags); CHECK_ERR(fd) << ": open " << filename; -#define CHECK_ERR(invocation) \ -PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ - << #invocation +#define CHECK_ERR(invocation) \ + PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ + << #invocation // Use macro expansion to create, for each use of LOG_EVERY_N(), static // variables with the __LINE__ expansion as part of the variable name. #define LOG_EVERY_N_VARNAME(base, line) LOG_EVERY_N_VARNAME_CONCAT(base, line) -#define LOG_EVERY_N_VARNAME_CONCAT(base, line) base ## line +#define LOG_EVERY_N_VARNAME_CONCAT(base, line) base##line #define LOG_OCCURRENCES LOG_EVERY_N_VARNAME(occurrences_, __LINE__) #define LOG_OCCURRENCES_MOD_N LOG_EVERY_N_VARNAME(occurrences_mod_n_, __LINE__) @@ -1022,13 +1028,14 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ #define LOG_PREVIOUS_TIME LOG_EVERY_N_VARNAME(previousTime_, __LINE__) #if defined(__has_feature) -# if __has_feature(thread_sanitizer) -# define GLOG_SANITIZE_THREAD 1 -# endif +#if __has_feature(thread_sanitizer) +#define GLOG_SANITIZE_THREAD 1 +#endif #endif -#if !defined(GLOG_SANITIZE_THREAD) && defined(__SANITIZE_THREAD__) && __SANITIZE_THREAD__ -# define GLOG_SANITIZE_THREAD 1 +#if !defined(GLOG_SANITIZE_THREAD) && defined(__SANITIZE_THREAD__) && \ + __SANITIZE_THREAD__ +#define GLOG_SANITIZE_THREAD 1 #endif #if defined(GLOG_SANITIZE_THREAD) @@ -1038,16 +1045,13 @@ PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ #endif #if defined(GLOG_SANITIZE_THREAD) -} // namespace google +} // namespace google // 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, - const char *description); +extern "C" void AnnotateBenignRaceSized(const char* file, int line, + const volatile void* mem, size_t size, + const char* description); namespace google { #endif @@ -1056,13 +1060,11 @@ namespace google { constexpr std::chrono::nanoseconds LOG_TIME_PERIOD = \ std::chrono::duration_cast( \ std::chrono::duration(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 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::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) \ +#define SOME_KIND_OF_LOG_EVERY_N(severity, n, what_to_do) \ static std::atomic 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), "")); \ - ++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() - -#define SOME_KIND_OF_LOG_IF_EVERY_N(severity, condition, n, what_to_do) \ - static std::atomic 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), "")); \ - ++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() - -#define SOME_KIND_OF_PLOG_EVERY_N(severity, n, what_to_do) \ + 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) \ + 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 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), "")); \ + ++LOG_OCCURRENCES; \ + if ((condition) && \ + ((LOG_OCCURRENCES_MOD_N = (LOG_OCCURRENCES_MOD_N + 1) % n) == (1 % n))) \ + 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 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), "")); \ - ++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() - -#define SOME_KIND_OF_LOG_FIRST_N(severity, n, what_to_do) \ - static std::atomic LOG_OCCURRENCES(0); \ - GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized(__FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \ - 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() + 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) \ + 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 LOG_OCCURRENCES(0); \ + GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized( \ + __FILE__, __LINE__, &LOG_OCCURRENCES, sizeof(int), "")); \ + if (LOG_OCCURRENCES <= n) ++LOG_OCCURRENCES; \ + if (LOG_OCCURRENCES <= n) \ + google::LogMessage(__FILE__, __LINE__, google::GLOG_##severity, \ + LOG_OCCURRENCES, &what_to_do) \ + .stream() namespace glog_internal_namespace_ { template -struct CompileAssert { -}; +struct CompileAssert {}; struct CrashReason; // Returns true if FailureSignalHandler is installed. @@ -1134,25 +1139,27 @@ struct CrashReason; 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) +#define LOG_EVERY_N(severity, n) \ + 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) +#define SYSLOG_EVERY_N(severity, n) \ + 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) +#define LOG_IF_EVERY_N(severity, condition, n) \ + 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}; +enum PRIVATE_Counter { COUNTER }; #ifdef GLOG_NO_ABBREVIATED_SEVERITIES // wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets @@ -1169,11 +1176,12 @@ 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 COMPACT_GOOGLE_LOG_0 GLOG_ERROR_MSG -# define SYSLOG_0 GLOG_ERROR_MSG -# define LOG_TO_STRING_0 GLOG_ERROR_MSG -# define GLOG_0 GLOG_ERROR_MSG +#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 +#define GLOG_0 GLOG_ERROR_MSG #endif // Plus some debug-logging macros that get compiled to nothing for production @@ -1208,96 +1216,86 @@ const LogSeverity GLOG_0 = GLOG_ERROR; #define DLOG(severity) \ static_cast(0), \ - true ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity) + true ? (void)0 : google::LogMessageVoidify() & LOG(severity) -#define DVLOG(verboselevel) \ - static_cast(0), \ - (true || !VLOG_IS_ON(verboselevel)) ? \ - (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(INFO) +#define DVLOG(verboselevel) \ + static_cast(0), (true || !VLOG_IS_ON(verboselevel)) \ + ? (void)0 \ + : google::LogMessageVoidify() & LOG(INFO) -#define DLOG_IF(severity, condition) \ - static_cast(0), \ - (true || !(condition)) ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity) +#define DLOG_IF(severity, condition) \ + static_cast(0), (true || !(condition)) \ + ? (void)0 \ + : google::LogMessageVoidify() & LOG(severity) #define DLOG_EVERY_N(severity, n) \ static_cast(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(0), \ - (true || !(condition))? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity) + static_cast(0), (true || !(condition)) \ + ? (void)0 \ + : google::LogMessageVoidify() & LOG(severity) #define DLOG_FIRST_N(severity, n) \ - static_cast(0), \ - true ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity) + static_cast(0), \ + true ? (void)0 : google::LogMessageVoidify() & LOG(severity) #define DLOG_EVERY_T(severity, T) \ static_cast(0), \ - true ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity) + true ? (void)0 : google::LogMessageVoidify() & LOG(severity) #define DLOG_ASSERT(condition) \ - static_cast(0), \ - true ? (void) 0 : LOG_ASSERT(condition) + static_cast(0), true ? (void)0 : LOG_ASSERT(condition) // MSVC warning C4127: conditional expression is constant -#define DCHECK(condition) \ +#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) \ +#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) \ +#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) \ +#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) \ +#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) \ +#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) \ +#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. #define DCHECK_NOTNULL(val) (val) -#define DCHECK_STREQ(str1, str2) \ +#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) \ +#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) \ +#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) \ +#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(pptr() - pbase()); } @@ -1348,7 +1342,7 @@ class GLOG_EXPORT LogStreamBuf : public std::streambuf { // though. You should use the LOG() macro (and variants thereof) // above. class GLOG_EXPORT LogMessage { -public: + public: enum { // Passing kNoLogPrefix for the line number disables the // log-message prefix. Useful for using the LogMessage @@ -1364,34 +1358,34 @@ class GLOG_EXPORT LogMessage { // 2005 if you are deriving from a type in the Standard C++ Library" // http://msdn.microsoft.com/en-us/library/3tdb471s(VS.80).aspx // Let's just ignore the warning. -GLOG_MSVC_PUSH_DISABLE_WARNING(4275) + GLOG_MSVC_PUSH_DISABLE_WARNING(4275) class GLOG_EXPORT LogStream : public std::ostream { -GLOG_MSVC_POP_WARNING() - public: - // In some cases, like when compiling glog as a static library with GCC and - // linking against a Clang-built executable, this constructor will be - // removed by the linker. We use this attribute to prevent the linker from - // discarding it. + GLOG_MSVC_POP_WARNING() + public: + // In some cases, like when compiling glog as a static library with GCC and + // linking against a Clang-built executable, this constructor will be + // removed by the linker. We use this attribute to prevent the linker from + // discarding it. GLOG_USED - LogStream(char* buf, int len, int64 ctr) - : std::ostream(nullptr), streambuf_(buf, len), ctr_(ctr), self_(this) { - rdbuf(&streambuf_); - } - - LogStream(LogStream&& other) noexcept - : std::ostream(nullptr), - streambuf_(std::move(other.streambuf_)), - ctr_(std::exchange(other.ctr_, 0)), - self_(this) { - rdbuf(&streambuf_); - } - - LogStream& operator=(LogStream&& other) noexcept { - streambuf_ = std::move(other.streambuf_); - ctr_ = std::exchange(other.ctr_, 0); - rdbuf(&streambuf_); - return *this; - } + LogStream(char* buf, int len, int64 ctr) + : std::ostream(nullptr), streambuf_(buf, len), ctr_(ctr), self_(this) { + rdbuf(&streambuf_); + } + + LogStream(LogStream&& other) noexcept + : std::ostream(nullptr), + streambuf_(std::move(other.streambuf_)), + ctr_(std::exchange(other.ctr_, 0)), + self_(this) { + rdbuf(&streambuf_); + } + + LogStream& operator=(LogStream&& other) noexcept { + streambuf_ = std::move(other.streambuf_); + ctr_ = std::exchange(other.ctr_, 0); + rdbuf(&streambuf_); + return *this; + } int64 ctr() const { return ctr_; } void set_ctr(int64 ctr) { ctr_ = ctr; } @@ -1405,13 +1399,13 @@ GLOG_MSVC_POP_WARNING() LogStream(const LogStream&) = delete; LogStream& operator=(const LogStream&) = delete; - private: + private: base_logging::LogStreamBuf streambuf_; - int64 ctr_; // Counter hack (for the LOG_EVERY_X() macro) - LogStream *self_; // Consistency check hack + int64 ctr_; // Counter hack (for the LOG_EVERY_X() macro) + LogStream* self_; // Consistency check hack }; -public: + public: // icc 8 requires this typedef to avoid an internal compiler error. typedef void (LogMessage::*SendMethod)(); @@ -1469,7 +1463,7 @@ GLOG_MSVC_POP_WARNING() // These should not be called directly outside of logging.*, // only passed as SendMethod arguments to other LogMessage methods: - void SendToLog(); // Actually dispatch to the logs + void SendToLog(); // Actually dispatch to the logs void SendToSyslogAndLog(); // Actually dispatch to syslog and the logs // Call abort() or similar to perform LOG(FATAL) crash. @@ -1486,10 +1480,10 @@ GLOG_MSVC_POP_WARNING() struct LogMessageData; -private: + private: // Fully internal SendMethod cases: void SendToSinkAndLog(); // Send to sink if provided and dispatch to the logs - void SendToSink(); // Send to sink if provided, do nothing otherwise. + void SendToSink(); // Send to sink if provided, do nothing otherwise. // Write to string if provided and dispatch to the logs. void WriteToStringAndLog(); @@ -1529,7 +1523,7 @@ class GLOG_EXPORT LogMessageFatal : public LogMessage { // A non-macro interface to the log facility; (useful // when the logging level is not a compile-time constant). -inline void LogAtLevel(int const severity, std::string const &msg) { +inline void LogAtLevel(int const severity, std::string const& msg) { LogMessage(__FILE__, __LINE__, severity).stream() << msg; } @@ -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(). // @@ -1549,18 +1544,16 @@ inline void LogAtLevel(int const severity, std::string const &msg) { // : x_(CHECK_NOTNULL(MethodReturningUniquePtr())) {} template T CheckNotNull(const char* file, int line, const char* names, T&& t) { - if (t == nullptr) { - LogMessageFatal(file, line, new std::string(names)); - } - return std::forward(t); + if (t == nullptr) { + LogMessageFatal(file, line, new std::string(names)); + } + return std::forward(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,20 +1569,18 @@ 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". class GLOG_EXPORT LogMessageVoidify { public: - LogMessageVoidify() { } + LogMessageVoidify() {} // This has to be an operator with a precedence lower than << but // higher than ?: - void operator&(std::ostream&) { } + 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); @@ -1605,7 +1596,7 @@ GLOG_EXPORT void FlushLogFilesUnsafe(LogSeverity min_severity); // severity". Thread-safe. // GLOG_EXPORT void SetLogDestination(LogSeverity severity, - const char* base_filename); + const char* base_filename); // // Set the basename of the symlink to the latest log file at a given @@ -1614,7 +1605,7 @@ GLOG_EXPORT void SetLogDestination(LogSeverity severity, // invocation name of the program. Thread-safe. // GLOG_EXPORT void SetLogSymlink(LogSeverity severity, - const char* symlink_basename); + const char* symlink_basename); // // Used to send logs to some other kind of destination @@ -1656,13 +1647,13 @@ class GLOG_EXPORT LogSink { // Returns the normal text output of the log message. // Can be useful to implement send(). static std::string ToString(LogSeverity severity, const char* file, int line, - const LogMessageTime &logmsgtime, + const LogMessageTime& logmsgtime, const char* message, size_t message_len); }; // Add or remove a LogSink as a consumer of logging data. Thread-safe. -GLOG_EXPORT void AddLogSink(LogSink *destination); -GLOG_EXPORT void RemoveLogSink(LogSink *destination); +GLOG_EXPORT void AddLogSink(LogSink* destination); +GLOG_EXPORT void RemoveLogSink(LogSink* destination); // // Specify an "extension" added to the filename specified via @@ -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 @@ -1692,7 +1682,7 @@ GLOG_EXPORT void LogToStderr(); // the email addresses to send to (separated by spaces, say). Thread-safe. // GLOG_EXPORT void SetEmailLogging(LogSeverity min_severity, - const char* addresses); + const char* addresses); // A simple function that sends email. dest is a comma-separated // list of addresses. Thread-safe. @@ -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* list); +GLOG_EXPORT void GetExistingTempDirectories(std::vector* 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 @@ -1797,7 +1784,7 @@ extern GLOG_EXPORT void SetLogger(LogSeverity level, Logger* logger); // cases, you do not need to check the error code and you can directly // use the value of "buf". It will never have an undefined value. // DEPRECATED: Use StrError(int) instead. -GLOG_EXPORT int posix_strerror_r(int err, char *buf, size_t len); +GLOG_EXPORT int posix_strerror_r(int err, char* buf, size_t len); // A thread-safe replacement for strerror(). Returns a string describing the // given POSIX error code. @@ -1828,8 +1815,10 @@ class GLOG_EXPORT NullStream : public LogMessage::LogStream { // SKIP_LOG=WARNING. In those cases, NullStream will be implicitly // converted to LogStream and the message will be computed and then // quietly discarded. -template -inline NullStream& operator<<(NullStream &str, const T &) { return str; } +template +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") @@ -1874,4 +1863,4 @@ GLOG_EXPORT void InstallFailureWriter( #pragma pop_macro("DECLARE_int32") #pragma pop_macro("DECLARE_uint32") -#endif // GLOG_LOGGING_H +#endif // GLOG_LOGGING_H diff --git a/src/glog/raw_logging.h.in b/src/glog/raw_logging.h similarity index 69% rename from src/glog/raw_logging.h.in rename to src/glog/raw_logging.h index 0bf52b488..0a9b52262 100644 --- a/src/glog/raw_logging.h.in +++ b/src/glog/raw_logging.h @@ -38,7 +38,7 @@ #include -@ac_google_start_namespace@ +namespace google { #include "glog/log_severity.h" #include "glog/logging.h" #include "glog/vlog_is_on.h" @@ -62,81 +62,81 @@ // These will print an almost standard log lines like this to stderr only: // E20200821 211317 file.cc:123] RAW: Failed foo with 22: bad_file // I20200821 211317 file.cc:142] RAW: status is 20 -#define RAW_LOG(severity, ...) \ - do { \ - switch (@ac_google_namespace@::GLOG_ ## severity) { \ - case 0: \ - RAW_LOG_INFO(__VA_ARGS__); \ - break; \ - case 1: \ - RAW_LOG_WARNING(__VA_ARGS__); \ - break; \ - case 2: \ - RAW_LOG_ERROR(__VA_ARGS__); \ - break; \ - case 3: \ - RAW_LOG_FATAL(__VA_ARGS__); \ - break; \ - default: \ - break; \ - } \ +#define RAW_LOG(severity, ...) \ + do { \ + switch (google::GLOG_##severity) { \ + case 0: \ + RAW_LOG_INFO(__VA_ARGS__); \ + break; \ + case 1: \ + RAW_LOG_WARNING(__VA_ARGS__); \ + break; \ + case 2: \ + RAW_LOG_ERROR(__VA_ARGS__); \ + break; \ + case 3: \ + RAW_LOG_FATAL(__VA_ARGS__); \ + break; \ + default: \ + break; \ + } \ } while (0) // The following STRIP_LOG testing is performed in the header file so that it's // possible to completely compile out the logging code and the log messages. #if !defined(STRIP_LOG) || STRIP_LOG == 0 #define RAW_VLOG(verboselevel, ...) \ - do { \ + do { \ if (VLOG_IS_ON(verboselevel)) { \ - RAW_LOG_INFO(__VA_ARGS__); \ - } \ + RAW_LOG_INFO(__VA_ARGS__); \ + } \ } while (0) #else #define RAW_VLOG(verboselevel, ...) RawLogStub__(0, __VA_ARGS__) -#endif // STRIP_LOG == 0 +#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__) -#endif // STRIP_LOG == 0 +#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__) -#endif // STRIP_LOG <= 1 +#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__) -#endif // STRIP_LOG <= 2 +#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__) -#else #define RAW_LOG_FATAL(...) \ - do { \ - @ac_google_namespace@::RawLogStub__(0, __VA_ARGS__); \ - exit(EXIT_FAILURE); \ + google::RawLog__(google::GLOG_FATAL, __FILE__, __LINE__, __VA_ARGS__) +#else +#define RAW_LOG_FATAL(...) \ + do { \ + google::RawLogStub__(0, __VA_ARGS__); \ + exit(EXIT_FAILURE); \ } while (0) -#endif // STRIP_LOG <= 3 +#endif // STRIP_LOG <= 3 // Similar to CHECK(condition) << message, // but for low-level modules: we use only RAW_LOG that does not allocate memory. // We do not want to provide args list here to encourage this usage: // if (!cond) RAW_LOG(FATAL, "foo ...", hard_to_compute_args); // so that the args are not computed when not needed. -#define RAW_CHECK(condition, message) \ - do { \ - if (!(condition)) { \ - RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \ - } \ +#define RAW_CHECK(condition, message) \ + do { \ + if (!(condition)) { \ + RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \ + } \ } while (0) // Debug versions of RAW_LOG and RAW_CHECK @@ -147,12 +147,10 @@ #else // NDEBUG -#define RAW_DLOG(severity, ...) \ - while (false) \ - RAW_LOG(severity, __VA_ARGS__) +#define RAW_DLOG(severity, ...) \ + 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 diff --git a/src/glog/stl_logging.h.in b/src/glog/stl_logging.h similarity index 62% rename from src/glog/stl_logging.h.in rename to src/glog/stl_logging.h index 4a3065552..3689df276 100644 --- a/src/glog/stl_logging.h.in +++ b/src/glog/stl_logging.h @@ -52,79 +52,78 @@ // Forward declare these two, and define them after all the container streams // operators so that we can recurse from pair -> container -> container -> pair // properly. -template +template std::ostream& operator<<(std::ostream& out, const std::pair& p); -@ac_google_start_namespace@ +namespace google { -template +template void PrintSequence(std::ostream& out, Iter begin, Iter end); -@ac_google_end_namespace@ -#define OUTPUT_TWO_ARG_CONTAINER(Sequence) \ -template \ -inline std::ostream& operator<<(std::ostream& out, \ - const Sequence& seq) { \ - @ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \ - return out; \ } +#define OUTPUT_TWO_ARG_CONTAINER(Sequence) \ + template \ + inline std::ostream& operator<<(std::ostream& out, \ + const Sequence& seq) { \ + 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::list) - +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 \ -inline std::ostream& operator<<(std::ostream& out, \ - const Sequence& seq) { \ - @ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \ - return out; \ -} +#define OUTPUT_THREE_ARG_CONTAINER(Sequence) \ + template \ + inline std::ostream& operator<<(std::ostream& out, \ + const Sequence& seq) { \ + 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 -#define OUTPUT_FOUR_ARG_CONTAINER(Sequence) \ -template \ -inline std::ostream& operator<<(std::ostream& out, \ - const Sequence& seq) { \ - @ac_google_namespace@::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::unordered_multiset) +#define OUTPUT_FOUR_ARG_CONTAINER(Sequence) \ + template \ + inline std::ostream& operator<<(std::ostream& out, \ + const Sequence& seq) { \ + 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::unordered_multiset) #undef OUTPUT_FOUR_ARG_CONTAINER -#define OUTPUT_FIVE_ARG_CONTAINER(Sequence) \ -template \ -inline std::ostream& operator<<(std::ostream& out, \ - const Sequence& seq) { \ - @ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \ - return out; \ -} +#define OUTPUT_FIVE_ARG_CONTAINER(Sequence) \ + template \ + inline std::ostream& operator<<(std::ostream& out, \ + const Sequence& seq) { \ + google::PrintSequence(out, seq.begin(), seq.end()); \ + return out; \ + } - OUTPUT_FIVE_ARG_CONTAINER(std::unordered_map) - OUTPUT_FIVE_ARG_CONTAINER(std::unordered_multimap) +OUTPUT_FIVE_ARG_CONTAINER(std::unordered_map) +OUTPUT_FIVE_ARG_CONTAINER(std::unordered_multimap) #undef OUTPUT_FIVE_ARG_CONTAINER - template - inline std::ostream& operator<<( - std::ostream& out, - const std::pair& p) { +template +inline std::ostream& operator<<(std::ostream& out, + const std::pair& p) { out << '(' << p.first << ", " << p.second << ')'; return out; } -@ac_google_start_namespace@ +namespace google { -template +template inline void PrintSequence(std::ostream& out, Iter begin, Iter end) { // Output at most 100 elements -- appropriate if used for logging. for (int i = 0; begin != end && i < 100; ++i, ++begin) { @@ -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_ diff --git a/src/glog/vlog_is_on.h.in b/src/glog/vlog_is_on.h similarity index 83% rename from src/glog/vlog_is_on.h.in rename to src/glog/vlog_is_on.h index 2327b0493..78d16d772 100644 --- a/src/glog/vlog_is_on.h.in +++ b/src/glog/vlog_is_on.h @@ -72,14 +72,15 @@ // it's either FLAGS_v or an appropriate internal variable // 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__); \ +#define VLOG_IS_ON(verboselevel) \ + __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_ diff --git a/src/googletest.h b/src/googletest.h index 329794e18..62b5b0b7b 100644 --- a/src/googletest.h +++ b/src/googletest.h @@ -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); } diff --git a/src/logging.cc b/src/logging.cc index c05e385ad..1b7dae54d 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -29,7 +29,7 @@ #define _GNU_SOURCE 1 // needed for O_NOFOLLOW and pread()/pwrite() -#include "utilities.h" +#include "glog/logging.h" #include #include @@ -38,51 +38,63 @@ #include #include -#ifdef HAVE_UNISTD_H -# include // For _exit. +#include "base/commandlineflags.h" // to get the program name +#include "base/googleinit.h" +#include "config.h" +#include "glog/raw_logging.h" +#include "utilities.h" + +#ifdef HAVE_STACKTRACE +#include "stacktrace.h" #endif -#include -#include -#include -#ifdef HAVE_SYS_UTSNAME_H -# include // For uname. + +#ifdef GLOG_OS_WINDOWS +#include "windows/dirent.h" +#else +#include // for automatic removal of old logs #endif -#include + #include -#include -#include +#include + +#include // for std::isspace +#include // for errno +#include #include +#include #include +#include +#include +#include +#include + +#ifdef HAVE__CHSIZE_S +#include // for truncate log file +#endif #ifdef HAVE_PWD_H -# include +#include +#endif +#ifdef HAVE_SYS_UTSNAME_H +#include // For uname. #endif #ifdef HAVE_SYSLOG_H -# include +#include #endif -#ifdef HAVE__CHSIZE_S -#include // for truncate log file + +#ifdef __ANDROID__ +#include #endif -#include -#include // for errno -#include -#include -#include // for std::isspace -#ifdef GLOG_OS_WINDOWS -#include "windows/dirent.h" -#else -#include // for automatic removal of old logs + +#ifdef HAVE_SYS_TYPES_H +#include #endif -#include "base/commandlineflags.h" // to get the program name -#include "base/googleinit.h" -#include "glog/logging.h" -#include "glog/raw_logging.h" -#ifdef HAVE_STACKTRACE -# include "stacktrace.h" +#ifdef HAVE_UNISTD_H +#include #endif -#ifdef __ANDROID__ -#include +#ifndef HAVE_MODE_T +typedef int mode_t; #endif using std::string; @@ -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 -#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(timestamp_ - gmt_sec + (isDst ? hour_secs : 0) ) ; } -_END_GOOGLE_NAMESPACE_ +} // namespace google diff --git a/src/logging_unittest.cc b/src/logging_unittest.cc index 0b43e423d..e091cb4eb 100644 --- a/src/logging_unittest.cc +++ b/src/logging_unittest.cc @@ -62,7 +62,7 @@ DECLARE_string(log_backtrace_at); // logging.cc -#ifdef HAVE_LIB_GFLAGS +#ifdef GLOG_USE_GFLAGS #include using namespace GFLAGS_NAMESPACE; #endif @@ -71,28 +71,28 @@ using namespace GFLAGS_NAMESPACE; #include #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"; diff --git a/src/mock-log.h b/src/mock-log.h index a6c11474a..317e0e709 100644 --- a/src/mock-log.h +++ b/src/mock-log.h @@ -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 #include @@ -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,9 +86,9 @@ 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, - const std::string& message)); + MOCK_METHOD3(Log, + void(google::LogSeverity severity, const std::string& file_path, + const std::string& message)); private: // Implements the send() virtual function in class LogSink. @@ -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_ diff --git a/src/mock-log_unittest.cc b/src/mock-log_unittest.cc index b9bef4ea6..f5990d433 100644 --- a/src/mock-log_unittest.cc +++ b/src/mock-log_unittest.cc @@ -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); diff --git a/src/raw_logging.cc b/src/raw_logging.cc index ede534def..d2d78781a 100644 --- a/src/raw_logging.cc +++ b/src/raw_logging.cc @@ -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 diff --git a/src/signalhandler.cc b/src/signalhandler.cc index f53e68719..1788ce94f 100644 --- a/src/signalhandler.cc +++ b/src/signalhandler.cc @@ -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 #include #include @@ -38,15 +39,18 @@ #include "stacktrace.h" #include "symbolize.h" #include "utilities.h" + #ifdef HAVE_UCONTEXT_H # include #endif #ifdef HAVE_SYS_UCONTEXT_H # include #endif -#include +#ifdef HAVE_UNISTD_H +#include +#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 diff --git a/src/signalhandler_unittest.cc b/src/signalhandler_unittest.cc index a110ac54d..1ffa52f78 100644 --- a/src/signalhandler_unittest.cc +++ b/src/signalhandler_unittest.cc @@ -44,12 +44,12 @@ #include "glog/logging.h" -#ifdef HAVE_LIB_GFLAGS +#ifdef GLOG_USE_GFLAGS #include 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(); diff --git a/src/stacktrace.h b/src/stacktrace.h index 3180d30fb..fb851e492 100644 --- a/src/stacktrace.h +++ b/src/stacktrace.h @@ -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_ diff --git a/src/stacktrace_generic-inl.h b/src/stacktrace_generic-inl.h index 0e473a9e8..c07072331 100644 --- a/src/stacktrace_generic-inl.h +++ b/src/stacktrace_generic-inl.h @@ -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 diff --git a/src/stacktrace_libunwind-inl.h b/src/stacktrace_libunwind-inl.h index e59c492a5..b01e37dd0 100644 --- a/src/stacktrace_libunwind-inl.h +++ b/src/stacktrace_libunwind-inl.h @@ -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 diff --git a/src/stacktrace_powerpc-inl.h b/src/stacktrace_powerpc-inl.h index af95adb55..656189368 100644 --- a/src/stacktrace_powerpc-inl.h +++ b/src/stacktrace_powerpc-inl.h @@ -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 diff --git a/src/stacktrace_unittest.cc b/src/stacktrace_unittest.cc index b92961ce3..05f0401f3 100644 --- a/src/stacktrace_unittest.cc +++ b/src/stacktrace_unittest.cc @@ -41,7 +41,7 @@ # include #endif -using namespace GOOGLE_NAMESPACE; +using namespace google; #ifdef HAVE_STACKTRACE diff --git a/src/stacktrace_unwind-inl.h b/src/stacktrace_unwind-inl.h index 5fec1a334..3bdb84f04 100644 --- a/src/stacktrace_unwind-inl.h +++ b/src/stacktrace_unwind-inl.h @@ -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 diff --git a/src/stacktrace_windows-inl.h b/src/stacktrace_windows-inl.h index 9c27664b7..33a1af775 100644 --- a/src/stacktrace_windows-inl.h +++ b/src/stacktrace_windows-inl.h @@ -36,7 +36,7 @@ #include "stacktrace.h" #include -_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(max_depth), result, nullptr); } -_END_GOOGLE_NAMESPACE_ +} // namespace google diff --git a/src/stacktrace_x86-inl.h b/src/stacktrace_x86-inl.h index f7afe8754..d2d51222c 100644 --- a/src/stacktrace_x86-inl.h +++ b/src/stacktrace_x86-inl.h @@ -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 diff --git a/src/striplog_unittest.cc b/src/striplog_unittest.cc index d87a50074..67926ab8c 100644 --- a/src/striplog_unittest.cc +++ b/src/striplog_unittest.cc @@ -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; diff --git a/src/symbolize.cc b/src/symbolize.cc index 9e887cb10..141bdb168 100644 --- a/src/symbolize.cc +++ b/src/symbolize.cc @@ -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 #include -_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 diff --git a/src/symbolize.h b/src/symbolize.h index 89a6a4f25..e26d3e417 100644 --- a/src/symbolize.h +++ b/src/symbolize.h @@ -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_ diff --git a/src/symbolize_unittest.cc b/src/symbolize_unittest.cc index f020ac91a..446a67fbf 100644 --- a/src/symbolize_unittest.cc +++ b/src/symbolize_unittest.cc @@ -41,13 +41,13 @@ #include "googletest.h" #include "utilities.h" -#ifdef HAVE_LIB_GFLAGS +#ifdef GLOG_USE_GFLAGS #include 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. diff --git a/src/utilities.cc b/src/utilities.cc index 5039ae6c6..38f84fee1 100644 --- a/src/utilities.cc +++ b/src/utilities.cc @@ -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 diff --git a/src/utilities.h b/src/utilities.h index e06a308e8..757790764 100644 --- a/src/utilities.h +++ b/src/utilities.h @@ -63,6 +63,19 @@ #include "config.h" +#if defined(HAVE_UNISTD_H) +#include +#endif + +#if !defined(HAVE_SSIZE_T) +#if defined(GLOG_OS_WINDOWS) +#include +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__ diff --git a/src/utilities_unittest.cc b/src/utilities_unittest.cc index c24df00cf..7ce930366 100644 --- a/src/utilities_unittest.cc +++ b/src/utilities_unittest.cc @@ -33,12 +33,12 @@ #include "glog/logging.h" #include "googletest.h" -#ifdef HAVE_LIB_GFLAGS +#ifdef GLOG_USE_GFLAGS #include using namespace GFLAGS_NAMESPACE; #endif -using namespace GOOGLE_NAMESPACE; +using namespace google; TEST(utilities, sync_val_compare_and_swap) { bool now_entering = false; diff --git a/src/vlog_is_on.cc b/src/vlog_is_on.cc index f78fd0777..d4272fe45 100644 --- a/src/vlog_is_on.cc +++ b/src/vlog_is_on.cc @@ -58,7 +58,7 @@ GLOG_DEFINE_string(vmodule, "", "per-module verbose level." " (that is, name ignoring .cc/.h./-inl.h)." " 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