Debian Codegraph @

ext/XS-APItest/t/xsppwrap.t

raw
1 #!perl
2 #
3 # Test the XSPP_wrapped() macro.
4 #
5 # The XS function set_custom_pp_func() modifies the pp_addr value of the
6 # op following it to point to a pp function written in the traditional
7 # non-refcounted style (POPs etc), but which is declared using
8 # XSPP_wrapped(), so on PERL_RC_STACK builds, the ref count handling of
9 # the args and return value should still be correct.
10
11 use warnings;
12 use strict;
13 use Test::More;
14 use Config;
15 use XS::APItest qw(set_custom_pp_func);
16
17 my ($count, $ret, $c);
18 sub DESTROY { $count++ }
19
20
21 $count = 0;
22 {
23 my $nine = 9;
24 # set_custom_pp_func() overrides the pp func for the next op,
25 # which is the pp_add
26 ($ret, $c) = (bless(\$nine)+set_custom_pp_func(15), $count);
27 }
28
29 is($ret, 24, "custom add returns correct value");
30 is($c, 0, "custom add: arg not yet freed");
31 is($count, 1, "custom add: arg now freed");
32
33
34 $count = 0;
35 {
36 my $nine = 9;
37 my $ten = 10;
38 my $eleven = 11;
39 # set_custom_pp_func() overrides the pp func for the next op,
40 # which is the anonlist
41 ($ret, $c) = (
42 [
43 bless(\$nine),
44 bless(\$ten),
45 set_custom_pp_func(bless(\$eleven)),
46 ],
47 $count
48 );
49 }
50
51 ok(defined $ret, "custom anonlist returns defined value");
52 is(${$ret->[0]}, 9, "custom anonlist arg [0]");
53 is(${$ret->[1]}, 10, "custom anonlist arg [1]");
54 is(${$ret->[2]}, 11, "custom anonlist arg [2]");
55 is($c, 0, "custom anonlist args not yet freed");
56 is($count, 0, "custom anonlist args not yet freed 2");
57
58 undef $ret;
59
60 is($count, 3, "custom anonlist args now freed");
61
62
63 done_testing();