Commit a901721dfca2590050a116eee5e163670dcde09f

Thomas de Grivel 2023-12-12T22:32:56

make demo_asan

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
diff --git a/Makefile b/Makefile
index 1cefaba..1448d25 100644
--- a/Makefile
+++ b/Makefile
@@ -74,12 +74,24 @@ debug:
 demo: build
 	${MAKE} -C libc3 demo
 
+demo_asan: asan
+	${MAKE} -C libc3 demo_asan
+
+demo_cov: cov
+	${MAKE} -C libc3 demo_cov
+
 demo_debug: debug
 	${MAKE} -C libc3 demo_debug
 
 demo_gl: build
 	${MAKE} -C libc3 demo_gl
 
+demo_gl_asan: asan
+	${MAKE} -C libc3 demo_gl_asan
+
+demo_gl_cov: cov
+	${MAKE} -C libc3 demo_gl_cov
+
 demo_gl_debug: debug
 	${MAKE} -C libc3 demo_gl_debug
 
@@ -190,27 +202,21 @@ test_gcovr:
 	${MAKE} gcovr
 
 test_ic3: build
-test_ic3:
 	${MAKE} -C test test_ic3
 
 test_ic3_asan: asan
-test_ic3_asan:
 	${MAKE} -C test test_ic3_asan
 
 test_ic3_cov: cov
-test_ic3_cov:
 	${MAKE} -C test test_ic3_cov
 
 test_ic3_debug: debug
-test_ic3_debug:
 	${MAKE} -C test test_ic3_debug
 
 test_libc3: build
-test_libc3:
 	${MAKE} -C test test_libc3
 
 test_libc3_cov: cov
-test_libc3_cov:
 	${MAKE} -C test test_libc3_cov
 
 test_libc3_debug:
@@ -220,12 +226,20 @@ test_libc3_debug:
 .PHONY: \
 	all \
 	asan \
+	build \
 	c3s \
 	cov \
 	clean \
 	clean_cov \
 	debug \
 	demo \
+	demo_asan \
+	demo_cov \
+	demo_debug \
+	demo_gl \
+	demo_gl_asan \
+	demo_gl_cov \
+	demo_gl_debug \
 	dist \
 	gcovr \
 	ic3 \
diff --git a/libc3/Makefile b/libc3/Makefile
index 1f4797b..57fb5d8 100644
--- a/libc3/Makefile
+++ b/libc3/Makefile
@@ -52,12 +52,24 @@ debug:
 demo: build
 	${MAKE} -C window demo
 
+demo_asan: asan
+	${MAKE} -C window demo_asan
+
+demo_cov: cov
+	${MAKE} -C window demo_cov
+
 demo_debug: debug
 	${MAKE} -C window demo_debug
 
 demo_gl: build
 	${MAKE} -C window demo_gl
 
+demo_gl_asan: asan
+	${MAKE} -C window demo_gl_asan
+
+demo_gl_cov: cov
+	${MAKE} -C window demo_gl_cov
+
 demo_gl_debug: debug
 	${MAKE} -C window demo_gl_debug
 
@@ -97,7 +109,30 @@ test:
 update_sources:
 	./update_sources
 
-.PHONY: all asan build clean cov debug distclean gdb_demo gen install lldb_demo test update_sources
+.PHONY: \
+	all \
+	asan \
+	build \
+	clean \
+	cov \
+	debug \
+	demo \
+	demo_asan \
+	demo_cov \
+	demo_debug \
+	demo_gl \
+	demo_gl_asan \
+	demo_gl_cov \
+	demo_gl_debug \
+	distclean \
+	gdb_demo \
+	gdb_demo_gl \
+	gen \
+	install \
+	lldb_demo \
+	lldb_demo_gl \
+	test \
+	update_sources \
 
 include config.mk
 include sources.mk
diff --git a/libc3/sequence.c b/libc3/sequence.c
index aab9017..e5864de 100644
--- a/libc3/sequence.c
+++ b/libc3/sequence.c
@@ -12,16 +12,24 @@
  */
 #include <assert.h>
 #include "sequence.h"
+#include "tag.h"
 
