Auto-generate files after cl/581384108

pull/14725/head
Protobuf Team Bot 1 year ago
parent c23d5333c3
commit c6b149cbf9
  1. 165
      php/ext/google/protobuf/php-upb.c
  2. 7
      php/ext/google/protobuf/php-upb.h
  3. 165
      ruby/ext/google/protobuf_c/ruby-upb.c
  4. 7
      ruby/ext/google/protobuf_c/ruby-upb.h

@ -8333,8 +8333,12 @@ upb_DefPool* upb_DefPool_New(void) {
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;
@ -8350,6 +8354,58 @@ const UPB_DESC(FeatureSetDefaults) *
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),
@ -8835,6 +8891,11 @@ bool upb_EnumDef_HasOptions(const upb_EnumDef* e) {
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) {
@ -9163,6 +9224,11 @@ bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* v) {
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;
}
@ -9381,6 +9447,11 @@ bool upb_FieldDef_HasOptions(const upb_FieldDef* f) {
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;
}
@ -9925,6 +9996,25 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix,
}
}
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);
@ -9988,26 +10078,10 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix,
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 =
@ -10331,6 +10405,20 @@ struct upb_FileDef {
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;
}
@ -10463,11 +10551,21 @@ const UPB_DESC(FeatureSet*)
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;
@ -10481,6 +10579,11 @@ const UPB_DESC(FeatureSet*)
}
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;
}
@ -11410,6 +11513,11 @@ bool upb_MessageDef_HasOptions(const upb_MessageDef* m) {
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;
}
@ -12103,6 +12211,11 @@ bool upb_MethodDef_HasOptions(const upb_MethodDef* m) {
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;
}
@ -12203,6 +12316,11 @@ bool upb_OneofDef_HasOptions(const upb_OneofDef* o) {
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;
}
@ -12399,6 +12517,11 @@ bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s) {
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;
}

@ -10164,6 +10164,11 @@ UPB_API upb_DefPool* upb_DefPool_New(void);
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);
@ -10410,6 +10415,8 @@ UPB_API upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f);
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);

@ -7848,8 +7848,12 @@ upb_DefPool* upb_DefPool_New(void) {
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 @@ const UPB_DESC(FeatureSetDefaults) *
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 @@ bool upb_EnumDef_HasOptions(const upb_EnumDef* e) {
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 @@ bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* v) {
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 @@ bool upb_FieldDef_HasOptions(const upb_FieldDef* f) {
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 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix,
}
}
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 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix,
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 @@ struct upb_FileDef {
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 @@ const UPB_DESC(FeatureSet*)
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 @@ const UPB_DESC(FeatureSet*)
}
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 @@ bool upb_MessageDef_HasOptions(const upb_MessageDef* m) {
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 @@ bool upb_MethodDef_HasOptions(const upb_MethodDef* m) {
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 @@ bool upb_OneofDef_HasOptions(const upb_OneofDef* o) {
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 @@ bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s) {
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;
}

@ -10668,6 +10668,11 @@ UPB_API upb_DefPool* upb_DefPool_New(void);
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 @@ UPB_API upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f);
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);

Loading…
Cancel
Save