From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NHfrf-0004zU-PY for qemu-devel@nongnu.org; Mon, 07 Dec 2009 10:51:07 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NHfrb-0004sq-BH for qemu-devel@nongnu.org; Mon, 07 Dec 2009 10:51:07 -0500 Received: from [199.232.76.173] (port=53192 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NHfra-0004sb-Ja for qemu-devel@nongnu.org; Mon, 07 Dec 2009 10:51:02 -0500 Received: from mail-yx0-f188.google.com ([209.85.210.188]:56903) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NHfra-0003iE-NU for qemu-devel@nongnu.org; Mon, 07 Dec 2009 10:51:02 -0500 Received: by yxe26 with SMTP id 26so4239131yxe.4 for ; Mon, 07 Dec 2009 07:51:01 -0800 (PST) Message-ID: <4B1D2462.3070000@codemonkey.ws> Date: Mon, 07 Dec 2009 09:50:58 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] Permit zero-sized qemu_malloc() & friends References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: Kevin Wolf , Paul Brook , qemu-devel@nongnu.org, Avi Kivity Markus Armbruster wrote: > Commit a7d27b53 made zero-sized allocations a fatal error, deviating > from ISO C's malloc() & friends. Revert 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 to capture some action items from the discussion that I think there is agreement about. Since 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 return malloc(1) when size=0 only for production builds (via --enable-zero-mallocs). Development trees will maintain their current 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. I'm not tied to them. Will do our best to convert old code to use these functions where ever possible. New code will be required to use these functions unless not possible. n_types==0 is valid. sizeof(type)==0 is valid. Both circumstances return a unique non-NULL pointer. If memory allocation fails, execution will abort. The existing qemu_malloc() will maintain it's current behavior (with the exception of the relaxed size==0 assertion for production releases). Does anyone object to this moving forward? Regards, Anthony Liguori