From: Markus Armbruster <armbru@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: Eric Blake <eblake@redhat.com>,
mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org,
anderson@redhat.com, pbonzini@redhat.com, lersek@redhat.com
Subject: Re: [Qemu-devel] [PATCH 04/21] qobject: add quint type
Date: Tue, 21 Mar 2017 17:49:24 +0100 [thread overview]
Message-ID: <878tnyk223.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <CAJ+F1CKMUGA26PhTchxL3GNBJr11JMdS-eujvhF3gSyLULjbXg@mail.gmail.com> ("Marc-André Lureau"'s message of "Tue, 21 Mar 2017 12:41:58 +0000")
Marc-André Lureau <marcandre.lureau@gmail.com> writes:
> Hi
>
> On Mon, Mar 13, 2017 at 5:29 PM Marc-André Lureau <mlureau@redhat.com>
> wrote:
>
> Hi
>
> ----- Original Message -----
>> On 03/13/2017 02:15 AM, Markus Armbruster wrote:
>> > Eric Blake <eblake@redhat.com> writes:
>> >
>> >> On 03/11/2017 07:22 AM, Marc-André Lureau wrote:
>> >>> The type is not used at all yet. Add some tests to exercice it.
>> >>
>> >> s/exercice/exercise/
>> >>
>> >> I wonder if we need this patch at all.
>> >>
>> >> I've been thinking about a possible alternative representation, such
>> >> that a single QInt type can cover _both_ signed and unsigned types, by
>> >> having QInt track a sign bit bool in addition to a uint64_t value.
>> >>
>>
>> > You say you've been thinking about extending QInt's range to cover
>> > uint64_t. I've been thinking even more radically: replace both QInt and
>> > QFloat by QNumber. This is how JSON *actually* works.
>> >
>> > The new QNumber type provides constructors from double, int64_t and
>> > uint64_t. It also provides conversion functions to double, int64_t and
>> > uint64_t. The latter two can fail.
>>
>> Interesting - I like it, as it takes my idea and goes one step further.
>> You'd want to track 64 bits of precision rather than just 53, when the
>> input was integral, but the idea seems to have some merit (we have some
>> special case in the testsuite for what happens in alternates with
>> various combinations of 'number' vs. 'int' that may need tweaking when
>> they are no longer distinguishable as QInt vs QFloat, but that's not too
>> onerous).
>>
>
> I wonder the benefits from hiding the real type behind a QNumber
> "superclass", then having to type check at a lower level. QType is not only
> used for json,
The less it is used for non-JSON purposes, the better.
> so I see some benefits from having a bit stricter type
> declaration and compile-time check. But I don't have a very good idea of
> what it would mean to have a generic QNumber type, I could try to implement
> it to have a more informed opinion.
>
>
> I have looked a bit more into implementing a QNumber type.
>
> There is a bit more error handling to add everywhere for getting a value
> (for get_int, get_uint), as some conversions will fail. The qdict getters
> will have to throw those errors too. Whereas the QObject type check or
> dispatch is there, so less error handling to add.
How many places convert QNumber to C integer type?
How many of them have to do range checking anyway?
If range checking turns out to be common, we could fuse it into the
conversion, say return -EINVAL for qtype other than QNumber, and -ERANGE
for a QNumber out of range, like qemu_strtol() does.
> In my proposal, conversion from int to uint is done for positive values,
> with the qdict helper (is it the only way we access json parsed values?).
I doubt it.
> Do we want to cast a negative int to a uint? Do we have qmp clients using
> this representation today, and can we break this?
We don't have "intepret negative as large unsigned" issues in the JSON
parser, but we have them in the QObject input visitor:
visit_type_uint64() rejects integers above INT64_MAX, but happily
accepts integers between INT64_MIN and -1, and cast them to uint64_t.
This makes no sense for QMP. It crept in right at the beginning because
visitors were added without adequate test coverage. Eric noticed this
problem and added the FIXME in commit f755dea, four and a half years
later. We still lack an adequate test case. I'll add one.
We're awfully slow learners.
QMP clients that work around the "large positive integers are rejected"
bugs by sending large negative ones instead may well exist. Fixing the
interface would break them. Depressing. Eric, could you have a peek at
libvirt?
Additionally, direct users of QObject could conceivably convert QInt to
int64_t, then silently cast to unsigned. Or narrower integer types;
same bad idea, really. The only way to find them is to review all the
code getting integers out of QObject.
> The qdev-properties will be slightly less convenient to define, but that's
> minor since it's behind macros, ex:
> - .qtype = QTYPE_QUINT, \
> - .defval.u = (_type)_defval, \
> + .qtype = QTYPE_QNUM, \
> + .defval.type = QNUM_U64, \
> + .defval.u.u64 = (_type)_defval, \
>
> The biggest issue I have is how to handle the alt visitors if all ints are
> numbers, ex with AltIntNum:
>
> switch ((*obj)->type) {
> case QTYPE_QNUM:
> visit_type_int(v, name, &(*obj)->u.i, &err);
> break;
> case QTYPE_QNUM:
> visit_type_number(v, name, &(*obj)->u.n, &err);
> break;
>
> Should the generator have special handling for QNUM and dispatch based on
> underlying type?
I'm afraid we'll need that for keyval anyway.
I've been playing with alternates a bit. I think
visit_start_alternate() needs to be redone. Need to find time to finish
my experiments and post patches.
> Overall, it seems to me that using QUINT like I proposed is more
> straightforward and equally convenient provided we have conversion helpers
> where needed (mostly for qdict).
Contradicts my gut feeling, but my gut is anything but infallible. I
guess I'd like to see (sketches of) both, so we can make an informed
decision.
> thanks for your comments
next prev parent reply other threads:[~2017-03-21 16:49 UTC|newest]
Thread overview: 46+ 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-trivial] [PATCH 01/21] qapi: add info comment for generated types Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] " Marc-André Lureau
2017-03-13 7:01 ` [Qemu-trivial] " Markus Armbruster
2017-03-13 7:01 ` Markus Armbruster
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-trivial] [PATCH 03/21] object: fix potential leak in getters Marc-André Lureau
2017-03-11 13:22 ` [Qemu-devel] " Marc-André Lureau
2017-03-21 14:43 ` [Qemu-trivial] " Eric Blake
2017-03-21 14:43 ` Eric Blake
2017-04-23 17:16 ` [Qemu-trivial] " Michael Tokarev
2017-04-23 17:16 ` [Qemu-devel] " 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 [this message]
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=878tnyk223.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=anderson@redhat.com \
--cc=eblake@redhat.com \
--cc=lersek@redhat.com \
--cc=marcandre.lureau@gmail.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=pbonzini@redhat.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 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.