Skip to contentSkip to conversation

qapi: easier debugging of introspection file

PATCH Superseded Eric Blake 3 participants 13 messages Jun 29, 2018 – Jul 3, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Eric Blake

author
#0 lore raw

cover qapi: easier debugging of introspection file

When inspecting the generated qapi-introspect.c (for debugging, or to see what QAPI changes are user visible vs. internal only), the fact that we've intentionally masked names from the QMP client makes it harder to tie back generated code back to the original QAPI .json files. We have a -u switch to qapi-gen for temporarily bypassing the name masking, but that's a rather heavy-handed tactic just for some temporary debugging. Better is to just make the generated file include strategic comments.

Eric Blake (2):
qapi: Add comments to aid debugging generated introspection
qapi: Drop qapi-gen --unmask option

 scripts/qapi-gen.py        |  5 +----
 scripts/qapi/introspect.py | 19 ++++++++++---------
 2 files changed, 11 insertions(+), 13 deletions(-)
Signature · 1 line
2.14.4
author
#1 lore raw

PATCH 1/2 qapi: Add comments to aid debugging generated introspection

We consciously chose in commit 1a9a507b to hide QAPI type names from the generated introspection output, but added a command line option -u to unmask the type name when doing a debug build. At that time, we generated a monolithic C string, so there was no better way to do things (we could not really inject comments).

Later, in commit 7d0f982b, we switched the generation to output a QLit object, in part to make it easier for future addition of conditional compilation. But this switch has also made it easier to interject strategic comments. That commit also forgot to delete some now-stale comments about long generated line lengths.

For now, type name debug aid comments are only output once per meta-type, rather than at all uses of the number used to encode the type to the introspection data. But this is still a lot more convenient than having to regenerate the file with the unmask operation temporarily turned on.

The generated qapi-introspect.c changes only with the addition of comments, such as:

