Received: from eggs.gnu.org ([140.186.70.92]:49306) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLZvM-00082M-GH for qemu-devel@nongnu.org; Wed, 02 Nov 2011 08:28:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RLZvL-0005a9-F2 for qemu-devel@nongnu.org; Wed, 02 Nov 2011 08:28:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50673) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLZvL-0005a5-6F for qemu-devel@nongnu.org; Wed, 02 Nov 2011 08:28:07 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pA2CS6TE030496 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 2 Nov 2011 08:28:06 -0400 Date: Wed, 2 Nov 2011 10:26:42 -0200 From: Eduardo Habkost Message-ID: <20111102122642.GF29718@otherpad.lan.raisama.net> References: <1320175230-27980-1-git-send-email-ehabkost@redhat.com> <1320175230-27980-6-git-send-email-ehabkost@redhat.com> <20111102115641.GE29718@otherpad.lan.raisama.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [RFC PATCH 05/11] qemu_fclose: return last_error if set List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org On Wed, Nov 02, 2011 at 01:15:46PM +0100, Paolo Bonzini wrote: > On 11/02/2011 12:56 PM, Eduardo Habkost wrote: > >No, if it's positive it won't be set on last_error, so we have to save > >it somewhere other than last_error (that's what the qemu_close() return > >value is used for). > > Ok, I was confused by your patch 6, which basically removes the only > case when qemu_fclose was returning a positive, nonzero value. :) I > guess the problem is there? Yes! We must return the pclose() return value there, as exec_close() needs it. Thanks for spotting it. :-) > > >Without a separate function and qemu_file_set_if_error(), the function > >will look like: > > > >int qemu_fclose(QEMUFile *f) > >{ > > int ret = 0; > > qemu_fflush(); > > if (f->close) { > > ret = f->close(f->opaque); > > } > > if (f->last_error) { > ^^^^^^^^^^^^^ > > "if (ret >= 0 && f->last_error)" perhaps? I don't think so: if f->close() fails but we have already got an error on any previous operation (in other words, if f->last_error was already set), I think we should return info about the first error (that will probably be more informative), instead of the close() error. > > > ret = f->last_error; > > } > > g_free(f); > > return ret; > >} > > > > > >Now that I am looking at the resulting code, it doesn't look too bad. I > >guess I was simply too eager to encapsulate every bit of logic (in this > >case the "if (f->close) ..." part) into separate functions. I find the > >two-function version slightly easier to analyze, though. > > Yes, it's the same for me too now that I actually understand what's > going on. Good. :-) -- Eduardo