Skip to content

Commit

Permalink
Use newly split feature defaults in plugins and runtimes.
Browse files Browse the repository at this point in the history
The new fields fixed_features and overridable_features can be simply merged to recover the old aggregate defaults.  By splitting them though, plugins and runtimes get some extra information about lifetimes for enforcement.

PiperOrigin-RevId: 625107741
  • Loading branch information
mkruskal-google authored and copybara-github committed Apr 16, 2024
1 parent d44ba90 commit 048e7c0
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions upb/reflection/file_def.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,35 @@ const UPB_DESC(FeatureSet*)
size_t n;
const UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault)* const* d =
UPB_DESC(FeatureSetDefaults_defaults)(defaults, &n);
const UPB_DESC(FeatureSet)* ret = NULL;
const UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault)* result = NULL;
for (size_t i = 0; i < n; i++) {
if (UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_edition)(d[i]) >
edition) {
break;
}
ret = UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_features)(d[i]);
result = d[i];
}
if (ret == NULL) {
if (result == NULL) {
_upb_DefBuilder_Errf(ctx, "No valid default found for edition %s",
upb_FileDef_EditionName(edition));
return NULL;
}
return ret;

// Merge the fixed and overridable features to get the edition's default
// feature set.
const UPB_DESC(FeatureSet)* fixed = UPB_DESC(
FeatureSetDefaults_FeatureSetEditionDefault_fixed_features)(result);
const UPB_DESC(FeatureSet)* overridable = UPB_DESC(
FeatureSetDefaults_FeatureSetEditionDefault_overridable_features)(result);
if (!fixed && !overridable) {
_upb_DefBuilder_Errf(ctx, "No valid default found for edition %s",
upb_FileDef_EditionName(edition));
return NULL;
} else if (!fixed) {
return overridable;
}
return _upb_DefBuilder_DoResolveFeatures(ctx, fixed, overridable,
/*is_implicit=*/true);
}

// Allocate and initialize one file def, and add it to the context object.
Expand Down

0 comments on commit 048e7c0

Please sign in to comment.