[json] Update the internal copy of JSON-GLib
JSON-GLib switch to 64 bit integers upstream, to avoid the undefined integer size of the JSON RFC. All integers are automatically promoted to gint64.
This commit is contained in:
parent
2b70b0d4ed
commit
4d52245637
@ -241,7 +241,7 @@ json_array_get_element (JsonArray *array,
|
||||
*
|
||||
* Since: 0.8
|
||||
*/
|
||||
gint
|
||||
gint64
|
||||
json_array_get_int_element (JsonArray *array,
|
||||
guint index_)
|
||||
{
|
||||
@ -483,7 +483,7 @@ json_array_add_element (JsonArray *array,
|
||||
*/
|
||||
void
|
||||
json_array_add_int_element (JsonArray *array,
|
||||
gint value)
|
||||
gint64 value)
|
||||
{
|
||||
JsonNode *node;
|
||||
|
||||
|
@ -359,6 +359,13 @@ json_node_get_value (JsonNode *node,
|
||||
}
|
||||
}
|
||||
|
||||
static void inline
|
||||
node_value_unset (JsonNode *node)
|
||||
{
|
||||
if (G_VALUE_TYPE (&(node->data.value)) != G_TYPE_INVALID)
|
||||
g_value_unset (&(node->data.value));
|
||||
}
|
||||
|
||||
/**
|
||||
* json_node_set_value:
|
||||
* @node: a #JsonNode
|
||||
@ -372,12 +379,42 @@ json_node_set_value (JsonNode *node,
|
||||
{
|
||||
g_return_if_fail (node != NULL);
|
||||
g_return_if_fail (JSON_NODE_TYPE (node) == JSON_NODE_VALUE);
|
||||
g_return_if_fail (G_VALUE_TYPE (value) != G_TYPE_INVALID);
|
||||
|
||||
if (G_VALUE_TYPE (&(node->data.value)) != 0)
|
||||
g_value_unset (&(node->data.value));
|
||||
switch (G_VALUE_TYPE (value))
|
||||
{
|
||||
/* direct copy for the types we use */
|
||||
case G_TYPE_INT64:
|
||||
case G_TYPE_BOOLEAN:
|
||||
case G_TYPE_DOUBLE:
|
||||
case G_TYPE_STRING:
|
||||
node_value_unset (node);
|
||||
g_value_init (&(node->data.value), G_VALUE_TYPE (value));
|
||||
g_value_copy (value, &(node->data.value));
|
||||
break;
|
||||
|
||||
/* auto-promote ints to long longs */
|
||||
case G_TYPE_INT:
|
||||
node_value_unset (node);
|
||||
g_value_init (&(node->data.value), G_TYPE_INT64);
|
||||
g_value_set_int64 (&(node->data.value),
|
||||
g_value_get_int (value));
|
||||
break;
|
||||
|
||||
/* auto-promote single precision to double precision */
|
||||
case G_TYPE_FLOAT:
|
||||
node_value_unset (node);
|
||||
g_value_init (&(node->data.value), G_TYPE_DOUBLE);
|
||||
g_value_set_double (&(node->data.value),
|
||||
g_value_get_float (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
g_warning ("Invalid value of type '%s'",
|
||||
g_type_name (G_VALUE_TYPE (value)));
|
||||
return;
|
||||
}
|
||||
|
||||
g_value_init (&(node->data.value), G_VALUE_TYPE (value));
|
||||
g_value_copy (value, &(node->data.value));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -548,19 +585,19 @@ json_node_dup_string (JsonNode *node)
|
||||
*/
|
||||
void
|
||||
json_node_set_int (JsonNode *node,
|
||||
gint value)
|
||||
gint64 value)
|
||||
{
|
||||
g_return_if_fail (node != NULL);
|
||||
g_return_if_fail (JSON_NODE_TYPE (node) == JSON_NODE_VALUE);
|
||||
|
||||
if (G_VALUE_TYPE (&(node->data.value)) == G_TYPE_INT)
|
||||
g_value_set_int (&(node->data.value), value);
|
||||
if (G_VALUE_TYPE (&(node->data.value)) == G_TYPE_INT64)
|
||||
g_value_set_int64 (&(node->data.value), value);
|
||||
else
|
||||
{
|
||||
GValue copy = { 0, };
|
||||
|
||||
g_value_init (©, G_TYPE_INT);
|
||||
g_value_set_int (©, value);
|
||||
g_value_init (©, G_TYPE_INT64);
|
||||
g_value_set_int64 (©, value);
|
||||
|
||||
json_node_set_value (node, ©);
|
||||
|
||||
@ -576,7 +613,7 @@ json_node_set_int (JsonNode *node,
|
||||
*
|
||||
* Return value: an integer value.
|
||||
*/
|
||||
gint
|
||||
gint64
|
||||
json_node_get_int (JsonNode *node)
|
||||
{
|
||||
g_return_val_if_fail (node != NULL, 0);
|
||||
@ -584,8 +621,8 @@ json_node_get_int (JsonNode *node)
|
||||
if (JSON_NODE_TYPE (node) == JSON_NODE_NULL)
|
||||
return 0;
|
||||
|
||||
if (G_VALUE_TYPE (&(node->data.value)) == G_TYPE_INT)
|
||||
return g_value_get_int (&(node->data.value));
|
||||
if (G_VALUE_TYPE (&(node->data.value)) == G_TYPE_INT64)
|
||||
return g_value_get_int64 (&(node->data.value));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -139,10 +139,9 @@ object_set_member_internal (JsonObject *object,
|
||||
const gchar *member_name,
|
||||
JsonNode *node)
|
||||
{
|
||||
gchar *name;
|
||||
|
||||
name = g_strdelimit (g_strdup (member_name), G_STR_DELIMITERS, '_');
|
||||
g_hash_table_replace (object->members, name, node);
|
||||
g_hash_table_replace (object->members,
|
||||
g_strdup (member_name),
|
||||
node);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -221,7 +220,7 @@ json_object_set_member (JsonObject *object,
|
||||
void
|
||||
json_object_set_int_member (JsonObject *object,
|
||||
const gchar *member_name,
|
||||
gint value)
|
||||
gint64 value)
|
||||
{
|
||||
JsonNode *node;
|
||||
|
||||
@ -381,7 +380,7 @@ json_object_set_array_member (JsonObject *object,
|
||||
* Convenience function for setting an object @value of
|
||||
* @member_name inside @object.
|
||||
*
|
||||
* The @object will take ownership of the passed #JsonArray
|
||||
* The @object will take ownership of the passed #JsonObject
|
||||
*
|
||||
* See also: json_object_set_member()
|
||||
*
|
||||
@ -397,7 +396,7 @@ json_object_set_object_member (JsonObject *object,
|
||||
g_return_if_fail (object != NULL);
|
||||
g_return_if_fail (member_name != NULL);
|
||||
|
||||
node = json_node_new (JSON_NODE_ARRAY);
|
||||
node = json_node_new (JSON_NODE_OBJECT);
|
||||
json_node_take_object (node, value);
|
||||
object_set_member_internal (object, member_name, node);
|
||||
}
|
||||
@ -521,16 +520,7 @@ static inline JsonNode *
|
||||
object_get_member_internal (JsonObject *object,
|
||||
const gchar *member_name)
|
||||
{
|
||||
JsonNode *retval;
|
||||
gchar *name;
|
||||
|
||||
name = g_strdelimit (g_strdup (member_name), G_STR_DELIMITERS, '_');
|
||||
|
||||
retval = g_hash_table_lookup (object->members, name);
|
||||
|
||||
g_free (name);
|
||||
|
||||
return retval;
|
||||
return g_hash_table_lookup (object->members, member_name);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -568,7 +558,7 @@ json_object_get_member (JsonObject *object,
|
||||
*
|
||||
* Since: 0.8
|
||||
*/
|
||||
gint
|
||||
gint64
|
||||
json_object_get_int_member (JsonObject *object,
|
||||
const gchar *member_name)
|
||||
{
|
||||
@ -776,17 +766,10 @@ gboolean
|
||||
json_object_has_member (JsonObject *object,
|
||||
const gchar *member_name)
|
||||
{
|
||||
gchar *name;
|
||||
gboolean retval;
|
||||
|
||||
g_return_val_if_fail (object != NULL, FALSE);
|
||||
g_return_val_if_fail (member_name != NULL, FALSE);
|
||||
|
||||
name = g_strdelimit (g_strdup (member_name), G_STR_DELIMITERS, '_');
|
||||
retval = (g_hash_table_lookup (object->members, name) != NULL);
|
||||
g_free (name);
|
||||
|
||||
return retval;
|
||||
return (g_hash_table_lookup (object->members, member_name) != NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -816,14 +799,10 @@ void
|
||||
json_object_remove_member (JsonObject *object,
|
||||
const gchar *member_name)
|
||||
{
|
||||
gchar *name;
|
||||
|
||||
g_return_if_fail (object != NULL);
|
||||
g_return_if_fail (member_name != NULL);
|
||||
|
||||
name = g_strdelimit (g_strdup (member_name), G_STR_DELIMITERS, '_');
|
||||
g_hash_table_remove (object->members, name);
|
||||
g_free (name);
|
||||
g_hash_table_remove (object->members, member_name);
|
||||
}
|
||||
|
||||
typedef struct _ForeachClosure ForeachClosure;
|
||||
|
@ -91,6 +91,7 @@ static const GScannerConfig json_scanner_config =
|
||||
TRUE /* char_2_token */,
|
||||
TRUE /* symbol_2_token */,
|
||||
FALSE /* scope_0_fallback */,
|
||||
TRUE /* store_int64 */
|
||||
};
|
||||
|
||||
|
||||
@ -454,8 +455,8 @@ json_parse_array (JsonParser *parser,
|
||||
{
|
||||
case G_TOKEN_INT:
|
||||
node = json_node_new (JSON_NODE_VALUE);
|
||||
json_node_set_int (node, negative ? scanner->value.v_int * -1
|
||||
: scanner->value.v_int);
|
||||
json_node_set_int (node, negative ? scanner->value.v_int64 * -1
|
||||
: scanner->value.v_int64);
|
||||
break;
|
||||
|
||||
case G_TOKEN_FLOAT:
|
||||
@ -662,8 +663,8 @@ json_parse_object (JsonParser *parser,
|
||||
{
|
||||
case G_TOKEN_INT:
|
||||
node = json_node_new (JSON_NODE_VALUE);
|
||||
json_node_set_int (node, negative ? scanner->value.v_int * -1
|
||||
: scanner->value.v_int);
|
||||
json_node_set_int (node, negative ? scanner->value.v_int64 * -1
|
||||
: scanner->value.v_int64);
|
||||
break;
|
||||
|
||||
case G_TOKEN_FLOAT:
|
||||
@ -756,7 +757,7 @@ json_parse_statement (JsonParser *parser,
|
||||
switch (token)
|
||||
{
|
||||
case G_TOKEN_INT:
|
||||
json_node_set_int (priv->current_node, scanner->value.v_int);
|
||||
json_node_set_int (priv->current_node, scanner->value.v_int64);
|
||||
break;
|
||||
case G_TOKEN_FLOAT:
|
||||
json_node_set_double (priv->current_node, scanner->value.v_float);
|
||||
@ -777,7 +778,7 @@ json_parse_statement (JsonParser *parser,
|
||||
case G_TOKEN_STRING:
|
||||
priv->root = priv->current_node = json_node_new (JSON_NODE_VALUE);
|
||||
if (token == G_TOKEN_INT)
|
||||
json_node_set_int (priv->current_node, scanner->value.v_int);
|
||||
json_node_set_int (priv->current_node, scanner->value.v_int64);
|
||||
else if (token == G_TOKEN_FLOAT)
|
||||
json_node_set_double (priv->current_node, scanner->value.v_float);
|
||||
else
|
||||
|
@ -21,6 +21,10 @@
|
||||
* Emmanuele Bassi <ebassi@linux.intel.com>
|
||||
*/
|
||||
|
||||
#if !defined(__JSON_GLIB_INSIDE__) && !defined(JSON_COMPILATION)
|
||||
#error "Only <json-glib/json-glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __JSON_TYPES_H__
|
||||
#define __JSON_TYPES_H__
|
||||
|
||||
@ -151,8 +155,8 @@ void json_node_set_string (JsonNode *node,
|
||||
G_CONST_RETURN gchar *json_node_get_string (JsonNode *node);
|
||||
gchar * json_node_dup_string (JsonNode *node);
|
||||
void json_node_set_int (JsonNode *node,
|
||||
gint value);
|
||||
gint json_node_get_int (JsonNode *node);
|
||||
gint64 value);
|
||||
gint64 json_node_get_int (JsonNode *node);
|
||||
void json_node_set_double (JsonNode *node,
|
||||
gdouble value);
|
||||
gdouble json_node_get_double (JsonNode *node);
|
||||
@ -180,7 +184,7 @@ void json_object_set_member (JsonObject *object,
|
||||
JsonNode *node);
|
||||
void json_object_set_int_member (JsonObject *object,
|
||||
const gchar *member_name,
|
||||
gint value);
|
||||
gint64 value);
|
||||
void json_object_set_double_member (JsonObject *object,
|
||||
const gchar *member_name,
|
||||
gdouble value);
|
||||
@ -203,7 +207,7 @@ JsonNode * json_object_get_member (JsonObject *object,
|
||||
const gchar *member_name);
|
||||
JsonNode * json_object_dup_member (JsonObject *object,
|
||||
const gchar *member_name);
|
||||
gint json_object_get_int_member (JsonObject *object,
|
||||
gint64 json_object_get_int_member (JsonObject *object,
|
||||
const gchar *member_name);
|
||||
gdouble json_object_get_double_member (JsonObject *object,
|
||||
const gchar *member_name);
|
||||
@ -235,7 +239,7 @@ void json_array_unref (JsonArray *array);
|
||||
void json_array_add_element (JsonArray *array,
|
||||
JsonNode *node);
|
||||
void json_array_add_int_element (JsonArray *array,
|
||||
gint value);
|
||||
gint64 value);
|
||||
void json_array_add_double_element (JsonArray *array,
|
||||
gdouble value);
|
||||
void json_array_add_boolean_element (JsonArray *array,
|
||||
@ -250,7 +254,7 @@ void json_array_add_object_element (JsonArray *array,
|
||||
GList * json_array_get_elements (JsonArray *array);
|
||||
JsonNode * json_array_get_element (JsonArray *array,
|
||||
guint index_);
|
||||
gint json_array_get_int_element (JsonArray *array,
|
||||
gint64 json_array_get_int_element (JsonArray *array,
|
||||
guint index_);
|
||||
gdouble json_array_get_double_element (JsonArray *array,
|
||||
guint index_);
|
||||
|
Loading…
Reference in New Issue
Block a user