# New Ticket Created by Patrick R. Michaud
# Please include the string: [perl #56448]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=56448 >
Parrot segfaults when C functions invoke PIR functions that
perform tailcalls. Here's a demo test:
Here's a demo test:
.sub 'main' :main
.local pmc array
array = new 'ResizablePMCArray'
push array, 4
push array, 5
push array, 3
push array, 2
push array, 5
push array, 1
$S0 = join ' ', array
say $S0
## sort using a non-tailcall function
$P0 = get_global 'cmp_normal'
$P1 = clone array
$P1.sort($P0)
$S0 = join ' ', $P1
say $S0
## sort using a tailcall function
$P0 = get_global 'cmp_tailcall'
$P1 = clone array
$P1.sort($P0)
$S0 = join ' ', $P1
say $S0
.end
.sub 'cmp_func'
.param pmc a
.param pmc b
$I0 = cmp a, b
.return ($I0)
.end
.sub 'cmp_normal'
.param pmc a
.param pmc b
$P0 = 'cmp_func'(a, b)
.return ($P0)
.end
.sub 'cmp_tailcall'
.param pmc a
.param pmc b
.return 'cmp_func'(a, b)
.end
Here, we perform a sort using Parrot's built-in sort method for
PMC arrays, using either 'cmp_normal' or 'cmp_tailcall' as
the comparison function. The only difference between the two
functions is the use of a tailcall in the return statement.
The output when the above is run is:
$ ./parrot tc.pir
4 5 3 2 5 1
1 2 3 4 5 5
Segmentation fault
This segmentation fault seems to occur anytime a PIR subroutine
that performs a tailcall is called from C -- in particular,
PIR methods marked with :vtable segfault whenever they return
a value via a tailcall.
Pm