| 1 |
#!perl |
| 2 |
# |
| 3 |
# Test the rpp_invoke_xs() function. |
| 4 |
# In particular, ensure that an XS CV flagged as CvXS_RCSTACK() |
| 5 |
# is called without being wrapped by xs_wrap() but works ok, with no |
| 6 |
# leaks or premature frees etc. |
| 7 |
|
| 8 |
use warnings; |
| 9 |
use strict; |
| 10 |
use Test::More; |
| 11 |
use XS::APItest qw(set_xs_rc_stack rc_add); |
| 12 |
|
| 13 |
|
| 14 |
# Test that $_[0] has the expected refcount |
| 15 |
|
| 16 |
sub rc_is { |
| 17 |
my (undef, $exp_rc, $desc) = @_; |
| 18 |
$exp_rc++ if (Internals::stack_refcounted() & 1); |
| 19 |
is(Internals::SvREFCNT($_[0]), $exp_rc, $desc); |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
# Mark the XS function as 'reference-counted-stack aware'. |
| 24 |
# There's no way do do this yet using XS syntax. |
| 25 |
|
| 26 |
set_xs_rc_stack(\&rc_add, 1); |
| 27 |
|
| 28 |
|
| 29 |
# Basic sanity check |
| 30 |
|
| 31 |
is (rc_add(7,15), 22, "7+15"); |
| 32 |
|
| 33 |
|
| 34 |
# Args with RC==1 should be the same afterwards |
| 35 |
|
| 36 |
{ |
| 37 |
my ($x, $y) = (3, 16); |
| 38 |
rc_is($x, 1, '3+16 rc($x) before'); |
| 39 |
rc_is($y, 1, '3+16 rc($y) before'); |
| 40 |
is (rc_add($x, $y), 19, "3+16"); |
| 41 |
rc_is($x, 1, '3+16 rc($x) after'); |
| 42 |
rc_is($y, 1, '3+16 rc($y) after'); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
# Return value is a newSV kept alive just by the stack |
| 47 |
|
| 48 |
rc_is(rc_add(34, 17), 1, "rc(34+17)"); |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
done_testing(); |