summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2013-04-22 17:37:18 -0400
committerRyan Lortie <desrt@desrt.ca>2013-05-29 09:25:25 -0400
commita8a9afe17c0ee484b65c6f75e0d22ad1ae2cd9b6 (patch)
tree246379b3ebe79ec2ededda0bfc119a4138f27dc5
parent8df1bb3486417bc67a5b38fb8fa81f333b18da22 (diff)
downloadglib-a8a9afe17c0ee484b65c6f75e0d22ad1ae2cd9b6.tar.gz
GObject: prevent installing properties after init
GObject has previously allowed installing properties after class_init has finished running. This means that you could install some of your own properties on G_TYPE_OBJECT, for example, although they wouldn't have worked properly. A previous patch asserted that this was not true and we had to revert it because it broke the shell. Instead of reverting, we should have used a critical, so do that now. Complaints go to this bug: https://bugzilla.gnome.org/show_bug.cgi?id=698614
-rw-r--r--gobject/gobject.c9
-rw-r--r--gobject/gtype-private.h1
-rw-r--r--gobject/gtype.c10
3 files changed, 18 insertions, 2 deletions
diff --git a/gobject/gobject.c b/gobject/gobject.c
index 0eaba7e0e..c22b655d8 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -540,8 +540,10 @@ g_object_class_install_property (GObjectClass *class,
g_return_if_fail (G_IS_PARAM_SPEC (pspec));
if (CLASS_HAS_DERIVED_CLASS (class))
- g_error ("Attempt to add property %s::%s to class after it was derived",
- G_OBJECT_CLASS_NAME (class), pspec->name);
+ g_error ("Attempt to add property %s::%s to class after it was derived", G_OBJECT_CLASS_NAME (class), pspec->name);
+
+ if (!g_type_is_in_init (G_OBJECT_CLASS_TYPE (class)))
+ g_critical ("Attempt to add property %s::%s after class was initialised", G_OBJECT_CLASS_NAME (class), pspec->name);
class->flags |= CLASS_HAS_PROPS_FLAG;
@@ -653,6 +655,9 @@ g_object_class_install_properties (GObjectClass *oclass,
g_error ("Attempt to add properties to %s after it was derived",
G_OBJECT_CLASS_NAME (oclass));
+ if (!g_type_is_in_init (G_OBJECT_CLASS_TYPE (oclass)))
+ g_critical ("Attempt to add properties %s after it was initialised", G_OBJECT_CLASS_NAME (oclass));
+
oclass_type = G_OBJECT_CLASS_TYPE (oclass);
parent_type = g_type_parent (oclass_type);
diff --git a/gobject/gtype-private.h b/gobject/gtype-private.h
index 5c415e5d0..d9e31e482 100644
--- a/gobject/gtype-private.h
+++ b/gobject/gtype-private.h
@@ -72,6 +72,7 @@ void _g_closure_invoke_va (GClosure *closure,
int n_params,
GType *param_types);
+gboolean g_type_is_in_init (GType type);
G_END_DECLS
diff --git a/gobject/gtype.c b/gobject/gtype.c
index 01a00dc6e..8d5df09d0 100644
--- a/gobject/gtype.c
+++ b/gobject/gtype.c
@@ -4701,3 +4701,13 @@ g_type_ensure (GType type)
if (G_UNLIKELY (type == (GType)-1))
g_error ("can't happen");
}
+
+gboolean
+g_type_is_in_init (GType type)
+{
+ TypeNode *node;
+
+ node = lookup_type_node_I (type);
+
+ return node->data->class.init_state != INITIALIZED;
+}