diff mbox series

[03/14] qapi: cope with special feature names containing a '-'

Message ID 20240604153242.251334-4-berrange@redhat.com (mailing list archive)
State New, archived
Headers show
Series Improve mechanism for configuring allowed commands | expand

Commit Message

Daniel P. Berrangé June 4, 2024, 3:32 p.m. UTC
When we shortly allow custom special feature names to be defined, it
will be valid to include a '-', which must be translated to a '_'
when generating code.

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

Comments

Markus Armbruster July 12, 2024, 7:54 a.m. UTC | #1
Daniel P. Berrangé <berrange@redhat.com> writes:

> When we shortly allow custom special feature names to be defined, it
> will be valid to include a '-', which must be translated to a '_'
> when generating code.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  scripts/qapi/gen.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
> index 9c590a1c2e..650efc59ed 100644
> --- a/scripts/qapi/gen.py
> +++ b/scripts/qapi/gen.py
> @@ -41,7 +41,7 @@
>  
>  
>  def gen_special_features(features: Sequence[QAPISchemaFeature]) -> str:
> -    special_features = [f"1u << QAPI_FEATURE_{feat.name.upper()}"
> +    special_features = [f"1u << QAPI_FEATURE_{feat.name.upper().replace('-','_')}"
>                          for feat in features if feat.is_special()]
>      return ' | '.join(special_features) or '0'

I'd prefer something like

    f"1 << {c_enum_const('QAPI_FEATURE', feat.name)}"
diff mbox series

Patch

diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
index 9c590a1c2e..650efc59ed 100644
--- a/scripts/qapi/gen.py
+++ b/scripts/qapi/gen.py
@@ -41,7 +41,7 @@ 
 
 
 def gen_special_features(features: Sequence[QAPISchemaFeature]) -> str:
-    special_features = [f"1u << QAPI_FEATURE_{feat.name.upper()}"
+    special_features = [f"1u << QAPI_FEATURE_{feat.name.upper().replace('-','_')}"
                         for feat in features if feat.is_special()]
     return ' | '.join(special_features) or '0'