aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/aterm-helper.pl5
-rw-r--r--src/libexpr/parser.y8
2 files changed, 10 insertions, 3 deletions
diff --git a/src/aterm-helper.pl b/src/aterm-helper.pl
index 9b2bde700..f1eb77ee8 100755
--- a/src/aterm-helper.pl
+++ b/src/aterm-helper.pl
@@ -146,8 +146,9 @@ while (<STDIN>) {
my $value = $2;
print HEADER "extern ATerm $name;\n";
print IMPL "ATerm $name = 0;\n";
- $init .= " $name = $value;\n";
- }
+ $init .= " $name = $value;\n";
+ $init .= " ATprotect(&$name);\n";
+ }
elsif (/^\s*init\s+(\w+)\s*$/) {
$initFun = $1;
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index c4afb72ea..8706ce025 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -85,6 +85,10 @@ static Expr fixAttrs(bool recursive, ATermList as)
{
Tree attrs;
+ /* This ATermMap is needed to ensure that the `leaf' fields in the
+ Tree nodes are not garbage collected. */
+ ATermMap gcRoots;
+
for (ATermIterator i(as); i; ++i) {
ATermList names, attrPath; Expr src, e; ATerm name, pos;
@@ -95,7 +99,9 @@ static Expr fixAttrs(bool recursive, ATermList as)
throw ParseError(format("duplicate definition of attribute `%1%' at %2%")
% showAttrPath(ATmakeList1(*j)) % showPos(pos));
Tree & t(attrs.children[*j]);
- t.leaf = fromScope ? makeVar(*j) : makeSelect(src, *j);
+ Expr leaf = fromScope ? makeVar(*j) : makeSelect(src, *j);
+ gcRoots.set(leaf, leaf);
+ t.leaf = leaf;
t.pos = pos;
if (recursive && fromScope) t.recursive = false;
}