[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 06/10] qapi: simplify qmp_input_next_list
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH 06/10] qapi: simplify qmp_input_next_list |
Date: |
Thu, 22 Mar 2012 22:24:04 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120216 Thunderbird/10.0.1 |
Il 22/03/2012 21:22, Anthony Liguori ha scritto:
>>
>> Signed-off-by: Paolo Bonzini<address@hidden>
>
> I've been staring a this patch for the past 5 minutes and I can't figure
> out what's going on here.
>
> Maybe the code was too obscure to begin with. Could you enhance the
> commit message a bit with what's going on here?
There's three possible questions about what's going on:
1) What's going on before the patch with so->entry
2) What's going on after the patch with so->entry
3) What's going on with *list. The patch doesn't change this, it just
unties it with so->entry, but it's the most puzzling part so the
question is a good one. :)
First of all, so->entry here is advanced and also used to figure out
whether we have a next element. It is then accessed in qmp_input_get_obj.
The caller must:
* call start_list
* call next_list for each element *including the first*
* on the first call to next_list, the result is the head of the list
(works for both input and output visitor).
Before: so->entry is initialized to qlist_first on start_list. The
first call will have *list == NULL, so it skips the qlist_next. The
caller assigns the result and makes *list not NULL, so that the next
iteration will advance so->entry and modify (*list)->next.
After: so->entry is initialized to NULL on start_list. The first call
sees so->entry == NULL and does qlist_first; subsequent calls do
qlist_next. *list is handled same as above: assignment done by the
caller on the first call, done by next_list on the next ones.
Thanks for making me write all this down, because it looks like there is
still room for further simplifying the handling of *list (for example,
do not have the caller write the list head). I'll submit a v2.
Depending on the amount of simplification I'll document the result in
either a code comment or the commit message.
Luckily this code is very well tested. It broke all the time for me. :P
Paolo
- [Qemu-devel] [PATCH 01/10] qapi: add a test case for type errors, (continued)
- [Qemu-devel] [PATCH 01/10] qapi: add a test case for type errors, Paolo Bonzini, 2012/03/22
- [Qemu-devel] [PATCH 04/10] qapi: shortcut visits on errors, Paolo Bonzini, 2012/03/22
- [Qemu-devel] [PATCH 03/10] qapi: fix memory leak on error, Paolo Bonzini, 2012/03/22
- [Qemu-devel] [PATCH 05/10] qapi: allow freeing partially-allocated objects, Paolo Bonzini, 2012/03/22
- [Qemu-devel] [PATCH 06/10] qapi: simplify qmp_input_next_list, Paolo Bonzini, 2012/03/22
[Qemu-devel] [PATCH 08/10] qapi: add strict mode to input visitor, Paolo Bonzini, 2012/03/22
[Qemu-devel] [PATCH 07/10] qapi: place outermost object on qiv stack, Paolo Bonzini, 2012/03/22
[Qemu-devel] [PATCH 09/10] qmp: add and use q type specifier, Paolo Bonzini, 2012/03/22
[Qemu-devel] [PATCH 10/10] qmp: parse commands in strict mode, Paolo Bonzini, 2012/03/22