| @@ -14927,6 +15410,7 @@
|          {}
|      })),
|      QLIT_QDICT(((QLitDictEntry[]) {
| +        /* QCryptoBlockInfoLUKSSlot */
|          { "members", QLIT_QLIST(((QLitObject[]) {
|              QLIT_QDICT(((QLitDictEntry[]) {
|                  { "name", QLIT_QSTR("active") },
|
---
 scripts/qapi/introspect.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
scripts/qapi/introspect.py +8 -3
index 6ad198ae5b5..b37160292bc 100644
@@ -35,10 +35,14 @@ def to_qlit(obj, level=0, suppress_first_indent=False):
     elif isinstance(obj, dict):
         elts = []
         for key, value in sorted(obj.items()):
+            if key == 'comment':
+                continue
             elts.append(indent(level + 1) + '{ %s, %s }' %
                         (to_c_string(key), to_qlit(value, level + 1, True)))
         elts.append(indent(level + 1) + '{}')
         ret += 'QLIT_QDICT(((QLitDictEntry[]) {\n'
+        if obj.get('comment'):
+            ret += indent(level + 1) + '/* %s */\n' % obj['comment']
         ret += ',\n'.join(elts) + '\n'
         ret += indent(level) + '}))'
     elif isinstance(obj, bool):
@@ -78,7 +82,6 @@ class QAPISchemaGenIntrospectVisitor(QAPISchemaMonolithicCVisitor):
         for typ in self._used_types:
             typ.visit(self)
         # generate C
-        # TODO can generate awfully long lines
         name = c_name(self._prefix, protect=False) + 'qmp_schema_qlit'
         self._genh.add(mcgen('''
 #include "qapi/qmp/qlit.h"
@@ -118,8 +121,8 @@ const QLitObject %(c_name)s = %(c_string)s;
         if typ not in self._used_types:
             self._used_types.append(typ)
         # Clients should examine commands and events, not types.  Hide
-        # type names to reduce the temptation.  Also saves a few
-        # characters.
+        # type names as integers to reduce the temptation, but provide
+        # comments for debugging aid.
         if isinstance(typ, QAPISchemaBuiltinType):
             return typ.name
         if isinstance(typ, QAPISchemaArrayType):
@@ -128,6 +131,8 @@ const QLitObject %(c_name)s = %(c_string)s;
 
     def _gen_qlit(self, name, mtype, obj):
         if mtype not in ('command', 'event', 'builtin', 'array'):
+            if not self._unmask:
+                obj['comment'] = name
             name = self._name(name)
         obj['name'] = name
         obj['meta-type'] = mtype
Signature · 1 line
2.14.4
author
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] qapi: Add comments to aid debugging generated introspection

Quoted 17 lines · Eric Blake

We consciously chose in commit 1a9a507b to hide QAPI type names from the generated introspection output, but added a command line option -u to unmask the type name when doing a debug build. At that time, we generated a monolithic C string, so there was no better way to do things (we could not really inject comments).

Later, in commit 7d0f982b, we switched the generation to output a QLit object, in part to make it easier for future addition of conditional compilation. But this switch has also made it easier to interject strategic comments. That commit also forgot to delete some now-stale comments about long generated line lengths.

For now, type name debug aid comments are only output once per meta-type, rather than at all uses of the number used to encode the type to the introspection data. But this is still a lot more convenient than having to regenerate the file with the unmask operation temporarily turned on.

...

Quoted 4 lines
---
  scripts/qapi/introspect.py | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)

Misses a change to docs/devel/qapi-code.gen.tx:

docs/devel/qapi-code-gen.txt +1 -0
index 88a70e4d451..0c98c7d7b6c 100644
@@ -1392,6 +1392,7 @@ Example:
             { }
         })),
         QLIT_QDICT(((QLitDictEntry[]) {
+            /* q_empty */
             { "members", QLIT_QLIST(((QLitObject[]) {
                 { }
             })) },

Review const QLitObject %(c_name)s = %(c_string)s; · line 125

Quoted 8 lines
(quoted diff) +2 -2
@@ -118,8 +121,8 @@ const QLitObject %(c_name)s = %(c_string)s;
          if typ not in self._used_types:
              self._used_types.append(typ)
          # Clients should examine commands and events, not types.  Hide
-        # type names to reduce the temptation.  Also saves a few
-        # characters.
+        # type names as integers to reduce the temptation, but provide
+        # comments for debugging aid.

When I wrote the patch, I assumed the final sentence of the comment was talking about fewer characters in the generated .c file (I nuked it, since adding comments makes for a longer, not shorter, generated .c file); but now that I'm writing this email, I see it could also refer to fewer characters sent over the wire in the QMP command (which length is unchanged by this patch, but was a 13KiB savings compared to the unmasked version, per commit 1a9a507b). So feel free to bikeshed this comment.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] qapi: Add comments to aid debugging generated introspection

Quoted 32 lines · Eric Blake
Quoted 17 lines · Eric Blake

We consciously chose in commit 1a9a507b to hide QAPI type names from the generated introspection output, but added a command line option -u to unmask the type name when doing a debug build. At that time, we generated a monolithic C string, so there was no better way to do things (we could not really inject comments).

Later, in commit 7d0f982b, we switched the generation to output a QLit object, in part to make it easier for future addition of conditional compilation. But this switch has also made it easier to interject strategic comments. That commit also forgot to delete some now-stale comments about long generated line lengths.

For now, type name debug aid comments are only output once per meta-type, rather than at all uses of the number used to encode the type to the introspection data. But this is still a lot more convenient than having to regenerate the file with the unmask operation temporarily turned on.

...

Quoted 4 lines
---
  scripts/qapi/introspect.py | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)

Misses a change to docs/devel/qapi-code.gen.tx:

docs/devel/qapi-code-gen.txt +0 -0
index 88a70e4d451..0c98c7d7b6c 100644

docs/devel/qapi-code-gen.txt Example: · line 1398

Quoted 7 lines
docs/devel/qapi-code-gen.txt +1 -0
@@ -1392,6 +1392,7 @@ Example:
             { }
         })),
         QLIT_QDICT(((QLitDictEntry[]) {
+            /* q_empty */
             { "members", QLIT_QLIST(((QLitObject[]) {
                 { }
             })) },

Yes.

Quoted 11 lines
Quoted 11 lines
scripts/qapi/introspect.py +2 -0
index 6ad198ae5b5..b37160292bc 100644
@@ -35,10 +35,14 @@ def to_qlit(obj, level=0, suppress_first_indent=False):
     elif isinstance(obj, dict):
         elts = []
         for key, value in sorted(obj.items()):
+            if key == 'comment':
+                continue
             elts.append(indent(level + 1) + '{ %s, %s }' %
Quoted 8 lines

scripts/qapi/introspect.py def to_qlit(obj, level=0, suppress_first_indent=False): · line 48

Quoted 8 lines
scripts/qapi/introspect.py +2 -0
                         (to_c_string(key), to_qlit(value, level + 1, True)))
         elts.append(indent(level + 1) + '{}')
         ret += 'QLIT_QDICT(((QLitDictEntry[]) {\n'
+        if obj.get('comment'):
+            ret += indent(level + 1) + '/* %s */\n' % obj['comment']
         ret += ',\n'.join(elts) + '\n'
         ret += indent(level) + '}))'
     elif isinstance(obj, bool):

to_qlit() converts from a natural representation of JSON in Python to JSON text.

Your patch breaks it for JSON objects that have a member named 'comment'.

Related work: Marc-André's "[PATCH v6 09/15] qapi-introspect: add preprocessor conditions to generated QLit" uses tuples to augment JSON. He uses them for conditionals, but the technique could be generalized, say from his (jobj, ifcond) to (jobj, { 'if': ifcond, '#': comment }.

Quoted 14 lines
Quoted 14 lines
scripts/qapi/introspect.py +0 -3
@@ -78,7 +82,6 @@ class QAPISchemaGenIntrospectVisitor(QAPISchemaMonolithicCVisitor):
         for typ in self._used_types:
             typ.visit(self)
         # generate C
-        # TODO can generate awfully long lines
         name = c_name(self._prefix, protect=False) + 'qmp_schema_qlit'
         self._genh.add(mcgen('''
 #include "qapi/qmp/qlit.h"
@@ -118,8 +121,8 @@ const QLitObject %(c_name)s = %(c_string)s;
          if typ not in self._used_types:
              self._used_types.append(typ)
         # Clients should examine commands and events, not types.  Hide
-        # type names to reduce the temptation.  Also saves a few
-        # characters.
Quoted 8 lines

scripts/qapi/introspect.py const QLitObject %(c_name)s = %(c_string)s; · line 125

Quoted 2 lines
scripts/qapi/introspect.py +2 -0
+        # type names as integers to reduce the temptation, but provide
+        # comments for debugging aid.

When I wrote the patch, I assumed the final sentence of the comment was talking about fewer characters in the generated .c file (I nuked it, since adding comments makes for a longer, not shorter, generated .c file); but now that I'm writing this email, I see it could also refer to fewer characters sent over the wire in the QMP command (which

Yes, that was my intent.

Quoted 3 lines

length is unchanged by this patch, but was a 13KiB savings compared to the unmasked version, per commit 1a9a507b). So feel free to bikeshed this comment.

I think I'd merely clarify the comment's last sentence by adding "on the wire", ...

Quoted 8 lines

scripts/qapi/introspect.py const QLitObject %(c_name)s = %(c_string)s; · line 134

Quoted 8 lines
scripts/qapi/introspect.py +1 -0
         if isinstance(typ, QAPISchemaBuiltinType):
             return typ.name
         if isinstance(typ, QAPISchemaArrayType):
@@ -128,6 +131,8 @@ const QLitObject %(c_name)s = %(c_string)s;
 
     def _gen_qlit(self, name, mtype, obj):
         if mtype not in ('command', 'event', 'builtin', 'array'):
+            if not self._unmask:

... and perhaps briefly explain here why we generate a comment.

Quoted 4 lines
Quoted 4 lines
scripts/qapi/introspect.py +1 -0
+                obj['comment'] = name
             name = self._name(name)
         obj['name'] = name
         obj['meta-type'] = mtype
author
#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] qapi: Add comments to aid debugging generated introspection

Quoted 20 lines · Markus Armbruster
Quoted 18 lines · Eric Blake
Quoted 17 lines · Eric Blake

We consciously chose in commit 1a9a507b to hide QAPI type names from the generated introspection output, but added a command line option -u to unmask the type name when doing a debug build. At that time, we generated a monolithic C string, so there was no better way to do things (we could not really inject comments).

Later, in commit 7d0f982b, we switched the generation to output a QLit object, in part to make it easier for future addition of conditional compilation. But this switch has also made it easier to interject strategic comments. That commit also forgot to delete some now-stale comments about long generated line lengths.

For now, type name debug aid comments are only output once per meta-type, rather than at all uses of the number used to encode the type to the introspection data. But this is still a lot more convenient than having to regenerate the file with the unmask operation temporarily turned on.

Quoted 7 lines
Quoted 1 line

...

to_qlit() converts from a natural representation of JSON in Python to JSON text.

Your patch breaks it for JSON objects that have a member named 'comment'.

Hmm. None do, presently. And I don't see where it would be permitted in the QAPI schema for query-qmp-schema.

Quoted 5 lines

Related work: Marc-André's "[PATCH v6 09/15] qapi-introspect: add preprocessor conditions to generated QLit" uses tuples to augment JSON. He uses them for conditionals, but the technique could be generalized, say from his (jobj, ifcond) to (jobj, { 'if': ifcond, '#': comment }.

Yeah, I can probably rebase on top of that (and at this point, it's late enough to probably have missed 3.0 anyways, so I'm not time-crunched for getting it done right now).

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#5 lore raw

Re: [Qemu-devel] [PATCH 1/2] qapi: Add comments to aid debugging generated introspection

Quoted 23 lines · Eric Blake
Quoted 21 lines · Markus Armbruster
Quoted 19 lines · Eric Blake
Quoted 17 lines · Eric Blake

We consciously chose in commit 1a9a507b to hide QAPI type names from the generated introspection output, but added a command line option -u to unmask the type name when doing a debug build. At that time, we generated a monolithic C string, so there was no better way to do things (we could not really inject comments).

Later, in commit 7d0f982b, we switched the generation to output a QLit object, in part to make it easier for future addition of conditional compilation. But this switch has also made it easier to interject strategic comments. That commit also forgot to delete some now-stale comments about long generated line lengths.

For now, type name debug aid comments are only output once per meta-type, rather than at all uses of the number used to encode the type to the introspection data. But this is still a lot more convenient than having to regenerate the file with the unmask operation temporarily turned on.

...

Quoted 8 lines
Quoted 5 lines

to_qlit() converts from a natural representation of JSON in Python to JSON text.

Your patch breaks it for JSON objects that have a member named 'comment'.

Hmm. None do, presently. And I don't see where it would be permitted in the QAPI schema for query-qmp-schema.

So far, to_qlit() is completely oblivious of the schema; it just crunches JSON. I'd like to keep it that way, if practical.

Quoted 8 lines
Quoted 4 lines

Related work: Marc-André's "[PATCH v6 09/15] qapi-introspect: add preprocessor conditions to generated QLit" uses tuples to augment JSON. He uses them for conditionals, but the technique could be generalized, say from his (jobj, ifcond) to (jobj, { 'if': ifcond, '#': comment }.

Yeah, I can probably rebase on top of that (and at this point, it's late enough to probably have missed 3.0 anyways, so I'm not time-crunched for getting it done right now).

It's a lovely improvement for developers, but it'll be just as lovely in 3.1 :)

author
#6 lore raw

Re: [Qemu-devel] [PATCH 1/2] qapi: Add comments to aid debugging generated introspection

In reply to Eric Blake
Quoted 11 lines · Eric Blake

The generated qapi-introspect.c changes only with the addition of comments, such as:

| @@ -14927,6 +15410,7 @@
|          {}
|      })),
|      QLIT_QDICT(((QLitDictEntry[]) {
| +        /* QCryptoBlockInfoLUKSSlot */
|          { "members", QLIT_QLIST(((QLitObject[]) {
|              QLIT_QDICT(((QLitDictEntry[]) {
|                  { "name", QLIT_QSTR("active") },

---
...

scripts/qapi/introspect.py const QLitObject %(c_name)s = %(c_string)s; · line 135

Quoted 6 lines
scripts/qapi/introspect.py +2 -0
@@ -128,6 +131,8 @@ const QLitObject %(c_name)s = %(c_string)s;
 
      def _gen_qlit(self, name, mtype, obj):
          if mtype not in ('command', 'event', 'builtin', 'array'):
+            if not self._unmask:
+                obj['comment'] = name

If desired, we could change this to:

if not self._unmask:

    obj['comment'] = '"%s" = %s' % (self._name(name), name)

to produce comments like /* "0" = q_empty */

for even easier debugging (if I see a line containing "ret-type", QLIT_QSTR("0"), then I can grep for '"0" =' to directly look up the type name, rather than having to grep for 'name.*"0"' then scrolling back to find the associated comment).

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
author
#7 lore raw

PATCH 2/2 qapi: Drop qapi-gen --unmask option

In reply to Eric Blake

Now that we have useful access to the type name as a comment in the generated qapi-introspect.c, we don't need to regenerate code with a temporary -u option just to get at type names.

---
 scripts/qapi-gen.py        |  5 +----
 scripts/qapi/introspect.py | 12 ++++--------
 2 files changed, 5 insertions(+), 12 deletions(-)
scripts/qapi-gen.py +1 -4
index 3d98ca2e0c6..6ec7e481b1b 100755
@@ -26,9 +26,6 @@ def main(argv):
                         help="write output to directory OUTPUT_DIR")
     parser.add_argument('-p', '--prefix', action='store', default='',
                         help="prefix for symbols")
-    parser.add_argument('-u', '--unmask-non-abi-names', action='store_true',
-                        dest='unmask',
-                        help="expose non-ABI names in introspection")
     parser.add_argument('schema', action='store')
     args = parser.parse_args()
 
@@ -49,7 +46,7 @@ def main(argv):
     gen_visit(schema, args.output_dir, args.prefix, args.builtins)
     gen_commands(schema, args.output_dir, args.prefix)
     gen_events(schema, args.output_dir, args.prefix)
-    gen_introspect(schema, args.output_dir, args.prefix, args.unmask)
+    gen_introspect(schema, args.output_dir, args.prefix)
     gen_doc(schema, args.output_dir, args.prefix)
 
 
scripts/qapi/introspect.py +4 -8
index b37160292bc..8dd4136c0af 100644
@@ -58,11 +58,10 @@ def to_c_string(string):
 
 class QAPISchemaGenIntrospectVisitor(QAPISchemaMonolithicCVisitor):
 
-    def __init__(self, prefix, unmask):
+    def __init__(self, prefix):
         QAPISchemaMonolithicCVisitor.__init__(
             self, prefix, 'qapi-introspect',
             ' * QAPI/QMP schema introspection', __doc__)
-        self._unmask = unmask
         self._schema = None
         self._qlits = []
         self._used_types = []
@@ -104,8 +103,6 @@ const QLitObject %(c_name)s = %(c_string)s;
         return not isinstance(entity, QAPISchemaType)
 
     def _name(self, name):
-        if self._unmask:
-            return name
         if name not in self._name_map:
             self._name_map[name] = '%d' % len(self._name_map)
         return self._name_map[name]
@@ -131,8 +128,7 @@ const QLitObject %(c_name)s = %(c_string)s;
 
     def _gen_qlit(self, name, mtype, obj):
         if mtype not in ('command', 'event', 'builtin', 'array'):
-            if not self._unmask:
-                obj['comment'] = name
+            obj['comment'] = name
             name = self._name(name)
         obj['name'] = name
         obj['meta-type'] = mtype
@@ -188,7 +184,7 @@ const QLitObject %(c_name)s = %(c_string)s;
         self._gen_qlit(name, 'event', {'arg-type': self._use_type(arg_type)})
 
 
-def gen_introspect(schema, output_dir, prefix, opt_unmask):
-    vis = QAPISchemaGenIntrospectVisitor(prefix, opt_unmask)
+def gen_introspect(schema, output_dir, prefix):
+    vis = QAPISchemaGenIntrospectVisitor(prefix)
     schema.visit(vis)
     vis.write(output_dir)
Signature · 1 line
2.14.4
Reviewed-by on v1 2/2
#8 lore raw

Re: [Qemu-devel] [PATCH 2/2] qapi: Drop qapi-gen --unmask option

Quoted 5 lines · Eric Blake

Now that we have useful access to the type name as a comment in the generated qapi-introspect.c, we don't need to regenerate code with a temporary -u option just to get at type names.

Signature · 1 line
Eduardo
#9 lore raw

Re: [Qemu-devel] [PATCH 2/2] qapi: Drop qapi-gen --unmask option

In reply to Eric Blake
Quoted 5 lines · Eric Blake

Now that we have useful access to the type name as a comment in the generated qapi-introspect.c, we don't need to regenerate code with a temporary -u option just to get at type names.

I occasionally feed output of query-qmp-schema to ad hoc Python scripts. My last one searched for object types containing non-string members (directly or indirectly). -u remains useful there, and having to recompile is not a problem. I'd prefer to keep it.

author
#10 lore raw

Re: [Qemu-devel] [PATCH 2/2] qapi: Drop qapi-gen --unmask option

Quoted 6 lines · Markus Armbruster
Quoted 4 lines · Eric Blake

Now that we have useful access to the type name as a comment in the generated qapi-introspect.c, we don't need to regenerate code with a temporary -u option just to get at type names.

Quoted 6 lines
Quoted 1 line

I occasionally feed output of query-qmp-schema to ad hoc Python scripts. My last one searched for object types containing non-string members (directly or indirectly). -u remains useful there, and having to recompile is not a problem. I'd prefer to keep it.

Would it be any easier to argue for the removal of -u if the generated output resembled:

{ "ret-type", QLIT_QSTR("1") /* Foo */ },

that is, sticking in the comment everywhere the type name is mangled to an integer, rather than just once per type?

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#11 lore raw

Re: [Qemu-devel] [PATCH 2/2] qapi: Drop qapi-gen --unmask option

Quoted 14 lines · Eric Blake
Quoted 6 lines · Markus Armbruster
Quoted 4 lines · Eric Blake

Now that we have useful access to the type name as a comment in the generated qapi-introspect.c, we don't need to regenerate code with a temporary -u option just to get at type names.

Quoted 6 lines
Quoted 1 line

I occasionally feed output of query-qmp-schema to ad hoc Python scripts. My last one searched for object types containing non-string members (directly or indirectly). -u remains useful there, and having to recompile is not a problem. I'd prefer to keep it.

Quoted 7 lines

Would it be any easier to argue for the removal of -u if the generated output resembled:

{ "ret-type", QLIT_QSTR("1") /* Foo */ },

that is, sticking in the comment everywhere the type name is mangled to an integer, rather than just once per type?

Doesn't help with my use case. Let me elaborate on it.

My ad hoc Python script gets the output of query-qmp-schema like this:

    pipe = subprocess.Popen('socat %s STDIO' % qmp_socket,
                            shell=True,
                            stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    (out, err) = pipe.communicate('{ "execute": "qmp_capabilities" }\n'
                                  '{ "execute": "query-qmp-schema" }\n')
    # three lines: greeting, output of qmp_capabilities, query-qmp-schema
    return json.loads(out.split('\n')[2])['return']

This returns an abstract syntax tree, represented in Python the obvious way. I can then explore it in Python, say search for object types with certain properties. For example, commit 2860b2b2cb8:

Thus, the flaw puts an artificial restriction on the QAPI schema: we can't have potentially empty objects and arrays within BlockdevOptions, except when they're optional and "empty" has the same meaning as "absent".

--> Our QAPI schema satisfies this restriction (I checked), but it's a
trap for the unwary, and a temptation to employ awkward workarounds for the wary. Let's get rid of it.

I checked with a Python script that read the schema as shown above. Without -u, I'd have to revert the identifier hiding. I could certainly write some more Python to read the mapping from the generated C, but that feels like busy work.

author
#12 lore raw

Re: [Qemu-devel] [PATCH 2/2] qapi: Drop qapi-gen --unmask option

Quoted 22 lines · Markus Armbruster
Quoted 7 lines · Eric Blake
Quoted 6 lines · Markus Armbruster
Quoted 4 lines · Eric Blake

Now that we have useful access to the type name as a comment in the generated qapi-introspect.c, we don't need to regenerate code with a temporary -u option just to get at type names.

     # three lines: greeting, output of qmp_capabilities, query-qmp-schema
     return json.loads(out.split('\n')[2])['return']

This returns an abstract syntax tree, represented in Python the obvious way. I can then explore it in Python, say search for object types with certain properties. For example, commit 2860b2b2cb8:

Thus, the flaw puts an artificial restriction on the QAPI schema: we can't have potentially empty objects and arrays within BlockdevOptions, except when they're optional and "empty" has the same meaning as "absent".

Quoted 8 lines

--> Our QAPI schema satisfies this restriction (I checked), but it's a
trap for the unwary, and a temptation to employ awkward workarounds for the wary. Let's get rid of it.

I checked with a Python script that read the schema as shown above. Without -u, I'd have to revert the identifier hiding. I could certainly write some more Python to read the mapping from the generated C, but that feels like busy work.

Good argument. Okay, I'm dropping this patch, and tweaking the other patch commit message to explain that -u is still useful, even with the addition of comment aids.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org