All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-trivial@nongnu.org,
	mdroth@linux.vnet.ibm.com, anderson@redhat.com,
	pbonzini@redhat.com, lersek@redhat.com
Subject: Re: [Qemu-devel] [PATCH 01/21] qapi: add info comment for generated types
Date: Mon, 13 Mar 2017 08:01:50 +0100	[thread overview]
Message-ID: <87o9x5k6ch.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20170311132256.22951-2-marcandre.lureau@redhat.com> (=?utf-8?Q?=22Marc-Andr=C3=A9?= Lureau"'s message of "Sat, 11 Mar 2017 17:22:36 +0400")

Re qemu-trivial: since I got another lengthy series touching
scripts/qapi* in the pipeline, I'd prefer to handle the conflicts in my
tree.

Marc-André Lureau <marcandre.lureau@redhat.com> writes:

> This may help to find where the origin of the type was declared in the
> json (when greping isn't easy enough).

An example for the generated comment would be nice here.

> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Cc: qemu-trivial@nongnu.org
> ---
>  scripts/qapi.py       | 11 +++++++++--
>  scripts/qapi-event.py |  4 +++-
>  scripts/qapi-types.py | 17 +++++++++--------
>  3 files changed, 21 insertions(+), 11 deletions(-)
>
> diff --git a/scripts/qapi.py b/scripts/qapi.py
> index 53a44779d0..9504ebd8c7 100644
> --- a/scripts/qapi.py
> +++ b/scripts/qapi.py
> @@ -1874,15 +1874,22 @@ const char *const %(c_name)s_lookup[] = {
>      return ret
>  
>  
> -def gen_enum(name, values, prefix=None):
> +def gen_info_comment(info):

Well, aren't all comments "info comments"?  What distinguishes this one
is that it's about the location of the source.  Suggest to rename to
gen_loc_comment() or maybe gen_src_loc_comment().

Hmm, the gen_ prefix is awkward.  Generated C should go through cgen()
exactly once (see commit 1f9a7a1).  The common way to get this wrong is
passing a foo=gen_foo() keyword argument to mcgen().  I'd like us to
adopt a naming convention where gen_ means "something that's been piped
through cgen(), and thus must not be passed to cgen() or mcgen()".
Requires renaming gen_params(), gen_marshal_proto() and
gen_event_send_proto().

> +    if info:
> +        return "/* %s:%d */" % (info['file'], info['line'])
> +    else:
> +        return ""

Please stick to the prevalent use of single vs. double quotes: use
single quotes unless double quotes let you avoid backslashes, except
always use double quotes for error messages.  See "[PATCH for-2.9 19/47]
qapi: Prefer single-quoted strings more consistently".

> +
> +def gen_enum(info, name, values, prefix=None):
>      # append automatically generated _MAX value
>      enum_values = values + ['_MAX']
>  
>      ret = mcgen('''
>  
> +%(info)s
>  typedef enum %(c_name)s {
>  ''',
> -                c_name=c_name(name))
> +                c_name=c_name(name), info=gen_info_comment(info))

Your chance to use identifier infocom ;-P

Seriously, I'd prefer comment to info.

>  
>      i = 0
>      for value in enum_values:
> diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
> index f4eb7f85b1..ca90d6a5df 100644
> --- a/scripts/qapi-event.py
> +++ b/scripts/qapi-event.py
> @@ -152,6 +152,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor):
>          self.decl = None
>          self.defn = None
>          self._event_names = None
> +        self.info = None
>  
>      def visit_begin(self, schema):
>          self.decl = ''
> @@ -159,7 +160,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor):
>          self._event_names = []
>  
>      def visit_end(self):
> -        self.decl += gen_enum(event_enum_name, self._event_names)
> +        self.decl += gen_enum(self.info, event_enum_name, self._event_names)
>          self.defn += gen_enum_lookup(event_enum_name, self._event_names)
>          self._event_names = None
>  
> @@ -167,6 +168,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor):
>          self.decl += gen_event_send_decl(name, arg_type, boxed)
>          self.defn += gen_event_send(name, arg_type, boxed)
>          self._event_names.append(name)
> +        self.info = info
>  
>  

I'm afraid this doesn't make sense.

You set self.info in each visit_event(), then use it in visit_end().
visit_end() thus sees the info of whatever event was visited last.
Won't produce a sane location comment.  None of the others would,
either.  That's because the enumeration is defined implicitly by all the
events together.

Let's pass info=None for this enum.

>  (input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
> diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
> index dabc42e047..896749bf61 100644
> --- a/scripts/qapi-types.py
> +++ b/scripts/qapi-types.py
> @@ -19,12 +19,13 @@ from qapi import *
>  objects_seen = set()
>  
>  
> -def gen_fwd_object_or_array(name):
> +def gen_fwd_object_or_array(info, name):
>      return mcgen('''
>  
> +%(info)s
>  typedef struct %(c_name)s %(c_name)s;

If info=None, gen_info_comment(info) is '', and we get an unwanted blank
line.

>  ''',
> -                 c_name=c_name(name))
> +                 c_name=c_name(name), info=gen_info_comment(info))
>  
>  
>  def gen_array(name, element_type):
> @@ -199,22 +200,22 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
>          # Special case for our lone builtin enum type
>          # TODO use something cleaner than existence of info
>          if not info:
> -            self._btin += gen_enum(name, values, prefix)
> +            self._btin += gen_enum(info, name, values, prefix)

