Index: third_party/protobuf/src/google/protobuf/stubs/common.cc |
diff --git a/third_party/protobuf/src/google/protobuf/stubs/common.cc b/third_party/protobuf/src/google/protobuf/stubs/common.cc |
index e6045026774246225433ac84a1eb0eb12e92f099..54dbafab5dcaca22cc2658a1682b5ef553dff595 100644 |
--- a/third_party/protobuf/src/google/protobuf/stubs/common.cc |
+++ b/third_party/protobuf/src/google/protobuf/stubs/common.cc |
@@ -1,6 +1,6 @@ |
// Protocol Buffers - Google's data interchange format |
// Copyright 2008 Google Inc. All rights reserved. |
-// http://code.google.com/p/protobuf/ |
+// https://developers.google.com/protocol-buffers/ |
// |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
@@ -32,12 +32,15 @@ |
#include <google/protobuf/stubs/common.h> |
#include <google/protobuf/stubs/once.h> |
-#include <stdio.h> |
+#include <google/protobuf/stubs/status.h> |
+#include <google/protobuf/stubs/stringpiece.h> |
+#include <google/protobuf/stubs/strutil.h> |
+#include <google/protobuf/stubs/int128.h> |
#include <errno.h> |
+#include <sstream> |
+#include <stdio.h> |
#include <vector> |
-#include "config.h" |
- |
#ifdef _WIN32 |
#define WIN32_LEAN_AND_MEAN // We only need minimal includes |
#include <windows.h> |
@@ -47,6 +50,9 @@ |
#else |
#error "No suitable threading library available." |
#endif |
+#if defined(__ANDROID__) |
+#include <android/log.h> |
+#endif |
namespace google { |
namespace protobuf { |
@@ -103,7 +109,43 @@ string VersionString(int version) { |
// emulates google3/base/logging.cc |
namespace internal { |
+#if defined(__ANDROID__) |
+inline void DefaultLogHandler(LogLevel level, const char* filename, int line, |
+ const string& message) { |
+#ifdef GOOGLE_PROTOBUF_MIN_LOG_LEVEL |
+ if (level < GOOGLE_PROTOBUF_MIN_LOG_LEVEL) { |
+ return; |
+ } |
+ static const char* level_names[] = {"INFO", "WARNING", "ERROR", "FATAL"}; |
+ static const int android_log_levels[] = { |
+ ANDROID_LOG_INFO, // LOG(INFO), |
+ ANDROID_LOG_WARN, // LOG(WARNING) |
+ ANDROID_LOG_ERROR, // LOG(ERROR) |
+ ANDROID_LOG_FATAL, // LOG(FATAL) |
+ }; |
+ |
+ // Bound the logging level. |
+ const int android_log_level = android_log_levels[level]; |
+ ::std::ostringstream ostr; |
+ ostr << "[libprotobuf " << level_names[level] << " " << filename << ":" |
+ << line << "] " << message.c_str(); |
+ |
+ // Output the log string the Android log at the appropriate level. |
+ __android_log_write(android_log_level, "libprotobuf-native", |
+ ostr.str().c_str()); |
+ // Also output to std::cerr. |
+ fprintf(stderr, "%s", ostr.str().c_str()); |
+ fflush(stderr); |
+ |
+ // Indicate termination if needed. |
+ if (android_log_level == ANDROID_LOG_FATAL) { |
+ __android_log_write(ANDROID_LOG_FATAL, "libprotobuf-native", |
+ "terminating.\n"); |
+ } |
+#endif |
+} |
+#else |
void DefaultLogHandler(LogLevel level, const char* filename, int line, |
const string& message) { |
static const char* level_names[] = { "INFO", "WARNING", "ERROR", "FATAL" }; |
@@ -114,9 +156,10 @@ void DefaultLogHandler(LogLevel level, const char* filename, int line, |
level_names[level], filename, line, message.c_str()); |
fflush(stderr); // Needed on MSVC. |
} |
+#endif |
-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. |
} |
@@ -148,6 +191,24 @@ LogMessage& LogMessage::operator<<(const char* value) { |
return *this; |
} |
+LogMessage& LogMessage::operator<<(const StringPiece& value) { |
+ message_ += value.ToString(); |
+ return *this; |
+} |
+ |
+LogMessage& LogMessage::operator<<( |
+ const ::google::protobuf::util::Status& status) { |
+ message_ += status.ToString(); |
+ return *this; |
+} |
+ |
+LogMessage& LogMessage::operator<<(const uint128& value) { |
+ std::ostringstream str; |
+ str << value; |
+ message_ += str.str(); |
+ return *this; |
+} |
+ |
// Since this is just for logging, we don't care if the current locale changes |
// the results -- in fact, we probably prefer that. So we use snprintf() |
// instead of Simple*toa(). |
@@ -167,10 +228,13 @@ LogMessage& LogMessage::operator<<(const char* value) { |
DECLARE_STREAM_OPERATOR(char , "%c" ) |
DECLARE_STREAM_OPERATOR(int , "%d" ) |
-DECLARE_STREAM_OPERATOR(uint , "%u" ) |
+DECLARE_STREAM_OPERATOR(unsigned int , "%u" ) |
DECLARE_STREAM_OPERATOR(long , "%ld") |
DECLARE_STREAM_OPERATOR(unsigned long, "%lu") |
DECLARE_STREAM_OPERATOR(double , "%g" ) |
+DECLARE_STREAM_OPERATOR(void* , "%p" ) |
+DECLARE_STREAM_OPERATOR(long long , "%" GOOGLE_LL_FORMAT "d") |
+DECLARE_STREAM_OPERATOR(unsigned long long, "%" GOOGLE_LL_FORMAT "u") |
#undef DECLARE_STREAM_OPERATOR |
LogMessage::LogMessage(LogLevel level, const char* filename, int line) |