1 /* This file is Based on output from
2 * Perl/Pollution/Portability Version 2.0000 */
4 #ifndef _P_P_PORTABILITY_H_
5 #define _P_P_PORTABILITY_H_
8 # ifndef __PATCHLEVEL_H_INCLUDED__
9 # include "patchlevel.h"
11 # ifndef PERL_REVISION
12 # define PERL_REVISION (5)
14 # define PERL_VERSION PATCHLEVEL
15 # define PERL_SUBVERSION SUBVERSION
16 /* Replace PERL_PATCHLEVEL with PERL_VERSION */
21 #define PERL_BCDVERSION ((PERL_REVISION * 0x1000000L) + (PERL_VERSION * 0x1000L) + PERL_SUBVERSION)
24 # define ERRSV perl_get_sv("@",FALSE)
27 #if (PERL_VERSION < 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION <= 5))
30 # define PL_compiling compiling
31 # define PL_copline copline
32 # define PL_curcop curcop
33 # define PL_curstash curstash
34 # define PL_defgv defgv
35 # define PL_dirty dirty
36 # define PL_hints hints
38 # define PL_perldb perldb
39 # define PL_rsfp_filters rsfp_filters
41 # define PL_stdingv stdingv
42 # define PL_sv_no sv_no
43 # define PL_sv_undef sv_undef
44 # define PL_sv_yes sv_yes
56 # define PTR2IV(d) (IV)(d)
60 # define INT2PTR(any,d) (any)(d)
65 # define dTHR extern int Perl___notused
67 # define dTHR extern int errno
72 # define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
76 # define gv_stashpvn(str,len,flags) gv_stashpv(str,flags)
80 # define newSVpvn(data,len) ((len) ? newSVpv ((data), (len)) : newSVpv ("", 0))
89 # define newRV_inc(sv) newRV(sv)
93 /* DEFSV appears first in 5.004_56 */
95 # define DEFSV GvSV(PL_defgv)
99 # define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
104 # define newRV_noinc(sv) \
106 SV *nsv = (SV*)newRV(sv); \
111 # if defined(CRIPPLED_CC) || defined(USE_THREADS)
112 static SV * newRV_noinc (SV * sv)
114 SV *nsv = (SV*)newRV(sv);
119 # define newRV_noinc(sv) \
120 ((PL_Sv=(SV*)newRV(sv), SvREFCNT_dec(sv), (SV*)PL_Sv)
125 /* Provide: newCONSTSUB */
127 /* newCONSTSUB from IO.xs is in the core starting with 5.004_63 */
128 #if (PERL_VERSION < 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION < 63))
130 #if defined(NEED_newCONSTSUB)
133 extern void newCONSTSUB _((HV * stash, char * name, SV *sv));
136 #if defined(NEED_newCONSTSUB) || defined(NEED_newCONSTSUB_GLOBAL)
138 newCONSTSUB(stash,name,sv)
143 U32 oldhints = PL_hints;
144 HV *old_cop_stash = PL_curcop->cop_stash;
145 HV *old_curstash = PL_curstash;
146 line_t oldline = PL_curcop->cop_line;
147 PL_curcop->cop_line = PL_copline;
149 PL_hints &= ~HINT_BLOCK_SCOPE;
151 PL_curstash = PL_curcop->cop_stash = stash;
155 #if (PERL_VERSION < 3) || ((PERL_VERSION == 3) && (PERL_SUBVERSION < 22))
156 /* before 5.003_22 */
159 # if (PERL_VERSION == 3) && (PERL_SUBVERSION == 22)
163 /* 5.003_23 onwards */
164 start_subparse(FALSE, 0),
168 newSVOP(OP_CONST, 0, newSVpv(name,0)),
169 newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
170 newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
174 PL_curcop->cop_stash = old_cop_stash;
175 PL_curstash = old_curstash;
176 PL_curcop->cop_line = oldline;
180 #endif /* newCONSTSUB */
186 * Boilerplate macros for initializing and accessing interpreter-local
187 * data from C. All statics in extensions should be reworked to use
188 * this, if you want to make the extension thread-safe. See ext/re/re.xs
189 * for an example of the use of these macros.
191 * Code that uses these macros is responsible for the following:
192 * 1. #define MY_CXT_KEY to a unique string, e.g. "DynaLoader_guts"
193 * 2. Declare a typedef named my_cxt_t that is a structure that contains
194 * all the data that needs to be interpreter-local.
195 * 3. Use the START_MY_CXT macro after the declaration of my_cxt_t.
196 * 4. Use the MY_CXT_INIT macro such that it is called exactly once
197 * (typically put in the BOOT: section).
198 * 5. Use the members of the my_cxt_t structure everywhere as
200 * 6. Use the dMY_CXT macro (a declaration) in all the functions that
204 #if defined(MULTIPLICITY) || defined(PERL_OBJECT) || \
205 defined(PERL_CAPI) || defined(PERL_IMPLICIT_CONTEXT)
207 /* This must appear in all extensions that define a my_cxt_t structure,
208 * right after the definition (i.e. at file scope). The non-threads
209 * case below uses it to declare the data as static. */
212 #if PERL_REVISION == 5 && \
213 (PERL_VERSION < 4 || (PERL_VERSION == 4 && PERL_SUBVERSION < 68 ))
214 /* Fetches the SV that keeps the per-interpreter data. */
216 SV *my_cxt_sv = perl_get_sv(MY_CXT_KEY, FALSE)
217 #else /* >= perl5.004_68 */
219 SV *my_cxt_sv = *hv_fetch(PL_modglobal, MY_CXT_KEY, \
220 sizeof(MY_CXT_KEY)-1, TRUE)
221 #endif /* < perl5.004_68 */
223 /* This declaration should be used within all functions that use the
224 * interpreter-local data. */
227 my_cxt_t *my_cxtp = INT2PTR(my_cxt_t*,SvUV(my_cxt_sv))
229 /* Creates and zeroes the per-interpreter data.
230 * (We allocate my_cxtp in a Perl SV so that it will be released when
231 * the interpreter goes away.) */
232 #define MY_CXT_INIT \
234 /* newSV() allocates one more than needed */ \
235 my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\
236 Zero(my_cxtp, 1, my_cxt_t); \
237 sv_setuv(my_cxt_sv, PTR2UV(my_cxtp))
239 /* This macro must be used to access members of the my_cxt_t structure.
240 * e.g. MYCXT.some_data */
241 #define MY_CXT (*my_cxtp)
243 /* Judicious use of these macros can reduce the number of times dMY_CXT
244 * is used. Use is similar to pTHX, aTHX etc. */
245 #define pMY_CXT my_cxt_t *my_cxtp
246 #define pMY_CXT_ pMY_CXT,
247 #define _pMY_CXT ,pMY_CXT
248 #define aMY_CXT my_cxtp
249 #define aMY_CXT_ aMY_CXT,
250 #define _aMY_CXT ,aMY_CXT
252 #else /* single interpreter */
255 # define NOOP (void)0
259 # define PERL_UNUSED_DECL __attribute__((unused))
261 # define PERL_UNUSED_DECL
265 # define dNOOP extern int Perl___notused PERL_UNUSED_DECL
268 #define START_MY_CXT static my_cxt_t my_cxt;
269 #define dMY_CXT_SV dNOOP
270 #define dMY_CXT dNOOP
271 #define MY_CXT_INIT NOOP
272 #define MY_CXT my_cxt
283 #endif /* START_MY_CXT */
286 #endif /* _P_P_PORTABILITY_H_ */