[json-glib] Fixed badly handled fundamental types in json_deserialize_pspec().
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [json-glib] Fixed badly handled fundamental types in json_deserialize_pspec().
- Date: Thu, 7 Jul 2011 20:46:40 +0000 (UTC)
commit 4ba9a6a81709221ba58d0f8e067de660eb96914e
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Thu Jul 7 16:35:21 2011 -0400
Fixed badly handled fundamental types in json_deserialize_pspec().
This patch fixes json_deserialize_pspec() to return FALSE when
failing to deserialize some properties. Consequently the patch
ensures we get the intended warnings when failing to deserialize
pspecs for some fundamental types:
Failed to deserialize property "foo" of type "int" on object "bar"
json-glib/json-gobject.c | 42 ++++++++++++++++++++++++++++++------------
1 files changed, 30 insertions(+), 12 deletions(-)
---
diff --git a/json-glib/json-gobject.c b/json-glib/json-gobject.c
index ccb3007..73ecaac 100644
--- a/json-glib/json-gobject.c
+++ b/json-glib/json-gobject.c
@@ -519,33 +519,51 @@ json_deserialize_pspec (GValue *value,
case G_TYPE_INT64:
case G_TYPE_DOUBLE:
case G_TYPE_STRING:
- g_value_copy (&node_value, value);
- retval = TRUE;
+ if (G_VALUE_HOLDS (&node_value, G_VALUE_TYPE (value)))
+ {
+ g_value_copy (&node_value, value);
+ retval = TRUE;
+ }
break;
case G_TYPE_INT:
- g_value_set_int (value, (gint) g_value_get_int64 (&node_value));
- retval = TRUE;
+ if (G_VALUE_HOLDS (&node_value, G_TYPE_INT64))
+ {
+ g_value_set_int (value, (gint) g_value_get_int64 (&node_value));
+ retval = TRUE;
+ }
break;
case G_TYPE_CHAR:
- g_value_set_char (value, (gchar) g_value_get_int64 (&node_value));
- retval = TRUE;
+ if (G_VALUE_HOLDS (&node_value, G_TYPE_INT64))
+ {
+ g_value_set_char (value, (gchar) g_value_get_int64 (&node_value));
+ retval = TRUE;
+ }
break;
case G_TYPE_UINT:
- g_value_set_uint (value, (guint) g_value_get_int64 (&node_value));
- retval = TRUE;
+ if (G_VALUE_HOLDS (&node_value, G_TYPE_INT64))
+ {
+ g_value_set_uint (value, (guint) g_value_get_int64 (&node_value));
+ retval = TRUE;
+ }
break;
case G_TYPE_UCHAR:
- g_value_set_uchar (value, (guchar) g_value_get_int64 (&node_value));
- retval = TRUE;
+ if (G_VALUE_HOLDS (&node_value, G_TYPE_INT64))
+ {
+ g_value_set_uchar (value, (guchar) g_value_get_int64 (&node_value));
+ retval = TRUE;
+ }
break;
case G_TYPE_FLOAT:
- g_value_set_float (value, (gfloat) g_value_get_double (&node_value));
- retval = TRUE;
+ if (G_VALUE_HOLDS (&node_value, G_TYPE_DOUBLE))
+ {
+ g_value_set_float (value, (gfloat) g_value_get_double (&node_value));
+ retval = TRUE;
+ }
break;
case G_TYPE_ENUM:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]