From c07de7c9dfa72d5b0169d1e4319449577576c02d Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 2 Jul 2024 11:42:07 -0700 Subject: [PATCH] Change to proto2_rust C prefix and proto2::rust C++ namespace PiperOrigin-RevId: 648791688 --- rust/cpp.rs | 66 ++++---- rust/cpp_kernel/debug.cc | 8 +- rust/cpp_kernel/debug.h | 4 +- rust/cpp_kernel/map.cc | 10 +- rust/cpp_kernel/map.h | 24 +-- rust/cpp_kernel/repeated.cc | 149 +++++++++--------- rust/cpp_kernel/rust_alloc_for_cpp_api.h | 2 +- rust/cpp_kernel/rust_alloc_for_cpp_api.rs | 2 +- rust/cpp_kernel/serialized_data.h | 6 +- rust/cpp_kernel/strings.cc | 6 +- rust/cpp_kernel/strings.h | 4 +- rust/test/cpp/interop/test_utils.cc | 6 +- .../rust/accessors/singular_string.cc | 6 +- src/google/protobuf/compiler/rust/message.cc | 6 +- src/google/protobuf/compiler/rust/naming.cc | 12 +- 15 files changed, 155 insertions(+), 156 deletions(-) diff --git a/rust/cpp.rs b/rust/cpp.rs index 49b292c5ff..1a96a95a8d 100644 --- a/rust/cpp.rs +++ b/rust/cpp.rs @@ -261,17 +261,17 @@ impl From for String { } extern "C" { - fn rust_proto_utf8_debug_string(msg: RawMessage) -> RustStringRawParts; - fn rust_proto_utf8_debug_string_lite(msg: RawMessage) -> RustStringRawParts; + fn proto2_rust_utf8_debug_string(msg: RawMessage) -> RustStringRawParts; + fn proto2_rust_utf8_debug_string_lite(msg: RawMessage) -> RustStringRawParts; } pub fn debug_string(_private: Private, msg: RawMessage, f: &mut fmt::Formatter<'_>) -> fmt::Result { // SAFETY: // - `msg` is a valid protobuf message. #[cfg(not(lite_runtime))] - let dbg_str: String = unsafe { rust_proto_utf8_debug_string(msg) }.into(); + let dbg_str: String = unsafe { proto2_rust_utf8_debug_string(msg) }.into(); #[cfg(lite_runtime)] - let dbg_str: String = unsafe { rust_proto_utf8_debug_string_lite(msg) }.into(); + let dbg_str: String = unsafe { proto2_rust_utf8_debug_string_lite(msg) }.into(); write!(f, "{dbg_str}") } @@ -485,15 +485,15 @@ macro_rules! impl_repeated_primitives { paste!{ impl_repeated_primitives!(@impl $( $t => [ - [< rust_proto_RepeatedField_ $t _new >], - [< rust_proto_RepeatedField_ $t _free >], - [< rust_proto_RepeatedField_ $t _add >], - [< rust_proto_RepeatedField_ $t _size >], - [< rust_proto_RepeatedField_ $t _get >], - [< rust_proto_RepeatedField_ $t _set >], - [< rust_proto_RepeatedField_ $t _clear >], - [< rust_proto_RepeatedField_ $t _copy_from >], - [< rust_proto_RepeatedField_ $t _reserve >], + [< proto2_rust_RepeatedField_ $t _new >], + [< proto2_rust_RepeatedField_ $t _free >], + [< proto2_rust_RepeatedField_ $t _add >], + [< proto2_rust_RepeatedField_ $t _size >], + [< proto2_rust_RepeatedField_ $t _get >], + [< proto2_rust_RepeatedField_ $t _set >], + [< proto2_rust_RepeatedField_ $t _clear >], + [< proto2_rust_RepeatedField_ $t _copy_from >], + [< proto2_rust_RepeatedField_ $t _reserve >], ], )*); } @@ -644,7 +644,7 @@ impl UntypedMapIterator { // - Standard layout. // - The size and alignment of the Rust type above. // - With the `node_` field first. - unsafe { rust_proto_thunk_UntypedMapIterator_increment(self) } + unsafe { proto2_rust_thunk_UntypedMapIterator_increment(self) } // SAFETY: // - The `get` function always writes valid values to `ffi_key` and `ffi_value` @@ -656,22 +656,22 @@ impl UntypedMapIterator { } extern "C" { - fn rust_proto_thunk_UntypedMapIterator_increment(iter: &mut UntypedMapIterator); + fn proto2_rust_thunk_UntypedMapIterator_increment(iter: &mut UntypedMapIterator); } macro_rules! impl_ProxiedInMapValue_for_non_generated_value_types { ($key_t:ty, $ffi_key_t:ty, $to_ffi_key:expr, $from_ffi_key:expr, for $($t:ty, $ffi_t:ty, $to_ffi_value:expr, $from_ffi_value:expr;)*) => { paste! { $( extern "C" { - fn [< rust_proto_thunk_Map_ $key_t _ $t _new >]() -> RawMap; - fn [< rust_proto_thunk_Map_ $key_t _ $t _free >](m: RawMap); - fn [< rust_proto_thunk_Map_ $key_t _ $t _clear >](m: RawMap); - fn [< rust_proto_thunk_Map_ $key_t _ $t _size >](m: RawMap) -> usize; - fn [< rust_proto_thunk_Map_ $key_t _ $t _insert >](m: RawMap, key: $ffi_key_t, value: $ffi_t) -> bool; - fn [< rust_proto_thunk_Map_ $key_t _ $t _get >](m: RawMap, key: $ffi_key_t, value: *mut $ffi_t) -> bool; - fn [< rust_proto_thunk_Map_ $key_t _ $t _iter >](m: RawMap) -> UntypedMapIterator; - fn [< rust_proto_thunk_Map_ $key_t _ $t _iter_get >](iter: &mut UntypedMapIterator, key: *mut $ffi_key_t, value: *mut $ffi_t); - fn [< rust_proto_thunk_Map_ $key_t _ $t _remove >](m: RawMap, key: $ffi_key_t, value: *mut $ffi_t) -> bool; + fn [< proto2_rust_thunk_Map_ $key_t _ $t _new >]() -> RawMap; + fn [< proto2_rust_thunk_Map_ $key_t _ $t _free >](m: RawMap); + fn [< proto2_rust_thunk_Map_ $key_t _ $t _clear >](m: RawMap); + fn [< proto2_rust_thunk_Map_ $key_t _ $t _size >](m: RawMap) -> usize; + fn [< proto2_rust_thunk_Map_ $key_t _ $t _insert >](m: RawMap, key: $ffi_key_t, value: $ffi_t) -> bool; + fn [< proto2_rust_thunk_Map_ $key_t _ $t _get >](m: RawMap, key: $ffi_key_t, value: *mut $ffi_t) -> bool; + fn [< proto2_rust_thunk_Map_ $key_t _ $t _iter >](m: RawMap) -> UntypedMapIterator; + fn [< proto2_rust_thunk_Map_ $key_t _ $t _iter_get >](iter: &mut UntypedMapIterator, key: *mut $ffi_key_t, value: *mut $ffi_t); + fn [< proto2_rust_thunk_Map_ $key_t _ $t _remove >](m: RawMap, key: $ffi_key_t, value: *mut $ffi_t) -> bool; } impl ProxiedInMapValue<$key_t> for $t { @@ -680,7 +680,7 @@ macro_rules! impl_ProxiedInMapValue_for_non_generated_value_types { Map::from_inner( Private, InnerMap { - raw: [< rust_proto_thunk_Map_ $key_t _ $t _new >](), + raw: [< proto2_rust_thunk_Map_ $key_t _ $t _new >](), } ) } @@ -690,28 +690,28 @@ macro_rules! impl_ProxiedInMapValue_for_non_generated_value_types { // SAFETY: // - `map.inner.raw` is a live `RawMap` // - This function is only called once for `map` in `Drop`. - unsafe { [< rust_proto_thunk_Map_ $key_t _ $t _free >](map.as_mut().as_raw(Private)); } + unsafe { [< proto2_rust_thunk_Map_ $key_t _ $t _free >](map.as_mut().as_raw(Private)); } } fn map_clear(mut map: Mut<'_, Map<$key_t, Self>>) { - unsafe { [< rust_proto_thunk_Map_ $key_t _ $t _clear >](map.as_raw(Private)); } + unsafe { [< proto2_rust_thunk_Map_ $key_t _ $t _clear >](map.as_raw(Private)); } } fn map_len(map: View<'_, Map<$key_t, Self>>) -> usize { - unsafe { [< rust_proto_thunk_Map_ $key_t _ $t _size >](map.as_raw(Private)) } + unsafe { [< proto2_rust_thunk_Map_ $key_t _ $t _size >](map.as_raw(Private)) } } fn map_insert(mut map: Mut<'_, Map<$key_t, Self>>, key: View<'_, $key_t>, value: View<'_, Self>) -> bool { let ffi_key = $to_ffi_key(key); let ffi_value = $to_ffi_value(value); - unsafe { [< rust_proto_thunk_Map_ $key_t _ $t _insert >](map.as_raw(Private), ffi_key, ffi_value) } + unsafe { [< proto2_rust_thunk_Map_ $key_t _ $t _insert >](map.as_raw(Private), ffi_key, ffi_value) } } fn map_get<'a>(map: View<'a, Map<$key_t, Self>>, key: View<'_, $key_t>) -> Option> { let ffi_key = $to_ffi_key(key); let mut ffi_value = MaybeUninit::uninit(); - let found = unsafe { [< rust_proto_thunk_Map_ $key_t _ $t _get >](map.as_raw(Private), ffi_key, ffi_value.as_mut_ptr()) }; + let found = unsafe { [< proto2_rust_thunk_Map_ $key_t _ $t _get >](map.as_raw(Private), ffi_key, ffi_value.as_mut_ptr()) }; if !found { return None; @@ -723,7 +723,7 @@ macro_rules! impl_ProxiedInMapValue_for_non_generated_value_types { fn map_remove(mut map: Mut<'_, Map<$key_t, Self>>, key: View<'_, $key_t>) -> bool { let ffi_key = $to_ffi_key(key); let mut ffi_value = MaybeUninit::uninit(); - unsafe { [< rust_proto_thunk_Map_ $key_t _ $t _remove >](map.as_raw(Private), ffi_key, ffi_value.as_mut_ptr()) } + unsafe { [< proto2_rust_thunk_Map_ $key_t _ $t _remove >](map.as_raw(Private), ffi_key, ffi_value.as_mut_ptr()) } } fn map_iter(map: View<'_, Map<$key_t, Self>>) -> MapIter<'_, $key_t, Self> { @@ -735,7 +735,7 @@ macro_rules! impl_ProxiedInMapValue_for_non_generated_value_types { unsafe { MapIter::from_raw( Private, - [< rust_proto_thunk_Map_ $key_t _ $t _iter >](map.as_raw(Private)) + [< proto2_rust_thunk_Map_ $key_t _ $t _iter >](map.as_raw(Private)) ) } } @@ -750,7 +750,7 @@ macro_rules! impl_ProxiedInMapValue_for_non_generated_value_types { unsafe { iter.as_raw_mut(Private).next_unchecked::<$key_t, Self, _, _>( Private, - [< rust_proto_thunk_Map_ $key_t _ $t _iter_get >], + [< proto2_rust_thunk_Map_ $key_t _ $t _iter_get >], $from_ffi_key, $from_ffi_value, ) diff --git a/rust/cpp_kernel/debug.cc b/rust/cpp_kernel/debug.cc index 4950a19456..6a396cacf5 100644 --- a/rust/cpp_kernel/debug.cc +++ b/rust/cpp_kernel/debug.cc @@ -8,16 +8,16 @@ extern "C" { -google::protobuf::rust_internal::RustStringRawParts rust_proto_utf8_debug_string( +google::protobuf::rust::RustStringRawParts proto2_rust_utf8_debug_string( const google::protobuf::Message* msg) { std::string text = google::protobuf::Utf8Format(*msg); - return google::protobuf::rust_internal::RustStringRawParts(text); + return google::protobuf::rust::RustStringRawParts(text); } -google::protobuf::rust_internal::RustStringRawParts rust_proto_utf8_debug_string_lite( +google::protobuf::rust::RustStringRawParts proto2_rust_utf8_debug_string_lite( const google::protobuf::MessageLite* msg) { std::string text = google::protobuf::Utf8Format(*msg); - return google::protobuf::rust_internal::RustStringRawParts(text); + return google::protobuf::rust::RustStringRawParts(text); } } // extern "C" diff --git a/rust/cpp_kernel/debug.h b/rust/cpp_kernel/debug.h index 9f6fbd4fd5..cd39ef5a3b 100644 --- a/rust/cpp_kernel/debug.h +++ b/rust/cpp_kernel/debug.h @@ -7,10 +7,10 @@ extern "C" { -google::protobuf::rust_internal::RustStringRawParts rust_proto_utf8_debug_string( +google::protobuf::rust::RustStringRawParts proto2_rust_utf8_debug_string( const google::protobuf::Message* msg); -google::protobuf::rust_internal::RustStringRawParts rust_proto_utf8_debug_string_lite( +google::protobuf::rust::RustStringRawParts proto2_rust_utf8_debug_string_lite( const google::protobuf::MessageLite* msg); } // extern "C" diff --git a/rust/cpp_kernel/map.cc b/rust/cpp_kernel/map.cc index d79b2d3bcf..08b8078926 100644 --- a/rust/cpp_kernel/map.cc +++ b/rust/cpp_kernel/map.cc @@ -8,7 +8,7 @@ extern "C" { -void rust_proto_thunk_UntypedMapIterator_increment( +void proto2_rust_thunk_UntypedMapIterator_increment( google::protobuf::internal::UntypedMapIterator* iter) { iter->PlusPlus(); } @@ -28,12 +28,12 @@ __PB_RUST_EXPOSE_SCALAR_MAP_METHODS_FOR_VALUE_TYPE(uint64_t, u64, uint64_t, __PB_RUST_EXPOSE_SCALAR_MAP_METHODS_FOR_VALUE_TYPE(int64_t, i64, int64_t, value, cpp_value); __PB_RUST_EXPOSE_SCALAR_MAP_METHODS_FOR_VALUE_TYPE( - std::string, ProtoBytes, google::protobuf::rust_internal::PtrAndLen, + std::string, ProtoBytes, google::protobuf::rust::PtrAndLen, std::string(value.ptr, value.len), - google::protobuf::rust_internal::PtrAndLen(cpp_value.data(), cpp_value.size())); + google::protobuf::rust::PtrAndLen(cpp_value.data(), cpp_value.size())); __PB_RUST_EXPOSE_SCALAR_MAP_METHODS_FOR_VALUE_TYPE( - std::string, ProtoString, google::protobuf::rust_internal::PtrAndLen, + std::string, ProtoString, google::protobuf::rust::PtrAndLen, std::string(value.ptr, value.len), - google::protobuf::rust_internal::PtrAndLen(cpp_value.data(), cpp_value.size())); + google::protobuf::rust::PtrAndLen(cpp_value.data(), cpp_value.size())); } // extern "C" diff --git a/rust/cpp_kernel/map.h b/rust/cpp_kernel/map.h index b29741f5ec..4d90ab322a 100644 --- a/rust/cpp_kernel/map.h +++ b/rust/cpp_kernel/map.h @@ -6,22 +6,22 @@ key_ty, rust_key_ty, ffi_key_ty, to_cpp_key, to_ffi_key, value_ty, \ rust_value_ty, ffi_value_ty, to_cpp_value, to_ffi_value) \ google::protobuf::Map* \ - rust_proto_thunk_Map_##rust_key_ty##_##rust_value_ty##_new() { \ + proto2_rust_thunk_Map_##rust_key_ty##_##rust_value_ty##_new() { \ return new google::protobuf::Map(); \ } \ - void rust_proto_thunk_Map_##rust_key_ty##_##rust_value_ty##_free( \ + void proto2_rust_thunk_Map_##rust_key_ty##_##rust_value_ty##_free( \ google::protobuf::Map* m) { \ delete m; \ } \ - void rust_proto_thunk_Map_##rust_key_ty##_##rust_value_ty##_clear( \ + void proto2_rust_thunk_Map_##rust_key_ty##_##rust_value_ty##_clear( \ google::protobuf::Map* m) { \ m->clear(); \ } \ - size_t rust_proto_thunk_Map_##rust_key_ty##_##rust_value_ty##_size( \ + size_t proto2_rust_thunk_Map_##rust_key_ty##_##rust_value_ty##_size( \ const google::protobuf::Map* m) { \ return m->size(); \ } \ - bool rust_proto_thunk_Map_##rust_key_ty##_##rust_value_ty##_insert( \ + bool proto2_rust_thunk_Map_##rust_key_ty##_##rust_value_ty##_insert( \ google::protobuf::Map* m, ffi_key_ty key, ffi_value_ty value) { \ auto iter_and_inserted = m->try_emplace(to_cpp_key, to_cpp_value); \ if (!iter_and_inserted.second) { \ @@ -29,7 +29,7 @@ } \ return iter_and_inserted.second; \ } \ - bool rust_proto_thunk_Map_##rust_key_ty##_##rust_value_ty##_get( \ + bool proto2_rust_thunk_Map_##rust_key_ty##_##rust_value_ty##_get( \ const google::protobuf::Map* m, ffi_key_ty key, \ ffi_value_ty* value) { \ auto cpp_key = to_cpp_key; \ @@ -42,11 +42,11 @@ return true; \ } \ google::protobuf::internal::UntypedMapIterator \ - rust_proto_thunk_Map_##rust_key_ty##_##rust_value_ty##_iter( \ + proto2_rust_thunk_Map_##rust_key_ty##_##rust_value_ty##_iter( \ const google::protobuf::Map* m) { \ return google::protobuf::internal::UntypedMapIterator::FromTyped(m->cbegin()); \ } \ - void rust_proto_thunk_Map_##rust_key_ty##_##rust_value_ty##_iter_get( \ + void proto2_rust_thunk_Map_##rust_key_ty##_##rust_value_ty##_iter_get( \ const google::protobuf::internal::UntypedMapIterator* iter, ffi_key_ty* key, \ ffi_value_ty* value) { \ auto typed_iter = \ @@ -56,7 +56,7 @@ *key = to_ffi_key; \ *value = to_ffi_value; \ } \ - bool rust_proto_thunk_Map_##rust_key_ty##_##rust_value_ty##_remove( \ + bool proto2_rust_thunk_Map_##rust_key_ty##_##rust_value_ty##_remove( \ google::protobuf::Map* m, ffi_key_ty key, ffi_value_ty* value) { \ auto cpp_key = to_cpp_key; \ auto num_removed = m->erase(cpp_key); \ @@ -82,9 +82,9 @@ value_ty, rust_value_ty, ffi_value_ty, \ to_cpp_value, to_ffi_value); \ __PB_RUST_EXPOSE_SCALAR_MAP_METHODS( \ - std::string, ProtoString, google::protobuf::rust_internal::PtrAndLen, \ + std::string, ProtoString, google::protobuf::rust::PtrAndLen, \ std::string(key.ptr, key.len), \ - google::protobuf::rust_internal::PtrAndLen(cpp_key.data(), cpp_key.size()), \ - value_ty, rust_value_ty, ffi_value_ty, to_cpp_value, to_ffi_value); + google::protobuf::rust::PtrAndLen(cpp_key.data(), cpp_key.size()), value_ty, \ + rust_value_ty, ffi_value_ty, to_cpp_value, to_ffi_value); #endif // GOOGLE_PROTOBUF_RUST_CPP_KERNEL_MAP_H__ diff --git a/rust/cpp_kernel/repeated.cc b/rust/cpp_kernel/repeated.cc index b76bca868d..ce2d6c911b 100644 --- a/rust/cpp_kernel/repeated.cc +++ b/rust/cpp_kernel/repeated.cc @@ -10,41 +10,41 @@ #include "rust/cpp_kernel/strings.h" extern "C" { -#define expose_repeated_field_methods(ty, rust_ty) \ - google::protobuf::RepeatedField* rust_proto_RepeatedField_##rust_ty##_new() { \ - return new google::protobuf::RepeatedField(); \ - } \ - void rust_proto_RepeatedField_##rust_ty##_free( \ - google::protobuf::RepeatedField* r) { \ - delete r; \ - } \ - void rust_proto_RepeatedField_##rust_ty##_add(google::protobuf::RepeatedField* r, \ - ty val) { \ - r->Add(val); \ - } \ - size_t rust_proto_RepeatedField_##rust_ty##_size( \ - google::protobuf::RepeatedField* r) { \ - return r->size(); \ - } \ - ty rust_proto_RepeatedField_##rust_ty##_get(google::protobuf::RepeatedField* r, \ - size_t index) { \ - return r->Get(index); \ - } \ - void rust_proto_RepeatedField_##rust_ty##_set(google::protobuf::RepeatedField* r, \ - size_t index, ty val) { \ - return r->Set(index, val); \ - } \ - void rust_proto_RepeatedField_##rust_ty##_copy_from( \ - const google::protobuf::RepeatedField* src, google::protobuf::RepeatedField* dst) { \ - dst->CopyFrom(*src); \ - } \ - void rust_proto_RepeatedField_##rust_ty##_clear( \ - google::protobuf::RepeatedField* r) { \ - r->Clear(); \ - } \ - void rust_proto_RepeatedField_##rust_ty##_reserve( \ - google::protobuf::RepeatedField* r, size_t additional) { \ - r->Reserve(r->size() + additional); \ +#define expose_repeated_field_methods(ty, rust_ty) \ + google::protobuf::RepeatedField* proto2_rust_RepeatedField_##rust_ty##_new() { \ + return new google::protobuf::RepeatedField(); \ + } \ + void proto2_rust_RepeatedField_##rust_ty##_free( \ + google::protobuf::RepeatedField* r) { \ + delete r; \ + } \ + void proto2_rust_RepeatedField_##rust_ty##_add(google::protobuf::RepeatedField* r, \ + ty val) { \ + r->Add(val); \ + } \ + size_t proto2_rust_RepeatedField_##rust_ty##_size( \ + google::protobuf::RepeatedField* r) { \ + return r->size(); \ + } \ + ty proto2_rust_RepeatedField_##rust_ty##_get(google::protobuf::RepeatedField* r, \ + size_t index) { \ + return r->Get(index); \ + } \ + void proto2_rust_RepeatedField_##rust_ty##_set(google::protobuf::RepeatedField* r, \ + size_t index, ty val) { \ + return r->Set(index, val); \ + } \ + void proto2_rust_RepeatedField_##rust_ty##_copy_from( \ + const google::protobuf::RepeatedField* src, google::protobuf::RepeatedField* dst) { \ + dst->CopyFrom(*src); \ + } \ + void proto2_rust_RepeatedField_##rust_ty##_clear( \ + google::protobuf::RepeatedField* r) { \ + r->Clear(); \ + } \ + void proto2_rust_RepeatedField_##rust_ty##_reserve( \ + google::protobuf::RepeatedField* r, size_t additional) { \ + r->Reserve(r->size() + additional); \ } expose_repeated_field_methods(int32_t, i32); @@ -56,46 +56,45 @@ expose_repeated_field_methods(uint64_t, u64); expose_repeated_field_methods(int64_t, i64); #undef expose_repeated_field_methods -#define expose_repeated_ptr_field_methods(ty) \ - google::protobuf::RepeatedPtrField* \ - rust_proto_RepeatedField_##ty##_new() { \ - return new google::protobuf::RepeatedPtrField(); \ - } \ - void rust_proto_RepeatedField_##ty##_free( \ - google::protobuf::RepeatedPtrField* r) { \ - delete r; \ - } \ - void rust_proto_RepeatedField_##ty##_add( \ - google::protobuf::RepeatedPtrField* r, \ - google::protobuf::rust_internal::PtrAndLen val) { \ - r->Add(std::string(val.ptr, val.len)); \ - } \ - size_t rust_proto_RepeatedField_##ty##_size( \ - google::protobuf::RepeatedPtrField* r) { \ - return r->size(); \ - } \ - google::protobuf::rust_internal::PtrAndLen rust_proto_RepeatedField_##ty##_get( \ - google::protobuf::RepeatedPtrField* r, size_t index) { \ - const std::string& s = r->Get(index); \ - return google::protobuf::rust_internal::PtrAndLen(s.data(), s.size()); \ - } \ - void rust_proto_RepeatedField_##ty##_set( \ - google::protobuf::RepeatedPtrField* r, size_t index, \ - google::protobuf::rust_internal::PtrAndLen val) { \ - *r->Mutable(index) = std::string(val.ptr, val.len); \ - } \ - void rust_proto_RepeatedField_##ty##_copy_from( \ - const google::protobuf::RepeatedPtrField* src, \ - google::protobuf::RepeatedPtrField* dst) { \ - dst->CopyFrom(*src); \ - } \ - void rust_proto_RepeatedField_##ty##_clear( \ - google::protobuf::RepeatedPtrField* r) { \ - r->Clear(); \ - } \ - void rust_proto_RepeatedField_##ty##_reserve( \ - google::protobuf::RepeatedPtrField* r, size_t additional) { \ - r->Reserve(r->size() + additional); \ +#define expose_repeated_ptr_field_methods(ty) \ + google::protobuf::RepeatedPtrField* \ + proto2_rust_RepeatedField_##ty##_new() { \ + return new google::protobuf::RepeatedPtrField(); \ + } \ + void proto2_rust_RepeatedField_##ty##_free( \ + google::protobuf::RepeatedPtrField* r) { \ + delete r; \ + } \ + void proto2_rust_RepeatedField_##ty##_add( \ + google::protobuf::RepeatedPtrField* r, google::protobuf::rust::PtrAndLen val) { \ + r->Add(std::string(val.ptr, val.len)); \ + } \ + size_t proto2_rust_RepeatedField_##ty##_size( \ + google::protobuf::RepeatedPtrField* r) { \ + return r->size(); \ + } \ + google::protobuf::rust::PtrAndLen proto2_rust_RepeatedField_##ty##_get( \ + google::protobuf::RepeatedPtrField* r, size_t index) { \ + const std::string& s = r->Get(index); \ + return google::protobuf::rust::PtrAndLen(s.data(), s.size()); \ + } \ + void proto2_rust_RepeatedField_##ty##_set( \ + google::protobuf::RepeatedPtrField* r, size_t index, \ + google::protobuf::rust::PtrAndLen val) { \ + *r->Mutable(index) = std::string(val.ptr, val.len); \ + } \ + void proto2_rust_RepeatedField_##ty##_copy_from( \ + const google::protobuf::RepeatedPtrField* src, \ + google::protobuf::RepeatedPtrField* dst) { \ + dst->CopyFrom(*src); \ + } \ + void proto2_rust_RepeatedField_##ty##_clear( \ + google::protobuf::RepeatedPtrField* r) { \ + r->Clear(); \ + } \ + void proto2_rust_RepeatedField_##ty##_reserve( \ + google::protobuf::RepeatedPtrField* r, size_t additional) { \ + r->Reserve(r->size() + additional); \ } expose_repeated_ptr_field_methods(ProtoString); diff --git a/rust/cpp_kernel/rust_alloc_for_cpp_api.h b/rust/cpp_kernel/rust_alloc_for_cpp_api.h index 9387cad54e..6062e17fca 100644 --- a/rust/cpp_kernel/rust_alloc_for_cpp_api.h +++ b/rust/cpp_kernel/rust_alloc_for_cpp_api.h @@ -6,6 +6,6 @@ // Allocates memory using the current Rust global allocator. // // This function is defined in `rust_alloc_for_cpp_api.rs`. -extern "C" void* rust_proto_alloc(size_t size, size_t align); +extern "C" void* proto2_rust_alloc(size_t size, size_t align); #endif // GOOGLE_PROTOBUF_RUST_CPP_KERNEL_RUST_ALLOC_FOR_CPP_API_H__ diff --git a/rust/cpp_kernel/rust_alloc_for_cpp_api.rs b/rust/cpp_kernel/rust_alloc_for_cpp_api.rs index 0bc54359ce..948b4302b9 100644 --- a/rust/cpp_kernel/rust_alloc_for_cpp_api.rs +++ b/rust/cpp_kernel/rust_alloc_for_cpp_api.rs @@ -8,7 +8,7 @@ use std::alloc::{alloc, Layout}; #[no_mangle] -extern "C" fn rust_proto_alloc(size: usize, align: usize) -> *mut u8 { +extern "C" fn proto2_rust_alloc(size: usize, align: usize) -> *mut u8 { if size == 0 { // A 0-sized layout is legal but the global allocator isn't required to support // it so return a dangling pointer instead. diff --git a/rust/cpp_kernel/serialized_data.h b/rust/cpp_kernel/serialized_data.h index a35d25ab57..48f310f9f6 100644 --- a/rust/cpp_kernel/serialized_data.h +++ b/rust/cpp_kernel/serialized_data.h @@ -20,7 +20,7 @@ namespace google { namespace protobuf { -namespace rust_internal { +namespace rust { // Represents serialized Protobuf wire format data. // @@ -46,7 +46,7 @@ inline bool SerializeMsg(const google::protobuf::MessageLite* msg, SerializedDat << " exceeded maximum protobuf size of 2GB: " << len; return false; } - uint8_t* bytes = static_cast(rust_proto_alloc(len, alignof(char))); + uint8_t* bytes = static_cast(proto2_rust_alloc(len, alignof(char))); if (bytes == nullptr) { ABSL_LOG(FATAL) << "Rust allocator failed to allocate memory."; } @@ -57,7 +57,7 @@ inline bool SerializeMsg(const google::protobuf::MessageLite* msg, SerializedDat return true; } -} // namespace rust_internal +} // namespace rust } // namespace protobuf } // namespace google diff --git a/rust/cpp_kernel/strings.cc b/rust/cpp_kernel/strings.cc index 51e45fef13..5893740b17 100644 --- a/rust/cpp_kernel/strings.cc +++ b/rust/cpp_kernel/strings.cc @@ -7,20 +7,20 @@ namespace google { namespace protobuf { -namespace rust_internal { +namespace rust { RustStringRawParts::RustStringRawParts(std::string src) { if (src.empty()) { data = nullptr; len = 0; } else { - void* d = rust_proto_alloc(src.length(), 1); + void* d = proto2_rust_alloc(src.length(), 1); std::memcpy(d, src.data(), src.length()); data = static_cast(d); len = src.length(); } } -} // namespace rust_internal +} // namespace rust } // namespace protobuf } // namespace google diff --git a/rust/cpp_kernel/strings.h b/rust/cpp_kernel/strings.h index 400a04afb3..55195bded1 100644 --- a/rust/cpp_kernel/strings.h +++ b/rust/cpp_kernel/strings.h @@ -14,7 +14,7 @@ namespace google { namespace protobuf { -namespace rust_internal { +namespace rust { // Represents an ABI-stable version of &[u8]/string_view (borrowed slice of // bytes) for FFI use only. @@ -43,7 +43,7 @@ struct RustStringRawParts { explicit RustStringRawParts(std::string src); }; -} // namespace rust_internal +} // namespace rust } // namespace protobuf } // namespace google diff --git a/rust/test/cpp/interop/test_utils.cc b/rust/test/cpp/interop/test_utils.cc index 33e51239a9..c6f5d84002 100644 --- a/rust/test/cpp/interop/test_utils.cc +++ b/rust/test/cpp/interop/test_utils.cc @@ -14,8 +14,8 @@ #include "rust/cpp_kernel/strings.h" #include "google/protobuf/unittest.pb.h" -using google::protobuf::rust_internal::SerializedData; -using google::protobuf::rust_internal::SerializeMsg; +using google::protobuf::rust::SerializedData; +using google::protobuf::rust::SerializeMsg; extern "C" void MutateTestAllTypes(protobuf_unittest::TestAllTypes* msg) { msg->set_optional_int64(42); @@ -46,7 +46,7 @@ extern "C" void* NewWithExtension() { return proto; } -extern "C" google::protobuf::rust_internal::PtrAndLen GetBytesExtension( +extern "C" google::protobuf::rust::PtrAndLen GetBytesExtension( const protobuf_unittest::TestAllExtensions* proto) { absl::string_view bytes = proto->GetExtension(protobuf_unittest::optional_bytes_extension); diff --git a/src/google/protobuf/compiler/rust/accessors/singular_string.cc b/src/google/protobuf/compiler/rust/accessors/singular_string.cc index 43774deff3..d37bb75dc9 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_string.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_string.cc @@ -161,11 +161,11 @@ void SingularString::InThunkCc(Context& ctx, }}}, R"cc( $with_presence_fields_thunks$; - ::google::protobuf::rust_internal::PtrAndLen $getter_thunk$($QualifiedMsg$* msg) { + ::google::protobuf::rust::PtrAndLen $getter_thunk$($QualifiedMsg$* msg) { absl::string_view val = msg->$field$(); - return ::google::protobuf::rust_internal::PtrAndLen(val.data(), val.size()); + return ::google::protobuf::rust::PtrAndLen(val.data(), val.size()); } - void $setter_thunk$($QualifiedMsg$* msg, ::google::protobuf::rust_internal::PtrAndLen s) { + void $setter_thunk$($QualifiedMsg$* msg, ::google::protobuf::rust::PtrAndLen s) { msg->set_$field$(absl::string_view(s.ptr, s.len)); } )cc"); diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 7f91cc792c..512d64d5ee 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -1267,11 +1267,11 @@ void GenerateThunksCc(Context& ctx, const Descriptor& msg) { extern $abi$ { void* $new_thunk$() { return new $QualifiedMsg$(); } void $delete_thunk$(void* ptr) { delete static_cast<$QualifiedMsg$*>(ptr); } - bool $serialize_thunk$($QualifiedMsg$* msg, google::protobuf::rust_internal::SerializedData* out) { - return google::protobuf::rust_internal::SerializeMsg(msg, out); + bool $serialize_thunk$($QualifiedMsg$* msg, google::protobuf::rust::SerializedData* out) { + return google::protobuf::rust::SerializeMsg(msg, out); } bool $parse_thunk$($QualifiedMsg$* msg, - google::protobuf::rust_internal::SerializedData data) { + google::protobuf::rust::SerializedData data) { return msg->ParseFromArray(data.data, data.len); } diff --git a/src/google/protobuf/compiler/rust/naming.cc b/src/google/protobuf/compiler/rust/naming.cc index 483931dfb0..6701bc19f5 100644 --- a/src/google/protobuf/compiler/rust/naming.cc +++ b/src/google/protobuf/compiler/rust/naming.cc @@ -65,13 +65,13 @@ std::string GetHeaderFile(Context& ctx, const FileDescriptor& file) { std::string RawMapThunk(Context& ctx, const Descriptor& msg, absl::string_view key_t, absl::string_view op) { - return absl::StrCat("rust_proto_thunk_Map_", key_t, "_", + return absl::StrCat("proto2_rust_thunk_Map_", key_t, "_", GetUnderscoreDelimitedFullName(ctx, *&msg), "_", op); } std::string RawMapThunk(Context& ctx, const EnumDescriptor& desc, absl::string_view key_t, absl::string_view op) { - return absl::StrCat("rust_proto_thunk_Map_", key_t, "_", + return absl::StrCat("proto2_rust_thunk_Map_", key_t, "_", GetUnderscoreDelimitedFullName(ctx, *&desc), "_", op); } @@ -82,7 +82,7 @@ std::string FieldPrefix(Context& ctx, const T& field) { // NOTE: When ctx.is_upb(), this functions outputs must match the symbols // that the upbc plugin generates exactly. Failure to do so correctly results // in a link-time failure. - absl::string_view prefix = ctx.is_cpp() ? "rust_proto_thunk_" : ""; + absl::string_view prefix = ctx.is_cpp() ? "proto2_rust_thunk_" : ""; std::string thunk_prefix = absl::StrCat( prefix, GetUnderscoreDelimitedFullName(ctx, *field.containing_type())); return thunk_prefix; @@ -148,7 +148,7 @@ std::string ThunkName(Context& ctx, const OneofDescriptor& field, std::string ThunkName(Context& ctx, const Descriptor& msg, absl::string_view op) { - absl::string_view prefix = ctx.is_cpp() ? "rust_proto_thunk_" : ""; + absl::string_view prefix = ctx.is_cpp() ? "proto2_rust_thunk_" : ""; return absl::StrCat(prefix, GetUnderscoreDelimitedFullName(ctx, msg), "_", op); } @@ -456,10 +456,10 @@ PROTOBUF_CONSTINIT const MapKeyType kMapKeyTypes[] = { /*rs_from_ffi_key_expr=*/ "$pb$::ProtoStr::from_utf8_unchecked(ffi_key.as_ref())", /*cc_key_t=*/"std::string", - /*cc_ffi_key_t=*/"google::protobuf::rust_internal::PtrAndLen", + /*cc_ffi_key_t=*/"google::protobuf::rust::PtrAndLen", /*cc_from_ffi_key_expr=*/ "std::string(key.ptr, key.len)", /*cc_to_ffi_key_expr=*/ - "google::protobuf::rust_internal::PtrAndLen(cpp_key.data(), cpp_key.size())"}}; + "google::protobuf::rust::PtrAndLen(cpp_key.data(), cpp_key.size())"}}; } // namespace rust } // namespace compiler