mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	json: Drop refcounting of json objects
We don't actually use the refcounting bits. Signed-off-by: Arun Raghavan <arun@arunraghavan.net>
This commit is contained in:
		
							parent
							
								
									8f45d83bdb
								
							
						
					
					
						commit
						e3148f9ac2
					
				
					 4 changed files with 33 additions and 37 deletions
				
			
		| 
						 | 
				
			
			@ -300,7 +300,7 @@ pa_prop_type_t pa_format_info_get_prop_type(const pa_format_info *f, const char
 | 
			
		|||
            break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
    return type;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -324,12 +324,12 @@ int pa_format_info_get_prop_int(const pa_format_info *f, const char *key, int *v
 | 
			
		|||
 | 
			
		||||
    if (pa_json_object_get_type(o) != PA_JSON_TYPE_INT) {
 | 
			
		||||
        pa_log_debug("Format info property '%s' type is not int.", key);
 | 
			
		||||
        pa_json_object_unref(o);
 | 
			
		||||
        pa_json_object_free(o);
 | 
			
		||||
        return -PA_ERR_INVALID;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    *v = pa_json_object_get_int(o);
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -376,7 +376,7 @@ out:
 | 
			
		|||
    if (ret < 0)
 | 
			
		||||
        pa_log_debug("Format info property '%s' is not a valid int range.", key);
 | 
			
		||||
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -423,7 +423,7 @@ out:
 | 
			
		|||
    if (ret < 0)
 | 
			
		||||
        pa_log_debug("Format info property '%s' is not a valid int array.", key);
 | 
			
		||||
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -447,12 +447,12 @@ int pa_format_info_get_prop_string(const pa_format_info *f, const char *key, cha
 | 
			
		|||
 | 
			
		||||
    if (pa_json_object_get_type(o) != PA_JSON_TYPE_STRING) {
 | 
			
		||||
        pa_log_debug("Format info property '%s' type is not string.", key);
 | 
			
		||||
        pa_json_object_unref(o);
 | 
			
		||||
        pa_json_object_free(o);
 | 
			
		||||
        return -PA_ERR_INVALID;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    *v = pa_xstrdup(pa_json_object_get_string(o));
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -500,7 +500,7 @@ out:
 | 
			
		|||
    if (ret < 0)
 | 
			
		||||
        pa_log_debug("Format info property '%s' is not a valid string array.", key);
 | 
			
		||||
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -675,9 +675,9 @@ static int pa_format_info_prop_compatible(const char *one, const char *two) {
 | 
			
		|||
 | 
			
		||||
out:
 | 
			
		||||
    if (o1)
 | 
			
		||||
        pa_json_object_unref(o1);
 | 
			
		||||
        pa_json_object_free(o1);
 | 
			
		||||
    if (o2)
 | 
			
		||||
        pa_json_object_unref(o2);
 | 
			
		||||
        pa_json_object_free(o2);
 | 
			
		||||
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,13 +27,11 @@
 | 
			
		|||
#include <pulse/xmalloc.h>
 | 
			
		||||
#include <pulsecore/core-util.h>
 | 
			
		||||
#include <pulsecore/hashmap.h>
 | 
			
		||||
#include <pulsecore/refcnt.h>
 | 
			
		||||
#include <pulsecore/strbuf.h>
 | 
			
		||||
 | 
			
		||||
#define MAX_NESTING_DEPTH 20 /* Arbitrary number to make sure we don't have a stack overflow */
 | 
			
		||||
 | 
			
		||||
struct pa_json_object {
 | 
			
		||||
    PA_REFCNT_DECLARE;
 | 
			
		||||
    pa_json_type type;
 | 
			
		||||
 | 
			
		||||
    union {
 | 
			
		||||
| 
						 | 
				
			
			@ -309,7 +307,7 @@ static const char *parse_object(const char *str, pa_json_object *obj, unsigned i
 | 
			
		|||
    pa_json_object *name = NULL, *value = NULL;
 | 
			
		||||
 | 
			
		||||
    obj->object_values = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func,
 | 
			
		||||
                                             pa_xfree, (pa_free_cb_t) pa_json_object_unref);
 | 
			
		||||
                                             pa_xfree, (pa_free_cb_t) pa_json_object_free);
 | 
			
		||||
 | 
			
		||||
    while (*str != '}') {
 | 
			
		||||
        str++; /* Consume leading '{' or ',' */
 | 
			
		||||
| 
						 | 
				
			
			@ -330,7 +328,7 @@ static const char *parse_object(const char *str, pa_json_object *obj, unsigned i
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
        pa_hashmap_put(obj->object_values, pa_xstrdup(pa_json_object_get_string(name)), value);
 | 
			
		||||
        pa_json_object_unref(name);
 | 
			
		||||
        pa_json_object_free(name);
 | 
			
		||||
 | 
			
		||||
        name = NULL;
 | 
			
		||||
        value = NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -349,9 +347,9 @@ error:
 | 
			
		|||
    obj->object_values = NULL;
 | 
			
		||||
 | 
			
		||||
    if (name)
 | 
			
		||||
        pa_json_object_unref(name);
 | 
			
		||||
        pa_json_object_free(name);
 | 
			
		||||
    if (value)
 | 
			
		||||
        pa_json_object_unref(value);
 | 
			
		||||
        pa_json_object_free(value);
 | 
			
		||||
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -390,7 +388,7 @@ static const char *parse_array(const char *str, pa_json_object *obj, unsigned in
 | 
			
		|||
    return str;
 | 
			
		||||
 | 
			
		||||
error:
 | 
			
		||||
    pa_idxset_free(obj->array_values, (pa_free_cb_t) pa_json_object_unref);
 | 
			
		||||
    pa_idxset_free(obj->array_values, (pa_free_cb_t) pa_json_object_free);
 | 
			
		||||
    obj->array_values = NULL;
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -467,7 +465,7 @@ static const char* parse_value(const char *str, const char *end, pa_json_object
 | 
			
		|||
    return str;
 | 
			
		||||
 | 
			
		||||
error:
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -484,7 +482,7 @@ pa_json_object* pa_json_parse(const char *str) {
 | 
			
		|||
 | 
			
		||||
    if (*str != '\0') {
 | 
			
		||||
        pa_log("Unable to parse complete JSON string, remainder is: %s", str);
 | 
			
		||||
        pa_json_object_unref(obj);
 | 
			
		||||
        pa_json_object_free(obj);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -495,9 +493,7 @@ pa_json_type pa_json_object_get_type(const pa_json_object *obj) {
 | 
			
		|||
    return obj->type;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void pa_json_object_unref(pa_json_object *obj) {
 | 
			
		||||
    if (PA_REFCNT_DEC(obj) > 0)
 | 
			
		||||
        return;
 | 
			
		||||
void pa_json_object_free(pa_json_object *obj) {
 | 
			
		||||
 | 
			
		||||
    switch (pa_json_object_get_type(obj)) {
 | 
			
		||||
        case PA_JSON_TYPE_INIT:
 | 
			
		||||
| 
						 | 
				
			
			@ -516,7 +512,7 @@ void pa_json_object_unref(pa_json_object *obj) {
 | 
			
		|||
            break;
 | 
			
		||||
 | 
			
		||||
        case PA_JSON_TYPE_ARRAY:
 | 
			
		||||
            pa_idxset_free(obj->array_values, (pa_free_cb_t) pa_json_object_unref);
 | 
			
		||||
            pa_idxset_free(obj->array_values, (pa_free_cb_t) pa_json_object_free);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        default:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -36,7 +36,7 @@ typedef struct pa_json_object pa_json_object;
 | 
			
		|||
 | 
			
		||||
pa_json_object* pa_json_parse(const char *str);
 | 
			
		||||
pa_json_type pa_json_object_get_type(const pa_json_object *obj);
 | 
			
		||||
void pa_json_object_unref(pa_json_object *obj);
 | 
			
		||||
void pa_json_object_free(pa_json_object *obj);
 | 
			
		||||
 | 
			
		||||
/* All pointer members that are returned are valid while the corresponding object is valid */
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,7 +45,7 @@ START_TEST (string_test) {
 | 
			
		|||
        fail_unless(pa_json_object_get_type(o) == PA_JSON_TYPE_STRING);
 | 
			
		||||
        fail_unless(pa_streq(pa_json_object_get_string(o), strings_compare[i]));
 | 
			
		||||
 | 
			
		||||
        pa_json_object_unref(o);
 | 
			
		||||
        pa_json_object_free(o);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
END_TEST
 | 
			
		||||
| 
						 | 
				
			
			@ -63,7 +63,7 @@ START_TEST(int_test) {
 | 
			
		|||
        fail_unless(pa_json_object_get_type(o) == PA_JSON_TYPE_INT);
 | 
			
		||||
        fail_unless(pa_json_object_get_int(o) == ints_compare[i]);
 | 
			
		||||
 | 
			
		||||
        pa_json_object_unref(o);
 | 
			
		||||
        pa_json_object_free(o);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
END_TEST
 | 
			
		||||
| 
						 | 
				
			
			@ -85,7 +85,7 @@ START_TEST(double_test) {
 | 
			
		|||
        fail_unless(pa_json_object_get_type(o) == PA_JSON_TYPE_DOUBLE);
 | 
			
		||||
        fail_unless(PA_DOUBLE_IS_EQUAL(pa_json_object_get_double(o), doubles_compare[i]));
 | 
			
		||||
 | 
			
		||||
        pa_json_object_unref(o);
 | 
			
		||||
        pa_json_object_free(o);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
END_TEST
 | 
			
		||||
| 
						 | 
				
			
			@ -98,7 +98,7 @@ START_TEST(null_test) {
 | 
			
		|||
    fail_unless(o != NULL);
 | 
			
		||||
    fail_unless(pa_json_object_get_type(o) == PA_JSON_TYPE_NULL);
 | 
			
		||||
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
}
 | 
			
		||||
END_TEST
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -111,7 +111,7 @@ START_TEST(bool_test) {
 | 
			
		|||
    fail_unless(pa_json_object_get_type(o) == PA_JSON_TYPE_BOOL);
 | 
			
		||||
    fail_unless(pa_json_object_get_bool(o) == true);
 | 
			
		||||
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
 | 
			
		||||
    o = pa_json_parse("false");
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -119,7 +119,7 @@ START_TEST(bool_test) {
 | 
			
		|||
    fail_unless(pa_json_object_get_type(o) == PA_JSON_TYPE_BOOL);
 | 
			
		||||
    fail_unless(pa_json_object_get_bool(o) == false);
 | 
			
		||||
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
}
 | 
			
		||||
END_TEST
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -137,7 +137,7 @@ START_TEST(object_test) {
 | 
			
		|||
    fail_unless(pa_json_object_get_type(v) == PA_JSON_TYPE_STRING);
 | 
			
		||||
    fail_unless(pa_streq(pa_json_object_get_string(v), "A Person"));
 | 
			
		||||
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
 | 
			
		||||
    o = pa_json_parse(" { \"age\" : -45.3e-0 } ");
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -149,7 +149,7 @@ START_TEST(object_test) {
 | 
			
		|||
    fail_unless(pa_json_object_get_type(v) == PA_JSON_TYPE_DOUBLE);
 | 
			
		||||
    fail_unless(PA_DOUBLE_IS_EQUAL(pa_json_object_get_double(v), -45.3));
 | 
			
		||||
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
 | 
			
		||||
    o = pa_json_parse("{\"person\":true}");
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -161,7 +161,7 @@ START_TEST(object_test) {
 | 
			
		|||
    fail_unless(pa_json_object_get_type(v) == PA_JSON_TYPE_BOOL);
 | 
			
		||||
    fail_unless(pa_json_object_get_bool(v) == true);
 | 
			
		||||
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
 | 
			
		||||
    o = pa_json_parse("{ \"parent\": { \"child\": false } }");
 | 
			
		||||
    fail_unless(o != NULL);
 | 
			
		||||
| 
						 | 
				
			
			@ -174,7 +174,7 @@ START_TEST(object_test) {
 | 
			
		|||
    fail_unless(pa_json_object_get_type(v) == PA_JSON_TYPE_BOOL);
 | 
			
		||||
    fail_unless(pa_json_object_get_bool(v) == false);
 | 
			
		||||
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
}
 | 
			
		||||
END_TEST
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -188,7 +188,7 @@ START_TEST(array_test) {
 | 
			
		|||
    fail_unless(pa_json_object_get_type(o) == PA_JSON_TYPE_ARRAY);
 | 
			
		||||
    fail_unless(pa_json_object_get_array_length(o) == 0);
 | 
			
		||||
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
 | 
			
		||||
    o = pa_json_parse("[\"a member\"]");
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -201,7 +201,7 @@ START_TEST(array_test) {
 | 
			
		|||
    fail_unless(pa_json_object_get_type(v) == PA_JSON_TYPE_STRING);
 | 
			
		||||
    fail_unless(pa_streq(pa_json_object_get_string(v), "a member"));
 | 
			
		||||
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
 | 
			
		||||
    o = pa_json_parse("[\"a member\", 1234.5, { \"another\": true } ]");
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -225,7 +225,7 @@ START_TEST(array_test) {
 | 
			
		|||
    fail_unless(pa_json_object_get_type(v2) == PA_JSON_TYPE_BOOL);
 | 
			
		||||
    fail_unless(pa_json_object_get_bool(v2) == true);
 | 
			
		||||
 | 
			
		||||
    pa_json_object_unref(o);
 | 
			
		||||
    pa_json_object_free(o);
 | 
			
		||||
}
 | 
			
		||||
END_TEST
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue