From: David Hildenbrand <david@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v1 6/9] qapi: rewrite string-input-visitor
Date: Mon, 19 Nov 2018 15:12:11 +0100 [thread overview]
Message-ID: <3d186921-e32f-60aa-cfc6-07345f6795c7@redhat.com> (raw)
In-Reply-To: <87muq972p0.fsf@dusky.pond.sub.org>
>>
>> Tests have to be fixed up:
>> - Two BUGs were hardcoded that are fixed now
>> - The string-input-visitor now actually returns a parsed list and not
>> an ordered set.
>
> I'd expect this to necessitate an update of callers that expect a set, but...
>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
>> include/qapi/string-input-visitor.h | 4 +-
>> qapi/string-input-visitor.c | 410 ++++++++++++++++------------
>> tests/test-string-input-visitor.c | 18 +-
>> 3 files changed, 239 insertions(+), 193 deletions(-)
>
> ... there's none.
>
> Let me know if you need help finding them. I think we tracked them down
> during the discussion that led to this series.
>
Indeed, I missed to document that. So here is the outcome:
1. backends/hostmem.c:host_memory_backend_set_host_nodes()
-> calls visit_type_uint16List(via bitmap)
-> the code can deal with duplicates/unsorted lists (bitmap_set)
Side node: I am not sure if there should be some range checks, but maybe
the bitmap is large enough .... hm ...
2. qapi-visit.c::visit_type_Memdev_members()
-> calls visit_type_uint16List()
-> I think this never used for input, only for output / freeing
3. qapi-visit.c::visit_type_NumaNodeOptions_members()
-> calls visit_type_uint16List()
-> I think this never used for input, only for output / freeing
4. qapi-visit.c::visit_type_RockerOfDpaGroup_members
-> calls visit_type_uint32List()
-> I think this never used for input, only for output / freeing
5. qapi-visit.c::visit_type_RxFilterInfo_members()
-> calls visit_type_intList()
-> I think this never used for input, only for output / freeing
6. numa.c::query_memdev()
-> calls object_property_get_uint16List()
--> String parsed via visit_type_uint16List() into list
-> qmp_query_memdev() uses this list
--> Not relevant if unique or sorted
-> hmp_info_memdev() uses this list
--> List converted again to a string using string output visitor
-> I don't think unique/sorted is relevant here.
Am I missing anything / is any of my statements wrong?
Thanks!
>>
>> diff --git a/include/qapi/string-input-visitor.h b/include/qapi/string-input-visitor.h
>> index 33551340e3..921f3875b9 100644
>> --- a/include/qapi/string-input-visitor.h
>> +++ b/include/qapi/string-input-visitor.h
>> @@ -19,8 +19,8 @@ typedef struct StringInputVisitor StringInputVisitor;
>>
>> /*
>> * The string input visitor does not implement support for visiting
>> - * QAPI structs, alternates, null, or arbitrary QTypes. It also
>> - * requires a non-null list argument to visit_start_list().
>> + * QAPI structs, alternates, null, or arbitrary QTypes. Only flat lists
>> + * of integers (except type "size") are supported.
>> */
>> Visitor *string_input_visitor_new(const char *str);
>>
>> diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c
>> index b89c6c4e06..4113be01fb 100644
>> --- a/qapi/string-input-visitor.c
>> +++ b/qapi/string-input-visitor.c
>> @@ -4,10 +4,10 @@
>> * Copyright Red Hat, Inc. 2012-2016
>> *
>> * Author: Paolo Bonzini <pbonzini@redhat.com>
>> + * David Hildenbrand <david@redhat.com>
>> *
>> * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
>> * See the COPYING.LIB file in the top-level directory.
>> - *
>> */
>>
>> #include "qemu/osdep.h"
>> @@ -18,21 +18,39 @@
>> #include "qapi/qmp/qerror.h"
>> #include "qapi/qmp/qnull.h"
>> #include "qemu/option.h"
>> -#include "qemu/queue.h"
>> -#include "qemu/range.h"
>> #include "qemu/cutils.h"
>>
[...]
>> static void parse_type_int64(Visitor *v, const char *name, int64_t *obj,
>> Error **errp)
>> {
>> StringInputVisitor *siv = to_siv(v);
>> -
>> - if (parse_str(siv, name, errp) < 0) {
>> + int64_t val;
>> +
>> + switch (siv->lm) {
>> + case LM_NONE:
>> + /* just parse a simple int64, bail out if not completely consumed */
>> + if (qemu_strtoi64(siv->string, NULL, 0, &val)) {
>> + error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
>> + name ? name : "null", "int64");
>> + return;
>> + }
>> + *obj = val;
>> return;
>> + case LM_UNPARSED:
>> + if (try_parse_int64_list_entry(siv, obj)) {
>> + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
>> + "list of int64 values or ranges");
>> + return;
>> + }
>> + assert(siv->lm == LM_INT64_RANGE);
>> + /* FALLTHROUGH */
>
> Please spell it /* fall through */, because:
>
> $ git-grep -Ei '/\* *fall.?thr[a-z]* *\*/' | sed 's/.*\* *\(fall[^*]*\)\*.*/\1/i' | sort | uniq -c
> 4 FALL THROUGH
> 8 FALLTHROUGH
> 61 FALLTHRU
> 36 Fall through
> 20 Fallthrough
> 4 Fallthru
> 237 fall through
> 1 fall-through
> 16 fallthrough
> 39 fallthru
Done!
[...]
>
>> + case LM_INT64_RANGE:
>> + /* return the next element in the range */
>> + assert(siv->rangeNext.i64 <= siv->rangeEnd.i64);
>> + *obj = siv->rangeNext.i64++;
>> +
>> + if (siv->rangeNext.i64 > siv->rangeEnd.i64 || *obj == INT64_MAX) {
>> + /* end of range, check if there is more to parse */
>> + if (siv->unparsed_string[0]) {
>> + siv->lm = LM_UNPARSED;
>> + } else {
>> + siv->lm = LM_END;
>> + }
>
> I'd do
>
> siv->lm = siv->unparsed_string[0] ? LM_UNPARSED : LM_END;
>
> Matter of taste, entirely up to you.
Yes, makes sense, thanks!
>
>> + }
>> + return;
>> + case LM_END:
>> + error_setg(errp, "Fewer list elements expected");
>> + return;
>> + default:
>> + abort();
>> }
>> +}
>>
>> - if (!siv->ranges) {
>> - goto error;
>> - }
>> -
>> - if (!siv->cur_range) {
>> - Range *r;
>> +static int try_parse_uint64_list_entry(StringInputVisitor *siv, uint64_t *obj)
>> +{
>> + const char *endptr;
>> + uint64_t start, end;
>>
>> - siv->cur_range = g_list_first(siv->ranges);
>> - if (!siv->cur_range) {
>> - goto error;
>> + /* parse a simple uint64 or range */
>
> try_parse_int64_list_entry() doesn't have this comment. I think either
> both or none should have it. You decide.
Indeed, the comment got lost on the way. Will readd it.
[...]
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2018-11-19 14:12 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-15 14:04 [Qemu-devel] [PATCH v1 0/9] qapi: rewrite string-input-visitor David Hildenbrand
2018-11-15 14:04 ` [Qemu-devel] [PATCH v1 1/9] cutils: add qemu_strtod() and qemu_strtod_finite() David Hildenbrand
2018-11-15 14:23 ` Eric Blake
2018-11-15 16:22 ` Markus Armbruster
2018-11-15 17:25 ` David Hildenbrand
2018-11-15 18:02 ` Eric Blake
2018-11-15 21:57 ` David Hildenbrand
2018-11-15 14:04 ` [Qemu-devel] [PATCH v1 2/9] cutils: use qemu_strtod_finite() in do_strtosz() David Hildenbrand
2018-11-15 14:36 ` Eric Blake
2018-11-15 16:41 ` Markus Armbruster
2018-11-15 17:59 ` David Hildenbrand
2018-11-15 14:04 ` [Qemu-devel] [PATCH v1 3/9] qapi: use qemu_strtod_finite() in string-input-visitor David Hildenbrand
2018-11-15 14:37 ` Eric Blake
2018-11-15 14:39 ` David Hildenbrand
2018-11-15 16:48 ` Markus Armbruster
2018-11-15 21:54 ` David Hildenbrand
2018-11-15 14:04 ` [Qemu-devel] [PATCH v1 4/9] qapi: use qemu_strtod_finite() in qobject-input-visitor David Hildenbrand
2018-11-15 14:45 ` Eric Blake
2018-11-16 14:46 ` Markus Armbruster
2018-11-15 14:04 ` [Qemu-devel] [PATCH v1 5/9] test-string-input-visitor: add more tests David Hildenbrand
2018-11-15 17:13 ` Eric Blake
2018-11-15 17:32 ` David Hildenbrand
2018-11-15 18:46 ` Markus Armbruster
2018-11-15 14:04 ` [Qemu-devel] [PATCH v1 6/9] qapi: rewrite string-input-visitor David Hildenbrand
2018-11-16 10:10 ` Markus Armbruster
2018-11-19 14:12 ` David Hildenbrand [this message]
2018-11-19 19:51 ` Markus Armbruster
2018-11-19 21:22 ` David Hildenbrand
2018-11-15 14:04 ` [Qemu-devel] [PATCH v1 7/9] test-string-input-visitor: use virtual walk David Hildenbrand
2018-11-16 14:48 ` Markus Armbruster
2018-11-15 14:05 ` [Qemu-devel] [PATCH v1 8/9] test-string-input-visitor: split off uint64 list tests David Hildenbrand
2018-11-16 14:51 ` Markus Armbruster
2018-11-15 14:05 ` [Qemu-devel] [PATCH v1 9/9] test-string-input-visitor: add range overflow tests David Hildenbrand
2018-11-16 14:51 ` Markus Armbruster
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=3d186921-e32f-60aa-cfc6-07345f6795c7@redhat.com \
--to=david@redhat.com \
--cc=armbru@redhat.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 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).