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: Eric Blake <eblake@redhat.com>, John Snow <jsnow@redhat.com>,
	qemu-devel <qemu-devel@nongnu.org>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [PATCH v6 02/11] qapi: wrap Sequence[str] in an object
Date: Thu, 05 Aug 2021 12:44:47 +0200	[thread overview]
Message-ID: <87zgtw9nmo.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <CAMxuvawv2-=90LUt_ByMhwckAcH=3M4h3oQvCoFbk=qavrfjWg@mail.gmail.com> (=?utf-8?Q?=22Marc-Andr=C3=A9?= Lureau"'s message of "Wed, 4 Aug 2021 12:22:48 +0400")

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

> Hi
>
> On Mon, Aug 2, 2021 at 1:21 PM Markus Armbruster <armbru@redhat.com> wrote:
>
>> marcandre.lureau@redhat.com writes:
>>
>> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
>> >
>> > Except for the special casing assert in _make_implicit_object_type(),
>> > which needs to handle schema objects, it's a mechanical change.
>> >
>> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> > ---
[...]
>> > diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py
>> > index 9a348ca2e5..77a8c33ad4 100644
>> > --- a/scripts/qapi/introspect.py
>> > +++ b/scripts/qapi/introspect.py
[...]
>> > @@ -125,10 +124,10 @@ def indent(level: int) -> str:
>> >          if obj.comment:
>> >              ret += indent(level) + f"/* {obj.comment} */\n"
>> >          if obj.ifcond:
>> > -            ret += gen_if(obj.ifcond)
>> > +            ret += gen_if(obj.ifcond.ifcond)
>> >          ret += _tree_to_qlit(obj.value, level)
>> >          if obj.ifcond:
>> > -            ret += '\n' + gen_endif(obj.ifcond)
>> > +            ret += '\n' + gen_endif(obj.ifcond.ifcond)
>> >          return ret
>> >
>> >      ret = ''
>>
>> You update obj.ifcond to obj.ifcond.ifcond when used as argument of
>> gen_if() and gen_endif().  This changes the argument from Tuple to
>> Sequence.  Fine, because Tuple is a special Sequence.
>>
>> Digression: I don't (anymore) understand why we made self.ifcond Tuple.
>> John, do you remember?
>>
>> You don't update obj.ifcond when used as conditional.  The code now
>> calls gen_if() and gen_endif() even for an empty Sequence.
>>
>> I believe this can't actually happen because check_if() rejects [] with
>> "'if' condition [] of %s is useless".
>>
>> Still, the mechanical change should update to obj.ifcond even when used
>> as conditional.
>>
>> Are there other, possibly not so harmless uses of values that change
>> from Sequence to QAPISchemaIfCond the patch doesn't update?
>>
>> Or asked differently: how did you find what to update?
>>
>
> Eh, you are asking me for something I spent just a few hours a few times
> over the last year. Sorry!

That's fair.

> Most probably simply with code reading/grepping, linter and the test suite.

Plausible.

I'm somewhat worried about the bug pattern, but a thorough search feels
uneconomical.  Instead, I've attempted two things to flush out such
bugs:

* Run "make check" with the appended patch.  Fails with v6, i.e. it can
  detect execution of the bug pattern.  Passes with v7.

* The variables holding QAPISchemaIfCond are generally named @ifcond.
  Eyeball grep -w ifcond with ifcond.MUMBLE, ifcond: QAPISchemaIfCond,
  and def parameter lists ignored.  Most remaining grep hits move values
  around.  I can see a few hits where @ifcond is used like a boolean:

  - In docgen_ifcond() and cgen_ifcond(), but @ifcond isn't
    QAPISchemaIfCond there.  Okay, but there's an unrelated oddity I'll
    discuss in review of PATCH 07.

  - In QAPISchemaIfCond.__init__(): likewise.

  - In QAPISchemaEntity.__init__() and QAPISchemaMember.__init__():
    okay, because @ifcond is Optional[QAPISchemaIfCond] there.

  - In check_if(), but @ifcond isn't QAPISchemaIfCond there.  Okay.

I think that's all we can sensibly do now.

[...]


diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index 627735a431..a71ad31d59 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -43,6 +43,9 @@ def docgen(self):
     def is_present(self):
         return bool(self.ifcond)
 
+    def __bool__(self):
+        assert False
+
 
 class QAPISchemaEntity:
     meta: Optional[str] = None
@@ -61,7 +64,7 @@ def __init__(self, name: str, info, doc, ifcond=None, features=None):
         # such place).
         self.info = info
         self.doc = doc
-        self._ifcond = ifcond or QAPISchemaIfCond()
+        self._ifcond = ifcond if ifcond != None else QAPISchemaIfCond()
         self.features = features or []
         self._checked = False
 
@@ -665,7 +668,7 @@ def __init__(self, name, info, ifcond=None):
         assert isinstance(name, str)
         self.name = name
         self.info = info
-        self.ifcond = ifcond or QAPISchemaIfCond()
+        self.ifcond = ifcond if ifcond != None else QAPISchemaIfCond()
         self.defined_in = None
 
     def set_defined_in(self, name):



  reply	other threads:[~2021-08-05 10:46 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-18 10:24 [PATCH v6 00/11] qapi: untie 'if' conditions from C preprocessor marcandre.lureau
2021-06-18 10:24 ` [PATCH v6 01/11] docs: update the documentation upfront about schema configuration marcandre.lureau
2021-07-12 14:07   ` Markus Armbruster
2021-06-18 10:24 ` [PATCH v6 02/11] qapi: wrap Sequence[str] in an object marcandre.lureau
2021-08-02  9:21   ` Markus Armbruster
2021-08-03 17:55     ` John Snow
2021-08-04  8:22     ` Marc-André Lureau
2021-08-05 10:44       ` Markus Armbruster [this message]
2021-08-06 11:19       ` Markus Armbruster
2021-06-18 10:24 ` [PATCH v6 03/11] qapi: add QAPISchemaIfCond.is_present() marcandre.lureau
2021-08-02  9:52   ` Markus Armbruster
2021-08-04  8:22     ` Marc-André Lureau
2021-06-18 10:25 ` [PATCH v6 04/11] qapi: _make_enum_members() to work with pre-built QAPISchemaIfCond marcandre.lureau
2021-08-02 10:41   ` Markus Armbruster
2021-08-04  8:22     ` Marc-André Lureau
2021-06-18 10:25 ` [PATCH v6 05/11] qapi: introduce QAPISchemaIfCond.cgen() marcandre.lureau
2021-08-02 14:46   ` Markus Armbruster
2021-08-03 11:19     ` Markus Armbruster
2021-08-03 11:20       ` Markus Armbruster
2021-08-03 11:23         ` Markus Armbruster
2021-08-04  8:23     ` Marc-André Lureau
2021-06-18 10:25 ` [PATCH v6 06/11] qapidoc: introduce QAPISchemaIfCond.docgen() marcandre.lureau
2021-08-02 15:47   ` Markus Armbruster
2021-08-04  8:23     ` Marc-André Lureau
2021-06-18 10:25 ` [PATCH v6 07/11] qapi: replace if condition list with dict {'all': [...]} marcandre.lureau
2021-08-03 13:05   ` Markus Armbruster
2021-08-04  8:23     ` Marc-André Lureau
2021-08-05 15:11     ` John Snow
2021-08-03 13:17   ` Markus Armbruster
2021-06-18 10:25 ` [PATCH v6 08/11] qapi: add 'any' condition marcandre.lureau
2021-08-03 13:20   ` Markus Armbruster
2021-06-18 10:25 ` [PATCH v6 09/11] qapi: convert 'if' C-expressions to the new syntax tree marcandre.lureau
2021-08-03 13:22   ` Markus Armbruster
2021-06-18 10:25 ` [PATCH v6 10/11] qapi: add 'not' condition operation marcandre.lureau
2021-06-18 10:25 ` [PATCH v6 11/11] qapi: make 'if' condition strings simple identifiers marcandre.lureau
2021-08-03 13:35   ` Markus Armbruster
2021-08-04  8:22     ` Marc-André Lureau
2021-08-03 13:44 ` [PATCH v6 00/11] qapi: untie 'if' conditions from C preprocessor Markus Armbruster
2021-08-04  8:25   ` Marc-André Lureau

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=87zgtw9nmo.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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.