qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] QMP: allow dot separated dict path arguments in


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [PATCH] QMP: allow dot separated dict path arguments in qmp-shell
Date: Tue, 11 Feb 2014 14:28:08 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]