const char *json_number_chars = "0123456789.+-eE";
const char *json_hex_chars = "0123456789abcdefABCDEF";
-static void json_object_generic_delete(struct json_object* jso);
static struct json_object* json_object_new(enum json_type o_type);
static json_object_to_json_string_fn json_object_object_to_json_string;
static json_object_to_json_string_fn json_object_string_to_json_string;
static json_object_to_json_string_fn json_object_array_to_json_string;
+typedef void (json_object_private_delete_fn)(struct json_object *o);
+
+static json_object_private_delete_fn json_object_string_delete;
+static json_object_private_delete_fn json_object_array_delete;
+static json_object_private_delete_fn json_object_object_delete;
+static json_object_private_delete_fn json_object_generic_delete;
/* ref count debugging */
if (jso->_user_delete)
jso->_user_delete(jso, jso->_userdata);
- jso->_delete(jso);
+
+ if (jso->o_type == json_type_string)
+ json_object_string_delete(jso);
+ else if (jso->o_type == json_type_array)
+ json_object_array_delete(jso);
+ else if (jso->o_type == json_type_object)
+ json_object_object_delete(jso);
+ else
+ json_object_generic_delete(jso);
+
return 1;
}
return NULL;
jso->o_type = o_type;
jso->_ref_count = 1;
- jso->_delete = &json_object_generic_delete;
#ifdef REFCOUNT_DEBUG
lh_table_insert(json_object_table, jso, jso);
MC_DEBUG("json_object_new_%s: %p\n", json_type_to_name(jso->o_type), jso);
struct json_object *jso = json_object_new(json_type_object);
if (!jso)
return NULL;
- jso->_delete = &json_object_object_delete;
jso->_to_json_string = &json_object_object_to_json_string;
jso->o.c_object = lh_kchar_table_new(JSON_OBJECT_DEF_HASH_ENTRIES,
&json_object_lh_entry_free);
struct json_object *jso = json_object_new(json_type_string);
if (!jso)
return NULL;
- jso->_delete = &json_object_string_delete;
jso->_to_json_string = &json_object_string_to_json_string;
jso->o.c_string.len = strlen(s);
if(jso->o.c_string.len < LEN_DIRECT_STRING_DATA) {
struct json_object *jso = json_object_new(json_type_string);
if (!jso)
return NULL;
- jso->_delete = &json_object_string_delete;
jso->_to_json_string = &json_object_string_to_json_string;
if(len < LEN_DIRECT_STRING_DATA) {
dstbuf = jso->o.c_string.str.data;
struct json_object *jso = json_object_new(json_type_array);
if (!jso)
return NULL;
- jso->_delete = &json_object_array_delete;
jso->_to_json_string = &json_object_array_to_json_string;
jso->o.c_array = array_list_new(&json_object_array_entry_free);
if(jso->o.c_array == NULL)