validate_pspec_to_install(): Factor out function to validate a GParamSpec

This was duplicated also in g_object_interface_install_property().

Now, validations specific to classes happen in
validate_and_install_class_property() - specifically, the checks for
the presence of the get_property() and set_property() methods.

https://bugzilla.gnome.org/show_bug.cgi?id=787551
This commit is contained in:
Federico Mena Quintero 2017-09-11 09:41:28 -05:00
parent 20720eaf1e
commit 51e852e5d0

View File

@ -530,6 +530,23 @@ install_property_internal (GType g_type,
return TRUE;
}
static gboolean
validate_pspec_to_install (GParamSpec *pspec)
{
g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
g_return_val_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0, FALSE); /* paranoid */
g_return_val_if_fail (pspec->flags & (G_PARAM_READABLE | G_PARAM_WRITABLE), FALSE);
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);
return TRUE;
}
static gboolean
validate_and_install_class_property (GObjectClass *class,
GType oclass_type,
@ -537,13 +554,8 @@ validate_and_install_class_property (GObjectClass *class,
guint property_id,
GParamSpec *pspec)
{
g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
g_return_val_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0, FALSE); /* paranoid */
g_return_val_if_fail (pspec->flags & (G_PARAM_READABLE | G_PARAM_WRITABLE), FALSE);
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);
if (!validate_pspec_to_install (pspec))
return FALSE;
if (pspec->flags & G_PARAM_WRITABLE)
g_return_val_if_fail (class->set_property != NULL, FALSE);
@ -748,14 +760,8 @@ g_object_interface_install_property (gpointer g_iface,
g_return_if_fail (G_TYPE_IS_INTERFACE (iface_class->g_type));
g_return_if_fail (!G_IS_PARAM_SPEC_OVERRIDE (pspec)); /* paranoid */
g_return_if_fail (G_IS_PARAM_SPEC (pspec));
g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0); /* paranoid */
g_return_if_fail (pspec->flags & (G_PARAM_READABLE | G_PARAM_WRITABLE));
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);
if (!validate_pspec_to_install (pspec))
return;
(void) install_property_internal (iface_class->g_type, 0, pspec);
}