This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Static inline functions for SvPADTMP and SvPADSTALE
[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
FC
14
15/* ------------------------------- sv.h ------------------------------- */
16
17PERL_STATIC_INLINE SV *
18S_SvREFCNT_inc(SV *sv)
19{
20 if (sv)
21 SvREFCNT(sv)++;
22 return sv;
23}
24PERL_STATIC_INLINE SV *
25S_SvREFCNT_inc_NN(SV *sv)
26{
27 SvREFCNT(sv)++;
28 return sv;
29}
30PERL_STATIC_INLINE void
31S_SvREFCNT_inc_void(SV *sv)
32{
33 if (sv)
34 SvREFCNT(sv)++;
35}
75e16a44
FC
36PERL_STATIC_INLINE void
37S_SvREFCNT_dec(pTHX_ SV *sv)
38{
39 if (sv) {
40 if (SvREFCNT(sv)) {
41 if (--(SvREFCNT(sv)) == 0)
42 Perl_sv_free2(aTHX_ sv);
43 } else {
44 sv_free(sv);
45 }
46 }
47}
541377b1
FC
48
49PERL_STATIC_INLINE void
50SvAMAGIC_on(SV *sv)
51{
52 assert(SvROK(sv));
53 if (SvOBJECT(SvRV(sv))) HvAMAGIC_on(SvSTASH(SvRV(sv)));
54}
55PERL_STATIC_INLINE void
56SvAMAGIC_off(SV *sv)
57{
58 if (SvROK(sv) && SvOBJECT(SvRV(sv)))
59 HvAMAGIC_off(SvSTASH(SvRV(sv)));
60}
61
62PERL_STATIC_INLINE U32
63S_SvPADTMP_on(SV *sv)
64{
65 assert(!(SvFLAGS(sv) & SVs_PADMY));
66 return SvFLAGS(sv) |= SVs_PADTMP;
67}
68PERL_STATIC_INLINE U32
69S_SvPADTMP_off(SV *sv)
70{
71 assert(!(SvFLAGS(sv) & SVs_PADMY));
72 return SvFLAGS(sv) &= ~SVs_PADTMP;
73}
74PERL_STATIC_INLINE U32
75S_SvPADSTALE_on(SV *sv)
76{
77 assert(SvFLAGS(sv) & SVs_PADMY);
78 return SvFLAGS(sv) |= SVs_PADSTALE;
79}
80PERL_STATIC_INLINE U32
81S_SvPADSTALE_off(SV *sv)
82{
83 assert(SvFLAGS(sv) & SVs_PADMY);
84 return SvFLAGS(sv) &= ~SVs_PADSTALE;
85}