[glib/wip/gproperty-2: 24/25] gobject: Initialize GProperties at instance init time
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/gproperty-2: 24/25] gobject: Initialize GProperties at instance init time
- Date: Thu, 13 Jun 2013 18:07:24 +0000 (UTC)
commit 75149e432d045069c238edba2e65d35f285fb018
Author: Emmanuele Bassi <ebassi gnome org>
Date: Tue Jun 11 14:01:04 2013 +0100
gobject: Initialize GProperties at instance init time
Using their default value. This removes the need to manually calling
g_property_init_default(), which means we can make it private.
https://bugzilla.gnome.org/show_bug.cgi?id=648526
gobject/gobject.c | 21 +++++++++++++++++++--
gobject/gproperty.c | 6 +++---
gobject/gproperty.h | 12 +++++-------
gobject/tests/property.c | 20 +++++++++++---------
4 files changed, 38 insertions(+), 21 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index e923e15..2dd8c9e 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -563,7 +563,7 @@ g_object_class_install_property (GObjectClass *class,
install_property_internal (G_OBJECT_CLASS_TYPE (class), property_id, pspec);
if (G_IS_PROPERTY (pspec))
- _g_property_set_installed ((GProperty *) pspec, class, G_OBJECT_CLASS_TYPE (class));
+ g_property_set_installed ((GProperty *) pspec, class, G_OBJECT_CLASS_TYPE (class));
if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY))
class->construct_properties = g_slist_append (class->construct_properties, pspec);
@@ -686,7 +686,7 @@ g_object_class_install_properties (GObjectClass *oclass,
install_property_internal (oclass_type, i, pspec);
if (G_IS_PROPERTY (pspec))
- _g_property_set_installed ((GProperty *) pspec, oclass, G_OBJECT_CLASS_TYPE (oclass));
+ g_property_set_installed ((GProperty *) pspec, oclass, G_OBJECT_CLASS_TYPE (oclass));
if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY))
oclass->construct_properties = g_slist_append (oclass->construct_properties, pspec);
@@ -978,6 +978,23 @@ g_object_init (GObject *object,
G_UNLOCK (construction_mutex);
}
+ if (CLASS_HAS_PROPS (class))
+ {
+ GParamSpec **pspecs;
+ guint n_pspecs, i;
+
+ /* initialize all properties that have a default */
+ pspecs = g_object_class_list_properties (class, &n_pspecs);
+
+ for (i = 0; i < n_pspecs; i++)
+ {
+ if (G_IS_PROPERTY (pspecs[i]))
+ g_property_init_default ((GProperty *) pspecs[i], object);
+ }
+
+ g_free (pspecs);
+ }
+
#ifdef G_ENABLE_DEBUG
IF_DEBUG (OBJECTS)
{
diff --git a/gobject/gproperty.c b/gobject/gproperty.c
index bc85445..bf64872 100644
--- a/gobject/gproperty.c
+++ b/gobject/gproperty.c
@@ -2743,9 +2743,9 @@ g_pointer_property_get_value (GProperty *property,
* the property.
*/
void
-_g_property_set_installed (GProperty *property,
- gpointer g_class,
- GType class_gtype)
+g_property_set_installed (GProperty *property,
+ gpointer g_class,
+ GType class_gtype)
{
if (property->field_offset >= 0)
{
diff --git a/gobject/gproperty.h b/gobject/gproperty.h
index 5a6d645..c94db1f 100644
--- a/gobject/gproperty.h
+++ b/gobject/gproperty.h
@@ -141,9 +141,6 @@ void g_property_override_default (GProperty *property,
GType gtype,
...);
GLIB_AVAILABLE_IN_2_38
-void g_property_init_default (GProperty *property,
- gpointer gobject);
-GLIB_AVAILABLE_IN_2_38
void g_property_set_prerequisite (GProperty *property,
GType gtype);
@@ -428,10 +425,11 @@ GParamSpec * g_pointer_property_new (const gchar *name,
/* private API */
-void _g_property_set_installed (GProperty *property,
- gpointer g_class,
- GType class_gtype);
-
+void g_property_set_installed (GProperty *property,
+ gpointer g_class,
+ GType class_gtype);
+void g_property_init_default (GProperty *property,
+ gpointer object);
/* accessors generation */
#define _G_DECLARE_PROPERTY_GETTER(T_n, t_n, f_t, f_n) f_t t_n##_get_##f_n (T_n *self)
diff --git a/gobject/tests/property.c b/gobject/tests/property.c
index 1f91ac1..ccb534a 100644
--- a/gobject/tests/property.c
+++ b/gobject/tests/property.c
@@ -83,8 +83,7 @@ static GParamSpec *test_object_properties[LAST_PROP] = { NULL, };
static void
test_object_finalize (GObject *gobject)
{
- TestObjectPrivate *priv =
- g_type_instance_get_private ((GTypeInstance *) gobject, test_object_get_type ());
+ TestObjectPrivate *priv = test_object_get_private ((TestObject *) gobject);
g_free (priv->str_val);
@@ -98,8 +97,7 @@ static gboolean
test_object_set_enum_val (gpointer obj,
gint val)
{
- TestObjectPrivate *priv =
- g_type_instance_get_private (obj, test_object_get_type ());
+ TestObjectPrivate *priv = test_object_get_private (obj);
if (priv->enum_val == val)
return FALSE;
@@ -149,6 +147,8 @@ test_object_class_init (TestObjectClass *klass)
NULL);
g_property_set_prerequisite ((GProperty *) test_object_properties[PROP_ENUM_VAL],
test_enum_get_type ());
+ g_property_set_default ((GProperty *) test_object_properties[PROP_ENUM_VAL],
+ TEST_ENUM_UNSET);
test_object_properties[PROP_WITH_DEFAULT] =
g_uint8_property_new ("with-default",
@@ -164,11 +164,6 @@ test_object_class_init (TestObjectClass *klass)
static void
test_object_init (TestObject *self)
{
- TestObjectPrivate *priv = test_object_get_private (self);
-
- priv->enum_val = TEST_ENUM_UNSET;
-
- g_property_init_default ((GProperty *) test_object_properties[PROP_WITH_DEFAULT], self);
}
G_DECLARE_PROPERTY_GET_SET (TestObject, test_object, gboolean, bool_val)
@@ -320,6 +315,13 @@ gproperty_accessors_get_set (void)
g_assert (did_emit_notify);
g_assert (!test_object_get_bool_val (obj));
+ did_emit_notify = FALSE;
+
+ test_object_set_bool_val (obj, FALSE);
+
+ g_assert (!did_emit_notify);
+ g_assert (!test_object_get_bool_val (obj));
+
g_object_unref (obj);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]