This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Allow regexp-to-pvlv assignment
[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
8d919b0a
FC
24/* ----------------------------- regexp.h ----------------------------- */
25
26PERL_STATIC_INLINE struct regexp *
27S_ReANY(const REGEXP * const re)
28{
29 assert(isREGEXP(re));
30 return re->sv_u.svu_rx;
31}
32
27669aa4
FC
33/* ------------------------------- sv.h ------------------------------- */
34
35PERL_STATIC_INLINE SV *
36S_SvREFCNT_inc(SV *sv)
37{
38 if (sv)
39 SvREFCNT(sv)++;
40 return sv;
41}
42PERL_STATIC_INLINE SV *
43S_SvREFCNT_inc_NN(SV *sv)
44{
45 SvREFCNT(sv)++;
46 return sv;
47}
48PERL_STATIC_INLINE void
49S_SvREFCNT_inc_void(SV *sv)
50{
51 if (sv)
52 SvREFCNT(sv)++;
53}
75e16a44
FC
54PERL_STATIC_INLINE void
55S_SvREFCNT_dec(pTHX_ SV *sv)
56{
57 if (sv) {
58 if (SvREFCNT(sv)) {
59 if (--(SvREFCNT(sv)) == 0)
60 Perl_sv_free2(aTHX_ sv);
61 } else {
62 sv_free(sv);
63 }
64 }
65}
541377b1
FC
66
67PERL_STATIC_INLINE void
68SvAMAGIC_on(SV *sv)
69{
70 assert(SvROK(sv));
71 if (SvOBJECT(SvRV(sv))) HvAMAGIC_on(SvSTASH(SvRV(sv)));
72}
73PERL_STATIC_INLINE void
74SvAMAGIC_off(SV *sv)
75{
76 if (SvROK(sv) && SvOBJECT(SvRV(sv)))
77 HvAMAGIC_off(SvSTASH(SvRV(sv)));
78}
79
80PERL_STATIC_INLINE U32
81S_SvPADTMP_on(SV *sv)
82{
83 assert(!(SvFLAGS(sv) & SVs_PADMY));
84 return SvFLAGS(sv) |= SVs_PADTMP;
85}
86PERL_STATIC_INLINE U32
87S_SvPADTMP_off(SV *sv)
88{
89 assert(!(SvFLAGS(sv) & SVs_PADMY));
90 return SvFLAGS(sv) &= ~SVs_PADTMP;
91}
92PERL_STATIC_INLINE U32
93S_SvPADSTALE_on(SV *sv)
94{
95 assert(SvFLAGS(sv) & SVs_PADMY);
96 return SvFLAGS(sv) |= SVs_PADSTALE;
97}
98PERL_STATIC_INLINE U32
99S_SvPADSTALE_off(SV *sv)
100{
101 assert(SvFLAGS(sv) & SVs_PADMY);
102 return SvFLAGS(sv) &= ~SVs_PADSTALE;
103}
4ddea69a
FC
104#ifdef PERL_CORE
105PERL_STATIC_INLINE STRLEN
6964422a 106S_sv_or_pv_pos_u2b(pTHX_ SV *sv, const char *pv, STRLEN pos, STRLEN *lenp)
4ddea69a
FC
107{
108 if (SvGAMAGIC(sv)) {
109 U8 *hopped = utf8_hop((U8 *)pv, pos);
110 if (lenp) *lenp = (STRLEN)(utf8_hop(hopped, *lenp) - hopped);
111 return (STRLEN)(hopped - (U8 *)pv);
112 }
113 return sv_pos_u2b_flags(sv,pos,lenp,SV_CONST_RETURN);
114}
115#endif
f019c49e
DD
116
117/* ------------------------------- handy.h ------------------------------- */
118
119/* saves machine code for a common noreturn idiom typically used in Newx*() */
120static void
121S_croak_memory_wrap(void)
122{
123 Perl_croak_nocontext("%s",PL_memory_wrap);
124}