context: Allow controlled destruction

Add a method meta_context_destroy() that both runs dispose and unrefs
the context. Tear down is moved to dispose() so that things owned by the
context are destroyed when calling meta_context_destroy(), or when the
last reference is released.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1861>
This commit is contained in:
Jonas Ådahl 2021-05-10 21:43:18 +02:00
parent 2deb751fd9
commit e62f7e2910
2 changed files with 22 additions and 1 deletions

View File

@ -469,6 +469,13 @@ meta_context_terminate_with_error (MetaContext *context,
meta_context_terminate (context); meta_context_terminate (context);
} }
void
meta_context_destroy (MetaContext *context)
{
g_object_run_dispose (G_OBJECT (context));
g_object_unref (context);
}
static void static void
meta_context_get_property (GObject *object, meta_context_get_property (GObject *object,
guint prop_id, guint prop_id,
@ -510,7 +517,7 @@ meta_context_set_property (GObject *object,
} }
static void static void
meta_context_finalize (GObject *object) meta_context_dispose (GObject *object)
{ {
MetaContext *context = META_CONTEXT (object); MetaContext *context = META_CONTEXT (object);
MetaContextPrivate *priv = meta_context_get_instance_private (context); MetaContextPrivate *priv = meta_context_get_instance_private (context);
@ -535,6 +542,16 @@ meta_context_finalize (GObject *object)
g_clear_pointer (&priv->option_context, g_option_context_free); g_clear_pointer (&priv->option_context, g_option_context_free);
g_clear_pointer (&priv->main_loop, g_main_loop_unref); g_clear_pointer (&priv->main_loop, g_main_loop_unref);
G_OBJECT_CLASS (meta_context_parent_class)->dispose (object);
}
static void
meta_context_finalize (GObject *object)
{
MetaContext *context = META_CONTEXT (object);
MetaContextPrivate *priv = meta_context_get_instance_private (context);
g_clear_pointer (&priv->gnome_wm_keybindings, g_free); g_clear_pointer (&priv->gnome_wm_keybindings, g_free);
g_clear_pointer (&priv->plugin_name, g_free); g_clear_pointer (&priv->plugin_name, g_free);
g_clear_pointer (&priv->name, g_free); g_clear_pointer (&priv->name, g_free);
@ -549,6 +566,7 @@ meta_context_class_init (MetaContextClass *klass)
object_class->get_property = meta_context_get_property; object_class->get_property = meta_context_get_property;
object_class->set_property = meta_context_set_property; object_class->set_property = meta_context_set_property;
object_class->dispose = meta_context_dispose;
object_class->finalize = meta_context_finalize; object_class->finalize = meta_context_finalize;
klass->configure = meta_context_real_configure; klass->configure = meta_context_real_configure;

View File

@ -34,6 +34,9 @@ G_DECLARE_DERIVABLE_TYPE (MetaContext, meta_context, META, CONTEXT, GObject)
META_EXPORT META_EXPORT
MetaContext * meta_create_context (const char *name); MetaContext * meta_create_context (const char *name);
META_EXPORT
void meta_context_destroy (MetaContext *context);
META_EXPORT META_EXPORT
void meta_context_add_option_entries (MetaContext *context, void meta_context_add_option_entries (MetaContext *context,
const GOptionEntry *entries, const GOptionEntry *entries,