mirror of https://github.com/xqemu/xqemu.git
QObject: Accept NULL
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. Patchworks-ID: 35332 Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
c62c4551b8
commit
d559ba1af2
|
@ -63,12 +63,10 @@ typedef struct QObject {
|
||||||
|
|
||||||
/* High-level interface for qobject_incref() */
|
/* High-level interface for qobject_incref() */
|
||||||
#define QINCREF(obj) \
|
#define QINCREF(obj) \
|
||||||
assert(obj != NULL); \
|
|
||||||
qobject_incref(QOBJECT(obj))
|
qobject_incref(QOBJECT(obj))
|
||||||
|
|
||||||
/* High-level interface for qobject_decref() */
|
/* High-level interface for qobject_decref() */
|
||||||
#define QDECREF(obj) \
|
#define QDECREF(obj) \
|
||||||
assert(obj != NULL); \
|
|
||||||
qobject_decref(QOBJECT(obj))
|
qobject_decref(QOBJECT(obj))
|
||||||
|
|
||||||
/* Initialize an object to default values */
|
/* Initialize an object to default values */
|
||||||
|
@ -81,6 +79,7 @@ typedef struct QObject {
|
||||||
*/
|
*/
|
||||||
static inline void qobject_incref(QObject *obj)
|
static inline void qobject_incref(QObject *obj)
|
||||||
{
|
{
|
||||||
|
if (obj)
|
||||||
obj->refcnt++;
|
obj->refcnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +89,7 @@ static inline void qobject_incref(QObject *obj)
|
||||||
*/
|
*/
|
||||||
static inline void qobject_decref(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 != NULL);
|
||||||
assert(obj->type->destroy != NULL);
|
assert(obj->type->destroy != NULL);
|
||||||
obj->type->destroy(obj);
|
obj->type->destroy(obj);
|
||||||
|
|
Loading…
Reference in New Issue