qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 06/22] qapi: add visitor interfaces for arrays


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH 06/22] qapi: add visitor interfaces for arrays
Date: Tue, 24 Jul 2012 17:18:29 -0500
User-agent: Notmuch/0.13.2+60~g7ecf77d (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu)

Michael Roth <address@hidden> writes:

> Signed-off-by: Michael Roth <address@hidden>
> ---
>  qapi/qapi-visit-core.c |   25 +++++++++++++++++++++++++
>  qapi/qapi-visit-core.h |    8 ++++++++
>  scripts/qapi_visit.py  |   28 ++++++++++++++++++++++++++++
>  3 files changed, 61 insertions(+)
>
> diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
> index 7a82b63..631387d 100644
> --- a/qapi/qapi-visit-core.c
> +++ b/qapi/qapi-visit-core.c
> @@ -311,3 +311,28 @@ void input_type_enum(Visitor *v, int *obj, const char 
> *strings[],
>      g_free(enum_str);
>      *obj = value;
>  }
> +
> +void visit_start_array(Visitor *v, void **obj, const char *name,
> +                       size_t elem_count, size_t elem_size, Error
> **errp)

So this is a C style single dimension array?  Can we at least call this
c_array then or something like that.

Regards,

Anthony Liguori

> +{
> +    g_assert(v->start_array);
> +    if (!error_is_set(errp)) {
> +        v->start_array(v, obj, name, elem_count, elem_size, errp);
> +    }
> +}
> +
> +void visit_next_array(Visitor *v, Error **errp)
> +{
> +    g_assert(v->next_array);
> +    if (!error_is_set(errp)) {
> +        v->next_array(v, errp);
> +    }
> +}
> +
> +void visit_end_array(Visitor *v, Error **errp)
> +{
> +    g_assert(v->end_array);
> +    if (!error_is_set(errp)) {
> +        v->end_array(v, errp);
> +    }
> +}
> diff --git a/qapi/qapi-visit-core.h b/qapi/qapi-visit-core.h
> index 60aceda..4a7bdb6 100644
> --- a/qapi/qapi-visit-core.h
> +++ b/qapi/qapi-visit-core.h
> @@ -43,6 +43,10 @@ struct Visitor
>      void (*type_str)(Visitor *v, char **obj, const char *name, Error **errp);
>      void (*type_number)(Visitor *v, double *obj, const char *name,
>                          Error **errp);
> +    void (*start_array)(Visitor *v, void **obj, const char *name,
> +                        size_t elem_count, size_t elem_size, Error **errp);
> +    void (*next_array)(Visitor *v, Error **errp);
> +    void (*end_array)(Visitor *v, Error **errp);
>  
>      /* May be NULL */
>      void (*start_optional)(Visitor *v, bool *present, const char *name,
> @@ -91,5 +95,9 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char 
> *name, Error **errp);
>  void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp);
>  void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp);
>  void visit_type_number(Visitor *v, double *obj, const char *name, Error 
> **errp);
> +void visit_start_array(Visitor *v, void **obj, const char *name,
> +                       size_t elem_count, size_t elem_size, Error **errp);
> +void visit_next_array(Visitor *v, Error **errp);
> +void visit_end_array(Visitor *v, Error **errp);
>  
>  #endif
> diff --git a/scripts/qapi_visit.py b/scripts/qapi_visit.py
> index 9839e3c..bf93bfe 100644
> --- a/scripts/qapi_visit.py
> +++ b/scripts/qapi_visit.py
> @@ -33,6 +33,34 @@ visit_end_array(m, errp);
>                  count=info['array_size'])
>      return ret
>  
> +def generate_visit_array_body(name, info):
> +    if info['array_size'][0].isdigit():
> +        array_size = info['array_size']
> +    elif info['array_size'][0] == '(' and info['array_size'][-1] == ')':
> +        array_size = info['array_size']
> +    else:
> +        array_size = "(*obj)->%s" % info['array_size']
> +
> +    if info.has_key('array_capacity'):
> +        array_capacity = info['array_capacity']
> +    else:
> +        array_capacity = array_size
> +
> +    ret = mcgen('''
> +visit_start_array(m, (void **)obj, "%(name)s", %(array_capacity)s, 
> sizeof(%(type)s), errp);
> +int %(name)s_i;
> +for (%(name)s_i = 0; %(name)s_i < %(array_size)s; %(name)s_i++) {
> +    visit_type_%(type_short)s(m, &(*obj)->%(name)s[%(name)s_i], NULL, errp);
> +    visit_next_array(m, errp);
> +}
> +visit_end_array(m, errp);
> +''',
> +                name=name, type=c_type(info['type'][0]),
> +                type_short=info['type'][0],
> +                array_size=array_size,
> +                array_capacity=array_capacity)
> +    return ret
> +
>  def generate_visit_struct_body(field_prefix, name, members):
>      ret = mcgen('''
>  if (!error_is_set(errp)) {
> -- 
> 1.7.9.5




reply via email to

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