From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvZam-0002Bt-Ja for qemu-devel@nongnu.org; Wed, 07 Oct 2009 12:42:20 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvZai-0002AD-Rm for qemu-devel@nongnu.org; Wed, 07 Oct 2009 12:42:20 -0400 Received: from [199.232.76.173] (port=49970 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvZai-0002A2-KY for qemu-devel@nongnu.org; Wed, 07 Oct 2009 12:42:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57905) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MvZah-0005PG-Rx for qemu-devel@nongnu.org; Wed, 07 Oct 2009 12:42:16 -0400 From: Luiz Capitulino Date: Wed, 7 Oct 2009 13:41:47 -0300 Message-Id: <1254933724-22485-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1254933724-22485-1-git-send-email-lcapitulino@redhat.com> References: <1254933724-22485-1-git-send-email-lcapitulino@redhat.com> Subject: [Qemu-devel] [PATCH 01/18] QObject: Accept NULL List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, avi@redhat.com 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); -- 1.6.5.rc2.17.gdbc1b