summaryrefslogtreecommitdiff
path: root/cpan/Devel-PPPort/parts/inc/SvREFCNT
blob: 3a2f8498024c002698874f8011965187ef2fab2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
################################################################################
##
##  $Revision: 6 $
##  $Author: mhx $
##  $Date: 2010/03/07 13:15:45 +0100 $
##
################################################################################
##
##  Version 3.x, Copyright (C) 2004-2010, Marcus Holland-Moritz.
##  Version 2.x, Copyright (C) 2001, Paul Marquess.
##  Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
##
##  This program is free software; you can redistribute it and/or
##  modify it under the same terms as Perl itself.
##
################################################################################

=provides

SvREFCNT_inc
SvREFCNT_inc_simple
SvREFCNT_inc_NN
SvREFCNT_inc_void
__UNDEFINED__

=implementation

#ifndef SvREFCNT_inc
#  ifdef PERL_USE_GCC_BRACE_GROUPS
#    define SvREFCNT_inc(sv)		\
      ({				\
          SV * const _sv = (SV*)(sv);	\
          if (_sv)			\
               (SvREFCNT(_sv))++;	\
          _sv;				\
      })
#  else
#    define SvREFCNT_inc(sv)	\
          ((PL_Sv=(SV*)(sv)) ? (++(SvREFCNT(PL_Sv)),PL_Sv) : NULL)
#  endif
#endif

#ifndef SvREFCNT_inc_simple
#  ifdef PERL_USE_GCC_BRACE_GROUPS
#    define SvREFCNT_inc_simple(sv)	\
      ({					\
          if (sv)				\
               (SvREFCNT(sv))++;		\
          (SV *)(sv);				\
      })
#  else
#    define SvREFCNT_inc_simple(sv) \
          ((sv) ? (SvREFCNT(sv)++,(SV*)(sv)) : NULL)
#  endif
#endif

#ifndef SvREFCNT_inc_NN
#  ifdef PERL_USE_GCC_BRACE_GROUPS
#    define SvREFCNT_inc_NN(sv)		\
      ({					\
          SV * const _sv = (SV*)(sv);	\
          SvREFCNT(_sv)++;		\
          _sv;				\
      })
#  else
#    define SvREFCNT_inc_NN(sv) \
          (PL_Sv=(SV*)(sv),++(SvREFCNT(PL_Sv)),PL_Sv)
#  endif
#endif

#ifndef SvREFCNT_inc_void
#  ifdef PERL_USE_GCC_BRACE_GROUPS
#    define SvREFCNT_inc_void(sv)		\
      ({					\
          SV * const _sv = (SV*)(sv);	\
          if (_sv)			\
              (void)(SvREFCNT(_sv)++);	\
      })
#  else
#    define SvREFCNT_inc_void(sv) \
          (void)((PL_Sv=(SV*)(sv)) ? ++(SvREFCNT(PL_Sv)) : 0)
#  endif
#endif

__UNDEFINED__  SvREFCNT_inc_simple_void(sv)	STMT_START { if (sv) SvREFCNT(sv)++; } STMT_END
__UNDEFINED__  SvREFCNT_inc_simple_NN(sv)	(++SvREFCNT(sv), (SV*)(sv))
__UNDEFINED__  SvREFCNT_inc_void_NN(sv)		(void)(++SvREFCNT((SV*)(sv)))
__UNDEFINED__  SvREFCNT_inc_simple_void_NN(sv)	(void)(++SvREFCNT((SV*)(sv)))

=xsubs

void
SvREFCNT()
	PREINIT:
		SV *sv, *svr;
	PPCODE:
		sv = newSV(0);
		mXPUSHi(SvREFCNT(sv) == 1);
		svr = SvREFCNT_inc(sv);
		mXPUSHi(sv == svr);
		mXPUSHi(SvREFCNT(sv) == 2);
		svr = SvREFCNT_inc_simple(sv);
		mXPUSHi(sv == svr);
		mXPUSHi(SvREFCNT(sv) == 3);
		svr = SvREFCNT_inc_NN(sv);
		mXPUSHi(sv == svr);
		mXPUSHi(SvREFCNT(sv) == 4);
		svr = SvREFCNT_inc_simple_NN(sv);
		mXPUSHi(sv == svr);
		mXPUSHi(SvREFCNT(sv) == 5);
		SvREFCNT_inc_void(sv);
		mXPUSHi(SvREFCNT(sv) == 6);
		SvREFCNT_inc_simple_void(sv);
		mXPUSHi(SvREFCNT(sv) == 7);
		SvREFCNT_inc_void_NN(sv);
		mXPUSHi(SvREFCNT(sv) == 8);
		SvREFCNT_inc_simple_void_NN(sv);
		mXPUSHi(SvREFCNT(sv) == 9);
		while (SvREFCNT(sv) > 1)
		  SvREFCNT_dec(sv);
		mXPUSHi(SvREFCNT(sv) == 1);
		SvREFCNT_dec(sv);
		XSRETURN(14);

=tests plan => 14

for (Devel::PPPort::SvREFCNT()) {
  ok(defined $_ and $_);
}