aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Björn Esser <besser82@fedoraproject.org>2017-12-14 01:30:54 +0100
committerLibravatar Drew DeVault <sir@cmpwn.com>2017-12-17 15:53:22 -0500
commitc08c805ecd8f2000a35cdeae7b16244d0b3c0528 (patch)
tree8a1a12a32a1d2c40bc4fdb43aa7205362438f65b
parentRevert "Merge remote-tracking branch 'besser82/bugfix/json-c' into 0.15" (diff)
downloadsway-0.15.1.tar.gz
sway-0.15.1.tar.zst
sway-0.15.1.zip
Adaptions for API change in json-c v0.130.15.1
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.
-rw-r--r--CMakeLists.txt2
-rw-r--r--README.de.md2
-rw-r--r--README.el.md2
-rw-r--r--README.fr.md2
-rw-r--r--README.it.md2
-rw-r--r--README.ja.md2
-rw-r--r--README.md2
-rw-r--r--README.pt.md2
-rw-r--r--README.ru.md2
-rw-r--r--README.uk.md2
-rw-r--r--include/sway_json_helper.h16
-rw-r--r--include/swaygrab/json.h2
-rw-r--r--sway/ipc-server.c7
-rw-r--r--swaybar/status_line.c5
-rw-r--r--swaygrab/json.c9
-rw-r--r--swaylock/main.c4
-rw-r--r--swaymsg/main.c4
17 files changed, 41 insertions, 26 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 99081dca..c4bf3f89 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,7 +48,7 @@ if (LD_LIBRARY_PATH)
48 add_definitions(-D_LD_LIBRARY_PATH="${LD_LIBRARY_PATH}") 48 add_definitions(-D_LD_LIBRARY_PATH="${LD_LIBRARY_PATH}")
49endif() 49endif()
50 50
51find_package(JsonC 0.12.1 REQUIRED) 51find_package(JsonC REQUIRED)
52find_package(PCRE REQUIRED) 52find_package(PCRE REQUIRED)
53find_package(WLC REQUIRED) 53find_package(WLC REQUIRED)
54find_package(Wayland REQUIRED) 54find_package(Wayland REQUIRED)
diff --git a/README.de.md b/README.de.md
index 701cc34f..293ffe70 100644
--- a/README.de.md
+++ b/README.de.md
@@ -60,7 +60,7 @@ Abhängigkeiten:
60* libcap 60* libcap
61* asciidoc 61* asciidoc
62* pcre 62* pcre
63* json-c <= 0.12.1 63* json-c
64* pango 64* pango
65* cairo 65* cairo
66* gdk-pixbuf2 * 66* gdk-pixbuf2 *
diff --git a/README.el.md b/README.el.md
index df39364f..eba97b9c 100644
--- a/README.el.md
+++ b/README.el.md
@@ -53,7 +53,7 @@ To username μου στο Freenode είναι kon14 και θα με βρείτ
53* libcap 53* libcap
54* asciidoc 54* asciidoc
55* pcre 55* pcre
56* json-c <= 0.12.1 56* json-c
57* pango 57* pango
58* cairo 58* cairo
59* gdk-pixbuf2 * 59* gdk-pixbuf2 *
diff --git a/README.fr.md b/README.fr.md
index 47b6c410..a4ff7cb9 100644
--- a/README.fr.md
+++ b/README.fr.md
@@ -55,7 +55,7 @@ Installez les dépendances :
55* libcap 55* libcap
56* asciidoc 56* asciidoc
57* pcre 57* pcre
58* json-c <= 0.12.1 58* json-c
59* pango 59* pango
60* cairo 60* cairo
61* gdk-pixbuf2 * 61* gdk-pixbuf2 *
diff --git a/README.it.md b/README.it.md
index f5e0d8e2..ded441c3 100644
--- a/README.it.md
+++ b/README.it.md
@@ -56,7 +56,7 @@ Installa queste dipendenze:
56* libcap 56* libcap
57* asciidoc 57* asciidoc
58* pcre 58* pcre
59* json-c <= 0.12.1 59* json-c
60* pango 60* pango
61* cairo 61* cairo
62* gdk-pixbuf2 * 62* gdk-pixbuf2 *
diff --git a/README.ja.md b/README.ja.md
index 2e8f9bfb..94b4ce9d 100644
--- a/README.ja.md
+++ b/README.ja.md
@@ -46,7 +46,7 @@ Swayは沢山のディストリビューションで提供されています。"
46* libcap 46* libcap
47* asciidoc 47* asciidoc
48* pcre 48* pcre
49* json-c <= 0.12.1 49* json-c
50* pango 50* pango
51* cairo 51* cairo
52* gdk-pixbuf2 * 52* gdk-pixbuf2 *
diff --git a/README.md b/README.md
index 29e8a674..eeca9f88 100644
--- a/README.md
+++ b/README.md
@@ -61,7 +61,7 @@ Install dependencies:
61* libcap 61* libcap
62* asciidoc 62* asciidoc
63* pcre 63* pcre
64* json-c <= 0.12.1 64* json-c
65* pango 65* pango
66* cairo 66* cairo
67* gdk-pixbuf2 * 67* gdk-pixbuf2 *
diff --git a/README.pt.md b/README.pt.md
index b5ca132f..e35849ec 100644
--- a/README.pt.md
+++ b/README.pt.md
@@ -62,7 +62,7 @@ Antes de iniciar a compilação, instale as dependências:
62* libcap 62* libcap
63* asciidoc 63* asciidoc
64* pcre 64* pcre
65* json-c <= 0.12.1 65* json-c
66* pango 66* pango
67* cairo 67* cairo
68* gdk-pixbuf2 * 68* gdk-pixbuf2 *
diff --git a/README.ru.md b/README.ru.md
index 4035b0fc..1551caa0 100644
--- a/README.ru.md
+++ b/README.ru.md
@@ -55,7 +55,7 @@ Sway доступен во многих дистрибутивах и наход
55* libcap 55* libcap
56* asciidoc 56* asciidoc
57* pcre 57* pcre
58* json-c <= 0.12.1 58* json-c
59* pango 59* pango
60* cairo 60* cairo
61* gdk-pixbuf2 * 61* gdk-pixbuf2 *
diff --git a/README.uk.md b/README.uk.md
index 2e107afc..c8520e4b 100644
--- a/README.uk.md
+++ b/README.uk.md
@@ -62,7 +62,7 @@ Sway доступний у багатьох дистрибутивах Linux (а
62* libcap 62* libcap
63* asciidoc 63* asciidoc
64* pcre 64* pcre
65* json-c <= 0.12.1 65* json-c
66* pango 66* pango
67* cairo 67* cairo
68* gdk-pixbuf2 * 68* gdk-pixbuf2 *
diff --git a/include/sway_json_helper.h b/include/sway_json_helper.h
new file mode 100644
index 00000000..66f9cff1
--- /dev/null
+++ b/include/sway_json_helper.h
@@ -0,0 +1,16 @@
1#ifndef _SWAY_JSON_HELPER_H
2#define _SWAY_JSON_HELPER_H
3
4#include <json-c/json.h>
5
6// Macros for checking a specific version.
7#define JSON_C_VERSION_013 (13 << 8)
8
9// json-c v0.13 uses size_t for array_list_length().
10#if defined(JSON_C_VERSION_NUM) && JSON_C_VERSION_NUM >= JSON_C_VERSION_013
11typedef size_t json_ar_len_t;
12#else
13typedef int json_ar_len_t;
14#endif
15
16#endif // _SWAY_JSON_HELPER_H
diff --git a/include/swaygrab/json.h b/include/swaygrab/json.h
index c1093ef1..c0bd8587 100644
--- a/include/swaygrab/json.h
+++ b/include/swaygrab/json.h
@@ -1,4 +1,4 @@
1#include <json-c/json.h> 1#include "sway_json_helper.h"
2#include "wlc/wlc.h" 2#include "wlc/wlc.h"
3 3
4void init_json_tree(int socketfd); 4void init_json_tree(int socketfd);
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index b560b930..e10445cf 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -15,7 +15,6 @@
15#include <stdlib.h> 15#include <stdlib.h>
16#include <sys/ioctl.h> 16#include <sys/ioctl.h>
17#include <fcntl.h> 17#include <fcntl.h>
18#include <json-c/json.h>
19#include <list.h> 18#include <list.h>
20#include <libinput.h> 19#include <libinput.h>
21#ifdef __linux__ 20#ifdef __linux__
@@ -25,6 +24,7 @@ struct ucred {
25 gid_t gid; 24 gid_t gid;
26}; 25};
27#endif 26#endif
27#include "sway_json_helper.h"
28#include "sway/ipc-json.h" 28#include "sway/ipc-json.h"
29#include "sway/ipc-server.h" 29#include "sway/ipc-server.h"
30#include "sway/security.h" 30#include "sway/security.h"
@@ -724,7 +724,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
724 } 724 }
725 725
726 // parse requested event types 726 // parse requested event types
727 for (int i = 0; i < json_object_array_length(request); i++) { 727 for (json_ar_len_t i = 0; i < json_object_array_length(request); i++) {
728 const char *event_type = json_object_get_string(json_object_array_get_idx(request, i)); 728 const char *event_type = json_object_get_string(json_object_array_get_idx(request, i));
729 if (strcmp(event_type, "workspace") == 0) { 729 if (strcmp(event_type, "workspace") == 0) {
730 client->subscribed_events |= event_mask(IPC_EVENT_WORKSPACE); 730 client->subscribed_events |= event_mask(IPC_EVENT_WORKSPACE);
@@ -1126,7 +1126,8 @@ static void ipc_event_binding(json_object *sb_obj) {
1126 sway_log(L_DEBUG, "Sending binding::run event"); 1126 sway_log(L_DEBUG, "Sending binding::run event");
1127 json_object *obj = json_object_new_object(); 1127 json_object *obj = json_object_new_object();
1128 json_object_object_add(obj, "change", json_object_new_string("run")); 1128 json_object_object_add(obj, "change", json_object_new_string("run"));
1129 json_object_object_add(obj, "binding", sb_obj); 1129 // sb_obj gets owned by the temporary json_object, too.
1130 json_object_object_add(obj, "binding", json_object_get(sb_obj));
1130 1131
1131 const char *json_string = json_object_to_json_string(obj); 1132 const char *json_string = json_object_to_json_string(obj);
1132 ipc_send_event(json_string, IPC_EVENT_BINDING); 1133 ipc_send_event(json_string, IPC_EVENT_BINDING);
diff --git a/swaybar/status_line.c b/swaybar/status_line.c
index 87e90caf..e3cc0bf4 100644
--- a/swaybar/status_line.c
+++ b/swaybar/status_line.c
@@ -2,8 +2,8 @@
2#include <stdlib.h> 2#include <stdlib.h>
3#include <string.h> 3#include <string.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <json-c/json.h>
6 5
6#include "sway_json_helper.h"
7#include "swaybar/config.h" 7#include "swaybar/config.h"
8#include "swaybar/status_line.h" 8#include "swaybar/status_line.h"
9#include "log.h" 9#include "log.h"
@@ -70,8 +70,7 @@ static void parse_json(struct bar *bar, const char *text) {
70 70
71 bar->status->block_line = create_list(); 71 bar->status->block_line = create_list();
72 72
73 int i; 73 for (json_ar_len_t i = 0; i < json_object_array_length(results); ++i) {
74 for (i = 0; i < json_object_array_length(results); ++i) {
75 json_object *full_text, *short_text, *color, *min_width, *align, *urgent; 74 json_object *full_text, *short_text, *color, *min_width, *align, *urgent;
76 json_object *name, *instance, *separator, *separator_block_width; 75 json_object *name, *instance, *separator, *separator_block_width;
77 json_object *background, *border, *border_top, *border_bottom; 76 json_object *background, *border, *border_top, *border_bottom;
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) {
50 } else { 50 } else {
51 json_object *nodes, *node, *child; 51 json_object *nodes, *node, *child;
52 json_object_object_get_ex(c, "nodes", &nodes); 52 json_object_object_get_ex(c, "nodes", &nodes);
53 int i; 53 for (json_ar_len_t i = 0; i < json_object_array_length(nodes); i++) {
54 for (i = 0; i < json_object_array_length(nodes); i++) {
55 node = json_object_array_get_idx(nodes, i); 54 node = json_object_array_get_idx(nodes, i);
56 55
57 if ((child = get_focused_container_r(node))) { 56 if ((child = get_focused_container_r(node))) {
@@ -60,7 +59,7 @@ static json_object *get_focused_container_r(json_object *c) {
60 } 59 }
61 60
62 json_object_object_get_ex(c, "floating_nodes", &nodes); 61 json_object_object_get_ex(c, "floating_nodes", &nodes);
63 for (i = 0; i < json_object_array_length(nodes); i++) { 62 for (json_ar_len_t i = 0; i < json_object_array_length(nodes); i++) {
64 node = json_object_array_get_idx(nodes, i); 63 node = json_object_array_get_idx(nodes, i);
65 64
66 if ((child = get_focused_container_r(node))) { 65 if ((child = get_focused_container_r(node))) {
@@ -83,7 +82,7 @@ char *get_focused_output() {
83 if (!outputs) { 82 if (!outputs) {
84 sway_abort("Unabled to get focused output. No nodes in tree."); 83 sway_abort("Unabled to get focused output. No nodes in tree.");
85 } 84 }
86 for (int i = 0; i < json_object_array_length(outputs); i++) { 85 for (json_ar_len_t i = 0; i < json_object_array_length(outputs); i++) {
87 output = json_object_array_get_idx(outputs, i); 86 output = json_object_array_get_idx(outputs, i);
88 87
89 if (get_focused_container_r(output)) { 88 if (get_focused_container_r(output)) {
@@ -131,7 +130,7 @@ json_object *get_output_container(const char *output) {
131 json_object *outputs, *json_output, *name; 130 json_object *outputs, *json_output, *name;
132 json_object_object_get_ex(tree, "nodes", &outputs); 131 json_object_object_get_ex(tree, "nodes", &outputs);
133 132
134 for (int i = 0; i < json_object_array_length(outputs); i++) { 133 for (json_ar_len_t i = 0; i < json_object_array_length(outputs); i++) {
135 json_output = json_object_array_get_idx(outputs, i); 134 json_output = json_object_array_get_idx(outputs, i);
136 json_object_object_get_ex(json_output, "name", &name); 135 json_object_object_get_ex(json_output, "name", &name);
137 136
diff --git a/swaylock/main.c b/swaylock/main.c
index 4b486461..3208a45b 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -3,7 +3,6 @@
3#include <xkbcommon/xkbcommon.h> 3#include <xkbcommon/xkbcommon.h>
4#include <xkbcommon/xkbcommon-names.h> 4#include <xkbcommon/xkbcommon-names.h>
5#include <security/pam_appl.h> 5#include <security/pam_appl.h>
6#include <json-c/json.h>
7#include <stdio.h> 6#include <stdio.h>
8#include <stdlib.h> 7#include <stdlib.h>
9#include <string.h> 8#include <string.h>
@@ -14,6 +13,7 @@
14#include <signal.h> 13#include <signal.h>
15#include <stdbool.h> 14#include <stdbool.h>
16#include <unistd.h> 15#include <unistd.h>
16#include "sway_json_helper.h"
17#include "client/window.h" 17#include "client/window.h"
18#include "client/registry.h" 18#include "client/registry.h"
19#include "client/cairo.h" 19#include "client/cairo.h"
@@ -583,7 +583,7 @@ int main(int argc, char **argv) {
583 583
584 for (i = 0; i < registry->outputs->length; ++i) { 584 for (i = 0; i < registry->outputs->length; ++i) {
585 if (displays_paths[i * 2] != NULL) { 585 if (displays_paths[i * 2] != NULL) {
586 for (int j = 0;; ++j) { 586 for (json_ar_len_t j = 0;; ++j) {
587 if (j >= json_object_array_length(json_outputs)) { 587 if (j >= json_object_array_length(json_outputs)) {
588 sway_log(L_ERROR, "%s is not an extant output", displays_paths[i * 2]); 588 sway_log(L_ERROR, "%s is not an extant output", displays_paths[i * 2]);
589 exit(EXIT_FAILURE); 589 exit(EXIT_FAILURE);
diff --git a/swaymsg/main.c b/swaymsg/main.c
index 2f9cfb14..0ee7c76f 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -9,7 +9,7 @@
9#include <sys/socket.h> 9#include <sys/socket.h>
10#include <ctype.h> 10#include <ctype.h>
11#include <unistd.h> 11#include <unistd.h>
12#include <json-c/json.h> 12#include "sway_json_helper.h"
13#include "stringop.h" 13#include "stringop.h"
14#include "ipc-client.h" 14#include "ipc-client.h"
15#include "readline.h" 15#include "readline.h"
@@ -149,7 +149,7 @@ static void pretty_print_version(json_object *v) {
149static void pretty_print_clipboard(json_object *v) { 149static void pretty_print_clipboard(json_object *v) {
150 if (success(v, true)) { 150 if (success(v, true)) {
151 if (json_object_is_type(v, json_type_array)) { 151 if (json_object_is_type(v, json_type_array)) {
152 for (int i = 0; i < json_object_array_length(v); ++i) { 152 for (json_ar_len_t i = 0; i < json_object_array_length(v); ++i) {
153 json_object *o = json_object_array_get_idx(v, i); 153 json_object *o = json_object_array_get_idx(v, i);
154 printf("%s\n", json_object_get_string(o)); 154 printf("%s\n", json_object_get_string(o));
155 } 155 }