This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move S_CvDEPTHp from cv.h to inline.h; shrink macros
[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
1afe1db1
FC
15/* ------------------------------- cv.h ------------------------------- */
16
17PERL_STATIC_INLINE I32 *
18S_CvDEPTHp(const CV * const sv)
19{
20 assert(SvTYPE(sv) == SVt_PVCV || SvTYPE(sv) == SVt_PVFM);
21 return SvTYPE(sv) == SVt_PVCV
22 ? &((XPVCV*)SvANY(sv))->xcv_depth
23 : &((XPVCV*)SvANY(sv))->xpv_fmdepth;
24}
25
27669aa4
FC
26/* ------------------------------- sv.h ------------------------------- */
27
28PERL_STATIC_INLINE SV *
29S_SvREFCNT_inc(SV *sv)
30{
31 if (sv)
32 SvREFCNT(sv)++;
33 return sv;
34}
35PERL_STATIC_INLINE SV *
36S_SvREFCNT_inc_NN(SV *sv)
37{
38 SvREFCNT(sv)++;
39 return sv;
40}
41PERL_STATIC_INLINE void
42S_SvREFCNT_inc_void(SV *sv)
43{
44 if (sv)
45 SvREFCNT(sv)++;
46}
75e16a44
FC
47PERL_STATIC_INLINE void
48S_SvREFCNT_dec(pTHX_ SV *sv)
49{
50 if (sv) {
51 if (SvREFCNT(sv)) {
52 if (--(SvREFCNT(sv)) == 0)
53 Perl_sv_free2(aTHX_ sv);
54 } else {
55 sv_free(sv);
56 }
57 }
58}
541377b1
FC
59
60PERL_STATIC_INLINE void
61SvAMAGIC_on(SV *sv)
62{
63 assert(SvROK(sv));
64 if (SvOBJECT(SvRV(sv))) HvAMAGIC_on(SvSTASH(SvRV(sv)));
65}
66PERL_STATIC_INLINE void
67SvAMAGIC_off(SV *sv)
68{
69 if (SvROK(sv) && SvOBJECT(SvRV(sv)))
70 HvAMAGIC_off(SvSTASH(SvRV(sv)));
71}
72
73PERL_STATIC_INLINE U32
74S_SvPADTMP_on(SV *sv)
75{
76 assert(!(SvFLAGS(sv) & SVs_PADMY));
77 return SvFLAGS(sv) |= SVs_PADTMP;
78}
79PERL_STATIC_INLINE U32
80S_SvPADTMP_off(SV *sv)
81{
82 assert(!(SvFLAGS(sv) & SVs_PADMY));
83 return SvFLAGS(sv) &= ~SVs_PADTMP;
84}
85PERL_STATIC_INLINE U32
86S_SvPADSTALE_on(SV *sv)
87{
88 assert(SvFLAGS(sv) & SVs_PADMY);
89 return SvFLAGS(sv) |= SVs_PADSTALE;
90}
91PERL_STATIC_INLINE U32
92S_SvPADSTALE_off(SV *sv)
93{
94 assert(SvFLAGS(sv) & SVs_PADMY);
95 return SvFLAGS(sv) &= ~SVs_PADSTALE;
96}