diff --git a/gobject/gobject.c b/gobject/gobject.c index 12daf72f2..5b0926bda 100644 --- a/gobject/gobject.c +++ b/gobject/gobject.c @@ -529,6 +529,41 @@ install_property_internal (GType g_type, g_param_spec_pool_insert (pspec_pool, pspec, g_type); } +static gboolean +validate_and_install_class_property (GObjectClass *class, + GType oclass_type, + GType parent_type, + guint property_id, + GParamSpec *pspec) +{ + g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE); + g_return_val_if_fail (pspec->flags & (G_PARAM_READABLE | G_PARAM_WRITABLE), FALSE); + if (pspec->flags & G_PARAM_WRITABLE) + g_return_val_if_fail (class->set_property != NULL, FALSE); + if (pspec->flags & G_PARAM_READABLE) + g_return_val_if_fail (class->get_property != NULL, FALSE); + g_return_val_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0, FALSE); /* paranoid */ + if (pspec->flags & G_PARAM_CONSTRUCT) + g_return_val_if_fail ((pspec->flags & G_PARAM_CONSTRUCT_ONLY) == 0, FALSE); + if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) + g_return_val_if_fail (pspec->flags & G_PARAM_WRITABLE, FALSE); + + class->flags |= CLASS_HAS_PROPS_FLAG; + install_property_internal (oclass_type, property_id, pspec); + + if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) + class->construct_properties = g_slist_append (class->construct_properties, pspec); + + /* for property overrides of construct properties, we have to get rid + * of the overidden inherited construct property + */ + pspec = g_param_spec_pool_lookup (pspec_pool, pspec->name, parent_type, TRUE); + if (pspec && pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) + class->construct_properties = g_slist_remove (class->construct_properties, pspec); + + return TRUE; +} + /** * g_object_class_install_property: * @oclass: a #GObjectClass @@ -562,30 +597,11 @@ g_object_class_install_property (GObjectClass *class, 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_return_if_fail (G_IS_PARAM_SPEC (pspec)); - g_return_if_fail (pspec->flags & (G_PARAM_READABLE | G_PARAM_WRITABLE)); - if (pspec->flags & G_PARAM_WRITABLE) - g_return_if_fail (class->set_property != NULL); - if (pspec->flags & G_PARAM_READABLE) - g_return_if_fail (class->get_property != NULL); - g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0); /* paranoid */ - if (pspec->flags & G_PARAM_CONSTRUCT) - g_return_if_fail ((pspec->flags & G_PARAM_CONSTRUCT_ONLY) == 0); - if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) - g_return_if_fail (pspec->flags & G_PARAM_WRITABLE); - - class->flags |= CLASS_HAS_PROPS_FLAG; - install_property_internal (oclass_type, property_id, pspec); - - if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) - class->construct_properties = g_slist_append (class->construct_properties, pspec); - - /* for property overrides of construct properties, we have to get rid - * of the overidden inherited construct property - */ - pspec = g_param_spec_pool_lookup (pspec_pool, pspec->name, parent_type, TRUE); - if (pspec && pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) - class->construct_properties = g_slist_remove (class->construct_properties, pspec); + (void) validate_and_install_class_property (class, + oclass_type, + parent_type, + property_id, + pspec); } /** @@ -683,30 +699,14 @@ g_object_class_install_properties (GObjectClass *oclass, { GParamSpec *pspec = pspecs[i]; - g_return_if_fail (G_IS_PARAM_SPEC (pspec)); - g_return_if_fail (pspec->flags & (G_PARAM_READABLE | G_PARAM_WRITABLE)); - if (pspec->flags & G_PARAM_WRITABLE) - g_return_if_fail (oclass->set_property != NULL); - if (pspec->flags & G_PARAM_READABLE) - g_return_if_fail (oclass->get_property != NULL); - g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0); /* paranoid */ - if (pspec->flags & G_PARAM_CONSTRUCT) - g_return_if_fail ((pspec->flags & G_PARAM_CONSTRUCT_ONLY) == 0); - if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) - g_return_if_fail (pspec->flags & G_PARAM_WRITABLE); - - oclass->flags |= CLASS_HAS_PROPS_FLAG; - install_property_internal (oclass_type, i, pspec); - - if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) - oclass->construct_properties = g_slist_append (oclass->construct_properties, pspec); - - /* for property overrides of construct properties, we have to get rid - * of the overidden inherited construct property - */ - pspec = g_param_spec_pool_lookup (pspec_pool, pspec->name, parent_type, TRUE); - if (pspec && pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) - oclass->construct_properties = g_slist_remove (oclass->construct_properties, pspec); + if (!validate_and_install_class_property (oclass, + oclass_type, + parent_type, + i, + pspec)) + { + break; + } } }