Skip to content

Commit 182a623

Browse files
Merge pull request #23841 from protocolbuffers/33rc2-cp
Backport changes for 33.0-rc2
2 parents 1e14bff + 768db14 commit 182a623

File tree

6 files changed

+65
-11
lines changed

6 files changed

+65
-11
lines changed

src/google/protobuf/compiler/java/lite/enum.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
6161
WriteEnumDocComment(printer, descriptor_, context_->options());
6262
MaybePrintGeneratedAnnotation(context_, printer, descriptor_, immutable_api_);
6363

64+
if (CheckLargeEnum(descriptor_)) {
65+
std::vector<
66+
std::pair<const EnumValueDescriptor*, const EnumValueDescriptor*>>
67+
alias_pairs;
68+
alias_pairs.reserve(aliases_.size());
69+
for (const Alias& alias : aliases_) {
70+
alias_pairs.emplace_back(alias.value, alias.canonical_value);
71+
}
72+
73+
GenerateLarge(printer, descriptor_, canonical_values_, alias_pairs,
74+
immutable_api_, context_, name_resolver_);
75+
return;
76+
}
77+
6478

6579
printer->Print(
6680
"$deprecation$public enum $classname$\n"

src/google/protobuf/map.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,10 +1036,6 @@ class Map : private internal::KeyMapBase<internal::KeyForBase<Key>> {
10361036
Map(const Map& other) : Map(nullptr, other) {}
10371037

10381038
// Internal Arena constructors: do not use!
1039-
// TODO: remove non internal ctors
1040-
explicit Map(Arena* arena) : Base(arena, GetTypeInfo()) {
1041-
StaticValidityCheck();
1042-
}
10431039
Map(internal::InternalVisibility, Arena* arena) : Map(arena) {}
10441040
Map(internal::InternalVisibility, Arena* arena, const Map& other)
10451041
: Map(arena, other) {}
@@ -1077,7 +1073,22 @@ class Map : private internal::KeyMapBase<internal::KeyForBase<Key>> {
10771073
this->ClearTable(false);
10781074
}
10791075

1076+
// If PROTOBUF_FUTURE_REMOVE_MAP_FIELD_ARENA_CONSTRUCTOR is defined, make the
1077+
// arena-enabled constructor private.
1078+
#ifdef PROTOBUF_FUTURE_REMOVE_MAP_FIELD_ARENA_CONSTRUCTOR
1079+
1080+
private:
1081+
#endif
1082+
explicit Map(Arena* arena) : Base(arena, GetTypeInfo()) {
1083+
StaticValidityCheck();
1084+
}
1085+
1086+
// If PROTOBUF_FUTURE_REMOVE_MAP_FIELD_ARENA_CONSTRUCTOR was not defined, we
1087+
// need to add the private tag here.
1088+
#ifndef PROTOBUF_FUTURE_REMOVE_MAP_FIELD_ARENA_CONSTRUCTOR
1089+
10801090
private:
1091+
#endif
10811092
Map(Arena* arena, const Map& other) : Map(arena) {
10821093
StaticValidityCheck();
10831094
CopyFromImpl(other);

src/google/protobuf/map_test.inc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,21 +244,25 @@ namespace {
244244
TEST_F(MapImplTest, OperatorBracketRValue) {
245245
Arena arena;
246246
for (Arena* arena_to_use : {&arena, static_cast<Arena*>(nullptr)}) {
247-
Map<std::string, int> map(arena_to_use);
247+
auto* map = Arena::Create<Map<std::string, int32_t>>(arena_to_use);
248248
{
249249
std::string key(10000, 'a');
250250
const char* const data = key.data();
251-
map[key] = 0;
251+
(*map)[key] = 0;
252252
EXPECT_EQ(data, key.data());
253-
EXPECT_NE(data, map.find(std::string(10000, 'a'))->first.data());
253+
EXPECT_NE(data, map->find(std::string(10000, 'a'))->first.data());
254254
}
255255

256256
{
257257
std::string key(10000, 'b');
258258
const char* const data = key.data();
259-
map[std::move(key)] = 0;
259+
(*map)[std::move(key)] = 0;
260260
EXPECT_NE(data, key.data()); // NOLINT
261-
EXPECT_EQ(data, map.find(std::string(10000, 'b'))->first.data());
261+
EXPECT_EQ(data, map->find(std::string(10000, 'b'))->first.data());
262+
}
263+
264+
if (arena_to_use == nullptr) {
265+
delete map;
262266
}
263267
}
264268
}
@@ -1032,8 +1036,10 @@ TEST_F(MapImplTest, SwapBasic) {
10321036

10331037
TEST_F(MapImplTest, SwapArena) {
10341038
Arena arena1, arena2;
1035-
Map<int32_t, int32_t> m1(&arena1);
1036-
Map<int32_t, int32_t> m2(&arena2);
1039+
auto* m1_ptr = Arena::Create<Map<int32_t, int32_t>>(&arena1);
1040+
auto* m2_ptr = Arena::Create<Map<int32_t, int32_t>>(&arena2);
1041+
auto& m1 = *m1_ptr;
1042+
auto& m2 = *m2_ptr;
10371043
map_[9398] = 41999;
10381044
m1[9398] = 41999;
10391045
m1[8070] = 42056;

src/google/protobuf/port_def.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3),
165165
// Owner: cknittel@, mkruskal@
166166
#define PROTOBUF_FUTURE_REMOVE_REPEATED_PTR_FIELD_ARENA_CONSTRUCTOR 1
167167

168+
// Removes the public Map(Arena*) constructor.
169+
// Owner: cknittel@, mkruskal@
170+
#define PROTOBUF_FUTURE_REMOVE_MAP_FIELD_ARENA_CONSTRUCTOR 1
171+
172+
// Removes the public RepeatedField(Arena*) constructor.
173+
// Owner: cknittel@, mkruskal@
174+
#define PROTOBUF_FUTURE_REMOVE_REPEATED_FIELD_ARENA_CONSTRUCTOR 1
175+
168176
#else
169177

170178
#define PROTOBUF_FUTURE_ADD_NODISCARD

src/google/protobuf/port_undef.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#undef PROTOBUF_FUTURE_ADD_NODISCARD
7777
#undef PROTOBUF_FUTURE_NO_RECURSIVE_MESSAGE_COPY
7878
#undef PROTOBUF_FUTURE_REMOVE_REPEATED_PTR_FIELD_ARENA_CONSTRUCTOR
79+
#undef PROTOBUF_FUTURE_REMOVE_MAP_FIELD_ARENA_CONSTRUCTOR
7980
#endif
8081

8182
#include "google/protobuf/os_macros_restore.inc"

src/google/protobuf/repeated_field.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ namespace protobuf {
5858

5959
class Message;
6060
class UnknownField; // For the allowlist
61+
class UnknownFieldSet;
62+
class DynamicMessage;
6163

6264
namespace internal {
6365

@@ -290,8 +292,10 @@ class ABSL_ATTRIBUTE_WARN_UNUSED RepeatedField final
290292
constexpr RepeatedField();
291293
RepeatedField(const RepeatedField& rhs) : RepeatedField(nullptr, rhs) {}
292294

295+
#ifndef PROTOBUF_FUTURE_REMOVE_REPEATED_FIELD_ARENA_CONSTRUCTOR
293296
// TODO: make this constructor private
294297
explicit RepeatedField(Arena* arena);
298+
#endif
295299

296300
template <typename Iter,
297301
typename = typename std::enable_if<std::is_constructible<
@@ -486,12 +490,22 @@ class ABSL_ATTRIBUTE_WARN_UNUSED RepeatedField final
486490

487491
friend class Arena;
488492

493+
#ifdef PROTOBUF_FUTURE_REMOVE_REPEATED_FIELD_ARENA_CONSTRUCTOR
494+
// For access to private arena constructor.
495+
friend class UnknownFieldSet;
496+
friend class DynamicMessage;
497+
#endif
498+
489499
static constexpr int kSooCapacityElements =
490500
internal::SooCapacityElements<Element>();
491501

492502
static constexpr int kInitialSize = 0;
493503
static PROTOBUF_CONSTEXPR const size_t kHeapRepHeaderSize = sizeof(HeapRep);
494504

505+
#ifdef PROTOBUF_FUTURE_REMOVE_REPEATED_FIELD_ARENA_CONSTRUCTOR
506+
explicit RepeatedField(Arena* arena);
507+
#endif
508+
495509
RepeatedField(Arena* arena, const RepeatedField& rhs);
496510
RepeatedField(Arena* arena, RepeatedField&& rhs);
497511

0 commit comments

Comments
 (0)