From patchwork Tue Jul 24 17:20:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 172977 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D5E7D2C007E for ; Wed, 25 Jul 2012 03:22:05 +1000 (EST) Received: from localhost ([::1]:36473 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Stio7-0003nT-Sd for incoming@patchwork.ozlabs.org; Tue, 24 Jul 2012 13:22:03 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sting-0003P1-Ai for qemu-devel@nongnu.org; Tue, 24 Jul 2012 13:21:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Stine-0000RJ-I7 for qemu-devel@nongnu.org; Tue, 24 Jul 2012 13:21:36 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:53639) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Stine-0000Fl-CE for qemu-devel@nongnu.org; Tue, 24 Jul 2012 13:21:34 -0400 Received: by mail-pb0-f45.google.com with SMTP id ro12so12773613pbb.4 for ; Tue, 24 Jul 2012 10:21:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=9X8G/BHUsdulJG4yd29U73r0xrhkTZ4KVj9W1XGs6j4=; b=YBEN865sVpRyPXzr3W4poQDXBqx1uhUvzhiBPouEXFgKp0A06IK7c8ThekRs1Gc3CQ f9rdj48ba7wx9rkJwqdOhM6LDE1ecpmzmQKGA468Jfuu1ldARfr9cnKUGL6vWzFjxNJV ZGOezCtY54qz2Z/bG3DVMN2hmfvva9/NPvuyUW4WlvKd+/CbWdRAKwn7WIbQLClYZ2xc sCz/QbKsj8lnX34W4rqeokSARzHJuEUpARU0NilLNeQ2CyfPGTywU3N93CkElGxtqqxb R8WiWvXYK2RZvjxG1bgSSb8I2azJnGE/GaU7O0zUpC3H6uAr0yAKNxom2lgMuak4l4zJ Wgzw== Received: by 10.68.238.68 with SMTP id vi4mr45998568pbc.123.1343150493954; Tue, 24 Jul 2012 10:21:33 -0700 (PDT) Received: from loki.morrigu.org (cpe-72-179-62-111.austin.res.rr.com. [72.179.62.111]) by mx.google.com with ESMTPS id nh8sm12522083pbc.60.2012.07.24.10.21.31 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 24 Jul 2012 10:21:32 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 24 Jul 2012 12:20:38 -0500 Message-Id: <1343150454-4677-7-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1343150454-4677-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1343150454-4677-1-git-send-email-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: aliguori@us.ibm.com, quintela@redhat.com, owasserm@redhat.com, yamahata@valinux.co.jp, pbonzini@redhat.com, akong@redhat.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH 06/22] qapi: add visitor interfaces for arrays X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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) +{ + 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)) {