[glib] validate_pspec_to_install(): Factor out function to validate a GParamSpec
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] validate_pspec_to_install(): Factor out function to validate a GParamSpec
- Date: Mon, 11 Sep 2017 17:46:51 +0000 (UTC)
commit 51e852e5d040381f123d6df6e9d7a3293afe4965
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Sep 11 09:41:28 2017 -0500
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
gobject/gobject.c | 32 +++++++++++++++++++-------------
1 files changed, 19 insertions(+), 13 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index f4266e3..e79c5e5 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -531,20 +531,32 @@ install_property_internal (GType g_type,
}
static gboolean
-validate_and_install_class_property (GObjectClass *class,
- GType oclass_type,
- GType parent_type,
- guint property_id,
- GParamSpec *pspec)
+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,
+ GType parent_type,
+ guint property_id,
+ GParamSpec *pspec)
+{
+ if (!validate_pspec_to_install (pspec))
+ return FALSE;
+
if (pspec->flags & G_PARAM_WRITABLE)
g_return_val_if_fail (class->set_property != NULL, FALSE);
if (pspec->flags & G_PARAM_READABLE)
@@ -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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]