Commit ee55121b1be1e50f013f99e0ad548d39c47aca35

Thomas de Grivel 2022-11-10T16:51:49

wip make test_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
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
diff --git a/.gitignore b/.gitignore
index 57ef1a3..6f97059 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,7 @@ ic3/ic3.debug
 .libs/
 *.lo
 *.o
+test/*.facts
 test/ic3/*.diff
 test/ic3/*.err
 test/ic3/*.out
diff --git a/facts_test_dump.facts b/facts_test_dump.facts
new file mode 100644
index 0000000..bebffb3
--- /dev/null
+++ b/facts_test_dump.facts
@@ -0,0 +1,23 @@
+add {a, a, a}
+add {-18446744073709551616, -18446744073709551616, -18446744073709551616}
+add {18446744073709551616, 18446744073709551616, 18446744073709551616}
+add {-4294967296, -4294967296, -4294967296}
+add {-65536, -65536, -65536}
+add {-256, -256, -256}
+add {-10, -10, -10}
+add {-1, -1, -1}
+add {0, 0, 0}
+add {1, 1, 1}
+add {10, 10, 10}
+add {256, 256, 256}
+add {65536, 65536, 65536}
+add {4294967296, 4294967296, 4294967296}
+add {[], [], []}
+add {[[], []], [[], []], [[], []]}
+add {"a", "a", "a"}
+add {A, A, A}
+add {:a, :a, :a}
+add {{a, b}, {a, b}, {a, b}}
+add {{:a, :b}, {:a, :b}, {:a, :b}}
+add {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
+add {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
diff --git a/facts_test_log_add.facts b/facts_test_log_add.facts
new file mode 100644
index 0000000..5286f7a
--- /dev/null
+++ b/facts_test_log_add.facts
@@ -0,0 +1,23 @@
+add {"a", "a", "a"}
+add {:a, :a, :a}
+add {A, A, A}
+add {a, a, a}
+add {[], [], []}
+add {[[], []], [[], []], [[], []]}
+add {{:a, :b}, {:a, :b}, {:a, :b}}
+add {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
+add {{a, b}, {a, b}, {a, b}}
+add {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
+add {0, 0, 0}
+add {1, 1, 1}
+add {10, 10, 10}
+add {256, 256, 256}
+add {65536, 65536, 65536}
+add {4294967296, 4294967296, 4294967296}
+add {18446744073709551616, 18446744073709551616, 18446744073709551616}
+add {-1, -1, -1}
+add {-10, -10, -10}
+add {-256, -256, -256}
+add {-65536, -65536, -65536}
+add {-4294967296, -4294967296, -4294967296}
+add {-18446744073709551616, -18446744073709551616, -18446744073709551616}
diff --git a/facts_test_log_remove.facts b/facts_test_log_remove.facts
new file mode 100644
index 0000000..f96c838
--- /dev/null
+++ b/facts_test_log_remove.facts
@@ -0,0 +1,46 @@
+add {"a", "a", "a"}
+add {:a, :a, :a}
+add {A, A, A}
+add {a, a, a}
+add {[], [], []}
+add {[[], []], [[], []], [[], []]}
+add {{:a, :b}, {:a, :b}, {:a, :b}}
+add {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
+add {{a, b}, {a, b}, {a, b}}
+add {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
+add {0, 0, 0}
+add {1, 1, 1}
+add {10, 10, 10}
+add {256, 256, 256}
+add {65536, 65536, 65536}
+add {4294967296, 4294967296, 4294967296}
+add {18446744073709551616, 18446744073709551616, 18446744073709551616}
+add {-1, -1, -1}
+add {-10, -10, -10}
+add {-256, -256, -256}
+add {-65536, -65536, -65536}
+add {-4294967296, -4294967296, -4294967296}
+add {-18446744073709551616, -18446744073709551616, -18446744073709551616}
+remove {-18446744073709551616, -18446744073709551616, -18446744073709551616}
+remove {-4294967296, -4294967296, -4294967296}
+remove {-65536, -65536, -65536}
+remove {-256, -256, -256}
+remove {-10, -10, -10}
+remove {-1, -1, -1}
+remove {18446744073709551616, 18446744073709551616, 18446744073709551616}
+remove {4294967296, 4294967296, 4294967296}
+remove {65536, 65536, 65536}
+remove {256, 256, 256}
+remove {10, 10, 10}
+remove {1, 1, 1}
+remove {0, 0, 0}
+remove {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
+remove {{a, b}, {a, b}, {a, b}}
+remove {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
+remove {{:a, :b}, {:a, :b}, {:a, :b}}
+remove {[[], []], [[], []], [[], []]}
+remove {[], [], []}
+remove {a, a, a}
+remove {A, A, A}
+remove {:a, :a, :a}
+remove {"a", "a", "a"}
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 6e49ab0..540475a 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -812,7 +812,9 @@ sw buf_inspect_tag_size (const s_tag *tag)
   case TAG_U16:     return buf_inspect_u16_size(tag->data.u16);
   case TAG_U32:     return buf_inspect_u32_size(tag->data.u32);
   case TAG_U64:     return buf_inspect_u64_size(tag->data.u64);
-  case TAG_VAR:     errx(1, "buf_inspect_tag_size: variable");
+  case TAG_VAR:
+    assert(! "variable");
+    errx(1, "buf_inspect_tag_size: variable");
     return -1;
   }
   assert(! "unknown tag type");
diff --git a/libc3/call.c b/libc3/call.c
index 7a0c738..8e6d3e8 100644
--- a/libc3/call.c
+++ b/libc3/call.c
@@ -39,6 +39,15 @@ s8 call_compare (const s_call *a, const s_call *b)
   return list_compare(a->args, b->args);
 }
 
+s_call * call_copy (const s_call *src, s_call *dest)
+{
+  assert(src);
+  assert(dest);
+  ident_copy(&src->ident, &dest->ident);
+  list_copy(src->args, &dest->args);
+  return dest;
+}
+
 t_hash_context * call_hash_update (t_hash_context *context,
                                    const s_call *x)
 {
diff --git a/libc3/call.h b/libc3/call.h
index ca0afe0..ecb852c 100644
--- a/libc3/call.h
+++ b/libc3/call.h
@@ -21,6 +21,7 @@ void             call_clean (s_call *call);
 s_call *         call_init_1 (s_call *call, const s8 *p);
 
 s8               call_compare (const s_call *a, const s_call *b);
+s_call *         call_copy (const s_call *src, s_call *dest);
 t_hash_context * call_hash_update (t_hash_context *context,
                                    const s_call *call);
 s_str *          call_inspect (const s_call *call, s_str *dest);
diff --git a/libc3/facts_cursor.c b/libc3/facts_cursor.c
index f48504c..43bd0ad 100644
--- a/libc3/facts_cursor.c
+++ b/libc3/facts_cursor.c
@@ -64,11 +64,11 @@ s_fact * facts_cursor_next (s_facts_cursor *cursor)
   if (cursor->node) {
     s_fact *fact = cursor->node->fact;
     if (cursor->var_subject)
-      tag_copy(fact->subject, cursor->var_subject);
+      cursor->var_subject->data.var = fact->subject;
     if (cursor->var_predicate)
-      tag_copy(fact->predicate, cursor->var_predicate);
+      cursor->var_predicate->data.var = fact->predicate;
     if (cursor->var_object)
-      tag_copy(fact->object, cursor->var_object);
+      cursor->var_object->data.var = fact->object;
     return fact;
   }
   if (cursor->var_subject)
diff --git a/libc3/facts_spec.c b/libc3/facts_spec.c
index 2d41bf0..ac4ac08 100644
--- a/libc3/facts_spec.c
+++ b/libc3/facts_spec.c
@@ -54,8 +54,8 @@ p_facts_spec facts_spec_new_expand (p_facts_spec spec)
 
 p_facts_spec facts_spec_sort (p_facts_spec spec)
 {
-  p_var *a;
-  p_var *b;
+  s_tag **a;
+  s_tag **b;
   uw count;
   uw i = 0;
   uw j;
@@ -68,7 +68,7 @@ p_facts_spec facts_spec_sort (p_facts_spec spec)
         a = spec + j * 4;
         b = spec + (j + 1) * 4;
         if (fact_compare_var_count((s_fact *) a, (s_fact *) b) > 0) {
-          p_var swap[3];
+          s_tag *swap[3];
           swap[0] = a[0];
           swap[1] = a[1];
           swap[2] = a[2];
diff --git a/libc3/facts_with.c b/libc3/facts_with.c
index ef410c4..f384e2b 100644
--- a/libc3/facts_with.c
+++ b/libc3/facts_with.c
@@ -91,9 +91,9 @@ s_facts_cursor * facts_with_tags (const s_facts *facts,
                                   s_tag *predicate,
                                   s_tag *object)
 {
-  p_var var_subject;
-  p_var var_predicate;
-  p_var var_object;
+  s_tag *var_subject;
+  s_tag *var_predicate;
+  s_tag *var_object;
   assert(facts);
   assert(cursor);
   assert(subject);
diff --git a/libc3/facts_with_cursor.c b/libc3/facts_with_cursor.c
index 82e0533..31741d0 100644
--- a/libc3/facts_with_cursor.c
+++ b/libc3/facts_with_cursor.c
@@ -49,7 +49,7 @@ s_fact * facts_with_cursor_next (s_facts_with_cursor *cursor)
   }
   while (cursor->level < cursor->facts_count) {
     level = cursor->l + cursor->level;
-    if (!level->spec) {
+    if (! level->spec) {
       parent_spec = cursor->level ?
         cursor->l[cursor->level - 1].spec + 4 :
         cursor->spec;
@@ -58,23 +58,17 @@ s_fact * facts_with_cursor_next (s_facts_with_cursor *cursor)
                       level->spec[1], level->spec[2]);
     }
     level->fact = fact = facts_cursor_next(&level->cursor);
-    if (level->fact)
+    if (fact) {
       cursor->level++;
-    else {
-      free(level->spec);
-      level->spec = NULL;
-      if (cursor->level > 0) {
-        cursor->level--;
-        if (!cursor->level) {
-          cursor->facts_count = 0;
-          return NULL;
-        }
-      }
-      else {
-        cursor->facts_count = 0;
-        return NULL;
-      }
+      continue;
     }
+    free(level->spec);
+    level->spec = NULL;
+    if (! cursor->level) {
+      cursor->facts_count = 0;
+      return NULL;
+    }
+    cursor->level--;
   }
   return fact;
 }
diff --git a/libc3/ident.c b/libc3/ident.c
index f6c969a..0e44b1f 100644
--- a/libc3/ident.c
+++ b/libc3/ident.c
@@ -47,6 +47,13 @@ s8 ident_compare (const s_ident *a, const s_ident *b)
   return sym_compare(a->sym, b->sym);
 }
 
+s_ident * ident_copy (const s_ident *src, s_ident *dest)
+{
+  dest->module = src->module;
+  dest->sym = src->sym;
+  return dest;
+}
+
 e_bool ident_first_character_is_reserved (character c)
 {
   return (character_is_digit(c) ||
diff --git a/libc3/ident.h b/libc3/ident.h
index 3c5000b..bf41e08 100644
--- a/libc3/ident.h
+++ b/libc3/ident.h
@@ -31,6 +31,8 @@ e_bool ident_character_is_reserved (character c);
 /* Compare two idents. Returns -1 if a < b, 0 if a = b, 1 if a > b. */
 s8 ident_compare (const s_ident *a, const s_ident *b);
 
