Skip to content

Commit c08c805

Browse files
besser82ddevault
authored andcommitted
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.
1 parent d0bd0ed commit c08c805

17 files changed

+41
-26
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ if (LD_LIBRARY_PATH)
4848
add_definitions(-D_LD_LIBRARY_PATH="${LD_LIBRARY_PATH}")
4949
endif()
5050

51-
find_package(JsonC 0.12.1 REQUIRED)
51+
find_package(JsonC REQUIRED)
5252
find_package(PCRE REQUIRED)
5353
find_package(WLC REQUIRED)
5454
find_package(Wayland REQUIRED)

README.de.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Abhängigkeiten:
6060
* libcap
6161
* asciidoc
6262
* pcre
63-
* json-c <= 0.12.1
63+
* json-c
6464
* pango
6565
* cairo
6666
* gdk-pixbuf2 *

README.el.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ To username μου στο Freenode είναι kon14 και θα με βρείτ
5353
* libcap
5454
* asciidoc
5555
* pcre
56-
* json-c <= 0.12.1
56+
* json-c
5757
* pango
5858
* cairo
5959
* gdk-pixbuf2 *

README.fr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Installez les dépendances :
5555
* libcap
5656
* asciidoc
5757
* pcre
58-
* json-c <= 0.12.1
58+
* json-c
5959
* pango
6060
* cairo
6161
* gdk-pixbuf2 *

README.it.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Installa queste dipendenze:
5656
* libcap
5757
* asciidoc
5858
* pcre
59-
* json-c <= 0.12.1
59+
* json-c
6060
* pango
6161
* cairo
6262
* gdk-pixbuf2 *

README.ja.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Swayは沢山のディストリビューションで提供されています。"
4646
* libcap
4747
* asciidoc
4848
* pcre
49-
* json-c <= 0.12.1
49+
* json-c
5050
* pango
5151
* cairo
5252
* gdk-pixbuf2 *

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Install dependencies:
6161
* libcap
6262
* asciidoc
6363
* pcre
64-
* json-c <= 0.12.1
64+
* json-c
6565
* pango
6666
* cairo
6767
* gdk-pixbuf2 *

README.pt.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Antes de iniciar a compilação, instale as dependências:
6262
* libcap
6363
* asciidoc
6464
* pcre
65-
* json-c <= 0.12.1
65+
* json-c
6666
* pango
6767
* cairo
6868
* gdk-pixbuf2 *

README.ru.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Sway доступен во многих дистрибутивах и наход
5555
* libcap
5656
* asciidoc
5757
* pcre
58-
* json-c <= 0.12.1
58+
* json-c
5959
* pango
6060
* cairo
6161
* gdk-pixbuf2 *

README.uk.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Sway доступний у багатьох дистрибутивах Linux (а
6262
* libcap
6363
* asciidoc
6464
* pcre
65-
* json-c <= 0.12.1
65+
* json-c
6666
* pango
6767
* cairo
6868
* gdk-pixbuf2 *

include/sway_json_helper.h

+16
Original file line numberDiff line numberDiff line change
@@ -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
11+
typedef size_t json_ar_len_t;
12+
#else
13+
typedef int json_ar_len_t;
14+
#endif
15+
16+
#endif // _SWAY_JSON_HELPER_H

include/swaygrab/json.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <json-c/json.h>
1+
#include "sway_json_helper.h"
22
#include "wlc/wlc.h"
33

44
void init_json_tree(int socketfd);

sway/ipc-server.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <stdlib.h>
1616
#include <sys/ioctl.h>
1717
#include <fcntl.h>
18-
#include <json-c/json.h>
1918
#include <list.h>
2019
#include <libinput.h>
2120
#ifdef __linux__
@@ -25,6 +24,7 @@ struct ucred {
2524
gid_t gid;
2625
};
2726
#endif
27+
#include "sway_json_helper.h"
2828
#include "sway/ipc-json.h"
2929
#include "sway/ipc-server.h"
3030
#include "sway/security.h"
@@ -724,7 +724,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
724724
}
725725

726726
// 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++) {
728728
const char *event_type = json_object_get_string(json_object_array_get_idx(request, i));
729729
if (strcmp(event_type, "workspace") == 0) {
730730
client->subscribed_events |= event_mask(IPC_EVENT_WORKSPACE);
@@ -1126,7 +1126,8 @@ static void ipc_event_binding(json_object *sb_obj) {
11261126
sway_log(L_DEBUG, "Sending binding::run event");
11271127
json_object *obj = json_object_new_object();
11281128
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));
11301131

