Commit 3ea776cf449ff38dccc28eeeacdbd0a035042d9f

Thomas de Grivel 2023-12-29T16:45:36

refactor hash

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
diff --git a/libc3/hash.c b/libc3/hash.c
index 7fa665c..29102b0 100644
--- a/libc3/hash.c
+++ b/libc3/hash.c
@@ -22,13 +22,13 @@
 #include "void.h"
 
 #define HASH_UPDATE_DEF(type)                                          \
-  void hash_update_##type (t_hash *hash, const type *x)                \
+  bool hash_update_##type (t_hash *hash, const type *x)                \
   {                                                                    \
     const s8 t[] = #type;                                              \
     assert(hash);                                                      \
     assert(x);                                                         \
-    hash_update(hash, t, sizeof(t));                                   \
-    hash_update(hash, x, sizeof(type));                                \
+    return hash_update(hash, t, sizeof(t)) &&                          \
+      hash_update(hash, x, sizeof(type));                              \
   }
 
 void hash_clean (t_hash *hash)
@@ -56,79 +56,86 @@ u64 hash_to_u64 (t_hash *hash)
   return *((u64 *) digest);
 }
 
-void hash_update (t_hash *hash, const void *data, uw size)
+bool hash_update (t_hash *hash, const void *data, uw size)
 {
   assert(hash);
   assert(data);
   SHA1Update(hash, data, size);
+  return true;
 }
 
-void hash_update_1 (t_hash *hash, const s8 *p)
+bool hash_update_1 (t_hash *hash, const s8 *p)
 {
   uw len;
   const s8 type[] = "s8*";
   assert(hash);
   assert(p);
-  hash_update(hash, type, sizeof(type));
   len = strlen(p);
-  hash_update(hash, &len, sizeof(len));
-  hash_update(hash, p, strlen(p));
+  return hash_update(hash, type, sizeof(type)) &&
+    hash_update(hash, &len, sizeof(len)) &&
+    hash_update(hash, p, strlen(p));
 }
 
-void hash_update_array (t_hash *hash, const s_array *a)
+bool hash_update_array (t_hash *hash, const s_array *a)
 {
   uw i = 0;
   const s8 type[] = "array";
   assert(hash);
   assert(a);
-  hash_update(hash, type, sizeof(type));
-  hash_update(hash, &a->dimension, sizeof(a->dimension));
-  hash_update(hash, &a->type, sizeof(a->type));
+  if (! hash_update(hash, type, sizeof(type)) ||
+      ! hash_update(hash, &a->dimension, sizeof(a->dimension)) ||
+      ! hash_update(hash, &a->type, sizeof(a->type)))
+    return false;
   while (i < a->dimension) {
-    hash_update(hash, &a->dimensions[i].count,
-                sizeof(a->dimensions[i].count));
+    if (! hash_update(hash, &a->dimensions[i].count,
+                      sizeof(a->dimensions[i].count)))
+      return false;
     i++;
   }
-  if (a->data)
-    hash_update(hash, a->data, a->size);
+  if (a->data) {
+    if (! hash_update(hash, a->data, a->size))
+      return false;
+  }
   else if (a->tags) {
     i = 0;
     while (i < a->count) {
-      hash_update_tag(hash, a->tags + i);
+      if (! hash_update_tag(hash, a->tags + i))
+        return false;
       i++;
     }
   }
+  return true;
 }
 
-void hash_update_bool (t_hash *hash, const bool *x)
+bool hash_update_bool (t_hash *hash, const bool *x)
 {
   bool b;
   const s8 type[] = "bool";
   assert(hash);
   assert(x);
-  hash_update(hash, type, sizeof(type));
   b = x ? 1 : 0;
-  hash_update(hash, &b, sizeof(b));
+  return hash_update(hash, type, sizeof(type)) &&
+    hash_update(hash, &b, sizeof(b));
 }
 
