[PATCH v2 3/5] virobject: Introduce VIR_CLASS_NEW() macro

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



So far we are repeating the following lines over and over:

  if (!(virSomeObjectClass = virClassNew(virClassForObject(),
                             "virSomeObject",
                             sizeof(virSomeObject),
                             virSomeObjectDispose);
      return -1;

While this works, it is impossible to do some checking. Firstly,
the class name (the 2nd argument) doesn't match the name in the
code in all cases (the 3rd argument). Secondly, the current style
is needlessly verbose. This commit turns example into following:

  VIR_CLASS_NEW(virClassForObject(),
                virSomeObject);

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/access/viraccessmanager.c           |   7 +-
 src/bhyve/bhyve_conf.c                  |   9 +-
 src/conf/capabilities.c                 |   7 +-
 src/conf/domain_capabilities.c          |  15 +--
 src/conf/domain_conf.c                  |  26 ++---
 src/conf/domain_event.c                 | 169 ++++++++------------------------
 src/conf/network_event.c                |  18 ++--
 src/conf/node_device_event.c            |  27 ++---
 src/conf/object_event.c                 |  16 +--
 src/conf/secret_event.c                 |  27 ++---
 src/conf/storage_event.c                |  27 ++---
 src/conf/virdomainobjlist.c             |   7 +-
 src/conf/virinterfaceobj.c              |  14 +--
 src/conf/virnetworkobj.c                |  14 +--
 src/conf/virnodedeviceobj.c             |  14 +--
 src/conf/virsecretobj.c                 |  14 +--
 src/conf/virstorageobj.c                |  28 ++----
 src/datatypes.c                         |  11 +--
 src/interface/interface_backend_netcf.c |   8 +-
 src/libvirt-admin.c                     |   8 +-
 src/libxl/libxl_conf.c                  |   7 +-
 src/libxl/libxl_domain.c                |   7 +-
 src/libxl/libxl_migration.c             |   7 +-
 src/logging/log_handler.c               |   7 +-
 src/lxc/lxc_conf.c                      |   7 +-
 src/lxc/lxc_monitor.c                   |   7 +-
 src/node_device/node_device_udev.c      |   7 +-
 src/qemu/qemu_agent.c                   |   7 +-
 src/qemu/qemu_capabilities.c            |   7 +-
 src/qemu/qemu_conf.c                    |  11 +--
 src/qemu/qemu_domain.c                  |  63 ++++--------
 src/qemu/qemu_monitor.c                 |   7 +-
 src/rpc/virkeepalive.c                  |   7 +-
 src/rpc/virnetclient.c                  |   7 +-
 src/rpc/virnetclientprogram.c           |   7 +-
 src/rpc/virnetclientstream.c            |   7 +-
 src/rpc/virnetdaemon.c                  |   7 +-
 src/rpc/virnetlibsshsession.c           |   7 +-
 src/rpc/virnetsaslcontext.c             |  14 +--
 src/rpc/virnetserver.c                  |   7 +-
 src/rpc/virnetserverclient.c            |   7 +-
 src/rpc/virnetserverprogram.c           |   7 +-
 src/rpc/virnetserverservice.c           |   7 +-
 src/rpc/virnetsocket.c                  |   7 +-
 src/rpc/virnetsshsession.c              |   7 +-
 src/rpc/virnettlscontext.c              |  14 +--
 src/security/security_manager.c         |   7 +-
 src/util/virclosecallbacks.c            |  11 +--
 src/util/virdnsmasq.c                   |   8 +-
 src/util/virfdstream.c                  |   7 +-
 src/util/virfilecache.c                 |   7 +-
 src/util/virhash.c                      |  12 +--
 src/util/virhostdev.c                   |   7 +-
 src/util/viridentity.c                  |   7 +-
 src/util/virmacmap.c                    |   7 +-
 src/util/virmdev.c                      |   7 +-
 src/util/virobject.c                    |  14 +--
 src/util/virobject.h                    |   9 ++
 src/util/virpci.c                       |   7 +-
 src/util/virportallocator.c             |   7 +-
 src/util/virresctrl.c                   |  14 +--
 src/util/virscsi.c                      |   7 +-
 src/util/virscsivhost.c                 |   7 +-
 src/util/virusb.c                       |   7 +-
 src/vbox/vbox_common.c                  |   7 +-
 src/vz/vz_driver.c                      |   7 +-
 tests/virfilecachetest.c                |   7 +-
 67 files changed, 264 insertions(+), 631 deletions(-)

diff --git a/src/access/viraccessmanager.c b/src/access/viraccessmanager.c
index c268ec57f7..a8d361d389 100644
--- a/src/access/viraccessmanager.c
+++ b/src/access/viraccessmanager.c
@@ -54,11 +54,8 @@ static void virAccessManagerDispose(void *obj);
 
 static int virAccessManagerOnceInit(void)
 {
-    if (!(virAccessManagerClass = virClassNew(virClassForObjectLockable(),
-                                              "virAccessManagerClass",
-                                              sizeof(virAccessManager),
-                                              virAccessManagerDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virAccessManager);
 
     return 0;
 }
diff --git a/src/bhyve/bhyve_conf.c b/src/bhyve/bhyve_conf.c
index b0b40c5754..f35ec1a207 100644
--- a/src/bhyve/bhyve_conf.c
+++ b/src/bhyve/bhyve_conf.c
@@ -36,13 +36,10 @@ static void virBhyveDriverConfigDispose(void *obj);
 
 static int virBhyveConfigOnceInit(void)
 {
-     if (!(virBhyveDriverConfigClass = virClassNew(virClassForObject(),
-                                                   "virBhyveDriverConfig",
-                                                   sizeof(virBhyveDriverConfig),
-                                                   virBhyveDriverConfigDispose)))
-         return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  virBhyveDriverConfig);
 
-     return 0;
+    return 0;
 }
 
 VIR_ONCE_GLOBAL_INIT(virBhyveConfig)
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 33b9194041..f35d754159 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -62,11 +62,8 @@ static void virCapsDispose(void *obj);
 
 static int virCapabilitiesOnceInit(void)
 {
-    if (!(virCapsClass = virClassNew(virClassForObject(),
-                                     "virCaps",
-                                     sizeof(virCaps),
-                                     virCapsDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  virCaps);
 
     return 0;
 }
diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c
index f7d9be50f8..9c32f72b92 100644
--- a/src/conf/domain_capabilities.c
+++ b/src/conf/domain_capabilities.c
@@ -40,18 +40,11 @@ static void virDomainCapsCPUModelsDispose(void *obj);
 
 static int virDomainCapsOnceInit(void)
 {
-    if (!(virDomainCapsClass = virClassNew(virClassForObjectLockable(),
-                                           "virDomainCapsClass",
-                                           sizeof(virDomainCaps),
-                                           virDomainCapsDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virDomainCaps);
 
-    virDomainCapsCPUModelsClass = virClassNew(virClassForObject(),
-                                              "virDomainCapsCPUModelsClass",
-                                              sizeof(virDomainCapsCPUModels),
-                                              virDomainCapsCPUModelsDispose);
-    if (!virDomainCapsCPUModelsClass)
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  virDomainCapsCPUModels);
 
     return 0;
 }
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4dad8e3b20..a47a89d9fa 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -938,17 +938,11 @@ static void virDomainXMLOptionDispose(void *obj);
 
 static int virDomainObjOnceInit(void)
 {
-    if (!(virDomainObjClass = virClassNew(virClassForObjectLockable(),
-                                          "virDomainObj",
-                                          sizeof(virDomainObj),
-                                          virDomainObjDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virDomainObj);
 
-    if (!(virDomainXMLOptionClass = virClassNew(virClassForObject(),
-                                                "virDomainXMLOption",
-                                                sizeof(virDomainXMLOption),
-                                                virDomainXMLOptionDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  virDomainXMLOption);
 
     return 0;
 }
@@ -12223,14 +12217,10 @@ static virClassPtr virDomainChrSourceDefClass;
 static int
 virDomainChrSourceDefOnceInit(void)
 {
-    virDomainChrSourceDefClass = virClassNew(virClassForObject(),
-                                             "virDomainChrSourceDef",
-                                             sizeof(virDomainChrSourceDef),
-                                             virDomainChrSourceDefDispose);
-    if (!virDomainChrSourceDefClass)
-        return -1;
-    else
-        return 0;
+    VIR_CLASS_NEW(virClassForObject(),
+                  virDomainChrSourceDef);
+
+    return 0;
 }
 
 VIR_ONCE_GLOBAL_INIT(virDomainChrSourceDef);
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index fdb48a1eaa..dd1194c268 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -295,132 +295,49 @@ typedef virDomainEventBlockThreshold *virDomainEventBlockThresholdPtr;
 static int
 virDomainEventsOnceInit(void)
 {
-    if (!(virDomainEventClass =
-          virClassNew(virClassForObjectEvent(),
-                      "virDomainEvent",
-                      sizeof(virDomainEvent),
-                      virDomainEventDispose)))
-        return -1;
-    if (!(virDomainEventLifecycleClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventLifecycle",
-                      sizeof(virDomainEventLifecycle),
-                      virDomainEventLifecycleDispose)))
-        return -1;
-    if (!(virDomainEventRTCChangeClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventRTCChange",
-                      sizeof(virDomainEventRTCChange),
-                      virDomainEventRTCChangeDispose)))
-        return -1;
-    if (!(virDomainEventWatchdogClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventWatchdog",
-                      sizeof(virDomainEventWatchdog),
-                      virDomainEventWatchdogDispose)))
-        return -1;
-    if (!(virDomainEventIOErrorClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventIOError",
-                      sizeof(virDomainEventIOError),
-                      virDomainEventIOErrorDispose)))
-        return -1;
-    if (!(virDomainEventGraphicsClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventGraphics",
-                      sizeof(virDomainEventGraphics),
-                      virDomainEventGraphicsDispose)))
-        return -1;
-    if (!(virDomainEventBlockJobClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventBlockJob",
-                      sizeof(virDomainEventBlockJob),
-                      virDomainEventBlockJobDispose)))
-        return -1;
-    if (!(virDomainEventDiskChangeClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventDiskChange",
-                      sizeof(virDomainEventDiskChange),
-                      virDomainEventDiskChangeDispose)))
-        return -1;
-    if (!(virDomainEventTrayChangeClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventTrayChange",
-                      sizeof(virDomainEventTrayChange),
-                      virDomainEventTrayChangeDispose)))
-        return -1;
-    if (!(virDomainEventBalloonChangeClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventBalloonChange",
-                      sizeof(virDomainEventBalloonChange),
-                      virDomainEventBalloonChangeDispose)))
-        return -1;
-    if (!(virDomainEventDeviceRemovedClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventDeviceRemoved",
-                      sizeof(virDomainEventDeviceRemoved),
-                      virDomainEventDeviceRemovedDispose)))
-        return -1;
-    if (!(virDomainEventDeviceAddedClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventDeviceAdded",
-                      sizeof(virDomainEventDeviceAdded),
-                      virDomainEventDeviceAddedDispose)))
-        return -1;
-    if (!(virDomainEventPMClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventPM",
-                      sizeof(virDomainEventPM),
-                      virDomainEventPMDispose)))
-        return -1;
-    if (!(virDomainQemuMonitorEventClass =
-          virClassNew(virClassForObjectEvent(),
-                      "virDomainQemuMonitorEvent",
-                      sizeof(virDomainQemuMonitorEvent),
-                      virDomainQemuMonitorEventDispose)))
-        return -1;
-    if (!(virDomainEventTunableClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventTunable",
-                      sizeof(virDomainEventTunable),
-                      virDomainEventTunableDispose)))
-        return -1;
-    if (!(virDomainEventAgentLifecycleClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventAgentLifecycle",
-                      sizeof(virDomainEventAgentLifecycle),
-                      virDomainEventAgentLifecycleDispose)))
-        return -1;
-    if (!(virDomainEventMigrationIterationClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventMigrationIteration",
-                      sizeof(virDomainEventMigrationIteration),
-                      virDomainEventMigrationIterationDispose)))
-        return -1;
-    if (!(virDomainEventJobCompletedClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventJobCompleted",
-                      sizeof(virDomainEventJobCompleted),
-                      virDomainEventJobCompletedDispose)))
-        return -1;
-    if (!(virDomainEventDeviceRemovalFailedClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventDeviceRemovalFailed",
-                      sizeof(virDomainEventDeviceRemovalFailed),
-                      virDomainEventDeviceRemovalFailedDispose)))
-        return -1;
-    if (!(virDomainEventMetadataChangeClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventMetadataChange",
-                      sizeof(virDomainEventMetadataChange),
-                      virDomainEventMetadataChangeDispose)))
-        return -1;
-    if (!(virDomainEventBlockThresholdClass =
-          virClassNew(virDomainEventClass,
-                      "virDomainEventBlockThreshold",
-                      sizeof(virDomainEventBlockThreshold),
-                      virDomainEventBlockThresholdDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectEvent(),
+                  virDomainEvent);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventLifecycle);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventRTCChange);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventWatchdog);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventIOError);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventGraphics);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventBlockJob);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventDiskChange);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventTrayChange);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventBalloonChange);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventDeviceRemoved);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventDeviceAdded);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventPM);
+    VIR_CLASS_NEW(virClassForObjectEvent(),
+                  virDomainQemuMonitorEvent);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventTunable);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventAgentLifecycle);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventMigrationIteration);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventJobCompleted);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventDeviceRemovalFailed);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventMetadataChange);
+    VIR_CLASS_NEW(virDomainEventClass,
+                  virDomainEventBlockThreshold);
+
     return 0;
 }
 
diff --git a/src/conf/network_event.c b/src/conf/network_event.c
index e0d1a3d5ca..2984c8f783 100644
--- a/src/conf/network_event.c
+++ b/src/conf/network_event.c
@@ -57,18 +57,12 @@ static void virNetworkEventLifecycleDispose(void *obj);
 static int
 virNetworkEventsOnceInit(void)
 {
-    if (!(virNetworkEventClass =
-          virClassNew(virClassForObjectEvent(),
-                      "virNetworkEvent",
-                      sizeof(virNetworkEvent),
-                      virNetworkEventDispose)))
-        return -1;
-    if (!(virNetworkEventLifecycleClass =
-          virClassNew(virNetworkEventClass,
-                      "virNetworkEventLifecycle",
-                      sizeof(virNetworkEventLifecycle),
-                      virNetworkEventLifecycleDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectEvent(),
+                  virNetworkEvent);
+
+    VIR_CLASS_NEW(virNetworkEventClass,
+                  virNetworkEventLifecycle);
+
     return 0;
 }
 
diff --git a/src/conf/node_device_event.c b/src/conf/node_device_event.c
index 312ef512d1..6448b199df 100644
--- a/src/conf/node_device_event.c
+++ b/src/conf/node_device_event.c
@@ -66,24 +66,15 @@ static void virNodeDeviceEventUpdateDispose(void *obj);
 static int
 virNodeDeviceEventsOnceInit(void)
 {
-    if (!(virNodeDeviceEventClass =
-          virClassNew(virClassForObjectEvent(),
-                      "virNodeDeviceEvent",
-                      sizeof(virNodeDeviceEvent),
-                      virNodeDeviceEventDispose)))
-        return -1;
-    if (!(virNodeDeviceEventLifecycleClass =
-          virClassNew(virNodeDeviceEventClass,
-                      "virNodeDeviceEventLifecycle",
-                      sizeof(virNodeDeviceEventLifecycle),
-                      virNodeDeviceEventLifecycleDispose)))
-        return -1;
-    if (!(virNodeDeviceEventUpdateClass =
-          virClassNew(virNodeDeviceEventClass,
-                      "virNodeDeviceEventUpdate",
-                      sizeof(virNodeDeviceEventUpdate),
-                      virNodeDeviceEventUpdateDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectEvent(),
+                  virNodeDeviceEvent);
+
+    VIR_CLASS_NEW(virNodeDeviceEventClass,
+                  virNodeDeviceEventLifecycle);
+
+    VIR_CLASS_NEW(virNodeDeviceEventClass,
+                  virNodeDeviceEventUpdate);
+
     return 0;
 }
 
diff --git a/src/conf/object_event.c b/src/conf/object_event.c
index e8116b880c..1c9559293e 100644
--- a/src/conf/object_event.c
+++ b/src/conf/object_event.c
@@ -92,19 +92,11 @@ static void virObjectEventStateDispose(void *obj);
 static int
 virObjectEventOnceInit(void)
 {
-    if (!(virObjectEventStateClass =
-          virClassNew(virClassForObjectLockable(),
-                      "virObjectEventState",
-                      sizeof(virObjectEventState),
-                      virObjectEventStateDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virObjectEventState);
 
-    if (!(virObjectEventClass =
-          virClassNew(virClassForObject(),
-                      "virObjectEvent",
-                      sizeof(virObjectEvent),
-                      virObjectEventDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  virObjectEvent);
 
     return 0;
 }
diff --git a/src/conf/secret_event.c b/src/conf/secret_event.c
index c130909282..d899aee1b5 100644
--- a/src/conf/secret_event.c
+++ b/src/conf/secret_event.c
@@ -65,24 +65,15 @@ static void virSecretEventValueChangedDispose(void *obj);
 static int
 virSecretEventsOnceInit(void)
 {
-    if (!(virSecretEventClass =
-          virClassNew(virClassForObjectEvent(),
-                      "virSecretEvent",
-                      sizeof(virSecretEvent),
-                      virSecretEventDispose)))
-        return -1;
-    if (!(virSecretEventLifecycleClass =
-          virClassNew(virSecretEventClass,
-                      "virSecretEventLifecycle",
-                      sizeof(virSecretEventLifecycle),
-                      virSecretEventLifecycleDispose)))
-        return -1;
-    if (!(virSecretEventValueChangedClass =
-          virClassNew(virSecretEventClass,
-                      "virSecretEventValueChanged",
-                      sizeof(virSecretEventValueChanged),
-                      virSecretEventValueChangedDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectEvent(),
+                  virSecretEvent);
+
+    VIR_CLASS_NEW(virSecretEventClass,
+                  virSecretEventLifecycle);
+
+    VIR_CLASS_NEW(virSecretEventClass,
+                  virSecretEventValueChanged);
+
     return 0;
 }
 
diff --git a/src/conf/storage_event.c b/src/conf/storage_event.c
index f9b796878a..d1ab965bff 100644
--- a/src/conf/storage_event.c
+++ b/src/conf/storage_event.c
@@ -66,24 +66,15 @@ static void virStoragePoolEventRefreshDispose(void *obj);
 static int
 virStoragePoolEventsOnceInit(void)
 {
-    if (!(virStoragePoolEventClass =
-          virClassNew(virClassForObjectEvent(),
-                      "virStoragePoolEvent",
-                      sizeof(virStoragePoolEvent),
-                      virStoragePoolEventDispose)))
-        return -1;
-    if (!(virStoragePoolEventLifecycleClass =
-          virClassNew(virStoragePoolEventClass,
-                      "virStoragePoolEventLifecycle",
-                      sizeof(virStoragePoolEventLifecycle),
-                      virStoragePoolEventLifecycleDispose)))
-        return -1;
-    if (!(virStoragePoolEventRefreshClass =
-          virClassNew(virStoragePoolEventClass,
-                      "virStoragePoolEventRefresh",
-                      sizeof(virStoragePoolEventRefresh),
-                      virStoragePoolEventRefreshDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectEvent(),
+                  virStoragePoolEvent);
+
+    VIR_CLASS_NEW(virStoragePoolEventClass,
+                  virStoragePoolEventLifecycle);
+
+    VIR_CLASS_NEW(virStoragePoolEventClass,
+                  virStoragePoolEventRefresh);
+
     return 0;
 }
 
diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
index 7022abe094..b8dee3b5a2 100644
--- a/src/conf/virdomainobjlist.c
+++ b/src/conf/virdomainobjlist.c
@@ -56,11 +56,8 @@ struct _virDomainObjList {
 
 static int virDomainObjListOnceInit(void)
 {
-    if (!(virDomainObjListClass = virClassNew(virClassForObjectRWLockable(),
-                                              "virDomainObjList",
-                                              sizeof(virDomainObjList),
-                                              virDomainObjListDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectRWLockable(),
+                  virDomainObjList);
 
     return 0;
 }
diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c
index f90c0bd9c4..cb8eefa9b6 100644
--- a/src/conf/virinterfaceobj.c
+++ b/src/conf/virinterfaceobj.c
@@ -58,17 +58,11 @@ static void virInterfaceObjListDispose(void *obj);
 static int
 virInterfaceObjOnceInit(void)
 {
-    if (!(virInterfaceObjClass = virClassNew(virClassForObjectLockable(),
-                                             "virInterfaceObj",
-                                             sizeof(virInterfaceObj),
-                                             virInterfaceObjDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virInterfaceObj);
 
-    if (!(virInterfaceObjListClass = virClassNew(virClassForObjectRWLockable(),
-                                                 "virInterfaceObjList",
-                                                 sizeof(virInterfaceObjList),
-                                                 virInterfaceObjListDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectRWLockable(),
+                  virInterfaceObjList);
 
     return 0;
 }
diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index 8cd1b62c1c..ba1a3f9374 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -74,17 +74,11 @@ static void virNetworkObjListDispose(void *obj);
 static int
 virNetworkObjOnceInit(void)
 {
-    if (!(virNetworkObjClass = virClassNew(virClassForObjectLockable(),
-                                           "virNetworkObj",
-                                           sizeof(virNetworkObj),
-                                           virNetworkObjDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virNetworkObj);
 
-    if (!(virNetworkObjListClass = virClassNew(virClassForObjectRWLockable(),
-                                               "virNetworkObjList",
-                                               sizeof(virNetworkObjList),
-                                               virNetworkObjListDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectRWLockable(),
+                  virNetworkObjList);
     return 0;
 }
 
diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index 9d2996046f..33f52f1217 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -58,17 +58,11 @@ static bool virNodeDeviceObjHasCap(const virNodeDeviceObj *obj, int type);
 static int
 virNodeDeviceObjOnceInit(void)
 {
-    if (!(virNodeDeviceObjClass = virClassNew(virClassForObjectLockable(),
-                                              "virNodeDeviceObj",
-                                              sizeof(virNodeDeviceObj),
-                                              virNodeDeviceObjDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virNodeDeviceObj);
 
-    if (!(virNodeDeviceObjListClass = virClassNew(virClassForObjectRWLockable(),
-                                                  "virNodeDeviceObjList",
-                                                  sizeof(virNodeDeviceObjList),
-                                                  virNodeDeviceObjListDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectRWLockable(),
+                  virNodeDeviceObjList);
 
     return 0;
 }
diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index 47e0b28968..e7a385aa59 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -68,17 +68,11 @@ struct virSecretSearchData {
 static int
 virSecretObjOnceInit(void)
 {
-    if (!(virSecretObjClass = virClassNew(virClassForObjectLockable(),
-                                          "virSecretObj",
-                                          sizeof(virSecretObj),
-                                          virSecretObjDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virSecretObj);
 
-    if (!(virSecretObjListClass = virClassNew(virClassForObjectRWLockable(),
-                                              "virSecretObjList",
-                                              sizeof(virSecretObjList),
-                                              virSecretObjListDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectRWLockable(),
+                  virSecretObjList);
 
     return 0;
 }
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 799b8c9fa3..2342b09815 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -110,17 +110,11 @@ struct _virStoragePoolObjList {
 static int
 virStorageVolObjOnceInit(void)
 {
-    if (!(virStorageVolObjClass = virClassNew(virClassForObjectLockable(),
-                                              "virStorageVolObj",
-                                              sizeof(virStorageVolObj),
-                                              virStorageVolObjDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virStorageVolObj);
 
-    if (!(virStorageVolObjListClass = virClassNew(virClassForObjectRWLockable(),
-                                                  "virStorageVolObjList",
-                                                  sizeof(virStorageVolObjList),
-                                                  virStorageVolObjListDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectRWLockable(),
+                  virStorageVolObjList);
 
     return 0;
 }
@@ -207,17 +201,11 @@ virStorageVolObjListDispose(void *opaque)
 static int
 virStoragePoolObjOnceInit(void)
 {
-    if (!(virStoragePoolObjClass = virClassNew(virClassForObjectLockable(),
-                                               "virStoragePoolObj",
-                                               sizeof(virStoragePoolObj),
-                                               virStoragePoolObjDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virStoragePoolObj);
 
-    if (!(virStoragePoolObjListClass = virClassNew(virClassForObjectRWLockable(),
-                                                   "virStoragePoolObjList",
-                                                   sizeof(virStoragePoolObjList),
-                                                   virStoragePoolObjListDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectRWLockable(),
+                  virStoragePoolObjList);
 
     return 0;
 }
diff --git a/src/datatypes.c b/src/datatypes.c
index 0c3c66a9ce..2a7725f6f7 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -73,16 +73,10 @@ static void virAdmClientDispose(void *obj);
 static int
 virDataTypesOnceInit(void)
 {
-#define DECLARE_CLASS_COMMON(basename, parent) \
-    if (!(basename ## Class = virClassNew(parent, \
-                                          #basename, \
-                                          sizeof(basename), \
-                                          basename ## Dispose))) \
-        return -1;
 #define DECLARE_CLASS(basename) \
-    DECLARE_CLASS_COMMON(basename, virClassForObject())
+    VIR_CLASS_NEW(virClassForObject(), basename)
 #define DECLARE_CLASS_LOCKABLE(basename) \
-    DECLARE_CLASS_COMMON(basename, virClassForObjectLockable())
+    VIR_CLASS_NEW(virClassForObjectLockable(), basename)
 
     DECLARE_CLASS_LOCKABLE(virConnect);
     DECLARE_CLASS_LOCKABLE(virConnectCloseCallbackData);
@@ -102,7 +96,6 @@ virDataTypesOnceInit(void)
     DECLARE_CLASS(virAdmServer);
     DECLARE_CLASS(virAdmClient);
 
-#undef DECLARE_CLASS_COMMON
 #undef DECLARE_CLASS_LOCKABLE
 #undef DECLARE_CLASS
 
diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c
index cc2402febb..49fb102954 100644
--- a/src/interface/interface_backend_netcf.c
+++ b/src/interface/interface_backend_netcf.c
@@ -55,11 +55,9 @@ static void virNetcfDriverStateDispose(void *obj);
 static int
 virNetcfDriverStateOnceInit(void)
 {
-    if (!(virNetcfDriverStateClass = virClassNew(virClassForObjectLockable(),
-                                       "virNetcfDriverState",
-                                       sizeof(virNetcfDriverState),
-                                       virNetcfDriverStateDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virNetcfDriverState);
+
     return 0;
 }
 
diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c
index 7f695311b4..6c7c7ef236 100644
--- a/src/libvirt-admin.c
+++ b/src/libvirt-admin.c
@@ -67,11 +67,9 @@ virAdmGlobalInit(void)
     if (!bindtextdomain(PACKAGE, LOCALEDIR))
         goto error;
 
-    if (!(remoteAdminPrivClass = virClassNew(virClassForObjectLockable(),
-                                             "remoteAdminPriv",
-                                             sizeof(remoteAdminPriv),
-                                             remoteAdminPrivDispose)))
-        goto error;
+    VIR_CLASS_NEW_GOTO(virClassForObjectLockable(),
+                       remoteAdminPriv,
+                       error);
 
     return;
  error:
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index df1cece82f..977431a910 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -62,11 +62,8 @@ static void libxlDriverConfigDispose(void *obj);
 
 static int libxlConfigOnceInit(void)
 {
-    if (!(libxlDriverConfigClass = virClassNew(virClassForObject(),
-                                               "libxlDriverConfig",
-                                               sizeof(libxlDriverConfig),
-                                               libxlDriverConfigDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  libxlDriverConfig);
 
     return 0;
 }
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index ef9a902671..bf4c8b7a1e 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -58,11 +58,8 @@ libxlDomainObjPrivateDispose(void *obj);
 static int
 libxlDomainObjPrivateOnceInit(void)
 {
-    if (!(libxlDomainObjPrivateClass = virClassNew(virClassForObjectLockable(),
-                                                   "libxlDomainObjPrivate",
-                                                   sizeof(libxlDomainObjPrivate),
-                                                   libxlDomainObjPrivateDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  libxlDomainObjPrivate);
 
     return 0;
 }
diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c
index 5c0fd4b052..ba6436fb9c 100644
--- a/src/libxl/libxl_migration.c
+++ b/src/libxl/libxl_migration.c
@@ -244,11 +244,8 @@ libxlMigrationDstArgsDispose(void *obj)
 static int
 libxlMigrationDstArgsOnceInit(void)
 {
-    if (!(libxlMigrationDstArgsClass = virClassNew(virClassForObject(),
-                                                   "libxlMigrationDstArgs",
-                                                   sizeof(libxlMigrationDstArgs),
-                                                   libxlMigrationDstArgsDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  libxlMigrationDstArgs);
 
     return 0;
 }
diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c
index cd0ba6ec24..b87e52a19e 100644
--- a/src/logging/log_handler.c
+++ b/src/logging/log_handler.c
@@ -76,11 +76,8 @@ static void virLogHandlerDispose(void *obj);
 static int
 virLogHandlerOnceInit(void)
 {
-    if (!(virLogHandlerClass = virClassNew(virClassForObjectLockable(),
-                                          "virLogHandler",
-                                          sizeof(virLogHandler),
-                                          virLogHandlerDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virLogHandler);
 
     return 0;
 }
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index 92a82a4768..f8e82c0adb 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -48,11 +48,8 @@ static void virLXCDriverConfigDispose(void *obj);
 
 static int virLXCConfigOnceInit(void)
 {
-    if (!(virLXCDriverConfigClass = virClassNew(virClassForObject(),
-                                                 "virLXCDriverConfig",
-                                                 sizeof(virLXCDriverConfig),
-                                                 virLXCDriverConfigDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  virLXCDriverConfig);
 
     return 0;
 }
diff --git a/src/lxc/lxc_monitor.c b/src/lxc/lxc_monitor.c
index 9cab6c2035..f1af5a86be 100644
--- a/src/lxc/lxc_monitor.c
+++ b/src/lxc/lxc_monitor.c
@@ -51,11 +51,8 @@ static void virLXCMonitorDispose(void *obj);
 
 static int virLXCMonitorOnceInit(void)
 {
-    if (!(virLXCMonitorClass = virClassNew(virClassForObjectLockable(),
-                                           "virLXCMonitor",
-                                           sizeof(virLXCMonitor),
-                                           virLXCMonitorDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virLXCMonitor);
 
     return 0;
 }
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index de01816402..6a7d5306b7 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -93,11 +93,8 @@ udevEventDataDispose(void *obj)
 static int
 udevEventDataOnceInit(void)
 {
-    if (!(udevEventDataClass = virClassNew(virClassForObjectLockable(),
-                                           "udevEventData",
-                                           sizeof(udevEventData),
-                                           udevEventDataDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  udevEventData);
 
     return 0;
 }
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 85af53d194..8b2864cf68 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -138,11 +138,8 @@ static void qemuAgentDispose(void *obj);
 
 static int qemuAgentOnceInit(void)
 {
-    if (!(qemuAgentClass = virClassNew(virClassForObjectLockable(),
-                                       "qemuAgent",
-                                       sizeof(qemuAgent),
-                                       qemuAgentDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  qemuAgent);
 
     return 0;
 }
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 70cf0e9bf3..2668560454 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -548,11 +548,8 @@ static void virQEMUCapsDispose(void *obj);
 
 static int virQEMUCapsOnceInit(void)
 {
-    if (!(virQEMUCapsClass = virClassNew(virClassForObject(),
-                                         "virQEMUCaps",
-                                         sizeof(virQEMUCaps),
-                                         virQEMUCapsDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  virQEMUCaps);
 
     return 0;
 }
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 36cf3a281c..c31eb6bc75 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -80,15 +80,10 @@ static void virQEMUDriverConfigDispose(void *obj);
 
 static int virQEMUConfigOnceInit(void)
 {
-    virQEMUDriverConfigClass = virClassNew(virClassForObject(),
-                                           "virQEMUDriverConfig",
-                                           sizeof(virQEMUDriverConfig),
-                                           virQEMUDriverConfigDispose);
+    VIR_CLASS_NEW(virClassForObject(),
+                  virQEMUDriverConfig);
 
-    if (!virQEMUDriverConfigClass)
-        return -1;
-    else
-        return 0;
+    return 0;
 }
 
 VIR_ONCE_GLOBAL_INIT(virQEMUConfig)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 6e18886d07..c87d41dbb8 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -130,17 +130,11 @@ static void qemuDomainSaveCookieDispose(void *obj);
 static int
 qemuDomainOnceInit(void)
 {
-    if (!(qemuDomainLogContextClass = virClassNew(virClassForObject(),
-                                                 "qemuDomainLogContext",
-                                                 sizeof(qemuDomainLogContext),
-                                                 qemuDomainLogContextDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  qemuDomainLogContext);
 
-    if (!(qemuDomainSaveCookieClass = virClassNew(virClassForObject(),
-                                                  "qemuDomainSaveCookie",
-                                                  sizeof(qemuDomainSaveCookie),
-                                                  qemuDomainSaveCookieDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  qemuDomainSaveCookie);
 
     return 0;
 }
@@ -988,14 +982,10 @@ static void qemuDomainDiskPrivateDispose(void *obj);
 static int
 qemuDomainDiskPrivateOnceInit(void)
 {
-    qemuDomainDiskPrivateClass = virClassNew(virClassForObject(),
-                                             "qemuDomainDiskPrivate",
-                                             sizeof(qemuDomainDiskPrivate),
-                                             qemuDomainDiskPrivateDispose);
-    if (!qemuDomainDiskPrivateClass)
-        return -1;
-    else
-        return 0;
+    VIR_CLASS_NEW(virClassForObject(),
+                  qemuDomainDiskPrivate);
+
+    return 0;
 }
 
 VIR_ONCE_GLOBAL_INIT(qemuDomainDiskPrivate)
@@ -1028,14 +1018,10 @@ static void qemuDomainStorageSourcePrivateDispose(void *obj);
 static int
 qemuDomainStorageSourcePrivateOnceInit(void)
 {
-    qemuDomainStorageSourcePrivateClass = virClassNew(virClassForObject(),
-                                                      "qemuDomainStorageSourcePrivate",
-                                                      sizeof(qemuDomainStorageSourcePrivate),
-                                                      qemuDomainStorageSourcePrivateDispose);
-    if (!qemuDomainStorageSourcePrivateClass)
-        return -1;
-    else
-        return 0;
+    VIR_CLASS_NEW(virClassForObject(),
+                  qemuDomainStorageSourcePrivate);
+
+    return 0;
 }
 
 VIR_ONCE_GLOBAL_INIT(qemuDomainStorageSourcePrivate)
@@ -1071,14 +1057,10 @@ static void qemuDomainVcpuPrivateDispose(void *obj);
 static int
 qemuDomainVcpuPrivateOnceInit(void)
 {
-    qemuDomainVcpuPrivateClass = virClassNew(virClassForObject(),
-                                             "qemuDomainVcpuPrivate",
-                                             sizeof(qemuDomainVcpuPrivate),
-                                             qemuDomainVcpuPrivateDispose);
-    if (!qemuDomainVcpuPrivateClass)
-        return -1;
-    else
-        return 0;
+    VIR_CLASS_NEW(virClassForObject(),
+                  qemuDomainVcpuPrivate);
+
+    return 0;
 }
 
 VIR_ONCE_GLOBAL_INIT(qemuDomainVcpuPrivate)
@@ -1115,15 +1097,10 @@ static void qemuDomainChrSourcePrivateDispose(void *obj);
 static int
 qemuDomainChrSourcePrivateOnceInit(void)
 {
-    qemuDomainChrSourcePrivateClass =
-        virClassNew(virClassForObject(),
-                    "qemuDomainChrSourcePrivate",
-                    sizeof(qemuDomainChrSourcePrivate),
-                    qemuDomainChrSourcePrivateDispose);
-    if (!qemuDomainChrSourcePrivateClass)
-        return -1;
-    else
-        return 0;
+    VIR_CLASS_NEW(virClassForObject(),
+                  qemuDomainChrSourcePrivate);
+
+    return 0;
 }
 
 VIR_ONCE_GLOBAL_INIT(qemuDomainChrSourcePrivate)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 22f05222db..9b3ac41d0b 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -165,11 +165,8 @@ static void qemuMonitorDispose(void *obj);
 
 static int qemuMonitorOnceInit(void)
 {
-    if (!(qemuMonitorClass = virClassNew(virClassForObjectLockable(),
-                                         "qemuMonitor",
-                                         sizeof(qemuMonitor),
-                                         qemuMonitorDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  qemuMonitor);
 
     return 0;
 }
diff --git a/src/rpc/virkeepalive.c b/src/rpc/virkeepalive.c
index 4f666fd09b..c5f353e350 100644
--- a/src/rpc/virkeepalive.c
+++ b/src/rpc/virkeepalive.c
@@ -58,11 +58,8 @@ static void virKeepAliveDispose(void *obj);
 
 static int virKeepAliveOnceInit(void)
 {
-    if (!(virKeepAliveClass = virClassNew(virClassForObjectLockable(),
-                                          "virKeepAlive",
-                                          sizeof(virKeepAlive),
-                                          virKeepAliveDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virKeepAlive);
 
     return 0;
 }
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 0c8d58c32c..2e79384017 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -120,11 +120,8 @@ static void virNetClientDispose(void *obj);
 
 static int virNetClientOnceInit(void)
 {
-    if (!(virNetClientClass = virClassNew(virClassForObjectLockable(),
-                                          "virNetClient",
-                                          sizeof(virNetClient),
-                                          virNetClientDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virNetClient);
 
     return 0;
 }
diff --git a/src/rpc/virnetclientprogram.c b/src/rpc/virnetclientprogram.c
index d1e54a0892..687378c41a 100644
--- a/src/rpc/virnetclientprogram.c
+++ b/src/rpc/virnetclientprogram.c
@@ -54,11 +54,8 @@ static void virNetClientProgramDispose(void *obj);
 
 static int virNetClientProgramOnceInit(void)
 {
-    if (!(virNetClientProgramClass = virClassNew(virClassForObject(),
-                                                 "virNetClientProgram",
-                                                 sizeof(virNetClientProgram),
-                                                 virNetClientProgramDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  virNetClientProgram);
 
     return 0;
 }
diff --git a/src/rpc/virnetclientstream.c b/src/rpc/virnetclientstream.c
index 2f037db0dc..2a1be174ba 100644
--- a/src/rpc/virnetclientstream.c
+++ b/src/rpc/virnetclientstream.c
@@ -71,11 +71,8 @@ static void virNetClientStreamDispose(void *obj);
 
 static int virNetClientStreamOnceInit(void)
 {
-    if (!(virNetClientStreamClass = virClassNew(virClassForObjectLockable(),
-                                                "virNetClientStream",
-                                                sizeof(virNetClientStream),
-                                                virNetClientStreamDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virNetClientStream);
 
     return 0;
 }
diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c
index 6f00bfd9d1..41cf31cfd3 100644
--- a/src/rpc/virnetdaemon.c
+++ b/src/rpc/virnetdaemon.c
@@ -110,11 +110,8 @@ virNetDaemonDispose(void *obj)
 static int
 virNetDaemonOnceInit(void)
 {
-    if (!(virNetDaemonClass = virClassNew(virClassForObjectLockable(),
-                                          "virNetDaemon",
-                                          sizeof(virNetDaemon),
-                                          virNetDaemonDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virNetDaemon);
 
     return 0;
 }
diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c
index 25f93cec97..1f0d171803 100644
--- a/src/rpc/virnetlibsshsession.c
+++ b/src/rpc/virnetlibsshsession.c
@@ -161,11 +161,8 @@ virNetLibsshSessionOnceInit(void)
 {
     const char *dbgLevelStr;
 
-    if (!(virNetLibsshSessionClass = virClassNew(virClassForObjectLockable(),
-                                                 "virNetLibsshSession",
-                                                 sizeof(virNetLibsshSession),
-                                                 virNetLibsshSessionDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virNetLibsshSession);
 
     if (ssh_init() < 0) {
         virReportError(VIR_ERR_LIBSSH, "%s",
diff --git a/src/rpc/virnetsaslcontext.c b/src/rpc/virnetsaslcontext.c
index 2b564d1736..a128fc06e9 100644
--- a/src/rpc/virnetsaslcontext.c
+++ b/src/rpc/virnetsaslcontext.c
@@ -57,17 +57,11 @@ static void virNetSASLSessionDispose(void *obj);
 
 static int virNetSASLContextOnceInit(void)
 {
-    if (!(virNetSASLContextClass = virClassNew(virClassForObjectLockable(),
-                                               "virNetSASLContext",
-                                               sizeof(virNetSASLContext),
-                                               virNetSASLContextDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virNetSASLContext);
 
-    if (!(virNetSASLSessionClass = virClassNew(virClassForObjectLockable(),
-                                               "virNetSASLSession",
-                                               sizeof(virNetSASLSession),
-                                               virNetSASLSessionDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virNetSASLSession);
 
     return 0;
 }
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index 3ce21a8f53..81f11ac816 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -93,11 +93,8 @@ static inline size_t virNetServerTrackCompletedAuthLocked(virNetServerPtr srv);
 
 static int virNetServerOnceInit(void)
 {
-    if (!(virNetServerClass = virClassNew(virClassForObjectLockable(),
-                                          "virNetServer",
-                                          sizeof(virNetServer),
-                                          virNetServerDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virNetServer);
 
     return 0;
 }
diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c
index d5f0cf448f..6f8e1c985f 100644
--- a/src/rpc/virnetserverclient.c
+++ b/src/rpc/virnetserverclient.c
@@ -129,11 +129,8 @@ static void virNetServerClientDispose(void *obj);
 
 static int virNetServerClientOnceInit(void)
 {
-    if (!(virNetServerClientClass = virClassNew(virClassForObjectLockable(),
-                                                "virNetServerClient",
-                                                sizeof(virNetServerClient),
-                                                virNetServerClientDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virNetServerClient);
 
     return 0;
 }
diff --git a/src/rpc/virnetserverprogram.c b/src/rpc/virnetserverprogram.c
index f28274fc22..b93c8163f5 100644
--- a/src/rpc/virnetserverprogram.c
+++ b/src/rpc/virnetserverprogram.c
@@ -51,11 +51,8 @@ static void virNetServerProgramDispose(void *obj);
 
 static int virNetServerProgramOnceInit(void)
 {
-    if (!(virNetServerProgramClass = virClassNew(virClassForObject(),
-                                                 "virNetServerProgram",
-                                                 sizeof(virNetServerProgram),
-                                                 virNetServerProgramDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  virNetServerProgram);
 
     return 0;
 }
diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c
index d2350b2b91..1acecfb4f2 100644
--- a/src/rpc/virnetserverservice.c
+++ b/src/rpc/virnetserverservice.c
@@ -57,11 +57,8 @@ static void virNetServerServiceDispose(void *obj);
 
 static int virNetServerServiceOnceInit(void)
 {
-    if (!(virNetServerServiceClass = virClassNew(virClassForObject(),
-                                                 "virNetServerService",
-                                                 sizeof(virNetServerService),
-                                                 virNetServerServiceDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  virNetServerService);
 
     return 0;
 }
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index f362a09555..9f40bea34b 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -124,11 +124,8 @@ static void virNetSocketDispose(void *obj);
 
 static int virNetSocketOnceInit(void)
 {
-    if (!(virNetSocketClass = virClassNew(virClassForObjectLockable(),
-                                          "virNetSocket",
-                                          sizeof(virNetSocket),
-                                          virNetSocketDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virNetSocket);
 
     return 0;
 }
diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c
index e742175654..4bfeac9b5e 100644
--- a/src/rpc/virnetsshsession.c
+++ b/src/rpc/virnetsshsession.c
@@ -167,11 +167,8 @@ static virClassPtr virNetSSHSessionClass;
 static int
 virNetSSHSessionOnceInit(void)
 {
-    if (!(virNetSSHSessionClass = virClassNew(virClassForObjectLockable(),
-                                              "virNetSSHSession",
-                                              sizeof(virNetSSHSession),
-                                              virNetSSHSessionDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virNetSSHSession);
 
     return 0;
 }
diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c
index 5699eb8f24..6a2f539269 100644
--- a/src/rpc/virnettlscontext.c
+++ b/src/rpc/virnettlscontext.c
@@ -90,17 +90,11 @@ static void virNetTLSSessionDispose(void *obj);
 
 static int virNetTLSContextOnceInit(void)
 {
-    if (!(virNetTLSContextClass = virClassNew(virClassForObjectLockable(),
-                                              "virNetTLSContext",
-                                              sizeof(virNetTLSContext),
-                                              virNetTLSContextDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virNetTLSContext);
 
-    if (!(virNetTLSSessionClass = virClassNew(virClassForObjectLockable(),
-                                              "virNetTLSSession",
-                                              sizeof(virNetTLSSession),
-                                              virNetTLSSessionDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virNetTLSSession);
 
     return 0;
 }
diff --git a/src/security/security_manager.c b/src/security/security_manager.c
index fdeea4d533..ee5ba78703 100644
--- a/src/security/security_manager.c
+++ b/src/security/security_manager.c
@@ -59,11 +59,8 @@ void virSecurityManagerDispose(void *obj)
 static int
 virSecurityManagerOnceInit(void)
 {
-    if (!(virSecurityManagerClass = virClassNew(virClassForObjectLockable(),
-                                                "virSecurityManagerClass",
-                                                sizeof(virSecurityManager),
-                                                virSecurityManagerDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virSecurityManager);
 
     return 0;
 }
diff --git a/src/util/virclosecallbacks.c b/src/util/virclosecallbacks.c
index 49dac65892..a69d2db1d7 100644
--- a/src/util/virclosecallbacks.c
+++ b/src/util/virclosecallbacks.c
@@ -53,15 +53,10 @@ static void virCloseCallbacksDispose(void *obj);
 
 static int virCloseCallbacksOnceInit(void)
 {
-    virCloseCallbacksClass = virClassNew(virClassForObjectLockable(),
-                                         "virCloseCallbacks",
-                                         sizeof(virCloseCallbacks),
-                                         virCloseCallbacksDispose);
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virCloseCallbacks);
 
-    if (!virCloseCallbacksClass)
-        return -1;
-    else
-        return 0;
+    return 0;
 }
 
 VIR_ONCE_GLOBAL_INIT(virCloseCallbacks)
diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c
index db5c51b6a2..836f0c537a 100644
--- a/src/util/virdnsmasq.c
+++ b/src/util/virdnsmasq.c
@@ -641,12 +641,8 @@ dnsmasqCapsDispose(void *obj)
 
 static int dnsmasqCapsOnceInit(void)
 {
-    if (!(dnsmasqCapsClass = virClassNew(virClassForObject(),
-                                         "dnsmasqCaps",
-                                         sizeof(dnsmasqCaps),
-                                         dnsmasqCapsDispose))) {
-        return -1;
-    }
+    VIR_CLASS_NEW(virClassForObject(),
+                  dnsmasqCaps);
 
     return 0;
 }
diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c
index be40379a92..0bac2d564b 100644
--- a/src/util/virfdstream.c
+++ b/src/util/virfdstream.c
@@ -129,11 +129,8 @@ virFDStreamDataDispose(void *obj)
 
 static int virFDStreamDataOnceInit(void)
 {
-    if (!(virFDStreamDataClass = virClassNew(virClassForObjectLockable(),
-                                             "virFDStreamData",
-                                             sizeof(virFDStreamData),
-                                             virFDStreamDataDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virFDStreamData);
 
     return 0;
 }
diff --git a/src/util/virfilecache.c b/src/util/virfilecache.c
index e24eb5a68c..28e7b10ad5 100644
--- a/src/util/virfilecache.c
+++ b/src/util/virfilecache.c
@@ -86,11 +86,8 @@ virFileCacheDispose(void *obj)
 static int
 virFileCacheOnceInit(void)
 {
-    if (!(virFileCacheClass = virClassNew(virClassForObjectLockable(),
-                                          "virFileCache",
-                                          sizeof(virFileCache),
-                                          virFileCacheDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virFileCache);
 
     return 0;
 }
diff --git a/src/util/virhash.c b/src/util/virhash.c
index 475c2b0281..75f89d3801 100644
--- a/src/util/virhash.c
+++ b/src/util/virhash.c
@@ -77,15 +77,11 @@ static void virHashAtomicDispose(void *obj);
 
 static int virHashAtomicOnceInit(void)
 {
-    virHashAtomicClass = virClassNew(virClassForObjectLockable(),
-                                     "virHashAtomic",
-                                     sizeof(virHashAtomic),
-                                     virHashAtomicDispose);
-    if (!virHashAtomicClass)
-        return -1;
-    else
-        return 0;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virHashAtomic);
+    return 0;
 }
+
 VIR_ONCE_GLOBAL_INIT(virHashAtomic)
 
 
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index a12224c58f..09400858e0 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -120,11 +120,8 @@ static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddressPtr devAddr, void *o
 
 static int virHostdevManagerOnceInit(void)
 {
-    if (!(virHostdevManagerClass = virClassNew(virClassForObject(),
-                                               "virHostdevManager",
-                                               sizeof(virHostdevManager),
-                                               virHostdevManagerDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  virHostdevManager);
 
     if (!(manager = virHostdevManagerNew()))
         return -1;
diff --git a/src/util/viridentity.c b/src/util/viridentity.c
index 52a0a30a45..ae2c22799b 100644
--- a/src/util/viridentity.c
+++ b/src/util/viridentity.c
@@ -54,11 +54,8 @@ static void virIdentityDispose(void *obj);
 
 static int virIdentityOnceInit(void)
 {
-    if (!(virIdentityClass = virClassNew(virClassForObject(),
-                                         "virIdentity",
-                                         sizeof(virIdentity),
-                                         virIdentityDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  virIdentity);
 
     if (virThreadLocalInit(&virIdentityCurrent,
                            (virThreadLocalCleanup)virObjectUnref) < 0) {
diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c
index 42890ba2ff..311638c536 100644
--- a/src/util/virmacmap.c
+++ b/src/util/virmacmap.c
@@ -74,11 +74,8 @@ virMacMapDispose(void *obj)
 
 static int virMacMapOnceInit(void)
 {
-    if (!(virMacMapClass = virClassNew(virClassForObjectLockable(),
-                                       "virMacMapClass",
-                                       sizeof(virMacMap),
-                                       virMacMapDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virMacMap);
 
     return 0;
 }
diff --git a/src/util/virmdev.c b/src/util/virmdev.c
index 27541cf34f..d7e2328d0d 100644
--- a/src/util/virmdev.c
+++ b/src/util/virmdev.c
@@ -58,11 +58,8 @@ virMediatedDeviceListDispose(void *obj);
 static int
 virMediatedOnceInit(void)
 {
-    if (!(virMediatedDeviceListClass = virClassNew(virClassForObjectLockable(),
-                                                   "virMediatedDeviceList",
-                                                   sizeof(virMediatedDeviceList),
-                                                   virMediatedDeviceListDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virMediatedDeviceList);
 
     return 0;
 }
diff --git a/src/util/virobject.c b/src/util/virobject.c
index 1723df6b2f..c64c400556 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -81,17 +81,11 @@ virObjectOnceInit(void)
                                        NULL)))
         return -1;
 
-    if (!(virObjectLockableClass = virClassNew(virObjectClass,
-                                               "virObjectLockable",
-                                               sizeof(virObjectLockable),
-                                               virObjectLockableDispose)))
-        return -1;
+    VIR_CLASS_NEW(virObjectClass,
+                  virObjectLockable);
 
-    if (!(virObjectRWLockableClass = virClassNew(virObjectClass,
-                                                 "virObjectRWLockable",
-                                                 sizeof(virObjectRWLockable),
-                                                 virObjectRWLockableDispose)))
-        return -1;
+    VIR_CLASS_NEW(virObjectClass,
+                  virObjectRWLockable);
 
     return 0;
 }
diff --git a/src/util/virobject.h b/src/util/virobject.h
index ac6cf22f9e..128d3ba2d2 100644
--- a/src/util/virobject.h
+++ b/src/util/virobject.h
@@ -74,6 +74,15 @@ virClassPtr virClassForObjectRWLockable(void);
 # ifndef VIR_PARENT_REQUIRED
 #  define VIR_PARENT_REQUIRED ATTRIBUTE_NONNULL(1)
 # endif
+
+# define VIR_CLASS_NEW(prnt, name) \
+    if (!(name##Class = virClassNew(prnt, #name, sizeof(name), name##Dispose))) \
+        return -1;
+
+# define VIR_CLASS_NEW_GOTO(prnt, name, label) \
+    if (!(name##Class = virClassNew(prnt, #name, sizeof(name), name##Dispose))) \
+        goto label;
+
 virClassPtr
 virClassNew(virClassPtr parent,
             const char *name,
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 55e4c3e492..0268e4bf23 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -204,11 +204,8 @@ static void virPCIDeviceListDispose(void *obj);
 
 static int virPCIOnceInit(void)
 {
-    if (!(virPCIDeviceListClass = virClassNew(virClassForObjectLockable(),
-                                              "virPCIDeviceList",
-                                              sizeof(virPCIDeviceList),
-                                              virPCIDeviceListDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virPCIDeviceList);
 
     return 0;
 }
diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c
index 25200fbbb2..33f7919c2c 100644
--- a/src/util/virportallocator.c
+++ b/src/util/virportallocator.c
@@ -80,11 +80,8 @@ virPortAllocatorNew(void)
 static int
 virPortAllocatorOnceInit(void)
 {
-    if (!(virPortAllocatorClass = virClassNew(virClassForObjectLockable(),
-                                              "virPortAllocator",
-                                              sizeof(virPortAllocator),
-                                              virPortAllocatorDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virPortAllocator);
 
     if (!(virPortAllocatorInstance = virPortAllocatorNew()))
         return -1;
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index 9639e00468..784e7d0b8b 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -133,11 +133,8 @@ virResctrlInfoDispose(void *obj)
 static int
 virResctrlInfoOnceInit(void)
 {
-    if (!(virResctrlInfoClass = virClassNew(virClassForObject(),
-                                            "virResctrlInfo",
-                                            sizeof(virResctrlInfo),
-                                            virResctrlInfoDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  virResctrlInfo);
 
     return 0;
 }
@@ -271,11 +268,8 @@ virResctrlAllocDispose(void *obj)
 static int
 virResctrlAllocOnceInit(void)
 {
-    if (!(virResctrlAllocClass = virClassNew(virClassForObject(),
-                                             "virResctrlAlloc",
-                                             sizeof(virResctrlAlloc),
-                                             virResctrlAllocDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  virResctrlAlloc);
 
     return 0;
 }
diff --git a/src/util/virscsi.c b/src/util/virscsi.c
index 22f2677a3f..8a80ff6839 100644
--- a/src/util/virscsi.c
+++ b/src/util/virscsi.c
@@ -85,11 +85,8 @@ static void virSCSIDeviceListDispose(void *obj);
 static int
 virSCSIOnceInit(void)
 {
-    if (!(virSCSIDeviceListClass = virClassNew(virClassForObjectLockable(),
-                                               "virSCSIDeviceList",
-                                               sizeof(virSCSIDeviceList),
-                                               virSCSIDeviceListDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virSCSIDeviceList);
 
     return 0;
 }
diff --git a/src/util/virscsivhost.c b/src/util/virscsivhost.c
index 5f176e177f..fd078dbaa3 100644
--- a/src/util/virscsivhost.c
+++ b/src/util/virscsivhost.c
@@ -70,11 +70,8 @@ virSCSIVHostDeviceListDispose(void *obj)
 static int
 virSCSIVHostOnceInit(void)
 {
-    if (!(virSCSIVHostDeviceListClass = virClassNew(virClassForObjectLockable(),
-                                                    "virSCSIVHostDeviceList",
-                                                    sizeof(virSCSIVHostDeviceList),
-                                                    virSCSIVHostDeviceListDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virSCSIVHostDeviceList);
 
     return 0;
 }
diff --git a/src/util/virusb.c b/src/util/virusb.c
index be7be5dc18..a1792b8fe3 100644
--- a/src/util/virusb.c
+++ b/src/util/virusb.c
@@ -80,11 +80,8 @@ static void virUSBDeviceListDispose(void *obj);
 
 static int virUSBOnceInit(void)
 {
-    if (!(virUSBDeviceListClass = virClassNew(virClassForObjectLockable(),
-                                              "virUSBDeviceList",
-                                              sizeof(virUSBDeviceList),
-                                              virUSBDeviceListDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  virUSBDeviceList);
 
     return 0;
 }
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 920af4c010..7121999259 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -118,11 +118,8 @@ vboxDriverDispose(void *obj)
 static int
 vboxDriverOnceInit(void)
 {
-    if (!(vboxDriverClass = virClassNew(virClassForObjectLockable(),
-                                        "vboxDriver",
-                                        sizeof(vboxDriver),
-                                        vboxDriverDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  vboxDriver);
 
     return 0;
 }
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index e51d968f28..1519c751dc 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -161,11 +161,8 @@ static void vzDriverDispose(void * obj)
 
 static int vzDriverOnceInit(void)
 {
-    if (!(vzDriverClass = virClassNew(virClassForObjectLockable(),
-                                      "vzDriver",
-                                      sizeof(vzDriver),
-                                      vzDriverDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObjectLockable(),
+                  vzDriver);
 
     return 0;
 }
diff --git a/tests/virfilecachetest.c b/tests/virfilecachetest.c
index d4a9d598ef..7d41182939 100644
--- a/tests/virfilecachetest.c
+++ b/tests/virfilecachetest.c
@@ -49,11 +49,8 @@ testFileCacheObjDispose(void *opaque)
 static int
 testFileCacheObjOnceInit(void)
 {
-    if (!(testFileCacheObjClass = virClassNew(virClassForObject(),
-                                              "testFileCacheObj",
-                                              sizeof(testFileCacheObj),
-                                              testFileCacheObjDispose)))
-        return -1;
+    VIR_CLASS_NEW(virClassForObject(),
+                  testFileCacheObj);
 
     return 0;
 }
-- 
2.16.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux