Debian Codegraph @

hax/perl-backcompat.c.inc

raw
1 /* vi: set ft=c : */
2
3 #define HAVE_PERL_VERSION(R, V, S) \
4 (PERL_REVISION > (R) || (PERL_REVISION == (R) && (PERL_VERSION > (V) || (PERL_VERSION == (V) && (PERL_SUBVERSION >= (S))))))
5
6 #ifndef NOT_REACHED
7 # define NOT_REACHED assert(0)
8 #endif
9
10 #ifndef SvTRUE_NN
11 # define SvTRUE_NN(sv) SvTRUE(sv)
12 #endif
13
14 #ifndef G_LIST
15 # define G_LIST G_ARRAY
16 #endif
17
18 #if !HAVE_PERL_VERSION(5, 18, 0)
19 typedef AV PADNAMELIST;
20 # define PadlistARRAY(pl) ((PAD **)AvARRAY(pl))
21 # define PadlistNAMES(pl) (*PadlistARRAY(pl))
22
23 typedef SV PADNAME;
24 # define PadnamePV(pn) (SvPOKp(pn) ? SvPVX(pn) : NULL)
25 # define PadnameLEN(pn) SvCUR(pn)
26 # define PadnameIsSTATE(pn) (!!SvPAD_STATE(pn))
27 # define PadnameOUTER(pn) (SvFAKE(pn) && !SvPAD_STATE(pn))
28 # define PadnamelistARRAY(pnl) AvARRAY(pnl)
29 # define PadnamelistMAX(pnl) AvFILLp(pnl)
30
31 # define PadARRAY(p) AvARRAY(p)
32 # define PadMAX(pad) AvFILLp(pad)
33 #endif
34
35 #if !HAVE_PERL_VERSION(5, 22, 0)
36 # define CvPADLIST_set(cv, padlist) (CvPADLIST(cv) = padlist)
37 # define newPADNAMEpvn(p,n) S_newPADNAMEpvn(aTHX_ p,n)
38 static PADNAME *S_newPADNAMEpvn(pTHX_ const char *pv, STRLEN n)
39 {
40 PADNAME *pn = newSVpvn(pv, n);
41 /* PADNAMEs need to be at least SVt_PVNV in order to store the COP_SEQ_*
42 * fields */
43 sv_upgrade(pn, SVt_PVNV);
44 return pn;
45 }
46 # define PadnameREFCNT_dec(pn) SvREFCNT_dec(pn)
47 #endif
48
49 #ifndef av_count
50 # define av_count(av) (AvFILL(av) + 1)
51 #endif
52
53 #ifndef av_fetch_simple
54 # define av_fetch_simple(av, idx, lval) av_fetch(av, idx, lval)
55 #endif
56
57 #ifndef av_push_simple
58 # define av_push_simple(av, sv) av_push(av, sv)
59 #endif
60
61 #ifndef av_store_simple
62 # define av_store_simple(av, key, sv) av_store(av, key, sv)
63 #endif
64
65 #ifndef av_top_index
66 # define av_top_index(av) AvFILL(av)
67 #endif
68
69 #ifndef block_end
70 # define block_end(a,b) Perl_block_end(aTHX_ a,b)
71 #endif
72
73 #ifndef block_start
74 # define block_start(a) Perl_block_start(aTHX_ a)
75 #endif
76
77 #ifndef cophh_exists_pvs
78 # define cophh_exists_pvs(a,b,c) cBOOL(cophh_fetch_pvs(a,b,c))
79 #endif
80
81 #ifndef cv_clone
82 # define cv_clone(a) Perl_cv_clone(aTHX_ a)
83 #endif
84
85 #ifndef intro_my
86 # define intro_my() Perl_intro_my(aTHX)
87 #endif
88
89 #ifndef pad_alloc
90 # define pad_alloc(a,b) Perl_pad_alloc(aTHX_ a,b)
91 #endif
92
93 #ifndef CX_CUR
94 # define CX_CUR() (&cxstack[cxstack_ix])
95 #endif
96
97 #if HAVE_PERL_VERSION(5, 24, 0)
98 # define OLDSAVEIX(cx) (cx->blk_oldsaveix)
99 #else
100 # define OLDSAVEIX(cx) (PL_scopestack[cx->blk_oldscopesp-1])
101 #endif
102
103 #ifndef OpSIBLING
104 # define OpSIBLING(op) ((op)->op_sibling)
105 #endif
106
107 #ifndef OpHAS_SIBLING
108 # define OpHAS_SIBLING(op) (cBOOL(OpSIBLING(op)))
109 #endif
110
111 #ifndef OpMORESIB_set
112 # define OpMORESIB_set(op,sib) ((op)->op_sibling = (sib))
113 #endif
114
115 #ifndef OpLASTSIB_set
116 /* older perls don't need to store this at all */
117 # define OpLASTSIB_set(op,parent) ((op)->op_sibling = NULL)
118 #endif
119
120 #ifndef op_convert_list
121 # define op_convert_list(type, flags, o) S_op_convert_list(aTHX_ type, flags, o)
122 static OP *S_op_convert_list(pTHX_ I32 type, I32 flags, OP *o)
123 {
124 /* A minimal recreation just for our purposes */
125 assert(
126 /* A hardcoded list of the optypes we know this will work for */
127 type == OP_ENTERSUB ||
128 type == OP_JOIN ||
129 type == OP_PUSH ||
130 0);
131
132 o->op_type = type;
133 o->op_flags |= flags;
134 o->op_ppaddr = PL_ppaddr[type];
135
136 o = PL_check[type](aTHX_ o);
137
138 /* op_std_init() */
139 if(PL_opargs[type] & OA_RETSCALAR)
140 o = op_contextualize(o, G_SCALAR);
141 if(PL_opargs[type] & OA_TARGET && !o->op_targ)
142 o->op_targ = pad_alloc(type, SVs_PADTMP);
143
144 return o;
145 }
146 #endif
147
148 #ifndef newMETHOP_named
149 # define newMETHOP_named(type, flags, name) newSVOP(type, flags, name)
150 #endif
151
152 #ifndef PARENT_PAD_INDEX_set
153 # if HAVE_PERL_VERSION(5, 22, 0)
154 # define PARENT_PAD_INDEX_set(pn,val) (PARENT_PAD_INDEX(pn) = val)
155 # else
156 /* stolen from perl-5.20.0's pad.c */
157 # define PARENT_PAD_INDEX_set(sv,val) \
158 STMT_START { ((XPVNV*)SvANY(sv))->xnv_u.xpad_cop_seq.xlow = (val); } STMT_END
159 # endif
160 #endif
161
162 /* On Perl 5.14 this had a different name */
163 #ifndef pad_add_name_pvn
164 #define pad_add_name_pvn(name, len, flags, typestash, ourstash) MY_pad_add_name(aTHX_ name, len, flags, typestash, ourstash)
165 static PADOFFSET MY_pad_add_name(pTHX_ const char *name, STRLEN len, U32 flags, HV *typestash, HV *ourstash)
166 {
167 /* perl 5.14's Perl_pad_add_name requires a NUL-terminated name */
168 SV *namesv = sv_2mortal(newSVpvn(name, len));
169
170 return Perl_pad_add_name(aTHX_ SvPV_nolen(namesv), SvCUR(namesv), flags, typestash, ourstash);
171 }
172 #endif
173
174 #if !HAVE_PERL_VERSION(5, 26, 0)
175 /* PERL_UNUSED_ARG() isn't usable to fix this on early perl versions */
176 # define isIDFIRST_utf8_safe(s, e) ((void)sizeof(e), isIDFIRST_utf8(s))
177 # define isIDCONT_utf8_safe(s, e) ((void)sizeof(e), isIDCONT_utf8(s))
178 #endif
179
180 #ifndef CXp_EVALBLOCK
181 /* before perl 5.34 this was called CXp_TRYBLOCK */
182 # define CXp_EVALBLOCK CXp_TRYBLOCK
183 #endif
184
185 #if !HAVE_PERL_VERSION(5, 26, 0)
186 # define sv_set_undef(sv) sv_setsv(sv, &PL_sv_undef)
187 #endif
188
189 #ifndef newAVav
190 # define newAVav(av) S_newAVav(aTHX_ av)
191 static AV *S_newAVav(pTHX_ AV *av)
192 {
193 AV *ret = newAV();
194 U32 count = av_count(av);
195 U32 i;
196 for(i = 0; i < count; i++)
197 av_push(ret, newSVsv(AvARRAY(av)[i]));
198 return ret;
199 }
200 #endif
201
202 #ifndef newAV_alloc_x
203 # define newAV_alloc_x(n) S_newAV_alloc_x(aTHX_ n)
204 static AV *S_newAV_alloc_x(pTHX_ SSize_t n)
205 {
206 AV *av = newAV();
207 av_extend(av, n-1);
208 return av;
209 }
210 #endif
211
212 #if !defined(sv_derived_from_hv) && HAVE_PERL_VERSION(5, 16, 0)
213 # define sv_derived_from_hv(sv, hv) MY_sv_derived_from_hv(aTHX_ sv, hv)
214 static bool MY_sv_derived_from_hv(pTHX_ SV *sv, HV *hv)
215 {
216 char *hvname = HvNAME(hv);
217 if(!hvname)
218 return FALSE;
219
220 return sv_derived_from_pvn(sv, hvname, HvNAMELEN(hv), HvNAMEUTF8(hv) ? SVf_UTF8 : 0);
221 }
222 #endif
223
224 #ifndef xV_FROM_REF
225 # ifdef PERL_USE_GCC_BRACE_GROUPS
226 # define xV_FROM_REF(XV, ref) \
227 ({ SV *_ref = ref; assert(SvROK(_ref)); assert(SvTYPE(SvRV(_ref)) == SVt_PV ## XV); (XV *)(SvRV(_ref)); })
228 # else
229 # define xV_FROM_REF(XV, ref) ((XV *)SvRV(ref))
230 # endif
231
232 # define AV_FROM_REF(ref) xV_FROM_REF(AV, ref)
233 # define CV_FROM_REF(ref) xV_FROM_REF(CV, ref)
234 # define HV_FROM_REF(ref) xV_FROM_REF(HV, ref)
235 #endif
236
237 #ifndef newPADxVOP
238 # define newPADxVOP(type, flags, padix) S_newPADxVOP(aTHX_ type, flags, padix)
239 static OP *S_newPADxVOP(pTHX_ I32 type, I32 flags, PADOFFSET padix)
240 {
241 OP *op = newOP(type, flags);
242 op->op_targ = padix;
243 return op;
244 }
245 #endif