*
* Jansson is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#define _GNU_SOURCE
*
* Jansson is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#define _GNU_SOURCE
an object_key_t instance. */
#define string_to_key(string) container_of(string, object_key_t, key)
an object_key_t instance. */
#define string_to_key(string) container_of(string, object_key_t, key)
{
return strcmp(((const object_key_t *)ptr1)->key,
((const object_key_t *)ptr2)->key) == 0;
{
return strcmp(((const object_key_t *)ptr1)->key,
((const object_key_t *)ptr2)->key) == 0;
- if(hashtable_init(&object->hashtable, hash_key, key_equal,
- free, value_decref))
+ if(hashtable_init(&object->hashtable,
+ jsonp_hash_key, jsonp_key_equal,
+ jsonp_free, value_decref))
- k = malloc(sizeof(object_key_t) + strlen(key) + 1);
+ /* offsetof(...) returns the size of object_key_t without the
+ last, flexible member. This way, the correct amount is
+ allocated. */
+ k = jsonp_malloc(offsetof(object_key_t, key) + strlen(key) + 1);
-static void array_move(json_array_t *array, unsigned int dest,
- unsigned int src, unsigned int count)
+static void array_move(json_array_t *array, size_t dest,
+ size_t src, size_t count)
-static void array_copy(json_t **dest, unsigned int dpos,
- json_t **src, unsigned int spos,
- unsigned int count)
+static void array_copy(json_t **dest, size_t dpos,
+ json_t **src, size_t spos,
+ size_t count)
{
memcpy(&dest[dpos], &src[spos], count * sizeof(json_t *));
}
static json_t **json_array_grow(json_array_t *array,
{
memcpy(&dest[dpos], &src[spos], count * sizeof(json_t *));
}
static json_t **json_array_grow(json_array_t *array,
json_t **old_table, **new_table;
if(array->entries + amount <= array->size)
json_t **old_table, **new_table;
if(array->entries + amount <= array->size)
old_table = array->table;
new_size = max(array->size + amount, array->size * 2);
old_table = array->table;
new_size = max(array->size + amount, array->size * 2);
if(copy) {
array_copy(array->table, 0, old_table, 0, array->entries);
if(copy) {
array_copy(array->table, 0, old_table, 0, array->entries);
array_copy(array->table, 0, old_table, 0, index);
array_copy(array->table, index + 1, old_table, index,
array->entries - index);
array_copy(array->table, 0, old_table, 0, index);
array_copy(array->table, index + 1, old_table, index,
array->entries - index);
}
else
array_move(array, index + 1, index, array->entries - index);
}
else
array_move(array, index + 1, index, array->entries - index);
int json_array_extend(json_t *json, json_t *other_json)
{
json_array_t *array, *other;
int json_array_extend(json_t *json, json_t *other_json)
{
json_array_t *array, *other;