From 13994ed823c2445bbeecea677fd604744b373c5e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 29 Jul 2021 07:51:02 -0700 Subject: gc: problem in several object copying functions. The functions copy-cons, copy-tree, copy-fun and copy-tnode have a problem. They copy the original object bitwise with a structure assignment, and then make some adjustments. The problem is that this inappropriately copies the object's metadata related to gc, such as its generation number or finalization count. To fix this, we introduce a copy_obj function, which is a companion to make_obj. This performs a shallow copy of an object without incorrectly propagating inappropriate metadata. * gc.c, gc.h (copy_obj): New function. * lib.c (copy_fun, copy_cons, copy_tree): Use copy_obj, instead of make_obj plus structure assignment. * tree.c (copy_tnode): Likewise. --- lib.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'lib.c') diff --git a/lib.c b/lib.c index 1a12e678..5de9f170 100644 --- a/lib.c +++ b/lib.c @@ -7494,8 +7494,7 @@ val copy_fun(val ofun) val self = lit("copy-fun"); type_check(self, ofun, FUN); { - val nfun = make_obj(); - nfun->f = ofun->f; + val nfun = copy_obj(ofun); if (nfun->f.env) nfun->f.env = if3(nfun->f.functype == FVM, @@ -9692,9 +9691,7 @@ val copy_cons(val cell) case CONS: case LCONS: { - val obj = make_obj(); - *obj = *cell; - return obj; + return copy_obj(cell); } default: type_mismatch(lit("copy-cons: ~s is not a cons"), cell, nao); @@ -9708,11 +9705,7 @@ val copy_tree(val tree) } else { val car = copy_tree(tree->c.car); val cdr = copy_tree(tree->c.cdr); - val copy = make_obj(); - *copy = *tree; - copy->c.car = car; - copy->c.cdr = cdr; - return copy; + return cons(car, cdr); } } -- cgit v1.2.3