From e62f7e2910655c2dbc0ced9514cd101289cf6a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 10 May 2021 21:43:18 +0200 Subject: [PATCH] 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: --- src/core/meta-context.c | 20 +++++++++++++++++++- src/meta/meta-context.h | 3 +++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/core/meta-context.c b/src/core/meta-context.c index 3441c60b5..82e8c90e7 100644 --- a/src/core/meta-context.c +++ b/src/core/meta-context.c @@ -469,6 +469,13 @@ meta_context_terminate_with_error (MetaContext *context, meta_context_terminate (context); } +void +meta_context_destroy (MetaContext *context) +{ + g_object_run_dispose (G_OBJECT (context)); + g_object_unref (context); +} + static void meta_context_get_property (GObject *object, guint prop_id, @@ -510,7 +517,7 @@ meta_context_set_property (GObject *object, } static void -meta_context_finalize (GObject *object) +meta_context_dispose (GObject *object) { MetaContext *context = META_CONTEXT (object); 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->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->plugin_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->set_property = meta_context_set_property; + object_class->dispose = meta_context_dispose; object_class->finalize = meta_context_finalize; klass->configure = meta_context_real_configure; diff --git a/src/meta/meta-context.h b/src/meta/meta-context.h index b72973e68..e4252daf6 100644 --- a/src/meta/meta-context.h +++ b/src/meta/meta-context.h @@ -34,6 +34,9 @@ G_DECLARE_DERIVABLE_TYPE (MetaContext, meta_context, META, CONTEXT, GObject) META_EXPORT MetaContext * meta_create_context (const char *name); +META_EXPORT +void meta_context_destroy (MetaContext *context); + META_EXPORT void meta_context_add_option_entries (MetaContext *context, const GOptionEntry *entries,