Skip to content

Commit 0b9134b

Browse files
mkruskal-googlecopybara-github
authored andcommitted
Deprecate SupportsUnknownEnumValues on Message reflection. Use FieldDescriptor or EnumDescriptor instead.
PiperOrigin-RevId: 514618684
1 parent 51f22eb commit 0b9134b

File tree

7 files changed

+12
-11
lines changed

7 files changed

+12
-11
lines changed

.github/workflows/codespell.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ jobs:
2424
with:
2525
check_filenames: true
2626
skip: ./.git,./third_party,./conformance/third_party,*.snk,*.pb,*.pb.cc,*.pb.h,./src/google/protobuf/testdata,./objectivec/Tests,./python/compatibility_tests/v2.5.0/tests/google/protobuf/internal,./.github/workflows/codespell.yml
27-
ignore_words_list: "alow,alse,atleast,ba,chec,cleare,copyable,cloneable,crate,dedup,dur,errorprone,falsy,files',fo,fundementals,hel,importd,inout,leapyear,nd,nin,ois,ons,parseable,process',ro,te,testof,ue,unparseable,wasn,wee,gae,keyserver,objext,od,optin,streem,sur,falsy"
27+
ignore_words_list: "alow,alse,atleast,ba,chec,cleare,copyable,cloneable,crate,dedup,dur,errorprone,falsy,files',fo,fundementals,hel,importd,inout,leapyear,nd,nin,ois,ons,parseable,process',ro,te,testof,ue,unparseable,wasn,wee,gae,keyserver,objext,od,optin,streem,sur,falsy,cleary"

python/google/protobuf/pyext/map_container.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,10 @@ int MapReflectionFriend::ScalarMapSetItem(PyObject* _self, PyObject* key,
437437
self->version++;
438438
}
439439

440-
if (!PythonToMapValueRef(self, v, reflection->SupportsUnknownEnumValues(),
440+
if (!PythonToMapValueRef(self, v,
441+
!self->parent_field_descriptor->message_type()
442+
->map_value()
443+
->legacy_enum_field_treated_as_closed(),
441444
&value)) {
442445
return -1;
443446
}

python/google/protobuf/pyext/message.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2300,7 +2300,7 @@ int InternalSetNonOneofScalar(
23002300
}
23012301
case FieldDescriptor::CPPTYPE_ENUM: {
23022302
PROTOBUF_CHECK_GET_INT32(arg, value, -1);
2303-
if (reflection->SupportsUnknownEnumValues()) {
2303+
if (!field_descriptor->legacy_enum_field_treated_as_closed()) {
23042304
reflection->SetEnumValue(message, field_descriptor, value);
23052305
} else {
23062306
const EnumDescriptor* enum_descriptor = field_descriptor->enum_type();

python/google/protobuf/pyext/repeated_scalar_container.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static int AssignItem(PyObject* pself, Py_ssize_t index, PyObject* arg) {
151151
}
152152
case FieldDescriptor::CPPTYPE_ENUM: {
153153
PROTOBUF_CHECK_GET_INT32(arg, value, -1);
154-
if (reflection->SupportsUnknownEnumValues()) {
154+
if (!field_descriptor->legacy_enum_field_treated_as_closed()) {
155155
reflection->SetRepeatedEnumValue(message, field_descriptor, index,
156156
value);
157157
} else {
@@ -376,7 +376,7 @@ PyObject* Append(RepeatedScalarContainer* self, PyObject* item) {
376376
}
377377
case FieldDescriptor::CPPTYPE_ENUM: {
378378
PROTOBUF_CHECK_GET_INT32(item, value, nullptr);
379-
if (reflection->SupportsUnknownEnumValues()) {
379+
if (!field_descriptor->legacy_enum_field_treated_as_closed()) {
380380
reflection->AddEnumValue(message, field_descriptor, value);
381381
} else {
382382
const EnumDescriptor* enum_descriptor = field_descriptor->enum_type();

src/google/protobuf/generated_message_reflection.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,10 +1540,6 @@ bool IsIndexInHasBitSet(const uint32_t* has_bit_set, uint32_t has_bit_index) {
15401540
static_cast<uint32_t>(1)) != 0;
15411541
}
15421542

1543-
bool CreateUnknownEnumValues(const FileDescriptor* file) {
1544-
return file->syntax() == FileDescriptor::SYNTAX_PROTO3;
1545-
}
1546-
15471543
void CheckInOrder(const FieldDescriptor* field, uint32_t* last) {
15481544
*last = *last <= static_cast<uint32_t>(field->number())
15491545
? static_cast<uint32_t>(field->number())
@@ -2486,7 +2482,7 @@ const FieldDescriptor* Reflection::FindKnownExtensionByNumber(
24862482
}
24872483

24882484
bool Reflection::SupportsUnknownEnumValues() const {
2489-
return CreateUnknownEnumValues(descriptor_->file());
2485+
return descriptor_->file()->syntax() == FileDescriptor::SYNTAX_PROTO3;
24902486
}
24912487

24922488
// ===================================================================

src/google/protobuf/message.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
#include "google/protobuf/stubs/common.h"
119119
#include "google/protobuf/arena.h"
120120
#include "google/protobuf/port.h"
121+
#include "absl/base/attributes.h"
121122
#include "absl/base/call_once.h"
122123
#include "absl/base/casts.h"
123124
#include "absl/functional/function_ref.h"
@@ -961,6 +962,7 @@ class PROTOBUF_EXPORT Reflection final {
961962
// reflection->SetEnumValue(message, field, new_value);
962963
// }
963964
// }
965+
ABSL_DEPRECATED("Use EnumDescriptor::is_closed instead.")
964966
bool SupportsUnknownEnumValues() const;
965967

966968
// Returns the MessageFactory associated with this message. This can be

src/google/protobuf/text_format.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ class TextFormat::Parser::ParserImpl {
918918

919919
if (enum_value == nullptr) {
920920
if (int_value != kint64max &&
921-
reflection->SupportsUnknownEnumValues()) {
921+
!field->legacy_enum_field_treated_as_closed()) {
922922
SET_FIELD(EnumValue, int_value);
923923
return true;
924924
} else if (!allow_unknown_enum_) {

0 commit comments

Comments
 (0)