This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Change 30034 wasn't enough to silence the warnings - also need to
[perl5.git] / perl.h
CommitLineData
a0d0e21e 1/* perl.h
a687059c 2 *
4bb101f2 3 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999,
7272f7c1 4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 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
95036ac7
JH
25#if defined(DGUX)
26#include <sys/fcntl.h>
27#endif
28
47a51902
SB
29#ifdef VOIDUSED
30# undef VOIDUSED
31#endif
0cb96387 32#define VOIDUSED 1
47a51902 33
d460ef45 34#ifdef PERL_MICRO
12ae5dfc
JH
35# include "uconfig.h"
36#else
b0f06652
VK
37# ifndef USE_CROSS_COMPILE
38# include "config.h"
39# else
40# include "xconfig.h"
41# endif
12ae5dfc 42#endif
0cb96387 43
2c2d71f5
JH
44/* See L<perlguts/"The Perl API"> for detailed notes on
45 * PERL_IMPLICIT_CONTEXT and PERL_IMPLICIT_SYS */
46
ac6bedea
JH
47/* Note that from here --> to <-- the same logic is
48 * repeated in makedef.pl, so be certain to update
49 * both places when editing. */
50
894ccb8c
JH
51#ifdef PERL_IMPLICIT_SYS
52/* PERL_IMPLICIT_SYS implies PerlMemShared != PerlMem
53 so use slab allocator to avoid lots of MUTEX overhead
54 */
55# ifndef PL_OP_SLAB_ALLOC
56# define PL_OP_SLAB_ALLOC
57# endif
ba979b31
NIS
58#endif
59
6f4183fe 60#ifdef USE_ITHREADS
acfe0abc 61# if !defined(MULTIPLICITY)
6f4183fe
GS
62# define MULTIPLICITY
63# endif
64#endif
65
27da23d5
JH
66#ifdef PERL_GLOBAL_STRUCT_PRIVATE
67# ifndef PERL_GLOBAL_STRUCT
68# define PERL_GLOBAL_STRUCT
69# endif
70#endif
97aff369 71
27da23d5
JH
72#ifdef PERL_GLOBAL_STRUCT
73# ifndef MULTIPLICITY
74# define MULTIPLICITY
75# endif
76#endif
77
97aff369
JH
78#ifdef MULTIPLICITY
79# ifndef PERL_IMPLICIT_CONTEXT
80# define PERL_IMPLICIT_CONTEXT
81# endif
82#endif
83
026fd48b
GH
84/* undef WIN32 when building on Cygwin (for libwin32) - gph */
85#ifdef __CYGWIN__
86# undef WIN32
87# undef _WIN32
88#endif
89
27da23d5
JH
90#if defined(__SYMBIAN32__) || (defined(__VC32__) && defined(WINS))
91# ifndef SYMBIAN
92# define SYMBIAN
93# endif
94#endif
95
a0fd4948 96#ifdef __SYMBIAN32__
27da23d5
JH
97# include "symbian/symbian_proto.h"
98#endif
99
100/* Any stack-challenged places. The limit varies (and often
101 * is configurable), but using more than a kilobyte of stack
102 * is usually dubious in these systems. */
a0fd4948 103#if defined(EPOC) || defined(__SYMBIAN32__)
27da23d5
JH
104/* EPOC/Symbian: need to work around the SDK features. *
105 * On WINS: MS VC5 generates calls to _chkstk, *
106 * if a "large" stack frame is allocated. *
107 * gcc on MARM does not generate calls like these. */
108# define USE_HEAP_INSTEAD_OF_STACK
109#endif
110
111#/* Use the reentrant APIs like localtime_r and getpwent_r */
10bc17b6 112/* Win32 has naturally threadsafe libraries, no need to use any _r variants. */
6239f2da 113#if defined(USE_ITHREADS) && !defined(USE_REENTRANT_API) && !defined(NETWARE) && !defined(WIN32) && !defined(PERL_DARWIN)
10bc17b6
JH
114# define USE_REENTRANT_API
115#endif
116
ac6bedea
JH
117/* <--- here ends the logic shared by perl.h and makedef.pl */
118
af28e889 119/*
6239f2da
JH
120 * PERL_DARWIN for MacOSX (__APPLE__ exists but is not officially sanctioned)
121 * (The -DPERL_DARWIN comes from the hints/darwin.sh.)
af28e889
JH
122 * __bsdi__ for BSD/OS
123 */
6239f2da 124#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(PERL_DARWIN) || defined(__bsdi__) || defined(BSD41) || defined(BSD42) || defined(BSD43) || defined(BSD44)
af28e889
JH
125# ifndef BSDish
126# define BSDish
127# endif
128#endif
129
27da23d5
JH
130#ifdef PERL_GLOBAL_STRUCT
131# ifndef PERL_GET_VARS
132# ifdef PERL_GLOBAL_STRUCT_PRIVATE
133 extern struct perl_vars* Perl_GetVarsPrivate();
134# define PERL_GET_VARS() Perl_GetVarsPrivate() /* see miniperlmain.c */
135# ifndef PERLIO_FUNCS_CONST
136# define PERLIO_FUNCS_CONST /* Can't have these lying around. */
137# endif
138# else
139# define PERL_GET_VARS() PL_VarsPtr
140# endif
141# endif
142#endif
143
7a89be66 144#define pVAR register struct perl_vars* my_vars PERL_UNUSED_DECL
27da23d5
JH
145
146#ifdef PERL_GLOBAL_STRUCT
147# define dVAR pVAR = (struct perl_vars*)PERL_GET_VARS()
148#else
149# define dVAR dNOOP
150#endif
151
c5be433b 152#ifdef PERL_IMPLICIT_CONTEXT
3db8f154
MB
153# ifndef MULTIPLICITY
154# define MULTIPLICITY
c5be433b 155# endif
e8dda941 156# define tTHX PerlInterpreter*
5ba4cab2 157# define pTHX register tTHX my_perl PERL_UNUSED_DECL
3db8f154 158# define aTHX my_perl
27da23d5 159# ifdef PERL_GLOBAL_STRUCT
e8dda941 160# define dTHXa(a) dVAR; pTHX = (tTHX)a
27da23d5 161# else
e8dda941 162# define dTHXa(a) pTHX = (tTHX)a
27da23d5
JH
163# endif
164# ifdef PERL_GLOBAL_STRUCT
165# define dTHX dVAR; pTHX = PERL_GET_THX
166# else
167# define dTHX pTHX = PERL_GET_THX
168# endif
c5be433b 169# define pTHX_ pTHX,
c5be433b 170# define aTHX_ aTHX,
4373e329 171# define pTHX_1 2
894356b3
GS
172# define pTHX_2 3
173# define pTHX_3 4
174# define pTHX_4 5
4373e329
AL
175# define pTHX_5 6
176# define pTHX_6 7
a3b680e6
AL
177# define pTHX_7 8
178# define pTHX_8 9
179# define pTHX_9 10
e8dda941
JD
180# if defined(DEBUGGING) && !defined(PERL_TRACK_MEMPOOL)
181# define PERL_TRACK_MEMPOOL
182# endif
183#else
184# undef PERL_TRACK_MEMPOOL
c5be433b
GS
185#endif
186
76e3520e
GS
187#define STATIC static
188#define CPERLscope(x) x
565764a8 189#define CPERLarg void
76e3520e 190#define CPERLarg_
e3b8966e 191#define _CPERLarg
1d583055
GS
192#define PERL_OBJECT_THIS
193#define _PERL_OBJECT_THIS
194#define PERL_OBJECT_THIS_
312caa8e 195#define CALL_FPTR(fptr) (*fptr)
76e3520e 196
312caa8e 197#define CALLRUNOPS CALL_FPTR(PL_runops)
f9f4320a 198
f8149455 199#define CALLREGCOMP(exp, xend, pm) Perl_pregcomp(aTHX_ (exp),(xend),(pm))
f9f4320a 200
f2f78491
YO
201#define CALLREGCOMP_ENG(prog, exp, xend, pm) \
202 CALL_FPTR(((prog)->comp))(aTHX_ exp, xend, pm)
f9f4320a 203#define CALLREGEXEC(prog,stringarg,strend,strbeg,minend,screamer,data,flags) \
f2f78491 204 CALL_FPTR((prog)->engine->exec)(aTHX_ (prog),(stringarg),(strend), \
f9f4320a
YO
205 (strbeg),(minend),(screamer),(data),(flags))
206#define CALLREG_INTUIT_START(prog,sv,strpos,strend,flags,data) \
f2f78491 207 CALL_FPTR((prog)->engine->intuit)(aTHX_ (prog), (sv), (strpos), \
f9f4320a
YO
208 (strend),(flags),(data))
209#define CALLREG_INTUIT_STRING(prog) \
f2f78491 210 CALL_FPTR((prog)->engine->checkstr)(aTHX_ (prog))
f8149455 211
de8c5301 212#define CALLREG_AS_STR(mg,lp,flags,haseval) \
f8149455 213 Perl_reg_stringify(aTHX_ (mg), (lp), (flags), (haseval))
de8c5301 214#define CALLREG_STRINGIFY(mg,lp,flags) CALLREG_AS_STR(mg,lp,flags,0)
f8149455
YO
215
216#define CALLREGFREE(prog) \
217 Perl_pregfree(aTHX_ (prog))
218
219#define CALLREGFREE_PVT(prog) \
220 if(prog) CALL_FPTR((prog)->engine->free)(aTHX_ (prog))
221
f9f4320a
YO
222#if defined(USE_ITHREADS)
223#define CALLREGDUPE(prog,param) \
f8149455
YO
224 Perl_re_dup(aTHX_ (prog),(param))
225
226#define CALLREGDUPE_PVT(prog,param) \
f2f78491 227 (prog ? CALL_FPTR((prog)->engine->dupe)(aTHX_ (prog),(param)) \
f9f4320a
YO
228 : (REGEXP *)NULL)
229#endif
14dd3ad8 230
a20207d7
YO
231
232/* chars and strings used as regex pattern modifiers
233 * Singlular is a 'c'har, plural is a "string"
234 */
235#define EXEC_PAT_MOD 'e'
236#define KEEPCOPY_PAT_MOD 'k'
237#define ONCE_PAT_MOD 'o'
238#define GLOBAL_PAT_MOD 'g'
239#define CONTINUE_PAT_MOD 'c'
240#define MULTILINE_PAT_MOD 'm'
241#define SINGLE_PAT_MOD 's'
242#define IGNORE_PAT_MOD 'i'
243#define XTENDED_PAT_MOD 'x'
244
245#define ONCE_PAT_MODS "o"
246#define KEEPCOPY_PAT_MODS "k"
247#define EXEC_PAT_MODS "e"
248#define LOOP_PAT_MODS "gc"
249
250#define STD_PAT_MODS "msix"
251
252#define EXT_PAT_MODS ONCE_PAT_MODS KEEPCOPY_PAT_MODS
253#define QR_PAT_MODS STD_PAT_MODS EXT_PAT_MODS
254#define M_PAT_MODS QR_PAT_MODS LOOP_PAT_MODS
255#define S_PAT_MODS M_PAT_MODS EXEC_PAT_MODS
256
257
5ba4cab2
SH
258/*
259 * Because of backward compatibility reasons the PERL_UNUSED_DECL
260 * cannot be changed from postfix to PERL_UNUSED_DECL(x). Sigh.
261 *
262 * Note that there are C compilers such as MetroWerks CodeWarrior
1266ad8c 263 * which do not have an "inlined" way (like the gcc __attribute__) of
5ba4cab2
SH
264 * marking unused variables (they need e.g. a #pragma) and therefore
265 * cpp macros like PERL_UNUSED_DECL cannot work for this purpose, even
266 * if it were PERL_UNUSED_DECL(x), which it cannot be (see above).
267 *
268 */
1266ad8c 269
9969cdde 270#if defined(__SYMBIAN32__) && defined(__GNUC__)
5b2bd0a5 271# ifdef __cplusplus
5ba4cab2 272# define PERL_UNUSED_DECL
5b2bd0a5 273# else
5ba4cab2 274# define PERL_UNUSED_DECL __attribute__((unused))
5b2bd0a5
AMS
275# endif
276#endif
44dbb695 277
5b2bd0a5 278#ifndef PERL_UNUSED_DECL
34659ad4 279# if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
5ba4cab2 280# define PERL_UNUSED_DECL __attribute__unused__
b79c357a 281# else
5ba4cab2 282# define PERL_UNUSED_DECL
b79c357a 283# endif
5b2bd0a5
AMS
284#endif
285
349b520e
DM
286/* gcc -Wall:
287 * for silencing unused variables that are actually used most of the time,
a0288114 288 * but we cannot quite get rid of, such as "ax" in PPCODE+noargs xsubs
349b520e 289 */
53c1dcc0 290#ifndef PERL_UNUSED_ARG
c99ffe5e 291# if defined(lint) && defined(S_SPLINT_S) /* www.splint.org */
ad73156c 292# include <note.h>
53c1dcc0 293# define PERL_UNUSED_ARG(x) NOTE(ARGUNUSED(x))
ad73156c 294# else
53c1dcc0 295# define PERL_UNUSED_ARG(x) ((void)x)
ad73156c
AL
296# endif
297#endif
53c1dcc0
AL
298#ifndef PERL_UNUSED_VAR
299# define PERL_UNUSED_VAR(x) ((void)x)
300#endif
ad73156c 301
96a5add6
AL
302#ifdef USE_ITHREADS
303# define PERL_UNUSED_CONTEXT PERL_UNUSED_ARG(my_perl)
304#else
305# define PERL_UNUSED_CONTEXT
306#endif
307
6f207bd3 308#define NOOP /*EMPTY*/(void)0
6b484a99
JH
309#if !defined(HASATTRIBUTE_UNUSED) && defined(__cplusplus)
310#define dNOOP /*EMPTY*/(void)0 /* Older g++ has no __attribute((unused))__ */
311#else
6f207bd3 312#define dNOOP extern int /*@unused@*/ Perl___notused PERL_UNUSED_DECL
6b484a99 313#endif
71be2cbc 314
0cb96387 315#ifndef pTHX
e8dda941
JD
316/* Don't bother defining tTHX and sTHX; using them outside
317 * code guarded by PERL_IMPLICIT_CONTEXT is an error.
318 */
0cb96387
GS
319# define pTHX void
320# define pTHX_
0cb96387
GS
321# define aTHX
322# define aTHX_
0cb96387
GS
323# define dTHXa(a) dNOOP
324# define dTHX dNOOP
894356b3
GS
325# define pTHX_1 1
326# define pTHX_2 2
327# define pTHX_3 3
328# define pTHX_4 4
3d42dc86
RGS
329# define pTHX_5 5
330# define pTHX_6 6
a3b680e6
AL
331# define pTHX_7 7
332# define pTHX_8 8
333# define pTHX_9 9
0cb96387
GS
334#endif
335
27da23d5
JH
336#ifndef dVAR
337# define dVAR dNOOP
338#endif
339
b4f7f263
GS
340/* these are only defined for compatibility; should not be used internally */
341#if !defined(pTHXo) && !defined(PERL_CORE)
0cb96387
GS
342# define pTHXo pTHX
343# define pTHXo_ pTHX_
0cb96387
GS
344# define aTHXo aTHX
345# define aTHXo_ aTHX_
c5be433b 346# define dTHXo dTHX
71d280e3 347# define dTHXoa(x) dTHXa(x)
0cb96387
GS
348#endif
349
350#ifndef pTHXx
351# define pTHXx register PerlInterpreter *my_perl
352# define pTHXx_ pTHXx,
0cb96387
GS
353# define aTHXx my_perl
354# define aTHXx_ aTHXx,
c5be433b 355# define dTHXx dTHX
22c35a8c 356#endif
71be2cbc 357
1de7c2ac
GS
358/* Under PERL_IMPLICIT_SYS (used in Windows for fork emulation)
359 * PerlIO_foo() expands to PL_StdIO->pFOO(PL_StdIO, ...).
360 * dTHXs is therefore needed for all functions using PerlIO_foo(). */
361#ifdef PERL_IMPLICIT_SYS
27da23d5
JH
362# ifdef PERL_GLOBAL_STRUCT_PRIVATE
363# define dTHXs dVAR; dTHX
364# else
365# define dTHXs dTHX
366# endif
1de7c2ac 367#else
27da23d5
JH
368# ifdef PERL_GLOBAL_STRUCT_PRIVATE
369# define dTHXs dVAR
370# else
371# define dTHXs dNOOP
372# endif
1de7c2ac
GS
373#endif
374
326b05e3
GS
375#undef START_EXTERN_C
376#undef END_EXTERN_C
377#undef EXTERN_C
32f822de
GS
378#ifdef __cplusplus
379# define START_EXTERN_C extern "C" {
380# define END_EXTERN_C }
381# define EXTERN_C extern "C"
382#else
d460ef45
NIS
383# define START_EXTERN_C
384# define END_EXTERN_C
73c4f7a1 385# define EXTERN_C extern
32f822de
GS
386#endif
387
27da23d5
JH
388/* Some platforms require marking function declarations
389 * for them to be exportable. Used in perlio.h, proto.h
390 * is handled either by the makedef.pl or by defining the
391 * PERL_CALLCONV to be something special. See also the
392 * definition of XS() in XSUB.h. */
393#ifndef PERL_EXPORT_C
a0c21aa1
JH
394# ifdef __cplusplus
395# define PERL_EXPORT_C extern "C"
396# else
397# define PERL_EXPORT_C extern
398# endif
27da23d5
JH
399#endif
400#ifndef PERL_XS_EXPORT_C
a0c21aa1
JH
401# ifdef __cplusplus
402# define PERL_XS_EXPORT_C extern "C"
403# else
404# define PERL_XS_EXPORT_C
405# endif
27da23d5
JH
406#endif
407
462e5cf6
MB
408#ifdef OP_IN_REGISTER
409# ifdef __GNUC__
410# define stringify_immed(s) #s
411# define stringify(s) stringify_immed(s)
d1ca3daa 412register struct op *Perl_op asm(stringify(OP_IN_REGISTER));
462e5cf6
MB
413# endif
414#endif
415
e5afc1ae 416/* gcc (-ansi) -pedantic doesn't allow gcc statement expressions,
b1e55cab
JH
417 * g++ allows them but seems to have problems with them
418 * (insane errors ensue). */
419#if defined(PERL_GCC_PEDANTIC) || (defined(__GNUC__) && defined(__cplusplus))
5b692037 420# ifndef PERL_GCC_BRACE_GROUPS_FORBIDDEN
22469a62
RGS
421# define PERL_GCC_BRACE_GROUPS_FORBIDDEN
422# endif
5dc8bdac
JH
423#endif
424
5b692037
JH
425#if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) && !defined(__cplusplus)
426# ifndef PERL_USE_GCC_BRACE_GROUPS
427# define PERL_USE_GCC_BRACE_GROUPS
428# endif
429#endif
430
728e2803
PP
431/*
432 * STMT_START { statements; } STMT_END;
433 * can be used as a single statement, as in
434 * if (x) STMT_START { ... } STMT_END; else ...
435 *
436 * Trying to select a version that gives no warnings...
437 */
438#if !(defined(STMT_START) && defined(STMT_END))
5b692037 439# ifdef PERL_USE_GCC_BRACE_GROUPS
a0288114 440# define STMT_START (void)( /* gcc supports "({ STATEMENTS; })" */
728e2803
PP
441# define STMT_END )
442# else
443 /* Now which other defined()s do we need here ??? */
93189314 444# if (VOIDFLAGS) && (defined(sun) || defined(__sun__)) && !defined(__GNUC__)
728e2803
PP
445# define STMT_START if (1)
446# define STMT_END else (void)0
447# else
448# define STMT_START do
449# define STMT_END while (0)
450# endif
451# endif
452#endif
453
0cb96387 454#define WITH_THX(s) STMT_START { dTHX; s; } STMT_END
411caa50 455#define WITH_THR(s) WITH_THX(s)
ea0efc06 456
d6f9c181
JH
457#ifndef BYTEORDER /* Should never happen -- byteorder is in config.h */
458# define BYTEORDER 0x1234
79072805
LW
459#endif
460
461/* Overall memory policy? */
462#ifndef CONSERVATIVE
463# define LIBERAL 1
464#endif
465
8ada0baa
JH
466#if 'A' == 65 && 'I' == 73 && 'J' == 74 && 'Z' == 90
467#define ASCIIish
468#else
469#undef ASCIIish
470#endif
471
79072805
LW
472/*
473 * The following contortions are brought to you on behalf of all the
474 * standards, semi-standards, de facto standards, not-so-de-facto standards
475 * of the world, as well as all the other botches anyone ever thought of.
476 * The basic theory is that if we work hard enough here, the rest of the
477 * code can be a lot prettier. Well, so much for theory. Sorry, Henry...
478 */
ac58e20f 479
ee0007ab 480/* define this once if either system, instead of cluttering up the src */
2986a63f 481#if defined(MSDOS) || defined(atarist) || defined(WIN32) || defined(NETWARE)
ee0007ab
LW
482#define DOSISH 1
483#endif
484
fb38d079 485#if defined(__STDC__) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus) || defined(EPOC) || defined(NETWARE) || defined(__SYMBIAN32__)
352d5a3a
LW
486# define STANDARD_C 1
487#endif
488
9969cdde 489#if defined(__cplusplus) || defined(WIN32) || defined(__sgi) || defined(__EMX__) || defined(__DGUX) || defined(EPOC) || defined(__QNX__) || defined(NETWARE) || defined(PERL_MICRO)
68dc0745
PP
490# define DONT_DECLARE_STD 1
491#endif
492
352d5a3a 493#if defined(HASVOLATILE) || defined(STANDARD_C)
79072805 494# ifdef __cplusplus
cb69f87a 495# define VOL /* to temporarily suppress warnings */
79072805
LW
496# else
497# define VOL volatile
498# endif
663a0e37 499#else
79072805 500# define VOL
663a0e37
LW
501#endif
502
3280af22
NIS
503#define TAINT (PL_tainted = TRUE)
504#define TAINT_NOT (PL_tainted = FALSE)
505#define TAINT_IF(c) if (c) { PL_tainted = TRUE; }
506#define TAINT_ENV() if (PL_tainting) { taint_env(); }
bd61b366 507#define TAINT_PROPER(s) if (PL_tainting) { taint_proper(NULL, s); }
a687059c 508
d460ef45 509/* XXX All process group stuff is handled in pp_sys.c. Should these
a6e633de
PP
510 defines move there? If so, I could simplify this a lot. --AD 9/96.
511*/
512/* Process group stuff changed from traditional BSD to POSIX.
513 perlfunc.pod documents the traditional BSD-style syntax, so we'll
514 try to preserve that, if possible.
515*/
516#ifdef HAS_SETPGID
517# define BSD_SETPGRP(pid, pgrp) setpgid((pid), (pgrp))
c07a80fd 518#else
a6e633de
PP
519# if defined(HAS_SETPGRP) && defined(USE_BSD_SETPGRP)
520# define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp))
521# else
522# ifdef HAS_SETPGRP2 /* DG/UX */
523# define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp))
524# endif
525# endif
526#endif
527#if defined(BSD_SETPGRP) && !defined(HAS_SETPGRP)
528# define HAS_SETPGRP /* Well, effectively it does . . . */
529#endif
530
531/* getpgid isn't POSIX, but at least Solaris and Linux have it, and it makes
532 our life easier :-) so we'll try it.
533*/
534#ifdef HAS_GETPGID
535# define BSD_GETPGRP(pid) getpgid((pid))
536#else
537# if defined(HAS_GETPGRP) && defined(USE_BSD_GETPGRP)
538# define BSD_GETPGRP(pid) getpgrp((pid))
539# else
540# ifdef HAS_GETPGRP2 /* DG/UX */
541# define BSD_GETPGRP(pid) getpgrp2((pid))
542# endif
543# endif
544#endif
545#if defined(BSD_GETPGRP) && !defined(HAS_GETPGRP)
546# define HAS_GETPGRP /* Well, effectively it does . . . */
547#endif
548
d460ef45 549/* These are not exact synonyms, since setpgrp() and getpgrp() may
a6e633de
PP
550 have different behaviors, but perl.h used to define USE_BSDPGRP
551 (prior to 5.003_05) so some extension might depend on it.
552*/
553#if defined(USE_BSD_SETPGRP) || defined(USE_BSD_GETPGRP)
554# ifndef USE_BSDPGRP
555# define USE_BSDPGRP
556# endif
663a0e37
LW
557#endif
558
8ac5a1fe
MH
559/* HP-UX 10.X CMA (Common Multithreaded Architecure) insists that
560 pthread.h must be included before all other header files.
561*/
3db8f154 562#if defined(USE_ITHREADS) && defined(PTHREAD_H_FIRST) && defined(I_PTHREAD)
8ac5a1fe
MH
563# include <pthread.h>
564#endif
565
760ac839
LW
566#ifndef _TYPES_ /* If types.h defines this it's easy. */
567# ifndef major /* Does everyone's types.h define this? */
568# include <sys/types.h>
c07a80fd 569# endif
663a0e37
LW
570#endif
571
760ac839
LW
572#ifdef __cplusplus
573# ifndef I_STDARG
574# define I_STDARG 1
575# endif
576#endif
577
578#ifdef I_STDARG
579# include <stdarg.h>
580#else
581# ifdef I_VARARGS
582# include <varargs.h>
583# endif
584#endif
585
4633a7c4 586#ifdef USE_NEXT_CTYPE
0c30d9ec 587
092bebab
JH
588#if NX_CURRENT_COMPILER_RELEASE >= 500
589# include <bsd/ctypes.h>
590#else
591# if NX_CURRENT_COMPILER_RELEASE >= 400
592# include <objc/NXCType.h>
593# else /* NX_CURRENT_COMPILER_RELEASE < 400 */
594# include <appkit/NXCType.h>
595# endif /* NX_CURRENT_COMPILER_RELEASE >= 400 */
596#endif /* NX_CURRENT_COMPILER_RELEASE >= 500 */
0c30d9ec
PP
597
598#else /* !USE_NEXT_CTYPE */
fe14fcc3 599#include <ctype.h>
0c30d9ec 600#endif /* USE_NEXT_CTYPE */
a0d0e21e
LW
601
602#ifdef METHOD /* Defined by OSF/1 v3.0 by ctype.h */
603#undef METHOD
a0d0e21e
LW
604#endif
605
12ae5dfc
JH
606#ifdef PERL_MICRO
607# define NO_LOCALE
608#endif
609
4633a7c4 610#ifdef I_LOCALE
36477c24 611# include <locale.h>
4633a7c4
LW
612#endif
613
36477c24
PP
614#if !defined(NO_LOCALE) && defined(HAS_SETLOCALE)
615# define USE_LOCALE
616# if !defined(NO_LOCALE_COLLATE) && defined(LC_COLLATE) \
617 && defined(HAS_STRXFRM)
618# define USE_LOCALE_COLLATE
619# endif
620# if !defined(NO_LOCALE_CTYPE) && defined(LC_CTYPE)
621# define USE_LOCALE_CTYPE
622# endif
623# if !defined(NO_LOCALE_NUMERIC) && defined(LC_NUMERIC)
624# define USE_LOCALE_NUMERIC
625# endif
626#endif /* !NO_LOCALE && HAS_SETLOCALE */
a0d0e21e 627
fe14fcc3 628#include <setjmp.h>
79072805 629
a0d0e21e 630#ifdef I_SYS_PARAM
79072805
LW
631# ifdef PARAM_NEEDS_TYPES
632# include <sys/types.h>
633# endif
634# include <sys/param.h>
352d5a3a 635#endif
79072805 636
79072805 637/* Use all the "standard" definitions? */
a0d0e21e 638#if defined(STANDARD_C) && defined(I_STDLIB)
79072805 639# include <stdlib.h>
ff68c719 640#endif
03a14243 641
3f270f98
JH
642/* If this causes problems, set i_unistd=undef in the hint file. */
643#ifdef I_UNISTD
644# include <unistd.h>
645#endif
646
9969cdde 647#ifdef __SYMBIAN32__
27da23d5
JH
648# undef _SC_ARG_MAX /* Symbian has _SC_ARG_MAX but no sysconf() */
649#endif
650
7114a2d2 651#if defined(HAS_SYSCALL) && !defined(HAS_SYSCALL_PROTO) && !defined(PERL_MICRO)
c45598c5 652EXTERN_C int syscall(int, ...);
2ef53570
JH
653#endif
654
7114a2d2 655#if defined(HAS_USLEEP) && !defined(HAS_USLEEP_PROTO) && !defined(PERL_MICRO)
c45598c5 656EXTERN_C int usleep(unsigned int);
2ef53570
JH
657#endif
658
9a34ef1d
GS
659#ifdef PERL_MICRO /* Last chance to export Perl_my_swap */
660# define MYSWAP
661#endif
662
1109a392
MHM
663#ifdef PERL_CORE
664
665/* macros for correct constant construction */
666# if INTSIZE >= 2
667# define U16_CONST(x) ((U16)x##U)
668# else
669# define U16_CONST(x) ((U16)x##UL)
670# endif
671
672# if INTSIZE >= 4
673# define U32_CONST(x) ((U32)x##U)
674# else
675# define U32_CONST(x) ((U32)x##UL)
676# endif
677
678# ifdef HAS_QUAD
679# if INTSIZE >= 8
680# define U64_CONST(x) ((U64)x##U)
681# elif LONGSIZE >= 8
682# define U64_CONST(x) ((U64)x##UL)
683# elif QUADKIND == QUAD_IS_LONG_LONG
684# define U64_CONST(x) ((U64)x##ULL)
685# else /* best guess we can make */
686# define U64_CONST(x) ((U64)x##UL)
687# endif
688# endif
689
690/* byte-swapping functions for big-/little-endian conversion */
691# define _swab_16_(x) ((U16)( \
692 (((U16)(x) & U16_CONST(0x00ff)) << 8) | \
693 (((U16)(x) & U16_CONST(0xff00)) >> 8) ))
694
695# define _swab_32_(x) ((U32)( \
696 (((U32)(x) & U32_CONST(0x000000ff)) << 24) | \
697 (((U32)(x) & U32_CONST(0x0000ff00)) << 8) | \
698 (((U32)(x) & U32_CONST(0x00ff0000)) >> 8) | \
699 (((U32)(x) & U32_CONST(0xff000000)) >> 24) ))
700
701# ifdef HAS_QUAD
702# define _swab_64_(x) ((U64)( \
703 (((U64)(x) & U64_CONST(0x00000000000000ff)) << 56) | \
704 (((U64)(x) & U64_CONST(0x000000000000ff00)) << 40) | \
705 (((U64)(x) & U64_CONST(0x0000000000ff0000)) << 24) | \
706 (((U64)(x) & U64_CONST(0x00000000ff000000)) << 8) | \
707 (((U64)(x) & U64_CONST(0x000000ff00000000)) >> 8) | \
708 (((U64)(x) & U64_CONST(0x0000ff0000000000)) >> 24) | \
709 (((U64)(x) & U64_CONST(0x00ff000000000000)) >> 40) | \
710 (((U64)(x) & U64_CONST(0xff00000000000000)) >> 56) ))
711# endif
712
713/*----------------------------------------------------------------------------*/
714# if BYTEORDER == 0x1234 || BYTEORDER == 0x12345678 /* little-endian */
715/*----------------------------------------------------------------------------*/
716# define my_htole16(x) (x)
717# define my_letoh16(x) (x)
718# define my_htole32(x) (x)
719# define my_letoh32(x) (x)
720# define my_htobe16(x) _swab_16_(x)
721# define my_betoh16(x) _swab_16_(x)
722# define my_htobe32(x) _swab_32_(x)
723# define my_betoh32(x) _swab_32_(x)
724# ifdef HAS_QUAD
725# define my_htole64(x) (x)
726# define my_letoh64(x) (x)
727# define my_htobe64(x) _swab_64_(x)
728# define my_betoh64(x) _swab_64_(x)
729# endif
730# define my_htoles(x) (x)
731# define my_letohs(x) (x)
732# define my_htolei(x) (x)
733# define my_letohi(x) (x)
734# define my_htolel(x) (x)
735# define my_letohl(x) (x)
736# if SHORTSIZE == 1
737# define my_htobes(x) (x)
738# define my_betohs(x) (x)
739# elif SHORTSIZE == 2
740# define my_htobes(x) _swab_16_(x)
741# define my_betohs(x) _swab_16_(x)
742# elif SHORTSIZE == 4
743# define my_htobes(x) _swab_32_(x)
744# define my_betohs(x) _swab_32_(x)
745# elif SHORTSIZE == 8
746# define my_htobes(x) _swab_64_(x)
747# define my_betohs(x) _swab_64_(x)
748# else
749# define PERL_NEED_MY_HTOBES
750# define PERL_NEED_MY_BETOHS
751# endif
752# if INTSIZE == 1
753# define my_htobei(x) (x)
754# define my_betohi(x) (x)
755# elif INTSIZE == 2
756# define my_htobei(x) _swab_16_(x)
757# define my_betohi(x) _swab_16_(x)
758# elif INTSIZE == 4
759# define my_htobei(x) _swab_32_(x)
760# define my_betohi(x) _swab_32_(x)
761# elif INTSIZE == 8
762# define my_htobei(x) _swab_64_(x)
763# define my_betohi(x) _swab_64_(x)
764# else
765# define PERL_NEED_MY_HTOBEI
766# define PERL_NEED_MY_BETOHI
767# endif
768# if LONGSIZE == 1
769# define my_htobel(x) (x)
770# define my_betohl(x) (x)
771# elif LONGSIZE == 2
772# define my_htobel(x) _swab_16_(x)
773# define my_betohl(x) _swab_16_(x)
774# elif LONGSIZE == 4
775# define my_htobel(x) _swab_32_(x)
776# define my_betohl(x) _swab_32_(x)
777# elif LONGSIZE == 8
778# define my_htobel(x) _swab_64_(x)
779# define my_betohl(x) _swab_64_(x)
780# else
781# define PERL_NEED_MY_HTOBEL
782# define PERL_NEED_MY_BETOHL
783# endif
784# define my_htolen(p,n) NOOP
785# define my_letohn(p,n) NOOP
786# define my_htoben(p,n) my_swabn(p,n)
787# define my_betohn(p,n) my_swabn(p,n)
788/*----------------------------------------------------------------------------*/
789# elif BYTEORDER == 0x4321 || BYTEORDER == 0x87654321 /* big-endian */
790/*----------------------------------------------------------------------------*/
791# define my_htobe16(x) (x)
792# define my_betoh16(x) (x)
793# define my_htobe32(x) (x)
794# define my_betoh32(x) (x)
795# define my_htole16(x) _swab_16_(x)
796# define my_letoh16(x) _swab_16_(x)
797# define my_htole32(x) _swab_32_(x)
798# define my_letoh32(x) _swab_32_(x)
799# ifdef HAS_QUAD
800# define my_htobe64(x) (x)
801# define my_betoh64(x) (x)
802# define my_htole64(x) _swab_64_(x)
803# define my_letoh64(x) _swab_64_(x)
804# endif
805# define my_htobes(x) (x)
806# define my_betohs(x) (x)
807# define my_htobei(x) (x)
808# define my_betohi(x) (x)
809# define my_htobel(x) (x)
810# define my_betohl(x) (x)
811# if SHORTSIZE == 1
812# define my_htoles(x) (x)
813# define my_letohs(x) (x)
814# elif SHORTSIZE == 2
815# define my_htoles(x) _swab_16_(x)
816# define my_letohs(x) _swab_16_(x)
817# elif SHORTSIZE == 4
818# define my_htoles(x) _swab_32_(x)
819# define my_letohs(x) _swab_32_(x)
820# elif SHORTSIZE == 8
821# define my_htoles(x) _swab_64_(x)
822# define my_letohs(x) _swab_64_(x)
823# else
824# define PERL_NEED_MY_HTOLES
825# define PERL_NEED_MY_LETOHS
826# endif
827# if INTSIZE == 1
828# define my_htolei(x) (x)
829# define my_letohi(x) (x)
830# elif INTSIZE == 2
831# define my_htolei(x) _swab_16_(x)
832# define my_letohi(x) _swab_16_(x)
833# elif INTSIZE == 4
834# define my_htolei(x) _swab_32_(x)
835# define my_letohi(x) _swab_32_(x)
836# elif INTSIZE == 8
837# define my_htolei(x) _swab_64_(x)
838# define my_letohi(x) _swab_64_(x)
839# else
840# define PERL_NEED_MY_HTOLEI
841# define PERL_NEED_MY_LETOHI
842# endif
843# if LONGSIZE == 1
844# define my_htolel(x) (x)
845# define my_letohl(x) (x)
846# elif LONGSIZE == 2
847# define my_htolel(x) _swab_16_(x)
848# define my_letohl(x) _swab_16_(x)
849# elif LONGSIZE == 4
850# define my_htolel(x) _swab_32_(x)
851# define my_letohl(x) _swab_32_(x)
852# elif LONGSIZE == 8
853# define my_htolel(x) _swab_64_(x)
854# define my_letohl(x) _swab_64_(x)
855# else
856# define PERL_NEED_MY_HTOLEL
857# define PERL_NEED_MY_LETOHL
858# endif
859# define my_htolen(p,n) my_swabn(p,n)
860# define my_letohn(p,n) my_swabn(p,n)
861# define my_htoben(p,n) NOOP
862# define my_betohn(p,n) NOOP
863/*----------------------------------------------------------------------------*/
864# else /* all other byte-orders */
865/*----------------------------------------------------------------------------*/
866# define PERL_NEED_MY_HTOLE16
867# define PERL_NEED_MY_LETOH16
868# define PERL_NEED_MY_HTOBE16
869# define PERL_NEED_MY_BETOH16
870# define PERL_NEED_MY_HTOLE32
871# define PERL_NEED_MY_LETOH32
872# define PERL_NEED_MY_HTOBE32
873# define PERL_NEED_MY_BETOH32
874# ifdef HAS_QUAD
875# define PERL_NEED_MY_HTOLE64
876# define PERL_NEED_MY_LETOH64
877# define PERL_NEED_MY_HTOBE64
878# define PERL_NEED_MY_BETOH64
879# endif
880# define PERL_NEED_MY_HTOLES
881# define PERL_NEED_MY_LETOHS
882# define PERL_NEED_MY_HTOBES
883# define PERL_NEED_MY_BETOHS
884# define PERL_NEED_MY_HTOLEI
885# define PERL_NEED_MY_LETOHI
886# define PERL_NEED_MY_HTOBEI
887# define PERL_NEED_MY_BETOHI
888# define PERL_NEED_MY_HTOLEL
889# define PERL_NEED_MY_LETOHL
890# define PERL_NEED_MY_HTOBEL
891# define PERL_NEED_MY_BETOHL
892/*----------------------------------------------------------------------------*/
893# endif /* end of byte-order macros */
894/*----------------------------------------------------------------------------*/
895
9c17f24a
NC
896/* The old value was hard coded at 1008. (4096-16) seems to be a bit faster,
897 at least on FreeBSD. YMMV, so experiment. */
898#ifndef PERL_ARENA_SIZE
899#define PERL_ARENA_SIZE 4080
900#endif
901
1109a392
MHM
902#endif /* PERL_CORE */
903
bdf3085f
NC
904/* We no longer default to creating a new SV for GvSV.
905 Do this before embed. */
906#ifndef PERL_CREATE_GVSV
7459f06b
NC
907# ifndef PERL_DONT_CREATE_GVSV
908# define PERL_DONT_CREATE_GVSV
909# endif
bdf3085f
NC
910#endif
911
ca0c25f6
NC
912#if !defined(HAS_WAITPID) && !defined(HAS_WAIT4) || defined(HAS_WAITPID_RUNTIME)
913#define PERL_USES_PL_PIDSTATUS
914#endif
915
a62746fa
RGS
916#if !defined(OS2) && !defined(WIN32) && !defined(DJGPP) && !defined(EPOC) && !defined(__SYMBIAN32__) && !defined(MACOS_TRADITIONAL)
917#define PERL_DEFAULT_DO_EXEC3_IMPLEMENTATION
918#endif
919
66a93824
NIS
920/* Cannot include embed.h here on Win32 as win32.h has not
921 yet been included and defines some config variables e.g. HAVE_INTERP_INTERN
922 */
96e176bf 923#if !defined(PERL_FOR_X2P) && !(defined(WIN32)||defined(VMS))
cea2e8a9 924# include "embed.h"
eb8433b7
NC
925# ifndef PERL_MAD
926# undef op_getmad
b3f24c00 927# define op_getmad(arg,pegop,slot) NOOP
eb8433b7 928# endif
cea2e8a9
GS
929#endif
930
c31fac66
GS
931#define MEM_SIZE Size_t
932
1936d2a7
NC
933/* Round all values passed to malloc up, by default to a multiple of
934 sizeof(size_t)
935*/
936#ifndef PERL_STRLEN_ROUNDUP_QUANTUM
937#define PERL_STRLEN_ROUNDUP_QUANTUM Size_t_size
938#endif
939
51371543
GS
940#if defined(STANDARD_C) && defined(I_STDDEF)
941# include <stddef.h>
942# define STRUCT_OFFSET(s,m) offsetof(s,m)
943#else
944# define STRUCT_OFFSET(s,m) (Size_t)(&(((s *)0)->m))
945#endif
946
9969cdde 947#ifndef __SYMBIAN32__
27da23d5
JH
948# if defined(I_STRING) || defined(__cplusplus)
949# include <string.h>
950# else
951# include <strings.h>
952# endif
51371543
GS
953#endif
954
55497cff
PP
955/* This comes after <stdlib.h> so we don't try to change the standard
956 * library prototypes; we'll use our own in proto.h instead. */
03a14243 957
4633a7c4 958#ifdef MYMALLOC
86058a2d 959# ifdef PERL_POLLUTE_MALLOC
ee13e175 960# ifndef PERL_EXTMALLOC_DEF
86058a2d
GS
961# define Perl_malloc malloc
962# define Perl_calloc calloc
963# define Perl_realloc realloc
964# define Perl_mfree free
ee13e175 965# endif
86058a2d
GS
966# else
967# define EMBEDMYMALLOC /* for compatibility */
968# endif
827e134a 969
651b9576
GS
970# define safemalloc Perl_malloc
971# define safecalloc Perl_calloc
972# define saferealloc Perl_realloc
973# define safefree Perl_mfree
22f7c9c9
JH
974# define CHECK_MALLOC_TOO_LATE_FOR_(code) STMT_START { \
975 if (!PL_tainting && MallocCfg_ptr[MallocCfg_cfg_env_read]) \
976 code; \
977 } STMT_END
978# define CHECK_MALLOC_TOO_LATE_FOR(ch) \
979 CHECK_MALLOC_TOO_LATE_FOR_(MALLOC_TOO_LATE_FOR(ch))
980# define panic_write2(s) write(2, s, strlen(s))
981# define CHECK_MALLOC_TAINT(newval) \
982 CHECK_MALLOC_TOO_LATE_FOR_( \
983 if (newval) { \
984 panic_write2("panic: tainting with $ENV{PERL_MALLOC_OPT}\n");\
985 exit(1); })
22f7c9c9 986# define MALLOC_CHECK_TAINT(argc,argv,env) STMT_START { \
b0891165 987 if (doing_taint(argc,argv,env)) { \
22f7c9c9
JH
988 MallocCfg_ptr[MallocCfg_skip_cfg_env] = 1; \
989 }} STMT_END;
f2517201
GS
990#else /* MYMALLOC */
991# define safemalloc safesysmalloc
992# define safecalloc safesyscalloc
993# define saferealloc safesysrealloc
994# define safefree safesysfree
22f7c9c9
JH
995# define CHECK_MALLOC_TOO_LATE_FOR(ch) ((void)0)
996# define CHECK_MALLOC_TAINT(newval) ((void)0)
997# define MALLOC_CHECK_TAINT(argc,argv,env)
55497cff 998#endif /* MYMALLOC */
4633a7c4 999
27da23d5 1000#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
1001#define TOO_LATE_FOR(ch) TOO_LATE_FOR_(ch, "")
1002#define MALLOC_TOO_LATE_FOR(ch) TOO_LATE_FOR_(ch, " with $ENV{PERL_MALLOC_OPT}")
1003#define MALLOC_CHECK_TAINT2(argc,argv) MALLOC_CHECK_TAINT(argc,argv,NULL)
1004
a0d0e21e
LW
1005#if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
1006#define strchr index
1007#define strrchr rindex
1008#endif
1009
16d20bd9
AD
1010#ifdef I_MEMORY
1011# include <memory.h>
1012#endif
1013
fe14fcc3 1014#ifdef HAS_MEMCPY
85e6fe83 1015# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
fe14fcc3 1016# ifndef memcpy
20ce7b12 1017 extern char * memcpy (char*, char*, int);
ee0007ab
LW
1018# endif
1019# endif
1020#else
1021# ifndef memcpy
1022# ifdef HAS_BCOPY
1023# define memcpy(d,s,l) bcopy(s,d,l)
1024# else
1025# define memcpy(d,s,l) my_bcopy(s,d,l)
1026# endif
1027# endif
1028#endif /* HAS_MEMCPY */
fe14fcc3 1029
ee0007ab 1030#ifdef HAS_MEMSET
85e6fe83 1031# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
ee0007ab 1032# ifndef memset
20ce7b12 1033 extern char *memset (char*, int, int);
ee0007ab
LW
1034# endif
1035# endif
ee0007ab 1036#else
12ae5dfc 1037# undef memset
fc36a67e 1038# define memset(d,c,l) my_memset(d,c,l)
ee0007ab
LW
1039#endif /* HAS_MEMSET */
1040
85e6fe83 1041#if !defined(HAS_MEMMOVE) && !defined(memmove)
2304df62 1042# if defined(HAS_BCOPY) && defined(HAS_SAFE_BCOPY)
79072805
LW
1043# define memmove(d,s,l) bcopy(s,d,l)
1044# else
2304df62 1045# if defined(HAS_MEMCPY) && defined(HAS_SAFE_MEMCPY)
79072805 1046# define memmove(d,s,l) memcpy(d,s,l)
ee0007ab 1047# else
79072805 1048# define memmove(d,s,l) my_bcopy(s,d,l)
ee0007ab 1049# endif
352d5a3a 1050# endif
d9d8d8de 1051#endif
ee0007ab 1052
36477c24
PP
1053#if defined(mips) && defined(ultrix) && !defined(__STDC__)
1054# undef HAS_MEMCMP
1055#endif
1056
1057#if defined(HAS_MEMCMP) && defined(HAS_SANE_MEMCMP)
85e6fe83 1058# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
ee0007ab 1059# ifndef memcmp
20ce7b12 1060 extern int memcmp (char*, char*, int);
ee0007ab
LW
1061# endif
1062# endif
36477c24 1063# ifdef BUGGY_MSC
7e4e8c89 1064# pragma function(memcmp)
36477c24 1065# endif
ee0007ab
LW
1066#else
1067# ifndef memcmp
ecfc5424 1068# define memcmp my_memcmp
352d5a3a 1069# endif
36477c24 1070#endif /* HAS_MEMCMP && HAS_SANE_MEMCMP */
8d063cd8 1071
fc36a67e 1072#ifndef memzero
c635e13b
PP
1073# ifdef HAS_MEMSET
1074# define memzero(d,l) memset(d,0,l)
79072805 1075# else
c635e13b
PP
1076# ifdef HAS_BZERO
1077# define memzero(d,l) bzero(d,l)
79072805 1078# else
fc36a67e 1079# define memzero(d,l) my_bzero(d,l)
79072805
LW
1080# endif
1081# endif
d9d8d8de 1082#endif
378cc40b 1083
2f42fcb0 1084#ifndef PERL_MICRO
0f27ced1
JH
1085#ifndef memchr
1086# ifndef HAS_MEMCHR
1087# define memchr(s,c,n) ninstr((char*)(s), ((char*)(s)) + n, &(c), &(c) + 1)
1088# endif
1089#endif
2f42fcb0 1090#endif
0f27ced1 1091
36477c24
PP
1092#ifndef HAS_BCMP
1093# ifndef bcmp
1094# define bcmp(s1,s2,l) memcmp(s1,s2,l)
79072805 1095# endif
36477c24 1096#endif /* !HAS_BCMP */
378cc40b 1097
ae986130 1098#ifdef I_NETINET_IN
79072805 1099# include <netinet/in.h>
ae986130
LW
1100#endif
1101
28e8609d
JH
1102#ifdef I_ARPA_INET
1103# include <arpa/inet.h>
1104#endif
1105
84902520
TB
1106#if defined(SF_APPEND) && defined(USE_SFIO) && defined(I_SFIO)
1107/* <sfio.h> defines SF_APPEND and <sys/stat.h> might define SF_APPEND
1108 * (the neo-BSD seem to do this). */
1109# undef SF_APPEND
1110#endif
1111
1aef975c 1112#ifdef I_SYS_STAT
84902520 1113# include <sys/stat.h>
1aef975c 1114#endif
79072805 1115
a0d0e21e
LW
1116/* The stat macros for Amdahl UTS, Unisoft System V/88 (and derivatives
1117 like UTekV) are broken, sometimes giving false positives. Undefine
1118 them here and let the code below set them to proper values.
1119
1120 The ghs macro stands for GreenHills Software C-1.8.5 which
1121 is the C compiler for sysV88 and the various derivatives.
1122 This header file bug is corrected in gcc-2.5.8 and later versions.
1123 --Kaveh Ghazi (ghazi@noc.rutgers.edu) 10/3/94. */
1124
1125#if defined(uts) || (defined(m88k) && defined(ghs))
79072805
LW
1126# undef S_ISDIR
1127# undef S_ISCHR
1128# undef S_ISBLK
1129# undef S_ISREG
1130# undef S_ISFIFO
1131# undef S_ISLNK
ee0007ab 1132#endif
135863df 1133
663a0e37
LW
1134#ifdef I_TIME
1135# include <time.h>
ffed7fef 1136#endif
663a0e37 1137
fe14fcc3 1138#ifdef I_SYS_TIME
85e6fe83 1139# ifdef I_SYS_TIME_KERNEL
663a0e37
LW
1140# define KERNEL
1141# endif
1142# include <sys/time.h>
85e6fe83 1143# ifdef I_SYS_TIME_KERNEL
663a0e37
LW
1144# undef KERNEL
1145# endif
a687059c 1146#endif
135863df 1147
55497cff 1148#if defined(HAS_TIMES) && defined(I_SYS_TIMES)
85e6fe83 1149# include <sys/times.h>
d9d8d8de 1150#endif
8d063cd8 1151
fe14fcc3 1152#if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
79072805 1153# undef HAS_STRERROR
663a0e37
LW
1154#endif
1155
1156#include <errno.h>
1e743fda 1157
acfe0abc 1158#if defined(WIN32) && defined(PERL_IMPLICIT_SYS)
b4748376
NIS
1159# define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */
1160#endif
1161
8cfab5ff
JH
1162/* In Tru64 use the 4.4BSD struct msghdr, not the 4.3 one.
1163 * This is important for using IPv6.
1164 * For OSF/1 3.2, however, defining _SOCKADDR_LEN would be
1165 * a bad idea since it breaks send() and recv(). */
1166#if defined(__osf__) && defined(__alpha) && !defined(_SOCKADDR_LEN) && !defined(DEC_OSF1_3_X)
1167# define _SOCKADDR_LEN
1168#endif
1169
8d3f517a 1170#if defined(HAS_SOCKET) && !defined(VMS) && !defined(WIN32) /* VMS/WIN32 handle sockets via vmsish.h/win32.h */
1e743fda
JH
1171# include <sys/socket.h>
1172# if defined(USE_SOCKS) && defined(I_SOCKS)
1173# if !defined(INCLUDE_PROTOTYPES)
1174# define INCLUDE_PROTOTYPES /* for <socks.h> */
1175# define PERL_SOCKS_NEED_PROTOTYPES
1176# endif
1177# include <socks.h>
1178# ifdef PERL_SOCKS_NEED_PROTOTYPES /* keep cpp space clean */
1179# undef INCLUDE_PROTOTYPES
1180# undef PERL_SOCKS_NEED_PROTOTYPES
ed6116ce 1181# endif
d460ef45 1182# endif
1e743fda 1183# ifdef I_NETDB
2986a63f
JH
1184# ifdef NETWARE
1185# include<stdio.h>
1186# endif
1e743fda
JH
1187# include <netdb.h>
1188# endif
1189# ifndef ENOTSOCK
1190# ifdef I_NET_ERRNO
1191# include <net/errno.h>
1192# endif
1193# endif
1194#endif
1195
fa0a29af 1196/* sockatmark() is so new (2001) that many places might have it hidden
29820b6d
MHM
1197 * behind some -D_BLAH_BLAH_SOURCE guard. The __THROW magic is required
1198 * e.g. in Gentoo, see http://bugs.gentoo.org/show_bug.cgi?id=12605 */
fa0a29af 1199#if defined(HAS_SOCKATMARK) && !defined(HAS_SOCKATMARK_PROTO)
29820b6d
MHM
1200# if defined(__THROW) && defined(__GLIBC__)
1201int sockatmark(int) __THROW;
1202# else
2ef53570 1203int sockatmark(int);
29820b6d 1204# endif
2ef53570
JH
1205#endif
1206
7e827271 1207#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
1208EXTERN_C int fchdir(int);
1209EXTERN_C int flock(int, int);
1210EXTERN_C int fseeko(FILE *, off_t, int);
1211EXTERN_C off_t ftello(FILE *);
1212#endif
1213
7e827271 1214#if defined(__SUNPRO_CC) /* SUNWspro CC (C++) */
1ccb7c8d 1215EXTERN_C char *crypt(const char *, const char *);
7e827271 1216EXTERN_C char **environ;
1ccb7c8d
JH
1217#endif
1218
b91fbb93
SP
1219#if defined(__OpenBSD__) && defined(__cplusplus)
1220EXTERN_C char **environ;
1221#endif
1222
667e2948
SP
1223#if defined(__CYGWIN__) && defined(__cplusplus)
1224EXTERN_C char *crypt(const char *, const char *);
1225#endif
1226
1e743fda
JH
1227#ifdef SETERRNO
1228# undef SETERRNO /* SOCKS might have defined this */
ed6116ce 1229#endif
f86702cc
PP
1230
1231#ifdef VMS
1232# define SETERRNO(errcode,vmserrcode) \
1233 STMT_START { \
1234 set_errno(errcode); \
1235 set_vaxc_errno(vmserrcode); \
1236 } STMT_END
93189314
JH
1237# define LIB_INVARG LIB$_INVARG
1238# define RMS_DIR RMS$_DIR
1239# define RMS_FAC RMS$_FAC
1240# define RMS_FEX RMS$_FEX
1241# define RMS_FNF RMS$_FNF
1242# define RMS_IFI RMS$_IFI
1243# define RMS_ISI RMS$_ISI
1244# define RMS_PRV RMS$_PRV
1245# define SS_ACCVIO SS$_ACCVIO
1246# define SS_DEVOFFLINE SS$_DEVOFFLINE
1247# define SS_IVCHAN SS$_IVCHAN
1248# define SS_NORMAL SS$_NORMAL
748a9306 1249#else
aba27d88 1250# define SETERRNO(errcode,vmserrcode) (errno = (errcode))
93189314
JH
1251# define LIB_INVARG 0
1252# define RMS_DIR 0
1253# define RMS_FAC 0
1254# define RMS_FEX 0
1255# define RMS_FNF 0
1256# define RMS_IFI 0
1257# define RMS_ISI 0
1258# define RMS_PRV 0
1259# define SS_ACCVIO 0
1260# define SS_DEVOFFLINE 0
1261# define SS_IVCHAN 0
1262# define SS_NORMAL 0
748a9306 1263#endif
ed6116ce 1264
3db8f154 1265#define ERRSV GvSV(PL_errgv)
e203899d
NC
1266/* FIXME? Change the assignments to PL_defgv to instantiate GvSV? */
1267#define DEFSV GvSVn(PL_defgv)
3db8f154 1268#define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
38a03e6e 1269
98eae8f5
GS
1270#define ERRHV GvHV(PL_errgv) /* XXX unused, here for compatibility */
1271
55497cff 1272#ifndef errno
5ff3f7a4
GS
1273 extern int errno; /* ANSI allows errno to be an lvalue expr.
1274 * For example in multithreaded environments
1275 * something like this might happen:
1276 * extern int *_errno(void);
1277 * #define errno (*_errno()) */
d9d8d8de 1278#endif
663a0e37 1279
2304df62 1280#ifdef HAS_STRERROR
a0d0e21e 1281# ifdef VMS
20ce7b12 1282 char *strerror (int,...);
a0d0e21e 1283# else
68dc0745 1284#ifndef DONT_DECLARE_STD
20ce7b12 1285 char *strerror (int);
68dc0745 1286#endif
a0d0e21e 1287# endif
2304df62
AD
1288# ifndef Strerror
1289# define Strerror strerror
1290# endif
1291#else
1292# ifdef HAS_SYS_ERRLIST
79072805
LW
1293 extern int sys_nerr;
1294 extern char *sys_errlist[];
2304df62
AD
1295# ifndef Strerror
1296# define Strerror(e) \
79072805 1297 ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
2304df62 1298# endif
79072805 1299# endif
35c8bce7 1300#endif
663a0e37 1301
2304df62 1302#ifdef I_SYS_IOCTL
79072805
LW
1303# ifndef _IOCTL_
1304# include <sys/ioctl.h>
1305# endif
a687059c
LW
1306#endif
1307
ee0007ab 1308#if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
79072805
LW
1309# ifdef HAS_SOCKETPAIR
1310# undef HAS_SOCKETPAIR
1311# endif
2304df62
AD
1312# ifdef I_NDBM
1313# undef I_NDBM
79072805 1314# endif
a687059c
LW
1315#endif
1316
02fc2eee
NC
1317#ifndef HAS_SOCKETPAIR
1318# ifdef HAS_SOCKET
1319# define socketpair Perl_my_socketpair
1320# endif
1321#endif
1322
a687059c 1323#if INTSIZE == 2
79072805
LW
1324# define htoni htons
1325# define ntohi ntohs
a687059c 1326#else
79072805
LW
1327# define htoni htonl
1328# define ntohi ntohl
a687059c
LW
1329#endif
1330
a0d0e21e 1331/* Configure already sets Direntry_t */
35c8bce7 1332#if defined(I_DIRENT)
663a0e37 1333# include <dirent.h>
8f1f23e8
W
1334 /* NeXT needs dirent + sys/dir.h */
1335# if defined(I_SYS_DIR) && (defined(NeXT) || defined(__NeXT__))
a0d0e21e
LW
1336# include <sys/dir.h>
1337# endif
ae986130 1338#else
fe14fcc3 1339# ifdef I_SYS_NDIR
79a0689e 1340# include <sys/ndir.h>
663a0e37 1341# else
fe14fcc3 1342# ifdef I_SYS_DIR
79a0689e
LW
1343# ifdef hp9000s500
1344# include <ndir.h> /* may be wrong in the future */
1345# else
1346# include <sys/dir.h>
1347# endif
663a0e37
LW
1348# endif
1349# endif
4633a7c4 1350#endif
a687059c 1351
12ae5dfc
JH
1352#ifdef PERL_MICRO
1353# ifndef DIR
1354# define DIR void
1355# endif
1356#endif
1357
352d5a3a
LW
1358#ifdef FPUTS_BOTCH
1359/* work around botch in SunOS 4.0.1 and 4.0.2 */
1360# ifndef fputs
79072805 1361# define fputs(sv,fp) fprintf(fp,"%s",sv)
352d5a3a
LW
1362# endif
1363#endif
1364
c623bd54
LW
1365/*
1366 * The following gobbledygook brought to you on behalf of __STDC__.
1367 * (I could just use #ifndef __STDC__, but this is more bulletproof
1368 * in the face of half-implementations.)
1369 */
1370
7114a2d2 1371#if defined(I_SYSMODE) && !defined(PERL_MICRO)
ca6e1c26
JH
1372#include <sys/mode.h>
1373#endif
1374
c623bd54
LW
1375#ifndef S_IFMT
1376# ifdef _S_IFMT
1377# define S_IFMT _S_IFMT
1378# else
1379# define S_IFMT 0170000
1380# endif
1381#endif
1382
1383#ifndef S_ISDIR
1384# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
1385#endif
1386
1387#ifndef S_ISCHR
1388# define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
1389#endif
1390
1391#ifndef S_ISBLK
fe14fcc3
LW
1392# ifdef S_IFBLK
1393# define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
1394# else
1395# define S_ISBLK(m) (0)
1396# endif
c623bd54
LW
1397#endif
1398
1399#ifndef S_ISREG
1400# define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
1401#endif
1402
1403#ifndef S_ISFIFO
fe14fcc3
LW
1404# ifdef S_IFIFO
1405# define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
1406# else
1407# define S_ISFIFO(m) (0)
1408# endif
c623bd54
LW
1409#endif
1410
1411#ifndef S_ISLNK
1412# ifdef _S_ISLNK
1413# define S_ISLNK(m) _S_ISLNK(m)
1414# else
1415# ifdef _S_IFLNK
1416# define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
1417# else
1418# ifdef S_IFLNK
1419# define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
1420# else
1421# define S_ISLNK(m) (0)
1422# endif
1423# endif
1424# endif
1425#endif
1426
1427#ifndef S_ISSOCK
1428# ifdef _S_ISSOCK
1429# define S_ISSOCK(m) _S_ISSOCK(m)
1430# else
1431# ifdef _S_IFSOCK
1432# define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
1433# else
1434# ifdef S_IFSOCK
1435# define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
1436# else
1437# define S_ISSOCK(m) (0)
1438# endif
1439# endif
1440# endif
1441#endif
1442
1443#ifndef S_IRUSR
1444# ifdef S_IREAD
1445# define S_IRUSR S_IREAD
1446# define S_IWUSR S_IWRITE
1447# define S_IXUSR S_IEXEC
1448# else
1449# define S_IRUSR 0400
1450# define S_IWUSR 0200
1451# define S_IXUSR 0100
1452# endif
fac7cdfc 1453#endif
1454
1455#ifndef S_IRGRP
1456# ifdef S_IRUSR
1457# define S_IRGRP (S_IRUSR>>3)
1458# define S_IWGRP (S_IWUSR>>3)
1459# define S_IXGRP (S_IXUSR>>3)
1460# else
1461# define S_IRGRP 0040
1462# define S_IWGRP 0020
1463# define S_IXGRP 0010
1464# endif
1465#endif
1466
1467#ifndef S_IROTH
1468# ifdef S_IRUSR
1469# define S_IROTH (S_IRUSR>>6)
1470# define S_IWOTH (S_IWUSR>>6)
1471# define S_IXOTH (S_IXUSR>>6)
1472# else
1473# define S_IROTH 0040
1474# define S_IWOTH 0020
1475# define S_IXOTH 0010
1476# endif
c623bd54
LW
1477#endif
1478
1479#ifndef S_ISUID
1480# define S_ISUID 04000
1481#endif
1482
1483#ifndef S_ISGID
1484# define S_ISGID 02000
1485#endif
1486
ca6e1c26
JH
1487#ifndef S_IRWXU
1488# define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR)
d460ef45 1489#endif
ca6e1c26
JH
1490
1491#ifndef S_IRWXG
1492# define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP)
d460ef45 1493#endif
ca6e1c26
JH
1494
1495#ifndef S_IRWXO
1496# define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH)
d460ef45 1497#endif
ca6e1c26 1498
c21fb2b8
JH
1499/* BeOS 5.0 seems to define S_IREAD and S_IWRITE in <posix/fcntl.h>
1500 * which would get included through <sys/file.h >, but that is 3000
1501 * lines in the future. --jhi */
1502
1503#if !defined(S_IREAD) && !defined(__BEOS__)
ca6e1c26
JH
1504# define S_IREAD S_IRUSR
1505#endif
1506
c21fb2b8 1507#if !defined(S_IWRITE) && !defined(__BEOS__)
ca6e1c26
JH
1508# define S_IWRITE S_IWUSR
1509#endif
1510
1511#ifndef S_IEXEC
1512# define S_IEXEC S_IXUSR
1513#endif
1514
79072805
LW
1515#ifdef ff_next
1516# undef ff_next
352d5a3a
LW
1517#endif
1518
a0d0e21e 1519#if defined(cray) || defined(gould) || defined(i860) || defined(pyr)
45d8adaa
LW
1520# define SLOPPYDIVIDE
1521#endif
1522
748a9306
LW
1523#ifdef UV
1524#undef UV
1525#endif
1526
c89df6bf
JH
1527#ifdef SPRINTF_E_BUG
1528# define sprintf UTS_sprintf_wrap
1529#endif
1530
ce582cee
NC
1531/* For the times when you want the return value of sprintf, and you want it
1532 to be the length. Can't have a thread variable passed in, because C89 has
1533 no varargs macros.
1534*/
1535#ifdef SPRINTF_RETURNS_STRLEN
1536# define my_sprintf sprintf
1537#else
1538# define my_sprintf Perl_my_sprintf
1539#endif
1540
5b692037
JH
1541/*
1542 * If we have v?snprintf() and the C99 variadic macros, we can just
1543 * use just the v?snprintf(). It is nice to try to trap the buffer
1544 * overflow, however, so if we are DEBUGGING, and we cannot use the
e5afc1ae
DD
1545 * gcc statement expressions, then use the function wrappers which try
1546 * to trap the overflow. If we can use the gcc statement expressions,
1547 * we can try that even with the version that uses the C99 variadic
1548 * macros.
5b692037
JH
1549 */
1550
1208b3dd
JH
1551/* Note that we do not check against snprintf()/vsnprintf() returning
1552 * negative values because that is non-standard behaviour and we use
1553 * snprintf/vsnprintf only iff HAS_VSNPRINTF has been defined, and
1554 * that should be true only if the snprintf()/vsnprintf() are true
1555 * to the standard. */
1556
dfeee9b1 1557#if defined(HAS_SNPRINTF) && defined(HAS_C99_VARIADIC_MACROS) && !(defined(DEBUGGING) && !defined(PERL_USE_GCC_BRACE_GROUPS)) && !defined(PERL_GCC_PEDANTIC)
5b692037 1558# ifdef PERL_USE_GCC_BRACE_GROUPS
12e82c57 1559# define my_snprintf(buffer, len, ...) ({ int __len__ = snprintf(buffer, len, __VA_ARGS__); if ((len) > 0 && (Size_t)__len__ >= (len)) Perl_croak_nocontext("panic: snprintf buffer overflow"); __len__; })
1208b3dd 1560# define PERL_MY_SNPRINTF_GUARDED
5b692037
JH
1561# else
1562# define my_snprintf(buffer, len, ...) snprintf(buffer, len, __VA_ARGS__)
1563# endif
1564#else
1565# define my_snprintf Perl_my_snprintf
1208b3dd 1566# define PERL_MY_SNPRINTF_GUARDED
5b692037
JH
1567#endif
1568
dfeee9b1 1569#if defined(HAS_VSNPRINTF) && defined(HAS_C99_VARIADIC_MACROS) && !(defined(DEBUGGING) && !defined(PERL_USE_GCC_BRACE_GROUPS)) && !defined(PERL_GCC_PEDANTIC)
5b692037 1570# ifdef PERL_USE_GCC_BRACE_GROUPS
12e82c57 1571# define my_vsnprintf(buffer, len, ...) ({ int __len__ = vsnprintf(buffer, len, __VA_ARGS__); if ((len) > 0 && (Size_t)__len__ >= (len)) Perl_croak_nocontext("panic: vsnprintf buffer overflow"); __len__; })
1208b3dd 1572# define PERL_MY_VSNPRINTF_GUARDED
5b692037
JH
1573# else
1574# define my_vsnprintf(buffer, len, ...) vsnprintf(buffer, len, __VA_ARGS__)
1575# endif
1576#else
1577# define my_vsnprintf Perl_my_vsnprintf
1208b3dd 1578# define PERL_MY_VSNPRINTF_GUARDED
5b692037 1579#endif
d9fad198 1580
a6cc4119
SP
1581#ifdef HAS_STRLCAT
1582# define my_strlcat strlcat
1583#else
1584# define my_strlcat Perl_my_strlcat
1585#endif
1586
1587#ifdef HAS_STRLCPY
1588# define my_strlcpy strlcpy
1589#else
1590# define my_strlcpy Perl_my_strlcpy
1591#endif
1592
c495e728
JH
1593/* Configure gets this right but the UTS compiler gets it wrong.
1594 -- Hal Morris <hom00@utsglobal.com> */
1595#ifdef UTS
1596# undef UVTYPE
1597# define UVTYPE unsigned
1598#endif
1599
05f13f53 1600/*
27d4fb96
PP
1601 The IV type is supposed to be long enough to hold any integral
1602 value or a pointer.
1603 --Andy Dougherty August 1996
1604*/
1605
a22e52b9
JH
1606typedef IVTYPE IV;
1607typedef UVTYPE UV;
8175356b 1608
10cc9d2a 1609#if defined(USE_64_BIT_INT) && defined(HAS_QUAD)
6b8eaf93 1610# if QUADKIND == QUAD_IS_INT64_T && defined(INT64_MAX)
5ff3f7a4
GS
1611# define IV_MAX INT64_MAX
1612# define IV_MIN INT64_MIN
1613# define UV_MAX UINT64_MAX
cae7ae48
JH
1614# ifndef UINT64_MIN
1615# define UINT64_MIN 0
1616# endif
5ff3f7a4
GS
1617# define UV_MIN UINT64_MIN
1618# else
1619# define IV_MAX PERL_QUAD_MAX
1620# define IV_MIN PERL_QUAD_MIN
1621# define UV_MAX PERL_UQUAD_MAX
1622# define UV_MIN PERL_UQUAD_MIN
1623# endif
cf2093f6
JH
1624# define IV_IS_QUAD
1625# define UV_IS_QUAD
79072805 1626#else
8175356b 1627# if defined(INT32_MAX) && IVSIZE == 4
5ff3f7a4
GS
1628# define IV_MAX INT32_MAX
1629# define IV_MIN INT32_MIN
716026f9
DL
1630# ifndef UINT32_MAX_BROKEN /* e.g. HP-UX with gcc messes this up */
1631# define UV_MAX UINT32_MAX
1632# else
1633# define UV_MAX 4294967295U
1634# endif
cae7ae48
JH
1635# ifndef UINT32_MIN
1636# define UINT32_MIN 0
1637# endif
5ff3f7a4
GS
1638# define UV_MIN UINT32_MIN
1639# else
1640# define IV_MAX PERL_LONG_MAX
1641# define IV_MIN PERL_LONG_MIN
1642# define UV_MAX PERL_ULONG_MAX
1643# define UV_MIN PERL_ULONG_MIN
1644# endif
8175356b 1645# if IVSIZE == 8
cf2093f6
JH
1646# define IV_IS_QUAD
1647# define UV_IS_QUAD
de1c2614
JH
1648# ifndef HAS_QUAD
1649# define HAS_QUAD
1650# endif
cf2093f6
JH
1651# else
1652# undef IV_IS_QUAD
1653# undef UV_IS_QUAD
de1c2614 1654# undef HAS_QUAD
cf2093f6 1655# endif
79072805 1656#endif
d7d93a81 1657
1109a392
MHM
1658#ifndef HAS_QUAD
1659# undef PERL_NEED_MY_HTOLE64
1660# undef PERL_NEED_MY_LETOH64
1661# undef PERL_NEED_MY_HTOBE64
1662# undef PERL_NEED_MY_BETOH64
1663#endif
1664
6cde8aec 1665#if defined(uts) || defined(UTS)
11afe549
HM
1666# undef UV_MAX
1667# define UV_MAX (4294967295u)
20601011
JH
1668#endif
1669
cae7ae48 1670#define IV_DIG (BIT_DIGITS(IVSIZE * 8))
22ec83e3 1671#define UV_DIG (BIT_DIGITS(UVSIZE * 8))
56431972 1672
28e5dec8 1673#ifndef NO_PERL_PRESERVE_IVUV
f5c03d33 1674#define PERL_PRESERVE_IVUV /* We like our integers to stay integers. */
28e5dec8
JH
1675#endif
1676
d460ef45 1677/*
26bb67e2
JH
1678 * The macros INT2PTR and NUM2PTR are (despite their names)
1679 * bi-directional: they will convert int/float to or from pointers.
1680 * However the conversion to int/float are named explicitly:
1681 * PTR2IV, PTR2UV, PTR2NV.
1682 *
1683 * For int conversions we do not need two casts if pointers are
1684 * the same size as IV and UV. Otherwise we need an explicit
1685 * cast (PTRV) to avoid compiler warnings.
1686 */
56431972
RB
1687#if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE)
1688# define PTRV UV
1689# define INT2PTR(any,d) (any)(d)
1690#else
d460ef45 1691# if PTRSIZE == LONGSIZE
56431972 1692# define PTRV unsigned long
e91e3b10 1693# define PTR2ul(p) (unsigned long)(p)
42718184 1694# else
56431972 1695# define PTRV unsigned
42718184 1696# endif
e91e3b10
RB
1697#endif
1698
1699#ifndef INT2PTR
56431972 1700# define INT2PTR(any,d) (any)(PTRV)(d)
42718184 1701#endif
e91e3b10
RB
1702
1703#ifndef PTR2ul
1704# define PTR2ul(p) INT2PTR(unsigned long,p)
1705#endif
1706
56431972
RB
1707#define NUM2PTR(any,d) (any)(PTRV)(d)
1708#define PTR2IV(p) INT2PTR(IV,p)
1709#define PTR2UV(p) INT2PTR(UV,p)
1710#define PTR2NV(p) NUM2PTR(NV,p)
e91e3b10 1711#define PTR2nat(p) (PTRV)(p) /* pointer to integer of PTRSIZE */
d460ef45 1712
8141890a
JH
1713/* According to strict ANSI C89 one cannot freely cast between
1714 * data pointers and function (code) pointers. There are at least
1715 * two ways around this. One (used below) is to do two casts,
1716 * first the other pointer to an (unsigned) integer, and then
1717 * the integer to the other pointer. The other way would be
1718 * to use unions to "overlay" the pointers. For an example of
1719 * the latter technique, see union dirpu in struct xpvio in sv.h.
1720 * The only feasible use is probably temporarily storing
1721 * function pointers in a data pointer (such as a void pointer). */
1722
e91e3b10
RB
1723#define DPTR2FPTR(t,p) ((t)PTR2nat(p)) /* data pointer to function pointer */
1724#define FPTR2DPTR(t,p) ((t)PTR2nat(p)) /* function pointer to data pointer */
8141890a 1725
65202027 1726#ifdef USE_LONG_DOUBLE
1048ea30
JH
1727# if defined(HAS_LONG_DOUBLE) && LONG_DOUBLESIZE == DOUBLESIZE
1728# define LONG_DOUBLE_EQUALS_DOUBLE
1729# endif
68d4903c 1730# if !(defined(HAS_LONG_DOUBLE) && (LONG_DOUBLESIZE > DOUBLESIZE))
2d4389e4 1731# undef USE_LONG_DOUBLE /* Ouch! */
65202027
DS
1732# endif
1733#endif
1734
2d4389e4
JH
1735#ifdef OVR_DBL_DIG
1736/* Use an overridden DBL_DIG */
1737# ifdef DBL_DIG
1738# undef DBL_DIG
1739# endif
1740# define DBL_DIG OVR_DBL_DIG
1741#else
1742/* The following is all to get DBL_DIG, in order to pick a nice
205f51d8
AS
1743 default value for printing floating point numbers in Gconvert
1744 (see config.h). (It also has other uses, such as figuring out if
1745 a given precision of printing can be done with a double instead of
1746 a long double - Allen).
2d4389e4
JH
1747*/
1748#ifdef I_LIMITS
1749#include <limits.h>
1750#endif
1751#ifdef I_FLOAT
1752#include <float.h>
1753#endif
1754#ifndef HAS_DBL_DIG
1755#define DBL_DIG 15 /* A guess that works lots of places */
1756#endif
1757#endif
1758
1759#ifdef OVR_LDBL_DIG
1760/* Use an overridden LDBL_DIG */
1761# ifdef LDBL_DIG
1762# undef LDBL_DIG
1763# endif
1764# define LDBL_DIG OVR_LDBL_DIG
1765#else
1766/* The following is all to get LDBL_DIG, in order to pick a nice
1767 default value for printing floating point numbers in Gconvert.
1768 (see config.h)
1769*/
68d4903c
JH
1770# ifdef I_LIMITS
1771# include <limits.h>
1772# endif
1773# ifdef I_FLOAT
1774# include <float.h>
1775# endif
1776# ifndef HAS_LDBL_DIG
1777# if LONG_DOUBLESIZE == 10
1778# define LDBL_DIG 18 /* assume IEEE */
1779# else
1780# if LONG_DOUBLESIZE == 12
1781# define LDBL_DIG 18 /* gcc? */
1782# else
1783# if LONG_DOUBLESIZE == 16
1784# define LDBL_DIG 33 /* assume IEEE */
1785# else
1786# if LONG_DOUBLESIZE == DOUBLESIZE
1787# define LDBL_DIG DBL_DIG /* bummer */
1788# endif
1789# endif
1790# endif
1791# endif
1792# endif
2d4389e4
JH
1793#endif
1794
20f6aaab
AS
1795/*
1796 * This is for making sure we have a good DBL_MAX value, if possible,
1797 * either for usage as NV_MAX or for usage in figuring out if we can
1798 * fit a given long double into a double, if bug-fixing makes it
1799 * necessary to do so. - Allen <allens@cpan.org>
1800 */
1801
205f51d8
AS
1802#ifdef I_LIMITS
1803# include <limits.h>
20f6aaab
AS
1804#endif
1805
205f51d8
AS
1806#ifdef I_VALUES
1807# if !(defined(DBL_MIN) && defined(DBL_MAX) && defined(I_LIMITS))
1808# include <values.h>
1809# if defined(MAXDOUBLE) && !defined(DBL_MAX)
1810# define DBL_MAX MAXDOUBLE
1811# endif
1812# if defined(MINDOUBLE) && !defined(DBL_MIN)
1813# define DBL_MIN MINDOUBLE
1814# endif
1815# endif
1816#endif /* defined(I_VALUES) */
1817
a22e52b9 1818typedef NVTYPE NV;
8175356b 1819
792d8dab
JH
1820#ifdef I_IEEEFP
1821# include <ieeefp.h>
1822#endif
923fc586 1823
65202027 1824#ifdef USE_LONG_DOUBLE
923fc586
JH
1825# ifdef I_SUNMATH
1826# include <sunmath.h>
1827# endif
2d4389e4 1828# define NV_DIG LDBL_DIG
d6c14000
JH
1829# ifdef LDBL_MANT_DIG
1830# define NV_MANT_DIG LDBL_MANT_DIG
1831# endif
06fc1729
JH
1832# ifdef LDBL_MIN
1833# define NV_MIN LDBL_MIN
1834# endif
1835# ifdef LDBL_MAX
1836# define NV_MAX LDBL_MAX
1837# endif
1838# ifdef LDBL_MIN_10_EXP
1839# define NV_MIN_10_EXP LDBL_MIN_10_EXP
1840# endif
1841# ifdef LDBL_MAX_10_EXP
1842# define NV_MAX_10_EXP LDBL_MAX_10_EXP
1843# endif
1844# ifdef LDBL_EPSILON
1845# define NV_EPSILON LDBL_EPSILON
1846# endif
f4a14a62
JH
1847# ifdef LDBL_MAX
1848# define NV_MAX LDBL_MAX
20f6aaab 1849/* Having LDBL_MAX doesn't necessarily mean that we have LDBL_MIN... -Allen */
f4a14a62
JH
1850# else
1851# ifdef HUGE_VALL
1852# define NV_MAX HUGE_VALL
1853# else
1854# ifdef HUGE_VAL
1855# define NV_MAX ((NV)HUGE_VAL)
1856# endif
1857# endif
1858# endif
68d4903c 1859# ifdef HAS_SQRTL
68d4903c
JH
1860# define Perl_cos cosl
1861# define Perl_sin sinl
1862# define Perl_sqrt sqrtl
1863# define Perl_exp expl
1864# define Perl_log logl
1865# define Perl_atan2 atan2l
1866# define Perl_pow powl
1867# define Perl_floor floorl
1bbae031 1868# define Perl_ceil ceill
68d4903c
JH
1869# define Perl_fmod fmodl
1870# endif
a3540c92
JH
1871/* e.g. libsunmath doesn't have modfl and frexpl as of mid-March 2000 */
1872# ifdef HAS_MODFL
1873# define Perl_modf(x,y) modfl(x,y)
51997bc3
NC
1874/* eg glibc 2.2 series seems to provide modfl on ppc and arm, but has no
1875 prototype in <math.h> */
1876# ifndef HAS_MODFL_PROTO
a221a8a5 1877EXTERN_C long double modfl(long double, long double *);
51997bc3 1878# endif
03476e8e
JH
1879# else
1880# if defined(HAS_AINTL) && defined(HAS_COPYSIGNL)
55954f19 1881 extern long double Perl_my_modfl(long double x, long double *ip);
03476e8e
JH
1882# define Perl_modf(x,y) Perl_my_modfl(x,y)
1883# endif
a3540c92
JH
1884# endif
1885# ifdef HAS_FREXPL
dff3e0b8 1886# define Perl_frexp(x,y) frexpl(x,y)
03476e8e
JH
1887# else
1888# if defined(HAS_ILOGBL) && defined(HAS_SCALBNL)
55954f19 1889 extern long double Perl_my_frexpl(long double x, int *e);
03476e8e
JH
1890# define Perl_frexp(x,y) Perl_my_frexpl(x,y)
1891# endif
a3540c92 1892# endif
38dbb4c5 1893# ifndef Perl_isnan
758a5d79
JH
1894# ifdef HAS_ISNANL
1895# define Perl_isnan(x) isnanl(x)
1896# endif
1897# endif
1898# ifndef Perl_isinf
1899# ifdef HAS_FINITEL
1900# define Perl_isinf(x) !(finitel(x)||Perl_isnan(x))
a3540c92
JH
1901# endif
1902# endif
65202027 1903#else
2d4389e4 1904# define NV_DIG DBL_DIG
d6c14000
JH
1905# ifdef DBL_MANT_DIG
1906# define NV_MANT_DIG DBL_MANT_DIG
1907# endif
06fc1729
JH
1908# ifdef DBL_MIN
1909# define NV_MIN DBL_MIN
1910# endif
1911# ifdef DBL_MAX
1912# define NV_MAX DBL_MAX
1913# endif
1914# ifdef DBL_MIN_10_EXP
1915# define NV_MIN_10_EXP DBL_MIN_10_EXP
1916# endif
1917# ifdef DBL_MAX_10_EXP
1918# define NV_MAX_10_EXP DBL_MAX_10_EXP
1919# endif
1920# ifdef DBL_EPSILON
1921# define NV_EPSILON DBL_EPSILON
1922# endif
205f51d8 1923# ifdef DBL_MAX /* XXX Does DBL_MAX imply having DBL_MIN? */
f4a14a62
JH
1924# define NV_MAX DBL_MAX
1925# define NV_MIN DBL_MIN
1926# else
1927# ifdef HUGE_VAL
1928# define NV_MAX HUGE_VAL
1929# endif
1930# endif
65202027
DS
1931# define Perl_cos cos
1932# define Perl_sin sin
1933# define Perl_sqrt sqrt
1934# define Perl_exp exp
1935# define Perl_log log
1936# define Perl_atan2 atan2
1937# define Perl_pow pow
1938# define Perl_floor floor
1bbae031 1939# define Perl_ceil ceil
65202027 1940# define Perl_fmod fmod
a3540c92 1941# define Perl_modf(x,y) modf(x,y)
dff3e0b8 1942# define Perl_frexp(x,y) frexp(x,y)
758a5d79
JH
1943#endif
1944
1945/* rumor has it that Win32 has _fpclass() */
1946
205f51d8
AS
1947/* SGI has fpclassl... but not with the same result values,
1948 * and it's via a typedef (not via #define), so will need to redo Configure
1949 * to use. Not worth the trouble, IMO, at least until the below is used
1950 * more places. Also has fp_class_l, BTW, via fp_class.h. Feel free to check
1951 * with me for the SGI manpages, SGI testing, etcetera, if you want to
1952 * try getting this to work with IRIX. - Allen <allens@cpan.org> */
1953
758a5d79
JH
1954#if !defined(Perl_fp_class) && (defined(HAS_FPCLASS)||defined(HAS_FPCLASSL))
1955# ifdef I_IEEFP
1956# include <ieeefp.h>
1957# endif
1958# ifdef I_FP
1959# include <fp.h>
1960# endif
1961# if defined(USE_LONG_DOUBLE) && defined(HAS_FPCLASSL)
1962# define Perl_fp_class() fpclassl(x)
1963# else
1964# define Perl_fp_class() fpclass(x)
1965# endif
1966# define Perl_fp_class_snan(x) (Perl_fp_class(x)==FP_CLASS_SNAN)
1967# define Perl_fp_class_qnan(x) (Perl_fp_class(x)==FP_CLASS_QNAN)
1968# define Perl_fp_class_nan(x) (Perl_fp_class(x)==FP_CLASS_SNAN||Perl_fp_class(x)==FP_CLASS_QNAN)
1969# define Perl_fp_class_ninf(x) (Perl_fp_class(x)==FP_CLASS_NINF)
1970# define Perl_fp_class_pinf(x) (Perl_fp_class(x)==FP_CLASS_PINF)
1971# define Perl_fp_class_inf(x) (Perl_fp_class(x)==FP_CLASS_NINF||Perl_fp_class(x)==FP_CLASS_PINF)
1972# define Perl_fp_class_nnorm(x) (Perl_fp_class(x)==FP_CLASS_NNORM)
1973# define Perl_fp_class_pnorm(x) (Perl_fp_class(x)==FP_CLASS_PNORM)
1974# define Perl_fp_class_norm(x) (Perl_fp_class(x)==FP_CLASS_NNORM||Perl_fp_class(x)==FP_CLASS_PNORM)
1975# define Perl_fp_class_ndenorm(x) (Perl_fp_class(x)==FP_CLASS_NDENORM)
1976# define Perl_fp_class_pdenorm(x) (Perl_fp_class(x)==FP_CLASS_PDENORM)
1977# define Perl_fp_class_denorm(x) (Perl_fp_class(x)==FP_CLASS_NDENORM||Perl_fp_class(x)==FP_CLASS_PDENORM)
1978# define Perl_fp_class_nzero(x) (Perl_fp_class(x)==FP_CLASS_NZERO)
1979# define Perl_fp_class_pzero(x) (Perl_fp_class(x)==FP_CLASS_PZERO)
1980# define Perl_fp_class_zero(x) (Perl_fp_class(x)==FP_CLASS_NZERO||Perl_fp_class(x)==FP_CLASS_PZERO)
1981#endif
1982
7114a2d2 1983#if !defined(Perl_fp_class) && defined(HAS_FP_CLASS) && !defined(PERL_MICRO)
758a5d79
JH
1984# include <math.h>
1985# if !defined(FP_SNAN) && defined(I_FP_CLASS)
1986# include <fp_class.h>
1987# endif
1988# define Perl_fp_class(x) fp_class(x)
1989# define Perl_fp_class_snan(x) (fp_class(x)==FP_SNAN)
1990# define Perl_fp_class_qnan(x) (fp_class(x)==FP_QNAN)
1991# define Perl_fp_class_nan(x) (fp_class(x)==FP_SNAN||fp_class(x)==FP_QNAN)
1992# define Perl_fp_class_ninf(x) (fp_class(x)==FP_NEG_INF)
1993# define Perl_fp_class_pinf(x) (fp_class(x)==FP_POS_INF)
1994# define Perl_fp_class_inf(x) (fp_class(x)==FP_NEG_INF||fp_class(x)==FP_POS_INF)
1995# define Perl_fp_class_nnorm(x) (fp_class(x)==FP_NEG_NORM)
1996# define Perl_fp_class_pnorm(x) (fp_class(x)==FP_POS_NORM)
1997# define Perl_fp_class_norm(x) (fp_class(x)==FP_NEG_NORM||fp_class(x)==FP_POS_NORM)
1998# define Perl_fp_class_ndenorm(x) (fp_class(x)==FP_NEG_DENORM)
1999# define Perl_fp_class_pdenorm(x) (fp_class(x)==FP_POS_DENORM)
2000# define Perl_fp_class_denorm(x) (fp_class(x)==FP_NEG_DENORM||fp_class(x)==FP_POS_DENORM)
2001# define Perl_fp_class_nzero(x) (fp_class(x)==FP_NEG_ZERO)
2002# define Perl_fp_class_pzero(x) (fp_class(x)==FP_POS_ZERO)
2003# define Perl_fp_class_zero(x) (fp_class(x)==FP_NEG_ZERO||fp_class(x)==FP_POS_ZERO)
2004#endif
2005
2006#if !defined(Perl_fp_class) && defined(HAS_FPCLASSIFY)
2007# include <math.h>
2008# define Perl_fp_class(x) fpclassify(x)
38dbb4c5 2009# define Perl_fp_class_nan(x) (fp_classify(x)==FP_SNAN||fp_classify(x)==FP_QNAN)
758a5d79
JH
2010# define Perl_fp_class_inf(x) (fp_classify(x)==FP_INFINITE)
2011# define Perl_fp_class_norm(x) (fp_classify(x)==FP_NORMAL)
2012# define Perl_fp_class_denorm(x) (fp_classify(x)==FP_SUBNORMAL)
2013# define Perl_fp_class_zero(x) (fp_classify(x)==FP_ZERO)
2014#endif
2015
2016#if !defined(Perl_fp_class) && defined(HAS_CLASS)
2017# include <math.h>
2018# ifndef _cplusplus
2019# define Perl_fp_class(x) class(x)
2020# else
2021# define Perl_fp_class(x) _class(x)
2022# endif
2023# define Perl_fp_class_snan(x) (Perl_fp_class(x)==FP_NANS)
2024# define Perl_fp_class_qnan(x) (Perl_fp_class(x)==FP_NANQ)
2025# define Perl_fp_class_nan(x) (Perl_fp_class(x)==FP_SNAN||Perl_fp_class(x)==FP_QNAN)
2026# define Perl_fp_class_ninf(x) (Perl_fp_class(x)==FP_MINUS_INF)
2027# define Perl_fp_class_pinf(x) (Perl_fp_class(x)==FP_PLUS_INF)
2028# define Perl_fp_class_inf(x) (Perl_fp_class(x)==FP_MINUS_INF||Perl_fp_class(x)==FP_PLUS_INF)
2029# define Perl_fp_class_nnorm(x) (Perl_fp_class(x)==FP_MINUS_NORM)
2030# define Perl_fp_class_pnorm(x) (Perl_fp_class(x)==FP_PLUS_NORM)
2031# define Perl_fp_class_norm(x) (Perl_fp_class(x)==FP_MINUS_NORM||Perl_fp_class(x)==FP_PLUS_NORM)
2032# define Perl_fp_class_ndenorm(x) (Perl_fp_class(x)==FP_MINUS_DENORM)
2033# define Perl_fp_class_pdenorm(x) (Perl_fp_class(x)==FP_PLUS_DENORM)
2034# define Perl_fp_class_denorm(x) (Perl_fp_class(x)==FP_MINUS_DENORM||Perl_fp_class(x)==FP_PLUS_DENORM)
2035# define Perl_fp_class_nzero(x) (Perl_fp_class(x)==FP_MINUS_ZERO)
2036# define Perl_fp_class_pzero(x) (Perl_fp_class(x)==FP_PLUS_ZERO)
2037# define Perl_fp_class_zero(x) (Perl_fp_class(x)==FP_MINUS_ZERO||Perl_fp_class(x)==FP_PLUS_ZERO)
2038#endif
2039
2040/* rumor has it that Win32 has _isnan() */
2041
2042#ifndef Perl_isnan
a3540c92 2043# ifdef HAS_ISNAN
758a5d79
JH
2044# define Perl_isnan(x) isnan((NV)x)
2045# else
2046# ifdef Perl_fp_class_nan
2047# define Perl_isnan(x) Perl_fp_class_nan(x)
2048# else
2049# ifdef HAS_UNORDERED
2050# define Perl_isnan(x) unordered((x), 0.0)
2051# else
2052# define Perl_isnan(x) ((x)!=(x))
2053# endif
2054# endif
2055# endif
2056#endif
2057
ca6c63e1
JH
2058#ifdef UNDER_CE
2059int isnan(double d);
2060#endif
2061
758a5d79
JH
2062#ifndef Perl_isinf
2063# ifdef HAS_ISINF
2064# define Perl_isinf(x) isinf((NV)x)
a3540c92 2065# else
758a5d79
JH
2066# ifdef Perl_fp_class_inf
2067# define Perl_isinf(x) Perl_fp_class_inf(x)
2068# else
2069# define Perl_isinf(x) ((x)==NV_INF)
2070# endif
2071# endif
2072#endif
2073
2074#ifndef Perl_isfinite
2075# ifdef HAS_FINITE
2076# define Perl_isfinite(x) finite((NV)x)
2077# else
2078# ifdef HAS_ISFINITE
2079# define Perl_isfinite(x) isfinite(x)
2080# else
2081# ifdef Perl_fp_class_finite
2082# define Perl_isfinite(x) Perl_fp_class_finite(x)
2083# else
2084# define Perl_isfinite(x) !(Perl_is_inf(x)||Perl_is_nan(x))
2085# endif
2086# endif
a3540c92 2087# endif
65202027
DS
2088#endif
2089
a36244b7
JH
2090/* The default is to use Perl's own atof() implementation (in numeric.c).
2091 * Usually that is the one to use but for some platforms (e.g. UNICOS)
2092 * it is however best to use the native implementation of atof.
2093 * You can experiment with using your native one by -DUSE_PERL_ATOF=0.
2094 * Some good tests to try out with either setting are t/base/num.t,
205f51d8
AS
2095 * t/op/numconvert.t, and t/op/pack.t. Note that if using long doubles
2096 * you may need to be using a different function than atof! */
a36244b7
JH
2097
2098#ifndef USE_PERL_ATOF
2099# ifndef _UNICOS
2100# define USE_PERL_ATOF
2101# endif
2102#else
2103# if USE_PERL_ATOF == 0
2104# undef USE_PERL_ATOF
2105# endif
2106#endif
2107
2108#ifdef USE_PERL_ATOF
2109# define Perl_atof(s) Perl_my_atof(s)
2110# define Perl_atof2(s, n) Perl_my_atof2(aTHX_ (s), &(n))
2111#else
2112# define Perl_atof(s) (NV)atof(s)
2113# define Perl_atof2(s, n) ((n) = atof(s))
2114#endif
cf2093f6 2115
d460ef45 2116/* Previously these definitions used hardcoded figures.
760ac839
LW
2117 * It is hoped these formula are more portable, although
2118 * no data one way or another is presently known to me.
2119 * The "PERL_" names are used because these calculated constants
2120 * do not meet the ANSI requirements for LONG_MAX, etc., which
2121 * need to be constants acceptable to #if - kja
2122 * define PERL_LONG_MAX 2147483647L
2123 * define PERL_LONG_MIN (-LONG_MAX - 1)
2124 * define PERL ULONG_MAX 4294967295L
2125 */
2126
2127#ifdef I_LIMITS /* Needed for cast_xxx() functions below. */
2128# include <limits.h>
760ac839 2129#endif
205f51d8
AS
2130/* Included values.h above if necessary; still including limits.h down here,
2131 * despite doing above, because math.h might have overriden... XXX - Allen */
760ac839 2132
99abf803
PP
2133/*
2134 * Try to figure out max and min values for the integral types. THE CORRECT
2135 * SOLUTION TO THIS MESS: ADAPT enquire.c FROM GCC INTO CONFIGURE. The
2136 * following hacks are used if neither limits.h or values.h provide them:
2137 * U<TYPE>_MAX: for types >= int: ~(unsigned TYPE)0
2138 * for types < int: (unsigned TYPE)~(unsigned)0
2139 * The argument to ~ must be unsigned so that later signed->unsigned
2140 * conversion can't modify the value's bit pattern (e.g. -0 -> +0),
2141 * and it must not be smaller than int because ~ does integral promotion.
2142 * <type>_MAX: (<type>) (U<type>_MAX >> 1)
2143 * <type>_MIN: -<type>_MAX - <is_twos_complement_architecture: (3 & -1) == 3>.
2144 * The latter is a hack which happens to work on some machines but
2145 * does *not* catch any random system, or things like integer types
2146 * with NaN if that is possible.
2147 *
2148 * All of the types are explicitly cast to prevent accidental loss of
2149 * numeric range, and in the hope that they will be less likely to confuse
2150 * over-eager optimizers.
2151 *
2152 */
27d4fb96 2153
99abf803
PP
2154#define PERL_UCHAR_MIN ((unsigned char)0)
2155
2156#ifdef UCHAR_MAX
2157# define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX)
27d4fb96 2158#else
99abf803
PP
2159# ifdef MAXUCHAR
2160# define PERL_UCHAR_MAX ((unsigned char)MAXUCHAR)
27d4fb96 2161# else
99abf803 2162# define PERL_UCHAR_MAX ((unsigned char)~(unsigned)0)
27d4fb96
PP
2163# endif
2164#endif
d460ef45 2165
99abf803
PP
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
99abf803
PP
2175#define PERL_USHORT_MIN ((unsigned short)0)
2176
2177#ifdef USHORT_MAX
2178# define PERL_USHORT_MAX ((unsigned short)USHORT_MAX)
27d4fb96 2179#else
99abf803
PP
2180# ifdef MAXUSHORT
2181# define PERL_USHORT_MAX ((unsigned short)MAXUSHORT)
27d4fb96 2182# else
ef2f54b0
CB
2183# ifdef USHRT_MAX
2184# define PERL_USHORT_MAX ((unsigned short)USHRT_MAX)
2185# else
2186# define PERL_USHORT_MAX ((unsigned short)~(unsigned)0)
2187# endif
27d4fb96
PP
2188# endif
2189#endif
2190
27d4fb96 2191#ifdef SHORT_MAX
99abf803 2192# define PERL_SHORT_MAX ((short)SHORT_MAX)
27d4fb96
PP
2193#else
2194# ifdef MAXSHORT /* Often used in <values.h> */
99abf803 2195# define PERL_SHORT_MAX ((short)MAXSHORT)
27d4fb96 2196# else
ef2f54b0
CB
2197# ifdef SHRT_MAX
2198# define PERL_SHORT_MAX ((short)SHRT_MAX)
2199# else
2200# define PERL_SHORT_MAX ((short) (PERL_USHORT_MAX >> 1))
2201# endif
27d4fb96
PP
2202# endif
2203#endif
2204
2205#ifdef SHORT_MIN
99abf803 2206# define PERL_SHORT_MIN ((short)SHORT_MIN)
27d4fb96
PP
2207#else
2208# ifdef MINSHORT
99abf803 2209# define PERL_SHORT_MIN ((short)MINSHORT)
27d4fb96 2210# else
ef2f54b0
CB
2211# ifdef SHRT_MIN
2212# define PERL_SHORT_MIN ((short)SHRT_MIN)
2213# else
2214# define PERL_SHORT_MIN (-PERL_SHORT_MAX - ((3 & -1) == 3))
2215# endif
27d4fb96
PP
2216# endif
2217#endif
2218
99abf803
PP
2219#ifdef UINT_MAX
2220# define PERL_UINT_MAX ((unsigned int)UINT_MAX)
27d4fb96 2221#else
99abf803
PP
2222# ifdef MAXUINT
2223# define PERL_UINT_MAX ((unsigned int)MAXUINT)
27d4fb96 2224# else
99abf803 2225# define PERL_UINT_MAX (~(unsigned int)0)
27d4fb96
PP
2226# endif
2227#endif
2228
99abf803 2229#define PERL_UINT_MIN ((unsigned int)0)
27d4fb96
PP
2230
2231#ifdef INT_MAX
99abf803 2232# define PERL_INT_MAX ((int)INT_MAX)
27d4fb96
PP
2233#else
2234# ifdef MAXINT /* Often used in <values.h> */
99abf803 2235# define PERL_INT_MAX ((int)MAXINT)
27d4fb96 2236# else
99abf803 2237# define PERL_INT_MAX ((int)(PERL_UINT_MAX >> 1))
27d4fb96
PP
2238# endif
2239#endif
2240
2241#ifdef INT_MIN
99abf803 2242# define PERL_INT_MIN ((int)INT_MIN)
27d4fb96
PP
2243#else
2244# ifdef MININT
99abf803 2245# define PERL_INT_MIN ((int)MININT)
27d4fb96
PP
2246# else
2247# define PERL_INT_MIN (-PERL_INT_MAX - ((3 & -1) == 3))
2248# endif
2249#endif
2250
99abf803
PP
2251#ifdef ULONG_MAX
2252# define PERL_ULONG_MAX ((unsigned long)ULONG_MAX)
27d4fb96 2253#else
99abf803
PP
2254# ifdef MAXULONG
2255# define PERL_ULONG_MAX ((unsigned long)MAXULONG)
27d4fb96 2256# else
99abf803 2257# define PERL_ULONG_MAX (~(unsigned long)0)
27d4fb96
PP
2258# endif
2259#endif
2260
99abf803 2261#define PERL_ULONG_MIN ((unsigned long)0L)
27d4fb96 2262
760ac839 2263#ifdef LONG_MAX
99abf803 2264# define PERL_LONG_MAX ((long)LONG_MAX)
760ac839
LW
2265#else
2266# ifdef MAXLONG /* Often used in <values.h> */
99abf803 2267# define PERL_LONG_MAX ((long)MAXLONG)
760ac839 2268# else
99abf803 2269# define PERL_LONG_MAX ((long) (PERL_ULONG_MAX >> 1))
760ac839
LW
2270# endif
2271#endif
2272
2273#ifdef LONG_MIN
99abf803 2274# define PERL_LONG_MIN ((long)LONG_MIN)
760ac839
LW
2275#else
2276# ifdef MINLONG
99abf803 2277# define PERL_LONG_MIN ((long)MINLONG)
760ac839 2278# else
27d4fb96 2279# define PERL_LONG_MIN (-PERL_LONG_MAX - ((3 & -1) == 3))
760ac839
LW
2280# endif
2281#endif
2282
d7d93a81 2283#ifdef UV_IS_QUAD
99abf803 2284
99abf803 2285# define PERL_UQUAD_MAX (~(UV)0)
f1c3b19a 2286# define PERL_UQUAD_MIN ((UV)0)
99abf803 2287# define PERL_QUAD_MAX ((IV) (PERL_UQUAD_MAX >> 1))
a6e633de 2288# define PERL_QUAD_MIN (-PERL_QUAD_MAX - ((3 & -1) == 3))
27d4fb96 2289
79072805
LW
2290#endif
2291
22f7c9c9
JH
2292#ifdef MYMALLOC
2293# include "malloc_ctl.h"
2294#endif
2295
830247a4 2296struct RExC_state_t;
8e11feef 2297struct _reg_trie_data;
880b20b6 2298
ee0007ab 2299typedef MEM_SIZE STRLEN;
450a55e4 2300
598921a7
NC
2301#ifdef PERL_MAD
2302typedef struct token TOKEN;
2303typedef struct madprop MADPROP;
2304typedef struct nexttoken NEXTTOKE;
2305#endif
79072805
LW
2306typedef struct op OP;
2307typedef struct cop COP;
2308typedef struct unop UNOP;
2309typedef struct binop BINOP;
2310typedef struct listop LISTOP;
2311typedef struct logop LOGOP;
79072805
LW
2312typedef struct pmop PMOP;
2313typedef struct svop SVOP;
7934575e 2314typedef struct padop PADOP;
79072805 2315typedef struct pvop PVOP;
79072805
LW
2316typedef struct loop LOOP;
2317
cd1541b2
NC
2318typedef struct interpreter PerlInterpreter;
2319
d2b3f365
SS
2320/* Amdahl's <ksync.h> has struct sv */
2321/* SGI's <sys/sema.h> has struct sv */
2322#if defined(UTS) || defined(__sgi)
2323# define STRUCT_SV perl_sv
b8d3c5db
JH
2324#else
2325# define STRUCT_SV sv
2326#endif
2327typedef struct STRUCT_SV SV;
79072805
LW
2328typedef struct av AV;
2329typedef struct hv HV;
2330typedef struct cv CV;
378cc40b 2331typedef struct regexp REGEXP;
79072805 2332typedef struct gp GP;
0c30d9ec 2333typedef struct gv GV;
8990e307 2334typedef struct io IO;
c09156bb 2335typedef struct context PERL_CONTEXT;
79072805
LW
2336typedef struct block BLOCK;
2337
2338typedef struct magic MAGIC;
2339typedef struct xpv XPV;
2340typedef struct xpviv XPVIV;
ff68c719 2341typedef struct xpvuv XPVUV;
79072805
LW
2342typedef struct xpvnv XPVNV;
2343typedef struct xpvmg XPVMG;
2344typedef struct xpvlv XPVLV;
2345typedef struct xpvav XPVAV;
2346typedef struct xpvhv XPVHV;
2347typedef struct xpvgv XPVGV;
2348typedef struct xpvcv XPVCV;
2349typedef struct xpvbm XPVBM;
2350typedef struct xpvfm XPVFM;
8990e307 2351typedef struct xpvio XPVIO;
79072805
LW
2352typedef struct mgvtbl MGVTBL;
2353typedef union any ANY;
5f7fde29
GS
2354typedef struct ptr_tbl_ent PTR_TBL_ENT_t;
2355typedef struct ptr_tbl PTR_TBL_t;
8cf8f3d1
NIS
2356typedef struct clone_params CLONE_PARAMS;
2357
378cc40b 2358#include "handy.h"
a0d0e21e 2359
6b8eaf93 2360#if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_RAWIO)
6b8eaf93
JH
2361# if LSEEKSIZE == 8 && !defined(USE_64_BIT_RAWIO)
2362# define USE_64_BIT_RAWIO /* implicit */
2363# endif
4564133c
JH
2364#endif
2365
6b8eaf93
JH
2366/* Notice the use of HAS_FSEEKO: now we are obligated to always use
2367 * fseeko/ftello if possible. Don't go #defining ftell to ftello yourself,
2368 * however, because operating systems like to do that themself. */
2369#ifndef FSEEKSIZE
2370# ifdef HAS_FSEEKO
2371# define FSEEKSIZE LSEEKSIZE
2372# else
2373# define FSEEKSIZE LONGSIZE
d460ef45 2374# endif
6b8eaf93
JH
2375#endif
2376
2377#if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_STDIO)
6b8eaf93
JH
2378# if FSEEKSIZE == 8 && !defined(USE_64_BIT_STDIO)
2379# define USE_64_BIT_STDIO /* implicit */
2380# endif
2381#endif
4564133c 2382
09458382 2383#ifdef USE_64_BIT_RAWIO
d9b3e12d
JH
2384# ifdef HAS_OFF64_T
2385# undef Off_t
2386# define Off_t off64_t
2387# undef LSEEKSIZE
2388# define LSEEKSIZE 8
5ff3f7a4 2389# endif
d9b3e12d
JH
2390/* Most 64-bit environments have defines like _LARGEFILE_SOURCE that
2391 * will trigger defines like the ones below. Some 64-bit environments,
09458382 2392 * however, do not. Therefore we have to explicitly mix and match. */
d9b3e12d
JH
2393# if defined(USE_OPEN64)
2394# define open open64
5ff3f7a4 2395# endif
d9b3e12d
JH
2396# if defined(USE_LSEEK64)
2397# define lseek lseek64
6b8eaf93
JH
2398# else
2399# if defined(USE_LLSEEK)
2400# define lseek llseek
2401# endif
d9b3e12d
JH
2402# endif
2403# if defined(USE_STAT64)
2404# define stat stat64
2405# endif
2406# if defined(USE_FSTAT64)
2407# define fstat fstat64
2408# endif
2409# if defined(USE_LSTAT64)
2410# define lstat lstat64
2411# endif
2412# if defined(USE_FLOCK64)
2413# define flock flock64
2414# endif
2415# if defined(USE_LOCKF64)
2416# define lockf lockf64
2417# endif
2418# if defined(USE_FCNTL64)
2419# define fcntl fcntl64
2420# endif
2421# if defined(USE_TRUNCATE64)
2422# define truncate truncate64
2423# endif
2424# if defined(USE_FTRUNCATE64)
2425# define ftruncate ftruncate64
2426# endif
2427#endif
2428
2429#ifdef USE_64_BIT_STDIO
2430# ifdef HAS_FPOS64_T
2431# undef Fpos_t
2432# define Fpos_t fpos64_t
2433# endif
2434/* Most 64-bit environments have defines like _LARGEFILE_SOURCE that
2435 * will trigger defines like the ones below. Some 64-bit environments,
2436 * however, do not. */
2437# if defined(USE_FOPEN64)
2438# define fopen fopen64
2439# endif
2440# if defined(USE_FSEEK64)
6b8eaf93 2441# define fseek fseek64 /* don't do fseeko here, see perlio.c */
d9b3e12d
JH
2442# endif
2443# if defined(USE_FTELL64)
6b8eaf93 2444# define ftell ftell64 /* don't do ftello here, see perlio.c */
d9b3e12d
JH
2445# endif
2446# if defined(USE_FSETPOS64)
2447# define fsetpos fsetpos64
2448# endif
2449# if defined(USE_FGETPOS64)
2450# define fgetpos fgetpos64
2451# endif
2452# if defined(USE_TMPFILE64)
2453# define tmpfile tmpfile64
2454# endif
2455# if defined(USE_FREOPEN64)
2456# define freopen freopen64
5ff3f7a4
GS
2457# endif
2458#endif
2459
af8b425d 2460#if defined(OS2) || defined(MACOS_TRADITIONAL)
2c2d71f5
JH
2461# include "iperlsys.h"
2462#endif
2463
6f71a643 2464#if defined(__OPEN_VM)
19848b3f
JH
2465# include "vmesa/vmesaish.h"
2466# define ISHISH "vmesa"
6f71a643
JH
2467#endif
2468
748a9306 2469#ifdef DOSISH
19848b3f
JH
2470# if defined(OS2)
2471# include "os2ish.h"
2472# else
2473# include "dosish.h"
2474# endif
2475# define ISHISH "dos"
2476#endif
2477
2478#if defined(VMS)
748a9306 2479# include "vmsish.h"
96e176bf 2480# include "embed.h"
eb8433b7
NC
2481# ifndef PERL_MAD
2482# undef op_getmad
b3f24c00 2483# define op_getmad(arg,pegop,slot) NOOP
eb8433b7 2484# endif
19848b3f
JH
2485# define ISHISH "vms"
2486#endif
2487
2488#if defined(PLAN9)
2489# include "./plan9/plan9ish.h"
2490# define ISHISH "plan9"
2491#endif
2492
2493#if defined(MPE)
2494# include "mpeix/mpeixish.h"
2495# define ISHISH "mpeix"
2496#endif
2497
2498#if defined(__VOS__)
196918b0
PG
2499# ifdef __GNUC__
2500# include "./vos/vosish.h"
2501# else
2502# include "vos/vosish.h"
2503# endif
19848b3f
JH
2504# define ISHISH "vos"
2505#endif
2506
2507#if defined(EPOC)
2508# include "epocish.h"
2509# define ISHISH "epoc"
2510#endif
2511
9969cdde 2512#ifdef __SYMBIAN32__
27da23d5
JH
2513# include "symbian/symbianish.h"
2514# include "embed.h"
eb8433b7
NC
2515# ifndef PERL_MAD
2516# undef op_getmad
b3f24c00 2517# define op_getmad(arg,pegop,slot) NOOP
eb8433b7 2518# endif
27da23d5
JH
2519# define ISHISH "symbian"
2520#endif
2521
19848b3f
JH
2522#if defined(MACOS_TRADITIONAL)
2523# include "macos/macish.h"
2524# ifndef NO_ENVIRON_ARRAY
2525# define NO_ENVIRON_ARRAY
0c30d9ec 2526# endif
19848b3f
JH
2527# define ISHISH "macos classic"
2528#endif
2529
efca5cc6
JH
2530#if defined(__BEOS__)
2531# include "beos/beosish.h"
2532# define ISHISH "beos"
2533#endif
2534
19848b3f
JH
2535#ifndef ISHISH
2536# include "unixish.h"
2537# define ISHISH "unix"
13b6e58c
JH
2538#endif
2539
2946a158
JH
2540/* NSIG logic from Configure --> */
2541/* Strange style to avoid deeply-nested #if/#else/#endif */
2542#ifndef NSIG
2543# ifdef _NSIG
2544# define NSIG (_NSIG)
2545# endif
2546#endif
2547
2548#ifndef NSIG
2549# ifdef SIGMAX
2550# define NSIG (SIGMAX+1)
2551# endif
2552#endif
2553
2554#ifndef NSIG
2555# ifdef SIG_MAX
2556# define NSIG (SIG_MAX+1)
2557# endif
2558#endif
2559
2560#ifndef NSIG
2561# ifdef _SIG_MAX
2562# define NSIG (_SIG_MAX+1)
2563# endif
2564#endif
2565
2566#ifndef NSIG
2567# ifdef MAXSIG
2568# define NSIG (MAXSIG+1)
2569# endif
2570#endif
2571
2572#ifndef NSIG
2573# ifdef MAX_SIG
2574# define NSIG (MAX_SIG+1)
2575# endif
2576#endif
2577
2578#ifndef NSIG
2579# ifdef SIGARRAYSIZE
2580# define NSIG SIGARRAYSIZE /* Assume ary[SIGARRAYSIZE] */
2581# endif
2582#endif
2583
2584#ifndef NSIG
2585# ifdef _sys_nsig
2586# define NSIG (_sys_nsig) /* Solaris 2.5 */
2587# endif
2588#endif
2589
2590/* Default to some arbitrary number that's big enough to get most
2591 of the common signals.
2592*/
2593#ifndef NSIG
2594# define NSIG 50
2595#endif
2596/* <-- NSIG logic from Configure */
2597
13b6e58c
JH
2598#ifndef NO_ENVIRON_ARRAY
2599# define USE_ENVIRON_ARRAY
2600#endif
32f822de 2601
c77b533b
JH
2602/*
2603 * initialise to avoid floating-point exceptions from overflow, etc
2604 */
2605#ifndef PERL_FPU_INIT
2606# ifdef HAS_FPSETMASK
2607# if HAS_FLOATINGPOINT_H
2608# include <floatingpoint.h>
2609# endif
7f7c3354 2610# define PERL_FPU_INIT fpsetmask(0)
c77b533b 2611# else
2f42fcb0 2612# if defined(SIGFPE) && defined(SIG_IGN) && !defined(PERL_MICRO)
7f7c3354 2613# define PERL_FPU_INIT PL_sigfpe_saved = (Sighandler_t) signal(SIGFPE, SIG_IGN)
b35112e7
CS
2614# define PERL_FPU_PRE_EXEC { Sigsave_t xfpe; rsignal_save(SIGFPE, PL_sigfpe_saved, &xfpe);
2615# define PERL_FPU_POST_EXEC rsignal_restore(SIGFPE, &xfpe); }
7014c407
JH
2616# else
2617# define PERL_FPU_INIT
2f42fcb0 2618
7014c407 2619# endif
c77b533b
JH
2620# endif
2621#endif
b35112e7
CS
2622#ifndef PERL_FPU_PRE_EXEC
2623# define PERL_FPU_PRE_EXEC {
2624# define PERL_FPU_POST_EXEC }
2625#endif
c77b533b 2626
ed344e4f
IZ
2627#ifndef PERL_SYS_INIT3
2628# define PERL_SYS_INIT3(argvp,argcp,envp) PERL_SYS_INIT(argvp,argcp)
2629#endif
2630
be708cc0
JH
2631#ifndef PERL_WRITE_MSG_TO_CONSOLE
2632# define PERL_WRITE_MSG_TO_CONSOLE(io, msg, len) PerlIO_write(io, msg, len)
2633#endif
2634
0f31cffe
GS
2635#ifndef MAXPATHLEN
2636# ifdef PATH_MAX
b990c8b2
JH
2637# ifdef _POSIX_PATH_MAX
2638# if PATH_MAX > _POSIX_PATH_MAX
09448d78
JH
2639/* POSIX 1990 (and pre) was ambiguous about whether PATH_MAX
2640 * included the null byte or not. Later amendments of POSIX,
2641 * XPG4, the Austin Group, and the Single UNIX Specification
2642 * all explicitly include the null byte in the PATH_MAX.
2643 * Ditto for _POSIX_PATH_MAX. */
2644# define MAXPATHLEN PATH_MAX
b990c8b2 2645# else
09448d78 2646# define MAXPATHLEN _POSIX_PATH_MAX
b990c8b2
JH
2647# endif
2648# else
2649# define MAXPATHLEN (PATH_MAX+1)
2650# endif
0f31cffe 2651# else
b990c8b2 2652# ifdef _POSIX_PATH_MAX
09448d78 2653# define MAXPATHLEN _POSIX_PATH_MAX
b990c8b2
JH
2654# else
2655# define MAXPATHLEN 1024 /* Err on the large side. */
2656# endif
0f31cffe
GS
2657# endif
2658#endif
2659
c80263a8
SH
2660/* In case Configure was not used (we are using a "canned config"
2661 * such as Win32, or a cross-compilation setup, for example) try going
2662 * by the gcc major and minor versions. One useful URL is
2663 * http://www.ohse.de/uwe/articles/gcc-attributes.html,
2664 * but contrary to this information warn_unused_result seems
2665 * not to be in gcc 3.3.5, at least. --jhi
42bf5550
AD
2666 * Also, when building extensions with an installed perl, this allows
2667 * the user to upgrade gcc and get the right attributes, rather than
2668 * relying on the list generated at Configure time. --AD
c80263a8
SH
2669 * Set these up now otherwise we get confused when some of the <*thread.h>
2670 * includes below indirectly pull in <perlio.h> (which needs to know if we
2671 * have HASATTRIBUTE_FORMAT).
2672 */
2673
fc2007d4 2674#if defined __GNUC__ && !defined(__INTEL_COMPILER)
c80263a8
SH
2675# if __GNUC__ >= 3 /* 3.0 -> */ /* XXX Verify this version */
2676# define HASATTRIBUTE_FORMAT
63cdf24b
SH
2677# if defined __MINGW32__
2678# define PRINTF_FORMAT_NULL_OK
2679# endif
c80263a8
SH
2680# endif
2681# if __GNUC__ >= 3 /* 3.0 -> */
2682# define HASATTRIBUTE_MALLOC
2683# endif
2684# if __GNUC__ == 3 && __GNUC_MINOR__ >= 3 || __GNUC__ > 3 /* 3.3 -> */
2685# define HASATTRIBUTE_NONNULL
2686# endif
2687# if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 || __GNUC__ > 2 /* 2.5 -> */
2688# define HASATTRIBUTE_NORETURN
2689# endif
2690# if __GNUC__ >= 3 /* gcc 3.0 -> */
2691# define HASATTRIBUTE_PURE
2692# endif
42bf5550 2693# if __GNUC__ == 3 && __GNUC_MINOR__ >= 4 || __GNUC__ > 3 /* 3.4 -> */
c80263a8
SH
2694# define HASATTRIBUTE_UNUSED
2695# endif
d324fe49
AD
2696# if __GNUC__ == 3 && __GNUC_MINOR__ == 3 && !defined(__cplusplus)
2697# define HASATTRIBUTE_UNUSED /* gcc-3.3, but not g++-3.3. */
2698# endif
c80263a8
SH
2699# if __GNUC__ == 3 && __GNUC_MINOR__ >= 4 || __GNUC__ > 3 /* 3.4 -> */
2700# define HASATTRIBUTE_WARN_UNUSED_RESULT
2701# endif
2702#endif
2703
3db8f154 2704/* USE_5005THREADS needs to be after unixish.h as <pthread.h> includes
dd96f567 2705 * <sys/signal.h> which defines NSIG - which will stop inclusion of <signal.h>
32f822de
GS
2706 * this results in many functions being undeclared which bothers C++
2707 * May make sense to have threads after "*ish.h" anyway
2708 */
2709
3db8f154 2710#if defined(USE_ITHREADS)
2986a63f
JH
2711# ifdef NETWARE
2712# include <nw5thread.h>
2713# else
32f822de
GS
2714# ifdef FAKE_THREADS
2715# include "fakethr.h"
2716# else
2717# ifdef WIN32
2718# include <win32thread.h>
2719# else
dd96f567
IZ
2720# ifdef OS2
2721# include "os2thread.h"
2722# else
7f3d1cf1 2723# ifdef I_MACH_CTHREADS
bdd66968 2724# include <mach/cthreads.h>
8f1f23e8 2725# if (defined(NeXT) || defined(__NeXT__)) && defined(PERL_POLLUTE_MALLOC)
772fe5b3
HM
2726# define MUTEX_INIT_CALLS_MALLOC
2727# endif
7f3d1cf1
BH
2728typedef cthread_t perl_os_thread;
2729typedef mutex_t perl_mutex;
2730typedef condition_t perl_cond;
2731typedef void * perl_key;
2732# else /* Posix threads */
1f5ae88c
JH
2733# ifdef I_PTHREAD
2734# include <pthread.h>
2735# endif
7f3d1cf1
BH
2736typedef pthread_t perl_os_thread;
2737typedef pthread_mutex_t perl_mutex;
2738typedef pthread_cond_t perl_cond;
2739typedef pthread_key_t perl_key;
2740# endif /* I_MACH_CTHREADS */
dd96f567 2741# endif /* OS2 */
32f822de
GS
2742# endif /* WIN32 */
2743# endif /* FAKE_THREADS */
2986a63f 2744#endif /* NETWARE */
3db8f154 2745#endif /* USE_ITHREADS */
c5be433b 2746
66a93824 2747#if defined(WIN32)
1feb2720 2748# include "win32.h"
c5be433b
GS
2749#endif
2750
2986a63f
JH
2751#ifdef NETWARE
2752# include "netware.h"
2753#endif
2754
e5218da5 2755#define STATUS_UNIX PL_statusvalue
68dc0745 2756#ifdef VMS
6b88bc9c 2757# define STATUS_NATIVE PL_statusvalue_vms
7a7fd8e0
JM
2758/*
2759 * vaxc$errno is only guaranteed to be valid if errno == EVMSERR, otherwise
ff7298cb 2760 * its contents can not be trusted. Unfortunately, Perl seems to check
7a7fd8e0
JM
2761 * it on exit, so it when PL_statusvalue_vms is updated, vaxc$errno should
2762 * be updated also.
2763 */
2764# include <stsdef.h>
2765# include <ssdef.h>
2766/* Presume this because if VMS changes it, it will require a new
2767 * set of APIs for waiting on children for binary compatibility.
2768 */
2769# define child_offset_bits (8)
2770# ifndef C_FAC_POSIX
2771# define C_FAC_POSIX 0x35A000
2772# endif
2773
2774/* STATUS_EXIT - validates and returns a NATIVE exit status code for the
2775 * platform from the existing UNIX or Native status values.
2776 */
2777
37038d91 2778# define STATUS_EXIT \
7a7fd8e0
JM
2779 (((I32)PL_statusvalue_vms == -1 ? SS$_ABORT : PL_statusvalue_vms) | \
2780 (VMSISH_HUSHED ? STS$M_INHIB_MSG : 0))
2781
7a7fd8e0 2782
fb38d079
JM
2783/* STATUS_NATIVE_CHILD_SET - Calculate UNIX status that matches the child
2784 * exit code and shifts the UNIX value over the correct number of bits to
2785 * be a child status. Usually the number of bits is 8, but that could be
2786 * platform dependent. The NATIVE status code is presumed to have either
2787 * from a child process.
7a7fd8e0
JM
2788 */
2789
fb38d079
JM
2790/* This is complicated. The child processes return a true native VMS
2791 status which must be saved. But there is an assumption in Perl that
2792 the UNIX child status has some relationship to errno values, so
2793 Perl tries to translate it to text in some of the tests.
2794 In order to get the string translation correct, for the error, errno
2795 must be EVMSERR, but that generates a different text message
2796 than what the test programs are expecting. So an errno value must
2797 be derived from the native status value when an error occurs.
2798 That will hide the true native status message. With this version of
2799 perl, the true native child status can always be retrieved so that
2800 is not a problem. But in this case, Pl_statusvalue and errno may
2801 have different values in them.
2802 */
7a7fd8e0 2803
fb38d079 2804# define STATUS_NATIVE_CHILD_SET(n) \
68dc0745 2805 STMT_START { \
2fbb330f
JM
2806 I32 evalue = (I32)n; \
2807 if (evalue == EVMSERR) { \
2808 PL_statusvalue_vms = vaxc$errno; \
2809 PL_statusvalue = evalue; \
7a7fd8e0 2810 } else { \
2fbb330f 2811 PL_statusvalue_vms = evalue; \
fb38d079 2812 if (evalue == -1) { \
3280af22 2813 PL_statusvalue = -1; \
7a7fd8e0
JM
2814 PL_statusvalue_vms = SS$_ABORT; /* Should not happen */ \
2815 } else \
fb38d079 2816 PL_statusvalue = Perl_vms_status_to_unix(evalue, 1); \
2fbb330f 2817 set_vaxc_errno(evalue); \
fb38d079
JM
2818 if ((PL_statusvalue_vms & C_FAC_POSIX) == C_FAC_POSIX) \
2819 set_errno(EVMSERR); \
2820 else set_errno(Perl_vms_status_to_unix(evalue, 0)); \
2821 PL_statusvalue = PL_statusvalue << child_offset_bits; \
2fbb330f 2822 } \
68dc0745 2823 } STMT_END
7a7fd8e0 2824
68dc0745 2825# ifdef VMSISH_STATUS
e5218da5 2826# define STATUS_CURRENT (VMSISH_STATUS ? STATUS_NATIVE : STATUS_UNIX)
68dc0745 2827# else
e5218da5 2828# define STATUS_CURRENT STATUS_UNIX
68dc0745 2829# endif
7a7fd8e0
JM
2830
2831 /* STATUS_UNIX_SET - takes a UNIX/POSIX errno value and attempts to update
2832 * the NATIVE status to an equivalent value. Can not be used to translate
2833 * exit code values as exit code values are not guaranteed to have any
2834 * relationship at all to errno values.
2835 * This is used when Perl is forcing errno to have a specific value.
2836 */
e5218da5 2837# define STATUS_UNIX_SET(n) \
68dc0745 2838 STMT_START { \
7a7fd8e0 2839 I32 evalue = (I32)n; \
0968cdad 2840 PL_statusvalue = evalue; \
3280af22 2841 if (PL_statusvalue != -1) { \
0968cdad
JM
2842 if (PL_statusvalue != EVMSERR) { \
2843 PL_statusvalue &= 0xFFFF; \
2844 if (MY_POSIX_EXIT) \
2845 PL_statusvalue_vms=PL_statusvalue ? SS$_ABORT : SS$_NORMAL;\
2846 else PL_statusvalue_vms = Perl_unix_status_to_vms(evalue); \
2847 } \
2848 else { \
2849 PL_statusvalue_vms = vaxc$errno; \
2850 } \
68dc0745 2851 } \
0968cdad
JM
2852 else PL_statusvalue_vms = SS$_ABORT; \
2853 set_vaxc_errno(PL_statusvalue_vms); \
7a7fd8e0
JM
2854 } STMT_END
2855
2856 /* STATUS_UNIX_EXIT_SET - Takes a UNIX/POSIX exit code and sets
2857 * the NATIVE error status based on it. It does not assume that
fb38d079
JM
2858 * the UNIX/POSIX exit codes have any relationship to errno, except
2859 * that 0 indicates a success. When in the default mode to comply
6ac6a52b
JM
2860 * with the Perl VMS documentation, any other code sets the NATIVE
2861 * status to a failure code of SS$_ABORT.
fb38d079
JM
2862 *
2863 * In the new POSIX EXIT mode, native status will be set so that the
2864 * actual exit code will can be retrieved by the calling program or
2865 * shell.
2866 *
2867 * If the exit code is not clearly a UNIX parent or child exit status,
2868 * it will be passed through as a VMS status.
7a7fd8e0
JM
2869 */
2870
fb38d079 2871# define STATUS_UNIX_EXIT_SET(n) \
7a7fd8e0
JM
2872 STMT_START { \
2873 I32 evalue = (I32)n; \
2874 PL_statusvalue = evalue; \
fb38d079
JM
2875 if (evalue != -1) { \
2876 if (evalue <= 0xFF00) { \
2877 if (evalue > 0xFF) \
2878 evalue = (evalue >> child_offset_bits) & 0xFF; \
2879 if (evalue == 0) \
2880 PL_statusvalue_vms == SS$_NORMAL; \
2881 else \
2882 if (MY_POSIX_EXIT) \
2883 PL_statusvalue_vms = \
2884 (C_FAC_POSIX | (evalue << 3 ) | (evalue == 1)? \
52e64fc8 2885 (STS$K_ERROR | STS$M_INHIB_MSG) : 1); \
0968cdad 2886 else \
6ac6a52b 2887 PL_statusvalue_vms = SS$_ABORT; \
fb38d079
JM
2888 } else { /* forgive them Perl, for they have sinned */ \
2889 if (evalue != EVMSERR) PL_statusvalue_vms = evalue; \
2890 else PL_statusvalue_vms = vaxc$errno; \
2891 /* And obviously used a VMS status value instead of UNIX */ \
2892 PL_statusvalue = EVMSERR; \
2893 } \
7a7fd8e0
JM
2894 } \
2895 else PL_statusvalue_vms = SS$_ABORT; \
2896 set_vaxc_errno(PL_statusvalue_vms); \
68dc0745 2897 } STMT_END
fb38d079 2898
6ac6a52b
JM
2899 /* STATUS_EXIT_SET - Takes a NATIVE/UNIX/POSIX exit code
2900 * and sets the NATIVE error status based on it. This special case
2901 * is needed to maintain compatibility with past VMS behavior.
2902 *
2903 * In the default mode on VMS, this number is passed through as
2904 * both the NATIVE and UNIX status. Which makes it different
2905 * that the STATUS_UNIX_EXIT_SET.
2906 *
2907 * In the new POSIX EXIT mode, native status will be set so that the
2908 * actual exit code will can be retrieved by the calling program or
2909 * shell.
2910 *
2911 */
2912
2913# define STATUS_EXIT_SET(n) \
2914 STMT_START { \
2915 I32 evalue = (I32)n; \
2916 PL_statusvalue = evalue; \
2917 if (MY_POSIX_EXIT) \
2918 PL_statusvalue_vms = \
2919 (C_FAC_POSIX | (evalue << 3 ) | (evalue == 1)? \
52e64fc8 2920 (STS$K_ERROR | STS$M_INHIB_MSG) : 1); \
6ac6a52b
JM
2921 else \
2922 PL_statusvalue_vms = evalue ? evalue : SS$_NORMAL; \
2923 set_vaxc_errno(PL_statusvalue_vms); \
2924 } STMT_END
2925
fb38d079
JM
2926
2927 /* This macro forces a success status */
7a7fd8e0
JM
2928# define STATUS_ALL_SUCCESS \
2929 (PL_statusvalue = 0, PL_statusvalue_vms = SS$_NORMAL)
fb38d079
JM
2930
2931 /* This macro forces a failure status */
7a7fd8e0
JM
2932# define STATUS_ALL_FAILURE (PL_statusvalue = 1, \
2933 vaxc$errno = PL_statusvalue_vms = MY_POSIX_EXIT ? \
2934 (C_FAC_POSIX | (1 << 3) | STS$K_ERROR | STS$M_INHIB_MSG) : SS$_ABORT)
fb38d079 2935
68dc0745 2936#else
e5218da5 2937# define STATUS_NATIVE PL_statusvalue_posix
e5218da5 2938# if defined(WCOREDUMP)
37038d91 2939# define STATUS_NATIVE_CHILD_SET(n) \
e5218da5
GA
2940 STMT_START { \
2941 PL_statusvalue_posix = (n); \
2942 if (PL_statusvalue_posix == -1) \
2943 PL_statusvalue = -1; \
2944 else { \
2945 PL_statusvalue = \
2946 (WIFEXITED(PL_statusvalue_posix) ? (WEXITSTATUS(PL_statusvalue_posix) << 8) : 0) | \
2947 (WIFSIGNALED(PL_statusvalue_posix) ? (WTERMSIG(PL_statusvalue_posix) & 0x7F) : 0) | \
2948 (WIFSIGNALED(PL_statusvalue_posix) && WCOREDUMP(PL_statusvalue_posix) ? 0x80 : 0); \
2949 } \
2950 } STMT_END
2951# elif defined(WIFEXITED)
37038d91 2952# define STATUS_NATIVE_CHILD_SET(n) \
e5218da5
GA
2953 STMT_START { \
2954 PL_statusvalue_posix = (n); \
2955 if (PL_statusvalue_posix == -1) \
2956 PL_statusvalue = -1; \
2957 else { \
2958 PL_statusvalue = \
2959 (WIFEXITED(PL_statusvalue_posix) ? (WEXITSTATUS(PL_statusvalue_posix) << 8) : 0) | \
2960 (WIFSIGNALED(PL_statusvalue_posix) ? (WTERMSIG(PL_statusvalue_posix) & 0x7F) : 0); \
2961 } \
2962 } STMT_END
2963# else
37038d91 2964# define STATUS_NATIVE_CHILD_SET(n) \
e5218da5
GA
2965 STMT_START { \
2966 PL_statusvalue_posix = (n); \
2967 if (PL_statusvalue_posix == -1) \
2968 PL_statusvalue = -1; \
2969 else { \
2970 PL_statusvalue = \
2971 PL_statusvalue_posix & 0xFFFF; \
2972 } \
2973 } STMT_END
2974# endif
2975# define STATUS_UNIX_SET(n) \
68dc0745 2976 STMT_START { \
3280af22
NIS
2977 PL_statusvalue = (n); \
2978 if (PL_statusvalue != -1) \
2979 PL_statusvalue &= 0xFFFF; \
68dc0745 2980 } STMT_END
7a7fd8e0 2981# define STATUS_UNIX_EXIT_SET(n) STATUS_UNIX_SET(n)
6ac6a52b 2982# define STATUS_EXIT_SET(n) STATUS_UNIX_SET(n)
e5218da5 2983# define STATUS_CURRENT STATUS_UNIX
37038d91 2984# define STATUS_EXIT STATUS_UNIX
e5218da5
GA
2985# define STATUS_ALL_SUCCESS (PL_statusvalue = 0, PL_statusvalue_posix = 0)
2986# define STATUS_ALL_FAILURE (PL_statusvalue = 1, PL_statusvalue_posix = 1)
68dc0745
PP
2987#endif
2988
cc3604b1
GS
2989/* flags in PL_exit_flags for nature of exit() */
2990#define PERL_EXIT_EXPECTED 0x01
31d77e54 2991#define PERL_EXIT_DESTRUCT_END 0x02 /* Run END in perl_destruct */
cc3604b1 2992
0b94c7bb 2993#ifndef MEMBER_TO_FPTR
a7cb1f99
GS
2994# define MEMBER_TO_FPTR(name) name
2995#endif
2996
2997/* format to use for version numbers in file/directory names */
273cf8d1 2998/* XXX move to Configure? */
a7cb1f99 2999#ifndef PERL_FS_VER_FMT
273cf8d1 3000# define PERL_FS_VER_FMT "%d.%d.%d"
0b94c7bb
GS
3001#endif
3002
45bc9206 3003/* This defines a way to flush all output buffers. This may be a
76549fef
JH
3004 * performance issue, so we allow people to disable it. Also, if
3005 * we are using stdio, there are broken implementations of fflush(NULL)
3006 * out there, Solaris being the most prominent.
45bc9206
GS
3007 */
3008#ifndef PERL_FLUSHALL_FOR_CHILD
76549fef 3009# if defined(USE_PERLIO) || defined(FFLUSH_NULL) || defined(USE_SFIO)
66fe083f 3010# define PERL_FLUSHALL_FOR_CHILD PerlIO_flush((PerlIO*)NULL)
767df6a1
JH
3011# else
3012# ifdef FFLUSH_ALL
3013# define PERL_FLUSHALL_FOR_CHILD my_fflush_all()
e2dbf222 3014# else
c5be433b 3015# define PERL_FLUSHALL_FOR_CHILD NOOP
767df6a1 3016# endif
66fe083f 3017# endif
45bc9206
GS
3018#endif
3019
7766f137
GS
3020#ifndef PERL_WAIT_FOR_CHILDREN
3021# define PERL_WAIT_FOR_CHILDREN NOOP
3022#endif
3023
ba869deb 3024/* the traditional thread-unsafe notion of "current interpreter". */
c5be433b
GS
3025#ifndef PERL_SET_INTERP
3026# define PERL_SET_INTERP(i) (PL_curinterp = (PerlInterpreter*)(i))
3027#endif
3028
3029#ifndef PERL_GET_INTERP
3030# define PERL_GET_INTERP (PL_curinterp)
3031#endif
3032
54aff467 3033#if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_GET_THX)
54aff467 3034# ifdef MULTIPLICITY
ba869deb 3035# define PERL_GET_THX ((PerlInterpreter *)PERL_GET_CONTEXT)
54aff467 3036# endif
ba869deb
GS
3037# define PERL_SET_THX(t) PERL_SET_CONTEXT(t)
3038#endif
3039
8896765a
RB
3040/*
3041 This replaces the previous %_ "hack" by the "%p" hacks.
0dbb1585 3042 All that is required is that the perl source does not
8896765a
RB
3043 use "%-p" or "%-<number>p" or "%<number>p" formats.
3044 These formats will still work in perl code.
3045 See comments in sv.c for futher details.
3046
3047 -DvdNUMBER=<number> can be used to redefine VDf
3048
3049 -DvdNUMBER=0 reverts VDf to "vd", as in perl5.8.7,
3050 which works properly but gives compiler warnings
3051
3052 Robin Barker 2005-07-14
0dbb1585 3053*/
8896765a
RB
3054
3055#ifndef SVf_
63ce7bf0 3056# define SVf_(n) "-" STRINGIFY(n) "p"
894356b3
GS
3057#endif
3058
8896765a 3059#ifndef SVf
104abab4 3060# define SVf "-p"
d2560b70
RB
3061#endif
3062
014ead4b 3063#ifndef SVf32
8896765a 3064# define SVf32 SVf_(32)
014ead4b
RB
3065#endif
3066
3067#ifndef SVf256
8896765a
RB
3068# define SVf256 SVf_(256)
3069#endif
3070
be2597df
MHM
3071#define SVfARG(p) ((void*)(p))
3072
8896765a
RB
3073#ifndef vdNUMBER
3074# define vdNUMBER 1
3075#endif
3076
3077#ifndef VDf
3078# if vdNUMBER
63ce7bf0 3079# define VDf STRINGIFY(vdNUMBER) "p"
8896765a
RB
3080# else
3081# define VDf "vd"
3082# endif
014ead4b
RB
3083#endif
3084
f5992bc4 3085/* not used; but needed for backward compatibilty with XS code? - RMB */
014ead4b
RB
3086#ifndef UVf
3087# define UVf UVuf
d2560b70
RB
3088#endif
3089
0dbb1585
AL
3090#ifdef HASATTRIBUTE_FORMAT
3091# define __attribute__format__(x,y,z) __attribute__((format(x,y,z)))
3092#endif
3093#ifdef HASATTRIBUTE_MALLOC
77785eea 3094# define __attribute__malloc__ __attribute__((__malloc__))
f22be1b8 3095#endif
0dbb1585 3096#ifdef HASATTRIBUTE_NONNULL
abb2c242 3097# define __attribute__nonnull__(a) __attribute__((nonnull(a)))
f22be1b8 3098#endif
0dbb1585 3099#ifdef HASATTRIBUTE_NORETURN
abb2c242 3100# define __attribute__noreturn__ __attribute__((noreturn))
f22be1b8 3101#endif
0dbb1585 3102#ifdef HASATTRIBUTE_PURE
abb2c242 3103# define __attribute__pure__ __attribute__((pure))
f22be1b8 3104#endif
0dbb1585
AL
3105#ifdef HASATTRIBUTE_UNUSED
3106# define __attribute__unused__ __attribute__((unused))
3107#endif
3108#ifdef HASATTRIBUTE_WARN_UNUSED_RESULT
abb2c242 3109# define __attribute__warn_unused_result__ __attribute__((warn_unused_result))
f22be1b8
JH
3110#endif
3111
0dbb1585
AL
3112/* If we haven't defined the attributes yet, define them to blank. */
3113#ifndef __attribute__format__
3114# define __attribute__format__(x,y,z)
3115#endif
f22be1b8 3116#ifndef __attribute__malloc__
abb2c242 3117# define __attribute__malloc__
f22be1b8
JH
3118#endif
3119#ifndef __attribute__nonnull__
abb2c242 3120# define __attribute__nonnull__(a)
f22be1b8
JH
3121#endif
3122#ifndef __attribute__noreturn__
abb2c242 3123# define __attribute__noreturn__
f22be1b8
JH
3124#endif
3125#ifndef __attribute__pure__
abb2c242 3126# define __attribute__pure__
f22be1b8 3127#endif
0dbb1585
AL
3128#ifndef __attribute__unused__
3129# define __attribute__unused__
3130#endif
f22be1b8 3131#ifndef __attribute__warn_unused_result__
abb2c242
JH
3132# define __attribute__warn_unused_result__
3133#endif
3134
0dbb1585
AL
3135/* For functions that are marked as __attribute__noreturn__, it's not
3136 appropriate to call return. In either case, include the lint directive.
3137 */
3138#ifdef HASATTRIBUTE_NORETURN
b37c2d43 3139# define NORETURN_FUNCTION_END /* NOTREACHED */
0dbb1585 3140#else
b37c2d43 3141# define NORETURN_FUNCTION_END /* NOTREACHED */ return 0
abb2c242
JH
3142#endif
3143
cdfeb707
RB
3144/* Some OS warn on NULL format to printf */
3145#ifdef PRINTF_FORMAT_NULL_OK
3146# define __attribute__format__null_ok__(x,y,z) __attribute__format__(x,y,z)
3147#else
3148# define __attribute__format__null_ok__(x,y,z)
3149#endif
3150
635aebb7 3151#ifdef HAS_BUILTIN_EXPECT
b37c2d43
AL
3152# define EXPECT(expr,val) __builtin_expect(expr,val)
3153#else
3154# define EXPECT(expr,val) (expr)
3155#endif
3156#define LIKELY(cond) EXPECT(cond,1)
3157#define UNLIKELY(cond) EXPECT(cond,0)
635aebb7
AL
3158#ifdef HAS_BUILTIN_CHOOSE_EXPR
3159/* placeholder */
3160#endif
b37c2d43 3161
3fc1aec6
PP
3162/* Some unistd.h's give a prototype for pause() even though
3163 HAS_PAUSE ends up undefined. This causes the #define
d2560b70 3164 below to be rejected by the compiler. Sigh.
3fc1aec6
PP
3165*/
3166#ifdef HAS_PAUSE
3167#define Pause pause
3168#else
3169#define Pause() sleep((32767<<16)+32767)
748a9306
LW
3170#endif
3171
3172#ifndef IOCPARM_LEN
3173# ifdef IOCPARM_MASK
61f1c44b 3174 /* on BSDish systems we're safe */
748a9306
LW
3175# define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
3176# else
61f1c44b 3177# if defined(_IOC_SIZE) && defined(__GLIBC__)
301eb2f0
GA
3178 /* on Linux systems we're safe; except when we're not [perl #38223] */
3179# define IOCPARM_LEN(x) (_IOC_SIZE(x) < 256 ? 256 : _IOC_SIZE(x))
61f1c44b 3180# else
748a9306 3181 /* otherwise guess at what's safe */
61f1c44b
JVD
3182# define IOCPARM_LEN(x) 256
3183# endif
748a9306 3184# endif
a0d0e21e
LW
3185#endif
3186
1761cee5 3187#if defined(__CYGWIN__)
521e0776
GS
3188/* USEMYBINMODE
3189 * This symbol, if defined, indicates that the program should
16fe6d59 3190 * use the routine my_binmode(FILE *fp, char iotype, int mode) to insure
521e0776
GS
3191 * that a file is in "binary" mode -- that is, that no translation
3192 * of bytes occurs on read or write operations.
3193 */
36894f0b 3194# define USEMYBINMODE /**/
77a40698 3195# include <io.h> /* for setmode() prototype */
16fe6d59 3196# define my_binmode(fp, iotype, mode) \
77a40698 3197 (PerlLIO_setmode(fileno(fp), mode) != -1 ? TRUE : FALSE)
5aabfad6
PP
3198#endif
3199
88d10794
JH
3200#ifdef __CYGWIN__
3201void init_os_extras(void);
3202#endif
3203
cea2e8a9
GS
3204#ifdef UNION_ANY_DEFINITION
3205UNION_ANY_DEFINITION;
3206#else
3207union any {
3208 void* any_ptr;
3209 I32 any_i32;
3210 IV any_iv;
3211 long any_long;
9febdf04 3212 bool any_bool;
c76ac1ee 3213 void (*any_dptr) (void*);
acfe0abc 3214 void (*any_dxptr) (pTHX_ void*);
cea2e8a9
GS
3215};
3216#endif
3217
acfe0abc 3218typedef I32 (*filter_t) (pTHX_ int, SV *, int);
cea2e8a9
GS
3219
3220#define FILTER_READ(idx, sv, len) filter_read(idx, sv, len)
3221#define FILTER_DATA(idx) (AvARRAY(PL_rsfp_filters)[idx])
3222#define FILTER_ISREADER(idx) (idx >= AvFILLp(PL_rsfp_filters))
3223
c5078cac
JH
3224#if defined(_AIX) && !defined(_AIX43)
3225#if defined(USE_REENTRANT) || defined(_REENTRANT) || defined(_THREAD_SAFE)
3226/* We cannot include <crypt.h> to get the struct crypt_data
3227 * because of setkey prototype problems when threading */
3228typedef struct crypt_data { /* straight from /usr/include/crypt.h */
3229 /* From OSF, Not needed in AIX
3230 char C[28], D[28];
3231 */
3232 char E[48];
3233 char KS[16][48];
3234 char block[66];
3235 char iobuf[16];
3236} CRYPTD;
3237#endif /* threading */
3238#endif /* AIX */
3239
af8b425d 3240#if !defined(OS2) && !defined(MACOS_TRADITIONAL)
2c2d71f5
JH
3241# include "iperlsys.h"
3242#endif
504f80c1 3243
d10dc2ae
JH
3244/* [perl #22371] Algorimic Complexity Attack on Perl 5.6.1, 5.8.0.
3245 * Note that the USE_HASH_SEED and USE_HASH_SEED_EXPLICIT are *NOT*
3246 * defined by Configure, despite their names being similar to the
3247 * other defines like USE_ITHREADS. Configure in fact knows nothing
3248 * about the randomised hashes. Therefore to enable/disable the hash
3249 * randomisation defines use the Configure -Accflags=... instead. */
504f80c1 3250#if !defined(NO_HASH_SEED) && !defined(USE_HASH_SEED) && !defined(USE_HASH_SEED_EXPLICIT)
4546b9e6 3251# define USE_HASH_SEED
504f80c1
JH
3252#endif
3253
598921a7
NC
3254/* Win32 defines a type 'WORD' in windef.h. This conflicts with the enumerator
3255 * 'WORD' defined in perly.h. The yytokentype enum is only a debugging aid, so
3256 * it's not really needed.
3257 */
3258#if defined(WIN32)
3259# define YYTOKENTYPE
3260#endif
3261#include "perly.h"
3262
3263#ifdef PERL_MAD
3264struct nexttoken {
3265 YYSTYPE next_val; /* value of next token, if any */
3266 I32 next_type; /* type of next token */
3267 MADPROP *next_mad; /* everything else about that token */
3268};
3269#endif
3270
378cc40b 3271#include "regexp.h"
79072805 3272#include "sv.h"
378cc40b 3273#include "util.h"
8d063cd8 3274#include "form.h"
79072805 3275#include "gv.h"
dd2155a4 3276#include "pad.h"
79072805 3277#include "cv.h"
abdd5c84 3278#include "opnames.h"
79072805 3279#include "op.h"
b3ca2e83 3280#include "hv.h"
79072805
LW
3281#include "cop.h"
3282#include "av.h"
79072805
LW
3283#include "mg.h"
3284#include "scope.h"
4438c4b7 3285#include "warnings.h"
a0ed51b3 3286#include "utf8.h"
8d063cd8 3287
7fae4e64
GS
3288
3289typedef struct _sublex_info SUBLEXINFO;
3290struct _sublex_info {
3291 I32 super_state; /* lexer state to save */
3292 I32 sub_inwhat; /* "lex_inwhat" to use */
3293 OP *sub_op; /* "lex_op" to use */
0244c3a4
GS
3294 char *super_bufptr; /* PL_bufptr that was */
3295 char *super_bufend; /* PL_bufend that was */
7fae4e64
GS
3296};
3297
199e78b7
DM
3298#include "parser.h"
3299
455ece5e 3300typedef struct magic_state MGS; /* struct magic_state defined in mg.c */
76e3520e 3301
2c2d71f5 3302struct scan_data_t; /* Used in S_* functions in regcomp.c */
653099ff 3303struct regnode_charclass_class; /* Used in S_* functions in regcomp.c */
76e3520e 3304
6f51351d
NC
3305/* Keep next first in this structure, because sv_free_arenas take
3306 advantage of this to share code between the pte arenas and the SV
3307 body arenas */
5f7fde29
GS
3308struct ptr_tbl_ent {
3309 struct ptr_tbl_ent* next;
53c1dcc0 3310 const void* oldval;
5f7fde29 3311 void* newval;
d18c6117
GS
3312};
3313
5f7fde29
GS
3314struct ptr_tbl {
3315 struct ptr_tbl_ent** tbl_ary;
3316 UV tbl_max;
3317 UV tbl_items;
d18c6117
GS
3318};
3319
450a55e4 3320#if defined(iAPX286) || defined(M_I286) || defined(I80286)
a687059c
LW
3321# define I286
3322#endif
3323
fe14fcc3
LW
3324#if defined(htonl) && !defined(HAS_HTONL)
3325#define HAS_HTONL
ae986130 3326#endif
fe14fcc3
LW
3327#if defined(htons) && !defined(HAS_HTONS)
3328#define HAS_HTONS
ae986130 3329#endif
fe14fcc3
LW
3330#if defined(ntohl) && !defined(HAS_NTOHL)
3331#define HAS_NTOHL
ae986130 3332#endif
fe14fcc3
LW
3333#if defined(ntohs) && !defined(HAS_NTOHS)
3334#define HAS_NTOHS
ae986130 3335#endif
fe14fcc3 3336#ifndef HAS_HTONL
d9d8d8de 3337#if (BYTEORDER & 0xffff) != 0x4321
fe14fcc3
LW
3338#define HAS_HTONS
3339#define HAS_HTONL
3340#define HAS_NTOHS
3341#define HAS_NTOHL
a687059c
LW
3342#define MYSWAP
3343#define htons my_swap
3344#define htonl my_htonl
3345#define ntohs my_swap
3346#define ntohl my_ntohl
3347#endif
3348#else
d9d8d8de 3349#if (BYTEORDER & 0xffff) == 0x4321
fe14fcc3
LW
3350#undef HAS_HTONS
3351#undef HAS_HTONL
3352#undef HAS_NTOHS
3353#undef HAS_NTOHL
a687059c
LW
3354#endif
3355#endif
3356
988174c1
LW
3357/*
3358 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
3359 * -DWS
3360 */
3361#if BYTEORDER != 0x1234
3362# define HAS_VTOHL
3363# define HAS_VTOHS
3364# define HAS_HTOVL
3365# define HAS_HTOVS
c67712b2 3366# if BYTEORDER == 0x4321 || BYTEORDER == 0x87654321
988174c1
LW
3367# define vtohl(x) ((((x)&0xFF)<<24) \
3368 +(((x)>>24)&0xFF) \
3369 +(((x)&0x0000FF00)<<8) \
3370 +(((x)&0x00FF0000)>>8) )
3371# define vtohs(x) ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
3372# define htovl(x) vtohl(x)
3373# define htovs(x) vtohs(x)
3374# endif
3375 /* otherwise default to functions in util.c */
2a8c3029 3376#ifndef htovs
c623ac67
GS
3377short htovs(short n);
3378short vtohs(short n);
3379long htovl(long n);
3380long vtohl(long n);
988174c1 3381#endif
2a8c3029 3382#endif
988174c1 3383
3bb7c1b4
JH
3384/* *MAX Plus 1. A floating point value.
3385 Hopefully expressed in a way that dodgy floating point can't mess up.
3386 >> 2 rather than 1, so that value is safely less than I32_MAX after 1
3387 is added to it
3388 May find that some broken compiler will want the value cast to I32.
3389 [after the shift, as signed >> may not be as secure as unsigned >>]
3390*/
3391#define I32_MAX_P1 (2.0 * (1 + (((U32)I32_MAX) >> 1)))
3392#define U32_MAX_P1 (4.0 * (1 + ((U32_MAX) >> 2)))
3393/* For compilers that can't correctly cast NVs over 0x7FFFFFFF (or
3394 0x7FFFFFFFFFFFFFFF) to an unsigned integer. In the future, sizeof(UV)
3395 may be greater than sizeof(IV), so don't assume that half max UV is max IV.
3396*/
3397#define U32_MAX_P1_HALF (2.0 * (1 + ((U32_MAX) >> 2)))
ee0007ab 3398
3bb7c1b4
JH
3399#define UV_MAX_P1 (4.0 * (1 + ((UV_MAX) >> 2)))
3400#define IV_MAX_P1 (2.0 * (1 + (((UV)IV_MAX) >> 1)))
3401#define UV_MAX_P1_HALF (2.0 * (1 + ((UV_MAX) >> 2)))
3402
3403/* This may look like unnecessary jumping through hoops, but converting
3404 out of range floating point values to integers *is* undefined behaviour,
3405 and it is starting to bite.
3406*/
3407#ifndef CAST_INLINE
65202027 3408#define I_32(what) (cast_i32((NV)(what)))
3bb7c1b4 3409#define U_32(what) (cast_ulong((NV)(what)))
65202027
DS
3410#define I_V(what) (cast_iv((NV)(what)))
3411#define U_V(what) (cast_uv((NV)(what)))
3bb7c1b4
JH
3412#else
3413#define I_32(n) ((n) < I32_MAX_P1 ? ((n) < I32_MIN ? I32_MIN : (I32) (n)) \
3414 : ((n) < U32_MAX_P1 ? (I32)(U32) (n) \
3415 : ((n) > 0 ? (I32) U32_MAX : 0 /* NaN */)))
3416#define U_32(n) ((n) < 0.0 ? ((n) < I32_MIN ? (UV) I32_MIN : (U32)(I32) (n)) \
3417 : ((n) < U32_MAX_P1 ? (U32) (n) \
3418 : ((n) > 0 ? U32_MAX : 0 /* NaN */)))
3419#define I_V(n) ((n) < IV_MAX_P1 ? ((n) < IV_MIN ? IV_MIN : (IV) (n)) \
3420 : ((n) < UV_MAX_P1 ? (IV)(UV) (n) \
3421 : ((n) > 0 ? (IV)UV_MAX : 0 /* NaN */)))
3422#define U_V(n) ((n) < 0.0 ? ((n) < IV_MIN ? (UV) IV_MIN : (UV)(IV) (n)) \
3423 : ((n) < UV_MAX_P1 ? (UV) (n) \
3424 : ((n) > 0 ? UV_MAX : 0 /* NaN */)))
3425#endif
3426
3427#define U_S(what) ((U16)U_32(what))
3428#define U_I(what) ((unsigned int)U_32(what))
3429#define U_L(what) U_32(what)
ed6116ce 3430
2d4389e4
JH
3431/* These do not care about the fractional part, only about the range. */
3432#define NV_WITHIN_IV(nv) (I_V(nv) >= IV_MIN && I_V(nv) <= IV_MAX)
24db6c0d 3433#define NV_WITHIN_UV(nv) ((nv)>=0.0 && U_V(nv) >= UV_MIN && U_V(nv) <= UV_MAX)
2d4389e4 3434
25da4f38
IZ
3435/* Used with UV/IV arguments: */
3436 /* XXXX: need to speed it up */
3437#define CLUMP_2UV(iv) ((iv) < 0 ? 0 : (UV)(iv))
3438#define CLUMP_2IV(uv) ((uv) > (UV)IV_MAX ? IV_MAX : (IV)(uv))
3439
352d5a3a
LW
3440#ifndef MAXSYSFD
3441# define MAXSYSFD 2
3442#endif
ee0007ab 3443
79072805 3444#ifndef __cplusplus
27da23d5 3445#if !(defined(UNDER_CE) || defined(SYMBIAN))
20ce7b12
GS
3446Uid_t getuid (void);
3447Uid_t geteuid (void);
3448Gid_t getgid (void);
3449Gid_t getegid (void);
79072805 3450#endif
e1caacb4 3451#endif
8d063cd8 3452
0c30d9ec 3453#ifndef Perl_debug_log
bf49b057
GS
3454# define Perl_debug_log PerlIO_stderr()
3455#endif
3456
3457#ifndef Perl_error_log
3458# define Perl_error_log (PL_stderrgv \
6b78add2 3459 && isGV(PL_stderrgv) \
01bb7c6d 3460 && GvIOp(PL_stderrgv) \
42de951c 3461 && IoOFP(GvIOp(PL_stderrgv)) \
bf49b057
GS
3462 ? IoOFP(GvIOp(PL_stderrgv)) \
3463 : PerlIO_stderr())
0c30d9ec 3464#endif
3967c732 3465
aea4f609
DM
3466
3467#define DEBUG_p_FLAG 0x00000001 /* 1 */
3468#define DEBUG_s_FLAG 0x00000002 /* 2 */
3469#define DEBUG_l_FLAG 0x00000004 /* 4 */
3470#define DEBUG_t_FLAG 0x00000008 /* 8 */
3471#define DEBUG_o_FLAG 0x00000010 /* 16 */
3472#define DEBUG_c_FLAG 0x00000020 /* 32 */
3473#define DEBUG_P_FLAG 0x00000040 /* 64 */
3474#define DEBUG_m_FLAG 0x00000080 /* 128 */
3475#define DEBUG_f_FLAG 0x00000100 /* 256 */
3476#define DEBUG_r_FLAG 0x00000200 /* 512 */
3477#define DEBUG_x_FLAG 0x00000400 /* 1024 */
3478#define DEBUG_u_FLAG 0x00000800 /* 2048 */
88d2d28a
JC
3479/* U is reserved for Unofficial, exploratory hacking */
3480#define DEBUG_U_FLAG 0x00001000 /* 4096 */
aea4f609
DM
3481#define DEBUG_H_FLAG 0x00002000 /* 8192 */
3482#define DEBUG_X_FLAG 0x00004000 /* 16384 */
3483#define DEBUG_D_FLAG 0x00008000 /* 32768 */
3484#define DEBUG_S_FLAG 0x00010000 /* 65536 */
3485#define DEBUG_T_FLAG 0x00020000 /* 131072 */
04932ac8 3486#define DEBUG_R_FLAG 0x00040000 /* 262144 */
1045810a 3487#define DEBUG_J_FLAG 0x00080000 /* 524288 */
d6721266 3488#define DEBUG_v_FLAG 0x00100000 /*1048576 */
46187eeb 3489#define DEBUG_C_FLAG 0x00200000 /*2097152 */
ecae49c0 3490#define DEBUG_A_FLAG 0x00400000 /*4194304 */
a3c98653 3491#define DEBUG_q_FLAG 0x00800000 /*8388608 */
ecae49c0 3492#define DEBUG_MASK 0x00FFEFFF /* mask of all the standard flags */
aea4f609
DM
3493
3494#define DEBUG_DB_RECURSE_FLAG 0x40000000
1045810a
IZ
3495#define DEBUG_TOP_FLAG 0x80000000 /* XXX what's this for ??? Signal
3496 that something was done? */
aea4f609 3497
bd16a5f0
IZ
3498# define DEBUG_p_TEST_ (PL_debug & DEBUG_p_FLAG)
3499# define DEBUG_s_TEST_ (PL_debug & DEBUG_s_FLAG)
3500# define DEBUG_l_TEST_ (PL_debug & DEBUG_l_FLAG)
3501# define DEBUG_t_TEST_ (PL_debug & DEBUG_t_FLAG)
3502# define DEBUG_o_TEST_ (PL_debug & DEBUG_o_FLAG)
3503# define DEBUG_c_TEST_ (PL_debug & DEBUG_c_FLAG)
3504# define DEBUG_P_TEST_ (PL_debug & DEBUG_P_FLAG)
3505# define DEBUG_m_TEST_ (PL_debug & DEBUG_m_FLAG)
3506# define DEBUG_f_TEST_ (PL_debug & DEBUG_f_FLAG)
3507# define DEBUG_r_TEST_ (PL_debug & DEBUG_r_FLAG)
3508# define DEBUG_x_TEST_ (PL_debug & DEBUG_x_FLAG)
3509# define DEBUG_u_TEST_ (PL_debug & DEBUG_u_FLAG)
88d2d28a 3510# define DEBUG_U_TEST_ (PL_debug & DEBUG_U_FLAG)
bd16a5f0
IZ
3511# define DEBUG_H_TEST_ (PL_debug & DEBUG_H_FLAG)
3512# define DEBUG_X_TEST_ (PL_debug & DEBUG_X_FLAG)
3513# define DEBUG_D_TEST_ (PL_debug & DEBUG_D_FLAG)
3514# define DEBUG_S_TEST_ (PL_debug & DEBUG_S_FLAG)
3515# define DEBUG_T_TEST_ (PL_debug & DEBUG_T_FLAG)
3516# define DEBUG_R_TEST_ (PL_debug & DEBUG_R_FLAG)
1045810a 3517# define DEBUG_J_TEST_ (PL_debug & DEBUG_J_FLAG)
d6721266 3518# define DEBUG_v_TEST_ (PL_debug & DEBUG_v_FLAG)
46187eeb 3519# define DEBUG_C_TEST_ (PL_debug & DEBUG_C_FLAG)
ecae49c0
NC
3520# define DEBUG_A_TEST_ (PL_debug & DEBUG_A_FLAG)
3521# define DEBUG_q_TEST_ (PL_debug & DEBUG_q_FLAG)
dd2155a4 3522# define DEBUG_Xv_TEST_ (DEBUG_X_TEST_ && DEBUG_v_TEST_)
bd16a5f0 3523
3967c732 3524#ifdef DEBUGGING
aea4f609 3525
bd16a5f0
IZ
3526# define DEBUG_p_TEST DEBUG_p_TEST_
3527# define DEBUG_s_TEST DEBUG_s_TEST_
3528# define DEBUG_l_TEST DEBUG_l_TEST_
3529# define DEBUG_t_TEST DEBUG_t_TEST_
3530# define DEBUG_o_TEST DEBUG_o_TEST_
3531# define DEBUG_c_TEST DEBUG_c_TEST_
3532# define DEBUG_P_TEST DEBUG_P_TEST_
3533# define DEBUG_m_TEST DEBUG_m_TEST_
3534# define DEBUG_f_TEST DEBUG_f_TEST_
3535# define DEBUG_r_TEST DEBUG_r_TEST_
3536# define DEBUG_x_TEST DEBUG_x_TEST_
3537# define DEBUG_u_TEST DEBUG_u_TEST_
88d2d28a 3538# define DEBUG_U_TEST DEBUG_U_TEST_
bd16a5f0
IZ
3539# define DEBUG_H_TEST DEBUG_H_TEST_
3540# define DEBUG_X_TEST DEBUG_X_TEST_
dd2155a4 3541# define DEBUG_Xv_TEST DEBUG_Xv_TEST_
bd16a5f0
IZ
3542# define DEBUG_D_TEST DEBUG_D_TEST_
3543# define DEBUG_S_TEST DEBUG_S_TEST_
3544# define DEBUG_T_TEST DEBUG_T_TEST_
3545# define DEBUG_R_TEST DEBUG_R_TEST_
1045810a 3546# define DEBUG_J_TEST DEBUG_J_TEST_
d6721266 3547# define DEBUG_v_TEST DEBUG_v_TEST_
46187eeb 3548# define DEBUG_C_TEST DEBUG_C_TEST_
ecae49c0 3549# define DEBUG_A_TEST DEBUG_A_TEST_
a3c98653 3550# define DEBUG_q_TEST DEBUG_q_TEST_
aea4f609 3551
488b0c7a
JH
3552# define PERL_DEB(a) a
3553# define PERL_DEBUG(a) if (PL_debug) a
aea4f609
DM
3554# define DEBUG_p(a) if (DEBUG_p_TEST) a
3555# define DEBUG_s(a) if (DEBUG_s_TEST) a
3556# define DEBUG_l(a) if (DEBUG_l_TEST) a
3557# define DEBUG_t(a) if (DEBUG_t_TEST) a
3558# define DEBUG_o(a) if (DEBUG_o_TEST) a
3559# define DEBUG_c(a) if (DEBUG_c_TEST) a
3560# define DEBUG_P(a) if (DEBUG_P_TEST) a
3561
969058bb
VK
3562 /* Temporarily turn off memory debugging in case the a
3563 * does memory allocation, either directly or indirectly. */
acfe0abc 3564# define DEBUG_m(a) \
0b250b9e 3565 STMT_START { \
aea4f609 3566 if (PERL_GET_INTERP) { dTHX; if (DEBUG_m_TEST) {PL_debug&=~DEBUG_m_FLAG; a; PL_debug|=DEBUG_m_FLAG;} } \
0b250b9e 3567 } STMT_END
aea4f609 3568
5f80b19c
AMS
3569# define DEBUG__(t, a) \
3570 STMT_START { \
3571 if (t) STMT_START {a;} STMT_END; \
3572 } STMT_END
3573
3574# define DEBUG_f(a) DEBUG__(DEBUG_f_TEST, a)
f9f4320a 3575#ifndef PERL_EXT_RE_BUILD
5f80b19c 3576# define DEBUG_r(a) DEBUG__(DEBUG_r_TEST, a)
f9f4320a
YO
3577#else
3578# define DEBUG_r(a) STMT_START {a;} STMT_END
3579#endif /* PERL_EXT_RE_BUILD */
5f80b19c
AMS
3580# define DEBUG_x(a) DEBUG__(DEBUG_x_TEST, a)
3581# define DEBUG_u(a) DEBUG__(DEBUG_u_TEST, a)
88d2d28a 3582# define DEBUG_U(a) DEBUG__(DEBUG_U_TEST, a)
5f80b19c
AMS
3583# define DEBUG_H(a) DEBUG__(DEBUG_H_TEST, a)
3584# define DEBUG_X(a) DEBUG__(DEBUG_X_TEST, a)
dd2155a4 3585# define DEBUG_Xv(a) DEBUG__(DEBUG_Xv_TEST, a)
5f80b19c 3586# define DEBUG_D(a) DEBUG__(DEBUG_D_TEST, a)
aea4f609 3587
3db8f154 3588# define DEBUG_S(a)
aea4f609 3589
5f80b19c
AMS
3590# define DEBUG_T(a) DEBUG__(DEBUG_T_TEST, a)
3591# define DEBUG_R(a) DEBUG__(DEBUG_R_TEST, a)
d6721266 3592# define DEBUG_v(a) DEBUG__(DEBUG_v_TEST, a)
46187eeb 3593# define DEBUG_C(a) DEBUG__(DEBUG_C_TEST, a)
ecae49c0
NC
3594# define DEBUG_A(a) DEBUG__(DEBUG_A_TEST, a)
3595# define DEBUG_q(a) DEBUG__(DEBUG_q_TEST, a)
aea4f609
DM
3596
3597#else /* DEBUGGING */
3598
3599# define DEBUG_p_TEST (0)
3600# define DEBUG_s_TEST (0)
3601# define DEBUG_l_TEST (0)
3602# define DEBUG_t_TEST (0)
3603# define DEBUG_o_TEST (0)
3604# define DEBUG_c_TEST (0)
3605# define DEBUG_P_TEST (0)
3606# define DEBUG_m_TEST (0)
3607# define DEBUG_f_TEST (0)
3608# define DEBUG_r_TEST (0)
3609# define DEBUG_x_TEST (0)
3610# define DEBUG_u_TEST (0)
88d2d28a 3611# define DEBUG_U_TEST (0)
aea4f609
DM
3612# define DEBUG_H_TEST (0)
3613# define DEBUG_X_TEST (0)
dd2155a4 3614# define DEBUG_Xv_TEST (0)
aea4f609
DM
3615# define DEBUG_D_TEST (0)
3616# define DEBUG_S_TEST (0)
3617# define DEBUG_T_TEST (0)
04932ac8 3618# define DEBUG_R_TEST (0)
1045810a 3619# define DEBUG_J_TEST (0)
d6721266 3620# define DEBUG_v_TEST (0)
46187eeb 3621# define DEBUG_C_TEST (0)
ecae49c0
NC
3622# define DEBUG_A_TEST (0)
3623# define DEBUG_q_TEST (0)
aea4f609 3624
488b0c7a
JH
3625# define PERL_DEB(a)
3626# define PERL_DEBUG(a)
aea4f609
DM
3627# define DEBUG_p(a)
3628# define DEBUG_s(a)
3629# define DEBUG_l(a)
3630# define DEBUG_t(a)
3631# define DEBUG_o(a)
3632# define DEBUG_c(a)
3633# define DEBUG_P(a)
3634# define DEBUG_m(a)
3635# define DEBUG_f(a)
3636# define DEBUG_r(a)
3637# define DEBUG_x(a)
3638# define DEBUG_u(a)
88d2d28a 3639# define DEBUG_U(a)
aea4f609
DM
3640# define DEBUG_H(a)
3641# define DEBUG_X(a)
dd2155a4 3642# define DEBUG_Xv(a)
aea4f609
DM
3643# define DEBUG_D(a)
3644# define DEBUG_S(a)
3645# define DEBUG_T(a)
04932ac8 3646# define DEBUG_R(a)
d6721266 3647# define DEBUG_v(a)
46187eeb 3648# define DEBUG_C(a)
ecae49c0
NC
3649# define DEBUG_A(a)
3650# define DEBUG_q(a)
aea4f609
DM
3651#endif /* DEBUGGING */
3652
3653
b4ab917c
DM
3654#define DEBUG_SCOPE(where) \
3655 DEBUG_l(WITH_THR(Perl_deb(aTHX_ "%s scope %ld at %s:%d\n", \
44f8325f 3656 where, (long)PL_scopestack_ix, __FILE__, __LINE__)));
b4ab917c
DM
3657
3658
3659
3660
d1be9408 3661/* These constants should be used in preference to raw characters
14befaf4
DM
3662 * when using magic. Note that some perl guts still assume
3663 * certain character properties of these constants, namely that
3664 * isUPPER() and toLOWER() may do useful mappings.
3665 *
3666 * Update the magic_names table in dump.c when adding/amending these
3667 */
3668
3669#define PERL_MAGIC_sv '\0' /* Special scalar variable */
3670#define PERL_MAGIC_overload 'A' /* %OVERLOAD hash */
3671#define PERL_MAGIC_overload_elem 'a' /* %OVERLOAD hash element */
3672#define PERL_MAGIC_overload_table 'c' /* Holds overload table (AMT) on stash */
3673#define PERL_MAGIC_bm 'B' /* Boyer-Moore (fast string search) */
3674#define PERL_MAGIC_regdata 'D' /* Regex match position data
3675 (@+ and @- vars) */
3676#define PERL_MAGIC_regdatum 'd' /* Regex match position data element */
3677#define PERL_MAGIC_env 'E' /* %ENV hash */
3678#define PERL_MAGIC_envelem 'e' /* %ENV hash element */
3679#define PERL_MAGIC_fm 'f' /* Formline ('compiled' format) */
3680#define PERL_MAGIC_regex_global 'g' /* m//g target / study()ed string */
b3ca2e83
NC
3681#define PERL_MAGIC_hints 'H' /* %^H hash */
3682#define PERL_MAGIC_hintselem 'h' /* %^H hash element */
14befaf4
DM
3683#define PERL_MAGIC_isa 'I' /* @ISA array */
3684#define PERL_MAGIC_isaelem 'i' /* @ISA array element */
3685#define PERL_MAGIC_nkeys 'k' /* scalar(keys()) lvalue */
3686#define PERL_MAGIC_dbfile 'L' /* Debugger %_<filename */
3687#define PERL_MAGIC_dbline 'l' /* Debugger %_<filename element */
68795e93
NIS
3688#define PERL_MAGIC_mutex 'm' /* for lock op */
3689#define PERL_MAGIC_shared 'N' /* Shared between threads */
3690#define PERL_MAGIC_shared_scalar 'n' /* Shared between threads */
14befaf4
DM
3691#define PERL_MAGIC_collxfrm 'o' /* Locale transformation */
3692#define PERL_MAGIC_tied 'P' /* Tied array or hash */
3693#define PERL_MAGIC_tiedelem 'p' /* Tied array or hash element */
3694#define PERL_MAGIC_tiedscalar 'q' /* Tied scalar or handle */
3695#define PERL_MAGIC_qr 'r' /* precompiled qr// regex */
3696#define PERL_MAGIC_sig 'S' /* %SIG hash */
3697#define PERL_MAGIC_sigelem 's' /* %SIG hash element */
3698#define PERL_MAGIC_taint 't' /* Taintedness */
3699#define PERL_MAGIC_uvar 'U' /* Available for use by extensions */
68795e93 3700#define PERL_MAGIC_uvar_elem 'u' /* Reserved for use by extensions */
14befaf4 3701#define PERL_MAGIC_vec 'v' /* vec() lvalue */
92f0c265 3702#define PERL_MAGIC_vstring 'V' /* SV was vstring literal */
7e8c5dac 3703#define PERL_MAGIC_utf8 'w' /* Cached UTF-8 information */
14befaf4
DM
3704#define PERL_MAGIC_substr 'x' /* substr() lvalue */
3705#define PERL_MAGIC_defelem 'y' /* Shadow "foreach" iterator variable /
3706 smart parameter vivification */
14befaf4
DM
3707#define PERL_MAGIC_arylen '#' /* Array length ($#ary) */
3708#define PERL_MAGIC_pos '.' /* pos() lvalue */
68795e93 3709#define PERL_MAGIC_backref '<' /* for weak ref data */
8d2f4536 3710#define PERL_MAGIC_symtab ':' /* extra data for symbol tables */
ca732855 3711#define PERL_MAGIC_rhash '%' /* extra data for restricted hashes */
a3874608 3712#define PERL_MAGIC_arylen_p '@' /* to move arylen out of XPVAV */
14befaf4
DM
3713#define PERL_MAGIC_ext '~' /* Available for use by extensions */
3714
3715
a6e633de 3716#ifndef assert /* <assert.h> might have been included somehow */
2b057284
NC
3717#define assert(what) PERL_DEB( \
3718 ((what) ? ((void) 0) : \
67eb4d30 3719 (Perl_croak_nocontext("Assertion %s failed: file \"" __FILE__ \
60b9f5a7 3720 "\", line %d", STRINGIFY(what), __LINE__), \
2b057284 3721 (void) 0)))
a446a88f 3722#endif
8d063cd8 3723
450a55e4 3724struct ufuncs {
24f81a43
DM
3725 I32 (*uf_val)(pTHX_ IV, SV*);
3726 I32 (*uf_set)(pTHX_ IV, SV*);
a0d0e21e 3727 IV uf_index;
450a55e4
LW
3728};
3729
14befaf4 3730/* In pre-5.7-Perls the PERL_MAGIC_uvar magic didn't get the thread context.
24f81a43
DM
3731 * XS code wanting to be backward compatible can do something
3732 * like the following:
c745e42c 3733
24f81a43 3734#ifndef PERL_MG_UFUNC
24f81a43
DM
3735#define PERL_MG_UFUNC(name,ix,sv) I32 name(IV ix, SV *sv)
3736#endif
3737
3738static PERL_MG_UFUNC(foo_get, index, val)
3739{
3740 sv_setsv(val, ...);
3741 return TRUE;
3742}
3743
3744-- Doug MacEachern
3745
3746*/
3747
fc9c74e6 3748#ifndef PERL_MG_UFUNC
24f81a43 3749#define PERL_MG_UFUNC(name,ix,sv) I32 name(pTHX_ IV ix, SV *sv)
fc9c74e6 3750#endif
24f81a43 3751
fe14fcc3 3752/* Fix these up for __STDC__ */
68dc0745 3753#ifndef DONT_DECLARE_STD
20ce7b12 3754char *mktemp (char*);
37bd1396 3755#ifndef atof
20ce7b12 3756double atof (const char*);
a0d0e21e 3757#endif
37bd1396 3758#endif
79072805 3759
352d5a3a 3760#ifndef STANDARD_C
fe14fcc3 3761/* All of these are in stdlib.h or time.h for ANSI C */
85e6fe83 3762Time_t time();
8d063cd8 3763struct tm *gmtime(), *localtime();
092bebab 3764#if defined(OEMVS) || defined(__OPEN_VM)
9d116dd7
JH
3765char *(strchr)(), *(strrchr)();
3766char *(strcpy)(), *(strcat)();
3767#else
93a17b20 3768char *strchr(), *strrchr();
378cc40b 3769char *strcpy(), *strcat();
9d116dd7 3770#endif
352d5a3a 3771#endif /* ! STANDARD_C */
8d063cd8 3772
79072805
LW
3773
3774#ifdef I_MATH
3775# include <math.h>
3776#else
32f822de 3777START_EXTERN_C
20ce7b12
GS
3778 double exp (double);
3779 double log (double);
3780 double log10 (double);
3781 double sqrt (double);
3782 double frexp (double,int*);
3783 double ldexp (double,int);
3784 double modf (double,double*);
3785 double sin (double);
3786 double cos (double);
3787 double atan2 (double,double);
3788 double pow (double,double);
32f822de 3789END_EXTERN_C
79072805
LW
3790#endif
3791
aa8b85de
JH
3792#if !defined(NV_INF) && defined(USE_LONG_DOUBLE) && defined(LDBL_INFINITY)
3793# define NV_INF LDBL_INFINITY
3794#endif
3795#if !defined(NV_INF) && defined(DBL_INFINITY)
3796# define NV_INF (NV)DBL_INFINITY
3797#endif
3798#if !defined(NV_INF) && defined(INFINITY)
3799# define NV_INF (NV)INFINITY
3800#endif
3801#if !defined(NV_INF) && defined(INF)
3802# define NV_INF (NV)INF
3803#endif
3804#if !defined(NV_INF) && defined(USE_LONG_DOUBLE) && defined(HUGE_VALL)
3805# define NV_INF (NV)HUGE_VALL
3806#endif