i3 - improved tiling WM


use designated initializers for yajl_callbacks struct

Patch status: merged

Patch by Alexander Kedrik

To apply this patch, use:
curl http://cr.i3wm.org/patch/366/raw.patch | git am

b/i3-msg/main.c

23
@@ -118,18 +118,12 @@ static int reply_map_key_cb(void *params, const unsigned char *keyVal, unsigned
24
     return 1;
25
 }
26
 
27
-yajl_callbacks reply_callbacks = {
28
-    NULL,
29
-    &reply_boolean_cb,
30
-    NULL,
31
-    NULL,
32
-    NULL,
33
-    &reply_string_cb,
34
-    &reply_start_map_cb,
35
-    &reply_map_key_cb,
36
-    &reply_end_map_cb,
37
-    NULL,
38
-    NULL
39
+static yajl_callbacks reply_callbacks = {
40
+    .yajl_boolean = reply_boolean_cb,
41
+    .yajl_string = reply_string_cb,
42
+    .yajl_start_map = reply_start_map_cb,
43
+    .yajl_map_key = reply_map_key_cb,
44
+    .yajl_end_map = reply_end_map_cb,
45
 };
46
 
47
 int main(int argc, char *argv[]) {

b/i3bar/src/child.c

52
@@ -35,7 +35,6 @@ ev_io    *stdin_io;
53
 ev_child *child_sig;
54
 
55
 /* JSON parser for stdin */
56
-yajl_callbacks callbacks;
57
 yajl_handle parser;
58
 
59
 /* JSON generator for stdout */
60
@@ -458,15 +457,16 @@ void start_child(char *command) {
61
         return;
62
 
63
     /* Allocate a yajl parser which will be used to parse stdin. */
64
-    memset(&callbacks, '\0', sizeof(yajl_callbacks));
65
-    callbacks.yajl_map_key = stdin_map_key;
66
-    callbacks.yajl_boolean = stdin_boolean;
67
-    callbacks.yajl_string = stdin_string;
68
-    callbacks.yajl_integer = stdin_integer;
69
-    callbacks.yajl_start_array = stdin_start_array;
70
-    callbacks.yajl_end_array = stdin_end_array;
71
-    callbacks.yajl_start_map = stdin_start_map;
72
-    callbacks.yajl_end_map = stdin_end_map;
73
+    static yajl_callbacks callbacks = {
74
+        .yajl_boolean = stdin_boolean,
75
+        .yajl_integer = stdin_integer,
76
+        .yajl_string = stdin_string,
77
+        .yajl_start_map = stdin_start_map,
78
+        .yajl_map_key = stdin_map_key,
79
+        .yajl_end_map = stdin_end_map,
80
+        .yajl_start_array = stdin_start_array,
81
+        .yajl_end_array = stdin_end_array,
82
+    };
83
 #if YAJL_MAJOR < 2
84
     yajl_parser_config parse_conf = { 0, 0 };
85
 

b/i3bar/src/config.c

90
@@ -212,17 +212,10 @@ static int config_boolean_cb(void *params_, int val) {
91
 
92
 /* A datastructure to pass all these callbacks to yajl */
93
 static yajl_callbacks outputs_callbacks = {
94
-    &config_null_cb,
95
-    &config_boolean_cb,
96
-    NULL,
97
-    NULL,
98
-    NULL,
99
-    &config_string_cb,
100
-    NULL,
101
-    &config_map_key_cb,
102
-    NULL,
103
-    NULL,
104
-    NULL
105
+    .yajl_null = config_null_cb,
106
+    .yajl_boolean = config_boolean_cb,
107
+    .yajl_string = config_string_cb,
108
+    .yajl_map_key = config_map_key_cb,
109
 };
110
 
111
 /*

b/i3bar/src/mode.c

116
@@ -72,18 +72,9 @@ static int mode_map_key_cb(void *params_, const unsigned char *keyVal, unsigned
117
 }
118
 
119
 /* A datastructure to pass all these callbacks to yajl */
120
-yajl_callbacks mode_callbacks = {
121
-    NULL,
122
-    NULL,
123
-    NULL,
124
-    NULL,
125
-    NULL,
126
-    &mode_string_cb,
127
-    NULL,
128
-    &mode_map_key_cb,
129
-    NULL,
130
-    NULL,
131
-    NULL
132
+static yajl_callbacks mode_callbacks = {
133
+    .yajl_string = mode_string_cb,
134
+    .yajl_map_key = mode_map_key_cb,
135
 };
136
 
137
 /*

b/i3bar/src/outputs.c

142
@@ -248,18 +248,14 @@ static int outputs_map_key_cb(void *params_, const unsigned char *keyVal, unsign
143
 }
144
 
145
 /* A datastructure to pass all these callbacks to yajl */
146
-yajl_callbacks outputs_callbacks = {
147
-    &outputs_null_cb,
148
-    &outputs_boolean_cb,
149
-    &outputs_integer_cb,
150
-    NULL,
151
-    NULL,
152
-    &outputs_string_cb,
153
-    &outputs_start_map_cb,
154
-    &outputs_map_key_cb,
155
-    &outputs_end_map_cb,
156
-    NULL,
157
-    NULL
158
+static yajl_callbacks outputs_callbacks = {
159
+    .yajl_null = outputs_null_cb,
160
+    .yajl_boolean = outputs_boolean_cb,
161
+    .yajl_integer = outputs_integer_cb,
162
+    .yajl_string = outputs_string_cb,
163
+    .yajl_start_map = outputs_start_map_cb,
164
+    .yajl_map_key = outputs_map_key_cb,
165
+    .yajl_end_map = outputs_end_map_cb,
166
 };
167
 
168
 /*

b/i3bar/src/parse_json_header.c

173
@@ -93,20 +93,6 @@ static int header_map_key(void *ctx, const unsigned char *stringval, unsigned in
174
     return 1;
175
 }
176
 
177
-static yajl_callbacks version_callbacks = {
178
-    NULL, /* null */
179
-    &header_boolean, /* boolean */
180
-    &header_integer,
181
-    NULL, /* double */
182
-    NULL, /* number */
183
-    NULL, /* string */
184
-    NULL, /* start_map */
185
-    &header_map_key,
186
-    NULL, /* end_map */
187
-    NULL, /* start_array */
188
-    NULL /* end_array */
189
-};
190
-
191
 static void child_init(i3bar_child *child) {
192
     child->version = 0;
193
     child->stop_signal = SIGSTOP;
194
@@ -122,6 +108,12 @@ static void child_init(i3bar_child *child) {
195
  *
196
  */
197
 void parse_json_header(i3bar_child *child, const unsigned char *buffer, int length, unsigned int *consumed) {
198
+    static yajl_callbacks version_callbacks = {
199
+        .yajl_boolean = header_boolean,
200
+        .yajl_integer = header_integer,
201
+        .yajl_map_key = &header_map_key,
202
+    };
203
+
204
     child_init(child);
205
 
206
     current_key = NO_KEY;

b/i3bar/src/workspaces.c

211
@@ -198,18 +198,12 @@ static int workspaces_map_key_cb(void *params_, const unsigned char *keyVal, uns
212
 }
213
 
214
 /* A datastructure to pass all these callbacks to yajl */
215
-yajl_callbacks workspaces_callbacks = {
216
-    NULL,
217
-    &workspaces_boolean_cb,
218
-    &workspaces_integer_cb,
219
-    NULL,
220
-    NULL,
221
-    &workspaces_string_cb,
222
-    &workspaces_start_map_cb,
223
-    &workspaces_map_key_cb,
224
-    NULL,
225
-    NULL,
226
-    NULL
227
+static yajl_callbacks workspaces_callbacks = {
228
+    .yajl_boolean = workspaces_boolean_cb,
229
+    .yajl_integer = workspaces_integer_cb,
230
+    .yajl_string = workspaces_string_cb,
231
+    .yajl_start_map = workspaces_start_map_cb,
232
+    .yajl_map_key = workspaces_map_key_cb,
233
 };
234
 
235
 /*

b/src/display_version.c

240
@@ -42,17 +42,8 @@ static int version_map_key(void *ctx, const unsigned char *stringval, unsigned i
241
 }
242
 
243
 static yajl_callbacks version_callbacks = {
244
-    NULL, /* null */
245
-    NULL, /* boolean */
246
-    NULL, /* integer */
247
-    NULL, /* double */
248
-    NULL, /* number */
249
-    &version_string,
250
-    NULL, /* start_map */
251
-    &version_map_key,
252
-    NULL, /* end_map */
253
-    NULL, /* start_array */
254
-    NULL /* end_array */
255
+    .yajl_string = version_string,
256
+    .yajl_map_key = version_map_key,
257
 };
258
 
259
 /*

b/src/ipc.c

264
@@ -815,7 +815,6 @@ static int add_subscription(void *extra, const unsigned char *s,
265
  */
266
 IPC_HANDLER(subscribe) {
267
     yajl_handle p;
268
-    yajl_callbacks callbacks;
269
     yajl_status stat;
270
     ipc_client *current, *client = NULL;
271
 
272
@@ -834,8 +833,9 @@ IPC_HANDLER(subscribe) {
273
     }
274
 
275
     /* Setup the JSON parser */
276
-    memset(&callbacks, 0, sizeof(yajl_callbacks));
277
-    callbacks.yajl_string = add_subscription;
278
+    static yajl_callbacks callbacks = {
279
+        .yajl_string = add_subscription,
280
+    };
281
 
282
     p = yalloc(&callbacks, (void*)client);
283
     stat = yajl_parse(p, (const unsigned char*)message, message_size);

b/src/key_press.c

288
@@ -51,17 +51,10 @@ static int json_end_map(void *ctx) {
289
 }
290
 
291
 static yajl_callbacks command_error_callbacks = {
292
-    NULL,
293
-    &json_boolean,
294
-    NULL,
295
-    NULL,
296
-    NULL,
297
-    NULL,
298
-    &json_start_map,
299
-    &json_map_key,
300
-    &json_end_map,
301
-    NULL,
302
-    NULL
303
+    .yajl_boolean = json_boolean,
304
+    .yajl_start_map = json_start_map,
305
+    .yajl_map_key = json_map_key,
306
+    .yajl_end_map = json_end_map,
307
 };
308
 
309
 /*

b/src/load_layout.c

314
@@ -406,16 +406,16 @@ void tree_append_json(const char *filename, char **errormsg) {
315
     LOG("read %d bytes\n", n);
316
     yajl_gen g;
317
     yajl_handle hand;
318
-    yajl_callbacks callbacks;
319
-    memset(&callbacks, '\0', sizeof(yajl_callbacks));
320
-    callbacks.yajl_start_map = json_start_map;
321
-    callbacks.yajl_end_map = json_end_map;
322
-    callbacks.yajl_end_array = json_end_array;
323
-    callbacks.yajl_string = json_string;
324
-    callbacks.yajl_map_key = json_key;
325
-    callbacks.yajl_integer = json_int;
326
-    callbacks.yajl_double = json_double;
327
-    callbacks.yajl_boolean = json_bool;
328
+    static yajl_callbacks callbacks = {
329
+        .yajl_boolean = json_bool,
330
+        .yajl_integer = json_int,
331
+        .yajl_double = json_double,
332
+        .yajl_string = json_string,
333
+        .yajl_start_map = json_start_map,
334
+        .yajl_map_key = json_key,
335
+        .yajl_end_map = json_end_map,
336
+        .yajl_end_array = json_end_array,
337
+    };
338
 #if YAJL_MAJOR >= 2
339
     g = yajl_gen_alloc(NULL);
340
     hand = yajl_alloc(&callbacks, NULL, (void*)g);