]> xenbits.xensource.com Git - libvirt.git/commitdiff
build: allow virObject to have no parent
authorEric Blake <eblake@redhat.com>
Tue, 22 Jan 2013 17:13:01 +0000 (10:13 -0700)
committerEric Blake <eblake@redhat.com>
Tue, 22 Jan 2013 20:45:38 +0000 (13:45 -0700)
When building with static analysis enabled, we turn on attribute
nonnull checking.  However, this caused the build to fail with:

../../src/util/virobject.c: In function 'virObjectOnceInit':
../../src/util/virobject.c:55:40: error: null argument where non-null required (argument 1) [-Werror=nonnull]

Creation of the virObject class is the one instance where the
parent class is allowed to be NULL.  Making things conditional
will let us keep static analysis checking for all other .c file
callers, without breaking the build on this one exception.

* src/util/virobject.c: Define witness.
* src/util/virobject.h (virClassNew): Use it to force most callers
to pass non-null parameter.

src/util/virobject.c
src/util/virobject.h

index 7f08a11ce35740cbfa82dba5902815ae2397a6f6..808edc4837da9d3b1dc8ebbac4a6e29c37813cd9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * virobject.c: libvirt reference counted object
  *
- * Copyright (C) 2012 Red Hat, Inc.
+ * Copyright (C) 2012-2013 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -21,6 +21,7 @@
 
 #include <config.h>
 
+#define VIR_PARENT_REQUIRED /* empty, to allow virObject to have no parent */
 #include "virobject.h"
 #include "virthread.h"
 #include "viralloc.h"
index bb72a25bc37e56f20ad57289567f7fdc5e5d43d4..3a08f10d050def5e909d21f48de1dee470307223 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * virobject.h: libvirt reference counted object
  *
- * Copyright (C) 2012 Red Hat, Inc.
+ * Copyright (C) 2012-2013 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -51,11 +51,14 @@ struct _virObjectLockable {
 virClassPtr virClassForObject(void);
 virClassPtr virClassForObjectLockable(void);
 
+# ifndef VIR_PARENT_REQUIRED
+#  define VIR_PARENT_REQUIRED ATTRIBUTE_NONNULL(1)
+# endif
 virClassPtr virClassNew(virClassPtr parent,
                         const char *name,
                         size_t objectSize,
                         virObjectDisposeCallback dispose)
-    ATTRIBUTE_NONNULL(1);
+    VIR_PARENT_REQUIRED ATTRIBUTE_NONNULL(2);
 
 const char *virClassName(virClassPtr klass)
     ATTRIBUTE_NONNULL(1);