From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: Re: [PATCH] Introduce QEMU_NEW() Date: Mon, 25 Jul 2011 12:37:14 +0300 Message-ID: <1311586634.3446.35.camel@lappy> References: <1311583872-362-1-git-send-email-avi@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: Avi Kivity , qemu-devel@nongnu.org, kvm@vger.kernel.org To: Alexander Graf Return-path: Received: from mail-wy0-f174.google.com ([74.125.82.174]:61335 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751100Ab1GYJhr (ORCPT ); Mon, 25 Jul 2011 05:37:47 -0400 Received: by wyg8 with SMTP id 8so2611299wyg.19 for ; Mon, 25 Jul 2011 02:37:46 -0700 (PDT) In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On Mon, 2011-07-25 at 11:32 +0200, Alexander Graf wrote: > On 25.07.2011, at 10:51, Avi Kivity wrote: > > > qemu_malloc() is type-unsafe as it returns a void pointer. Introduce > > QEMU_NEW() (and QEMU_NEWZ()), which return the correct type. > > What does this buy you over > > type *x = qemu_malloc(sizeof(type)); > > ? I find the non-C++ version easier to read even. It'll warn when you do silly things such as: struct some_struct *k; k = qemu_malloc(sizeof(k)); -- Sasha. From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:47603) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QlHbg-0002st-T0 for qemu-devel@nongnu.org; Mon, 25 Jul 2011 05:37:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QlHbf-0002O2-Pj for qemu-devel@nongnu.org; Mon, 25 Jul 2011 05:37:48 -0400 Received: from mail-ww0-f53.google.com ([74.125.82.53]:35659) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QlHbf-0002Ny-LP for qemu-devel@nongnu.org; Mon, 25 Jul 2011 05:37:47 -0400 Received: by wwf26 with SMTP id 26so3473582wwf.10 for ; Mon, 25 Jul 2011 02:37:46 -0700 (PDT) From: Sasha Levin In-Reply-To: References: <1311583872-362-1-git-send-email-avi@redhat.com> Content-Type: text/plain; charset="us-ascii" Date: Mon, 25 Jul 2011 12:37:14 +0300 Message-ID: <1311586634.3446.35.camel@lappy> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] Introduce QEMU_NEW() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Graf Cc: Avi Kivity , kvm@vger.kernel.org, qemu-devel@nongnu.org On Mon, 2011-07-25 at 11:32 +0200, Alexander Graf wrote: > On 25.07.2011, at 10:51, Avi Kivity wrote: > > > qemu_malloc() is type-unsafe as it returns a void pointer. Introduce > > QEMU_NEW() (and QEMU_NEWZ()), which return the correct type. > > What does this buy you over > > type *x = qemu_malloc(sizeof(type)); > > ? I find the non-C++ version easier to read even. It'll warn when you do silly things such as: struct some_struct *k; k = qemu_malloc(sizeof(k)); -- Sasha.