From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=40860 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ok1Nk-0001hU-S4 for qemu-devel@nongnu.org; Fri, 13 Aug 2010 17:01:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Ok1Nj-00035f-1a for qemu-devel@nongnu.org; Fri, 13 Aug 2010 17:01:40 -0400 Received: from fe01x03-cgp.akado.ru ([77.232.31.164]:62406 helo=akado.ru) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Ok1Ni-00035S-Rd for qemu-devel@nongnu.org; Fri, 13 Aug 2010 17:01:39 -0400 Date: Sat, 14 Aug 2010 01:01:20 +0400 (MSD) From: malc Subject: Re: [Qemu-devel] Re: [PATCH 3/5] CODING_STYLE: add memory management rules In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="33734824-912822679-1281733283=:6495" List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: qemu-devel This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --33734824-912822679-1281733283=:6495 Content-Type: TEXT/PLAIN; charset=UTF-8 Content-Transfer-Encoding: 8BIT On Fri, 13 Aug 2010, Blue Swirl wrote: > On Thu, Aug 12, 2010 at 5:50 PM, Blue Swirl wrote: > > Add memory management rules, somewhat like libvirt HACKING. > > > > Signed-off-by: Blue Swirl > > --- > >  CODING_STYLE |    8 ++++++++ > >  1 files changed, 8 insertions(+), 0 deletions(-) > > > > diff --git a/CODING_STYLE b/CODING_STYLE > > index 3f10d72..085c86f 100644 > > --- a/CODING_STYLE > > +++ b/CODING_STYLE > > @@ -148,3 +148,11 @@ up-front that this is a read-only pointer.  Perhaps more > >  importantly, if we're diligent about this, when you see a non-const > >  pointer, you're guaranteed that it is used to modify the storage > >  it points to, or it is aliased to another pointer that is. > > + > > + > > +7. Low level memory management > > + > > +Use of the malloc/free/realloc/calloc APIs is not allowed in the QEMU > > I forgot to add valloc/memalign/posix_memalign. > > > +codebase. Instead of these routines, use the replacement > > +qemu_malloc/qemu_mallocz/qemu_realloc/qemu_free or > > +qemu_vmalloc/qemu_memalign/qemu_vfree APIs. > > This should also mention that memory allocated by qemu_vmalloc or > qemu_memalign should be freed with qemu_vfree. > > In general, whole of 7 is an existing rule and current codebase seems > to follow it. > > This should be added as a strict rule (as opposed to guideline), since > breaking this will cause problems on Win32 and user emulators. > This is all perfectly reasonable, but begs one question, where do we stop codifying self-evident truths (or who is the ultimiate judge of what is self-evident and what isn't), since taking the above to extreme we will end up adding stuff like: you must use close to dispose of open-ed descriptors and such like. -- mailto:av1474@comtv.ru --33734824-912822679-1281733283=:6495--