+s_ident * ident_copy (const s_ident *src, s_ident *dest);
+
 /* Returns true iff c is an ident reserved character as first. */
 e_bool ident_first_character_is_reserved (character c);
 
diff --git a/libc3/tag.c b/libc3/tag.c
index 01b3667..bdddfc0 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -118,6 +118,7 @@ void tag_clean (s_tag *tag)
 {
   assert(tag);
   switch (tag->type.type) {
+  case TAG_CALL:    call_clean(&tag->data.call);       break;
   case TAG_INTEGER: integer_clean(&tag->data.integer); break;
   case TAG_LIST:    list_delete(tag->data.list);       break;
   case TAG_QUOTE:   quote_clean(tag->data.quote);      break;
@@ -168,7 +169,7 @@ s8 tag_compare (const s_tag *a, const s_tag *b) {
   case TAG_U16: return u16_compare(a->data.u16, b->data.u16);
   case TAG_U32: return u32_compare(a->data.u32, b->data.u32);
   case TAG_U64: return u64_compare(a->data.u64, b->data.u64);
-  case TAG_VAR: return ptr_compare(a, b);
+  case TAG_VAR: return ptr_compare(a->data.var, b->data.var);
   }
   assert(! "tag_compare: error");
   errx(1, "tag_compare");
@@ -180,6 +181,7 @@ s_tag * tag_copy (const s_tag *src, s_tag *dest)
   assert(src);
   assert(dest);
   switch (src->type.type) {
+  case TAG_CALL: call_copy(&src->data.call, &dest->data.call);    break;
   case TAG_INTEGER:
     integer_init(&dest->data.integer);
     integer_copy(&src->data.integer, &dest->data.integer);        break;
diff --git a/libc3/types.h b/libc3/types.h
index 8175c43..9e756be 100644
--- a/libc3/types.h
+++ b/libc3/types.h
@@ -129,7 +129,7 @@ typedef struct call {
   s_list *args;
 } s_call;
 
-typedef s_tag * p_var;
+typedef const s_tag * p_var;
 
 typedef enum tag_type {
   TAG_VOID = 0,
@@ -183,6 +183,7 @@ typedef union tag_data {
   u16          u16;
   u32          u32;
   u64          u64;
+  p_var        var;
 } u_tag_data;
 
 struct tag {
@@ -283,7 +284,7 @@ typedef s_tag ** p_facts_spec;
 
 typedef struct facts_spec_cursor {
   p_facts_spec spec;
-  s_tag *subject;
+  const s_tag *subject;
   uw pos;
 } s_facts_spec_cursor;
 
diff --git a/test/buf_parse_test.c b/test/buf_parse_test.c
index ff1ed74..8f5bc03 100644
--- a/test/buf_parse_test.c
+++ b/test/buf_parse_test.c
@@ -17,6 +17,7 @@
 #include <string.h>
 #include "../libc3/buf.h"
 #include "../libc3/buf_parse.h"
+#include "../libc3/call.h"
 #include "../libc3/list.h"
 #include "../libc3/str.h"
 #include "../libc3/integer.h"
@@ -42,6 +43,7 @@
     test_context("buf_parse_call(" # test ")");                        \
     buf_init_1(&buf, (test));                                          \
     TEST_EQ(buf_parse_call(&buf, &dest), strlen(test));                \
+    call_clean(&dest);                                                 \
     buf_clean(&buf);                                                   \
     test_context(NULL);                                                \
   } while (0)
diff --git a/test/call_test.c b/test/call_test.c
index d6fa930..9ed310e 100644
--- a/test/call_test.c
+++ b/test/call_test.c
@@ -13,6 +13,7 @@
  */
 #include <string.h>
 #include "../libc3/call.h"
+#include "../libc3/str.h"
 #include "test.h"
 
 #define CALL_TEST_INIT_1(test)                                         \
@@ -30,7 +31,10 @@
     call_init_1(&call, (test));                                        \
     TEST_EQ(call_inspect(&call, &result), &result);                    \
     TEST_EQ(result.size, strlen(test));                                \
-    TEST_STRNCMP(result.ptr.p, (test), result.size);                   \
+    if (g_test_last_ok)	                                               \
+      TEST_STRNCMP(result.ptr.p, (test), result.size);                 \
+    call_clean(&call);						       \
+    str_clean(&result);						       \
   } while (0)
 
 void call_test ();
diff --git a/test/fact_test.c b/test/fact_test.c
index 0321154..de63286 100644
--- a/test/fact_test.c
+++ b/test/fact_test.c
@@ -13,6 +13,7 @@
  */
 #include <string.h>
 #include "../libc3/fact.h"
+#include "../libc3/str.h"
 #include "fact_test.h"
 #include "test.h"
 
@@ -21,7 +22,9 @@
     s_str str;                                                         \
     TEST_EQ(fact_inspect(test, &str), &str);                           \
     TEST_EQ(str.size, strlen(expected));                               \
-    TEST_STRNCMP(str.ptr.p, (expected), str.size);                     \
+    if (g_test_last_ok)						       \
+      TEST_STRNCMP(str.ptr.p, (expected), str.size);		       \
+    str_clean(&str);						       \
   } while (0)
 
 void fact_test ();
@@ -34,13 +37,18 @@ void fact_test ()
   fact_test_inspect();
 }
 
-s_fact * fact_test_clean (s_fact *fact)
+void fact_test_clean_1 (s_fact *fact)
+{
+  assert(fact);
+  tag_delete((s_tag *) fact->subject);
+}
+
+void fact_test_clean_3 (s_fact *fact)
 {
   assert(fact);
   tag_delete((s_tag *) fact->subject);
   tag_delete((s_tag *) fact->predicate);
   tag_delete((s_tag *) fact->object);
-  return fact;
 }
 
 void fact_test_init ()
@@ -58,7 +66,9 @@ void fact_test_init ()
 
 s_fact * fact_test_init_1 (s_fact *fact, const s8 *tag)
 {
-  return fact_test_init_3(fact, tag, tag, tag);
+  assert(fact);
+  fact->subject = fact->predicate = fact->object = tag_new_1(tag);
+  return fact;
 }
 
 s_fact * fact_test_init_3 (s_fact *fact, const s8 *subject,
diff --git a/test/fact_test.h b/test/fact_test.h
index 67e437a..14c9054 100644
--- a/test/fact_test.h
+++ b/test/fact_test.h
@@ -44,7 +44,8 @@
     }                                                                  \
   } while (0)
 
-s_fact * fact_test_clean (s_fact *fact);
+void     fact_test_clean_1 (s_fact *fact);
+void     fact_test_clean_3 (s_fact *fact);
 s_fact * fact_test_init_1 (s_fact *fact, const s8 *tag);
 s_fact * fact_test_init_3 (s_fact *fact, const s8 *subject,
                            const s8 *predicate, const s8 *object);
diff --git a/test/facts_cursor_test.c b/test/facts_cursor_test.c
index 0bfec79..e18ec9e 100644
--- a/test/facts_cursor_test.c
+++ b/test/facts_cursor_test.c
@@ -91,7 +91,7 @@ void facts_cursor_test_init ()
                             fact + 6), &cursor);
   i = 0;
   while (p[i]) {
-    fact_test_clean(fact + i);
+    fact_test_clean_1(fact + i);
     i++;
   }
   facts_clean(&facts);
