Re: [PATCH v2 15/23] util: convert virIdentity class to use GObject

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

 



On Mon, Oct 07, 2019 at 06:14:17PM +0100, Daniel P. Berrangé wrote:
Converting from virObject to GObject is reasonably straightforward,
as illustrated by this patch for virIdentity

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)

- 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@xxxxxxxxxx>
---
m4/virt-glib.m4              |  4 +--
src/qemu/qemu_process.c      |  4 +--
src/rpc/virnetserverclient.c | 10 +++----
src/util/viridentity.c       | 57 ++++++++++++++++++++++--------------
src/util/viridentity.h       |  9 +++---
tests/viridentitytest.c      |  5 +---
6 files changed, 50 insertions(+), 39 deletions(-)

diff --git a/src/util/viridentity.c b/src/util/viridentity.c
index a24704b690..c6299a6b09 100644
--- a/src/util/viridentity.c
+++ b/src/util/viridentity.c
@@ -43,25 +43,29 @@
-static void virIdentityDispose(void *object)
+static void virIdentityFinalize(GObject *object)
{
-    virIdentityPtr ident = object;
+    virIdentityPtr ident = VIR_IDENTITY(object);

    virTypedParamsFree(ident->params, ident->nparams);
+
+    G_OBJECT_CLASS(virIdentity_parent_class)->finalize(object);
}


+

Extra whitespace

/*
 * Returns: 0 if not present, 1 if present, -1 on error
 */
diff --git a/src/util/viridentity.h b/src/util/viridentity.h
index 7513dd4e35..df658ea844 100644
--- a/src/util/viridentity.h
+++ b/src/util/viridentity.h
@@ -21,12 +21,13 @@

#pragma once

-#include "virobject.h"
+#include "internal.h"
+#include <glib-object.h>

-typedef struct _virIdentity virIdentity;
-typedef virIdentity *virIdentityPtr;
+#define VIR_TYPE_IDENTITY virIdentity_get_type()

Consider not mixing camel case with snake case.

+G_DECLARE_FINAL_TYPE(virIdentity, virIdentity, VIR, IDENTITY, GObject);

-G_DEFINE_AUTOPTR_CLEANUP_FUNC(virIdentity, virObjectUnref);
+typedef virIdentity *virIdentityPtr;

virIdentityPtr virIdentityGetCurrent(void);
int virIdentitySetCurrent(virIdentityPtr ident);

Reviewed-by: Ján Tomko <jtomko@xxxxxxxxxx>

Jano

Attachment: signature.asc
Description: PGP signature

--
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