[libvirt] [PATCH 07/11] util: convert virIdentity class to use GObject

Ján Tomko jtomko at redhat.com
Mon Sep 30 13:04:38 UTC 2019


On Fri, Sep 27, 2019 at 06:17:29PM +0100, Daniel P. Berrangé wrote:
>Converting from virObject to GObject is reasonably straightforward,
>as illustrated by this patch for virIdentity
>

The change would be much easier to see if this patch did not contain
the g_autofree changes and the removal of cleanup/error labels, which
generate a lot of churn.

>In the header file
>
> - Remove
>
>     typedef struct _virIdentity virIdentity
>
> - Add
>
>     #define VIR_TYPE_IDENTITY virIdentity_get_type ()
>     G_DECLARE_FINAL_TYPE (virIdentity, virIdentity, VIR, IDENTITY, GObject);
>
>   Which provides the typedef we just removed, and class
>   declaration boilerplate and various other constants/macros.
>
>In the source file
>
> - Change 'virObject parent' to 'GObject parent' in the struct
> - Remove the virClass variable and its initializing call
> - Add
>
>      G_DEFINE_TYPE(virIdentity, virIdentity, G_TYPE_OBJECT)
>
>   which declares the instance & class constructor functions
>
> - Add an impl of the instance & class constructors
>   wiring up the finalize method to point to our dispose impl
>
>In all files
>
> - Replace VIR_AUTOUNREF(virIdentityPtr) with g_autoptr(virIdentity)
>

Is the idea to never mix VIR_ALLOC/VIR_AUTOFREE with g_alloc/g_auto*?
If not, this step could be separated by temporarily setting
virObjectUnref as the cleanup function for g_autoptr.

Jano

> - Replace virObjectRef/Unref with g_object_ref/unref. Note
>   the latter functions do *NOT* accept a NULL object where as
>   libvirt's do. If you replace g_object_unref with g_clear_object
>   it is NULL safe, but also clears the pointer.
>
>Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
>---
> src/access/viraccessdriverpolkit.c  | 21 +++----
> src/admin/admin_server.c            |  3 +-
> src/qemu/qemu_process.c             |  4 +-
> src/remote/remote_daemon.c          |  3 +-
> src/remote/remote_daemon_dispatch.c | 35 ++++--------
> src/rpc/virnetserverclient.c        | 57 ++++++++-----------
> src/rpc/virnetserverprogram.c       | 13 +----
> src/util/viridentity.c              | 87 ++++++++++++++++-------------
> src/util/viridentity.h              |  7 ++-
> tests/viridentitytest.c             | 45 ++++++---------
> tests/virnetserverclienttest.c      |  3 +-
> 11 files changed, 122 insertions(+), 156 deletions(-)
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190930/4c333328/attachment-0001.sig>


More information about the libvir-list mailing list