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. --- tree.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tree.c') diff --git a/tree.c b/tree.c index a0a0faf8..53496e3e 100644 --- a/tree.c +++ b/tree.c @@ -140,9 +140,7 @@ val set_key(val node, val nkey) val copy_tnode(val node) { - val obj = (type_check(lit("copy-tnode"), node, TNOD), make_obj()); - obj->tn = node->tn; - return obj; + return (type_check(lit("copy-tnode"), node, TNOD), copy_obj(node)); } static ucnum tn_size(val node) -- cgit v1.2.3