-void hash_update_call (t_hash *hash, const s_call *call)
+bool hash_update_call (t_hash *hash, const s_call *call)
 {
   const s8 type[] = "call";
   assert(hash);
   assert(call);
-  hash_update(hash, type, sizeof(type));
-  hash_update_ident(hash, &call->ident);
-  hash_update_list(hash, (const s_list * const *) &call->arguments);
+  return hash_update(hash, type, sizeof(type)) &&
+    hash_update_ident(hash, &call->ident) &&
+    hash_update_list(hash, (const s_list * const *) &call->arguments);
 }
 
-void hash_update_cfn (t_hash *hash, const s_cfn *cfn)
+bool hash_update_cfn (t_hash *hash, const s_cfn *cfn)
 {
   const s8 type[] = "cfn";
   assert(hash);
   assert(cfn);
-  hash_update(hash, type, sizeof(type));
-  hash_update_sym(hash, &cfn->name);
-  hash_update_list(hash, (const s_list * const *) &cfn->arg_types);
+  return hash_update(hash, type, sizeof(type)) &&
+    hash_update_sym(hash, &cfn->name) &&
+    hash_update_list(hash, (const s_list * const *) &cfn->arg_types);
 }
 
 HASH_UPDATE_DEF(character)
@@ -137,7 +144,7 @@ HASH_UPDATE_DEF(f32)
 
 HASH_UPDATE_DEF(f64)
 
-void hash_update_fact (t_hash *hash, const s_fact *fact)
+bool hash_update_fact (t_hash *hash, const s_fact *fact)
 {
   const s8 type[] = "fact";
   assert(hash);
@@ -145,58 +152,67 @@ void hash_update_fact (t_hash *hash, const s_fact *fact)
   assert(fact->subject);
   assert(fact->predicate);
   assert(fact->object);
-  hash_update(hash, type, sizeof(type));
-  hash_update_tag(hash, fact->subject);
-  hash_update_tag(hash, fact->predicate);
-  hash_update_tag(hash, fact->object);
+  return hash_update(hash, type, sizeof(type)) &&
+    hash_update_tag(hash, fact->subject) &&
+    hash_update_tag(hash, fact->predicate) &&
+    hash_update_tag(hash, fact->object);
 }
 
-void hash_update_fn (t_hash *hash, const s_fn *fn)
+bool hash_update_fn (t_hash *hash, const s_fn *fn)
 {
   const s8 type[] = "fn";
   assert(hash);
   assert(fn);
-  hash_update(hash, type, sizeof(type));
-  hash_update_bool(hash, &fn->macro);
-  hash_update_bool(hash, &fn->special_operator);
-  hash_update_fn_clauses(hash, fn->clauses);
+  return hash_update(hash, type, sizeof(type)) &&
+    hash_update_bool(hash, &fn->macro) &&
+    hash_update_bool(hash, &fn->special_operator) &&
+    hash_update_fn_clauses(hash, fn->clauses);
 }
 
-void hash_update_fn_clauses (t_hash *hash, const s_fn_clause *clauses)
+bool hash_update_fn_clauses (t_hash *hash, const s_fn_clause *clauses)
 {
   uw count = 0;
   const s_fn_clause *f;
   const s8 type[] = "fn_clauses";
   assert(hash);
   assert(clauses);
-  hash_update(hash, type, sizeof(type));
+  if (! hash_update(hash, type, sizeof(type)))
+    return false;
   f = clauses;
   while (f) {
     count++;
     f = f->next_clause;
   }
-  hash_update_uw(hash, &count);
+  if (! hash_update_uw(hash, &count))
+    return false;
   f = clauses;
   while (f) {
-    hash_update_list(hash, (const s_list * const *) &f->pattern);
-    hash_update_list(hash, (const s_list * const *) &f->algo);
+    if (! hash_update_list(hash, (const s_list * const *)
+                           &f->pattern) ||
+        ! hash_update_list(hash, (const s_list * const *)
+                           &f->algo))
+      return false;
     f = f->next_clause;
   }
+  return true;
 }
 
