Auto-generate files after cl/581384108
diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 888f507..dfad0d5 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c
@@ -7848,8 +7848,12 @@ if (!s->extreg) goto err; s->platform = kUpb_MiniTablePlatform_Native; - s->feature_set_defaults = UPB_DESC(FeatureSetDefaults_parse)( - serialized_defaults, sizeof(serialized_defaults) - 1, s->arena); + + upb_Status status; + if (!upb_DefPool_SetFeatureSetDefaults( + s, serialized_defaults, sizeof(serialized_defaults) - 1, &status)) { + goto err; + } if (!s->feature_set_defaults) goto err; @@ -7865,6 +7869,58 @@ return s->feature_set_defaults; } +bool upb_DefPool_SetFeatureSetDefaults(upb_DefPool* s, + const char* serialized_defaults, + size_t serialized_len, + upb_Status* status) { + const UPB_DESC(FeatureSetDefaults)* defaults = UPB_DESC( + FeatureSetDefaults_parse)(serialized_defaults, serialized_len, s->arena); + if (!defaults) { + upb_Status_SetErrorFormat(status, "Failed to parse defaults"); + return false; + } + if (upb_strtable_count(&s->files) > 0) { + upb_Status_SetErrorFormat(status, + "Feature set defaults can't be changed once the " + "pool has started building"); + return false; + } + int min_edition = UPB_DESC(FeatureSetDefaults_minimum_edition(defaults)); + int max_edition = UPB_DESC(FeatureSetDefaults_maximum_edition(defaults)); + if (min_edition > max_edition) { + upb_Status_SetErrorFormat(status, "Invalid edition range %s to %s", + upb_FileDef_EditionName(min_edition), + upb_FileDef_EditionName(max_edition)); + return false; + } + size_t size; + const UPB_DESC( + FeatureSetDefaults_FeatureSetEditionDefault)* const* default_list = + UPB_DESC(FeatureSetDefaults_defaults(defaults, &size)); + int prev_edition = UPB_DESC(EDITION_UNKNOWN); + for (size_t i = 0; i < size; ++i) { + int edition = UPB_DESC( + FeatureSetDefaults_FeatureSetEditionDefault_edition(default_list[i])); + if (edition == UPB_DESC(EDITION_UNKNOWN)) { + upb_Status_SetErrorFormat(status, "Invalid edition UNKNOWN specified"); + return false; + } + if (edition <= prev_edition) { + upb_Status_SetErrorFormat(status, + "Feature set defaults are not strictly " + "increasing, %s is greater than or equal to %s", + upb_FileDef_EditionName(prev_edition), + upb_FileDef_EditionName(edition)); + return false; + } + prev_edition = edition; + } + + // Copy the defaults into the pool. + s->feature_set_defaults = defaults; + return true; +} + bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext, const upb_FieldDef* f) { return upb_inttable_insert(&s->exts, (uintptr_t)ext, upb_value_constptr(f), @@ -8350,6 +8406,11 @@ return e->opts != (void*)kUpbDefOptDefault; } +const UPB_DESC(FeatureSet) * + upb_EnumDef_ResolvedFeatures(const upb_EnumDef* e) { + return e->resolved_features; +} + const char* upb_EnumDef_FullName(const upb_EnumDef* e) { return e->full_name; } const char* upb_EnumDef_Name(const upb_EnumDef* e) { @@ -8678,6 +8739,11 @@ return v->opts != (void*)kUpbDefOptDefault; } +const UPB_DESC(FeatureSet) * + upb_EnumValueDef_ResolvedFeatures(const upb_EnumValueDef* e) { + return e->resolved_features; +} + const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* v) { return v->parent; } @@ -8896,6 +8962,11 @@ return f->opts != (void*)kUpbDefOptDefault; } +const UPB_DESC(FeatureSet) * + upb_FieldDef_ResolvedFeatures(const upb_FieldDef* f) { + return f->resolved_features; +} + const char* upb_FieldDef_FullName(const upb_FieldDef* f) { return f->full_name; } @@ -9440,6 +9511,25 @@ } } + if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { + int oneof_index = UPB_DESC(FieldDescriptorProto_oneof_index)(field_proto); + + if (!m) { + _upb_DefBuilder_Errf(ctx, "oneof field (%s) has no containing msg", + f->full_name); + } + + if (oneof_index >= upb_MessageDef_OneofCount(m)) { + _upb_DefBuilder_Errf(ctx, "oneof_index out of range (%s)", f->full_name); + } + + upb_OneofDef* oneof = (upb_OneofDef*)upb_MessageDef_Oneof(m, oneof_index); + f->scope.oneof = oneof; + parent_features = upb_OneofDef_ResolvedFeatures(oneof); + + _upb_OneofDef_Insert(ctx, oneof, f, name.data, name.size); + } + f->resolved_features = _upb_DefBuilder_DoResolveFeatures( ctx, parent_features, unresolved_features, implicit); @@ -9503,26 +9593,10 @@ f->sub.unresolved = field_proto; if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { - int oneof_index = UPB_DESC(FieldDescriptorProto_oneof_index)(field_proto); - if (upb_FieldDef_Label(f) != kUpb_Label_Optional) { _upb_DefBuilder_Errf(ctx, "fields in oneof must have OPTIONAL label (%s)", f->full_name); } - - if (!m) { - _upb_DefBuilder_Errf(ctx, "oneof field (%s) has no containing msg", - f->full_name); - } - - if (oneof_index >= upb_MessageDef_OneofCount(m)) { - _upb_DefBuilder_Errf(ctx, "oneof_index out of range (%s)", f->full_name); - } - - upb_OneofDef* oneof = (upb_OneofDef*)upb_MessageDef_Oneof(m, oneof_index); - f->scope.oneof = oneof; - - _upb_OneofDef_Insert(ctx, oneof, f, name.data, name.size); } f->has_presence = @@ -9846,6 +9920,20 @@ upb_Syntax syntax; }; +UPB_API const char* upb_FileDef_EditionName(int edition) { + // TODO Synchronize this with descriptor.proto better. + switch (edition) { + case UPB_DESC(EDITION_PROTO2): + return "PROTO2"; + case UPB_DESC(EDITION_PROTO3): + return "PROTO3"; + case UPB_DESC(EDITION_2023): + return "2023"; + default: + return "UNKNOWN"; + } +} + const UPB_DESC(FileOptions) * upb_FileDef_Options(const upb_FileDef* f) { return f->opts; } @@ -9978,11 +10066,21 @@ int min = UPB_DESC(FeatureSetDefaults_minimum_edition)(defaults); int max = UPB_DESC(FeatureSetDefaults_maximum_edition)(defaults); - if (edition < min || edition > max) { + if (edition < min) { _upb_DefBuilder_Errf(ctx, - "Edition %d is outside the supported range [%d, %d] " + "Edition %s is earlier than the minimum edition %s " "given in the defaults", - edition, min, max); + upb_FileDef_EditionName(edition), + upb_FileDef_EditionName(min)); + return NULL; + } + if (edition > max) { + _upb_DefBuilder_Errf(ctx, + "Edition %s is later than the maximum edition %s " + "given in the defaults", + upb_FileDef_EditionName(edition), + upb_FileDef_EditionName(max)); + return NULL; } size_t n; @@ -9996,6 +10094,11 @@ } ret = UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_features)(d[i]); } + if (ret == NULL) { + _upb_DefBuilder_Errf(ctx, "No valid default found for edition %s", + upb_FileDef_EditionName(edition)); + return NULL; + } return ret; } @@ -10925,6 +11028,11 @@ return m->opts != (void*)kUpbDefOptDefault; } +const UPB_DESC(FeatureSet) * + upb_MessageDef_ResolvedFeatures(const upb_MessageDef* m) { + return m->resolved_features; +} + const char* upb_MessageDef_FullName(const upb_MessageDef* m) { return m->full_name; } @@ -11618,6 +11726,11 @@ return m->opts != (void*)kUpbDefOptDefault; } +const UPB_DESC(FeatureSet) * + upb_MethodDef_ResolvedFeatures(const upb_MethodDef* m) { + return m->resolved_features; +} + const char* upb_MethodDef_FullName(const upb_MethodDef* m) { return m->full_name; } @@ -11718,6 +11831,11 @@ return o->opts != (void*)kUpbDefOptDefault; } +const UPB_DESC(FeatureSet) * + upb_OneofDef_ResolvedFeatures(const upb_OneofDef* o) { + return o->resolved_features; +} + const char* upb_OneofDef_FullName(const upb_OneofDef* o) { return o->full_name; } @@ -11914,6 +12032,11 @@ return s->opts != (void*)kUpbDefOptDefault; } +const UPB_DESC(FeatureSet) * + upb_ServiceDef_ResolvedFeatures(const upb_ServiceDef* s) { + return s->resolved_features; +} + const char* upb_ServiceDef_FullName(const upb_ServiceDef* s) { return s->full_name; }
diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index ba67dfa..292e401 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h
@@ -10668,6 +10668,11 @@ UPB_API const UPB_DESC(FeatureSetDefaults) * upb_DefPool_FeatureSetDefaults(const upb_DefPool* s); +UPB_API bool upb_DefPool_SetFeatureSetDefaults(upb_DefPool* s, + const char* serialized_defaults, + size_t serialized_len, + upb_Status* status); + UPB_API const upb_MessageDef* upb_DefPool_FindMessageByName( const upb_DefPool* s, const char* sym); @@ -10914,6 +10919,8 @@ extern "C" { #endif +UPB_API const char* upb_FileDef_EditionName(int edition); + const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i); int upb_FileDef_DependencyCount(const upb_FileDef* f); bool upb_FileDef_HasOptions(const upb_FileDef* f);