Fix absl log and check headers and deps for port_def.inc

PiperOrigin-RevId: 517013387
pull/12223/head
Martijn Vels 2 years ago committed by Copybara-Service
parent 6ed3b558d2
commit c8572b1de4
  1. 23
      src/google/protobuf/json/internal/parser.cc
  2. 21
      src/google/protobuf/json/internal/unparser.cc
  3. 17
      src/google/protobuf/port_def.inc
  4. 1
      src/google/protobuf/port_undef.inc

@ -45,6 +45,8 @@
#include "google/protobuf/message.h"
#include "absl/base/attributes.h"
#include "absl/container/flat_hash_set.h"
#include "absl/log/absl_check.h"
#include "absl/log/absl_log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/ascii.h"
@ -1302,7 +1304,9 @@ absl::Status ParseMessage(JsonLexer& lex, const Desc<Traits>& desc,
absl::Status JsonStringToMessage(absl::string_view input, Message* message,
json_internal::ParseOptions options) {
MessagePath path(message->GetDescriptor()->full_name());
PROTOBUF_DLOG(INFO) << "json2/input: " << absl::CHexEscape(input);
if (PROTOBUF_DEBUG) {
ABSL_DLOG(INFO) << "json2/input: " << absl::CHexEscape(input);
}
io::ArrayInputStream in(input.data(), input.size());
JsonLexer lex(&in, options, &path);
@ -1315,9 +1319,10 @@ absl::Status JsonStringToMessage(absl::string_view input, Message* message,
"extraneous characters after end of JSON object");
}
PROTOBUF_DLOG(INFO) << "json2/status: " << s;
PROTOBUF_DLOG(INFO) << "json2/output: " << message->DebugString();
if (PROTOBUF_DEBUG) {
ABSL_DLOG(INFO) << "json2/status: " << s;
ABSL_DLOG(INFO) << "json2/output: " << message->DebugString();
}
return s;
}
@ -1350,7 +1355,9 @@ absl::Status JsonToBinaryStream(google::protobuf::util::TypeResolver* resolver,
tee_output.emplace(&out);
}
PROTOBUF_DLOG(INFO) << "json2/input: " << absl::CHexEscape(copy);
if (PROTOBUF_DEBUG) {
ABSL_DLOG(INFO) << "json2/input: " << absl::CHexEscape(copy);
}
// This scope forces the CodedOutputStream inside of `msg` to flush before we
// possibly handle logging the binary protobuf output.
@ -1379,8 +1386,10 @@ absl::Status JsonToBinaryStream(google::protobuf::util::TypeResolver* resolver,
.Append(out.data(), out.size());
}
PROTOBUF_DLOG(INFO) << "json2/status: " << s;
PROTOBUF_DLOG(INFO) << "json2/output: " << absl::BytesToHexString(out);
if (PROTOBUF_DEBUG) {
ABSL_DLOG(INFO) << "json2/status: " << s;
ABSL_DLOG(INFO) << "json2/output: " << absl::BytesToHexString(out);
}
return s;
}
} // namespace json_internal