gen_enum(None, ...) feels slightly clearer to me.

>              if do_builtins:
>                  self.defn += gen_enum_lookup(name, values, prefix)
>          else:
> -            self._fwdecl += gen_enum(name, values, prefix)
> +            self._fwdecl += gen_enum(info, name, values, prefix)
>              self.defn += gen_enum_lookup(name, values, prefix)
>  
>      def visit_array_type(self, name, info, element_type):
>          if isinstance(element_type, QAPISchemaBuiltinType):
> -            self._btin += gen_fwd_object_or_array(name)
> +            self._btin += gen_fwd_object_or_array(info, name)
>              self._btin += gen_array(name, element_type)
>              self._btin += gen_type_cleanup_decl(name)
>              if do_builtins:
>                  self.defn += gen_type_cleanup(name)
>          else:
> -            self._fwdecl += gen_fwd_object_or_array(name)
> +            self._fwdecl += gen_fwd_object_or_array(info, name)
>              self.decl += gen_array(name, element_type)
>              self._gen_type_cleanup(name)
>  

Note that @info points to an arbitrarily chosen user of the array type,
*not* to the definition of the element type.  The resulting source
location comment feels useless to me.  Suggest to pass None for arrays.

> @@ -222,7 +223,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
>          # Nothing to do for the special empty builtin
>          if name == 'q_empty':
>              return
> -        self._fwdecl += gen_fwd_object_or_array(name)
> +        self._fwdecl += gen_fwd_object_or_array(info, name)
>          self.decl += gen_object(name, base, members, variants)
>          if base and not base.is_implicit():
>              self.decl += gen_upcast(name, base)
> @@ -233,7 +234,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
>              self._gen_type_cleanup(name)
>  
>      def visit_alternate_type(self, name, info, variants):
> -        self._fwdecl += gen_fwd_object_or_array(name)
> +        self._fwdecl += gen_fwd_object_or_array(info, name)
>          self.decl += gen_object(name, None, [variants.tag_member], variants)
>          self._gen_type_cleanup(name)

  reply	other threads:[~2017-03-13  7:01 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-11 13:22 [Qemu-devel] [PATCH 00/21] WIP: dump: add kaslr support (for after 2.9) Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 01/21] qapi: add info comment for generated types Marc-André Lureau
2017-03-13  7:01   ` Markus Armbruster [this message]
2017-03-11 13:22 ` [Qemu-devel] [PATCH 02/21] pci-host: use more specific type names Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 03/21] object: fix potential leak in getters Marc-André Lureau
2017-03-21 14:43   ` Eric Blake
2017-04-23 17:16   ` Michael Tokarev
2017-03-11 13:22 ` [Qemu-devel] [PATCH 04/21] qobject: add quint type Marc-André Lureau
2017-03-11 20:17   ` Eric Blake
2017-03-13  7:15     ` Markus Armbruster
2017-03-13 13:21       ` Eric Blake
2017-03-13 13:28         ` Marc-André Lureau
2017-03-21 12:41           ` Marc-André Lureau
2017-03-21 16:49             ` Markus Armbruster
2017-03-21 17:06               ` Eric Blake
2017-03-21 17:46                 ` Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 05/21] qapi: update the qobject visitor to use QUInt Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 06/21] json: learn to parse uint64 numbers Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 07/21] object: add uint property setter/getter Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 08/21] qdev: use int and uint properties Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 09/21] qdev: use appropriate type Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 10/21] Use uint property getter/setter where appropriate Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 11/21] qdict: learn to lookup quint Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 12/21] test-qga: drop everything until guest-sync Marc-André Lureau
2017-03-11 20:07   ` Eric Blake
2017-03-11 13:22 ` [Qemu-devel] [PATCH 13/21] qga: report error on keyfile dump error Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 14/21] qga: add and populate VMDumpInfo Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 15/21] qga: register event emit function Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 16/21] qga: emit VMDUMP_INFO event Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 17/21] virtio-channel: parse qga stream for " Marc-André Lureau
2017-04-05 16:12   ` Daniel P. Berrange
     [not found]     ` <CAJ+F1C+2x=0pZxMz8FgxbkQD59zM2pngHKv7AT-hv-KA6xjN+Q@mail.gmail.com>
2017-04-05 16:38       ` Marc-André Lureau
2017-04-05 17:06     ` Eric Blake
2017-04-05 17:39       ` Daniel P. Berrange
2017-03-11 13:22 ` [Qemu-devel] [PATCH 18/21] dump: use qga VMDUMP_INFO for ELF dump Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 19/21] kdump: write vmcoreinfo in header Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 20/21] scripts/dump-guest-memory.py: fix int128_get64 on recent gcc Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] [PATCH 21/21] scripts/dump-guest-memory.py: add VMCOREINFO Marc-André Lureau
2017-03-11 13:47 ` [Qemu-devel] [PATCH 00/21] WIP: dump: add kaslr support (for after 2.9) no-reply
2017-03-11 14:31 ` Dave Anderson
2017-04-05 16:01   ` Paolo Bonzini

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=87o9x5k6ch.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=anderson@redhat.com \
    --cc=lersek@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.