This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[Merge] utf8 caches and overload; other bug fixes
[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);
8de47657 21 return &((XPVCV*)SvANY(sv))->xcv_depth;
1afe1db1
FC
22}
23
27669aa4
FC
24/* ------------------------------- sv.h ------------------------------- */
25
26PERL_STATIC_INLINE SV *
27S_SvREFCNT_inc(SV *sv)
28{
29 if (sv)
30 SvREFCNT(sv)++;
31 return sv;
32}
33PERL_STATIC_INLINE SV *
34S_SvREFCNT_inc_NN(SV *sv)
35{
36 SvREFCNT(sv)++;
37 return sv;
38}
39PERL_STATIC_INLINE void
40S_SvREFCNT_inc_void(SV *sv)
41{
42 if (sv)
43 SvREFCNT(sv)++;
44}
75e16a44
FC
45PERL_STATIC_INLINE void
46S_SvREFCNT_dec(pTHX_ SV *sv)
47{
48 if (sv) {
49 if (SvREFCNT(sv)) {
50 if (--(SvREFCNT(sv)) == 0)
51 Perl_sv_free2(aTHX_ sv);
52 } else {
53 sv_free(sv);
54 }
55 }
56}
541377b1
FC
57
58PERL_STATIC_INLINE void
59SvAMAGIC_on(SV *sv)
60{
61 assert(SvROK(sv));
62 if (SvOBJECT(SvRV(sv))) HvAMAGIC_on(SvSTASH(SvRV(sv)));
63}
64PERL_STATIC_INLINE void
65SvAMAGIC_off(SV *sv)
66{
67 if (SvROK(sv) && SvOBJECT(SvRV(sv)))
68 HvAMAGIC_off(SvSTASH(SvRV(sv)));
69}
70
71PERL_STATIC_INLINE U32
72S_SvPADTMP_on(SV *sv)
73{
74 assert(!(SvFLAGS(sv) & SVs_PADMY));
75 return SvFLAGS(sv) |= SVs_PADTMP;
76}
77PERL_STATIC_INLINE U32
78S_SvPADTMP_off(SV *sv)
79{
80 assert(!(SvFLAGS(sv) & SVs_PADMY));
81 return SvFLAGS(sv) &= ~SVs_PADTMP;
82}
83PERL_STATIC_INLINE U32
84S_SvPADSTALE_on(SV *sv)
85{
86 assert(SvFLAGS(sv) & SVs_PADMY);
87 return SvFLAGS(sv) |= SVs_PADSTALE;
88}
89PERL_STATIC_INLINE U32
90S_SvPADSTALE_off(SV *sv)
91{
92 assert(SvFLAGS(sv) & SVs_PADMY);
93 return SvFLAGS(sv) &= ~SVs_PADSTALE;
94}
4ddea69a
FC
95#ifdef PERL_CORE
96PERL_STATIC_INLINE STRLEN
97sv_or_pv_pos_u2b(aTHX_ SV *sv, const char *pv, STRLEN pos, STRLEN *lenp)
98{
99 if (SvGAMAGIC(sv)) {
100 U8 *hopped = utf8_hop((U8 *)pv, pos);
101 if (lenp) *lenp = (STRLEN)(utf8_hop(hopped, *lenp) - hopped);
102 return (STRLEN)(hopped - (U8 *)pv);
103 }
104 return sv_pos_u2b_flags(sv,pos,lenp,SV_CONST_RETURN);
105}
106#endif