Use correct parent class when chaining up overridden functions

How `g_type_class_peek ()` was used it didn't return the correct parent
class in most cases.
G_DEFINE_TYPE macro creates a pointer we can use to get the parent
class `n_p_parent_class`.
Because we didn't use the correct parent class the object initialisation
wasn't fully completed for some GtkWidgets.
See https://developer.gnome.org/gobject/stable/chapter-gobject.html#gobject-instantiation
for more information.

This commit makes use of the `n_p_parent_class pointer` created for this
specific use case where ever possible.

Fixes: https://source.puri.sm/Librem5/calls/issues/118
This commit is contained in:
Julian Sparber
2020-02-18 16:01:22 +01:00
parent 06481155fd
commit e911f391c6
24 changed files with 50 additions and 100 deletions

View File

@@ -280,7 +280,6 @@ disconnect_reason_cb (CallsOfonoCall *self,
static void
constructed (GObject *object)
{
GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT);
CallsOfonoCall *self = CALLS_OFONO_CALL (object);
g_return_if_fail (self->voice_call != NULL);
@@ -290,33 +289,31 @@ constructed (GObject *object)
g_signal_connect_swapped (self->voice_call, "disconnect-reason",
G_CALLBACK (disconnect_reason_cb), self);
parent_class->constructed (object);
G_OBJECT_CLASS (calls_ofono_call_parent_class)->constructed (object);
}
static void
dispose (GObject *object)
{
GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT);
CallsOfonoCall *self = CALLS_OFONO_CALL (object);
g_clear_object (&self->voice_call);
parent_class->dispose (object);
G_OBJECT_CLASS (calls_ofono_call_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT);
CallsOfonoCall *self = CALLS_OFONO_CALL (object);
g_free (self->disconnect_reason);
g_free (self->name);
g_free (self->number);
parent_class->finalize (object);
G_OBJECT_CLASS (calls_ofono_call_parent_class)->finalize (object);
}

View File

@@ -448,7 +448,6 @@ voice_new_cb (GDBusConnection *connection,
static void
constructed (GObject *object)
{
GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT);
CallsOfonoOrigin *self = CALLS_OFONO_ORIGIN (object);
GDBusProxy *modem_proxy;
gchar *name;
@@ -478,28 +477,26 @@ constructed (GObject *object)
g_clear_object (&self->modem);
parent_class->constructed (object);
G_OBJECT_CLASS (calls_ofono_origin_parent_class)->constructed (object);
}
static void
dispose (GObject *object)
{
GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT);
CallsOfonoOrigin *self = CALLS_OFONO_ORIGIN (object);
remove_calls (self, NULL);
g_clear_object (&self->modem);
g_clear_object (&self->connection);
parent_class->dispose (object);
G_OBJECT_CLASS (calls_ofono_origin_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT);
CallsOfonoOrigin *self = CALLS_OFONO_ORIGIN (object);
if (self->tone_queue)
@@ -508,7 +505,7 @@ finalize (GObject *object)
}
g_free (self->name);
parent_class->finalize (object);
G_OBJECT_CLASS (calls_ofono_origin_parent_class)->finalize (object);
}

View File

@@ -380,7 +380,6 @@ get_modems_cb (GDBOManager *manager,
static void
constructed (GObject *object)
{
GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT);
CallsOfonoProvider *self = CALLS_OFONO_PROVIDER (object);
GError *error = NULL;
@@ -415,33 +414,31 @@ constructed (GObject *object)
(GAsyncReadyCallback) get_modems_cb,
self);
parent_class->constructed (object);
G_OBJECT_CLASS (calls_ofono_provider_parent_class)->constructed (object);
}
static void
dispose (GObject *object)
{
GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT);
CallsOfonoProvider *self = CALLS_OFONO_PROVIDER (object);
g_clear_object (&self->manager);
g_clear_object (&self->connection);
parent_class->dispose (object);
G_OBJECT_CLASS (calls_ofono_provider_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT);
CallsOfonoProvider *self = CALLS_OFONO_PROVIDER (object);
g_hash_table_unref (self->origins);
g_hash_table_unref (self->modems);
parent_class->finalize (object);
G_OBJECT_CLASS (calls_ofono_provider_parent_class)->finalize (object);
}