-s_sequence * sequence_init (s_sequence *sequence, f64 duration,
+void sequence_clean (s_sequence *seq)
+{
+  tag_clean(&seq->tag);
+}
+
+s_sequence * sequence_init (s_sequence *seq, f64 duration,
                             const s8 *title, f_sequence_load load,
                             f_sequence_render render)
 {
-  assert(sequence);
-  sequence->t = 0.0;
-  sequence->duration = duration;
-  sequence->title = title;
-  sequence->load = load;
-  sequence->render = render;
-  return sequence;
+  assert(seq);
+  seq->dt = 0.0;
+  seq->t = 0.0;
+  seq->duration = duration;
+  seq->title = title;
+  seq->load = load;
+  seq->render = render;
+  tag_init_void(&seq->tag);
+  return seq;
 }
diff --git a/libc3/sequence.h b/libc3/sequence.h
index d4a2c53..f150359 100644
--- a/libc3/sequence.h
+++ b/libc3/sequence.h
@@ -15,6 +15,9 @@
 
 #include "types.h"
 
+/* Stack-allocation compatible functions, call sequence_clean after
+   use. */
+void         sequence_clean (s_sequence *seq);
 s_sequence * sequence_init (s_sequence *sequence, f64 duration,
                             const s8 *title, f_sequence_load load,
                             f_sequence_render render);
diff --git a/libc3/window/Makefile b/libc3/window/Makefile
index f9a3a5b..14505c2 100644
--- a/libc3/window/Makefile
+++ b/libc3/window/Makefile
@@ -47,12 +47,24 @@ debug:
 demo: build
 	if ${HAVE_CAIRO}; then ${MAKE} -C cairo demo; fi
 
+demo_asan: asan
+	if ${HAVE_CAIRO}; then ${MAKE} -C cairo demo_asan; fi
+
+demo_cov: cov
+	if ${HAVE_CAIRO}; then ${MAKE} -C cairo demo_cov; fi
+
 demo_debug: debug
 	if ${HAVE_CAIRO}; then ${MAKE} -C cairo demo_debug; fi
 
 demo_gl: build
 	if ${HAVE_SDL2}; then ${MAKE} -C sdl2 demo; fi
 
+demo_gl_asan: asan
+	if ${HAVE_SDL2}; then ${MAKE} -C sdl2 demo_asan; fi
+
+demo_gl_cov: cov
+	if ${HAVE_SDL2}; then ${MAKE} -C sdl2 demo_cov; fi
+
 demo_gl_debug: debug
 	if ${HAVE_SDL2}; then ${MAKE} -C sdl2 demo_debug; fi
 
@@ -100,8 +112,19 @@ update_sources:
 	cov \
 	debug \
 	demo \
+	demo_asan \
+	demo_cov \
+	demo_debug \
+	demo_gl \
+	demo_gl_asan \
+	demo_gl_cov \
+	demo_gl_debug \
 	distclean \
+	gdb_demo \
+	gdb_demo_gl \
 	install \
+	lldb_demo \
+	lldb_demo_gl \
 	test \
 	update_sources
 
diff --git a/libc3/window/cairo/Makefile b/libc3/window/cairo/Makefile
index b00677a..daf6400 100644
--- a/libc3/window/cairo/Makefile
+++ b/libc3/window/cairo/Makefile
@@ -57,6 +57,12 @@ debug:
 demo: build
 	if ${HAVE_COCOA}; then ${MAKE} -C quartz demo; else if ${HAVE_WIN32}; then ${MAKE} -C win32 demo; else if ${HAVE_XCB}; then ${MAKE} -C xcb demo; fi; fi; fi
 
+demo_asan: asan
+	if ${HAVE_COCOA}; then ${MAKE} -C quartz demo_asan; else if ${HAVE_WIN32}; then ${MAKE} -C win32 demo_asan; else if ${HAVE_XCB}; then ${MAKE} -C xcb demo_asan; fi; fi; fi
+
+demo_cov: cov
+	if ${HAVE_COCOA}; then ${MAKE} -C quartz demo_cov; else if ${HAVE_WIN32}; then ${MAKE} -C win32 demo_cov; else if ${HAVE_XCB}; then ${MAKE} -C xcb demo_cov; fi; fi; fi
+
 demo_debug: debug
 	if ${HAVE_COCOA}; then ${MAKE} -C quartz demo_debug; else if ${HAVE_WIN32}; then ${MAKE} -C win32 demo_debug; else if ${HAVE_XCB}; then ${MAKE} -C xcb demo_debug; fi; fi; fi
 
@@ -106,9 +112,13 @@ update_sources:
 	cov \
 	debug \
 	demo \
+	demo_asan \
+	demo_cov \
+	demo_debug \
 	distclean \
 	gdb_demo \
 	install \
+	lldb_demo \
 	test \
 	update_sources
 
diff --git a/libc3/window/cairo/window_cairo.c b/libc3/window/cairo/window_cairo.c
index 67dd84d..8f7823a 100644
--- a/libc3/window/cairo/window_cairo.c
+++ b/libc3/window/cairo/window_cairo.c
@@ -14,6 +14,7 @@
 #include <stdlib.h>
 #include <xkbcommon/xkbcommon.h>
 #include <libc3/tag.h>
+#include "../window.h"
 #include "window_cairo.h"
 
 void c3_window_cairo_clean (void)
@@ -24,6 +25,11 @@ void c3_window_cairo_init (void)
 {
 }
 
+void window_cairo_clean (s_window_cairo *window)
+{
+  window_clean((s_window *) window);
+}
+
 s_window_cairo * window_cairo_init (s_window_cairo *window,
                                     sw x, sw y, uw w, uw h,
                                     const s8 *title,
@@ -118,6 +124,7 @@ s_sequence * window_cairo_sequence_init
  f_window_cairo_sequence_render render)
 {
   assert(seq);
+  seq->dt = 0.0;
   seq->t = 0.0;
   seq->duration = duration;
   seq->title = title;
diff --git a/libc3/window/cairo/window_cairo.h b/libc3/window/cairo/window_cairo.h
index 76e03fe..be868c2 100644
--- a/libc3/window/cairo/window_cairo.h
+++ b/libc3/window/cairo/window_cairo.h
@@ -20,18 +20,23 @@
 void c3_window_cairo_clean (void);
 void c3_window_cairo_init (void);
 
+/* Stack-allocation compatible functions, call window_cairo_clean
+   after use. */
+void             window_cairo_clean (s_window_cairo *window);
 s_window_cairo * window_cairo_init (s_window_cairo *window,
                                     sw x, sw y, uw w, uw h,
                                     const s8 *title,
                                     uw sequence_count);
 bool             window_cairo_run (s_window_cairo *window);
 
+/* Stack-allocation compatible functions, call sequence_clean
+   after use. */
 s_sequence *     window_cairo_sequence_init
 (s_sequence *sequence, f64 duration, const s8 *title,
  f_window_cairo_sequence_load load,
  f_window_cairo_sequence_render render);
 
-/* callbacks */
+/* Callbacks. */
 bool window_cairo_button_default (s_window_cairo *window, u8 button,
                                   sw x, sw y);
 bool window_cairo_key_default (s_window_cairo *window, uw keysym);
diff --git a/libc3/window/cairo/xcb/Makefile b/libc3/window/cairo/xcb/Makefile
index 69807db..0cfa050 100644
--- a/libc3/window/cairo/xcb/Makefile
+++ b/libc3/window/cairo/xcb/Makefile
@@ -51,6 +51,15 @@ debug:
 demo: build
 	${MAKE} -C demo demo
 
+demo_asan: asan
+	${MAKE} -C demo demo_asan
+
+demo_cov: cov
+	${MAKE} -C demo demo_cov
+
+demo_debug: debug
+	${MAKE} -C demo demo_debug
+
 distclean:
 	rm -rf ${DISTCLEANFILES}
 	${MAKE} -C demo distclean
@@ -80,10 +89,14 @@ update_sources:
 	cov \
 	debug \
 	demo \
+	demo_asan \
+	demo_cov \
+	demo_debug \
 	distclean \
 	gdb_demo \
 	gen \
 	install \
+	lldb_demo \
 	test \
 	update_sources
 
diff --git a/libc3/window/cairo/xcb/demo/Makefile b/libc3/window/cairo/xcb/demo/Makefile
index 6565300..49f6ea1 100644
--- a/libc3/window/cairo/xcb/demo/Makefile
+++ b/libc3/window/cairo/xcb/demo/Makefile
@@ -27,7 +27,8 @@ all:
 	${MAKE} debug
 	if ${HAVE_ASAN}; then ${MAKE} asan; fi
 
-asan: ${PROG_ASAN}
+asan:
+	${MAKE} ${PROG_ASAN}
 
 clean:
 	rm -rf ${CLEANFILES}
@@ -35,13 +36,28 @@ clean:
 clean_cov:
 	rm -rf ${CLEANFILES_COV}
 
-cov:   ${PROG_COV}
+cov:
+	${MAKE} ${PROG_COV}
 
-debug: ${PROG_DEBUG}
+debug:
+	${MAKE} ${PROG_DEBUG}
 
-demo: ${PROG}
+demo:
+	${MAKE} ${PROG}
 	time ./${PROG}
 
+demo_asan:
+	${MAKE} ${PROG_ASAN}
+	time ./${PROG_ASAN}
+
+demo_cov:
+	${MAKE} ${PROG_COV}
+	time ./${PROG_COV}
+
+demo_debug:
+	${MAKE} ${PROG_DEBUG}
+	time ./${PROG_DEBUG}
+
 distclean:
 	rm -rf ${DISTCLEANFILES}
 
@@ -55,6 +71,12 @@ install:
 	install -m 755 -d ${prefix}/bin
 	install -m 755 ${PROG} ${prefix}/bin/${PROG}
 
+lldb_demo: debug
+	if [ -f ${PROG_DEBUG}.core ]; then lldb .libs/${PROG_DEBUG} ${PROG_DEBUG}.core; else lldb .libs/${PROG_DEBUG}; fi
+
+update_sources:
+	./update_sources
+
 .PHONY: \
 	all \
 	asan \
@@ -64,9 +86,14 @@ install:
 	cov \
 	debug \
 	demo \
+	demo_asan \
+	demo_cov \
+	demo_debug \
 	distclean \
 	gdb_demo \
-	install
+	install \
+	lldb_demo \
+	update_sources \
 
 include config.mk
 include sources.mk
diff --git a/libc3/window/cairo/xcb/demo/window_cairo_xcb_demo.c b/libc3/window/cairo/xcb/demo/window_cairo_xcb_demo.c
index 9cf1feb..779d09e 100644
--- a/libc3/window/cairo/xcb/demo/window_cairo_xcb_demo.c
+++ b/libc3/window/cairo/xcb/demo/window_cairo_xcb_demo.c
@@ -38,7 +38,7 @@ int main (int argc, char **argv)
     c3_clean(NULL);
     return g_c3_exit_code;
   }
-  c3_window_cairo_clean();
+  window_cairo_clean(&window);
   c3_clean(NULL);
   return 0;
 }
diff --git a/libc3/window/window.c b/libc3/window/window.c
index e95fd38..76d7cc9 100644
--- a/libc3/window/window.c
+++ b/libc3/window/window.c
@@ -42,6 +42,18 @@ bool window_animate (s_window *window)
   return true;
 }
 
+void window_clean (s_window *window)
+{
+  uw i;
+  assert(window);
+  i = 0;
+  while (i < window->sequence_count) {
+    sequence_clean(window->sequence + i);
+    i++;
+  }
+  free(window->sequence);
+}
+
 bool window_set_sequence_pos (s_window *window, uw sequence_pos)
 {
   s_sequence *seq;
diff --git a/libc3/window/window.h b/libc3/window/window.h
index 716498f..90338ca 100644
--- a/libc3/window/window.h
+++ b/libc3/window/window.h
@@ -16,6 +16,10 @@
 #include <libc3/types.h>
 #include "types.h"
 
+/* Stack-allocation compatible functions, call window_clean
+   after use. */
+void window_clean (s_window *window);
+
 bool window_animate (s_window *window);
 bool window_set_sequence_pos (s_window *window, uw sequence_pos);