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))
85
# define newRV_inc(sv) newRV(sv)
89
/* DEFSV appears first in 5.004_56 */
91
# define DEFSV GvSV(PL_defgv)
95
# define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
100
# define newRV_noinc(sv) \
102
SV *nsv = (SV*)newRV(sv); \
107
# if defined(CRIPPLED_CC) || defined(USE_THREADS)
108
static SV * newRV_noinc (SV * sv)
110
SV *nsv = (SV*)newRV(sv);
115
# define newRV_noinc(sv) \
116
((PL_Sv=(SV*)newRV(sv), SvREFCNT_dec(sv), (SV*)PL_Sv)
121
/* Provide: newCONSTSUB */
123
/* newCONSTSUB from IO.xs is in the core starting with 5.004_63 */
124
#if (PERL_VERSION < 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION < 63))
126
#if defined(NEED_newCONSTSUB)
129
extern void newCONSTSUB _((HV * stash, char * name, SV *sv));
132
#if defined(NEED_newCONSTSUB) || defined(NEED_newCONSTSUB_GLOBAL)
134
newCONSTSUB(stash,name,sv)
139
U32 oldhints = PL_hints;
140
HV *old_cop_stash = PL_curcop->cop_stash;
141
HV *old_curstash = PL_curstash;
142
line_t oldline = PL_curcop->cop_line;
143
PL_curcop->cop_line = PL_copline;
145
PL_hints &= ~HINT_BLOCK_SCOPE;
147
PL_curstash = PL_curcop->cop_stash = stash;
151
#if (PERL_VERSION < 3) || ((PERL_VERSION == 3) && (PERL_SUBVERSION < 22))
152
/* before 5.003_22 */
155
# if (PERL_VERSION == 3) && (PERL_SUBVERSION == 22)
159
/* 5.003_23 onwards */
160
start_subparse(FALSE, 0),
164
newSVOP(OP_CONST, 0, newSVpv(name,0)),
165
newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
166
newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
170
PL_curcop->cop_stash = old_cop_stash;
171
PL_curstash = old_curstash;
172
PL_curcop->cop_line = oldline;
176
#endif /* newCONSTSUB */
182
* Boilerplate macros for initializing and accessing interpreter-local
183
* data from C. All statics in extensions should be reworked to use
184
* this, if you want to make the extension thread-safe. See ext/re/re.xs
185
* for an example of the use of these macros.
187
* Code that uses these macros is responsible for the following:
188
* 1. #define MY_CXT_KEY to a unique string, e.g. "DynaLoader_guts"
189
* 2. Declare a typedef named my_cxt_t that is a structure that contains
190
* all the data that needs to be interpreter-local.
191
* 3. Use the START_MY_CXT macro after the declaration of my_cxt_t.
192
* 4. Use the MY_CXT_INIT macro such that it is called exactly once
193
* (typically put in the BOOT: section).
194
* 5. Use the members of the my_cxt_t structure everywhere as
196
* 6. Use the dMY_CXT macro (a declaration) in all the functions that
200
#if defined(MULTIPLICITY) || defined(PERL_OBJECT) || \
201
defined(PERL_CAPI) || defined(PERL_IMPLICIT_CONTEXT)
203
/* This must appear in all extensions that define a my_cxt_t structure,
204
* right after the definition (i.e. at file scope). The non-threads
205
* case below uses it to declare the data as static. */
208
#if PERL_REVISION == 5 && \
209
(PERL_VERSION < 4 || (PERL_VERSION == 4 && PERL_SUBVERSION < 68 ))
210
/* Fetches the SV that keeps the per-interpreter data. */
212
SV *my_cxt_sv = perl_get_sv(MY_CXT_KEY, FALSE)
213
#else /* >= perl5.004_68 */
215
SV *my_cxt_sv = *hv_fetch(PL_modglobal, MY_CXT_KEY, \
216
sizeof(MY_CXT_KEY)-1, TRUE)
217
#endif /* < perl5.004_68 */
219
/* This declaration should be used within all functions that use the
220
* interpreter-local data. */
223
my_cxt_t *my_cxtp = INT2PTR(my_cxt_t*,SvUV(my_cxt_sv))
225
/* Creates and zeroes the per-interpreter data.
226
* (We allocate my_cxtp in a Perl SV so that it will be released when
227
* the interpreter goes away.) */
228
#define MY_CXT_INIT \
230
/* newSV() allocates one more than needed */ \
231
my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\
232
Zero(my_cxtp, 1, my_cxt_t); \
233
sv_setuv(my_cxt_sv, PTR2UV(my_cxtp))
235
/* This macro must be used to access members of the my_cxt_t structure.
236
* e.g. MYCXT.some_data */
237
#define MY_CXT (*my_cxtp)
239
/* Judicious use of these macros can reduce the number of times dMY_CXT
240
* is used. Use is similar to pTHX, aTHX etc. */
241
#define pMY_CXT my_cxt_t *my_cxtp
242
#define pMY_CXT_ pMY_CXT,
243
#define _pMY_CXT ,pMY_CXT
244
#define aMY_CXT my_cxtp
245
#define aMY_CXT_ aMY_CXT,
246
#define _aMY_CXT ,aMY_CXT
248
#else /* single interpreter */
251
# define NOOP (void)0
255
# define PERL_UNUSED_DECL __attribute__((unused))
257
# define PERL_UNUSED_DECL
261
# define dNOOP extern int Perl___notused PERL_UNUSED_DECL
264
#define START_MY_CXT static my_cxt_t my_cxt;
265
#define dMY_CXT_SV dNOOP
266
#define dMY_CXT dNOOP
267
#define MY_CXT_INIT NOOP
268
#define MY_CXT my_cxt
279
#endif /* START_MY_CXT */
282
#ifndef DBM_setFilter
285
The DBM_setFilter & DBM_ckFilter macros are only used by
286
the *DB*_File modules
289
#define DBM_setFilter(db_type,code) \
292
RETVAL = sv_mortalcopy(db_type) ; \
294
if (db_type && (code == &PL_sv_undef)) { \
295
SvREFCNT_dec(db_type) ; \
300
sv_setsv(db_type, code) ; \
302
db_type = newSVsv(code) ; \
306
#define DBM_ckFilter(arg,type,name) \
308
if (db->filtering) { \
309
croak("recursion detected in %s", name) ; \
313
SAVEINT(db->filtering) ; \
314
db->filtering = TRUE ; \
320
(void) perl_call_sv(db->type, G_DISCARD); \
327
#endif /* DBM_setFilter */
329
#endif /* _P_P_PORTABILITY_H_ */