Received: from eggs.gnu.org ([208.118.235.92]:33054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIJpZ-00024j-D8 for qemu-devel@nongnu.org; Wed, 20 Mar 2013 10:17:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UIJpT-0003n8-2c for qemu-devel@nongnu.org; Wed, 20 Mar 2013 10:17:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34924) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIJpS-0003my-Jm for qemu-devel@nongnu.org; Wed, 20 Mar 2013 10:17:22 -0400 From: Markus Armbruster References: <1360096768-8863-1-git-send-email-lersek@redhat.com> <1360096768-8863-7-git-send-email-lersek@redhat.com> <20130207171841.GL9964@otherpad.lan.raisama.net> <20130207160359.15e71575@redhat.com> Date: Wed, 20 Mar 2013 15:17:18 +0100 In-Reply-To: <20130207160359.15e71575@redhat.com> (Luiz Capitulino's message of "Thu, 7 Feb 2013 16:03:59 -0200") Message-ID: <87txo6i2a9.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v2 06/15] set_property(): extend signature with Error List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: kwolf@redhat.com, aliguori@us.ibm.com, Eduardo Habkost , jasowang@redhat.com, qemu-devel@nongnu.org, xiawenc@linux.vnet.ibm.com, pbonzini@redhat.com, Laszlo Ersek , afaerber@suse.de, stefanha@linux.vnet.ibm.com Luiz Capitulino writes: > On Thu, 7 Feb 2013 15:18:41 -0200 > Eduardo Habkost wrote: > >> On Tue, Feb 05, 2013 at 09:39:19PM +0100, Laszlo Ersek wrote: >> > >> > Signed-off-by: Laszlo Ersek >> > --- >> > hw/qdev-monitor.c | 21 ++++++++++++++++----- >> > 1 files changed, 16 insertions(+), 5 deletions(-) >> > >> > diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c >> > index cf96046..545e66c 100644 >> > --- a/hw/qdev-monitor.c >> > +++ b/hw/qdev-monitor.c >> > @@ -100,9 +100,14 @@ static void qdev_print_devinfo(ObjectClass *klass, void *opaque) >> > error_printf("\n"); >> > } >> > >> > +typedef struct { >> > + DeviceState *dev; >> > + Error **errp; >> > +} PropertyContext; >> > + >> > static int set_property(const char *name, const char *value, void *opaque) >> > { >> > - DeviceState *dev = opaque; >> > + PropertyContext *ctx = opaque; >> > Error *err = NULL; >> > >> > if (strcmp(name, "driver") == 0) >> > @@ -110,7 +115,7 @@ static int set_property(const char *name, const char *value, void *opaque) >> > if (strcmp(name, "bus") == 0) >> > return 0; >> > >> > - qdev_prop_parse(dev, name, value, &err); >> > + qdev_prop_parse(ctx->dev, name, value, &err); >> > if (error_is_set(&err)) { >> > qerror_report_err(err); >> > error_free(err); >> > @@ -481,10 +486,16 @@ DeviceState *qdev_device_add(QemuOpts *opts) >> > if (id) { >> > qdev->id = id; >> > } >> > - if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) { >> > - qdev_free(qdev); >> > - return NULL; >> > + >> > + { >> > + PropertyContext ctx = { .dev = qdev, .errp = NULL }; >> > + >> > + if (qemu_opt_foreach(opts, set_property, &ctx, 1) != 0) { >> >> What about redefining qemu_opt_loopfunc to accept an Error parameter? >> >> qemu_opt_foreach() is used in only 4 places in the whole QEMU code, and >> it already has code to abort on error (but using the function return >> value instead of an Error** paramater). > > He would have to convert the users too, which would be very welcome, > but it's out of the scope of this series IMO (but would be fine as > a first series to this work). I'm fine with this patch as is. I wouldn't add Error support to qemu_opt_foreach(), I'd replace it by a more C-ish qemu_opt_next(): for (opt = qemu_opt_next(NULL); opt; opt = qemu_opt_next(opt)) { set_property(qdev, qemu_opt_name(opt), qemu_opt_value(opt), &err); if (err) { ... break; } } Higher-order functions are great in Lisp, but awkward in C. > >> >> >> >> > + qdev_free(qdev); >> > + return NULL; >> > + } >> > } >> > + >> > if (qdev->id) { >> > object_property_add_child(qdev_get_peripheral(), qdev->id, >> > OBJECT(qdev), NULL); >> > -- >> > 1.7.1 >> > >> > >>