2.replace json_object_get/put API with json_object_retain/release, as they operate the reference counter, and confused with array_list_get/put_idx.
3.replace array_list_get/put_idx API with array_list_get/insert to make them more clear to use.
./linkhash.h
./math_compat.h
./strdup_compat.h
+ ./strerror_override.h
+ ./strerror_override_private
./vasprintf_compat.h
./printbuf.h
./random_seed.h
./json_util.c
./linkhash.c
./printbuf.c
+ ./strerror_override.c
./random_seed.c
)
}
void*
-array_list_get_idx(struct array_list *arr, size_t i)
+array_list_get(struct array_list *arr, size_t i)
{
if(i >= arr->length) return NULL;
return arr->array[i];
}
int
-array_list_put_idx(struct array_list *arr, size_t idx, void *data)
+array_list_insert(struct array_list *arr, size_t idx, void *data)
{
if (idx > SIZE_T_MAX - 1 ) return -1;
if(array_list_expand_internal(arr, idx+1)) return -1;
int
array_list_add(struct array_list *arr, void *data)
{
- return array_list_put_idx(arr, arr->length, data);
+ return array_list_insert(arr, arr->length, data);
}
void
array_list_free(struct array_list *al);
extern void*
-array_list_get_idx(struct array_list *al, size_t i);
+array_list_get(struct array_list *al, size_t i);
extern int
-array_list_put_idx(struct array_list *al, size_t i, void *data);
+array_list_insert(struct array_list *al, size_t i, void *data);
extern int
array_list_add(struct array_list *al, void *data);
/* reference counting */
-extern struct json_object* json_object_get(struct json_object *jso)
+extern struct json_object* json_object_retain(struct json_object *jso)
{
if (jso)
jso->_ref_count++;
return jso;
}
-int json_object_put(struct json_object *jso)
+int json_object_release(struct json_object *jso)
{
if(jso)
{
{
if (!ent->k_is_constant)
free(lh_entry_k(ent));
- json_object_put((struct json_object*)lh_entry_v(ent));
+ json_object_release((struct json_object*)lh_entry_v(ent));
}
static void json_object_object_delete(struct json_object* jso)
struct json_object *const val,
const unsigned opts)
{
+ struct json_object *existing_value = NULL;
+ struct lh_entry *existing_entry;
+ unsigned long hash;
+
assert(json_object_get_type(jso) == json_type_object);
// We lookup the entry and replace the value, rather than just deleting
// and re-adding it, so the existing key remains valid.
- json_object *existing_value = NULL;
- struct lh_entry *existing_entry;
- const unsigned long hash = lh_get_hash(jso->o.c_object, (const void *)key);
+ hash = lh_get_hash(jso->o.c_object, (const void *)key);
existing_entry = (opts & JSON_C_OBJECT_ADD_KEY_IS_NEW) ? NULL :
lh_table_lookup_entry_w_hash(jso->o.c_object,
(const void *)key, hash);
}
existing_value = (json_object *) lh_entry_v(existing_entry);
if (existing_value)
- json_object_put(existing_value);
+ json_object_release(existing_value);
existing_entry->v = val;
return 0;
}
struct json_object* json_object_new_double_s(double d, const char *ds)
{
+ char *new_ds;
struct json_object *jso = json_object_new_double(d);
if (!jso)
return NULL;
- char *new_ds = strdup(ds);
+ new_ds = strdup(ds);
if (!new_ds)
{
json_object_generic_delete(jso);
}
int json_object_set_string_len(json_object* jso, const char* s, int len){
- if (jso==NULL || jso->o_type!=json_type_string) return 0;
char *dstbuf;
+ if (jso==NULL || jso->o_type!=json_type_string) return 0;
if (len<LEN_DIRECT_STRING_DATA) {
dstbuf=jso->o.c_string.str.data;
if (jso->o.c_string.len>=LEN_DIRECT_STRING_DATA) free(jso->o.c_string.str.ptr);
static void json_object_array_entry_free(void *data)
{
- json_object_put((struct json_object*)data);
+ json_object_release((struct json_object*)data);
}
static void json_object_array_delete(struct json_object* jso)
struct json_object *val)
{
assert(json_object_get_type(jso) == json_type_array);
- return array_list_put_idx(jso->o.c_array, idx, val);
+ return array_list_insert(jso->o.c_array, idx, val);
}
int json_object_array_del_idx(struct json_object *jso, size_t idx, size_t count)
size_t idx)
{
assert(json_object_get_type(jso) == json_type_array);
- return (struct json_object*)array_list_get_idx(jso->o.c_array, idx);
+ return (struct json_object*)array_list_get(jso->o.c_array, idx);
}
static int json_array_equal(struct json_object* jso1,
*
* @param obj the json_object instance
*/
-JSON_EXPORT struct json_object* json_object_get(struct json_object *obj);
+JSON_EXPORT struct json_object* json_object_retain(struct json_object *obj);
/**
* Decrement the reference count of json_object and free if it reaches zero.
* @param obj the json_object instance
* @returns 1 if the object was freed.
*/
-JSON_EXPORT int json_object_put(struct json_object *obj);
+JSON_EXPORT int json_object_release(struct json_object *obj);
/**
* Check if the json_object is of a given type
}
if (path[0] == '\0') {
- json_object_put(*obj);
+ json_object_release(*obj);
*obj = value;
return 0;
}
return rc;
if (path_copy[0] == '\0') {
- json_object_put(*obj);
+ json_object_release(*obj);
*obj = value;
goto out;
}
{
tok->stack[depth].state = json_tokener_state_eatws;
tok->stack[depth].saved_state = json_tokener_state_start;
- json_object_put(tok->stack[depth].current);
+ json_object_release(tok->stack[depth].current);
tok->stack[depth].current = NULL;
free(tok->stack[depth].obj_field_name);
tok->stack[depth].obj_field_name = NULL;
*error = tok->err;
if(tok->err != json_tokener_success) {
if (obj != NULL)
- json_object_put(obj);
+ json_object_release(obj);
obj = NULL;
}
case json_tokener_state_finish:
if(tok->depth == 0) goto out;
- obj = json_object_get(current);
+ obj = json_object_retain(current);
json_tokener_reset_level(tok, tok->depth);
tok->depth--;
goto redo_char;
{
size_t size_inf;
int is_negative = 0;
+ char *infbuf;
printbuf_memappend_fast(tok->pb, &c, 1);
size_inf = json_min(tok->st_pos+1, json_inf_str_len);
- char *infbuf = tok->pb->buf;
+ infbuf = tok->pb->buf;
if (*infbuf == '-')
{
infbuf++;
if (tok->err == json_tokener_success)
{
- json_object *ret = json_object_get(current);
+ json_object *ret = json_object_retain(current);
int ii;
/* Partially reset, so we parse additional objects on subsequent calls. */
return 0;
}
+unsigned long lh_get_hash(const struct lh_table *t, const void *k)
+{
+ return t->hash_fn(k);
+}
+
void lh_table_free(struct lh_table *t)
{
struct lh_entry *c;
* @param k a pointer to the key to lookup
* @return the key's hash
*/
-static inline unsigned long lh_get_hash(const struct lh_table *t, const void *k)
-{
- return t->hash_fn(k);
-}
+unsigned long lh_get_hash(const struct lh_table *t, const void *k);
/* Don't use this outside of linkhash.h: */
#ifdef __UNCONST
static int get_cryptgenrandom_seed()
{
- DEBUG_SEED("get_cryptgenrandom_seed");
-
HCRYPTPROV hProvider = 0;
int r;
+ DEBUG_SEED("get_cryptgenrandom_seed");
+
if (!CryptAcquireContextW(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
fprintf(stderr, "error CryptAcquireContextW");
exit(1);