[gcr/main: 25/30] gck-slot: Use G_DECLARE_FINAL_TYPE to declare the type
- From: Corentin Noël <corentinnoel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcr/main: 25/30] gck-slot: Use G_DECLARE_FINAL_TYPE to declare the type
- Date: Sun, 27 Mar 2022 08:40:10 +0000 (UTC)
commit 2d48429eab2a009777d06c62bfb7d3d22daa9e61
Author: Corentin Noël <corentin elementary io>
Date: Mon Feb 7 20:48:36 2022 +0100
gck-slot: Use G_DECLARE_FINAL_TYPE to declare the type
gck/gck-slot.c | 53 ++++++++++++++++++++++-------------------------------
gck/gck.h | 34 ++++------------------------------
gck/test-gck-slot.c | 2 +-
3 files changed, 27 insertions(+), 62 deletions(-)
---
diff --git a/gck/gck-slot.c b/gck/gck-slot.c
index a2b4a7c1..b2976291 100644
--- a/gck/gck-slot.c
+++ b/gck/gck-slot.c
@@ -46,12 +46,14 @@ enum {
PROP_HANDLE
};
-struct _GckSlotPrivate {
+struct _GckSlot {
+ GObject parent_instance;
+
GckModule *module;
CK_SLOT_ID handle;
};
-G_DEFINE_TYPE_WITH_PRIVATE (GckSlot, gck_slot, G_TYPE_OBJECT);
+G_DEFINE_TYPE (GckSlot, gck_slot, G_TYPE_OBJECT);
/* ----------------------------------------------------------------------------
* OBJECT
@@ -60,7 +62,6 @@ G_DEFINE_TYPE_WITH_PRIVATE (GckSlot, gck_slot, G_TYPE_OBJECT);
static void
gck_slot_init (GckSlot *self)
{
- self->pv = gck_slot_get_instance_private (self);
}
static void
@@ -92,14 +93,13 @@ gck_slot_set_property (GObject *obj, guint prop_id, const GValue *value,
switch (prop_id) {
case PROP_MODULE:
- g_assert (!self->pv->module);
- self->pv->module = g_value_get_object (value);
- g_assert (self->pv->module);
- g_object_ref (self->pv->module);
+ g_assert (!self->module);
+ self->module = g_value_dup_object (value);
+ g_assert (self->module);
break;
case PROP_HANDLE:
- g_assert (!self->pv->handle);
- self->pv->handle = g_value_get_ulong (value);
+ g_assert (!self->handle);
+ self->handle = g_value_get_ulong (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
@@ -112,7 +112,7 @@ gck_slot_finalize (GObject *obj)
{
GckSlot *self = GCK_SLOT (obj);
- g_clear_object (&self->pv->module);
+ g_clear_object (&self->module);
G_OBJECT_CLASS (gck_slot_parent_class)->finalize (obj);
}
@@ -207,9 +207,9 @@ gck_slot_info_free (GckSlotInfo *slot_info)
{
if (!slot_info)
return;
- g_free (slot_info->slot_description);
- g_free (slot_info->manufacturer_id);
- g_free (slot_info);
+ g_clear_pointer (&slot_info->slot_description, g_free);
+ g_clear_pointer (&slot_info->manufacturer_id, g_free);
+ g_clear_pointer (&slot_info, g_free);
}
/**
@@ -422,20 +422,15 @@ gck_mechanisms_check (GArray *mechanisms, ...)
* %FALSE if either is not a GckSlot.
**/
gboolean
-gck_slot_equal (gconstpointer slot1, gconstpointer slot2)
+gck_slot_equal (GckSlot *slot1, GckSlot *slot2)
{
- GckSlot *s1, *s2;
-
if (slot1 == slot2)
return TRUE;
if (!GCK_IS_SLOT (slot1) || !GCK_IS_SLOT (slot2))
return FALSE;
- s1 = GCK_SLOT (slot1);
- s2 = GCK_SLOT (slot2);
-
- return s1->pv->handle == s2->pv->handle &&
- gck_module_equal (s1->pv->module, s2->pv->module);
+ return slot1->handle == slot2->handle &&
+ gck_module_equal (slot1->module, slot2->module);
}
/**
@@ -450,16 +445,12 @@ gck_slot_equal (gconstpointer slot1, gconstpointer slot2)
* Return value: An integer that can be used as a hash value, or 0 if invalid.
**/
guint
-gck_slot_hash (gconstpointer slot)
+gck_slot_hash (GckSlot *slot)
{
- GckSlot *self;
-
g_return_val_if_fail (GCK_IS_SLOT (slot), 0);
- self = GCK_SLOT (slot);
-
- return _gck_ulong_hash (&self->pv->handle) ^
- gck_module_hash (self->pv->module);
+ return _gck_ulong_hash (&slot->handle) ^
+ gck_module_hash (slot->module);
}
/**
@@ -493,7 +484,7 @@ gulong
gck_slot_get_handle (GckSlot *self)
{
g_return_val_if_fail (GCK_IS_SLOT (self), (CK_SLOT_ID)-1);
- return self->pv->handle;
+ return self->handle;
}
/**
@@ -509,8 +500,8 @@ GckModule *
gck_slot_get_module (GckSlot *self)
{
g_return_val_if_fail (GCK_IS_SLOT (self), NULL);
- g_return_val_if_fail (GCK_IS_MODULE (self->pv->module), NULL);
- return g_object_ref (self->pv->module);
+ g_return_val_if_fail (GCK_IS_MODULE (self->module), NULL);
+ return g_object_ref (self->module);
}
/**
diff --git a/gck/gck.h b/gck/gck.h
index 70337f49..ee66cd48 100644
--- a/gck/gck.h
+++ b/gck/gck.h
@@ -643,36 +643,12 @@ gboolean gck_mechanisms_check (GArray *mechanisms,
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GckMechanismInfo, gck_mechanism_info_free);
#define GCK_TYPE_SLOT (gck_slot_get_type())
-#define GCK_SLOT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCK_TYPE_SLOT, GckSlot))
-#define GCK_SLOT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GCK_TYPE_SLOT, GckSlot))
-#define GCK_IS_SLOT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCK_TYPE_SLOT))
-#define GCK_IS_SLOT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GCK_TYPE_SLOT))
-#define GCK_SLOT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCK_TYPE_SLOT, GckSlotClass))
+G_DECLARE_FINAL_TYPE (GckSlot, gck_slot, GCK, SLOT, GObject)
-typedef struct _GckSlotClass GckSlotClass;
-typedef struct _GckSlotPrivate GckSlotPrivate;
+gboolean gck_slot_equal (GckSlot *slot1,
+ GckSlot *slot2);
-struct _GckSlot {
- GObject parent;
-
- /*< private >*/
- GckSlotPrivate *pv;
- gpointer reserved[4];
-};
-
-struct _GckSlotClass {
- GObjectClass parent;
-
- /*< private >*/
- gpointer reserved[9];
-};
-
-GType gck_slot_get_type (void) G_GNUC_CONST;
-
-gboolean gck_slot_equal (gconstpointer slot1,
- gconstpointer slot2);
-
-guint gck_slot_hash (gconstpointer slot);
+guint gck_slot_hash (GckSlot *slot);
gboolean gck_slot_match (GckSlot *self,
GckUriData *uri);
@@ -740,8 +716,6 @@ GckEnumerator* gck_slots_enumerate_objects (GList *slots,
GckAttributes *match,
GckSessionOptions options);
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (GckSlot, g_object_unref);
-
/* ------------------------------------------------------------------------
* SESSION
*/
diff --git a/gck/test-gck-slot.c b/gck/test-gck-slot.c
index 4cfddbee..6d09c427 100644
--- a/gck/test-gck-slot.c
+++ b/gck/test-gck-slot.c
@@ -156,7 +156,7 @@ test_slot_equals_hash (Test *test, gconstpointer unused)
g_object_unref (other_slot);
obj = g_object_new (G_TYPE_OBJECT, NULL);
- g_assert_false (gck_slot_equal (test->slot, obj));
+ g_assert_false (gck_slot_equal (test->slot, (GckSlot *) obj));
g_object_unref (obj);
other_slot = g_object_new (GCK_TYPE_SLOT, "module", test->module, "handle", 8909, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]