[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 0/2] Replace anti-social QOM type names (again)
From: |
Markus Armbruster |
Subject: |
Re: [PATCH 0/2] Replace anti-social QOM type names (again) |
Date: |
Tue, 14 Nov 2023 08:41:30 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) |
Cc: the other QOM maintainers
Daniel P. Berrangé <berrange@redhat.com> writes:
> On Mon, Nov 13, 2023 at 02:43:42PM +0100, Markus Armbruster wrote:
>> We got rid of QOM type names containing ',' in 6.0, but some have
>> crept back in. Replace them just like we did in 6.0.
>
> It is practical to add
>
> assert(strchr(name, ',') == NULL)
>
> to some place in QOM to stop them coming back yet again ?
This adds a naming rule to QOM. Right now, QOM has none whatsoever,
which I've long called out as a mistake.
I'm all for correcting that mistake, but I'd go further than just
outlawing ','.
Discussed in more depth here:
>> Cover letter of 6.0's replacement:
>> https://lore.kernel.org/qemu-devel/20210304140229.575481-1-armbru@redhat.com/
Let me copy the text for convenience.
QAPI has naming rules. docs/devel/qapi-code-gen.txt:
=== Naming rules and reserved names ===
All names must begin with a letter, and contain only ASCII letters,
digits, hyphen, and underscore. There are two exceptions: enum values
may start with a digit, and names that are downstream extensions (see
section Downstream extensions) start with underscore.
[More on reserved names, upper vs. lower case, '-' vs. '_'...]
The generator enforces the rules.
Naming rules help in at least three ways:
1. They help with keeping names in interfaces consistent and
predictable.
2. They make avoiding collisions with the users' names in the
generator simpler.
3. They enable quote-less, evolvable syntax.
For instance, keyval_parse() syntax consists of names, values, and
special characters ',', '=', '.'
Since names cannot contain special characters, there is no need for
quoting[*]. Simple.
Values are unrestricted, but only ',' is special there. We quote
it by doubling.
Together, we get exactly the same quoting as in QemuOpts. This is
a feature.
If we ever decice to extend key syntax, we have plenty of special
characters to choose from. This is also a feature.
Both features rely on naming rules.
QOM has no naming rules whatsoever. Actual names aren't nearly as bad
as they could be. Still, there are plenty of "funny" names. This may
become a problem when we
* Switch from QemuOpts to keyval_parse()
Compared to QemuOpts, keyval_parse() restricts *keys*, but not
*values*.
"Funny" type names occuring as values are no worse than before:
quoting issues, described below.
Type names occuring in keys must be valid QAPI names. Should be
avoidable.
* QAPIfy (the compile-time static parts of) QOM
QOM type names become QAPI enum values. They must conform to QAPI
enum naming rules.
[...]
One more thing on relaxing QAPI naming rules. QAPI names get mapped
to (parts of) C identifiers. These mappings are not injective. The
basic mapping is simple: replace characters other than letters and
digits by '_'.
This means names distinct QAPI names can clash in C. Fairly harmless
when the only "other" characters are '-' and '_'. The more "others" we
permit, the more likely confusing clashes become. Not a show stopper,
"merely" an issue of ergonomics.