public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	qemu-rust@nongnu.org
Subject: Re: [PATCH v2 11/16] scripts/qapi: pull c_name from camel_to_upper to caller
Date: Wed, 25 Feb 2026 09:32:12 +0100	[thread overview]
Message-ID: <87wm01w7eb.fsf@pond.sub.org> (raw)
In-Reply-To: <20260108131043.490084-12-pbonzini@redhat.com> (Paolo Bonzini's message of "Thu, 8 Jan 2026 14:10:38 +0100")

Paolo Bonzini <pbonzini@redhat.com> writes:

> Allow using it for other languages too.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  scripts/qapi/common.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
> index 14d5dd259c4..c75396a01b5 100644
> --- a/scripts/qapi/common.py
> +++ b/scripts/qapi/common.py
> @@ -61,7 +61,7 @@ def camel_to_upper(value: str) -> str:
>          ret += ch
>          upc = ch.isupper()
>  
> -    return c_name(ret.upper()).lstrip('_')
> +    return ret.upper()
>  
>  
>  def c_enum_const(type_name: str,
> @@ -75,7 +75,7 @@ def c_enum_const(type_name: str,
>      :param prefix: Optional, prefix that overrides the type_name.
>      """
>      if prefix is None:
> -        prefix = camel_to_upper(type_name)
> +        prefix = c_name(camel_to_upper(type_name)).lstrip('_')
>      return prefix + '_' + c_name(const_name, False).upper()

No change in behavior, because this is the only use of camel_to_upper().

The move of c_name() out of camel_to_upper() is clearly wanted to make
it usable for other languages.

What about .lstrip('_')?  I wonder why we even have it.  Goes back all
the way to commit 6299659f544 (qapi script: code move for
generate_enum_name()) from 2014.  It seems to affect just
tests/qapi-schema/qapi-schema-test.json's

    { 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }

This tests a downstream extension prefix __RFQDN_.

As is, we generate

    typedef enum __org_qemu_x_Enum {
        ORG_QEMU_X_ENUM___ORG_QEMU_X_VALUE,
        ORG_QEMU_X_ENUM__MAX,
    } __org_qemu_x_Enum;

Without the .lstrip('_'), we'd generate

    typedef enum __org_qemu_x_Enum {
        __ORG_QEMU_X_ENUM___ORG_QEMU_X_VALUE,
        __ORG_QEMU_X_ENUM__MAX,
    } __org_qemu_x_Enum;

Meh.

Turns out this isn't on purpose.  Back then, the loop to map camel to
upper worked differently, and produced unwanted leading '_'.  For
instance, it mapped 'AbraCadabra' to '_ABRA_CADABRA'.  The .lstrip()
made the function produce 'ABRA_CADABRA'.  It also makes it eat
downstream extensions' leading '__'.  Oopsie.

By moving it, we insulate Rust from this accident.  Okay.

We could delete it instead.  Might inconvenience downstreams.  Not a
demand; you may wish to keep this series focused on Rust.



  parent reply	other threads:[~2026-02-25  8:33 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-08 13:10 [PATCH v2 00/16] rust: QObject and QAPI bindings Paolo Bonzini
2026-01-08 13:10 ` [PATCH v2 01/16] rust/qobject: add basic bindings Paolo Bonzini
2026-02-24 10:03   ` Markus Armbruster
2026-02-24 10:35     ` Paolo Bonzini
2026-02-24 13:33       ` Markus Armbruster
2026-02-25  8:05         ` Paolo Bonzini
2026-01-08 13:10 ` [PATCH v2 02/16] subprojects: add serde Paolo Bonzini
2026-01-08 13:10 ` [PATCH v2 03/16] rust/qobject: add Serialize implementation Paolo Bonzini
2026-02-24 10:29   ` Markus Armbruster
2026-02-24 10:48     ` Paolo Bonzini
2026-02-24 13:41       ` Markus Armbruster
2026-01-08 13:10 ` [PATCH v2 04/16] rust/qobject: add Serializer (to_qobject) implementation Paolo Bonzini
2026-01-08 13:10 ` [PATCH v2 05/16] rust/qobject: add Deserialize implementation Paolo Bonzini
2026-01-08 13:10 ` [PATCH v2 06/16] rust/qobject: add Deserializer (from_qobject) implementation Paolo Bonzini
2026-01-08 13:10 ` [PATCH v2 07/16] rust/qobject: add from/to JSON bindings for QObject Paolo Bonzini
2026-01-15 13:17   ` Zhao Liu
2026-01-08 13:10 ` [PATCH v2 08/16] rust/qobject: add Display/Debug Paolo Bonzini
2026-01-15 13:19   ` Zhao Liu
2026-01-08 13:10 ` [PATCH v2 09/16] scripts/qapi: add QAPISchemaIfCond.rsgen() Paolo Bonzini
2026-01-19  6:58   ` Zhao Liu
2026-02-25  6:48   ` Markus Armbruster
2026-02-25  7:53     ` Paolo Bonzini
2026-01-08 13:10 ` [PATCH v2 10/16] scripts/qapi: add QAPISchemaType.is_predefined Paolo Bonzini
2026-02-25  7:33   ` Markus Armbruster
2026-02-25  8:01     ` Paolo Bonzini
2026-02-25  8:44       ` Markus Armbruster
2026-02-26 14:12         ` Paolo Bonzini
2026-01-08 13:10 ` [PATCH v2 11/16] scripts/qapi: pull c_name from camel_to_upper to caller Paolo Bonzini
2026-01-19  7:05   ` Zhao Liu
2026-02-25  8:32   ` Markus Armbruster [this message]
2026-01-08 13:10 ` [PATCH v2 12/16] scripts/qapi: generate high-level Rust bindings Paolo Bonzini
2026-02-23 12:36   ` Markus Armbruster
2026-02-23 16:11     ` Paolo Bonzini
2026-02-24 13:46       ` Markus Armbruster
2026-02-25 14:39   ` Markus Armbruster
2026-03-03 10:00     ` Paolo Bonzini
2026-03-03 12:31       ` Markus Armbruster
2026-03-03 15:55         ` Paolo Bonzini
2026-03-04  8:09           ` Markus Armbruster
2026-03-03  9:19   ` Markus Armbruster
2026-03-03 13:17     ` Paolo Bonzini
2026-01-08 13:10 ` [PATCH v2 13/16] scripts/rustc_args: add --no-strict-cfg Paolo Bonzini
2026-01-08 13:10 ` [PATCH v2 14/16] rust/util: build QAPI types Paolo Bonzini
2026-01-08 13:10 ` [PATCH v2 15/16] scripts/qapi: add serde attributes Paolo Bonzini
2026-01-08 13:10 ` [PATCH v2 16/16] rust/tests: QAPI integration tests Paolo Bonzini
2026-02-17  8:10 ` [PATCH v2 00/16] rust: QObject and QAPI bindings Paolo Bonzini
2026-02-19 13:39 ` Markus Armbruster
2026-02-19 16:28   ` Paolo Bonzini
2026-02-23  9:53 ` Daniel P. Berrangé
2026-02-23 15:54   ` Paolo Bonzini
2026-02-23 16:24     ` Daniel P. Berrangé
2026-02-23 19:03       ` Paolo Bonzini
2026-02-24 14:06 ` Markus Armbruster
2026-02-24 17:28   ` Paolo Bonzini
2026-02-26 12:42     ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wm01w7eb.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox