From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NIlbG-0000UW-Qo for qemu-devel@nongnu.org; Thu, 10 Dec 2009 11:10:42 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NIlbB-0000OG-WE for qemu-devel@nongnu.org; Thu, 10 Dec 2009 11:10:42 -0500 Received: from [199.232.76.173] (port=50636 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NIlbB-0000Nv-Od for qemu-devel@nongnu.org; Thu, 10 Dec 2009 11:10:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48300) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NIlbB-0006Ic-Vv for qemu-devel@nongnu.org; Thu, 10 Dec 2009 11:10:38 -0500 Message-ID: <4B211D6F.7020906@redhat.com> Date: Thu, 10 Dec 2009 18:10:23 +0200 From: Avi Kivity MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 10/19] monitor: Convert do_info_name() to QObject References: <1260376078-8694-1-git-send-email-lcapitulino@redhat.com> <1260376078-8694-11-git-send-email-lcapitulino@redhat.com> <20091210095237.38cafe5c@doriath> <4B20F003.6070409@linux.vnet.ibm.com> <4B2119F9.6010003@redhat.com> <4B211BE2.60907@linux.vnet.ibm.com> In-Reply-To: <4B211BE2.60907@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel@nongnu.org, Markus Armbruster , Luiz Capitulino On 12/10/2009 06:03 PM, Anthony Liguori wrote: > Avi Kivity wrote: >> On 12/10/2009 02:56 PM, Anthony Liguori wrote: >>> >>> I'd prefer an empty dict. I actually prefer that over null. >>> >> >> Depends. Key not present suggests the feature is not implemented. >> Value is null suggests the feature is not used. Both key and value >> present suggest the feature is in implemented and active. > > What I suggested to Luiz was that all info commands return a > dictionary. The main reason was that for most commands, we can extend > the commands in a compatible way by adding new fields to the dictionary. Oh yes. > > My expectation is that there will be a lot of client code that does: > > hpet_info = qmp.info_hpet() > if hpet_info.has_key('period'): > period = hpet_info['period'] > else: > period = 100 # old qemu's has a fixed period of 100ns > > So in keeping with this idiom, I think that checking > name_info.has_key('name') is a more meaningful way to determine > whether the virtual machine has been given a name vs comparing > name_info['name'] == None. But we have two null conditions to check for, in an extendible dictionary: 1. The feature is unknown to qemu 2. The feature is known to qemu, but disabled So, "if 'field' in result:" tests the former, and "if result['field']:" tests the latter. In your example, a period of None makes no sense, so it would be sufficient to period = hpet_info.get('period', 0.100) -- error compiling committee.c: too many arguments to function