@@ -203,7 +203,7 @@ void facts_cursor_test_next ()
   TEST_EQ(facts_cursor_next(&cursor), NULL);
   i = 0;
   while (p[i]) {
-    fact_test_clean(fact + i);
+    fact_test_clean_1(fact + i);
     i++;
   }
   facts_clean(&facts);
diff --git a/test/facts_test.c b/test/facts_test.c
index 5d46050..02d98f5 100644
--- a/test/facts_test.c
+++ b/test/facts_test.c
@@ -87,7 +87,7 @@ void facts_test_add ()
     TEST_EQ(tag_compare(fact[i].subject, pf->subject), 0);
     TEST_EQ(tag_compare(fact[i].predicate, pf->predicate), 0);
     TEST_EQ(tag_compare(fact[i].object, pf->object), 0);
-    fact_test_clean(fact + i);
+    fact_test_clean_1(fact + i);
     i++;
   }
   facts_clean(&facts);
@@ -133,6 +133,11 @@ void facts_test_dump ()
   facts_dump(&facts, "facts_test_dump.facts");
   test_file_compare("facts_test_dump.facts",
                     "facts_test_dump.facts.expected");
+  i = 0;
+  while (p[i]) {
+    fact_test_clean_1(fact + i);
+    i++;
+  }
   facts_clean(&facts);
 }
 
@@ -184,7 +189,7 @@ void facts_test_find ()
     facts_remove_fact(&facts, fact + i);
     TEST_EQ(facts_find_fact(&facts, fact + i), NULL);
     TEST_EQ(facts_find_fact(&facts, fact + i), NULL);
-    fact_test_clean(fact + i);
+    fact_test_clean_1(fact + i);
   }
   facts_clean(&facts);
 }
@@ -252,7 +257,7 @@ void facts_test_log_add ()
   while (p[i]) {
     fact_test_init_1(fact + i, p[i]);
     facts_add_fact(&facts, fact + i);
-    fact_test_clean(fact + i);
+    fact_test_clean_1(fact + i);
     i++;
   }
   facts_clean(&facts);
@@ -306,6 +311,11 @@ void facts_test_log_remove ()
   while (i--) {
     facts_remove_fact(&facts, fact + i);
   }
+  i = 0;
+  while (p[i]) {
+    fact_test_clean_1(fact + i);
+    i++;
+  }
   facts_clean(&facts);
   buf_file_close(&log);
   fclose(fp);
@@ -380,7 +390,7 @@ void facts_test_remove ()
     TEST_EQ(facts_remove_fact(&facts, fact + i), false);
     TEST_EQ(facts.tags.count, i);
     TEST_EQ(facts.facts.count, i);
