Skip to content

Commit

Permalink
fix: cleanup exports (#1029)
Browse files Browse the repository at this point in the history
Reduce unnecessary utility function exports.
  • Loading branch information
sergiud authored Jan 4, 2024
1 parent e1f424a commit dfce35c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 32 deletions.
2 changes: 2 additions & 0 deletions bazel/glog.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def glog_library(with_gflags = 1, **kwargs):

linux_or_darwin_copts = wasm_copts + [
"-DGLOG_EXPORT=__attribute__((visibility(\\\"default\\\")))",
"-DGLOG_NO_EXPORT=__attribute__((visibility(\\\"default\\\")))",
"-DHAVE_MODE_T",
"-DHAVE_SSIZE_T",
"-DHAVE_SYS_TYPES_H",
Expand Down Expand Up @@ -101,6 +102,7 @@ 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",
"-DHAVE__CHSIZE_S",
"-I" + src_windows,
Expand Down
10 changes: 7 additions & 3 deletions src/glog/log_severity.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ enum LogSeverity {

#if defined(__cpp_inline_variables)
# if (__cpp_inline_variables >= 201606L)
inline
# define GLOG_INLINE_VARIABLE inline
# endif // (__cpp_inline_variables >= 201606L)
#endif // defined(__cpp_inline_variables)
// clang-format off

#if !defined(GLOG_INLINE_VARIABLE)
# define GLOG_INLINE_VARIABLE
#endif // !defined(GLOG_INLINE_VARIABLE)

GLOG_INLINE_VARIABLE
constexpr int NUM_SEVERITIES = 4;
// clang-format on

// DFATAL is FATAL in debug mode, ERROR in normal mode
#ifdef NDEBUG
Expand Down
30 changes: 5 additions & 25 deletions src/glog/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,8 @@ GLOG_EXPORT bool IsFailureSignalHandlerInstalled();
google::LogMessage::SendToLog)

// We want the special COUNTER value available for LOG_EVERY_X()'ed messages
enum PRIVATE_Counter { COUNTER };
struct Counter_t {};
GLOG_INLINE_VARIABLE constexpr Counter_t COUNTER{};

#ifdef GLOG_NO_ABBREVIATED_SEVERITIES
// wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets
Expand All @@ -1173,7 +1174,8 @@ enum PRIVATE_Counter { COUNTER };
# define SYSLOG_0 SYSLOG_ERROR
# define LOG_TO_STRING_0 LOG_TO_STRING_ERROR
// Needed for LOG_IS_ON(ERROR).
const LogSeverity GLOG_0 = GLOG_ERROR;
GLOG_INLINE_VARIABLE
constexpr LogSeverity GLOG_0 = GLOG_ERROR;
#else
// Users may include windows.h after logging.h without
// GLOG_NO_ABBREVIATED_SEVERITIES nor WIN32_LEAN_AND_MEAN.
Expand Down Expand Up @@ -1556,7 +1558,7 @@ T CheckNotNull(const char* file, int line, const char* names, T&& t) {
// Allow folks to put a counter in the LOG_EVERY_X()'ed messages. This
// only works if ostream is a LogStream. If the ostream is not a
// LogStream you'll get an assert saying as much at runtime.
GLOG_EXPORT std::ostream& operator<<(std::ostream& os, const PRIVATE_Counter&);
GLOG_EXPORT std::ostream& operator<<(std::ostream& os, const Counter_t&);

// Derived class for PLOG*() above.
class GLOG_EXPORT ErrnoLogMessage : public LogMessage {
Expand Down Expand Up @@ -1694,11 +1696,6 @@ GLOG_EXPORT bool SendEmail(const char* dest, const char* subject,

GLOG_EXPORT const std::vector<std::string>& GetLoggingDirectories();

// Returns a set of existing temporary directories, which will be a
// subset of the directories returned by GetLoggingDirectories().
// Thread-safe.
GLOG_EXPORT void GetExistingTempDirectories(std::vector<std::string>* list);

// Print any fatal message again -- useful to call from signal handler
// so that the last thing in the output is the fatal message.
// Thread-hostile, but a race is unlikely.
Expand Down Expand Up @@ -1771,23 +1768,6 @@ 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
// version that we want, but it is not clear whether it even works with
// all versions of glibc.
// So, instead, we provide this wrapper that automatically detects the
// version that is in use, and then implements POSIX semantics.
// N.B. In addition to what POSIX says, we also guarantee that "buf" will
// be set to an empty string, if this function failed. This means, in most
// 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);

// A thread-safe replacement for strerror(). Returns a string describing the
// given POSIX error code.
GLOG_EXPORT std::string StrError(int err);

// A class for which we define operator<<, which does nothing.
class GLOG_EXPORT NullStream : public LogMessage::LogStream {
public:
Expand Down
7 changes: 4 additions & 3 deletions src/googletest.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ using std::string;
using std::vector;

namespace google {

extern GLOG_EXPORT void (*g_logging_fail_func)();

extern void (*g_logging_fail_func)();
extern void GetExistingTempDirectories(vector<string>* list);
extern int posix_strerror_r(int err, char* buf, size_t len);
extern std::string StrError(int err);
}

#undef GLOG_EXPORT
Expand Down
23 changes: 22 additions & 1 deletion src/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ static bool TerminalSupportsColor() {

namespace google {

std::string StrError(int err);

enum GLogColor { COLOR_DEFAULT, COLOR_RED, COLOR_GREEN, COLOR_YELLOW };

static GLogColor SeverityToColor(LogSeverity severity) {
Expand Down Expand Up @@ -2051,7 +2053,7 @@ int64 LogMessage::num_messages(int severity) {

// Output the COUNTER value. This is only valid if ostream is a
// LogStream.
ostream& operator<<(ostream& os, const PRIVATE_Counter&) {
ostream& operator<<(ostream& os, const Counter_t&) {
#ifdef DISABLE_RTTI
LogMessage::LogStream* log = static_cast<LogMessage::LogStream*>(&os);
#else
Expand Down Expand Up @@ -2435,6 +2437,10 @@ const vector<string>& GetLoggingDirectories() {
return *logging_directories_list;
}

// Returns a set of existing temporary directories, which will be a
// subset of the directories returned by GetLoggingDirectories().
// Thread-safe.
GLOG_NO_EXPORT
void GetExistingTempDirectories(vector<string>* list) {
GetTempDirectories(list);
auto i_dir = list->begin();
Expand Down Expand Up @@ -2567,6 +2573,18 @@ DEFINE_CHECK_STROP_IMPL(CHECK_STRCASEEQ, strcasecmp, true)
DEFINE_CHECK_STROP_IMPL(CHECK_STRCASENE, strcasecmp, false)
#undef DEFINE_CHECK_STROP_IMPL

// glibc has traditionally implemented two incompatible versions of
// strerror_r(). There is a poorly defined convention for picking the
// version that we want, but it is not clear whether it even works with
// all versions of glibc.
// So, instead, we provide this wrapper that automatically detects the
// version that is in use, and then implements POSIX semantics.
// N.B. In addition to what POSIX says, we also guarantee that "buf" will
// be set to an empty string, if this function failed. This means, in most
// 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_NO_EXPORT
int posix_strerror_r(int err, char* buf, size_t len) {
// Sanity check input parameters
if (buf == nullptr || len <= 0) {
Expand Down Expand Up @@ -2618,6 +2636,9 @@ 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.
GLOG_NO_EXPORT
string StrError(int err) {
char buf[100];
int rc = posix_strerror_r(err, buf, sizeof(buf));
Expand Down

0 comments on commit dfce35c

Please sign in to comment.