11311132
const char *json_string = json_object_to_json_string(obj);
11321133
ipc_send_event(json_string, IPC_EVENT_BINDING);

swaybar/status_line.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#include <stdlib.h>
33
#include <string.h>
44
#include <unistd.h>
5-
#include <json-c/json.h>
65

6+
#include "sway_json_helper.h"
77
#include "swaybar/config.h"
88
#include "swaybar/status_line.h"
99
#include "log.h"
@@ -70,8 +70,7 @@ static void parse_json(struct bar *bar, const char *text) {
7070

7171
bar->status->block_line = create_list();
7272

73-
int i;
74-
for (i = 0; i < json_object_array_length(results); ++i) {
73+
for (json_ar_len_t i = 0; i < json_object_array_length(results); ++i) {
7574
json_object *full_text, *short_text, *color, *min_width, *align, *urgent;
7675
json_object *name, *instance, *separator, *separator_block_width;
7776
json_object *background, *border, *border_top, *border_bottom;

swaygrab/json.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ static json_object *get_focused_container_r(json_object *c) {
5050
} else {
5151
json_object *nodes, *node, *child;
5252
json_object_object_get_ex(c, "nodes", &nodes);
53-
int i;
54-
for (i = 0; i < json_object_array_length(nodes); i++) {
53+
for (json_ar_len_t i = 0; i < json_object_array_length(nodes); i++) {
5554
node = json_object_array_get_idx(nodes, i);
5655

5756
if ((child = get_focused_container_r(node))) {
@@ -60,7 +59,7 @@ static json_object *get_focused_container_r(json_object *c) {
6059
}
6160

6261
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++) {
6463
node = json_object_array_get_idx(nodes, i);
6564

6665
if ((child = get_focused_container_r(node))) {
@@ -83,7 +82,7 @@ char *get_focused_output() {
8382
if (!outputs) {
8483
sway_abort("Unabled to get focused output. No nodes in tree.");
8584
}
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++) {
8786
output = json_object_array_get_idx(outputs, i);
8887

8988
if (get_focused_container_r(output)) {
@@ -131,7 +130,7 @@ json_object *get_output_container(const char *output) {
131130
json_object *outputs, *json_output, *name;
132131
json_object_object_get_ex(tree, "nodes", &outputs);
133132

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++) {
135134
json_output = json_object_array_get_idx(outputs, i);
136135
json_object_object_get_ex(json_output, "name", &name);
137136

swaylock/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <xkbcommon/xkbcommon.h>
44
#include <xkbcommon/xkbcommon-names.h>
55
#include <security/pam_appl.h>
6-
#include <json-c/json.h>
76
#include <stdio.h>
87
#include <stdlib.h>
98
#include <string.h>
@@ -14,6 +13,7 @@
1413
#include <signal.h>
1514
#include <stdbool.h>
1615
#include <unistd.h>
16+
#include "sway_json_helper.h"
1717
#include "client/window.h"
1818
#include "client/registry.h"
1919
#include "client/cairo.h"
@@ -583,7 +583,7 @@ int main(int argc, char **argv) {
583583

584584
for (i = 0; i < registry->outputs->length; ++i) {
585585
if (displays_paths[i * 2] != NULL) {
586-
for (int j = 0;; ++j) {
586+
for (json_ar_len_t j = 0;; ++j) {
587587
if (j >= json_object_array_length(json_outputs)) {
588588
sway_log(L_ERROR, "%s is not an extant output", displays_paths[i * 2]);
589589
exit(EXIT_FAILURE);

swaymsg/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <sys/socket.h>
1010
#include <ctype.h>
1111
#include <unistd.h>
12-
#include <json-c/json.h>
12+
#include "sway_json_helper.h"
1313
#include "stringop.h"
1414
#include "ipc-client.h"
1515
#include "readline.h"
@@ -149,7 +149,7 @@ static void pretty_print_version(json_object *v) {
149149
static void pretty_print_clipboard(json_object *v) {
150150
if (success(v, true)) {
151151
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) {
153153
json_object *o = json_object_array_get_idx(v, i);
154154
printf("%s\n", json_object_get_string(o));
155155
}

0 commit comments

Comments
 (0)