-    fact_test_clean(fact + i);
+    fact_test_clean_1(fact + i);
   }
   facts_clean(&facts);
 }
diff --git a/test/facts_test_dump.facts b/test/facts_test_dump.facts
deleted file mode 100644
index bebffb3..0000000
--- a/test/facts_test_dump.facts
+++ /dev/null
@@ -1,23 +0,0 @@
-add {a, a, a}
-add {-18446744073709551616, -18446744073709551616, -18446744073709551616}
-add {18446744073709551616, 18446744073709551616, 18446744073709551616}
-add {-4294967296, -4294967296, -4294967296}
-add {-65536, -65536, -65536}
-add {-256, -256, -256}
-add {-10, -10, -10}
-add {-1, -1, -1}
-add {0, 0, 0}
-add {1, 1, 1}
-add {10, 10, 10}
-add {256, 256, 256}
-add {65536, 65536, 65536}
-add {4294967296, 4294967296, 4294967296}
-add {[], [], []}
-add {[[], []], [[], []], [[], []]}
-add {"a", "a", "a"}
-add {A, A, A}
-add {:a, :a, :a}
-add {{a, b}, {a, b}, {a, b}}
-add {{:a, :b}, {:a, :b}, {:a, :b}}
-add {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
-add {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
diff --git a/test/facts_test_log_add.facts b/test/facts_test_log_add.facts
deleted file mode 100644
index 5286f7a..0000000
--- a/test/facts_test_log_add.facts
+++ /dev/null
@@ -1,23 +0,0 @@
-add {"a", "a", "a"}
-add {:a, :a, :a}
-add {A, A, A}
-add {a, a, a}
-add {[], [], []}
-add {[[], []], [[], []], [[], []]}
-add {{:a, :b}, {:a, :b}, {:a, :b}}
-add {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-add {{a, b}, {a, b}, {a, b}}
-add {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
-add {0, 0, 0}
-add {1, 1, 1}
-add {10, 10, 10}
-add {256, 256, 256}
-add {65536, 65536, 65536}
-add {4294967296, 4294967296, 4294967296}
-add {18446744073709551616, 18446744073709551616, 18446744073709551616}
-add {-1, -1, -1}
-add {-10, -10, -10}
-add {-256, -256, -256}
-add {-65536, -65536, -65536}
-add {-4294967296, -4294967296, -4294967296}
-add {-18446744073709551616, -18446744073709551616, -18446744073709551616}
diff --git a/test/facts_test_log_remove.facts b/test/facts_test_log_remove.facts
deleted file mode 100644
index f96c838..0000000
--- a/test/facts_test_log_remove.facts
+++ /dev/null
@@ -1,46 +0,0 @@
-add {"a", "a", "a"}
-add {:a, :a, :a}
-add {A, A, A}
-add {a, a, a}
-add {[], [], []}
-add {[[], []], [[], []], [[], []]}
-add {{:a, :b}, {:a, :b}, {:a, :b}}
-add {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-add {{a, b}, {a, b}, {a, b}}
-add {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
-add {0, 0, 0}
-add {1, 1, 1}
-add {10, 10, 10}
-add {256, 256, 256}
-add {65536, 65536, 65536}
-add {4294967296, 4294967296, 4294967296}
-add {18446744073709551616, 18446744073709551616, 18446744073709551616}
-add {-1, -1, -1}
-add {-10, -10, -10}
-add {-256, -256, -256}
-add {-65536, -65536, -65536}
-add {-4294967296, -4294967296, -4294967296}
-add {-18446744073709551616, -18446744073709551616, -18446744073709551616}
-remove {-18446744073709551616, -18446744073709551616, -18446744073709551616}
-remove {-4294967296, -4294967296, -4294967296}
-remove {-65536, -65536, -65536}
-remove {-256, -256, -256}
-remove {-10, -10, -10}
-remove {-1, -1, -1}
-remove {18446744073709551616, 18446744073709551616, 18446744073709551616}
-remove {4294967296, 4294967296, 4294967296}
-remove {65536, 65536, 65536}
-remove {256, 256, 256}
-remove {10, 10, 10}
-remove {1, 1, 1}
-remove {0, 0, 0}
-remove {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
-remove {{a, b}, {a, b}, {a, b}}
-remove {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-remove {{:a, :b}, {:a, :b}, {:a, :b}}
-remove {[[], []], [[], []], [[], []]}
-remove {[], [], []}
-remove {a, a, a}
-remove {A, A, A}
-remove {:a, :a, :a}
-remove {"a", "a", "a"}
diff --git a/test/facts_with_test.c b/test/facts_with_test.c
index 9638bfb..bded6a7 100644
--- a/test/facts_with_test.c
+++ b/test/facts_with_test.c
@@ -109,21 +109,25 @@ void facts_with_test_ ()
                                             &object,
                                             NULL, NULL });
   TEST_ASSERT(facts_with_cursor_next(&cursor));
-  TAG_TEST_EQ(&subject, tag);
-  TAG_TEST_EQ(&predicate, tag + 1);
-  TAG_TEST_EQ(&object, tag + 2);
+  TAG_TEST_EQ(subject.data.var, tag);
+  TAG_TEST_EQ(predicate.data.var, tag + 1);
+  TAG_TEST_EQ(object.data.var, tag + 2);
   TEST_ASSERT(facts_with_cursor_next(&cursor));
-  TAG_TEST_EQ(&subject, tag + 5);
-  TAG_TEST_EQ(&predicate, tag + 1);
-  TAG_TEST_EQ(&object, tag + 2);
+  TAG_TEST_EQ(subject.data.var, tag);
+  TAG_TEST_EQ(predicate.data.var, tag + 1);
+  TAG_TEST_EQ(object.data.var, tag + 3);
   TEST_ASSERT(facts_with_cursor_next(&cursor));
-  TAG_TEST_EQ(&subject, tag);
-  TAG_TEST_EQ(&predicate, tag + 1);
-  TAG_TEST_EQ(&object, tag + 3);
+  TAG_TEST_EQ(subject.data.var, tag + 5);
+  TAG_TEST_EQ(predicate.data.var, tag + 1);
+  TAG_TEST_EQ(object.data.var, tag + 2);
   TEST_ASSERT(facts_with_cursor_next(&cursor));
-  TAG_TEST_EQ(&subject, tag);
-  TAG_TEST_EQ(&predicate, tag + 4);
-  TAG_TEST_EQ(&object, tag + 3);
+  TAG_TEST_EQ(subject.data.var, tag);
+  TAG_TEST_EQ(predicate.data.var, tag + 1);
+  TAG_TEST_EQ(object.data.var, tag + 3);
+  TEST_ASSERT(facts_with_cursor_next(&cursor));
+  TAG_TEST_EQ(subject.data.var, tag);
+  TAG_TEST_EQ(predicate.data.var, tag + 4);
+  TAG_TEST_EQ(object.data.var, tag + 3);
   TEST_EQ(facts_with_cursor_next(&cursor), NULL);
   TEST_EQ(facts_with_cursor_next(&cursor), NULL);
   facts_with_cursor_clean(&cursor);
diff --git a/test/set__fact_test.c b/test/set__fact_test.c
index 4dda7f1..54bd407 100644
--- a/test/set__fact_test.c
+++ b/test/set__fact_test.c
@@ -133,7 +133,7 @@ void set__fact_test_add ()
   }
   i = 0;
   while (p[i]) {
-    fact_test_clean(fact + i);
+    fact_test_clean_1(fact + i);
     i++;
   }
   set_clean__fact(&set);
@@ -183,7 +183,7 @@ void set__fact_test_cursor ()
   while (i--) {
     set_remove__fact(&set, fact + i);
     SET__FACT_TEST_CURSOR(i);
-    fact_test_clean(fact + i);
+    fact_test_clean_1(fact + i);
   }
   set_clean__fact(&set);
 }
@@ -263,7 +263,7 @@ void set__fact_test_remove ()
   i = set.count;
   while (i--) {
     SET__FACT_TEST_REMOVE(fact + i, i);
-    fact_test_clean(fact + i);
+    fact_test_clean_1(fact + i);
   }
   set_clean__fact(&set);
 }
@@ -341,8 +341,10 @@ void set__fact_test_resize ()
   SET__FACT_TEST_RESIZE(32768);
   SET__FACT_TEST_RESIZE(65536);
   SET__FACT_TEST_RESIZE(65536);
-  i = set.count;
-  while (i--)
-    fact_test_clean(fact + i);
+  i = 0;
+  while (p[i]) {
+    fact_test_clean_1(fact + i);
+    i++;
+  }
   set_clean__fact(&set);
 }
diff --git a/test/skiplist__fact_test.c b/test/skiplist__fact_test.c
index cb846a2..5d34cf1 100644
--- a/test/skiplist__fact_test.c
+++ b/test/skiplist__fact_test.c
@@ -130,7 +130,7 @@ void skiplist__fact_test_find ()
       while (i--) {
         skiplist_remove__fact(skiplist, fact + i);
         TEST_ASSERT(! skiplist_find__fact(skiplist, fact + i));
-        fact_test_clean(fact + i);
+        fact_test_clean_1(fact + i);
       }
       skiplist_clean__fact(skiplist);
     }
@@ -190,7 +190,7 @@ void skiplist__fact_test_insert ()
   }
   i = 0;
   while (p[i]) {
-    fact_test_clean(fact + i);
+    fact_test_clean_1(fact + i);
     i++;
   }
 }
@@ -268,7 +268,7 @@ void skiplist__fact_test_remove ()
       i = skiplist->length;
       while (i--) {
         SKIPLIST__FACT_TEST_REMOVE(fact + i, i);
-        fact_test_clean(fact + i);
+        fact_test_clean_1(fact + i);
       }
       skiplist_clean__fact(skiplist);
     }
diff --git a/test/tag_test.h b/test/tag_test.h
index ebd7d00..2c72d2c 100644
--- a/test/tag_test.h
+++ b/test/tag_test.h
@@ -18,8 +18,8 @@
 
 #define TAG_TEST_EQ(test, expected)                                    \
   do {                                                                 \
-    s_tag *tag_expected;                                               \
-    s_tag *tag_test;                                                   \
+    const s_tag *tag_expected;                                               \
+    const s_tag *tag_test;                                                   \
     tag_expected = (expected);                                         \
     tag_test = (test);                                                 \
     if (tag_compare(tag_test, tag_expected) == 0) {                    \