[glib: 3/4] tutorial: Add private members to example code in tutorial



commit ca60cd3314f649afd847bc502f4ed12f19a3b318
Author: Philip Withnall <withnall endlessm com>
Date:   Thu Aug 29 09:20:01 2019 +0100

    tutorial: Add private members to example code in tutorial
    
    Add the private members referred to in the property setting/getting
    example, and a finalize function for them, to make the tutorial code
    more self-contained.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>
    
    Helps: #1858

 docs/reference/gobject/tut_gobject.xml | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
---
diff --git a/docs/reference/gobject/tut_gobject.xml b/docs/reference/gobject/tut_gobject.xml
index c42d5e6b3..fc7d6fe16 100644
--- a/docs/reference/gobject/tut_gobject.xml
+++ b/docs/reference/gobject/tut_gobject.xml
@@ -65,6 +65,8 @@ struct _ViewerFile
   GObject parent_instance;
 
   /* instance members */
+  gchar *filename;
+  guint zoom_level;
 };
 
 /* will create viewer_file_get_type and set viewer_file_parent_class */
@@ -80,12 +82,25 @@ viewer_file_constructed (GObject *obj)
   G_OBJECT_CLASS (viewer_file_parent_class)-&gt;constructed (obj);
 }
 
+static void
+viewer_file_finalize (GObject *obj)
+{
+  ViewerFile *self = VIEWER_FILE (obj);
+
+  g_free (self->filename);
+
+  /* Always chain up to the parent finalize function to complete object
+   * destruction. */
+  G_OBJECT_CLASS (viewer_file_parent_class)-&gt;finalize (obj);
+}
+
 static void
 viewer_file_class_init (ViewerFileClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
   object_class-&gt;constructed = viewer_file_constructed;
+  object_class-&gt;finalize = viewer_file_finalize;
 }
 
 static void


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