This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
podcheck.t: Re-enable --add_link
[perl5.git] / inline.h
CommitLineData
25468daa
FC
1/* inline.h
2 *
3 * Copyright (C) 2012 by Larry Wall and others
4 *
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
7 *
8 * This file is a home for static inline functions that cannot go in other
9 * headers files, because they depend on proto.h (included after most other
10 * headers) or struct definitions.
11 *
12 * Each section names the header file that the functions "belong" to.
13 */
27669aa4 14
be3a7a5d
KW
15/* ------------------------------- av.h ------------------------------- */
16
17PERL_STATIC_INLINE I32
18S_av_top_index(pTHX_ AV *av)
19{
20 PERL_ARGS_ASSERT_AV_TOP_INDEX;
21 assert(SvTYPE(av) == SVt_PVAV);
22
23 return AvFILL(av);
24}
25
1afe1db1
FC
26/* ------------------------------- cv.h ------------------------------- */
27
28PERL_STATIC_INLINE I32 *
29S_CvDEPTHp(const CV * const sv)
30{
31 assert(SvTYPE(sv) == SVt_PVCV || SvTYPE(sv) == SVt_PVFM);
8de47657 32 return &((XPVCV*)SvANY(sv))->xcv_depth;
1afe1db1
FC
33}
34
8d919b0a
FC
35/* ----------------------------- regexp.h ----------------------------- */
36
37PERL_STATIC_INLINE struct regexp *
38S_ReANY(const REGEXP * const re)
39{
40 assert(isREGEXP(re));
41 return re->sv_u.svu_rx;
42}
43
27669aa4
FC
44/* ------------------------------- sv.h ------------------------------- */
45
46PERL_STATIC_INLINE SV *
47S_SvREFCNT_inc(SV *sv)
48{
2439e033 49 if (LIKELY(sv != NULL))
27669aa4
FC
50 SvREFCNT(sv)++;
51 return sv;
52}
53PERL_STATIC_INLINE SV *
54S_SvREFCNT_inc_NN(SV *sv)
55{
56 SvREFCNT(sv)++;
57 return sv;
58}
59PERL_STATIC_INLINE void
60S_SvREFCNT_inc_void(SV *sv)
61{
2439e033 62 if (LIKELY(sv != NULL))
27669aa4
FC
63 SvREFCNT(sv)++;
64}
75e16a44
FC
65PERL_STATIC_INLINE void
66S_SvREFCNT_dec(pTHX_ SV *sv)
67{
2439e033 68 if (LIKELY(sv != NULL)) {
75a9bf96 69 U32 rc = SvREFCNT(sv);
79e2a32a 70 if (LIKELY(rc > 1))
75a9bf96
DM
71 SvREFCNT(sv) = rc - 1;
72 else
73 Perl_sv_free2(aTHX_ sv, rc);
75e16a44
FC
74 }
75}
541377b1
FC
76
77PERL_STATIC_INLINE void
4a9a56a7
DM
78S_SvREFCNT_dec_NN(pTHX_ SV *sv)
79{
80 U32 rc = SvREFCNT(sv);
79e2a32a 81 if (LIKELY(rc > 1))
4a9a56a7
DM
82 SvREFCNT(sv) = rc - 1;
83 else
84 Perl_sv_free2(aTHX_ sv, rc);
85}
86
87PERL_STATIC_INLINE void
541377b1
FC
88SvAMAGIC_on(SV *sv)
89{
90 assert(SvROK(sv));
91 if (SvOBJECT(SvRV(sv))) HvAMAGIC_on(SvSTASH(SvRV(sv)));
92}
93PERL_STATIC_INLINE void
94SvAMAGIC_off(SV *sv)
95{
96 if (SvROK(sv) && SvOBJECT(SvRV(sv)))
97 HvAMAGIC_off(SvSTASH(SvRV(sv)));
98}
99
100PERL_STATIC_INLINE U32
101S_SvPADTMP_on(SV *sv)
102{
103 assert(!(SvFLAGS(sv) & SVs_PADMY));
104 return SvFLAGS(sv) |= SVs_PADTMP;
105}
106PERL_STATIC_INLINE U32
107S_SvPADTMP_off(SV *sv)
108{
109 assert(!(SvFLAGS(sv) & SVs_PADMY));
110 return SvFLAGS(sv) &= ~SVs_PADTMP;
111}
112PERL_STATIC_INLINE U32
113S_SvPADSTALE_on(SV *sv)
114{
115 assert(SvFLAGS(sv) & SVs_PADMY);
116 return SvFLAGS(sv) |= SVs_PADSTALE;
117}
118PERL_STATIC_INLINE U32
119S_SvPADSTALE_off(SV *sv)
120{
121 assert(SvFLAGS(sv) & SVs_PADMY);
122 return SvFLAGS(sv) &= ~SVs_PADSTALE;
123}
4ddea69a
FC
124#ifdef PERL_CORE
125PERL_STATIC_INLINE STRLEN
6964422a 126S_sv_or_pv_pos_u2b(pTHX_ SV *sv, const char *pv, STRLEN pos, STRLEN *lenp)
4ddea69a
FC
127{
128 if (SvGAMAGIC(sv)) {
129 U8 *hopped = utf8_hop((U8 *)pv, pos);
130 if (lenp) *lenp = (STRLEN)(utf8_hop(hopped, *lenp) - hopped);
131 return (STRLEN)(hopped - (U8 *)pv);
132 }
133 return sv_pos_u2b_flags(sv,pos,lenp,SV_CONST_RETURN);
134}
135#endif
f019c49e 136
a8a2ceaa
KW
137/* ------------------------------- utf8.h ------------------------------- */
138
139/* These exist only to replace the macros they formerly were so that their use
140 * can be deprecated */
141
142PERL_STATIC_INLINE bool
143S_isIDFIRST_lazy(pTHX_ const char* p)
144{
145 PERL_ARGS_ASSERT_ISIDFIRST_LAZY;
146
147 return isIDFIRST_lazy_if(p,1);
148}
149
150PERL_STATIC_INLINE bool
151S_isALNUM_lazy(pTHX_ const char* p)
152{
153 PERL_ARGS_ASSERT_ISALNUM_LAZY;
154
155 return isALNUM_lazy_if(p,1);
156}