-void hash_update_ident (t_hash *hash, const s_ident *ident)
+bool hash_update_ident (t_hash *hash, const s_ident *ident)
 {
+  const s8 type[] = "ident";
   assert(hash);
   assert(ident);
-  hash_update_s8(hash, "_");
+  if (! hash_update(hash, type, sizeof(type)))
+    return false;
   if (ident->module) {
-    hash_update_sym(hash, &ident->module);
-    hash_update_s8(hash, ".");
+    if (! hash_update_sym(hash, &ident->module) ||
+        ! hash_update_s8(hash, "."))
+      return false;
   }
-  hash_update_sym(hash, &ident->sym);
+  return hash_update_sym(hash, &ident->sym);
 }
 
-void hash_update_integer (t_hash *hash, const s_integer *i)
+bool hash_update_integer (t_hash *hash, const s_integer *i)
 {
   int j = 0;
   mp_digit *digit;
@@ -204,17 +220,20 @@ void hash_update_integer (t_hash *hash, const s_integer *i)
   assert(hash);
   assert(i);
   digit = i->mp_int.dp;
-  hash_update(hash, type, 7);
-  hash_update(hash, &i->mp_int.used, sizeof(i->mp_int.used));
+  if (! hash_update(hash, type, sizeof(type)) ||
+      ! hash_update(hash, &i->mp_int.used, sizeof(i->mp_int.used)))
+    return false;
   while (j < i->mp_int.used) {
-    hash_update(hash, digit, sizeof(*digit));
+    if (! hash_update(hash, digit, sizeof(*digit)))
+      return false;
     digit++;
     j++;
   }
+  return true;
 }
 
 /* FIXME: circular lists */
-void hash_update_list (t_hash *hash, const s_list * const *list)
+bool hash_update_list (t_hash *hash, const s_list * const *list)
 {
   uw count;
   const s_list *l;
@@ -223,62 +242,73 @@ void hash_update_list (t_hash *hash, const s_list * const *list)
   assert(hash);
   assert(list);
   l = *list;
-  hash_update(hash, type, sizeof(type));
   count = list_length(l);
-  hash_update_uw(hash, &count);
+  if (! hash_update(hash, type, sizeof(type)) ||
+      ! hash_update_uw(hash, &count))
+    return false;
   if (l) {
     while (l) {
-      hash_update_tag(hash, &l->tag);
+      if (! hash_update_tag(hash, &l->tag))
+        return false;
       last = l;
       l = list_next(l);
     }
-    hash_update_tag(hash, &last->next);
+    if (! hash_update_tag(hash, &last->next))
+      return false;
   }
+  return true;
 }
 
-void hash_update_map (t_hash *hash, const s_map *map)
+bool hash_update_map (t_hash *hash, const s_map *map)
 {
   uw i = 0;
   const s8 type[] = "map";
   assert(hash);
   assert(map);
-  hash_update(hash, type, strlen(type));
-  hash_update(hash, &map->count, sizeof(map->count));
+  if (! hash_update(hash, type, strlen(type)) ||
+      ! hash_update(hash, &map->count, sizeof(map->count)))
+    return false;
   while (i < map->count) {
-    hash_update_tag(hash, map->key + i);
-    hash_update_tag(hash, map->value + i);
+    if (! hash_update_tag(hash, map->key + i) ||
+        ! hash_update_tag(hash, map->value + i))
+      return false;
     i++;
   }
+  return true;
 }
 
-void hash_update_ptag (t_hash *hash, const p_tag *ptag)
+bool hash_update_ptag (t_hash *hash, const p_tag *ptag)
 {
   const s8 type[] = "ptag";
   assert(hash);
   assert(ptag);
-  hash_update(hash, type, sizeof(type));
-  hash_update(hash, ptag, sizeof(ptag));
+  if (! hash_update(hash, type, sizeof(type)))
+    return false;
+  return hash_update(hash, ptag, sizeof(ptag));
 }
 
-void hash_update_ptr (t_hash *hash, const u_ptr_w *ptr)
+bool hash_update_ptr (t_hash *hash, const u_ptr_w *ptr)
 {
   const s8 type[] = "ptr";
-  hash_update(hash, type, strlen(type));
-  hash_update(hash, &ptr->p, sizeof(void *));
+  if (! hash_update(hash, type, strlen(type)))
+    return false;
+  return hash_update(hash, &ptr->p, sizeof(void *));
 }
 
