Skip to content

Commit ff24053

Browse files
rwgkcopybara-github
authored andcommitted
Use dynamic_cast<const ProtoType *> instead of static_cast.
PiperOrigin-RevId: 568932318
1 parent e9d7a6b commit ff24053

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pybind11_protobuf/proto_caster_impl.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ struct proto_caster_load_impl {
5252
// from the object.
5353
const ::google::protobuf::Message *message =
5454
pybind11_protobuf::PyProtoGetCppMessagePointer(src);
55-
if (message && message->GetReflection() ==
56-
ProtoType::default_instance().GetReflection()) {
57-
// If the capability were available, then we could probe PyProto_API and
58-
// allow c++ mutability based on the python reference count.
59-
value = static_cast<const ProtoType *>(message);
60-
return true;
55+
if (message) {
56+
value = dynamic_cast<const ProtoType *>(message);
57+
if (value) {
58+
// If the capability were available, then we could probe PyProto_API and
59+
// allow c++ mutability based on the python reference count.
60+
return true;
61+
}
6162
}
6263

6364
// The incoming object is not a compatible fast_cpp_proto, so check whether

0 commit comments

Comments
 (0)