Subject: | panic: attempt to copy freed scalar 96c1fe8 to 96c1d48 |
Attached are two files, add.pl (original w/ goto) and add-y.pl (using
Sub::Call::Tail).
Expected output:
% perl add.pl 1 2
Show quoted text
> 1 + 2
> 3 + 0
3
Actual output:
% perl add-y.pl 1 2
Show quoted text> 1 + 2
> 3 + 0
panic: attempt to copy freed scalar 8654fe8 to 8654d48 at add-y.pl line 32.
Subject: | add.pl |
#!/usr/bin/perl
use warnings;
use strict;
use integer;
@ARGV == 2 or die "Usage: $0 INTEGER INTEGER\n";
sub {
my $r = shift;
my $a = 0 + shift;
my $b = 0 + shift;
@_ = (
sub {
my $f = shift;
@_ = (
sub {
my $f = shift;
@_ = (
sub {
my $f = shift;
@_ = (
sub {
my $n = shift;
print "$n\n";
@_ = 0;
goto &$r;
},
$b
);
goto &$f;
},
$a
);
goto &$f;
},
sub {
my $r = shift;
my $f = shift;
@_ = sub {
my $r = shift;
my $x = shift;
@_ = sub {
my $r = shift;
my $y = shift;
print "> $x + $y\n";
if ($x && $y) {
@_ = (
sub {
my $f = shift;
@_ = ($r, ($x & $y) << 1);
goto &$f;
},
$x ^ $y
);
goto &$f;
}
@_ = $x ^ $y;
goto &$r;
};
goto &$r;
};
goto &$r;
}
);
goto &$f;
},
sub {
my $r = shift;
my $y = shift;
@_ = sub {
my $r = shift;
my $f = shift;
@_ = sub {
my $r = shift;
my $x = shift;
@_ = (
sub {
my $f = shift;
@_ = ($r, $x);
goto &$f;
},
sub {
my $r = shift;
my $x = shift;
@_ = (
sub {
my $g = shift;
@_ = (
sub {
my $f = shift;
@_ = ($r, $x);
goto &$f;
},
$f
);
goto &$g;
},
$y
);
goto &$y;
}
);
goto &$f;
};
goto &$r;
};
goto &$r;
}
);
goto & {
sub {
my $r = shift;
my $f = shift;
@_ = ($r, $f);
goto &$f;
}
};
}->(sub { exit $_[0] }, @ARGV)
Subject: | add-y.pl |
#!/usr/bin/perl
use warnings;
use strict;
use Sub::Call::Tail;
use integer;
@ARGV == 2 or die "Usage: $0 INTEGER INTEGER\n";
sub {
my $r = shift;
my $a = 0 + shift;
my $b = 0 + shift;
tail sub {
my $r = shift;
my $f = shift;
tail $f->($r, $f);
}->(
sub {
my $f = shift;
tail $f->(
sub {
my $f = shift;
tail $f->(
sub {
my $f = shift;
tail $f->(
sub {
my $n = shift;
print "$n\n";
tail $r->(0);
},
$b
);
},
$a
);
},
sub {
my $r = shift;
my $f = shift;
tail $r->(sub {
my $r = shift;
my $x = shift;
tail $r->(sub {
my $r = shift;
my $y = shift;
print "> $x + $y\n";
if ($x && $y) {
tail $f->(
sub {
my $f = shift;
tail $f->($r, ($x & $y) << 1);
},
$x ^ $y
);
}
tail $r->($x ^ $y);
});
});
}
);
},
sub {
my $r = shift;
my $y = shift;
tail $r->(sub {
my $r = shift;
my $f = shift;
tail $r->(sub {
my $r = shift;
my $x = shift;
tail $f->(
sub {
my $f = shift;
tail $f->($r, $x);
},
sub {
my $r = shift;
my $x = shift;
tail $y->(
sub {
my $g = shift;
tail $g->(
sub {
my $f = shift;
tail $f->($r, $x);
},
$f
);
},
$y
);
}
);
});
});
}
);
}->(sub { exit $_[0] }, @ARGV)