-void hash_update_ptr_free (t_hash *hash, const u_ptr_w *ptr_free)
+bool hash_update_ptr_free (t_hash *hash, const u_ptr_w *ptr_free)
 {
   const s8 type[] = "ptr_free";
-  hash_update(hash, type, strlen(type));
-  hash_update(hash, &ptr_free->p, sizeof(void *));
+  if (! hash_update(hash, type, strlen(type)))
+    return false;
+  return hash_update(hash, &ptr_free->p, sizeof(void *));
 }
 
-void hash_update_quote (t_hash *hash, const s_quote *x)
+bool hash_update_quote (t_hash *hash, const s_quote *x)
 {
   const s8 type[] = "quote";
-  hash_update(hash, type, strlen(type));
-  hash_update_tag(hash, x->tag);
+  if (! hash_update(hash, type, strlen(type)))
+    return false;
+  return hash_update_tag(hash, x->tag);
 }
 
 HASH_UPDATE_DEF(s8)
@@ -291,17 +321,17 @@ HASH_UPDATE_DEF(s64)
 
 HASH_UPDATE_DEF(sw)
 
-void hash_update_str (t_hash *hash, const s_str *str)
+bool hash_update_str (t_hash *hash, const s_str *str)
 {
   s8 type[] = "str";
   assert(hash);
   assert(str);
-  hash_update(hash, type, strlen(type));
-  hash_update(hash, &str->size, sizeof(str->size));
-  hash_update(hash, str->ptr.p, str->size);
+  return hash_update(hash, type, strlen(type)) &&
+    hash_update(hash, &str->size, sizeof(str->size)) &&
+    hash_update(hash, str->ptr.p, str->size);
 }
 
-void hash_update_struct (t_hash *hash, const s_struct *s)
+bool hash_update_struct (t_hash *hash, const s_struct *s)
 {
   const void *data;
   uw i = 0;
@@ -309,99 +339,113 @@ void hash_update_struct (t_hash *hash, const s_struct *s)
   s8 type[] = "struct";
   assert(hash);
   assert(s);
-  hash_update(hash, type, sizeof(type));
-  hash_update_sym(hash, &s->type.module);
-  hash_update(hash, &s->type.map.count, sizeof(s->type.map.count));
+  if (! hash_update(hash, type, sizeof(type)) ||
+      ! hash_update_sym(hash, &s->type.module) ||
+      ! hash_update(hash, &s->type.map.count,
+                    sizeof(s->type.map.count)))
+    return false;
   while (i < s->type.map.count) {
-    hash_update_tag(hash, s->type.map.key + i);
+    if (! hash_update_tag(hash, s->type.map.key + i))
+      return false;
     if (! tag_type(s->type.map.value + i, &sym))
-      exit(1);
+      return false;
     if (s->data)
       data = (s8 *) s->data + s->type.offset[i];
     else {
       if (s->tag) {
         if (! tag_to_const_pointer(s->tag + i, sym, &data))
-          exit(1);
+          return false;
       }
       else {
         if (! tag_to_const_pointer(s->type.map.value + i, sym, &data))
-          exit(1);
+          return false;
       }
     }
-    void_hash_update(sym, hash, data);
+    if (! void_hash_update(sym, hash, data))
+      return false;
     i++;
   }
+  return true;
 }
 
-void hash_update_sym (t_hash *hash, const s_sym * const *sym)
+bool hash_update_sym (t_hash *hash, const s_sym * const *sym)
 {
   s8 type[] = "sym";
   assert(hash);
   assert(sym);
-  hash_update(hash, type, sizeof(type));
-  hash_update_str(hash, &(*sym)->str);
+  return hash_update(hash, type, sizeof(type)) &&
+    hash_update_str(hash, &(*sym)->str);
 }
 
