From patchwork Wed Oct 7 00:26:58 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 35174 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AB526B7B70 for ; Wed, 7 Oct 2009 11:31:04 +1100 (EST) Received: from localhost ([127.0.0.1]:47563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvKQn-0002lx-Q1 for incoming@patchwork.ozlabs.org; Tue, 06 Oct 2009 20:31:01 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvKNR-0001Pg-Hc for qemu-devel@nongnu.org; Tue, 06 Oct 2009 20:27:33 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvKNM-0001K0-5H for qemu-devel@nongnu.org; Tue, 06 Oct 2009 20:27:32 -0400 Received: from [199.232.76.173] (port=45740 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvKNL-0001Jo-Pr for qemu-devel@nongnu.org; Tue, 06 Oct 2009 20:27:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45237) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MvKNJ-00072h-J7 for qemu-devel@nongnu.org; Tue, 06 Oct 2009 20:27:26 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n970RO74026452; Tue, 6 Oct 2009 20:27:24 -0400 Received: from localhost (vpn-12-79.rdu.redhat.com [10.11.12.79]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n970RNx8020650; Tue, 6 Oct 2009 20:27:24 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Tue, 6 Oct 2009 21:26:58 -0300 Message-Id: <1254875232-25012-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1254875232-25012-1-git-send-email-lcapitulino@redhat.com> References: <1254875232-25012-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com, avi@redhat.com Subject: [Qemu-devel] [PATCH 01/15] QObject: Accept NULL X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It is convenient that QDECREF() and QINCREF() accept the QObject parameter to be NULL, so that we don't duplicate 'if' tests in the callers. Signed-off-by: Luiz Capitulino --- qobject.h | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-) diff --git a/qobject.h b/qobject.h index 39b8649..dcc8c63 100644 --- a/qobject.h +++ b/qobject.h @@ -63,12 +63,10 @@ typedef struct QObject { /* High-level interface for qobject_incref() */ #define QINCREF(obj) \ - assert(obj != NULL); \ qobject_incref(QOBJECT(obj)) /* High-level interface for qobject_decref() */ #define QDECREF(obj) \ - assert(obj != NULL); \ qobject_decref(QOBJECT(obj)) /* Initialize an object to default values */ @@ -81,7 +79,8 @@ typedef struct QObject { */ static inline void qobject_incref(QObject *obj) { - obj->refcnt++; + if (obj) + obj->refcnt++; } /** @@ -90,7 +89,7 @@ static inline void qobject_incref(QObject *obj) */ static inline void qobject_decref(QObject *obj) { - if (--obj->refcnt == 0) { + if (obj && --obj->refcnt == 0) { assert(obj->type != NULL); assert(obj->type->destroy != NULL); obj->type->destroy(obj);