3 * Copyright (C) 2012 by Larry Wall and others
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.
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.
12 * Each section names the header file that the functions "belong" to.
15 /* ------------------------------- av.h ------------------------------- */
17 PERL_STATIC_INLINE I32
18 S_av_top_index(pTHX_ AV *av)
20 PERL_ARGS_ASSERT_AV_TOP_INDEX;
21 assert(SvTYPE(av) == SVt_PVAV);
26 /* ------------------------------- cv.h ------------------------------- */
28 PERL_STATIC_INLINE I32 *
29 S_CvDEPTHp(const CV * const sv)
31 assert(SvTYPE(sv) == SVt_PVCV || SvTYPE(sv) == SVt_PVFM);
32 return &((XPVCV*)SvANY(sv))->xcv_depth;
36 CvPROTO returns the prototype as stored, which is not necessarily what
37 the interpreter should be using. Specifically, the interpreter assumes
38 that spaces have been stripped, which has been the case if the prototype
39 was added by toke.c, but is generally not the case if it was added elsewhere.
40 Since we can't enforce the spacelessness at assignment time, this routine
41 provides a temporary copy at parse time with spaces removed.
42 I<orig> is the start of the original buffer, I<len> is the length of the
43 prototype and will be updated when this returns.
47 PERL_STATIC_INLINE char *
48 S_strip_spaces(pTHX_ const char * orig, STRLEN * const len)
52 tmpsv = newSVpvn_flags(orig, *len, SVs_TEMP);
60 *len = tmps - SvPVX(tmpsv);
65 /* ----------------------------- regexp.h ----------------------------- */
67 PERL_STATIC_INLINE struct regexp *
68 S_ReANY(const REGEXP * const re)
71 return re->sv_u.svu_rx;
74 /* ------------------------------- sv.h ------------------------------- */
76 PERL_STATIC_INLINE SV *
77 S_SvREFCNT_inc(SV *sv)
79 if (LIKELY(sv != NULL))
83 PERL_STATIC_INLINE SV *
84 S_SvREFCNT_inc_NN(SV *sv)
89 PERL_STATIC_INLINE void
90 S_SvREFCNT_inc_void(SV *sv)
92 if (LIKELY(sv != NULL))
95 PERL_STATIC_INLINE void
96 S_SvREFCNT_dec(pTHX_ SV *sv)
98 if (LIKELY(sv != NULL)) {
99 U32 rc = SvREFCNT(sv);
101 SvREFCNT(sv) = rc - 1;
103 Perl_sv_free2(aTHX_ sv, rc);
107 PERL_STATIC_INLINE void
108 S_SvREFCNT_dec_NN(pTHX_ SV *sv)
110 U32 rc = SvREFCNT(sv);
112 SvREFCNT(sv) = rc - 1;
114 Perl_sv_free2(aTHX_ sv, rc);
117 PERL_STATIC_INLINE void
121 if (SvOBJECT(SvRV(sv))) HvAMAGIC_on(SvSTASH(SvRV(sv)));
123 PERL_STATIC_INLINE void
126 if (SvROK(sv) && SvOBJECT(SvRV(sv)))
127 HvAMAGIC_off(SvSTASH(SvRV(sv)));
130 PERL_STATIC_INLINE U32
131 S_SvPADTMP_on(SV *sv)
133 assert(!(SvFLAGS(sv) & SVs_PADMY));
134 return SvFLAGS(sv) |= SVs_PADTMP;
136 PERL_STATIC_INLINE U32
137 S_SvPADTMP_off(SV *sv)
139 assert(!(SvFLAGS(sv) & SVs_PADMY));
140 return SvFLAGS(sv) &= ~SVs_PADTMP;
142 PERL_STATIC_INLINE U32
143 S_SvPADSTALE_on(SV *sv)
145 assert(SvFLAGS(sv) & SVs_PADMY);
146 return SvFLAGS(sv) |= SVs_PADSTALE;
148 PERL_STATIC_INLINE U32
149 S_SvPADSTALE_off(SV *sv)
151 assert(SvFLAGS(sv) & SVs_PADMY);
152 return SvFLAGS(sv) &= ~SVs_PADSTALE;
155 PERL_STATIC_INLINE STRLEN
156 S_sv_or_pv_pos_u2b(pTHX_ SV *sv, const char *pv, STRLEN pos, STRLEN *lenp)
159 U8 *hopped = utf8_hop((U8 *)pv, pos);
160 if (lenp) *lenp = (STRLEN)(utf8_hop(hopped, *lenp) - hopped);
161 return (STRLEN)(hopped - (U8 *)pv);
163 return sv_pos_u2b_flags(sv,pos,lenp,SV_CONST_RETURN);
167 /* ------------------------------- utf8.h ------------------------------- */
169 /* These exist only to replace the macros they formerly were so that their use
170 * can be deprecated */
172 PERL_STATIC_INLINE bool
173 S_isIDFIRST_lazy(pTHX_ const char* p)
175 PERL_ARGS_ASSERT_ISIDFIRST_LAZY;
177 return isIDFIRST_lazy_if(p,1);
180 PERL_STATIC_INLINE bool
181 S_isALNUM_lazy(pTHX_ const char* p)
183 PERL_ARGS_ASSERT_ISALNUM_LAZY;
185 return isALNUM_lazy_if(p,1);