-void hash_update_tag (t_hash *hash, const s_tag *tag)
+bool hash_update_tag (t_hash *hash, const s_tag *tag)
 {
   u8 tag_type;
   s8 type[] = "tag";
   assert(hash);
   assert(tag);
-  hash_update(hash, type, strlen(type));
+  if (! hash_update(hash, type, strlen(type)))
+    return false;
   tag_type = tag->type;
-  hash_update_u8(hash, &tag_type);
+  if (! hash_update_u8(hash, &tag_type))
+    return false;
   switch (tag->type) {
-  case TAG_ARRAY: hash_update_array(hash, &tag->data.array);     break;
-  case TAG_BOOL: hash_update_bool(hash, &tag->data.bool);        break;
-  case TAG_CALL: hash_update_call(hash, &tag->data.call);        break;
-  case TAG_CFN: hash_update_cfn(hash, &tag->data.cfn);           break;
+  case TAG_ARRAY: return hash_update_array(hash, &tag->data.array);
+  case TAG_BOOL:  return hash_update_bool(hash, &tag->data.bool);
+  case TAG_CALL:  return hash_update_call(hash, &tag->data.call);
+  case TAG_CFN:   return hash_update_cfn(hash, &tag->data.cfn);
   case TAG_CHARACTER:
-    hash_update_character(hash, &tag->data.character);           break;
-  case TAG_F32: hash_update_f32(hash, &tag->data.f32);           break;
-  case TAG_F64: hash_update_f64(hash, &tag->data.f64);           break;
-  case TAG_FACT: hash_update_fact(hash, &tag->data.fact);        break;
-  case TAG_FN: hash_update_fn(hash, &tag->data.fn);              break;
-  case TAG_IDENT: hash_update_ident(hash, &tag->data.ident);     break;
+    return hash_update_character(hash, &tag->data.character);
+  case TAG_F32:   return hash_update_f32(hash, &tag->data.f32);
+  case TAG_F64:   return hash_update_f64(hash, &tag->data.f64);
+  case TAG_FACT:  return hash_update_fact(hash, &tag->data.fact);
+  case TAG_FN:    return hash_update_fn(hash, &tag->data.fn);
+  case TAG_IDENT: return hash_update_ident(hash, &tag->data.ident);
   case TAG_INTEGER:
-    hash_update_integer(hash, &tag->data.integer);               break;
+    return hash_update_integer(hash, &tag->data.integer);
   case TAG_LIST:
-    hash_update_list(hash, (const s_list * const *) &tag->data.list);
-    break;
-  case TAG_MAP: hash_update_map(hash, &tag->data.map);           break;
-  case TAG_PTAG: hash_update_ptag(hash, &tag->data.ptag);        break;
-  case TAG_PTR: hash_update_ptr(hash, &tag->data.ptr);           break;
+    return hash_update_list(hash, (const s_list * const *)
+                            &tag->data.list);
+  case TAG_MAP:    hash_update_map(hash, &tag->data.map);
+  case TAG_PTAG:   hash_update_ptag(hash, &tag->data.ptag);
+  case TAG_PTR:    hash_update_ptr(hash, &tag->data.ptr);
   case TAG_PTR_FREE:
-    hash_update_ptr_free(hash, &tag->data.ptr_free);             break;
-  case TAG_QUOTE: hash_update_quote(hash, &tag->data.quote);     break;
-  case TAG_S8: hash_update_s8(hash, &tag->data.s8);              break;
-  case TAG_S16: hash_update_s16(hash, &tag->data.s16);           break;
-  case TAG_S32: hash_update_s32(hash, &tag->data.s32);           break;
-  case TAG_S64: hash_update_s64(hash, &tag->data.s64);           break;
-  case TAG_SW: hash_update_sw(hash, &tag->data.sw);              break;
-  case TAG_STR: hash_update_str(hash, &tag->data.str);           break;
-  case TAG_STRUCT: hash_update_struct(hash, &tag->data.struct_); break;
-  case TAG_SYM: hash_update_sym(hash, &tag->data.sym);           break;
-  case TAG_TUPLE: hash_update_tuple(hash, &tag->data.tuple);     break;
-  case TAG_U8: hash_update_u8(hash, &tag->data.u8);              break;
-  case TAG_U16: hash_update_u16(hash, &tag->data.u16);           break;
-  case TAG_U32: hash_update_u32(hash, &tag->data.u32);           break;
-  case TAG_U64: hash_update_u64(hash, &tag->data.u64);           break;
-  case TAG_UW: hash_update_uw(hash, &tag->data.uw);              break;
-  case TAG_VAR: hash_update_var(hash, NULL);                     break;
-  case TAG_VOID: hash_update_void(hash, NULL);                   break;
+    hash_update_ptr_free(hash, &tag->data.ptr_free);
+  case TAG_QUOTE: return hash_update_quote(hash, &tag->data.quote);
+  case TAG_S8:    return hash_update_s8(hash, &tag->data.s8);
+  case TAG_S16:   return hash_update_s16(hash, &tag->data.s16);
+  case TAG_S32:   return hash_update_s32(hash, &tag->data.s32);
+  case TAG_S64:   return hash_update_s64(hash, &tag->data.s64);
+  case TAG_SW:    return hash_update_sw(hash, &tag->data.sw);
+  case TAG_STR:   return hash_update_str(hash, &tag->data.str);
+  case TAG_STRUCT:
+    return hash_update_struct(hash, &tag->data.struct_);
+  case TAG_SYM:   return hash_update_sym(hash, &tag->data.sym);
+  case TAG_TUPLE: return hash_update_tuple(hash, &tag->data.tuple);
+  case TAG_U8:    return hash_update_u8(hash, &tag->data.u8);
+  case TAG_U16:   return hash_update_u16(hash, &tag->data.u16);
+  case TAG_U32:   return hash_update_u32(hash, &tag->data.u32);
+  case TAG_U64:   return hash_update_u64(hash, &tag->data.u64);
+  case TAG_UW:    return hash_update_uw(hash, &tag->data.uw);
+  case TAG_VAR:   return hash_update_var(hash, NULL);
+  case TAG_VOID:  return hash_update_void(hash, NULL);
   }
+  warnx("hash_update_tag: unknown tag type: %d", tag->type);
+  assert(! "hash_update_tag: unknown tag type");
+  return false;
 }
 
