summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Raghavan <arun@arunraghavan.net>2016-06-01 16:48:48 +0530
committerArun Raghavan <arun@arunraghavan.net>2016-06-01 18:13:55 +0530
commit76ec93feee625003a509bc823518df7a7d966d6d (patch)
tree1b24ddf218195dc476169575932c70221c14cefb
parent544644417ba36792c7edb7a35d79457955c0846e (diff)
json: Drop refcounting of json objectsjson
We don't actually use the refcounting bits. Signed-off-by: Arun Raghavan <arun@arunraghavan.net>
-rw-r--r--src/pulse/format.c20
-rw-r--r--src/pulse/json.c18
-rw-r--r--src/pulse/json.h2
-rw-r--r--src/tests/json-test.c26
4 files changed, 31 insertions, 35 deletions
diff --git a/src/pulse/format.c b/src/pulse/format.c
index ee8b7ac1c..8474978d5 100644
--- a/src/pulse/format.c
+++ b/src/pulse/format.c
@@ -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;
}
diff --git a/src/pulse/json.c b/src/pulse/json.c
index 60c4cd1b5..15526e787 100644
--- a/src/pulse/json.c
+++ b/src/pulse/json.c
@@ -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;
@@ -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:
diff --git a/src/pulse/json.h b/src/pulse/json.h
index d8a946f4c..7759bf2db 100644
--- a/src/pulse/json.h
+++ b/src/pulse/json.h
@@ -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 */
diff --git a/src/tests/json-test.c b/src/tests/json-test.c
index 08b2ff6e8..3e956dbad 100644
--- a/src/tests/json-test.c
+++ b/src/tests/json-test.c
@@ -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