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: if (!(VIR_CLASS_NEW(virSomeObject, virClassForObject))) return -1; Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/access/viraccessmanager.c | 5 +- src/bhyve/bhyve_conf.c | 5 +- src/conf/capabilities.c | 5 +- src/conf/domain_capabilities.c | 11 +-- src/conf/domain_conf.c | 20 +--- src/conf/domain_event.c | 166 ++++++++------------------------ src/conf/network_event.c | 14 +-- src/conf/node_device_event.c | 21 ++-- src/conf/object_event.c | 12 +-- src/conf/secret_event.c | 21 ++-- src/conf/storage_event.c | 21 ++-- src/conf/virdomainobjlist.c | 5 +- src/conf/virinterfaceobj.c | 10 +- src/conf/virnetworkobj.c | 11 +-- src/conf/virnodedeviceobj.c | 10 +- src/conf/virsecretobj.c | 10 +- src/conf/virstorageobj.c | 20 +--- src/datatypes.c | 5 +- src/interface/interface_backend_netcf.c | 6 +- src/libvirt-admin.c | 5 +- src/libxl/libxl_conf.c | 5 +- src/libxl/libxl_domain.c | 5 +- src/libxl/libxl_migration.c | 5 +- src/logging/log_handler.c | 5 +- src/lxc/lxc_conf.c | 5 +- src/lxc/lxc_monitor.c | 5 +- src/node_device/node_device_udev.c | 5 +- src/qemu/qemu_agent.c | 5 +- src/qemu/qemu_capabilities.c | 5 +- src/qemu/qemu_conf.c | 11 +-- src/qemu/qemu_domain.c | 51 +++------- src/qemu/qemu_monitor.c | 5 +- src/rpc/virkeepalive.c | 5 +- src/rpc/virnetclient.c | 5 +- src/rpc/virnetclientprogram.c | 5 +- src/rpc/virnetclientstream.c | 5 +- src/rpc/virnetdaemon.c | 5 +- src/rpc/virnetlibsshsession.c | 5 +- src/rpc/virnetsaslcontext.c | 10 +- src/rpc/virnetserver.c | 5 +- src/rpc/virnetserverclient.c | 5 +- src/rpc/virnetserverprogram.c | 5 +- src/rpc/virnetserverservice.c | 5 +- src/rpc/virnetsocket.c | 5 +- src/rpc/virnetsshsession.c | 5 +- src/rpc/virnettlscontext.c | 10 +- src/security/security_manager.c | 5 +- src/util/virclosecallbacks.c | 11 +-- src/util/virdnsmasq.c | 6 +- src/util/virfdstream.c | 5 +- src/util/virfilecache.c | 5 +- src/util/virhash.c | 11 +-- src/util/virhostdev.c | 5 +- src/util/viridentity.c | 5 +- src/util/virmacmap.c | 5 +- src/util/virmdev.c | 5 +- src/util/virobject.c | 10 +- src/util/virobject.h | 4 + src/util/virpci.c | 5 +- src/util/virportallocator.c | 5 +- src/util/virresctrl.c | 10 +- src/util/virscsi.c | 5 +- src/util/virscsivhost.c | 5 +- src/util/virusb.c | 5 +- src/vbox/vbox_common.c | 5 +- src/vz/vz_driver.c | 5 +- tests/virfilecachetest.c | 5 +- 67 files changed, 167 insertions(+), 535 deletions(-) diff --git a/src/access/viraccessmanager.c b/src/access/viraccessmanager.c index c268ec57f7..b048a367e3 100644 --- a/src/access/viraccessmanager.c +++ b/src/access/viraccessmanager.c @@ -54,10 +54,7 @@ static void virAccessManagerDispose(void *obj); static int virAccessManagerOnceInit(void) { - if (!(virAccessManagerClass = virClassNew(virClassForObjectLockable(), - "virAccessManagerClass", - sizeof(virAccessManager), - virAccessManagerDispose))) + if (!VIR_CLASS_NEW(virAccessManager, virClassForObjectLockable())) return -1; return 0; diff --git a/src/bhyve/bhyve_conf.c b/src/bhyve/bhyve_conf.c index b0b40c5754..153de7b391 100644 --- a/src/bhyve/bhyve_conf.c +++ b/src/bhyve/bhyve_conf.c @@ -36,10 +36,7 @@ static void virBhyveDriverConfigDispose(void *obj); static int virBhyveConfigOnceInit(void) { - if (!(virBhyveDriverConfigClass = virClassNew(virClassForObject(), - "virBhyveDriverConfig", - sizeof(virBhyveDriverConfig), - virBhyveDriverConfigDispose))) + if (!VIR_CLASS_NEW(virBhyveDriverConfig, virClassForObject())) return -1; return 0; diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 33b9194041..c4ee7efb5f 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -62,10 +62,7 @@ static void virCapsDispose(void *obj); static int virCapabilitiesOnceInit(void) { - if (!(virCapsClass = virClassNew(virClassForObject(), - "virCaps", - sizeof(virCaps), - virCapsDispose))) + if (!VIR_CLASS_NEW(virCaps, virClassForObject())) return -1; return 0; diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c index f7d9be50f8..bebbaf44d0 100644 --- a/src/conf/domain_capabilities.c +++ b/src/conf/domain_capabilities.c @@ -40,17 +40,10 @@ static void virDomainCapsCPUModelsDispose(void *obj); static int virDomainCapsOnceInit(void) { - if (!(virDomainCapsClass = virClassNew(virClassForObjectLockable(), - "virDomainCapsClass", - sizeof(virDomainCaps), - virDomainCapsDispose))) + if (!VIR_CLASS_NEW(virDomainCaps, virClassForObjectLockable())) return -1; - virDomainCapsCPUModelsClass = virClassNew(virClassForObject(), - "virDomainCapsCPUModelsClass", - sizeof(virDomainCapsCPUModels), - virDomainCapsCPUModelsDispose); - if (!virDomainCapsCPUModelsClass) + if (!VIR_CLASS_NEW(virDomainCapsCPUModels, virClassForObject())) return -1; return 0; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4dad8e3b20..e2345bba17 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -938,16 +938,10 @@ static void virDomainXMLOptionDispose(void *obj); static int virDomainObjOnceInit(void) { - if (!(virDomainObjClass = virClassNew(virClassForObjectLockable(), - "virDomainObj", - sizeof(virDomainObj), - virDomainObjDispose))) + if (!VIR_CLASS_NEW(virDomainObj, virClassForObjectLockable())) return -1; - if (!(virDomainXMLOptionClass = virClassNew(virClassForObject(), - "virDomainXMLOption", - sizeof(virDomainXMLOption), - virDomainXMLOptionDispose))) + if (!VIR_CLASS_NEW(virDomainXMLOption, virClassForObject())) return -1; return 0; @@ -12223,14 +12217,10 @@ static virClassPtr virDomainChrSourceDefClass; static int virDomainChrSourceDefOnceInit(void) { - virDomainChrSourceDefClass = virClassNew(virClassForObject(), - "virDomainChrSourceDef", - sizeof(virDomainChrSourceDef), - virDomainChrSourceDefDispose); - if (!virDomainChrSourceDefClass) + if (!VIR_CLASS_NEW(virDomainChrSourceDef, virClassForObject())) return -1; - else - return 0; + + return 0; } VIR_ONCE_GLOBAL_INIT(virDomainChrSourceDef); diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index fdb48a1eaa..97520706c9 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -295,131 +295,47 @@ 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))) + if (!VIR_CLASS_NEW(virDomainEvent, virClassForObjectEvent())) + return -1; + if (!VIR_CLASS_NEW(virDomainEventLifecycle, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventRTCChange, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventWatchdog, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventIOError, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventGraphics, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventBlockJob, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventDiskChange, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventTrayChange, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventBalloonChange, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventDeviceRemoved, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventDeviceAdded, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventPM, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainQemuMonitorEvent, virClassForObjectEvent())) + return -1; + if (!VIR_CLASS_NEW(virDomainEventTunable, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventAgentLifecycle, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventMigrationIteration, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventJobCompleted, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventDeviceRemovalFailed, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventMetadataChange, virDomainEventClass)) + return -1; + if (!VIR_CLASS_NEW(virDomainEventBlockThreshold, virDomainEventClass)) return -1; return 0; } diff --git a/src/conf/network_event.c b/src/conf/network_event.c index e0d1a3d5ca..5f8ad30d26 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))) + if (!VIR_CLASS_NEW(virNetworkEvent, virClassForObjectEvent())) return -1; - if (!(virNetworkEventLifecycleClass = - virClassNew(virNetworkEventClass, - "virNetworkEventLifecycle", - sizeof(virNetworkEventLifecycle), - virNetworkEventLifecycleDispose))) + + if (!VIR_CLASS_NEW(virNetworkEventLifecycle, virNetworkEventClass)) return -1; + return 0; } diff --git a/src/conf/node_device_event.c b/src/conf/node_device_event.c index 312ef512d1..e85bcbba0d 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))) + if (!VIR_CLASS_NEW(virNodeDeviceEvent, virClassForObjectEvent())) return -1; - if (!(virNodeDeviceEventLifecycleClass = - virClassNew(virNodeDeviceEventClass, - "virNodeDeviceEventLifecycle", - sizeof(virNodeDeviceEventLifecycle), - virNodeDeviceEventLifecycleDispose))) + + if (!VIR_CLASS_NEW(virNodeDeviceEventLifecycle, virNodeDeviceEventClass)) return -1; - if (!(virNodeDeviceEventUpdateClass = - virClassNew(virNodeDeviceEventClass, - "virNodeDeviceEventUpdate", - sizeof(virNodeDeviceEventUpdate), - virNodeDeviceEventUpdateDispose))) + + if (!VIR_CLASS_NEW(virNodeDeviceEventUpdate, virNodeDeviceEventClass)) return -1; + return 0; } diff --git a/src/conf/object_event.c b/src/conf/object_event.c index e8116b880c..9a7e7e50c1 100644 --- a/src/conf/object_event.c +++ b/src/conf/object_event.c @@ -92,18 +92,10 @@ static void virObjectEventStateDispose(void *obj); static int virObjectEventOnceInit(void) { - if (!(virObjectEventStateClass = - virClassNew(virClassForObjectLockable(), - "virObjectEventState", - sizeof(virObjectEventState), - virObjectEventStateDispose))) + if (!VIR_CLASS_NEW(virObjectEventState, virClassForObjectLockable())) return -1; - if (!(virObjectEventClass = - virClassNew(virClassForObject(), - "virObjectEvent", - sizeof(virObjectEvent), - virObjectEventDispose))) + if (!VIR_CLASS_NEW(virObjectEvent, virClassForObject())) return -1; return 0; diff --git a/src/conf/secret_event.c b/src/conf/secret_event.c index c130909282..3395aa128d 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))) + if (!VIR_CLASS_NEW(virSecretEvent, virClassForObjectEvent())) return -1; - if (!(virSecretEventLifecycleClass = - virClassNew(virSecretEventClass, - "virSecretEventLifecycle", - sizeof(virSecretEventLifecycle), - virSecretEventLifecycleDispose))) + + if (!VIR_CLASS_NEW(virSecretEventLifecycle, virSecretEventClass)) return -1; - if (!(virSecretEventValueChangedClass = - virClassNew(virSecretEventClass, - "virSecretEventValueChanged", - sizeof(virSecretEventValueChanged), - virSecretEventValueChangedDispose))) + + if (!VIR_CLASS_NEW(virSecretEventValueChanged, virSecretEventClass)) return -1; + return 0; } diff --git a/src/conf/storage_event.c b/src/conf/storage_event.c index f9b796878a..32a12eb63f 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))) + if (!VIR_CLASS_NEW(virStoragePoolEvent, virClassForObjectEvent())) return -1; - if (!(virStoragePoolEventLifecycleClass = - virClassNew(virStoragePoolEventClass, - "virStoragePoolEventLifecycle", - sizeof(virStoragePoolEventLifecycle), - virStoragePoolEventLifecycleDispose))) + + if (!VIR_CLASS_NEW(virStoragePoolEventLifecycle, virStoragePoolEventClass)) return -1; - if (!(virStoragePoolEventRefreshClass = - virClassNew(virStoragePoolEventClass, - "virStoragePoolEventRefresh", - sizeof(virStoragePoolEventRefresh), - virStoragePoolEventRefreshDispose))) + + if (!VIR_CLASS_NEW(virStoragePoolEventRefresh, virStoragePoolEventClass)) return -1; + return 0; } diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index 7022abe094..c09e5e5d2f 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -56,10 +56,7 @@ struct _virDomainObjList { static int virDomainObjListOnceInit(void) { - if (!(virDomainObjListClass = virClassNew(virClassForObjectRWLockable(), - "virDomainObjList", - sizeof(virDomainObjList), - virDomainObjListDispose))) + if (!VIR_CLASS_NEW(virDomainObjList, virClassForObjectRWLockable())) return -1; return 0; diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index f90c0bd9c4..a1d7346eb2 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -58,16 +58,10 @@ static void virInterfaceObjListDispose(void *obj); static int virInterfaceObjOnceInit(void) { - if (!(virInterfaceObjClass = virClassNew(virClassForObjectLockable(), - "virInterfaceObj", - sizeof(virInterfaceObj), - virInterfaceObjDispose))) + if (!VIR_CLASS_NEW(virInterfaceObj, virClassForObjectLockable())) return -1; - if (!(virInterfaceObjListClass = virClassNew(virClassForObjectRWLockable(), - "virInterfaceObjList", - sizeof(virInterfaceObjList), - virInterfaceObjListDispose))) + if (!VIR_CLASS_NEW(virInterfaceObjList, virClassForObjectRWLockable())) return -1; return 0; diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index 8cd1b62c1c..e00c8a7f6c 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -74,17 +74,12 @@ static void virNetworkObjListDispose(void *obj); static int virNetworkObjOnceInit(void) { - if (!(virNetworkObjClass = virClassNew(virClassForObjectLockable(), - "virNetworkObj", - sizeof(virNetworkObj), - virNetworkObjDispose))) + if (!VIR_CLASS_NEW(virNetworkObj, virClassForObjectLockable())) return -1; - if (!(virNetworkObjListClass = virClassNew(virClassForObjectRWLockable(), - "virNetworkObjList", - sizeof(virNetworkObjList), - virNetworkObjListDispose))) + if (!VIR_CLASS_NEW(virNetworkObjList, virClassForObjectRWLockable())) return -1; + return 0; } diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 9d2996046f..13e9a17518 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -58,16 +58,10 @@ static bool virNodeDeviceObjHasCap(const virNodeDeviceObj *obj, int type); static int virNodeDeviceObjOnceInit(void) { - if (!(virNodeDeviceObjClass = virClassNew(virClassForObjectLockable(), - "virNodeDeviceObj", - sizeof(virNodeDeviceObj), - virNodeDeviceObjDispose))) + if (!VIR_CLASS_NEW(virNodeDeviceObj, virClassForObjectLockable())) return -1; - if (!(virNodeDeviceObjListClass = virClassNew(virClassForObjectRWLockable(), - "virNodeDeviceObjList", - sizeof(virNodeDeviceObjList), - virNodeDeviceObjListDispose))) + if (!VIR_CLASS_NEW(virNodeDeviceObjList, virClassForObjectRWLockable())) return -1; return 0; diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 47e0b28968..48ce3c8141 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -68,16 +68,10 @@ struct virSecretSearchData { static int virSecretObjOnceInit(void) { - if (!(virSecretObjClass = virClassNew(virClassForObjectLockable(), - "virSecretObj", - sizeof(virSecretObj), - virSecretObjDispose))) + if (!VIR_CLASS_NEW(virSecretObj, virClassForObjectLockable())) return -1; - if (!(virSecretObjListClass = virClassNew(virClassForObjectRWLockable(), - "virSecretObjList", - sizeof(virSecretObjList), - virSecretObjListDispose))) + if (!VIR_CLASS_NEW(virSecretObjList, virClassForObjectRWLockable())) return -1; return 0; diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 799b8c9fa3..6c937f105c 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -110,16 +110,10 @@ struct _virStoragePoolObjList { static int virStorageVolObjOnceInit(void) { - if (!(virStorageVolObjClass = virClassNew(virClassForObjectLockable(), - "virStorageVolObj", - sizeof(virStorageVolObj), - virStorageVolObjDispose))) + if (!VIR_CLASS_NEW(virStorageVolObj, virClassForObjectLockable())) return -1; - if (!(virStorageVolObjListClass = virClassNew(virClassForObjectRWLockable(), - "virStorageVolObjList", - sizeof(virStorageVolObjList), - virStorageVolObjListDispose))) + if (!VIR_CLASS_NEW(virStorageVolObjList, virClassForObjectRWLockable())) return -1; return 0; @@ -207,16 +201,10 @@ virStorageVolObjListDispose(void *opaque) static int virStoragePoolObjOnceInit(void) { - if (!(virStoragePoolObjClass = virClassNew(virClassForObjectLockable(), - "virStoragePoolObj", - sizeof(virStoragePoolObj), - virStoragePoolObjDispose))) + if (!VIR_CLASS_NEW(virStoragePoolObj, virClassForObjectLockable())) return -1; - if (!(virStoragePoolObjListClass = virClassNew(virClassForObjectRWLockable(), - "virStoragePoolObjList", - sizeof(virStoragePoolObjList), - virStoragePoolObjListDispose))) + if (!VIR_CLASS_NEW(virStoragePoolObjList, virClassForObjectRWLockable())) return -1; return 0; diff --git a/src/datatypes.c b/src/datatypes.c index 0c3c66a9ce..09b8eea5a2 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -74,10 +74,7 @@ static int virDataTypesOnceInit(void) { #define DECLARE_CLASS_COMMON(basename, parent) \ - if (!(basename ## Class = virClassNew(parent, \ - #basename, \ - sizeof(basename), \ - basename ## Dispose))) \ + if (!(VIR_CLASS_NEW(basename, parent))) \ return -1; #define DECLARE_CLASS(basename) \ DECLARE_CLASS_COMMON(basename, virClassForObject()) diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c index cc2402febb..8ca7f9012e 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))) + if (!VIR_CLASS_NEW(virNetcfDriverState, virClassForObjectLockable())) return -1; + return 0; } diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c index 7f695311b4..a1a0d567a6 100644 --- a/src/libvirt-admin.c +++ b/src/libvirt-admin.c @@ -67,10 +67,7 @@ virAdmGlobalInit(void) if (!bindtextdomain(PACKAGE, LOCALEDIR)) goto error; - if (!(remoteAdminPrivClass = virClassNew(virClassForObjectLockable(), - "remoteAdminPriv", - sizeof(remoteAdminPriv), - remoteAdminPrivDispose))) + if (!VIR_CLASS_NEW(remoteAdminPriv, virClassForObjectLockable())) goto error; return; diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index df1cece82f..9229057f25 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -62,10 +62,7 @@ static void libxlDriverConfigDispose(void *obj); static int libxlConfigOnceInit(void) { - if (!(libxlDriverConfigClass = virClassNew(virClassForObject(), - "libxlDriverConfig", - sizeof(libxlDriverConfig), - libxlDriverConfigDispose))) + if (!VIR_CLASS_NEW(libxlDriverConfig, virClassForObject())) return -1; return 0; diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index ef9a902671..ee57938112 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -58,10 +58,7 @@ libxlDomainObjPrivateDispose(void *obj); static int libxlDomainObjPrivateOnceInit(void) { - if (!(libxlDomainObjPrivateClass = virClassNew(virClassForObjectLockable(), - "libxlDomainObjPrivate", - sizeof(libxlDomainObjPrivate), - libxlDomainObjPrivateDispose))) + if (!VIR_CLASS_NEW(libxlDomainObjPrivate, virClassForObjectLockable())) return -1; return 0; diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index 5c0fd4b052..d7b494b392 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -244,10 +244,7 @@ libxlMigrationDstArgsDispose(void *obj) static int libxlMigrationDstArgsOnceInit(void) { - if (!(libxlMigrationDstArgsClass = virClassNew(virClassForObject(), - "libxlMigrationDstArgs", - sizeof(libxlMigrationDstArgs), - libxlMigrationDstArgsDispose))) + if (!VIR_CLASS_NEW(libxlMigrationDstArgs, virClassForObject())) return -1; return 0; diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c index cd0ba6ec24..40dfa8ecae 100644 --- a/src/logging/log_handler.c +++ b/src/logging/log_handler.c @@ -76,10 +76,7 @@ static void virLogHandlerDispose(void *obj); static int virLogHandlerOnceInit(void) { - if (!(virLogHandlerClass = virClassNew(virClassForObjectLockable(), - "virLogHandler", - sizeof(virLogHandler), - virLogHandlerDispose))) + if (!VIR_CLASS_NEW(virLogHandler, virClassForObjectLockable())) return -1; return 0; diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index 92a82a4768..5cd6f231dd 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -48,10 +48,7 @@ static void virLXCDriverConfigDispose(void *obj); static int virLXCConfigOnceInit(void) { - if (!(virLXCDriverConfigClass = virClassNew(virClassForObject(), - "virLXCDriverConfig", - sizeof(virLXCDriverConfig), - virLXCDriverConfigDispose))) + if (!VIR_CLASS_NEW(virLXCDriverConfig, virClassForObject())) return -1; return 0; diff --git a/src/lxc/lxc_monitor.c b/src/lxc/lxc_monitor.c index 9cab6c2035..a569e41849 100644 --- a/src/lxc/lxc_monitor.c +++ b/src/lxc/lxc_monitor.c @@ -51,10 +51,7 @@ static void virLXCMonitorDispose(void *obj); static int virLXCMonitorOnceInit(void) { - if (!(virLXCMonitorClass = virClassNew(virClassForObjectLockable(), - "virLXCMonitor", - sizeof(virLXCMonitor), - virLXCMonitorDispose))) + if (!VIR_CLASS_NEW(virLXCMonitor, virClassForObjectLockable())) return -1; return 0; diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index de01816402..d34ec30379 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -93,10 +93,7 @@ udevEventDataDispose(void *obj) static int udevEventDataOnceInit(void) { - if (!(udevEventDataClass = virClassNew(virClassForObjectLockable(), - "udevEventData", - sizeof(udevEventData), - udevEventDataDispose))) + if (!VIR_CLASS_NEW(udevEventData, virClassForObjectLockable())) return -1; return 0; diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 85af53d194..488a19d4a6 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -138,10 +138,7 @@ static void qemuAgentDispose(void *obj); static int qemuAgentOnceInit(void) { - if (!(qemuAgentClass = virClassNew(virClassForObjectLockable(), - "qemuAgent", - sizeof(qemuAgent), - qemuAgentDispose))) + if (!VIR_CLASS_NEW(qemuAgent, virClassForObjectLockable())) return -1; return 0; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index c6defb773f..2de3d6207f 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -548,10 +548,7 @@ static void virQEMUCapsDispose(void *obj); static int virQEMUCapsOnceInit(void) { - if (!(virQEMUCapsClass = virClassNew(virClassForObject(), - "virQEMUCaps", - sizeof(virQEMUCaps), - virQEMUCapsDispose))) + if (!VIR_CLASS_NEW(virQEMUCaps, virClassForObject())) return -1; return 0; diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 36cf3a281c..bfbb572f01 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); - - if (!virQEMUDriverConfigClass) + if (!VIR_CLASS_NEW(virQEMUDriverConfig, virClassForObject())) 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 4c4a9a428d..e999351cd9 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -131,16 +131,10 @@ static void qemuDomainSaveCookieDispose(void *obj); static int qemuDomainOnceInit(void) { - if (!(qemuDomainLogContextClass = virClassNew(virClassForObject(), - "qemuDomainLogContext", - sizeof(qemuDomainLogContext), - qemuDomainLogContextDispose))) + if (!VIR_CLASS_NEW(qemuDomainLogContext, virClassForObject())) return -1; - if (!(qemuDomainSaveCookieClass = virClassNew(virClassForObject(), - "qemuDomainSaveCookie", - sizeof(qemuDomainSaveCookie), - qemuDomainSaveCookieDispose))) + if (!VIR_CLASS_NEW(qemuDomainSaveCookie, virClassForObject())) return -1; return 0; @@ -992,14 +986,10 @@ static void qemuDomainDiskPrivateDispose(void *obj); static int qemuDomainDiskPrivateOnceInit(void) { - qemuDomainDiskPrivateClass = virClassNew(virClassForObject(), - "qemuDomainDiskPrivate", - sizeof(qemuDomainDiskPrivate), - qemuDomainDiskPrivateDispose); - if (!qemuDomainDiskPrivateClass) + if (!VIR_CLASS_NEW(qemuDomainDiskPrivate, virClassForObject())) return -1; - else - return 0; + + return 0; } VIR_ONCE_GLOBAL_INIT(qemuDomainDiskPrivate) @@ -1032,14 +1022,10 @@ static void qemuDomainStorageSourcePrivateDispose(void *obj); static int qemuDomainStorageSourcePrivateOnceInit(void) { - qemuDomainStorageSourcePrivateClass = virClassNew(virClassForObject(), - "qemuDomainStorageSourcePrivate", - sizeof(qemuDomainStorageSourcePrivate), - qemuDomainStorageSourcePrivateDispose); - if (!qemuDomainStorageSourcePrivateClass) + if (!VIR_CLASS_NEW(qemuDomainStorageSourcePrivate, virClassForObject())) return -1; - else - return 0; + + return 0; } VIR_ONCE_GLOBAL_INIT(qemuDomainStorageSourcePrivate) @@ -1075,14 +1061,10 @@ static void qemuDomainVcpuPrivateDispose(void *obj); static int qemuDomainVcpuPrivateOnceInit(void) { - qemuDomainVcpuPrivateClass = virClassNew(virClassForObject(), - "qemuDomainVcpuPrivate", - sizeof(qemuDomainVcpuPrivate), - qemuDomainVcpuPrivateDispose); - if (!qemuDomainVcpuPrivateClass) + if (!VIR_CLASS_NEW(qemuDomainVcpuPrivate, virClassForObject())) return -1; - else - return 0; + + return 0; } VIR_ONCE_GLOBAL_INIT(qemuDomainVcpuPrivate) @@ -1119,15 +1101,10 @@ static void qemuDomainChrSourcePrivateDispose(void *obj); static int qemuDomainChrSourcePrivateOnceInit(void) { - qemuDomainChrSourcePrivateClass = - virClassNew(virClassForObject(), - "qemuDomainChrSourcePrivate", - sizeof(qemuDomainChrSourcePrivate), - qemuDomainChrSourcePrivateDispose); - if (!qemuDomainChrSourcePrivateClass) + if (!VIR_CLASS_NEW(qemuDomainChrSourcePrivate, virClassForObject())) return -1; - else - return 0; + + return 0; } VIR_ONCE_GLOBAL_INIT(qemuDomainChrSourcePrivate) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index eb5c8d70bb..143eb0fb68 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -165,10 +165,7 @@ static void qemuMonitorDispose(void *obj); static int qemuMonitorOnceInit(void) { - if (!(qemuMonitorClass = virClassNew(virClassForObjectLockable(), - "qemuMonitor", - sizeof(qemuMonitor), - qemuMonitorDispose))) + if (!VIR_CLASS_NEW(qemuMonitor, virClassForObjectLockable())) return -1; return 0; diff --git a/src/rpc/virkeepalive.c b/src/rpc/virkeepalive.c index 4f666fd09b..04bba82112 100644 --- a/src/rpc/virkeepalive.c +++ b/src/rpc/virkeepalive.c @@ -58,10 +58,7 @@ static void virKeepAliveDispose(void *obj); static int virKeepAliveOnceInit(void) { - if (!(virKeepAliveClass = virClassNew(virClassForObjectLockable(), - "virKeepAlive", - sizeof(virKeepAlive), - virKeepAliveDispose))) + if (!VIR_CLASS_NEW(virKeepAlive, virClassForObjectLockable())) return -1; return 0; diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 0c8d58c32c..6bbc984e48 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -120,10 +120,7 @@ static void virNetClientDispose(void *obj); static int virNetClientOnceInit(void) { - if (!(virNetClientClass = virClassNew(virClassForObjectLockable(), - "virNetClient", - sizeof(virNetClient), - virNetClientDispose))) + if (!VIR_CLASS_NEW(virNetClient, virClassForObjectLockable())) return -1; return 0; diff --git a/src/rpc/virnetclientprogram.c b/src/rpc/virnetclientprogram.c index d1e54a0892..0c7bcef39c 100644 --- a/src/rpc/virnetclientprogram.c +++ b/src/rpc/virnetclientprogram.c @@ -54,10 +54,7 @@ static void virNetClientProgramDispose(void *obj); static int virNetClientProgramOnceInit(void) { - if (!(virNetClientProgramClass = virClassNew(virClassForObject(), - "virNetClientProgram", - sizeof(virNetClientProgram), - virNetClientProgramDispose))) + if (!VIR_CLASS_NEW(virNetClientProgram, virClassForObject())) return -1; return 0; diff --git a/src/rpc/virnetclientstream.c b/src/rpc/virnetclientstream.c index 2f037db0dc..7b8b4e5c89 100644 --- a/src/rpc/virnetclientstream.c +++ b/src/rpc/virnetclientstream.c @@ -71,10 +71,7 @@ static void virNetClientStreamDispose(void *obj); static int virNetClientStreamOnceInit(void) { - if (!(virNetClientStreamClass = virClassNew(virClassForObjectLockable(), - "virNetClientStream", - sizeof(virNetClientStream), - virNetClientStreamDispose))) + if (!VIR_CLASS_NEW(virNetClientStream, virClassForObjectLockable())) return -1; return 0; diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 6f00bfd9d1..eb0b822545 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -110,10 +110,7 @@ virNetDaemonDispose(void *obj) static int virNetDaemonOnceInit(void) { - if (!(virNetDaemonClass = virClassNew(virClassForObjectLockable(), - "virNetDaemon", - sizeof(virNetDaemon), - virNetDaemonDispose))) + if (!VIR_CLASS_NEW(virNetDaemon, virClassForObjectLockable())) return -1; return 0; diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c index 25f93cec97..309e8a9340 100644 --- a/src/rpc/virnetlibsshsession.c +++ b/src/rpc/virnetlibsshsession.c @@ -161,10 +161,7 @@ virNetLibsshSessionOnceInit(void) { const char *dbgLevelStr; - if (!(virNetLibsshSessionClass = virClassNew(virClassForObjectLockable(), - "virNetLibsshSession", - sizeof(virNetLibsshSession), - virNetLibsshSessionDispose))) + if (!VIR_CLASS_NEW(virNetLibsshSession, virClassForObjectLockable())) return -1; if (ssh_init() < 0) { diff --git a/src/rpc/virnetsaslcontext.c b/src/rpc/virnetsaslcontext.c index 2b564d1736..b4db5c40c6 100644 --- a/src/rpc/virnetsaslcontext.c +++ b/src/rpc/virnetsaslcontext.c @@ -57,16 +57,10 @@ static void virNetSASLSessionDispose(void *obj); static int virNetSASLContextOnceInit(void) { - if (!(virNetSASLContextClass = virClassNew(virClassForObjectLockable(), - "virNetSASLContext", - sizeof(virNetSASLContext), - virNetSASLContextDispose))) + if (!VIR_CLASS_NEW(virNetSASLContext, virClassForObjectLockable())) return -1; - if (!(virNetSASLSessionClass = virClassNew(virClassForObjectLockable(), - "virNetSASLSession", - sizeof(virNetSASLSession), - virNetSASLSessionDispose))) + if (!VIR_CLASS_NEW(virNetSASLSession, virClassForObjectLockable())) return -1; return 0; diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index 3ce21a8f53..f4105b1394 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -93,10 +93,7 @@ static inline size_t virNetServerTrackCompletedAuthLocked(virNetServerPtr srv); static int virNetServerOnceInit(void) { - if (!(virNetServerClass = virClassNew(virClassForObjectLockable(), - "virNetServer", - sizeof(virNetServer), - virNetServerDispose))) + if (!VIR_CLASS_NEW(virNetServer, virClassForObjectLockable())) return -1; return 0; diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index d5f0cf448f..b373ca1a8b 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -129,10 +129,7 @@ static void virNetServerClientDispose(void *obj); static int virNetServerClientOnceInit(void) { - if (!(virNetServerClientClass = virClassNew(virClassForObjectLockable(), - "virNetServerClient", - sizeof(virNetServerClient), - virNetServerClientDispose))) + if (!VIR_CLASS_NEW(virNetServerClient, virClassForObjectLockable())) return -1; return 0; diff --git a/src/rpc/virnetserverprogram.c b/src/rpc/virnetserverprogram.c index f28274fc22..b04c36d3aa 100644 --- a/src/rpc/virnetserverprogram.c +++ b/src/rpc/virnetserverprogram.c @@ -51,10 +51,7 @@ static void virNetServerProgramDispose(void *obj); static int virNetServerProgramOnceInit(void) { - if (!(virNetServerProgramClass = virClassNew(virClassForObject(), - "virNetServerProgram", - sizeof(virNetServerProgram), - virNetServerProgramDispose))) + if (!VIR_CLASS_NEW(virNetServerProgram, virClassForObject())) return -1; return 0; diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index d2350b2b91..fb19d09dda 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -57,10 +57,7 @@ static void virNetServerServiceDispose(void *obj); static int virNetServerServiceOnceInit(void) { - if (!(virNetServerServiceClass = virClassNew(virClassForObject(), - "virNetServerService", - sizeof(virNetServerService), - virNetServerServiceDispose))) + if (!VIR_CLASS_NEW(virNetServerService, virClassForObject())) return -1; return 0; diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index f362a09555..f253eb2605 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -124,10 +124,7 @@ static void virNetSocketDispose(void *obj); static int virNetSocketOnceInit(void) { - if (!(virNetSocketClass = virClassNew(virClassForObjectLockable(), - "virNetSocket", - sizeof(virNetSocket), - virNetSocketDispose))) + if (!VIR_CLASS_NEW(virNetSocket, virClassForObjectLockable())) return -1; return 0; diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index e742175654..6566f36ce0 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -167,10 +167,7 @@ static virClassPtr virNetSSHSessionClass; static int virNetSSHSessionOnceInit(void) { - if (!(virNetSSHSessionClass = virClassNew(virClassForObjectLockable(), - "virNetSSHSession", - sizeof(virNetSSHSession), - virNetSSHSessionDispose))) + if (!VIR_CLASS_NEW(virNetSSHSession, virClassForObjectLockable())) return -1; return 0; diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c index 5699eb8f24..2c46aebf31 100644 --- a/src/rpc/virnettlscontext.c +++ b/src/rpc/virnettlscontext.c @@ -90,16 +90,10 @@ static void virNetTLSSessionDispose(void *obj); static int virNetTLSContextOnceInit(void) { - if (!(virNetTLSContextClass = virClassNew(virClassForObjectLockable(), - "virNetTLSContext", - sizeof(virNetTLSContext), - virNetTLSContextDispose))) + if (!VIR_CLASS_NEW(virNetTLSContext, virClassForObjectLockable())) return -1; - if (!(virNetTLSSessionClass = virClassNew(virClassForObjectLockable(), - "virNetTLSSession", - sizeof(virNetTLSSession), - virNetTLSSessionDispose))) + if (!VIR_CLASS_NEW(virNetTLSSession, virClassForObjectLockable())) return -1; return 0; diff --git a/src/security/security_manager.c b/src/security/security_manager.c index fdeea4d533..71f7f59b9c 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -59,10 +59,7 @@ void virSecurityManagerDispose(void *obj) static int virSecurityManagerOnceInit(void) { - if (!(virSecurityManagerClass = virClassNew(virClassForObjectLockable(), - "virSecurityManagerClass", - sizeof(virSecurityManager), - virSecurityManagerDispose))) + if (!VIR_CLASS_NEW(virSecurityManager, virClassForObjectLockable())) return -1; return 0; diff --git a/src/util/virclosecallbacks.c b/src/util/virclosecallbacks.c index 49dac65892..0a395eb167 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); - - if (!virCloseCallbacksClass) + if (!VIR_CLASS_NEW(virCloseCallbacks, virClassForObjectLockable())) 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..492dcadc96 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))) { + if (!VIR_CLASS_NEW(dnsmasqCaps, virClassForObject())) return -1; - } return 0; } diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c index be40379a92..e4973a2bd0 100644 --- a/src/util/virfdstream.c +++ b/src/util/virfdstream.c @@ -129,10 +129,7 @@ virFDStreamDataDispose(void *obj) static int virFDStreamDataOnceInit(void) { - if (!(virFDStreamDataClass = virClassNew(virClassForObjectLockable(), - "virFDStreamData", - sizeof(virFDStreamData), - virFDStreamDataDispose))) + if (!VIR_CLASS_NEW(virFDStreamData, virClassForObjectLockable())) return -1; return 0; diff --git a/src/util/virfilecache.c b/src/util/virfilecache.c index e24eb5a68c..dab72163dd 100644 --- a/src/util/virfilecache.c +++ b/src/util/virfilecache.c @@ -86,10 +86,7 @@ virFileCacheDispose(void *obj) static int virFileCacheOnceInit(void) { - if (!(virFileCacheClass = virClassNew(virClassForObjectLockable(), - "virFileCache", - sizeof(virFileCache), - virFileCacheDispose))) + if (!VIR_CLASS_NEW(virFileCache, virClassForObjectLockable())) return -1; return 0; diff --git a/src/util/virhash.c b/src/util/virhash.c index 475c2b0281..ecda55dba5 100644 --- a/src/util/virhash.c +++ b/src/util/virhash.c @@ -77,15 +77,12 @@ static void virHashAtomicDispose(void *obj); static int virHashAtomicOnceInit(void) { - virHashAtomicClass = virClassNew(virClassForObjectLockable(), - "virHashAtomic", - sizeof(virHashAtomic), - virHashAtomicDispose); - if (!virHashAtomicClass) + if (!VIR_CLASS_NEW(virHashAtomic, virClassForObjectLockable())) return -1; - else - return 0; + + return 0; } + VIR_ONCE_GLOBAL_INIT(virHashAtomic) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index a12224c58f..db10b7a204 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -120,10 +120,7 @@ static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddressPtr devAddr, void *o static int virHostdevManagerOnceInit(void) { - if (!(virHostdevManagerClass = virClassNew(virClassForObject(), - "virHostdevManager", - sizeof(virHostdevManager), - virHostdevManagerDispose))) + if (!VIR_CLASS_NEW(virHostdevManager, virClassForObject())) return -1; if (!(manager = virHostdevManagerNew())) diff --git a/src/util/viridentity.c b/src/util/viridentity.c index 52a0a30a45..2f4307bc82 100644 --- a/src/util/viridentity.c +++ b/src/util/viridentity.c @@ -54,10 +54,7 @@ static void virIdentityDispose(void *obj); static int virIdentityOnceInit(void) { - if (!(virIdentityClass = virClassNew(virClassForObject(), - "virIdentity", - sizeof(virIdentity), - virIdentityDispose))) + if (!VIR_CLASS_NEW(virIdentity, virClassForObject())) return -1; if (virThreadLocalInit(&virIdentityCurrent, diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c index 42890ba2ff..88ca9b3f36 100644 --- a/src/util/virmacmap.c +++ b/src/util/virmacmap.c @@ -74,10 +74,7 @@ virMacMapDispose(void *obj) static int virMacMapOnceInit(void) { - if (!(virMacMapClass = virClassNew(virClassForObjectLockable(), - "virMacMapClass", - sizeof(virMacMap), - virMacMapDispose))) + if (!VIR_CLASS_NEW(virMacMap, virClassForObjectLockable())) return -1; return 0; diff --git a/src/util/virmdev.c b/src/util/virmdev.c index 27541cf34f..536ddbeed2 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -58,10 +58,7 @@ virMediatedDeviceListDispose(void *obj); static int virMediatedOnceInit(void) { - if (!(virMediatedDeviceListClass = virClassNew(virClassForObjectLockable(), - "virMediatedDeviceList", - sizeof(virMediatedDeviceList), - virMediatedDeviceListDispose))) + if (!VIR_CLASS_NEW(virMediatedDeviceList, virClassForObjectLockable())) return -1; return 0; diff --git a/src/util/virobject.c b/src/util/virobject.c index 1723df6b2f..9fb0328d58 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -81,16 +81,10 @@ virObjectOnceInit(void) NULL))) return -1; - if (!(virObjectLockableClass = virClassNew(virObjectClass, - "virObjectLockable", - sizeof(virObjectLockable), - virObjectLockableDispose))) + if (!VIR_CLASS_NEW(virObjectLockable, virObjectClass)) return -1; - if (!(virObjectRWLockableClass = virClassNew(virObjectClass, - "virObjectRWLockable", - sizeof(virObjectRWLockable), - virObjectRWLockableDispose))) + if (!VIR_CLASS_NEW(virObjectRWLockable, virObjectClass)) return -1; return 0; diff --git a/src/util/virobject.h b/src/util/virobject.h index ac6cf22f9e..ed1a117b09 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -74,6 +74,10 @@ virClassPtr virClassForObjectRWLockable(void); # ifndef VIR_PARENT_REQUIRED # define VIR_PARENT_REQUIRED ATTRIBUTE_NONNULL(1) # endif + +# define VIR_CLASS_NEW(name, prnt) \ + (name##Class = virClassNew(prnt, #name, sizeof(name), name##Dispose)) + virClassPtr virClassNew(virClassPtr parent, const char *name, diff --git a/src/util/virpci.c b/src/util/virpci.c index 55e4c3e492..23932558e9 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -204,10 +204,7 @@ static void virPCIDeviceListDispose(void *obj); static int virPCIOnceInit(void) { - if (!(virPCIDeviceListClass = virClassNew(virClassForObjectLockable(), - "virPCIDeviceList", - sizeof(virPCIDeviceList), - virPCIDeviceListDispose))) + if (!VIR_CLASS_NEW(virPCIDeviceList, virClassForObjectLockable())) return -1; return 0; diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c index 25200fbbb2..004a2dab81 100644 --- a/src/util/virportallocator.c +++ b/src/util/virportallocator.c @@ -80,10 +80,7 @@ virPortAllocatorNew(void) static int virPortAllocatorOnceInit(void) { - if (!(virPortAllocatorClass = virClassNew(virClassForObjectLockable(), - "virPortAllocator", - sizeof(virPortAllocator), - virPortAllocatorDispose))) + if (!VIR_CLASS_NEW(virPortAllocator, virClassForObjectLockable())) return -1; if (!(virPortAllocatorInstance = virPortAllocatorNew())) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 9639e00468..fc1163508a 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -133,10 +133,7 @@ virResctrlInfoDispose(void *obj) static int virResctrlInfoOnceInit(void) { - if (!(virResctrlInfoClass = virClassNew(virClassForObject(), - "virResctrlInfo", - sizeof(virResctrlInfo), - virResctrlInfoDispose))) + if (!VIR_CLASS_NEW(virResctrlInfo, virClassForObject())) return -1; return 0; @@ -271,10 +268,7 @@ virResctrlAllocDispose(void *obj) static int virResctrlAllocOnceInit(void) { - if (!(virResctrlAllocClass = virClassNew(virClassForObject(), - "virResctrlAlloc", - sizeof(virResctrlAlloc), - virResctrlAllocDispose))) + if (!VIR_CLASS_NEW(virResctrlAlloc, virClassForObject())) return -1; return 0; diff --git a/src/util/virscsi.c b/src/util/virscsi.c index 22f2677a3f..b51103a86d 100644 --- a/src/util/virscsi.c +++ b/src/util/virscsi.c @@ -85,10 +85,7 @@ static void virSCSIDeviceListDispose(void *obj); static int virSCSIOnceInit(void) { - if (!(virSCSIDeviceListClass = virClassNew(virClassForObjectLockable(), - "virSCSIDeviceList", - sizeof(virSCSIDeviceList), - virSCSIDeviceListDispose))) + if (!VIR_CLASS_NEW(virSCSIDeviceList, virClassForObjectLockable())) return -1; return 0; diff --git a/src/util/virscsivhost.c b/src/util/virscsivhost.c index 5f176e177f..84c09e8458 100644 --- a/src/util/virscsivhost.c +++ b/src/util/virscsivhost.c @@ -70,10 +70,7 @@ virSCSIVHostDeviceListDispose(void *obj) static int virSCSIVHostOnceInit(void) { - if (!(virSCSIVHostDeviceListClass = virClassNew(virClassForObjectLockable(), - "virSCSIVHostDeviceList", - sizeof(virSCSIVHostDeviceList), - virSCSIVHostDeviceListDispose))) + if (!VIR_CLASS_NEW(virSCSIVHostDeviceList, virClassForObjectLockable())) return -1; return 0; diff --git a/src/util/virusb.c b/src/util/virusb.c index be7be5dc18..2fe1bfc290 100644 --- a/src/util/virusb.c +++ b/src/util/virusb.c @@ -80,10 +80,7 @@ static void virUSBDeviceListDispose(void *obj); static int virUSBOnceInit(void) { - if (!(virUSBDeviceListClass = virClassNew(virClassForObjectLockable(), - "virUSBDeviceList", - sizeof(virUSBDeviceList), - virUSBDeviceListDispose))) + if (!VIR_CLASS_NEW(virUSBDeviceList, virClassForObjectLockable())) return -1; return 0; diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 920af4c010..72a24a3464 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -118,10 +118,7 @@ vboxDriverDispose(void *obj) static int vboxDriverOnceInit(void) { - if (!(vboxDriverClass = virClassNew(virClassForObjectLockable(), - "vboxDriver", - sizeof(vboxDriver), - vboxDriverDispose))) + if (!VIR_CLASS_NEW(vboxDriver, virClassForObjectLockable())) return -1; return 0; diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index e51d968f28..2ff2018a43 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -161,10 +161,7 @@ static void vzDriverDispose(void * obj) static int vzDriverOnceInit(void) { - if (!(vzDriverClass = virClassNew(virClassForObjectLockable(), - "vzDriver", - sizeof(vzDriver), - vzDriverDispose))) + if (!VIR_CLASS_NEW(vzDriver, virClassForObjectLockable())) return -1; return 0; diff --git a/tests/virfilecachetest.c b/tests/virfilecachetest.c index d4a9d598ef..3c55cd1e02 100644 --- a/tests/virfilecachetest.c +++ b/tests/virfilecachetest.c @@ -49,10 +49,7 @@ testFileCacheObjDispose(void *opaque) static int testFileCacheObjOnceInit(void) { - if (!(testFileCacheObjClass = virClassNew(virClassForObject(), - "testFileCacheObj", - sizeof(testFileCacheObj), - testFileCacheObjDispose))) + if (!VIR_CLASS_NEW(testFileCacheObj, virClassForObject())) return -1; return 0; -- 2.16.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list