On 04/27/2016 06:01 PM, Eric Blake wrote:
> The semantics of the list visit are somewhat baroque, with the
> following pseudocode when FooList is used:
> 

> 
> We can greatly simplify things by hoisting the special case
> into the start() routine, and flipping the order in the loop
> to visit before advance:
> 
> start(head)
> for (tail = *head; tail; tail = next(tail)) {
>     visit(&tail->value)
> }
> 

> +++ b/qapi/qapi-visit-core.c
> @@ -48,15 +48,17 @@ void visit_end_struct(Visitor *v)
>      v->end_struct(v);
>  }
> 
> -void visit_start_list(Visitor *v, const char *name, Error **errp)
> +void visit_start_list(Visitor *v, const char *name, GenericList **list,
> +                      size_t size, Error **errp)
>  {
> -    v->start_list(v, name, errp);
> +    assert(!list || size >= sizeof(GenericList));
> +    v->start_list(v, name, list, size, errp);
>  }

As mentioned in 02/23, this would be a good place to assert that:

if (v->type == VISITOR_INPUT) {
    assert(!(err && *list));
}

of course, that means declaring a local 'err'.

-- 
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