diff --git a/rust/cpp_kernel/cpp_api.cc b/rust/cpp_kernel/cpp_api.cc index 0536b9356b..a71db58e65 100644 --- a/rust/cpp_kernel/cpp_api.cc +++ b/rust/cpp_kernel/cpp_api.cc @@ -1,5 +1,6 @@ #include "rust/cpp_kernel/cpp_api.h" +#include #include #include @@ -33,8 +34,8 @@ extern "C" { return r->Set(index, val); \ } \ void __pb_rust_RepeatedField_##rust_ty##_copy_from( \ - google::protobuf::RepeatedField const& src, google::protobuf::RepeatedField& dst) { \ - dst.CopyFrom(src); \ + const google::protobuf::RepeatedField* src, google::protobuf::RepeatedField* dst) { \ + dst->CopyFrom(*src); \ } \ void __pb_rust_RepeatedField_##rust_ty##_clear( \ google::protobuf::RepeatedField* r) { \ @@ -63,7 +64,7 @@ expose_repeated_field_methods(int64_t, i64); m->clear(); \ } \ size_t __pb_rust_Map_##rust_key_ty##_##rust_value_ty##_size( \ - google::protobuf::Map* m) { \ + const google::protobuf::Map* m) { \ return m->size(); \ } \ void __pb_rust_Map_##rust_key_ty##_##rust_value_ty##_insert( \ @@ -73,7 +74,8 @@ expose_repeated_field_methods(int64_t, i64); (*m)[cpp_key] = cpp_value; \ } \ bool __pb_rust_Map_##rust_key_ty##_##rust_value_ty##_get( \ - google::protobuf::Map* m, ffi_key_ty key, ffi_value_ty* value) { \ + const google::protobuf::Map* m, ffi_key_ty key, \ + ffi_value_ty* value) { \ auto cpp_key = to_cpp_key; \ auto it = m->find(cpp_key); \ if (it == m->end()) { \ diff --git a/src/google/protobuf/compiler/rust/accessors/map.cc b/src/google/protobuf/compiler/rust/accessors/map.cc index 89535d40e2..633e21cfda 100644 --- a/src/google/protobuf/compiler/rust/accessors/map.cc +++ b/src/google/protobuf/compiler/rust/accessors/map.cc @@ -135,8 +135,8 @@ void Map::InThunkCc(Context& ctx, const FieldDescriptor& field) const { [&] { ctx.Emit( R"cc( - const void* $getter_thunk$($QualifiedMsg$& msg) { - return &msg.$field$(); + const void* $getter_thunk$(const $QualifiedMsg$* msg) { + return &msg->$field$(); } void* $getter_mut_thunk$($QualifiedMsg$* msg) { return msg->mutable_$field$(); } )cc"); diff --git a/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc b/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc index e0e1c6cffc..9b26784384 100644 --- a/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc @@ -150,8 +150,9 @@ void RepeatedScalar::InThunkCc(Context& ctx, google::protobuf::RepeatedField<$Scalar$>* $getter_mut_thunk$($QualifiedMsg$* msg) { return msg->mutable_$field$(); } - const google::protobuf::RepeatedField<$Scalar$>& $getter_thunk$($QualifiedMsg$& msg) { - return msg.$field$(); + const google::protobuf::RepeatedField<$Scalar$>* $getter_thunk$( + const $QualifiedMsg$* msg) { + return &msg->$field$(); } )cc"); }}},