Commit | Line | Data |
c07deaaf |
1 | ################################################################################ |
2 | ## |
bfc37ff7 |
3 | ## $Revision: 6 $ |
c07deaaf |
4 | ## $Author: mhx $ |
bfc37ff7 |
5 | ## $Date: 2010/03/07 13:15:45 +0100 $ |
c07deaaf |
6 | ## |
7 | ################################################################################ |
8 | ## |
bfc37ff7 |
9 | ## Version 3.x, Copyright (C) 2004-2010, Marcus Holland-Moritz. |
c07deaaf |
10 | ## Version 2.x, Copyright (C) 2001, Paul Marquess. |
11 | ## Version 1.x, Copyright (C) 1999, Kenneth Albanowski. |
12 | ## |
13 | ## This program is free software; you can redistribute it and/or |
14 | ## modify it under the same terms as Perl itself. |
15 | ## |
16 | ################################################################################ |
17 | |
18 | =provides |
19 | |
20 | SvREFCNT_inc |
21 | SvREFCNT_inc_simple |
22 | SvREFCNT_inc_NN |
23 | SvREFCNT_inc_void |
24 | __UNDEFINED__ |
25 | |
26 | =implementation |
27 | |
28 | #ifndef SvREFCNT_inc |
29 | # ifdef PERL_USE_GCC_BRACE_GROUPS |
30 | # define SvREFCNT_inc(sv) \ |
31 | ({ \ |
32 | SV * const _sv = (SV*)(sv); \ |
33 | if (_sv) \ |
34 | (SvREFCNT(_sv))++; \ |
35 | _sv; \ |
36 | }) |
37 | # else |
38 | # define SvREFCNT_inc(sv) \ |
39 | ((PL_Sv=(SV*)(sv)) ? (++(SvREFCNT(PL_Sv)),PL_Sv) : NULL) |
40 | # endif |
41 | #endif |
42 | |
43 | #ifndef SvREFCNT_inc_simple |
44 | # ifdef PERL_USE_GCC_BRACE_GROUPS |
45 | # define SvREFCNT_inc_simple(sv) \ |
46 | ({ \ |
47 | if (sv) \ |
48 | (SvREFCNT(sv))++; \ |
49 | (SV *)(sv); \ |
50 | }) |
51 | # else |
52 | # define SvREFCNT_inc_simple(sv) \ |
53 | ((sv) ? (SvREFCNT(sv)++,(SV*)(sv)) : NULL) |
54 | # endif |
55 | #endif |
56 | |
57 | #ifndef SvREFCNT_inc_NN |
58 | # ifdef PERL_USE_GCC_BRACE_GROUPS |
59 | # define SvREFCNT_inc_NN(sv) \ |
60 | ({ \ |
61 | SV * const _sv = (SV*)(sv); \ |
62 | SvREFCNT(_sv)++; \ |
63 | _sv; \ |
64 | }) |
65 | # else |
66 | # define SvREFCNT_inc_NN(sv) \ |
67 | (PL_Sv=(SV*)(sv),++(SvREFCNT(PL_Sv)),PL_Sv) |
68 | # endif |
69 | #endif |
70 | |
71 | #ifndef SvREFCNT_inc_void |
72 | # ifdef PERL_USE_GCC_BRACE_GROUPS |
73 | # define SvREFCNT_inc_void(sv) \ |
74 | ({ \ |
75 | SV * const _sv = (SV*)(sv); \ |
76 | if (_sv) \ |
77 | (void)(SvREFCNT(_sv)++); \ |
78 | }) |
79 | # else |
80 | # define SvREFCNT_inc_void(sv) \ |
81 | (void)((PL_Sv=(SV*)(sv)) ? ++(SvREFCNT(PL_Sv)) : 0) |
82 | # endif |
83 | #endif |
84 | |
85 | __UNDEFINED__ SvREFCNT_inc_simple_void(sv) STMT_START { if (sv) SvREFCNT(sv)++; } STMT_END |
86 | __UNDEFINED__ SvREFCNT_inc_simple_NN(sv) (++SvREFCNT(sv), (SV*)(sv)) |
87 | __UNDEFINED__ SvREFCNT_inc_void_NN(sv) (void)(++SvREFCNT((SV*)(sv))) |
88 | __UNDEFINED__ SvREFCNT_inc_simple_void_NN(sv) (void)(++SvREFCNT((SV*)(sv))) |
89 | |
90 | =xsubs |
91 | |
92 | void |
93 | SvREFCNT() |
94 | PREINIT: |
95 | SV *sv, *svr; |
96 | PPCODE: |
97 | sv = newSV(0); |
c1a049cb |
98 | mXPUSHi(SvREFCNT(sv) == 1); |
c07deaaf |
99 | svr = SvREFCNT_inc(sv); |
c1a049cb |
100 | mXPUSHi(sv == svr); |
101 | mXPUSHi(SvREFCNT(sv) == 2); |
c07deaaf |
102 | svr = SvREFCNT_inc_simple(sv); |
c1a049cb |
103 | mXPUSHi(sv == svr); |
104 | mXPUSHi(SvREFCNT(sv) == 3); |
c07deaaf |
105 | svr = SvREFCNT_inc_NN(sv); |
c1a049cb |
106 | mXPUSHi(sv == svr); |
107 | mXPUSHi(SvREFCNT(sv) == 4); |
c07deaaf |
108 | svr = SvREFCNT_inc_simple_NN(sv); |
c1a049cb |
109 | mXPUSHi(sv == svr); |
110 | mXPUSHi(SvREFCNT(sv) == 5); |
c07deaaf |
111 | SvREFCNT_inc_void(sv); |
c1a049cb |
112 | mXPUSHi(SvREFCNT(sv) == 6); |
c07deaaf |
113 | SvREFCNT_inc_simple_void(sv); |
c1a049cb |
114 | mXPUSHi(SvREFCNT(sv) == 7); |
c07deaaf |
115 | SvREFCNT_inc_void_NN(sv); |
c1a049cb |
116 | mXPUSHi(SvREFCNT(sv) == 8); |
c07deaaf |
117 | SvREFCNT_inc_simple_void_NN(sv); |
c1a049cb |
118 | mXPUSHi(SvREFCNT(sv) == 9); |
c07deaaf |
119 | while (SvREFCNT(sv) > 1) |
120 | SvREFCNT_dec(sv); |
c1a049cb |
121 | mXPUSHi(SvREFCNT(sv) == 1); |
c07deaaf |
122 | SvREFCNT_dec(sv); |
123 | XSRETURN(14); |
124 | |
125 | =tests plan => 14 |
126 | |
127 | for (Devel::PPPort::SvREFCNT()) { |
128 | ok(defined $_ and $_); |
129 | } |
130 | |