Commit | Line | Data |
---|---|---|
a0d0e21e | 1 | /* perl.h |
a687059c | 2 | * |
1129b882 | 3 | * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 |
5cd3f21a | 4 | * 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by Larry Wall and others |
a687059c | 5 | * |
352d5a3a LW |
6 | * You may distribute under the terms of either the GNU General Public |
7 | * License or the Artistic License, as specified in the README file. | |
8d063cd8 | 8 | * |
8d063cd8 | 9 | */ |
d6376244 | 10 | |
85e6fe83 LW |
11 | #ifndef H_PERL |
12 | #define H_PERL 1 | |
8d063cd8 | 13 | |
760ac839 LW |
14 | #ifdef PERL_FOR_X2P |
15 | /* | |
d460ef45 | 16 | * This file is being used for x2p stuff. |
760ac839 | 17 | * Above symbol is defined via -D in 'x2p/Makefile.SH' |
d460ef45 | 18 | * Decouple x2p stuff from some of perls more extreme eccentricities. |
760ac839 | 19 | */ |
55497cff | 20 | #undef MULTIPLICITY |
760ac839 LW |
21 | #undef USE_STDIO |
22 | #define USE_STDIO | |
23 | #endif /* PERL_FOR_X2P */ | |
24 | ||
d460ef45 | 25 | #ifdef PERL_MICRO |
12ae5dfc JH |
26 | # include "uconfig.h" |
27 | #else | |
611cf957 | 28 | # include "config.h" |
12ae5dfc | 29 | #endif |
0cb96387 | 30 | |
70febf4f CB |
31 | /* this is used for functions which take a depth trailing |
32 | * argument under debugging */ | |
33 | #ifdef DEBUGGING | |
34 | #define _pDEPTH ,U32 depth | |
35 | #define _aDEPTH ,depth | |
36 | #else | |
37 | #define _pDEPTH | |
38 | #define _aDEPTH | |
39 | #endif | |
40 | ||
7dc3eb73 | 41 | /* NOTE 1: that with gcc -std=c89 the __STDC_VERSION__ is *not* defined |
9267464d | 42 | * because the __STDC_VERSION__ became a thing only with C90. Therefore, |
7dc3eb73 JH |
43 | * with gcc, HAS_C99 will never become true as long as we use -std=c89. |
44 | ||
45 | * NOTE 2: headers lie. Do not expect that if HAS_C99 gets to be true, | |
46 | * all the C99 features are there and are correct. */ | |
9267464d | 47 | #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ |
996959af | 48 | defined(_STDC_C99) || defined(__c99) |
86a3cabf | 49 | # define HAS_C99 1 |
86a3cabf JH |
50 | #endif |
51 | ||
2c2d71f5 JH |
52 | /* See L<perlguts/"The Perl API"> for detailed notes on |
53 | * PERL_IMPLICIT_CONTEXT and PERL_IMPLICIT_SYS */ | |
54 | ||
ac6bedea JH |
55 | /* Note that from here --> to <-- the same logic is |
56 | * repeated in makedef.pl, so be certain to update | |
57 | * both places when editing. */ | |
58 | ||
6f4183fe | 59 | #ifdef USE_ITHREADS |
acfe0abc | 60 | # if !defined(MULTIPLICITY) |
6f4183fe GS |
61 | # define MULTIPLICITY |
62 | # endif | |
63 | #endif | |
64 | ||
27da23d5 JH |
65 | #ifdef PERL_GLOBAL_STRUCT_PRIVATE |
66 | # ifndef PERL_GLOBAL_STRUCT | |
67 | # define PERL_GLOBAL_STRUCT | |
68 | # endif | |
69 | #endif | |
97aff369 | 70 | |
27da23d5 JH |
71 | #ifdef PERL_GLOBAL_STRUCT |
72 | # ifndef MULTIPLICITY | |
73 | # define MULTIPLICITY | |
74 | # endif | |
75 | #endif | |
76 | ||
97aff369 JH |
77 | #ifdef MULTIPLICITY |
78 | # ifndef PERL_IMPLICIT_CONTEXT | |
79 | # define PERL_IMPLICIT_CONTEXT | |
80 | # endif | |
81 | #endif | |
82 | ||
026fd48b GH |
83 | /* undef WIN32 when building on Cygwin (for libwin32) - gph */ |
84 | #ifdef __CYGWIN__ | |
85 | # undef WIN32 | |
86 | # undef _WIN32 | |
87 | #endif | |
88 | ||
27da23d5 JH |
89 | #if defined(__SYMBIAN32__) || (defined(__VC32__) && defined(WINS)) |
90 | # ifndef SYMBIAN | |
91 | # define SYMBIAN | |
92 | # endif | |
93 | #endif | |
94 | ||
a0fd4948 | 95 | #ifdef __SYMBIAN32__ |
27da23d5 JH |
96 | # include "symbian/symbian_proto.h" |
97 | #endif | |
98 | ||
99 | /* Any stack-challenged places. The limit varies (and often | |
100 | * is configurable), but using more than a kilobyte of stack | |
101 | * is usually dubious in these systems. */ | |
739a0b84 NC |
102 | #if defined(__SYMBIAN32__) |
103 | /* Symbian: need to work around the SDK features. * | |
27da23d5 JH |
104 | * On WINS: MS VC5 generates calls to _chkstk, * |
105 | * if a "large" stack frame is allocated. * | |
106 | * gcc on MARM does not generate calls like these. */ | |
107 | # define USE_HEAP_INSTEAD_OF_STACK | |
108 | #endif | |
109 | ||
dd134d2c | 110 | /* Use the reentrant APIs like localtime_r and getpwent_r */ |
10bc17b6 | 111 | /* Win32 has naturally threadsafe libraries, no need to use any _r variants. */ |
14795193 | 112 | #if defined(USE_ITHREADS) && !defined(USE_REENTRANT_API) && !defined(NETWARE) && !defined(WIN32) |
10bc17b6 JH |
113 | # define USE_REENTRANT_API |
114 | #endif | |
115 | ||
ac6bedea JH |
116 | /* <--- here ends the logic shared by perl.h and makedef.pl */ |
117 | ||
9ea40801 SH |
118 | /* Microsoft Visual C++ 6.0 needs special treatment in numerous places */ |
119 | #if defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1200 && _MSC_VER < 1300 | |
120 | # define USING_MSVC6 | |
121 | #endif | |
122 | ||
cf5a8da6 MHM |
123 | #undef START_EXTERN_C |
124 | #undef END_EXTERN_C | |
125 | #undef EXTERN_C | |
126 | #ifdef __cplusplus | |
127 | # define START_EXTERN_C extern "C" { | |
128 | # define END_EXTERN_C } | |
129 | # define EXTERN_C extern "C" | |
130 | #else | |
131 | # define START_EXTERN_C | |
132 | # define END_EXTERN_C | |
133 | # define EXTERN_C extern | |
134 | #endif | |
135 | ||
17a6c8e3 AD |
136 | /* Fallback definitions in case we don't have definitions from config.h. |
137 | This should only matter for systems that don't use Configure and | |
138 | haven't been modified to define PERL_STATIC_INLINE yet. | |
139 | */ | |
140 | #if !defined(PERL_STATIC_INLINE) | |
141 | # ifdef HAS_STATIC_INLINE | |
142 | # define PERL_STATIC_INLINE static inline | |
143 | # else | |
144 | # define PERL_STATIC_INLINE static | |
145 | # endif | |
146 | #endif | |
147 | ||
da5fdda8 | 148 | #if defined(PERL_GLOBAL_STRUCT) && !defined(PERL_GET_VARS) |
27da23d5 | 149 | # ifdef PERL_GLOBAL_STRUCT_PRIVATE |
cf5a8da6 | 150 | EXTERN_C struct perl_vars* Perl_GetVarsPrivate(); |
27da23d5 | 151 | # define PERL_GET_VARS() Perl_GetVarsPrivate() /* see miniperlmain.c */ |
27da23d5 JH |
152 | # else |
153 | # define PERL_GET_VARS() PL_VarsPtr | |
154 | # endif | |
27da23d5 JH |
155 | #endif |
156 | ||
f0e5c859 DD |
157 | /* this used to be off by default, now its on, see perlio.h */ |
158 | #define PERLIO_FUNCS_CONST | |
159 | ||
5aaab254 | 160 | #define pVAR struct perl_vars* my_vars PERL_UNUSED_DECL |
27da23d5 JH |
161 | |
162 | #ifdef PERL_GLOBAL_STRUCT | |
163 | # define dVAR pVAR = (struct perl_vars*)PERL_GET_VARS() | |
164 | #else | |
165 | # define dVAR dNOOP | |
166 | #endif | |
167 | ||
c5be433b | 168 | #ifdef PERL_IMPLICIT_CONTEXT |
3db8f154 MB |
169 | # ifndef MULTIPLICITY |
170 | # define MULTIPLICITY | |
c5be433b | 171 | # endif |
e8dda941 | 172 | # define tTHX PerlInterpreter* |
5aaab254 | 173 | # define pTHX tTHX my_perl PERL_UNUSED_DECL |
3db8f154 | 174 | # define aTHX my_perl |
9399a70c | 175 | # define aTHXa(a) aTHX = (tTHX)a |
27da23d5 | 176 | # ifdef PERL_GLOBAL_STRUCT |
e8dda941 | 177 | # define dTHXa(a) dVAR; pTHX = (tTHX)a |
27da23d5 | 178 | # else |
e8dda941 | 179 | # define dTHXa(a) pTHX = (tTHX)a |
27da23d5 JH |
180 | # endif |
181 | # ifdef PERL_GLOBAL_STRUCT | |
182 | # define dTHX dVAR; pTHX = PERL_GET_THX | |
183 | # else | |
184 | # define dTHX pTHX = PERL_GET_THX | |
185 | # endif | |
c5be433b | 186 | # define pTHX_ pTHX, |
c5be433b | 187 | # define aTHX_ aTHX, |
4373e329 | 188 | # define pTHX_1 2 |
894356b3 GS |
189 | # define pTHX_2 3 |
190 | # define pTHX_3 4 | |
191 | # define pTHX_4 5 | |
4373e329 AL |
192 | # define pTHX_5 6 |
193 | # define pTHX_6 7 | |
a3b680e6 AL |
194 | # define pTHX_7 8 |
195 | # define pTHX_8 9 | |
196 | # define pTHX_9 10 | |
a6fc70e5 | 197 | # define pTHX_12 13 |
e8dda941 JD |
198 | # if defined(DEBUGGING) && !defined(PERL_TRACK_MEMPOOL) |
199 | # define PERL_TRACK_MEMPOOL | |
200 | # endif | |
201 | #else | |
202 | # undef PERL_TRACK_MEMPOOL | |
c5be433b GS |
203 | #endif |
204 | ||
76e3520e | 205 | #define STATIC static |
16c91539 BM |
206 | |
207 | #ifndef PERL_CORE | |
208 | /* Do not use these macros. They were part of PERL_OBJECT, which was an | |
209 | * implementation of multiplicity using C++ objects. They have been left | |
210 | * here solely for the sake of XS code which has incorrectly | |
211 | * cargo-culted them. | |
212 | */ | |
76e3520e | 213 | #define CPERLscope(x) x |
565764a8 | 214 | #define CPERLarg void |
76e3520e | 215 | #define CPERLarg_ |
e3b8966e | 216 | #define _CPERLarg |
1d583055 GS |
217 | #define PERL_OBJECT_THIS |
218 | #define _PERL_OBJECT_THIS | |
219 | #define PERL_OBJECT_THIS_ | |
312caa8e | 220 | #define CALL_FPTR(fptr) (*fptr) |
ef69c8fc | 221 | #define MEMBER_TO_FPTR(name) name |
16c91539 | 222 | #endif /* !PERL_CORE */ |
76e3520e | 223 | |
16c91539 | 224 | #define CALLRUNOPS PL_runops |
f9f4320a | 225 | |
3ab4a224 | 226 | #define CALLREGCOMP(sv, flags) Perl_pregcomp(aTHX_ (sv),(flags)) |
f9f4320a | 227 | |
16c91539 | 228 | #define CALLREGCOMP_ENG(prog, sv, flags) (prog)->comp(aTHX_ sv, flags) |
a340edde | 229 | #define CALLREGEXEC(prog,stringarg,strend,strbeg,minend,sv,data,flags) \ |
16c91539 | 230 | RX_ENGINE(prog)->exec(aTHX_ (prog),(stringarg),(strend), \ |
a340edde | 231 | (strbeg),(minend),(sv),(data),(flags)) |
52a21eb3 DM |
232 | #define CALLREG_INTUIT_START(prog,sv,strbeg,strpos,strend,flags,data) \ |
233 | RX_ENGINE(prog)->intuit(aTHX_ (prog), (sv), (strbeg), (strpos), \ | |
f9f4320a YO |
234 | (strend),(flags),(data)) |
235 | #define CALLREG_INTUIT_STRING(prog) \ | |
16c91539 | 236 | RX_ENGINE(prog)->checkstr(aTHX_ (prog)) |
f8149455 | 237 | |
f8149455 YO |
238 | #define CALLREGFREE(prog) \ |
239 | Perl_pregfree(aTHX_ (prog)) | |
240 | ||
241 | #define CALLREGFREE_PVT(prog) \ | |
fc6bde6f | 242 | if(prog) RX_ENGINE(prog)->rxfree(aTHX_ (prog)) |
f8149455 | 243 | |
2fdbfb4d | 244 | #define CALLREG_NUMBUF_FETCH(rx,paren,usesv) \ |
16c91539 | 245 | RX_ENGINE(rx)->numbered_buff_FETCH(aTHX_ (rx),(paren),(usesv)) |
93b32b6d | 246 | |
2fdbfb4d | 247 | #define CALLREG_NUMBUF_STORE(rx,paren,value) \ |
16c91539 | 248 | RX_ENGINE(rx)->numbered_buff_STORE(aTHX_ (rx),(paren),(value)) |
2fdbfb4d AB |
249 | |
250 | #define CALLREG_NUMBUF_LENGTH(rx,sv,paren) \ | |
16c91539 | 251 | RX_ENGINE(rx)->numbered_buff_LENGTH(aTHX_ (rx),(sv),(paren)) |
2fdbfb4d | 252 | |
192b9cd1 | 253 | #define CALLREG_NAMED_BUFF_FETCH(rx, key, flags) \ |
16c91539 | 254 | RX_ENGINE(rx)->named_buff(aTHX_ (rx), (key), NULL, ((flags) | RXapif_FETCH)) |
192b9cd1 AB |
255 | |
256 | #define CALLREG_NAMED_BUFF_STORE(rx, key, value, flags) \ | |
16c91539 | 257 | RX_ENGINE(rx)->named_buff(aTHX_ (rx), (key), (value), ((flags) | RXapif_STORE)) |
192b9cd1 AB |
258 | |
259 | #define CALLREG_NAMED_BUFF_DELETE(rx, key, flags) \ | |
16c91539 | 260 | RX_ENGINE(rx)->named_buff(aTHX_ (rx),(key), NULL, ((flags) | RXapif_DELETE)) |
192b9cd1 AB |
261 | |
262 | #define CALLREG_NAMED_BUFF_CLEAR(rx, flags) \ | |
16c91539 | 263 | RX_ENGINE(rx)->named_buff(aTHX_ (rx), NULL, NULL, ((flags) | RXapif_CLEAR)) |
192b9cd1 AB |
264 | |
265 | #define CALLREG_NAMED_BUFF_EXISTS(rx, key, flags) \ | |
16c91539 | 266 | RX_ENGINE(rx)->named_buff(aTHX_ (rx), (key), NULL, ((flags) | RXapif_EXISTS)) |
192b9cd1 AB |
267 | |
268 | #define CALLREG_NAMED_BUFF_FIRSTKEY(rx, flags) \ | |
16c91539 | 269 | RX_ENGINE(rx)->named_buff_iter(aTHX_ (rx), NULL, ((flags) | RXapif_FIRSTKEY)) |
192b9cd1 AB |
270 | |
271 | #define CALLREG_NAMED_BUFF_NEXTKEY(rx, lastkey, flags) \ | |
16c91539 | 272 | RX_ENGINE(rx)->named_buff_iter(aTHX_ (rx), (lastkey), ((flags) | RXapif_NEXTKEY)) |
192b9cd1 AB |
273 | |
274 | #define CALLREG_NAMED_BUFF_SCALAR(rx, flags) \ | |
16c91539 | 275 | RX_ENGINE(rx)->named_buff(aTHX_ (rx), NULL, NULL, ((flags) | RXapif_SCALAR)) |
192b9cd1 AB |
276 | |
277 | #define CALLREG_NAMED_BUFF_COUNT(rx) \ | |
16c91539 | 278 | RX_ENGINE(rx)->named_buff(aTHX_ (rx), NULL, NULL, RXapif_REGNAMES_COUNT) |
192b9cd1 AB |
279 | |
280 | #define CALLREG_NAMED_BUFF_ALL(rx, flags) \ | |
16c91539 | 281 | RX_ENGINE(rx)->named_buff(aTHX_ (rx), NULL, NULL, flags) |
93b32b6d | 282 | |
49d7dfbc | 283 | #define CALLREG_PACKAGE(rx) \ |
16c91539 | 284 | RX_ENGINE(rx)->qr_package(aTHX_ (rx)) |
93b32b6d | 285 | |
00f254e2 | 286 | #if defined(USE_ITHREADS) |
f9f4320a | 287 | #define CALLREGDUPE(prog,param) \ |
f8149455 YO |
288 | Perl_re_dup(aTHX_ (prog),(param)) |
289 | ||
290 | #define CALLREGDUPE_PVT(prog,param) \ | |
16c91539 | 291 | (prog ? RX_ENGINE(prog)->dupe(aTHX_ (prog),(param)) \ |
00f254e2 | 292 | : (REGEXP *)NULL) |
f9f4320a | 293 | #endif |
14dd3ad8 | 294 | |
a20207d7 | 295 | |
bcdf7404 | 296 | |
a20207d7 YO |
297 | |
298 | ||
5ba4cab2 SH |
299 | /* |
300 | * Because of backward compatibility reasons the PERL_UNUSED_DECL | |
301 | * cannot be changed from postfix to PERL_UNUSED_DECL(x). Sigh. | |
302 | * | |
303 | * Note that there are C compilers such as MetroWerks CodeWarrior | |
1266ad8c | 304 | * which do not have an "inlined" way (like the gcc __attribute__) of |
5ba4cab2 SH |
305 | * marking unused variables (they need e.g. a #pragma) and therefore |
306 | * cpp macros like PERL_UNUSED_DECL cannot work for this purpose, even | |
307 | * if it were PERL_UNUSED_DECL(x), which it cannot be (see above). | |
308 | * | |
309 | */ | |
1266ad8c | 310 | |
9969cdde | 311 | #if defined(__SYMBIAN32__) && defined(__GNUC__) |
5b2bd0a5 | 312 | # ifdef __cplusplus |
5ba4cab2 | 313 | # define PERL_UNUSED_DECL |
5b2bd0a5 | 314 | # else |
5ba4cab2 | 315 | # define PERL_UNUSED_DECL __attribute__((unused)) |
5b2bd0a5 AMS |
316 | # endif |
317 | #endif | |
44dbb695 | 318 | |
5b2bd0a5 | 319 | #ifndef PERL_UNUSED_DECL |
f7a9299a | 320 | # if defined(HASATTRIBUTE_UNUSED) && (!defined(__cplusplus) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) |
5ba4cab2 | 321 | # define PERL_UNUSED_DECL __attribute__unused__ |
b79c357a | 322 | # else |
5ba4cab2 | 323 | # define PERL_UNUSED_DECL |
b79c357a | 324 | # endif |
5b2bd0a5 | 325 | #endif |
00f254e2 | 326 | |
349b520e DM |
327 | /* gcc -Wall: |
328 | * for silencing unused variables that are actually used most of the time, | |
a730e3f2 JH |
329 | * but we cannot quite get rid of, such as "ax" in PPCODE+noargs xsubs, |
330 | * or variables/arguments that are used only in certain configurations. | |
349b520e | 331 | */ |
53c1dcc0 | 332 | #ifndef PERL_UNUSED_ARG |
c707756e | 333 | # define PERL_UNUSED_ARG(x) ((void)sizeof(x)) |
ad73156c | 334 | #endif |
53c1dcc0 | 335 | #ifndef PERL_UNUSED_VAR |
a730e3f2 | 336 | # define PERL_UNUSED_VAR(x) ((void)sizeof(x)) |
53c1dcc0 | 337 | #endif |
ad73156c | 338 | |
23491f1d | 339 | #if defined(USE_ITHREADS) || defined(PERL_GLOBAL_STRUCT) |
96a5add6 AL |
340 | # define PERL_UNUSED_CONTEXT PERL_UNUSED_ARG(my_perl) |
341 | #else | |
342 | # define PERL_UNUSED_CONTEXT | |
343 | #endif | |
344 | ||
24e7ff4e JH |
345 | /* gcc (-ansi) -pedantic doesn't allow gcc statement expressions, |
346 | * g++ allows them but seems to have problems with them | |
347 | * (insane errors ensue). | |
348 | * g++ does not give insane errors now (RMB 2008-01-30, gcc 4.2.2). | |
349 | */ | |
350 | #if defined(PERL_GCC_PEDANTIC) || \ | |
351 | (defined(__GNUC__) && defined(__cplusplus) && \ | |
352 | ((__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 2)))) | |
353 | # ifndef PERL_GCC_BRACE_GROUPS_FORBIDDEN | |
354 | # define PERL_GCC_BRACE_GROUPS_FORBIDDEN | |
355 | # endif | |
356 | #endif | |
357 | ||
ffea512f | 358 | /* Use PERL_UNUSED_RESULT() to suppress the warnings about unused results |
b469f1e0 JH |
359 | * of function calls, e.g. PERL_UNUSED_RESULT(foo(a, b)). |
360 | * | |
361 | * The main reason for this is that the combination of gcc -Wunused-result | |
362 | * (part of -Wall) and the __attribute__((warn_unused_result)) cannot | |
363 | * be silenced with casting to void. This causes trouble when the system | |
364 | * header files use the attribute. | |
365 | * | |
366 | * Use PERL_UNUSED_RESULT sparingly, though, since usually the warning | |
367 | * is there for a good reason: you might lose success/failure information, | |
368 | * or leak resources, or changes in resources. | |
ffea512f JH |
369 | * |
370 | * But sometimes you just want to ignore the return value, e.g. on | |
b469f1e0 JH |
371 | * codepaths soon ending up in abort, or in "best effort" attempts, |
372 | * or in situations where there is no good way to handle failures. | |
ffea512f | 373 | * |
b469f1e0 JH |
374 | * Sometimes PERL_UNUSED_RESULT might not be the most natural way: |
375 | * another possibility is that you can capture the return value | |
376 | * and use PERL_UNUSED_VAR on that. | |
ffea512f | 377 | * |
b469f1e0 JH |
378 | * The __typeof__() is used instead of typeof() since typeof() is not |
379 | * available under strict C89, and because of compilers masquerading | |
380 | * as gcc (clang and icc), we want exactly the gcc extension | |
381 | * __typeof__ and nothing else. | |
ffea512f JH |
382 | */ |
383 | #ifndef PERL_UNUSED_RESULT | |
b469f1e0 JH |
384 | # if defined(__GNUC__) && defined(HASATTRIBUTE_WARN_UNUSED_RESULT) |
385 | # define PERL_UNUSED_RESULT(v) STMT_START { __typeof__(v) z = (v); (void)sizeof(z); } STMT_END | |
ffea512f JH |
386 | # else |
387 | # define PERL_UNUSED_RESULT(v) ((void)(v)) | |
388 | # endif | |
389 | #endif | |
390 | ||
b56aac20 DM |
391 | /* on gcc (and clang), specify that a warning should be temporarily |
392 | * ignored; e.g. | |
393 | * | |
394 | * GCC_DIAG_IGNORE(-Wmultichar); | |
395 | * char b = 'ab'; | |
396 | * GCC_DIAG_RESTORE; | |
397 | * | |
398 | * based on http://dbp-consulting.com/tutorials/SuppressingGCCWarnings.html | |
399 | * | |
400 | * Note that "pragma GCC diagnostic push/pop" was added in GCC 4.6, Mar 2011; | |
401 | * clang only pretends to be GCC 4.2, but still supports push/pop. | |
c1d6452f JH |
402 | * |
403 | * Note on usage: on non-gcc (or lookalike, like clang) compilers | |
95b872d5 LM |
404 | * one cannot use these with a semicolon at file (global) level without |
405 | * warnings since they are defined as empty, which leads into the terminating | |
c1d6452f JH |
406 | * semicolon being left alone on a line: |
407 | * ; | |
408 | * which makes compilers mildly cranky. Therefore at file level one | |
95b872d5 | 409 | * should use the GCC_DIAG_IGNORE and GCC_DIAG_RESTORE macros *without* |
6ab56f1e | 410 | * the semicolons. |
c1d6452f JH |
411 | * |
412 | * (A dead-on-arrival solution would be to try to define the macros as | |
413 | * NOOP or dNOOP, those don't work both inside functions and outside.) | |
b56aac20 DM |
414 | */ |
415 | ||
57d4b8c5 | 416 | #if defined(__clang__) || defined(__clang) || \ |
d28ce8b4 | 417 | (defined( __GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) |
c1d6452f JH |
418 | # define GCC_DIAG_PRAGMA(x) _Pragma (#x) |
419 | /* clang has "clang diagnostic" pragmas, but also understands gcc. */ | |
b56aac20 | 420 | # define GCC_DIAG_IGNORE(x) _Pragma("GCC diagnostic push") \ |
c1d6452f | 421 | GCC_DIAG_PRAGMA(GCC diagnostic ignored #x) |
b56aac20 DM |
422 | # define GCC_DIAG_RESTORE _Pragma("GCC diagnostic pop") |
423 | #else | |
8ce6f80a JH |
424 | # define GCC_DIAG_IGNORE(w) |
425 | # define GCC_DIAG_RESTORE | |
b56aac20 | 426 | #endif |
337458b1 JH |
427 | /* for clang specific pragmas */ |
428 | #if defined(__clang__) || defined(__clang) | |
429 | # define CLANG_DIAG_PRAGMA(x) _Pragma (#x) | |
430 | # define CLANG_DIAG_IGNORE(x) _Pragma("clang diagnostic push") \ | |
431 | CLANG_DIAG_PRAGMA(clang diagnostic ignored #x) | |
432 | # define CLANG_DIAG_RESTORE _Pragma("clang diagnostic pop") | |
433 | #else | |
434 | # define CLANG_DIAG_IGNORE(w) | |
435 | # define CLANG_DIAG_RESTORE | |
436 | #endif | |
b56aac20 | 437 | |
6f207bd3 | 438 | #define NOOP /*EMPTY*/(void)0 |
bafdc25d NC |
439 | /* cea2e8a9dd23747f accidentally lost the comment originally from the first |
440 | check in of thread.h, explaining why we need dNOOP at all: */ | |
441 | /* Rats: if dTHR is just blank then the subsequent ";" throws an error */ | |
442 | /* Declaring a *function*, instead of a variable, ensures that we don't rely | |
443 | on being able to suppress "unused" warnings. */ | |
7db66e12 CB |
444 | #ifdef __cplusplus |
445 | #define dNOOP (void)0 | |
446 | #else | |
64a8239e | 447 | #define dNOOP extern int Perl___notused(void) |
7db66e12 | 448 | #endif |
71be2cbc | 449 | |
0cb96387 | 450 | #ifndef pTHX |
a78adc84 | 451 | /* Don't bother defining tTHX ; using it outside |
e8dda941 JD |
452 | * code guarded by PERL_IMPLICIT_CONTEXT is an error. |
453 | */ | |
0cb96387 GS |
454 | # define pTHX void |
455 | # define pTHX_ | |
0cb96387 GS |
456 | # define aTHX |
457 | # define aTHX_ | |
9399a70c | 458 | # define aTHXa(a) NOOP |
0cb96387 GS |
459 | # define dTHXa(a) dNOOP |
460 | # define dTHX dNOOP | |
894356b3 GS |
461 | # define pTHX_1 1 |
462 | # define pTHX_2 2 | |
463 | # define pTHX_3 3 | |
464 | # define pTHX_4 4 | |
3d42dc86 RGS |
465 | # define pTHX_5 5 |
466 | # define pTHX_6 6 | |
a3b680e6 AL |
467 | # define pTHX_7 7 |
468 | # define pTHX_8 8 | |
469 | # define pTHX_9 9 | |
a6fc70e5 | 470 | # define pTHX_12 12 |
0cb96387 GS |
471 | #endif |
472 | ||
27da23d5 JH |
473 | #ifndef dVAR |
474 | # define dVAR dNOOP | |
475 | #endif | |
476 | ||
b4f7f263 GS |
477 | /* these are only defined for compatibility; should not be used internally */ |
478 | #if !defined(pTHXo) && !defined(PERL_CORE) | |
0cb96387 GS |
479 | # define pTHXo pTHX |
480 | # define pTHXo_ pTHX_ | |
0cb96387 GS |
481 | # define aTHXo aTHX |
482 | # define aTHXo_ aTHX_ | |
c5be433b | 483 | # define dTHXo dTHX |
71d280e3 | 484 | # define dTHXoa(x) dTHXa(x) |
0cb96387 GS |
485 | #endif |
486 | ||
487 | #ifndef pTHXx | |
5aaab254 | 488 | # define pTHXx PerlInterpreter *my_perl |
0cb96387 | 489 | # define pTHXx_ pTHXx, |
0cb96387 GS |
490 | # define aTHXx my_perl |
491 | # define aTHXx_ aTHXx, | |
c5be433b | 492 | # define dTHXx dTHX |
22c35a8c | 493 | #endif |
71be2cbc | 494 | |
1de7c2ac GS |
495 | /* Under PERL_IMPLICIT_SYS (used in Windows for fork emulation) |
496 | * PerlIO_foo() expands to PL_StdIO->pFOO(PL_StdIO, ...). | |
497 | * dTHXs is therefore needed for all functions using PerlIO_foo(). */ | |
498 | #ifdef PERL_IMPLICIT_SYS | |
27da23d5 JH |
499 | # ifdef PERL_GLOBAL_STRUCT_PRIVATE |
500 | # define dTHXs dVAR; dTHX | |
501 | # else | |
502 | # define dTHXs dTHX | |
503 | # endif | |
1de7c2ac | 504 | #else |
27da23d5 JH |
505 | # ifdef PERL_GLOBAL_STRUCT_PRIVATE |
506 | # define dTHXs dVAR | |
507 | # else | |
508 | # define dTHXs dNOOP | |
509 | # endif | |
1de7c2ac GS |
510 | #endif |
511 | ||
5b692037 JH |
512 | #if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) && !defined(__cplusplus) |
513 | # ifndef PERL_USE_GCC_BRACE_GROUPS | |
514 | # define PERL_USE_GCC_BRACE_GROUPS | |
515 | # endif | |
516 | #endif | |
517 | ||
728e2803 | 518 | /* |
519 | * STMT_START { statements; } STMT_END; | |
520 | * can be used as a single statement, as in | |
521 | * if (x) STMT_START { ... } STMT_END; else ... | |
522 | * | |
523 | * Trying to select a version that gives no warnings... | |
524 | */ | |
525 | #if !(defined(STMT_START) && defined(STMT_END)) | |
5b692037 | 526 | # ifdef PERL_USE_GCC_BRACE_GROUPS |
a0288114 | 527 | # define STMT_START (void)( /* gcc supports "({ STATEMENTS; })" */ |
728e2803 | 528 | # define STMT_END ) |
529 | # else | |
728e2803 | 530 | # define STMT_START do |
531 | # define STMT_END while (0) | |
728e2803 | 532 | # endif |
533 | #endif | |
534 | ||
d6f9c181 JH |
535 | #ifndef BYTEORDER /* Should never happen -- byteorder is in config.h */ |
536 | # define BYTEORDER 0x1234 | |
79072805 LW |
537 | #endif |
538 | ||
539 | /* Overall memory policy? */ | |
540 | #ifndef CONSERVATIVE | |
541 | # define LIBERAL 1 | |
542 | #endif | |
543 | ||
8ada0baa JH |
544 | #if 'A' == 65 && 'I' == 73 && 'J' == 74 && 'Z' == 90 |
545 | #define ASCIIish | |
546 | #else | |
547 | #undef ASCIIish | |
548 | #endif | |
549 | ||
79072805 LW |
550 | /* |
551 | * The following contortions are brought to you on behalf of all the | |
552 | * standards, semi-standards, de facto standards, not-so-de-facto standards | |
553 | * of the world, as well as all the other botches anyone ever thought of. | |
554 | * The basic theory is that if we work hard enough here, the rest of the | |
555 | * code can be a lot prettier. Well, so much for theory. Sorry, Henry... | |
556 | */ | |
ac58e20f | 557 | |
ee0007ab | 558 | /* define this once if either system, instead of cluttering up the src */ |
7c458fae | 559 | #if defined(MSDOS) || defined(WIN32) || defined(NETWARE) |
ee0007ab LW |
560 | #define DOSISH 1 |
561 | #endif | |
562 | ||
3d97541c | 563 | /* These exist only for back-compat with XS modules. */ |
8162b70e | 564 | #ifndef PERL_CORE |
516e10a9 | 565 | #define VOL volatile |
3d97541c | 566 | #define CAN_PROTOTYPE |
ae75e3d0 | 567 | #define _(args) args |
36a113ce | 568 | #define I_STDARG |
8162b70e | 569 | #endif |
663a0e37 | 570 | |
284167a5 S |
571 | /* By compiling a perl with -DNO_TAINT_SUPPORT or -DSILENT_NO_TAINT_SUPPORT, |
572 | * you get a perl without taint support, but doubtlessly with a lesser | |
573 | * degree of support. Do not do so unless you know exactly what it means | |
574 | * technically, have a good reason to do so, and know exactly how the | |
575 | * perl will be used. perls with -DSILENT_NO_TAINT_SUPPORT are considered | |
576 | * a potential security risk due to flat out ignoring the security-relevant | |
577 | * taint flags. This being said, a perl without taint support compiled in | |
578 | * has marginal run-time performance benefits. | |
579 | * SILENT_NO_TAINT_SUPPORT implies NO_TAINT_SUPPORT. | |
580 | * SILENT_NO_TAINT_SUPPORT is the same as NO_TAINT_SUPPORT except it | |
581 | * silently ignores -t/-T instead of throwing an exception. | |
053a3618 S |
582 | * |
583 | * DANGER! Using NO_TAINT_SUPPORT or SILENT_NO_TAINT_SUPPORT | |
6ecb40c7 | 584 | * voids your nonexistent warranty! |
284167a5 | 585 | */ |
dc6d7f5c | 586 | #if defined(SILENT_NO_TAINT_SUPPORT) && !defined(NO_TAINT_SUPPORT) |
284167a5 S |
587 | # define NO_TAINT_SUPPORT 1 |
588 | #endif | |
589 | ||
590 | /* NO_TAINT_SUPPORT can be set to transform virtually all taint-related | |
591 | * operations into no-ops for a very modest speed-up. Enable only if you | |
592 | * know what you're doing: tests and CPAN modules' tests are bound to fail. | |
593 | */ | |
dc6d7f5c | 594 | #ifdef NO_TAINT_SUPPORT |
284167a5 S |
595 | # define TAINT NOOP |
596 | # define TAINT_NOT NOOP | |
597 | # define TAINT_IF(c) NOOP | |
598 | # define TAINT_ENV() NOOP | |
599 | # define TAINT_PROPER(s) NOOP | |
600 | # define TAINT_set(s) NOOP | |
601 | # define TAINT_get 0 | |
602 | # define TAINTING_get 0 | |
603 | # define TAINTING_set(s) NOOP | |
604 | # define TAINT_WARN_get 0 | |
605 | # define TAINT_WARN_set(s) NOOP | |
606 | #else | |
d48c660d | 607 | # define TAINT (PL_tainted = PL_tainting) |
284167a5 | 608 | # define TAINT_NOT (PL_tainted = FALSE) |
d48c660d | 609 | # define TAINT_IF(c) if (UNLIKELY(c)) { PL_tainted = PL_tainting; } |
2439e033 S |
610 | # define TAINT_ENV() if (UNLIKELY(PL_tainting)) { taint_env(); } |
611 | # define TAINT_PROPER(s) if (UNLIKELY(PL_tainting)) { taint_proper(NULL, s); } | |
284167a5 S |
612 | # define TAINT_set(s) (PL_tainted = (s)) |
613 | # define TAINT_get (PL_tainted) | |
614 | # define TAINTING_get (PL_tainting) | |
615 | # define TAINTING_set(s) (PL_tainting = (s)) | |
616 | # define TAINT_WARN_get (PL_taint_warn) | |
617 | # define TAINT_WARN_set(s) (PL_taint_warn = (s)) | |
618 | #endif | |
a687059c | 619 | |
20be6587 DM |
620 | /* flags used internally only within pp_subst and pp_substcont */ |
621 | #ifdef PERL_CORE | |
622 | # define SUBST_TAINT_STR 1 /* string tainted */ | |
623 | # define SUBST_TAINT_PAT 2 /* pattern tainted */ | |
624 | # define SUBST_TAINT_REPL 4 /* replacement tainted */ | |
625 | # define SUBST_TAINT_RETAINT 8 /* use re'taint' in scope */ | |
626 | # define SUBST_TAINT_BOOLRET 16 /* return is boolean (don't taint) */ | |
627 | #endif | |
628 | ||
d460ef45 | 629 | /* XXX All process group stuff is handled in pp_sys.c. Should these |
a6e633de | 630 | defines move there? If so, I could simplify this a lot. --AD 9/96. |
631 | */ | |
632 | /* Process group stuff changed from traditional BSD to POSIX. | |
633 | perlfunc.pod documents the traditional BSD-style syntax, so we'll | |
634 | try to preserve that, if possible. | |
635 | */ | |
636 | #ifdef HAS_SETPGID | |
637 | # define BSD_SETPGRP(pid, pgrp) setpgid((pid), (pgrp)) | |
da5fdda8 AC |
638 | #elif defined(HAS_SETPGRP) && defined(USE_BSD_SETPGRP) |
639 | # define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp)) | |
640 | #elif defined(HAS_SETPGRP2) | |
641 | # define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp)) | |
a6e633de | 642 | #endif |
643 | #if defined(BSD_SETPGRP) && !defined(HAS_SETPGRP) | |
644 | # define HAS_SETPGRP /* Well, effectively it does . . . */ | |
645 | #endif | |
646 | ||
647 | /* getpgid isn't POSIX, but at least Solaris and Linux have it, and it makes | |
648 | our life easier :-) so we'll try it. | |
649 | */ | |
650 | #ifdef HAS_GETPGID | |
651 | # define BSD_GETPGRP(pid) getpgid((pid)) | |
da5fdda8 AC |
652 | #elif defined(HAS_GETPGRP) && defined(USE_BSD_GETPGRP) |
653 | # define BSD_GETPGRP(pid) getpgrp((pid)) | |
654 | #elif defined(HAS_GETPGRP2) | |
655 | # define BSD_GETPGRP(pid) getpgrp2((pid)) | |
a6e633de | 656 | #endif |
657 | #if defined(BSD_GETPGRP) && !defined(HAS_GETPGRP) | |
658 | # define HAS_GETPGRP /* Well, effectively it does . . . */ | |
659 | #endif | |
660 | ||
d460ef45 | 661 | /* These are not exact synonyms, since setpgrp() and getpgrp() may |
a6e633de | 662 | have different behaviors, but perl.h used to define USE_BSDPGRP |
663 | (prior to 5.003_05) so some extension might depend on it. | |
664 | */ | |
665 | #if defined(USE_BSD_SETPGRP) || defined(USE_BSD_GETPGRP) | |
666 | # ifndef USE_BSDPGRP | |
667 | # define USE_BSDPGRP | |
668 | # endif | |
663a0e37 LW |
669 | #endif |
670 | ||
486ec47a | 671 | /* HP-UX 10.X CMA (Common Multithreaded Architecture) insists that |
8ac5a1fe MH |
672 | pthread.h must be included before all other header files. |
673 | */ | |
3db8f154 | 674 | #if defined(USE_ITHREADS) && defined(PTHREAD_H_FIRST) && defined(I_PTHREAD) |
8ac5a1fe MH |
675 | # include <pthread.h> |
676 | #endif | |
677 | ||
58ab9e8b | 678 | #include <sys/types.h> |
663a0e37 | 679 | |
c7925a5e DD |
680 | /* EVC 4 SDK headers includes a bad definition of MB_CUR_MAX in stdlib.h |
681 | which is included from stdarg.h. Bad definition not present in SD 2008 | |
682 | SDK headers. wince.h is not yet included, so we cant fix this from there | |
683 | since by then MB_CUR_MAX will be defined from stdlib.h. | |
684 | cewchar.h includes a correct definition of MB_CUR_MAX and it is copied here | |
685 | since cewchar.h can't be included this early */ | |
686 | #if defined(UNDER_CE) && (_MSC_VER < 1300) | |
687 | # define MB_CUR_MAX 1 | |
688 | #endif | |
9d82a2b7 AC |
689 | |
690 | # include <stdarg.h> | |
760ac839 | 691 | |
27db2737 JH |
692 | #ifdef I_STDINT |
693 | # include <stdint.h> | |
694 | #endif | |
695 | ||
fe14fcc3 | 696 | #include <ctype.h> |
63b481b9 AC |
697 | #include <float.h> |
698 | #include <limits.h> | |
a0d0e21e LW |
699 | |
700 | #ifdef METHOD /* Defined by OSF/1 v3.0 by ctype.h */ | |
701 | #undef METHOD | |
a0d0e21e LW |
702 | #endif |
703 | ||
12ae5dfc JH |
704 | #ifdef PERL_MICRO |
705 | # define NO_LOCALE | |
706 | #endif | |
707 | ||
4633a7c4 | 708 | #ifdef I_LOCALE |
36477c24 | 709 | # include <locale.h> |
4633a7c4 LW |
710 | #endif |
711 | ||
6ebbc862 KW |
712 | #ifdef I_XLOCALE |
713 | # include <xlocale.h> | |
714 | #endif | |
715 | ||
36477c24 | 716 | #if !defined(NO_LOCALE) && defined(HAS_SETLOCALE) |
717 | # define USE_LOCALE | |
ccd65d51 KW |
718 | # define HAS_SKIP_LOCALE_INIT /* Solely for XS code to test for this |
719 | capability */ | |
36477c24 | 720 | # if !defined(NO_LOCALE_COLLATE) && defined(LC_COLLATE) \ |
721 | && defined(HAS_STRXFRM) | |
722 | # define USE_LOCALE_COLLATE | |
723 | # endif | |
724 | # if !defined(NO_LOCALE_CTYPE) && defined(LC_CTYPE) | |
725 | # define USE_LOCALE_CTYPE | |
726 | # endif | |
727 | # if !defined(NO_LOCALE_NUMERIC) && defined(LC_NUMERIC) | |
728 | # define USE_LOCALE_NUMERIC | |
729 | # endif | |
fa9b773e KW |
730 | # if !defined(NO_LOCALE_MESSAGES) && defined(LC_MESSAGES) |
731 | # define USE_LOCALE_MESSAGES | |
732 | # endif | |
733 | # if !defined(NO_LOCALE_MONETARY) && defined(LC_MONETARY) | |
734 | # define USE_LOCALE_MONETARY | |
735 | # endif | |
56e45410 KW |
736 | # if !defined(NO_LOCALE_TIME) && defined(LC_TIME) |
737 | # define USE_LOCALE_TIME | |
738 | # endif | |
36477c24 | 739 | #endif /* !NO_LOCALE && HAS_SETLOCALE */ |
a0d0e21e | 740 | |
fe14fcc3 | 741 | #include <setjmp.h> |
79072805 | 742 | |
a0d0e21e | 743 | #ifdef I_SYS_PARAM |
79072805 LW |
744 | # ifdef PARAM_NEEDS_TYPES |
745 | # include <sys/types.h> | |
746 | # endif | |
747 | # include <sys/param.h> | |
352d5a3a | 748 | #endif |
79072805 | 749 | |
ce3470dc AD |
750 | /* On BSD-derived systems, <sys/param.h> defines BSD to a year-month |
751 | value something like 199306. This may be useful if no more-specific | |
752 | feature test is available. | |
753 | */ | |
754 | #if defined(BSD) | |
755 | # ifndef BSDish | |
756 | # define BSDish | |
757 | # endif | |
758 | #endif | |
759 | ||
dd512de3 AC |
760 | /* Use all the "standard" definitions */ |
761 | #include <stdlib.h> | |
03a14243 | 762 | |
3f270f98 JH |
763 | /* If this causes problems, set i_unistd=undef in the hint file. */ |
764 | #ifdef I_UNISTD | |
763ee752 AB |
765 | # if defined(__amigaos4__) |
766 | # ifdef I_NETINET_IN | |
767 | # include <netinet/in.h> | |
768 | # endif | |
769 | # endif | |
3f270f98 | 770 | # include <unistd.h> |
6e3136a6 AB |
771 | # if defined(__amigaos4__) |
772 | /* Under AmigaOS 4 newlib.library provides an environ. However using | |
773 | * it doesn't give us enough control over inheritance of variables by | |
774 | * subshells etc. so replace with custom version based on abc-shell | |
775 | * code. */ | |
776 | extern char **myenviron; | |
777 | # undef environ | |
778 | # define environ myenviron | |
779 | # endif | |
3f270f98 JH |
780 | #endif |
781 | ||
de8ca8af NT |
782 | /* for WCOREDUMP */ |
783 | #ifdef I_SYS_WAIT | |
784 | # include <sys/wait.h> | |
785 | #endif | |
786 | ||
9969cdde | 787 | #ifdef __SYMBIAN32__ |
27da23d5 JH |
788 | # undef _SC_ARG_MAX /* Symbian has _SC_ARG_MAX but no sysconf() */ |
789 | #endif | |
790 | ||
21e89b5f | 791 | #if defined(HAS_SYSCALL) && !defined(HAS_SYSCALL_PROTO) |
c45598c5 | 792 | EXTERN_C int syscall(int, ...); |
2ef53570 JH |
793 | #endif |
794 | ||
21e89b5f | 795 | #if defined(HAS_USLEEP) && !defined(HAS_USLEEP_PROTO) |
c45598c5 | 796 | EXTERN_C int usleep(unsigned int); |
2ef53570 JH |
797 | #endif |
798 | ||
1109a392 MHM |
799 | #ifdef PERL_CORE |
800 | ||
801 | /* macros for correct constant construction */ | |
802 | # if INTSIZE >= 2 | |
803 | # define U16_CONST(x) ((U16)x##U) | |
804 | # else | |
805 | # define U16_CONST(x) ((U16)x##UL) | |
806 | # endif | |
807 | ||
808 | # if INTSIZE >= 4 | |
809 | # define U32_CONST(x) ((U32)x##U) | |
810 | # else | |
811 | # define U32_CONST(x) ((U32)x##UL) | |
812 | # endif | |
813 | ||
814 | # ifdef HAS_QUAD | |
815 | # if INTSIZE >= 8 | |
816 | # define U64_CONST(x) ((U64)x##U) | |
817 | # elif LONGSIZE >= 8 | |
818 | # define U64_CONST(x) ((U64)x##UL) | |
819 | # elif QUADKIND == QUAD_IS_LONG_LONG | |
820 | # define U64_CONST(x) ((U64)x##ULL) | |
52865553 SH |
821 | # elif QUADKIND == QUAD_IS___INT64 |
822 | # define U64_CONST(x) ((U64)x##UI64) | |
1109a392 MHM |
823 | # else /* best guess we can make */ |
824 | # define U64_CONST(x) ((U64)x##UL) | |
825 | # endif | |
826 | # endif | |
827 | ||
828 | /* byte-swapping functions for big-/little-endian conversion */ | |
829 | # define _swab_16_(x) ((U16)( \ | |
830 | (((U16)(x) & U16_CONST(0x00ff)) << 8) | \ | |
831 | (((U16)(x) & U16_CONST(0xff00)) >> 8) )) | |
832 | ||
833 | # define _swab_32_(x) ((U32)( \ | |
834 | (((U32)(x) & U32_CONST(0x000000ff)) << 24) | \ | |
835 | (((U32)(x) & U32_CONST(0x0000ff00)) << 8) | \ | |
836 | (((U32)(x) & U32_CONST(0x00ff0000)) >> 8) | \ | |
837 | (((U32)(x) & U32_CONST(0xff000000)) >> 24) )) | |
838 | ||
839 | # ifdef HAS_QUAD | |
840 | # define _swab_64_(x) ((U64)( \ | |
841 | (((U64)(x) & U64_CONST(0x00000000000000ff)) << 56) | \ | |
842 | (((U64)(x) & U64_CONST(0x000000000000ff00)) << 40) | \ | |
843 | (((U64)(x) & U64_CONST(0x0000000000ff0000)) << 24) | \ | |
844 | (((U64)(x) & U64_CONST(0x00000000ff000000)) << 8) | \ | |
845 | (((U64)(x) & U64_CONST(0x000000ff00000000)) >> 8) | \ | |
846 | (((U64)(x) & U64_CONST(0x0000ff0000000000)) >> 24) | \ | |
847 | (((U64)(x) & U64_CONST(0x00ff000000000000)) >> 40) | \ | |
848 | (((U64)(x) & U64_CONST(0xff00000000000000)) >> 56) )) | |
849 | # endif | |
850 | ||
9c17f24a NC |
851 | /* The old value was hard coded at 1008. (4096-16) seems to be a bit faster, |
852 | at least on FreeBSD. YMMV, so experiment. */ | |
853 | #ifndef PERL_ARENA_SIZE | |
854 | #define PERL_ARENA_SIZE 4080 | |
855 | #endif | |
856 | ||
ccb2c8b8 | 857 | /* Maximum level of recursion */ |
2b9dff67 RGS |
858 | #ifndef PERL_SUB_DEPTH_WARN |
859 | #define PERL_SUB_DEPTH_WARN 100 | |
ccb2c8b8 RGS |
860 | #endif |
861 | ||
1109a392 MHM |
862 | #endif /* PERL_CORE */ |
863 | ||
bdf3085f NC |
864 | /* We no longer default to creating a new SV for GvSV. |
865 | Do this before embed. */ | |
866 | #ifndef PERL_CREATE_GVSV | |
7459f06b NC |
867 | # ifndef PERL_DONT_CREATE_GVSV |
868 | # define PERL_DONT_CREATE_GVSV | |
869 | # endif | |
bdf3085f NC |
870 | #endif |
871 | ||
ca0c25f6 NC |
872 | #if !defined(HAS_WAITPID) && !defined(HAS_WAIT4) || defined(HAS_WAITPID_RUNTIME) |
873 | #define PERL_USES_PL_PIDSTATUS | |
874 | #endif | |
875 | ||
739a0b84 | 876 | #if !defined(OS2) && !defined(WIN32) && !defined(DJGPP) && !defined(__SYMBIAN32__) |
a62746fa RGS |
877 | #define PERL_DEFAULT_DO_EXEC3_IMPLEMENTATION |
878 | #endif | |
879 | ||
c31fac66 GS |
880 | #define MEM_SIZE Size_t |
881 | ||
1936d2a7 NC |
882 | /* Round all values passed to malloc up, by default to a multiple of |
883 | sizeof(size_t) | |
884 | */ | |
885 | #ifndef PERL_STRLEN_ROUNDUP_QUANTUM | |
886 | #define PERL_STRLEN_ROUNDUP_QUANTUM Size_t_size | |
887 | #endif | |
888 | ||
f1200559 WH |
889 | /* sv_grow() will expand strings by at least a certain percentage of |
890 | the previously *used* length to avoid excessive calls to realloc(). | |
891 | The default is 25% of the current length. | |
892 | */ | |
893 | #ifndef PERL_STRLEN_EXPAND_SHIFT | |
894 | # define PERL_STRLEN_EXPAND_SHIFT 2 | |
895 | #endif | |
896 | ||
346712be AC |
897 | #include <stddef.h> |
898 | #define STRUCT_OFFSET(s,m) offsetof(s,m) | |
d0b86e2f BF |
899 | |
900 | /* ptrdiff_t is C11, so undef it under pedantic builds */ | |
901 | #ifdef PERL_GCC_PEDANTIC | |
902 | # undef HAS_PTRDIFF_T | |
51371543 GS |
903 | #endif |
904 | ||
9969cdde | 905 | #ifndef __SYMBIAN32__ |
d54fbe84 | 906 | # include <string.h> |
51371543 GS |
907 | #endif |
908 | ||
55497cff | 909 | /* This comes after <stdlib.h> so we don't try to change the standard |
910 | * library prototypes; we'll use our own in proto.h instead. */ | |
03a14243 | 911 | |
4633a7c4 | 912 | #ifdef MYMALLOC |
86058a2d | 913 | # ifdef PERL_POLLUTE_MALLOC |
ee13e175 | 914 | # ifndef PERL_EXTMALLOC_DEF |
86058a2d GS |
915 | # define Perl_malloc malloc |
916 | # define Perl_calloc calloc | |
917 | # define Perl_realloc realloc | |
918 | # define Perl_mfree free | |
ee13e175 | 919 | # endif |
86058a2d GS |
920 | # else |
921 | # define EMBEDMYMALLOC /* for compatibility */ | |
922 | # endif | |
827e134a | 923 | |
651b9576 GS |
924 | # define safemalloc Perl_malloc |
925 | # define safecalloc Perl_calloc | |
926 | # define saferealloc Perl_realloc | |
927 | # define safefree Perl_mfree | |
22f7c9c9 JH |
928 | # define CHECK_MALLOC_TOO_LATE_FOR_(code) STMT_START { \ |
929 | if (!PL_tainting && MallocCfg_ptr[MallocCfg_cfg_env_read]) \ | |
930 | code; \ | |
931 | } STMT_END | |
932 | # define CHECK_MALLOC_TOO_LATE_FOR(ch) \ | |
933 | CHECK_MALLOC_TOO_LATE_FOR_(MALLOC_TOO_LATE_FOR(ch)) | |
934 | # define panic_write2(s) write(2, s, strlen(s)) | |
935 | # define CHECK_MALLOC_TAINT(newval) \ | |
936 | CHECK_MALLOC_TOO_LATE_FOR_( \ | |
937 | if (newval) { \ | |
acfd4d8e | 938 | PERL_UNUSED_RESULT(panic_write2("panic: tainting with $ENV{PERL_MALLOC_OPT}\n"));\ |
22f7c9c9 | 939 | exit(1); }) |
22f7c9c9 | 940 | # define MALLOC_CHECK_TAINT(argc,argv,env) STMT_START { \ |
b0891165 | 941 | if (doing_taint(argc,argv,env)) { \ |
22f7c9c9 JH |
942 | MallocCfg_ptr[MallocCfg_skip_cfg_env] = 1; \ |
943 | }} STMT_END; | |
f2517201 GS |
944 | #else /* MYMALLOC */ |
945 | # define safemalloc safesysmalloc | |
946 | # define safecalloc safesyscalloc | |
947 | # define saferealloc safesysrealloc | |
948 | # define safefree safesysfree | |
22f7c9c9 JH |
949 | # define CHECK_MALLOC_TOO_LATE_FOR(ch) ((void)0) |
950 | # define CHECK_MALLOC_TAINT(newval) ((void)0) | |
951 | # define MALLOC_CHECK_TAINT(argc,argv,env) | |
55497cff | 952 | #endif /* MYMALLOC */ |
4633a7c4 | 953 | |
fe13d51d | 954 | /* diag_listed_as: "-T" is on the #! line, it must also be used on the command line */ |
27da23d5 | 955 | #define TOO_LATE_FOR_(ch,what) Perl_croak(aTHX_ "\"-%c\" is on the #! line, it must also be used on the command line%s", (char)(ch), what) |
22f7c9c9 JH |
956 | #define TOO_LATE_FOR(ch) TOO_LATE_FOR_(ch, "") |
957 | #define MALLOC_TOO_LATE_FOR(ch) TOO_LATE_FOR_(ch, " with $ENV{PERL_MALLOC_OPT}") | |
958 | #define MALLOC_CHECK_TAINT2(argc,argv) MALLOC_CHECK_TAINT(argc,argv,NULL) | |
959 | ||
fc36a67e | 960 | #ifndef memzero |
04322328 | 961 | # define memzero(d,l) memset(d,0,l) |
d9d8d8de | 962 | #endif |
378cc40b | 963 | |
ae986130 | 964 | #ifdef I_NETINET_IN |
79072805 | 965 | # include <netinet/in.h> |
ae986130 LW |
966 | #endif |
967 | ||
28e8609d JH |
968 | #ifdef I_ARPA_INET |
969 | # include <arpa/inet.h> | |
970 | #endif | |
971 | ||
1aef975c | 972 | #ifdef I_SYS_STAT |
84902520 | 973 | # include <sys/stat.h> |
1aef975c | 974 | #endif |
79072805 | 975 | |
287a962e JD |
976 | /* Microsoft VC's sys/stat.h defines all S_Ixxx macros except S_IFIFO. |
977 | This definition should ideally go into win32/win32.h, but S_IFIFO is | |
978 | used later here in perl.h before win32/win32.h is being included. */ | |
979 | #if !defined(S_IFIFO) && defined(_S_IFIFO) | |
980 | # define S_IFIFO _S_IFIFO | |
981 | #endif | |
982 | ||
cc3315ba | 983 | /* The stat macros for Unisoft System V/88 (and derivatives |
a0d0e21e LW |
984 | like UTekV) are broken, sometimes giving false positives. Undefine |
985 | them here and let the code below set them to proper values. | |
986 | ||
987 | The ghs macro stands for GreenHills Software C-1.8.5 which | |
988 | is the C compiler for sysV88 and the various derivatives. | |
989 | This header file bug is corrected in gcc-2.5.8 and later versions. | |
990 | --Kaveh Ghazi (ghazi@noc.rutgers.edu) 10/3/94. */ | |
991 | ||
cc3315ba | 992 | #if defined(m88k) && defined(ghs) |
79072805 LW |
993 | # undef S_ISDIR |
994 | # undef S_ISCHR | |
995 | # undef S_ISBLK | |
996 | # undef S_ISREG | |
997 | # undef S_ISFIFO | |
998 | # undef S_ISLNK | |
ee0007ab | 999 | #endif |
135863df | 1000 | |
9245da2a | 1001 | #include <time.h> |
663a0e37 | 1002 | |
fe14fcc3 | 1003 | #ifdef I_SYS_TIME |
85e6fe83 | 1004 | # ifdef I_SYS_TIME_KERNEL |
663a0e37 LW |
1005 | # define KERNEL |
1006 | # endif | |
1007 | # include <sys/time.h> | |
85e6fe83 | 1008 | # ifdef I_SYS_TIME_KERNEL |
663a0e37 LW |
1009 | # undef KERNEL |
1010 | # endif | |
a687059c | 1011 | #endif |
135863df | 1012 | |
55497cff | 1013 | #if defined(HAS_TIMES) && defined(I_SYS_TIMES) |
85e6fe83 | 1014 | # include <sys/times.h> |
d9d8d8de | 1015 | #endif |
8d063cd8 | 1016 | |
663a0e37 | 1017 | #include <errno.h> |
1e743fda | 1018 | |
acfe0abc | 1019 | #if defined(WIN32) && defined(PERL_IMPLICIT_SYS) |
b4748376 NIS |
1020 | # define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */ |
1021 | #endif | |
1022 | ||
da70cfc6 | 1023 | #if defined(HAS_SOCKET) && !defined(WIN32) /* WIN32 handles sockets via win32.h */ |
1e743fda JH |
1024 | # include <sys/socket.h> |
1025 | # if defined(USE_SOCKS) && defined(I_SOCKS) | |
1026 | # if !defined(INCLUDE_PROTOTYPES) | |
1027 | # define INCLUDE_PROTOTYPES /* for <socks.h> */ | |
1028 | # define PERL_SOCKS_NEED_PROTOTYPES | |
1029 | # endif | |
1030 | # include <socks.h> | |
1031 | # ifdef PERL_SOCKS_NEED_PROTOTYPES /* keep cpp space clean */ | |
1032 | # undef INCLUDE_PROTOTYPES | |
1033 | # undef PERL_SOCKS_NEED_PROTOTYPES | |
ed6116ce | 1034 | # endif |
d460ef45 | 1035 | # endif |
1e743fda | 1036 | # ifdef I_NETDB |
2986a63f JH |
1037 | # ifdef NETWARE |
1038 | # include<stdio.h> | |
1039 | # endif | |
1e743fda JH |
1040 | # include <netdb.h> |
1041 | # endif | |
1042 | # ifndef ENOTSOCK | |
1043 | # ifdef I_NET_ERRNO | |
1044 | # include <net/errno.h> | |
1045 | # endif | |
1046 | # endif | |
1047 | #endif | |
1048 | ||
fa0a29af | 1049 | /* sockatmark() is so new (2001) that many places might have it hidden |
29820b6d MHM |
1050 | * behind some -D_BLAH_BLAH_SOURCE guard. The __THROW magic is required |
1051 | * e.g. in Gentoo, see http://bugs.gentoo.org/show_bug.cgi?id=12605 */ | |
fa0a29af | 1052 | #if defined(HAS_SOCKATMARK) && !defined(HAS_SOCKATMARK_PROTO) |
29820b6d MHM |
1053 | # if defined(__THROW) && defined(__GLIBC__) |
1054 | int sockatmark(int) __THROW; | |
1055 | # else | |
2ef53570 | 1056 | int sockatmark(int); |
29820b6d | 1057 | # endif |
2ef53570 JH |
1058 | #endif |
1059 | ||
7e827271 | 1060 | #if defined(__osf__) && defined(__cplusplus) && !defined(_XOPEN_SOURCE_EXTENDED) /* Tru64 "cxx" (C++), see hints/dec_osf.sh for why the _XOPEN_SOURCE_EXTENDED cannot be defined. */ |
45d3b546 JH |
1061 | EXTERN_C int fchdir(int); |
1062 | EXTERN_C int flock(int, int); | |
1063 | EXTERN_C int fseeko(FILE *, off_t, int); | |
1064 | EXTERN_C off_t ftello(FILE *); | |
1065 | #endif | |
1066 | ||
7e827271 | 1067 | #if defined(__SUNPRO_CC) /* SUNWspro CC (C++) */ |
1ccb7c8d JH |
1068 | EXTERN_C char *crypt(const char *, const char *); |
1069 | #endif | |
1070 | ||
a54aca4b | 1071 | #if defined(__cplusplus) && defined(__CYGWIN__) |
667e2948 SP |
1072 | EXTERN_C char *crypt(const char *, const char *); |
1073 | #endif | |
1074 | ||
1e743fda JH |
1075 | #ifdef SETERRNO |
1076 | # undef SETERRNO /* SOCKS might have defined this */ | |
ed6116ce | 1077 | #endif |
f86702cc | 1078 | |
1079 | #ifdef VMS | |
1080 | # define SETERRNO(errcode,vmserrcode) \ | |
1081 | STMT_START { \ | |
1082 | set_errno(errcode); \ | |
1083 | set_vaxc_errno(vmserrcode); \ | |
1084 | } STMT_END | |
4ee39169 CS |
1085 | # define dSAVEDERRNO int saved_errno; unsigned saved_vms_errno |
1086 | # define dSAVE_ERRNO int saved_errno = errno; unsigned saved_vms_errno = vaxc$errno | |
1087 | # define SAVE_ERRNO ( saved_errno = errno, saved_vms_errno = vaxc$errno ) | |
1088 | # define RESTORE_ERRNO SETERRNO(saved_errno, saved_vms_errno) | |
1089 | ||
93189314 JH |
1090 | # define LIB_INVARG LIB$_INVARG |
1091 | # define RMS_DIR RMS$_DIR | |
1092 | # define RMS_FAC RMS$_FAC | |
1093 | # define RMS_FEX RMS$_FEX | |
1094 | # define RMS_FNF RMS$_FNF | |
1095 | # define RMS_IFI RMS$_IFI | |
1096 | # define RMS_ISI RMS$_ISI | |
1097 | # define RMS_PRV RMS$_PRV | |
1098 | # define SS_ACCVIO SS$_ACCVIO | |
1099 | # define SS_DEVOFFLINE SS$_DEVOFFLINE | |
1100 | # define SS_IVCHAN SS$_IVCHAN | |
1101 | # define SS_NORMAL SS$_NORMAL | |
8a9f18be | 1102 | # define SS_NOPRIV SS$_NOPRIV |
4388f261 | 1103 | # define SS_BUFFEROVF SS$_BUFFEROVF |
748a9306 | 1104 | #else |
93189314 JH |
1105 | # define LIB_INVARG 0 |
1106 | # define RMS_DIR 0 | |
1107 | # define RMS_FAC 0 | |
1108 | # define RMS_FEX 0 | |
1109 | # define RMS_FNF 0 | |
1110 | # define RMS_IFI 0 | |
1111 | # define RMS_ISI 0 | |
1112 | # define RMS_PRV 0 | |
1113 | # define SS_ACCVIO 0 | |
1114 | # define SS_DEVOFFLINE 0 | |
1115 | # define SS_IVCHAN 0 | |
1116 | # define SS_NORMAL 0 | |
8a9f18be | 1117 | # define SS_NOPRIV 0 |
4388f261 | 1118 | # define SS_BUFFEROVF 0 |
748a9306 | 1119 | #endif |
ed6116ce | 1120 | |
6ca940a9 TC |
1121 | #ifdef WIN32 |
1122 | # define dSAVEDERRNO int saved_errno; DWORD saved_win32_errno | |
1123 | # define dSAVE_ERRNO int saved_errno = errno; DWORD saved_win32_errno = GetLastError() | |
1124 | # define SAVE_ERRNO ( saved_errno = errno, saved_win32_errno = GetLastError() ) | |
1125 | # define RESTORE_ERRNO ( errno = saved_errno, SetLastError(saved_win32_errno) ) | |
1126 | #endif | |
1127 | ||
1128 | #ifdef OS2 | |
1129 | # define dSAVEDERRNO int saved_errno; unsigned long saved_os2_errno | |
1130 | # define dSAVE_ERRNO int saved_errno = errno; unsigned long saved_os2_errno = Perl_rc | |
1131 | # define SAVE_ERRNO ( saved_errno = errno, saved_os2_errno = Perl_rc ) | |
1132 | # define RESTORE_ERRNO ( errno = saved_errno, Perl_rc = saved_os2_errno ) | |
1133 | #endif | |
1134 | ||
1135 | #ifndef SETERRNO | |
1136 | # define SETERRNO(errcode,vmserrcode) (errno = (errcode)) | |
1137 | #endif | |
1138 | ||
1139 | #ifndef dSAVEDERRNO | |
1140 | # define dSAVEDERRNO int saved_errno | |
1141 | # define dSAVE_ERRNO int saved_errno = errno | |
1142 | # define SAVE_ERRNO (saved_errno = errno) | |
1143 | # define RESTORE_ERRNO (errno = saved_errno) | |
1144 | #endif | |
1145 | ||
f5fa9033 | 1146 | #define ERRSV GvSVn(PL_errgv) |
dfd167e9 | 1147 | |
b4f8d149 | 1148 | /* contains inlined gv_add_by_type */ |
dfd167e9 | 1149 | #define CLEAR_ERRSV() STMT_START { \ |
b4f8d149 DD |
1150 | SV ** const svp = &GvSV(PL_errgv); \ |
1151 | if (!*svp) { \ | |
a1b60c8d | 1152 | *svp = newSVpvs(""); \ |
b4f8d149 DD |
1153 | } else if (SvREADONLY(*svp)) { \ |
1154 | SvREFCNT_dec_NN(*svp); \ | |
b4f8d149 | 1155 | *svp = newSVpvs(""); \ |
dfd167e9 | 1156 | } else { \ |
b4f8d149 | 1157 | SV *const errsv = *svp; \ |
a1b60c8d | 1158 | SvPVCLEAR(errsv); \ |
b4f8d149 | 1159 | SvPOK_only(errsv); \ |
dfd167e9 NC |
1160 | if (SvMAGICAL(errsv)) { \ |
1161 | mg_free(errsv); \ | |
1162 | } \ | |
dfd167e9 NC |
1163 | } \ |
1164 | } STMT_END | |
1165 | ||
1166 | ||
414bf5ae MHM |
1167 | #ifdef PERL_CORE |
1168 | # define DEFSV (0 + GvSVn(PL_defgv)) | |
55b5114f FC |
1169 | # define DEFSV_set(sv) \ |
1170 | (SvREFCNT_dec(GvSV(PL_defgv)), GvSV(PL_defgv) = SvREFCNT_inc(sv)) | |
1171 | # define SAVE_DEFSV \ | |
1172 | ( \ | |
1173 | save_gp(PL_defgv, 0), \ | |
1174 | GvINTRO_off(PL_defgv), \ | |
1175 | SAVEGENERICSV(GvSV(PL_defgv)), \ | |
1176 | GvSV(PL_defgv) = NULL \ | |
1177 | ) | |
414bf5ae MHM |
1178 | #else |
1179 | # define DEFSV GvSVn(PL_defgv) | |
55b5114f FC |
1180 | # define DEFSV_set(sv) (GvSV(PL_defgv) = (sv)) |
1181 | # define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv)) | |
414bf5ae | 1182 | #endif |
38a03e6e | 1183 | |
55497cff | 1184 | #ifndef errno |
5ff3f7a4 GS |
1185 | extern int errno; /* ANSI allows errno to be an lvalue expr. |
1186 | * For example in multithreaded environments | |
1187 | * something like this might happen: | |
1188 | * extern int *_errno(void); | |
1189 | * #define errno (*_errno()) */ | |
d9d8d8de | 1190 | #endif |
663a0e37 | 1191 | |
7e996671 KW |
1192 | #define UNKNOWN_ERRNO_MSG "(unknown)" |
1193 | ||
b21d8587 AC |
1194 | #if VMS |
1195 | #define Strerror(e) strerror((e), vaxc$errno) | |
1196 | #else | |
1197 | #define Strerror(e) strerror(e) | |
35c8bce7 | 1198 | #endif |
663a0e37 | 1199 | |
2304df62 | 1200 | #ifdef I_SYS_IOCTL |
79072805 LW |
1201 | # ifndef _IOCTL_ |
1202 | # include <sys/ioctl.h> | |
1203 | # endif | |
a687059c LW |
1204 | #endif |
1205 | ||
ee0007ab | 1206 | #if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000) |
79072805 LW |
1207 | # ifdef HAS_SOCKETPAIR |
1208 | # undef HAS_SOCKETPAIR | |
1209 | # endif | |
2304df62 AD |
1210 | # ifdef I_NDBM |
1211 | # undef I_NDBM | |
79072805 | 1212 | # endif |
a687059c LW |
1213 | #endif |
1214 | ||
02fc2eee NC |
1215 | #ifndef HAS_SOCKETPAIR |
1216 | # ifdef HAS_SOCKET | |
1217 | # define socketpair Perl_my_socketpair | |
1218 | # endif | |
1219 | #endif | |
1220 | ||
a687059c | 1221 | #if INTSIZE == 2 |
79072805 LW |
1222 | # define htoni htons |
1223 | # define ntohi ntohs | |
a687059c | 1224 | #else |
79072805 LW |
1225 | # define htoni htonl |
1226 | # define ntohi ntohl | |
a687059c LW |
1227 | #endif |
1228 | ||
a0d0e21e | 1229 | /* Configure already sets Direntry_t */ |
35c8bce7 | 1230 | #if defined(I_DIRENT) |
da5fdda8 AC |
1231 | # include <dirent.h> |
1232 | #elif defined(I_SYS_NDIR) | |
1233 | # include <sys/ndir.h> | |
1234 | #elif defined(I_SYS_DIR) | |
1235 | # include <sys/dir.h> | |
4633a7c4 | 1236 | #endif |
a687059c | 1237 | |
c623bd54 LW |
1238 | /* |
1239 | * The following gobbledygook brought to you on behalf of __STDC__. | |
1240 | * (I could just use #ifndef __STDC__, but this is more bulletproof | |
1241 | * in the face of half-implementations.) | |
1242 | */ | |
1243 | ||
21e89b5f | 1244 | #if defined(I_SYSMODE) |
ca6e1c26 JH |
1245 | #include <sys/mode.h> |
1246 | #endif | |
1247 | ||
c623bd54 LW |
1248 | #ifndef S_IFMT |
1249 | # ifdef _S_IFMT | |
1250 | # define S_IFMT _S_IFMT | |
1251 | # else | |
1252 | # define S_IFMT 0170000 | |
1253 | # endif | |
1254 | #endif | |
1255 | ||
1256 | #ifndef S_ISDIR | |
1257 | # define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR) | |
1258 | #endif | |
1259 | ||
1260 | #ifndef S_ISCHR | |
1261 | # define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR) | |
1262 | #endif | |
1263 | ||
1264 | #ifndef S_ISBLK | |
fe14fcc3 LW |
1265 | # ifdef S_IFBLK |
1266 | # define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK) | |
1267 | # else | |
1268 | # define S_ISBLK(m) (0) | |
1269 | # endif | |
c623bd54 LW |
1270 | #endif |
1271 | ||
1272 | #ifndef S_ISREG | |
1273 | # define S_ISREG(m) ((m & S_IFMT) == S_IFREG) | |
1274 | #endif | |
1275 | ||
1276 | #ifndef S_ISFIFO | |
fe14fcc3 LW |
1277 | # ifdef S_IFIFO |
1278 | # define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO) | |
1279 | # else | |
1280 | # define S_ISFIFO(m) (0) | |
1281 | # endif | |
c623bd54 LW |
1282 | #endif |
1283 | ||
1284 | #ifndef S_ISLNK | |
da5fdda8 AC |
1285 | # ifdef _S_ISLNK |
1286 | # define S_ISLNK(m) _S_ISLNK(m) | |
1287 | # elif defined(_S_IFLNK) | |
1288 | # define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK) | |
1289 | # elif defined(S_IFLNK) | |
1290 | # define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK) | |
1291 | # else | |
1292 | # define S_ISLNK(m) (0) | |
1293 | # endif | |
c623bd54 LW |
1294 | #endif |
1295 | ||
1296 | #ifndef S_ISSOCK | |
da5fdda8 AC |
1297 | # ifdef _S_ISSOCK |
1298 | # define S_ISSOCK(m) _S_ISSOCK(m) | |
1299 | # elif defined(_S_IFSOCK) | |
1300 | # define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK) | |
1301 | # elif defined(S_IFSOCK) | |
1302 | # define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK) | |
1303 | # else | |
1304 | # define S_ISSOCK(m) (0) | |
1305 | # endif | |
c623bd54 LW |
1306 | #endif |
1307 | ||
1308 | #ifndef S_IRUSR | |
1309 | # ifdef S_IREAD | |
1310 | # define S_IRUSR S_IREAD | |
1311 | # define S_IWUSR S_IWRITE | |
1312 | # define S_IXUSR S_IEXEC | |
1313 | # else | |
1314 | # define S_IRUSR 0400 | |
1315 | # define S_IWUSR 0200 | |
1316 | # define S_IXUSR 0100 | |
1317 | # endif | |
fac7cdfc JS |
1318 | #endif |
1319 | ||
1320 | #ifndef S_IRGRP | |
1321 | # ifdef S_IRUSR | |
1322 | # define S_IRGRP (S_IRUSR>>3) | |
1323 | # define S_IWGRP (S_IWUSR>>3) | |
1324 | # define S_IXGRP (S_IXUSR>>3) | |
1325 | # else | |
1326 | # define S_IRGRP 0040 | |
1327 | # define S_IWGRP 0020 | |
1328 | # define S_IXGRP 0010 | |
1329 | # endif | |
1330 | #endif | |
1331 | ||
1332 | #ifndef S_IROTH | |
1333 | # ifdef S_IRUSR | |
1334 | # define S_IROTH (S_IRUSR>>6) | |
1335 | # define S_IWOTH (S_IWUSR>>6) | |
1336 | # define S_IXOTH (S_IXUSR>>6) | |
1337 | # else | |
1338 | # define S_IROTH 0040 | |
1339 | # define S_IWOTH 0020 | |
1340 | # define S_IXOTH 0010 | |
1341 | # endif | |
c623bd54 LW |
1342 | #endif |
1343 | ||
1344 | #ifndef S_ISUID | |
1345 | # define S_ISUID 04000 | |
1346 | #endif | |
1347 | ||
1348 | #ifndef S_ISGID | |
1349 | # define S_ISGID 02000 | |
1350 | #endif | |
1351 | ||
ca6e1c26 JH |
1352 | #ifndef S_IRWXU |
1353 | # define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR) | |
d460ef45 | 1354 | #endif |
ca6e1c26 JH |
1355 | |
1356 | #ifndef S_IRWXG | |
1357 | # define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP) | |
d460ef45 | 1358 | #endif |
ca6e1c26 JH |
1359 | |
1360 | #ifndef S_IRWXO | |
1361 | # define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH) | |
d460ef45 | 1362 | #endif |
ca6e1c26 | 1363 | |
b6c36746 | 1364 | /* Haiku R1 seems to define S_IREAD and S_IWRITE in <posix/fcntl.h> |
c21fb2b8 JH |
1365 | * which would get included through <sys/file.h >, but that is 3000 |
1366 | * lines in the future. --jhi */ | |
1367 | ||
b6c36746 | 1368 | #if !defined(S_IREAD) && !defined(__HAIKU__) |
ca6e1c26 JH |
1369 | # define S_IREAD S_IRUSR |
1370 | #endif | |
1371 | ||
b6c36746 | 1372 | #if !defined(S_IWRITE) && !defined(__HAIKU__) |
ca6e1c26 JH |
1373 | # define S_IWRITE S_IWUSR |
1374 | #endif | |
1375 | ||
1376 | #ifndef S_IEXEC | |
1377 | # define S_IEXEC S_IXUSR | |
1378 | #endif | |
1379 | ||
a0d0e21e | 1380 | #if defined(cray) || defined(gould) || defined(i860) || defined(pyr) |
45d8adaa LW |
1381 | # define SLOPPYDIVIDE |
1382 | #endif | |
1383 | ||
748a9306 LW |
1384 | #ifdef UV |
1385 | #undef UV | |
1386 | #endif | |
1387 | ||
f1519f70 AC |
1388 | /* This used to be conditionally defined based on whether we had a sprintf() |
1389 | * that correctly returns the string length (as required by C89), but we no | |
1390 | * longer need that. XS modules can (and do) use this name, so it must remain | |
1391 | * a part of the API that's visible to modules. But we no longer document it | |
1392 | * either (because using sprintf() rather than snprintf() is almost always | |
1393 | * a bad idea). */ | |
1394 | #define my_sprintf sprintf | |
ce582cee | 1395 | |
5b692037 JH |
1396 | /* |
1397 | * If we have v?snprintf() and the C99 variadic macros, we can just | |
1398 | * use just the v?snprintf(). It is nice to try to trap the buffer | |
1399 | * overflow, however, so if we are DEBUGGING, and we cannot use the | |
e5afc1ae DD |
1400 | * gcc statement expressions, then use the function wrappers which try |
1401 | * to trap the overflow. If we can use the gcc statement expressions, | |
1402 | * we can try that even with the version that uses the C99 variadic | |
1403 | * macros. | |
5b692037 JH |
1404 | */ |
1405 | ||
1208b3dd | 1406 | /* Note that we do not check against snprintf()/vsnprintf() returning |
13d66b05 AC |
1407 | * negative values because that is non-standard behaviour and we now |
1408 | * assume a working C89 implementation. */ | |
1208b3dd | 1409 | |
571ee10c | 1410 | #define PERL_SNPRINTF_CHECK(len, max, api) STMT_START { if ((max) > 0 && (Size_t)len > (max)) Perl_croak_nocontext("panic: %s buffer overflow", STRINGIFY(api)); } STMT_END |
e8549682 | 1411 | |
a4eca1d4 JH |
1412 | #ifdef USE_QUADMATH |
1413 | # define my_snprintf Perl_my_snprintf | |
1414 | # define PERL_MY_SNPRINTF_GUARDED | |
da5fdda8 | 1415 | #elif defined(HAS_C99_VARIADIC_MACROS) && !(defined(DEBUGGING) && !defined(PERL_USE_GCC_BRACE_GROUPS)) && !defined(PERL_GCC_PEDANTIC) |
5b692037 | 1416 | # ifdef PERL_USE_GCC_BRACE_GROUPS |
e8549682 | 1417 | # define my_snprintf(buffer, max, ...) ({ int len = snprintf(buffer, max, __VA_ARGS__); PERL_SNPRINTF_CHECK(len, max, snprintf); len; }) |
1208b3dd | 1418 | # define PERL_MY_SNPRINTF_GUARDED |
5b692037 | 1419 | # else |
e8549682 | 1420 | # define my_snprintf(buffer, max, ...) snprintf(buffer, max, __VA_ARGS__) |
5b692037 JH |
1421 | # endif |
1422 | #else | |
1423 | # define my_snprintf Perl_my_snprintf | |
1208b3dd | 1424 | # define PERL_MY_SNPRINTF_GUARDED |
5b692037 JH |
1425 | #endif |
1426 | ||
a4eca1d4 JH |
1427 | /* There is no quadmath_vsnprintf, and therefore my_vsnprintf() |
1428 | * dies if called under USE_QUADMATH. */ | |
13d66b05 | 1429 | #if defined(HAS_C99_VARIADIC_MACROS) && !(defined(DEBUGGING) && !defined(PERL_USE_GCC_BRACE_GROUPS)) && !defined(PERL_GCC_PEDANTIC) |
5b692037 | 1430 | # ifdef PERL_USE_GCC_BRACE_GROUPS |
e8549682 | 1431 | # define my_vsnprintf(buffer, max, ...) ({ int len = vsnprintf(buffer, max, __VA_ARGS__); PERL_SNPRINTF_CHECK(len, max, vsnprintf); len; }) |
1208b3dd | 1432 | # define PERL_MY_VSNPRINTF_GUARDED |
5b692037 | 1433 | # else |
e8549682 | 1434 | # define my_vsnprintf(buffer, max, ...) vsnprintf(buffer, max, __VA_ARGS__) |
5b692037 JH |
1435 | # endif |
1436 | #else | |
1437 | # define my_vsnprintf Perl_my_vsnprintf | |
1208b3dd | 1438 | # define PERL_MY_VSNPRINTF_GUARDED |
5b692037 | 1439 | #endif |
d9fad198 | 1440 | |
e8549682 JH |
1441 | /* You will definitely need to use the PERL_MY_SNPRINTF_POST_GUARD() |
1442 | * or PERL_MY_VSNPRINTF_POST_GUARD() if you otherwise decide to ignore | |
1443 | * the result of my_snprintf() or my_vsnprintf(). (No, you should not | |
1444 | * completely ignore it: otherwise you cannot know whether your output | |
1445 | * was too long.) | |
1446 | * | |
1447 | * int len = my_sprintf(buf, max, ...); | |
1448 | * PERL_MY_SNPRINTF_POST_GUARD(len, max); | |
1449 | * | |
1450 | * The trick is that in certain platforms [a] the my_sprintf() already | |
1451 | * contains the sanity check, while in certain platforms [b] it needs | |
1452 | * to be done as a separate step. The POST_GUARD is that step-- in [a] | |
1453 | * platforms the POST_GUARD actually does nothing since the check has | |
1454 | * already been done. Watch out for the max being the same in both calls. | |
1455 | * | |
1456 | * If you actually use the snprintf/vsnprintf return value already, | |
1457 | * you assumedly are checking its validity somehow. But you can | |
1458 | * insert the POST_GUARD() also in that case. */ | |
1459 | ||
1460 | #ifndef PERL_MY_SNPRINTF_GUARDED | |
1461 | # define PERL_MY_SNPRINTF_POST_GUARD(len, max) PERL_SNPRINTF_CHECK(len, max, snprintf) | |
1462 | #else | |
1463 | # define PERL_MY_SNPRINTF_POST_GUARD(len, max) PERL_UNUSED_VAR(len) | |
1464 | #endif | |
1465 | ||
1466 | #ifndef PERL_MY_VSNPRINTF_GUARDED | |
1467 | # define PERL_MY_VSNPRINTF_POST_GUARD(len, max) PERL_SNPRINTF_CHECK(len, max, vsnprintf) | |
1468 | #else | |
1469 | # define PERL_MY_VSNPRINTF_POST_GUARD(len, max) PERL_UNUSED_VAR(len) | |
1470 | #endif | |
1471 | ||
a6cc4119 SP |
1472 | #ifdef HAS_STRLCAT |
1473 | # define my_strlcat strlcat | |
1474 | #else | |
1475 | # define my_strlcat Perl_my_strlcat | |
1476 | #endif | |
1477 | ||
1478 | #ifdef HAS_STRLCPY | |
1479 | # define my_strlcpy strlcpy | |
1480 | #else | |
1481 | # define my_strlcpy Perl_my_strlcpy | |
1482 | #endif | |
1483 | ||
aefb3fa0 DIM |
1484 | #ifdef HAS_STRNLEN |
1485 | # define my_strnlen strnlen | |
1486 | #else | |
1487 | # define my_strnlen Perl_my_strnlen | |
1488 | #endif | |
1489 | ||
05f13f53 | 1490 | /* |
27d4fb96 | 1491 | The IV type is supposed to be long enough to hold any integral |
1492 | value or a pointer. | |
1493 | --Andy Dougherty August 1996 | |
1494 | */ | |
1495 | ||
a22e52b9 JH |
1496 | typedef IVTYPE IV; |
1497 | typedef UVTYPE UV; | |
8175356b | 1498 | |
10cc9d2a | 1499 | #if defined(USE_64_BIT_INT) && defined(HAS_QUAD) |
6b8eaf93 | 1500 | # if QUADKIND == QUAD_IS_INT64_T && defined(INT64_MAX) |
5ff3f7a4 GS |
1501 | # define IV_MAX INT64_MAX |
1502 | # define IV_MIN INT64_MIN | |
1503 | # define UV_MAX UINT64_MAX | |
cae7ae48 JH |
1504 | # ifndef UINT64_MIN |
1505 | # define UINT64_MIN 0 | |
1506 | # endif | |
5ff3f7a4 GS |
1507 | # define UV_MIN UINT64_MIN |
1508 | # else | |
1509 | # define IV_MAX PERL_QUAD_MAX | |
1510 | # define IV_MIN PERL_QUAD_MIN | |
1511 | # define UV_MAX PERL_UQUAD_MAX | |
1512 | # define UV_MIN PERL_UQUAD_MIN | |
1513 | # endif | |
cf2093f6 JH |
1514 | # define IV_IS_QUAD |
1515 | # define UV_IS_QUAD | |
79072805 | 1516 | #else |
8175356b | 1517 | # if defined(INT32_MAX) && IVSIZE == 4 |
5ff3f7a4 GS |
1518 | # define IV_MAX INT32_MAX |
1519 | # define IV_MIN INT32_MIN | |
716026f9 DL |
1520 | # ifndef UINT32_MAX_BROKEN /* e.g. HP-UX with gcc messes this up */ |
1521 | # define UV_MAX UINT32_MAX | |
1522 | # else | |
1523 | # define UV_MAX 4294967295U | |
1524 | # endif | |
cae7ae48 JH |
1525 | # ifndef UINT32_MIN |
1526 | # define UINT32_MIN 0 | |
1527 | # endif | |
5ff3f7a4 GS |
1528 | # define UV_MIN UINT32_MIN |
1529 | # else | |
1530 | # define IV_MAX PERL_LONG_MAX | |
1531 | # define IV_MIN PERL_LONG_MIN | |
1532 | # define UV_MAX PERL_ULONG_MAX | |
1533 | # define UV_MIN PERL_ULONG_MIN | |
1534 | # endif | |
8175356b | 1535 | # if IVSIZE == 8 |
cf2093f6 JH |
1536 | # define IV_IS_QUAD |
1537 | # define UV_IS_QUAD | |
de1c2614 JH |
1538 | # ifndef HAS_QUAD |
1539 | # define HAS_QUAD | |
1540 | # endif | |
cf2093f6 JH |
1541 | # else |
1542 | # undef IV_IS_QUAD | |
1543 | # undef UV_IS_QUAD | |
9ea40801 | 1544 | #if !defined(PERL_CORE) || defined(USING_MSVC6) |
e25d460c NC |
1545 | /* We think that removing this decade-old undef this will cause too much |
1546 | breakage on CPAN for too little gain. (See RT #119753) | |
9ea40801 SH |
1547 | However, we do need HAS_QUAD in the core for use by the drand48 code, |
1548 | but not for Win32 VC6 because it has poor __int64 support. */ | |
cb4b14d5 | 1549 | # undef HAS_QUAD |
e25d460c | 1550 | #endif |
cf2093f6 | 1551 | # endif |
79072805 | 1552 | #endif |
d7d93a81 | 1553 | |
6313e544 JH |
1554 | #define Size_t_MAX (~(Size_t)0) |
1555 | #define SSize_t_MAX (SSize_t)(~(Size_t)0 >> 1) | |
9a543cee | 1556 | |
cae7ae48 | 1557 | #define IV_DIG (BIT_DIGITS(IVSIZE * 8)) |
22ec83e3 | 1558 | #define UV_DIG (BIT_DIGITS(UVSIZE * 8)) |
56431972 | 1559 | |
28e5dec8 | 1560 | #ifndef NO_PERL_PRESERVE_IVUV |
f5c03d33 | 1561 | #define PERL_PRESERVE_IVUV /* We like our integers to stay integers. */ |
28e5dec8 JH |
1562 | #endif |
1563 | ||
d460ef45 | 1564 | /* |
26bb67e2 JH |
1565 | * The macros INT2PTR and NUM2PTR are (despite their names) |
1566 | * bi-directional: they will convert int/float to or from pointers. | |
1567 | * However the conversion to int/float are named explicitly: | |
1568 | * PTR2IV, PTR2UV, PTR2NV. | |
1569 | * | |
1570 | * For int conversions we do not need two casts if pointers are | |
1571 | * the same size as IV and UV. Otherwise we need an explicit | |
1572 | * cast (PTRV) to avoid compiler warnings. | |
1573 | */ | |
56431972 RB |
1574 | #if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE) |
1575 | # define PTRV UV | |
1576 | # define INT2PTR(any,d) (any)(d) | |
da5fdda8 AC |
1577 | #elif PTRSIZE == LONGSIZE |
1578 | # define PTRV unsigned long | |
1579 | # define PTR2ul(p) (unsigned long)(p) | |
56431972 | 1580 | #else |
da5fdda8 | 1581 | # define PTRV unsigned |
e91e3b10 RB |
1582 | #endif |
1583 | ||
1584 | #ifndef INT2PTR | |
56431972 | 1585 | # define INT2PTR(any,d) (any)(PTRV)(d) |
42718184 | 1586 | #endif |
e91e3b10 RB |
1587 | |
1588 | #ifndef PTR2ul | |
1589 | # define PTR2ul(p) INT2PTR(unsigned long,p) | |
1590 | #endif | |
1591 | ||
56431972 RB |
1592 | #define NUM2PTR(any,d) (any)(PTRV)(d) |
1593 | #define PTR2IV(p) INT2PTR(IV,p) | |
1594 | #define PTR2UV(p) INT2PTR(UV,p) | |
1595 | #define PTR2NV(p) NUM2PTR(NV,p) | |
e91e3b10 | 1596 | #define PTR2nat(p) (PTRV)(p) /* pointer to integer of PTRSIZE */ |
d460ef45 | 1597 | |
8141890a JH |
1598 | /* According to strict ANSI C89 one cannot freely cast between |
1599 | * data pointers and function (code) pointers. There are at least | |
1600 | * two ways around this. One (used below) is to do two casts, | |
1601 | * first the other pointer to an (unsigned) integer, and then | |
1602 | * the integer to the other pointer. The other way would be | |
1603 | * to use unions to "overlay" the pointers. For an example of | |
1604 | * the latter technique, see union dirpu in struct xpvio in sv.h. | |
1605 | * The only feasible use is probably temporarily storing | |
1606 | * function pointers in a data pointer (such as a void pointer). */ | |
1607 | ||
e91e3b10 RB |
1608 | #define DPTR2FPTR(t,p) ((t)PTR2nat(p)) /* data pointer to function pointer */ |
1609 | #define FPTR2DPTR(t,p) ((t)PTR2nat(p)) /* function pointer to data pointer */ | |
8141890a | 1610 | |
65202027 | 1611 | #ifdef USE_LONG_DOUBLE |
f3654d06 JH |
1612 | # if LONG_DOUBLESIZE == DOUBLESIZE |
1613 | # define LONG_DOUBLE_EQUALS_DOUBLE | |
1614 | # undef USE_LONG_DOUBLE /* Ouch! */ | |
65202027 DS |
1615 | # endif |
1616 | #endif | |
1617 | ||
2d4389e4 JH |
1618 | /* The following is all to get LDBL_DIG, in order to pick a nice |
1619 | default value for printing floating point numbers in Gconvert. | |
1620 | (see config.h) | |
1621 | */ | |
63b481b9 | 1622 | #ifndef HAS_LDBL_DIG |
68d4903c | 1623 | # if LONG_DOUBLESIZE == 10 |
63b481b9 AC |
1624 | # define LDBL_DIG 18 /* assume IEEE */ |
1625 | # elif LONG_DOUBLESIZE == 12 | |
68d4903c | 1626 | # define LDBL_DIG 18 /* gcc? */ |
63b481b9 AC |
1627 | # elif LONG_DOUBLESIZE == 16 |
1628 | # define LDBL_DIG 33 /* assume IEEE */ | |
1629 | # elif LONG_DOUBLESIZE == DOUBLESIZE | |
1630 | # define LDBL_DIG DBL_DIG /* bummer */ | |
68d4903c | 1631 | # endif |
2d4389e4 JH |
1632 | #endif |
1633 | ||
a22e52b9 | 1634 | typedef NVTYPE NV; |
8175356b | 1635 | |
792d8dab JH |
1636 | #ifdef I_IEEEFP |
1637 | # include <ieeefp.h> | |
1638 | #endif | |
923fc586 | 1639 | |
c32c3de1 JH |
1640 | #ifdef USING_MSVC6 |
1641 | /* VC6 has broken NaN semantics: NaN == NaN returns true instead of false, | |
1642 | * and for example NaN < IV_MIN. */ | |
bcd8bfa9 JH |
1643 | # define NAN_COMPARE_BROKEN |
1644 | #endif | |
1645 | #if defined(__DECC) && defined(__osf__) | |
1646 | /* Also Tru64 cc has broken NaN comparisons. */ | |
1647 | # define NAN_COMPARE_BROKEN | |
c32c3de1 | 1648 | #endif |
6504068e JH |
1649 | #if defined(__sgi) |
1650 | # define NAN_COMPARE_BROKEN | |
1651 | #endif | |
c32c3de1 | 1652 | |
65202027 | 1653 | #ifdef USE_LONG_DOUBLE |
923fc586 JH |
1654 | # ifdef I_SUNMATH |
1655 | # include <sunmath.h> | |
1656 | # endif | |
84e6cb05 | 1657 | # if defined(LDBL_DIG) |
05b4a618 JH |
1658 | # define NV_DIG LDBL_DIG |
1659 | # ifdef LDBL_MANT_DIG | |
1660 | # define NV_MANT_DIG LDBL_MANT_DIG | |
1661 | # endif | |
1662 | # ifdef LDBL_MIN | |
1663 | # define NV_MIN LDBL_MIN | |
1664 | # endif | |
1665 | # ifdef LDBL_MAX | |
1666 | # define NV_MAX LDBL_MAX | |
1667 | # endif | |
1668 | # ifdef LDBL_MIN_EXP | |
1669 | # define NV_MIN_EXP LDBL_MIN_EXP | |
1670 | # endif | |
1671 | # ifdef LDBL_MAX_EXP | |
1672 | # define NV_MAX_EXP LDBL_MAX_EXP | |
1673 | # endif | |
1674 | # ifdef LDBL_MIN_10_EXP | |
1675 | # define NV_MIN_10_EXP LDBL_MIN_10_EXP | |
1676 | # endif | |
1677 | # ifdef LDBL_MAX_10_EXP | |
1678 | # define NV_MAX_10_EXP LDBL_MAX_10_EXP | |
1679 | # endif | |
1680 | # ifdef LDBL_EPSILON | |
1681 | # define NV_EPSILON LDBL_EPSILON | |
1682 | # endif | |
1683 | # ifdef LDBL_MAX | |
1684 | # define NV_MAX LDBL_MAX | |
20f6aaab | 1685 | /* Having LDBL_MAX doesn't necessarily mean that we have LDBL_MIN... -Allen */ |
da5fdda8 AC |
1686 | # elif defined(HUGE_VALL) |
1687 | # define NV_MAX HUGE_VALL | |
f4a14a62 JH |
1688 | # endif |
1689 | # endif | |
84e6cb05 | 1690 | # if defined(HAS_SQRTL) |
8a00eddc JH |
1691 | # define Perl_acos acosl |
1692 | # define Perl_asin asinl | |
1693 | # define Perl_atan atanl | |
940e3d56 JH |
1694 | # define Perl_atan2 atan2l |
1695 | # define Perl_ceil ceill | |
1696 | # define Perl_cos cosl | |
8a00eddc | 1697 | # define Perl_cosh coshl |
940e3d56 | 1698 | # define Perl_exp expl |
55da5e5b | 1699 | /* no Perl_fabs, but there's PERL_ABS */ |
940e3d56 JH |
1700 | # define Perl_floor floorl |
1701 | # define Perl_fmod fmodl | |
1702 | # define Perl_log logl | |
8a00eddc | 1703 | # define Perl_log10 log10l |
940e3d56 JH |
1704 | # define Perl_pow powl |
1705 | # define Perl_sin sinl | |
8a00eddc | 1706 | # define Perl_sinh sinhl |
940e3d56 | 1707 | # define Perl_sqrt sqrtl |
8a00eddc JH |
1708 | # define Perl_tan tanl |
1709 | # define Perl_tanh tanhl | |
68d4903c | 1710 | # endif |
a3540c92 | 1711 | /* e.g. libsunmath doesn't have modfl and frexpl as of mid-March 2000 */ |
05b4a618 JH |
1712 | # ifndef Perl_modf |
1713 | # ifdef HAS_MODFL | |
1714 | # define Perl_modf(x,y) modfl(x,y) | |
51997bc3 NC |
1715 | /* eg glibc 2.2 series seems to provide modfl on ppc and arm, but has no |
1716 | prototype in <math.h> */ | |
05b4a618 | 1717 | # ifndef HAS_MODFL_PROTO |
a221a8a5 | 1718 | EXTERN_C long double modfl(long double, long double *); |
05b4a618 JH |
1719 | # endif |
1720 | # elif (defined(HAS_TRUNCL) || defined(HAS_AINTL)) && defined(HAS_COPYSIGNL) | |
55954f19 | 1721 | extern long double Perl_my_modfl(long double x, long double *ip); |
03476e8e | 1722 | # define Perl_modf(x,y) Perl_my_modfl(x,y) |
05b4a618 | 1723 | # endif |
a3540c92 | 1724 | # endif |
05b4a618 JH |
1725 | # ifndef Perl_frexp |
1726 | # ifdef HAS_FREXPL | |
1727 | # define Perl_frexp(x,y) frexpl(x,y) | |
da5fdda8 | 1728 | # elif defined(HAS_ILOGBL) && defined(HAS_SCALBNL) |
05b4a618 | 1729 | extern long double Perl_my_frexpl(long double x, int *e); |
da5fdda8 | 1730 | # define Perl_frexp(x,y) Perl_my_frexpl(x,y) |
03476e8e | 1731 | # endif |
a3540c92 | 1732 | # endif |
05b4a618 JH |
1733 | # ifndef Perl_ldexp |
1734 | # ifdef HAS_LDEXPL | |
1735 | # define Perl_ldexp(x, y) ldexpl(x,y) | |
da5fdda8 AC |
1736 | # elif defined(HAS_SCALBNL) && FLT_RADIX == 2 |
1737 | # define Perl_ldexp(x,y) scalbnl(x,y) | |
98181445 JH |
1738 | # endif |
1739 | # endif | |
38dbb4c5 | 1740 | # ifndef Perl_isnan |
e4c957f4 | 1741 | # if defined(HAS_ISNANL) && !(defined(isnan) && defined(HAS_C99)) |
758a5d79 | 1742 | # define Perl_isnan(x) isnanl(x) |
a1115378 JH |
1743 | # elif defined(__sgi) && defined(__c99) /* XXX Configure test needed */ |
1744 | # define Perl_isnan(x) isnan(x) | |
758a5d79 JH |
1745 | # endif |
1746 | # endif | |
1747 | # ifndef Perl_isinf | |
e4c957f4 | 1748 | # if defined(HAS_ISINFL) && !(defined(isinf) && defined(HAS_C99)) |
87190886 | 1749 | # define Perl_isinf(x) isinfl(x) |
a1115378 JH |
1750 | # elif defined(__sgi) && defined(__c99) /* XXX Configure test needed */ |
1751 | # define Perl_isinf(x) isinf(x) | |
bcd8bfa9 | 1752 | # elif defined(LDBL_MAX) && !defined(NAN_COMPARE_BROKEN) |
efcbf317 | 1753 | # define Perl_isinf(x) ((x) > LDBL_MAX || (x) < -LDBL_MAX) |
a3540c92 JH |
1754 | # endif |
1755 | # endif | |
e38461cc JH |
1756 | # ifndef Perl_isfinite |
1757 | # define Perl_isfinite(x) Perl_isfinitel(x) | |
1758 | # endif | |
84e6cb05 JH |
1759 | #elif defined(USE_QUADMATH) && defined(I_QUADMATH) |
1760 | # include <quadmath.h> | |
1761 | # define NV_DIG FLT128_DIG | |
1762 | # define NV_MANT_DIG FLT128_MANT_DIG | |
1763 | # define NV_MIN FLT128_MIN | |
1764 | # define NV_MAX FLT128_MAX | |
1765 | # define NV_MIN_EXP FLT128_MIN_EXP | |
1766 | # define NV_MAX_EXP FLT128_MAX_EXP | |
1767 | # define NV_EPSILON FLT128_EPSILON | |
1768 | # define NV_MIN_10_EXP FLT128_MIN_10_EXP | |
1769 | # define NV_MAX_10_EXP FLT128_MAX_10_EXP | |
84e6cb05 JH |
1770 | # define Perl_acos acosq |
1771 | # define Perl_asin asinq | |
1772 | # define Perl_atan atanq | |
1773 | # define Perl_atan2 atan2q | |
1774 | # define Perl_ceil ceilq | |
1775 | # define Perl_cos cosq | |
1776 | # define Perl_cosh coshq | |
1777 | # define Perl_exp expq | |
1778 | /* no Perl_fabs, but there's PERL_ABS */ | |
1779 | # define Perl_floor floorq | |
1780 | # define Perl_fmod fmodq | |
1781 | # define Perl_log logq | |
1782 | # define Perl_log10 log10q | |
1783 | # define Perl_pow powq | |
1784 | # define Perl_sin sinq | |
1785 | # define Perl_sinh sinhq | |
1786 | # define Perl_sqrt sqrtq | |
1787 | # define Perl_tan tanq | |
1788 | # define Perl_tanh tanhq | |
1789 | # define Perl_modf(x,y) modfq(x,y) | |
1790 | # define Perl_frexp(x,y) frexpq(x,y) | |
1791 | # define Perl_ldexp(x, y) ldexpq(x,y) | |
1792 | # define Perl_isinf(x) isinfq(x) | |
1793 | # define Perl_isnan(x) isnanq(x) | |
1794 | # define Perl_isfinite(x) !(isnanq(x) || isinfq(x)) | |
b28053d1 JH |
1795 | # define Perl_fp_class(x) ((x) == 0.0Q ? 0 : isinfq(x) ? 3 : isnanq(x) ? 4 : PERL_ABS(x) < FLT128_MIN ? 2 : 1) |
1796 | # define Perl_fp_class_inf(x) (Perl_fp_class(x) == 3) | |
1797 | # define Perl_fp_class_nan(x) (Perl_fp_class(x) == 4) | |
1798 | # define Perl_fp_class_norm(x) (Perl_fp_class(x) == 1) | |
1799 | # define Perl_fp_class_denorm(x) (Perl_fp_class(x) == 2) | |
1800 | # define Perl_fp_class_zero(x) (Perl_fp_class(x) == 0) | |
65202027 | 1801 | #else |
2d4389e4 | 1802 | # define NV_DIG DBL_DIG |
63b481b9 AC |
1803 | # define NV_MANT_DIG DBL_MANT_DIG |
1804 | # define NV_MIN DBL_MIN | |
1805 | # define NV_MAX DBL_MAX | |
1806 | # define NV_MIN_EXP DBL_MIN_EXP | |
1807 | # define NV_MAX_EXP DBL_MAX_EXP | |
1808 | # define NV_MIN_10_EXP DBL_MIN_10_EXP | |
1809 | # define NV_MAX_10_EXP DBL_MAX_10_EXP | |
1810 | # define NV_EPSILON DBL_EPSILON | |
1811 | # define NV_MAX DBL_MAX | |
1812 | # define NV_MIN DBL_MIN | |
940e3d56 | 1813 | |
55da5e5b | 1814 | /* These math interfaces are C89. */ |
8a00eddc JH |
1815 | # define Perl_acos acos |
1816 | # define Perl_asin asin | |
1817 | # define Perl_atan atan | |
940e3d56 JH |
1818 | # define Perl_atan2 atan2 |
1819 | # define Perl_ceil ceil | |
1820 | # define Perl_cos cos | |
8a00eddc | 1821 | # define Perl_cosh cosh |
940e3d56 | 1822 | # define Perl_exp exp |
55da5e5b | 1823 | /* no Perl_fabs, but there's PERL_ABS */ |
940e3d56 JH |
1824 | # define Perl_floor floor |
1825 | # define Perl_fmod fmod | |
1826 | # define Perl_log log | |
8a00eddc | 1827 | # define Perl_log10 log10 |
940e3d56 JH |
1828 | # define Perl_pow pow |
1829 | # define Perl_sin sin | |
8a00eddc | 1830 | # define Perl_sinh sinh |
940e3d56 | 1831 | # define Perl_sqrt sqrt |
8a00eddc JH |
1832 | # define Perl_tan tan |
1833 | # define Perl_tanh tanh | |
940e3d56 JH |
1834 | |
1835 | # define Perl_modf(x,y) modf(x,y) | |
1836 | # define Perl_frexp(x,y) frexp(x,y) | |
1837 | # define Perl_ldexp(x,y) ldexp(x,y) | |
1838 | ||
1a322af2 JH |
1839 | # ifndef Perl_isnan |
1840 | # ifdef HAS_ISNAN | |
1841 | # define Perl_isnan(x) isnan(x) | |
1842 | # endif | |
1843 | # endif | |
1844 | # ifndef Perl_isinf | |
1845 | # if defined(HAS_ISINF) | |
1846 | # define Perl_isinf(x) isinf(x) | |
bcd8bfa9 | 1847 | # elif defined(DBL_MAX) && !defined(NAN_COMPARE_BROKEN) |
efcbf317 | 1848 | # define Perl_isinf(x) ((x) > DBL_MAX || (x) < -DBL_MAX) |
1a322af2 JH |
1849 | # endif |
1850 | # endif | |
1851 | # ifndef Perl_isfinite | |
1852 | # ifdef HAS_ISFINITE | |
1853 | # define Perl_isfinite(x) isfinite(x) | |
1854 | # elif defined(HAS_FINITE) | |
1855 | # define Perl_isfinite(x) finite(x) | |
1856 | # endif | |
1857 | # endif | |
758a5d79 JH |
1858 | #endif |
1859 | ||
30404d48 JH |
1860 | /* fpclassify(): C99. It is supposed to be a macro that switches on |
1861 | * the sizeof() of its argument, so there's no need for e.g. fpclassifyl().*/ | |
1862 | #if !defined(Perl_fp_class) && defined(HAS_FPCLASSIFY) | |
1863 | # include <math.h> | |
25c46df8 JH |
1864 | # if defined(FP_INFINITE) && defined(FP_NAN) |
1865 | # define Perl_fp_class(x) fpclassify(x) | |
1866 | # define Perl_fp_class_inf(x) (Perl_fp_class(x)==FP_INFINITE) | |
1867 | # define Perl_fp_class_nan(x) (Perl_fp_class(x)==FP_NAN) | |
1868 | # define Perl_fp_class_norm(x) (Perl_fp_class(x)==FP_NORMAL) | |
1869 | # define Perl_fp_class_denorm(x) (Perl_fp_class(x)==FP_SUBNORMAL) | |
1870 | # define Perl_fp_class_zero(x) (Perl_fp_class(x)==FP_ZERO) | |
1871 | # elif defined(FP_PLUS_INF) && defined(FP_QNAN) | |
1872 | /* Some versions of HP-UX (10.20) have (only) fpclassify() but which is | |
1873 | * actually not the C99 fpclassify, with its own set of return defines. */ | |
1874 | # define Perl_fp_class(x) fpclassify(x) | |
1875 | # define Perl_fp_class_pinf(x) (Perl_fp_class(x)==FP_PLUS_INF) | |
1876 | # define Perl_fp_class_ninf(x) (Perl_fp_class(x)==FP_MINUS_INF) | |
82947af8 | 1877 | # define Perl_fp_class_snan(x) (Perl_fp_class(x)==FP_SNAN) |
25c46df8 JH |
1878 | # define Perl_fp_class_qnan(x) (Perl_fp_class(x)==FP_QNAN) |
1879 | # define Perl_fp_class_pnorm(x) (Perl_fp_class(x)==FP_PLUS_NORM) | |
1ae51000 | 1880 | # define Perl_fp_class_nnorm(x) (Perl_fp_class(x)==FP_MINUS_NORM) |
25c46df8 JH |
1881 | # define Perl_fp_class_pdenorm(x) (Perl_fp_class(x)==FP_PLUS_DENORM) |
1882 | # define Perl_fp_class_ndenorm(x) (Perl_fp_class(x)==FP_MINUS_DENORM) | |
1883 | # define Perl_fp_class_pzero(x) (Perl_fp_class(x)==FP_PLUS_ZERO) | |
1884 | # define Perl_fp_class_nzero(x) (Perl_fp_class(x)==FP_MINUS_ZERO) | |
1885 | # else | |
1886 | # undef Perl_fp_class /* Unknown set of defines */ | |
1887 | # endif | |
30404d48 JH |
1888 | #endif |
1889 | ||
25c46df8 JH |
1890 | /* fp_classify(): Legacy: VMS, maybe Unicos? The values, however, |
1891 | * are identical to the C99 fpclassify(). */ | |
1892 | #if !defined(Perl_fp_class) && defined(HAS_FP_CLASSIFY) | |
1893 | # include <math.h> | |
558f3e66 CB |
1894 | # ifdef __VMS |
1895 | /* FP_INFINITE and others are here rather than in math.h as C99 stipulates */ | |
1896 | # include <fp.h> | |
56610b8f CB |
1897 | /* oh, and the isnormal macro has a typo in it! */ |
1898 | # undef isnormal | |
1899 | # define isnormal(x) Perl_fp_class_norm(x) | |
558f3e66 | 1900 | # endif |
25c46df8 JH |
1901 | # if defined(FP_INFINITE) && defined(FP_NAN) |
1902 | # define Perl_fp_class(x) fp_classify(x) | |
1903 | # define Perl_fp_class_inf(x) (Perl_fp_class(x)==FP_INFINITE) | |
1904 | # define Perl_fp_class_nan(x) (Perl_fp_class(x)==FP_NAN) | |
1905 | # define Perl_fp_class_norm(x) (Perl_fp_class(x)==FP_NORMAL) | |
1906 | # define Perl_fp_class_denorm(x) (Perl_fp_class(x)==FP_SUBNORMAL) | |
1907 | # define Perl_fp_class_zero(x) (Perl_fp_class(x)==FP_ZERO) | |
1908 | # else | |
1909 | # undef Perl_fp_class /* Unknown set of defines */ | |
1910 | # endif | |
f279e099 | 1911 | #endif |
205f51d8 | 1912 | |
30404d48 JH |
1913 | /* Feel free to check with me for the SGI manpages, SGI testing, |
1914 | * etcetera, if you want to try getting this to work with IRIX. | |
1915 | * | |
1916 | * - Allen <allens@cpan.org> */ | |
1917 | ||
1918 | /* fpclass(): SysV, at least Solaris and some versions of IRIX. */ | |
758a5d79 | 1919 | #if !defined(Perl_fp_class) && (defined(HAS_FPCLASS)||defined(HAS_FPCLASSL)) |
25c46df8 JH |
1920 | /* Solaris and IRIX have fpclass/fpclassl, but they are using |
1921 | * an enum typedef, not cpp symbols, and Configure doesn't detect that. | |
1922 | * Define some symbols also as cpp symbols so we can detect them. */ | |
033a6f7a | 1923 | # if defined(__sun) || defined(__sgi) /* XXX Configure test instead */ |
25c46df8 JH |
1924 | # define FP_PINF FP_PINF |
1925 | # define FP_QNAN FP_QNAN | |
1926 | # endif | |
f279e099 | 1927 | # include <math.h> |
758a5d79 JH |
1928 | # ifdef I_IEEFP |
1929 | # include <ieeefp.h> | |
1930 | # endif | |
1931 | # ifdef I_FP | |
1932 | # include <fp.h> | |
1933 | # endif | |
1934 | # if defined(USE_LONG_DOUBLE) && defined(HAS_FPCLASSL) | |
f279e099 | 1935 | # define Perl_fp_class(x) fpclassl(x) |
758a5d79 | 1936 | # else |
f279e099 JH |
1937 | # define Perl_fp_class(x) fpclass(x) |
1938 | # endif | |
25c46df8 | 1939 | # if defined(FP_CLASS_PINF) && defined(FP_CLASS_SNAN) |
f279e099 JH |
1940 | # define Perl_fp_class_snan(x) (Perl_fp_class(x)==FP_CLASS_SNAN) |
1941 | # define Perl_fp_class_qnan(x) (Perl_fp_class(x)==FP_CLASS_QNAN) | |
1942 | # define Perl_fp_class_ninf(x) (Perl_fp_class(x)==FP_CLASS_NINF) | |
1943 | # define Perl_fp_class_pinf(x) (Perl_fp_class(x)==FP_CLASS_PINF) | |
1944 | # define Perl_fp_class_nnorm(x) (Perl_fp_class(x)==FP_CLASS_NNORM) | |
1945 | # define Perl_fp_class_pnorm(x) (Perl_fp_class(x)==FP_CLASS_PNORM) | |
1946 | # define Perl_fp_class_ndenorm(x) (Perl_fp_class(x)==FP_CLASS_NDENORM) | |
1947 | # define Perl_fp_class_pdenorm(x) (Perl_fp_class(x)==FP_CLASS_PDENORM) | |
1948 | # define Perl_fp_class_nzero(x) (Perl_fp_class(x)==FP_CLASS_NZERO) | |
1949 | # define Perl_fp_class_pzero(x) (Perl_fp_class(x)==FP_CLASS_PZERO) | |
25c46df8 | 1950 | # elif defined(FP_PINF) && defined(FP_QNAN) |
f279e099 JH |
1951 | # define Perl_fp_class_snan(x) (Perl_fp_class(x)==FP_SNAN) |
1952 | # define Perl_fp_class_qnan(x) (Perl_fp_class(x)==FP_QNAN) | |
1953 | # define Perl_fp_class_ninf(x) (Perl_fp_class(x)==FP_NINF) | |
1954 | # define Perl_fp_class_pinf(x) (Perl_fp_class(x)==FP_PINF) | |
1955 | # define Perl_fp_class_nnorm(x) (Perl_fp_class(x)==FP_NNORM) | |
1956 | # define Perl_fp_class_pnorm(x) (Perl_fp_class(x)==FP_PNORM) | |
1957 | # define Perl_fp_class_ndenorm(x) (Perl_fp_class(x)==FP_NDENORM) | |
1958 | # define Perl_fp_class_pdenorm(x) (Perl_fp_class(x)==FP_PDENORM) | |
1959 | # define Perl_fp_class_nzero(x) (Perl_fp_class(x)==FP_NZERO) | |
1960 | # define Perl_fp_class_pzero(x) (Perl_fp_class(x)==FP_PZERO) | |
25c46df8 JH |
1961 | # else |
1962 | # undef Perl_fp_class /* Unknown set of defines */ | |
758a5d79 | 1963 | # endif |
758a5d79 JH |
1964 | #endif |
1965 | ||
30404d48 JH |
1966 | /* fp_class(): Legacy: at least Tru64, some versions of IRIX. */ |
1967 | #if !defined(Perl_fp_class) && (defined(HAS_FP_CLASS)||defined(HAS_FP_CLASSL)) | |
758a5d79 JH |
1968 | # include <math.h> |
1969 | # if !defined(FP_SNAN) && defined(I_FP_CLASS) | |
1970 | # include <fp_class.h> | |
1971 | # endif | |
25c46df8 | 1972 | # if defined(FP_POS_INF) && defined(FP_QNAN) |
033a6f7a | 1973 | # ifdef __sgi /* XXX Configure test instead */ |
25c46df8 JH |
1974 | # ifdef USE_LONG_DOUBLE |
1975 | # define Perl_fp_class(x) fp_class_l(x) | |
1976 | # else | |
1977 | # define Perl_fp_class(x) fp_class_d(x) | |
1978 | # endif | |
f279e099 | 1979 | # else |
25c46df8 JH |
1980 | # if defined(USE_LONG_DOUBLE) && defined(HAS_FP_CLASSL) |
1981 | # define Perl_fp_class(x) fp_classl(x) | |
1982 | # else | |
1983 | # define Perl_fp_class(x) fp_class(x) | |
1984 | # endif | |
f279e099 | 1985 | # endif |
25c46df8 JH |
1986 | # if defined(FP_POS_INF) && defined(FP_QNAN) |
1987 | # define Perl_fp_class_snan(x) (Perl_fp_class(x)==FP_SNAN) | |
1988 | # define Perl_fp_class_qnan(x) (Perl_fp_class(x)==FP_QNAN) | |
1989 | # define Perl_fp_class_ninf(x) (Perl_fp_class(x)==FP_NEG_INF) | |
1990 | # define Perl_fp_class_pinf(x) (Perl_fp_class(x)==FP_POS_INF) | |
1991 | # define Perl_fp_class_nnorm(x) (Perl_fp_class(x)==FP_NEG_NORM) | |
1992 | # define Perl_fp_class_pnorm(x) (Perl_fp_class(x)==FP_POS_NORM) | |
1993 | # define Perl_fp_class_ndenorm(x) (Perl_fp_class(x)==FP_NEG_DENORM) | |
1994 | # define Perl_fp_class_pdenorm(x) (Perl_fp_class(x)==FP_POS_DENORM) | |
1995 | # define Perl_fp_class_nzero(x) (Perl_fp_class(x)==FP_NEG_ZERO) | |
1996 | # define Perl_fp_class_pzero(x) (Perl_fp_class(x)==FP_POS_ZERO) | |
30404d48 | 1997 | # else |
25c46df8 | 1998 | # undef Perl_fp_class /* Unknown set of defines */ |
30404d48 | 1999 | # endif |
f279e099 | 2000 | # endif |
30404d48 JH |
2001 | #endif |
2002 | ||
052758ae | 2003 | /* class(), _class(): Legacy: AIX. */ |
758a5d79 JH |
2004 | #if !defined(Perl_fp_class) && defined(HAS_CLASS) |
2005 | # include <math.h> | |
25c46df8 JH |
2006 | # if defined(FP_PLUS_NORM) && defined(FP_PLUS_INF) |
2007 | # ifndef _cplusplus | |
2008 | # define Perl_fp_class(x) class(x) | |
2009 | # else | |
2010 | # define Perl_fp_class(x) _class(x) | |
2011 | # endif | |
2012 | # if defined(FP_PLUS_INF) && defined(FP_NANQ) | |
2013 | # define Perl_fp_class_snan(x) (Perl_fp_class(x)==FP_NANS) | |
2014 | # define Perl_fp_class_qnan(x) (Perl_fp_class(x)==FP_NANQ) | |
2015 | # define Perl_fp_class_ninf(x) (Perl_fp_class(x)==FP_MINUS_INF) | |
2016 | # define Perl_fp_class_pinf(x) (Perl_fp_class(x)==FP_PLUS_INF) | |
2017 | # define Perl_fp_class_nnorm(x) (Perl_fp_class(x)==FP_MINUS_NORM) | |
2018 | # define Perl_fp_class_pnorm(x) (Perl_fp_class(x)==FP_PLUS_NORM) | |
2019 | # define Perl_fp_class_ndenorm(x) (Perl_fp_class(x)==FP_MINUS_DENORM) | |
2020 | # define Perl_fp_class_pdenorm(x) (Perl_fp_class(x)==FP_PLUS_DENORM) | |
2021 | # define Perl_fp_class_nzero(x) (Perl_fp_class(x)==FP_MINUS_ZERO) | |
2022 | # define Perl_fp_class_pzero(x) (Perl_fp_class(x)==FP_PLUS_ZERO) | |
2023 | # else | |
2024 | # undef Perl_fp_class /* Unknown set of defines */ | |
2025 | # endif | |
758a5d79 | 2026 | # endif |
30404d48 JH |
2027 | #endif |
2028 | ||
2029 | /* Win32: _fpclass(), _isnan(), _finite(). */ | |
796ea9ea JH |
2030 | #ifdef WIN32 |
2031 | # ifndef Perl_isnan | |
2032 | # define Perl_isnan(x) _isnan(x) | |
2033 | # endif | |
2034 | # ifndef Perl_isfinite | |
2035 | # define Perl_isfinite(x) _finite(x) | |
2036 | # endif | |
2037 | # ifndef Perl_fp_class_snan | |
25c46df8 JH |
2038 | /* No simple way to #define Perl_fp_class because _fpclass() |
2039 | * returns a set of bits. */ | |
796ea9ea JH |
2040 | # define Perl_fp_class_snan(x) (_fpclass(x) & _FPCLASS_SNAN) |
2041 | # define Perl_fp_class_qnan(x) (_fpclass(x) & _FPCLASS_QNAN) | |
82947af8 | 2042 | # define Perl_fp_class_nan(x) (_fpclass(x) & (_FPCLASS_SNAN|_FPCLASS_QNAN)) |
796ea9ea JH |
2043 | # define Perl_fp_class_ninf(x) (_fpclass(x) & _FPCLASS_NINF)) |
2044 | # define Perl_fp_class_pinf(x) (_fpclass(x) & _FPCLASS_PINF)) | |
2045 | # define Perl_fp_class_inf(x) (_fpclass(x) & (_FPCLASS_NINF|_FPCLASS_PINF)) | |
2046 | # define Perl_fp_class_nnorm(x) (_fpclass(x) & _FPCLASS_NN) | |
2047 | # define Perl_fp_class_pnorm(x) (_fpclass(x) & _FPCLASS_PN) | |
2048 | # define Perl_fp_class_norm(x) (_fpclass(x) & (_FPCLASS_NN|_FPCLASS_PN)) | |
2049 | # define Perl_fp_class_ndenorm(x) (_fpclass(x) & _FPCLASS_ND) | |
2050 | # define Perl_fp_class_pdenorm(x) (_fpclass(x) & _FPCLASS_PD) | |
2051 | # define Perl_fp_class_denorm(x) (_fpclass(x) & (_FPCLASS_ND|_FPCLASS_PD)) | |
2052 | # define Perl_fp_class_nzero(x) (_fpclass(x) & _FPCLASS_NZ) | |
2053 | # define Perl_fp_class_pzero(x) (_fpclass(x) & _FPCLASS_PZ) | |
2054 | # define Perl_fp_class_zero(x) (_fpclass(x) & (_FPCLASS_NZ|_FPCLASS_PZ)) | |
2055 | # endif | |
f279e099 JH |
2056 | #endif |
2057 | ||
2058 | #if !defined(Perl_fp_class_inf) && \ | |
2059 | defined(Perl_fp_class_pinf) && defined(Perl_fp_class_ninf) | |
2060 | # define Perl_fp_class_inf(x) \ | |
2061 | (Perl_fp_class_pinf(x) || Perl_fp_class_ninf(x)) | |
2062 | #endif | |
2063 | ||
2064 | #if !defined(Perl_fp_class_nan) && \ | |
2065 | defined(Perl_fp_class_snan) && defined(Perl_fp_class_qnan) | |
2066 | # define Perl_fp_class_nan(x) \ | |
2067 | (Perl_fp_class_snan(x) || Perl_fp_class_qnan(x)) | |
2068 | #endif | |
2069 | ||
2070 | #if !defined(Perl_fp_class_zero) && \ | |
2071 | defined(Perl_fp_class_pzero) && defined(Perl_fp_class_nzero) | |
2072 | # define Perl_fp_class_zero(x) \ | |
2073 | (Perl_fp_class_pzero(x) || Perl_fp_class_nzero(x)) | |
2074 | #endif | |
2075 | ||
2076 | #if !defined(Perl_fp_class_norm) && \ | |
2077 | defined(Perl_fp_class_pnorm) && defined(Perl_fp_class_nnorm) | |
2078 | # define Perl_fp_class_norm(x) \ | |
2079 | (Perl_fp_class_pnorm(x) || Perl_fp_class_nnorm(x)) | |
2080 | #endif | |
2081 | ||
2082 | #if !defined(Perl_fp_class_denorm) && \ | |
2083 | defined(Perl_fp_class_pdenorm) && defined(Perl_fp_class_ndenorm) | |
2084 | # define Perl_fp_class_denorm(x) \ | |
2085 | (Perl_fp_class_pdenorm(x) || Perl_fp_class_ndenorm(x)) | |
796ea9ea | 2086 | #endif |
758a5d79 | 2087 | |
1a322af2 JH |
2088 | #ifdef UNDER_CE |
2089 | int isnan(double d); | |
2090 | #endif | |
2091 | ||
758a5d79 | 2092 | #ifndef Perl_isnan |
1a322af2 JH |
2093 | # ifdef Perl_fp_class_nan |
2094 | # define Perl_isnan(x) Perl_fp_class_nan(x) | |
da5fdda8 AC |
2095 | # elif defined(HAS_UNORDERED) |
2096 | # define Perl_isnan(x) unordered((x), 0.0) | |
758a5d79 | 2097 | # else |
da5fdda8 | 2098 | # define Perl_isnan(x) ((x)!=(x)) |
758a5d79 JH |
2099 | # endif |
2100 | #endif | |
2101 | ||
1a322af2 JH |
2102 | #ifndef Perl_isinf |
2103 | # ifdef Perl_fp_class_inf | |
2104 | # define Perl_isinf(x) Perl_fp_class_inf(x) | |
2105 | # endif | |
ca6c63e1 JH |
2106 | #endif |
2107 | ||
758a5d79 | 2108 | #ifndef Perl_isfinite |
25c46df8 | 2109 | # if defined(HAS_ISFINITE) && !defined(isfinite) |
c496ca58 | 2110 | # define Perl_isfinite(x) isfinite((double)(x)) |
4efd38a4 | 2111 | # elif defined(HAS_FINITE) |
c496ca58 | 2112 | # define Perl_isfinite(x) finite((double)(x)) |
4efd38a4 JH |
2113 | # elif defined(Perl_fp_class_finite) |
2114 | # define Perl_isfinite(x) Perl_fp_class_finite(x) | |
758a5d79 | 2115 | # else |
c496ca58 JH |
2116 | /* For the infinities the multiplication returns nan, |
2117 | * for the nan the multiplication also returns nan, | |
2118 | * for everything else (that is, finite) zero should be returned. */ | |
4efd38a4 | 2119 | # define Perl_isfinite(x) (((x) * 0) == 0) |
a3540c92 | 2120 | # endif |
65202027 DS |
2121 | #endif |
2122 | ||
25c46df8 JH |
2123 | #ifndef Perl_isinf |
2124 | # if defined(Perl_isfinite) && defined(Perl_isnan) | |
2125 | # define Perl_isinf(x) !(Perl_isfinite(x)||Perl_isnan(x)) | |
2126 | # endif | |
2127 | #endif | |
2128 | ||
d3685250 JH |
2129 | /* We need Perl_isfinitel (ends with ell) (if available) even when |
2130 | * not USE_LONG_DOUBLE because the printf code (sv_catpvfn_flags) | |
2131 | * needs that. */ | |
2132 | #if defined(HAS_LONG_DOUBLE) && !defined(Perl_isfinitel) | |
2133 | /* If isfinite() is a macro and looks like we have C99, | |
2134 | * we assume it's the type-aware C99 isfinite(). */ | |
c06e9e3e | 2135 | # if defined(HAS_ISFINITE) && defined(isfinite) && defined(HAS_C99) |
d3685250 JH |
2136 | # define Perl_isfinitel(x) isfinite(x) |
2137 | # elif defined(HAS_ISFINITEL) | |
2138 | # define Perl_isfinitel(x) isfinitel(x) | |
2139 | # elif defined(HAS_FINITEL) | |
2140 | # define Perl_isfinitel(x) finitel(x) | |
2141 | # elif defined(HAS_INFL) && defined(HAS_NANL) | |
2142 | # define Perl_isfinitel(x) !(isinfl(x)||isnanl(x)) | |
16334e6e | 2143 | # else |
99bf9e32 | 2144 | # define Perl_isfinitel(x) ((x) * 0 == 0) /* See Perl_isfinite. */ |
d3685250 JH |
2145 | # endif |
2146 | #endif | |
2147 | ||
a36244b7 JH |
2148 | /* The default is to use Perl's own atof() implementation (in numeric.c). |
2149 | * Usually that is the one to use but for some platforms (e.g. UNICOS) | |
2150 | * it is however best to use the native implementation of atof. | |
2151 | * You can experiment with using your native one by -DUSE_PERL_ATOF=0. | |
2152 | * Some good tests to try out with either setting are t/base/num.t, | |
205f51d8 AS |
2153 | * t/op/numconvert.t, and t/op/pack.t. Note that if using long doubles |
2154 | * you may need to be using a different function than atof! */ | |
a36244b7 JH |
2155 | |
2156 | #ifndef USE_PERL_ATOF | |
2157 | # ifndef _UNICOS | |
2158 | # define USE_PERL_ATOF | |
2159 | # endif | |
2160 | #else | |
2161 | # if USE_PERL_ATOF == 0 | |
2162 | # undef USE_PERL_ATOF | |
2163 | # endif | |
2164 | #endif | |
2165 | ||
2166 | #ifdef USE_PERL_ATOF | |
2167 | # define Perl_atof(s) Perl_my_atof(s) | |
2168 | # define Perl_atof2(s, n) Perl_my_atof2(aTHX_ (s), &(n)) | |
2169 | #else | |
2170 | # define Perl_atof(s) (NV)atof(s) | |
2171 | # define Perl_atof2(s, n) ((n) = atof(s)) | |
2172 | #endif | |
cf2093f6 | 2173 | |
99abf803 | 2174 | /* |
2175 | * CHAR_MIN and CHAR_MAX are not included here, as the (char) type may be | |
2176 | * ambiguous. It may be equivalent to (signed char) or (unsigned char) | |
2177 | * depending on local options. Until Configure detects this (or at least | |
2178 | * detects whether the "signed" keyword is available) the CHAR ranges | |
2179 | * will not be included. UCHAR functions normally. | |
2180 | * - kja | |
2181 | */ | |
27d4fb96 | 2182 | |
6ec488b3 AC |
2183 | #define PERL_UCHAR_MIN ((unsigned char)0) |
2184 | #define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX) | |
27d4fb96 | 2185 | |
6ec488b3 AC |
2186 | #define PERL_USHORT_MIN ((unsigned short)0) |
2187 | #define PERL_USHORT_MAX ((unsigned short)USHRT_MAX) | |
27d4fb96 | 2188 | |
6ec488b3 AC |
2189 | #define PERL_SHORT_MAX ((short)SHRT_MAX) |
2190 | #define PERL_SHORT_MIN ((short)SHRT_MIN) | |
27d4fb96 | 2191 | |
6ec488b3 | 2192 | #define PERL_UINT_MAX ((unsigned int)UINT_MAX) |
99abf803 | 2193 | #define PERL_UINT_MIN ((unsigned int)0) |
27d4fb96 | 2194 | |
6ec488b3 AC |
2195 | #define PERL_INT_MAX ((int)INT_MAX) |
2196 | #define PERL_INT_MIN ((int)INT_MIN) | |
27d4fb96 | 2197 | |
6ec488b3 | 2198 | #define PERL_ULONG_MAX ((unsigned long)ULONG_MAX) |
99abf803 | 2199 | #define PERL_ULONG_MIN ((unsigned long)0L) |
27d4fb96 | 2200 | |
6ec488b3 AC |
2201 | #define PERL_LONG_MAX ((long)LONG_MAX) |
2202 | #define PERL_LONG_MIN ((long)LONG_MIN) | |
760ac839 | 2203 | |
d7d93a81 | 2204 | #ifdef UV_IS_QUAD |
99abf803 | 2205 | # define PERL_UQUAD_MAX (~(UV)0) |
f1c3b19a | 2206 | # define PERL_UQUAD_MIN ((UV)0) |
99abf803 | 2207 | # define PERL_QUAD_MAX ((IV) (PERL_UQUAD_MAX >> 1)) |
a6e633de | 2208 | # define PERL_QUAD_MIN (-PERL_QUAD_MAX - ((3 & -1) == 3)) |
79072805 LW |
2209 | #endif |
2210 | ||
ee0007ab | 2211 | typedef MEM_SIZE STRLEN; |
450a55e4 | 2212 | |
79072805 LW |
2213 | typedef struct op OP; |
2214 | typedef struct cop COP; | |
2215 | typedef struct unop UNOP; | |
2f7c6295 | 2216 | typedef struct unop_aux UNOP_AUX; |
79072805 LW |
2217 | typedef struct binop BINOP; |
2218 | typedef struct listop LISTOP; | |
2219 | typedef struct logop LOGOP; | |
79072805 LW |
2220 | typedef struct pmop PMOP; |
2221 | typedef struct svop SVOP; | |
7934575e | 2222 | typedef struct padop PADOP; |
79072805 | 2223 | typedef struct pvop PVOP; |
79072805 | 2224 | typedef struct loop LOOP; |
b46e009d | 2225 | typedef struct methop METHOP; |
79072805 | 2226 | |
7aef8e5b | 2227 | #ifdef PERL_CORE |
8be227ab FC |
2228 | typedef struct opslab OPSLAB; |
2229 | typedef struct opslot OPSLOT; | |
2230 | #endif | |
2231 | ||
52db365a | 2232 | typedef struct block_hooks BHK; |
1830b3d9 | 2233 | typedef struct custom_op XOP; |
52db365a | 2234 | |
cd1541b2 NC |
2235 | typedef struct interpreter PerlInterpreter; |
2236 | ||
d2b3f365 | 2237 | /* SGI's <sys/sema.h> has struct sv */ |
cc3315ba | 2238 | #if defined(__sgi) |
d2b3f365 | 2239 | # define STRUCT_SV perl_sv |
b8d3c5db JH |
2240 | #else |
2241 | # define STRUCT_SV sv | |
2242 | #endif | |
2243 | typedef struct STRUCT_SV SV; | |
79072805 LW |
2244 | typedef struct av AV; |
2245 | typedef struct hv HV; | |
2246 | typedef struct cv CV; | |
d2f13c59 | 2247 | typedef struct p5rx REGEXP; |
79072805 | 2248 | typedef struct gp GP; |
0c30d9ec | 2249 | typedef struct gv GV; |
8990e307 | 2250 | typedef struct io IO; |
c09156bb | 2251 | typedef struct context PERL_CONTEXT; |
79072805 LW |
2252 | typedef struct block BLOCK; |
2253 | ||
2254 | typedef struct magic MAGIC; | |
2255 | typedef struct xpv XPV; | |
2256 | typedef struct xpviv XPVIV; | |
ff68c719 | 2257 | typedef struct xpvuv XPVUV; |
79072805 LW |
2258 | typedef struct xpvnv XPVNV; |
2259 | typedef struct xpvmg XPVMG; | |
2260 | typedef struct xpvlv XPVLV; | |
d361b004 | 2261 | typedef struct xpvinvlist XINVLIST; |
79072805 LW |
2262 | typedef struct xpvav XPVAV; |
2263 | typedef struct xpvhv XPVHV; | |
2264 | typedef struct xpvgv XPVGV; | |
2265 | typedef struct xpvcv XPVCV; | |
2266 | typedef struct xpvbm XPVBM; | |
2267 | typedef struct xpvfm XPVFM; | |
8990e307 | 2268 | typedef struct xpvio XPVIO; |
79072805 LW |
2269 | typedef struct mgvtbl MGVTBL; |
2270 | typedef union any ANY; | |
5f7fde29 GS |
2271 | typedef struct ptr_tbl_ent PTR_TBL_ENT_t; |
2272 | typedef struct ptr_tbl PTR_TBL_t; | |
8cf8f3d1 NIS |
2273 | typedef struct clone_params CLONE_PARAMS; |
2274 | ||
0f94cb1f | 2275 | /* a pad is currently just an AV; but that might change, |
7261499d FC |
2276 | * so hide the type. */ |
2277 | typedef struct padlist PADLIST; | |
67634234 | 2278 | typedef AV PAD; |
9b7476d7 | 2279 | typedef struct padnamelist PADNAMELIST; |
0f94cb1f | 2280 | typedef struct padname PADNAME; |
67634234 | 2281 | |
5d32d268 DM |
2282 | /* enable PERL_OP_PARENT by default */ |
2283 | #if !defined(PERL_OP_PARENT) && !defined(PERL_NO_OP_PARENT) | |
2284 | # define PERL_OP_PARENT | |
2285 | #endif | |
2286 | ||
93c10d60 FC |
2287 | /* enable PERL_COPY_ON_WRITE by default */ |
2288 | #if !defined(PERL_COPY_ON_WRITE) && !defined(PERL_NO_COW) | |
2289 | # define PERL_COPY_ON_WRITE | |
13b0f67d | 2290 | #endif |
07d01d6e | 2291 | |
93c10d60 | 2292 | #ifdef PERL_COPY_ON_WRITE |
db2c6cb3 | 2293 | # define PERL_ANY_COW |
9f351b45 DM |
2294 | #else |
2295 | # define PERL_SAWAMPERSAND | |
db2c6cb3 FC |
2296 | #endif |
2297 | ||
40653c20 FC |
2298 | #if defined(PERL_DEBUG_READONLY_OPS) && !defined(USE_ITHREADS) |
2299 | # error PERL_DEBUG_READONLY_OPS only works with ithreads | |
2300 | #endif | |
2301 | ||
378cc40b | 2302 | #include "handy.h" |
64935bc6 | 2303 | #include "charclass_invlists.h" |
a0d0e21e | 2304 | |
6b8eaf93 | 2305 | #if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_RAWIO) |
6b8eaf93 JH |
2306 | # if LSEEKSIZE == 8 && !defined(USE_64_BIT_RAWIO) |
2307 | # define USE_64_BIT_RAWIO /* implicit */ | |
2308 | # endif | |
4564133c JH |
2309 | #endif |
2310 | ||
6b8eaf93 JH |
2311 | /* Notice the use of HAS_FSEEKO: now we are obligated to always use |
2312 | * fseeko/ftello if possible. Don't go #defining ftell to ftello yourself, | |
2313 | * however, because operating systems like to do that themself. */ | |
2314 | #ifndef FSEEKSIZE | |
2315 | # ifdef HAS_FSEEKO | |
2316 | # define FSEEKSIZE LSEEKSIZE | |
2317 | # else | |
2318 | # define FSEEKSIZE LONGSIZE | |
d460ef45 | 2319 | # endif |
6b8eaf93 JH |
2320 | #endif |
2321 | ||
2322 | #if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_STDIO) | |
6b8eaf93 JH |
2323 | # if FSEEKSIZE == 8 && !defined(USE_64_BIT_STDIO) |
2324 | # define USE_64_BIT_STDIO /* implicit */ | |
2325 | # endif | |
2326 | #endif | |
4564133c | 2327 | |
09458382 | 2328 | #ifdef USE_64_BIT_RAWIO |
d9b3e12d JH |
2329 | # ifdef HAS_OFF64_T |
2330 | # undef Off_t | |
2331 | # define Off_t off64_t | |
2332 | # undef LSEEKSIZE | |
2333 | # define LSEEKSIZE 8 | |
5ff3f7a4 | 2334 | # endif |
d9b3e12d JH |
2335 | /* Most 64-bit environments have defines like _LARGEFILE_SOURCE that |
2336 | * will trigger defines like the ones below. Some 64-bit environments, | |
09458382 | 2337 | * however, do not. Therefore we have to explicitly mix and match. */ |
d9b3e12d JH |
2338 | # if defined(USE_OPEN64) |
2339 | # define open open64 | |
5ff3f7a4 | 2340 | # endif |
d9b3e12d JH |
2341 | # if defined(USE_LSEEK64) |
2342 | # define lseek lseek64 | |
6b8eaf93 JH |
2343 | # else |
2344 | # if defined(USE_LLSEEK) | |
2345 | # define lseek llseek | |
2346 | # endif | |
d9b3e12d JH |
2347 | # endif |
2348 | # if defined(USE_STAT64) | |
2349 | # define stat stat64 | |
2350 | # endif | |
2351 | # if defined(USE_FSTAT64) | |
2352 | # define fstat fstat64 | |
2353 | # endif | |
2354 | # if defined(USE_LSTAT64) | |
2355 | # define lstat lstat64 | |
2356 | # endif | |
2357 | # if defined(USE_FLOCK64) | |
2358 | # define flock flock64 | |
2359 | # endif | |
2360 | # if defined(USE_LOCKF64) | |
2361 | # define lockf lockf64 | |
2362 | # endif | |
2363 | # if defined(USE_FCNTL64) | |
2364 | # define fcntl fcntl64 | |
2365 | # endif | |
2366 | # if defined(USE_TRUNCATE64) | |
2367 | # define truncate truncate64 | |
2368 | # endif | |
2369 | # if defined(USE_FTRUNCATE64) | |
2370 | # define ftruncate ftruncate64 | |
2371 | # endif | |
2372 | #endif | |
2373 | ||
2374 | #ifdef USE_64_BIT_STDIO | |
2375 | # ifdef HAS_FPOS64_T | |
2376 | # undef Fpos_t | |
2377 | # define Fpos_t fpos64_t | |
2378 | # endif | |
2379 | /* Most 64-bit environments have defines like _LARGEFILE_SOURCE that | |
2380 | * will trigger defines like the ones below. Some 64-bit environments, | |
2381 | * however, do not. */ | |
2382 | # if defined(USE_FOPEN64) | |
2383 | # define fopen fopen64 | |
2384 | # endif | |
2385 | # if defined(USE_FSEEK64) | |
6b8eaf93 | 2386 | # define fseek fseek64 /* don't do fseeko here, see perlio.c */ |
d9b3e12d JH |
2387 | # endif |
2388 | # if defined(USE_FTELL64) | |
6b8eaf93 | 2389 | # define ftell ftell64 /* don't do ftello here, see perlio.c */ |
d9b3e12d JH |
2390 | # endif |
2391 | # if defined(USE_FSETPOS64) | |
2392 | # define fsetpos fsetpos64 | |
2393 | # endif | |
2394 | # if defined(USE_FGETPOS64) | |
2395 | # define fgetpos fgetpos64 | |
2396 | # endif | |
2397 | # if defined(USE_TMPFILE64) | |
2398 | # define tmpfile tmpfile64 | |
2399 | # endif | |
2400 | # if defined(USE_FREOPEN64) | |
2401 | # define freopen freopen64 | |
5ff3f7a4 GS |
2402 | # endif |
2403 | #endif | |
2404 | ||
e37778c2 | 2405 | #if defined(OS2) |
2c2d71f5 JH |
2406 | # include "iperlsys.h" |
2407 | #endif | |
2408 | ||
748a9306 | 2409 | #ifdef DOSISH |
19848b3f JH |
2410 | # if defined(OS2) |
2411 | # include "os2ish.h" | |
2412 | # else | |
2413 | # include "dosish.h" | |
2414 | # endif | |
009819bb | 2415 | #elif defined(VMS) |
748a9306 | 2416 | # include "vmsish.h" |
009819bb | 2417 | #elif defined(PLAN9) |
19848b3f | 2418 | # include "./plan9/plan9ish.h" |
009819bb | 2419 | #elif defined(__VOS__) |
196918b0 PG |
2420 | # ifdef __GNUC__ |
2421 | # include "./vos/vosish.h" | |
2422 | # else | |
2423 | # include "vos/vosish.h" | |
2424 | # endif | |
009819bb | 2425 | #elif defined(__SYMBIAN32__) |
27da23d5 | 2426 | # include "symbian/symbianish.h" |
009819bb | 2427 | #elif defined(__HAIKU__) |
df00ff3b | 2428 | # include "haiku/haikuish.h" |
009819bb | 2429 | #else |
19848b3f | 2430 | # include "unixish.h" |
13b6e58c JH |
2431 | #endif |
2432 | ||
ea34f6bd | 2433 | #ifdef __amigaos4__ |
3c0208ad AB |
2434 | # include "amigaos.h" |
2435 | # undef FD_CLOEXEC /* a lie in AmigaOS */ | |
2436 | #endif | |
2437 | ||
2946a158 | 2438 | /* NSIG logic from Configure --> */ |
2946a158 JH |
2439 | #ifndef NSIG |
2440 | # ifdef _NSIG | |
2441 | # define NSIG (_NSIG) | |
da5fdda8 | 2442 | # elif defined(SIGMAX) |
2946a158 | 2443 | # define NSIG (SIGMAX+1) |
da5fdda8 | 2444 | # elif defined(SIG_MAX) |
2946a158 | 2445 | # define NSIG (SIG_MAX+1) |
da5fdda8 | 2446 | # elif defined(_SIG_MAX) |
2946a158 | 2447 | # define NSIG (_SIG_MAX+1) |
da5fdda8 | 2448 | # elif defined(MAXSIG) |
2946a158 | 2449 | # define NSIG (MAXSIG+1) |
da5fdda8 | 2450 | # elif defined(MAX_SIG) |
2946a158 | 2451 | # define NSIG (MAX_SIG+1) |
da5fdda8 | 2452 | # elif defined(SIGARRAYSIZE) |
2946a158 | 2453 | # define NSIG SIGARRAYSIZE /* Assume ary[SIGARRAYSIZE] */ |
da5fdda8 | 2454 | # elif defined(_sys_nsig) |
2946a158 | 2455 | # define NSIG (_sys_nsig) /* Solaris 2.5 */ |
da5fdda8 AC |
2456 | # else |
2457 | /* Default to some arbitrary number that's big enough to get most | |
2458 | * of the common signals. */ | |
2946a158 | 2459 | # define NSIG 50 |
da5fdda8 | 2460 | # endif |
2946a158 JH |
2461 | #endif |
2462 | /* <-- NSIG logic from Configure */ | |
2463 | ||
13b6e58c JH |
2464 | #ifndef NO_ENVIRON_ARRAY |
2465 | # define USE_ENVIRON_ARRAY | |
2466 | #endif | |
32f822de | 2467 | |
c77b533b JH |
2468 | /* |
2469 | * initialise to avoid floating-point exceptions from overflow, etc | |
2470 | */ | |
2471 | #ifndef PERL_FPU_INIT | |
2472 | # ifdef HAS_FPSETMASK | |
2473 | # if HAS_FLOATINGPOINT_H | |
2474 | # include <floatingpoint.h> | |
2475 | # endif | |
ad3a8c67 NC |
2476 | /* Some operating systems have this as a macro, which in turn expands to a comma |
2477 | expression, and the last sub-expression is something that gets calculated, | |
2478 | and then they have the gall to warn that a value computed is not used. Hence | |
2479 | cast to void. */ | |
2480 | # define PERL_FPU_INIT (void)fpsetmask(0) | |
da5fdda8 AC |
2481 | # elif defined(SIGFPE) && defined(SIG_IGN) && !defined(PERL_MICRO) |
2482 | # define PERL_FPU_INIT PL_sigfpe_saved = (Sighandler_t) signal(SIGFPE, SIG_IGN) | |
2483 | # define PERL_FPU_PRE_EXEC { Sigsave_t xfpe; rsignal_save(SIGFPE, PL_sigfpe_saved, &xfpe); | |
2484 | # define PERL_FPU_POST_EXEC rsignal_restore(SIGFPE, &xfpe); } | |
c77b533b | 2485 | # else |
da5fdda8 | 2486 | # define PERL_FPU_INIT |
c77b533b JH |
2487 | # endif |
2488 | #endif | |
b35112e7 CS |
2489 | #ifndef PERL_FPU_PRE_EXEC |
2490 | # define PERL_FPU_PRE_EXEC { | |
2491 | # define PERL_FPU_POST_EXEC } | |
2492 | #endif | |
c77b533b | 2493 | |
a308b05a JH |
2494 | /* In Tru64 the cc -ieee enables the IEEE math but disables traps. |
2495 | * We need to reenable the "invalid" trap because otherwise generation | |
2496 | * of NaN values leaves the IEEE fp flags in bad state, leaving any further | |
2497 | * fp ops behaving strangely (Inf + 1 resulting in zero, for example). */ | |
2498 | #ifdef __osf__ | |
2499 | # include <machine/fpu.h> | |
2500 | # define PERL_SYS_FPU_INIT \ | |
2501 | STMT_START { \ | |
2502 | ieee_set_fp_control(IEEE_TRAP_ENABLE_INV); \ | |
2503 | signal(SIGFPE, SIG_IGN); \ | |
2504 | } STMT_END | |
2505 | #endif | |
94a08944 JH |
2506 | /* In IRIX the default for Flush to Zero bit is true, |
2507 | * which means that results going below the minimum of normal | |
2508 | * floating points go to zero, instead of going denormal/subnormal. | |
2509 | * This is unlike almost any other system running Perl, so let's clear it. | |
2510 | * [perl #123767] IRIX64 blead (ddce084a) opbasic/arith.t failure, originally | |
2511 | * [perl #120426] small numbers shouldn't round to zero if they have extra floating digits | |
2512 | * | |
2513 | * XXX The flush-to-zero behaviour should be a Configure scan. | |
2514 | * To change the behaviour usually requires some system-specific | |
2515 | * incantation, though, like the below. */ | |
2516 | #ifdef __sgi | |
2517 | # include <sys/fpu.h> | |
2518 | # define PERL_SYS_FPU_INIT \ | |
2519 | STMT_START { \ | |
2520 | union fpc_csr csr; \ | |
2521 | csr.fc_word = get_fpc_csr(); \ | |
2522 | csr.fc_struct.flush = 0; \ | |
2523 | set_fpc_csr(csr.fc_word); \ | |
2524 | } STMT_END | |
2525 | #endif | |
a308b05a JH |
2526 | |
2527 | #ifndef PERL_SYS_FPU_INIT | |
2528 | # define PERL_SYS_FPU_INIT NOOP | |
2529 | #endif | |
2530 | ||
cbec8ebe DM |
2531 | #ifndef PERL_SYS_INIT3_BODY |
2532 | # define PERL_SYS_INIT3_BODY(argvp,argcp,envp) PERL_SYS_INIT_BODY(argvp,argcp) | |
ed344e4f IZ |
2533 | #endif |
2534 | ||
eb533572 | 2535 | /* |
dcccc8ff KW |
2536 | =head1 Miscellaneous Functions |
2537 | ||
4ad9e498 | 2538 | =for apidoc Am|void|PERL_SYS_INIT|int *argc|char*** argv |
eb533572 | 2539 | Provides system-specific tune up of the C runtime environment necessary to |
72d33970 | 2540 | run Perl interpreters. This should be called only once, before creating |
eb533572 DM |
2541 | any Perl interpreters. |
2542 | ||
4ad9e498 | 2543 | =for apidoc Am|void|PERL_SYS_INIT3|int *argc|char*** argv|char*** env |
eb533572 | 2544 | Provides system-specific tune up of the C runtime environment necessary to |
72d33970 | 2545 | run Perl interpreters. This should be called only once, before creating |
eb533572 DM |
2546 | any Perl interpreters. |
2547 | ||
2548 | =for apidoc Am|void|PERL_SYS_TERM| | |
2549 | Provides system-specific clean up of the C runtime environment after | |
72d33970 | 2550 | running Perl interpreters. This should be called only once, after |
eb533572 DM |
2551 | freeing any remaining Perl interpreters. |
2552 | ||
2553 | =cut | |
2554 | */ | |
2555 | ||
cbec8ebe DM |
2556 | #define PERL_SYS_INIT(argc, argv) Perl_sys_init(argc, argv) |
2557 | #define PERL_SYS_INIT3(argc, argv, env) Perl_sys_init3(argc, argv, env) | |
d0820ef1 | 2558 | #define PERL_SYS_TERM() Perl_sys_term() |
cbec8ebe | 2559 | |
be708cc0 JH |
2560 | #ifndef PERL_WRITE_MSG_TO_CONSOLE |
2561 | # define PERL_WRITE_MSG_TO_CONSOLE(io, msg, len) PerlIO_write(io, msg, len) | |
2562 | #endif | |
2563 | ||
0f31cffe GS |
2564 | #ifndef MAXPATHLEN |
2565 | # ifdef PATH_MAX | |
b990c8b2 JH |
2566 | # ifdef _POSIX_PATH_MAX |
2567 | # if PATH_MAX > _POSIX_PATH_MAX | |
09448d78 JH |
2568 | /* POSIX 1990 (and pre) was ambiguous about whether PATH_MAX |
2569 | * included the null byte or not. Later amendments of POSIX, | |
2570 | * XPG4, the Austin Group, and the Single UNIX Specification | |
2571 | * all explicitly include the null byte in the PATH_MAX. | |
2572 | * Ditto for _POSIX_PATH_MAX. */ | |
2573 | # define MAXPATHLEN PATH_MAX | |
b990c8b2 | 2574 | # else |
09448d78 | 2575 | # define MAXPATHLEN _POSIX_PATH_MAX |
b990c8b2 JH |
2576 | # endif |
2577 | # else | |
2578 | # define MAXPATHLEN (PATH_MAX+1) | |
2579 | # endif | |
0f31cffe | 2580 | # else |
d552bce8 | 2581 | # define MAXPATHLEN 1024 /* Err on the large side. */ |
0f31cffe GS |
2582 | # endif |
2583 | #endif | |
2584 | ||
c80263a8 SH |
2585 | /* In case Configure was not used (we are using a "canned config" |
2586 | * such as Win32, or a cross-compilation setup, for example) try going | |
2587 | * by the gcc major and minor versions. One useful URL is | |
2588 | * http://www.ohse.de/uwe/articles/gcc-attributes.html, | |
2589 | * but contrary to this information warn_unused_result seems | |
2590 | * not to be in gcc 3.3.5, at least. --jhi | |
42bf5550 AD |
2591 | * Also, when building extensions with an installed perl, this allows |
2592 | * the user to upgrade gcc and get the right attributes, rather than | |
2593 | * relying on the list generated at Configure time. --AD | |
c80263a8 SH |
2594 | * Set these up now otherwise we get confused when some of the <*thread.h> |
2595 | * includes below indirectly pull in <perlio.h> (which needs to know if we | |
2596 | * have HASATTRIBUTE_FORMAT). | |
2597 | */ | |
2598 | ||
4d7c7898 | 2599 | #ifndef PERL_MICRO |
fc2007d4 | 2600 | #if defined __GNUC__ && !defined(__INTEL_COMPILER) |
6a387721 RGS |
2601 | # if __GNUC__ == 3 && __GNUC_MINOR__ >= 1 || __GNUC__ > 3 /* 3.1 -> */ |
2602 | # define HASATTRIBUTE_DEPRECATED | |
2603 | # endif | |
c80263a8 SH |
2604 | # if __GNUC__ >= 3 /* 3.0 -> */ /* XXX Verify this version */ |
2605 | # define HASATTRIBUTE_FORMAT | |
63cdf24b SH |
2606 | # if defined __MINGW32__ |
2607 | # define PRINTF_FORMAT_NULL_OK | |
2608 | # endif | |
c80263a8 SH |
2609 | # endif |
2610 | # if __GNUC__ >= 3 /* 3.0 -> */ | |
2611 | # define HASATTRIBUTE_MALLOC | |
2612 | # endif | |
2613 | # if __GNUC__ == 3 && __GNUC_MINOR__ >= 3 || __GNUC__ > 3 /* 3.3 -> */ | |
2614 | # define HASATTRIBUTE_NONNULL | |
2615 | # endif | |
2616 | # if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 || __GNUC__ > 2 /* 2.5 -> */ | |
2617 | # define HASATTRIBUTE_NORETURN | |
2618 | # endif | |
2619 | # if __GNUC__ >= 3 /* gcc 3.0 -> */ | |
2620 | # define HASATTRIBUTE_PURE | |
2621 | # endif | |
42bf5550 | 2622 | # if __GNUC__ == 3 && __GNUC_MINOR__ >= 4 || __GNUC__ > 3 /* 3.4 -> */ |
c80263a8 SH |
2623 | # define HASATTRIBUTE_UNUSED |
2624 | # endif | |
d324fe49 AD |
2625 | # if __GNUC__ == 3 && __GNUC_MINOR__ == 3 && !defined(__cplusplus) |
2626 | # define HASATTRIBUTE_UNUSED /* gcc-3.3, but not g++-3.3. */ | |
2627 | # endif | |
c80263a8 SH |
2628 | # if __GNUC__ == 3 && __GNUC_MINOR__ >= 4 || __GNUC__ > 3 /* 3.4 -> */ |
2629 | # define HASATTRIBUTE_WARN_UNUSED_RESULT | |
2630 | # endif | |
2631 | #endif | |
00f254e2 | 2632 | #endif /* #ifndef PERL_MICRO */ |
c80263a8 | 2633 | |
3db8f154 | 2634 | /* USE_5005THREADS needs to be after unixish.h as <pthread.h> includes |
dd96f567 | 2635 | * <sys/signal.h> which defines NSIG - which will stop inclusion of <signal.h> |
32f822de GS |
2636 | * this results in many functions being undeclared which bothers C++ |
2637 | * May make sense to have threads after "*ish.h" anyway | |
2638 | */ | |
2639 | ||
3baee7cc JH |
2640 | /* clang Thread Safety Analysis/Annotations/Attributes |
2641 | * http://clang.llvm.org/docs/ThreadSafetyAnalysis.html | |
2642 | * | |
bdc795f4 | 2643 | * Available since clang 3.6-ish (appeared in 3.4, but shaky still in 3.5). |
3baee7cc | 2644 | * Apple XCode hijacks __clang_major__ and __clang_minor__ |
bdc795f4 JH |
2645 | * (6.1 means really clang 3.6), so needs extra hijinks |
2646 | * (could probably also test the contents of __apple_build_version__). | |
3baee7cc JH |
2647 | */ |
2648 | #if defined(USE_ITHREADS) && defined(I_PTHREAD) && \ | |
2649 | defined(__clang__) && \ | |
ab0fe36e DM |
2650 | !defined(PERL_GLOBAL_STRUCT) && \ |
2651 | !defined(PERL_GLOBAL_STRUCT_PRIVATE) && \ | |
3baee7cc JH |
2652 | !defined(SWIG) && \ |
2653 | ((!defined(__apple_build_version__) && \ | |
bdc795f4 | 2654 | ((__clang_major__ == 3 && __clang_minor__ >= 6) || \ |
8412ccf9 | 2655 | (__clang_major__ >= 4))) || \ |
3baee7cc | 2656 | (defined(__apple_build_version__) && \ |
bdc795f4 JH |
2657 | ((__clang_major__ == 6 && __clang_minor__ >= 1) || \ |
2658 | (__clang_major__ >= 7)))) | |
3baee7cc JH |
2659 | # define PERL_TSA__(x) __attribute__((x)) |
2660 | # define PERL_TSA_ACTIVE | |
2661 | #else | |
2662 | # define PERL_TSA__(x) /* No TSA, make TSA attributes no-ops. */ | |
2663 | # undef PERL_TSA_ACTIVE | |
2664 | #endif | |
2665 | ||
2666 | /* PERL_TSA_CAPABILITY() is used to annotate typedefs. | |
2667 | * typedef old_type PERL_TSA_CAPABILITY("mutex") new_type; | |
2668 | */ | |
2669 | #define PERL_TSA_CAPABILITY(x) \ | |
2670 | PERL_TSA__(capability(x)) | |
2671 | ||
2672 | /* In the below examples the mutex must be lexically visible, usually | |
2673 | * either as global variables, or as function arguments. */ | |
2674 | ||
2675 | /* PERL_TSA_GUARDED_BY() is used to annotate global variables. | |
2676 | * | |
2677 | * Foo foo PERL_TSA_GUARDED_BY(mutex); | |
2678 | */ | |
2679 | #define PERL_TSA_GUARDED_BY(x) \ | |
2680 | PERL_TSA__(guarded_by(x)) | |
2681 | ||
2682 | /* PERL_TSA_PT_GUARDED_BY() is used to annotate global pointers. | |
2683 | * The data _behind_ the pointer is guarded. | |
2684 | * | |
2685 | * Foo* ptr PERL_TSA_PT_GUARDED_BY(mutex); | |
2686 | */ | |
2687 | #define PERL_TSA_PT_GUARDED_BY(x) \ | |
2688 | PERL_TSA__(pt_guarded_by(x)) | |
2689 | ||
2690 | /* PERL_TSA_REQUIRES() is used to annotate functions. | |
2691 | * The caller MUST hold the resource when calling the function. | |
2692 | * | |
2693 | * void Foo() PERL_TSA_REQUIRES(mutex); | |
2694 | */ | |
2695 | #define PERL_TSA_REQUIRES(x) \ | |
2696 | PERL_TSA__(requires_capability(x)) | |
2697 | ||
2698 | /* PERL_TSA_EXCLUDES() is used to annotate functions. | |
2699 | * The caller MUST NOT hold resource when calling the function. | |
2700 | * | |
2701 | * EXCLUDES should be used when the function first acquires | |
2702 | * the resource and then releases it. Use to avoid deadlock. | |
2703 | * | |
2704 | * void Foo() PERL_TSA_EXCLUDES(mutex); | |
2705 | */ | |
2706 | #define PERL_TSA_EXCLUDES(x) \ | |
2707 | PERL_TSA__(locks_excluded(x)) | |
2708 | ||
2709 | /* PERL_TSA_ACQUIRE() is used to annotate functions. | |
2710 | * The caller MUST NOT hold the resource when calling the function, | |
2711 | * and the function will acquire the resource. | |
2712 | * | |
2713 | * void Foo() PERL_TSA_ACQUIRE(mutex); | |
2714 | */ | |
2715 | #define PERL_TSA_ACQUIRE(x) \ | |
2716 | PERL_TSA__(acquire_capability(x)) | |
2717 | ||
2718 | /* PERL_TSA_RELEASE() is used to annotate functions. | |
2719 | * The caller MUST hold the resource when calling the function, | |
2720 | * and the function will release the resource. | |
2721 | * | |
2722 | * void Foo() PERL_TSA_RELEASE(mutex); | |
2723 | */ | |
2724 | #define PERL_TSA_RELEASE(x) \ | |
2725 | PERL_TSA__(release_capability(x)) | |
2726 | ||
2727 | /* PERL_TSA_NO_TSA is used to annotate functions. | |
2728 | * Used when being intentionally unsafe, or when the code is too | |
2729 | * complicated for the analysis. Use sparingly. | |
2730 | * | |
2731 | * void Foo() PERL_TSA_NO_TSA; | |
2732 | */ | |
2733 | #define PERL_TSA_NO_TSA \ | |
2734 | PERL_TSA__(no_thread_safety_analysis) | |
2735 | ||
2736 | /* There are more annotations/attributes available, see the clang | |
2737 | * documentation for details. */ | |
2738 | ||
3db8f154 | 2739 | #if defined(USE_ITHREADS) |
2986a63f | 2740 | # ifdef NETWARE |
da5fdda8 AC |
2741 | # include <nw5thread.h> |
2742 | # elif defined(WIN32) | |
2743 | # include <win32thread.h> | |
2744 | # elif defined(OS2) | |
2745 | # include "os2thread.h" | |
2746 | # elif defined(I_MACH_CTHREADS) | |
2747 | # include <mach/cthreads.h> | |
7f3d1cf1 BH |
2748 | typedef cthread_t perl_os_thread; |
2749 | typedef mutex_t perl_mutex; | |
2750 | typedef condition_t perl_cond; | |
2751 | typedef void * perl_key; | |
da5fdda8 AC |
2752 | # elif defined(I_PTHREAD) /* Posix threads */ |
2753 | # include <pthread.h> | |
7f3d1cf1 | 2754 | typedef pthread_t perl_os_thread; |
3baee7cc | 2755 | typedef pthread_mutex_t PERL_TSA_CAPABILITY("mutex") perl_mutex; |
7f3d1cf1 BH |
2756 | typedef pthread_cond_t perl_cond; |
2757 | typedef pthread_key_t perl_key; | |
da5fdda8 | 2758 | # endif |
3db8f154 | 2759 | #endif /* USE_ITHREADS */ |
c5be433b | 2760 | |
3baee7cc JH |
2761 | #ifdef PERL_TSA_ACTIVE |
2762 | /* Since most pthread mutex interfaces have not been annotated, we | |
2763 | * need to have these wrappers. The NO_TSA annotation is quite ugly | |
2764 | * but it cannot be avoided in plain C, unlike in C++, where one could | |
2765 | * e.g. use ACQUIRE() with no arg on a mutex lock method. | |
2766 | * | |
2767 | * The bodies of these wrappers are in util.c | |
2768 | * | |
2769 | * TODO: however, some platforms are starting to get these clang | |
2770 | * thread safety annotations for pthreads, for example FreeBSD. | |
2771 | * Do we need a way to a bypass these wrappers? */ | |
67083b7b | 2772 | EXTERN_C int perl_tsa_mutex_lock(perl_mutex* mutex) |
3baee7cc JH |
2773 | PERL_TSA_ACQUIRE(*mutex) |
2774 | PERL_TSA_NO_TSA; | |
67083b7b | 2775 | EXTERN_C int perl_tsa_mutex_unlock(perl_mutex* mutex) |
3baee7cc JH |
2776 | PERL_TSA_RELEASE(*mutex) |
2777 | PERL_TSA_NO_TSA; | |
2778 | #endif | |
2779 | ||
66a93824 | 2780 | #if defined(WIN32) |
1feb2720 | 2781 | # include "win32.h" |
c5be433b GS |
2782 | #endif |
2783 | ||
2986a63f JH |
2784 | #ifdef NETWARE |
2785 | # include "netware.h" | |
2786 | #endif | |
2787 | ||
e5218da5 | 2788 | #define STATUS_UNIX PL_statusvalue |
68dc0745 | 2789 | #ifdef VMS |
6b88bc9c | 2790 | # define STATUS_NATIVE PL_statusvalue_vms |
7a7fd8e0 JM |
2791 | /* |
2792 | * vaxc$errno is only guaranteed to be valid if errno == EVMSERR, otherwise | |
ff7298cb | 2793 | * its contents can not be trusted. Unfortunately, Perl seems to check |
7a7fd8e0 JM |
2794 | * it on exit, so it when PL_statusvalue_vms is updated, vaxc$errno should |
2795 | * be updated also. | |
2796 | */ | |
2797 | # include <stsdef.h> | |
2798 | # include <ssdef.h> | |
2799 | /* Presume this because if VMS changes it, it will require a new | |
2800 | * set of APIs for waiting on children for binary compatibility. | |
2801 | */ | |
2802 | # define child_offset_bits (8) | |
2803 | # ifndef C_FAC_POSIX | |
2804 | # define C_FAC_POSIX 0x35A000 | |
2805 | # endif | |
2806 | ||
2807 | /* STATUS_EXIT - validates and returns a NATIVE exit status code for the | |
2808 | * platform from the existing UNIX or Native status values. | |
2809 | */ | |
2810 | ||
37038d91 | 2811 | # define STATUS_EXIT \ |
7a7fd8e0 JM |
2812 | (((I32)PL_statusvalue_vms == -1 ? SS$_ABORT : PL_statusvalue_vms) | \ |
2813 | (VMSISH_HUSHED ? STS$M_INHIB_MSG : 0)) | |
2814 | ||
7a7fd8e0 | 2815 | |
fb38d079 JM |
2816 | /* STATUS_NATIVE_CHILD_SET - Calculate UNIX status that matches the child |
2817 | * exit code and shifts the UNIX value over the correct number of bits to | |
2818 | * be a child status. Usually the number of bits is 8, but that could be | |
2819 | * platform dependent. The NATIVE status code is presumed to have either | |
2820 | * from a child process. | |
7a7fd8e0 JM |
2821 | */ |
2822 | ||
fb38d079 JM |
2823 | /* This is complicated. The child processes return a true native VMS |
2824 | status which must be saved. But there is an assumption in Perl that | |
2825 | the UNIX child status has some relationship to errno values, so | |
00f254e2 | 2826 | Perl tries to translate it to text in some of the tests. |
fb38d079 JM |
2827 | In order to get the string translation correct, for the error, errno |
2828 | must be EVMSERR, but that generates a different text message | |
2829 | than what the test programs are expecting. So an errno value must | |
2830 | be derived from the native status value when an error occurs. | |
2831 | That will hide the true native status message. With this version of | |
2832 | perl, the true native child status can always be retrieved so that | |
2833 | is not a problem. But in this case, Pl_statusvalue and errno may | |
2834 | have different values in them. | |
2835 | */ | |
7a7fd8e0 | 2836 | |
fb38d079 | 2837 | # define STATUS_NATIVE_CHILD_SET(n) \ |
68dc0745 | 2838 | STMT_START { \ |
2fbb330f JM |
2839 | I32 evalue = (I32)n; \ |
2840 | if (evalue == EVMSERR) { \ | |
2841 | PL_statusvalue_vms = vaxc$errno; \ | |
2842 | PL_statusvalue = evalue; \ | |
7a7fd8e0 | 2843 | } else { \ |
2fbb330f | 2844 | PL_statusvalue_vms = evalue; \ |
fb38d079 | 2845 | if (evalue == -1) { \ |
3280af22 | 2846 | PL_statusvalue = -1; \ |
7a7fd8e0 JM |
2847 | PL_statusvalue_vms = SS$_ABORT; /* Should not happen */ \ |
2848 | } else \ | |
fb38d079 | 2849 | PL_statusvalue = Perl_vms_status_to_unix(evalue, 1); \ |
2fbb330f | 2850 | set_vaxc_errno(evalue); \ |
fb38d079 JM |
2851 | if ((PL_statusvalue_vms & C_FAC_POSIX) == C_FAC_POSIX) \ |
2852 | set_errno(EVMSERR); \ | |
2853 | else set_errno(Perl_vms_status_to_unix(evalue, 0)); \ | |
2854 | PL_statusvalue = PL_statusvalue << child_offset_bits; \ | |
2fbb330f | 2855 | } \ |
68dc0745 | 2856 | } STMT_END |
7a7fd8e0 | 2857 | |
68dc0745 | 2858 | # ifdef VMSISH_STATUS |
e5218da5 | 2859 | # define STATUS_CURRENT (VMSISH_STATUS ? STATUS_NATIVE : STATUS_UNIX) |
68dc0745 | 2860 | # else |
e5218da5 | 2861 | # define STATUS_CURRENT STATUS_UNIX |
68dc0745 | 2862 | # endif |
7a7fd8e0 JM |
2863 | |
2864 | /* STATUS_UNIX_SET - takes a UNIX/POSIX errno value and attempts to update | |
2865 | * the NATIVE status to an equivalent value. Can not be used to translate | |
2866 | * exit code values as exit code values are not guaranteed to have any | |
2867 | * relationship at all to errno values. | |
2868 | * This is used when Perl is forcing errno to have a specific value. | |
2869 | */ | |
e5218da5 | 2870 | # define STATUS_UNIX_SET(n) \ |
68dc0745 | 2871 | STMT_START { \ |
7a7fd8e0 | 2872 | I32 evalue = (I32)n; \ |
0968cdad | 2873 | PL_statusvalue = evalue; \ |
3280af22 | 2874 | if (PL_statusvalue != -1) { \ |
0968cdad JM |
2875 | if (PL_statusvalue != EVMSERR) { \ |
2876 | PL_statusvalue &= 0xFFFF; \ | |
2877 | if (MY_POSIX_EXIT) \ | |
2878 | PL_statusvalue_vms=PL_statusvalue ? SS$_ABORT : SS$_NORMAL;\ | |
2879 | else PL_statusvalue_vms = Perl_unix_status_to_vms(evalue); \ | |
2880 | } \ | |
2881 | else { \ | |
2882 | PL_statusvalue_vms = vaxc$errno; \ | |
2883 | } \ | |
68dc0745 | 2884 | } \ |
0968cdad JM |
2885 | else PL_statusvalue_vms = SS$_ABORT; \ |
2886 | set_vaxc_errno(PL_statusvalue_vms); \ | |
7a7fd8e0 JM |
2887 | } STMT_END |
2888 | ||
2889 | /* STATUS_UNIX_EXIT_SET - Takes a UNIX/POSIX exit code and sets | |
e08e1e1d JM |
2890 | * the NATIVE error status based on it. |
2891 | * | |
2892 | * When in the default mode to comply with the Perl VMS documentation, | |
2893 | * 0 is a success and any other code sets the NATIVE status to a failure | |
2894 | * code of SS$_ABORT. | |
fb38d079 JM |
2895 | * |
2896 | * In the new POSIX EXIT mode, native status will be set so that the | |
2897 | * actual exit code will can be retrieved by the calling program or | |
2898 | * shell. | |
2899 | * | |
2900 | * If the exit code is not clearly a UNIX parent or child exit status, | |
2901 | * it will be passed through as a VMS status. | |
7a7fd8e0 JM |
2902 | */ |
2903 | ||
fb38d079 | 2904 | # define STATUS_UNIX_EXIT_SET(n) \ |
7a7fd8e0 JM |
2905 | STMT_START { \ |
2906 | I32 evalue = (I32)n; \ | |
2907 | PL_statusvalue = evalue; \ | |
e08e1e1d JM |
2908 | if (MY_POSIX_EXIT) { \ |
2909 | if (evalue <= 0xFF00) { \ | |
2910 | if (evalue > 0xFF) \ | |
2911 | evalue = (evalue >> child_offset_bits) & 0xFF; \ | |
2912 | PL_statusvalue_vms = \ | |
2913 | (C_FAC_POSIX | (evalue << 3 ) | \ | |
2914 | ((evalue == 1) ? (STS$K_ERROR | STS$M_INHIB_MSG) : 1)); \ | |
2915 | } else /* forgive them Perl, for they have sinned */ \ | |
2916 | PL_statusvalue_vms = evalue; \ | |
2917 | } else { \ | |
2918 | if (evalue == 0) \ | |
2919 | PL_statusvalue_vms = SS$_NORMAL; \ | |
2920 | else if (evalue <= 0xFF00) \ | |
2921 | PL_statusvalue_vms = SS$_ABORT; \ | |
2922 | else { /* forgive them Perl, for they have sinned */ \ | |
2923 | if (evalue != EVMSERR) PL_statusvalue_vms = evalue; \ | |
2924 | else PL_statusvalue_vms = vaxc$errno; \ | |
2925 | /* And obviously used a VMS status value instead of UNIX */ \ | |
2926 | PL_statusvalue = EVMSERR; \ | |
2927 | } \ | |
2928 | set_vaxc_errno(PL_statusvalue_vms); \ | |
2929 | } \ | |
68dc0745 | 2930 | } STMT_END |
fb38d079 | 2931 | |
e08e1e1d | 2932 | |
6ac6a52b JM |
2933 | /* STATUS_EXIT_SET - Takes a NATIVE/UNIX/POSIX exit code |
2934 | * and sets the NATIVE error status based on it. This special case | |
2935 | * is needed to maintain compatibility with past VMS behavior. | |
2936 | * | |
2937 | * In the default mode on VMS, this number is passed through as | |
2938 | * both the NATIVE and UNIX status. Which makes it different | |
2939 | * that the STATUS_UNIX_EXIT_SET. | |
2940 | * | |
2941 | * In the new POSIX EXIT mode, native status will be set so that the | |
2942 | * actual exit code will can be retrieved by the calling program or | |
2943 | * shell. | |
2944 | * | |
1a3aec58 JM |
2945 | * A POSIX exit code is from 0 to 255. If the exit code is higher |
2946 | * than this, it needs to be assumed that it is a VMS exit code and | |
2947 | * passed through. | |
6ac6a52b JM |
2948 | */ |
2949 | ||
2950 | # define STATUS_EXIT_SET(n) \ | |
2951 | STMT_START { \ | |
2952 | I32 evalue = (I32)n; \ | |
2953 | PL_statusvalue = evalue; \ | |
2954 | if (MY_POSIX_EXIT) \ | |
1a3aec58 JM |
2955 | if (evalue > 255) PL_statusvalue_vms = evalue; else { \ |
2956 | PL_statusvalue_vms = \ | |
2957 | (C_FAC_POSIX | (evalue << 3 ) | \ | |
2958 | ((evalue == 1) ? (STS$K_ERROR | STS$M_INHIB_MSG) : 1));} \ | |
6ac6a52b JM |
2959 | else \ |
2960 | PL_statusvalue_vms = evalue ? evalue : SS$_NORMAL; \ | |
2961 | set_vaxc_errno(PL_statusvalue_vms); \ | |
2962 | } STMT_END | |
2963 | ||
fb38d079 JM |
2964 | |
2965 | /* This macro forces a success status */ | |
7a7fd8e0 JM |
2966 | # define STATUS_ALL_SUCCESS \ |
2967 | (PL_statusvalue = 0, PL_statusvalue_vms = SS$_NORMAL) | |
fb38d079 JM |
2968 | |
2969 | /* This macro forces a failure status */ | |
7a7fd8e0 JM |
2970 | # define STATUS_ALL_FAILURE (PL_statusvalue = 1, \ |
2971 | vaxc$errno = PL_statusvalue_vms = MY_POSIX_EXIT ? \ | |
2972 | (C_FAC_POSIX | (1 << 3) | STS$K_ERROR | STS$M_INHIB_MSG) : SS$_ABORT) | |
fb38d079 | 2973 | |
738ab09f AB |
2974 | #elif defined(__amigaos4__) |
2975 | /* A somewhat experimental attempt to simulate posix return code values */ | |
2976 | # define STATUS_NATIVE PL_statusvalue_posix | |
2977 | # define STATUS_NATIVE_CHILD_SET(n) \ | |
2978 | STMT_START { \ | |
2979 | PL_statusvalue_posix = (n); \ | |
2980 | if (PL_statusvalue_posix < 0) { \ | |
2981 | PL_statusvalue = -1; \ | |
2982 | } \ | |
2983 | else { \ | |
2984 | PL_statusvalue = n << 8; \ | |
2985 | } \ | |
2986 | } STMT_END | |
2987 | # define STATUS_UNIX_SET(n) \ | |
2988 | STMT_START { \ | |
2989 | PL_statusvalue = (n); \ | |
2990 | if (PL_statusvalue != -1) \ | |
2991 | PL_statusvalue &= 0xFFFF; \ | |
2992 | } STMT_END | |
2993 | # define STATUS_UNIX_EXIT_SET(n) STATUS_UNIX_SET(n) | |
2994 | # define STATUS_EXIT_SET(n) STATUS_UNIX_SET(n) | |
2995 | # define STATUS_CURRENT STATUS_UNIX | |
2996 | # define STATUS_EXIT STATUS_UNIX | |
2997 | # define STATUS_ALL_SUCCESS (PL_statusvalue = 0, PL_statusvalue_posix = 0) | |
2998 | # define STATUS_ALL_FAILURE (PL_statusvalue = 1, PL_statusvalue_posix = 1) | |
2999 | ||
68dc0745 | 3000 | #else |
e5218da5 | 3001 | # define STATUS_NATIVE PL_statusvalue_posix |
e5218da5 | 3002 | # if defined(WCOREDUMP) |
37038d91 | 3003 | # define STATUS_NATIVE_CHILD_SET(n) \ |
e5218da5 GA |
3004 | STMT_START { \ |
3005 | PL_statusvalue_posix = (n); \ | |
3006 | if (PL_statusvalue_posix == -1) \ | |
3007 | PL_statusvalue = -1; \ | |
3008 | else { \ | |
3009 | PL_statusvalue = \ | |
3010 | (WIFEXITED(PL_statusvalue_posix) ? (WEXITSTATUS(PL_statusvalue_posix) << 8) : 0) | \ | |
3011 | (WIFSIGNALED(PL_statusvalue_posix) ? (WTERMSIG(PL_statusvalue_posix) & 0x7F) : 0) | \ | |
3012 | (WIFSIGNALED(PL_statusvalue_posix) && WCOREDUMP(PL_statusvalue_posix) ? 0x80 : 0); \ | |
3013 | } \ | |
3014 | } STMT_END | |
3015 | # elif defined(WIFEXITED) | |
37038d91 | 3016 | # define STATUS_NATIVE_CHILD_SET(n) \ |
e5218da5 GA |
3017 | STMT_START { \ |
3018 | PL_statusvalue_posix = (n); \ | |
3019 | if (PL_statusvalue_posix == -1) \ | |
3020 | PL_statusvalue = -1; \ | |
3021 | else { \ | |
3022 | PL_statusvalue = \ | |
3023 | (WIFEXITED(PL_statusvalue_posix) ? (WEXITSTATUS(PL_statusvalue_posix) << 8) : 0) | \ | |
3024 | (WIFSIGNALED(PL_statusvalue_posix) ? (WTERMSIG(PL_statusvalue_posix) & 0x7F) : 0); \ | |
3025 | } \ | |
3026 | } STMT_END | |
3027 | # else | |
37038d91 | 3028 | # define STATUS_NATIVE_CHILD_SET(n) \ |
e5218da5 GA |
3029 | STMT_START { \ |
3030 | PL_statusvalue_posix = (n); \ | |
3031 | if (PL_statusvalue_posix == -1) \ | |
3032 | PL_statusvalue = -1; \ | |
3033 | else { \ | |
3034 | PL_statusvalue = \ | |
3035 | PL_statusvalue_posix & 0xFFFF; \ | |
3036 | } \ | |
3037 | } STMT_END | |
3038 | # endif | |
3039 | # define STATUS_UNIX_SET(n) \ | |
68dc0745 | 3040 | STMT_START { \ |
3280af22 NIS |
3041 | PL_statusvalue = (n); \ |
3042 | if (PL_statusvalue != -1) \ | |
3043 | PL_statusvalue &= 0xFFFF; \ | |
68dc0745 | 3044 | } STMT_END |
7a7fd8e0 | 3045 | # define STATUS_UNIX_EXIT_SET(n) STATUS_UNIX_SET(n) |
6ac6a52b | 3046 | # define STATUS_EXIT_SET(n) STATUS_UNIX_SET(n) |
e5218da5 | 3047 | # define STATUS_CURRENT STATUS_UNIX |
37038d91 | 3048 | # define STATUS_EXIT STATUS_UNIX |
e5218da5 GA |
3049 | # define STATUS_ALL_SUCCESS (PL_statusvalue = 0, PL_statusvalue_posix = 0) |
3050 | # define STATUS_ALL_FAILURE (PL_statusvalue = 1, PL_statusvalue_posix = 1) | |
68dc0745 | 3051 | #endif |
3052 | ||
cc3604b1 GS |
3053 | /* flags in PL_exit_flags for nature of exit() */ |
3054 | #define PERL_EXIT_EXPECTED 0x01 | |
31d77e54 | 3055 | #define PERL_EXIT_DESTRUCT_END 0x02 /* Run END in perl_destruct */ |
6136213b JGM |
3056 | #define PERL_EXIT_WARN 0x04 /* Warn if Perl_my_exit() or Perl_my_failure_exit() called */ |
3057 | #define PERL_EXIT_ABORT 0x08 /* Call abort() if Perl_my_exit() or Perl_my_failure_exit() called */ | |
cc3604b1 | 3058 | |
b79b76e0 | 3059 | #ifndef PERL_CORE |
a7cb1f99 | 3060 | /* format to use for version numbers in file/directory names */ |
273cf8d1 | 3061 | /* XXX move to Configure? */ |
b79b76e0 NC |
3062 | /* This was only ever used for the current version, and that can be done at |
3063 | compile time, as PERL_FS_VERSION, so should we just delete it? */ | |
3064 | # ifndef PERL_FS_VER_FMT | |
3065 | # define PERL_FS_VER_FMT "%d.%d.%d" | |
3066 | # endif | |
3067 | #endif | |
3068 | ||
3069 | #ifndef PERL_FS_VERSION | |
3070 | # define PERL_FS_VERSION PERL_VERSION_STRING | |
0b94c7bb GS |
3071 | #endif |
3072 | ||
45bc9206 | 3073 | /* This defines a way to flush all output buffers. This may be a |
76549fef JH |
3074 | * performance issue, so we allow people to disable it. Also, if |
3075 | * we are using stdio, there are broken implementations of fflush(NULL) | |
3076 | * out there, Solaris being the most prominent. | |
45bc9206 GS |
3077 | */ |
3078 | #ifndef PERL_FLUSHALL_FOR_CHILD | |
97cb92d6 | 3079 | # if defined(USE_PERLIO) || defined(FFLUSH_NULL) |
66fe083f | 3080 | # define PERL_FLUSHALL_FOR_CHILD PerlIO_flush((PerlIO*)NULL) |
da5fdda8 AC |
3081 | # elif defined(FFLUSH_ALL) |
3082 | # define PERL_FLUSHALL_FOR_CHILD my_fflush_all() | |
767df6a1 | 3083 | # else |
da5fdda8 | 3084 | # define PERL_FLUSHALL_FOR_CHILD NOOP |
66fe083f | 3085 | # endif |
45bc9206 GS |
3086 | #endif |
3087 | ||
7766f137 GS |
3088 | #ifndef PERL_WAIT_FOR_CHILDREN |
3089 | # define PERL_WAIT_FOR_CHILDREN NOOP | |
3090 | #endif | |
3091 | ||
ba869deb | 3092 | /* the traditional thread-unsafe notion of "current interpreter". */ |
c5be433b GS |
3093 | #ifndef PERL_SET_INTERP |
3094 | # define PERL_SET_INTERP(i) (PL_curinterp = (PerlInterpreter*)(i)) | |
3095 | #endif | |
3096 | ||
3097 | #ifndef PERL_GET_INTERP | |
3098 | # define PERL_GET_INTERP (PL_curinterp) | |
3099 | #endif | |
3100 | ||
54aff467 | 3101 | #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_GET_THX) |
54aff467 | 3102 | # ifdef MULTIPLICITY |
ba869deb | 3103 | # define PERL_GET_THX ((PerlInterpreter *)PERL_GET_CONTEXT) |
54aff467 | 3104 | # endif |
ba869deb GS |
3105 | # define PERL_SET_THX(t) PERL_SET_CONTEXT(t) |
3106 | #endif | |
3107 | ||
00f254e2 | 3108 | /* |
8896765a | 3109 | This replaces the previous %_ "hack" by the "%p" hacks. |
0dbb1585 | 3110 | All that is required is that the perl source does not |
00f254e2 KW |
3111 | use "%-p" or "%-<number>p" or "%<number>p" formats. |
3112 | These formats will still work in perl code. | |
486ec47a | 3113 | See comments in sv.c for further details. |
8896765a | 3114 | |
8896765a | 3115 | Robin Barker 2005-07-14 |
f46d31f2 | 3116 | |
00f254e2 | 3117 | No longer use %1p for VDf = %vd. RMB 2007-10-19 |
0dbb1585 | 3118 | */ |
8896765a RB |
3119 | |
3120 | #ifndef SVf_ | |
63ce7bf0 | 3121 | # define SVf_(n) "-" STRINGIFY(n) "p" |
894356b3 GS |
3122 | #endif |
3123 | ||
8896765a | 3124 | #ifndef SVf |
104abab4 | 3125 | # define SVf "-p" |
d2560b70 RB |
3126 | #endif |
3127 | ||
014ead4b | 3128 | #ifndef SVf32 |
8896765a | 3129 | # define SVf32 SVf_(32) |
014ead4b RB |
3130 | #endif |
3131 | ||
3132 | #ifndef SVf256 | |
8896765a RB |
3133 | # define SVf256 SVf_(256) |
3134 | #endif | |
3135 | ||
be2597df MHM |
3136 | #define SVfARG(p) ((void*)(p)) |
3137 | ||
20023040 FC |
3138 | #ifndef HEKf |
3139 | # define HEKf "2p" | |
3140 | #endif | |
3141 | ||
b8fa5213 FC |
3142 | /* Not ideal, but we cannot easily include a number in an already-numeric |
3143 | * format sequence. */ | |
3144 | #ifndef HEKf256 | |
3145 | # define HEKf256 "3p" | |
3146 | #endif | |
3147 | ||
20023040 FC |
3148 | #define HEKfARG(p) ((void*)(p)) |
3149 | ||
b17a0679 FC |
3150 | /* Takes three arguments: is_utf8, length, str */ |
3151 | #ifndef UTF8f | |
61608bb7 | 3152 | # define UTF8f "d%" UVuf "%4p" |
b17a0679 FC |
3153 | #endif |
3154 | #define UTF8fARG(u,l,p) (int)cBOOL(u), (UV)(l), (void*)(p) | |
3155 | ||
0f94cb1f FC |
3156 | #define PNf UTF8f |
3157 | #define PNfARG(pn) (int)1, (UV)PadnameLEN(pn), (void *)PadnamePV(pn) | |
0d1e9135 | 3158 | |
f46d31f2 | 3159 | #ifdef PERL_CORE |
486ec47a | 3160 | /* not used; but needed for backward compatibility with XS code? - RMB */ |
7776bb98 | 3161 | # undef UVf |
da5fdda8 AC |
3162 | #elif !defined(UVf) |
3163 | # define UVf UVuf | |
d2560b70 RB |
3164 | #endif |
3165 | ||
fcdf39cf RGS |
3166 | #ifdef HASATTRIBUTE_DEPRECATED |
3167 | # define __attribute__deprecated__ __attribute__((deprecated)) | |
3168 | #endif | |
0dbb1585 AL |
3169 | #ifdef HASATTRIBUTE_FORMAT |
3170 | # define __attribute__format__(x,y,z) __attribute__((format(x,y,z))) | |
3171 | #endif | |
3172 | #ifdef HASATTRIBUTE_MALLOC | |
77785eea | 3173 | # define __attribute__malloc__ __attribute__((__malloc__)) |
f22be1b8 | 3174 | #endif |
0dbb1585 | 3175 | #ifdef HASATTRIBUTE_NONNULL |
abb2c242 | 3176 | # define __attribute__nonnull__(a) __attribute__((nonnull(a))) |
f22be1b8 | 3177 | #endif |
0dbb1585 | 3178 | #ifdef HASATTRIBUTE_NORETURN |
abb2c242 | 3179 | # define __attribute__noreturn__ __attribute__((noreturn)) |
f22be1b8 | 3180 | #endif |
0dbb1585 | 3181 | #ifdef HASATTRIBUTE_PURE |
abb2c242 | 3182 | # define __attribute__pure__ __attribute__((pure)) |
f22be1b8 | 3183 | #endif |
0dbb1585 AL |
3184 | #ifdef HASATTRIBUTE_UNUSED |
3185 | # define __attribute__unused__ __attribute__((unused)) | |
3186 | #endif | |
3187 | #ifdef HASATTRIBUTE_WARN_UNUSED_RESULT | |
abb2c242 | 3188 | # define __attribute__warn_unused_result__ __attribute__((warn_unused_result)) |
f22be1b8 JH |
3189 | #endif |
3190 | ||
0dbb1585 | 3191 | /* If we haven't defined the attributes yet, define them to blank. */ |
fcdf39cf RGS |
3192 | #ifndef __attribute__deprecated__ |
3193 | # define __attribute__deprecated__ | |
3194 | #endif | |
0dbb1585 AL |
3195 | #ifndef __attribute__format__ |
3196 | # define __attribute__format__(x,y,z) | |
3197 | #endif | |
f22be1b8 | 3198 | #ifndef __attribute__malloc__ |
abb2c242 | 3199 | # define __attribute__malloc__ |
f22be1b8 JH |
3200 | #endif |
3201 | #ifndef __attribute__nonnull__ | |
abb2c242 | 3202 | # define __attribute__nonnull__(a) |
f22be1b8 JH |
3203 | #endif |
3204 | #ifndef __attribute__noreturn__ | |
abb2c242 | 3205 | # define __attribute__noreturn__ |
f22be1b8 JH |
3206 | #endif |
3207 | #ifndef __attribute__pure__ | |
abb2c242 | 3208 | # define __attribute__pure__ |
f22be1b8 | 3209 | #endif |
0dbb1585 AL |
3210 | #ifndef __attribute__unused__ |
3211 | # define __attribute__unused__ | |
3212 | #endif | |
f22be1b8 | 3213 | #ifndef __attribute__warn_unused_result__ |
abb2c242 JH |
3214 | # define __attribute__warn_unused_result__ |
3215 | #endif | |
3216 | ||
6ff2ec7d AC |
3217 | #if !defined(DEBUGGING) && !defined(NDEBUG) |
3218 | # define NDEBUG 1 | |
cd13e623 | 3219 | #endif |
6ff2ec7d | 3220 | #include <assert.h> |
cd13e623 | 3221 | |
0dbb1585 AL |
3222 | /* For functions that are marked as __attribute__noreturn__, it's not |
3223 | appropriate to call return. In either case, include the lint directive. | |
3224 | */ | |
3225 | #ifdef HASATTRIBUTE_NORETURN | |
bc3d2941 | 3226 | # define NORETURN_FUNCTION_END NOT_REACHED; |
0dbb1585 | 3227 | #else |
bc3d2941 | 3228 | # define NORETURN_FUNCTION_END NOT_REACHED; return 0 |
abb2c242 JH |
3229 | #endif |
3230 | ||
cdfeb707 RB |
3231 | /* Some OS warn on NULL format to printf */ |
3232 | #ifdef PRINTF_FORMAT_NULL_OK | |
3233 | # define __attribute__format__null_ok__(x,y,z) __attribute__format__(x,y,z) | |
3234 | #else | |
00f254e2 | 3235 | # define __attribute__format__null_ok__(x,y,z) |
cdfeb707 RB |
3236 | #endif |
3237 | ||
635aebb7 | 3238 | #ifdef HAS_BUILTIN_EXPECT |
b37c2d43 AL |
3239 | # define EXPECT(expr,val) __builtin_expect(expr,val) |
3240 | #else | |
3241 | # define EXPECT(expr,val) (expr) | |
3242 | #endif | |
6d5abc62 NC |
3243 | #define LIKELY(cond) EXPECT(cBOOL(cond),TRUE) |
3244 | #define UNLIKELY(cond) EXPECT(cBOOL(cond),FALSE) | |
635aebb7 AL |
3245 | #ifdef HAS_BUILTIN_CHOOSE_EXPR |
3246 | /* placeholder */ | |
3247 | #endif | |
b37c2d43 | 3248 | |
a36ca6de | 3249 | /* STATIC_ASSERT_DECL/STATIC_ASSERT_STMT are like assert(), but for compile |
5074d4c5 LM |
3250 | time invariants. That is, their argument must be a constant expression that |
3251 | can be verified by the compiler. This expression can contain anything that's | |
3252 | known to the compiler, e.g. #define constants, enums, or sizeof (...). If | |
3253 | the expression evaluates to 0, compilation fails. | |
3254 | Because they generate no runtime code (i.e. their use is "free"), they're | |
3255 | always active, even under non-DEBUGGING builds. | |
a36ca6de | 3256 | STATIC_ASSERT_DECL expands to a declaration and is suitable for use at |
5074d4c5 LM |
3257 | file scope (outside of any function). |
3258 | STATIC_ASSERT_STMT expands to a statement and is suitable for use inside a | |
3259 | function. | |
3260 | */ | |
7ea096df | 3261 | #if (defined(static_assert) || (defined(__cplusplus) && __cplusplus >= 201103L)) && (!defined(__IBMC__) || __IBMC__ >= 1210) |
6d59e610 | 3262 | /* static_assert is a macro defined in <assert.h> in C11 or a compiler |
a36ca6de LM |
3263 | builtin in C++11. But IBM XL C V11 does not support _Static_assert, no |
3264 | matter what <assert.h> says. | |
6d59e610 | 3265 | */ |
a36ca6de | 3266 | # define STATIC_ASSERT_DECL(COND) static_assert(COND, #COND) |
6d59e610 LM |
3267 | #else |
3268 | /* We use a bit-field instead of an array because gcc accepts | |
3269 | 'typedef char x[n]' where n is not a compile-time constant. | |
3270 | We want to enforce constantness. | |
3271 | */ | |
3272 | # define STATIC_ASSERT_2(COND, SUFFIX) \ | |
3273 | typedef struct { \ | |
3274 | unsigned int _static_assertion_failed_##SUFFIX : (COND) ? 1 : -1; \ | |
3275 | } _static_assertion_failed_##SUFFIX PERL_UNUSED_DECL | |
3276 | # define STATIC_ASSERT_1(COND, SUFFIX) STATIC_ASSERT_2(COND, SUFFIX) | |
a36ca6de | 3277 | # define STATIC_ASSERT_DECL(COND) STATIC_ASSERT_1(COND, __LINE__) |
6d59e610 LM |
3278 | #endif |
3279 | /* We need this wrapper even in C11 because 'case X: static_assert(...);' is an | |
3280 | error (static_assert is a declaration, and only statements can have labels). | |
3281 | */ | |
21aae866 | 3282 | #define STATIC_ASSERT_STMT(COND) STMT_START { STATIC_ASSERT_DECL(COND); } STMT_END |
ae103e09 DD |
3283 | |
3284 | #ifndef __has_builtin | |
3285 | # define __has_builtin(x) 0 /* not a clang style compiler */ | |
3286 | #endif | |
3287 | ||
3288 | /* ASSUME is like assert(), but it has a benefit in a release build. It is a | |
3289 | hint to a compiler about a statement of fact in a function call free | |
3290 | expression, which allows the compiler to generate better machine code. | |
3291 | In a debug build, ASSUME(x) is a synonym for assert(x). ASSUME(0) means | |
3292 | the control path is unreachable. In a for loop, ASSUME can be used to hint | |
b8fda935 | 3293 | that a loop will run at least X times. ASSUME is based off MSVC's __assume |
ae103e09 DD |
3294 | intrinsic function, see its documents for more details. |
3295 | */ | |
3296 | ||
3297 | #ifndef DEBUGGING | |
3298 | # if __has_builtin(__builtin_unreachable) \ | |
d1020b40 | 3299 | || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5 || __GNUC__ > 4) /* 4.5 -> */ |
ae103e09 DD |
3300 | # define ASSUME(x) ((x) ? (void) 0 : __builtin_unreachable()) |
3301 | # elif defined(_MSC_VER) | |
3302 | # define ASSUME(x) __assume(x) | |
3303 | # elif defined(__ARMCC_VERSION) /* untested */ | |
3304 | # define ASSUME(x) __promise(x) | |
3305 | # else | |
3306 | /* a random compiler might define assert to its own special optimization token | |
3307 | so pass it through to C lib as a last resort */ | |
3308 | # define ASSUME(x) assert(x) | |
3309 | # endif | |
3310 | #else | |
3311 | # define ASSUME(x) assert(x) | |
3312 | #endif | |
3313 | ||
dbc47c6f KW |
3314 | #if defined(__sun) /* ASSUME() generates warnings on Solaris */ |
3315 | # define NOT_REACHED | |
2145f4b6 LM |
3316 | #elif defined(DEBUGGING) && (__has_builtin(__builtin_unreachable) \ |
3317 | || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5 || __GNUC__ > 4)) /* 4.5 -> */ | |
3318 | # define NOT_REACHED STMT_START { ASSUME(0); __builtin_unreachable(); } STMT_END | |
dbc47c6f KW |
3319 | #else |
3320 | # define NOT_REACHED ASSUME(0) | |
3321 | #endif | |
ae103e09 | 3322 | |
3fc1aec6 | 3323 | /* Some unistd.h's give a prototype for pause() even though |
3324 | HAS_PAUSE ends up undefined. This causes the #define | |
d2560b70 | 3325 | below to be rejected by the compiler. Sigh. |
3fc1aec6 | 3326 | */ |
3327 | #ifdef HAS_PAUSE | |
3328 | #define Pause pause | |
3329 | #else | |
3330 | #define Pause() sleep((32767<<16)+32767) | |
748a9306 LW |
3331 | #endif |
3332 | ||
3333 | #ifndef IOCPARM_LEN | |
3334 | # ifdef IOCPARM_MASK | |
61f1c44b | 3335 | /* on BSDish systems we're safe */ |
748a9306 | 3336 | # define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK) |
da5fdda8 | 3337 | # elif defined(_IOC_SIZE) && defined(__GLIBC__) |
301eb2f0 | 3338 | /* on Linux systems we're safe; except when we're not [perl #38223] */ |
da5fdda8 AC |
3339 | # define IOCPARM_LEN(x) (_IOC_SIZE(x) < 256 ? 256 : _IOC_SIZE(x)) |
3340 | # else | |
748a9306 | 3341 | /* otherwise guess at what's safe */ |
da5fdda8 | 3342 | # define IOCPARM_LEN(x) 256 |
748a9306 | 3343 | # endif |
a0d0e21e LW |
3344 | #endif |
3345 | ||
1761cee5 | 3346 | #if defined(__CYGWIN__) |
521e0776 GS |
3347 | /* USEMYBINMODE |
3348 | * This symbol, if defined, indicates that the program should | |
16fe6d59 | 3349 | * use the routine my_binmode(FILE *fp, char iotype, int mode) to insure |
521e0776 GS |
3350 | * that a file is in "binary" mode -- that is, that no translation |
3351 | * of bytes occurs on read or write operations. | |
3352 | */ | |
36894f0b | 3353 | # define USEMYBINMODE /**/ |
77a40698 | 3354 | # include <io.h> /* for setmode() prototype */ |
16fe6d59 | 3355 | # define my_binmode(fp, iotype, mode) \ |
8298454c | 3356 | cBOOL(PerlLIO_setmode(fileno(fp), mode) != -1) |
5aabfad6 | 3357 | #endif |
3358 | ||
88d10794 JH |
3359 | #ifdef __CYGWIN__ |
3360 | void init_os_extras(void); | |
3361 | #endif | |
3362 | ||
cea2e8a9 GS |
3363 | #ifdef UNION_ANY_DEFINITION |
3364 | UNION_ANY_DEFINITION; | |
3365 | #else | |
3366 | union any { | |
3367 | void* any_ptr; | |
c9728782 DM |
3368 | SV* any_sv; |
3369 | SV** any_svp; | |
3370 | GV* any_gv; | |
3371 | AV* any_av; | |
3372 | HV* any_hv; | |
6ffb8402 | 3373 | OP* any_op; |
c9728782 DM |
3374 | char* any_pv; |
3375 | char** any_pvp; | |
cea2e8a9 | 3376 | I32 any_i32; |
ae103e09 | 3377 | U32 any_u32; |
cea2e8a9 | 3378 | IV any_iv; |
c6bf6a65 | 3379 | UV any_uv; |
cea2e8a9 | 3380 | long any_long; |
9febdf04 | 3381 | bool any_bool; |
c76ac1ee | 3382 | void (*any_dptr) (void*); |
acfe0abc | 3383 | void (*any_dxptr) (pTHX_ void*); |
cea2e8a9 GS |
3384 | }; |
3385 | #endif | |
3386 | ||
acfe0abc | 3387 | typedef I32 (*filter_t) (pTHX_ int, SV *, int); |
cea2e8a9 GS |
3388 | |
3389 | #define FILTER_READ(idx, sv, len) filter_read(idx, sv, len) | |
5486870f DM |
3390 | #define FILTER_DATA(idx) \ |
3391 | (PL_parser ? AvARRAY(PL_parser->rsfp_filters)[idx] : NULL) | |
3392 | #define FILTER_ISREADER(idx) \ | |
3393 | (PL_parser && PL_parser->rsfp_filters \ | |
3394 | && idx >= AvFILLp(PL_parser->rsfp_filters)) | |
3395 | #define PERL_FILTER_EXISTS(i) \ | |
3396 | (PL_parser && PL_parser->rsfp_filters \ | |
b9f2b683 | 3397 | && (i) <= av_tindex(PL_parser->rsfp_filters)) |
cea2e8a9 | 3398 | |
c5078cac JH |
3399 | #if defined(_AIX) && !defined(_AIX43) |
3400 | #if defined(USE_REENTRANT) || defined(_REENTRANT) || defined(_THREAD_SAFE) | |
3401 | /* We cannot include <crypt.h> to get the struct crypt_data | |
3402 | * because of setkey prototype problems when threading */ | |
3403 | typedef struct crypt_data { /* straight from /usr/include/crypt.h */ | |
3404 | /* From OSF, Not needed in AIX | |
3405 | char C[28], D[28]; | |
3406 | */ | |
3407 | char E[48]; | |
3408 | char KS[16][48]; | |
3409 | char block[66]; | |
3410 | char iobuf[16]; | |
3411 | } CRYPTD; | |
3412 | #endif /* threading */ | |
3413 | #endif /* AIX */ | |
3414 | ||
fc6bde6f DD |
3415 | #ifndef PERL_CALLCONV |
3416 | # ifdef __cplusplus | |
3417 | # define PERL_CALLCONV extern "C" | |
3418 | # else | |
3419 | # define PERL_CALLCONV | |
3420 | # endif | |
3421 | #endif | |
3422 | #ifndef PERL_CALLCONV_NO_RET | |
3423 | # define PERL_CALLCONV_NO_RET PERL_CALLCONV | |
3424 | #endif | |
3425 | ||
3426 | /* PERL_STATIC_NO_RET is supposed to be equivalent to STATIC on builds that | |
3427 | dont have a noreturn as a declaration specifier | |
3428 | */ | |
3429 | #ifndef PERL_STATIC_NO_RET | |
3430 | # define PERL_STATIC_NO_RET STATIC | |
3431 | #endif | |
3432 | /* PERL_STATIC_NO_RET is supposed to be equivalent to PERL_STATIC_INLINE on | |
3433 | builds that dont have a noreturn as a declaration specifier | |
3434 | */ | |
3435 | #ifndef PERL_STATIC_INLINE_NO_RET | |
3436 | # define PERL_STATIC_INLINE_NO_RET PERL_STATIC_INLINE | |
3437 | #endif | |
3438 | ||
e37778c2 | 3439 | #if !defined(OS2) |
2c2d71f5 JH |
3440 | # include "iperlsys.h" |
3441 | #endif | |
504f80c1 | 3442 | |
9c12f1e5 | 3443 | #ifdef __LIBCATAMOUNT__ |
00f254e2 | 3444 | #undef HAS_PASSWD /* unixish.h but not unixish enough. */ |
9c12f1e5 RGS |
3445 | #undef HAS_GROUP |
3446 | #define FAKE_BIT_BUCKET | |
3447 | #endif | |
3448 | ||
d10dc2ae | 3449 | /* [perl #22371] Algorimic Complexity Attack on Perl 5.6.1, 5.8.0. |
1a237f4f YO |
3450 | * Note that the USE_HASH_SEED and similar defines are *NOT* defined by |
3451 | * Configure, despite their names being similar to other defines like | |
3452 | * USE_ITHREADS. Configure in fact knows nothing about the randomised | |
3453 | * hashes. Therefore to enable/disable the hash randomisation defines | |
3454 | * use the Configure -Accflags=... instead. */ | |
3455 | #if !defined(NO_HASH_SEED) && !defined(USE_HASH_SEED) | |
4546b9e6 | 3456 | # define USE_HASH_SEED |
504f80c1 JH |
3457 | #endif |
3458 | ||
598921a7 NC |
3459 | #include "perly.h" |
3460 | ||
598921a7 | 3461 | |
654eccd5 JD |
3462 | /* macros to define bit-fields in structs. */ |
3463 | #ifndef PERL_BITFIELD8 | |
3464 | # define PERL_BITFIELD8 unsigned | |
3465 | #endif | |
3466 | #ifndef PERL_BITFIELD16 | |
3467 | # define PERL_BITFIELD16 unsigned | |
3468 | #endif | |
3469 | #ifndef PERL_BITFIELD32 | |
3470 | # define PERL_BITFIELD32 unsigned | |
3471 | #endif | |
3472 | ||
79072805 | 3473 | #include "sv.h" |
288b8c02 | 3474 | #include "regexp.h" |
378cc40b | 3475 | #include "util.h" |
8d063cd8 | 3476 | #include "form.h" |
79072805 | 3477 | #include "gv.h" |
dd2155a4 | 3478 | #include "pad.h" |
79072805 | 3479 | #include "cv.h" |
abdd5c84 | 3480 | #include "opnames.h" |
79072805 | 3481 | #include "op.h" |
b3ca2e83 | 3482 | #include "hv.h" |
79072805 LW |
3483 | #include "cop.h" |
3484 | #include "av.h" | |
79072805 LW |
3485 | #include "mg.h" |
3486 | #include "scope.h" | |
4438c4b7 | 3487 | #include "warnings.h" |
a0ed51b3 | 3488 | #include "utf8.h" |
8d063cd8 | 3489 | |
0d7d409d DM |
3490 | /* these would be in doio.h if there was such a file */ |
3491 | #define my_stat() my_stat_flags(SV_GMAGIC) | |
3492 | #define my_lstat() my_lstat_flags(SV_GMAGIC) | |
3493 | ||
20f4945e | 3494 | /* defined in sv.c, but also used in [ach]v.c */ |
20f4945e MHM |
3495 | #undef _XPV_HEAD |
3496 | #undef _XPVMG_HEAD | |
3497 | #undef _XPVCV_COMMON | |
7fae4e64 | 3498 | |
199e78b7 DM |
3499 | #include "parser.h" |
3500 | ||
455ece5e | 3501 | typedef struct magic_state MGS; /* struct magic_state defined in mg.c */ |
76e3520e | 3502 | |
2260ab51 KW |
3503 | #if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_REGEXEC_C) |
3504 | ||
3505 | /* These have to be predeclared, as they are used in proto.h which is #included | |
3506 | * before their definitions in regcomp.h. */ | |
3507 | ||
3508 | struct scan_data_t; | |
7dcac5f6 KW |
3509 | typedef struct regnode_charclass regnode_charclass; |
3510 | ||
2260ab51 | 3511 | struct regnode_charclass_class; |
d1d040e5 KW |
3512 | |
3513 | /* A hopefully less confusing name. The sub-classes are all Posix classes only | |
3514 | * used under /l matching */ | |
3515 | typedef struct regnode_charclass_class regnode_charclass_posixl; | |
3516 | ||
b8f7bb16 | 3517 | typedef struct regnode_ssc regnode_ssc; |
09b2b2e6 KW |
3518 | typedef struct RExC_state_t RExC_state_t; |
3519 | struct _reg_trie_data; | |
76e3520e | 3520 | |
2260ab51 KW |
3521 | #endif |
3522 | ||
5f7fde29 GS |
3523 | struct ptr_tbl_ent { |
3524 | struct ptr_tbl_ent* next; | |
53c1dcc0 | 3525 | const void* oldval; |
5f7fde29 | 3526 | void* newval; |
d18c6117 GS |
3527 | }; |
3528 | ||
5f7fde29 GS |
3529 | struct ptr_tbl { |
3530 | struct ptr_tbl_ent** tbl_ary; | |
3531 | UV tbl_max; | |
3532 | UV tbl_items; | |
db93c0c4 NC |
3533 | struct ptr_tbl_arena *tbl_arena; |
3534 | struct ptr_tbl_ent *tbl_arena_next; | |
3535 | struct ptr_tbl_ent *tbl_arena_end; | |
d18c6117 GS |
3536 | }; |
3537 | ||
fe14fcc3 LW |
3538 | #if defined(htonl) && !defined(HAS_HTONL) |
3539 | #define HAS_HTONL | |
ae986130 | 3540 | #endif |
fe14fcc3 LW |
3541 | #if defined(htons) && !defined(HAS_HTONS) |
3542 | #define HAS_HTONS | |
ae986130 | 3543 | #endif |
fe14fcc3 LW |
3544 | #if defined(ntohl) && !defined(HAS_NTOHL) |
3545 | #define HAS_NTOHL | |
ae986130 | 3546 | #endif |
fe14fcc3 LW |
3547 | #if defined(ntohs) && !defined(HAS_NTOHS) |
3548 | #define HAS_NTOHS | |
ae986130 | 3549 | #endif |
fe14fcc3 | 3550 | #ifndef HAS_HTONL |
fe14fcc3 LW |
3551 | #define HAS_HTONS |
3552 | #define HAS_HTONL | |
3553 | #define HAS_NTOHS | |
3554 | #define HAS_NTOHL | |
8e2d7c44 NC |
3555 | # if (BYTEORDER & 0xffff) == 0x4321 |
3556 | /* Big endian system, so ntohl, ntohs, htonl and htons do not need to | |
3557 | re-order their values. However, to behave identically to the alternative | |
3558 | implementations, they should truncate to the correct size. */ | |
3559 | # define ntohl(x) ((x)&0xFFFFFFFF) | |
3560 | # define htonl(x) ntohl(x) | |
3561 | # define ntohs(x) ((x)&0xFFFF) | |
3562 | # define htons(x) ntohs(x) | |
e4b03fed NC |
3563 | # elif BYTEORDER == 0x1234 || BYTEORDER == 0x12345678 |
3564 | ||
3565 | /* Note that we can't straight out declare our own htonl and htons because | |
3566 | the Win32 build process forcibly undefines HAS_HTONL etc for its miniperl, | |
3567 | to avoid the overhead of initialising the socket subsystem, but the headers | |
3568 | that *declare* the various functions are still seen. If we declare our own | |
3569 | htonl etc they will clash with the declarations in the Win32 headers. */ | |
3570 | ||
3571 | PERL_STATIC_INLINE U32 | |
3572 | my_swap32(const U32 x) { | |
3573 | return ((x & 0xFF) << 24) | ((x >> 24) & 0xFF) | |
3574 | | ((x & 0x0000FF00) << 8) | ((x & 0x00FF0000) >> 8); | |
3575 | } | |
3576 | ||
3577 | PERL_STATIC_INLINE U16 | |
3578 | my_swap16(const U16 x) { | |
3579 | return ((x & 0xFF) << 8) | ((x >> 8) & 0xFF); | |
3580 | } | |
3581 | ||
3582 | # define htonl(x) my_swap32(x) | |
3583 | # define ntohl(x) my_swap32(x) | |
3584 | # define ntohs(x) my_swap16(x) | |
3585 | # define htons(x) my_swap16(x) | |
8e2d7c44 | 3586 | # else |
691a44df NC |
3587 | # error "Unsupported byteorder" |
3588 | /* The C pre-processor doesn't let us return the value of BYTEORDER as part of | |
3589 | the error message. Please check the value of the macro BYTEORDER, as defined | |
3590 | in config.h. The values of BYTEORDER we expect are | |
3591 | ||
3592 | big endian little endian | |
3593 | 32 bit 0x4321 0x1234 | |
3594 | 64 bit 0x87654321 0x12345678 | |
3595 | ||
3596 | If you have a system with a different byte order, please see | |
3597 | pod/perlhack.pod for how to submit a patch to add supporting code. | |
3598 | */ | |
3599 | # endif | |
a687059c LW |
3600 | #endif |
3601 | ||
988174c1 LW |
3602 | /* |
3603 | * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'. | |
3604 | * -DWS | |
3605 | */ | |
5ae72479 | 3606 | #if BYTEORDER == 0x1234 || BYTEORDER == 0x12345678 |
260c6fee NC |
3607 | /* Little endian system, so vtohl, vtohs, htovl and htovs do not need to |
3608 | re-order their values. However, to behave identically to the alternative | |
3609 | implementations, they should truncate to the correct size. */ | |
3610 | # define vtohl(x) ((x)&0xFFFFFFFF) | |
3611 | # define vtohs(x) ((x)&0xFFFF) | |
3612 | # define htovl(x) vtohl(x) | |
3613 | # define htovs(x) vtohs(x) | |
545872c5 | 3614 | #elif BYTEORDER == 0x4321 || BYTEORDER == 0x87654321 |
988174c1 LW |
3615 | # define vtohl(x) ((((x)&0xFF)<<24) \ |
3616 | +(((x)>>24)&0xFF) \ | |
3617 | +(((x)&0x0000FF00)<<8) \ | |
3618 | +(((x)&0x00FF0000)>>8) ) | |
3619 | # define vtohs(x) ((((x)&0xFF)<<8) + (((x)>>8)&0xFF)) | |
3620 | # define htovl(x) vtohl(x) | |
3621 | # define htovs(x) vtohs(x) | |
545872c5 NC |
3622 | #else |
3623 | # error "Unsupported byteorder" | |
3624 | /* If you have need for current perl on PDP-11 or similar, and can help test | |
3625 | that blead keeps working on a mixed-endian system, then see | |
3626 | pod/perlhack.pod for how to submit patches to things working again. */ | |
2a8c3029 | 3627 | #endif |
988174c1 | 3628 | |
3bb7c1b4 JH |
3629 | /* *MAX Plus 1. A floating point value. |
3630 | Hopefully expressed in a way that dodgy floating point can't mess up. | |
3631 | >> 2 rather than 1, so that value is safely less than I32_MAX after 1 | |
3632 | is added to it | |
3633 | May find that some broken compiler will want the value cast to I32. | |
3634 | [after the shift, as signed >> may not be as secure as unsigned >>] | |
3635 | */ | |
3636 | #define I32_MAX_P1 (2.0 * (1 + (((U32)I32_MAX) >> 1))) | |
3637 | #define U32_MAX_P1 (4.0 * (1 + ((U32_MAX) >> 2))) | |
3638 | /* For compilers that can't correctly cast NVs over 0x7FFFFFFF (or | |
3639 | 0x7FFFFFFFFFFFFFFF) to an unsigned integer. In the future, sizeof(UV) | |
3640 | may be greater than sizeof(IV), so don't assume that half max UV is max IV. | |
3641 | */ | |
3642 | #define U32_MAX_P1_HALF (2.0 * (1 + ((U32_MAX) >> 2))) | |
ee0007ab | 3643 | |
3bb7c1b4 JH |
3644 | #define UV_MAX_P1 (4.0 * (1 + ((UV_MAX) >> 2))) |
3645 | #define IV_MAX_P1 (2.0 * (1 + (((UV)IV_MAX) >> 1))) | |
3646 | #define UV_MAX_P1_HALF (2.0 * (1 + ((UV_MAX) >> 2))) | |
3647 | ||
3648 | /* This may look like unnecessary jumping through hoops, but converting | |
3649 | out of range floating point values to integers *is* undefined behaviour, | |
3650 | and it is starting to bite. | |
3651 | */ | |
3652 | #ifndef CAST_INLINE | |
65202027 | 3653 | #define I_32(what) (cast_i32((NV)(what))) |
3bb7c1b4 | 3654 | #define U_32(what) (cast_ulong((NV)(what))) |
65202027 DS |
3655 | #define I_V(what) (cast_iv((NV)(what))) |
3656 | #define U_V(what) (cast_uv((NV)(what))) | |
3bb7c1b4 JH |
3657 | #else |
3658 | #define I_32(n) ((n) < I32_MAX_P1 ? ((n) < I32_MIN ? I32_MIN : (I32) (n)) \ | |
3659 | : ((n) < U32_MAX_P1 ? (I32)(U32) (n) \ | |
3660 | : ((n) > 0 ? (I32) U32_MAX : 0 /* NaN */))) | |
3661 | #define U_32(n) ((n) < 0.0 ? ((n) < I32_MIN ? (UV) I32_MIN : (U32)(I32) (n)) \ | |
3662 | : ((n) < U32_MAX_P1 ? (U32) (n) \ | |
3663 | : ((n) > 0 ? U32_MAX : 0 /* NaN */))) | |
5d9574c1 DM |
3664 | #define I_V(n) (LIKELY((n) < IV_MAX_P1) ? (UNLIKELY((n) < IV_MIN) ? IV_MIN : (IV) (n)) \ |
3665 | : (LIKELY((n) < UV_MAX_P1) ? (IV)(UV) (n) \ | |
3bb7c1b4 | 3666 | : ((n) > 0 ? (IV)UV_MAX : 0 /* NaN */))) |
5d9574c1 DM |
3667 | #define U_V(n) ((n) < 0.0 ? (UNLIKELY((n) < IV_MIN) ? (UV) IV_MIN : (UV)(IV) (n)) \ |
3668 | : (LIKELY((n) < UV_MAX_P1) ? (UV) (n) \ | |
3bb7c1b4 JH |
3669 | : ((n) > 0 ? UV_MAX : 0 /* NaN */))) |
3670 | #endif | |
3671 | ||
3672 | #define U_S(what) ((U16)U_32(what)) | |
3673 | #define U_I(what) ((unsigned int)U_32(what)) | |
3674 | #define U_L(what) U_32(what) | |
ed6116ce | 3675 | |
ed140128 AD |
3676 | #ifdef HAS_SIGNBIT |
3677 | # define Perl_signbit signbit | |
3678 | #endif | |
3679 | ||
2d4389e4 JH |
3680 | /* These do not care about the fractional part, only about the range. */ |
3681 | #define NV_WITHIN_IV(nv) (I_V(nv) >= IV_MIN && I_V(nv) <= IV_MAX) | |
24db6c0d | 3682 | #define NV_WITHIN_UV(nv) ((nv)>=0.0 && U_V(nv) >= UV_MIN && U_V(nv) <= UV_MAX) |
2d4389e4 | 3683 | |
25da4f38 IZ |
3684 | /* Used with UV/IV arguments: */ |
3685 | /* XXXX: need to speed it up */ | |
3686 | #define CLUMP_2UV(iv) ((iv) < 0 ? 0 : (UV)(iv)) | |
3687 | #define CLUMP_2IV(uv) ((uv) > (UV)IV_MAX ? IV_MAX : (IV)(uv)) | |
3688 | ||
352d5a3a LW |
3689 | #ifndef MAXSYSFD |
3690 | # define MAXSYSFD 2 | |
3691 | #endif | |
ee0007ab | 3692 | |
79072805 | 3693 | #ifndef __cplusplus |
e37d7e38 | 3694 | #if !(defined(WIN32) || defined(UNDER_CE) || defined(SYMBIAN)) |
20ce7b12 GS |
3695 | Uid_t getuid (void); |
3696 | Uid_t geteuid (void); | |
3697 | Gid_t getgid (void); | |
3698 | Gid_t getegid (void); | |
79072805 | 3699 | #endif |
e1caacb4 | 3700 | #endif |
8d063cd8 | 3701 | |
0c30d9ec | 3702 | #ifndef Perl_debug_log |
bf49b057 GS |
3703 | # define Perl_debug_log PerlIO_stderr() |
3704 | #endif | |
3705 | ||
3706 | #ifndef Perl_error_log | |
3707 | # define Perl_error_log (PL_stderrgv \ | |
6b78add2 | 3708 | && isGV(PL_stderrgv) \ |
01bb7c6d | 3709 | && GvIOp(PL_stderrgv) \ |
42de951c | 3710 | && IoOFP(GvIOp(PL_stderrgv)) \ |
bf49b057 GS |
3711 | ? IoOFP(GvIOp(PL_stderrgv)) \ |
3712 | : PerlIO_stderr()) | |
0c30d9ec | 3713 | #endif |
3967c732 | 3714 | |
aea4f609 DM |
3715 | |
3716 | #define DEBUG_p_FLAG 0x00000001 /* 1 */ | |
3717 | #define DEBUG_s_FLAG 0x00000002 /* 2 */ | |
3718 | #define DEBUG_l_FLAG 0x00000004 /* 4 */ | |
3719 | #define DEBUG_t_FLAG 0x00000008 /* 8 */ | |
3720 | #define DEBUG_o_FLAG 0x00000010 /* 16 */ | |
3721 | #define DEBUG_c_FLAG 0x00000020 /* 32 */ | |
3722 | #define DEBUG_P_FLAG 0x00000040 /* 64 */ | |
3723 | #define DEBUG_m_FLAG 0x00000080 /* 128 */ | |
3724 | #define DEBUG_f_FLAG 0x00000100 /* 256 */ | |
3725 | #define DEBUG_r_FLAG 0x00000200 /* 512 */ | |
3726 | #define DEBUG_x_FLAG 0x00000400 /* 1024 */ | |
3727 | #define DEBUG_u_FLAG 0x00000800 /* 2048 */ | |
88d2d28a JC |
3728 | /* U is reserved for Unofficial, exploratory hacking */ |
3729 | #define DEBUG_U_FLAG 0x00001000 /* 4096 */ | |
fcd573e7 | 3730 | /* spare 8192 */ |
aea4f609 DM |
3731 | #define DEBUG_X_FLAG 0x00004000 /* 16384 */ |
3732 | #define DEBUG_D_FLAG 0x00008000 /* 32768 */ | |
56967202 | 3733 | #define DEBUG_S_FLAG 0x00010000 /* 65536 */ |
aea4f609 | 3734 | #define DEBUG_T_FLAG 0x00020000 /* 131072 */ |
04932ac8 | 3735 | #define DEBUG_R_FLAG 0x00040000 /* 262144 */ |
1045810a | 3736 | #define DEBUG_J_FLAG 0x00080000 /* 524288 */ |
d6721266 | 3737 | #define DEBUG_v_FLAG 0x00100000 /*1048576 */ |
46187eeb | 3738 | #define DEBUG_C_FLAG 0x00200000 /*2097152 */ |
ecae49c0 | 3739 | #define DEBUG_A_FLAG 0x00400000 /*4194304 */ |
a3c98653 | 3740 | #define DEBUG_q_FLAG 0x00800000 /*8388608 */ |
cc8773c0 CS |
3741 | #define DEBUG_M_FLAG 0x01000000 /*16777216*/ |
3742 | #define DEBUG_B_FLAG 0x02000000 /*33554432*/ | |
69014004 | 3743 | #define DEBUG_L_FLAG 0x04000000 /*67108864*/ |
e17bc05a TC |
3744 | #define DEBUG_i_FLAG 0x08000000 /*134217728*/ |
3745 | #define DEBUG_MASK 0x0FFFEFFF /* mask of all the standard flags */ | |
aea4f609 DM |
3746 | |
3747 | #define DEBUG_DB_RECURSE_FLAG 0x40000000 | |
31ada1fb | 3748 | #define DEBUG_TOP_FLAG 0x80000000 /* -D was given --> PL_debug |= FLAG */ |
aea4f609 | 3749 | |
36195052 KW |
3750 | # define DEBUG_p_TEST_ UNLIKELY(PL_debug & DEBUG_p_FLAG) |
3751 | # define DEBUG_s_TEST_ UNLIKELY(PL_debug & DEBUG_s_FLAG) | |
3752 | # define DEBUG_l_TEST_ UNLIKELY(PL_debug & DEBUG_l_FLAG) | |
3753 | # define DEBUG_t_TEST_ UNLIKELY(PL_debug & DEBUG_t_FLAG) | |
3754 | # define DEBUG_o_TEST_ UNLIKELY(PL_debug & DEBUG_o_FLAG) | |
3755 | # define DEBUG_c_TEST_ UNLIKELY(PL_debug & DEBUG_c_FLAG) | |
3756 | # define DEBUG_P_TEST_ UNLIKELY(PL_debug & DEBUG_P_FLAG) | |
3757 | # define DEBUG_m_TEST_ UNLIKELY(PL_debug & DEBUG_m_FLAG) | |
3758 | # define DEBUG_f_TEST_ UNLIKELY(PL_debug & DEBUG_f_FLAG) | |
3759 | # define DEBUG_r_TEST_ UNLIKELY(PL_debug & DEBUG_r_FLAG) | |
3760 | # define DEBUG_x_TEST_ UNLIKELY(PL_debug & DEBUG_x_FLAG) | |
3761 | # define DEBUG_u_TEST_ UNLIKELY(PL_debug & DEBUG_u_FLAG) | |
3762 | # define DEBUG_U_TEST_ UNLIKELY(PL_debug & DEBUG_U_FLAG) | |
36195052 KW |
3763 | # define DEBUG_X_TEST_ UNLIKELY(PL_debug & DEBUG_X_FLAG) |
3764 | # define DEBUG_D_TEST_ UNLIKELY(PL_debug & DEBUG_D_FLAG) | |
3765 | # define DEBUG_S_TEST_ UNLIKELY(PL_debug & DEBUG_S_FLAG) | |
3766 | # define DEBUG_T_TEST_ UNLIKELY(PL_debug & DEBUG_T_FLAG) | |
3767 | # define DEBUG_R_TEST_ UNLIKELY(PL_debug & DEBUG_R_FLAG) | |
3768 | # define DEBUG_J_TEST_ UNLIKELY(PL_debug & DEBUG_J_FLAG) | |
3769 | # define DEBUG_v_TEST_ UNLIKELY(PL_debug & DEBUG_v_FLAG) | |
3770 | # define DEBUG_C_TEST_ UNLIKELY(PL_debug & DEBUG_C_FLAG) | |
3771 | # define DEBUG_A_TEST_ UNLIKELY(PL_debug & DEBUG_A_FLAG) | |
3772 | # define DEBUG_q_TEST_ UNLIKELY(PL_debug & DEBUG_q_FLAG) | |
3773 | # define DEBUG_M_TEST_ UNLIKELY(PL_debug & DEBUG_M_FLAG) | |
3774 | # define DEBUG_B_TEST_ UNLIKELY(PL_debug & DEBUG_B_FLAG) | |
3775 | # define DEBUG_L_TEST_ UNLIKELY(PL_debug & DEBUG_L_FLAG) | |
3776 | # define DEBUG_i_TEST_ UNLIKELY(PL_debug & DEBUG_i_FLAG) | |
dd2155a4 | 3777 | # define DEBUG_Xv_TEST_ (DEBUG_X_TEST_ && DEBUG_v_TEST_) |
7949c6f5 | 3778 | # define DEBUG_Uv_TEST_ (DEBUG_U_TEST_ && DEBUG_v_TEST_) |
ad9e76a8 | 3779 | # define DEBUG_Pv_TEST_ (DEBUG_P_TEST_ && DEBUG_v_TEST_) |
bbc98134 | 3780 | # define DEBUG_Lv_TEST_ (DEBUG_L_TEST_ && DEBUG_v_TEST_) |
bd16a5f0 | 3781 | |
3967c732 | 3782 | #ifdef DEBUGGING |
aea4f609 | 3783 | |
bd16a5f0 IZ |
3784 | # define DEBUG_p_TEST DEBUG_p_TEST_ |
3785 | # define DEBUG_s_TEST DEBUG_s_TEST_ | |
3786 | # define DEBUG_l_TEST DEBUG_l_TEST_ | |
3787 | # define DEBUG_t_TEST DEBUG_t_TEST_ | |
3788 | # define DEBUG_o_TEST DEBUG_o_TEST_ | |
3789 | # define DEBUG_c_TEST DEBUG_c_TEST_ | |
3790 | # define DEBUG_P_TEST DEBUG_P_TEST_ | |
3791 | # define DEBUG_m_TEST DEBUG_m_TEST_ | |
3792 | # define DEBUG_f_TEST DEBUG_f_TEST_ | |
3793 | # define DEBUG_r_TEST DEBUG_r_TEST_ | |
3794 | # define DEBUG_x_TEST DEBUG_x_TEST_ | |
3795 | # define DEBUG_u_TEST DEBUG_u_TEST_ | |
88d2d28a | 3796 | # define DEBUG_U_TEST DEBUG_U_TEST_ |
bd16a5f0 IZ |
3797 | # define DEBUG_X_TEST DEBUG_X_TEST_ |
3798 | # define DEBUG_D_TEST DEBUG_D_TEST_ | |
56967202 | 3799 | # define DEBUG_S_TEST DEBUG_S_TEST_ |
bd16a5f0 IZ |
3800 | # define DEBUG_T_TEST DEBUG_T_TEST_ |
3801 | # define DEBUG_R_TEST DEBUG_R_TEST_ | |
1045810a | 3802 | # define DEBUG_J_TEST DEBUG_J_TEST_ |
d6721266 | 3803 | # define DEBUG_v_TEST DEBUG_v_TEST_ |
46187eeb | 3804 | # define DEBUG_C_TEST DEBUG_C_TEST_ |
ecae49c0 | 3805 | # define DEBUG_A_TEST DEBUG_A_TEST_ |
a3c98653 | 3806 | # define DEBUG_q_TEST DEBUG_q_TEST_ |
d7c0d282 | 3807 | # define DEBUG_M_TEST DEBUG_M_TEST_ |
cc8773c0 | 3808 | # define DEBUG_B_TEST DEBUG_B_TEST_ |
69014004 | 3809 | # define DEBUG_L_TEST DEBUG_L_TEST_ |
e17bc05a | 3810 | # define DEBUG_i_TEST DEBUG_i_TEST_ |
7949c6f5 JC |
3811 | # define DEBUG_Xv_TEST DEBUG_Xv_TEST_ |
3812 | # define DEBUG_Uv_TEST DEBUG_Uv_TEST_ | |
ad9e76a8 | 3813 | # define DEBUG_Pv_TEST DEBUG_Pv_TEST_ |
bbc98134 | 3814 | # define DEBUG_Lv_TEST DEBUG_Lv_TEST_ |
aea4f609 | 3815 | |
488b0c7a | 3816 | # define PERL_DEB(a) a |
11f9ab1a | 3817 | # define PERL_DEB2(a,b) a |
488b0c7a | 3818 | # define PERL_DEBUG(a) if (PL_debug) a |
aea4f609 DM |
3819 | # define DEBUG_p(a) if (DEBUG_p_TEST) a |
3820 | # define DEBUG_s(a) if (DEBUG_s_TEST) a | |
3821 | # define DEBUG_l(a) if (DEBUG_l_TEST) a | |
3822 | # define DEBUG_t(a) if (DEBUG_t_TEST) a | |
3823 | # define DEBUG_o(a) if (DEBUG_o_TEST) a | |
3824 | # define DEBUG_c(a) if (DEBUG_c_TEST) a | |
3825 | # define DEBUG_P(a) if (DEBUG_P_TEST) a | |
3826 | ||
969058bb VK |
3827 | /* Temporarily turn off memory debugging in case the a |
3828 | * does memory allocation, either directly or indirectly. */ | |
acfe0abc | 3829 | # define DEBUG_m(a) \ |
f60d22a6 KW |
3830 | STMT_START { \ |
3831 | if (PERL_GET_INTERP) { \ | |
3832 | dTHX; \ | |
3833 | if (DEBUG_m_TEST) { \ | |
3834 | PL_debug &= ~DEBUG_m_FLAG; \ | |
3835 | a; \ | |
3836 | PL_debug |= DEBUG_m_FLAG; \ | |
3837 | } \ | |
3838 | } \ | |
0b250b9e | 3839 | } STMT_END |
aea4f609 | 3840 | |
f60d22a6 KW |
3841 | # define DEBUG__(t, a) \ |
3842 | STMT_START { \ | |
3843 | if (t) STMT_START {a;} STMT_END; \ | |
3844 | } STMT_END | |
5f80b19c AMS |
3845 | |
3846 | # define DEBUG_f(a) DEBUG__(DEBUG_f_TEST, a) | |
f60d22a6 | 3847 | |
f9f4320a | 3848 | #ifndef PERL_EXT_RE_BUILD |
5f80b19c | 3849 | # define DEBUG_r(a) DEBUG__(DEBUG_r_TEST, a) |
f9f4320a YO |
3850 | #else |
3851 | # define DEBUG_r(a) STMT_START {a;} STMT_END | |
3852 | #endif /* PERL_EXT_RE_BUILD */ | |
f60d22a6 | 3853 | |
5f80b19c AMS |
3854 | # define DEBUG_x(a) DEBUG__(DEBUG_x_TEST, a) |
3855 | # define DEBUG_u(a) DEBUG__(DEBUG_u_TEST, a) | |
88d2d28a | 3856 | # define DEBUG_U(a) DEBUG__(DEBUG_U_TEST, a) |
5f80b19c AMS |
3857 | # define DEBUG_X(a) DEBUG__(DEBUG_X_TEST, a) |
3858 | # define DEBUG_D(a) DEBUG__(DEBUG_D_TEST, a) | |
7949c6f5 JC |
3859 | # define DEBUG_Xv(a) DEBUG__(DEBUG_Xv_TEST, a) |
3860 | # define DEBUG_Uv(a) DEBUG__(DEBUG_Uv_TEST, a) | |
ad9e76a8 | 3861 | # define DEBUG_Pv(a) DEBUG__(DEBUG_Pv_TEST, a) |
bbc98134 | 3862 | # define DEBUG_Lv(a) DEBUG__(DEBUG_Lv_TEST, a) |
aea4f609 | 3863 | |
56967202 | 3864 | # define DEBUG_S(a) DEBUG__(DEBUG_S_TEST, a) |
5f80b19c AMS |
3865 | # define DEBUG_T(a) DEBUG__(DEBUG_T_TEST, a) |
3866 | # define DEBUG_R(a) DEBUG__(DEBUG_R_TEST, a) | |
d6721266 | 3867 | # define DEBUG_v(a) DEBUG__(DEBUG_v_TEST, a) |
46187eeb | 3868 | # define DEBUG_C(a) DEBUG__(DEBUG_C_TEST, a) |
ecae49c0 NC |
3869 | # define DEBUG_A(a) DEBUG__(DEBUG_A_TEST, a) |
3870 | # define DEBUG_q(a) DEBUG__(DEBUG_q_TEST, a) | |
d7c0d282 | 3871 | # define DEBUG_M(a) DEBUG__(DEBUG_M_TEST, a) |
cc8773c0 | 3872 | # define DEBUG_B(a) DEBUG__(DEBUG_B_TEST, a) |
69014004 | 3873 | # define DEBUG_L(a) DEBUG__(DEBUG_L_TEST, a) |
e17bc05a | 3874 | # define DEBUG_i(a) DEBUG__(DEBUG_i_TEST, a) |
aea4f609 DM |
3875 | |
3876 | #else /* DEBUGGING */ | |
3877 | ||
3878 | # define DEBUG_p_TEST (0) | |
3879 | # define DEBUG_s_TEST (0) | |
3880 | # define DEBUG_l_TEST (0) | |
3881 | # define DEBUG_t_TEST (0) | |
3882 | # define DEBUG_o_TEST (0) | |
3883 | # define DEBUG_c_TEST (0) | |
3884 | # define DEBUG_P_TEST (0) | |
3885 | # define DEBUG_m_TEST (0) | |
3886 | # define DEBUG_f_TEST (0) | |
3887 | # define DEBUG_r_TEST (0) | |
3888 | # define DEBUG_x_TEST (0) | |
3889 | # define DEBUG_u_TEST (0) | |
88d2d28a | 3890 | # define DEBUG_U_TEST (0) |
aea4f609 DM |
3891 | # define DEBUG_X_TEST (0) |
3892 | # define DEBUG_D_TEST (0) | |
56967202 | 3893 | # define DEBUG_S_TEST (0) |
aea4f609 | 3894 | # define DEBUG_T_TEST (0) |
04932ac8 | 3895 | # define DEBUG_R_TEST (0) |
1045810a | 3896 | # define DEBUG_J_TEST (0) |
d6721266 | 3897 | # define DEBUG_v_TEST (0) |
46187eeb | 3898 | # define DEBUG_C_TEST (0) |
ecae49c0 NC |
3899 | # define DEBUG_A_TEST (0) |
3900 | # define DEBUG_q_TEST (0) | |
d7c0d282 | 3901 | # define DEBUG_M_TEST (0) |
cc8773c0 | 3902 | # define DEBUG_B_TEST (0) |
69014004 | 3903 | # define DEBUG_L_TEST (0) |
e17bc05a | 3904 | # define DEBUG_i_TEST (0) |
7949c6f5 JC |
3905 | # define DEBUG_Xv_TEST (0) |
3906 | # define DEBUG_Uv_TEST (0) | |
ad9e76a8 | 3907 | # define DEBUG_Pv_TEST (0) |
bbc98134 | 3908 | # define DEBUG_Lv_TEST (0) |
aea4f609 | 3909 | |
488b0c7a | 3910 | # define PERL_DEB(a) |
11f9ab1a | 3911 | # define PERL_DEB2(a,b) b |
488b0c7a | 3912 | # define PERL_DEBUG(a) |
aea4f609 DM |
3913 | # define DEBUG_p(a) |
3914 | # define DEBUG_s(a) | |
3915 | # define DEBUG_l(a) | |
3916 | # define DEBUG_t(a) | |
3917 | # define DEBUG_o(a) | |
3918 | # define DEBUG_c(a) | |
3919 | # define DEBUG_P(a) | |
3920 | # define DEBUG_m(a) | |
3921 | # define DEBUG_f(a) | |
3922 | # define DEBUG_r(a) | |
3923 | # define DEBUG_x(a) | |
3924 | # define DEBUG_u(a) | |
88d2d28a | 3925 | # define DEBUG_U(a) |
aea4f609 DM |
3926 | # define DEBUG_X(a) |
3927 | # define DEBUG_D(a) | |
56967202 | 3928 | # define DEBUG_S(a) |
aea4f609 | 3929 | # define DEBUG_T(a) |
04932ac8 | 3930 | # define DEBUG_R(a) |
d6721266 | 3931 | # define DEBUG_v(a) |
46187eeb | 3932 | # define DEBUG_C(a) |
ecae49c0 NC |
3933 | # define DEBUG_A(a) |
3934 | # define DEBUG_q(a) | |
d7c0d282 | 3935 | # define DEBUG_M(a) |
cc8773c0 | 3936 | # define DEBUG_B(a) |
69014004 | 3937 | # define DEBUG_L(a) |
e17bc05a | 3938 | # define DEBUG_i(a) |
7949c6f5 JC |
3939 | # define DEBUG_Xv(a) |
3940 | # define DEBUG_Uv(a) | |
ad9e76a8 | 3941 | # define DEBUG_Pv(a) |
bbc98134 | 3942 | # define DEBUG_Lv(a) |
aea4f609 DM |
3943 | #endif /* DEBUGGING */ |
3944 | ||
3945 | ||
b4ab917c | 3946 | #define DEBUG_SCOPE(where) \ |
d9f81b50 | 3947 | DEBUG_l( \ |
1c98cc53 DM |
3948 | Perl_deb(aTHX_ "%s scope %ld (savestack=%ld) at %s:%d\n", \ |
3949 | where, (long)PL_scopestack_ix, (long)PL_savestack_ix, \ | |
d9f81b50 | 3950 | __FILE__, __LINE__)); |
b4ab917c | 3951 | |
de84dc04 | 3952 | /* Keep the old croak based assert for those who want it, and as a fallback if |
27ceb597 | 3953 | the platform is so heretically non-ANSI that it can't assert. */ |
14befaf4 | 3954 | |
11f9ab1a | 3955 | #define Perl_assert(what) PERL_DEB2( \ |
2b057284 | 3956 | ((what) ? ((void) 0) : \ |
67eb4d30 | 3957 | (Perl_croak_nocontext("Assertion %s failed: file \"" __FILE__ \ |
60b9f5a7 | 3958 | "\", line %d", STRINGIFY(what), __LINE__), \ |
11f9ab1a | 3959 | (void) 0)), ((void)0)) |
de84dc04 | 3960 | |
6ff2ec7d | 3961 | /* assert() gets defined if DEBUGGING. |
81d52ecd | 3962 | * If no DEBUGGING, the <assert.h> has not been included. */ |
de84dc04 NC |
3963 | #ifndef assert |
3964 | # define assert(what) Perl_assert(what) | |
a446a88f | 3965 | #endif |
c7724415 FC |
3966 | #ifdef DEBUGGING |
3967 | # define assert_(what) assert(what), | |
3968 | #else | |
3969 | # define assert_(what) | |
3970 | #endif | |
8d063cd8 | 3971 | |
450a55e4 | 3972 | struct ufuncs { |
24f81a43 DM |
3973 | I32 (*uf_val)(pTHX_ IV, SV*); |
3974 | I32 (*uf_set)(pTHX_ IV, SV*); | |
a0d0e21e | 3975 | IV uf_index; |
450a55e4 LW |
3976 | }; |
3977 | ||
14befaf4 | 3978 | /* In pre-5.7-Perls the PERL_MAGIC_uvar magic didn't get the thread context. |
24f81a43 DM |
3979 | * XS code wanting to be backward compatible can do something |
3980 | * like the following: | |
c745e42c | 3981 | |
24f81a43 | 3982 | #ifndef PERL_MG_UFUNC |
24f81a43 DM |
3983 | #define PERL_MG_UFUNC(name,ix,sv) I32 name(IV ix, SV *sv) |
3984 | #endif | |
3985 | ||
3986 | static PERL_MG_UFUNC(foo_get, index, val) | |
3987 | { | |
3988 | sv_setsv(val, ...); | |
3989 | return TRUE; | |
3990 | } | |
3991 | ||
3992 | -- Doug MacEachern | |
3993 | ||
3994 | */ | |
3995 | ||
fc9c74e6 | 3996 | #ifndef PERL_MG_UFUNC |
24f81a43 | 3997 | #define PERL_MG_UFUNC(name,ix,sv) I32 name(pTHX_ IV ix, SV *sv) |
fc9c74e6 | 3998 | #endif |
24f81a43 | 3999 | |
7e034659 AC |
4000 | #include <math.h> |
4001 | #ifdef __VMS | |
a80f53e7 | 4002 | /* isfinite and others are here rather than in math.h as C99 stipulates */ |
7e034659 | 4003 | # include <fp.h> |
79072805 LW |
4004 | #endif |
4005 | ||
a0d0e21e | 4006 | #ifndef __cplusplus |
f05550c0 | 4007 | # if !defined(WIN32) && !defined(VMS) |
10bc17b6 | 4008 | #ifndef crypt |
20ce7b12 | 4009 | char *crypt (const char*, const char*); |
10bc17b6 | 4010 | #endif |
f05550c0 | 4011 | # endif /* !WIN32 */ |
e37d7e38 SH |
4012 | # ifndef WIN32 |
4013 | # ifndef getlogin | |
20ce7b12 | 4014 | char *getlogin (void); |
e37d7e38 SH |
4015 | # endif |
4016 | # endif /* !WIN32 */ | |
26618a56 | 4017 | #endif /* !__cplusplus */ |
79072805 | 4018 | |
7a7fd8e0 JM |
4019 | /* Fixme on VMS. This needs to be a run-time, not build time options */ |
4020 | /* Also rename() is affected by this */ | |
16d20bd9 | 4021 | #ifdef UNLINK_ALL_VERSIONS /* Currently only makes sense for VMS */ |
378cc40b | 4022 | #define UNLINK unlnk |
083639a9 | 4023 | I32 unlnk (pTHX_ const char*); |
8d063cd8 | 4024 | #else |
80252599 | 4025 | #define UNLINK PerlLIO_unlink |
8d063cd8 | 4026 | #endif |
a687059c | 4027 | |
fa0a29af JH |
4028 | /* some versions of glibc are missing the setresuid() proto */ |
4029 | #if defined(HAS_SETRESUID) && !defined(HAS_SETRESUID_PROTO) | |
640374d0 JH |
4030 | int setresuid(uid_t ruid, uid_t euid, uid_t suid); |
4031 | #endif | |
fa0a29af JH |
4032 | /* some versions of glibc are missing the setresgid() proto */ |
4033 | #if defined(HAS_SETRESGID) && !defined(HAS_SETRESGID_PROTO) | |
640374d0 JH |
4034 | int setresgid(gid_t rgid, gid_t egid, gid_t sgid); |
4035 | #endif | |
4036 | ||
fe14fcc3 | 4037 | #ifndef HAS_SETREUID |
85e6fe83 LW |
4038 | # ifdef HAS_SETRESUID |
4039 | # define setreuid(r,e) setresuid(r,e,(Uid_t)-1) | |
4040 | # define HAS_SETREUID | |
4041 | # endif | |
a687059c | 4042 | #endif |
fe14fcc3 | 4043 | #ifndef HAS_SETREGID |
85e6fe83 LW |
4044 | # ifdef HAS_SETRESGID |
4045 | # define setregid(r,e) setresgid(r,e,(Gid_t)-1) | |
4046 | # define HAS_SETREGID | |
4047 | # endif | |
a687059c | 4048 | #endif |
ee0007ab | 4049 | |
d543acb6 | 4050 | /* Sighandler_t defined in iperlsys.h */ |
ff68c719 | 4051 | |
4052 | #ifdef HAS_SIGACTION | |
4053 | typedef struct sigaction Sigsave_t; | |
4054 | #else | |
4055 | typedef Sighandler_t Sigsave_t; | |
4056 | #endif | |
4057 | ||
ee0007ab LW |
4058 | #define SCAN_DEF 0 |
4059 | #define SCAN_TR 1 | |
4060 | #define SCAN_REPL 2 | |
79072805 LW |
4061 | |
4062 | #ifdef DEBUGGING | |
4633a7c4 | 4063 | # ifndef register |
a0d0e21e LW |
4064 | # define register |
4065 | # endif | |
cea2e8a9 | 4066 | # define RUNOPS_DEFAULT Perl_runops_debug |
79072805 | 4067 | #else |
cea2e8a9 | 4068 | # define RUNOPS_DEFAULT Perl_runops_standard |
79072805 LW |
4069 | #endif |
4070 | ||
97cb92d6 | 4071 | #if defined(USE_PERLIO) |
0934c9d9 | 4072 | EXTERN_C void PerlIO_teardown(void); |
2f44961c | 4073 | # ifdef USE_ITHREADS |
6cb8cb21 RGS |
4074 | # define PERLIO_INIT MUTEX_INIT(&PL_perlio_mutex) |
4075 | # define PERLIO_TERM \ | |
4076 | STMT_START { \ | |
d0820ef1 | 4077 | PerlIO_teardown(); \ |
6cb8cb21 RGS |
4078 | MUTEX_DESTROY(&PL_perlio_mutex);\ |
4079 | } STMT_END | |
4080 | # else | |
4081 | # define PERLIO_INIT | |
d0820ef1 | 4082 | # define PERLIO_TERM PerlIO_teardown() |
6cb8cb21 | 4083 | # endif |
6b29934b NC |
4084 | #else |
4085 | # define PERLIO_INIT | |
4086 | # define PERLIO_TERM | |
6cb8cb21 RGS |
4087 | #endif |
4088 | ||
18f739ee | 4089 | #ifdef MYMALLOC |
772fe5b3 | 4090 | # ifdef MUTEX_INIT_CALLS_MALLOC |
3541dd58 HM |
4091 | # define MALLOC_INIT \ |
4092 | STMT_START { \ | |
4093 | PL_malloc_mutex = NULL; \ | |
4094 | MUTEX_INIT(&PL_malloc_mutex); \ | |
4095 | } STMT_END | |
4096 | # define MALLOC_TERM \ | |
4097 | STMT_START { \ | |
4098 | perl_mutex tmp = PL_malloc_mutex; \ | |
4099 | PL_malloc_mutex = NULL; \ | |
4100 | MUTEX_DESTROY(&tmp); \ | |
4101 | } STMT_END | |
4102 | # else | |
4103 | # define MALLOC_INIT MUTEX_INIT(&PL_malloc_mutex) | |
4104 | # define MALLOC_TERM MUTEX_DESTROY(&PL_malloc_mutex) | |
4105 | # endif | |
18f739ee IZ |
4106 | #else |
4107 | # define MALLOC_INIT | |
4108 | # define MALLOC_TERM | |
4109 | #endif | |
4110 | ||
cd1541b2 | 4111 | #if defined(PERL_IMPLICIT_CONTEXT) |
7cb608b5 NC |
4112 | |
4113 | struct perl_memory_debug_header; | |
cd1541b2 NC |
4114 | struct perl_memory_debug_header { |
4115 | tTHX interpreter; | |
b001a0d1 | 4116 | # if defined(PERL_POISON) || defined(PERL_DEBUG_READONLY_COW) |
cd1541b2 | 4117 | MEM_SIZE size; |
cd1541b2 | 4118 | # endif |
7cb608b5 NC |
4119 | struct perl_memory_debug_header *prev; |
4120 | struct perl_memory_debug_header *next; | |
b001a0d1 FC |
4121 | # ifdef PERL_DEBUG_READONLY_COW |
4122 | bool readonly; | |
4123 | # endif | |
4124 | }; | |
4125 | ||
4126 | #elif defined(PERL_DEBUG_READONLY_COW) | |
4127 | ||
4128 | struct perl_memory_debug_header; | |
4129 | struct perl_memory_debug_header { | |
4130 | MEM_SIZE size; | |
cd1541b2 NC |
4131 | }; |
4132 | ||
b001a0d1 FC |
4133 | #endif |
4134 | ||
60175f94 | 4135 | #if defined (PERL_TRACK_MEMPOOL) || defined (PERL_DEBUG_READONLY_COW) |
b001a0d1 | 4136 | |
a78adc84 DM |
4137 | # define PERL_MEMORY_DEBUG_HEADER_SIZE \ |
4138 | (sizeof(struct perl_memory_debug_header) + \ | |
cd1541b2 NC |
4139 | (MEM_ALIGNBYTES - sizeof(struct perl_memory_debug_header) \ |
4140 | %MEM_ALIGNBYTES) % MEM_ALIGNBYTES) | |
4141 | ||
d8fca402 | 4142 | #else |
a78adc84 | 4143 | # define PERL_MEMORY_DEBUG_HEADER_SIZE 0 |
cd1541b2 NC |
4144 | #endif |
4145 | ||
7cb608b5 | 4146 | #ifdef PERL_TRACK_MEMPOOL |
b001a0d1 | 4147 | # ifdef PERL_DEBUG_READONLY_COW |
7cb608b5 NC |
4148 | # define INIT_TRACK_MEMPOOL(header, interp) \ |
4149 | STMT_START { \ | |
4150 | (header).interpreter = (interp); \ | |
4151 | (header).prev = (header).next = &(header); \ | |
b001a0d1 | 4152 | (header).readonly = 0; \ |
7cb608b5 | 4153 | } STMT_END |
b001a0d1 FC |
4154 | # else |
4155 | # define INIT_TRACK_MEMPOOL(header, interp) \ | |
4156 | STMT_START { \ | |
4157 | (header).interpreter = (interp); \ | |
4158 | (header).prev = (header).next = &(header); \ | |
4159 | } STMT_END | |
4160 | # endif | |
4161 | # else | |
7cb608b5 NC |
4162 | # define INIT_TRACK_MEMPOOL(header, interp) |
4163 | #endif | |
4164 | ||
1cd66f7c DD |
4165 | #ifdef I_MALLOCMALLOC |
4166 | /* Needed for malloc_size(), malloc_good_size() on some systems */ | |
4167 | # include <malloc/malloc.h> | |
4168 | #endif | |
4169 | ||
ca7c1a29 NC |
4170 | #ifdef MYMALLOC |
4171 | # define Perl_safesysmalloc_size(where) Perl_malloced_size(where) | |
cfe52898 | 4172 | #else |
b001a0d1 | 4173 | # if defined(HAS_MALLOC_SIZE) && !defined(PERL_DEBUG_READONLY_COW) |
e82be400 | 4174 | # ifdef PERL_TRACK_MEMPOOL |
cfe52898 | 4175 | # define Perl_safesysmalloc_size(where) \ |
a78adc84 | 4176 | (malloc_size(((char *)(where)) - PERL_MEMORY_DEBUG_HEADER_SIZE) - PERL_MEMORY_DEBUG_HEADER_SIZE) |
e82be400 NC |
4177 | # else |
4178 | # define Perl_safesysmalloc_size(where) malloc_size(where) | |
4179 | # endif | |
4180 | # endif | |
4181 | # ifdef HAS_MALLOC_GOOD_SIZE | |
4182 | # ifdef PERL_TRACK_MEMPOOL | |
d8fca402 | 4183 | # define Perl_malloc_good_size(how_much) \ |
a78adc84 | 4184 | (malloc_good_size((how_much) + PERL_MEMORY_DEBUG_HEADER_SIZE) - PERL_MEMORY_DEBUG_HEADER_SIZE) |
e82be400 NC |
4185 | # else |
4186 | # define Perl_malloc_good_size(how_much) malloc_good_size(how_much) | |
4187 | # endif | |
4188 | # else | |
d8fca402 NC |
4189 | /* Having this as the identity operation makes some code simpler. */ |
4190 | # define Perl_malloc_good_size(how_much) (how_much) | |
e82be400 | 4191 | # endif |
ca7c1a29 | 4192 | #endif |
b6d9d515 | 4193 | |
16c91539 BM |
4194 | typedef int (*runops_proc_t)(pTHX); |
4195 | typedef void (*share_proc_t) (pTHX_ SV *sv); | |
4196 | typedef int (*thrhook_proc_t) (pTHX); | |
4197 | typedef OP* (*PPADDR_t[]) (pTHX); | |
4198 | typedef bool (*destroyable_proc_t) (pTHX_ SV *sv); | |
4199 | typedef void (*despatch_signals_proc_t) (pTHX); | |
22c35a8c | 4200 | |
f05550c0 BF |
4201 | #if defined(__DYNAMIC__) && defined(PERL_DARWIN) && defined(PERL_CORE) |
4202 | # include <crt_externs.h> /* for the env array */ | |
4203 | # define environ (*_NSGetEnviron()) | |
a54aca4b | 4204 | #elif defined(USE_ENVIRON_ARRAY) && !defined(environ) |
8f1f23e8 | 4205 | /* VMS and some other platforms don't use the environ array */ |
a54aca4b | 4206 | EXTERN_C char **environ; /* environment variables supplied via exec */ |
8f1f23e8 | 4207 | #endif |
79072805 | 4208 | |
457c5385 NC |
4209 | #define PERL_PATCHLEVEL_H_IMPLICIT |
4210 | #include "patchlevel.h" | |
4211 | #undef PERL_PATCHLEVEL_H_IMPLICIT | |
4212 | ||
4213 | #define PERL_VERSION_STRING STRINGIFY(PERL_REVISION) "." \ | |
4214 | STRINGIFY(PERL_VERSION) "." \ | |
4215 | STRINGIFY(PERL_SUBVERSION) | |
4216 | ||
4217 | #define PERL_API_VERSION_STRING STRINGIFY(PERL_API_REVISION) "." \ | |
4218 | STRINGIFY(PERL_API_VERSION) "." \ | |
4219 | STRINGIFY(PERL_API_SUBVERSION) | |
4220 | ||
73c4f7a1 GS |
4221 | START_EXTERN_C |
4222 | ||
79072805 | 4223 | /* handy constants */ |
22c35a8c | 4224 | EXTCONST char PL_warn_uninit[] |
29489e7c | 4225 | INIT("Use of uninitialized value%s%s%s"); |
fef7e7a0 | 4226 | EXTCONST char PL_warn_uninit_sv[] |
61608bb7 | 4227 | INIT("Use of uninitialized value%" SVf "%s%s"); |
22c35a8c | 4228 | EXTCONST char PL_warn_nosemi[] |
463ee0b2 | 4229 | INIT("Semicolon seems to be missing"); |
22c35a8c | 4230 | EXTCONST char PL_warn_reserved[] |
463ee0b2 | 4231 | INIT("Unquoted string \"%s\" may clash with future reserved word"); |
22c35a8c | 4232 | EXTCONST char PL_warn_nl[] |
93a17b20 | 4233 | INIT("Unsuccessful %s on filename containing newline"); |
22c35a8c | 4234 | EXTCONST char PL_no_wrongref[] |
a0d0e21e | 4235 | INIT("Can't use %s ref as %s ref"); |
fedf30e1 | 4236 | /* The core no longer needs this here. If you require the string constant, |
def89bff | 4237 | please inline a copy into your own code. */ |
973a7615 NC |
4238 | EXTCONST char PL_no_symref[] __attribute__deprecated__ |
4239 | INIT("Can't use string (\"%.32s\") as %s ref while \"strict refs\" in use"); | |
fedf30e1 DM |
4240 | EXTCONST char PL_no_symref_sv[] |
4241 | INIT("Can't use string (\"%" SVf32 "\"%s) as %s ref while \"strict refs\" in use"); | |
4242 | ||
22c35a8c | 4243 | EXTCONST char PL_no_usym[] |
8990e307 | 4244 | INIT("Can't use an undefined value as %s reference"); |
22c35a8c | 4245 | EXTCONST char PL_no_aelem[] |
93a17b20 | 4246 | INIT("Modification of non-creatable array value attempted, subscript %d"); |
ce5030a2 | 4247 | EXTCONST char PL_no_helem_sv[] |
61608bb7 | 4248 | INIT("Modification of non-creatable hash value attempted, subscript \"%" SVf "\""); |
22c35a8c | 4249 | EXTCONST char PL_no_modify[] |
93a17b20 | 4250 | INIT("Modification of a read-only value attempted"); |
4cbe3a7d | 4251 | EXTCONST char PL_no_mem[sizeof("Out of memory!\n")] |
93a17b20 | 4252 | INIT("Out of memory!\n"); |
22c35a8c | 4253 | EXTCONST char PL_no_security[] |
463ee0b2 | 4254 | INIT("Insecure dependency in %s%s"); |
22c35a8c | 4255 | EXTCONST char PL_no_sock_func[] |
93a17b20 | 4256 | INIT("Unsupported socket function \"%s\" called"); |
22c35a8c | 4257 | EXTCONST char PL_no_dir_func[] |
93a17b20 | 4258 | INIT("Unsupported directory function \"%s\" called"); |
22c35a8c | 4259 | EXTCONST char PL_no_func[] |
93a17b20 | 4260 | INIT("The %s function is unimplemented"); |
22c35a8c | 4261 | EXTCONST char PL_no_myglob[] |
a21eb52b | 4262 | INIT("\"%s\" %se %s can't be in a package"); |
82d03984 RGS |
4263 | EXTCONST char PL_no_localize_ref[] |
4264 | INIT("Can't localize through a reference"); | |
27d5b266 JH |
4265 | EXTCONST char PL_memory_wrap[] |
4266 | INIT("panic: memory wrap"); | |
93a17b20 | 4267 | |
58f645e2 NC |
4268 | EXTCONST char PL_Yes[] |
4269 | INIT("1"); | |
4270 | EXTCONST char PL_No[] | |
4271 | INIT(""); | |
5a6c2837 DM |
4272 | EXTCONST char PL_Zero[] |
4273 | INIT("0"); | |
58f645e2 NC |
4274 | EXTCONST char PL_hexdigit[] |
4275 | INIT("0123456789abcdef0123456789ABCDEF"); | |
4276 | ||
0447859b NC |
4277 | /* This is constant on most architectures, a global on OS/2 */ |
4278 | #ifndef OS2 | |
4279 | EXTCONST char PL_sh_path[] | |
4280 | INIT(SH_PATH); /* full path of shell */ | |
4281 | #endif | |
4282 | ||
618b9757 NC |
4283 | #ifdef CSH |
4284 | EXTCONST char PL_cshname[] | |
4285 | INIT(CSH); | |
4286 | # define PL_cshlen (sizeof(CSH "") - 1) | |
4287 | #endif | |
4288 | ||
457c5385 NC |
4289 | /* These are baked at compile time into any shared perl library. |
4290 | In future releases this will allow us in main() to sanity test the | |
4291 | library we're linking against. */ | |
4292 | ||
4293 | EXTCONST U8 PL_revision | |
4294 | INIT(PERL_REVISION); | |
4295 | EXTCONST U8 PL_version | |
4296 | INIT(PERL_VERSION); | |
4297 | EXTCONST U8 PL_subversion | |
4298 | INIT(PERL_SUBVERSION); | |
4299 | ||
7575fa06 | 4300 | EXTCONST char PL_uuemap[65] |
80252599 GS |
4301 | INIT("`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"); |
4302 | ||
7bfe3bfd DM |
4303 | /* a special string address whose value is "isa", but which perl knows |
4304 | * to treat as if it were really "DOES" when printing the method name in | |
4305 | * the "Can't call method '%s'" error message */ | |
4306 | EXTCONST char PL_isa_DOES[] | |
4307 | INIT("isa"); | |
4308 | ||
79072805 | 4309 | #ifdef DOINIT |
9444d213 | 4310 | EXTCONST char PL_uudmap[256] = |
dde5ec2c NC |
4311 | # ifdef PERL_MICRO |
4312 | # include "uuudmap.h" | |
4313 | # else | |
4314 | # include "uudmap.h" | |
4315 | # endif | |
9444d213 | 4316 | ; |
efa50c51 | 4317 | EXTCONST char PL_bitcount[256] = |
dde5ec2c NC |
4318 | # ifdef PERL_MICRO |
4319 | # include "ubitcount.h" | |
4320 | #else | |
4321 | # include "bitcount.h" | |
4322 | # endif | |
efa50c51 | 4323 | ; |
27da23d5 JH |
4324 | EXTCONST char* const PL_sig_name[] = { SIG_NAME }; |
4325 | EXTCONST int PL_sig_num[] = { SIG_NUM }; | |
79072805 | 4326 | #else |
9444d213 | 4327 | EXTCONST char PL_uudmap[256]; |
efa50c51 | 4328 | EXTCONST char PL_bitcount[256]; |
27da23d5 JH |
4329 | EXTCONST char* const PL_sig_name[]; |
4330 | EXTCONST int PL_sig_num[]; | |
79072805 LW |
4331 | #endif |
4332 | ||
6d8e7a01 KW |
4333 | /* fast conversion and case folding tables. The folding tables complement the |
4334 | * fold, so that 'a' maps to 'A' and 'A' maps to 'a', ignoring more complicated | |
4335 | * folds such as outside the range or to multiple characters. */ | |
bbce6d69 | 4336 | |
79072805 | 4337 | #ifdef DOINIT |
d02f4dad KW |
4338 | #ifndef EBCDIC |
4339 | ||
4340 | /* The EBCDIC fold table depends on the code page, and hence is found in | |
4341 | * utfebcdic.h */ | |
4342 | ||
22c35a8c | 4343 | EXTCONST unsigned char PL_fold[] = { |
79072805 LW |
4344 | 0, 1, 2, 3, 4, 5, 6, 7, |
4345 | 8, 9, 10, 11, 12, 13, 14, 15, | |
4346 | 16, 17, 18, 19, 20, 21, 22, 23, | |
4347 | 24, 25, 26, 27, 28, 29, 30, 31, | |
4348 | 32, 33, 34, 35, 36, 37, 38, 39, | |
4349 | 40, 41, 42, 43, 44, 45, 46, 47, | |
4350 | 48, 49, 50, 51, 52, 53, 54, 55, | |
4351 | 56, 57, 58, 59, 60, 61, 62, 63, | |
4352 | 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g', | |
4353 | 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', | |
4354 | 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', | |
4355 | 'x', 'y', 'z', 91, 92, 93, 94, 95, | |
4356 | 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G', | |
4357 | 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', | |
4358 | 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', | |
4359 | 'X', 'Y', 'Z', 123, 124, 125, 126, 127, | |
4360 | 128, 129, 130, 131, 132, 133, 134, 135, | |
4361 | 136, 137, 138, 139, 140, 141, 142, 143, | |
4362 | 144, 145, 146, 147, 148, 149, 150, 151, | |
4363 | 152, 153, 154, 155, 156, 157, 158, 159, | |
4364 | 160, 161, 162, 163, 164, 165, 166, 167, | |
4365 | 168, 169, 170, 171, 172, 173, 174, 175, | |
4366 | 176, 177, 178, 179, 180, 181, 182, 183, | |
4367 | 184, 185, 186, 187, 188, 189, 190, 191, | |
4368 | 192, 193, 194, 195, 196, 197, 198, 199, | |
4369 | 200, 201, 202, 203, 204, 205, 206, 207, | |
4370 | 208, 209, 210, 211, 212, 213, 214, 215, | |
4371 | 216, 217, 218, 219, 220, 221, 222, 223, | |
4372 | 224, 225, 226, 227, 228, 229, 230, 231, | |
4373 | 232, 233, 234, 235, 236, 237, 238, 239, | |
4374 | 240, 241, 242, 243, 244, 245, 246, 247, | |
4375 | 248, 249, 250, 251, 252, 253, 254, 255 | |
4376 | }; | |
3871f40b KW |
4377 | EXTCONST unsigned char PL_fold_latin1[] = { |
4378 | /* Full latin1 complement folding, except for three problematic code points: | |
4379 | * Micro sign (181 = 0xB5) and y with diearesis (255 = 0xFF) have their | |
4380 | * fold complements outside the Latin1 range, so can't match something | |
4381 | * that isn't in utf8. | |
4382 | * German lower case sharp s (223 = 0xDF) folds to two characters, 'ss', | |
4383 | * not one, so can't be represented in this table. | |
4384 | * | |
4385 | * All have to be specially handled */ | |
4386 | 0, 1, 2, 3, 4, 5, 6, 7, | |
4387 | 8, 9, 10, 11, 12, 13, 14, 15, | |
4388 | 16, 17, 18, 19, 20, 21, 22, 23, | |
4389 | 24, 25, 26, 27, 28, 29, 30, 31, | |
4390 | 32, 33, 34, 35, 36, 37, 38, 39, | |
4391 | 40, 41, 42, 43, 44, 45, 46, 47, | |
4392 | 48, 49, 50, 51, 52, 53, 54, 55, | |
4393 | 56, 57, 58, 59, 60, 61, 62, 63, | |
4394 | 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g', | |
4395 | 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', | |
4396 | 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', | |
4397 | 'x', 'y', 'z', 91, 92, 93, 94, 95, | |
4398 | 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G', | |
4399 | 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', | |
4400 | 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', | |
4401 | 'X', 'Y', 'Z', 123, 124, 125, 126, 127, | |
4402 | 128, 129, 130, 131, 132, 133, 134, 135, | |
4403 | 136, 137, 138, 139, 140, 141, 142, 143, | |
4404 | 144, 145, 146, 147, 148, 149, 150, 151, | |
4405 | 152, 153, 154, 155, 156, 157, 158, 159, | |
4406 | 160, 161, 162, 163, 164, 165, 166, 167, | |
4407 | 168, 169, 170, 171, 172, 173, 174, 175, | |
4408 | 176, 177, 178, 179, 180, 181 /*micro */, 182, 183, | |
4409 | 184, 185, 186, 187, 188, 189, 190, 191, | |
4410 | 192+32, 193+32, 194+32, 195+32, 196+32, 197+32, 198+32, 199+32, | |
4411 | 200+32, 201+32, 202+32, 203+32, 204+32, 205+32, 206+32, 207+32, | |
4412 | 208+32, 209+32, 210+32, 211+32, 212+32, 213+32, 214+32, 215, | |
4413 | 216+32, 217+32, 218+32, 219+32, 220+32, 221+32, 222+32, 223 /* ss */, | |
4414 | 224-32, 225-32, 226-32, 227-32, 228-32, 229-32, 230-32, 231-32, | |
4415 | 232-32, 233-32, 234-32, 235-32, 236-32, 237-32, 238-32, 239-32, | |
4416 | 240-32, 241-32, 242-32, 243-32, 244-32, 245-32, 246-32, 247, | |
4417 | 248-32, 249-32, 250-32, 251-32, 252-32, 253-32, 254-32, | |
4418 | 255 /* y with diaeresis */ | |
4419 | }; | |
00f254e2 KW |
4420 | |
4421 | /* If these tables are accessed through ebcdic, the access will be converted to | |
4422 | * latin1 first */ | |
4423 | EXTCONST unsigned char PL_latin1_lc[] = { /* lowercasing */ | |
4424 | 0, 1, 2, 3, 4, 5, 6, 7, | |
4425 | 8, 9, 10, 11, 12, 13, 14, 15, | |
4426 | 16, 17, 18, 19, 20, 21, 22, 23, | |
4427 | 24, 25, 26, 27, 28, 29, 30, 31, | |
4428 | 32, 33, 34, 35, 36, 37, 38, 39, | |
4429 | 40, 41, 42, 43, 44, 45, 46, 47, | |
4430 | 48, 49, 50, 51, 52, 53, 54, 55, | |
4431 | 56, 57, 58, 59, 60, 61, 62, 63, | |
4432 | 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g', | |
4433 | 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', | |
4434 | 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', | |
4435 | 'x', 'y', 'z', 91, 92, 93, 94, 95, | |
4436 | 96, 97, 98, 99, 100, 101, 102, 103, | |
4437 | 104, 105, 106, 107, 108, 109, 110, 111, | |
4438 | 112, 113, 114, 115, 116, 117, 118, 119, | |
4439 | 120, 121, 122, 123, 124, 125, 126, 127, | |
4440 | 128, 129, 130, 131, 132, 133, 134, 135, | |
4441 | 136, 137, 138, 139, 140, 141, 142, 143, | |
4442 | 144, 145, 146, 147, 148, 149, 150, 151, | |
4443 | 152, 153, 154, 155, 156, 157, 158, 159, | |
4444 | 160, 161, 162, 163, 164, 165, 166, 167, | |
4445 | 168, 169, 170, 171, 172, 173, 174, 175, | |
4446 | 176, 177, 178, 179, 180, 181, 182, 183, | |
4447 | 184, 185, 186, 187, 188, 189, 190, 191, | |
4448 | 192+32, 193+32, 194+32, 195+32, 196+32, 197+32, 198+32, 199+32, | |
4449 | 200+32, 201+32, 202+32, 203+32, 204+32, 205+32, 206+32, 207+32, | |
4450 | 208+32, 209+32, 210+32, 211+32, 212+32, 213+32, 214+32, 215, | |
4451 | 216+32, 217+32, 218+32, 219+32, 220+32, 221+32, 222+32, 223, | |
4452 | 224, 225, 226, 227, 228, 229, 230, 231, | |
4453 | 232, 233, 234, 235, 236, 237, 238, 239, | |
4454 | 240, 241, 242, 243, 244, 245, 246, 247, | |
4455 | 248, 249, 250, 251, 252, 253, 254, 255 | |
4456 | }; | |
4457 | ||
4458 | /* upper and title case of latin1 characters, modified so that the three tricky | |
4459 | * ones are mapped to 255 (which is one of the three) */ | |
4460 | EXTCONST unsigned char PL_mod_latin1_uc[] = { | |
4461 | 0, 1, 2, 3, 4, 5, 6, 7, | |
4462 | 8, 9, 10, 11, 12, 13, 14, 15, | |
4463 | 16, 17, 18, 19, 20, 21, 22, 23, | |
4464 | 24, 25, 26, 27, 28, 29, 30, 31, | |
4465 | 32, 33, 34, 35, 36, 37, 38, 39, | |
4466 | 40, 41, 42, 43, 44, 45, 46, 47, | |
4467 | 48, 49, 50, 51, 52, 53, 54, 55, | |
4468 | 56, 57, 58, 59, 60, 61, 62, 63, | |
4469 | 64, 65, 66, 67, 68, 69, 70, 71, | |
4470 | 72, 73, 74, 75, 76, 77, 78, 79, | |
4471 | 80, 81, 82, 83, 84, 85, 86, 87, | |
4472 | 88, 89, 90, 91, 92, 93, 94, 95, | |
4473 | 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G', | |
4474 | 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', | |
4475 | 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', | |
4476 | 'X', 'Y', 'Z', 123, 124, 125, 126, 127, | |
4477 | 128, 129, 130, 131, 132, 133, 134, 135, | |
4478 | 136, 137, 138, 139, 140, 141, 142, 143, | |
4479 | 144, 145, 146, 147, 148, 149, 150, 151, | |
4480 | 152, 153, 154, 155, 156, 157, 158, 159, | |
4481 | 160, 161, 162, 163, 164, 165, 166, 167, | |
4482 | 168, 169, 170, 171, 172, 173, 174, 175, | |
4483 | 176, 177, 178, 179, 180, 255 /*micro*/, 182, 183, | |
4484 | 184, 185, 186, 187, 188, 189, 190, 191, | |
4485 | 192, 193, 194, 195, 196, 197, 198, 199, | |
4486 | 200, 201, 202, 203, 204, 205, 206, 207, | |
4487 | 208, 209, 210, 211, 212, 213, 214, 215, | |
79e064b9 KW |
4488 | 216, 217, 218, 219, 220, 221, 222, |
4489 | #if UNICODE_MAJOR_VERSION > 2 \ | |
4490 | || (UNICODE_MAJOR_VERSION == 2 && UNICODE_DOT_VERSION >= 1 \ | |
4491 | && UNICODE_DOT_DOT_VERSION >= 8) | |
4492 | 255 /*sharp s*/, | |
4493 | #else /* uc() is itself in early unicode */ | |
4494 | 223, | |
4495 | #endif | |
00f254e2 KW |
4496 | 224-32, 225-32, 226-32, 227-32, 228-32, 229-32, 230-32, 231-32, |
4497 | 232-32, 233-32, 234-32, 235-32, 236-32, 237-32, 238-32, 239-32, | |
4498 | 240-32, 241-32, 242-32, 243-32, 244-32, 245-32, 246-32, 247, | |
4499 | 248-32, 249-32, 250-32, 251-32, 252-32, 253-32, 254-32, 255 | |
4500 | }; | |
1248eb9d | 4501 | #endif /* !EBCDIC, but still in DOINIT */ |
00f254e2 | 4502 | #else /* ! DOINIT */ |
1248eb9d | 4503 | # ifndef EBCDIC |
22c35a8c | 4504 | EXTCONST unsigned char PL_fold[]; |
3871f40b | 4505 | EXTCONST unsigned char PL_fold_latin1[]; |
00f254e2 KW |
4506 | EXTCONST unsigned char PL_mod_latin1_uc[]; |
4507 | EXTCONST unsigned char PL_latin1_lc[]; | |
1248eb9d | 4508 | # endif |
79072805 LW |
4509 | #endif |
4510 | ||
27da23d5 | 4511 | #ifndef PERL_GLOBAL_STRUCT /* or perlvars.h */ |
79072805 | 4512 | #ifdef DOINIT |
27da23d5 | 4513 | EXT unsigned char PL_fold_locale[] = { /* Unfortunately not EXTCONST. */ |
79072805 LW |
4514 | 0, 1, 2, 3, 4, 5, 6, 7, |
4515 | 8, 9, 10, 11, 12, 13, 14, 15, | |
4516 | 16, 17, 18, 19, 20, 21, 22, 23, | |
4517 | 24, 25, 26, 27, 28, 29, 30, 31, | |
4518 | 32, 33, 34, 35, 36, 37, 38, 39, | |
4519 | 40, 41, 42, 43, 44, 45, 46, 47, | |
4520 | 48, 49, 50, 51, 52, 53, 54, 55, | |
4521 | 56, 57, 58, 59, 60, 61, 62, 63, | |
4522 | 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g', | |
4523 | 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', | |
4524 | 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', | |
4525 | 'x', 'y', 'z', 91, 92, 93, 94, 95, | |
4526 | 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G', | |
4527 | 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', | |
4528 | 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', | |
4529 | 'X', 'Y', 'Z', 123, 124, 125, 126, 127, | |
4530 | 128, 129, 130, 131, 132, 133, 134, 135, | |
4531 | 136, 137, 138, 139, 140, 141, 142, 143, | |
4532 | 144, 145, 146, 147, 148, 149, 150, 151, | |
4533 | 152, 153, 154, 155, 156, 157, 158, 159, | |
4534 | 160, 161, 162, 163, 164, 165, 166, 167, | |
4535 | 168, 169, 170, 171, 172, 173, 174, 175, | |
4536 | 176, 177, 178, 179, 180, 181, 182, 183, | |
4537 | 184, 185, 186, 187, 188, 189, 190, 191, | |
4538 | 192, 193, 194, 195, 196, 197, 198, 199, | |
4539 | 200, 201, 202, 203, 204, 205, 206, 207, | |
4540 | 208, 209, 210, 211, 212, 213, 214, 215, | |
4541 | 216, 217, 218, 219, 220, 221, 222, 223, | |
4542 | 224, 225, 226, 227, 228, 229, 230, 231, | |
4543 | 232, 233, 234, 235, 236, 237, 238, 239, | |
4544 | 240, 241, 242, 243, 244, 245, 246, 247, | |
4545 | 248, 249, 250, 251, 252, 253, 254, 255 | |
4546 | }; | |
4547 | #else | |
27da23d5 | 4548 | EXT unsigned char PL_fold_locale[]; /* Unfortunately not EXTCONST. */ |
79072805 | 4549 | #endif |
27da23d5 | 4550 | #endif /* !PERL_GLOBAL_STRUCT */ |
79072805 LW |
4551 | |
4552 | #ifdef DOINIT | |
9d116dd7 | 4553 | #ifdef EBCDIC |
27da23d5 | 4554 | EXTCONST unsigned char PL_freq[] = {/* EBCDIC frequencies for mixed English/C */ |
9d116dd7 JH |
4555 | 1, 2, 84, 151, 154, 155, 156, 157, |
4556 | 165, 246, 250, 3, 158, 7, 18, 29, | |
4557 | 40, 51, 62, 73, 85, 96, 107, 118, | |
4558 | 129, 140, 147, 148, 149, 150, 152, 153, | |
4559 | 255, 6, 8, 9, 10, 11, 12, 13, | |
4560 | 14, 15, 24, 25, 26, 27, 28, 226, | |
4561 | 29, 30, 31, 32, 33, 43, 44, 45, | |
4562 | 46, 47, 48, 49, 50, 76, 77, 78, | |
4563 | 79, 80, 81, 82, 83, 84, 85, 86, | |
4564 | 87, 94, 95, 234, 181, 233, 187, 190, | |
4565 | 180, 96, 97, 98, 99, 100, 101, 102, | |
4566 | 104, 112, 182, 174, 236, 232, 229, 103, | |
4567 | 228, 226, 114, 115, 116, 117, 118, 119, | |
4568 | 120, 121, 122, 235, 176, 230, 194, 162, | |
4569 | 130, 131, 132, 133, 134, 135, 136, 137, | |
4570 | 138, 139, 201, 205, 163, 217, 220, 224, | |
4571 | 5, 248, 227, 244, 242, 255, 241, 231, | |
4572 | 240, 253, 16, 197, 19, 20, 21, 187, | |
4573 | 23, 169, 210, 245, 237, 249, 247, 239, | |
4574 | 168, 252, 34, 196, 36, 37, 38, 39, | |
4575 | 41, 42, 251, 254, 238, 223, 221, 213, | |
4576 | 225, 177, 52, 53, 54, 55, 56, 57, | |
4577 | 58, 59, 60, 61, 63, 64, 65, 66, | |
4578 | 67, 68, 69, 70, 71, 72, 74, 75, | |
4579 | 205, 208, 186, 202, 200, 218, 198, 179, | |
4580 | 178, 214, 88, 89, 90, 91, 92, 93, | |
4581 | 217, 166, 170, 207, 199, 209, 206, 204, | |
4582 | 160, 212, 105, 106, 108, 109, 110, 111, | |
4583 | 203, 113, 216, 215, 192, 175, 193, 243, | |
4584 | 172, 161, 123, 124, 125, 126, 127, 128, | |
4585 | 222, 219, 211, 195, 188, 193, 185, 184, | |
4586 | 191, 183, 141, 142, 143, 144, 145, 146 | |
4587 | }; | |
4588 | #else /* ascii rather than ebcdic */ | |
22c35a8c | 4589 | EXTCONST unsigned char PL_freq[] = { /* letter frequencies for mixed English/C */ |
79072805 LW |
4590 | 1, 2, 84, 151, 154, 155, 156, 157, |
4591 | 165, 246, 250, 3, 158, 7, 18, 29, | |
4592 | 40, 51, 62, 73, 85, 96, 107, 118, | |
4593 | 129, 140, 147, 148, 149, 150, 152, 153, | |
4594 | 255, 182, 224, 205, 174, 176, 180, 217, | |
4595 | 233, 232, 236, 187, 235, 228, 234, 226, | |
4596 | 222, 219, 211, 195, 188, 193, 185, 184, | |
4597 | 191, 183, 201, 229, 181, 220, 194, 162, | |
4598 | 163, 208, 186, 202, 200, 218, 198, 179, | |
4599 | 178, 214, 166, 170, 207, 199, 209, 206, | |
4600 | 204, 160, 212, 216, 215, 192, 175, 173, | |
4601 | 243, 172, 161, 190, 203, 189, 164, 230, | |
4602 | 167, 248, 227, 244, 242, 255, 241, 231, | |
4603 | 240, 253, 169, 210, 245, 237, 249, 247, | |
4604 | 239, 168, 252, 251, 254, 238, 223, 221, | |
4605 | 213, 225, 177, 197, 171, 196, 159, 4, | |
4606 | 5, 6, 8, 9, 10, 11, 12, 13, | |
4607 | 14, 15, 16, 17, 19, 20, 21, 22, | |
4608 | 23, 24, 25, 26, 27, 28, 30, 31, | |
4609 | 32, 33, 34, 35, 36, 37, 38, 39, | |
4610 | 41, 42, 43, 44, 45, 46, 47, 48, | |
4611 | 49, 50, 52, 53, 54, 55, 56, 57, | |
4612 | 58, 59, 60, 61, 63, 64, 65, 66, | |
4613 | 67, 68, 69, 70, 71, 72, 74, 75, | |
4614 | 76, 77, 78, 79, 80, 81, 82, 83, | |
4615 | 86, 87, 88, 89, 90, 91, 92, 93, | |
4616 | 94, 95, 97, 98, 99, 100, 101, 102, | |
4617 | 103, 104, 105, 106, 108, 109, 110, 111, | |
4618 | 112, 113, 114, 115, 116, 117, 119, 120, | |
4619 | 121, 122, 123, 124, 125, 126, 127, 128, | |
4620 | 130, 131, 132, 133, 134, 135, 136, 137, | |
4621 | 138, 139, 141, 142, 143, 144, 145, 146 | |
4622 | }; | |
9d116dd7 | 4623 | #endif |
79072805 | 4624 | #else |
22c35a8c | 4625 | EXTCONST unsigned char PL_freq[]; |
79072805 LW |
4626 | #endif |
4627 | ||
b0812ba3 DM |
4628 | /* Although only used for debugging, these constants must be available in |
4629 | * non-debugging builds too, since they're used in ext/re/re_exec.c, | |
4630 | * which has DEBUGGING enabled always */ | |
8990e307 | 4631 | #ifdef DOINIT |
27da23d5 | 4632 | EXTCONST char* const PL_block_type[] = { |
8990e307 | 4633 | "NULL", |
d01136d6 | 4634 | "WHEN", |
8990e307 | 4635 | "BLOCK", |
0d863452 | 4636 | "GIVEN", |
1611176f | 4637 | "LOOP_ARY", |
93661e56 | 4638 | "LOOP_LAZYSV", |
1611176f | 4639 | "LOOP_LAZYIV", |
93661e56 | 4640 | "LOOP_LIST", |
1611176f | 4641 | "LOOP_PLAIN", |
76753e7f NC |
4642 | "SUB", |
4643 | "FORMAT", | |
4644 | "EVAL", | |
4645 | "SUBST" | |
8990e307 LW |
4646 | }; |
4647 | #else | |
22c35a8c | 4648 | EXTCONST char* PL_block_type[]; |
8990e307 | 4649 | #endif |
8990e307 | 4650 | |
b75885fd NC |
4651 | /* These are all the compile time options that affect binary compatibility. |
4652 | Other compile time options that are binary compatible are in perl.c | |
e23397c2 | 4653 | (in S_Internals_V()). Both are combined for the output of perl -V |
b75885fd NC |
4654 | However, this string will be embedded in any shared perl library, which will |
4655 | allow us add a comparison check in perlmain.c in the near future. */ | |
4656 | #ifdef DOINIT | |
4657 | EXTCONST char PL_bincompat_options[] = | |
4658 | # ifdef DEBUG_LEAKING_SCALARS | |
4659 | " DEBUG_LEAKING_SCALARS" | |
4660 | # endif | |
4661 | # ifdef DEBUG_LEAKING_SCALARS_FORK_DUMP | |
4662 | " DEBUG_LEAKING_SCALARS_FORK_DUMP" | |
4663 | # endif | |
eba804b9 NC |
4664 | # ifdef FCRYPT |
4665 | " FCRYPT" | |
4666 | # endif | |
4667 | # ifdef HAS_TIMES | |
4668 | " HAS_TIMES" | |
4669 | # endif | |
4670 | # ifdef HAVE_INTERP_INTERN | |
426f6eb2 | 4671 | " HAVE_INTERP_INTERN" |
eba804b9 | 4672 | # endif |
b75885fd NC |
4673 | # ifdef MULTIPLICITY |
4674 | " MULTIPLICITY" | |
4675 | # endif | |
4676 | # ifdef MYMALLOC | |
4677 | " MYMALLOC" | |
4678 | # endif | |
eba804b9 NC |
4679 | # ifdef PERLIO_LAYERS |
4680 | " PERLIO_LAYERS" | |
4681 | # endif | |
cb26ef7a MB |
4682 | # ifdef PERL_DEBUG_READONLY_COW |
4683 | " PERL_DEBUG_READONLY_COW" | |
4684 | # endif | |
b75885fd NC |
4685 | # ifdef PERL_DEBUG_READONLY_OPS |
4686 | " PERL_DEBUG_READONLY_OPS" | |
4687 | # endif | |
4688 | # ifdef PERL_GLOBAL_STRUCT | |
4689 | " PERL_GLOBAL_STRUCT" | |
4690 | # endif | |
59dba841 JH |
4691 | # ifdef PERL_GLOBAL_STRUCT_PRIVATE |
4692 | " PERL_GLOBAL_STRUCT_PRIVATE" | |
4693 | # endif | |
b75885fd NC |
4694 | # ifdef PERL_IMPLICIT_CONTEXT |
4695 | " PERL_IMPLICIT_CONTEXT" | |
4696 | # endif | |
4697 | # ifdef PERL_IMPLICIT_SYS | |
4698 | " PERL_IMPLICIT_SYS" | |
4699 | # endif | |
eba804b9 NC |
4700 | # ifdef PERL_MICRO |
4701 | " PERL_MICRO" | |
4702 | # endif | |
b75885fd NC |
4703 | # ifdef PERL_NEED_APPCTX |
4704 | " PERL_NEED_APPCTX" | |
4705 | # endif | |
4706 | # ifdef PERL_NEED_TIMESBASE | |
4707 | " PERL_NEED_TIMESBASE" | |
4708 | # endif | |
b75885fd NC |
4709 | # ifdef PERL_POISON |
4710 | " PERL_POISON" | |
4711 | # endif | |
5b50f57e FC |
4712 | # ifdef PERL_SAWAMPERSAND |
4713 | " PERL_SAWAMPERSAND" | |
4714 | # endif | |
b75885fd NC |
4715 | # ifdef PERL_TRACK_MEMPOOL |
4716 | " PERL_TRACK_MEMPOOL" | |
4717 | # endif | |
4718 | # ifdef PERL_USES_PL_PIDSTATUS | |
4719 | " PERL_USES_PL_PIDSTATUS" | |
4720 | # endif | |
b75885fd NC |
4721 | # ifdef USE_64_BIT_ALL |
4722 | " USE_64_BIT_ALL" | |
4723 | # endif | |
4724 | # ifdef USE_64_BIT_INT | |
4725 | " USE_64_BIT_INT" | |
4726 | # endif | |
c7b392fa NC |
4727 | # ifdef USE_IEEE |
4728 | " USE_IEEE" | |
4729 | # endif | |
b75885fd NC |
4730 | # ifdef USE_ITHREADS |
4731 | " USE_ITHREADS" | |
4732 | # endif | |
4733 | # ifdef USE_LARGE_FILES | |
4734 | " USE_LARGE_FILES" | |
4735 | # endif | |
eba804b9 NC |
4736 | # ifdef USE_LOCALE_COLLATE |
4737 | " USE_LOCALE_COLLATE" | |
4738 | # endif | |
4739 | # ifdef USE_LOCALE_NUMERIC | |
4740 | " USE_LOCALE_NUMERIC" | |
4741 | # endif | |
56e45410 KW |
4742 | # ifdef USE_LOCALE_TIME |
4743 | " USE_LOCALE_TIME" | |
4744 | # endif | |
b75885fd NC |
4745 | # ifdef USE_LONG_DOUBLE |
4746 | " USE_LONG_DOUBLE" | |
4747 | # endif | |
4748 | # ifdef USE_PERLIO | |
4749 | " USE_PERLIO" | |
4750 | # endif | |
05b4a618 JH |
4751 | # ifdef USE_QUADMATH |
4752 | " USE_QUADMATH" | |
4753 | # endif | |
b75885fd NC |
4754 | # ifdef USE_REENTRANT_API |
4755 | " USE_REENTRANT_API" | |
4756 | # endif | |
b75885fd NC |
4757 | # ifdef USE_SOCKS |
4758 | " USE_SOCKS" | |
4759 | # endif | |
4f575702 CB |
4760 | # ifdef VMS_DO_SOCKETS |
4761 | " VMS_DO_SOCKETS" | |
4f575702 | 4762 | # endif |
e8b231c6 CB |
4763 | # ifdef VMS_SHORTEN_LONG_SYMBOLS |
4764 | " VMS_SHORTEN_LONG_SYMBOLS" | |
4765 | # endif | |
ad5e438d NC |
4766 | # ifdef VMS_WE_ARE_CASE_SENSITIVE |
4767 | " VMS_SYMBOL_CASE_AS_IS" | |
4768 | # endif | |
a68dd89e | 4769 | ""; |
b75885fd NC |
4770 | #else |
4771 | EXTCONST char PL_bincompat_options[]; | |
4772 | #endif | |
4773 | ||
ca7b837b SM |
4774 | #ifndef PERL_SET_PHASE |
4775 | # define PERL_SET_PHASE(new_phase) \ | |
3f6bd23a | 4776 | PERL_DTRACE_PROBE_PHASE(new_phase); \ |
ca7b837b SM |
4777 | PL_phase = new_phase; |
4778 | #endif | |
4779 | ||
9ebf26ad FR |
4780 | /* The interpreter phases. If these ever change, PL_phase_names right below will |
4781 | * need to be updated accordingly. */ | |
4782 | enum perl_phase { | |
4783 | PERL_PHASE_CONSTRUCT = 0, | |
4784 | PERL_PHASE_START = 1, | |
4785 | PERL_PHASE_CHECK = 2, | |
4786 | PERL_PHASE_INIT = 3, | |
4787 | PERL_PHASE_RUN = 4, | |
4788 | PERL_PHASE_END = 5, | |
4789 | PERL_PHASE_DESTRUCT = 6 | |
4790 | }; | |
4791 | ||
4792 | #ifdef DOINIT | |
4793 | EXTCONST char *const PL_phase_names[] = { | |
4794 | "CONSTRUCT", | |
4795 | "START", | |
4796 | "CHECK", | |
4797 | "INIT", | |
4798 | "RUN", | |
4799 | "END", | |
4800 | "DESTRUCT" | |
4801 | }; | |
4802 | #else | |
4803 | EXTCONST char *const PL_phase_names[]; | |
4804 | #endif | |
4805 | ||
627364f1 FR |
4806 | #ifndef PERL_CORE |
4807 | /* Do not use this macro. It only exists for extensions that rely on PL_dirty | |
4808 | * instead of using the newer PL_phase, which provides everything PL_dirty | |
4809 | * provided, and more. */ | |
9d990559 | 4810 | # define PL_dirty cBOOL(PL_phase == PERL_PHASE_DESTRUCT) |
66978156 FC |
4811 | |
4812 | # define PL_amagic_generation PL_na | |
8bfa1b58 | 4813 | # define PL_encoding ((SV *)NULL) |
627364f1 FR |
4814 | #endif /* !PERL_CORE */ |
4815 | ||
823ac2c8 | 4816 | #define PL_hints PL_compiling.cop_hints |
8d89205a | 4817 | #define PL_maxo MAXO |
823ac2c8 | 4818 | |
73c4f7a1 GS |
4819 | END_EXTERN_C |
4820 | ||
79072805 LW |
4821 | /*****************************************************************************/ |
4822 | /* This lexer/parser stuff is currently global since yacc is hard to reenter */ | |
4823 | /*****************************************************************************/ | |
8990e307 | 4824 | /* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */ |
79072805 | 4825 | |
d4c3c482 | 4826 | #ifdef __Lynx__ |
9cffb111 OS |
4827 | /* LynxOS defines these in scsi.h which is included via ioctl.h */ |
4828 | #ifdef FORMAT | |
4829 | #undef FORMAT | |
4830 | #endif | |
4831 | #ifdef SPACE | |
4832 | #undef SPACE | |
4833 | #endif | |
d4c3c482 | 4834 | #endif |
9cffb111 | 4835 | |
fb73857a | 4836 | #define LEX_NOTPARSING 11 /* borrowed from toke.c */ |
4837 | ||
79072805 LW |
4838 | typedef enum { |
4839 | XOPERATOR, | |
4840 | XTERM, | |
79072805 | 4841 | XREF, |
8990e307 | 4842 | XSTATE, |
a0d0e21e | 4843 | XBLOCK, |
09bef843 SB |
4844 | XATTRBLOCK, |
4845 | XATTRTERM, | |
6f33ba73 | 4846 | XTERMBLOCK, |
b5b6210a | 4847 | XBLOCKTERM, |
89f35911 | 4848 | XPOSTDEREF, |
6f33ba73 | 4849 | XTERMORDORDOR /* evil hack */ |
27308ded | 4850 | /* update exp_name[] in toke.c if adding to this enum */ |
79072805 LW |
4851 | } expectation; |
4852 | ||
49fb8620 DM |
4853 | #define KEY_sigvar 0xFFFF /* fake keyword representing a signature var */ |
4854 | ||
d5ec2987 NC |
4855 | /* Hints are now stored in a dedicated U32, so the bottom 8 bits are no longer |
4856 | special and there is no need for HINT_PRIVATE_MASK for COPs | |
538e84ed KW |
4857 | However, bitops store HINT_INTEGER in their op_private. |
4858 | ||
4859 | NOTE: The typical module using these has the bit value hard-coded, so don't | |
d6ded950 KW |
4860 | blindly change the values of these. |
4861 | ||
4862 | If we run out of bits, the 2 locale ones could be combined. The PARTIAL one | |
4863 | is for "use locale 'FOO'" which excludes some categories. It requires going | |
4864 | to %^H to find out which are in and which are out. This could be extended | |
4865 | for the normal case of a plain HINT_LOCALE, so that %^H would be used for | |
4866 | any locale form. */ | |
9cfe5470 RGS |
4867 | #define HINT_INTEGER 0x00000001 /* integer pragma */ |
4868 | #define HINT_STRICT_REFS 0x00000002 /* strict pragma */ | |
4869 | #define HINT_LOCALE 0x00000004 /* locale pragma */ | |
4870 | #define HINT_BYTES 0x00000008 /* bytes pragma */ | |
d6ded950 | 4871 | #define HINT_LOCALE_PARTIAL 0x00000010 /* locale, but a subset of categories */ |
894ea76b FC |
4872 | |
4873 | #define HINT_EXPLICIT_STRICT_REFS 0x00000020 /* strict.pm */ | |
4874 | #define HINT_EXPLICIT_STRICT_SUBS 0x00000040 /* strict.pm */ | |
4875 | #define HINT_EXPLICIT_STRICT_VARS 0x00000080 /* strict.pm */ | |
85e6fe83 LW |
4876 | |
4877 | #define HINT_BLOCK_SCOPE 0x00000100 | |
9cfe5470 RGS |
4878 | #define HINT_STRICT_SUBS 0x00000200 /* strict pragma */ |
4879 | #define HINT_STRICT_VARS 0x00000400 /* strict pragma */ | |
1863b879 | 4880 | #define HINT_UNI_8_BIT 0x00000800 /* unicode_strings feature */ |
85e6fe83 | 4881 | |
9cfe5470 | 4882 | /* The HINT_NEW_* constants are used by the overload pragma */ |
b3ac6de7 IZ |
4883 | #define HINT_NEW_INTEGER 0x00001000 |
4884 | #define HINT_NEW_FLOAT 0x00002000 | |
4885 | #define HINT_NEW_BINARY 0x00004000 | |
4886 | #define HINT_NEW_STRING 0x00008000 | |
4887 | #define HINT_NEW_RE 0x00010000 | |
4888 | #define HINT_LOCALIZE_HH 0x00020000 /* %^H needs to be copied */ | |
8b850bd5 NC |
4889 | #define HINT_LEXICAL_IO_IN 0x00040000 /* ${^OPEN} is set for input */ |
4890 | #define HINT_LEXICAL_IO_OUT 0x00080000 /* ${^OPEN} is set for output */ | |
b3ac6de7 | 4891 | |
9cfe5470 RGS |
4892 | #define HINT_RE_TAINT 0x00100000 /* re pragma */ |
4893 | #define HINT_RE_EVAL 0x00200000 /* re pragma */ | |
b3eb6a9b | 4894 | |
9cfe5470 RGS |
4895 | #define HINT_FILETEST_ACCESS 0x00400000 /* filetest pragma */ |
4896 | #define HINT_UTF8 0x00800000 /* utf8 pragma */ | |
5ff3f7a4 | 4897 | |
e46c382e YK |
4898 | #define HINT_NO_AMAGIC 0x01000000 /* overloading pragma */ |
4899 | ||
1e215989 FC |
4900 | #define HINT_RE_FLAGS 0x02000000 /* re '/xism' pragma */ |
4901 | ||
a803b9b4 FC |
4902 | #define HINT_FEATURE_MASK 0x1c000000 /* 3 bits for feature bundles */ |
4903 | ||
15da1ccf FC |
4904 | /* Note: Used for HINT_M_VMSISH_*, |
4905 | currently defined by vms/vmsish.h: | |
894ea76b FC |
4906 | 0x40000000 |
4907 | 0x80000000 | |
4908 | */ | |
d1718a7c | 4909 | |
0239f47c | 4910 | /* The following are stored in $^H{sort}, not in PL_hints */ |
84d4ea48 JH |
4911 | #define HINT_SORT_SORT_BITS 0x000000FF /* allow 256 different ones */ |
4912 | #define HINT_SORT_QUICKSORT 0x00000001 | |
4913 | #define HINT_SORT_MERGESORT 0x00000002 | |
afe59f35 FC |
4914 | #define HINT_SORT_STABLE 0x00000100 /* sort styles */ |
4915 | #define HINT_SORT_UNSTABLE 0x00000200 | |
84d4ea48 | 4916 | |
d3b97530 DM |
4917 | /* flags for PL_sawampersand */ |
4918 | ||
4919 | #define SAWAMPERSAND_LEFT 1 /* saw $` */ | |
4920 | #define SAWAMPERSAND_MIDDLE 2 /* saw $& */ | |
4921 | #define SAWAMPERSAND_RIGHT 4 /* saw $' */ | |
4922 | ||
1a904fc8 FC |
4923 | #ifndef PERL_SAWAMPERSAND |
4924 | # define PL_sawampersand \ | |
4925 | (SAWAMPERSAND_LEFT|SAWAMPERSAND_MIDDLE|SAWAMPERSAND_RIGHT) | |
4926 | #endif | |
4927 | ||
a6d69523 TC |
4928 | /* Used for debugvar magic */ |
4929 | #define DBVARMG_SINGLE 0 | |
4930 | #define DBVARMG_TRACE 1 | |
4931 | #define DBVARMG_SIGNAL 2 | |
4932 | #define DBVARMG_COUNT 3 | |
4933 | ||
4934 | #define PL_DBsingle_iv (PL_DBcontrol[DBVARMG_SINGLE]) | |
4935 | #define PL_DBtrace_iv (PL_DBcontrol[DBVARMG_TRACE]) | |
4936 | #define PL_DBsignal_iv (PL_DBcontrol[DBVARMG_SIGNAL]) | |
4937 | ||
8bfdd7d9 | 4938 | /* Various states of the input record separator SV (rs) */ |
d4cce5f1 | 4939 | #define RsSNARF(sv) (! SvOK(sv)) |
af7d13df MG |
4940 | #define RsSIMPLE(sv) (SvOK(sv) && (! SvPOK(sv) || SvCUR(sv))) |
4941 | #define RsPARA(sv) (SvPOK(sv) && ! SvCUR(sv)) | |
5b2b9c68 | 4942 | #define RsRECORD(sv) (SvROK(sv) && (SvIV(SvRV(sv)) > 0)) |
79072805 | 4943 | |
128e8167 | 4944 | /* A struct for keeping various DEBUGGING related stuff, |
ce333219 | 4945 | * neatly packed. Currently only scratch variables for |
128e8167 JH |
4946 | * constructing debug output are included. Needed always, |
4947 | * not just when DEBUGGING, though, because of the re extension. c*/ | |
ce333219 JH |
4948 | struct perl_debug_pad { |
4949 | SV pad[3]; | |
4950 | }; | |
4951 | ||
4952 | #define PERL_DEBUG_PAD(i) &(PL_debug_pad.pad[i]) | |
a5c57919 RGS |
4953 | #define PERL_DEBUG_PAD_ZERO(i) (SvPVX(PERL_DEBUG_PAD(i))[0] = 0, \ |
4954 | (((XPV*) SvANY(PERL_DEBUG_PAD(i)))->xpv_cur = 0), \ | |
4955 | PERL_DEBUG_PAD(i)) | |
ce333219 | 4956 | |
56953603 | 4957 | /* Enable variables which are pointers to functions */ |
16c91539 BM |
4958 | typedef void (*peep_t)(pTHX_ OP* o); |
4959 | typedef regexp* (*regcomp_t) (pTHX_ char* exp, char* xend, PMOP* pm); | |
4960 | typedef I32 (*regexec_t) (pTHX_ regexp* prog, char* stringarg, | |
0cb96387 GS |
4961 | char* strend, char* strbeg, I32 minend, |
4962 | SV* screamer, void* data, U32 flags); | |
16c91539 | 4963 | typedef char* (*re_intuit_start_t) (pTHX_ regexp *prog, SV *sv, |
f722798b IZ |
4964 | char *strpos, char *strend, |
4965 | U32 flags, | |
9f61653a | 4966 | re_scream_pos_data *d); |
16c91539 BM |
4967 | typedef SV* (*re_intuit_string_t) (pTHX_ regexp *prog); |
4968 | typedef void (*regfree_t) (pTHX_ struct regexp* r); | |
4969 | typedef regexp* (*regdupe_t) (pTHX_ const regexp* r, CLONE_PARAMS *param); | |
a932d541 | 4970 | typedef I32 (*re_fold_t)(const char *, char const *, I32); |
56953603 | 4971 | |
c76ac1ee | 4972 | typedef void (*DESTRUCTORFUNC_NOCONTEXT_t) (void*); |
acfe0abc | 4973 | typedef void (*DESTRUCTORFUNC_t) (pTHX_ void*); |
f30de749 | 4974 | typedef void (*SVFUNC_t) (pTHX_ SV* const); |
31e9e0a3 | 4975 | typedef I32 (*SVCOMPARE_t) (pTHX_ SV* const, SV* const); |
acfe0abc GS |
4976 | typedef void (*XSINIT_t) (pTHX); |
4977 | typedef void (*ATEXIT_t) (pTHX_ void*); | |
4978 | typedef void (*XSUBADDR_t) (pTHX_ CV *); | |
15e52e56 | 4979 | |
16c91539 BM |
4980 | typedef OP* (*Perl_ppaddr_t)(pTHX); |
4981 | typedef OP* (*Perl_check_t) (pTHX_ OP*); | |
4982 | typedef void(*Perl_ophook_t)(pTHX_ OP*); | |
4983 | typedef int (*Perl_keyword_plugin_t)(pTHX_ char*, STRLEN, OP**); | |
1830b3d9 | 4984 | typedef void(*Perl_cpeep_t)(pTHX_ OP *, OP *); |
88e1f1a2 | 4985 | |
d67594ff FC |
4986 | typedef void(*globhook_t)(pTHX); |
4987 | ||
88e1f1a2 JV |
4988 | #define KEYWORD_PLUGIN_DECLINE 0 |
4989 | #define KEYWORD_PLUGIN_STMT 1 | |
4990 | #define KEYWORD_PLUGIN_EXPR 2 | |
22239a37 | 4991 | |
58a50f62 GS |
4992 | /* Interpreter exitlist entry */ |
4993 | typedef struct exitlistentry { | |
acfe0abc | 4994 | void (*fn) (pTHX_ void*); |
58a50f62 GS |
4995 | void *ptr; |
4996 | } PerlExitListEntry; | |
4997 | ||
aadb217d JH |
4998 | /* if you only have signal() and it resets on each signal, FAKE_PERSISTENT_SIGNAL_HANDLERS fixes */ |
4999 | /* These have to be before perlvars.h */ | |
5000 | #if !defined(HAS_SIGACTION) && defined(VMS) | |
5001 | # define FAKE_PERSISTENT_SIGNAL_HANDLERS | |
5002 | #endif | |
5003 | /* if we're doing kill() with sys$sigprc on VMS, FAKE_DEFAULT_SIGNAL_HANDLERS */ | |
5004 | #if defined(KILL_BY_SIGPRC) | |
5005 | # define FAKE_DEFAULT_SIGNAL_HANDLERS | |
5006 | #endif | |
5007 | ||
8c1cc017 NC |
5008 | #if !defined(MULTIPLICITY) |
5009 | ||
5010 | struct interpreter { | |
5011 | char broiled; | |
22239a37 NIS |
5012 | }; |
5013 | ||
8c1cc017 | 5014 | #else |
22239a37 | 5015 | |
d460ef45 | 5016 | /* If we have multiple interpreters define a struct |
d4cce5f1 | 5017 | holding variables which must be per-interpreter |
d460ef45 | 5018 | If we don't have threads anything that would have |
d4cce5f1 NIS |
5019 | be per-thread is per-interpreter. |
5020 | */ | |
5021 | ||
8c1cc017 | 5022 | /* Set up PERLVAR macros for populating structs */ |
115ff745 | 5023 | # define PERLVAR(prefix,var,type) type prefix##var; |
eb42f199 KW |
5024 | |
5025 | /* 'var' is an array of length 'n' */ | |
115ff745 | 5026 | # define PERLVARA(prefix,var,n,type) type prefix##var[n]; |
eb42f199 KW |
5027 | |
5028 | /* initialize 'var' to init' */ | |
115ff745 | 5029 | # define PERLVARI(prefix,var,type,init) type prefix##var; |
eb42f199 KW |
5030 | |
5031 | /* like PERLVARI, but make 'var' a const */ | |
115ff745 | 5032 | # define PERLVARIC(prefix,var,type,init) type prefix##var; |
8c1cc017 | 5033 | |
79072805 | 5034 | struct interpreter { |
7766f137 | 5035 | # include "intrpvar.h" |
49f531da | 5036 | }; |
d4cce5f1 | 5037 | |
724cf8d6 NC |
5038 | EXTCONST U16 PL_interp_size |
5039 | INIT(sizeof(struct interpreter)); | |
5040 | ||
5041 | # define PERL_INTERPRETER_SIZE_UPTO_MEMBER(member) \ | |
5042 | STRUCT_OFFSET(struct interpreter, member) + \ | |
5043 | sizeof(((struct interpreter*)0)->member) | |
5044 | ||
5045 | /* This will be useful for subsequent releases, because this has to be the | |
5046 | same in your libperl as in main(), else you have a mismatch and must abort. | |
5047 | */ | |
d399cf59 NC |
5048 | EXTCONST U16 PL_interp_size_5_18_0 |
5049 | INIT(PERL_INTERPRETER_SIZE_UPTO_MEMBER(PERL_LAST_5_18_0_INTERP_MEMBER)); | |
724cf8d6 NC |
5050 | |
5051 | ||
8c1cc017 NC |
5052 | # ifdef PERL_GLOBAL_STRUCT |
5053 | /* MULTIPLICITY is automatically defined when PERL_GLOBAL_STRUCT is defined, | |
5054 | hence it's safe and sane to nest this within #ifdef MULTIPLICITY */ | |
5055 | ||
5056 | struct perl_vars { | |
5057 | # include "perlvars.h" | |
49f531da | 5058 | }; |
8c1cc017 | 5059 | |
724cf8d6 NC |
5060 | EXTCONST U16 PL_global_struct_size |
5061 | INIT(sizeof(struct perl_vars)); | |
5062 | ||
8c1cc017 NC |
5063 | # ifdef PERL_CORE |
5064 | # ifndef PERL_GLOBAL_STRUCT_PRIVATE | |
5065 | EXT struct perl_vars PL_Vars; | |
5066 | EXT struct perl_vars *PL_VarsPtr INIT(&PL_Vars); | |
5067 | # undef PERL_GET_VARS | |
5068 | # define PERL_GET_VARS() PL_VarsPtr | |
5069 | # endif /* !PERL_GLOBAL_STRUCT_PRIVATE */ | |
5070 | # else /* PERL_CORE */ | |
5071 | # if !defined(__GNUC__) || !defined(WIN32) | |
5072 | EXT | |
5073 | # endif /* WIN32 */ | |
5074 | struct perl_vars *PL_VarsPtr; | |
5075 | # define PL_Vars (*((PL_VarsPtr) \ | |
5076 | ? PL_VarsPtr : (PL_VarsPtr = Perl_GetVars(aTHX)))) | |
5077 | # endif /* PERL_CORE */ | |
5078 | # endif /* PERL_GLOBAL_STRUCT */ | |
79072805 | 5079 | |
22239a37 | 5080 | /* Done with PERLVAR macros for now ... */ |
8c1cc017 NC |
5081 | # undef PERLVAR |
5082 | # undef PERLVARA | |
5083 | # undef PERLVARI | |
5084 | # undef PERLVARIC | |
8c1cc017 NC |
5085 | |
5086 | #endif /* MULTIPLICITY */ | |
79072805 | 5087 | |
f7fe979e | 5088 | struct tempsym; /* defined in pp_pack.c */ |
49704364 | 5089 | |
22239a37 | 5090 | #include "thread.h" |
79072805 | 5091 | #include "pp.h" |
864dbfa3 | 5092 | |
0cb96387 GS |
5093 | #undef PERL_CKDEF |
5094 | #undef PERL_PPDEF | |
0159f81b JH |
5095 | #define PERL_CKDEF(s) PERL_CALLCONV OP *s (pTHX_ OP *o); |
5096 | #define PERL_PPDEF(s) PERL_CALLCONV OP *s (pTHX); | |
0cb96387 | 5097 | |
158cfab6 JD |
5098 | #ifdef MYMALLOC |
5099 | # include "malloc_ctl.h" | |
5100 | #endif | |
5101 | ||
fc6bde6f DD |
5102 | /* |
5103 | * This provides a layer of functions and macros to ensure extensions will | |
5104 | * get to use the same RTL functions as the core. | |
5105 | */ | |
5106 | #if defined(WIN32) | |
5107 | # include "win32iop.h" | |
5108 | #endif | |
5109 | ||
839a9f02 | 5110 | |
7766f137 | 5111 | #include "proto.h" |
864dbfa3 | 5112 | |
0cb96387 | 5113 | /* this has structure inits, so it cannot be included before here */ |
acfe0abc | 5114 | #include "opcode.h" |
864dbfa3 | 5115 | |
d4cce5f1 NIS |
5116 | /* The following must follow proto.h as #defines mess up syntax */ |
5117 | ||
22c35a8c GS |
5118 | #if !defined(PERL_FOR_X2P) |
5119 | # include "embedvar.h" | |
5120 | #endif | |
d4cce5f1 | 5121 | |
d460ef45 | 5122 | /* Now include all the 'global' variables |
d4cce5f1 | 5123 | * If we don't have threads or multiple interpreters |
d460ef45 | 5124 | * these include variables that would have been their struct-s |
d4cce5f1 | 5125 | */ |
d460ef45 | 5126 | |
115ff745 NC |
5127 | #define PERLVAR(prefix,var,type) EXT type PL_##var; |
5128 | #define PERLVARA(prefix,var,n,type) EXT type PL_##var[n]; | |
5129 | #define PERLVARI(prefix,var,type,init) EXT type PL_##var INIT(init); | |
5130 | #define PERLVARIC(prefix,var,type,init) EXTCONST type PL_##var INIT(init); | |
d4cce5f1 | 5131 | |
acfe0abc | 5132 | #if !defined(MULTIPLICITY) |
7766f137 | 5133 | START_EXTERN_C |
066ef5b5 | 5134 | # include "intrpvar.h" |
7766f137 | 5135 | END_EXTERN_C |
7c123f9d DM |
5136 | # define PL_sv_yes (PL_sv_immortals[0]) |
5137 | # define PL_sv_undef (PL_sv_immortals[1]) | |
5138 | # define PL_sv_no (PL_sv_immortals[2]) | |
5139 | # define PL_sv_zero (PL_sv_immortals[3]) | |
22239a37 NIS |
5140 | #endif |
5141 | ||
24792b8d NC |
5142 | #ifdef PERL_CORE |
5143 | /* All core uses now exterminated. Ensure no zombies can return: */ | |
5144 | # undef PL_na | |
5145 | #endif | |
5146 | ||
f9293c5b NC |
5147 | /* Now all the config stuff is setup we can include embed.h |
5148 | In particular, need the relevant *ish file included already, as it may | |
5149 | define HAVE_INTERP_INTERN */ | |
5150 | #include "embed.h" | |
22239a37 | 5151 | |
c5be433b GS |
5152 | #ifndef PERL_GLOBAL_STRUCT |
5153 | START_EXTERN_C | |
5154 | ||
5155 | # include "perlvars.h" | |
5156 | ||
5157 | END_EXTERN_C | |
5158 | #endif | |
5159 | ||
d4cce5f1 | 5160 | #undef PERLVAR |
51371543 | 5161 | #undef PERLVARA |
d4cce5f1 | 5162 | #undef PERLVARI |
0f3f18a6 | 5163 | #undef PERLVARIC |
79072805 | 5164 | |
db6e00bd DD |
5165 | #if !defined(MULTIPLICITY) |
5166 | /* Set up PERLVAR macros for populating structs */ | |
5167 | # define PERLVAR(prefix,var,type) type prefix##var; | |
5168 | /* 'var' is an array of length 'n' */ | |
5169 | # define PERLVARA(prefix,var,n,type) type prefix##var[n]; | |
5170 | /* initialize 'var' to init' */ | |
5171 | # define PERLVARI(prefix,var,type,init) type prefix##var; | |
5172 | /* like PERLVARI, but make 'var' a const */ | |
5173 | # define PERLVARIC(prefix,var,type,init) type prefix##var; | |
5174 | ||
5175 | /* this is never instantiated, is it just used for sizeof(struct PerlHandShakeInterpreter) */ | |
5176 | struct PerlHandShakeInterpreter { | |
5177 | # include "intrpvar.h" | |
5178 | }; | |
5179 | # undef PERLVAR | |
5180 | # undef PERLVARA | |
5181 | # undef PERLVARI | |
5182 | # undef PERLVARIC | |
5183 | #endif | |
5184 | ||
73c4f7a1 GS |
5185 | START_EXTERN_C |
5186 | ||
af2f0da9 NC |
5187 | /* dummy variables that hold pointers to both runops functions, thus forcing |
5188 | * them *both* to get linked in (useful for Peek.xs, debugging etc) */ | |
5189 | ||
5190 | EXTCONST runops_proc_t PL_runops_std | |
5191 | INIT(Perl_runops_standard); | |
5192 | EXTCONST runops_proc_t PL_runops_dbg | |
5193 | INIT(Perl_runops_debug); | |
5194 | ||
c910fead | 5195 | #define EXT_MGVTBL EXTCONST MGVTBL |
bc028b6b | 5196 | |
82ff486e | 5197 | #define PERL_MAGIC_READONLY_ACCEPTABLE 0x40 |
e0a73de4 NC |
5198 | #define PERL_MAGIC_VALUE_MAGIC 0x80 |
5199 | #define PERL_MAGIC_VTABLE_MASK 0x3F | |
82ff486e NC |
5200 | #define PERL_MAGIC_TYPE_READONLY_ACCEPTABLE(t) \ |
5201 | (PL_magic_data[(U8)(t)] & PERL_MAGIC_READONLY_ACCEPTABLE) | |
e0a73de4 NC |
5202 | #define PERL_MAGIC_TYPE_IS_VALUE_MAGIC(t) \ |
5203 | (PL_magic_data[(U8)(t)] & PERL_MAGIC_VALUE_MAGIC) | |
5204 | ||
8b09643d | 5205 | #include "mg_vtable.h" |
6f83ef0e NC |
5206 | |
5207 | #ifdef DOINIT | |
5208 | EXTCONST U8 PL_magic_data[256] = | |
dde5ec2c NC |
5209 | # ifdef PERL_MICRO |
5210 | # include "umg_data.h" | |
5211 | # else | |
5212 | # include "mg_data.h" | |
5213 | # endif | |
6f83ef0e NC |
5214 | ; |
5215 | #else | |
5216 | EXTCONST U8 PL_magic_data[256]; | |
5217 | #endif | |
5218 | ||
f1fb8741 | 5219 | #ifdef DOINIT |
e94d9b54 | 5220 | /* NL IV NV PV INV PI PN MG RX GV LV AV HV CV FM IO */ |
f1fb8741 | 5221 | EXTCONST bool |
e94d9b54 | 5222 | PL_valid_types_IVX[] = { 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0 }; |
f1fb8741 | 5223 | EXTCONST bool |
e94d9b54 | 5224 | PL_valid_types_NVX[] = { 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0 }; |
f1fb8741 | 5225 | EXTCONST bool |
df6b4bd5 | 5226 | PL_valid_types_PVX[] = { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1 }; |
f1fb8741 | 5227 | EXTCONST bool |
e94d9b54 | 5228 | PL_valid_types_RV[] = { 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1 }; |
f1fb8741 | 5229 | EXTCONST bool |
e94d9b54 | 5230 | PL_valid_types_IV_set[] = { 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1 }; |
f1fb8741 | 5231 | EXTCONST bool |
e94d9b54 | 5232 | PL_valid_types_NV_set[] = { 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; |
f1fb8741 DM |
5233 | |
5234 | #else | |
5235 | ||
5236 | EXTCONST bool PL_valid_types_IVX[]; | |
5237 | EXTCONST bool PL_valid_types_NVX[]; | |
5238 | EXTCONST bool PL_valid_types_PVX[]; | |
5239 | EXTCONST bool PL_valid_types_RV[]; | |
5240 | EXTCONST bool PL_valid_types_IV_set[]; | |
5241 | EXTCONST bool PL_valid_types_NV_set[]; | |
5242 | ||
5243 | #endif | |
5244 | ||
9e76e8dd JH |
5245 | /* In C99 we could use designated (named field) union initializers. |
5246 | * In C89 we need to initialize the member declared first. | |
0879cd66 | 5247 | * In C++ we need extern C initializers. |
9e76e8dd JH |
5248 | * |
5249 | * With the U8_NV version you will want to have inner braces, | |
9ee3aea9 | 5250 | * while with the NV_U8 use just the NV. */ |
0879cd66 JH |
5251 | |
5252 | #ifdef __cplusplus | |
5253 | #define INFNAN_U8_NV_DECL EXTERN_C const union { U8 u8[NVSIZE]; NV nv; } | |
5254 | #define INFNAN_NV_U8_DECL EXTERN_C const union { NV nv; U8 u8[NVSIZE]; } | |
5255 | #else | |
9e76e8dd JH |
5256 | #define INFNAN_U8_NV_DECL EXTCONST union { U8 u8[NVSIZE]; NV nv; } |
5257 | #define INFNAN_NV_U8_DECL EXTCONST union { NV nv; U8 u8[NVSIZE]; } | |
0879cd66 | 5258 | #endif |
9e76e8dd | 5259 | |
cf6e31e9 DM |
5260 | /* if these never got defined, they need defaults */ |
5261 | #ifndef PERL_SET_CONTEXT | |
5262 | # define PERL_SET_CONTEXT(i) PERL_SET_INTERP(i) | |
5263 | #endif | |
5264 | ||
5265 | #ifndef PERL_GET_CONTEXT | |
5266 | # define PERL_GET_CONTEXT PERL_GET_INTERP | |
5267 | #endif | |
5268 | ||
5269 | #ifndef PERL_GET_THX | |
5270 | # define PERL_GET_THX ((void*)NULL) | |
5271 | #endif | |
5272 | ||
5273 | #ifndef PERL_SET_THX | |
5274 | # define PERL_SET_THX(t) NOOP | |
5275 | #endif | |
5276 | ||
5277 | ||
c7627e6d NC |
5278 | #ifndef PERL_NO_INLINE_FUNCTIONS |
5279 | /* Static inline funcs that depend on includes and declarations above. | |
5280 | Some of these reference functions in the perl object files, and some | |
5281 | compilers aren't smart enough to eliminate unused static inline | |
5282 | functions, so including this file in source code can cause link errors | |
5283 | even if the source code uses none of the functions. Hence including these | |
5284 | can be be suppressed by setting PERL_NO_INLINE_FUNCTIONS. Doing this will | |
5285 | (obviously) result in unworkable XS code, but allows simple probing code | |
5286 | to continue to work, because it permits tests to include the perl headers | |
5287 | for definitions without creating a link dependency on the perl library | |
5288 | (which may not exist yet). | |
5289 | */ | |
5290 | ||
5291 | # include "inline.h" | |
5292 | #endif | |
f1fb8741 | 5293 | |
bab3dc31 | 5294 | #include "overload.h" |
a0d0e21e | 5295 | |
73c4f7a1 GS |
5296 | END_EXTERN_C |
5297 | ||
a6006777 | 5298 | struct am_table { |
8978b4ac NC |
5299 | U8 flags; |
5300 | U8 fallback; | |
5301 | U16 spare; | |
eb160463 | 5302 | U32 was_ok_sub; |
9bd87817 | 5303 | CV* table[NofAMmeth]; |
a0d0e21e | 5304 | }; |
a6006777 | 5305 | struct am_table_short { |
8978b4ac NC |
5306 | U8 flags; |
5307 | U8 fallback; | |
5308 | U16 spare; | |
eb160463 | 5309 | U32 was_ok_sub; |
a6006777 | 5310 | }; |
a0d0e21e | 5311 | typedef struct am_table AMT; |
a6006777 | 5312 | typedef struct am_table_short AMTS; |
a0d0e21e LW |
5313 | |
5314 | #define AMGfallNEVER 1 | |
5315 | #define AMGfallNO 2 | |
5316 | #define AMGfallYES 3 | |
5317 | ||
a6006777 | 5318 | #define AMTf_AMAGIC 1 |
5319 | #define AMT_AMAGIC(amt) ((amt)->flags & AMTf_AMAGIC) | |
5320 | #define AMT_AMAGIC_on(amt) ((amt)->flags |= AMTf_AMAGIC) | |
5321 | #define AMT_AMAGIC_off(amt) ((amt)->flags &= ~AMTf_AMAGIC) | |
5322 | ||
32251b26 | 5323 | #define StashHANDLER(stash,meth) gv_handler((stash),CAT2(meth,_amg)) |
c0315cdf JH |
5324 | |
5325 | /* | |
5326 | * some compilers like to redefine cos et alia as faster | |
5327 | * (and less accurate?) versions called F_cos et cetera (Quidquid | |
5328 | * latine dictum sit, altum viditur.) This trick collides with | |
5329 | * the Perl overloading (amg). The following #defines fool both. | |
5330 | */ | |
5331 | ||
5332 | #ifdef _FASTMATH | |
5333 | # ifdef atan2 | |
5334 | # define F_atan2_amg atan2_amg | |
5335 | # endif | |
5336 | # ifdef cos | |
5337 | # define F_cos_amg cos_amg | |
5338 | # endif | |
5339 | # ifdef exp | |
5340 | # define F_exp_amg exp_amg | |
5341 | # endif | |
5342 | # ifdef log | |
5343 | # define F_log_amg log_amg | |
5344 | # endif | |
5345 | # ifdef pow | |
5346 | # define F_pow_amg pow_amg | |
5347 | # endif | |
5348 | # ifdef sin | |
5349 | # define F_sin_amg sin_amg | |
5350 | # endif | |
5351 | # ifdef sqrt | |
5352 | # define F_sqrt_amg sqrt_amg | |
5353 | # endif | |
5354 | #endif /* _FASTMATH */ | |
5355 | ||
83ee9e09 GS |
5356 | #define PERLDB_ALL (PERLDBf_SUB | PERLDBf_LINE | \ |
5357 | PERLDBf_NOOPT | PERLDBf_INTER | \ | |
5358 | PERLDBf_SUBLINE| PERLDBf_SINGLE| \ | |
b8fcbefe NC |
5359 | PERLDBf_NAMEEVAL| PERLDBf_NAMEANON | \ |
5360 | PERLDBf_SAVESRC) | |
925cfbb8 | 5361 | /* No _NONAME, _GOTO */ |
83ee9e09 GS |
5362 | #define PERLDBf_SUB 0x01 /* Debug sub enter/exit */ |
5363 | #define PERLDBf_LINE 0x02 /* Keep line # */ | |
5364 | #define PERLDBf_NOOPT 0x04 /* Switch off optimizations */ | |
5365 | #define PERLDBf_INTER 0x08 /* Preserve more data for | |
5366 | later inspections */ | |
5367 | #define PERLDBf_SUBLINE 0x10 /* Keep subr source lines */ | |
5368 | #define PERLDBf_SINGLE 0x20 /* Start with single-step on */ | |
5369 | #define PERLDBf_NONAME 0x40 /* For _SUB: no name of the subr */ | |
5370 | #define PERLDBf_GOTO 0x80 /* Report goto: call DB::goto */ | |
5371 | #define PERLDBf_NAMEEVAL 0x100 /* Informative names for evals */ | |
5372 | #define PERLDBf_NAMEANON 0x200 /* Informative names for anon subs */ | |
b8fcbefe | 5373 | #define PERLDBf_SAVESRC 0x400 /* Save source lines into @{"_<$filename"} */ |
486ec47a | 5374 | #define PERLDBf_SAVESRC_NOSUBS 0x800 /* Including evals that generate no subroutines */ |
c30d8139 | 5375 | #define PERLDBf_SAVESRC_INVALID 0x1000 /* Save source that did not compile */ |
84902520 | 5376 | |
8bd38399 DD |
5377 | #define PERLDB_SUB (PL_perldb & PERLDBf_SUB) |
5378 | #define PERLDB_LINE (PL_perldb & PERLDBf_LINE) | |
5379 | #define PERLDB_NOOPT (PL_perldb & PERLDBf_NOOPT) | |
5380 | #define PERLDB_INTER (PL_perldb & PERLDBf_INTER) | |
5381 | #define PERLDB_SUBLINE (PL_perldb & PERLDBf_SUBLINE) | |
5382 | #define PERLDB_SINGLE (PL_perldb & PERLDBf_SINGLE) | |
5383 | #define PERLDB_SUB_NN (PL_perldb & PERLDBf_NONAME) | |
5384 | #define PERLDB_GOTO (PL_perldb & PERLDBf_GOTO) | |
5385 | #define PERLDB_NAMEEVAL (PL_perldb & PERLDBf_NAMEEVAL) | |
5386 | #define PERLDB_NAMEANON (PL_perldb & PERLDBf_NAMEANON) | |
5387 | #define PERLDB_SAVESRC (PL_perldb & PERLDBf_SAVESRC) | |
5388 | #define PERLDB_SAVESRC_NOSUBS (PL_perldb & PERLDBf_SAVESRC_NOSUBS) | |
5389 | #define PERLDB_SAVESRC_INVALID (PL_perldb & PERLDBf_SAVESRC_INVALID) | |
bbce6d69 | 5390 | |
c7a622b3 DD |
5391 | #define PERLDB_LINE_OR_SAVESRC (PL_perldb & (PERLDBf_LINE | PERLDBf_SAVESRC)) |
5392 | ||
91191cf7 | 5393 | #ifdef USE_LOCALE |
d6ded950 | 5394 | /* These locale things are all subject to change */ |
929e1213 | 5395 | |
5acc3fa5 KW |
5396 | |
5397 | # if defined(HAS_NEWLOCALE) \ | |
d269de98 KW |
5398 | && defined(LC_ALL_MASK) \ |
5399 | && defined(HAS_FREELOCALE) \ | |
5400 | && defined(HAS_USELOCALE) \ | |
f1d2176b | 5401 | && ! defined(NO_POSIX_2008_LOCALE) |
d269de98 KW |
5402 | |
5403 | /* The code is written for simplicity to assume that any platform advanced | |
5404 | * enough to have the Posix 2008 locale functions has LC_ALL. The test | |
5405 | * above makes sure that assumption is valid */ | |
5406 | ||
5acc3fa5 | 5407 | # define HAS_POSIX_2008_LOCALE |
d269de98 KW |
5408 | # endif |
5409 | ||
5acc3fa5 KW |
5410 | /* We create a C locale object unconditionally if we have the functions to do |
5411 | * so; hence must destroy it unconditionally at the end */ | |
5412 | # ifndef HAS_POSIX_2008_LOCALE | |
5413 | # define _LOCALE_TERM_POSIX_2008 NOOP | |
5414 | # else | |
5415 | # define _LOCALE_TERM_POSIX_2008 \ | |
ffdde306 | 5416 | STMT_START { \ |
ffdde306 KW |
5417 | if (PL_C_locale_obj) { \ |
5418 | /* Make sure we aren't using the locale \ | |
5419 | * space we are about to free */ \ | |
5420 | uselocale(LC_GLOBAL_LOCALE); \ | |
5421 | freelocale(PL_C_locale_obj); \ | |
5422 | PL_C_locale_obj = (locale_t) NULL; \ | |
5423 | } \ | |
5acc3fa5 KW |
5424 | } STMT_END |
5425 | # endif | |
5426 | ||
5427 | # ifndef USE_ITHREADS | |
5428 | # define LOCALE_INIT | |
5429 | # define LOCALE_LOCK | |
5430 | # define LOCALE_UNLOCK | |
5431 | # define LOCALE_TERM STMT_START { _LOCALE_TERM_POSIX_2008; } STMT_END | |
5432 | # else /* Below is do use threads */ | |
5433 | # define LOCALE_INIT MUTEX_INIT(&PL_locale_mutex) | |
5434 | # define LOCALE_LOCK MUTEX_LOCK(&PL_locale_mutex) | |
5435 | # define LOCALE_UNLOCK MUTEX_UNLOCK(&PL_locale_mutex) | |
5436 | # define LOCALE_TERM \ | |
5437 | STMT_START { \ | |
5438 | MUTEX_DESTROY(&PL_locale_mutex); \ | |
5439 | _LOCALE_TERM_POSIX_2008; \ | |
5440 | } STMT_END | |
5441 | # ifdef HAS_POSIX_2008_LOCALE | |
5442 | # define USE_POSIX_2008_LOCALE | |
5443 | # define USE_THREAD_SAFE_LOCALE | |
5444 | # endif | |
5445 | # endif | |
a0b53297 | 5446 | |
c8bf5ca7 | 5447 | /* Returns TRUE if the plain locale pragma without a parameter is in effect |
66cbab2c | 5448 | */ |
6b421707 FC |
5449 | # define IN_LOCALE_RUNTIME (PL_curcop \ |
5450 | && CopHINTS_get(PL_curcop) & HINT_LOCALE) | |
66cbab2c | 5451 | |
c8bf5ca7 | 5452 | /* Returns TRUE if either form of the locale pragma is in effect */ |
6d62ead0 | 5453 | # define IN_SOME_LOCALE_FORM_RUNTIME \ |
d6ded950 | 5454 | cBOOL(CopHINTS_get(PL_curcop) & (HINT_LOCALE|HINT_LOCALE_PARTIAL)) |
66cbab2c | 5455 | |
6d62ead0 KW |
5456 | # define IN_LOCALE_COMPILETIME cBOOL(PL_hints & HINT_LOCALE) |
5457 | # define IN_SOME_LOCALE_FORM_COMPILETIME \ | |
d6ded950 | 5458 | cBOOL(PL_hints & (HINT_LOCALE|HINT_LOCALE_PARTIAL)) |
2de3dbcc | 5459 | |
6d62ead0 | 5460 | # define IN_LOCALE \ |
923e4eb5 | 5461 | (IN_PERL_COMPILETIME ? IN_LOCALE_COMPILETIME : IN_LOCALE_RUNTIME) |
6d62ead0 | 5462 | # define IN_SOME_LOCALE_FORM \ |
66cbab2c KW |
5463 | (IN_PERL_COMPILETIME ? IN_SOME_LOCALE_FORM_COMPILETIME \ |
5464 | : IN_SOME_LOCALE_FORM_RUNTIME) | |
2de3dbcc | 5465 | |
6d62ead0 KW |
5466 | # define IN_LC_ALL_COMPILETIME IN_LOCALE_COMPILETIME |
5467 | # define IN_LC_ALL_RUNTIME IN_LOCALE_RUNTIME | |
5468 | ||
5469 | # define IN_LC_PARTIAL_COMPILETIME cBOOL(PL_hints & HINT_LOCALE_PARTIAL) | |
5470 | # define IN_LC_PARTIAL_RUNTIME \ | |
6b421707 | 5471 | (PL_curcop && CopHINTS_get(PL_curcop) & HINT_LOCALE_PARTIAL) |
6d62ead0 KW |
5472 | |
5473 | # define IN_LC_COMPILETIME(category) \ | |
5474 | (IN_LC_ALL_COMPILETIME || (IN_LC_PARTIAL_COMPILETIME \ | |
5475 | && _is_in_locale_category(TRUE, (category)))) | |
5476 | # define IN_LC_RUNTIME(category) \ | |
5477 | (IN_LC_ALL_RUNTIME || (IN_LC_PARTIAL_RUNTIME \ | |
5478 | && _is_in_locale_category(FALSE, (category)))) | |
5479 | # define IN_LC(category) \ | |
5480 | (IN_LC_COMPILETIME(category) || IN_LC_RUNTIME(category)) | |
d6ded950 | 5481 | |
780fcc9f KW |
5482 | # if defined (PERL_CORE) || defined (PERL_IN_XSUB_RE) |
5483 | ||
5484 | /* This internal macro should be called from places that operate under | |
5485 | * locale rules. It there is a problem with the current locale that | |
2726666d KW |
5486 | * hasn't been raised yet, it will output a warning this time. Because |
5487 | * this will so rarely be true, there is no point to optimize for | |
5488 | * time; instead it makes sense to minimize space used and do all the | |
5489 | * work in the rarely called function */ | |
33245021 KW |
5490 | # ifdef USE_LOCALE_CTYPE |
5491 | # define _CHECK_AND_WARN_PROBLEMATIC_LOCALE \ | |
5492 | STMT_START { \ | |
5493 | if (UNLIKELY(PL_warn_locale)) { \ | |
8d8472df | 5494 | Perl__warn_problematic_locale(); \ |
33245021 KW |
5495 | } \ |
5496 | } STMT_END | |
5497 | # else | |
5498 | # define _CHECK_AND_WARN_PROBLEMATIC_LOCALE | |
5499 | # endif | |
780fcc9f KW |
5500 | |
5501 | ||
613abc6d KW |
5502 | /* These two internal macros are called when a warning should be raised, |
5503 | * and will do so if enabled. The first takes a single code point | |
5504 | * argument; the 2nd, is a pointer to the first byte of the UTF-8 encoded | |
5505 | * string, and an end position which it won't try to read past */ | |
5506 | # define _CHECK_AND_OUTPUT_WIDE_LOCALE_CP_MSG(cp) \ | |
008e8e82 KW |
5507 | STMT_START { \ |
5508 | if (! PL_in_utf8_CTYPE_locale && ckWARN(WARN_LOCALE)) { \ | |
5509 | Perl_warner(aTHX_ packWARN(WARN_LOCALE), \ | |
147e3846 KW |
5510 | "Wide character (U+%" UVXf ") in %s",\ |
5511 | (UV) cp, OP_DESC(PL_op)); \ | |
008e8e82 KW |
5512 | } \ |
5513 | } STMT_END | |
613abc6d KW |
5514 | |
5515 | # define _CHECK_AND_OUTPUT_WIDE_LOCALE_UTF8_MSG(s, send) \ | |
5516 | STMT_START { /* Check if to warn before doing the conversion work */\ | |
008e8e82 | 5517 | if (! PL_in_utf8_CTYPE_locale && ckWARN(WARN_LOCALE)) { \ |
613abc6d KW |
5518 | UV cp = utf8_to_uvchr_buf((U8 *) s, (U8 *) send, NULL); \ |
5519 | Perl_warner(aTHX_ packWARN(WARN_LOCALE), \ | |
147e3846 | 5520 | "Wide character (U+%" UVXf ") in %s", \ |
613abc6d KW |
5521 | (cp == 0) \ |
5522 | ? UNICODE_REPLACEMENT \ | |
5523 | : (UV) cp, \ | |
5524 | OP_DESC(PL_op)); \ | |
5525 | } \ | |
5526 | } STMT_END | |
5527 | ||
780fcc9f KW |
5528 | # endif /* PERL_CORE or PERL_IN_XSUB_RE */ |
5529 | ||
91191cf7 | 5530 | #else /* No locale usage */ |
929e1213 KW |
5531 | # define LOCALE_INIT |
5532 | # define LOCALE_TERM | |
a0b53297 KW |
5533 | # define LOCALE_LOCK |
5534 | # define LOCALE_UNLOCK | |
91191cf7 KW |
5535 | # define IN_LOCALE_RUNTIME 0 |
5536 | # define IN_SOME_LOCALE_FORM_RUNTIME 0 | |
5537 | # define IN_LOCALE_COMPILETIME 0 | |
5538 | # define IN_SOME_LOCALE_FORM_COMPILETIME 0 | |
5539 | # define IN_LOCALE 0 | |
5540 | # define IN_SOME_LOCALE_FORM 0 | |
5541 | # define IN_LC_ALL_COMPILETIME 0 | |
5542 | # define IN_LC_ALL_RUNTIME 0 | |
5543 | # define IN_LC_PARTIAL_COMPILETIME 0 | |
5544 | # define IN_LC_PARTIAL_RUNTIME 0 | |
5545 | # define IN_LC_COMPILETIME(category) 0 | |
5546 | # define IN_LC_RUNTIME(category) 0 | |
5547 | # define IN_LC(category) 0 | |
780fcc9f KW |
5548 | |
5549 | # define _CHECK_AND_WARN_PROBLEMATIC_LOCALE | |
613abc6d KW |
5550 | # define _CHECK_AND_OUTPUT_WIDE_LOCALE_CP_MSG(a) |
5551 | # define _CHECK_AND_OUTPUT_WIDE_LOCALE_UTF8_MSG(a,b) | |
91191cf7 KW |
5552 | #endif |
5553 | ||
6bf09f55 KW |
5554 | #ifdef USE_LOCALE_NUMERIC |
5555 | ||
67d796ae | 5556 | /* These macros are for toggling between the underlying locale (UNDERLYING or |
45235d99 KW |
5557 | * LOCAL) and the C locale (STANDARD). |
5558 | ||
5559 | =head1 Locale-related functions and macros | |
5560 | ||
5561 | =for apidoc Amn|void|DECLARATION_FOR_LC_NUMERIC_MANIPULATION | |
5562 | ||
5563 | This macro should be used as a statement. It declares a private variable | |
5564 | (whose name begins with an underscore) that is needed by the other macros in | |
5565 | this section. Failing to include this correctly should lead to a syntax error. | |
5566 | For compatibility with C89 C compilers it should be placed in a block before | |
5567 | any executable statements. | |
5568 | ||
5569 | =for apidoc Am|void|STORE_LC_NUMERIC_FORCE_TO_UNDERLYING | |
5570 | ||
5571 | This is used by XS code that that is C<LC_NUMERIC> locale-aware to force the | |
5572 | locale for category C<LC_NUMERIC> to be what perl thinks is the current | |
5573 | underlying locale. (The perl interpreter could be wrong about what the | |
5574 | underlying locale actually is if some C or XS code has called the C library | |
5575 | function L<setlocale(3)> behind its back; calling L</sync_locale> before calling | |
5576 | this macro will update perl's records.) | |
5577 | ||
5578 | A call to L</DECLARATION_FOR_LC_NUMERIC_MANIPULATION> must have been made to | |
5579 | declare at compile time a private variable used by this macro. This macro | |
5580 | should be called as a single statement, not an expression, but with an empty | |
5581 | argument list, like this: | |
5582 | ||
5583 | { | |
5584 | DECLARATION_FOR_LC_NUMERIC_MANIPULATION; | |
5585 | ... | |
5586 | STORE_LC_NUMERIC_FORCE_TO_UNDERLYING(); | |
5587 | ... | |
5588 | RESTORE_LC_NUMERIC(); | |
5589 | ... | |
5590 | } | |
5591 | ||
5592 | The private variable is used to save the current locale state, so | |
5593 | that the requisite matching call to L</RESTORE_LC_NUMERIC> can restore it. | |
5594 | ||
5595 | =for apidoc Am|void|STORE_LC_NUMERIC_SET_TO_NEEDED | |
5596 | ||
5597 | This is used to help wrap XS or C code that that is C<LC_NUMERIC> locale-aware. | |
5598 | This locale category is generally kept set to the C locale by Perl for | |
5599 | backwards compatibility, and because most XS code that reads floating point | |
5600 | values can cope only with the decimal radix character being a dot. | |
5601 | ||
5602 | This macro makes sure the current C<LC_NUMERIC> state is set properly, to be | |
5603 | aware of locale if the call to the XS or C code from the Perl program is | |
5604 | from within the scope of a S<C<use locale>>; or to ignore locale if the call is | |
5605 | instead from outside such scope. | |
5606 | ||
5607 | This macro is the start of wrapping the C or XS code; the wrap ending is done | |
5608 | by calling the L</RESTORE_LC_NUMERIC> macro after the operation. Otherwise | |
5609 | the state can be changed that will adversely affect other XS code. | |
5610 | ||
5611 | A call to L</DECLARATION_FOR_LC_NUMERIC_MANIPULATION> must have been made to | |
5612 | declare at compile time a private variable used by this macro. This macro | |
5613 | should be called as a single statement, not an expression, but with an empty | |
5614 | argument list, like this: | |
5615 | ||
5616 | { | |
5617 | DECLARATION_FOR_LC_NUMERIC_MANIPULATION; | |
5618 | ... | |
5619 | STORE_LC_NUMERIC_SET_TO_NEEDED(); | |
5620 | ... | |
5621 | RESTORE_LC_NUMERIC(); | |
5622 | ... | |
5623 | } | |
5624 | ||
5625 | =for apidoc Am|void|RESTORE_LC_NUMERIC | |
5626 | ||
5627 | This is used in conjunction with one of the macros | |
5628 | L</STORE_LC_NUMERIC_SET_TO_NEEDED> | |
5629 | and | |
5630 | L</STORE_LC_NUMERIC_FORCE_TO_UNDERLYING> | |
5631 | ||
5632 | to properly restore the C<LC_NUMERIC> state. | |
5633 | ||
5634 | A call to L</DECLARATION_FOR_LC_NUMERIC_MANIPULATION> must have been made to | |
5635 | declare at compile time a private variable used by this macro and the two | |
5636 | C<STORE> ones. This macro should be called as a single statement, not an | |
5637 | expression, but with an empty argument list, like this: | |
5638 | ||
5639 | { | |
5640 | DECLARATION_FOR_LC_NUMERIC_MANIPULATION; | |
5641 | ... | |
5642 | RESTORE_LC_NUMERIC(); | |
5643 | ... | |
5644 | } | |
5645 | ||
5646 | =cut | |
5647 | ||
5648 | */ | |
8a11fac9 | 5649 | |
aaaeb297 | 5650 | #define _NOT_IN_NUMERIC_STANDARD (! PL_numeric_standard) |
7738054c KW |
5651 | |
5652 | /* We can lock the category to stay in the C locale, making requests to the | |
260c7ace KW |
5653 | * contrary be noops, in the dynamic scope by setting PL_numeric_standard to 2. |
5654 | * */ | |
67d796ae KW |
5655 | #define _NOT_IN_NUMERIC_UNDERLYING \ |
5656 | (! PL_numeric_local && PL_numeric_standard < 2) | |
5657 | ||
5658 | #define DECLARATION_FOR_LC_NUMERIC_MANIPULATION \ | |
5659 | void (*_restore_LC_NUMERIC_function)(pTHX) = NULL | |
5660 | ||
5661 | #define STORE_LC_NUMERIC_SET_TO_NEEDED() \ | |
5662 | if (IN_LC(LC_NUMERIC)) { \ | |
5663 | if (_NOT_IN_NUMERIC_UNDERLYING) { \ | |
8d8472df | 5664 | Perl_set_numeric_local(aTHX); \ |
67d796ae KW |
5665 | _restore_LC_NUMERIC_function = &Perl_set_numeric_standard; \ |
5666 | } \ | |
5667 | } \ | |
5668 | else { \ | |
5669 | if (_NOT_IN_NUMERIC_STANDARD) { \ | |
5670 | SET_NUMERIC_STANDARD(); \ | |
5671 | _restore_LC_NUMERIC_function = &Perl_set_numeric_local; \ | |
5672 | } \ | |
8a11fac9 KW |
5673 | } |
5674 | ||
e737dcc5 KW |
5675 | #define RESTORE_LC_NUMERIC() \ |
5676 | if (_restore_LC_NUMERIC_function) { \ | |
5677 | _restore_LC_NUMERIC_function(aTHX); \ | |
8a11fac9 KW |
5678 | } |
5679 | ||
5680 | /* The next two macros set unconditionally. These should be rarely used, and | |
5681 | * only after being sure that this is what is needed */ | |
8d98ede7 | 5682 | #define SET_NUMERIC_STANDARD() \ |
8d8472df KW |
5683 | STMT_START { if (_NOT_IN_NUMERIC_STANDARD) \ |
5684 | Perl_set_numeric_standard(aTHX); \ | |
5685 | } STMT_END | |
87755cd9 | 5686 | |
67d796ae KW |
5687 | #define SET_NUMERIC_UNDERLYING() \ |
5688 | STMT_START { if (_NOT_IN_NUMERIC_UNDERLYING) \ | |
8d8472df | 5689 | Perl_set_numeric_local(aTHX); } STMT_END |
87755cd9 | 5690 | |
8a11fac9 KW |
5691 | /* The rest of these LC_NUMERIC macros toggle to one or the other state, with |
5692 | * the RESTORE_foo ones called to switch back, but only if need be */ | |
67d796ae KW |
5693 | #define STORE_LC_NUMERIC_UNDERLYING_SET_STANDARD() \ |
5694 | bool _was_local = _NOT_IN_NUMERIC_STANDARD; \ | |
8d8472df | 5695 | if (_was_local) Perl_set_numeric_standard(aTHX); |
f93f4e46 | 5696 | |
b34856cb KW |
5697 | /* Doesn't change to underlying locale unless within the scope of some form of |
5698 | * 'use locale'. This is the usual desired behavior. */ | |
67d796ae KW |
5699 | #define STORE_LC_NUMERIC_STANDARD_SET_UNDERLYING() \ |
5700 | bool _was_standard = _NOT_IN_NUMERIC_UNDERLYING \ | |
5701 | && IN_LC(LC_NUMERIC); \ | |
8d8472df | 5702 | if (_was_standard) Perl_set_numeric_local(aTHX); |
f93f4e46 | 5703 | |
371d5d44 KW |
5704 | /* Rarely, we want to change to the underlying locale even outside of 'use |
5705 | * locale'. This is principally in the POSIX:: functions */ | |
67d796ae KW |
5706 | #define STORE_LC_NUMERIC_FORCE_TO_UNDERLYING() \ |
5707 | if (_NOT_IN_NUMERIC_UNDERLYING) { \ | |
8d8472df | 5708 | Perl_set_numeric_local(aTHX); \ |
67d796ae KW |
5709 | _restore_LC_NUMERIC_function = &Perl_set_numeric_standard; \ |
5710 | } | |
371d5d44 | 5711 | |
42752acc KW |
5712 | /* Lock/unlock to the C locale until unlock is called. This needs to be |
5713 | * recursively callable. [perl #128207] */ | |
67d796ae KW |
5714 | #define LOCK_LC_NUMERIC_STANDARD() \ |
5715 | (__ASSERT_(PL_numeric_standard) \ | |
42752acc | 5716 | PL_numeric_standard++) |
67d796ae | 5717 | #define UNLOCK_LC_NUMERIC_STANDARD() \ |
42752acc KW |
5718 | STMT_START { \ |
5719 | if (PL_numeric_standard > 1) { \ | |
5720 | PL_numeric_standard--; \ | |
5721 | } \ | |
5722 | else { \ | |
5723 | assert(0); \ | |
5724 | } \ | |
5725 | } STMT_END | |
7738054c | 5726 | |
67d796ae | 5727 | #define RESTORE_LC_NUMERIC_UNDERLYING() \ |
8d8472df | 5728 | if (_was_local) Perl_set_numeric_local(aTHX); |
f93f4e46 | 5729 | |
67d796ae KW |
5730 | #define RESTORE_LC_NUMERIC_STANDARD() \ |
5731 | if (_restore_LC_NUMERIC_function) { \ | |
5732 | _restore_LC_NUMERIC_function(aTHX); \ | |
5733 | } | |
f93f4e46 | 5734 | |
36477c24 | 5735 | #else /* !USE_LOCALE_NUMERIC */ |
bbce6d69 | 5736 | |
63b18b66 KW |
5737 | #define SET_NUMERIC_STANDARD() |
5738 | #define SET_NUMERIC_UNDERLYING() | |
5e931b6b | 5739 | #define IS_NUMERIC_RADIX(a, b) (0) |
67d796ae KW |
5740 | #define STORE_LC_NUMERIC_UNDERLYING_SET_STANDARD() |
5741 | #define STORE_LC_NUMERIC_STANDARD_SET_UNDERLYING() | |
5742 | #define STORE_LC_NUMERIC_FORCE_TO_UNDERLYING() | |
5743 | #define RESTORE_LC_NUMERIC_UNDERLYING() | |
e737dcc5 | 5744 | #define RESTORE_LC_NUMERIC_STANDARD() |
67d796ae | 5745 | #define DECLARATION_FOR_LC_NUMERIC_MANIPULATION |
8a11fac9 | 5746 | #define STORE_LC_NUMERIC_SET_TO_NEEDED() |
8a11fac9 | 5747 | #define RESTORE_LC_NUMERIC() |
67d796ae KW |
5748 | #define LOCK_LC_NUMERIC_STANDARD() |
5749 | #define UNLOCK_LC_NUMERIC_STANDARD() | |
8a11fac9 | 5750 | |
36477c24 | 5751 | #endif /* !USE_LOCALE_NUMERIC */ |
a0d0e21e | 5752 | |
22bc8aa4 KW |
5753 | #define Atof my_atof |
5754 | ||
67d796ae KW |
5755 | /* Back-compat names */ |
5756 | #define DECLARATION_FOR_STORE_LC_NUMERIC_SET_TO_NEEDED \ | |
5757 | DECLARATION_FOR_LC_NUMERIC_MANIPULATION | |
5758 | #define DECLARE_STORE_LC_NUMERIC_SET_TO_NEEDED() \ | |
5759 | DECLARATION_FOR_STORE_LC_NUMERIC_SET_TO_NEEDED; \ | |
5760 | STORE_LC_NUMERIC_SET_TO_NEEDED(); | |
5761 | #define LOCK_NUMERIC_STANDARD() LOCK_LC_NUMERIC_STANDARD() | |
5762 | #define RESTORE_NUMERIC_LOCAL() RESTORE_LC_NUMERIC_UNDERLYING() | |
5763 | #define RESTORE_NUMERIC_STANDARD() RESTORE_LC_NUMERIC_STANDARD() | |
5764 | #define SET_NUMERIC_LOCAL() SET_NUMERIC_UNDERLYING() | |
5765 | #define STORE_NUMERIC_LOCAL_SET_STANDARD() \ | |
5766 | STORE_LC_NUMERIC_UNDERLYING_SET_STANDARD() | |
5767 | #define STORE_NUMERIC_STANDARD_SET_LOCAL() \ | |
5768 | STORE_LC_NUMERIC_STANDARD_SET_UNDERLYING() | |
5769 | #define STORE_NUMERIC_STANDARD_FORCE_LOCAL() \ | |
5770 | STORE_LC_NUMERIC_FORCE_TO_UNDERLYING() | |
5771 | #define UNLOCK_NUMERIC_STANDARD() UNLOCK_LC_NUMERIC_STANDARD() | |
5772 | ||
5773 | ||
5774 | ||
05b4a618 JH |
5775 | #ifdef USE_QUADMATH |
5776 | # define Perl_strtod(s, e) strtoflt128(s, e) | |
5777 | #elif defined(HAS_LONG_DOUBLE) && defined(USE_LONG_DOUBLE) | |
f1b32d61 JH |
5778 | # if defined(HAS_STRTOLD) |
5779 | # define Perl_strtod(s, e) strtold(s, e) | |
5780 | # elif defined(HAS_STRTOD) | |
5781 | # define Perl_strtod(s, e) (NV)strtod(s, e) /* Unavoidable loss. */ | |
5782 | # endif | |
5783 | #elif defined(HAS_STRTOD) | |
5784 | # define Perl_strtod(s, e) strtod(s, e) | |
5785 | #endif | |
5786 | ||
85b76970 SH |
5787 | #if !defined(Strtol) && defined(USE_64_BIT_INT) && defined(IV_IS_QUAD) && \ |
5788 | (QUADKIND == QUAD_IS_LONG_LONG || QUADKIND == QUAD_IS___INT64) | |
ec7b9793 JH |
5789 | # ifdef __hpux |
5790 | # define strtoll __strtoll /* secret handshake */ | |
5791 | # endif | |
8ed77d12 | 5792 | # if defined(WIN64) && defined(_MSC_VER) |
c623ac67 GS |
5793 | # define strtoll _strtoi64 /* secret handshake */ |
5794 | # endif | |
079290de GS |
5795 | # if !defined(Strtol) && defined(HAS_STRTOLL) |
5796 | # define Strtol strtoll | |
ad551343 | 5797 | # endif |
28e5dec8 JH |
5798 | # if !defined(Strtol) && defined(HAS_STRTOQ) |
5799 | # define Strtol strtoq | |
5800 | # endif | |
ff935051 | 5801 | /* is there atoq() anywhere? */ |
15b99d39 | 5802 | #endif |
079290de GS |
5803 | #if !defined(Strtol) && defined(HAS_STRTOL) |
5804 | # define Strtol strtol | |
5805 | #endif | |
5806 | #ifndef Atol | |
5807 | /* It would be more fashionable to use Strtol() to define atol() | |
5808 | * (as is done for Atoul(), see below) but for backward compatibility | |
5809 | * we just assume atol(). */ | |
85b76970 SH |
5810 | # if defined(USE_64_BIT_INT) && defined(IV_IS_QUAD) && defined(HAS_ATOLL) && \ |
5811 | (QUADKIND == QUAD_IS_LONG_LONG || QUADKIND == QUAD_IS___INT64) | |
c623ac67 GS |
5812 | # ifdef WIN64 |
5813 | # define atoll _atoi64 /* secret handshake */ | |
5814 | # endif | |
76b882ba JH |
5815 | # define Atol atoll |
5816 | # else | |
5817 | # define Atol atol | |
5818 | # endif | |
cf2093f6 JH |
5819 | #endif |
5820 | ||
85b76970 SH |
5821 | #if !defined(Strtoul) && defined(USE_64_BIT_INT) && defined(UV_IS_QUAD) && \ |
5822 | (QUADKIND == QUAD_IS_LONG_LONG || QUADKIND == QUAD_IS___INT64) | |
ec7b9793 JH |
5823 | # ifdef __hpux |
5824 | # define strtoull __strtoull /* secret handshake */ | |
5825 | # endif | |
8ed77d12 | 5826 | # if defined(WIN64) && defined(_MSC_VER) |
c623ac67 GS |
5827 | # define strtoull _strtoui64 /* secret handshake */ |
5828 | # endif | |
ad551343 | 5829 | # if !defined(Strtoul) && defined(HAS_STRTOULL) |
388d3c03 | 5830 | # define Strtoul strtoull |
15b99d39 | 5831 | # endif |
079290de GS |
5832 | # if !defined(Strtoul) && defined(HAS_STRTOUQ) |
5833 | # define Strtoul strtouq | |
5834 | # endif | |
76d49b1c | 5835 | /* is there atouq() anywhere? */ |
ad551343 | 5836 | #endif |
079290de GS |
5837 | #if !defined(Strtoul) && defined(HAS_STRTOUL) |
5838 | # define Strtoul strtoul | |
cf2093f6 | 5839 | #endif |
a5523c5b JH |
5840 | #if !defined(Strtoul) && defined(HAS_STRTOL) /* Last resort. */ |
5841 | # define Strtoul(s, e, b) strchr((s), '-') ? ULONG_MAX : (unsigned long)strtol((s), (e), (b)) | |
5842 | #endif | |
079290de | 5843 | #ifndef Atoul |
d4c19fe8 | 5844 | # define Atoul(s) Strtoul(s, NULL, 10) |
55eb892c | 5845 | #endif |
cf2093f6 | 5846 | |
a868473f NIS |
5847 | #ifndef PERL_SCRIPT_MODE |
5848 | #define PERL_SCRIPT_MODE "r" | |
5849 | #endif | |
5850 | ||
d2af2719 | 5851 | /* not used. Kept as a NOOP for backcompat */ |
c2af87cb | 5852 | #define PERL_STACK_OVERFLOW_CHECK() NOOP |
da927450 JH |
5853 | |
5854 | /* | |
5855 | * Some nonpreemptive operating systems find it convenient to | |
5856 | * check for asynchronous conditions after each op execution. | |
5857 | * Keep this check simple, or it may slow down execution | |
5858 | * massively. | |
5859 | */ | |
ce08f86c | 5860 | |
1d615522 | 5861 | #ifndef PERL_MICRO |
4ffa73a3 | 5862 | # ifndef PERL_ASYNC_CHECK |
5d9574c1 | 5863 | # define PERL_ASYNC_CHECK() if (UNLIKELY(PL_sig_pending)) PL_signalhook(aTHX) |
4ffa73a3 | 5864 | # endif |
ce08f86c NIS |
5865 | #endif |
5866 | ||
da927450 | 5867 | #ifndef PERL_ASYNC_CHECK |
1d615522 | 5868 | # define PERL_ASYNC_CHECK() NOOP |
da927450 JH |
5869 | #endif |
5870 | ||
5871 | /* | |
5872 | * On some operating systems, a memory allocation may succeed, | |
5873 | * but put the process too close to the system's comfort limit. | |
5874 | * In this case, PERL_ALLOC_CHECK frees the pointer and sets | |
5875 | * it to NULL. | |
5876 | */ | |
5877 | #ifndef PERL_ALLOC_CHECK | |
c2af87cb | 5878 | #define PERL_ALLOC_CHECK(p) NOOP |
da927450 JH |
5879 | #endif |
5880 | ||
bd89102f AD |
5881 | #ifdef HAS_SEM |
5882 | # include <sys/ipc.h> | |
5883 | # include <sys/sem.h> | |
5884 | # ifndef HAS_UNION_SEMUN /* Provide the union semun. */ | |
5885 | union semun { | |
dbba660d TC |
5886 | int val; |
5887 | struct semid_ds *buf; | |
5888 | unsigned short *array; | |
bd89102f AD |
5889 | }; |
5890 | # endif | |
5891 | # ifdef USE_SEMCTL_SEMUN | |
dbba660d TC |
5892 | # ifdef IRIX32_SEMUN_BROKEN_BY_GCC |
5893 | union gccbug_semun { | |
5894 | int val; | |
5895 | struct semid_ds *buf; | |
5896 | unsigned short *array; | |
5897 | char __dummy[5]; | |
5898 | }; | |
5899 | # define semun gccbug_semun | |
5900 | # endif | |
bd89102f | 5901 | # define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun) |
da5fdda8 | 5902 | # elif defined(USE_SEMCTL_SEMID_DS) |
e6f0bdd6 GS |
5903 | # ifdef EXTRA_F_IN_SEMUN_BUF |
5904 | # define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun.buff) | |
5905 | # else | |
5906 | # define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun.buf) | |
5907 | # endif | |
bd89102f | 5908 | # endif |
bd89102f | 5909 | #endif |
49f531da | 5910 | |
89ca4ac7 JH |
5911 | /* |
5912 | * Boilerplate macros for initializing and accessing interpreter-local | |
5913 | * data from C. All statics in extensions should be reworked to use | |
7588b095 JH |
5914 | * this, if you want to make the extension thread-safe. See |
5915 | * ext/XS/APItest/APItest.xs for an example of the use of these macros, | |
5916 | * and perlxs.pod for more. | |
89ca4ac7 JH |
5917 | * |
5918 | * Code that uses these macros is responsible for the following: | |
43a739c2 JH |
5919 | * 1. #define MY_CXT_KEY to a unique string, e.g. |
5920 | * "DynaLoader::_guts" XS_VERSION | |
f16dd614 | 5921 | * XXX in the current implementation, this string is ignored. |
89ca4ac7 JH |
5922 | * 2. Declare a typedef named my_cxt_t that is a structure that contains |
5923 | * all the data that needs to be interpreter-local. | |
5924 | * 3. Use the START_MY_CXT macro after the declaration of my_cxt_t. | |
5925 | * 4. Use the MY_CXT_INIT macro such that it is called exactly once | |
5926 | * (typically put in the BOOT: section). | |
5927 | * 5. Use the members of the my_cxt_t structure everywhere as | |
5928 | * MY_CXT.member. | |
5929 | * 6. Use the dMY_CXT macro (a declaration) in all the functions that | |
5930 | * access MY_CXT. | |
5931 | */ | |
5932 | ||
fc958cd2 | 5933 | #if defined(PERL_IMPLICIT_CONTEXT) |
89ca4ac7 | 5934 | |
4eddb856 | 5935 | /* START_MY_CXT must appear in all extensions that define a my_cxt_t structure, |
53d44271 JH |
5936 | * right after the definition (i.e. at file scope). The non-threads |
5937 | * case below uses it to declare the data as static. */ | |
00ab59c9 DM |
5938 | # ifdef PERL_GLOBAL_STRUCT_PRIVATE |
5939 | # define START_MY_CXT | |
5940 | # define MY_CXT_INDEX Perl_my_cxt_index(aTHX_ MY_CXT_KEY) | |
5941 | # define MY_CXT_INIT_ARG MY_CXT_KEY | |
5942 | # else | |
5943 | # define START_MY_CXT static int my_cxt_index = -1; | |
5944 | # define MY_CXT_INDEX my_cxt_index | |
5945 | # define MY_CXT_INIT_ARG &my_cxt_index | |
5946 | # endif /* #ifdef PERL_GLOBAL_STRUCT_PRIVATE */ | |
53d44271 JH |
5947 | |
5948 | /* Creates and zeroes the per-interpreter data. | |
5949 | * (We allocate my_cxtp in a Perl SV so that it will be released when | |
5950 | * the interpreter goes away.) */ | |
00ab59c9 | 5951 | # define MY_CXT_INIT \ |
53d44271 | 5952 | my_cxt_t *my_cxtp = \ |
9f6df31a Z |
5953 | (my_cxt_t*)Perl_my_cxt_init(aTHX_ MY_CXT_INIT_ARG, sizeof(my_cxt_t)); \ |
5954 | PERL_UNUSED_VAR(my_cxtp) | |
00ab59c9 | 5955 | # define MY_CXT_INIT_INTERP(my_perl) \ |
53d44271 | 5956 | my_cxt_t *my_cxtp = \ |
9f6df31a Z |
5957 | (my_cxt_t*)Perl_my_cxt_init(my_perl, MY_CXT_INIT_ARG, sizeof(my_cxt_t)); \ |
5958 | PERL_UNUSED_VAR(my_cxtp) | |
53d44271 JH |
5959 | |
5960 | /* This declaration should be used within all functions that use the | |
5961 | * interpreter-local data. */ | |
00ab59c9 | 5962 | # define dMY_CXT \ |
53d44271 | 5963 | my_cxt_t *my_cxtp = (my_cxt_t *)PL_my_cxt_list[MY_CXT_INDEX] |
00ab59c9 | 5964 | # define dMY_CXT_INTERP(my_perl) \ |
53d44271 JH |
5965 | my_cxt_t *my_cxtp = (my_cxt_t *)(my_perl)->Imy_cxt_list[MY_CXT_INDEX] |
5966 | ||
5967 | /* Clones the per-interpreter data. */ | |
00ab59c9 | 5968 | # define MY_CXT_CLONE \ |
53d44271 | 5969 | my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\ |
8b573070 | 5970 | void * old_my_cxtp = PL_my_cxt_list[MY_CXT_INDEX]; \ |
ccaa51ca DD |
5971 | PL_my_cxt_list[MY_CXT_INDEX] = my_cxtp; \ |
5972 | Copy(old_my_cxtp, my_cxtp, 1, my_cxt_t); | |
5973 | ||
53d44271 | 5974 | |
53d44271 | 5975 | |
89ca4ac7 | 5976 | /* This macro must be used to access members of the my_cxt_t structure. |
870598ae | 5977 | * e.g. MY_CXT.some_data */ |
00ab59c9 | 5978 | # define MY_CXT (*my_cxtp) |
89ca4ac7 JH |
5979 | |
5980 | /* Judicious use of these macros can reduce the number of times dMY_CXT | |
5981 | * is used. Use is similar to pTHX, aTHX etc. */ | |
00ab59c9 DM |
5982 | # define pMY_CXT my_cxt_t *my_cxtp |
5983 | # define pMY_CXT_ pMY_CXT, | |
5984 | # define _pMY_CXT ,pMY_CXT | |
5985 | # define aMY_CXT my_cxtp | |
5986 | # define aMY_CXT_ aMY_CXT, | |
5987 | # define _aMY_CXT ,aMY_CXT | |
89ca4ac7 | 5988 | |
f16dd614 | 5989 | #else /* PERL_IMPLICIT_CONTEXT */ |
89ca4ac7 | 5990 | |
00ab59c9 DM |
5991 | # define START_MY_CXT static my_cxt_t my_cxt; |
5992 | # define dMY_CXT_SV dNOOP | |
5993 | # define dMY_CXT dNOOP | |
5994 | # define dMY_CXT_INTERP(my_perl) dNOOP | |
5995 | # define MY_CXT_INIT NOOP | |
5996 | # define MY_CXT_CLONE NOOP | |
5997 | # define MY_CXT my_cxt | |
5998 | ||
5999 | # define pMY_CXT void | |
6000 | # define pMY_CXT_ | |
6001 | # define _pMY_CXT | |
6002 | # define aMY_CXT | |
6003 | # define aMY_CXT_ | |
6004 | # define _aMY_CXT | |
89ca4ac7 | 6005 | |
f16dd614 | 6006 | #endif /* !defined(PERL_IMPLICIT_CONTEXT) */ |
89ca4ac7 | 6007 | |
9a34ef1d GS |
6008 | #ifdef I_FCNTL |
6009 | # include <fcntl.h> | |
9a34ef1d GS |
6010 | #endif |
6011 | ||
9cffb111 OS |
6012 | #ifdef __Lynx__ |
6013 | # include <fcntl.h> | |
6014 | #endif | |
6015 | ||
3c0208ad AB |
6016 | #ifdef __amigaos4__ |
6017 | # undef FD_CLOEXEC /* a lie in AmigaOS */ | |
6018 | #endif | |
6019 | ||
9a34ef1d GS |
6020 | #ifdef I_SYS_FILE |
6021 | # include <sys/file.h> | |
6022 | #endif | |
6023 | ||
fa0a29af | 6024 | #if defined(HAS_FLOCK) && !defined(HAS_FLOCK_PROTO) |
2ef53570 JH |
6025 | int flock(int fd, int op); |
6026 | #endif | |
6027 | ||
fe52b3b7 GS |
6028 | #ifndef O_RDONLY |
6029 | /* Assume UNIX defaults */ | |
6030 | # define O_RDONLY 0000 | |
6031 | # define O_WRONLY 0001 | |
6032 | # define O_RDWR 0002 | |
6033 | # define O_CREAT 0100 | |
6034 | #endif | |
9a34ef1d | 6035 | |
16fe6d59 GS |
6036 | #ifndef O_BINARY |
6037 | # define O_BINARY 0 | |
6038 | #endif | |
6039 | ||
6040 | #ifndef O_TEXT | |
6041 | # define O_TEXT 0 | |
6042 | #endif | |
6043 | ||
6ce75a77 | 6044 | #if O_TEXT != O_BINARY |
38d96942 | 6045 | /* If you have different O_TEXT and O_BINARY and you are a CRLF shop, |
6ce75a77 | 6046 | * that is, you are somehow DOSish. */ |
b6c36746 NC |
6047 | # if defined(__HAIKU__) || defined(__VOS__) || defined(__CYGWIN__) |
6048 | /* Haiku has O_TEXT != O_BINARY but O_TEXT and O_BINARY have no effect; | |
6049 | * Haiku is always UNIXoid (LF), not DOSish (CRLF). */ | |
73250e76 JH |
6050 | /* VOS has O_TEXT != O_BINARY, and they have effect, |
6051 | * but VOS always uses LF, never CRLF. */ | |
6ce75a77 JH |
6052 | /* If you have O_TEXT different from your O_BINARY but you still are |
6053 | * not a CRLF shop. */ | |
35990314 | 6054 | # undef PERLIO_USING_CRLF |
ec53fe4f JH |
6055 | # else |
6056 | /* If you really are DOSish. */ | |
6057 | # define PERLIO_USING_CRLF 1 | |
6ce75a77 JH |
6058 | # endif |
6059 | #endif | |
6060 | ||
4bc88a62 PS |
6061 | #ifdef I_LIBUTIL |
6062 | # include <libutil.h> /* setproctitle() in some FreeBSDs */ | |
6063 | #endif | |
6064 | ||
b4748376 | 6065 | #ifndef EXEC_ARGV_CAST |
360ea906 | 6066 | #define EXEC_ARGV_CAST(x) (char **)x |
b4748376 NIS |
6067 | #endif |
6068 | ||
dd5dc04f JH |
6069 | #define IS_NUMBER_IN_UV 0x01 /* number within UV range (maybe not |
6070 | int). value returned in pointed- | |
6071 | to UV */ | |
6072 | #define IS_NUMBER_GREATER_THAN_UV_MAX 0x02 /* pointed to UV undefined */ | |
d70489e1 | 6073 | #define IS_NUMBER_NOT_INT 0x04 /* saw . or E notation or infnan */ |
dd5dc04f JH |
6074 | #define IS_NUMBER_NEG 0x08 /* leading minus sign */ |
6075 | #define IS_NUMBER_INFINITY 0x10 /* this is big */ | |
aa8b85de | 6076 | #define IS_NUMBER_NAN 0x20 /* this is not */ |
3f7602fa | 6077 | #define IS_NUMBER_TRAILING 0x40 /* number has trailing trash */ |
dd5dc04f JH |
6078 | |
6079 | #define GROK_NUMERIC_RADIX(sp, send) grok_numeric_radix(sp, send) | |
6080 | ||
53305cf1 NC |
6081 | /* Input flags: */ |
6082 | #define PERL_SCAN_ALLOW_UNDERSCORES 0x01 /* grok_??? accept _ in numbers */ | |
a4c04bdc | 6083 | #define PERL_SCAN_DISALLOW_PREFIX 0x02 /* grok_??? reject 0x in hex etc */ |
94dd8549 | 6084 | #define PERL_SCAN_SILENT_ILLDIGIT 0x04 /* grok_??? not warn about illegal digits */ |
02470786 KW |
6085 | #define PERL_SCAN_SILENT_NON_PORTABLE 0x08 /* grok_??? not warn about very large |
6086 | numbers which are <= UV_MAX */ | |
3f7602fa TC |
6087 | #define PERL_SCAN_TRAILING 0x10 /* grok_number_flags() allow trailing |
6088 | and set IS_NUMBER_TRAILING */ | |
6089 | ||
53305cf1 NC |
6090 | /* Output flags: */ |
6091 | #define PERL_SCAN_GREATER_THAN_UV_MAX 0x02 /* should this merge with above? */ | |
6092 | ||
2c4f7f0e DM |
6093 | /* to let user control profiling */ |
6094 | #ifdef PERL_GPROF_CONTROL | |
6095 | extern void moncontrol(int); | |
6096 | #define PERL_GPROF_MONCONTROL(x) moncontrol(x) | |
6097 | #else | |
6098 | #define PERL_GPROF_MONCONTROL(x) | |
6099 | #endif | |
6100 | ||
ae0e3d3b JH |
6101 | #ifdef UNDER_CE |
6102 | #include "wince.h" | |
6103 | #endif | |
6104 | ||
6105 | /* ISO 6429 NEL - C1 control NExt Line */ | |
6106 | /* See http://www.unicode.org/unicode/reports/tr13/ */ | |
ec34087a | 6107 | #define NEXT_LINE_CHAR NEXT_LINE_NATIVE |
ae0e3d3b | 6108 | |
479b2847 GS |
6109 | #ifndef PIPESOCK_MODE |
6110 | # define PIPESOCK_MODE | |
6111 | #endif | |
6112 | ||
460c8493 IZ |
6113 | #ifndef SOCKET_OPEN_MODE |
6114 | # define SOCKET_OPEN_MODE PIPESOCK_MODE | |
6115 | #endif | |
6116 | ||
6117 | #ifndef PIPE_OPEN_MODE | |
6118 | # define PIPE_OPEN_MODE PIPESOCK_MODE | |
6119 | #endif | |
6120 | ||
7e8c5dac HS |
6121 | #define PERL_MAGIC_UTF8_CACHESIZE 2 |
6122 | ||
a05d7ebb JH |
6123 | #define PERL_UNICODE_STDIN_FLAG 0x0001 |
6124 | #define PERL_UNICODE_STDOUT_FLAG 0x0002 | |
6125 | #define PERL_UNICODE_STDERR_FLAG 0x0004 | |
a05d7ebb JH |
6126 | #define PERL_UNICODE_IN_FLAG 0x0008 |
6127 | #define PERL_UNICODE_OUT_FLAG 0x0010 | |
06e66572 | 6128 | #define PERL_UNICODE_ARGV_FLAG 0x0020 |
a05d7ebb JH |
6129 | #define PERL_UNICODE_LOCALE_FLAG 0x0040 |
6130 | #define PERL_UNICODE_WIDESYSCALLS_FLAG 0x0080 /* for Sarathy */ | |
5a22a2bb | 6131 | #define PERL_UNICODE_UTF8CACHEASSERT_FLAG 0x0100 |
a05d7ebb | 6132 | |
06e66572 JH |
6133 | #define PERL_UNICODE_STD_FLAG \ |
6134 | (PERL_UNICODE_STDIN_FLAG | \ | |
6135 | PERL_UNICODE_STDOUT_FLAG | \ | |
6136 | PERL_UNICODE_STDERR_FLAG) | |
6137 | ||
6138 | #define PERL_UNICODE_INOUT_FLAG \ | |
6139 | (PERL_UNICODE_IN_FLAG | \ | |
6140 | PERL_UNICODE_OUT_FLAG) | |
6141 | ||
6142 | #define PERL_UNICODE_DEFAULT_FLAGS \ | |
a05d7ebb JH |
6143 | (PERL_UNICODE_STD_FLAG | \ |
6144 | PERL_UNICODE_INOUT_FLAG | \ | |
6145 | PERL_UNICODE_LOCALE_FLAG) | |
6146 | ||
5a22a2bb | 6147 | #define PERL_UNICODE_ALL_FLAGS 0x01ff |
a05d7ebb JH |
6148 | |
6149 | #define PERL_UNICODE_STDIN 'I' | |
6150 | #define PERL_UNICODE_STDOUT 'O' | |
6151 | #define PERL_UNICODE_STDERR 'E' | |
6152 | #define PERL_UNICODE_STD 'S' | |
6153 | #define PERL_UNICODE_IN 'i' | |
6154 | #define PERL_UNICODE_OUT 'o' | |
6155 | #define PERL_UNICODE_INOUT 'D' | |
6156 | #define PERL_UNICODE_ARGV 'A' | |
6157 | #define PERL_UNICODE_LOCALE 'L' | |
6158 | #define PERL_UNICODE_WIDESYSCALLS 'W' | |
5a22a2bb | 6159 | #define PERL_UNICODE_UTF8CACHEASSERT 'a' |
a05d7ebb | 6160 | |
4ffa73a3 JH |
6161 | #define PERL_SIGNALS_UNSAFE_FLAG 0x0001 |
6162 | ||
32fdb065 | 6163 | /* Use instead of abs() since abs() forces its argument to be an int, |
56c380de | 6164 | * but also beware since this evaluates its argument twice, so no x++. */ |
32fdb065 JH |
6165 | #define PERL_ABS(x) ((x) < 0 ? -(x) : (x)) |
6166 | ||
3c0f78ca JH |
6167 | #if defined(__DECC) && defined(__osf__) |
6168 | #pragma message disable (mainparm) /* Perl uses the envp in main(). */ | |
24801a4b JH |
6169 | #endif |
6170 | ||
e4dba786 NC |
6171 | #define do_open(g, n, l, a, rm, rp, sf) \ |
6172 | do_openn(g, n, l, a, rm, rp, sf, (SV **) NULL, 0) | |
9555a685 | 6173 | #ifdef PERL_DEFAULT_DO_EXEC3_IMPLEMENTATION |
711aba4c | 6174 | # define do_exec(cmd) do_exec3(cmd,0,0) |
a9f96b3f | 6175 | #endif |
15871fce NC |
6176 | #ifdef OS2 |
6177 | # define do_aexec Perl_do_aexec | |
6178 | #else | |
6179 | # define do_aexec(really, mark,sp) do_aexec5(really, mark, sp, 0, 0) | |
9555a685 | 6180 | #endif |
e4dba786 | 6181 | |
c8028aa6 TC |
6182 | /* check embedded \0 characters in pathnames passed to syscalls, |
6183 | but allow one ending \0 */ | |
41188aa0 | 6184 | #define IS_SAFE_SYSCALL(p, len, what, op_name) (S_is_safe_syscall(aTHX_ (p), (len), (what), (op_name))) |
c8028aa6 | 6185 | |
41188aa0 | 6186 | #define IS_SAFE_PATHNAME(p, len, op_name) IS_SAFE_SYSCALL((p), (len), "pathname", (op_name)) |
c8028aa6 | 6187 | |
53e89cff | 6188 | #if defined(OEMVS) || defined(__amigaos4__) |
2f3efc97 JH |
6189 | #define NO_ENV_ARRAY_IN_MAIN |
6190 | #endif | |
6191 | ||
00f254e2 KW |
6192 | /* These are used by Perl_pv_escape() and Perl_pv_pretty() |
6193 | * are here so that they are available throughout the core | |
10edeb5d JH |
6194 | * NOTE that even though some are for _escape and some for _pretty |
6195 | * there must not be any clashes as the flags from _pretty are | |
6196 | * passed straight through to _escape. | |
6197 | */ | |
6198 | ||
4420a417 | 6199 | #define PERL_PV_ESCAPE_QUOTE 0x000001 |
10edeb5d JH |
6200 | #define PERL_PV_PRETTY_QUOTE PERL_PV_ESCAPE_QUOTE |
6201 | ||
4420a417 YO |
6202 | #define PERL_PV_PRETTY_ELLIPSES 0x000002 |
6203 | #define PERL_PV_PRETTY_LTGT 0x000004 | |
6204 | #define PERL_PV_PRETTY_EXACTSIZE 0x000008 | |
10edeb5d | 6205 | |
4420a417 YO |
6206 | #define PERL_PV_ESCAPE_UNI 0x000100 |
6207 | #define PERL_PV_ESCAPE_UNI_DETECT 0x000200 | |
6208 | #define PERL_PV_ESCAPE_NONASCII 0x000400 | |
6209 | #define PERL_PV_ESCAPE_FIRSTCHAR 0x000800 | |
10edeb5d | 6210 | |
4420a417 YO |
6211 | #define PERL_PV_ESCAPE_ALL 0x001000 |
6212 | #define PERL_PV_ESCAPE_NOBACKSLASH 0x002000 | |
6213 | #define PERL_PV_ESCAPE_NOCLEAR 0x004000 | |
6214 | #define PERL_PV_PRETTY_NOCLEAR PERL_PV_ESCAPE_NOCLEAR | |
6215 | #define PERL_PV_ESCAPE_RE 0x008000 | |
10edeb5d | 6216 | |
4420a417 | 6217 | #define PERL_PV_ESCAPE_DWIM 0x010000 |
0eb335df | 6218 | |
881a015e | 6219 | |
10edeb5d | 6220 | /* used by pv_display in dump.c*/ |
95b611b0 | 6221 | #define PERL_PV_PRETTY_DUMP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_QUOTE |
c89df6cf | 6222 | #define PERL_PV_PRETTY_REGPROP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_LTGT|PERL_PV_ESCAPE_RE|PERL_PV_ESCAPE_NONASCII |
10edeb5d | 6223 | |
a7157111 JH |
6224 | #if DOUBLEKIND == DOUBLE_IS_VAX_F_FLOAT || \ |
6225 | DOUBLEKIND == DOUBLE_IS_VAX_D_FLOAT || \ | |
6226 | DOUBLEKIND == DOUBLE_IS_VAX_G_FLOAT | |
6227 | # define DOUBLE_IS_VAX_FLOAT | |
6228 | #else | |
6229 | # define DOUBLE_IS_IEEE_FORMAT | |
6230 | #endif | |
6231 | ||
3fd106b1 JH |
6232 | #if DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN || \ |
6233 | DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN || \ | |
6234 | DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN | |
6235 | # define DOUBLE_LITTLE_ENDIAN | |
6236 | #endif | |
6237 | ||
075bc527 JH |
6238 | #if DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN || \ |
6239 | DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN || \ | |
6240 | DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN | |
6241 | # define DOUBLE_BIG_ENDIAN | |
6242 | #endif | |
6243 | ||
804d4e64 JH |
6244 | #if DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE || \ |
6245 | DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE | |
6246 | # define DOUBLE_MIX_ENDIAN | |
6247 | #endif | |
6248 | ||
60d50332 JH |
6249 | /* The VAX fp formats are neither consistently little-endian nor |
6250 | * big-endian, and neither are they really IEEE-mixed endian like | |
6251 | * the mixed-endian ARM IEEE formats (with swapped bytes). | |
e90f8530 | 6252 | * Ultimately, the VAX format came from the PDP-11. |
60d50332 JH |
6253 | * |
6254 | * The ordering of the parts in VAX floats is quite vexing. | |
6255 | * In the below the fraction_n are the mantissa bits. | |
df127a67 | 6256 | * |
60d50332 | 6257 | * The fraction_1 is the most significant (numbering as by DEC/Digital), |
6ce22998 JH |
6258 | * while the rightmost bit in each fraction is the least significant: |
6259 | * in other words, big-endian bit order within the fractions. | |
df127a67 | 6260 | * |
6ce22998 | 6261 | * The fraction segments themselves would be big-endianly, except that |
df127a67 | 6262 | * within 32 bit segments the less significant half comes first, the more |
6ce22998 | 6263 | * significant after, except that in the format H (used for long doubles) |
df127a67 | 6264 | * the first fraction segment is alone, because the exponent is wider. |
6ce22998 JH |
6265 | * This means for example that both the most and the least significant |
6266 | * bits can be in the middle of the floats, not at either end. | |
6267 | * | |
6268 | * References: | |
6269 | * http://nssdc.gsfc.nasa.gov/nssdc/formats/VAXFloatingPoint.htm | |
6270 | * http://www.quadibloc.com/comp/cp0201.htm | |
6271 | * http://h71000.www7.hp.com/doc/82final/6443/6443pro_028.html | |
6272 | * (somebody at HP should be fired for the URLs) | |
60d50332 | 6273 | * |
df127a67 | 6274 | * F fraction_2:16 sign:1 exp:8 fraction_1:7 |
e90f8530 | 6275 | * (exponent bias 128, hidden first one-bit) |
60d50332 | 6276 | * |
df127a67 | 6277 | * D fraction_2:16 sign:1 exp:8 fraction_1:7 |
60d50332 | 6278 | * fraction_4:16 fraction_3:16 |
e90f8530 | 6279 | * (exponent bias 128, hidden first one-bit) |
60d50332 | 6280 | * |
6ce22998 | 6281 | * G fraction_2:16 sign:1 exp:11 fraction_1:4 |
60d50332 | 6282 | * fraction_4:16 fraction_3:16 |
e90f8530 | 6283 | * (exponent bias 1024, hidden first one-bit) |
60d50332 JH |
6284 | * |
6285 | * H fraction_1:16 sign:1 exp:15 | |
6286 | * fraction_3:16 fraction_2:16 | |
6287 | * fraction_5:16 fraction_4:16 | |
6288 | * fraction_7:16 fraction_6:16 | |
e90f8530 JH |
6289 | * (exponent bias 16384, hidden first one-bit) |
6290 | * (available only on VAX, and only on Fortran?) | |
6291 | * | |
6292 | * The formats S, T and X are available on the Alpha (and Itanium, | |
6293 | * also known as I64/IA64) and are equivalent with the IEEE-754 formats | |
6294 | * binary32, binary64, and binary128 (commonly: float, double, long double). | |
6295 | * | |
6296 | * S sign:1 exp:8 mantissa:23 | |
6297 | * (exponent bias 127, hidden first one-bit) | |
6298 | * | |
6299 | * T sign:1 exp:11 mantissa:52 | |
6300 | * (exponent bias 1022, hidden first one-bit) | |
6301 | * | |
6302 | * X sign:1 exp:15 mantissa:112 | |
6303 | * (exponent bias 16382, hidden first one-bit) | |
60d50332 | 6304 | * |
60d50332 | 6305 | */ |
a7157111 JH |
6306 | |
6307 | #ifdef DOUBLE_IS_VAX_FLOAT | |
6308 | # define DOUBLE_VAX_ENDIAN | |
6309 | #endif | |
6310 | ||
6311 | #ifdef DOUBLE_IS_IEEE_FORMAT | |
63a6ab05 | 6312 | /* All the basic IEEE formats have the implicit bit, |
b6d9b423 JH |
6313 | * except for the x86 80-bit extended formats, which will undef this. |
6314 | * Also note that the IEEE 754 subnormals (formerly known as denormals) | |
6315 | * do not have the implicit bit of one. */ | |
a7157111 JH |
6316 | # define NV_IMPLICIT_BIT |
6317 | #endif | |
63a6ab05 | 6318 | |
a7157111 | 6319 | #if defined(LONG_DOUBLEKIND) && LONG_DOUBLEKIND != LONG_DOUBLE_IS_DOUBLE |
3fd106b1 JH |
6320 | |
6321 | # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN || \ | |
6322 | LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN || \ | |
1f02ab1d | 6323 | LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE |
3fd106b1 JH |
6324 | # define LONGDOUBLE_LITTLE_ENDIAN |
6325 | # endif | |
6326 | ||
6327 | # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN || \ | |
6328 | LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN || \ | |
1f02ab1d | 6329 | LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE |
3fd106b1 JH |
6330 | # define LONGDOUBLE_BIG_ENDIAN |
6331 | # endif | |
6332 | ||
1f02ab1d JH |
6333 | # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE || \ |
6334 | LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE | |
6335 | # define LONGDOUBLE_MIX_ENDIAN | |
6336 | # endif | |
6337 | ||
3fd106b1 JH |
6338 | # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN || \ |
6339 | LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN | |
6340 | # define LONGDOUBLE_X86_80_BIT | |
63a6ab05 JH |
6341 | # ifdef USE_LONG_DOUBLE |
6342 | # undef NV_IMPLICIT_BIT | |
f40ac91c | 6343 | # define NV_X86_80_BIT |
63a6ab05 | 6344 | # endif |
3fd106b1 JH |
6345 | # endif |
6346 | ||
1f02ab1d JH |
6347 | # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE || \ |
6348 | LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE || \ | |
6349 | LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE || \ | |
6350 | LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE | |
3fd106b1 JH |
6351 | # define LONGDOUBLE_DOUBLEDOUBLE |
6352 | # endif | |
6353 | ||
2c7d9883 JH |
6354 | # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_VAX_H_FLOAT |
6355 | # define LONGDOUBLE_VAX_ENDIAN | |
6356 | # endif | |
6357 | ||
f03a9d38 | 6358 | #endif /* LONG_DOUBLEKIND */ |
3fd106b1 | 6359 | |
9e76e8dd JH |
6360 | #ifdef USE_QUADMATH /* assume quadmath endianness == native double endianness */ |
6361 | # if defined(DOUBLE_LITTLE_ENDIAN) | |
6362 | # define NV_LITTLE_ENDIAN | |
6363 | # elif defined(DOUBLE_BIG_ENDIAN) | |
6364 | # define NV_BIG_ENDIAN | |
6365 | # elif defined(DOUBLE_MIX_ENDIAN) /* stretch */ | |
6366 | # define NV_MIX_ENDIAN | |
6367 | # endif | |
6368 | #elif NVSIZE == DOUBLESIZE | |
d701dd28 JH |
6369 | # ifdef DOUBLE_LITTLE_ENDIAN |
6370 | # define NV_LITTLE_ENDIAN | |
6371 | # endif | |
6372 | # ifdef DOUBLE_BIG_ENDIAN | |
6373 | # define NV_BIG_ENDIAN | |
6374 | # endif | |
804d4e64 JH |
6375 | # ifdef DOUBLE_MIX_ENDIAN |
6376 | # define NV_MIX_ENDIAN | |
6377 | # endif | |
a7157111 JH |
6378 | # ifdef DOUBLE_VAX_ENDIAN |
6379 | # define NV_VAX_ENDIAN | |
6380 | # endif | |
d701dd28 JH |
6381 | #elif NVSIZE == LONG_DOUBLESIZE |
6382 | # ifdef LONGDOUBLE_LITTLE_ENDIAN | |
6383 | # define NV_LITTLE_ENDIAN | |
6384 | # endif | |
6385 | # ifdef LONGDOUBLE_BIG_ENDIAN | |
6386 | # define NV_BIG_ENDIAN | |
6387 | # endif | |
1f02ab1d JH |
6388 | # ifdef LONGDOUBLE_MIX_ENDIAN |
6389 | # define NV_MIX_ENDIAN | |
6390 | # endif | |
2c7d9883 JH |
6391 | # ifdef LONGDOUBLE_VAX_ENDIAN |
6392 | # define NV_VAX_ENDIAN | |
6393 | # endif | |
d701dd28 JH |
6394 | #endif |
6395 | ||
488307ff S |
6396 | /* We have somehow managed not to define the denormal/subnormal |
6397 | * detection. | |
6398 | * | |
6399 | * This may happen if the compiler doesn't expose the C99 math like | |
6400 | * the fpclassify() without some special switches. Perl tries to | |
6401 | * stay C89, so for example -std=c99 is not an option. | |
6402 | * | |
6403 | * The Perl_isinf() and Perl_isnan() should have been defined even if | |
6404 | * the C99 isinf() and isnan() are unavailable, and the NV_MIN becomes | |
6405 | * from the C89 DBL_MIN or moral equivalent. */ | |
6406 | #if !defined(Perl_fp_class_denorm) && defined(Perl_isinf) && defined(Perl_isnan) && defined(NV_MIN) | |
6407 | # define Perl_fp_class_denorm(x) ((x) != 0.0 && !Perl_isinf(x) && !Perl_isnan(x) && PERL_ABS(x) < NV_MIN) | |
6408 | #endif | |
6409 | ||
6410 | /* This is not a great fallback: subnormals tests will fail, | |
6411 | * but at least Perl will link and 99.999% of tests will work. */ | |
6412 | #if !defined(Perl_fp_class_denorm) | |
6413 | # define Perl_fp_class_denorm(x) FALSE | |
6414 | #endif | |
6415 | ||
a7157111 JH |
6416 | #ifdef DOUBLE_IS_IEEE_FORMAT |
6417 | # define DOUBLE_HAS_INF | |
6418 | # define DOUBLE_HAS_NAN | |
6419 | #endif | |
6420 | ||
6421 | #ifdef DOUBLE_HAS_NAN | |
6422 | ||
9ee3aea9 JH |
6423 | #ifdef DOINIT |
6424 | ||
6425 | /* PL_inf and PL_nan initialization. | |
6426 | * | |
6427 | * For inf and nan initialization the ultimate fallback is dividing | |
6428 | * one or zero by zero: however, some compilers will warn or even fail | |
6429 | * on divide-by-zero, but hopefully something earlier will work. | |
6430 | * | |
6431 | * If you are thinking of using HUGE_VAL for infinity, or using | |
6432 | * <math.h> functions to generate NV_INF (e.g. exp(1e9), log(-1.0)), | |
6433 | * stop. Neither will work portably: HUGE_VAL can be just DBL_MAX, | |
6434 | * and the math functions might be just generating DBL_MAX, or even zero. | |
6435 | * | |
6436 | * Also, do NOT try doing NV_NAN based on NV_INF and trying (NV_INF-NV_INF). | |
6437 | * Though logically correct, some compilers (like Visual C 2003) | |
6438 | * falsely misoptimize that to zero (x-x is always zero, right?) | |
6439 | * | |
6440 | * Finally, note that not all floating point formats define Inf (or NaN). | |
6441 | * For the infinity a large number may be used instead. Operations that | |
6442 | * under the IEEE floating point would return Inf or NaN may return | |
6443 | * either large numbers (positive or negative), or they may cause | |
6444 | * a floating point exception or some other fault. | |
6445 | */ | |
6446 | ||
6447 | /* The quadmath literals are anon structs which -Wc++-compat doesn't like. */ | |
6448 | GCC_DIAG_IGNORE(-Wc++-compat) | |
6449 | ||
6450 | # ifdef USE_QUADMATH | |
6451 | /* Cannot use HUGE_VALQ for PL_inf because not a compile-time | |
6452 | * constant. */ | |
6453 | INFNAN_NV_U8_DECL PL_inf = { 1.0Q/0.0Q }; | |
6454 | # elif NVSIZE == LONG_DOUBLESIZE && defined(LONGDBLINFBYTES) | |
6455 | INFNAN_U8_NV_DECL PL_inf = { { LONGDBLINFBYTES } }; | |
6456 | # elif NVSIZE == DOUBLESIZE && defined(DOUBLEINFBYTES) | |
6457 | INFNAN_U8_NV_DECL PL_inf = { { DOUBLEINFBYTES } }; | |
6458 | # else | |
6459 | # if NVSIZE == LONG_DOUBLESIZE && defined(USE_LONG_DOUBLE) | |
6460 | # if defined(LDBL_INFINITY) | |
6461 | INFNAN_NV_U8_DECL PL_inf = { LDBL_INFINITY }; | |
6462 | # elif defined(LDBL_INF) | |
6463 | INFNAN_NV_U8_DECL PL_inf = { LDBL_INF }; | |
6464 | # elif defined(INFINITY) | |
6465 | INFNAN_NV_U8_DECL PL_inf = { (NV)INFINITY }; | |
6466 | # elif defined(INF) | |
6467 | INFNAN_NV_U8_DECL PL_inf = { (NV)INF }; | |
6468 | # else | |
6469 | INFNAN_NV_U8_DECL PL_inf = { 1.0L/0.0L }; /* keep last */ | |
6470 | # endif | |
6471 | # else | |
6472 | # if defined(DBL_INFINITY) | |
6473 | INFNAN_NV_U8_DECL PL_inf = { DBL_INFINITY }; | |
6474 | # elif defined(DBL_INF) | |
6475 | INFNAN_NV_U8_DECL PL_inf = { DBL_INF }; | |
6476 | # elif defined(INFINITY) /* C99 */ | |
6477 | INFNAN_NV_U8_DECL PL_inf = { (NV)INFINITY }; | |
6478 | # elif defined(INF) | |
6479 | INFNAN_NV_U8_DECL PL_inf = { (NV)INF }; | |
6480 | # else | |
6481 | INFNAN_NV_U8_DECL PL_inf = { 1.0/0.0 }; /* keep last */ | |
6482 | # endif | |
6483 | # endif | |
6484 | # endif | |
6485 | ||
6486 | # ifdef USE_QUADMATH | |
6487 | /* Cannot use nanq("0") for PL_nan because not a compile-time | |
6488 | * constant. */ | |
6489 | INFNAN_NV_U8_DECL PL_nan = { 0.0Q/0.0Q }; | |
6490 | # elif NVSIZE == LONG_DOUBLESIZE && defined(LONGDBLNANBYTES) | |
6491 | INFNAN_U8_NV_DECL PL_nan = { { LONGDBLNANBYTES } }; | |
6492 | # elif NVSIZE == DOUBLESIZE && defined(DOUBLENANBYTES) | |
6493 | INFNAN_U8_NV_DECL PL_nan = { { DOUBLENANBYTES } }; | |
6494 | # else | |
6495 | # if NVSIZE == LONG_DOUBLESIZE && defined(USE_LONG_DOUBLE) | |
6496 | # if defined(LDBL_NAN) | |
6497 | INFNAN_NV_U8_DECL PL_nan = { LDBL_NAN }; | |
6498 | # elif defined(LDBL_QNAN) | |
6499 | INFNAN_NV_U8_DECL PL_nan = { LDBL_QNAN }; | |
6500 | # elif defined(NAN) | |
6501 | INFNAN_NV_U8_DECL PL_nan = { (NV)NAN }; | |
6502 | # else | |
6503 | INFNAN_NV_U8_DECL PL_nan = { 0.0L/0.0L }; /* keep last */ | |
6504 | # endif | |
6505 | # else | |
6506 | # if defined(DBL_NAN) | |
6507 | INFNAN_NV_U8_DECL PL_nan = { DBL_NAN }; | |
6508 | # elif defined(DBL_QNAN) | |
6509 | INFNAN_NV_U8_DECL PL_nan = { DBL_QNAN }; | |
6510 | # elif defined(NAN) /* C99 */ | |
6511 | INFNAN_NV_U8_DECL PL_nan = { (NV)NAN }; | |
6512 | # else | |
6513 | INFNAN_NV_U8_DECL PL_nan = { 0.0/0.0 }; /* keep last */ | |
6514 | # endif | |
6515 | # endif | |
6516 | # endif | |
6517 | ||
6518 | GCC_DIAG_RESTORE | |
6519 | ||
6520 | #else | |
6521 | ||
6522 | INFNAN_NV_U8_DECL PL_inf; | |
6523 | INFNAN_NV_U8_DECL PL_nan; | |
6524 | ||
6525 | #endif | |
6526 | ||
6527 | /* If you have not defined NV_INF/NV_NAN (like for example win32/win32.h), | |
6528 | * we will define NV_INF/NV_NAN as the nv part of the global const | |
6529 | * PL_inf/PL_nan. Note, however, that the preexisting NV_INF/NV_NAN | |
6530 | * might not be a compile-time constant, in which case it cannot be | |
6531 | * used to initialize PL_inf/PL_nan above. */ | |
6532 | #ifndef NV_INF | |
6533 | # define NV_INF PL_inf.nv | |
6534 | #endif | |
6535 | #ifndef NV_NAN | |
6536 | # define NV_NAN PL_nan.nv | |
6537 | #endif | |
6538 | ||
5c255b3b JH |
6539 | /* NaNs (not-a-numbers) can carry payload bits, in addition to |
6540 | * "nan-ness". Part of the payload is the quiet/signaling bit. | |
6541 | * To back up a bit (harhar): | |
6542 | * | |
6543 | * For IEEE 754 64-bit formats [1]: | |
6544 | * | |
6545 | * s 000 (mantissa all-zero) zero | |
6546 | * s 000 (mantissa non-zero) subnormals (denormals) | |
6547 | * s 001 ... 7fe normals | |
6548 | * s 7ff q nan | |
6549 | * | |
6550 | * For IEEE 754 128-bit formats: | |
6551 | * | |
6552 | * s 0000 (mantissa all-zero) zero | |
6553 | * s 0000 (mantissa non-zero) subnormals (denormals) | |
6554 | * s 0001 ... 7ffe normals | |
6555 | * s 7fff q nan | |
6556 | * | |
6557 | * [1] this looks like big-endian, but applies equally to little-endian. | |
6558 | * | |
6559 | * s = Sign bit. Yes, zeros and nans can have negative sign, | |
6560 | * the interpretation is application-specific. | |
6561 | * | |
6562 | * q = Quietness bit, the interpretation is platform-specific. | |
453b60f1 | 6563 | * Most platforms have the most significant bit being one |
5c255b3b JH |
6564 | * meaning quiet, but some (older mips, hppa) have the msb |
6565 | * being one meaning signaling. Note that the above means | |
6566 | * that on most platforms there cannot be signaling nan with | |
453b60f1 JH |
6567 | * zero payload because that is identical with infinity; |
6568 | * while conversely on older mips/hppa there cannot be a quiet nan | |
6569 | * because that is identical with infinity. | |
6570 | * | |
6571 | * Moreover, whether there is any behavioral difference | |
6572 | * between quiet and signaling NaNs, depends on the platform. | |
5c255b3b JH |
6573 | * |
6574 | * x86 80-bit extended precision is different, the mantissa bits: | |
6575 | * | |
6576 | * 63 62 61 30387+ pre-387 visual c | |
6577 | * -------- ---- -------- -------- | |
6578 | * 0 0 0 invalid infinity | |
6579 | * 0 0 1 invalid snan | |
6580 | * 0 1 0 invalid snan | |
6581 | * 0 1 1 invalid snan | |
6582 | * 1 0 0 infinity snan 1.#INF | |
6583 | * 1 0 1 snan 1.#SNAN | |
6584 | * 1 1 0 qnan -1.#IND (x86 chooses this to negative) | |
6585 | * 1 1 1 qnan 1.#QNAN | |
6586 | * | |
6587 | * This means that in this format there are 61 bits available | |
6588 | * for the nan payload. | |
6589 | * | |
3bbe6a60 JH |
6590 | * Note that the 32-bit x86 ABI cannot do signaling nans: the x87 |
6591 | * simply cannot preserve the bit. You can either use the 80-bit | |
6592 | * extended precision (long double, -Duselongdouble), or use x86-64. | |
6593 | * | |
453b60f1 JH |
6594 | * In all platforms, the payload bytes (and bits, some of them are |
6595 | * often in a partial byte) themselves can be either all zero (x86), | |
6596 | * all one (sparc or mips), or a mixture: in IEEE 754 128-bit double | |
6597 | * or in a double-double, the first half of the payload can follow the | |
6598 | * native double, while in the second half the payload can be all | |
6599 | * zeros. (Therefore the mask for payload bits is not necessarily | |
6600 | * identical to bit complement of the NaN.) Another way of putting | |
6601 | * this: the payload for the default NaN might not be zero. | |
6602 | * | |
6603 | * For the x86 80-bit long doubles, the trailing bytes (the 80 bits | |
6604 | * being 'packaged' in either 12 or 16 bytes) can be whatever random | |
6605 | * garbage. | |
6606 | * | |
6607 | * Furthermore, the semantics of the sign bit on NaNs are platform-specific. | |
6608 | * On normal floats, the sign bit being on means negative. But this may, | |
6609 | * or may not, be reverted on NaNs: in other words, the default NaN might | |
6610 | * have the sign bit on, and therefore look like negative if you look | |
6611 | * at it at the bit level. | |
6612 | * | |
6613 | * NaN payloads are not propagated even on copies, or in arithmetics. | |
6614 | * They *might* be, according to some rules, on your particular | |
6615 | * cpu/os/compiler/libraries, but no guarantees. | |
6616 | * | |
6617 | * To summarize, on most platforms, and for 64-bit doubles | |
6618 | * (using big-endian ordering here): | |
6619 | * | |
6620 | * [7FF8000000000000..7FFFFFFFFFFFFFFF] quiet | |
6621 | * [FFF8000000000000..FFFFFFFFFFFFFFFF] quiet | |
6622 | * [7FF0000000000001..7FF7FFFFFFFFFFFF] signaling | |
6623 | * [FFF0000000000001..FFF7FFFFFFFFFFFF] signaling | |
6624 | * | |
6625 | * The C99 nan() is supposed to generate *quiet* NaNs. | |
6626 | * | |
6627 | * Note the asymmetry: | |
6628 | * The 7FF0000000000000 is positive infinity, | |
6629 | * the FFF0000000000000 is negative infinity. | |
6630 | */ | |
6631 | ||
6632 | /* NVMANTBITS is the number of _real_ mantissa bits in an NV. | |
5a14060a JH |
6633 | * For the standard IEEE 754 fp this number is usually one less that |
6634 | * *DBL_MANT_DIG because of the implicit (aka hidden) bit, which isn't | |
6635 | * real. For the 80-bit extended precision formats (x86*), the number | |
6636 | * of mantissa bits... depends. For normal floats, it's 64. But for | |
6637 | * the inf/nan, it's different (zero for inf, 61 for nan). | |
6638 | * NVMANTBITS works for normal floats. */ | |
6639 | ||
6640 | /* We do not want to include the quiet/signaling bit. */ | |
6641 | #define NV_NAN_BITS (NVMANTBITS - 1) | |
5c255b3b | 6642 | |
f37aa828 JH |
6643 | #if defined(USE_LONG_DOUBLE) && NVSIZE > DOUBLESIZE |
6644 | # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN | |
6645 | # define NV_NAN_QS_BYTE_OFFSET 13 | |
6646 | # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN | |
6647 | # define NV_NAN_QS_BYTE_OFFSET 2 | |
6648 | # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN | |
6649 | # define NV_NAN_QS_BYTE_OFFSET 7 | |
6650 | # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN | |
6651 | # define NV_NAN_QS_BYTE_OFFSET 2 | |
1f02ab1d | 6652 | # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE |
f37aa828 | 6653 | # define NV_NAN_QS_BYTE_OFFSET 13 |
1f02ab1d | 6654 | # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE |
f37aa828 | 6655 | # define NV_NAN_QS_BYTE_OFFSET 1 |
1f02ab1d JH |
6656 | # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE |
6657 | # define NV_NAN_QS_BYTE_OFFSET 9 | |
6658 | # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE | |
6659 | # define NV_NAN_QS_BYTE_OFFSET 6 | |
f37aa828 JH |
6660 | # else |
6661 | # error "Unexpected long double format" | |
6662 | # endif | |
6663 | #else | |
6664 | # ifdef USE_QUADMATH | |
6665 | # ifdef NV_LITTLE_ENDIAN | |
6666 | # define NV_NAN_QS_BYTE_OFFSET 13 | |
6667 | # elif defined(NV_BIG_ENDIAN) | |
6668 | # define NV_NAN_QS_BYTE_OFFSET 2 | |
6669 | # else | |
6670 | # error "Unexpected quadmath format" | |
6671 | # endif | |
6672 | # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN | |
6673 | # define NV_NAN_QS_BYTE_OFFSET 2 | |
6674 | # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN | |
6675 | # define NV_NAN_QS_BYTE_OFFSET 1 | |
6676 | # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN | |
6677 | # define NV_NAN_QS_BYTE_OFFSET 6 | |
6678 | # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN | |
6679 | # define NV_NAN_QS_BYTE_OFFSET 1 | |
6680 | # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN | |
6681 | # define NV_NAN_QS_BYTE_OFFSET 13 | |
6682 | # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN | |
6683 | # define NV_NAN_QS_BYTE_OFFSET 2 | |
6684 | # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE | |
6685 | # define NV_NAN_QS_BYTE_OFFSET 2 /* bytes 4 5 6 7 0 1 2 3 (MSB 7) */ | |
6686 | # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE | |
6687 | # define NV_NAN_QS_BYTE_OFFSET 5 /* bytes 3 2 1 0 7 6 5 4 (MSB 7) */ | |
6688 | # else | |
a7157111 JH |
6689 | /* For example the VAX formats should never |
6690 | * get here because they do not have NaN. */ | |
f37aa828 JH |
6691 | # error "Unexpected double format" |
6692 | # endif | |
6693 | #endif | |
6694 | /* NV_NAN_QS_BYTE is the byte to test for the quiet/signaling */ | |
6695 | #define NV_NAN_QS_BYTE(nvp) (((U8*)(nvp))[NV_NAN_QS_BYTE_OFFSET]) | |
6696 | /* NV_NAN_QS_BIT is the bit to test in the NV_NAN_QS_BYTE_OFFSET | |
6697 | * for the quiet/signaling */ | |
6698 | #if defined(USE_LONG_DOUBLE) && \ | |
6699 | (LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN || \ | |
6700 | LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN) | |
6701 | # define NV_NAN_QS_BIT_SHIFT 6 /* 0x40 */ | |
6702 | #elif defined(USE_LONG_DOUBLE) && \ | |
1f02ab1d JH |
6703 | (LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE || \ |
6704 | LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE || \ | |
6705 | LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE || \ | |
6706 | LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE) | |
5a14060a | 6707 | # define NV_NAN_QS_BIT_SHIFT 3 /* 0x08, but not via NV_NAN_BITS */ |
f37aa828 | 6708 | #else |
5a14060a | 6709 | # define NV_NAN_QS_BIT_SHIFT ((NV_NAN_BITS) % 8) /* usually 3, or 0x08 */ |
f37aa828 JH |
6710 | #endif |
6711 | #define NV_NAN_QS_BIT (1 << (NV_NAN_QS_BIT_SHIFT)) | |
6712 | /* NV_NAN_QS_BIT_OFFSET is the bit offset from the beginning of a NV | |
6713 | * (bytes ordered big-endianly) for the quiet/signaling bit | |
6714 | * for the quiet/signaling */ | |
6715 | #define NV_NAN_QS_BIT_OFFSET \ | |
6716 | (8 * (NV_NAN_QS_BYTE_OFFSET) + (NV_NAN_QS_BIT_SHIFT)) | |
8122f9aa JH |
6717 | /* NV_NAN_QS_QUIET (always defined) is true if the NV_NAN_QS_QS_BIT being |
6718 | * on indicates quiet NaN. NV_NAN_QS_SIGNALING (also always defined) | |
6719 | * is true if the NV_NAN_QS_BIT being on indicates signaling NaN. */ | |
f37aa828 JH |
6720 | #define NV_NAN_QS_QUIET \ |
6721 | ((NV_NAN_QS_BYTE(PL_nan.u8) & NV_NAN_QS_BIT) == NV_NAN_QS_BIT) | |
6722 | #define NV_NAN_QS_SIGNALING (!(NV_NAN_QS_QUIET)) | |
6723 | #define NV_NAN_QS_TEST(nvp) (NV_NAN_QS_BYTE(nvp) & NV_NAN_QS_BIT) | |
6724 | /* NV_NAN_IS_QUIET() returns true if the NV behind nvp is a NaN, | |
6725 | * whether it is a quiet NaN, NV_NAN_IS_SIGNALING() if a signaling NaN. | |
6726 | * Note however that these do not check whether the nvp is a NaN. */ | |
6727 | #define NV_NAN_IS_QUIET(nvp) \ | |
6728 | (NV_NAN_QS_TEST(nvp) == (NV_NAN_QS_QUIET ? NV_NAN_QS_BIT : 0)) | |
6729 | #define NV_NAN_IS_SIGNALING(nvp) \ | |
6730 | (NV_NAN_QS_TEST(nvp) == (NV_NAN_QS_QUIET ? 0 : NV_NAN_QS_BIT)) | |
6731 | #define NV_NAN_SET_QUIET(nvp) \ | |
6732 | (NV_NAN_QS_QUIET ? \ | |
6733 | (NV_NAN_QS_BYTE(nvp) |= NV_NAN_QS_BIT) : \ | |
6734 | (NV_NAN_QS_BYTE(nvp) &= ~NV_NAN_QS_BIT)) | |
6735 | #define NV_NAN_SET_SIGNALING(nvp) \ | |
6736 | (NV_NAN_QS_QUIET ? \ | |
6737 | (NV_NAN_QS_BYTE(nvp) &= ~NV_NAN_QS_BIT) : \ | |
6738 | (NV_NAN_QS_BYTE(nvp) |= NV_NAN_QS_BIT)) | |
6739 | #define NV_NAN_QS_XOR(nvp) (NV_NAN_QS_BYTE(nvp) ^= NV_NAN_QS_BIT) | |
6740 | ||
d3137b5f JH |
6741 | /* NV_NAN_PAYLOAD_MASK: masking the nan payload bits. |
6742 | * | |
6743 | * NV_NAN_PAYLOAD_PERM: permuting the nan payload bytes. | |
6744 | * 0xFF means "don't go here".*/ | |
6745 | ||
6746 | /* Shorthands to avoid typoses. */ | |
1f02ab1d JH |
6747 | #define NV_NAN_PAYLOAD_MASK_SKIP_EIGHT \ |
6748 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 | |
6749 | #define NV_NAN_PAYLOAD_PERM_SKIP_EIGHT \ | |
6750 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | |
d3137b5f JH |
6751 | #define NV_NAN_PAYLOAD_PERM_0_TO_7 \ |
6752 | 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7 | |
6753 | #define NV_NAN_PAYLOAD_PERM_7_TO_0 \ | |
6754 | 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0x0 | |
6755 | #define NV_NAN_PAYLOAD_MASK_IEEE_754_128_LE \ | |
6756 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ | |
6757 | 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00 | |
6758 | #define NV_NAN_PAYLOAD_PERM_IEEE_754_128_LE \ | |
6759 | NV_NAN_PAYLOAD_PERM_0_TO_7, \ | |
6760 | 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xFF, 0xFF | |
6761 | #define NV_NAN_PAYLOAD_MASK_IEEE_754_128_BE \ | |
6762 | 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, \ | |
6763 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | |
6764 | #define NV_NAN_PAYLOAD_PERM_IEEE_754_128_BE \ | |
6765 | 0xFF, 0xFF, 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, \ | |
6766 | NV_NAN_PAYLOAD_PERM_7_TO_0 | |
6767 | #define NV_NAN_PAYLOAD_MASK_IEEE_754_64_LE \ | |
6768 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00 | |
6769 | #define NV_NAN_PAYLOAD_PERM_IEEE_754_64_LE \ | |
6770 | 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0xFF | |
6771 | #define NV_NAN_PAYLOAD_MASK_IEEE_754_64_BE \ | |
6772 | 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | |
6773 | #define NV_NAN_PAYLOAD_PERM_IEEE_754_64_BE \ | |
6774 | 0xFF, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0x0 | |
6775 | ||
6776 | #if defined(USE_LONG_DOUBLE) && NVSIZE > DOUBLESIZE | |
6777 | # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN | |
6778 | # define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_LE | |
6779 | # define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_LE | |
6780 | # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN | |
6781 | # define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_BE | |
6782 | # define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_BE | |
6783 | # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN | |
a7ab4d96 JH |
6784 | # if LONG_DOUBLESIZE == 10 |
6785 | # define NV_NAN_PAYLOAD_MASK \ | |
6786 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, \ | |
6787 | 0x00, 0x00 | |
6788 | # define NV_NAN_PAYLOAD_PERM \ | |
6789 | NV_NAN_PAYLOAD_PERM_0_TO_7, 0xFF, 0xFF | |
6790 | # elif LONG_DOUBLESIZE == 12 | |
d3137b5f JH |
6791 | # define NV_NAN_PAYLOAD_MASK \ |
6792 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, \ | |
6793 | 0x00, 0x00, 0x00, 0x00 | |
6794 | # define NV_NAN_PAYLOAD_PERM \ | |
6795 | NV_NAN_PAYLOAD_PERM_0_TO_7, 0xFF, 0xFF, 0xFF, 0xFF | |
6796 | # elif LONG_DOUBLESIZE == 16 | |
6797 | # define NV_NAN_PAYLOAD_MASK \ | |
6798 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, \ | |
6799 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | |
6800 | # define NV_NAN_PAYLOAD_PERM \ | |
6801 | NV_NAN_PAYLOAD_PERM_0_TO_7, \ | |
6802 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF | |
6803 | # else | |
6804 | # error "Unexpected x86 80-bit little-endian long double format" | |
6805 | # endif | |
6806 | # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN | |
a7ab4d96 JH |
6807 | # if LONG_DOUBLESIZE == 10 |
6808 | # define NV_NAN_PAYLOAD_MASK \ | |
6809 | 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, \ | |
6810 | 0xff, 0xff | |
6811 | # define NV_NAN_PAYLOAD_PERM \ | |
6812 | NV_NAN_PAYLOAD_PERM_7_TO_0, 0xFF, 0xFF | |
6813 | # elif LONG_DOUBLESIZE == 12 | |
d3137b5f JH |
6814 | # define NV_NAN_PAYLOAD_MASK \ |
6815 | 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, \ | |
6816 | 0xff, 0xff, 0x00, 0x00 | |
6817 | # define NV_NAN_PAYLOAD_PERM \ | |
6818 | NV_NAN_PAYLOAD_PERM_7_TO_0, 0xFF, 0xFF, 0xFF, 0xFF | |
6819 | # elif LONG_DOUBLESIZE == 16 | |
6820 | # define NV_NAN_PAYLOAD_MASK \ | |
6821 | 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, \ | |
6822 | 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | |
6823 | # define NV_NAN_PAYLOAD_PERM \ | |
6824 | NV_NAN_PAYLOAD_PERM_7_TO_0, \ | |
6825 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF | |
6826 | # else | |
a7ab4d96 | 6827 | # error "Unexpected x86 80-bit big-endian long double format" |
d3137b5f | 6828 | # endif |
1f02ab1d JH |
6829 | # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE |
6830 | /* For double-double we assume only the first double (in LE or BE terms) | |
6831 | * is used for NaN. */ | |
d3137b5f | 6832 | # define NV_NAN_PAYLOAD_MASK \ |
1f02ab1d | 6833 | NV_NAN_PAYLOAD_MASK_SKIP_EIGHT, NV_NAN_PAYLOAD_MASK_IEEE_754_64_LE |
d3137b5f | 6834 | # define NV_NAN_PAYLOAD_PERM \ |
1f02ab1d JH |
6835 | NV_NAN_PAYLOAD_PERM_SKIP_EIGHT, NV_NAN_PAYLOAD_PERM_IEEE_754_64_LE |
6836 | # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE | |
d3137b5f JH |
6837 | # define NV_NAN_PAYLOAD_MASK \ |
6838 | NV_NAN_PAYLOAD_MASK_IEEE_754_64_BE | |
6839 | # define NV_NAN_PAYLOAD_PERM \ | |
6840 | NV_NAN_PAYLOAD_PERM_IEEE_754_64_BE | |
1f02ab1d JH |
6841 | # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE |
6842 | # define NV_NAN_PAYLOAD_MASK \ | |
6843 | NV_NAN_PAYLOAD_MASK_IEEE_754_64_LE | |
6844 | # define NV_NAN_PAYLOAD_PERM \ | |
6845 | NV_NAN_PAYLOAD_PERM_IEEE_754_64_LE | |
6846 | # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE | |
6847 | # define NV_NAN_PAYLOAD_MASK \ | |
6848 | NV_NAN_PAYLOAD_MASK_SKIP_EIGHT, NV_NAN_PAYLOAD_MASK_IEEE_754_64_BE | |
6849 | # define NV_NAN_PAYLOAD_PERM \ | |
6850 | NV_NAN_PAYLOAD_PERM_SKIP_EIGHT, NV_NAN_PAYLOAD_PERM_IEEE_754_64_BE | |
d3137b5f JH |
6851 | # else |
6852 | # error "Unexpected long double format" | |
6853 | # endif | |
6854 | #else | |
6855 | # ifdef USE_QUADMATH /* quadmath is not long double */ | |
6856 | # ifdef NV_LITTLE_ENDIAN | |
6857 | # define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_LE | |
6858 | # define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_LE | |
6859 | # elif defined(NV_BIG_ENDIAN) | |
6860 | # define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_BE | |
6861 | # define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_BE | |
6862 | # else | |
6863 | # error "Unexpected quadmath format" | |
6864 | # endif | |
6865 | # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN | |
6866 | # define NV_NAN_PAYLOAD_MASK 0xff, 0xff, 0x07, 0x00 | |
6867 | # define NV_NAN_PAYLOAD_PERM 0x0, 0x1, 0x2, 0xFF | |
6868 | # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN | |
6869 | # define NV_NAN_PAYLOAD_MASK 0x00, 0x07, 0xff, 0xff | |
6870 | # define NV_NAN_PAYLOAD_PERM 0xFF, 0x2, 0x1, 0x0 | |
6871 | # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN | |
6872 | # define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_64_LE | |
6873 | # define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_64_LE | |
6874 | # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN | |
6875 | # define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_64_BE | |
6876 | # define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_64_BE | |
6877 | # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN | |
6878 | # define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_LE | |
6879 | # define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_LE | |
6880 | # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN | |
6881 | # define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_BE | |
6882 | # define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_BE | |
6883 | # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE | |
6884 | # define NV_NAN_PAYLOAD_MASK 0xff, 0xff, 0x07, 0x00, 0xff, 0xff, 0xff, 0xff | |
6885 | # define NV_NAN_PAYLOAD_PERM 0x4, 0x5, 0x6, 0xFF, 0x0, 0x1, 0x2, 0x3 | |
6886 | # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE | |
6887 | # define NV_NAN_PAYLOAD_MASK 0xff, 0xff, 0xff, 0xff, 0x00, 0x07, 0xff, 0xff | |
6888 | # define NV_NAN_PAYLOAD_PERM 0x3, 0x2, 0x1, 0x0, 0xFF, 0x6, 0x5, 0x4 | |
6889 | # else | |
6890 | # error "Unexpected double format" | |
6891 | # endif | |
6892 | #endif | |
a7157111 JH |
6893 | |
6894 | #endif /* DOUBLE_HAS_NAN */ | |
6895 | ||
21553840 | 6896 | |
10edeb5d JH |
6897 | /* |
6898 | ||
6899 | (KEEP THIS LAST IN perl.h!) | |
6900 | ||
6901 | Mention | |
d460ef45 | 6902 | |
43999f95 | 6903 | NV_PRESERVES_UV |
fe749a9f | 6904 | |
fe749a9f JH |
6905 | HAS_MKSTEMP |
6906 | HAS_MKSTEMPS | |
6907 | HAS_MKDTEMP | |
6908 | ||
49dabb45 JH |
6909 | HAS_GETCWD |
6910 | ||
d59b5429 | 6911 | HAS_MMAP |
fe749a9f JH |
6912 | HAS_MPROTECT |
6913 | HAS_MSYNC | |
1e8c3fde | 6914 | HAS_MADVISE |
fe749a9f JH |
6915 | HAS_MUNMAP |
6916 | I_SYSMMAN | |
6917 | Mmap_t | |
6918 | ||
6b4667fc A |
6919 | NVef |
6920 | NVff | |
6921 | NVgf | |
6922 | ||
4e0554ec | 6923 | HAS_UALARM |
2d736872 | 6924 | HAS_USLEEP |
4e0554ec JH |
6925 | |
6926 | HAS_SETITIMER | |
6927 | HAS_GETITIMER | |
6928 | ||
6929 | HAS_SENDMSG | |
6930 | HAS_RECVMSG | |
6931 | HAS_READV | |
6932 | HAS_WRITEV | |
6933 | I_SYSUIO | |
6934 | HAS_STRUCT_MSGHDR | |
6935 | HAS_STRUCT_CMSGHDR | |
6936 | ||
2765b840 | 6937 | HAS_NL_LANGINFO |
0a7020c9 | 6938 | |
ae0e3d3b | 6939 | HAS_DIRFD |
2765b840 | 6940 | |
10edeb5d | 6941 | so that Configure picks them up. |
ab3bbdeb | 6942 | |
10edeb5d | 6943 | (KEEP THIS LAST IN perl.h!) |
3df15adc | 6944 | |
10edeb5d | 6945 | */ |
3df15adc | 6946 | |
85e6fe83 | 6947 | #endif /* Include guard */ |
e9a8c099 MHM |
6948 | |
6949 | /* | |
14d04a33 | 6950 | * ex: set ts=8 sts=4 sw=4 et: |
e9a8c099 | 6951 | */ |