Received: from eggs.gnu.org ([2001:4830:134:3::10]:56962) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bL7E7-00086a-MW for qemu-devel@nongnu.org; Thu, 07 Jul 2016 07:12:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bL7E4-0000AC-BS for qemu-devel@nongnu.org; Thu, 07 Jul 2016 07:12:15 -0400 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]:34334) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bL7E4-0000A8-3i for qemu-devel@nongnu.org; Thu, 07 Jul 2016 07:12:12 -0400 Received: by mail-wm0-x232.google.com with SMTP id 187so2223202wmz.1 for ; Thu, 07 Jul 2016 04:12:11 -0700 (PDT) Sender: Paolo Bonzini References: <1467809017-25023-1-git-send-email-pbonzini@redhat.com> <1467809017-25023-2-git-send-email-pbonzini@redhat.com> <577D2629.80007@redhat.com> From: Paolo Bonzini Message-ID: Date: Thu, 7 Jul 2016 13:12:08 +0200 MIME-Version: 1.0 In-Reply-To: <577D2629.80007@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] qapi: change QmpInputVisitor to QSLIST List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake , qemu-devel@nongnu.org Cc: armbru@redhat.com On 06/07/2016 17:39, Eric Blake wrote: > On 07/06/2016 06:43 AM, Paolo Bonzini wrote: >> This saves a lot of memory compared to a statically-sized array. >> >> Signed-off-by: Paolo Bonzini >> --- >> qapi/qmp-input-visitor.c | 53 ++++++++++++++++++++++++------------------------ >> 1 file changed, 26 insertions(+), 27 deletions(-) >> > >> @@ -99,17 +100,10 @@ static const QListEntry *qmp_input_push(QmpInputVisitor *qiv, QObject *obj, >> Error **errp) >> { >> GHashTable *h; >> - StackObject *tos = &qiv->stack[qiv->nb_stack]; >> + StackObject *tos = g_new0(StackObject, 1); >> >> assert(obj); >> - if (qiv->nb_stack >= QIV_STACK_SIZE) { > > You should also delete QIV_STACK_SIZE as it is now unused. > >> @@ -127,9 +121,7 @@ static const QListEntry *qmp_input_push(QmpInputVisitor *qiv, QObject *obj, >> static void qmp_input_check_struct(Visitor *v, Error **errp) >> { >> QmpInputVisitor *qiv = to_qiv(v); >> - StackObject *tos = &qiv->stack[qiv->nb_stack - 1]; >> - >> - assert(qiv->nb_stack > 0); >> + StackObject *tos = QSLIST_FIRST(&qiv->stack); > > Does QSLIST_FIRST() properly crash if the list is empty, or do we need > to add an assert(tos) to replace the assertion on nb_stack being non-zero? StackObject *tos = QSLIST_FIRST(&qiv->stack); if (qiv->strict) { GHashTable *const top_ht = tos->h; if (top_ht) { GHashTableIter iter; const char *key; g_hash_table_iter_init(&iter, top_ht); if (g_hash_table_iter_next(&iter, (void **)&key, NULL)) { error_setg(errp, QERR_QMP_EXTRA_MEMBER, key); } } } If qiv->strict, the tos->h dereference will cause a crash so the assertion is not necessary. If !qiv->strict, check_struct should be immediately followed by end_struct which will also crash. However, I agree that it's nicer to keep the assertion. Paolo > Otherwise looking reasonable; looking forward to v2. >