[mutter] context: Allow controlled destruction



commit e62f7e2910655c2dbc0ced9514cd101289cf6a6e
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Mon May 10 21:43:18 2021 +0200

    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>

 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 3441c60b56..82e8c90e75 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 b72973e682..e4252daf67 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,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]