Received: from [140.186.70.92] (port=51489 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OTZCp-0004h5-DJ for qemu-devel@nongnu.org; Tue, 29 Jun 2010 07:42:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OTZCo-00054d-0v for qemu-devel@nongnu.org; Tue, 29 Jun 2010 07:42:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:61119) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OTZCn-00054X-Nj for qemu-devel@nongnu.org; Tue, 29 Jun 2010 07:42:21 -0400 From: Markus Armbruster References: <1277470342-5861-1-git-send-email-pbonzini@redhat.com> <1277470342-5861-6-git-send-email-pbonzini@redhat.com> <4C2748AA.8040806@redhat.com> Date: Tue, 29 Jun 2010 13:42:17 +0200 In-Reply-To: <4C2748AA.8040806@redhat.com> (Paolo Bonzini's message of "Sun, 27 Jun 2010 14:48:42 +0200") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: [Qemu-devel] Re: [PATCH 5/7] add qdev property type "cpu" List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Amit Shah , Isaku Yamahata , qemu-devel@nongnu.org Paolo Bonzini writes: >> Hmm. Parse method doesn't accept output of the print method. Not so >> nice. Is the "CPU #" decoration essential? > > I noticed the same in parse/print string: > > static int parse_string(DeviceState *dev, Property *prop, const char *str) > { > char **ptr = qdev_get_prop_ptr(dev, prop); > > if (*ptr) > qemu_free(*ptr); > *ptr = qemu_strdup(str); > return 0; > } > > static int print_string(DeviceState *dev, Property *prop, char *dest, > size_t len) > { > char **ptr = qdev_get_prop_ptr(dev, prop); > if (!*ptr) > return snprintf(dest, len, ""); > return snprintf(dest, len, "\"%s\"", *ptr); > } > > It looks like printing representation is chosen "for the user", not > for parsing. Yes, but does that mean we *should* add such decorations? For me, the print method should be reasonably close to what the parse method accepts. A bit like Lisp's princ, whose ouput is close, but not identical to what the reader accepts (for output acceptable to the reader, use prin1). As to "for the user": dev-prop: cpu_env = CPU #0 dev-prop: cpu_env = 0 Both are equally intelligible, in my opinion: obvious if you know what the property is about, gibberish if you don't. The latter is slightly easier to parse with simple tools like AWK. By the way, print_string() should escape double-quote and funny characters.