commands.c yajl macros allow NULL
Patch status: needinfo
Patch by Tony Crisci
To apply this patch, use:
curl http://cr.i3wm.org/patch/552/raw.patch | git am
b/src/commands.c
13 |
@@ -16,21 +16,25 @@ |
14 |
#include "shmlog.h" |
15 |
|
16 |
// Macros to make the YAJL API a bit easier to use. |
17 |
-#define y(x, ...) yajl_gen_ ## x (cmd_output->json_gen, ##__VA_ARGS__) |
18 |
-#define ystr(str) yajl_gen_string(cmd_output->json_gen, (unsigned char*)str, strlen(str)) |
19 |
+#define y(x, ...) (cmd_output != NULL ? yajl_gen_ ## x (cmd_output->json_gen, ##__VA_ARGS__) : 0) |
20 |
+#define ystr(str) (cmd_output != NULL ? yajl_gen_string(cmd_output->json_gen, (unsigned char*)str, strlen(str)) : 0) |
21 |
#define ysuccess(success) do { \ |
22 |
- y(map_open); \ |
23 |
- ystr("success"); \ |
24 |
- y(bool, success); \ |
25 |
- y(map_close); \ |
26 |
+ if (cmd_output->json_gen != NULL) { \ |
27 |
+ y(map_open); \ |
28 |
+ ystr("success"); \ |
29 |
+ y(bool, success); \ |
30 |
+ y(map_close); \ |
31 |
+ } \ |
32 |
} while (0) |
33 |
#define yerror(message) do { \ |
34 |
- y(map_open); \ |
35 |
- ystr("success"); \ |
36 |
- y(bool, false); \ |
37 |
- ystr("error"); \ |
38 |
- ystr(message); \ |
39 |
- y(map_close); \ |
40 |
+ if (cmd_output->json_gen != NULL) { \ |
41 |
+ y(map_open); \ |
42 |
+ ystr("success"); \ |
43 |
+ y(bool, false); \ |
44 |
+ ystr("error"); \ |
45 |
+ ystr(message); \ |
46 |
+ y(map_close); \ |
47 |
+ } \ |
48 |
} while (0) |
49 |
|
50 |
/** When the command did not include match criteria (!), we use the currently |