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