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