-void hash_update_tuple (t_hash *hash, const s_tuple *tuple)
+bool hash_update_tuple (t_hash *hash, const s_tuple *tuple)
 {
   uw i = 0;
   assert(tuple);
-  hash_update(hash, &tuple->count, sizeof(tuple->count));
+  if (! hash_update(hash, &tuple->count, sizeof(tuple->count)))
+    return false;
   while (i < tuple->count) {
-    hash_update_tag(hash, tuple->tag + i);
+    if (! hash_update_tag(hash, tuple->tag + i))
+      return false;
     i++;
   }
+  return true;
 }
 
 HASH_UPDATE_DEF(u8)
@@ -410,18 +454,18 @@ HASH_UPDATE_DEF(u32)
 HASH_UPDATE_DEF(u64)
 HASH_UPDATE_DEF(uw)
 
-void hash_update_var (t_hash *hash, const void *x)
+bool hash_update_var (t_hash *hash, const void *x)
 {
   s8 type[] = "var";
   (void) x;
   assert(hash);
-  hash_update(hash, type, strlen(type));
+  return hash_update(hash, type, strlen(type));
 }
 
-void hash_update_void (t_hash *hash, const void *x)
+bool hash_update_void (t_hash *hash, const void *x)
 {
   s8 type[] = "void";
   (void) x;
   assert(hash);
-  hash_update(hash, type, strlen(type));
+  return hash_update(hash, type, strlen(type));
 }
diff --git a/libc3/hash.h b/libc3/hash.h
index 4a9f95d..04c7616 100644
--- a/libc3/hash.h
+++ b/libc3/hash.h
@@ -16,48 +16,48 @@
 #include "types.h"
 
 #define HASH_UPDATE_PROTOTYPE(type)                           \
