qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v3 10/18] vmstate: Use new JSON output visitor


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v3 10/18] vmstate: Use new JSON output visitor
Date: Wed, 4 May 2016 09:17:51 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

On 05/04/2016 08:53 AM, Dr. David Alan Gilbert wrote:

>> Here's the example from visitor.h at the end of this series (with a
>> small mistake corrected):
>>
>>     Visitor *v;
>>     Error *err = NULL;
>>     int value;
>>
>>     v = ...obtain visitor...
>>     visit_start_struct(v, NULL, NULL, 0, &err);
>>     if (err) {
>>         goto out;
>>     }
>>     visit_start_list(v, "list", NULL, 0, &err);
>>     if (err) {
>>         goto outobj;
>>     }
>>     value = 1;
>>     visit_type_int(v, NULL, &value, &err);
>>     if (err) {
>>         goto outlist;
>>     }
>>     value = 2;
>>     visit_type_int(v, NULL, &value, &err);
>>     if (err) {
>>         goto outlist;
>>     }
>>    outlist:
>>     visit_end_list(v, NULL);
>>     if (!err) {
>>         visit_check_struct(v, &err);
>>     }
>>    outobj:
>>     visit_end_struct(v, NULL);

> Hmm the visit_end_* are interesting; I guess we have to be careful
> of those, unless that is you could make the visit_end_struct(v, NULL)
> to fail nicely in that case.

Here, visit_end_struct() _can't_ fail; you are passing NULL to match the
fact that the earlier visit_start_struct() passed NULL for obj (that is,
at the end of the current qapi series, the parameter changes from
Error** to void **, and is NOT an error indicator).

>>
>> Visitors will abort when their preconditions or invariants are violated.

And it's very easy to avoid violating those preconditions. But if it's
not easy enough for you, then the solution is...

>> If that's not okay for migration, I'm afraid migration needs to continue
>> to roll its own JSON writer.  Visitors are pretty heavily used nowadays,
>> and we very much rely on these assertions to catch mistakes.
> 
> OK, lets keep our own writer; if we can't have more control over visitors
> failure paths, we'll have to.

...exactly this. So in the next spin of my series, I will drop (both!)
of my attempts to rework qjson.c to reuse the visitors, and instead just
move it into the migration tree and out of the top level.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]