From: Ian Jackson Subject: Re: [PATCH V5 07/32] libxl.h: document the paradigm of using libxl types Date: Tue, 20 May 2014 15:54:22 +0100 Message-ID: <21371.27806.771736.627734@mariner.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> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1400590147.6946.37.camel@kazak.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 Campbell Cc: Wei Liu , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org 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. > 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. 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. Ian.