Received: from eggs.gnu.org ([2001:4830:134:3::10]:48368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDDNq-0006Vw-3a for qemu-devel@nongnu.org; Tue, 11 Feb 2014 08:28:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WDDNk-0007E3-4p for qemu-devel@nongnu.org; Tue, 11 Feb 2014 08:28:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39895) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDDNj-0007Dp-TS for qemu-devel@nongnu.org; Tue, 11 Feb 2014 08:28:12 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1BDS9np019984 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 11 Feb 2014 08:28:10 -0500 Date: Tue, 11 Feb 2014 14:28:08 +0100 From: Stefan Hajnoczi Message-ID: <20140211132808.GA29957@stefanha-thinkpad.brq.redhat.com> References: <1390994251-21768-1-git-send-email-stefanha@redhat.com> <1392115505-21969-1-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1392115505-21969-1-git-send-email-famz@redhat.com> Subject: Re: [Qemu-devel] [PATCH] QMP: allow dot separated dict path arguments in qmp-shell List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: Igor Mammedov , qemu-devel@nongnu.org, Luiz Capitulino On Tue, Feb 11, 2014 at 06:45:05PM +0800, Fam Zheng wrote: > diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell > index d374b35..9c84551 100755 > --- a/scripts/qmp/qmp-shell > +++ b/scripts/qmp/qmp-shell > @@ -112,7 +112,14 @@ class QMPShell(qmp.QEMUMonitorProtocol): > value = json.loads(opt[1]) > else: > value = opt[1] > - qmpcmd['arguments'][opt[0]] = value > + optpath = opt[0].split('.') > + parent = qmpcmd['arguments'] > + for p in optpath[:-1]: > + if not p in parent: > + d = dict() > + parent[p] = d > + parent = d d is a stale reference when the path component already exists (e.g. a.b.c=1 a.d=2). Since 'a' already exists when processing 'a.d' we'll the value of d will actually be the a.b dict! I think you need the following instead: for p in optpath[:-1]: d = parent.get(p, {}) parent[p] = d parent = d