From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:37707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RW9EW-000119-5h for qemu-devel@nongnu.org; Thu, 01 Dec 2011 11:11:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RW9EV-0000kK-7i for qemu-devel@nongnu.org; Thu, 01 Dec 2011 11:11:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:20517) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RW9EU-0000k8-Vu for qemu-devel@nongnu.org; Thu, 01 Dec 2011 11:11:35 -0500 Message-ID: <4ED7A7ED.7040903@redhat.com> Date: Thu, 01 Dec 2011 17:14:37 +0100 From: Kevin Wolf MIME-Version: 1.0 References: <1322687028-29714-1-git-send-email-aliguori@us.ibm.com> <1322687028-29714-3-git-send-email-aliguori@us.ibm.com> In-Reply-To: <1322687028-29714-3-git-send-email-aliguori@us.ibm.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 02/18] qom: register legacy properties as new style properties List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Peter Maydell , Stefan Hajnoczi , Jan Kiszka , Markus Armbruster , qemu-devel@nongnu.org, Luiz Capitulino Am 30.11.2011 22:03, schrieb Anthony Liguori: > Expose all legacy properties through the new QOM property mechanism. The qdev > property types are exposed through the 'legacy<>' namespace. They are always > visited as strings since they do their own string parsing. > > Signed-off-by: Anthony Liguori > --- > hw/qdev.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > hw/qdev.h | 7 +++++ > 2 files changed, 89 insertions(+), 0 deletions(-) Not directly related to this patch, but looking for the first time at visitor code, visitors are clearly underdocumented. > +static void qdev_get_legacy_property(DeviceState *dev, Visitor *v, void *opaque, > + const char *name, Error **errp) > +{ > + Property *prop = opaque; > + > + if (prop->info->print) { > + char buffer[1024]; > + char *ptr = buffer; > + > + prop->info->print(dev, prop, buffer, sizeof(buffer)); > + visit_type_str(v, &ptr, name, errp); So a string output visitor (this is what it's called, right?) takes a buffer on the stack that the visitor must not free... > + } else { > + error_set(errp, QERR_PERMISSION_DENIED); > + } > +} > + > +static void qdev_set_legacy_property(DeviceState *dev, Visitor *v, void *opaque, > + const char *name, Error **errp) > +{ > + Property *prop = opaque; > + > + if (dev->state != DEV_STATE_CREATED) { > + error_set(errp, QERR_PERMISSION_DENIED); > + return; > + } > + > + if (prop->info->parse) { > + Error *local_err = NULL; > + char *ptr = NULL; > + > + visit_type_str(v, &ptr, name, &local_err); > + if (!local_err) { > + int ret; > + ret = prop->info->parse(dev, prop, ptr); > + if (ret != 0) { > + error_set(errp, QERR_INVALID_PARAMETER_VALUE, > + name, prop->info->name); > + } > + g_free(ptr); ...but a string input visitor creates a copy that must be freed. Kind of surprising behaviour, and qapi-visit-core.h doesn't document it. Kevin