Patchwork [01/18] QObject: Accept NULL

login
register
mail settings
Submitter Luiz Capitulino
Date Oct. 7, 2009, 4:31 p.m.
Message ID <1254933135-21888-2-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/35315/
State Superseded
Headers show

Comments

Luiz Capitulino - Oct. 7, 2009, 4:31 p.m.
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 <lcapitulino@redhat.com>
---
 qobject.h |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

Patch

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);