From: Ian Campbell Subject: Re: [PATCH V5 07/32] libxl.h: document the paradigm of using libxl types Date: Tue, 20 May 2014 16:02:04 +0100 Message-ID: <1400598124.6946.95.camel@kazak.uk.xensource.com> References: <1400018054-26038-1-git-send-email-wei.liu2@citrix.com> <1400018054-26038-8-git-send-email-wei.liu2@citrix.com> <1400590147.6946.37.camel@kazak.uk.xensource.com> <21371.27806.771736.627734@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <21371.27806.771736.627734@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Jackson Cc: Wei Liu , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Tue, 2014-05-20 at 15:54 +0100, Ian Jackson wrote: > Ian Campbell writes ("Re: [PATCH V5 07/32] libxl.h: document the paradigm of using libxl types"): > > On Tue, 2014-05-13 at 22:53 +0100, Wei Liu wrote: > > > + * once afterwards, to clean up, regardless of whether operations on > > > + * this object succeeded or failed. See the xl code for examples. > > > + * > > > + * "init" is idempotent. > > > > I wondered if this was true, or if calling it twice would leak. None of > > the _init functions allocate any memory so this is OK, I think. > > I think it's a necessary guarantee that they don't, for this to be a > convenient interface. Yes. > > Calling init on a partially setup object could leak things though, so > > init is only idempotent until you initialise some of the fields, which > > isn't a terribly useful guarantee I don't think. > > Uh. What a strange thing to say. > > init is idempotent even if you have already filled in some of the > fields with allocated values. If you initialise some of the fields > and then call init one or more times it's just like calling it once. Right, that is true, but the first call was destructive is what I was getting at. I think I was simply thinking myself into circles. > What you mean is that it is _incorrect_ to call init on a struct with > allocations in it. Yes. That's surely obvious. But it has nothing > to do with idempotency. Right. Ian.