From c08c805ecd8f2000a35cdeae7b16244d0b3c0528 Mon Sep 17 00:00:00 2001 From: Björn Esser Date: Thu, 14 Dec 2017 01:30:54 +0100 Subject: Adaptions for API change in json-c v0.13 Lift restriction on json-c <= 0.12.1 ipc-server: Acquire ownership of referenced json_object properly When adding a referenced json_object with an unknown lifetime to another json_object, it must be done with a wrapped call to json_object_get() to acquire the ownership of that json_object. --- swaygrab/json.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'swaygrab/json.c') diff --git a/swaygrab/json.c b/swaygrab/json.c index 286085c3..f0e8fa90 100644 --- a/swaygrab/json.c +++ b/swaygrab/json.c @@ -50,8 +50,7 @@ static json_object *get_focused_container_r(json_object *c) { } else { json_object *nodes, *node, *child; json_object_object_get_ex(c, "nodes", &nodes); - int i; - for (i = 0; i < json_object_array_length(nodes); i++) { + for (json_ar_len_t i = 0; i < json_object_array_length(nodes); i++) { node = json_object_array_get_idx(nodes, i); if ((child = get_focused_container_r(node))) { @@ -60,7 +59,7 @@ static json_object *get_focused_container_r(json_object *c) { } json_object_object_get_ex(c, "floating_nodes", &nodes); - for (i = 0; i < json_object_array_length(nodes); i++) { + for (json_ar_len_t i = 0; i < json_object_array_length(nodes); i++) { node = json_object_array_get_idx(nodes, i); if ((child = get_focused_container_r(node))) { @@ -83,7 +82,7 @@ char *get_focused_output() { if (!outputs) { sway_abort("Unabled to get focused output. No nodes in tree."); } - for (int i = 0; i < json_object_array_length(outputs); i++) { + for (json_ar_len_t i = 0; i < json_object_array_length(outputs); i++) { output = json_object_array_get_idx(outputs, i); if (get_focused_container_r(output)) { @@ -131,7 +130,7 @@ json_object *get_output_container(const char *output) { json_object *outputs, *json_output, *name; json_object_object_get_ex(tree, "nodes", &outputs); - for (int i = 0; i < json_object_array_length(outputs); i++) { + for (json_ar_len_t i = 0; i < json_object_array_length(outputs); i++) { json_output = json_object_array_get_idx(outputs, i); json_object_object_get_ex(json_output, "name", &name); -- cgit v1.2.3-54-g00ecf