summaryrefslogtreecommitdiffstats
path: root/tree.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-07-29 07:51:02 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-07-29 07:51:02 -0700
commit13994ed823c2445bbeecea677fd604744b373c5e (patch)
treedccbf9179283db3e7760319a4689a76697d5dba1 /tree.c
parenta7f9a8749ab3eae450c2a447782e9a9c034057ea (diff)
downloadtxr-13994ed823c2445bbeecea677fd604744b373c5e.tar.gz
txr-13994ed823c2445bbeecea677fd604744b373c5e.tar.bz2
txr-13994ed823c2445bbeecea677fd604744b373c5e.zip
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.
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c4
1 files changed, 1 insertions, 3 deletions
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)