-  void hash_update_##type (t_hash *hash, const type *x)
+  bool hash_update_##type (t_hash *hash, const type *x)
 
 void hash_clean (t_hash *hash);
 void hash_init (t_hash *hash);
 uw   hash_to_uw (t_hash *hash);
 u64  hash_to_u64 (t_hash *hash);
-void hash_update (t_hash *hash, const void *data, uw size);
-void hash_update_1 (t_hash *hash, const s8 *p);
-void hash_update_array (t_hash *hash, const s_array *a);
-void hash_update_bool (t_hash *hash, const bool *b);
-void hash_update_call (t_hash *hash, const s_call *call);
-void hash_update_cfn (t_hash *hash, const s_cfn *cfn);
+bool hash_update (t_hash *hash, const void *data, uw size);
+bool hash_update_1 (t_hash *hash, const s8 *p);
+bool hash_update_array (t_hash *hash, const s_array *a);
+bool hash_update_bool (t_hash *hash, const bool *b);
+bool hash_update_call (t_hash *hash, const s_call *call);
+bool hash_update_cfn (t_hash *hash, const s_cfn *cfn);
 HASH_UPDATE_PROTOTYPE(character);
 HASH_UPDATE_PROTOTYPE(f32);
 HASH_UPDATE_PROTOTYPE(f64);
-void hash_update_fact (t_hash *hash, const s_fact *fact);
-void hash_update_fn (t_hash *hash, const s_fn *fn);
-void hash_update_fn_clauses (t_hash *hash, const s_fn_clause *clauses);
-void hash_update_ident (t_hash *hash, const s_ident *ident);
-void hash_update_integer (t_hash *hash, const s_integer *i);
-void hash_update_list (t_hash *hash, const s_list * const *list);
-void hash_update_map (t_hash *hash, const s_map *map);
-void hash_update_ptag (t_hash *hash, const p_tag *ptag);
-void hash_update_ptr (t_hash *hash, const u_ptr_w *ptr);
-void hash_update_ptr_free (t_hash *hash, const u_ptr_w *ptr_free);
-void hash_update_quote (t_hash *hash, const s_quote *x);
+bool hash_update_fact (t_hash *hash, const s_fact *fact);
+bool hash_update_fn (t_hash *hash, const s_fn *fn);
+bool hash_update_fn_clauses (t_hash *hash, const s_fn_clause *clauses);
+bool hash_update_ident (t_hash *hash, const s_ident *ident);
+bool hash_update_integer (t_hash *hash, const s_integer *i);
+bool hash_update_list (t_hash *hash, const s_list * const *list);
+bool hash_update_map (t_hash *hash, const s_map *map);
+bool hash_update_ptag (t_hash *hash, const p_tag *ptag);
+bool hash_update_ptr (t_hash *hash, const u_ptr_w *ptr);
+bool hash_update_ptr_free (t_hash *hash, const u_ptr_w *ptr_free);
+bool hash_update_quote (t_hash *hash, const s_quote *x);
 HASH_UPDATE_PROTOTYPE(s8);
 HASH_UPDATE_PROTOTYPE(s16);
 HASH_UPDATE_PROTOTYPE(s32);
 HASH_UPDATE_PROTOTYPE(s64);
 HASH_UPDATE_PROTOTYPE(sw);
-void hash_update_str (t_hash *hash, const s_str *str);
-void hash_update_struct (t_hash *hash, const s_struct *s);
-void hash_update_sym (t_hash *hash, const s_sym * const *sym);
-void hash_update_tag (t_hash *hash, const s_tag *tag);
-void hash_update_tuple (t_hash *hash, const s_tuple *tuple);
+bool hash_update_str (t_hash *hash, const s_str *str);
+bool hash_update_struct (t_hash *hash, const s_struct *s);
+bool hash_update_sym (t_hash *hash, const s_sym * const *sym);
+bool hash_update_tag (t_hash *hash, const s_tag *tag);
+bool hash_update_tuple (t_hash *hash, const s_tuple *tuple);
 HASH_UPDATE_PROTOTYPE(u8);
 HASH_UPDATE_PROTOTYPE(u16);
 HASH_UPDATE_PROTOTYPE(u32);
 HASH_UPDATE_PROTOTYPE(u64);
 HASH_UPDATE_PROTOTYPE(uw);
