From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:55044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StnSA-0005la-3E for qemu-devel@nongnu.org; Tue, 24 Jul 2012 18:19:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1StnS8-0005sL-0e for qemu-devel@nongnu.org; Tue, 24 Jul 2012 18:19:42 -0400 Received: from e8.ny.us.ibm.com ([32.97.182.138]:53806) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StnS7-0005sG-T3 for qemu-devel@nongnu.org; Tue, 24 Jul 2012 18:19:39 -0400 Received: from /spool/local by e8.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 24 Jul 2012 18:19:39 -0400 Received: from d01relay07.pok.ibm.com (d01relay07.pok.ibm.com [9.56.227.147]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 935E9C9001C for ; Tue, 24 Jul 2012 18:18:32 -0400 (EDT) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay07.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q6OMIWBj2752830 for ; Tue, 24 Jul 2012 18:18:32 -0400 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q6OMIVXQ014013 for ; Tue, 24 Jul 2012 19:18:32 -0300 From: Anthony Liguori In-Reply-To: <1343150454-4677-7-git-send-email-mdroth@linux.vnet.ibm.com> References: <1343150454-4677-1-git-send-email-mdroth@linux.vnet.ibm.com> <1343150454-4677-7-git-send-email-mdroth@linux.vnet.ibm.com> Date: Tue, 24 Jul 2012 17:18:29 -0500 Message-ID: <874nowls5m.fsf@codemonkey.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCH 06/22] qapi: add visitor interfaces for arrays List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Roth , qemu-devel@nongnu.org Cc: quintela@redhat.com, owasserm@redhat.com, yamahata@valinux.co.jp, pbonzini@redhat.com, akong@redhat.com, afaerber@suse.de Michael Roth writes: > Signed-off-by: Michael Roth > --- > 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