@ -46,6 +46,7 @@
#include "google/protobuf/dynamic_message.h"
#include "google/protobuf/message.h"
#include "absl/log/absl_check.h"
#include "absl/log/absl_log.h"
#include "absl/status/status.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
@ -854,16 +855,20 @@ absl::Status WriteMessage(JsonWriter& writer, const Msg<Traits>& msg,
absl::Status MessageToJsonString(const Message& message, std::string* output,
json_internal::WriterOptions options) {
PROTOBUF_DLOG(INFO) << "json2/input: " << message.DebugString();
if (PROTOBUF_DEBUG) {
ABSL_DLOG(INFO) << "json2/input: " << message.DebugString();
}
io::StringOutputStream out(output);
JsonWriter writer(&out, options);
absl::Status s = WriteMessage<UnparseProto2Descriptor>(
writer, message, *message.GetDescriptor(), /*is_top_level=*/true);
PROTOBUF_DLOG(INFO) << "json2/status: " << s;
if (PROTOBUF_DEBUG) ABSL_DLOG(INFO) << "json2/status: " << s;
RETURN_IF_ERROR(s);
writer.NewLine();
PROTOBUF_DLOG(INFO) << "json2/output: " << absl::CHexEscape(*output);
if (PROTOBUF_DEBUG) {
ABSL_DLOG(INFO) << "json2/output: " << absl::CHexEscape(*output);
}
return absl::OkStatus();
}
@ -896,7 +901,9 @@ absl::Status BinaryToJsonStream(google::protobuf::util::TypeResolver* resolver,
tee_output.emplace(&out);
}
PROTOBUF_DLOG(INFO) << "json2/input: " << absl::BytesToHexString(copy);
if (PROTOBUF_DEBUG) {
ABSL_DLOG(INFO) << "json2/input: " << absl::BytesToHexString(copy);
}
ResolverPool pool(resolver);
auto desc = pool.FindMessage(type_url);
@ -912,7 +919,7 @@ absl::Status BinaryToJsonStream(google::protobuf::util::TypeResolver* resolver,
absl::Status s = WriteMessage<UnparseProto3Type>(
writer, *msg, UnparseProto3Type::GetDesc(*msg),
/*is_top_level=*/true);
PROTOBUF_DLOG(INFO) << "json2/status: " << s;
if (PROTOBUF_DEBUG) ABSL_DLOG(INFO) << "json2/status: " << s;
RETURN_IF_ERROR(s);
if (PROTOBUF_DEBUG) {
@ -921,7 +928,9 @@ absl::Status BinaryToJsonStream(google::protobuf::util::TypeResolver* resolver,
.Append(out.data(), out.size());
}
PROTOBUF_DLOG(INFO) << "json2/output: " << absl::CHexEscape(out);
if (PROTOBUF_DEBUG) {
ABSL_DLOG(INFO) << "json2/output: " << absl::CHexEscape(out);
}
writer.NewLine();
return absl::OkStatus();

@ -83,6 +83,8 @@
// - MSVC: https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes-history
// https://docs.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes-history
#include <cassert>
// Portable fallbacks for C++20 feature test macros:
// https://en.cppreference.com/w/cpp/feature_test
#ifndef __has_cpp_attribute
@ -622,7 +624,7 @@ static_assert(PROTOBUF_CPLUSPLUS_MIN(201402L), "Protobuf only supports C++14 and
#endif
// PROTOBUF_ASSUME(pred) tells the compiler that it can assume pred is true. To
// be safe, we also validate the assumption with a ABSL_DCHECK in unoptimized
// be safe, we also validate the assumption with an `assert()` in unoptimized
// builds. The macro does not do anything useful if the compiler does not
// support __builtin_assume.
#ifdef PROTOBUF_ASSUME
@ -630,10 +632,10 @@ static_assert(PROTOBUF_CPLUSPLUS_MIN(201402L), "Protobuf only supports C++14 and
#endif
#if __has_builtin(__builtin_assume)
#define PROTOBUF_ASSUME(pred) \
ABSL_DCHECK(pred); \
assert(pred); \
__builtin_assume(pred)
#else
#define PROTOBUF_ASSUME(pred) ABSL_DCHECK(pred)
#define PROTOBUF_ASSUME(pred) assert(pred)
#endif
// Specify memory alignment for structs, classes, etc.
@ -1075,15 +1077,6 @@ static_assert(PROTOBUF_CPLUSPLUS_MIN(201402L), "Protobuf only supports C++14 and
#define PROTOBUF_DEBUG false
#endif
// This `for` allows us to condition the `ABSL_LOG` on the define above, so that
// code can write `PROTOBUF_DLOG(INFO) << ...;` and have it turned off when
// debug logging is off.
//
// This is a `for`, not and `if`, to avoid it accidentally chaining with an
// `else` below it.
#define PROTOBUF_DLOG(x) \
for (bool b = PROTOBUF_DEBUG; b; b = false) ABSL_LOG(x)
#define PROTO2_IS_OSS true
#ifdef PROTOBUF_NO_THREADLOCAL

@ -113,7 +113,6 @@
#undef PROTOBUF_NO_THREAD_SAFETY_ANALYSIS
#undef PROTOBUF_GUARDED_BY
#undef PROTOBUF_DEBUG
#undef PROTOBUF_DLOG
#undef PROTO2_IS_OSS
#undef PROTOBUF_NO_THREADLOCAL

Loading…
Cancel
Save