aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Esser <besser82@fedoraproject.org>2017-12-14 01:30:54 +0100
committerDrew DeVault <sir@cmpwn.com>2017-12-17 15:53:22 -0500
commitc08c805ecd8f2000a35cdeae7b16244d0b3c0528 (patch)
tree8a1a12a32a1d2c40bc4fdb43aa7205362438f65b
parentd0bd0ed59887fdbcbe0630c23e5d1cc6a254340c (diff)
downloadsway-c08c805ecd8f2000a35cdeae7b16244d0b3c0528.zip
sway-c08c805ecd8f2000a35cdeae7b16244d0b3c0528.tar.gz
sway-c08c805ecd8f2000a35cdeae7b16244d0b3c0528.tar.bz2
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 99081dc..c4bf3f8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,7 +48,7 @@ if (LD_LIBRARY_PATH)
add_definitions(-D_LD_LIBRARY_PATH="${LD_LIBRARY_PATH}")
endif()
-find_package(JsonC 0.12.1 REQUIRED)
+find_package(JsonC REQUIRED)
find_package(PCRE REQUIRED)
find_package(WLC REQUIRED)
find_package(Wayland REQUIRED)
diff --git a/README.de.md b/README.de.md
index 701cc34..293ffe7 100644
--- a/README.de.md
+++ b/README.de.md
@@ -60,7 +60,7 @@ Abhängigkeiten:
* libcap
* asciidoc
* pcre
-* json-c <= 0.12.1
+* json-c
* pango
* cairo
* gdk-pixbuf2 *
diff --git a/README.el.md b/README.el.md
index df39364..eba97b9 100644
--- a/README.el.md
+++ b/README.el.md
@@ -53,7 +53,7 @@ To username μου στο Freenode είναι kon14 και θα με βρείτ
* libcap
* asciidoc
* pcre
-* json-c <= 0.12.1
+* json-c
* pango
* cairo
* gdk-pixbuf2 *
diff --git a/README.fr.md b/README.fr.md
index 47b6c41..a4ff7cb 100644
--- a/README.fr.md
+++ b/README.fr.md
@@ -55,7 +55,7 @@ Installez les dépendances :
* libcap
* asciidoc
* pcre
-* json-c <= 0.12.1
+* json-c
* pango
* cairo
* gdk-pixbuf2 *
diff --git a/README.it.md b/README.it.md
index f5e0d8e..ded441c 100644
--- a/README.it.md
+++ b/README.it.md
@@ -56,7 +56,7 @@ Installa queste dipendenze:
* libcap
* asciidoc
* pcre
-* json-c <= 0.12.1
+* json-c
* pango
* cairo
* gdk-pixbuf2 *
diff --git a/README.ja.md b/README.ja.md
index 2e8f9bf..94b4ce9 100644
--- a/README.ja.md
+++ b/README.ja.md
@@ -46,7 +46,7 @@ Swayは沢山のディストリビューションで提供されています。"
* libcap
* asciidoc
* pcre
-* json-c <= 0.12.1
+* json-c
* pango
* cairo
* gdk-pixbuf2 *
diff --git a/README.md b/README.md
index 29e8a67..eeca9f8 100644
--- a/README.md
+++ b/README.md
@@ -61,7 +61,7 @@ Install dependencies:
* libcap
* asciidoc
* pcre
-* json-c <= 0.12.1
+* json-c
* pango
* cairo
* gdk-pixbuf2 *
diff --git a/README.pt.md b/README.pt.md
index b5ca132..e35849e 100644
--- a/README.pt.md
+++ b/README.pt.md
@@ -62,7 +62,7 @@ Antes de iniciar a compilação, instale as dependências:
* libcap
* asciidoc
* pcre
-* json-c <= 0.12.1
+* json-c
* pango
* cairo
* gdk-pixbuf2 *
diff --git a/README.ru.md b/README.ru.md
index 4035b0f..1551caa 100644
--- a/README.ru.md
+++ b/README.ru.md
@@ -55,7 +55,7 @@ Sway доступен во многих дистрибутивах и наход
* libcap
* asciidoc
* pcre
-* json-c <= 0.12.1
+* json-c
* pango
* cairo
* gdk-pixbuf2 *
diff --git a/README.uk.md b/README.uk.md
index 2e107af..c8520e4 100644
--- a/README.uk.md
+++ b/README.uk.md
@@ -62,7 +62,7 @@ Sway доступний у багатьох дистрибутивах Linux (а
* libcap
* asciidoc
* pcre
-* json-c <= 0.12.1
+* json-c
* pango
* cairo
* gdk-pixbuf2 *
diff --git a/include/sway_json_helper.h b/include/sway_json_helper.h
new file mode 100644
index 0000000..66f9cff
--- /dev/null
+++ b/include/sway_json_helper.h
@@ -0,0 +1,16 @@
+#ifndef _SWAY_JSON_HELPER_H
+#define _SWAY_JSON_HELPER_H
+
+#include <json-c/json.h>
+
+// Macros for checking a specific version.
+#define JSON_C_VERSION_013 (13 << 8)
+
+// json-c v0.13 uses size_t for array_list_length().
+#if defined(JSON_C_VERSION_NUM) && JSON_C_VERSION_NUM >= JSON_C_VERSION_013
+typedef size_t json_ar_len_t;
+#else
+typedef int json_ar_len_t;
+#endif
+
+#endif // _SWAY_JSON_HELPER_H
diff --git a/include/swaygrab/json.h b/include/swaygrab/json.h
index c1093ef..c0bd858 100644
--- a/include/swaygrab/json.h
+++ b/include/swaygrab/json.h
@@ -1,4 +1,4 @@
-#include <json-c/json.h>
+#include "sway_json_helper.h"
#include "wlc/wlc.h"
void init_json_tree(int socketfd);
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index b560b93..e10445c 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -15,7 +15,6 @@
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
-#include <json-c/json.h>
#include <list.h>
#include <libinput.h>
#ifdef __linux__
@@ -25,6 +24,7 @@ struct ucred {
gid_t gid;
};
#endif
+#include "sway_json_helper.h"
#include "sway/ipc-json.h"
#include "sway/ipc-server.h"
#include "sway/security.h"
@@ -724,7 +724,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
}
// parse requested event types
- for (int i = 0; i < json_object_array_length(request); i++) {
+ for (json_ar_len_t i = 0; i < json_object_array_length(request); i++) {
const char *event_type = json_object_get_string(json_object_array_get_idx(request, i));
if (strcmp(event_type, "workspace") == 0) {
client->subscribed_events |= event_mask(IPC_EVENT_WORKSPACE);
@@ -1126,7 +1126,8 @@ static void ipc_event_binding(json_object *sb_obj) {
sway_log(L_DEBUG, "Sending binding::run event");
json_object *obj = json_object_new_object();
json_object_object_add(obj, "change", json_object_new_string("run"));
- json_object_object_add(obj, "binding", sb_obj);
+ // sb_obj gets owned by the temporary json_object, too.
+ json_object_object_add(obj, "binding", json_object_get(sb_obj));
const char *json_string = json_object_to_json_string(obj);
ipc_send_event(json_string, IPC_EVENT_BINDING);
diff --git a/swaybar/status_line.c b/swaybar/status_line.c
index 87e90ca..e3cc0bf 100644
--- a/swaybar/status_line.c
+++ b/swaybar/status_line.c
@@ -2,8 +2,8 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <json-c/json.h>
+#include "sway_json_helper.h"
#include "swaybar/config.h"
#include "swaybar/status_line.h"
#include "log.h"
@@ -70,8 +70,7 @@ static void parse_json(struct bar *bar, const char *text) {
bar->status->block_line = create_list();
- int i;
- for (i = 0; i < json_object_array_length(results); ++i) {
+ for (json_ar_len_t i = 0; i < json_object_array_length(results); ++i) {
json_object *full_text, *short_text, *color, *min_width, *align, *urgent;
json_object *name, *instance, *separator, *separator_block_width;
json_object *background, *border, *border_top, *border_bottom;
diff --git a/swaygrab/json.c b/swaygrab/json.c
index 286085c..f0e8fa9 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);
diff --git a/swaylock/main.c b/swaylock/main.c
index 4b48646..3208a45 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -3,7 +3,6 @@
#include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbcommon-names.h>
#include <security/pam_appl.h>
-#include <json-c/json.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -14,6 +13,7 @@
#include <signal.h>
#include <stdbool.h>
#include <unistd.h>
+#include "sway_json_helper.h"
#include "client/window.h"
#include "client/registry.h"
#include "client/cairo.h"
@@ -583,7 +583,7 @@ int main(int argc, char **argv) {
for (i = 0; i < registry->outputs->length; ++i) {
if (displays_paths[i * 2] != NULL) {
- for (int j = 0;; ++j) {
+ for (json_ar_len_t j = 0;; ++j) {
if (j >= json_object_array_length(json_outputs)) {
sway_log(L_ERROR, "%s is not an extant output", displays_paths[i * 2]);
exit(EXIT_FAILURE);
diff --git a/swaymsg/main.c b/swaymsg/main.c
index 2f9cfb1..0ee7c76 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -9,7 +9,7 @@
#include <sys/socket.h>
#include <ctype.h>
#include <unistd.h>
-#include <json-c/json.h>
+#include "sway_json_helper.h"
#include "stringop.h"
#include "ipc-client.h"
#include "readline.h"
@@ -149,7 +149,7 @@ static void pretty_print_version(json_object *v) {
static void pretty_print_clipboard(json_object *v) {
if (success(v, true)) {
if (json_object_is_type(v, json_type_array)) {
- for (int i = 0; i < json_object_array_length(v); ++i) {
+ for (json_ar_len_t i = 0; i < json_object_array_length(v); ++i) {
json_object *o = json_object_array_get_idx(v, i);
printf("%s\n", json_object_get_string(o));
}