qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-arm <qemu-arm@nongnu.org>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"patches@linaro.org" <patches@linaro.org>
Subject: Re: [Qemu-devel] [PATCH 1/3] qdev-properties.h: Explicitly set the default value for arraylen properties
Date: Thu, 13 Jul 2017 15:26:35 +0100	[thread overview]
Message-ID: <CAFEAcA--qraHck1_ba9ZFbZU+N-3FMzY8Z5rpri-NKr6K-dUmA@mail.gmail.com> (raw)
In-Reply-To: <87lgns2zps.fsf@dusky.pond.sub.org>

On 13 July 2017 at 15:11, Markus Armbruster <armbru@redhat.com> wrote:
> Peter Maydell <peter.maydell@linaro.org> writes:
>
>> In DEFINE_PROP_ARRAY, because we use a PropertyInfo (qdev_prop_arraylen)
>> which has a .set_default_value member we will set the field to a default
>> value. That default value will be zero, by the C rule that struct
>> initialization sets unmentioned members to zero if at least one member
>> is initialized. However it's clearer to state it explicitly.
>>
>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>> ---
>> If my eyeball of the sources is correct, this is the only case we
>> have of a Property struct that uses a PropertyInfo with a non-NULL
>> .set_default_value but which doesn't explicitly set .defval.u.
>> ---
>>  include/hw/qdev-properties.h | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
>> index 0604c33..36d040c 100644
>> --- a/include/hw/qdev-properties.h
>> +++ b/include/hw/qdev-properties.h
>> @@ -110,6 +110,7 @@ extern PropertyInfo qdev_prop_arraylen;
>>                            _arrayfield, _arrayprop, _arraytype) {        \
>>          .name = (PROP_ARRAY_LEN_PREFIX _name),                          \
>>          .info = &(qdev_prop_arraylen),                                  \
>> +        .defval.u = 0,                                                  \
>>          .offset = offsetof(_state, _field)                              \
>>              + type_check(uint32_t, typeof_field(_state, _field)),       \
>>          .arrayinfo = &(_arrayprop),                                     \
>
> Hmm.
>
> .info and .defval apply to the array *length*.
> .info.set_default_value() is set_default_uint(), which uses .defval.u.
> Setting it here is correct.
>
> The array *elements* are described by .arrayinfo.  There is no
> .arraydefval, but that's okay, because .arrayinfo.set_default_value()
> doesn't get called.  Correct?

Correct. (There's no way to specify a default value for array properties.)

thanks
-- PMM

  reply	other threads:[~2017-07-13 14:26 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-11 15:53 [Qemu-devel] [PATCH 0/3] Allow int props with no default, use them in ARM Peter Maydell
2017-07-11 15:53 ` [Qemu-devel] [PATCH 1/3] qdev-properties.h: Explicitly set the default value for arraylen properties Peter Maydell
2017-07-11 16:46   ` Marc-André Lureau
2017-07-13 14:11   ` Markus Armbruster
2017-07-13 14:26     ` Peter Maydell [this message]
2017-07-13 16:21       ` Markus Armbruster
2017-07-11 15:53 ` [Qemu-devel] [PATCH 2/3] qdev: support properties which don't set a default value Peter Maydell
2017-07-11 17:15   ` Marc-André Lureau
2017-07-11 17:25     ` Peter Maydell
2017-07-12 11:22   ` Markus Armbruster
2017-07-12 12:27     ` Peter Maydell
2017-07-13 15:38     ` Peter Maydell
2017-07-13 17:10       ` Markus Armbruster
2017-07-13 17:18         ` Peter Maydell
2017-07-13 18:25           ` Markus Armbruster
2017-07-11 15:53 ` [Qemu-devel] [PATCH 3/3] target/arm: Make Cortex-M3 and M4 default to 8 PMSA regions Peter Maydell
2017-07-11 17:18   ` Marc-André Lureau
2017-07-11 17:27     ` Peter Maydell
2017-07-11 17:30       ` 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=CAFEAcA--qraHck1_ba9ZFbZU+N-3FMzY8Z5rpri-NKr6K-dUmA@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=armbru@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=patches@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --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).