Browse Source

Merge 3d867481e6 into 4d62de3898

pull/248/merge
Nicola Spanti GitHub 9 years ago
parent
commit
09e434d191
2 changed files with 32 additions and 17 deletions
  1. +26
    -15
      json_object.c
  2. +6
    -2
      linkhash.c

+ 26
- 15
json_object.c View File

@@ -4,10 +4,10 @@
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
* Copyright (c) 2009 Hewlett-Packard Development Company, L.P.
* Copyright (C) 2016 Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See COPYING for details.
*
*/

#include "config.h"
@@ -196,20 +196,23 @@ int json_object_put(struct json_object *jso)

static void json_object_generic_delete(struct json_object* jso)
{
if(jso != NULL)
{
#ifdef REFCOUNT_DEBUG
MC_DEBUG("json_object_delete_%s: %p\n",
json_type_to_name(jso->o_type), jso);
lh_table_delete(json_object_table, jso);
MC_DEBUG("json_object_delete_%s: %p\n",
json_type_to_name(jso->o_type), jso);
lh_table_delete(json_object_table, jso);
#endif /* REFCOUNT_DEBUG */
printbuf_free(jso->_pb);
free(jso);
printbuf_free(jso->_pb);
free(jso);
}
}

static struct json_object* json_object_new(enum json_type o_type)
{
struct json_object *jso;

jso = (struct json_object*)calloc(sizeof(struct json_object), 1);
jso = (struct json_object*) calloc(sizeof(struct json_object), 1);
if (!jso)
return NULL;
jso->o_type = o_type;
@@ -240,12 +243,15 @@ enum json_type json_object_get_type(const struct json_object *jso)
}

void* json_object_get_userdata(json_object *jso) {
return jso->_userdata;
return jso == NULL ? NULL : jso->_userdata;
}

void json_object_set_userdata(json_object *jso, void *userdata,
json_object_delete_fn *user_delete)
{
if (!jso)
return;

// First, clean up any previously existing user info
if (jso->_user_delete)
jso->_user_delete(jso, jso->_userdata);
@@ -396,8 +402,7 @@ static int json_object_object_to_json_string(struct json_object* jso,
}
if (flags & JSON_C_TO_STRING_SPACED)
return sprintbuf(pb, /*{*/ " }");
else
return sprintbuf(pb, /*{*/ "}");
return sprintbuf(pb, /*{*/ "}");
}


@@ -410,8 +415,11 @@ static void json_object_lh_entry_free(struct lh_entry *ent)

static void json_object_object_delete(struct json_object* jso)
{
lh_table_free(jso->o.c_object);
json_object_generic_delete(jso);
if(jso)
{
lh_table_free(jso->o.c_object);
json_object_generic_delete(jso);
}
}

struct json_object* json_object_new_object(void)
@@ -534,7 +542,8 @@ json_bool json_object_object_get_ex(const struct json_object* jso, const char *k

void json_object_object_del(struct json_object* jso, const char *key)
{
lh_table_delete(jso->o.c_object, key);
if(jso)
lh_table_delete(jso->o.c_object, key);
}


@@ -545,7 +554,7 @@ static int json_object_boolean_to_json_string(struct json_object* jso,
int level,
int flags)
{
if (jso->o.c_boolean)
if (jso && jso->o.c_boolean)
return sprintbuf(pb, "true");
return sprintbuf(pb, "false");
}
@@ -587,6 +596,8 @@ static int json_object_int_to_json_string(struct json_object* jso,
int level,
int flags)
{
if(!jso)
return -1;
return sprintbuf(pb, "%" PRId64, jso->o.c_int64);
}

@@ -772,7 +783,7 @@ int json_object_userdata_to_json_string(struct json_object *jso,

void json_object_free_userdata(struct json_object *jso, void *userdata)
{
free(userdata);
if(userdata) free(userdata);
}

double json_object_get_double(const struct json_object *jso)


+ 6
- 2
linkhash.c View File

@@ -4,10 +4,10 @@
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
* Copyright (c) 2009 Hewlett-Packard Development Company, L.P.
* Copyright (C) 2016 Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See COPYING for details.
*
*/

#include "config.h"
@@ -561,6 +561,8 @@ int lh_table_resize(struct lh_table *t, int new_size)

void lh_table_free(struct lh_table *t)
{
if(!t) return;
struct lh_entry *c;
if(t->free_fn) {
for(c = t->head; c != NULL; c = c->next)
@@ -611,6 +613,8 @@ int lh_table_insert(struct lh_table *t, const void *k, const void *v)

struct lh_entry* lh_table_lookup_entry_w_hash(struct lh_table *t, const void *k, const unsigned long h)
{
if(!t) return NULL;
unsigned long n = h % t->size;
int count = 0;

@@ -685,5 +689,5 @@ int lh_table_delete(struct lh_table *t, const void *k)

int lh_table_length(struct lh_table *t)
{
return t->count;
return t == NULL ? -1 : t->count;
}

Loading…
Cancel
Save