[glibmm] Custom Interface Properties: Use base finalize function to free data.



commit 1826a955cc607527ebb47eecf701aa5e28fdc1ef
Author: José Alburquerque <jaalburquerque gmail com>
Date:   Tue May 14 16:22:17 2013 -0400

    Custom Interface Properties: Use base finalize function to free data.
    
        * glib/glibmm/class.cc (Class::clone_custom_type): Specify a custom
        base finalize function for the custom type which would free the
        properties data that might exist due to properties of implemented
        interfaces being overridden.  This is better than having an interface
        finalize function because the custom type could implement several
        interfaces which would mean that the interface finalize function would
        execute more than once as opposed to just once for the base finalize
        function.
        * glib/glibmm/class.h (Class::interface_finalize_function): Replace
        with Class::custom_class_base_finalize_function().
    
        * glib/glibmm/interface.cc (Interface_Class::add_interface): Do not
        specify a custom interface finalize function.
    
        (Interface::Interface(const Interface_Class&): Also initialize the
        property GValues using g_param_value_set_default() so that they are
        initialized with the default values of the properties and not just the
        default value of the GValue type.
    
        Bug #697229.

 ChangeLog                |   25 +++++++++++++++++++++++++
 glib/glibmm/class.cc     |    6 +++---
 glib/glibmm/class.h      |    4 +---
 glib/glibmm/interface.cc |    3 ++-
 4 files changed, 31 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index bb6e571..508ec67 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2013-05-14  José Alburquerque  <jaalburquerque gmail com>
+
+       Custom Interface Properties: Use base finalize function to free data.
+
+       * glib/glibmm/class.cc (Class::clone_custom_type): Specify a custom
+       base finalize function for the custom type which would free the
+       properties data that might exist due to properties of implemented
+       interfaces being overridden.  This is better than having an interface
+       finalize function because the custom type could implement several
+       interfaces which would mean that the interface finalize function would
+       execute more than once as opposed to just once for the base finalize
+       function.
+       * glib/glibmm/class.h (Class::interface_finalize_function): Replace
+       with Class::custom_class_base_finalize_function().
+
+       * glib/glibmm/interface.cc (Interface_Class::add_interface): Do not
+       specify a custom interface finalize function.
+
+       (Interface::Interface(const Interface_Class&): Also initialize the
+       property GValues using g_param_value_set_default() so that they are
+       initialized with the default values of the properties and not just the
+       default value of the GValue type.
+
+       Bug #697229.
+
 2013-05-07  José Alburquerque  <jaalburquerque gmail com>
 
        UnixSocketAddress: Add the "path-as-array" property.
diff --git a/glib/glibmm/class.cc b/glib/glibmm/class.cc
index c31a834..3b6da41 100644
--- a/glib/glibmm/class.cc
+++ b/glib/glibmm/class.cc
@@ -114,7 +114,7 @@ GType Class::clone_custom_type(const char* custom_type_name) const
     {
       class_size,
       0, // base_init
-      0, // base_finalize
+      &Class::custom_class_base_finalize_function, // base_finalize
       &Class::custom_class_init_function,
       0, // class_finalize
       this, // class_data
@@ -135,9 +135,9 @@ GType Class::clone_custom_type(const char* custom_type_name) const
 GQuark Class::properties_quark = g_quark_from_string("gtkmm_CustomObject_properties");
 
 // static
-void Class::interface_finalize_function(void* g_iface, void*)
+void Class::custom_class_base_finalize_function(void* g_class)
 {
-  const GType gtype = G_TYPE_FROM_CLASS(g_iface);
+  const GType gtype = G_TYPE_FROM_CLASS(g_class);
 
   // Free the data related to the properties for the custom type, if any.
   properties_type* props = static_cast<properties_type*>(g_type_get_qdata(gtype, properties_quark));
diff --git a/glib/glibmm/class.h b/glib/glibmm/class.h
index 7092d50..dbd7c58 100644
--- a/glib/glibmm/class.h
+++ b/glib/glibmm/class.h
@@ -67,10 +67,8 @@ protected:
    */
   void register_derived_type(GType base_type, GTypeModule* module);
 
-protected:
-  static void interface_finalize_function(void* g_iface, void* iface_data);
-
 private:
+  static void custom_class_base_finalize_function(void* g_class);
   static void custom_class_init_function(void* g_class, void* class_data);
 
 public:
diff --git a/glib/glibmm/interface.cc b/glib/glibmm/interface.cc
index d55b9bd..7183bc7 100644
--- a/glib/glibmm/interface.cc
+++ b/glib/glibmm/interface.cc
@@ -36,7 +36,7 @@ void Interface_Class::add_interface(GType instance_type) const
     const GInterfaceInfo interface_info =
     {
       class_init_func_,
-      &Class::interface_finalize_function, // interface_finalize
+      0, // interface_finalize
       0, // interface_data
     };
 
@@ -86,6 +86,7 @@ Interface::Interface(const Interface_Class& interface_class)
       {
         GValue* g_value = g_new0(GValue, 1);
         g_value_init(g_value, iface_props[p]->value_type);
+        g_param_value_set_default(iface_props[p], g_value);
         props->push_back(g_value);
 
         const gchar* prop_name = g_param_spec_get_name(iface_props[p]);


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