[gom] gom: Add better check on the primary-key property
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gom] gom: Add better check on the primary-key property
- Date: Tue, 6 May 2014 19:43:54 +0000 (UTC)
commit f416919a96d6fc087c01b9fdf1bec9d624790ec9
Author: Bastien Nocera <hadess hadess net>
Date: Tue May 6 21:39:43 2014 +0200
gom: Add better check on the primary-key property
Make sure that the primary-key property isn't set as a construct-only
property, or that its default value is non-NULL.
Thanks to Mathieu Bridon for the code that needed those checks :)
gom/gom-resource.c | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/gom/gom-resource.c b/gom/gom-resource.c
index 225e8db..f138031 100644
--- a/gom/gom-resource.c
+++ b/gom/gom-resource.c
@@ -47,9 +47,31 @@ void
gom_resource_class_set_primary_key (GomResourceClass *resource_class,
const gchar *primary_key)
{
+ GParamSpec *pspec;
+ const GValue *value;
+
g_return_if_fail(GOM_IS_RESOURCE_CLASS(resource_class));
g_return_if_fail(primary_key != NULL);
+ pspec = g_object_class_find_property(G_OBJECT_CLASS(resource_class), primary_key);
+ if (!pspec) {
+ g_warning("Property for primary key '%s' isn't declared yet. Are you running
gom_resource_class_set_primary_key() too early?",
+ primary_key);
+ return;
+ }
+
+ if (pspec->flags & G_PARAM_CONSTRUCT_ONLY) {
+ g_warning("Property for primary key '%s' is declared as construct-only. This will not work as
expected.", primary_key);
+ return;
+ }
+
+ /* Same check as in has_primary_key() */
+ value = g_param_spec_get_default_value (pspec);
+ if (value->data[0].v_pointer) {
+ g_warning("Property for primary key '%s' has a non-NULL/non-zero default value. This will not work as
expected.", primary_key);
+ return;
+ }
+
g_snprintf(resource_class->primary_key,
sizeof(resource_class->primary_key),
"%s", primary_key);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]