Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from DownCastToGenerated to DownCastMessage #250

Merged
merged 2 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmake/external/protobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ list(APPEND PROTOBUF_LIBRARIES
absl_examine_stack
absl_exponential_biased
absl_failure_signal_handler
absl_flags
absl_flags_commandlineflag
absl_flags_commandlineflag_internal
absl_flags_config
Expand Down Expand Up @@ -153,7 +152,7 @@ include (ExternalProject)
ExternalProject_Add(${PROTOBUF_TARGET}
PREFIX ${PROTOBUF_TARGET}
GIT_REPOSITORY https://github.com/google/protobuf.git
GIT_TAG v25.2
GIT_TAG v27.1
UPDATE_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND} ${PROTOBUF_INSTALL_DIR}/src/${PROTOBUF_TARGET}
-G${CMAKE_GENERATOR}
Expand Down
23 changes: 17 additions & 6 deletions port/protobuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,36 @@
// clang-format off
#include "google/protobuf/port_def.inc" // MUST be last header included
// clang-format on
#if PROTOBUF_VERSION < 4025000

namespace google {
namespace protobuf {
#if PROTOBUF_VERSION < 4025000

template <typename T>
const T* DownCastToGenerated(const Message* message) {
const T* DownCastMessage(const Message* message) {
return static_cast<const T*>(message);
}

template <typename T>
T* DownCastToGenerated(Message* message) {
T* DownCastMessage(Message* message) {
const Message* message_const = message;
return const_cast<T*>(DownCastToGenerated<T>(message_const));
return const_cast<T*>(DownCastMessage<T>(message_const));
}

#elif PROTOBUF_VERSION < 5029000

template <typename T>
const T* DownCastMessage(const Message* message) {
return DownCastToGenerated<T>(message);
}

template <typename T>
T* DownCastMessage(Message* message) {
return DownCastToGenerated<T>(message);
}

#endif // PROTOBUF_VERSION
} // namespace protobuf
} // namespace google
#endif // PROTOBUF_VERSION
#include "google/protobuf/port_undef.inc"


Expand Down
2 changes: 1 addition & 1 deletion src/libfuzzer/libfuzzer_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct PostProcessorRegistration {
RegisterPostProcessor(
Proto::descriptor(),
[callback](protobuf::Message* message, unsigned int seed) {
callback(protobuf::DownCastToGenerated<Proto>(message), seed);
callback(protobuf::DownCastMessage<Proto>(message), seed);
});
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/mutator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,13 @@ std::unique_ptr<Message> UnpackAny(const Any& any) {

const Any* CastToAny(const Message* message) {
return Any::GetDescriptor() == message->GetDescriptor()
? protobuf::DownCastToGenerated<Any>(message)
? protobuf::DownCastMessage<Any>(message)
: nullptr;
}

Any* CastToAny(Message* message) {
return Any::GetDescriptor() == message->GetDescriptor()
? protobuf::DownCastToGenerated<Any>(message)
? protobuf::DownCastMessage<Any>(message)
: nullptr;
}

Expand Down
4 changes: 2 additions & 2 deletions src/mutator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace protobuf_mutator {

using protobuf::DownCastToGenerated;
using protobuf::DownCastMessage;
using protobuf::util::MessageDifferencer;
using testing::TestWithParam;
using testing::ValuesIn;
Expand Down Expand Up @@ -623,7 +623,7 @@ TYPED_TEST(MutatorTypedTest, RegisterPostProcessor) {
TestFixture::Message::descriptor(),
[=](protobuf::Message* message, unsigned int seed) {
auto test_message =
DownCastToGenerated<typename TestFixture::Message>(message);
DownCastMessage<typename TestFixture::Message>(message);
if (seed % 2) test_message->set_optional_string(v);
});
}
Expand Down
Loading