From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDO7k-0004yl-5s for qemu-devel@nongnu.org; Tue, 11 Feb 2014 19:56:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WDO7e-0005Ie-5T for qemu-devel@nongnu.org; Tue, 11 Feb 2014 19:56:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:17881) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDO7d-0005IS-Tu for qemu-devel@nongnu.org; Tue, 11 Feb 2014 19:56:18 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1C0uF5Z024473 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 11 Feb 2014 19:56:16 -0500 Date: Wed, 12 Feb 2014 08:56:22 +0800 From: Fam Zheng Message-ID: <20140212005622.GC7257@T430.nay.redhat.com> References: <1390994251-21768-1-git-send-email-stefanha@redhat.com> <1392115505-21969-1-git-send-email-famz@redhat.com> <20140211132808.GA29957@stefanha-thinkpad.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20140211132808.GA29957@stefanha-thinkpad.brq.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: Stefan Hajnoczi Cc: Igor Mammedov , qemu-devel@nongnu.org, Luiz Capitulino On Tue, 02/11 14:28, Stefan Hajnoczi wrote: > 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 Yes, thanks. And we should check the contradictive case "foo=a foo.bar=b". Will send v2. Fam