From: Eric Blake <eblake@redhat.com>
To: "Daniel P. Berrange" <berrange@redhat.com>, qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Markus Armbruster <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v5 1/9] qapi: allow override of default enum prefix naming
Date: Wed, 26 Aug 2015 09:22:55 -0600 [thread overview]
Message-ID: <55DDD9CF.3090302@redhat.com> (raw)
In-Reply-To: <1440601524-30316-2-git-send-email-berrange@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 4007 bytes --]
On 08/26/2015 09:05 AM, Daniel P. Berrange wrote:
> The camel_to_upper() method applies some heuristics to turn
> a mixed case type name into an all-uppercase name. This is
> used for example, to generate enum constant name prefixes.
>
> The heuristics don't also generate a satisfactory name
> though. eg
>
> { 'enum': 'QCryptoTLSCredsEndpoint',
> 'data': ['client', 'server']}
>
> Results in Q_CRYPTOTLS_CREDS_ENDPOINT_CLIENT. This has
> an undesirable _ after the initial Q and is missing an
> _ betweeen the CRYPTO & TLS strings.
s/betweeen/between/
>
> Rather than try to add more and more heuristics to try
> to cope with this, simply allow the QAPI schema to
> specify the desired enum constant prefix explicitly.
>
> eg
>
> { 'enum': 'QCryptoTLSCredsEndpoint',
> 'prefix': 'QCRYPTO_TLS_CREDS_ENDPOINT',
> 'data': ['client', 'server']}
>
> Now gives the QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT name.
Idea seems reasonable.
>
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
> scripts/qapi-types.py | 14 +++++++-------
> scripts/qapi.py | 9 ++++++---
> 2 files changed, 13 insertions(+), 10 deletions(-)
Missing documentation (docs/qapi-code-gen.txt) and a testsuite addition.
I suggest using 'prefix' on one of the existing enums in
tests/qapi-schema/qapi-schema-test.json, then fixing any fallout from
'make check-unit check-qapi-schema' to ensure it still passes - probably
done correctly if this also touches
tests/qapi-schema/qapi-schema-test.out and tests/test-qmp-*visitor.c.
Doesn't affect QMP wire ABI, so the new key shouldn't impact the output
produced by Markus' pending series on introspection, although we may
have some code collisions with the refactoring work going on there.
>
> diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
> index e6eb4b6..549c2f7 100644
> --- a/scripts/qapi-types.py
> +++ b/scripts/qapi-types.py
> @@ -336,9 +336,9 @@ for expr in exprs:
> if expr.has_key('struct'):
> ret += generate_fwd_struct(expr['struct'])
> elif expr.has_key('enum'):
> - ret += generate_enum(expr['enum'], expr['data']) + "\n"
> + ret += generate_enum(expr['enum'], expr['data'], expr.get('prefix')) + "\n"
> ret += generate_fwd_enum_struct(expr['enum'])
> - fdef.write(generate_enum_lookup(expr['enum'], expr['data']))
> + fdef.write(generate_enum_lookup(expr['enum'], expr['data'], expr.get('prefix')))
Long line; I'd wrap after the last ','
> +++ b/scripts/qapi.py
> @@ -698,7 +698,7 @@ def check_exprs(exprs):
> expr = expr_elem['expr']
> info = expr_elem['info']
> if expr.has_key('enum'):
> - check_keys(expr_elem, 'enum', ['data'])
> + check_keys(expr_elem, 'enum', ['data'], ['prefix'])
I'd also amend check_enum() to ensure that the supplied prefix is a
string (and not some other data structure); if you add a new error
message that explicitly filters out an invalid prefix, then that is a
further testsuite addition of a new negative test (tests/Makefile.am to
add the the new tests/qapi-schema/*.json file, plus the corresponding
.{out,exit,err} files to match expected results).
> -def c_enum_const(type_name, const_name):
> - return camel_to_upper(type_name + '_' + const_name)
> +def c_enum_const(type_name, const_name, prefix=None):
> + if prefix is not None:
> + return prefix + '_' + camel_to_upper(const_name)
> + else:
> + return camel_to_upper(type_name + '_' + const_name)
Would it be any easier to read as:
def c_enum_const(type_name, const_name, prefix=None):
if not prefix:
prefix = camel_to_upper(type_name)
return prefix + '_' + camel_to_upper(const_name)
But I'm not sure if that would introduce any subtle changes to existing
enums.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2015-08-26 15:23 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-26 15:05 [Qemu-devel] [PATCH v5 0/9] Extract TLS handling code from VNC server Daniel P. Berrange
2015-08-26 15:05 ` [Qemu-devel] [PATCH v5 1/9] qapi: allow override of default enum prefix naming Daniel P. Berrange
2015-08-26 15:22 ` Eric Blake [this message]
2015-08-27 11:04 ` Daniel P. Berrange
2015-08-26 15:05 ` [Qemu-devel] [PATCH v5 2/9] make: ensure all members of libqemuutil.a are linked Daniel P. Berrange
2015-08-26 15:25 ` Eric Blake
2015-08-26 15:42 ` Daniel P. Berrange
2015-08-26 15:05 ` [Qemu-devel] [PATCH v5 3/9] crypto: introduce new base module for TLS credentials Daniel P. Berrange
2015-08-26 16:56 ` Eric Blake
2015-08-26 15:05 ` [Qemu-devel] [PATCH v5 4/9] crypto: introduce new module for TLS anonymous credentials Daniel P. Berrange
2015-08-26 21:22 ` Eric Blake
2015-08-26 15:05 ` [Qemu-devel] [PATCH v5 5/9] crypto: introduce new module for TLS x509 credentials Daniel P. Berrange
2015-08-26 21:32 ` Eric Blake
2015-08-26 15:05 ` [Qemu-devel] [PATCH v5 6/9] crypto: add sanity checking of " Daniel P. Berrange
2015-08-26 21:53 ` Eric Blake
2015-08-27 8:48 ` Daniel P. Berrange
2015-08-26 15:05 ` [Qemu-devel] [PATCH v5 7/9] crypto: introduce new module for handling TLS sessions Daniel P. Berrange
2015-08-27 14:33 ` Eric Blake
2015-08-28 13:14 ` Daniel P. Berrange
2015-08-26 15:05 ` [Qemu-devel] [PATCH v5 8/9] ui: fix return type for VNC I/O functions to be ssize_t Daniel P. Berrange
2015-08-28 21:08 ` Eric Blake
2015-08-26 15:05 ` [Qemu-devel] [PATCH v5 9/9] ui: convert VNC server to use QCryptoTLSSession Daniel P. Berrange
2015-09-01 15:08 ` Eric Blake
2015-09-02 11:06 ` Daniel P. Berrange
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=55DDD9CF.3090302@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=kraxel@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@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;
as well as URLs for NNTP newsgroup(s).