qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org,  michael.roth@amd.com,  jsnow@redhat.com,
	eblake@redhat.com
Subject: Re: [PATCH 05/27] qapi tests: Elide redundant has_FOO in generated C
Date: Fri, 16 Sep 2022 12:36:30 +0200	[thread overview]
Message-ID: <87fsgrd2s1.fsf@pond.sub.org> (raw)
In-Reply-To: <YyQ51Gvy2JS56+TL@redhat.com> ("Daniel P. Berrangé"'s message of "Fri, 16 Sep 2022 09:54:44 +0100")

Daniel P. Berrangé <berrange@redhat.com> writes:

> On Thu, Sep 15, 2022 at 10:42:55PM +0200, Markus Armbruster wrote:
>> The has_FOO for pointer-valued FOO are redundant, except for arrays.
>> They are also a nuisance to work with.  Recent commit "qapi: Start to
>> elide redundant has_FOO in generated C" provided the means to elide
>> them step by step.  This is the step for
>> tests/qapi-schema/qapi-schema-test.json.
>> 
>> Said commit explains the transformation in more detail.  The invariant
>> violations mentioned there do not occur here.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  tests/qtest/qmp-cmd-test.c               |  2 +-
>>  tests/unit/test-qmp-cmds.c               | 26 +++++++++++-------------
>>  tests/unit/test-qmp-event.c              |  4 ++--
>>  tests/unit/test-qobject-input-visitor.c  |  2 +-
>>  tests/unit/test-qobject-output-visitor.c |  2 --
>>  tests/unit/test-visitor-serialization.c  |  3 +--
>>  scripts/qapi/schema.py                   |  4 +---
>>  7 files changed, 18 insertions(+), 25 deletions(-)
>
>> diff --git a/tests/unit/test-qmp-cmds.c b/tests/unit/test-qmp-cmds.c
>> index 6085c09995..2373cd64cb 100644
>> --- a/tests/unit/test-qmp-cmds.c
>> +++ b/tests/unit/test-qmp-cmds.c
>> @@ -43,15 +43,15 @@ void qmp_user_def_cmd1(UserDefOne * ud1, Error **errp)
>>  {
>>  }
>>  
>> -FeatureStruct1 *qmp_test_features0(bool has_fs0, FeatureStruct0 *fs0,
>> -                                   bool has_fs1, FeatureStruct1 *fs1,
>> -                                   bool has_fs2, FeatureStruct2 *fs2,
>> -                                   bool has_fs3, FeatureStruct3 *fs3,
>> -                                   bool has_fs4, FeatureStruct4 *fs4,
>> -                                   bool has_cfs1, CondFeatureStruct1 *cfs1,
>> -                                   bool has_cfs2, CondFeatureStruct2 *cfs2,
>> -                                   bool has_cfs3, CondFeatureStruct3 *cfs3,
>> -                                   bool has_cfs4, CondFeatureStruct4 *cfs4,
>> +FeatureStruct1 *qmp_test_features0(FeatureStruct0 *fs0,
>> +                                   FeatureStruct1 *fs1,
>> +                                   FeatureStruct2 *fs2,
>> +                                   FeatureStruct3 *fs3,
>> +                                   FeatureStruct4 *fs4,
>> +                                   CondFeatureStruct1 *cfs1,
>> +                                   CondFeatureStruct2 *cfs2,
>> +                                   CondFeatureStruct3 *cfs3,
>> +                                   CondFeatureStruct4 *cfs4,
>>                                     Error **errp)
>
> It makes me so happy to see this change finally arrive, the new
> method signature just "feels right".

Thank you!

>> @@ -87,8 +86,8 @@ UserDefTwo *qmp_user_def_cmd2(UserDefOne *ud1a,
>>  
>>      ud1c->string = strdup(ud1a->string);
>>      ud1c->integer = ud1a->integer;
>> -    ud1d->string = strdup(has_udb1 ? ud1b->string : "blah0");
>> -    ud1d->integer = has_udb1 ? ud1b->integer : 0;
>> +    ud1d->string = strdup(ud1b ? ud1b->string : "blah0");
>> +    ud1d->integer = ud1b ? ud1b->integer : 0;
>
> Pre-existing problem. use of 'strdup' will leave these fields
> NULL on OOM and nothing is checking this.

Yes.

Here, the value is assigned to a mandatory member of a QAPI object type.
Such members are specified not to be null.  When strdup() returns null
on OOM, we break the invariant.  Unaffected by the patch.

However, changes like

   -    obj->has_frob = true;
        obj->frob = strdup(...);

*are* affected: before the patch, we break the invariant "obj->has_frob
== !!obj->frob", and afterwards, we change present to absent instead.

Arguing the finer points of this change seems a waste of time, since OOM
means doom anyway.

>                                           Fortunately it is only
> the test suite so not a big deal, but worth changing to g_strdup
> at some point (separate from this patch / series). Repeated in
> other chunks of the test beyond this quoted one, but I won't
> point them out.

Yes, g_strdup() would be better.

I count some 50 occurences of strdup() in the tree.  Getting rid of them
shouldn't be too hard.

> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Thanks again!



  reply	other threads:[~2022-09-16 10:37 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-15 20:42 [PATCH 00/27] qapi: Elide redundant has_FOO in generated C Markus Armbruster
2022-09-15 20:42 ` [PATCH 01/27] docs/devel/qapi-code-gen: Update example to match current code Markus Armbruster
2022-09-16  8:38   ` Daniel P. Berrangé
2022-09-15 20:42 ` [PATCH 02/27] qapi: Tidy up whitespace in generated code Markus Armbruster
2022-09-16  8:44   ` Daniel P. Berrangé
2022-09-15 20:42 ` [PATCH 03/27] docs/devel/qapi-code-gen: Extend example for next commit's change Markus Armbruster
2022-09-16  8:47   ` Daniel P. Berrangé
2022-09-15 20:42 ` [PATCH 04/27] qapi: Start to elide redundant has_FOO in generated C Markus Armbruster
2022-09-16  8:50   ` Daniel P. Berrangé
2022-09-15 20:42 ` [PATCH 05/27] qapi tests: Elide " Markus Armbruster
2022-09-16  8:54   ` Daniel P. Berrangé
2022-09-16 10:36     ` Markus Armbruster [this message]
2022-09-15 20:42 ` [PATCH 06/27] qapi acpi: " Markus Armbruster
2022-09-16  7:50   ` Igor Mammedov
2022-09-16  8:00   ` Ani Sinha
2022-09-16  8:18     ` Markus Armbruster
2022-09-16  8:21       ` Ani Sinha
2022-09-16  8:37         ` Daniel P. Berrangé
2022-09-16  8:45           ` Ani Sinha
2022-09-16  9:32             ` Ani Sinha
2022-09-16  9:35             ` Markus Armbruster
2022-09-16  8:59   ` Daniel P. Berrangé
2022-09-15 20:42 ` [PATCH 07/27] qapi audio: " Markus Armbruster
2022-09-16  9:13   ` Daniel P. Berrangé
2022-09-15 20:42 ` [PATCH 08/27] qapi block: " Markus Armbruster
2022-09-15 20:42 ` [PATCH 09/27] qapi char: " Markus Armbruster
2022-09-16  9:09   ` Daniel P. Berrangé
2022-09-15 20:43 ` [PATCH 10/27] qapi crypto: " Markus Armbruster
2022-09-16  9:02   ` Daniel P. Berrangé
2022-09-15 20:43 ` [PATCH 11/27] qapi dump: " Markus Armbruster
2022-09-15 20:43 ` [PATCH 12/27] qapi job: " Markus Armbruster
2022-09-16  8:42   ` Vladimir Sementsov-Ogievskiy
2022-09-15 20:43 ` [PATCH 13/27] qapi machine: " Markus Armbruster
2022-09-15 20:43 ` [PATCH 14/27] qapi migration: " Markus Armbruster
2022-09-22 11:28   ` Dr. David Alan Gilbert
2022-09-22 12:40     ` Daniel P. Berrangé
2022-09-22 13:15   ` Philippe Mathieu-Daudé via
2022-09-22 13:36     ` Markus Armbruster
2022-09-15 20:43 ` [PATCH 15/27] qapi misc: " Markus Armbruster
2022-09-15 20:43 ` [PATCH 16/27] qapi net: " Markus Armbruster
2022-09-15 20:43 ` [PATCH 17/27] qapi pci: " Markus Armbruster
2022-09-15 20:43 ` [PATCH 18/27] qapi qdev qom: " Markus Armbruster
2022-09-15 20:43 ` [PATCH 19/27] qapi replay: " Markus Armbruster
2022-09-15 20:43 ` [PATCH 20/27] qapi rocker: " Markus Armbruster
2022-09-15 20:43 ` [PATCH 21/27] qapi run-state: " Markus Armbruster
2022-09-15 20:43 ` [PATCH 22/27] qapi stats: " Markus Armbruster
2022-09-16 14:29   ` Mark Kanda
2022-09-15 20:43 ` [PATCH 23/27] qapi tpm: " Markus Armbruster
2022-09-15 21:12   ` Stefan Berger
2022-09-15 20:43 ` [PATCH 24/27] qapi transaction: " Markus Armbruster
2022-09-15 20:43 ` [PATCH 25/27] qapi ui: " Markus Armbruster
2022-09-16  9:04   ` Daniel P. Berrangé
2022-09-15 20:43 ` [PATCH 26/27] qapi qga: " Markus Armbruster
2022-09-15 20:43 ` [PATCH 27/27] qapi: Drop temporary logic to support conversion step by step Markus Armbruster
2022-09-16  9:04   ` Daniel P. Berrangé
2022-09-16  8:42 ` [PATCH 00/27] qapi: Elide redundant has_FOO in generated C Vladimir Sementsov-Ogievskiy

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=87fsgrd2s1.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=michael.roth@amd.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).