core: handle global references in a simpler way
This commit is contained in:
@@ -32,9 +32,15 @@ struct _WpCore
|
|||||||
G_DEFINE_TYPE (WpCore, wp_core, G_TYPE_OBJECT)
|
G_DEFINE_TYPE (WpCore, wp_core, G_TYPE_OBJECT)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
free_global_object (gpointer g)
|
free_global_object (gpointer p)
|
||||||
{
|
{
|
||||||
g_slice_free (struct global_object, g);
|
struct global_object *g = p;
|
||||||
|
|
||||||
|
/* Destroy the object */
|
||||||
|
if (g->destroy)
|
||||||
|
g->destroy(g->object);
|
||||||
|
|
||||||
|
g_slice_free (struct global_object, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -49,17 +55,15 @@ wp_core_dispose (GObject * obj)
|
|||||||
WpCore *self = WP_CORE (obj);
|
WpCore *self = WP_CORE (obj);
|
||||||
g_autoptr (GPtrArray) global_objects;
|
g_autoptr (GPtrArray) global_objects;
|
||||||
struct global_object *global;
|
struct global_object *global;
|
||||||
gint i;
|
|
||||||
|
|
||||||
global_objects = g_steal_pointer (&self->global_objects);
|
global_objects = g_steal_pointer (&self->global_objects);
|
||||||
|
|
||||||
for (i = 0; i < global_objects->len; i++) {
|
/* Remove and emit the removed signal for all globals */
|
||||||
global = g_ptr_array_index (global_objects, i);
|
while (global_objects->len > 0) {
|
||||||
|
global = g_ptr_array_steal_index_fast (global_objects, 0);
|
||||||
g_signal_emit (self, signals[SIGNAL_GLOBAL_REMOVED], global->key,
|
g_signal_emit (self, signals[SIGNAL_GLOBAL_REMOVED], global->key,
|
||||||
global->key, global->object);
|
global->key, global->object);
|
||||||
|
free_global_object (global);
|
||||||
if (global->destroy)
|
|
||||||
global->destroy (global->object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
G_OBJECT_CLASS (wp_core_parent_class)->dispose (obj);
|
G_OBJECT_CLASS (wp_core_parent_class)->dispose (obj);
|
||||||
@@ -198,7 +202,6 @@ wp_core_remove_global (WpCore * self, GQuark key, gpointer obj)
|
|||||||
{
|
{
|
||||||
gint i;
|
gint i;
|
||||||
struct global_object *global;
|
struct global_object *global;
|
||||||
struct global_object tmp;
|
|
||||||
|
|
||||||
g_return_if_fail (WP_IS_CORE (self));
|
g_return_if_fail (WP_IS_CORE (self));
|
||||||
|
|
||||||
@@ -212,15 +215,12 @@ wp_core_remove_global (WpCore * self, GQuark key, gpointer obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (i < self->global_objects->len) {
|
if (i < self->global_objects->len) {
|
||||||
tmp = *global;
|
global = g_ptr_array_steal_index_fast (self->global_objects, i);
|
||||||
|
|
||||||
g_ptr_array_remove_index_fast (self->global_objects, i);
|
|
||||||
|
|
||||||
g_signal_emit (self, signals[SIGNAL_GLOBAL_REMOVED], key,
|
g_signal_emit (self, signals[SIGNAL_GLOBAL_REMOVED], key,
|
||||||
key, tmp.object);
|
key, global->object);
|
||||||
|
|
||||||
if (tmp.destroy)
|
free_global_object (global);
|
||||||
tmp.destroy (tmp.object);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user