-void hash_update_var (t_hash *hash, const void *x);
-void hash_update_void (t_hash *hash, const void *x);
+bool hash_update_var (t_hash *hash, const void *x);
+bool hash_update_void (t_hash *hash, const void *x);
 
 #endif /* LIBC3_HASH_H */
diff --git a/libc3/tag_type.c b/libc3/tag_type.c
index 892114d..852ca47 100644
--- a/libc3/tag_type.c
+++ b/libc3/tag_type.c
@@ -464,16 +464,51 @@ bool tag_type_to_init_copy (e_tag_type type, f_init_copy *p)
   assert(! "tag_type_to_init_copy: invalid tag type");
   return false;
 }
+*/
 
-const s8 * tag_type_to_string (e_tag_type type)
+const s8 * tag_type_to_string (e_tag_type tag_type)
 {
-  const s_sym *sym;
-  if (! (sym = tag_type_to_sym(type)))
-    return NULL;
-  return sym->str.ptr.ps8;
+  switch (tag_type) {
+  case TAG_VOID:      return "Void";
+  case TAG_ARRAY:     return "Array";
+  case TAG_BOOL:      return "Bool";
+  case TAG_CALL:      return "Call";
+  case TAG_CFN:       return "Cfn";
+  case TAG_CHARACTER: return "Character";
+  case TAG_F32:       return "F32";
+  case TAG_F64:       return "F64";
+  case TAG_FACT:      return "Fact";
+  case TAG_FN:        return "Fn";
+  case TAG_IDENT:     return "Ident";
+  case TAG_INTEGER:   return "Integer";
+  case TAG_SW:        return "Sw";
+  case TAG_S64:       return "S64";
+  case TAG_S32:       return "S32";
+  case TAG_S16:       return "S16";
+  case TAG_S8:        return "S8";
+  case TAG_U8:        return "U8";
+  case TAG_U16:       return "U16";
+  case TAG_U32:       return "U32";
+  case TAG_U64:       return "U64";
+  case TAG_UW:        return "Uw";
+  case TAG_LIST:      return "List";
+  case TAG_MAP:       return "Map";
+  case TAG_PTAG:      return "Ptag";
+  case TAG_PTR:       return "Ptr";
+  case TAG_PTR_FREE:  return "PtrFree";
+  case TAG_QUOTE:     return "Quote";
+  case TAG_STR:       return "Str";
+  case TAG_STRUCT:    return "Struct";
+  case TAG_SYM:       return "Sym";
+  case TAG_TUPLE:     return "Tuple";
+  case TAG_VAR:       return "Var";
+  }
+  warnx("tag_type_to_string: unknown tag type: %d", tag_type);
+  assert(! "tag_type_to_string: unknown tag type");
+  return NULL;
 }
-*/
 
+/*
 const s_sym * tag_type_to_sym (e_tag_type tag_type)
 {
   switch (tag_type) {
@@ -515,3 +550,4 @@ const s_sym * tag_type_to_sym (e_tag_type tag_type)
   errx(1, "tag_type_to_sym: invalid tag type: %d", tag_type);
   return NULL;
 }
+*/
diff --git a/libc3/void.h b/libc3/void.h
index 142f033..280fde3 100644
--- a/libc3/void.h
+++ b/libc3/void.h
@@ -24,7 +24,7 @@
 sw     void_buf_inspect (const s_sym *type, s_buf *buf, const void *v);
 sw     void_buf_inspect_size (const s_sym *type, const void *v);
 bool   void_clean (const s_sym *type, void *v);
-void   void_hash_update (const s_sym *type, t_hash *hash,
+bool   void_hash_update (const s_sym *type, t_hash *hash,
                          const void *s);
 void * void_init_cast (const s_sym *type, void *v, const s_tag *src);
 void * void_init_copy (const s_sym *type, void *v, const void *src);