[PATCH 4/6] qapi: cope with feature names containing a '-'

Daniel P. Berrangé posted 6 patches 3 months, 3 weeks ago
There is a newer version of this series
[PATCH 4/6] qapi: cope with feature names containing a '-'
Posted by Daniel P. Berrangé 3 months, 3 weeks ago
When we shortly expose all feature names to code, it will be valid to
include a '-', which must be translated to a '_' for the enum constants.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 scripts/qapi/gen.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
index 0ff29dc776..036977d989 100644
--- a/scripts/qapi/gen.py
+++ b/scripts/qapi/gen.py
@@ -24,6 +24,7 @@
 )
 
 from .common import (
+    c_enum_const,
     c_fname,
     c_name,
     guardend,
@@ -41,7 +42,7 @@
 
 
 def gen_features(features: Sequence[QAPISchemaFeature]) -> str:
-    features = [f"1u << QAPI_FEATURE_{feat.name.upper()}"
+    features = [f"1u << {c_enum_const('QAPI_FEATURE', feat.name)}"
                 for feat in features if feat.is_special()]
     return ' | '.join(features) or '0'
 
-- 
2.45.2


Re: [PATCH 4/6] qapi: cope with feature names containing a '-'
Posted by Markus Armbruster 3 months, 3 weeks ago
Daniel P. Berrangé <berrange@redhat.com> writes:

> When we shortly expose all feature names to code, it will be valid to
> include a '-', which must be translated to a '_' for the enum constants.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  scripts/qapi/gen.py | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
> index 0ff29dc776..036977d989 100644
> --- a/scripts/qapi/gen.py
> +++ b/scripts/qapi/gen.py
> @@ -24,6 +24,7 @@
>  )
>  
>  from .common import (
> +    c_enum_const,
>      c_fname,
>      c_name,
>      guardend,
> @@ -41,7 +42,7 @@
>  
>  
>  def gen_features(features: Sequence[QAPISchemaFeature]) -> str:
> -    features = [f"1u << QAPI_FEATURE_{feat.name.upper()}"
> +    features = [f"1u << {c_enum_const('QAPI_FEATURE', feat.name)}"
>                  for feat in features if feat.is_special()]
>      return ' | '.join(features) or '0'

Reviewed-by: Markus Armbruster <armbru@redhat.com>