diff options
Diffstat (limited to 'src/google/protobuf/stubs/common.cc')
-rw-r--r-- | src/google/protobuf/stubs/common.cc | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/src/google/protobuf/stubs/common.cc b/src/google/protobuf/stubs/common.cc index 1e2d68d..a4de636 100644 --- a/src/google/protobuf/stubs/common.cc +++ b/src/google/protobuf/stubs/common.cc @@ -110,13 +110,13 @@ void DefaultLogHandler(LogLevel level, const char* filename, int line, // We use fprintf() instead of cerr because we want this to work at static // initialization time. - fprintf(stderr, "libprotobuf %s %s:%d] %s\n", + fprintf(stderr, "[libprotobuf %s %s:%d] %s\n", level_names[level], filename, line, message.c_str()); fflush(stderr); // Needed on MSVC. } -void NullLogHandler(LogLevel level, const char* filename, int line, - const string& message) { +void NullLogHandler(LogLevel /* level */, const char* /* filename */, + int /* line */, const string& /* message */) { // Nothing. } @@ -183,15 +183,19 @@ void LogMessage::Finish() { if (level_ != LOGLEVEL_FATAL) { InitLogSilencerCountOnce(); MutexLock lock(log_silencer_count_mutex_); - suppress = internal::log_silencer_count_ > 0; + suppress = log_silencer_count_ > 0; } if (!suppress) { - internal::log_handler_(level_, filename_, line_, message_); + log_handler_(level_, filename_, line_, message_); } if (level_ == LOGLEVEL_FATAL) { +#if PROTOBUF_USE_EXCEPTIONS + throw FatalException(filename_, line_, message_); +#else abort(); +#endif } } @@ -316,6 +320,24 @@ void Mutex::AssertHeld() { #endif // =================================================================== +// emulates google3/util/endian/endian.h +// +// TODO(xiaofeng): PROTOBUF_LITTLE_ENDIAN is unfortunately defined in +// google/protobuf/io/coded_stream.h and therefore can not be used here. +// Maybe move that macro definition here in the furture. +uint32 ghtonl(uint32 x) { + union { + uint32 result; + uint8 result_array[4]; + }; + result_array[0] = static_cast<uint8>(x >> 24); + result_array[1] = static_cast<uint8>((x >> 16) & 0xFF); + result_array[2] = static_cast<uint8>((x >> 8) & 0xFF); + result_array[3] = static_cast<uint8>(x & 0xFF); + return result; +} + +// =================================================================== // Shutdown support. namespace internal { @@ -361,5 +383,13 @@ void ShutdownProtobufLibrary() { internal::shutdown_functions_mutex = NULL; } +#if PROTOBUF_USE_EXCEPTIONS +FatalException::~FatalException() throw() {} + +const char* FatalException::what() const throw() { + return message_.c_str(); +} +#endif + } // namespace protobuf } // namespace google |