This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Correct the SYNOPSIS for Module::CoreList::Utils
[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
be3a7a5d
KW
15/* ------------------------------- av.h ------------------------------- */
16
17PERL_STATIC_INLINE I32
18S_av_top_index(pTHX_ AV *av)
19{
20 PERL_ARGS_ASSERT_AV_TOP_INDEX;
21 assert(SvTYPE(av) == SVt_PVAV);
22
23 return AvFILL(av);
24}
25
1afe1db1
FC
26/* ------------------------------- cv.h ------------------------------- */
27
28PERL_STATIC_INLINE I32 *
29S_CvDEPTHp(const CV * const sv)
30{
31 assert(SvTYPE(sv) == SVt_PVCV || SvTYPE(sv) == SVt_PVFM);
8de47657 32 return &((XPVCV*)SvANY(sv))->xcv_depth;
1afe1db1
FC
33}
34
d16269d8
PM
35/*
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.
44 */
45
46PERL_STATIC_INLINE char *
47S_strip_spaces(pTHX_ const char * orig, STRLEN * const len)
48{
49 SV * tmpsv;
50 char * tmps;
51 tmpsv = newSVpvn_flags(orig, *len, SVs_TEMP);
52 tmps = SvPVX(tmpsv);
53 while ((*len)--) {
54 if (!isSPACE(*orig))
55 *tmps++ = *orig;
56 orig++;
57 }
58 *tmps = '\0';
59 *len = tmps - SvPVX(tmpsv);
60 return SvPVX(tmpsv);
61}
62
8d919b0a
FC
63/* ----------------------------- regexp.h ----------------------------- */
64
65PERL_STATIC_INLINE struct regexp *
66S_ReANY(const REGEXP * const re)
67{
68 assert(isREGEXP(re));
69 return re->sv_u.svu_rx;
70}
71
27669aa4
FC
72/* ------------------------------- sv.h ------------------------------- */
73
74PERL_STATIC_INLINE SV *
75S_SvREFCNT_inc(SV *sv)
76{
2439e033 77 if (LIKELY(sv != NULL))
27669aa4
FC
78 SvREFCNT(sv)++;
79 return sv;
80}
81PERL_STATIC_INLINE SV *
82S_SvREFCNT_inc_NN(SV *sv)
83{
84 SvREFCNT(sv)++;
85 return sv;
86}
87PERL_STATIC_INLINE void
88S_SvREFCNT_inc_void(SV *sv)
89{
2439e033 90 if (LIKELY(sv != NULL))
27669aa4
FC
91 SvREFCNT(sv)++;
92}
75e16a44
FC
93PERL_STATIC_INLINE void
94S_SvREFCNT_dec(pTHX_ SV *sv)
95{
2439e033 96 if (LIKELY(sv != NULL)) {
75a9bf96 97 U32 rc = SvREFCNT(sv);
79e2a32a 98 if (LIKELY(rc > 1))
75a9bf96
DM
99 SvREFCNT(sv) = rc - 1;
100 else
101 Perl_sv_free2(aTHX_ sv, rc);
75e16a44
FC
102 }
103}
541377b1
FC
104
105PERL_STATIC_INLINE void
4a9a56a7
DM
106S_SvREFCNT_dec_NN(pTHX_ SV *sv)
107{
108 U32 rc = SvREFCNT(sv);
79e2a32a 109 if (LIKELY(rc > 1))
4a9a56a7
DM
110 SvREFCNT(sv) = rc - 1;
111 else
112 Perl_sv_free2(aTHX_ sv, rc);
113}
114
115PERL_STATIC_INLINE void
541377b1
FC
116SvAMAGIC_on(SV *sv)
117{
118 assert(SvROK(sv));
119 if (SvOBJECT(SvRV(sv))) HvAMAGIC_on(SvSTASH(SvRV(sv)));
120}
121PERL_STATIC_INLINE void
122SvAMAGIC_off(SV *sv)
123{
124 if (SvROK(sv) && SvOBJECT(SvRV(sv)))
125 HvAMAGIC_off(SvSTASH(SvRV(sv)));
126}
127
128PERL_STATIC_INLINE U32
129S_SvPADTMP_on(SV *sv)
130{
131 assert(!(SvFLAGS(sv) & SVs_PADMY));
132 return SvFLAGS(sv) |= SVs_PADTMP;
133}
134PERL_STATIC_INLINE U32
135S_SvPADTMP_off(SV *sv)
136{
137 assert(!(SvFLAGS(sv) & SVs_PADMY));
138 return SvFLAGS(sv) &= ~SVs_PADTMP;
139}
140PERL_STATIC_INLINE U32
141S_SvPADSTALE_on(SV *sv)
142{
143 assert(SvFLAGS(sv) & SVs_PADMY);
144 return SvFLAGS(sv) |= SVs_PADSTALE;
145}
146PERL_STATIC_INLINE U32
147S_SvPADSTALE_off(SV *sv)
148{
149 assert(SvFLAGS(sv) & SVs_PADMY);
150 return SvFLAGS(sv) &= ~SVs_PADSTALE;
151}
4ddea69a
FC
152#ifdef PERL_CORE
153PERL_STATIC_INLINE STRLEN
6964422a 154S_sv_or_pv_pos_u2b(pTHX_ SV *sv, const char *pv, STRLEN pos, STRLEN *lenp)
4ddea69a
FC
155{
156 if (SvGAMAGIC(sv)) {
157 U8 *hopped = utf8_hop((U8 *)pv, pos);
158 if (lenp) *lenp = (STRLEN)(utf8_hop(hopped, *lenp) - hopped);
159 return (STRLEN)(hopped - (U8 *)pv);
160 }
161 return sv_pos_u2b_flags(sv,pos,lenp,SV_CONST_RETURN);
162}
163#endif
f019c49e 164
a8a2ceaa
KW
165/* ------------------------------- utf8.h ------------------------------- */
166
167/* These exist only to replace the macros they formerly were so that their use
168 * can be deprecated */
169
170PERL_STATIC_INLINE bool
171S_isIDFIRST_lazy(pTHX_ const char* p)
172{
173 PERL_ARGS_ASSERT_ISIDFIRST_LAZY;
174
175 return isIDFIRST_lazy_if(p,1);
176}
177
178PERL_STATIC_INLINE bool
179S_isALNUM_lazy(pTHX_ const char* p)
180{
181 PERL_ARGS_ASSERT_ISALNUM_LAZY;
182
183 return isALNUM_lazy_if(p,1);
184}