summaryrefslogtreecommitdiffstats
path: root/gc.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-04-16 22:26:12 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-04-16 22:26:12 -0700
commit307ddfe0bbb4ad7997cccbda5abb750b599b10be (patch)
tree824d8242bdac63f8234a596af1b71e2cb0bed9db /gc.c
parent8b50725da4d58aa77ba61c4270c5407438b2209d (diff)
downloadtxr-307ddfe0bbb4ad7997cccbda5abb750b599b10be.tar.gz
txr-307ddfe0bbb4ad7997cccbda5abb750b599b10be.tar.bz2
txr-307ddfe0bbb4ad7997cccbda5abb750b599b10be.zip
New buffer data type.
Work in progress. * gc.c (finalize): Add cast to switch expression so gcc flags when we are missing one of the enumerations. Handle new BUF enum to free dynamic buffers. (mark_obj): Mark len and size fields of buf, in case they aren't just nil or integers. * hash.c (hash_buf): New static function. (equal_hash): Route BUF type to hash_buf. * lib.c (buf_s): New symbol variable. (code2type): Handle BUF. (equal): Handle BUF using memcmp on the data. (obj_init): Intern buf symbol and initialize buf_s. * lib.h (type_t): New enum member BUF. (struct buf): New type. (union obj): New member b, of struct buf type. (buf_s): Declared.
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/gc.c b/gc.c
index 33afca91..e42e7552 100644
--- a/gc.c
+++ b/gc.c
@@ -244,7 +244,7 @@ val make_obj(void)
static void finalize(val obj)
{
- switch (obj->t.type) {
+ switch (convert(type_t, obj->t.type)) {
case NIL:
case CONS:
case CHR:
@@ -280,6 +280,12 @@ static void finalize(val obj)
case BGNUM:
mp_clear(mp(obj));
return;
+ case BUF:
+ if (obj->b.size) {
+ free(obj->b.data);
+ obj->b.data = 0;
+ }
+ return;
}
assert (0 && "corrupt type field");
@@ -395,6 +401,9 @@ tail_call:
case RNG:
mark_obj(obj->rn.from);
mark_obj_tail(obj->rn.to);
+ case BUF:
+ mark_obj(obj->b.len);
+ mark_obj_tail(obj->b.size);
}
assert (0 && "corrupt type field");