From 048e7c0bf8af715eb217d3a85c9b77ce52bd37c4 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Mon, 15 Apr 2024 15:46:20 -0700 Subject: [PATCH] Use newly split feature defaults in plugins and runtimes. 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 --- upb/reflection/file_def.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/upb/reflection/file_def.c b/upb/reflection/file_def.c index 34774f3df0035..5a51deecf947e 100644 --- a/upb/reflection/file_def.c +++ b/upb/reflection/file_def.c @@ -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.