mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_json_object_unref(o);
|
pa_json_object_free(o);
|
||||||
return type;
|
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) {
|
if (pa_json_object_get_type(o) != PA_JSON_TYPE_INT) {
|
||||||
pa_log_debug("Format info property '%s' type is not int.", key);
|
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;
|
return -PA_ERR_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
*v = pa_json_object_get_int(o);
|
*v = pa_json_object_get_int(o);
|
||||||
pa_json_object_unref(o);
|
pa_json_object_free(o);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -376,7 +376,7 @@ out:
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
pa_log_debug("Format info property '%s' is not a valid int range.", key);
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -423,7 +423,7 @@ out:
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
pa_log_debug("Format info property '%s' is not a valid int array.", key);
|
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;
|
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) {
|
if (pa_json_object_get_type(o) != PA_JSON_TYPE_STRING) {
|
||||||
pa_log_debug("Format info property '%s' type is not string.", key);
|
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;
|
return -PA_ERR_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
*v = pa_xstrdup(pa_json_object_get_string(o));
|
*v = pa_xstrdup(pa_json_object_get_string(o));
|
||||||
pa_json_object_unref(o);
|
pa_json_object_free(o);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -500,7 +500,7 @@ out:
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
pa_log_debug("Format info property '%s' is not a valid string array.", key);
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -675,9 +675,9 @@ static int pa_format_info_prop_compatible(const char *one, const char *two) {
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (o1)
|
if (o1)
|
||||||
pa_json_object_unref(o1);
|
pa_json_object_free(o1);
|
||||||
if (o2)
|
if (o2)
|
||||||
pa_json_object_unref(o2);
|
pa_json_object_free(o2);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,13 +27,11 @@
|
||||||
#include <pulse/xmalloc.h>
|
#include <pulse/xmalloc.h>
|
||||||
#include <pulsecore/core-util.h>
|
#include <pulsecore/core-util.h>
|
||||||
#include <pulsecore/hashmap.h>
|
#include <pulsecore/hashmap.h>
|
||||||
#include <pulsecore/refcnt.h>
|
|
||||||
#include <pulsecore/strbuf.h>
|
#include <pulsecore/strbuf.h>
|
||||||
|
|
||||||
#define MAX_NESTING_DEPTH 20 /* Arbitrary number to make sure we don't have a stack overflow */
|
#define MAX_NESTING_DEPTH 20 /* Arbitrary number to make sure we don't have a stack overflow */
|
||||||
|
|
||||||
struct pa_json_object {
|
struct pa_json_object {
|
||||||
PA_REFCNT_DECLARE;
|
|
||||||
pa_json_type type;
|
pa_json_type type;
|
||||||
|
|
||||||
union {
|
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;
|
pa_json_object *name = NULL, *value = NULL;
|
||||||
|
|
||||||
obj->object_values = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func,
|
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 != '}') {
|
while (*str != '}') {
|
||||||
str++; /* Consume leading '{' or ',' */
|
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_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;
|
name = NULL;
|
||||||
value = NULL;
|
value = NULL;
|
||||||
|
|
@ -349,9 +347,9 @@ error:
|
||||||
obj->object_values = NULL;
|
obj->object_values = NULL;
|
||||||
|
|
||||||
if (name)
|
if (name)
|
||||||
pa_json_object_unref(name);
|
pa_json_object_free(name);
|
||||||
if (value)
|
if (value)
|
||||||
pa_json_object_unref(value);
|
pa_json_object_free(value);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -390,7 +388,7 @@ static const char *parse_array(const char *str, pa_json_object *obj, unsigned in
|
||||||
return str;
|
return str;
|
||||||
|
|
||||||
error:
|
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;
|
obj->array_values = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -467,7 +465,7 @@ static const char* parse_value(const char *str, const char *end, pa_json_object
|
||||||
return str;
|
return str;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
pa_json_object_unref(o);
|
pa_json_object_free(o);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -484,7 +482,7 @@ pa_json_object* pa_json_parse(const char *str) {
|
||||||
|
|
||||||
if (*str != '\0') {
|
if (*str != '\0') {
|
||||||
pa_log("Unable to parse complete JSON string, remainder is: %s", str);
|
pa_log("Unable to parse complete JSON string, remainder is: %s", str);
|
||||||
pa_json_object_unref(obj);
|
pa_json_object_free(obj);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -495,9 +493,7 @@ pa_json_type pa_json_object_get_type(const pa_json_object *obj) {
|
||||||
return obj->type;
|
return obj->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pa_json_object_unref(pa_json_object *obj) {
|
void pa_json_object_free(pa_json_object *obj) {
|
||||||
if (PA_REFCNT_DEC(obj) > 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (pa_json_object_get_type(obj)) {
|
switch (pa_json_object_get_type(obj)) {
|
||||||
case PA_JSON_TYPE_INIT:
|
case PA_JSON_TYPE_INIT:
|
||||||
|
|
@ -516,7 +512,7 @@ void pa_json_object_unref(pa_json_object *obj) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PA_JSON_TYPE_ARRAY:
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ typedef struct pa_json_object pa_json_object;
|
||||||
|
|
||||||
pa_json_object* pa_json_parse(const char *str);
|
pa_json_object* pa_json_parse(const char *str);
|
||||||
pa_json_type pa_json_object_get_type(const pa_json_object *obj);
|
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 */
|
/* 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_json_object_get_type(o) == PA_JSON_TYPE_STRING);
|
||||||
fail_unless(pa_streq(pa_json_object_get_string(o), strings_compare[i]));
|
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
|
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_type(o) == PA_JSON_TYPE_INT);
|
||||||
fail_unless(pa_json_object_get_int(o) == ints_compare[i]);
|
fail_unless(pa_json_object_get_int(o) == ints_compare[i]);
|
||||||
|
|
||||||
pa_json_object_unref(o);
|
pa_json_object_free(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END_TEST
|
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_json_object_get_type(o) == PA_JSON_TYPE_DOUBLE);
|
||||||
fail_unless(PA_DOUBLE_IS_EQUAL(pa_json_object_get_double(o), doubles_compare[i]));
|
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
|
END_TEST
|
||||||
|
|
@ -98,7 +98,7 @@ START_TEST(null_test) {
|
||||||
fail_unless(o != NULL);
|
fail_unless(o != NULL);
|
||||||
fail_unless(pa_json_object_get_type(o) == PA_JSON_TYPE_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
|
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_type(o) == PA_JSON_TYPE_BOOL);
|
||||||
fail_unless(pa_json_object_get_bool(o) == true);
|
fail_unless(pa_json_object_get_bool(o) == true);
|
||||||
|
|
||||||
pa_json_object_unref(o);
|
pa_json_object_free(o);
|
||||||
|
|
||||||
o = pa_json_parse("false");
|
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_type(o) == PA_JSON_TYPE_BOOL);
|
||||||
fail_unless(pa_json_object_get_bool(o) == false);
|
fail_unless(pa_json_object_get_bool(o) == false);
|
||||||
|
|
||||||
pa_json_object_unref(o);
|
pa_json_object_free(o);
|
||||||
}
|
}
|
||||||
END_TEST
|
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_json_object_get_type(v) == PA_JSON_TYPE_STRING);
|
||||||
fail_unless(pa_streq(pa_json_object_get_string(v), "A Person"));
|
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 } ");
|
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_json_object_get_type(v) == PA_JSON_TYPE_DOUBLE);
|
||||||
fail_unless(PA_DOUBLE_IS_EQUAL(pa_json_object_get_double(v), -45.3));
|
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}");
|
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_type(v) == PA_JSON_TYPE_BOOL);
|
||||||
fail_unless(pa_json_object_get_bool(v) == true);
|
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 } }");
|
o = pa_json_parse("{ \"parent\": { \"child\": false } }");
|
||||||
fail_unless(o != NULL);
|
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_type(v) == PA_JSON_TYPE_BOOL);
|
||||||
fail_unless(pa_json_object_get_bool(v) == false);
|
fail_unless(pa_json_object_get_bool(v) == false);
|
||||||
|
|
||||||
pa_json_object_unref(o);
|
pa_json_object_free(o);
|
||||||
}
|
}
|
||||||
END_TEST
|
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_type(o) == PA_JSON_TYPE_ARRAY);
|
||||||
fail_unless(pa_json_object_get_array_length(o) == 0);
|
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\"]");
|
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_json_object_get_type(v) == PA_JSON_TYPE_STRING);
|
||||||
fail_unless(pa_streq(pa_json_object_get_string(v), "a member"));
|
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 } ]");
|
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_type(v2) == PA_JSON_TYPE_BOOL);
|
||||||
fail_unless(pa_json_object_get_bool(v2) == true);
|
fail_unless(pa_json_object_get_bool(v2) == true);
|
||||||
|
|
||||||
pa_json_object_unref(o);
|
pa_json_object_free(o);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue