Skip to content

Commit

Permalink
fix: better encapsulate internals
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiud committed Jan 9, 2024
1 parent 2b5a53c commit ab9e571
Show file tree
Hide file tree
Showing 31 changed files with 389 additions and 265 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ check_type_size (ssize_t HAVE_SSIZE_T LANGUAGE CXX)

check_cxx_symbol_exists (dladdr dlfcn.h HAVE_DLADDR)
check_cxx_symbol_exists (fcntl fcntl.h HAVE_FCNTL)
check_cxx_symbol_exists (posix_fadvise fcntl.h HAVE_POSIX_FADVISE)
check_cxx_symbol_exists (pread unistd.h HAVE_PREAD)
check_cxx_symbol_exists (pwrite unistd.h HAVE_PWRITE)
check_cxx_symbol_exists (sigaction csignal HAVE_SIGACTION)
Expand Down Expand Up @@ -364,6 +365,8 @@ set (GLOG_SRCS
src/logging.cc
src/raw_logging.cc
src/signalhandler.cc
src/stacktrace.cc
src/stacktrace.h
src/symbolize.cc
src/symbolize.h
src/utilities.cc
Expand Down
14 changes: 9 additions & 5 deletions bazel/glog.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ def glog_library(with_gflags = 1, **kwargs):

common_copts = [
"-std=c++14",
"-DGLOG_BAZEL_BUILD",
"-DHAVE_STRING_H",
"-I%s/glog_internal" % gendir,
] + (["-DGLOG_USE_GFLAGS"] if with_gflags else [])

Expand All @@ -74,6 +72,7 @@ def glog_library(with_gflags = 1, **kwargs):
"-DGLOG_EXPORT=__attribute__((visibility(\\\"default\\\")))",
"-DGLOG_NO_EXPORT=__attribute__((visibility(\\\"default\\\")))",
"-DHAVE_MODE_T",
"-DHAVE_POSIX_FADVISE",
"-DHAVE_SSIZE_T",
"-DHAVE_SYS_TYPES_H",
# For src/utilities.cc.
Expand Down Expand Up @@ -102,10 +101,11 @@ def glog_library(with_gflags = 1, **kwargs):
windows_only_copts = [
# Override -DGLOG_EXPORT= from the cc_library's defines.
"-DGLOG_EXPORT=__declspec(dllexport)",
"-DGLOG_NO_EXPORT=",
"-DGLOG_NO_ABBREVIATED_SEVERITIES",
"-DGLOG_NO_EXPORT=",
"-DGLOG_USE_WINDOWS_PORT",
"-DHAVE__CHSIZE_S",
"-DHAVE_DBGHELP",
"-I" + src_windows,
]

Expand All @@ -115,7 +115,6 @@ def glog_library(with_gflags = 1, **kwargs):
]

windows_only_srcs = [
"src/glog/log_severity.h",
"src/windows/dirent.h",
"src/windows/port.cc",
"src/windows/port.h",
Expand All @@ -127,13 +126,15 @@ def glog_library(with_gflags = 1, **kwargs):
# GLOG_EXPORT is normally set by export.h, but that's not
# generated for Bazel.
"@bazel_tools//src/conditions:windows": [
"GLOG_EXPORT=",
"GLOG_DEPRECATED=__declspec(deprecated)",
"GLOG_EXPORT=",
"GLOG_NO_ABBREVIATED_SEVERITIES",
"GLOG_NO_EXPORT=",
],
"//conditions:default": [
"GLOG_DEPRECATED=__attribute__((deprecated))",
"GLOG_EXPORT=__attribute__((visibility(\\\"default\\\")))",
"GLOG_NO_EXPORT=__attribute__((visibility(\\\"default\\\")))",
],
})

Expand Down Expand Up @@ -171,6 +172,8 @@ def glog_library(with_gflags = 1, **kwargs):
"src/logging.cc",
"src/raw_logging.cc",
"src/signalhandler.cc",
"src/stacktrace.cc",
"src/stacktrace.h",
"src/stacktrace_generic-inl.h",
"src/stacktrace_libunwind-inl.h",
"src/stacktrace_powerpc-inl.h",
Expand All @@ -180,6 +183,7 @@ def glog_library(with_gflags = 1, **kwargs):
"src/symbolize.cc",
"src/symbolize.h",
"src/utilities.cc",
"src/utilities.h",
"src/vlog_is_on.cc",
] + select({
"@bazel_tools//src/conditions:windows": windows_only_srcs,
Expand Down
3 changes: 3 additions & 0 deletions src/config.h.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
/* Define if you have the 'pread' function */
#cmakedefine HAVE_PREAD

/* Define if you have the 'posix_fadvise' function in <fcntl.h> */
#cmakedefine HAVE_POSIX_FADVISE

/* Define to 1 if you have the <pwd.h> header file. */
#cmakedefine HAVE_PWD_H

Expand Down
3 changes: 2 additions & 1 deletion src/demangle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "demangle.h"

#include <algorithm>
#include <cstddef>
#include <cstdlib>
#include <limits>

Expand All @@ -52,6 +51,7 @@
#endif

namespace google {
inline namespace glog_internal_namespace_ {

#if !defined(GLOG_OS_WINDOWS) && !defined(HAVE___CXA_DEMANGLE)
namespace {
Expand Down Expand Up @@ -1359,4 +1359,5 @@ bool Demangle(const char* mangled, char* out, size_t out_size) {
#endif
}

} // namespace glog_internal_namespace_
} // namespace google
21 changes: 15 additions & 6 deletions src/demangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,28 @@
// C++ ABI in the future.
//

#ifndef BASE_DEMANGLE_H_
#define BASE_DEMANGLE_H_
#ifndef GLOG_INTERNAL_DEMANGLE_H
#define GLOG_INTERNAL_DEMANGLE_H

#include "config.h"
#include "glog/logging.h"
#include <cstddef>

#if defined(GLOG_USE_GLOG_EXPORT)
# include "glog/export.h"
#endif

#if !defined(GLOG_NO_EXPORT)
# error "demangle.h" was not included correctly.
#endif

namespace google {
inline namespace glog_internal_namespace_ {

// 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);
bool GLOG_NO_EXPORT Demangle(const char* mangled, char* out, size_t out_size);

} // namespace glog_internal_namespace_
} // namespace google

#endif // BASE_DEMANGLE_H_
#endif // GLOG_INTERNAL_DEMANGLE_H
2 changes: 0 additions & 2 deletions src/glog/log_severity.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ constexpr int NUM_SEVERITIES = 4;
# define DFATAL_LEVEL FATAL
#endif

extern GLOG_EXPORT const char* const LogSeverityNames[NUM_SEVERITIES];

// NDEBUG usage helpers related to (RAW_)DCHECK:
//
// DEBUG_MODE is for small !NDEBUG uses like
Expand Down
Loading

0 comments on commit ab9e571

Please sign in to comment.