From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:52623) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RW6k7-0006k5-Ci for qemu-devel@nongnu.org; Thu, 01 Dec 2011 08:32:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RW6k3-00070u-Db for qemu-devel@nongnu.org; Thu, 01 Dec 2011 08:32:03 -0500 Received: from mail-gx0-f173.google.com ([209.85.161.173]:41338) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RW6k3-00070h-8h for qemu-devel@nongnu.org; Thu, 01 Dec 2011 08:31:59 -0500 Received: by ggnk1 with SMTP id k1so255097ggn.4 for ; Thu, 01 Dec 2011 05:31:58 -0800 (PST) Message-ID: <4ED781CC.9090900@codemonkey.ws> Date: Thu, 01 Dec 2011 07:31:56 -0600 From: Anthony Liguori 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> <20111201083316.GD29861@stefanha-thinkpad.localdomain> In-Reply-To: <20111201083316.GD29861@stefanha-thinkpad.localdomain> Content-Type: text/plain; charset=ISO-8859-1; format=flowed 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: Stefan Hajnoczi Cc: Kevin Wolf , Peter Maydell , Stefan Hajnoczi , Jan Kiszka , qemu-devel@nongnu.org, Markus Armbruster , Luiz Capitulino On 12/01/2011 02:33 AM, Stefan Hajnoczi wrote: > On Wed, Nov 30, 2011 at 03:03:32PM -0600, Anthony Liguori wrote: >> +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); >> + } else { >> + error_propagate(errp, local_err); >> + } > > I noticed something subtle about Error** here. Your code is correct but > I (incorrectly) wanted to eliminate local_err and use errp directly: > > if (prop->info->parse) { > char *ptr = NULL; > > visit_type_str(v,&ptr, name, errp); > if (!error_is_set(errp)) { > 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); > } > } else { > ... > > Turns out you cannot do this because error_is_set(errp) will be false if > the caller passed in a NULL errp. That means we wouldn't detect the > error from visit_type_str()! > > So it's not okay to depend on the caller's errp. We always need to > juggle around a local_err with propagation :(. > > Just wanted to share. Yes, you are correct. You see this idiom a lot in QAPI an also in glib code that uses GError. Regards, Anthony Liguori >