From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NHi5L-00052O-RY for qemu-devel@nongnu.org; Mon, 07 Dec 2009 13:13:23 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NHi5H-0004wZ-0h for qemu-devel@nongnu.org; Mon, 07 Dec 2009 13:13:23 -0500 Received: from [199.232.76.173] (port=48069 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NHi5G-0004w9-Hr for qemu-devel@nongnu.org; Mon, 07 Dec 2009 13:13:18 -0500 Received: from mail-yx0-f188.google.com ([209.85.210.188]:45577) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NHi5G-0001uN-2H for qemu-devel@nongnu.org; Mon, 07 Dec 2009 13:13:18 -0500 Received: by yxe26 with SMTP id 26so4379419yxe.4 for ; Mon, 07 Dec 2009 10:13:17 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <4B1D2462.3070000@codemonkey.ws> References: <4B1D2462.3070000@codemonkey.ws> From: Blue Swirl Date: Mon, 7 Dec 2009 20:12:57 +0200 Message-ID: Subject: Re: [Qemu-devel] [PATCH] Permit zero-sized qemu_malloc() & friends Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Kevin Wolf , qemu-devel@nongnu.org, Avi Kivity , Markus Armbruster , Paul Brook On Mon, Dec 7, 2009 at 5:50 PM, Anthony Liguori wro= te: > Markus Armbruster wrote: >> >> Commit a7d27b53 made zero-sized allocations a fatal error, deviating >> from ISO C's malloc() & friends. =C2=A0Revert that, but take care never = to >> return a null pointer, like malloc() & friends may do (it's >> implementation defined), because that's another source of bugs. >> > > While it's always fun to argue about standards interpretation, I wanted t= o > capture some action items from the discussion that I think there is > agreement about. =C2=A0Since I want to make changes for 0.12, I think it = would be > best to try and settle these now so we can do this before -rc2. > > For 0.12.0-rc2: > > I will send out a patch tonight or tomorrow changing qemu_malloc() to ret= urn > malloc(1) when size=3D0 only for production builds (via > --enable-zero-mallocs). =C2=A0Development trees will maintain their curre= nt > behavior. > > For 0.13: > > Someone (Marcus?) will introduce four new allocation functions. > > type *qemu_new(type, n_types); > type *qemu_new0(type, n_types); > > type *qemu_renew(type, mem, n_types); > type *qemu_renew0(type, mem, n_types); > > NB: The names are borrowed from glib. =C2=A0I'm not tied to them. > > Will do our best to convert old code to use these functions where ever > possible. =C2=A0New code will be required to use these functions unless n= ot > possible. =C2=A0n_types=3D=3D0 is valid. =C2=A0sizeof(type)=3D=3D0 is val= id. =C2=A0Both > circumstances return a unique non-NULL pointer. =C2=A0If memory allocatio= n fails, > execution will abort. > > The existing qemu_malloc() will maintain it's current behavior (with the > exception of the relaxed size=3D=3D0 assertion for production releases). > > Does anyone object to this moving forward? Excellent plan.