This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate:
[perl5.git] / perl.h
CommitLineData
a0d0e21e 1/* perl.h
a687059c 2 *
e6906430 3 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999,
31ab2e0d 4 * 2000, 2001, 2002, 2003, 2004, 2005 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
37# include "config.h"
38#endif
0cb96387 39
aaacdc8b
GS
40#if defined(USE_ITHREADS) && defined(USE_5005THREADS)
41# include "error: USE_ITHREADS and USE_5005THREADS are incompatible"
42#endif
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
f4a6c1f7
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
4d1ff10f 66#ifdef USE_5005THREADS
c5be433b
GS
67# ifndef PERL_IMPLICIT_CONTEXT
68# define PERL_IMPLICIT_CONTEXT
69# endif
c5be433b
GS
70#endif
71
c5be433b
GS
72#if defined(MULTIPLICITY)
73# ifndef PERL_IMPLICIT_CONTEXT
74# define PERL_IMPLICIT_CONTEXT
75# endif
c5be433b
GS
76#endif
77
026fd48b
GH
78/* undef WIN32 when building on Cygwin (for libwin32) - gph */
79#ifdef __CYGWIN__
80# undef WIN32
81# undef _WIN32
82#endif
83
10bc17b6
JH
84/* Use the reentrant APIs like localtime_r and getpwent_r */
85/* Win32 has naturally threadsafe libraries, no need to use any _r variants. */
6bf46c2a 86#if defined(USE_ITHREADS) && !defined(USE_REENTRANT_API) && !defined(NETWARE) && !defined(WIN32) && !defined(PERL_DARWIN)
10bc17b6
JH
87# define USE_REENTRANT_API
88#endif
89
ac6bedea
JH
90/* <--- here ends the logic shared by perl.h and makedef.pl */
91
7865c879 92/*
6bf46c2a
JH
93 * PERL_DARWIN for MacOSX (__APPLE__ exists but is not officially sanctioned)
94 * (The -DPERL_DARWIN comes from the hints/darwin.sh.)
7865c879
JH
95 * __bsdi__ for BSD/OS
96 */
6bf46c2a 97#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(PERL_DARWIN) || defined(__bsdi__) || defined(BSD41) || defined(BSD42) || defined(BSD43) || defined(BSD44)
7865c879
JH
98# ifndef BSDish
99# define BSDish
100# endif
101#endif
102
c5be433b 103#ifdef PERL_IMPLICIT_CONTEXT
4d1ff10f 104# ifdef USE_5005THREADS
c5be433b 105struct perl_thread;
24e8e624 106# define pTHX register struct perl_thread *thr PERL_UNUSED_DECL
c5be433b 107# define aTHX thr
411caa50 108# define dTHR dNOOP /* only backward compatibility */
fd89de3a 109# define dTHXa(a) pTHX = (struct perl_thread*)a
c5be433b 110# else
f63b9778
GS
111# ifndef MULTIPLICITY
112# define MULTIPLICITY
113# endif
24e8e624 114# define pTHX register PerlInterpreter *my_perl PERL_UNUSED_DECL
c5be433b 115# define aTHX my_perl
fd89de3a 116# define dTHXa(a) pTHX = (PerlInterpreter*)a
c5be433b 117# endif
fd89de3a 118# define dTHX pTHX = PERL_GET_THX
c5be433b 119# define pTHX_ pTHX,
c5be433b 120# define aTHX_ aTHX,
894356b3
GS
121# define pTHX_1 2
122# define pTHX_2 3
123# define pTHX_3 4
124# define pTHX_4 5
c5be433b
GS
125#endif
126
76e3520e
GS
127#define STATIC static
128#define CPERLscope(x) x
565764a8 129#define CPERLarg void
76e3520e 130#define CPERLarg_
e3b8966e 131#define _CPERLarg
1d583055
GS
132#define PERL_OBJECT_THIS
133#define _PERL_OBJECT_THIS
134#define PERL_OBJECT_THIS_
312caa8e 135#define CALL_FPTR(fptr) (*fptr)
76e3520e 136
312caa8e
CS
137#define CALLRUNOPS CALL_FPTR(PL_runops)
138#define CALLREGCOMP CALL_FPTR(PL_regcompp)
139#define CALLREGEXEC CALL_FPTR(PL_regexecp)
f722798b
IZ
140#define CALLREG_INTUIT_START CALL_FPTR(PL_regint_start)
141#define CALLREG_INTUIT_STRING CALL_FPTR(PL_regint_string)
142#define CALLREGFREE CALL_FPTR(PL_regfree)
14dd3ad8
GS
143
144#ifdef PERL_FLEXIBLE_EXCEPTIONS
145# define CALLPROTECT CALL_FPTR(PL_protect)
146#endif
312caa8e 147
44dbb695 148#ifdef HASATTRIBUTE
fc8a01dc 149# if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER)
3da75212
MB
150# define PERL_UNUSED_DECL
151# else
152# define PERL_UNUSED_DECL __attribute__((unused))
153# endif
44dbb695
JH
154#else
155# define PERL_UNUSED_DECL
156#endif
157
349b520e
DM
158/* gcc -Wall:
159 * for silencing unused variables that are actually used most of the time,
160 * but we cannot quite get rid of, such `ax' in PPCODE+noargs xsubs
161 */
162#define PERL_UNUSED_VAR(var) if (0) var = var
163
0cb96387 164#define NOOP (void)0
44dbb695 165#define dNOOP extern int Perl___notused PERL_UNUSED_DECL
71be2cbc 166
0cb96387
GS
167#ifndef pTHX
168# define pTHX void
169# define pTHX_
0cb96387
GS
170# define aTHX
171# define aTHX_
0cb96387
GS
172# define dTHXa(a) dNOOP
173# define dTHX dNOOP
894356b3
GS
174# define pTHX_1 1
175# define pTHX_2 2
176# define pTHX_3 3
177# define pTHX_4 4
0cb96387
GS
178#endif
179
b4f7f263
GS
180/* these are only defined for compatibility; should not be used internally */
181#if !defined(pTHXo) && !defined(PERL_CORE)
0cb96387
GS
182# define pTHXo pTHX
183# define pTHXo_ pTHX_
0cb96387
GS
184# define aTHXo aTHX
185# define aTHXo_ aTHX_
c5be433b 186# define dTHXo dTHX
71d280e3 187# define dTHXoa(x) dTHXa(x)
0cb96387
GS
188#endif
189
190#ifndef pTHXx
191# define pTHXx register PerlInterpreter *my_perl
192# define pTHXx_ pTHXx,
0cb96387
GS
193# define aTHXx my_perl
194# define aTHXx_ aTHXx,
c5be433b 195# define dTHXx dTHX
22c35a8c 196#endif
71be2cbc 197
1de7c2ac
GS
198/* Under PERL_IMPLICIT_SYS (used in Windows for fork emulation)
199 * PerlIO_foo() expands to PL_StdIO->pFOO(PL_StdIO, ...).
200 * dTHXs is therefore needed for all functions using PerlIO_foo(). */
201#ifdef PERL_IMPLICIT_SYS
202# define dTHXs dTHX
203#else
204# define dTHXs dNOOP
205#endif
206
326b05e3
GS
207#undef START_EXTERN_C
208#undef END_EXTERN_C
209#undef EXTERN_C
32f822de
GS
210#ifdef __cplusplus
211# define START_EXTERN_C extern "C" {
212# define END_EXTERN_C }
213# define EXTERN_C extern "C"
214#else
d460ef45
NIS
215# define START_EXTERN_C
216# define END_EXTERN_C
73c4f7a1 217# define EXTERN_C extern
32f822de
GS
218#endif
219
462e5cf6
MB
220#ifdef OP_IN_REGISTER
221# ifdef __GNUC__
222# define stringify_immed(s) #s
223# define stringify(s) stringify_immed(s)
d1ca3daa 224register struct op *Perl_op asm(stringify(OP_IN_REGISTER));
462e5cf6
MB
225# endif
226#endif
227
653fb8f3 228#if defined(__STRICT_ANSI__) && defined(PERL_GCC_PEDANTIC)
31ab2e0d
NC
229# if !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)
230# define PERL_GCC_BRACE_GROUPS_FORBIDDEN
231# endif
653fb8f3
JH
232#endif
233
728e2803 234/*
235 * STMT_START { statements; } STMT_END;
236 * can be used as a single statement, as in
237 * if (x) STMT_START { ... } STMT_END; else ...
238 *
239 * Trying to select a version that gives no warnings...
240 */
241#if !(defined(STMT_START) && defined(STMT_END))
653fb8f3 242# if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) && !defined(__cplusplus)
728e2803 243# define STMT_START (void)( /* gcc supports ``({ STATEMENTS; })'' */
244# define STMT_END )
245# else
246 /* Now which other defined()s do we need here ??? */
5b7ea690 247# if (VOIDFLAGS) && (defined(sun) || defined(__sun__)) && !defined(__GNUC__)
728e2803 248# define STMT_START if (1)
249# define STMT_END else (void)0
250# else
251# define STMT_START do
252# define STMT_END while (0)
253# endif
254# endif
255#endif
256
0cb96387 257#define WITH_THX(s) STMT_START { dTHX; s; } STMT_END
411caa50 258#define WITH_THR(s) WITH_THX(s)
ea0efc06 259
55497cff 260/*
261 * SOFT_CAST can be used for args to prototyped functions to retain some
262 * type checking; it only casts if the compiler does not know prototypes.
263 */
264#if defined(CAN_PROTOTYPE) && defined(DEBUGGING_COMPILE)
265#define SOFT_CAST(type)
266#else
267#define SOFT_CAST(type) (type)
268#endif
79072805 269
6ee623d5 270#ifndef BYTEORDER /* Should never happen -- byteorder is in config.h */
79072805
LW
271# define BYTEORDER 0x1234
272#endif
273
274/* Overall memory policy? */
275#ifndef CONSERVATIVE
276# define LIBERAL 1
277#endif
278
8ada0baa
JH
279#if 'A' == 65 && 'I' == 73 && 'J' == 74 && 'Z' == 90
280#define ASCIIish
281#else
282#undef ASCIIish
283#endif
284
79072805
LW
285/*
286 * The following contortions are brought to you on behalf of all the
287 * standards, semi-standards, de facto standards, not-so-de-facto standards
288 * of the world, as well as all the other botches anyone ever thought of.
289 * The basic theory is that if we work hard enough here, the rest of the
290 * code can be a lot prettier. Well, so much for theory. Sorry, Henry...
291 */
ac58e20f 292
ee0007ab 293/* define this once if either system, instead of cluttering up the src */
2986a63f 294#if defined(MSDOS) || defined(atarist) || defined(WIN32) || defined(NETWARE)
ee0007ab
LW
295#define DOSISH 1
296#endif
297
2986a63f 298#if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus) || defined( EPOC) || defined(NETWARE)
352d5a3a
LW
299# define STANDARD_C 1
300#endif
301
74563541 302#if defined(__cplusplus) || defined(WIN32) || defined(__sgi) || defined(__EMX__) || defined(__DGUX) || defined( EPOC) || defined(__QNX__) || defined(NETWARE) || defined(PERL_MICRO)
68dc0745 303# define DONT_DECLARE_STD 1
304#endif
305
352d5a3a 306#if defined(HASVOLATILE) || defined(STANDARD_C)
79072805 307# ifdef __cplusplus
cb69f87a 308# define VOL /* to temporarily suppress warnings */
79072805
LW
309# else
310# define VOL volatile
311# endif
663a0e37 312#else
79072805 313# define VOL
663a0e37
LW
314#endif
315
3280af22
NIS
316#define TAINT (PL_tainted = TRUE)
317#define TAINT_NOT (PL_tainted = FALSE)
318#define TAINT_IF(c) if (c) { PL_tainted = TRUE; }
319#define TAINT_ENV() if (PL_tainting) { taint_env(); }
22c35a8c 320#define TAINT_PROPER(s) if (PL_tainting) { taint_proper(Nullch, s); }
a687059c 321
d460ef45 322/* XXX All process group stuff is handled in pp_sys.c. Should these
a6e633de 323 defines move there? If so, I could simplify this a lot. --AD 9/96.
324*/
325/* Process group stuff changed from traditional BSD to POSIX.
326 perlfunc.pod documents the traditional BSD-style syntax, so we'll
327 try to preserve that, if possible.
328*/
329#ifdef HAS_SETPGID
330# define BSD_SETPGRP(pid, pgrp) setpgid((pid), (pgrp))
c07a80fd 331#else
a6e633de 332# if defined(HAS_SETPGRP) && defined(USE_BSD_SETPGRP)
333# define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp))
334# else
335# ifdef HAS_SETPGRP2 /* DG/UX */
336# define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp))
337# endif
338# endif
339#endif
340#if defined(BSD_SETPGRP) && !defined(HAS_SETPGRP)
341# define HAS_SETPGRP /* Well, effectively it does . . . */
342#endif
343
344/* getpgid isn't POSIX, but at least Solaris and Linux have it, and it makes
345 our life easier :-) so we'll try it.
346*/
347#ifdef HAS_GETPGID
348# define BSD_GETPGRP(pid) getpgid((pid))
349#else
350# if defined(HAS_GETPGRP) && defined(USE_BSD_GETPGRP)
351# define BSD_GETPGRP(pid) getpgrp((pid))
352# else
353# ifdef HAS_GETPGRP2 /* DG/UX */
354# define BSD_GETPGRP(pid) getpgrp2((pid))
355# endif
356# endif
357#endif
358#if defined(BSD_GETPGRP) && !defined(HAS_GETPGRP)
359# define HAS_GETPGRP /* Well, effectively it does . . . */
360#endif
361
d460ef45 362/* These are not exact synonyms, since setpgrp() and getpgrp() may
a6e633de 363 have different behaviors, but perl.h used to define USE_BSDPGRP
364 (prior to 5.003_05) so some extension might depend on it.
365*/
366#if defined(USE_BSD_SETPGRP) || defined(USE_BSD_GETPGRP)
367# ifndef USE_BSDPGRP
368# define USE_BSDPGRP
369# endif
663a0e37
LW
370#endif
371
8ac5a1fe
MH
372/* HP-UX 10.X CMA (Common Multithreaded Architecure) insists that
373 pthread.h must be included before all other header files.
374*/
4d1ff10f 375#if (defined(USE_5005THREADS) || defined(USE_ITHREADS)) \
1feb2720 376 && defined(PTHREAD_H_FIRST) && defined(I_PTHREAD)
8ac5a1fe
MH
377# include <pthread.h>
378#endif
379
760ac839
LW
380#ifndef _TYPES_ /* If types.h defines this it's easy. */
381# ifndef major /* Does everyone's types.h define this? */
382# include <sys/types.h>
c07a80fd 383# endif
663a0e37
LW
384#endif
385
760ac839
LW
386#ifdef __cplusplus
387# ifndef I_STDARG
388# define I_STDARG 1
389# endif
390#endif
391
392#ifdef I_STDARG
393# include <stdarg.h>
394#else
395# ifdef I_VARARGS
396# include <varargs.h>
397# endif
398#endif
399
4633a7c4 400#ifdef USE_NEXT_CTYPE
0c30d9ec 401
092bebab
JH
402#if NX_CURRENT_COMPILER_RELEASE >= 500
403# include <bsd/ctypes.h>
404#else
405# if NX_CURRENT_COMPILER_RELEASE >= 400
406# include <objc/NXCType.h>
407# else /* NX_CURRENT_COMPILER_RELEASE < 400 */
408# include <appkit/NXCType.h>
409# endif /* NX_CURRENT_COMPILER_RELEASE >= 400 */
410#endif /* NX_CURRENT_COMPILER_RELEASE >= 500 */
0c30d9ec 411
412#else /* !USE_NEXT_CTYPE */
fe14fcc3 413#include <ctype.h>
0c30d9ec 414#endif /* USE_NEXT_CTYPE */
a0d0e21e
LW
415
416#ifdef METHOD /* Defined by OSF/1 v3.0 by ctype.h */
417#undef METHOD
a0d0e21e
LW
418#endif
419
12ae5dfc
JH
420#ifdef PERL_MICRO
421# define NO_LOCALE
422#endif
423
4633a7c4 424#ifdef I_LOCALE
36477c24 425# include <locale.h>
4633a7c4
LW
426#endif
427
36477c24 428#if !defined(NO_LOCALE) && defined(HAS_SETLOCALE)
429# define USE_LOCALE
430# if !defined(NO_LOCALE_COLLATE) && defined(LC_COLLATE) \
431 && defined(HAS_STRXFRM)
432# define USE_LOCALE_COLLATE
433# endif
434# if !defined(NO_LOCALE_CTYPE) && defined(LC_CTYPE)
435# define USE_LOCALE_CTYPE
436# endif
437# if !defined(NO_LOCALE_NUMERIC) && defined(LC_NUMERIC)
438# define USE_LOCALE_NUMERIC
439# endif
440#endif /* !NO_LOCALE && HAS_SETLOCALE */
a0d0e21e 441
fe14fcc3 442#include <setjmp.h>
79072805 443
a0d0e21e 444#ifdef I_SYS_PARAM
79072805
LW
445# ifdef PARAM_NEEDS_TYPES
446# include <sys/types.h>
447# endif
448# include <sys/param.h>
352d5a3a 449#endif
79072805 450
79072805 451/* Use all the "standard" definitions? */
a0d0e21e 452#if defined(STANDARD_C) && defined(I_STDLIB)
79072805 453# include <stdlib.h>
ff68c719 454#endif
03a14243 455
3f270f98
JH
456/* If this causes problems, set i_unistd=undef in the hint file. */
457#ifdef I_UNISTD
458# include <unistd.h>
459#endif
460
7114a2d2 461#if defined(HAS_SYSCALL) && !defined(HAS_SYSCALL_PROTO) && !defined(PERL_MICRO)
2ef53570
JH
462int syscall(int, ...);
463#endif
464
7114a2d2 465#if defined(HAS_USLEEP) && !defined(HAS_USLEEP_PROTO) && !defined(PERL_MICRO)
fa0a29af 466int usleep(unsigned int);
2ef53570
JH
467#endif
468
9a34ef1d
GS
469#ifdef PERL_MICRO /* Last chance to export Perl_my_swap */
470# define MYSWAP
471#endif
472
cc3ea0aa
NC
473#ifdef PERL_CORE
474
475/* macros for correct constant construction */
476# if INTSIZE >= 2
477# define U16_CONST(x) ((U16)x##U)
478# else
479# define U16_CONST(x) ((U16)x##UL)
480# endif
481
482# if INTSIZE >= 4
483# define U32_CONST(x) ((U32)x##U)
484# else
485# define U32_CONST(x) ((U32)x##UL)
486# endif
487
488# ifdef HAS_QUAD
489# if INTSIZE >= 8
490# define U64_CONST(x) ((U64)x##U)
491# elif LONGSIZE >= 8
492# define U64_CONST(x) ((U64)x##UL)
493# elif QUADKIND == QUAD_IS_LONG_LONG
494# define U64_CONST(x) ((U64)x##ULL)
495# else /* best guess we can make */
496# define U64_CONST(x) ((U64)x##UL)
497# endif
498# endif
499
500/* byte-swapping functions for big-/little-endian conversion */
501# define _swab_16_(x) ((U16)( \
502 (((U16)(x) & U16_CONST(0x00ff)) << 8) | \
503 (((U16)(x) & U16_CONST(0xff00)) >> 8) ))
504
505# define _swab_32_(x) ((U32)( \
506 (((U32)(x) & U32_CONST(0x000000ff)) << 24) | \
507 (((U32)(x) & U32_CONST(0x0000ff00)) << 8) | \
508 (((U32)(x) & U32_CONST(0x00ff0000)) >> 8) | \
509 (((U32)(x) & U32_CONST(0xff000000)) >> 24) ))
510
511# ifdef HAS_QUAD
512# define _swab_64_(x) ((U64)( \
513 (((U64)(x) & U64_CONST(0x00000000000000ff)) << 56) | \
514 (((U64)(x) & U64_CONST(0x000000000000ff00)) << 40) | \
515 (((U64)(x) & U64_CONST(0x0000000000ff0000)) << 24) | \
516 (((U64)(x) & U64_CONST(0x00000000ff000000)) << 8) | \
517 (((U64)(x) & U64_CONST(0x000000ff00000000)) >> 8) | \
518 (((U64)(x) & U64_CONST(0x0000ff0000000000)) >> 24) | \
519 (((U64)(x) & U64_CONST(0x00ff000000000000)) >> 40) | \
520 (((U64)(x) & U64_CONST(0xff00000000000000)) >> 56) ))
521# endif
522
523/*----------------------------------------------------------------------------*/
524# if BYTEORDER == 0x1234 || BYTEORDER == 0x12345678 /* little-endian */
525/*----------------------------------------------------------------------------*/
526# define my_htole16(x) (x)
527# define my_letoh16(x) (x)
528# define my_htole32(x) (x)
529# define my_letoh32(x) (x)
530# define my_htobe16(x) _swab_16_(x)
531# define my_betoh16(x) _swab_16_(x)
532# define my_htobe32(x) _swab_32_(x)
533# define my_betoh32(x) _swab_32_(x)
534# ifdef HAS_QUAD
535# define my_htole64(x) (x)
536# define my_letoh64(x) (x)
537# define my_htobe64(x) _swab_64_(x)
538# define my_betoh64(x) _swab_64_(x)
539# endif
540# define my_htoles(x) (x)
541# define my_letohs(x) (x)
542# define my_htolei(x) (x)
543# define my_letohi(x) (x)
544# define my_htolel(x) (x)
545# define my_letohl(x) (x)
546# if SHORTSIZE == 1
547# define my_htobes(x) (x)
548# define my_betohs(x) (x)
549# elif SHORTSIZE == 2
550# define my_htobes(x) _swab_16_(x)
551# define my_betohs(x) _swab_16_(x)
552# elif SHORTSIZE == 4
553# define my_htobes(x) _swab_32_(x)
554# define my_betohs(x) _swab_32_(x)
555# elif SHORTSIZE == 8
556# define my_htobes(x) _swab_64_(x)
557# define my_betohs(x) _swab_64_(x)
558# else
559# define PERL_NEED_MY_HTOBES
560# define PERL_NEED_MY_BETOHS
561# endif
562# if INTSIZE == 1
563# define my_htobei(x) (x)
564# define my_betohi(x) (x)
565# elif INTSIZE == 2
566# define my_htobei(x) _swab_16_(x)
567# define my_betohi(x) _swab_16_(x)
568# elif INTSIZE == 4
569# define my_htobei(x) _swab_32_(x)
570# define my_betohi(x) _swab_32_(x)
571# elif INTSIZE == 8
572# define my_htobei(x) _swab_64_(x)
573# define my_betohi(x) _swab_64_(x)
574# else
575# define PERL_NEED_MY_HTOBEI
576# define PERL_NEED_MY_BETOHI
577# endif
578# if LONGSIZE == 1
579# define my_htobel(x) (x)
580# define my_betohl(x) (x)
581# elif LONGSIZE == 2
582# define my_htobel(x) _swab_16_(x)
583# define my_betohl(x) _swab_16_(x)
584# elif LONGSIZE == 4
585# define my_htobel(x) _swab_32_(x)
586# define my_betohl(x) _swab_32_(x)
587# elif LONGSIZE == 8
588# define my_htobel(x) _swab_64_(x)
589# define my_betohl(x) _swab_64_(x)
590# else
591# define PERL_NEED_MY_HTOBEL
592# define PERL_NEED_MY_BETOHL
593# endif
594# define my_htolen(p,n) NOOP
595# define my_letohn(p,n) NOOP
596# define my_htoben(p,n) my_swabn(p,n)
597# define my_betohn(p,n) my_swabn(p,n)
598/*----------------------------------------------------------------------------*/
599# elif BYTEORDER == 0x4321 || BYTEORDER == 0x87654321 /* big-endian */
600/*----------------------------------------------------------------------------*/
601# define my_htobe16(x) (x)
602# define my_betoh16(x) (x)
603# define my_htobe32(x) (x)
604# define my_betoh32(x) (x)
605# define my_htole16(x) _swab_16_(x)
606# define my_letoh16(x) _swab_16_(x)
607# define my_htole32(x) _swab_32_(x)
608# define my_letoh32(x) _swab_32_(x)
609# ifdef HAS_QUAD
610# define my_htobe64(x) (x)
611# define my_betoh64(x) (x)
612# define my_htole64(x) _swab_64_(x)
613# define my_letoh64(x) _swab_64_(x)
614# endif
615# define my_htobes(x) (x)
616# define my_betohs(x) (x)
617# define my_htobei(x) (x)
618# define my_betohi(x) (x)
619# define my_htobel(x) (x)
620# define my_betohl(x) (x)
621# if SHORTSIZE == 1
622# define my_htoles(x) (x)
623# define my_letohs(x) (x)
624# elif SHORTSIZE == 2
625# define my_htoles(x) _swab_16_(x)
626# define my_letohs(x) _swab_16_(x)
627# elif SHORTSIZE == 4
628# define my_htoles(x) _swab_32_(x)
629# define my_letohs(x) _swab_32_(x)
630# elif SHORTSIZE == 8
631# define my_htoles(x) _swab_64_(x)
632# define my_letohs(x) _swab_64_(x)
633# else
634# define PERL_NEED_MY_HTOLES
635# define PERL_NEED_MY_LETOHS
636# endif
637# if INTSIZE == 1
638# define my_htolei(x) (x)
639# define my_letohi(x) (x)
640# elif INTSIZE == 2
641# define my_htolei(x) _swab_16_(x)
642# define my_letohi(x) _swab_16_(x)
643# elif INTSIZE == 4
644# define my_htolei(x) _swab_32_(x)
645# define my_letohi(x) _swab_32_(x)
646# elif INTSIZE == 8
647# define my_htolei(x) _swab_64_(x)
648# define my_letohi(x) _swab_64_(x)
649# else
650# define PERL_NEED_MY_HTOLEI
651# define PERL_NEED_MY_LETOHI
652# endif
653# if LONGSIZE == 1
654# define my_htolel(x) (x)
655# define my_letohl(x) (x)
656# elif LONGSIZE == 2
657# define my_htolel(x) _swab_16_(x)
658# define my_letohl(x) _swab_16_(x)
659# elif LONGSIZE == 4
660# define my_htolel(x) _swab_32_(x)
661# define my_letohl(x) _swab_32_(x)
662# elif LONGSIZE == 8
663# define my_htolel(x) _swab_64_(x)
664# define my_letohl(x) _swab_64_(x)
665# else
666# define PERL_NEED_MY_HTOLEL
667# define PERL_NEED_MY_LETOHL
668# endif
669# define my_htolen(p,n) my_swabn(p,n)
670# define my_letohn(p,n) my_swabn(p,n)
671# define my_htoben(p,n) NOOP
672# define my_betohn(p,n) NOOP
673/*----------------------------------------------------------------------------*/
674# else /* all other byte-orders */
675/*----------------------------------------------------------------------------*/
676# define PERL_NEED_MY_HTOLE16
677# define PERL_NEED_MY_LETOH16
678# define PERL_NEED_MY_HTOBE16
679# define PERL_NEED_MY_BETOH16
680# define PERL_NEED_MY_HTOLE32
681# define PERL_NEED_MY_LETOH32
682# define PERL_NEED_MY_HTOBE32
683# define PERL_NEED_MY_BETOH32
684# ifdef HAS_QUAD
685# define PERL_NEED_MY_HTOLE64
686# define PERL_NEED_MY_LETOH64
687# define PERL_NEED_MY_HTOBE64
688# define PERL_NEED_MY_BETOH64
689# endif
690# define PERL_NEED_MY_HTOLES
691# define PERL_NEED_MY_LETOHS
692# define PERL_NEED_MY_HTOBES
693# define PERL_NEED_MY_BETOHS
694# define PERL_NEED_MY_HTOLEI
695# define PERL_NEED_MY_LETOHI
696# define PERL_NEED_MY_HTOBEI
697# define PERL_NEED_MY_BETOHI
698# define PERL_NEED_MY_HTOLEL
699# define PERL_NEED_MY_LETOHL
700# define PERL_NEED_MY_HTOBEL
701# define PERL_NEED_MY_BETOHL
702/*----------------------------------------------------------------------------*/
703# endif /* end of byte-order macros */
704/*----------------------------------------------------------------------------*/
705
706#endif /* PERL_CORE */
707
66a93824
NIS
708/* Cannot include embed.h here on Win32 as win32.h has not
709 yet been included and defines some config variables e.g. HAVE_INTERP_INTERN
710 */
96e176bf 711#if !defined(PERL_FOR_X2P) && !(defined(WIN32)||defined(VMS))
cea2e8a9
GS
712# include "embed.h"
713#endif
714
c31fac66
GS
715#define MEM_SIZE Size_t
716
51371543
GS
717#if defined(STANDARD_C) && defined(I_STDDEF)
718# include <stddef.h>
719# define STRUCT_OFFSET(s,m) offsetof(s,m)
720#else
721# define STRUCT_OFFSET(s,m) (Size_t)(&(((s *)0)->m))
722#endif
723
724#if defined(I_STRING) || defined(__cplusplus)
725# include <string.h>
726#else
727# include <strings.h>
728#endif
729
55497cff 730/* This comes after <stdlib.h> so we don't try to change the standard
731 * library prototypes; we'll use our own in proto.h instead. */
03a14243 732
4633a7c4 733#ifdef MYMALLOC
86058a2d 734# ifdef PERL_POLLUTE_MALLOC
ee13e175 735# ifndef PERL_EXTMALLOC_DEF
86058a2d
GS
736# define Perl_malloc malloc
737# define Perl_calloc calloc
738# define Perl_realloc realloc
739# define Perl_mfree free
ee13e175 740# endif
86058a2d
GS
741# else
742# define EMBEDMYMALLOC /* for compatibility */
743# endif
827e134a 744
651b9576
GS
745# define safemalloc Perl_malloc
746# define safecalloc Perl_calloc
747# define saferealloc Perl_realloc
748# define safefree Perl_mfree
26776375
JH
749# define CHECK_MALLOC_TOO_LATE_FOR_(code) STMT_START { \
750 if (!PL_tainting && MallocCfg_ptr[MallocCfg_cfg_env_read]) \
751 code; \
752 } STMT_END
753# define CHECK_MALLOC_TOO_LATE_FOR(ch) \
754 CHECK_MALLOC_TOO_LATE_FOR_(MALLOC_TOO_LATE_FOR(ch))
755# define panic_write2(s) write(2, s, strlen(s))
756# define CHECK_MALLOC_TAINT(newval) \
757 CHECK_MALLOC_TOO_LATE_FOR_( \
758 if (newval) { \
759 panic_write2("panic: tainting with $ENV{PERL_MALLOC_OPT}\n");\
760 exit(1); })
26776375 761# define MALLOC_CHECK_TAINT(argc,argv,env) STMT_START { \
2adc3af3 762 if (doing_taint(argc,argv,env)) { \
26776375
JH
763 MallocCfg_ptr[MallocCfg_skip_cfg_env] = 1; \
764 }} STMT_END;
f2517201
GS
765#else /* MYMALLOC */
766# define safemalloc safesysmalloc
767# define safecalloc safesyscalloc
768# define saferealloc safesysrealloc
769# define safefree safesysfree
26776375
JH
770# define CHECK_MALLOC_TOO_LATE_FOR(ch) ((void)0)
771# define CHECK_MALLOC_TAINT(newval) ((void)0)
772# define MALLOC_CHECK_TAINT(argc,argv,env)
55497cff 773#endif /* MYMALLOC */
4633a7c4 774
db910c29 775#define TOO_LATE_FOR_(ch,s) Perl_croak(aTHX_ "\"-%c\" is on the #! line, it must also be used on the command line%s", (char)(ch), s)
26776375
JH
776#define TOO_LATE_FOR(ch) TOO_LATE_FOR_(ch, "")
777#define MALLOC_TOO_LATE_FOR(ch) TOO_LATE_FOR_(ch, " with $ENV{PERL_MALLOC_OPT}")
778#define MALLOC_CHECK_TAINT2(argc,argv) MALLOC_CHECK_TAINT(argc,argv,NULL)
779
a0d0e21e
LW
780#if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
781#define strchr index
782#define strrchr rindex
783#endif
784
16d20bd9
AD
785#ifdef I_MEMORY
786# include <memory.h>
787#endif
788
fe14fcc3 789#ifdef HAS_MEMCPY
85e6fe83 790# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
fe14fcc3 791# ifndef memcpy
20ce7b12 792 extern char * memcpy (char*, char*, int);
ee0007ab
LW
793# endif
794# endif
795#else
796# ifndef memcpy
797# ifdef HAS_BCOPY
798# define memcpy(d,s,l) bcopy(s,d,l)
799# else
800# define memcpy(d,s,l) my_bcopy(s,d,l)
801# endif
802# endif
803#endif /* HAS_MEMCPY */
fe14fcc3 804
ee0007ab 805#ifdef HAS_MEMSET
85e6fe83 806# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
ee0007ab 807# ifndef memset
20ce7b12 808 extern char *memset (char*, int, int);
ee0007ab
LW
809# endif
810# endif
ee0007ab 811#else
12ae5dfc 812# undef memset
fc36a67e 813# define memset(d,c,l) my_memset(d,c,l)
ee0007ab
LW
814#endif /* HAS_MEMSET */
815
85e6fe83 816#if !defined(HAS_MEMMOVE) && !defined(memmove)
2304df62 817# if defined(HAS_BCOPY) && defined(HAS_SAFE_BCOPY)
79072805
LW
818# define memmove(d,s,l) bcopy(s,d,l)
819# else
2304df62 820# if defined(HAS_MEMCPY) && defined(HAS_SAFE_MEMCPY)
79072805 821# define memmove(d,s,l) memcpy(d,s,l)
ee0007ab 822# else
79072805 823# define memmove(d,s,l) my_bcopy(s,d,l)
ee0007ab 824# endif
352d5a3a 825# endif
d9d8d8de 826#endif
ee0007ab 827
36477c24 828#if defined(mips) && defined(ultrix) && !defined(__STDC__)
829# undef HAS_MEMCMP
830#endif
831
832#if defined(HAS_MEMCMP) && defined(HAS_SANE_MEMCMP)
85e6fe83 833# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
ee0007ab 834# ifndef memcmp
20ce7b12 835 extern int memcmp (char*, char*, int);
ee0007ab
LW
836# endif
837# endif
36477c24 838# ifdef BUGGY_MSC
56b65a99 839# pragma function(memcmp)
36477c24 840# endif
ee0007ab
LW
841#else
842# ifndef memcmp
ecfc5424 843# define memcmp my_memcmp
352d5a3a 844# endif
36477c24 845#endif /* HAS_MEMCMP && HAS_SANE_MEMCMP */
8d063cd8 846
fc36a67e 847#ifndef memzero
c635e13b 848# ifdef HAS_MEMSET
849# define memzero(d,l) memset(d,0,l)
79072805 850# else
c635e13b 851# ifdef HAS_BZERO
852# define memzero(d,l) bzero(d,l)
79072805 853# else
fc36a67e 854# define memzero(d,l) my_bzero(d,l)
79072805
LW
855# endif
856# endif
d9d8d8de 857#endif
378cc40b 858
75a5c1c6 859#ifndef PERL_MICRO
0f27ced1
JH
860#ifndef memchr
861# ifndef HAS_MEMCHR
862# define memchr(s,c,n) ninstr((char*)(s), ((char*)(s)) + n, &(c), &(c) + 1)
863# endif
864#endif
75a5c1c6 865#endif
0f27ced1 866
36477c24 867#ifndef HAS_BCMP
868# ifndef bcmp
869# define bcmp(s1,s2,l) memcmp(s1,s2,l)
79072805 870# endif
36477c24 871#endif /* !HAS_BCMP */
378cc40b 872
ae986130 873#ifdef I_NETINET_IN
79072805 874# include <netinet/in.h>
ae986130
LW
875#endif
876
28e8609d
JH
877#ifdef I_ARPA_INET
878# include <arpa/inet.h>
879#endif
880
84902520
TB
881#if defined(SF_APPEND) && defined(USE_SFIO) && defined(I_SFIO)
882/* <sfio.h> defines SF_APPEND and <sys/stat.h> might define SF_APPEND
883 * (the neo-BSD seem to do this). */
884# undef SF_APPEND
885#endif
886
1aef975c 887#ifdef I_SYS_STAT
84902520 888# include <sys/stat.h>
1aef975c 889#endif
79072805 890
a0d0e21e
LW
891/* The stat macros for Amdahl UTS, Unisoft System V/88 (and derivatives
892 like UTekV) are broken, sometimes giving false positives. Undefine
893 them here and let the code below set them to proper values.
894
895 The ghs macro stands for GreenHills Software C-1.8.5 which
896 is the C compiler for sysV88 and the various derivatives.
897 This header file bug is corrected in gcc-2.5.8 and later versions.
898 --Kaveh Ghazi (ghazi@noc.rutgers.edu) 10/3/94. */
899
900#if defined(uts) || (defined(m88k) && defined(ghs))
79072805
LW
901# undef S_ISDIR
902# undef S_ISCHR
903# undef S_ISBLK
904# undef S_ISREG
905# undef S_ISFIFO
906# undef S_ISLNK
ee0007ab 907#endif
135863df 908
663a0e37
LW
909#ifdef I_TIME
910# include <time.h>
ffed7fef 911#endif
663a0e37 912
fe14fcc3 913#ifdef I_SYS_TIME
85e6fe83 914# ifdef I_SYS_TIME_KERNEL
663a0e37
LW
915# define KERNEL
916# endif
917# include <sys/time.h>
85e6fe83 918# ifdef I_SYS_TIME_KERNEL
663a0e37
LW
919# undef KERNEL
920# endif
a687059c 921#endif
135863df 922
55497cff 923#if defined(HAS_TIMES) && defined(I_SYS_TIMES)
85e6fe83 924# include <sys/times.h>
d9d8d8de 925#endif
8d063cd8 926
fe14fcc3 927#if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
79072805 928# undef HAS_STRERROR
663a0e37
LW
929#endif
930
931#include <errno.h>
1e743fda 932
acfe0abc 933#if defined(WIN32) && defined(PERL_IMPLICIT_SYS)
b4748376
NIS
934# define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */
935#endif
936
7b24b0b0
JH
937/* In Tru64 use the 4.4BSD struct msghdr, not the 4.3 one.
938 * This is important for using IPv6.
939 * For OSF/1 3.2, however, defining _SOCKADDR_LEN would be
940 * a bad idea since it breaks send() and recv(). */
941#if defined(__osf__) && defined(__alpha) && !defined(_SOCKADDR_LEN) && !defined(DEC_OSF1_3_X)
942# define _SOCKADDR_LEN
943#endif
944
8d3f517a 945#if defined(HAS_SOCKET) && !defined(VMS) && !defined(WIN32) /* VMS/WIN32 handle sockets via vmsish.h/win32.h */
1e743fda
JH
946# include <sys/socket.h>
947# if defined(USE_SOCKS) && defined(I_SOCKS)
948# if !defined(INCLUDE_PROTOTYPES)
949# define INCLUDE_PROTOTYPES /* for <socks.h> */
950# define PERL_SOCKS_NEED_PROTOTYPES
951# endif
4d1ff10f 952# ifdef USE_5005THREADS
c3dedce1 953# define PERL_USE_THREADS /* store our value */
4d1ff10f 954# undef USE_5005THREADS
c3dedce1 955# endif
1e743fda 956# include <socks.h>
4d1ff10f
AB
957# ifdef USE_5005THREADS
958# undef USE_5005THREADS /* socks.h does this on its own */
c3dedce1
JH
959# endif
960# ifdef PERL_USE_THREADS
4d1ff10f 961# define USE_5005THREADS /* restore our value */
c3dedce1
JH
962# undef PERL_USE_THREADS
963# endif
1e743fda
JH
964# ifdef PERL_SOCKS_NEED_PROTOTYPES /* keep cpp space clean */
965# undef INCLUDE_PROTOTYPES
966# undef PERL_SOCKS_NEED_PROTOTYPES
ed6116ce 967# endif
d460ef45 968# endif
1e743fda 969# ifdef I_NETDB
2986a63f
JH
970# ifdef NETWARE
971# include<stdio.h>
972# endif
1e743fda
JH
973# include <netdb.h>
974# endif
975# ifndef ENOTSOCK
976# ifdef I_NET_ERRNO
977# include <net/errno.h>
978# endif
979# endif
980#endif
981
fa0a29af 982/* sockatmark() is so new (2001) that many places might have it hidden
a45b0351
JH
983 * behind some -D_BLAH_BLAH_SOURCE guard. The __THROW magic is required
984 * e.g. in Gentoo, see http://bugs.gentoo.org/show_bug.cgi?id=12605 */
fa0a29af 985#if defined(HAS_SOCKATMARK) && !defined(HAS_SOCKATMARK_PROTO)
a45b0351
JH
986# if defined(__THROW) && defined(__GLIBC__)
987int sockatmark(int) __THROW;
988# else
2ef53570 989int sockatmark(int);
a45b0351 990# endif
2ef53570
JH
991#endif
992
1e743fda
JH
993#ifdef SETERRNO
994# undef SETERRNO /* SOCKS might have defined this */
ed6116ce 995#endif
f86702cc 996
997#ifdef VMS
998# define SETERRNO(errcode,vmserrcode) \
999 STMT_START { \
1000 set_errno(errcode); \
1001 set_vaxc_errno(vmserrcode); \
1002 } STMT_END
5b7ea690
JH
1003# define LIB_INVARG LIB$_INVARG
1004# define RMS_DIR RMS$_DIR
1005# define RMS_FAC RMS$_FAC
1006# define RMS_FEX RMS$_FEX
1007# define RMS_FNF RMS$_FNF
1008# define RMS_IFI RMS$_IFI
1009# define RMS_ISI RMS$_ISI
1010# define RMS_PRV RMS$_PRV
1011# define SS_ACCVIO SS$_ACCVIO
1012# define SS_DEVOFFLINE SS$_DEVOFFLINE
1013# define SS_IVCHAN SS$_IVCHAN
1014# define SS_NORMAL SS$_NORMAL
748a9306 1015#else
aba27d88 1016# define SETERRNO(errcode,vmserrcode) (errno = (errcode))
5b7ea690
JH
1017# define LIB_INVARG 0
1018# define RMS_DIR 0
1019# define RMS_FAC 0
1020# define RMS_FEX 0
1021# define RMS_FNF 0
1022# define RMS_IFI 0
1023# define RMS_ISI 0
1024# define RMS_PRV 0
1025# define SS_ACCVIO 0
1026# define SS_DEVOFFLINE 0
1027# define SS_IVCHAN 0
1028# define SS_NORMAL 0
748a9306 1029#endif
ed6116ce 1030
4d1ff10f 1031#ifdef USE_5005THREADS
38a03e6e 1032# define ERRSV (thr->errsv)
940cb80d
MB
1033# define DEFSV THREADSV(0)
1034# define SAVE_DEFSV save_threadsv(0)
38a03e6e 1035#else
3280af22 1036# define ERRSV GvSV(PL_errgv)
3280af22
NIS
1037# define DEFSV GvSV(PL_defgv)
1038# define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
4d1ff10f 1039#endif /* USE_5005THREADS */
38a03e6e 1040
98eae8f5
GS
1041#define ERRHV GvHV(PL_errgv) /* XXX unused, here for compatibility */
1042
55497cff 1043#ifndef errno
5ff3f7a4
GS
1044 extern int errno; /* ANSI allows errno to be an lvalue expr.
1045 * For example in multithreaded environments
1046 * something like this might happen:
1047 * extern int *_errno(void);
1048 * #define errno (*_errno()) */
d9d8d8de 1049#endif
663a0e37 1050
2304df62 1051#ifdef HAS_STRERROR
a0d0e21e 1052# ifdef VMS
20ce7b12 1053 char *strerror (int,...);
a0d0e21e 1054# else
68dc0745 1055#ifndef DONT_DECLARE_STD
20ce7b12 1056 char *strerror (int);
68dc0745 1057#endif
a0d0e21e 1058# endif
2304df62
AD
1059# ifndef Strerror
1060# define Strerror strerror
1061# endif
1062#else
1063# ifdef HAS_SYS_ERRLIST
79072805
LW
1064 extern int sys_nerr;
1065 extern char *sys_errlist[];
2304df62
AD
1066# ifndef Strerror
1067# define Strerror(e) \
79072805 1068 ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
2304df62 1069# endif
79072805 1070# endif
35c8bce7 1071#endif
663a0e37 1072
2304df62 1073#ifdef I_SYS_IOCTL
79072805
LW
1074# ifndef _IOCTL_
1075# include <sys/ioctl.h>
1076# endif
a687059c
LW
1077#endif
1078
ee0007ab 1079#if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
79072805
LW
1080# ifdef HAS_SOCKETPAIR
1081# undef HAS_SOCKETPAIR
1082# endif
2304df62
AD
1083# ifdef I_NDBM
1084# undef I_NDBM
79072805 1085# endif
a687059c
LW
1086#endif
1087
02fc2eee
NC
1088#ifndef HAS_SOCKETPAIR
1089# ifdef HAS_SOCKET
1090# define socketpair Perl_my_socketpair
1091# endif
1092#endif
1093
a687059c 1094#if INTSIZE == 2
79072805
LW
1095# define htoni htons
1096# define ntohi ntohs
a687059c 1097#else
79072805
LW
1098# define htoni htonl
1099# define ntohi ntohl
a687059c
LW
1100#endif
1101
a0d0e21e 1102/* Configure already sets Direntry_t */
35c8bce7 1103#if defined(I_DIRENT)
663a0e37 1104# include <dirent.h>
8f1f23e8
W
1105 /* NeXT needs dirent + sys/dir.h */
1106# if defined(I_SYS_DIR) && (defined(NeXT) || defined(__NeXT__))
a0d0e21e
LW
1107# include <sys/dir.h>
1108# endif
ae986130 1109#else
fe14fcc3 1110# ifdef I_SYS_NDIR
79a0689e 1111# include <sys/ndir.h>
663a0e37 1112# else
fe14fcc3 1113# ifdef I_SYS_DIR
79a0689e
LW
1114# ifdef hp9000s500
1115# include <ndir.h> /* may be wrong in the future */
1116# else
1117# include <sys/dir.h>
1118# endif
663a0e37
LW
1119# endif
1120# endif
4633a7c4 1121#endif
a687059c 1122
12ae5dfc
JH
1123#ifdef PERL_MICRO
1124# ifndef DIR
1125# define DIR void
1126# endif
1127#endif
1128
352d5a3a
LW
1129#ifdef FPUTS_BOTCH
1130/* work around botch in SunOS 4.0.1 and 4.0.2 */
1131# ifndef fputs
79072805 1132# define fputs(sv,fp) fprintf(fp,"%s",sv)
352d5a3a
LW
1133# endif
1134#endif
1135
c623bd54
LW
1136/*
1137 * The following gobbledygook brought to you on behalf of __STDC__.
1138 * (I could just use #ifndef __STDC__, but this is more bulletproof
1139 * in the face of half-implementations.)
1140 */
1141
7114a2d2 1142#if defined(I_SYSMODE) && !defined(PERL_MICRO)
ca6e1c26
JH
1143#include <sys/mode.h>
1144#endif
1145
c623bd54
LW
1146#ifndef S_IFMT
1147# ifdef _S_IFMT
1148# define S_IFMT _S_IFMT
1149# else
1150# define S_IFMT 0170000
1151# endif
1152#endif
1153
1154#ifndef S_ISDIR
1155# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
1156#endif
1157
1158#ifndef S_ISCHR
1159# define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
1160#endif
1161
1162#ifndef S_ISBLK
fe14fcc3
LW
1163# ifdef S_IFBLK
1164# define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
1165# else
1166# define S_ISBLK(m) (0)
1167# endif
c623bd54
LW
1168#endif
1169
1170#ifndef S_ISREG
1171# define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
1172#endif
1173
1174#ifndef S_ISFIFO
fe14fcc3
LW
1175# ifdef S_IFIFO
1176# define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
1177# else
1178# define S_ISFIFO(m) (0)
1179# endif
c623bd54
LW
1180#endif
1181
1182#ifndef S_ISLNK
1183# ifdef _S_ISLNK
1184# define S_ISLNK(m) _S_ISLNK(m)
1185# else
1186# ifdef _S_IFLNK
1187# define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
1188# else
1189# ifdef S_IFLNK
1190# define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
1191# else
1192# define S_ISLNK(m) (0)
1193# endif
1194# endif
1195# endif
1196#endif
1197
1198#ifndef S_ISSOCK
1199# ifdef _S_ISSOCK
1200# define S_ISSOCK(m) _S_ISSOCK(m)
1201# else
1202# ifdef _S_IFSOCK
1203# define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
1204# else
1205# ifdef S_IFSOCK
1206# define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
1207# else
1208# define S_ISSOCK(m) (0)
1209# endif
1210# endif
1211# endif
1212#endif
1213
1214#ifndef S_IRUSR
1215# ifdef S_IREAD
1216# define S_IRUSR S_IREAD
1217# define S_IWUSR S_IWRITE
1218# define S_IXUSR S_IEXEC
1219# else
1220# define S_IRUSR 0400
1221# define S_IWUSR 0200
1222# define S_IXUSR 0100
1223# endif
fac7cdfc
JS
1224#endif
1225
1226#ifndef S_IRGRP
1227# ifdef S_IRUSR
1228# define S_IRGRP (S_IRUSR>>3)
1229# define S_IWGRP (S_IWUSR>>3)
1230# define S_IXGRP (S_IXUSR>>3)
1231# else
1232# define S_IRGRP 0040
1233# define S_IWGRP 0020
1234# define S_IXGRP 0010
1235# endif
1236#endif
1237
1238#ifndef S_IROTH
1239# ifdef S_IRUSR
1240# define S_IROTH (S_IRUSR>>6)
1241# define S_IWOTH (S_IWUSR>>6)
1242# define S_IXOTH (S_IXUSR>>6)
1243# else
1244# define S_IROTH 0040
1245# define S_IWOTH 0020
1246# define S_IXOTH 0010
1247# endif
c623bd54
LW
1248#endif
1249
1250#ifndef S_ISUID
1251# define S_ISUID 04000
1252#endif
1253
1254#ifndef S_ISGID
1255# define S_ISGID 02000
1256#endif
1257
ca6e1c26
JH
1258#ifndef S_IRWXU
1259# define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR)
d460ef45 1260#endif
ca6e1c26
JH
1261
1262#ifndef S_IRWXG
1263# define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP)
d460ef45 1264#endif
ca6e1c26
JH
1265
1266#ifndef S_IRWXO
1267# define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH)
d460ef45 1268#endif
ca6e1c26 1269
c21fb2b8
JH
1270/* BeOS 5.0 seems to define S_IREAD and S_IWRITE in <posix/fcntl.h>
1271 * which would get included through <sys/file.h >, but that is 3000
1272 * lines in the future. --jhi */
1273
1274#if !defined(S_IREAD) && !defined(__BEOS__)
ca6e1c26
JH
1275# define S_IREAD S_IRUSR
1276#endif
1277
c21fb2b8 1278#if !defined(S_IWRITE) && !defined(__BEOS__)
ca6e1c26
JH
1279# define S_IWRITE S_IWUSR
1280#endif
1281
1282#ifndef S_IEXEC
1283# define S_IEXEC S_IXUSR
1284#endif
1285
79072805
LW
1286#ifdef ff_next
1287# undef ff_next
352d5a3a
LW
1288#endif
1289
a0d0e21e 1290#if defined(cray) || defined(gould) || defined(i860) || defined(pyr)
45d8adaa
LW
1291# define SLOPPYDIVIDE
1292#endif
1293
748a9306
LW
1294#ifdef UV
1295#undef UV
1296#endif
1297
c89df6bf
JH
1298#ifdef SPRINTF_E_BUG
1299# define sprintf UTS_sprintf_wrap
1300#endif
1301
c495e728
JH
1302/* Configure gets this right but the UTS compiler gets it wrong.
1303 -- Hal Morris <hom00@utsglobal.com> */
1304#ifdef UTS
1305# undef UVTYPE
1306# define UVTYPE unsigned
1307#endif
1308
05f13f53 1309/*
27d4fb96 1310 The IV type is supposed to be long enough to hold any integral
1311 value or a pointer.
1312 --Andy Dougherty August 1996
1313*/
1314
a22e52b9
JH
1315typedef IVTYPE IV;
1316typedef UVTYPE UV;
8175356b 1317
10cc9d2a 1318#if defined(USE_64_BIT_INT) && defined(HAS_QUAD)
6b8eaf93 1319# if QUADKIND == QUAD_IS_INT64_T && defined(INT64_MAX)
5ff3f7a4
GS
1320# define IV_MAX INT64_MAX
1321# define IV_MIN INT64_MIN
1322# define UV_MAX UINT64_MAX
cae7ae48
JH
1323# ifndef UINT64_MIN
1324# define UINT64_MIN 0
1325# endif
5ff3f7a4
GS
1326# define UV_MIN UINT64_MIN
1327# else
1328# define IV_MAX PERL_QUAD_MAX
1329# define IV_MIN PERL_QUAD_MIN
1330# define UV_MAX PERL_UQUAD_MAX
1331# define UV_MIN PERL_UQUAD_MIN
1332# endif
cf2093f6
JH
1333# define IV_IS_QUAD
1334# define UV_IS_QUAD
79072805 1335#else
8175356b 1336# if defined(INT32_MAX) && IVSIZE == 4
5ff3f7a4
GS
1337# define IV_MAX INT32_MAX
1338# define IV_MIN INT32_MIN
716026f9
DL
1339# ifndef UINT32_MAX_BROKEN /* e.g. HP-UX with gcc messes this up */
1340# define UV_MAX UINT32_MAX
1341# else
1342# define UV_MAX 4294967295U
1343# endif
cae7ae48
JH
1344# ifndef UINT32_MIN
1345# define UINT32_MIN 0
1346# endif
5ff3f7a4
GS
1347# define UV_MIN UINT32_MIN
1348# else
1349# define IV_MAX PERL_LONG_MAX
1350# define IV_MIN PERL_LONG_MIN
1351# define UV_MAX PERL_ULONG_MAX
1352# define UV_MIN PERL_ULONG_MIN
1353# endif
8175356b 1354# if IVSIZE == 8
cf2093f6
JH
1355# define IV_IS_QUAD
1356# define UV_IS_QUAD
de1c2614
JH
1357# ifndef HAS_QUAD
1358# define HAS_QUAD
1359# endif
cf2093f6
JH
1360# else
1361# undef IV_IS_QUAD
1362# undef UV_IS_QUAD
de1c2614 1363# undef HAS_QUAD
cf2093f6 1364# endif
79072805 1365#endif
d7d93a81 1366
cc3ea0aa
NC
1367#ifndef HAS_QUAD
1368# undef PERL_NEED_MY_HTOLE64
1369# undef PERL_NEED_MY_LETOH64
1370# undef PERL_NEED_MY_HTOBE64
1371# undef PERL_NEED_MY_BETOH64
1372#endif
1373
6cde8aec 1374#if defined(uts) || defined(UTS)
11afe549
HM
1375# undef UV_MAX
1376# define UV_MAX (4294967295u)
20601011
JH
1377#endif
1378
cae7ae48 1379#define IV_DIG (BIT_DIGITS(IVSIZE * 8))
22ec83e3 1380#define UV_DIG (BIT_DIGITS(UVSIZE * 8))
56431972 1381
28e5dec8 1382#ifndef NO_PERL_PRESERVE_IVUV
f5c03d33 1383#define PERL_PRESERVE_IVUV /* We like our integers to stay integers. */
28e5dec8
JH
1384#endif
1385
d460ef45 1386/*
26bb67e2
JH
1387 * The macros INT2PTR and NUM2PTR are (despite their names)
1388 * bi-directional: they will convert int/float to or from pointers.
1389 * However the conversion to int/float are named explicitly:
1390 * PTR2IV, PTR2UV, PTR2NV.
1391 *
1392 * For int conversions we do not need two casts if pointers are
1393 * the same size as IV and UV. Otherwise we need an explicit
1394 * cast (PTRV) to avoid compiler warnings.
1395 */
56431972
RB
1396#if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE)
1397# define PTRV UV
1398# define INT2PTR(any,d) (any)(d)
1399#else
d460ef45 1400# if PTRSIZE == LONGSIZE
56431972 1401# define PTRV unsigned long
42718184 1402# else
56431972 1403# define PTRV unsigned
42718184 1404# endif
56431972 1405# define INT2PTR(any,d) (any)(PTRV)(d)
42718184 1406#endif
56431972
RB
1407#define NUM2PTR(any,d) (any)(PTRV)(d)
1408#define PTR2IV(p) INT2PTR(IV,p)
1409#define PTR2UV(p) INT2PTR(UV,p)
1410#define PTR2NV(p) NUM2PTR(NV,p)
d460ef45 1411#if PTRSIZE == LONGSIZE
d2560b70
RB
1412# define PTR2ul(p) (unsigned long)(p)
1413#else
1414# define PTR2ul(p) INT2PTR(unsigned long,p)
1415#endif
d460ef45 1416
65202027 1417#ifdef USE_LONG_DOUBLE
1048ea30
JH
1418# if defined(HAS_LONG_DOUBLE) && LONG_DOUBLESIZE == DOUBLESIZE
1419# define LONG_DOUBLE_EQUALS_DOUBLE
1420# endif
68d4903c 1421# if !(defined(HAS_LONG_DOUBLE) && (LONG_DOUBLESIZE > DOUBLESIZE))
2d4389e4 1422# undef USE_LONG_DOUBLE /* Ouch! */
65202027
DS
1423# endif
1424#endif
1425
2d4389e4
JH
1426#ifdef OVR_DBL_DIG
1427/* Use an overridden DBL_DIG */
1428# ifdef DBL_DIG
1429# undef DBL_DIG
1430# endif
1431# define DBL_DIG OVR_DBL_DIG
1432#else
1433/* The following is all to get DBL_DIG, in order to pick a nice
5b7ea690
JH
1434 default value for printing floating point numbers in Gconvert
1435 (see config.h). (It also has other uses, such as figuring out if
1436 a given precision of printing can be done with a double instead of
1437 a long double - Allen).
2d4389e4
JH
1438*/
1439#ifdef I_LIMITS
1440#include <limits.h>
1441#endif
1442#ifdef I_FLOAT
1443#include <float.h>
1444#endif
1445#ifndef HAS_DBL_DIG
1446#define DBL_DIG 15 /* A guess that works lots of places */
1447#endif
1448#endif
cbca01e1
JH
1449#ifdef I_FLOAT
1450#include <float.h>
1451#endif
1452#ifndef HAS_DBL_DIG
1453#define DBL_DIG 15 /* A guess that works lots of places */
1454#endif
2d4389e4
JH
1455
1456#ifdef OVR_LDBL_DIG
1457/* Use an overridden LDBL_DIG */
1458# ifdef LDBL_DIG
1459# undef LDBL_DIG
1460# endif
1461# define LDBL_DIG OVR_LDBL_DIG
1462#else
1463/* The following is all to get LDBL_DIG, in order to pick a nice
1464 default value for printing floating point numbers in Gconvert.
1465 (see config.h)
1466*/
68d4903c
JH
1467# ifdef I_LIMITS
1468# include <limits.h>
1469# endif
1470# ifdef I_FLOAT
1471# include <float.h>
1472# endif
1473# ifndef HAS_LDBL_DIG
1474# if LONG_DOUBLESIZE == 10
1475# define LDBL_DIG 18 /* assume IEEE */
1476# else
1477# if LONG_DOUBLESIZE == 12
1478# define LDBL_DIG 18 /* gcc? */
1479# else
1480# if LONG_DOUBLESIZE == 16
1481# define LDBL_DIG 33 /* assume IEEE */
1482# else
1483# if LONG_DOUBLESIZE == DOUBLESIZE
1484# define LDBL_DIG DBL_DIG /* bummer */
1485# endif
1486# endif
1487# endif
1488# endif
1489# endif
2d4389e4
JH
1490#endif
1491
5b7ea690
JH
1492/*
1493 * This is for making sure we have a good DBL_MAX value, if possible,
1494 * either for usage as NV_MAX or for usage in figuring out if we can
1495 * fit a given long double into a double, if bug-fixing makes it
1496 * necessary to do so. - Allen <allens@cpan.org>
1497 */
1498
1499#ifdef I_LIMITS
1500# include <limits.h>
1501#endif
1502
1503#ifdef I_VALUES
1504# if !(defined(DBL_MIN) && defined(DBL_MAX) && defined(I_LIMITS))
1505# include <values.h>
1506# if defined(MAXDOUBLE) && !defined(DBL_MAX)
1507# define DBL_MAX MAXDOUBLE
1508# endif
1509# if defined(MINDOUBLE) && !defined(DBL_MIN)
1510# define DBL_MIN MINDOUBLE
1511# endif
1512# endif
1513#endif /* defined(I_VALUES) */
1514
a22e52b9 1515typedef NVTYPE NV;
8175356b 1516
792d8dab
JH
1517#ifdef I_IEEEFP
1518# include <ieeefp.h>
1519#endif
923fc586 1520
65202027 1521#ifdef USE_LONG_DOUBLE
923fc586
JH
1522# ifdef I_SUNMATH
1523# include <sunmath.h>
1524# endif
2d4389e4 1525# define NV_DIG LDBL_DIG
d6c14000
JH
1526# ifdef LDBL_MANT_DIG
1527# define NV_MANT_DIG LDBL_MANT_DIG
1528# endif
06fc1729
JH
1529# ifdef LDBL_MIN
1530# define NV_MIN LDBL_MIN
1531# endif
1532# ifdef LDBL_MAX
1533# define NV_MAX LDBL_MAX
1534# endif
1535# ifdef LDBL_MIN_10_EXP
1536# define NV_MIN_10_EXP LDBL_MIN_10_EXP
1537# endif
1538# ifdef LDBL_MAX_10_EXP
1539# define NV_MAX_10_EXP LDBL_MAX_10_EXP
1540# endif
1541# ifdef LDBL_EPSILON
1542# define NV_EPSILON LDBL_EPSILON
1543# endif
f4a14a62
JH
1544# ifdef LDBL_MAX
1545# define NV_MAX LDBL_MAX
5b7ea690 1546/* Having LDBL_MAX doesn't necessarily mean that we have LDBL_MIN... -Allen */
f4a14a62
JH
1547# else
1548# ifdef HUGE_VALL
1549# define NV_MAX HUGE_VALL
1550# else
1551# ifdef HUGE_VAL
1552# define NV_MAX ((NV)HUGE_VAL)
1553# endif
1554# endif
1555# endif
68d4903c 1556# ifdef HAS_SQRTL
68d4903c
JH
1557# define Perl_cos cosl
1558# define Perl_sin sinl
1559# define Perl_sqrt sqrtl
1560# define Perl_exp expl
1561# define Perl_log logl
1562# define Perl_atan2 atan2l
1563# define Perl_pow powl
1564# define Perl_floor floorl
b6a2e6ed 1565# define Perl_ceil ceill
68d4903c
JH
1566# define Perl_fmod fmodl
1567# endif
a3540c92
JH
1568/* e.g. libsunmath doesn't have modfl and frexpl as of mid-March 2000 */
1569# ifdef HAS_MODFL
1570# define Perl_modf(x,y) modfl(x,y)
5a29c6bc
JH
1571/* eg glibc 2.2 series seems to provide modfl on ppc and arm, but has no
1572 prototype in <math.h> */
1573# ifndef HAS_MODFL_PROTO
922661e1 1574EXTERN_C long double modfl(long double, long double *);
5a29c6bc 1575# endif
e82e08d5 1576# else
5a29c6bc
JH
1577# if defined(HAS_AINTL) && defined(HAS_COPYSIGNL)
1578 extern long double Perl_my_modfl(long double x, long double *ip);
1579# define Perl_modf(x,y) Perl_my_modfl(x,y)
1580# endif
a3540c92
JH
1581# endif
1582# ifdef HAS_FREXPL
dff3e0b8 1583# define Perl_frexp(x,y) frexpl(x,y)
e82e08d5 1584# else
5a29c6bc
JH
1585# if defined(HAS_ILOGBL) && defined(HAS_SCALBNL)
1586 extern long double Perl_my_frexpl(long double x, int *e);
1587# define Perl_frexp(x,y) Perl_my_frexpl(x,y)
1588# endif
a3540c92 1589# endif
38dbb4c5 1590# ifndef Perl_isnan
758a5d79
JH
1591# ifdef HAS_ISNANL
1592# define Perl_isnan(x) isnanl(x)
1593# endif
1594# endif
1595# ifndef Perl_isinf
1596# ifdef HAS_FINITEL
1597# define Perl_isinf(x) !(finitel(x)||Perl_isnan(x))
a3540c92
JH
1598# endif
1599# endif
65202027 1600#else
2d4389e4 1601# define NV_DIG DBL_DIG
d6c14000
JH
1602# ifdef DBL_MANT_DIG
1603# define NV_MANT_DIG DBL_MANT_DIG
1604# endif
06fc1729
JH
1605# ifdef DBL_MIN
1606# define NV_MIN DBL_MIN
1607# endif
1608# ifdef DBL_MAX
1609# define NV_MAX DBL_MAX
1610# endif
1611# ifdef DBL_MIN_10_EXP
1612# define NV_MIN_10_EXP DBL_MIN_10_EXP
1613# endif
1614# ifdef DBL_MAX_10_EXP
1615# define NV_MAX_10_EXP DBL_MAX_10_EXP
1616# endif
1617# ifdef DBL_EPSILON
1618# define NV_EPSILON DBL_EPSILON
1619# endif
5b7ea690 1620# ifdef DBL_MAX /* XXX Does DBL_MAX imply having DBL_MIN? */
f4a14a62
JH
1621# define NV_MAX DBL_MAX
1622# define NV_MIN DBL_MIN
1623# else
1624# ifdef HUGE_VAL
1625# define NV_MAX HUGE_VAL
1626# endif
1627# endif
65202027
DS
1628# define Perl_cos cos
1629# define Perl_sin sin
1630# define Perl_sqrt sqrt
1631# define Perl_exp exp
1632# define Perl_log log
1633# define Perl_atan2 atan2
1634# define Perl_pow pow
1635# define Perl_floor floor
b6a2e6ed 1636# define Perl_ceil ceil
65202027 1637# define Perl_fmod fmod
a3540c92 1638# define Perl_modf(x,y) modf(x,y)
dff3e0b8 1639# define Perl_frexp(x,y) frexp(x,y)
758a5d79
JH
1640#endif
1641
1642/* rumor has it that Win32 has _fpclass() */
1643
5b7ea690
JH
1644/* SGI has fpclassl... but not with the same result values,
1645 * and it's via a typedef (not via #define), so will need to redo Configure
1646 * to use. Not worth the trouble, IMO, at least until the below is used
1647 * more places. Also has fp_class_l, BTW, via fp_class.h. Feel free to check
1648 * with me for the SGI manpages, SGI testing, etcetera, if you want to
1649 * try getting this to work with IRIX. - Allen <allens@cpan.org> */
1650
758a5d79
JH
1651#if !defined(Perl_fp_class) && (defined(HAS_FPCLASS)||defined(HAS_FPCLASSL))
1652# ifdef I_IEEFP
1653# include <ieeefp.h>
1654# endif
1655# ifdef I_FP
1656# include <fp.h>
1657# endif
1658# if defined(USE_LONG_DOUBLE) && defined(HAS_FPCLASSL)
1659# define Perl_fp_class() fpclassl(x)
1660# else
1661# define Perl_fp_class() fpclass(x)
1662# endif
1663# define Perl_fp_class_snan(x) (Perl_fp_class(x)==FP_CLASS_SNAN)
1664# define Perl_fp_class_qnan(x) (Perl_fp_class(x)==FP_CLASS_QNAN)
1665# define Perl_fp_class_nan(x) (Perl_fp_class(x)==FP_CLASS_SNAN||Perl_fp_class(x)==FP_CLASS_QNAN)
1666# define Perl_fp_class_ninf(x) (Perl_fp_class(x)==FP_CLASS_NINF)
1667# define Perl_fp_class_pinf(x) (Perl_fp_class(x)==FP_CLASS_PINF)
1668# define Perl_fp_class_inf(x) (Perl_fp_class(x)==FP_CLASS_NINF||Perl_fp_class(x)==FP_CLASS_PINF)
1669# define Perl_fp_class_nnorm(x) (Perl_fp_class(x)==FP_CLASS_NNORM)
1670# define Perl_fp_class_pnorm(x) (Perl_fp_class(x)==FP_CLASS_PNORM)
1671# define Perl_fp_class_norm(x) (Perl_fp_class(x)==FP_CLASS_NNORM||Perl_fp_class(x)==FP_CLASS_PNORM)
1672# define Perl_fp_class_ndenorm(x) (Perl_fp_class(x)==FP_CLASS_NDENORM)
1673# define Perl_fp_class_pdenorm(x) (Perl_fp_class(x)==FP_CLASS_PDENORM)
1674# define Perl_fp_class_denorm(x) (Perl_fp_class(x)==FP_CLASS_NDENORM||Perl_fp_class(x)==FP_CLASS_PDENORM)
1675# define Perl_fp_class_nzero(x) (Perl_fp_class(x)==FP_CLASS_NZERO)
1676# define Perl_fp_class_pzero(x) (Perl_fp_class(x)==FP_CLASS_PZERO)
1677# define Perl_fp_class_zero(x) (Perl_fp_class(x)==FP_CLASS_NZERO||Perl_fp_class(x)==FP_CLASS_PZERO)
1678#endif
1679
7114a2d2 1680#if !defined(Perl_fp_class) && defined(HAS_FP_CLASS) && !defined(PERL_MICRO)
758a5d79
JH
1681# include <math.h>
1682# if !defined(FP_SNAN) && defined(I_FP_CLASS)
1683# include <fp_class.h>
1684# endif
1685# define Perl_fp_class(x) fp_class(x)
1686# define Perl_fp_class_snan(x) (fp_class(x)==FP_SNAN)
1687# define Perl_fp_class_qnan(x) (fp_class(x)==FP_QNAN)
1688# define Perl_fp_class_nan(x) (fp_class(x)==FP_SNAN||fp_class(x)==FP_QNAN)
1689# define Perl_fp_class_ninf(x) (fp_class(x)==FP_NEG_INF)
1690# define Perl_fp_class_pinf(x) (fp_class(x)==FP_POS_INF)
1691# define Perl_fp_class_inf(x) (fp_class(x)==FP_NEG_INF||fp_class(x)==FP_POS_INF)
1692# define Perl_fp_class_nnorm(x) (fp_class(x)==FP_NEG_NORM)
1693# define Perl_fp_class_pnorm(x) (fp_class(x)==FP_POS_NORM)
1694# define Perl_fp_class_norm(x) (fp_class(x)==FP_NEG_NORM||fp_class(x)==FP_POS_NORM)
1695# define Perl_fp_class_ndenorm(x) (fp_class(x)==FP_NEG_DENORM)
1696# define Perl_fp_class_pdenorm(x) (fp_class(x)==FP_POS_DENORM)
1697# define Perl_fp_class_denorm(x) (fp_class(x)==FP_NEG_DENORM||fp_class(x)==FP_POS_DENORM)
1698# define Perl_fp_class_nzero(x) (fp_class(x)==FP_NEG_ZERO)
1699# define Perl_fp_class_pzero(x) (fp_class(x)==FP_POS_ZERO)
1700# define Perl_fp_class_zero(x) (fp_class(x)==FP_NEG_ZERO||fp_class(x)==FP_POS_ZERO)
1701#endif
1702
1703#if !defined(Perl_fp_class) && defined(HAS_FPCLASSIFY)
1704# include <math.h>
1705# define Perl_fp_class(x) fpclassify(x)
38dbb4c5 1706# define Perl_fp_class_nan(x) (fp_classify(x)==FP_SNAN||fp_classify(x)==FP_QNAN)
758a5d79
JH
1707# define Perl_fp_class_inf(x) (fp_classify(x)==FP_INFINITE)
1708# define Perl_fp_class_norm(x) (fp_classify(x)==FP_NORMAL)
1709# define Perl_fp_class_denorm(x) (fp_classify(x)==FP_SUBNORMAL)
1710# define Perl_fp_class_zero(x) (fp_classify(x)==FP_ZERO)
1711#endif
1712
1713#if !defined(Perl_fp_class) && defined(HAS_CLASS)
1714# include <math.h>
1715# ifndef _cplusplus
1716# define Perl_fp_class(x) class(x)
1717# else
1718# define Perl_fp_class(x) _class(x)
1719# endif
1720# define Perl_fp_class_snan(x) (Perl_fp_class(x)==FP_NANS)
1721# define Perl_fp_class_qnan(x) (Perl_fp_class(x)==FP_NANQ)
1722# define Perl_fp_class_nan(x) (Perl_fp_class(x)==FP_SNAN||Perl_fp_class(x)==FP_QNAN)
1723# define Perl_fp_class_ninf(x) (Perl_fp_class(x)==FP_MINUS_INF)
1724# define Perl_fp_class_pinf(x) (Perl_fp_class(x)==FP_PLUS_INF)
1725# define Perl_fp_class_inf(x) (Perl_fp_class(x)==FP_MINUS_INF||Perl_fp_class(x)==FP_PLUS_INF)
1726# define Perl_fp_class_nnorm(x) (Perl_fp_class(x)==FP_MINUS_NORM)
1727# define Perl_fp_class_pnorm(x) (Perl_fp_class(x)==FP_PLUS_NORM)
1728# define Perl_fp_class_norm(x) (Perl_fp_class(x)==FP_MINUS_NORM||Perl_fp_class(x)==FP_PLUS_NORM)
1729# define Perl_fp_class_ndenorm(x) (Perl_fp_class(x)==FP_MINUS_DENORM)
1730# define Perl_fp_class_pdenorm(x) (Perl_fp_class(x)==FP_PLUS_DENORM)
1731# define Perl_fp_class_denorm(x) (Perl_fp_class(x)==FP_MINUS_DENORM||Perl_fp_class(x)==FP_PLUS_DENORM)
1732# define Perl_fp_class_nzero(x) (Perl_fp_class(x)==FP_MINUS_ZERO)
1733# define Perl_fp_class_pzero(x) (Perl_fp_class(x)==FP_PLUS_ZERO)
1734# define Perl_fp_class_zero(x) (Perl_fp_class(x)==FP_MINUS_ZERO||Perl_fp_class(x)==FP_PLUS_ZERO)
1735#endif
1736
1737/* rumor has it that Win32 has _isnan() */
1738
1739#ifndef Perl_isnan
a3540c92 1740# ifdef HAS_ISNAN
758a5d79
JH
1741# define Perl_isnan(x) isnan((NV)x)
1742# else
1743# ifdef Perl_fp_class_nan
1744# define Perl_isnan(x) Perl_fp_class_nan(x)
1745# else
1746# ifdef HAS_UNORDERED
1747# define Perl_isnan(x) unordered((x), 0.0)
1748# else
1749# define Perl_isnan(x) ((x)!=(x))
1750# endif
1751# endif
1752# endif
1753#endif
1754
ca6c63e1
JH
1755#ifdef UNDER_CE
1756int isnan(double d);
1757#endif
1758
758a5d79
JH
1759#ifndef Perl_isinf
1760# ifdef HAS_ISINF
1761# define Perl_isinf(x) isinf((NV)x)
a3540c92 1762# else
758a5d79
JH
1763# ifdef Perl_fp_class_inf
1764# define Perl_isinf(x) Perl_fp_class_inf(x)
1765# else
1766# define Perl_isinf(x) ((x)==NV_INF)
1767# endif
1768# endif
1769#endif
1770
1771#ifndef Perl_isfinite
1772# ifdef HAS_FINITE
1773# define Perl_isfinite(x) finite((NV)x)
1774# else
1775# ifdef HAS_ISFINITE
1776# define Perl_isfinite(x) isfinite(x)
1777# else
1778# ifdef Perl_fp_class_finite
1779# define Perl_isfinite(x) Perl_fp_class_finite(x)
1780# else
1781# define Perl_isfinite(x) !(Perl_is_inf(x)||Perl_is_nan(x))
1782# endif
1783# endif
a3540c92 1784# endif
65202027
DS
1785#endif
1786
a36244b7
JH
1787/* The default is to use Perl's own atof() implementation (in numeric.c).
1788 * Usually that is the one to use but for some platforms (e.g. UNICOS)
1789 * it is however best to use the native implementation of atof.
1790 * You can experiment with using your native one by -DUSE_PERL_ATOF=0.
1791 * Some good tests to try out with either setting are t/base/num.t,
5b7ea690
JH
1792 * t/op/numconvert.t, and t/op/pack.t. Note that if using long doubles
1793 * you may need to be using a different function than atof! */
a36244b7
JH
1794
1795#ifndef USE_PERL_ATOF
1796# ifndef _UNICOS
1797# define USE_PERL_ATOF
1798# endif
1799#else
1800# if USE_PERL_ATOF == 0
1801# undef USE_PERL_ATOF
1802# endif
1803#endif
1804
1805#ifdef USE_PERL_ATOF
1806# define Perl_atof(s) Perl_my_atof(s)
1807# define Perl_atof2(s, n) Perl_my_atof2(aTHX_ (s), &(n))
1808#else
1809# define Perl_atof(s) (NV)atof(s)
1810# define Perl_atof2(s, n) ((n) = atof(s))
1811#endif
cf2093f6 1812
d460ef45 1813/* Previously these definitions used hardcoded figures.
760ac839
LW
1814 * It is hoped these formula are more portable, although
1815 * no data one way or another is presently known to me.
1816 * The "PERL_" names are used because these calculated constants
1817 * do not meet the ANSI requirements for LONG_MAX, etc., which
1818 * need to be constants acceptable to #if - kja
1819 * define PERL_LONG_MAX 2147483647L
1820 * define PERL_LONG_MIN (-LONG_MAX - 1)
1821 * define PERL ULONG_MAX 4294967295L
1822 */
1823
1824#ifdef I_LIMITS /* Needed for cast_xxx() functions below. */
1825# include <limits.h>
760ac839 1826#endif
5b7ea690
JH
1827/* Included values.h above if necessary; still including limits.h down here,
1828 * despite doing above, because math.h might have overriden... XXX - Allen */
760ac839 1829
99abf803 1830/*
1831 * Try to figure out max and min values for the integral types. THE CORRECT
1832 * SOLUTION TO THIS MESS: ADAPT enquire.c FROM GCC INTO CONFIGURE. The
1833 * following hacks are used if neither limits.h or values.h provide them:
1834 * U<TYPE>_MAX: for types >= int: ~(unsigned TYPE)0
1835 * for types < int: (unsigned TYPE)~(unsigned)0
1836 * The argument to ~ must be unsigned so that later signed->unsigned
1837 * conversion can't modify the value's bit pattern (e.g. -0 -> +0),
1838 * and it must not be smaller than int because ~ does integral promotion.
1839 * <type>_MAX: (<type>) (U<type>_MAX >> 1)
1840 * <type>_MIN: -<type>_MAX - <is_twos_complement_architecture: (3 & -1) == 3>.
1841 * The latter is a hack which happens to work on some machines but
1842 * does *not* catch any random system, or things like integer types
1843 * with NaN if that is possible.
1844 *
1845 * All of the types are explicitly cast to prevent accidental loss of
1846 * numeric range, and in the hope that they will be less likely to confuse
1847 * over-eager optimizers.
1848 *
1849 */
27d4fb96 1850
99abf803 1851#define PERL_UCHAR_MIN ((unsigned char)0)
1852
1853#ifdef UCHAR_MAX
1854# define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX)
27d4fb96 1855#else
99abf803 1856# ifdef MAXUCHAR
1857# define PERL_UCHAR_MAX ((unsigned char)MAXUCHAR)
27d4fb96 1858# else
99abf803 1859# define PERL_UCHAR_MAX ((unsigned char)~(unsigned)0)
27d4fb96 1860# endif
1861#endif
d460ef45 1862
99abf803 1863/*
1864 * CHAR_MIN and CHAR_MAX are not included here, as the (char) type may be
1865 * ambiguous. It may be equivalent to (signed char) or (unsigned char)
1866 * depending on local options. Until Configure detects this (or at least
1867 * detects whether the "signed" keyword is available) the CHAR ranges
1868 * will not be included. UCHAR functions normally.
1869 * - kja
1870 */
27d4fb96 1871
99abf803 1872#define PERL_USHORT_MIN ((unsigned short)0)
1873
1874#ifdef USHORT_MAX
1875# define PERL_USHORT_MAX ((unsigned short)USHORT_MAX)
27d4fb96 1876#else
99abf803 1877# ifdef MAXUSHORT
1878# define PERL_USHORT_MAX ((unsigned short)MAXUSHORT)
27d4fb96 1879# else
ef2f54b0
CB
1880# ifdef USHRT_MAX
1881# define PERL_USHORT_MAX ((unsigned short)USHRT_MAX)
1882# else
1883# define PERL_USHORT_MAX ((unsigned short)~(unsigned)0)
1884# endif
27d4fb96 1885# endif
1886#endif
1887
27d4fb96 1888#ifdef SHORT_MAX
99abf803 1889# define PERL_SHORT_MAX ((short)SHORT_MAX)
27d4fb96 1890#else
1891# ifdef MAXSHORT /* Often used in <values.h> */
99abf803 1892# define PERL_SHORT_MAX ((short)MAXSHORT)
27d4fb96 1893# else
ef2f54b0
CB
1894# ifdef SHRT_MAX
1895# define PERL_SHORT_MAX ((short)SHRT_MAX)
1896# else
1897# define PERL_SHORT_MAX ((short) (PERL_USHORT_MAX >> 1))
1898# endif
27d4fb96 1899# endif
1900#endif
1901
1902#ifdef SHORT_MIN
99abf803 1903# define PERL_SHORT_MIN ((short)SHORT_MIN)
27d4fb96 1904#else
1905# ifdef MINSHORT
99abf803 1906# define PERL_SHORT_MIN ((short)MINSHORT)
27d4fb96 1907# else
ef2f54b0
CB
1908# ifdef SHRT_MIN
1909# define PERL_SHORT_MIN ((short)SHRT_MIN)
1910# else
1911# define PERL_SHORT_MIN (-PERL_SHORT_MAX - ((3 & -1) == 3))
1912# endif
27d4fb96 1913# endif
1914#endif
1915
99abf803 1916#ifdef UINT_MAX
1917# define PERL_UINT_MAX ((unsigned int)UINT_MAX)
27d4fb96 1918#else
99abf803 1919# ifdef MAXUINT
1920# define PERL_UINT_MAX ((unsigned int)MAXUINT)
27d4fb96 1921# else
99abf803 1922# define PERL_UINT_MAX (~(unsigned int)0)
27d4fb96 1923# endif
1924#endif
1925
99abf803 1926#define PERL_UINT_MIN ((unsigned int)0)
27d4fb96 1927
1928#ifdef INT_MAX
99abf803 1929# define PERL_INT_MAX ((int)INT_MAX)
27d4fb96 1930#else
1931# ifdef MAXINT /* Often used in <values.h> */
99abf803 1932# define PERL_INT_MAX ((int)MAXINT)
27d4fb96 1933# else
99abf803 1934# define PERL_INT_MAX ((int)(PERL_UINT_MAX >> 1))
27d4fb96 1935# endif
1936#endif
1937
1938#ifdef INT_MIN
99abf803 1939# define PERL_INT_MIN ((int)INT_MIN)
27d4fb96 1940#else
1941# ifdef MININT
99abf803 1942# define PERL_INT_MIN ((int)MININT)
27d4fb96 1943# else
1944# define PERL_INT_MIN (-PERL_INT_MAX - ((3 & -1) == 3))
1945# endif
1946#endif
1947
99abf803 1948#ifdef ULONG_MAX
1949# define PERL_ULONG_MAX ((unsigned long)ULONG_MAX)
27d4fb96 1950#else
99abf803 1951# ifdef MAXULONG
1952# define PERL_ULONG_MAX ((unsigned long)MAXULONG)
27d4fb96 1953# else
99abf803 1954# define PERL_ULONG_MAX (~(unsigned long)0)
27d4fb96 1955# endif
1956#endif
1957
99abf803 1958#define PERL_ULONG_MIN ((unsigned long)0L)
27d4fb96 1959
760ac839 1960#ifdef LONG_MAX
99abf803 1961# define PERL_LONG_MAX ((long)LONG_MAX)
760ac839
LW
1962#else
1963# ifdef MAXLONG /* Often used in <values.h> */
99abf803 1964# define PERL_LONG_MAX ((long)MAXLONG)
760ac839 1965# else
99abf803 1966# define PERL_LONG_MAX ((long) (PERL_ULONG_MAX >> 1))
760ac839
LW
1967# endif
1968#endif
1969
1970#ifdef LONG_MIN
99abf803 1971# define PERL_LONG_MIN ((long)LONG_MIN)
760ac839
LW
1972#else
1973# ifdef MINLONG
99abf803 1974# define PERL_LONG_MIN ((long)MINLONG)
760ac839 1975# else
27d4fb96 1976# define PERL_LONG_MIN (-PERL_LONG_MAX - ((3 & -1) == 3))
760ac839
LW
1977# endif
1978#endif
1979
d7d93a81 1980#ifdef UV_IS_QUAD
99abf803 1981
99abf803 1982# define PERL_UQUAD_MAX (~(UV)0)
f1c3b19a 1983# define PERL_UQUAD_MIN ((UV)0)
99abf803 1984# define PERL_QUAD_MAX ((IV) (PERL_UQUAD_MAX >> 1))
a6e633de 1985# define PERL_QUAD_MIN (-PERL_QUAD_MAX - ((3 & -1) == 3))
27d4fb96 1986
79072805
LW
1987#endif
1988
26776375
JH
1989#ifdef MYMALLOC
1990# include "malloc_ctl.h"
1991#endif
1992
830247a4 1993struct RExC_state_t;
880b20b6 1994
ee0007ab 1995typedef MEM_SIZE STRLEN;
450a55e4 1996
79072805
LW
1997typedef struct op OP;
1998typedef struct cop COP;
1999typedef struct unop UNOP;
2000typedef struct binop BINOP;
2001typedef struct listop LISTOP;
2002typedef struct logop LOGOP;
79072805
LW
2003typedef struct pmop PMOP;
2004typedef struct svop SVOP;
7934575e 2005typedef struct padop PADOP;
79072805 2006typedef struct pvop PVOP;
79072805
LW
2007typedef struct loop LOOP;
2008
93a17b20 2009typedef struct interpreter PerlInterpreter;
d2b3f365
SS
2010
2011/* Amdahl's <ksync.h> has struct sv */
2012/* SGI's <sys/sema.h> has struct sv */
2013#if defined(UTS) || defined(__sgi)
2014# define STRUCT_SV perl_sv
b8d3c5db
JH
2015#else
2016# define STRUCT_SV sv
2017#endif
2018typedef struct STRUCT_SV SV;
79072805
LW
2019typedef struct av AV;
2020typedef struct hv HV;
2021typedef struct cv CV;
378cc40b 2022typedef struct regexp REGEXP;
79072805 2023typedef struct gp GP;
0c30d9ec 2024typedef struct gv GV;
8990e307 2025typedef struct io IO;
c09156bb 2026typedef struct context PERL_CONTEXT;
79072805
LW
2027typedef struct block BLOCK;
2028
2029typedef struct magic MAGIC;
ed6116ce 2030typedef struct xrv XRV;
79072805
LW
2031typedef struct xpv XPV;
2032typedef struct xpviv XPVIV;
ff68c719 2033typedef struct xpvuv XPVUV;
79072805
LW
2034typedef struct xpvnv XPVNV;
2035typedef struct xpvmg XPVMG;
2036typedef struct xpvlv XPVLV;
2037typedef struct xpvav XPVAV;
2038typedef struct xpvhv XPVHV;
2039typedef struct xpvgv XPVGV;
2040typedef struct xpvcv XPVCV;
2041typedef struct xpvbm XPVBM;
2042typedef struct xpvfm XPVFM;
8990e307 2043typedef struct xpvio XPVIO;
79072805
LW
2044typedef struct mgvtbl MGVTBL;
2045typedef union any ANY;
5f7fde29
GS
2046typedef struct ptr_tbl_ent PTR_TBL_ENT_t;
2047typedef struct ptr_tbl PTR_TBL_t;
8cf8f3d1
NIS
2048typedef struct clone_params CLONE_PARAMS;
2049
378cc40b 2050#include "handy.h"
a0d0e21e 2051
6b8eaf93 2052#if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_RAWIO)
6b8eaf93
JH
2053# if LSEEKSIZE == 8 && !defined(USE_64_BIT_RAWIO)
2054# define USE_64_BIT_RAWIO /* implicit */
2055# endif
4564133c
JH
2056#endif
2057
6b8eaf93
JH
2058/* Notice the use of HAS_FSEEKO: now we are obligated to always use
2059 * fseeko/ftello if possible. Don't go #defining ftell to ftello yourself,
2060 * however, because operating systems like to do that themself. */
2061#ifndef FSEEKSIZE
2062# ifdef HAS_FSEEKO
2063# define FSEEKSIZE LSEEKSIZE
2064# else
2065# define FSEEKSIZE LONGSIZE
d460ef45 2066# endif
6b8eaf93
JH
2067#endif
2068
2069#if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_STDIO)
6b8eaf93
JH
2070# if FSEEKSIZE == 8 && !defined(USE_64_BIT_STDIO)
2071# define USE_64_BIT_STDIO /* implicit */
2072# endif
2073#endif
4564133c 2074
09458382 2075#ifdef USE_64_BIT_RAWIO
d9b3e12d
JH
2076# ifdef HAS_OFF64_T
2077# undef Off_t
2078# define Off_t off64_t
2079# undef LSEEKSIZE
2080# define LSEEKSIZE 8
5ff3f7a4 2081# endif
d9b3e12d
JH
2082/* Most 64-bit environments have defines like _LARGEFILE_SOURCE that
2083 * will trigger defines like the ones below. Some 64-bit environments,
09458382 2084 * however, do not. Therefore we have to explicitly mix and match. */
d9b3e12d
JH
2085# if defined(USE_OPEN64)
2086# define open open64
5ff3f7a4 2087# endif
d9b3e12d
JH
2088# if defined(USE_LSEEK64)
2089# define lseek lseek64
6b8eaf93
JH
2090# else
2091# if defined(USE_LLSEEK)
2092# define lseek llseek
2093# endif
d9b3e12d
JH
2094# endif
2095# if defined(USE_STAT64)
2096# define stat stat64
2097# endif
2098# if defined(USE_FSTAT64)
2099# define fstat fstat64
2100# endif
2101# if defined(USE_LSTAT64)
2102# define lstat lstat64
2103# endif
2104# if defined(USE_FLOCK64)
2105# define flock flock64
2106# endif
2107# if defined(USE_LOCKF64)
2108# define lockf lockf64
2109# endif
2110# if defined(USE_FCNTL64)
2111# define fcntl fcntl64
2112# endif
2113# if defined(USE_TRUNCATE64)
2114# define truncate truncate64
2115# endif
2116# if defined(USE_FTRUNCATE64)
2117# define ftruncate ftruncate64
2118# endif
2119#endif
2120
2121#ifdef USE_64_BIT_STDIO
2122# ifdef HAS_FPOS64_T
2123# undef Fpos_t
2124# define Fpos_t fpos64_t
2125# endif
2126/* Most 64-bit environments have defines like _LARGEFILE_SOURCE that
2127 * will trigger defines like the ones below. Some 64-bit environments,
2128 * however, do not. */
2129# if defined(USE_FOPEN64)
2130# define fopen fopen64
2131# endif
2132# if defined(USE_FSEEK64)
6b8eaf93 2133# define fseek fseek64 /* don't do fseeko here, see perlio.c */
d9b3e12d
JH
2134# endif
2135# if defined(USE_FTELL64)
6b8eaf93 2136# define ftell ftell64 /* don't do ftello here, see perlio.c */
d9b3e12d
JH
2137# endif
2138# if defined(USE_FSETPOS64)
2139# define fsetpos fsetpos64
2140# endif
2141# if defined(USE_FGETPOS64)
2142# define fgetpos fgetpos64
2143# endif
2144# if defined(USE_TMPFILE64)
2145# define tmpfile tmpfile64
2146# endif
2147# if defined(USE_FREOPEN64)
2148# define freopen freopen64
5ff3f7a4
GS
2149# endif
2150#endif
2151
af8b425d 2152#if defined(OS2) || defined(MACOS_TRADITIONAL)
2c2d71f5
JH
2153# include "iperlsys.h"
2154#endif
2155
6f71a643 2156#if defined(__OPEN_VM)
19848b3f
JH
2157# include "vmesa/vmesaish.h"
2158# define ISHISH "vmesa"
6f71a643
JH
2159#endif
2160
748a9306 2161#ifdef DOSISH
19848b3f
JH
2162# if defined(OS2)
2163# include "os2ish.h"
2164# else
2165# include "dosish.h"
2166# endif
2167# define ISHISH "dos"
2168#endif
2169
2170#if defined(VMS)
748a9306 2171# include "vmsish.h"
96e176bf 2172# include "embed.h"
19848b3f
JH
2173# define ISHISH "vms"
2174#endif
2175
2176#if defined(PLAN9)
2177# include "./plan9/plan9ish.h"
2178# define ISHISH "plan9"
2179#endif
2180
2181#if defined(MPE)
2182# include "mpeix/mpeixish.h"
2183# define ISHISH "mpeix"
2184#endif
2185
2186#if defined(__VOS__)
196918b0
PG
2187# ifdef __GNUC__
2188# include "./vos/vosish.h"
2189# else
2190# include "vos/vosish.h"
2191# endif
19848b3f
JH
2192# define ISHISH "vos"
2193#endif
2194
2195#if defined(EPOC)
2196# include "epocish.h"
2197# define ISHISH "epoc"
2198#endif
2199
2200#if defined(MACOS_TRADITIONAL)
2201# include "macos/macish.h"
2202# ifndef NO_ENVIRON_ARRAY
2203# define NO_ENVIRON_ARRAY
0c30d9ec 2204# endif
19848b3f
JH
2205# define ISHISH "macos classic"
2206#endif
2207
efca5cc6
JH
2208#if defined(__BEOS__)
2209# include "beos/beosish.h"
2210# define ISHISH "beos"
2211#endif
2212
19848b3f
JH
2213#ifndef ISHISH
2214# include "unixish.h"
2215# define ISHISH "unix"
13b6e58c
JH
2216#endif
2217
2218#ifndef NO_ENVIRON_ARRAY
2219# define USE_ENVIRON_ARRAY
2220#endif
32f822de 2221
c77b533b
JH
2222/*
2223 * initialise to avoid floating-point exceptions from overflow, etc
2224 */
2225#ifndef PERL_FPU_INIT
2226# ifdef HAS_FPSETMASK
2227# if HAS_FLOATINGPOINT_H
2228# include <floatingpoint.h>
2229# endif
2230# define PERL_FPU_INIT fpsetmask(0);
c77b533b 2231# else
75a5c1c6 2232# if defined(SIGFPE) && defined(SIG_IGN) && !defined(PERL_MICRO)
ac388100 2233# define PERL_FPU_INIT PL_sigfpe_saved = signal(SIGFPE, SIG_IGN);
629185f5
JH
2234# define PERL_FPU_PRE_EXEC { Sigsave_t xfpe; rsignal_save(SIGFPE, PL_sigfpe_saved, &xfpe);
2235# define PERL_FPU_POST_EXEC rsignal_restore(SIGFPE, &xfpe); }
7014c407
JH
2236# else
2237# define PERL_FPU_INIT
75a5c1c6 2238
7014c407 2239# endif
c77b533b
JH
2240# endif
2241#endif
629185f5
JH
2242#ifndef PERL_FPU_PRE_EXEC
2243# define PERL_FPU_PRE_EXEC {
2244# define PERL_FPU_POST_EXEC }
2245#endif
c77b533b 2246
ed344e4f
IZ
2247#ifndef PERL_SYS_INIT3
2248# define PERL_SYS_INIT3(argvp,argcp,envp) PERL_SYS_INIT(argvp,argcp)
2249#endif
2250
be708cc0
JH
2251#ifndef PERL_WRITE_MSG_TO_CONSOLE
2252# define PERL_WRITE_MSG_TO_CONSOLE(io, msg, len) PerlIO_write(io, msg, len)
2253#endif
2254
0f31cffe
GS
2255#ifndef MAXPATHLEN
2256# ifdef PATH_MAX
b990c8b2
JH
2257# ifdef _POSIX_PATH_MAX
2258# if PATH_MAX > _POSIX_PATH_MAX
5b7ea690
JH
2259/* POSIX 1990 (and pre) was ambiguous about whether PATH_MAX
2260 * included the null byte or not. Later amendments of POSIX,
2261 * XPG4, the Austin Group, and the Single UNIX Specification
2262 * all explicitly include the null byte in the PATH_MAX.
2263 * Ditto for _POSIX_PATH_MAX. */
2264# define MAXPATHLEN PATH_MAX
b990c8b2 2265# else
5b7ea690 2266# define MAXPATHLEN _POSIX_PATH_MAX
b990c8b2
JH
2267# endif
2268# else
2269# define MAXPATHLEN (PATH_MAX+1)
2270# endif
0f31cffe 2271# else
b990c8b2 2272# ifdef _POSIX_PATH_MAX
5b7ea690 2273# define MAXPATHLEN _POSIX_PATH_MAX
b990c8b2
JH
2274# else
2275# define MAXPATHLEN 1024 /* Err on the large side. */
2276# endif
0f31cffe
GS
2277# endif
2278#endif
2279
d460ef45 2280/*
4d1ff10f 2281 * USE_5005THREADS needs to be after unixish.h as <pthread.h> includes
dd96f567 2282 * <sys/signal.h> which defines NSIG - which will stop inclusion of <signal.h>
32f822de
GS
2283 * this results in many functions being undeclared which bothers C++
2284 * May make sense to have threads after "*ish.h" anyway
2285 */
2286
4d1ff10f
AB
2287#if defined(USE_5005THREADS) || defined(USE_ITHREADS)
2288# if defined(USE_5005THREADS)
79d59c5f
GS
2289 /* pending resolution of licensing issues, we avoid the erstwhile
2290 * atomic.h everywhere */
2291# define EMULATE_ATOMIC_REFCOUNTS
1feb2720 2292# endif
2986a63f
JH
2293# ifdef NETWARE
2294# include <nw5thread.h>
2295# else
32f822de
GS
2296# ifdef FAKE_THREADS
2297# include "fakethr.h"
2298# else
2299# ifdef WIN32
2300# include <win32thread.h>
2301# else
dd96f567
IZ
2302# ifdef OS2
2303# include "os2thread.h"
2304# else
7f3d1cf1 2305# ifdef I_MACH_CTHREADS
bdd66968 2306# include <mach/cthreads.h>
8f1f23e8 2307# if (defined(NeXT) || defined(__NeXT__)) && defined(PERL_POLLUTE_MALLOC)
772fe5b3
HM
2308# define MUTEX_INIT_CALLS_MALLOC
2309# endif
7f3d1cf1
BH
2310typedef cthread_t perl_os_thread;
2311typedef mutex_t perl_mutex;
2312typedef condition_t perl_cond;
2313typedef void * perl_key;
2314# else /* Posix threads */
1f5ae88c
JH
2315# ifdef I_PTHREAD
2316# include <pthread.h>
2317# endif
7f3d1cf1
BH
2318typedef pthread_t perl_os_thread;
2319typedef pthread_mutex_t perl_mutex;
2320typedef pthread_cond_t perl_cond;
2321typedef pthread_key_t perl_key;
2322# endif /* I_MACH_CTHREADS */
dd96f567 2323# endif /* OS2 */
32f822de
GS
2324# endif /* WIN32 */
2325# endif /* FAKE_THREADS */
2986a63f 2326#endif /* NETWARE */
4d1ff10f 2327#endif /* USE_5005THREADS || USE_ITHREADS */
c5be433b 2328
66a93824 2329#if defined(WIN32)
1feb2720 2330# include "win32.h"
c5be433b
GS
2331#endif
2332
2986a63f
JH
2333#ifdef NETWARE
2334# include "netware.h"
2335#endif
2336
68dc0745 2337#ifdef VMS
6b88bc9c 2338# define STATUS_NATIVE PL_statusvalue_vms
68dc0745 2339# define STATUS_NATIVE_EXPORT \
d98f61e7 2340 (((I32)PL_statusvalue_vms == -1 ? 44 : PL_statusvalue_vms) | (VMSISH_HUSHED ? 0x10000000 : 0))
68dc0745 2341# define STATUS_NATIVE_SET(n) \
2342 STMT_START { \
6b88bc9c
GS
2343 PL_statusvalue_vms = (n); \
2344 if ((I32)PL_statusvalue_vms == -1) \
3280af22 2345 PL_statusvalue = -1; \
6b88bc9c 2346 else if (PL_statusvalue_vms & STS$M_SUCCESS) \
3280af22 2347 PL_statusvalue = 0; \
6b88bc9c
GS
2348 else if ((PL_statusvalue_vms & STS$M_SEVERITY) == 0) \
2349 PL_statusvalue = 1 << 8; \
68dc0745 2350 else \
6b88bc9c 2351 PL_statusvalue = (PL_statusvalue_vms & STS$M_SEVERITY) << 8; \
68dc0745 2352 } STMT_END
3280af22 2353# define STATUS_POSIX PL_statusvalue
68dc0745 2354# ifdef VMSISH_STATUS
2355# define STATUS_CURRENT (VMSISH_STATUS ? STATUS_NATIVE : STATUS_POSIX)
2356# else
2357# define STATUS_CURRENT STATUS_POSIX
2358# endif
2359# define STATUS_POSIX_SET(n) \
2360 STMT_START { \
3280af22
NIS
2361 PL_statusvalue = (n); \
2362 if (PL_statusvalue != -1) { \
2363 PL_statusvalue &= 0xFFFF; \
6b88bc9c 2364 PL_statusvalue_vms = PL_statusvalue ? 44 : 1; \
68dc0745 2365 } \
6b88bc9c 2366 else PL_statusvalue_vms = -1; \
68dc0745 2367 } STMT_END
6b88bc9c
GS
2368# define STATUS_ALL_SUCCESS (PL_statusvalue = 0, PL_statusvalue_vms = 1)
2369# define STATUS_ALL_FAILURE (PL_statusvalue = 1, PL_statusvalue_vms = 44)
68dc0745 2370#else
2371# define STATUS_NATIVE STATUS_POSIX
2372# define STATUS_NATIVE_EXPORT STATUS_POSIX
2373# define STATUS_NATIVE_SET STATUS_POSIX_SET
3280af22 2374# define STATUS_POSIX PL_statusvalue
68dc0745 2375# define STATUS_POSIX_SET(n) \
2376 STMT_START { \
3280af22
NIS
2377 PL_statusvalue = (n); \
2378 if (PL_statusvalue != -1) \
2379 PL_statusvalue &= 0xFFFF; \
68dc0745 2380 } STMT_END
2381# define STATUS_CURRENT STATUS_POSIX
3280af22
NIS
2382# define STATUS_ALL_SUCCESS (PL_statusvalue = 0)
2383# define STATUS_ALL_FAILURE (PL_statusvalue = 1)
68dc0745 2384#endif
2385
cc3604b1
GS
2386/* flags in PL_exit_flags for nature of exit() */
2387#define PERL_EXIT_EXPECTED 0x01
31d77e54 2388#define PERL_EXIT_DESTRUCT_END 0x02 /* Run END in perl_destruct */
cc3604b1 2389
0b94c7bb 2390#ifndef MEMBER_TO_FPTR
a7cb1f99
GS
2391# define MEMBER_TO_FPTR(name) name
2392#endif
2393
2394/* format to use for version numbers in file/directory names */
273cf8d1 2395/* XXX move to Configure? */
a7cb1f99 2396#ifndef PERL_FS_VER_FMT
273cf8d1 2397# define PERL_FS_VER_FMT "%d.%d.%d"
0b94c7bb
GS
2398#endif
2399
45bc9206 2400/* This defines a way to flush all output buffers. This may be a
76549fef
JH
2401 * performance issue, so we allow people to disable it. Also, if
2402 * we are using stdio, there are broken implementations of fflush(NULL)
2403 * out there, Solaris being the most prominent.
45bc9206
GS
2404 */
2405#ifndef PERL_FLUSHALL_FOR_CHILD
76549fef 2406# if defined(USE_PERLIO) || defined(FFLUSH_NULL) || defined(USE_SFIO)
66fe083f 2407# define PERL_FLUSHALL_FOR_CHILD PerlIO_flush((PerlIO*)NULL)
767df6a1
JH
2408# else
2409# ifdef FFLUSH_ALL
2410# define PERL_FLUSHALL_FOR_CHILD my_fflush_all()
e2dbf222 2411# else
c5be433b 2412# define PERL_FLUSHALL_FOR_CHILD NOOP
767df6a1 2413# endif
66fe083f 2414# endif
45bc9206
GS
2415#endif
2416
7766f137
GS
2417#ifndef PERL_WAIT_FOR_CHILDREN
2418# define PERL_WAIT_FOR_CHILDREN NOOP
2419#endif
2420
ba869deb 2421/* the traditional thread-unsafe notion of "current interpreter". */
c5be433b
GS
2422#ifndef PERL_SET_INTERP
2423# define PERL_SET_INTERP(i) (PL_curinterp = (PerlInterpreter*)(i))
2424#endif
2425
2426#ifndef PERL_GET_INTERP
2427# define PERL_GET_INTERP (PL_curinterp)
2428#endif
2429
54aff467 2430#if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_GET_THX)
4d1ff10f 2431# ifdef USE_5005THREADS
ba869deb 2432# define PERL_GET_THX ((struct perl_thread *)PERL_GET_CONTEXT)
54aff467
GS
2433# else
2434# ifdef MULTIPLICITY
ba869deb 2435# define PERL_GET_THX ((PerlInterpreter *)PERL_GET_CONTEXT)
54aff467
GS
2436# endif
2437# endif
ba869deb
GS
2438# define PERL_SET_THX(t) PERL_SET_CONTEXT(t)
2439#endif
2440
894356b3
GS
2441#ifndef SVf
2442# ifdef CHECK_FORMAT
9982c483 2443# define SVf "-p"
894356b3
GS
2444# else
2445# define SVf "_"
d460ef45 2446# endif
894356b3
GS
2447#endif
2448
9982c483 2449#ifndef SVf_precision
d2560b70 2450# ifdef CHECK_FORMAT
9982c483 2451# define SVf_precision(n) "-" n "p"
d2560b70 2452# else
9982c483 2453# define SVf_precision(n) "." n "_"
d460ef45 2454# endif
d2560b70
RB
2455#endif
2456
2457#ifndef VDf
2458# ifdef CHECK_FORMAT
9a2a392e 2459# define VDf "-1p"
d2560b70
RB
2460# else
2461# define VDf "vd"
d460ef45 2462# endif
d2560b70
RB
2463#endif
2464
9982c483
RB
2465#ifndef SVf32
2466# define SVf32 SVf_precision("32")
2467#endif
2468
2469#ifndef SVf256
2470# define SVf256 SVf_precision("256")
2471#endif
2472
2473#ifndef UVf
2474# define UVf UVuf
2475#endif
2476
2477#ifndef DieNull
b3fe4827 2478# ifdef CHECK_FORMAT
9982c483 2479# define DieNull Perl_vdie(aTHX_ Nullch, Null(va_list *))
b3fe4827 2480# else
9982c483 2481# define DieNull Perl_die(aTHX_ Nullch)
b3fe4827
RB
2482# endif
2483#endif
2484
16c773f9
JH
2485#ifndef __attribute__format__
2486# ifdef CHECK_FORMAT
2487# define __attribute__format__(x,y,z) __attribute__((__format__(x,y,z)))
2488# else
2489# define __attribute__format__(x,y,z)
2490# endif
2491#endif
2492
3fc1aec6 2493/* Some unistd.h's give a prototype for pause() even though
2494 HAS_PAUSE ends up undefined. This causes the #define
d2560b70 2495 below to be rejected by the compiler. Sigh.
3fc1aec6 2496*/
2497#ifdef HAS_PAUSE
2498#define Pause pause
2499#else
2500#define Pause() sleep((32767<<16)+32767)
748a9306
LW
2501#endif
2502
2503#ifndef IOCPARM_LEN
2504# ifdef IOCPARM_MASK
2505 /* on BSDish systes we're safe */
2506# define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
2507# else
2508 /* otherwise guess at what's safe */
2509# define IOCPARM_LEN(x) 256
2510# endif
a0d0e21e
LW
2511#endif
2512
1761cee5 2513#if defined(__CYGWIN__)
521e0776
GS
2514/* USEMYBINMODE
2515 * This symbol, if defined, indicates that the program should
16fe6d59 2516 * use the routine my_binmode(FILE *fp, char iotype, int mode) to insure
521e0776
GS
2517 * that a file is in "binary" mode -- that is, that no translation
2518 * of bytes occurs on read or write operations.
2519 */
16c773f9 2520# define USEMYBINMODE /**/
5ed858ef 2521# include <io.h> /* for setmode() prototype */
16fe6d59 2522# define my_binmode(fp, iotype, mode) \
5ed858ef 2523 (PerlLIO_setmode(fileno(fp), mode) != -1 ? TRUE : FALSE)
5aabfad6 2524#endif
2525
ecde6dd6
NA
2526#ifdef __CYGWIN__
2527void init_os_extras(void);
2528#endif
2529
cea2e8a9
GS
2530#ifdef UNION_ANY_DEFINITION
2531UNION_ANY_DEFINITION;
2532#else
2533union any {
2534 void* any_ptr;
2535 I32 any_i32;
2536 IV any_iv;
2537 long any_long;
4f4e7967 2538 bool any_bool;
c76ac1ee 2539 void (*any_dptr) (void*);
acfe0abc 2540 void (*any_dxptr) (pTHX_ void*);
cea2e8a9
GS
2541};
2542#endif
2543
4d1ff10f 2544#ifdef USE_5005THREADS
cea2e8a9
GS
2545#define ARGSproto struct perl_thread *thr
2546#else
2547#define ARGSproto
4d1ff10f 2548#endif /* USE_5005THREADS */
cea2e8a9 2549
acfe0abc 2550typedef I32 (*filter_t) (pTHX_ int, SV *, int);
cea2e8a9
GS
2551
2552#define FILTER_READ(idx, sv, len) filter_read(idx, sv, len)
2553#define FILTER_DATA(idx) (AvARRAY(PL_rsfp_filters)[idx])
2554#define FILTER_ISREADER(idx) (idx >= AvFILLp(PL_rsfp_filters))
2555
c5078cac
JH
2556#if defined(_AIX) && !defined(_AIX43)
2557#if defined(USE_REENTRANT) || defined(_REENTRANT) || defined(_THREAD_SAFE)
2558/* We cannot include <crypt.h> to get the struct crypt_data
2559 * because of setkey prototype problems when threading */
2560typedef struct crypt_data { /* straight from /usr/include/crypt.h */
2561 /* From OSF, Not needed in AIX
2562 char C[28], D[28];
2563 */
2564 char E[48];
2565 char KS[16][48];
2566 char block[66];
2567 char iobuf[16];
2568} CRYPTD;
2569#endif /* threading */
2570#endif /* AIX */
2571
af8b425d 2572#if !defined(OS2) && !defined(MACOS_TRADITIONAL)
2c2d71f5
JH
2573# include "iperlsys.h"
2574#endif
c71f9582 2575
a8770bf5
JH
2576/* [perl #22371] Algorimic Complexity Attack on Perl 5.6.1, 5.8.0.
2577 * Note that the USE_HASH_SEED and USE_HASH_SEED_EXPLICIT are *NOT*
2578 * defined by Configure, despite their names being similar to the
2579 * other defines like USE_ITHREADS. Configure in fact knows nothing
2580 * about the randomised hashes. Therefore to enable/disable the hash
2581 * randomisation defines use the Configure -Accflags=... instead. */
c71f9582 2582#if !defined(NO_HASH_SEED) && !defined(USE_HASH_SEED) && !defined(USE_HASH_SEED_EXPLICIT)
aa69cd32 2583# define USE_HASH_SEED
c71f9582
PN
2584#endif
2585
378cc40b 2586#include "regexp.h"
79072805 2587#include "sv.h"
378cc40b 2588#include "util.h"
8d063cd8 2589#include "form.h"
79072805 2590#include "gv.h"
9755d405 2591#include "pad.h"
79072805 2592#include "cv.h"
abdd5c84 2593#include "opnames.h"
79072805
LW
2594#include "op.h"
2595#include "cop.h"
2596#include "av.h"
2597#include "hv.h"
2598#include "mg.h"
2599#include "scope.h"
4438c4b7 2600#include "warnings.h"
a0ed51b3 2601#include "utf8.h"
8d063cd8 2602
7fae4e64
GS
2603/* Current curly descriptor */
2604typedef struct curcur CURCUR;
2605struct curcur {
2606 int parenfloor; /* how far back to strip paren data */
2607 int cur; /* how many instances of scan we've matched */
2608 int min; /* the minimal number of scans to match */
2609 int max; /* the maximal number of scans to match */
2610 int minmod; /* whether to work our way up or down */
2611 regnode * scan; /* the thing to match */
2612 regnode * next; /* what has to match after it */
2613 char * lastloc; /* where we started matching this scan */
2614 CURCUR * oldcc; /* current curly before we started this one */
2615};
2616
2617typedef struct _sublex_info SUBLEXINFO;
2618struct _sublex_info {
2619 I32 super_state; /* lexer state to save */
2620 I32 sub_inwhat; /* "lex_inwhat" to use */
2621 OP *sub_op; /* "lex_op" to use */
0244c3a4
GS
2622 char *super_bufptr; /* PL_bufptr that was */
2623 char *super_bufend; /* PL_bufend that was */
7fae4e64
GS
2624};
2625
455ece5e 2626typedef struct magic_state MGS; /* struct magic_state defined in mg.c */
76e3520e 2627
2c2d71f5 2628struct scan_data_t; /* Used in S_* functions in regcomp.c */
653099ff 2629struct regnode_charclass_class; /* Used in S_* functions in regcomp.c */
76e3520e
GS
2630
2631typedef I32 CHECKPOINT;
76e3520e 2632
5f7fde29
GS
2633struct ptr_tbl_ent {
2634 struct ptr_tbl_ent* next;
2635 void* oldval;
2636 void* newval;
d18c6117
GS
2637};
2638
5f7fde29
GS
2639struct ptr_tbl {
2640 struct ptr_tbl_ent** tbl_ary;
2641 UV tbl_max;
2642 UV tbl_items;
d18c6117
GS
2643};
2644
450a55e4 2645#if defined(iAPX286) || defined(M_I286) || defined(I80286)
a687059c
LW
2646# define I286
2647#endif
2648
fe14fcc3
LW
2649#if defined(htonl) && !defined(HAS_HTONL)
2650#define HAS_HTONL
ae986130 2651#endif
fe14fcc3
LW
2652#if defined(htons) && !defined(HAS_HTONS)
2653#define HAS_HTONS
ae986130 2654#endif
fe14fcc3
LW
2655#if defined(ntohl) && !defined(HAS_NTOHL)
2656#define HAS_NTOHL
ae986130 2657#endif
fe14fcc3
LW
2658#if defined(ntohs) && !defined(HAS_NTOHS)
2659#define HAS_NTOHS
ae986130 2660#endif
fe14fcc3 2661#ifndef HAS_HTONL
d9d8d8de 2662#if (BYTEORDER & 0xffff) != 0x4321
fe14fcc3
LW
2663#define HAS_HTONS
2664#define HAS_HTONL
2665#define HAS_NTOHS
2666#define HAS_NTOHL
a687059c
LW
2667#define MYSWAP
2668#define htons my_swap
2669#define htonl my_htonl
2670#define ntohs my_swap
2671#define ntohl my_ntohl
2672#endif
2673#else
d9d8d8de 2674#if (BYTEORDER & 0xffff) == 0x4321
fe14fcc3
LW
2675#undef HAS_HTONS
2676#undef HAS_HTONL
2677#undef HAS_NTOHS
2678#undef HAS_NTOHL
a687059c
LW
2679#endif
2680#endif
2681
988174c1
LW
2682/*
2683 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
2684 * -DWS
2685 */
2686#if BYTEORDER != 0x1234
2687# define HAS_VTOHL
2688# define HAS_VTOHS
2689# define HAS_HTOVL
2690# define HAS_HTOVS
c67712b2 2691# if BYTEORDER == 0x4321 || BYTEORDER == 0x87654321
988174c1
LW
2692# define vtohl(x) ((((x)&0xFF)<<24) \
2693 +(((x)>>24)&0xFF) \
2694 +(((x)&0x0000FF00)<<8) \
2695 +(((x)&0x00FF0000)>>8) )
2696# define vtohs(x) ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
2697# define htovl(x) vtohl(x)
2698# define htovs(x) vtohs(x)
2699# endif
2700 /* otherwise default to functions in util.c */
2a8c3029 2701#ifndef htovs
c623ac67
GS
2702short htovs(short n);
2703short vtohs(short n);
2704long htovl(long n);
2705long vtohl(long n);
988174c1 2706#endif
2a8c3029 2707#endif
988174c1 2708
3bb7c1b4
JH
2709/* *MAX Plus 1. A floating point value.
2710 Hopefully expressed in a way that dodgy floating point can't mess up.
2711 >> 2 rather than 1, so that value is safely less than I32_MAX after 1
2712 is added to it
2713 May find that some broken compiler will want the value cast to I32.
2714 [after the shift, as signed >> may not be as secure as unsigned >>]
2715*/
2716#define I32_MAX_P1 (2.0 * (1 + (((U32)I32_MAX) >> 1)))
2717#define U32_MAX_P1 (4.0 * (1 + ((U32_MAX) >> 2)))
2718/* For compilers that can't correctly cast NVs over 0x7FFFFFFF (or
2719 0x7FFFFFFFFFFFFFFF) to an unsigned integer. In the future, sizeof(UV)
2720 may be greater than sizeof(IV), so don't assume that half max UV is max IV.
2721*/
2722#define U32_MAX_P1_HALF (2.0 * (1 + ((U32_MAX) >> 2)))
ee0007ab 2723
3bb7c1b4
JH
2724#define UV_MAX_P1 (4.0 * (1 + ((UV_MAX) >> 2)))
2725#define IV_MAX_P1 (2.0 * (1 + (((UV)IV_MAX) >> 1)))
2726#define UV_MAX_P1_HALF (2.0 * (1 + ((UV_MAX) >> 2)))
2727
2728/* This may look like unnecessary jumping through hoops, but converting
2729 out of range floating point values to integers *is* undefined behaviour,
2730 and it is starting to bite.
2731*/
2732#ifndef CAST_INLINE
65202027 2733#define I_32(what) (cast_i32((NV)(what)))
3bb7c1b4 2734#define U_32(what) (cast_ulong((NV)(what)))
65202027
DS
2735#define I_V(what) (cast_iv((NV)(what)))
2736#define U_V(what) (cast_uv((NV)(what)))
3bb7c1b4
JH
2737#else
2738#define I_32(n) ((n) < I32_MAX_P1 ? ((n) < I32_MIN ? I32_MIN : (I32) (n)) \
2739 : ((n) < U32_MAX_P1 ? (I32)(U32) (n) \
2740 : ((n) > 0 ? (I32) U32_MAX : 0 /* NaN */)))
2741#define U_32(n) ((n) < 0.0 ? ((n) < I32_MIN ? (UV) I32_MIN : (U32)(I32) (n)) \
2742 : ((n) < U32_MAX_P1 ? (U32) (n) \
2743 : ((n) > 0 ? U32_MAX : 0 /* NaN */)))
2744#define I_V(n) ((n) < IV_MAX_P1 ? ((n) < IV_MIN ? IV_MIN : (IV) (n)) \
2745 : ((n) < UV_MAX_P1 ? (IV)(UV) (n) \
2746 : ((n) > 0 ? (IV)UV_MAX : 0 /* NaN */)))
2747#define U_V(n) ((n) < 0.0 ? ((n) < IV_MIN ? (UV) IV_MIN : (UV)(IV) (n)) \
2748 : ((n) < UV_MAX_P1 ? (UV) (n) \
2749 : ((n) > 0 ? UV_MAX : 0 /* NaN */)))
2750#endif
2751
2752#define U_S(what) ((U16)U_32(what))
2753#define U_I(what) ((unsigned int)U_32(what))
2754#define U_L(what) U_32(what)
ed6116ce 2755
2d4389e4
JH
2756/* These do not care about the fractional part, only about the range. */
2757#define NV_WITHIN_IV(nv) (I_V(nv) >= IV_MIN && I_V(nv) <= IV_MAX)
24db6c0d 2758#define NV_WITHIN_UV(nv) ((nv)>=0.0 && U_V(nv) >= UV_MIN && U_V(nv) <= UV_MAX)
2d4389e4 2759
25da4f38
IZ
2760/* Used with UV/IV arguments: */
2761 /* XXXX: need to speed it up */
2762#define CLUMP_2UV(iv) ((iv) < 0 ? 0 : (UV)(iv))
2763#define CLUMP_2IV(uv) ((uv) > (UV)IV_MAX ? IV_MAX : (IV)(uv))
2764
352d5a3a
LW
2765#ifndef MAXSYSFD
2766# define MAXSYSFD 2
2767#endif
ee0007ab 2768
79072805 2769#ifndef __cplusplus
e1caacb4 2770#ifndef UNDER_CE
20ce7b12
GS
2771Uid_t getuid (void);
2772Uid_t geteuid (void);
2773Gid_t getgid (void);
2774Gid_t getegid (void);
79072805 2775#endif
e1caacb4 2776#endif
8d063cd8 2777
0c30d9ec 2778#ifndef Perl_debug_log
bf49b057
GS
2779# define Perl_debug_log PerlIO_stderr()
2780#endif
2781
2782#ifndef Perl_error_log
2783# define Perl_error_log (PL_stderrgv \
5b7ea690 2784 && isGV(PL_stderrgv) \
01bb7c6d 2785 && GvIOp(PL_stderrgv) \
42de951c 2786 && IoOFP(GvIOp(PL_stderrgv)) \
bf49b057
GS
2787 ? IoOFP(GvIOp(PL_stderrgv)) \
2788 : PerlIO_stderr())
0c30d9ec 2789#endif
3967c732 2790
aea4f609
DM
2791
2792#define DEBUG_p_FLAG 0x00000001 /* 1 */
2793#define DEBUG_s_FLAG 0x00000002 /* 2 */
2794#define DEBUG_l_FLAG 0x00000004 /* 4 */
2795#define DEBUG_t_FLAG 0x00000008 /* 8 */
2796#define DEBUG_o_FLAG 0x00000010 /* 16 */
2797#define DEBUG_c_FLAG 0x00000020 /* 32 */
2798#define DEBUG_P_FLAG 0x00000040 /* 64 */
2799#define DEBUG_m_FLAG 0x00000080 /* 128 */
2800#define DEBUG_f_FLAG 0x00000100 /* 256 */
2801#define DEBUG_r_FLAG 0x00000200 /* 512 */
2802#define DEBUG_x_FLAG 0x00000400 /* 1024 */
2803#define DEBUG_u_FLAG 0x00000800 /* 2048 */
aea4f609
DM
2804#define DEBUG_H_FLAG 0x00002000 /* 8192 */
2805#define DEBUG_X_FLAG 0x00004000 /* 16384 */
2806#define DEBUG_D_FLAG 0x00008000 /* 32768 */
2807#define DEBUG_S_FLAG 0x00010000 /* 65536 */
2808#define DEBUG_T_FLAG 0x00020000 /* 131072 */
04932ac8 2809#define DEBUG_R_FLAG 0x00040000 /* 262144 */
1045810a 2810#define DEBUG_J_FLAG 0x00080000 /* 524288 */
bbb1cf39
JH
2811#define DEBUG_v_FLAG 0x00100000 /*1048576 */
2812#define DEBUG_MASK 0x001FEFFF /* mask of all the standard flags */
aea4f609
DM
2813
2814#define DEBUG_DB_RECURSE_FLAG 0x40000000
1045810a
IZ
2815#define DEBUG_TOP_FLAG 0x80000000 /* XXX what's this for ??? Signal
2816 that something was done? */
aea4f609 2817
bd16a5f0
IZ
2818# define DEBUG_p_TEST_ (PL_debug & DEBUG_p_FLAG)
2819# define DEBUG_s_TEST_ (PL_debug & DEBUG_s_FLAG)
2820# define DEBUG_l_TEST_ (PL_debug & DEBUG_l_FLAG)
2821# define DEBUG_t_TEST_ (PL_debug & DEBUG_t_FLAG)
2822# define DEBUG_o_TEST_ (PL_debug & DEBUG_o_FLAG)
2823# define DEBUG_c_TEST_ (PL_debug & DEBUG_c_FLAG)
2824# define DEBUG_P_TEST_ (PL_debug & DEBUG_P_FLAG)
2825# define DEBUG_m_TEST_ (PL_debug & DEBUG_m_FLAG)
2826# define DEBUG_f_TEST_ (PL_debug & DEBUG_f_FLAG)
2827# define DEBUG_r_TEST_ (PL_debug & DEBUG_r_FLAG)
2828# define DEBUG_x_TEST_ (PL_debug & DEBUG_x_FLAG)
2829# define DEBUG_u_TEST_ (PL_debug & DEBUG_u_FLAG)
bd16a5f0
IZ
2830# define DEBUG_H_TEST_ (PL_debug & DEBUG_H_FLAG)
2831# define DEBUG_X_TEST_ (PL_debug & DEBUG_X_FLAG)
2832# define DEBUG_D_TEST_ (PL_debug & DEBUG_D_FLAG)
2833# define DEBUG_S_TEST_ (PL_debug & DEBUG_S_FLAG)
2834# define DEBUG_T_TEST_ (PL_debug & DEBUG_T_FLAG)
2835# define DEBUG_R_TEST_ (PL_debug & DEBUG_R_FLAG)
1045810a 2836# define DEBUG_J_TEST_ (PL_debug & DEBUG_J_FLAG)
bbb1cf39 2837# define DEBUG_v_TEST_ (PL_debug & DEBUG_v_FLAG)
9755d405
JH
2838# define DEBUG_Xv_TEST_ (DEBUG_X_TEST_ && DEBUG_v_TEST_)
2839
bd16a5f0 2840
3967c732 2841#ifdef DEBUGGING
aea4f609
DM
2842
2843# undef YYDEBUG
2844# define YYDEBUG 1
2845
bd16a5f0
IZ
2846# define DEBUG_p_TEST DEBUG_p_TEST_
2847# define DEBUG_s_TEST DEBUG_s_TEST_
2848# define DEBUG_l_TEST DEBUG_l_TEST_
2849# define DEBUG_t_TEST DEBUG_t_TEST_
2850# define DEBUG_o_TEST DEBUG_o_TEST_
2851# define DEBUG_c_TEST DEBUG_c_TEST_
2852# define DEBUG_P_TEST DEBUG_P_TEST_
2853# define DEBUG_m_TEST DEBUG_m_TEST_
2854# define DEBUG_f_TEST DEBUG_f_TEST_
2855# define DEBUG_r_TEST DEBUG_r_TEST_
2856# define DEBUG_x_TEST DEBUG_x_TEST_
2857# define DEBUG_u_TEST DEBUG_u_TEST_
bd16a5f0
IZ
2858# define DEBUG_H_TEST DEBUG_H_TEST_
2859# define DEBUG_X_TEST DEBUG_X_TEST_
9755d405 2860# define DEBUG_Xv_TEST DEBUG_Xv_TEST_
bd16a5f0
IZ
2861# define DEBUG_D_TEST DEBUG_D_TEST_
2862# define DEBUG_S_TEST DEBUG_S_TEST_
2863# define DEBUG_T_TEST DEBUG_T_TEST_
2864# define DEBUG_R_TEST DEBUG_R_TEST_
1045810a 2865# define DEBUG_J_TEST DEBUG_J_TEST_
bbb1cf39 2866# define DEBUG_v_TEST DEBUG_v_TEST_
aea4f609 2867
70cc50ef
JH
2868# define PERL_DEB(a) a
2869# define PERL_DEBUG(a) if (PL_debug) a
aea4f609
DM
2870# define DEBUG_p(a) if (DEBUG_p_TEST) a
2871# define DEBUG_s(a) if (DEBUG_s_TEST) a
2872# define DEBUG_l(a) if (DEBUG_l_TEST) a
2873# define DEBUG_t(a) if (DEBUG_t_TEST) a
2874# define DEBUG_o(a) if (DEBUG_o_TEST) a
2875# define DEBUG_c(a) if (DEBUG_c_TEST) a
2876# define DEBUG_P(a) if (DEBUG_P_TEST) a
2877
969058bb
VK
2878 /* Temporarily turn off memory debugging in case the a
2879 * does memory allocation, either directly or indirectly. */
acfe0abc 2880# define DEBUG_m(a) \
0b250b9e 2881 STMT_START { \
aea4f609 2882 if (PERL_GET_INTERP) { dTHX; if (DEBUG_m_TEST) {PL_debug&=~DEBUG_m_FLAG; a; PL_debug|=DEBUG_m_FLAG;} } \
0b250b9e 2883 } STMT_END
aea4f609 2884
5f80b19c
AMS
2885# define DEBUG__(t, a) \
2886 STMT_START { \
2887 if (t) STMT_START {a;} STMT_END; \
2888 } STMT_END
2889
2890# define DEBUG_f(a) DEBUG__(DEBUG_f_TEST, a)
2891# define DEBUG_r(a) DEBUG__(DEBUG_r_TEST, a)
2892# define DEBUG_x(a) DEBUG__(DEBUG_x_TEST, a)
2893# define DEBUG_u(a) DEBUG__(DEBUG_u_TEST, a)
5f80b19c
AMS
2894# define DEBUG_H(a) DEBUG__(DEBUG_H_TEST, a)
2895# define DEBUG_X(a) DEBUG__(DEBUG_X_TEST, a)
9755d405 2896# define DEBUG_Xv(a) DEBUG__(DEBUG_Xv_TEST, a)
5f80b19c 2897# define DEBUG_D(a) DEBUG__(DEBUG_D_TEST, a)
aea4f609 2898
4d1ff10f 2899# ifdef USE_5005THREADS
5f80b19c 2900# define DEBUG_S(a) DEBUG__(DEBUG_S_TEST, a)
8b73bbec
IZ
2901# else
2902# define DEBUG_S(a)
2903# endif
aea4f609 2904
5f80b19c
AMS
2905# define DEBUG_T(a) DEBUG__(DEBUG_T_TEST, a)
2906# define DEBUG_R(a) DEBUG__(DEBUG_R_TEST, a)
bbb1cf39 2907# define DEBUG_v(a) DEBUG__(DEBUG_v_TEST, a)
aea4f609
DM
2908
2909#else /* DEBUGGING */
2910
2911# define DEBUG_p_TEST (0)
2912# define DEBUG_s_TEST (0)
2913# define DEBUG_l_TEST (0)
2914# define DEBUG_t_TEST (0)
2915# define DEBUG_o_TEST (0)
2916# define DEBUG_c_TEST (0)
2917# define DEBUG_P_TEST (0)
2918# define DEBUG_m_TEST (0)
2919# define DEBUG_f_TEST (0)
2920# define DEBUG_r_TEST (0)
2921# define DEBUG_x_TEST (0)
2922# define DEBUG_u_TEST (0)
aea4f609
DM
2923# define DEBUG_H_TEST (0)
2924# define DEBUG_X_TEST (0)
9755d405 2925# define DEBUG_Xv_TEST (0)
aea4f609
DM
2926# define DEBUG_D_TEST (0)
2927# define DEBUG_S_TEST (0)
2928# define DEBUG_T_TEST (0)
04932ac8 2929# define DEBUG_R_TEST (0)
1045810a 2930# define DEBUG_J_TEST (0)
bbb1cf39 2931# define DEBUG_v_TEST (0)
aea4f609 2932
70cc50ef
JH
2933# define PERL_DEB(a)
2934# define PERL_DEBUG(a)
aea4f609
DM
2935# define DEBUG_p(a)
2936# define DEBUG_s(a)
2937# define DEBUG_l(a)
2938# define DEBUG_t(a)
2939# define DEBUG_o(a)
2940# define DEBUG_c(a)
2941# define DEBUG_P(a)
2942# define DEBUG_m(a)
2943# define DEBUG_f(a)
2944# define DEBUG_r(a)
2945# define DEBUG_x(a)
2946# define DEBUG_u(a)
aea4f609
DM
2947# define DEBUG_H(a)
2948# define DEBUG_X(a)
9755d405 2949# define DEBUG_Xv(a)
aea4f609
DM
2950# define DEBUG_D(a)
2951# define DEBUG_S(a)
2952# define DEBUG_T(a)
04932ac8 2953# define DEBUG_R(a)
bbb1cf39 2954# define DEBUG_v(a)
aea4f609
DM
2955#endif /* DEBUGGING */
2956
2957
1aa6899f
JH
2958#define DEBUG_SCOPE(where) \
2959 DEBUG_l(WITH_THR(Perl_deb(aTHX_ "%s scope %ld at %s:%d\n", \
2960 where, PL_scopestack_ix, __FILE__, __LINE__)));
2961
2962
2963
2964
d1be9408 2965/* These constants should be used in preference to raw characters
14befaf4
DM
2966 * when using magic. Note that some perl guts still assume
2967 * certain character properties of these constants, namely that
2968 * isUPPER() and toLOWER() may do useful mappings.
2969 *
2970 * Update the magic_names table in dump.c when adding/amending these
2971 */
2972
2973#define PERL_MAGIC_sv '\0' /* Special scalar variable */
2974#define PERL_MAGIC_overload 'A' /* %OVERLOAD hash */
2975#define PERL_MAGIC_overload_elem 'a' /* %OVERLOAD hash element */
2976#define PERL_MAGIC_overload_table 'c' /* Holds overload table (AMT) on stash */
2977#define PERL_MAGIC_bm 'B' /* Boyer-Moore (fast string search) */
2978#define PERL_MAGIC_regdata 'D' /* Regex match position data
2979 (@+ and @- vars) */
2980#define PERL_MAGIC_regdatum 'd' /* Regex match position data element */
2981#define PERL_MAGIC_env 'E' /* %ENV hash */
2982#define PERL_MAGIC_envelem 'e' /* %ENV hash element */
2983#define PERL_MAGIC_fm 'f' /* Formline ('compiled' format) */
2984#define PERL_MAGIC_regex_global 'g' /* m//g target / study()ed string */
2985#define PERL_MAGIC_isa 'I' /* @ISA array */
2986#define PERL_MAGIC_isaelem 'i' /* @ISA array element */
2987#define PERL_MAGIC_nkeys 'k' /* scalar(keys()) lvalue */
2988#define PERL_MAGIC_dbfile 'L' /* Debugger %_<filename */
2989#define PERL_MAGIC_dbline 'l' /* Debugger %_<filename element */
68795e93
NIS
2990#define PERL_MAGIC_mutex 'm' /* for lock op */
2991#define PERL_MAGIC_shared 'N' /* Shared between threads */
2992#define PERL_MAGIC_shared_scalar 'n' /* Shared between threads */
14befaf4
DM
2993#define PERL_MAGIC_collxfrm 'o' /* Locale transformation */
2994#define PERL_MAGIC_tied 'P' /* Tied array or hash */
2995#define PERL_MAGIC_tiedelem 'p' /* Tied array or hash element */
2996#define PERL_MAGIC_tiedscalar 'q' /* Tied scalar or handle */
2997#define PERL_MAGIC_qr 'r' /* precompiled qr// regex */
2998#define PERL_MAGIC_sig 'S' /* %SIG hash */
2999#define PERL_MAGIC_sigelem 's' /* %SIG hash element */
3000#define PERL_MAGIC_taint 't' /* Taintedness */
3001#define PERL_MAGIC_uvar 'U' /* Available for use by extensions */
68795e93 3002#define PERL_MAGIC_uvar_elem 'u' /* Reserved for use by extensions */
7d7ce6cc 3003#define PERL_MAGIC_vstring 'V' /* SV was vstring literal */
14befaf4 3004#define PERL_MAGIC_vec 'v' /* vec() lvalue */
323eb6b5 3005#define PERL_MAGIC_utf8 'w' /* Cached UTF-8 information */
14befaf4
DM
3006#define PERL_MAGIC_substr 'x' /* substr() lvalue */
3007#define PERL_MAGIC_defelem 'y' /* Shadow "foreach" iterator variable /
3008 smart parameter vivification */
3009#define PERL_MAGIC_glob '*' /* GV (typeglob) */
3010#define PERL_MAGIC_arylen '#' /* Array length ($#ary) */
3011#define PERL_MAGIC_pos '.' /* pos() lvalue */
68795e93 3012#define PERL_MAGIC_backref '<' /* for weak ref data */
14befaf4
DM
3013#define PERL_MAGIC_ext '~' /* Available for use by extensions */
3014
3015
fe14fcc3 3016#define YYMAXDEPTH 300
8d063cd8 3017
a6e633de 3018#ifndef assert /* <assert.h> might have been included somehow */
a446a88f 3019#ifdef DEBUGGING
70cc50ef 3020#define assert(what) PERL_DEB( { \
a446a88f
NIS
3021 if (!(what)) { \
3022 Perl_croak(aTHX_ "Assertion " STRINGIFY(what) " failed: file \"%s\", line %d", \
3023 __FILE__, __LINE__); \
3024 PerlProc_exit(1); \
3025 }})
3026#else
70cc50ef 3027#define assert(what) PERL_DEB( { \
79072805 3028 if (!(what)) { \
cea2e8a9 3029 Perl_croak(aTHX_ "Assertion failed: file \"%s\", line %d", \
79072805 3030 __FILE__, __LINE__); \
cea2e8a9 3031 PerlProc_exit(1); \
79072805 3032 }})
a6e633de 3033#endif
a446a88f 3034#endif
8d063cd8 3035
450a55e4 3036struct ufuncs {
24f81a43
DM
3037 I32 (*uf_val)(pTHX_ IV, SV*);
3038 I32 (*uf_set)(pTHX_ IV, SV*);
a0d0e21e 3039 IV uf_index;
450a55e4
LW
3040};
3041
14befaf4 3042/* In pre-5.7-Perls the PERL_MAGIC_uvar magic didn't get the thread context.
24f81a43
DM
3043 * XS code wanting to be backward compatible can do something
3044 * like the following:
c745e42c 3045
24f81a43 3046#ifndef PERL_MG_UFUNC
24f81a43
DM
3047#define PERL_MG_UFUNC(name,ix,sv) I32 name(IV ix, SV *sv)
3048#endif
3049
3050static PERL_MG_UFUNC(foo_get, index, val)
3051{
3052 sv_setsv(val, ...);
3053 return TRUE;
3054}
3055
3056-- Doug MacEachern
3057
3058*/
3059
fc9c74e6 3060#ifndef PERL_MG_UFUNC
24f81a43 3061#define PERL_MG_UFUNC(name,ix,sv) I32 name(pTHX_ IV ix, SV *sv)
fc9c74e6 3062#endif
24f81a43 3063
fe14fcc3 3064/* Fix these up for __STDC__ */
68dc0745 3065#ifndef DONT_DECLARE_STD
20ce7b12 3066char *mktemp (char*);
37bd1396 3067#ifndef atof
20ce7b12 3068double atof (const char*);
a0d0e21e 3069#endif
37bd1396 3070#endif
79072805 3071
352d5a3a 3072#ifndef STANDARD_C
fe14fcc3 3073/* All of these are in stdlib.h or time.h for ANSI C */
85e6fe83 3074Time_t time();
8d063cd8 3075struct tm *gmtime(), *localtime();
092bebab 3076#if defined(OEMVS) || defined(__OPEN_VM)
9d116dd7
JH
3077char *(strchr)(), *(strrchr)();
3078char *(strcpy)(), *(strcat)();
3079#else
93a17b20 3080char *strchr(), *strrchr();
378cc40b 3081char *strcpy(), *strcat();
9d116dd7 3082#endif
352d5a3a 3083#endif /* ! STANDARD_C */
8d063cd8 3084
79072805
LW
3085
3086#ifdef I_MATH
3087# include <math.h>
3088#else
32f822de 3089START_EXTERN_C
20ce7b12
GS
3090 double exp (double);
3091 double log (double);
3092 double log10 (double);
3093 double sqrt (double);
3094 double frexp (double,int*);
3095 double ldexp (double,int);
3096 double modf (double,double*);
3097 double sin (double);
3098 double cos (double);
3099 double atan2 (double,double);
3100 double pow (double,double);
32f822de 3101END_EXTERN_C
79072805
LW
3102#endif
3103
aa8b85de
JH
3104#if !defined(NV_INF) && defined(USE_LONG_DOUBLE) && defined(LDBL_INFINITY)
3105# define NV_INF LDBL_INFINITY
3106#endif
3107#if !defined(NV_INF) && defined(DBL_INFINITY)
3108# define NV_INF (NV)DBL_INFINITY
3109#endif
3110#if !defined(NV_INF) && defined(INFINITY)
3111# define NV_INF (NV)INFINITY
3112#endif
3113#if !defined(NV_INF) && defined(INF)
3114# define NV_INF (NV)INF
3115#endif
3116#if !defined(NV_INF) && defined(USE_LONG_DOUBLE) && defined(HUGE_VALL)
3117# define NV_INF (NV)HUGE_VALL
3118#endif
3119#if !defined(NV_INF) && defined(HUGE_VAL)
3120# define NV_INF (NV)HUGE_VAL
3121#endif
3122
3123#if !defined(NV_NAN) && defined(USE_LONG_DOUBLE)
3124# if !defined(NV_NAN) && defined(LDBL_NAN)
3125# define NV_NAN LDBL_NAN
3126# endif
3127# if !defined(NV_NAN) && defined(LDBL_QNAN)
3128# define NV_NAN LDBL_QNAN
3129# endif
3130# if !defined(NV_NAN) && defined(LDBL_SNAN)
3131# define NV_NAN LDBL_SNAN
3132# endif
3133#endif
3134#if !defined(NV_NAN) && defined(DBL_NAN)
3135# define NV_NAN (NV)DBL_NAN
3136#endif
3137#if !defined(NV_NAN) && defined(DBL_QNAN)
3138# define NV_NAN (NV)DBL_QNAN
3139#endif
3140#if !defined(NV_NAN) && defined(DBL_SNAN)
3141# define NV_NAN (NV)DBL_SNAN
3142#endif
3143#if !defined(NV_NAN) && defined(QNAN)
3144# define NV_NAN (NV)QNAN
3145#endif
3146#if !defined(NV_NAN) && defined(SNAN)
3147# define NV_NAN (NV)SNAN
3148#endif
3149#if !defined(NV_NAN) && defined(NAN)
3150# define NV_NAN (NV)NAN
3151#endif
3152
a0d0e21e 3153#ifndef __cplusplus
8f1f23e8 3154# if defined(NeXT) || defined(__NeXT__) /* or whatever catches all NeXTs */
3fc1aec6 3155char *crypt (); /* Maybe more hosts will need the unprototyped version */
26618a56 3156# else
fd8cd3a3 3157# if !defined(WIN32) && !defined(VMS)
10bc17b6 3158#ifndef crypt
20ce7b12 3159char *crypt (const char*, const char*);
10bc17b6 3160#endif
5014db98 3161# endif /* !WIN32 */
8f1f23e8 3162# endif /* !NeXT && !__NeXT__ */
26618a56
GS
3163# ifndef DONT_DECLARE_STD
3164# ifndef getenv
20ce7b12 3165char *getenv (const char*);
26618a56 3166# endif /* !getenv */
28ca6303 3167# if !defined(HAS_LSEEK_PROTO) && !defined(EPOC) && !defined(__hpux)
0fc67700 3168# ifdef _FILE_OFFSET_BITS
28ca6303 3169# if _FILE_OFFSET_BITS == 64
20ce7b12 3170Off_t lseek (int,Off_t,int);
0fc67700
JH
3171# endif
3172# endif
bf0c440f 3173# endif
26618a56 3174# endif /* !DONT_DECLARE_STD */
10bc17b6 3175#ifndef getlogin
20ce7b12 3176char *getlogin (void);
10bc17b6 3177#endif
26618a56 3178#endif /* !__cplusplus */
79072805 3179
16d20bd9 3180#ifdef UNLINK_ALL_VERSIONS /* Currently only makes sense for VMS */
378cc40b 3181#define UNLINK unlnk
20ce7b12 3182I32 unlnk (char*);
8d063cd8 3183#else
80252599 3184#define UNLINK PerlLIO_unlink
8d063cd8 3185#endif
a687059c 3186
fa0a29af
JH
3187/* some versions of glibc are missing the setresuid() proto */
3188#if defined(HAS_SETRESUID) && !defined(HAS_SETRESUID_PROTO)
640374d0
JH
3189int setresuid(uid_t ruid, uid_t euid, uid_t suid);
3190#endif
fa0a29af
JH
3191/* some versions of glibc are missing the setresgid() proto */
3192#if defined(HAS_SETRESGID) && !defined(HAS_SETRESGID_PROTO)
640374d0
JH
3193int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
3194#endif
3195
fe14fcc3 3196#ifndef HAS_SETREUID
85e6fe83
LW
3197# ifdef HAS_SETRESUID
3198# define setreuid(r,e) setresuid(r,e,(Uid_t)-1)
3199# define HAS_SETREUID
3200# endif
a687059c 3201#endif
fe14fcc3 3202#ifndef HAS_SETREGID
85e6fe83
LW
3203# ifdef HAS_SETRESGID
3204# define setregid(r,e) setresgid(r,e,(Gid_t)-1)
3205# define HAS_SETREGID
3206# endif
a687059c 3207#endif
ee0007ab 3208
d543acb6 3209/* Sighandler_t defined in iperlsys.h */
ff68c719 3210
3211#ifdef HAS_SIGACTION
3212typedef struct sigaction Sigsave_t;
3213#else
3214typedef Sighandler_t Sigsave_t;
3215#endif
3216
ee0007ab
LW
3217#define SCAN_DEF 0
3218#define SCAN_TR 1
3219#define SCAN_REPL 2
79072805
LW
3220
3221#ifdef DEBUGGING
4633a7c4 3222# ifndef register
a0d0e21e
LW
3223# define register
3224# endif
cea2e8a9 3225# define RUNOPS_DEFAULT Perl_runops_debug
79072805 3226#else
cea2e8a9 3227# define RUNOPS_DEFAULT Perl_runops_standard
79072805
LW
3228#endif
3229
18f739ee 3230#ifdef MYMALLOC
772fe5b3 3231# ifdef MUTEX_INIT_CALLS_MALLOC
3541dd58
HM
3232# define MALLOC_INIT \
3233 STMT_START { \
3234 PL_malloc_mutex = NULL; \
3235 MUTEX_INIT(&PL_malloc_mutex); \
3236 } STMT_END
3237# define MALLOC_TERM \
3238 STMT_START { \
3239 perl_mutex tmp = PL_malloc_mutex; \
3240 PL_malloc_mutex = NULL; \
3241 MUTEX_DESTROY(&tmp); \
3242 } STMT_END
3243# else
3244# define MALLOC_INIT MUTEX_INIT(&PL_malloc_mutex)
3245# define MALLOC_TERM MUTEX_DESTROY(&PL_malloc_mutex)
3246# endif
18f739ee
IZ
3247#else
3248# define MALLOC_INIT
3249# define MALLOC_TERM
3250#endif
3251
b6d9d515 3252
0cb96387 3253typedef int (CPERLscope(*runops_proc_t)) (pTHX);
68795e93 3254typedef void (CPERLscope(*share_proc_t)) (pTHX_ SV *sv);
62375a60 3255typedef int (CPERLscope(*thrhook_proc_t)) (pTHX);
0cb96387 3256typedef OP* (CPERLscope(*PPADDR_t)[]) (pTHX);
22c35a8c 3257
940cb80d 3258/* _ (for $_) must be first in the following list (DEFSV requires it) */
54b9620d 3259#define THREADSV_NAMES "_123456789&`'+/.,\\\";^-%=|~:\001\005!@"
a863c7d1 3260
8f1f23e8
W
3261/* NeXT has problems with crt0.o globals */
3262#if defined(__DYNAMIC__) && \
6bf46c2a 3263 (defined(NeXT) || defined(__NeXT__) || defined(PERL_DARWIN))
8f1f23e8
W
3264# if defined(NeXT) || defined(__NeXT)
3265# include <mach-o/dyld.h>
3266# define environ (*environ_pointer)
0c30d9ec 3267EXT char *** environ_pointer;
8f1f23e8 3268# else
6bf46c2a 3269# if defined(PERL_DARWIN) && defined(PERL_CORE)
8f1f23e8
W
3270# include <crt_externs.h> /* for the env array */
3271# define environ (*_NSGetEnviron())
3272# endif
0c30d9ec 3273# endif
8f1f23e8
W
3274#else
3275 /* VMS and some other platforms don't use the environ array */
13b6e58c 3276# ifdef USE_ENVIRON_ARRAY
a6c40364
GS
3277# if !defined(DONT_DECLARE_STD) || \
3278 (defined(__svr4__) && defined(__GNUC__) && defined(sun)) || \
3279 defined(__sgi) || \
d460ef45 3280 defined(__DGUX)
8f1f23e8 3281extern char ** environ; /* environment variables supplied via exec */
a6c40364 3282# endif
8f1f23e8
W
3283# endif
3284#endif
79072805 3285
73c4f7a1
GS
3286START_EXTERN_C
3287
79072805 3288/* handy constants */
22c35a8c 3289EXTCONST char PL_warn_uninit[]
b89fed5f 3290 INIT("Use of uninitialized value%s%s");
22c35a8c 3291EXTCONST char PL_warn_nosemi[]
463ee0b2 3292 INIT("Semicolon seems to be missing");
22c35a8c 3293EXTCONST char PL_warn_reserved[]
463ee0b2 3294 INIT("Unquoted string \"%s\" may clash with future reserved word");
22c35a8c 3295EXTCONST char PL_warn_nl[]
93a17b20 3296 INIT("Unsuccessful %s on filename containing newline");
22c35a8c 3297EXTCONST char PL_no_wrongref[]
a0d0e21e 3298 INIT("Can't use %s ref as %s ref");
22c35a8c 3299EXTCONST char PL_no_symref[]
748a9306 3300 INIT("Can't use string (\"%.32s\") as %s ref while \"strict refs\" in use");
22c35a8c 3301EXTCONST char PL_no_usym[]
8990e307 3302 INIT("Can't use an undefined value as %s reference");
22c35a8c 3303EXTCONST char PL_no_aelem[]
93a17b20 3304 INIT("Modification of non-creatable array value attempted, subscript %d");
22c35a8c 3305EXTCONST char PL_no_helem[]
93a17b20 3306 INIT("Modification of non-creatable hash value attempted, subscript \"%s\"");
22c35a8c 3307EXTCONST char PL_no_modify[]
93a17b20 3308 INIT("Modification of a read-only value attempted");
22c35a8c 3309EXTCONST char PL_no_mem[]
93a17b20 3310 INIT("Out of memory!\n");
22c35a8c 3311EXTCONST char PL_no_security[]
463ee0b2 3312 INIT("Insecure dependency in %s%s");
22c35a8c 3313EXTCONST char PL_no_sock_func[]
93a17b20 3314 INIT("Unsupported socket function \"%s\" called");
22c35a8c 3315EXTCONST char PL_no_dir_func[]
93a17b20 3316 INIT("Unsupported directory function \"%s\" called");
22c35a8c 3317EXTCONST char PL_no_func[]
93a17b20 3318 INIT("The %s function is unimplemented");
22c35a8c 3319EXTCONST char PL_no_myglob[]
748a9306 3320 INIT("\"my\" variable %s can't be in a package");
5835a535
JH
3321EXTCONST char PL_no_localize_ref[]
3322 INIT("Can't localize through a reference");
1c6118a4
JH
3323#ifdef PERL_MALLOC_WRAP
3324EXTCONST char PL_memory_wrap[]
3325 INIT("panic: memory wrap");
3326#endif
93a17b20 3327
7575fa06 3328EXTCONST char PL_uuemap[65]
80252599
GS
3329 INIT("`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_");
3330
3331
79072805 3332#ifdef DOINIT
22c35a8c
GS
3333EXT char *PL_sig_name[] = { SIG_NAME };
3334EXT int PL_sig_num[] = { SIG_NUM };
79072805 3335#else
22c35a8c
GS
3336EXT char *PL_sig_name[];
3337EXT int PL_sig_num[];
79072805
LW
3338#endif
3339
3bd709b1 3340/* fast conversion and case folding tables */
bbce6d69 3341
79072805 3342#ifdef DOINIT
9d116dd7 3343#ifdef EBCDIC
22c35a8c 3344EXT unsigned char PL_fold[] = { /* fast EBCDIC case folding table */
9d116dd7
JH
3345 0, 1, 2, 3, 4, 5, 6, 7,
3346 8, 9, 10, 11, 12, 13, 14, 15,
3347 16, 17, 18, 19, 20, 21, 22, 23,
3348 24, 25, 26, 27, 28, 29, 30, 31,
3349 32, 33, 34, 35, 36, 37, 38, 39,
3350 40, 41, 42, 43, 44, 45, 46, 47,
3351 48, 49, 50, 51, 52, 53, 54, 55,
3352 56, 57, 58, 59, 60, 61, 62, 63,
3353 64, 65, 66, 67, 68, 69, 70, 71,
3354 72, 73, 74, 75, 76, 77, 78, 79,
3355 80, 81, 82, 83, 84, 85, 86, 87,
3356 88, 89, 90, 91, 92, 93, 94, 95,
3357 96, 97, 98, 99, 100, 101, 102, 103,
3358 104, 105, 106, 107, 108, 109, 110, 111,
3359 112, 113, 114, 115, 116, 117, 118, 119,
3360 120, 121, 122, 123, 124, 125, 126, 127,
3361 128, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
3362 'H', 'I', 138, 139, 140, 141, 142, 143,
3363 144, 'J', 'K', 'L', 'M', 'N', 'O', 'P',
3364 'Q', 'R', 154, 155, 156, 157, 158, 159,
3365 160, 161, 'S', 'T', 'U', 'V', 'W', 'X',
3366 'Y', 'Z', 170, 171, 172, 173, 174, 175,
3367 176, 177, 178, 179, 180, 181, 182, 183,
3368 184, 185, 186, 187, 188, 189, 190, 191,
3369 192, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
3370 'h', 'i', 202, 203, 204, 205, 206, 207,
3371 208, 'j', 'k', 'l', 'm', 'n', 'o', 'p',
3372 'q', 'r', 218, 219, 220, 221, 222, 223,
3373 224, 225, 's', 't', 'u', 'v', 'w', 'x',
3374 'y', 'z', 234, 235, 236, 237, 238, 239,
3375 240, 241, 242, 243, 244, 245, 246, 247,
3376 248, 249, 250, 251, 252, 253, 254, 255
3377};
3378#else /* ascii rather than ebcdic */
22c35a8c 3379EXTCONST unsigned char PL_fold[] = {
79072805
LW
3380 0, 1, 2, 3, 4, 5, 6, 7,
3381 8, 9, 10, 11, 12, 13, 14, 15,
3382 16, 17, 18, 19, 20, 21, 22, 23,
3383 24, 25, 26, 27, 28, 29, 30, 31,
3384 32, 33, 34, 35, 36, 37, 38, 39,
3385 40, 41, 42, 43, 44, 45, 46, 47,
3386 48, 49, 50, 51, 52, 53, 54, 55,
3387 56, 57, 58, 59, 60, 61, 62, 63,
3388 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
3389 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
3390 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
3391 'x', 'y', 'z', 91, 92, 93, 94, 95,
3392 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
3393 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
3394 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
3395 'X', 'Y', 'Z', 123, 124, 125, 126, 127,
3396 128, 129, 130, 131, 132, 133, 134, 135,
3397 136, 137, 138, 139, 140, 141, 142, 143,
3398 144, 145, 146, 147, 148, 149, 150, 151,
3399 152, 153, 154, 155, 156, 157, 158, 159,
3400 160, 161, 162, 163, 164, 165, 166, 167,
3401 168, 169, 170, 171, 172, 173, 174, 175,
3402 176, 177, 178, 179, 180, 181, 182, 183,
3403 184, 185, 186, 187, 188, 189, 190, 191,
3404 192, 193, 194, 195, 196, 197, 198, 199,
3405 200, 201, 202, 203, 204, 205, 206, 207,
3406 208, 209, 210, 211, 212, 213, 214, 215,
3407 216, 217, 218, 219, 220, 221, 222, 223,
3408 224, 225, 226, 227, 228, 229, 230, 231,
3409 232, 233, 234, 235, 236, 237, 238, 239,
3410 240, 241, 242, 243, 244, 245, 246, 247,
3411 248, 249, 250, 251, 252, 253, 254, 255
3412};
9d116dd7 3413#endif /* !EBCDIC */
79072805 3414#else
22c35a8c 3415EXTCONST unsigned char PL_fold[];
79072805
LW
3416#endif
3417
3418#ifdef DOINIT
22c35a8c 3419EXT unsigned char PL_fold_locale[] = {
79072805
LW
3420 0, 1, 2, 3, 4, 5, 6, 7,
3421 8, 9, 10, 11, 12, 13, 14, 15,
3422 16, 17, 18, 19, 20, 21, 22, 23,
3423 24, 25, 26, 27, 28, 29, 30, 31,
3424 32, 33, 34, 35, 36, 37, 38, 39,
3425 40, 41, 42, 43, 44, 45, 46, 47,
3426 48, 49, 50, 51, 52, 53, 54, 55,
3427 56, 57, 58, 59, 60, 61, 62, 63,
3428 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
3429 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
3430 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
3431 'x', 'y', 'z', 91, 92, 93, 94, 95,
3432 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
3433 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
3434 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
3435 'X', 'Y', 'Z', 123, 124, 125, 126, 127,
3436 128, 129, 130, 131, 132, 133, 134, 135,
3437 136, 137, 138, 139, 140, 141, 142, 143,
3438 144, 145, 146, 147, 148, 149, 150, 151,
3439 152, 153, 154, 155, 156, 157, 158, 159,
3440 160, 161, 162, 163, 164, 165, 166, 167,
3441 168, 169, 170, 171, 172, 173, 174, 175,
3442 176, 177, 178, 179, 180, 181, 182, 183,
3443 184, 185, 186, 187, 188, 189, 190, 191,
3444 192, 193, 194, 195, 196, 197, 198, 199,
3445 200, 201, 202, 203, 204, 205, 206, 207,
3446 208, 209, 210, 211, 212, 213, 214, 215,
3447 216, 217, 218, 219, 220, 221, 222, 223,
3448 224, 225, 226, 227, 228, 229, 230, 231,
3449 232, 233, 234, 235, 236, 237, 238, 239,
3450 240, 241, 242, 243, 244, 245, 246, 247,
3451 248, 249, 250, 251, 252, 253, 254, 255
3452};
3453#else
22c35a8c 3454EXT unsigned char PL_fold_locale[];
79072805
LW
3455#endif
3456
3457#ifdef DOINIT
9d116dd7 3458#ifdef EBCDIC
22c35a8c 3459EXT unsigned char PL_freq[] = {/* EBCDIC frequencies for mixed English/C */
9d116dd7
JH
3460 1, 2, 84, 151, 154, 155, 156, 157,
3461 165, 246, 250, 3, 158, 7, 18, 29,
3462 40, 51, 62, 73, 85, 96, 107, 118,
3463 129, 140, 147, 148, 149, 150, 152, 153,
3464 255, 6, 8, 9, 10, 11, 12, 13,
3465 14, 15, 24, 25, 26, 27, 28, 226,
3466 29, 30, 31, 32, 33, 43, 44, 45,
3467 46, 47, 48, 49, 50, 76, 77, 78,
3468 79, 80, 81, 82, 83, 84, 85, 86,
3469 87, 94, 95, 234, 181, 233, 187, 190,
3470 180, 96, 97, 98, 99, 100, 101, 102,
3471 104, 112, 182, 174, 236, 232, 229, 103,
3472 228, 226, 114, 115, 116, 117, 118, 119,
3473 120, 121, 122, 235, 176, 230, 194, 162,
3474 130, 131, 132, 133, 134, 135, 136, 137,
3475 138, 139, 201, 205, 163, 217, 220, 224,
3476 5, 248, 227, 244, 242, 255, 241, 231,
3477 240, 253, 16, 197, 19, 20, 21, 187,
3478 23, 169, 210, 245, 237, 249, 247, 239,
3479 168, 252, 34, 196, 36, 37, 38, 39,
3480 41, 42, 251, 254, 238, 223, 221, 213,
3481 225, 177, 52, 53, 54, 55, 56, 57,
3482 58, 59, 60, 61, 63, 64, 65, 66,
3483 67, 68, 69, 70, 71, 72, 74, 75,
3484 205, 208, 186, 202, 200, 218, 198, 179,
3485 178, 214, 88, 89, 90, 91, 92, 93,
3486 217, 166, 170, 207, 199, 209, 206, 204,
3487 160, 212, 105, 106, 108, 109, 110, 111,
3488 203, 113, 216, 215, 192, 175, 193, 243,
3489 172, 161, 123, 124, 125, 126, 127, 128,
3490 222, 219, 211, 195, 188, 193, 185, 184,
3491 191, 183, 141, 142, 143, 144, 145, 146
3492};
3493#else /* ascii rather than ebcdic */
22c35a8c 3494EXTCONST unsigned char PL_freq[] = { /* letter frequencies for mixed English/C */
79072805
LW
3495 1, 2, 84, 151, 154, 155, 156, 157,
3496 165, 246, 250, 3, 158, 7, 18, 29,
3497 40, 51, 62, 73, 85, 96, 107, 118,
3498 129, 140, 147, 148, 149, 150, 152, 153,
3499 255, 182, 224, 205, 174, 176, 180, 217,
3500 233, 232, 236, 187, 235, 228, 234, 226,
3501 222, 219, 211, 195, 188, 193, 185, 184,
3502 191, 183, 201, 229, 181, 220, 194, 162,
3503 163, 208, 186, 202, 200, 218, 198, 179,
3504 178, 214, 166, 170, 207, 199, 209, 206,
3505 204, 160, 212, 216, 215, 192, 175, 173,
3506 243, 172, 161, 190, 203, 189, 164, 230,
3507 167, 248, 227, 244, 242, 255, 241, 231,
3508 240, 253, 169, 210, 245, 237, 249, 247,
3509 239, 168, 252, 251, 254, 238, 223, 221,
3510 213, 225, 177, 197, 171, 196, 159, 4,
3511 5, 6, 8, 9, 10, 11, 12, 13,
3512 14, 15, 16, 17, 19, 20, 21, 22,
3513 23, 24, 25, 26, 27, 28, 30, 31,
3514 32, 33, 34, 35, 36, 37, 38, 39,
3515 41, 42, 43, 44, 45, 46, 47, 48,
3516 49, 50, 52, 53, 54, 55, 56, 57,
3517 58, 59, 60, 61, 63, 64, 65, 66,
3518 67, 68, 69, 70, 71, 72, 74, 75,
3519 76, 77, 78, 79, 80, 81, 82, 83,
3520 86, 87, 88, 89, 90, 91, 92, 93,
3521 94, 95, 97, 98, 99, 100, 101, 102,
3522 103, 104, 105, 106, 108, 109, 110, 111,
3523 112, 113, 114, 115, 116, 117, 119, 120,
3524 121, 122, 123, 124, 125, 126, 127, 128,
3525 130, 131, 132, 133, 134, 135, 136, 137,
3526 138, 139, 141, 142, 143, 144, 145, 146
3527};
9d116dd7 3528#endif
79072805 3529#else
22c35a8c 3530EXTCONST unsigned char PL_freq[];
79072805
LW
3531#endif
3532
8990e307
LW
3533#ifdef DEBUGGING
3534#ifdef DOINIT
22c35a8c 3535EXTCONST char* PL_block_type[] = {
8990e307
LW
3536 "NULL",
3537 "SUB",
3538 "EVAL",
3539 "LOOP",
3540 "SUBST",
3541 "BLOCK",
3542};
3543#else
22c35a8c 3544EXTCONST char* PL_block_type[];
8990e307
LW
3545#endif
3546#endif
3547
73c4f7a1
GS
3548END_EXTERN_C
3549
79072805
LW
3550/*****************************************************************************/
3551/* This lexer/parser stuff is currently global since yacc is hard to reenter */
3552/*****************************************************************************/
8990e307 3553/* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */
79072805 3554
f0798ba3
OS
3555#ifdef __Lynx__
3556/* LynxOS defines these in scsi.h which is included via ioctl.h */
3557#ifdef FORMAT
3558#undef FORMAT
3559#endif
3560#ifdef SPACE
3561#undef SPACE
3562#endif
3563#endif
3564
a0d0e21e
LW
3565#include "perly.h"
3566
fb73857a 3567#define LEX_NOTPARSING 11 /* borrowed from toke.c */
3568
79072805
LW
3569typedef enum {
3570 XOPERATOR,
3571 XTERM,
79072805 3572 XREF,
8990e307 3573 XSTATE,
a0d0e21e 3574 XBLOCK,
09bef843
SB
3575 XATTRBLOCK,
3576 XATTRTERM,
a0d0e21e 3577 XTERMBLOCK
79072805
LW
3578} expectation;
3579
dc9e4912
GS
3580enum { /* pass one of these to get_vtbl */
3581 want_vtbl_sv,
3582 want_vtbl_env,
3583 want_vtbl_envelem,
3584 want_vtbl_sig,
3585 want_vtbl_sigelem,
3586 want_vtbl_pack,
3587 want_vtbl_packelem,
3588 want_vtbl_dbline,
3589 want_vtbl_isa,
3590 want_vtbl_isaelem,
3591 want_vtbl_arylen,
3592 want_vtbl_glob,
3593 want_vtbl_mglob,
3594 want_vtbl_nkeys,
3595 want_vtbl_taint,
3596 want_vtbl_substr,
3597 want_vtbl_vec,
3598 want_vtbl_pos,
3599 want_vtbl_bm,
3600 want_vtbl_fm,
3601 want_vtbl_uvar,
3602 want_vtbl_defelem,
3603 want_vtbl_regexp,
3604 want_vtbl_collxfrm,
3605 want_vtbl_amagic,
3606 want_vtbl_amagicelem,
4d1ff10f 3607#ifdef USE_5005THREADS
dc9e4912
GS
3608 want_vtbl_mutex,
3609#endif
3610 want_vtbl_regdata,
810b8aa5 3611 want_vtbl_regdatum,
323eb6b5
JH
3612 want_vtbl_backref,
3613 want_vtbl_utf8
dc9e4912
GS
3614};
3615
85e6fe83
LW
3616 /* Note: the lowest 8 bits are reserved for
3617 stuffing into op->op_private */
f3aa04c2 3618#define HINT_PRIVATE_MASK 0x000000ff
1da2d140
JH
3619#define HINT_INTEGER 0x00000001 /* integer pragma */
3620#define HINT_STRICT_REFS 0x00000002 /* strict pragma */
3621#define HINT_LOCALE 0x00000004 /* locale pragma */
3622#define HINT_BYTES 0x00000008 /* bytes pragma */
393fec97 3623/* #define HINT_notused10 0x00000010 */
a0ed51b3 3624 /* Note: 20,40,80 used for NATIVE_HINTS */
1da2d140 3625 /* currently defined by vms/vmsish.h */
85e6fe83
LW
3626
3627#define HINT_BLOCK_SCOPE 0x00000100
1da2d140
JH
3628#define HINT_STRICT_SUBS 0x00000200 /* strict pragma */
3629#define HINT_STRICT_VARS 0x00000400 /* strict pragma */
85e6fe83 3630
1da2d140 3631/* The HINT_NEW_* constants are used by the overload pragma */
b3ac6de7
IZ
3632#define HINT_NEW_INTEGER 0x00001000
3633#define HINT_NEW_FLOAT 0x00002000
3634#define HINT_NEW_BINARY 0x00004000
3635#define HINT_NEW_STRING 0x00008000
3636#define HINT_NEW_RE 0x00010000
3637#define HINT_LOCALIZE_HH 0x00020000 /* %^H needs to be copied */
3638
1da2d140
JH
3639#define HINT_RE_TAINT 0x00100000 /* re pragma */
3640#define HINT_RE_EVAL 0x00200000 /* re pragma */
b3eb6a9b 3641
1da2d140
JH
3642#define HINT_FILETEST_ACCESS 0x00400000 /* filetest pragma */
3643#define HINT_UTF8 0x00800000 /* utf8 pragma */
5ff3f7a4 3644
1da2d140 3645/* The following are stored in $sort::hints, not in PL_hints */
84d4ea48
JH
3646#define HINT_SORT_SORT_BITS 0x000000FF /* allow 256 different ones */
3647#define HINT_SORT_QUICKSORT 0x00000001
3648#define HINT_SORT_MERGESORT 0x00000002
c53fc8a6 3649#define HINT_SORT_STABLE 0x00000100 /* sort styles (currently one) */
84d4ea48 3650
8bfdd7d9 3651/* Various states of the input record separator SV (rs) */
d4cce5f1 3652#define RsSNARF(sv) (! SvOK(sv))
af7d13df
MG
3653#define RsSIMPLE(sv) (SvOK(sv) && (! SvPOK(sv) || SvCUR(sv)))
3654#define RsPARA(sv) (SvPOK(sv) && ! SvCUR(sv))
5b2b9c68 3655#define RsRECORD(sv) (SvROK(sv) && (SvIV(SvRV(sv)) > 0))
79072805 3656
128e8167 3657/* A struct for keeping various DEBUGGING related stuff,
ce333219 3658 * neatly packed. Currently only scratch variables for
128e8167
JH
3659 * constructing debug output are included. Needed always,
3660 * not just when DEBUGGING, though, because of the re extension. c*/
ce333219
JH
3661struct perl_debug_pad {
3662 SV pad[3];
3663};
3664
3665#define PERL_DEBUG_PAD(i) &(PL_debug_pad.pad[i])
48c6b404 3666#define PERL_DEBUG_PAD_ZERO(i) (SvPVX(PERL_DEBUG_PAD(i))[0] = 0, SvCUR(PERL_DEBUG_PAD(i)) = 0, PERL_DEBUG_PAD(i))
ce333219 3667
56953603 3668/* Enable variables which are pointers to functions */
a2efc822 3669typedef void (CPERLscope(*peep_t))(pTHX_ OP* o);
0cb96387
GS
3670typedef regexp*(CPERLscope(*regcomp_t)) (pTHX_ char* exp, char* xend, PMOP* pm);
3671typedef I32 (CPERLscope(*regexec_t)) (pTHX_ regexp* prog, char* stringarg,
3672 char* strend, char* strbeg, I32 minend,
3673 SV* screamer, void* data, U32 flags);
f722798b
IZ
3674typedef char* (CPERLscope(*re_intuit_start_t)) (pTHX_ regexp *prog, SV *sv,
3675 char *strpos, char *strend,
3676 U32 flags,
3677 struct re_scream_pos_data_s *d);
3678typedef SV* (CPERLscope(*re_intuit_string_t)) (pTHX_ regexp *prog);
3679typedef void (CPERLscope(*regfree_t)) (pTHX_ struct regexp* r);
56953603 3680
c76ac1ee 3681typedef void (*DESTRUCTORFUNC_NOCONTEXT_t) (void*);
acfe0abc
GS
3682typedef void (*DESTRUCTORFUNC_t) (pTHX_ void*);
3683typedef void (*SVFUNC_t) (pTHX_ SV*);
3684typedef I32 (*SVCOMPARE_t) (pTHX_ SV*, SV*);
3685typedef void (*XSINIT_t) (pTHX);
3686typedef void (*ATEXIT_t) (pTHX_ void*);
3687typedef void (*XSUBADDR_t) (pTHX_ CV *);
15e52e56 3688
22239a37
NIS
3689/* Set up PERLVAR macros for populating structs */
3690#define PERLVAR(var,type) type var;
51371543 3691#define PERLVARA(var,n,type) type var[n];
22239a37 3692#define PERLVARI(var,type,init) type var;
3fe35a81 3693#define PERLVARIC(var,type,init) type var;
22239a37 3694
58a50f62
GS
3695/* Interpreter exitlist entry */
3696typedef struct exitlistentry {
acfe0abc 3697 void (*fn) (pTHX_ void*);
58a50f62
GS
3698 void *ptr;
3699} PerlExitListEntry;
3700
22239a37
NIS
3701#ifdef PERL_GLOBAL_STRUCT
3702struct perl_vars {
7766f137 3703# include "perlvars.h"
22239a37
NIS
3704};
3705
7766f137 3706# ifdef PERL_CORE
533c011a
NIS
3707EXT struct perl_vars PL_Vars;
3708EXT struct perl_vars *PL_VarsPtr INIT(&PL_Vars);
7766f137
GS
3709# else /* PERL_CORE */
3710# if !defined(__GNUC__) || !defined(WIN32)
22239a37 3711EXT
7766f137 3712# endif /* WIN32 */
533c011a 3713struct perl_vars *PL_VarsPtr;
7766f137
GS
3714# define PL_Vars (*((PL_VarsPtr) \
3715 ? PL_VarsPtr : (PL_VarsPtr = Perl_GetVars(aTHX))))
3716# endif /* PERL_CORE */
22239a37
NIS
3717#endif /* PERL_GLOBAL_STRUCT */
3718
acfe0abc 3719#if defined(MULTIPLICITY)
d460ef45 3720/* If we have multiple interpreters define a struct
d4cce5f1 3721 holding variables which must be per-interpreter
d460ef45 3722 If we don't have threads anything that would have
d4cce5f1
NIS
3723 be per-thread is per-interpreter.
3724*/
3725
79072805 3726struct interpreter {
4d1ff10f 3727# ifndef USE_5005THREADS
7766f137
GS
3728# include "thrdvar.h"
3729# endif
3730# include "intrpvar.h"
3731/*
3732 * The following is a buffer where new variables must
acfe0abc 3733 * be defined to maintain binary compatibility with previous versions
7766f137
GS
3734 */
3735PERLVARA(object_compatibility,30, char)
49f531da 3736};
d4cce5f1 3737
79072805 3738#else
49f531da
NIS
3739struct interpreter {
3740 char broiled;
3741};
acfe0abc 3742#endif /* MULTIPLICITY */
79072805 3743
4d1ff10f 3744#ifdef USE_5005THREADS
d4cce5f1
NIS
3745/* If we have threads define a struct with all the variables
3746 * that have to be per-thread
49f531da 3747 */
8023c3ce 3748
79072805 3749
49f531da 3750struct perl_thread {
49f531da 3751#include "thrdvar.h"
79072805 3752};
d4cce5f1 3753
22fae026
TM
3754typedef struct perl_thread *Thread;
3755
3756#else
3757typedef void *Thread;
22239a37
NIS
3758#endif
3759
3760/* Done with PERLVAR macros for now ... */
d4cce5f1 3761#undef PERLVAR
51371543 3762#undef PERLVARA
d4cce5f1 3763#undef PERLVARI
3fe35a81 3764#undef PERLVARIC
79072805 3765
cf168e39
WL
3766/* Types used by pack/unpack */
3767typedef enum {
3768 e_no_len, /* no length */
3769 e_number, /* number, [] */
3770 e_star /* asterisk */
3771} howlen_t;
3772
3773typedef struct {
3774 char* patptr; /* current template char */
3775 char* patend; /* one after last char */
3776 char* grpbeg; /* 1st char of ()-group */
3777 char* grpend; /* end of ()-group */
cc3ea0aa 3778 I32 code; /* template code (!<>) */
cf168e39
WL
3779 I32 length; /* length/repeat count */
3780 howlen_t howlen; /* how length is given */
3781 int level; /* () nesting level */
3782 U32 flags; /* /=4, comma=2, pack=1 */
cc3ea0aa 3783 /* and group modifiers */
cf168e39
WL
3784} tempsym_t;
3785
22239a37 3786#include "thread.h"
79072805 3787#include "pp.h"
864dbfa3
GS
3788
3789#ifndef PERL_CALLCONV
3790# define PERL_CALLCONV
d460ef45 3791#endif
864dbfa3 3792
65f19062
GS
3793#ifndef NEXT30_NO_ATTRIBUTE
3794# ifndef HASATTRIBUTE /* disable GNU-cc attribute checking? */
3795# ifdef __attribute__ /* Avoid possible redefinition errors */
3796# undef __attribute__
3797# endif
3798# define __attribute__(attr)
3799# endif
3800#endif
3801
0cb96387
GS
3802#undef PERL_CKDEF
3803#undef PERL_PPDEF
3804#define PERL_CKDEF(s) OP *s (pTHX_ OP *o);
3805#define PERL_PPDEF(s) OP *s (pTHX);
0cb96387 3806
7766f137 3807#include "proto.h"
864dbfa3 3808
0cb96387 3809/* this has structure inits, so it cannot be included before here */
acfe0abc 3810#include "opcode.h"
864dbfa3 3811
d4cce5f1
NIS
3812/* The following must follow proto.h as #defines mess up syntax */
3813
22c35a8c
GS
3814#if !defined(PERL_FOR_X2P)
3815# include "embedvar.h"
3816#endif
d4cce5f1 3817
d460ef45 3818/* Now include all the 'global' variables
d4cce5f1 3819 * If we don't have threads or multiple interpreters
d460ef45 3820 * these include variables that would have been their struct-s
d4cce5f1 3821 */
d460ef45 3822
533c011a 3823#define PERLVAR(var,type) EXT type PL_##var;
51371543 3824#define PERLVARA(var,n,type) EXT type PL_##var[n];
533c011a
NIS
3825#define PERLVARI(var,type,init) EXT type PL_##var INIT(init);
3826#define PERLVARIC(var,type,init) EXTCONST type PL_##var INIT(init);
d4cce5f1 3827
acfe0abc 3828#if !defined(MULTIPLICITY)
7766f137 3829START_EXTERN_C
066ef5b5 3830# include "intrpvar.h"
4d1ff10f 3831# ifndef USE_5005THREADS
066ef5b5
GS
3832# include "thrdvar.h"
3833# endif
7766f137 3834END_EXTERN_C
22239a37
NIS
3835#endif
3836
acfe0abc 3837#if defined(WIN32)
66a93824 3838/* Now all the config stuff is setup we can include embed.h */
22c35a8c 3839# include "embed.h"
acfe0abc 3840#endif
22239a37 3841
c5be433b
GS
3842#ifndef PERL_GLOBAL_STRUCT
3843START_EXTERN_C
3844
3845# include "perlvars.h"
3846
3847END_EXTERN_C
3848#endif
3849
d909e69f
JD
3850#include "reentr.inc"
3851
d4cce5f1 3852#undef PERLVAR
51371543 3853#undef PERLVARA
d4cce5f1 3854#undef PERLVARI
0f3f18a6 3855#undef PERLVARIC
79072805 3856
73c4f7a1
GS
3857START_EXTERN_C
3858
79072805 3859#ifdef DOINIT
bbce6d69 3860
68795e93 3861EXT MGVTBL PL_vtbl_sv = {MEMBER_TO_FPTR(Perl_magic_get),
2b260de0
GS
3862 MEMBER_TO_FPTR(Perl_magic_set),
3863 MEMBER_TO_FPTR(Perl_magic_len),
463ee0b2 3864 0, 0};
2b260de0
GS
3865EXT MGVTBL PL_vtbl_env = {0, MEMBER_TO_FPTR(Perl_magic_set_all_env),
3866 0, MEMBER_TO_FPTR(Perl_magic_clear_all_env),
66b1d557 3867 0};
2b260de0
GS
3868EXT MGVTBL PL_vtbl_envelem = {0, MEMBER_TO_FPTR(Perl_magic_setenv),
3869 0, MEMBER_TO_FPTR(Perl_magic_clearenv),
85e6fe83 3870 0};
22c35a8c 3871EXT MGVTBL PL_vtbl_sig = {0, 0, 0, 0, 0};
64ca3a65
JH
3872#ifdef PERL_MICRO
3873EXT MGVTBL PL_vtbl_sigelem = {0, 0, 0, 0, 0};
3874#else
2b260de0
GS
3875EXT MGVTBL PL_vtbl_sigelem = {MEMBER_TO_FPTR(Perl_magic_getsig),
3876 MEMBER_TO_FPTR(Perl_magic_setsig),
3877 0, MEMBER_TO_FPTR(Perl_magic_clearsig),
0c30d9ec 3878 0};
64ca3a65 3879#endif
68795e93
NIS
3880EXT MGVTBL PL_vtbl_pack = {0, 0,
3881 MEMBER_TO_FPTR(Perl_magic_sizepack),
3882 MEMBER_TO_FPTR(Perl_magic_wipepack),
a0d0e21e 3883 0};
2b260de0 3884EXT MGVTBL PL_vtbl_packelem = {MEMBER_TO_FPTR(Perl_magic_getpack),
68795e93 3885 MEMBER_TO_FPTR(Perl_magic_setpack),
2b260de0 3886 0, MEMBER_TO_FPTR(Perl_magic_clearpack),
463ee0b2 3887 0};
2b260de0 3888EXT MGVTBL PL_vtbl_dbline = {0, MEMBER_TO_FPTR(Perl_magic_setdbline),
463ee0b2 3889 0, 0, 0};
2b260de0
GS
3890EXT MGVTBL PL_vtbl_isa = {0, MEMBER_TO_FPTR(Perl_magic_setisa),
3891 0, MEMBER_TO_FPTR(Perl_magic_setisa),
fb73857a 3892 0};
2b260de0 3893EXT MGVTBL PL_vtbl_isaelem = {0, MEMBER_TO_FPTR(Perl_magic_setisa),
463ee0b2 3894 0, 0, 0};
2b260de0
GS
3895EXT MGVTBL PL_vtbl_arylen = {MEMBER_TO_FPTR(Perl_magic_getarylen),
3896 MEMBER_TO_FPTR(Perl_magic_setarylen),
463ee0b2 3897 0, 0, 0};
2b260de0
GS
3898EXT MGVTBL PL_vtbl_glob = {MEMBER_TO_FPTR(Perl_magic_getglob),
3899 MEMBER_TO_FPTR(Perl_magic_setglob),
463ee0b2 3900 0, 0, 0};
2b260de0 3901EXT MGVTBL PL_vtbl_mglob = {0, MEMBER_TO_FPTR(Perl_magic_setmglob),
463ee0b2 3902 0, 0, 0};
2b260de0
GS
3903EXT MGVTBL PL_vtbl_nkeys = {MEMBER_TO_FPTR(Perl_magic_getnkeys),
3904 MEMBER_TO_FPTR(Perl_magic_setnkeys),
99abf803 3905 0, 0, 0};
68795e93
NIS
3906EXT MGVTBL PL_vtbl_taint = {MEMBER_TO_FPTR(Perl_magic_gettaint),
3907 MEMBER_TO_FPTR(Perl_magic_settaint),
463ee0b2 3908 0, 0, 0};
68795e93
NIS
3909EXT MGVTBL PL_vtbl_substr = {MEMBER_TO_FPTR(Perl_magic_getsubstr),
3910 MEMBER_TO_FPTR(Perl_magic_setsubstr),
463ee0b2 3911 0, 0, 0};
2b260de0 3912EXT MGVTBL PL_vtbl_vec = {MEMBER_TO_FPTR(Perl_magic_getvec),
68795e93 3913 MEMBER_TO_FPTR(Perl_magic_setvec),
463ee0b2 3914 0, 0, 0};
2b260de0
GS
3915EXT MGVTBL PL_vtbl_pos = {MEMBER_TO_FPTR(Perl_magic_getpos),
3916 MEMBER_TO_FPTR(Perl_magic_setpos),
a0d0e21e 3917 0, 0, 0};
2b260de0 3918EXT MGVTBL PL_vtbl_bm = {0, MEMBER_TO_FPTR(Perl_magic_setbm),
463ee0b2 3919 0, 0, 0};
2b260de0 3920EXT MGVTBL PL_vtbl_fm = {0, MEMBER_TO_FPTR(Perl_magic_setfm),
55497cff 3921 0, 0, 0};
2b260de0
GS
3922EXT MGVTBL PL_vtbl_uvar = {MEMBER_TO_FPTR(Perl_magic_getuvar),
3923 MEMBER_TO_FPTR(Perl_magic_setuvar),
463ee0b2 3924 0, 0, 0};
4d1ff10f 3925#ifdef USE_5005THREADS
68795e93
NIS
3926EXT MGVTBL PL_vtbl_mutex = {0, 0, 0, 0,
3927 MEMBER_TO_FPTR(Perl_magic_mutexfree)};
4d1ff10f 3928#endif /* USE_5005THREADS */
68795e93
NIS
3929EXT MGVTBL PL_vtbl_defelem = {MEMBER_TO_FPTR(Perl_magic_getdefelem),
3930 MEMBER_TO_FPTR(Perl_magic_setdefelem),
02270b4e 3931 0, 0, 0};
a0d0e21e 3932
5835a535 3933EXT MGVTBL PL_vtbl_regexp = {0, MEMBER_TO_FPTR(Perl_magic_setregexp),0,0, MEMBER_TO_FPTR(Perl_magic_freeregexp)};
2b260de0 3934EXT MGVTBL PL_vtbl_regdata = {0, 0, MEMBER_TO_FPTR(Perl_magic_regdata_cnt), 0, 0};
a29d06ed
MG
3935EXT MGVTBL PL_vtbl_regdatum = {MEMBER_TO_FPTR(Perl_magic_regdatum_get),
3936 MEMBER_TO_FPTR(Perl_magic_regdatum_set), 0, 0, 0};
c277df42 3937
36477c24 3938#ifdef USE_LOCALE_COLLATE
22c35a8c 3939EXT MGVTBL PL_vtbl_collxfrm = {0,
2b260de0 3940 MEMBER_TO_FPTR(Perl_magic_setcollxfrm),
bbce6d69 3941 0, 0, 0};
3942#endif
a0d0e21e 3943
2b260de0
GS
3944EXT MGVTBL PL_vtbl_amagic = {0, MEMBER_TO_FPTR(Perl_magic_setamagic),
3945 0, 0, MEMBER_TO_FPTR(Perl_magic_setamagic)};
3946EXT MGVTBL PL_vtbl_amagicelem = {0, MEMBER_TO_FPTR(Perl_magic_setamagic),
3947 0, 0, MEMBER_TO_FPTR(Perl_magic_setamagic)};
a0d0e21e 3948
810b8aa5 3949EXT MGVTBL PL_vtbl_backref = {0, 0,
2b260de0 3950 0, 0, MEMBER_TO_FPTR(Perl_magic_killbackrefs)};
810b8aa5 3951
d460ef45
NIS
3952EXT MGVTBL PL_vtbl_ovrld = {0, 0,
3953 0, 0, MEMBER_TO_FPTR(Perl_magic_freeovrld)};
3954
323eb6b5
JH
3955EXT MGVTBL PL_vtbl_utf8 = {0,
3956 MEMBER_TO_FPTR(Perl_magic_setutf8),
3957 0, 0, 0};
3958
bbce6d69 3959#else /* !DOINIT */
3960
22c35a8c
GS
3961EXT MGVTBL PL_vtbl_sv;
3962EXT MGVTBL PL_vtbl_env;
3963EXT MGVTBL PL_vtbl_envelem;
3964EXT MGVTBL PL_vtbl_sig;
3965EXT MGVTBL PL_vtbl_sigelem;
3966EXT MGVTBL PL_vtbl_pack;
3967EXT MGVTBL PL_vtbl_packelem;
3968EXT MGVTBL PL_vtbl_dbline;
3969EXT MGVTBL PL_vtbl_isa;
3970EXT MGVTBL PL_vtbl_isaelem;
3971EXT MGVTBL PL_vtbl_arylen;
3972EXT MGVTBL PL_vtbl_glob;
3973EXT MGVTBL PL_vtbl_mglob;
3974EXT MGVTBL PL_vtbl_nkeys;
3975EXT MGVTBL PL_vtbl_taint;
3976EXT MGVTBL PL_vtbl_substr;
3977EXT MGVTBL PL_vtbl_vec;
3978EXT MGVTBL PL_vtbl_pos;
3979EXT MGVTBL PL_vtbl_bm;
3980EXT MGVTBL PL_vtbl_fm;
3981EXT MGVTBL PL_vtbl_uvar;
d460ef45 3982EXT MGVTBL PL_vtbl_ovrld;
a0d0e21e 3983
4d1ff10f 3984#ifdef USE_5005THREADS
22c35a8c 3985EXT MGVTBL PL_vtbl_mutex;
4d1ff10f 3986#endif /* USE_5005THREADS */
f93b4edd 3987
22c35a8c
GS
3988EXT MGVTBL PL_vtbl_defelem;
3989EXT MGVTBL PL_vtbl_regexp;
3990EXT MGVTBL PL_vtbl_regdata;
3991EXT MGVTBL PL_vtbl_regdatum;
a0d0e21e 3992
36477c24 3993#ifdef USE_LOCALE_COLLATE
22c35a8c 3994EXT MGVTBL PL_vtbl_collxfrm;
bbce6d69 3995#endif
a0d0e21e 3996
22c35a8c
GS
3997EXT MGVTBL PL_vtbl_amagic;
3998EXT MGVTBL PL_vtbl_amagicelem;
a0d0e21e 3999
810b8aa5 4000EXT MGVTBL PL_vtbl_backref;
323eb6b5 4001EXT MGVTBL PL_vtbl_utf8;
810b8aa5 4002
bbce6d69 4003#endif /* !DOINIT */
85e6fe83 4004
f5284f61
IZ
4005enum {
4006 fallback_amg, abs_amg,
4007 bool__amg, nomethod_amg,
4008 string_amg, numer_amg,
4009 add_amg, add_ass_amg,
4010 subtr_amg, subtr_ass_amg,
4011 mult_amg, mult_ass_amg,
4012 div_amg, div_ass_amg,
4013 modulo_amg, modulo_ass_amg,
4014 pow_amg, pow_ass_amg,
4015 lshift_amg, lshift_ass_amg,
4016 rshift_amg, rshift_ass_amg,
4017 band_amg, band_ass_amg,
4018 bor_amg, bor_ass_amg,
4019 bxor_amg, bxor_ass_amg,
4020 lt_amg, le_amg,
4021 gt_amg, ge_amg,
4022 eq_amg, ne_amg,
4023 ncmp_amg, scmp_amg,
4024 slt_amg, sle_amg,
4025 sgt_amg, sge_amg,
4026 seq_amg, sne_amg,
4027 not_amg, compl_amg,
4028 inc_amg, dec_amg,
4029 atan2_amg, cos_amg,
4030 sin_amg, exp_amg,
4031 log_amg, sqrt_amg,
4032 repeat_amg, repeat_ass_amg,
4033 concat_amg, concat_ass_amg,
4034 copy_amg, neg_amg,
4035 to_sv_amg, to_av_amg,
4036 to_hv_amg, to_gv_amg,
d460ef45 4037 to_cv_amg, iter_amg,
f216259d
IZ
4038 int_amg, DESTROY_amg,
4039 max_amg_code
64a0062a 4040 /* Do not leave a trailing comma here. C9X allows it, C89 doesn't. */
f5284f61
IZ
4041};
4042
4043#define NofAMmeth max_amg_code
89ffc314 4044#define AMG_id2name(id) ((char*)PL_AMG_names[id]+1)
f5284f61 4045
a0d0e21e 4046#ifdef DOINIT
22c35a8c 4047EXTCONST char * PL_AMG_names[NofAMmeth] = {
89ffc314
IZ
4048 /* Names kept in the symbol table. fallback => "()", the rest has
4049 "(" prepended. The only other place in perl which knows about
4050 this convention is AMG_id2name (used for debugging output and
4051 'nomethod' only), the only other place which has it hardwired is
4052 overload.pm. */
4053 "()", "(abs", /* "fallback" should be the first. */
4054 "(bool", "(nomethod",
4055 "(\"\"", "(0+",
4056 "(+", "(+=",
4057 "(-", "(-=",
4058 "(*", "(*=",
4059 "(/", "(/=",
4060 "(%", "(%=",
4061 "(**", "(**=",
4062 "(<<", "(<<=",
4063 "(>>", "(>>=",
4064 "(&", "(&=",
4065 "(|", "(|=",
4066 "(^", "(^=",
4067 "(<", "(<=",
4068 "(>", "(>=",
4069 "(==", "(!=",
4070 "(<=>", "(cmp",
4071 "(lt", "(le",
4072 "(gt", "(ge",
4073 "(eq", "(ne",
4074 "(!", "(~",
4075 "(++", "(--",
4076 "(atan2", "(cos",
4077 "(sin", "(exp",
4078 "(log", "(sqrt",
4079 "(x", "(x=",
4080 "(.", "(.=",
4081 "(=", "(neg",
4082 "(${}", "(@{}",
4083 "(%{}", "(*{}",
4084 "(&{}", "(<>",
f216259d 4085 "(int", "DESTROY",
a0d0e21e
LW
4086};
4087#else
22c35a8c 4088EXTCONST char * PL_AMG_names[NofAMmeth];
a0d0e21e
LW
4089#endif /* def INITAMAGIC */
4090
73c4f7a1
GS
4091END_EXTERN_C
4092
a6006777 4093struct am_table {
eb160463 4094 U32 was_ok_sub;
a0d0e21e 4095 long was_ok_am;
a6006777 4096 U32 flags;
4097 CV* table[NofAMmeth];
a0d0e21e
LW
4098 long fallback;
4099};
a6006777 4100struct am_table_short {
eb160463 4101 U32 was_ok_sub;
a6006777 4102 long was_ok_am;
4103 U32 flags;
4104};
a0d0e21e 4105typedef struct am_table AMT;
a6006777 4106typedef struct am_table_short AMTS;
a0d0e21e
LW
4107
4108#define AMGfallNEVER 1
4109#define AMGfallNO 2
4110#define AMGfallYES 3
4111
a6006777 4112#define AMTf_AMAGIC 1
32251b26 4113#define AMTf_OVERLOADED 2
a6006777 4114#define AMT_AMAGIC(amt) ((amt)->flags & AMTf_AMAGIC)
4115#define AMT_AMAGIC_on(amt) ((amt)->flags |= AMTf_AMAGIC)
4116#define AMT_AMAGIC_off(amt) ((amt)->flags &= ~AMTf_AMAGIC)
32251b26
IZ
4117#define AMT_OVERLOADED(amt) ((amt)->flags & AMTf_OVERLOADED)
4118#define AMT_OVERLOADED_on(amt) ((amt)->flags |= AMTf_OVERLOADED)
4119#define AMT_OVERLOADED_off(amt) ((amt)->flags &= ~AMTf_OVERLOADED)
a6006777 4120
32251b26 4121#define StashHANDLER(stash,meth) gv_handler((stash),CAT2(meth,_amg))
c0315cdf
JH
4122
4123/*
4124 * some compilers like to redefine cos et alia as faster
4125 * (and less accurate?) versions called F_cos et cetera (Quidquid
4126 * latine dictum sit, altum viditur.) This trick collides with
4127 * the Perl overloading (amg). The following #defines fool both.
4128 */
4129
4130#ifdef _FASTMATH
4131# ifdef atan2
4132# define F_atan2_amg atan2_amg
4133# endif
4134# ifdef cos
4135# define F_cos_amg cos_amg
4136# endif
4137# ifdef exp
4138# define F_exp_amg exp_amg
4139# endif
4140# ifdef log
4141# define F_log_amg log_amg
4142# endif
4143# ifdef pow
4144# define F_pow_amg pow_amg
4145# endif
4146# ifdef sin
4147# define F_sin_amg sin_amg
4148# endif
4149# ifdef sqrt
4150# define F_sqrt_amg sqrt_amg
4151# endif
4152#endif /* _FASTMATH */
4153
83ee9e09
GS
4154#define PERLDB_ALL (PERLDBf_SUB | PERLDBf_LINE | \
4155 PERLDBf_NOOPT | PERLDBf_INTER | \
4156 PERLDBf_SUBLINE| PERLDBf_SINGLE| \
4157 PERLDBf_NAMEEVAL| PERLDBf_NAMEANON)
4158 /* No _NONAME, _GOTO */
4159#define PERLDBf_SUB 0x01 /* Debug sub enter/exit */
4160#define PERLDBf_LINE 0x02 /* Keep line # */
4161#define PERLDBf_NOOPT 0x04 /* Switch off optimizations */
4162#define PERLDBf_INTER 0x08 /* Preserve more data for
4163 later inspections */
4164#define PERLDBf_SUBLINE 0x10 /* Keep subr source lines */
4165#define PERLDBf_SINGLE 0x20 /* Start with single-step on */
4166#define PERLDBf_NONAME 0x40 /* For _SUB: no name of the subr */
4167#define PERLDBf_GOTO 0x80 /* Report goto: call DB::goto */
4168#define PERLDBf_NAMEEVAL 0x100 /* Informative names for evals */
4169#define PERLDBf_NAMEANON 0x200 /* Informative names for anon subs */
84902520 4170
3280af22
NIS
4171#define PERLDB_SUB (PL_perldb && (PL_perldb & PERLDBf_SUB))
4172#define PERLDB_LINE (PL_perldb && (PL_perldb & PERLDBf_LINE))
4173#define PERLDB_NOOPT (PL_perldb && (PL_perldb & PERLDBf_NOOPT))
4174#define PERLDB_INTER (PL_perldb && (PL_perldb & PERLDBf_INTER))
4175#define PERLDB_SUBLINE (PL_perldb && (PL_perldb & PERLDBf_SUBLINE))
4176#define PERLDB_SINGLE (PL_perldb && (PL_perldb & PERLDBf_SINGLE))
4177#define PERLDB_SUB_NN (PL_perldb && (PL_perldb & (PERLDBf_NONAME)))
4178#define PERLDB_GOTO (PL_perldb && (PL_perldb & PERLDBf_GOTO))
83ee9e09
GS
4179#define PERLDB_NAMEEVAL (PL_perldb && (PL_perldb & PERLDBf_NAMEEVAL))
4180#define PERLDB_NAMEANON (PL_perldb && (PL_perldb & PERLDBf_NAMEANON))
84902520 4181
bbce6d69 4182
36477c24 4183#ifdef USE_LOCALE_NUMERIC
bbce6d69 4184
36477c24 4185#define SET_NUMERIC_STANDARD() \
ff4fed7c 4186 set_numeric_standard();
36477c24 4187
4188#define SET_NUMERIC_LOCAL() \
ff4fed7c 4189 set_numeric_local();
bbce6d69 4190
2de3dbcc
JH
4191#define IN_LOCALE_RUNTIME (PL_curcop->op_private & HINT_LOCALE)
4192#define IN_LOCALE_COMPILETIME (PL_hints & HINT_LOCALE)
4193
4194#define IN_LOCALE \
ef7b71f0 4195 (IN_PERL_COMPILETIME ? IN_LOCALE_COMPILETIME : IN_LOCALE_RUNTIME)
2de3dbcc 4196
f93f4e46 4197#define STORE_NUMERIC_LOCAL_SET_STANDARD() \
2de3dbcc 4198 bool was_local = PL_numeric_local && IN_LOCALE; \
ff4fed7c 4199 if (was_local) SET_NUMERIC_STANDARD();
f93f4e46
CK
4200
4201#define STORE_NUMERIC_STANDARD_SET_LOCAL() \
2de3dbcc 4202 bool was_standard = PL_numeric_standard && IN_LOCALE; \
ff4fed7c 4203 if (was_standard) SET_NUMERIC_LOCAL();
f93f4e46
CK
4204
4205#define RESTORE_NUMERIC_LOCAL() \
4206 if (was_local) SET_NUMERIC_LOCAL();
4207
4208#define RESTORE_NUMERIC_STANDARD() \
4209 if (was_standard) SET_NUMERIC_STANDARD();
4210
5b877257 4211#define Atof my_atof
097ee67d 4212
36477c24 4213#else /* !USE_LOCALE_NUMERIC */
bbce6d69 4214
097ee67d
JH
4215#define SET_NUMERIC_STANDARD() /**/
4216#define SET_NUMERIC_LOCAL() /**/
5e931b6b 4217#define IS_NUMERIC_RADIX(a, b) (0)
f93f4e46
CK
4218#define STORE_NUMERIC_LOCAL_SET_STANDARD() /**/
4219#define STORE_NUMERIC_STANDARD_SET_LOCAL() /**/
097ee67d
JH
4220#define RESTORE_NUMERIC_LOCAL() /**/
4221#define RESTORE_NUMERIC_STANDARD() /**/
2cdc7fd1 4222#define Atof my_atof
ad3e0f90 4223#define IN_LOCALE_RUNTIME 0
bbce6d69 4224
36477c24 4225#endif /* !USE_LOCALE_NUMERIC */
a0d0e21e 4226
079290de 4227#if !defined(Strtol) && defined(USE_64_BIT_INT) && defined(IV_IS_QUAD) && QUADKIND == QUAD_IS_LONG_LONG
ec7b9793
JH
4228# ifdef __hpux
4229# define strtoll __strtoll /* secret handshake */
4230# endif
c623ac67
GS
4231# ifdef WIN64
4232# define strtoll _strtoi64 /* secret handshake */
4233# endif
079290de
GS
4234# if !defined(Strtol) && defined(HAS_STRTOLL)
4235# define Strtol strtoll
ad551343 4236# endif
28e5dec8
JH
4237# if !defined(Strtol) && defined(HAS_STRTOQ)
4238# define Strtol strtoq
4239# endif
ff935051 4240/* is there atoq() anywhere? */
15b99d39 4241#endif
079290de
GS
4242#if !defined(Strtol) && defined(HAS_STRTOL)
4243# define Strtol strtol
4244#endif
4245#ifndef Atol
4246/* It would be more fashionable to use Strtol() to define atol()
4247 * (as is done for Atoul(), see below) but for backward compatibility
4248 * we just assume atol(). */
76b882ba 4249# if defined(USE_64_BIT_INT) && defined(IV_IS_QUAD) && QUADKIND == QUAD_IS_LONG_LONG && defined(HAS_ATOLL)
c623ac67
GS
4250# ifdef WIN64
4251# define atoll _atoi64 /* secret handshake */
4252# endif
76b882ba
JH
4253# define Atol atoll
4254# else
4255# define Atol atol
4256# endif
cf2093f6
JH
4257#endif
4258
55eb892c 4259#if !defined(Strtoul) && defined(USE_64_BIT_INT) && defined(UV_IS_QUAD) && QUADKIND == QUAD_IS_LONG_LONG
ec7b9793
JH
4260# ifdef __hpux
4261# define strtoull __strtoull /* secret handshake */
4262# endif
c623ac67
GS
4263# ifdef WIN64
4264# define strtoull _strtoui64 /* secret handshake */
4265# endif
ad551343 4266# if !defined(Strtoul) && defined(HAS_STRTOULL)
388d3c03 4267# define Strtoul strtoull
15b99d39 4268# endif
079290de
GS
4269# if !defined(Strtoul) && defined(HAS_STRTOUQ)
4270# define Strtoul strtouq
4271# endif
76d49b1c 4272/* is there atouq() anywhere? */
ad551343 4273#endif
079290de
GS
4274#if !defined(Strtoul) && defined(HAS_STRTOUL)
4275# define Strtoul strtoul
cf2093f6 4276#endif
667e2a0c
JH
4277#if !defined(Strtoul) && defined(HAS_STRTOL) /* Last resort. */
4278# define Strtoul(s, e, b) strchr((s), '-') ? ULONG_MAX : (unsigned long)strtol((s), (e), (b))
4279#endif
079290de
GS
4280#ifndef Atoul
4281# define Atoul(s) Strtoul(s, (char **)NULL, 10)
55eb892c 4282#endif
cf2093f6 4283
760ac839 4284
06d86050
GS
4285/* if these never got defined, they need defaults */
4286#ifndef PERL_SET_CONTEXT
4287# define PERL_SET_CONTEXT(i) PERL_SET_INTERP(i)
4288#endif
4289
4290#ifndef PERL_GET_CONTEXT
4291# define PERL_GET_CONTEXT PERL_GET_INTERP
4292#endif
4293
4294#ifndef PERL_GET_THX
4295# define PERL_GET_THX ((void*)NULL)
4296#endif
4297
4298#ifndef PERL_SET_THX
4299# define PERL_SET_THX(t) NOOP
4300#endif
4301
a868473f
NIS
4302#ifndef PERL_SCRIPT_MODE
4303#define PERL_SCRIPT_MODE "r"
4304#endif
4305
fba3b22e 4306/*
da927450
JH
4307 * Some operating systems are stingy with stack allocation,
4308 * so perl may have to guard against stack overflow.
4309 */
4310#ifndef PERL_STACK_OVERFLOW_CHECK
c2af87cb 4311#define PERL_STACK_OVERFLOW_CHECK() NOOP
da927450
JH
4312#endif
4313
4314/*
4315 * Some nonpreemptive operating systems find it convenient to
4316 * check for asynchronous conditions after each op execution.
4317 * Keep this check simple, or it may slow down execution
4318 * massively.
4319 */
ce08f86c 4320
1d615522 4321#ifndef PERL_MICRO
5835a535
JH
4322# ifndef PERL_ASYNC_CHECK
4323# define PERL_ASYNC_CHECK() if (PL_sig_pending) despatch_signals()
4324# endif
ce08f86c
NIS
4325#endif
4326
da927450 4327#ifndef PERL_ASYNC_CHECK
1d615522 4328# define PERL_ASYNC_CHECK() NOOP
da927450
JH
4329#endif
4330
4331/*
4332 * On some operating systems, a memory allocation may succeed,
4333 * but put the process too close to the system's comfort limit.
4334 * In this case, PERL_ALLOC_CHECK frees the pointer and sets
4335 * it to NULL.
4336 */
4337#ifndef PERL_ALLOC_CHECK
c2af87cb 4338#define PERL_ALLOC_CHECK(p) NOOP
da927450
JH
4339#endif
4340
4341/*
fba3b22e
MB
4342 * nice_chunk and nice_chunk size need to be set
4343 * and queried under the protection of sv_mutex
4344 */
30ad99e7
MJD
4345#define offer_nice_chunk(chunk, chunk_size) STMT_START { \
4346 void *new_chunk; \
4347 U32 new_chunk_size; \
4348 LOCK_SV_MUTEX; \
4349 new_chunk = (void *)(chunk); \
4350 new_chunk_size = (chunk_size); \
4351 if (new_chunk_size > PL_nice_chunk_size) { \
4352 if (PL_nice_chunk) Safefree(PL_nice_chunk); \
4353 PL_nice_chunk = new_chunk; \
4354 PL_nice_chunk_size = new_chunk_size; \
4355 } else { \
4356 Safefree(chunk); \
4357 } \
4358 UNLOCK_SV_MUTEX; \
4359 } STMT_END
fba3b22e 4360
bd89102f
AD
4361#ifdef HAS_SEM
4362# include <sys/ipc.h>
4363# include <sys/sem.h>
4364# ifndef HAS_UNION_SEMUN /* Provide the union semun. */
4365 union semun {
dbba660d
TC
4366 int val;
4367 struct semid_ds *buf;
4368 unsigned short *array;
bd89102f
AD
4369 };
4370# endif
4371# ifdef USE_SEMCTL_SEMUN
dbba660d
TC
4372# ifdef IRIX32_SEMUN_BROKEN_BY_GCC
4373 union gccbug_semun {
4374 int val;
4375 struct semid_ds *buf;
4376 unsigned short *array;
4377 char __dummy[5];
4378 };
4379# define semun gccbug_semun
4380# endif
bd89102f
AD
4381# define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun)
4382# else
4383# ifdef USE_SEMCTL_SEMID_DS
e6f0bdd6
GS
4384# ifdef EXTRA_F_IN_SEMUN_BUF
4385# define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun.buff)
4386# else
4387# define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun.buf)
4388# endif
bd89102f
AD
4389# endif
4390# endif
bd89102f 4391#endif
49f531da 4392
89ca4ac7
JH
4393/*
4394 * Boilerplate macros for initializing and accessing interpreter-local
4395 * data from C. All statics in extensions should be reworked to use
4396 * this, if you want to make the extension thread-safe. See ext/re/re.xs
9f650e94 4397 * for an example of the use of these macros, and perlxs.pod for more.
89ca4ac7
JH
4398 *
4399 * Code that uses these macros is responsible for the following:
43a739c2
JH
4400 * 1. #define MY_CXT_KEY to a unique string, e.g.
4401 * "DynaLoader::_guts" XS_VERSION
89ca4ac7
JH
4402 * 2. Declare a typedef named my_cxt_t that is a structure that contains
4403 * all the data that needs to be interpreter-local.
4404 * 3. Use the START_MY_CXT macro after the declaration of my_cxt_t.
4405 * 4. Use the MY_CXT_INIT macro such that it is called exactly once
4406 * (typically put in the BOOT: section).
4407 * 5. Use the members of the my_cxt_t structure everywhere as
4408 * MY_CXT.member.
4409 * 6. Use the dMY_CXT macro (a declaration) in all the functions that
4410 * access MY_CXT.
4411 */
4412
fc958cd2 4413#if defined(PERL_IMPLICIT_CONTEXT)
89ca4ac7
JH
4414
4415/* This must appear in all extensions that define a my_cxt_t structure,
4416 * right after the definition (i.e. at file scope). The non-threads
4417 * case below uses it to declare the data as static. */
4418#define START_MY_CXT
4419
4420/* Fetches the SV that keeps the per-interpreter data. */
4421#define dMY_CXT_SV \
4422 SV *my_cxt_sv = *hv_fetch(PL_modglobal, MY_CXT_KEY, \
4423 sizeof(MY_CXT_KEY)-1, TRUE)
4424
4425/* This declaration should be used within all functions that use the
4426 * interpreter-local data. */
4427#define dMY_CXT \
4428 dMY_CXT_SV; \
ec0e15e0 4429 my_cxt_t *my_cxtp = INT2PTR(my_cxt_t*, SvUV(my_cxt_sv))
89ca4ac7
JH
4430
4431/* Creates and zeroes the per-interpreter data.
4432 * (We allocate my_cxtp in a Perl SV so that it will be released when
4433 * the interpreter goes away.) */
4434#define MY_CXT_INIT \
4435 dMY_CXT_SV; \
4436 /* newSV() allocates one more than needed */ \
4437 my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\
4438 Zero(my_cxtp, 1, my_cxt_t); \
ec0e15e0 4439 sv_setuv(my_cxt_sv, PTR2UV(my_cxtp))
89ca4ac7 4440
240fcc4a
JC
4441/* Clones the per-interpreter data. */
4442#define MY_CXT_CLONE \
4443 dMY_CXT_SV; \
4444 my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\
4445 Copy(INT2PTR(my_cxt_t*, SvUV(my_cxt_sv)), my_cxtp, 1, my_cxt_t);\
4446 sv_setuv(my_cxt_sv, PTR2UV(my_cxtp))
4447
89ca4ac7
JH
4448/* This macro must be used to access members of the my_cxt_t structure.
4449 * e.g. MYCXT.some_data */
4450#define MY_CXT (*my_cxtp)
4451
4452/* Judicious use of these macros can reduce the number of times dMY_CXT
4453 * is used. Use is similar to pTHX, aTHX etc. */
4454#define pMY_CXT my_cxt_t *my_cxtp
4455#define pMY_CXT_ pMY_CXT,
4456#define _pMY_CXT ,pMY_CXT
4457#define aMY_CXT my_cxtp
4458#define aMY_CXT_ aMY_CXT,
4459#define _aMY_CXT ,aMY_CXT
4460
4461#else /* USE_ITHREADS */
4462
4463#define START_MY_CXT static my_cxt_t my_cxt;
4464#define dMY_CXT_SV dNOOP
4465#define dMY_CXT dNOOP
4466#define MY_CXT_INIT NOOP
240fcc4a 4467#define MY_CXT_CLONE NOOP
89ca4ac7
JH
4468#define MY_CXT my_cxt
4469
4470#define pMY_CXT void
4471#define pMY_CXT_
4472#define _pMY_CXT
4473#define aMY_CXT
4474#define aMY_CXT_
4475#define _aMY_CXT
4476
4477#endif /* !defined(USE_ITHREADS) */
4478
9a34ef1d
GS
4479#ifdef I_FCNTL
4480# include <fcntl.h>
9a34ef1d
GS
4481#endif
4482
f0798ba3
OS
4483#ifdef __Lynx__
4484# include <fcntl.h>
4485#endif
4486
9a34ef1d
GS
4487#ifdef I_SYS_FILE
4488# include <sys/file.h>
4489#endif
4490
fa0a29af 4491#if defined(HAS_FLOCK) && !defined(HAS_FLOCK_PROTO)
2ef53570
JH
4492int flock(int fd, int op);
4493#endif
4494
fe52b3b7
GS
4495#ifndef O_RDONLY
4496/* Assume UNIX defaults */
4497# define O_RDONLY 0000
4498# define O_WRONLY 0001
4499# define O_RDWR 0002
4500# define O_CREAT 0100
4501#endif
9a34ef1d 4502
16fe6d59
GS
4503#ifndef O_BINARY
4504# define O_BINARY 0
4505#endif
4506
4507#ifndef O_TEXT
4508# define O_TEXT 0
4509#endif
4510
6ce75a77
JH
4511#if O_TEXT != O_BINARY
4512 /* If you have different O_TEXT and O_BINARY and you are a CLRF shop,
4513 * that is, you are somehow DOSish. */
6d061c82 4514# if defined(__BEOS__) || defined(__VOS__) || defined(__CYGWIN__)
a6e45062
JH
4515 /* BeOS has O_TEXT != O_BINARY but O_TEXT and O_BINARY have no effect;
4516 * BeOS is always UNIXoid (LF), not DOSish (CRLF). */
73250e76
JH
4517 /* VOS has O_TEXT != O_BINARY, and they have effect,
4518 * but VOS always uses LF, never CRLF. */
6ce75a77
JH
4519 /* If you have O_TEXT different from your O_BINARY but you still are
4520 * not a CRLF shop. */
35990314 4521# undef PERLIO_USING_CRLF
ec53fe4f
JH
4522# else
4523 /* If you really are DOSish. */
4524# define PERLIO_USING_CRLF 1
6ce75a77
JH
4525# endif
4526#endif
4527
104d25b7
JH
4528#ifdef IAMSUID
4529
4530#ifdef I_SYS_STATVFS
9f982a77
IG
4531# if defined(PERL_SCO) && !defined(_SVID3)
4532# define _SVID3
4533# endif
32b3cf08
JH
4534# include <sys/statvfs.h> /* for f?statvfs() */
4535#endif
4536#ifdef I_SYS_MOUNT
4537# include <sys/mount.h> /* for *BSD f?statfs() */
4538#endif
4539#ifdef I_MNTENT
4540# include <mntent.h> /* for getmntent() */
104d25b7 4541#endif
0545a864
JH
4542#ifdef I_SYS_STATFS
4543# include <sys/statfs.h> /* for some statfs() */
4544#endif
4545#ifdef I_SYS_VFS
8d9e1a19
GS
4546# ifdef __sgi
4547# define sv IRIX_sv /* kludge: IRIX has an sv of its own */
4548# endif
4549# include <sys/vfs.h> /* for some statfs() */
4550# ifdef __sgi
4551# undef IRIX_sv
4552# endif
0545a864
JH
4553#endif
4554#ifdef I_USTAT
4555# include <ustat.h> /* for ustat() */
4556#endif
4557
4558#if !defined(PERL_MOUNT_NOSUID) && defined(MOUNT_NOSUID)
4559# define PERL_MOUNT_NOSUID MOUNT_NOSUID
4560#endif
4561#if !defined(PERL_MOUNT_NOSUID) && defined(MNT_NOSUID)
4562# define PERL_MOUNT_NOSUID MNT_NOSUID
4563#endif
4564#if !defined(PERL_MOUNT_NOSUID) && defined(MS_NOSUID)
4565# define PERL_MOUNT_NOSUID MS_NOSUID
4566#endif
4567#if !defined(PERL_MOUNT_NOSUID) && defined(M_NOSUID)
4568# define PERL_MOUNT_NOSUID M_NOSUID
4569#endif
104d25b7 4570
23c73cf5
PS
4571#if !defined(PERL_MOUNT_NOEXEC) && defined(MOUNT_NOEXEC)
4572# define PERL_MOUNT_NOEXEC MOUNT_NOEXEC
4573#endif
4574#if !defined(PERL_MOUNT_NOEXEC) && defined(MNT_NOEXEC)
4575# define PERL_MOUNT_NOEXEC MNT_NOEXEC
4576#endif
4577#if !defined(PERL_MOUNT_NOEXEC) && defined(MS_NOEXEC)
4578# define PERL_MOUNT_NOEXEC MS_NOEXEC
4579#endif
4580#if !defined(PERL_MOUNT_NOEXEC) && defined(M_NOEXEC)
4581# define PERL_MOUNT_NOEXEC M_NOEXEC
4582#endif
4583
104d25b7
JH
4584#endif /* IAMSUID */
4585
4bc88a62
PS
4586#ifdef I_LIBUTIL
4587# include <libutil.h> /* setproctitle() in some FreeBSDs */
4588#endif
4589
b4748376
NIS
4590#ifndef EXEC_ARGV_CAST
4591#define EXEC_ARGV_CAST(x) x
4592#endif
4593
dd5dc04f
JH
4594#define IS_NUMBER_IN_UV 0x01 /* number within UV range (maybe not
4595 int). value returned in pointed-
4596 to UV */
4597#define IS_NUMBER_GREATER_THAN_UV_MAX 0x02 /* pointed to UV undefined */
4598#define IS_NUMBER_NOT_INT 0x04 /* saw . or E notation */
4599#define IS_NUMBER_NEG 0x08 /* leading minus sign */
4600#define IS_NUMBER_INFINITY 0x10 /* this is big */
aa8b85de 4601#define IS_NUMBER_NAN 0x20 /* this is not */
dd5dc04f
JH
4602
4603#define GROK_NUMERIC_RADIX(sp, send) grok_numeric_radix(sp, send)
4604
53305cf1
NC
4605/* Input flags: */
4606#define PERL_SCAN_ALLOW_UNDERSCORES 0x01 /* grok_??? accept _ in numbers */
a4c04bdc 4607#define PERL_SCAN_DISALLOW_PREFIX 0x02 /* grok_??? reject 0x in hex etc */
a77f7f8b 4608#define PERL_SCAN_SILENT_ILLDIGIT 0x04 /* grok_??? not warn about illegal digits */
53305cf1
NC
4609/* Output flags: */
4610#define PERL_SCAN_GREATER_THAN_UV_MAX 0x02 /* should this merge with above? */
4611
2c4f7f0e
DM
4612/* to let user control profiling */
4613#ifdef PERL_GPROF_CONTROL
4614extern void moncontrol(int);
4615#define PERL_GPROF_MONCONTROL(x) moncontrol(x)
4616#else
4617#define PERL_GPROF_MONCONTROL(x)
4618#endif
4619
ae0e3d3b
JH
4620#ifdef UNDER_CE
4621#include "wince.h"
4622#endif
4623
4624/* ISO 6429 NEL - C1 control NExt Line */
4625/* See http://www.unicode.org/unicode/reports/tr13/ */
4626#ifdef EBCDIC /* In EBCDIC NEL is just an alias for LF */
4627# if '^' == 95 /* CP 1047: MVS OpenEdition - OS/390 - z/OS */
4628# define NEXT_LINE_CHAR 0x15
4629# else /* CDRA */
4630# define NEXT_LINE_CHAR 0x25
4631# endif
4632#else
4633# define NEXT_LINE_CHAR 0x85
4634#endif
4635
4636/* The UTF-8 bytes of the Unicode LS and PS, U+2028 and U+2029 */
4637#define UNICODE_LINE_SEPA_0 0xE2
4638#define UNICODE_LINE_SEPA_1 0x80
4639#define UNICODE_LINE_SEPA_2 0xA8
4640#define UNICODE_PARA_SEPA_0 0xE2
4641#define UNICODE_PARA_SEPA_1 0x80
4642#define UNICODE_PARA_SEPA_2 0xA9
4643
43af864e
JH
4644#ifndef PIPESOCK_MODE
4645# define PIPESOCK_MODE
4646#endif
4647
5a560d3a
IZ
4648#ifndef SOCKET_OPEN_MODE
4649# define SOCKET_OPEN_MODE PIPESOCK_MODE
4650#endif
4651
4652#ifndef PIPE_OPEN_MODE
4653# define PIPE_OPEN_MODE PIPESOCK_MODE
4654#endif
4655
323eb6b5
JH
4656#define PERL_MAGIC_UTF8_CACHESIZE 2
4657
f8bb70a6
JH
4658#define PERL_UNICODE_STDIN_FLAG 0x0001
4659#define PERL_UNICODE_STDOUT_FLAG 0x0002
4660#define PERL_UNICODE_STDERR_FLAG 0x0004
f8bb70a6
JH
4661#define PERL_UNICODE_IN_FLAG 0x0008
4662#define PERL_UNICODE_OUT_FLAG 0x0010
d2aaa77e 4663#define PERL_UNICODE_ARGV_FLAG 0x0020
f8bb70a6
JH
4664#define PERL_UNICODE_LOCALE_FLAG 0x0040
4665#define PERL_UNICODE_WIDESYSCALLS_FLAG 0x0080 /* for Sarathy */
4666
d2aaa77e
JH
4667#define PERL_UNICODE_STD_FLAG \
4668 (PERL_UNICODE_STDIN_FLAG | \
4669 PERL_UNICODE_STDOUT_FLAG | \
4670 PERL_UNICODE_STDERR_FLAG)
4671
4672#define PERL_UNICODE_INOUT_FLAG \
4673 (PERL_UNICODE_IN_FLAG | \
4674 PERL_UNICODE_OUT_FLAG)
4675
4676#define PERL_UNICODE_DEFAULT_FLAGS \
f8bb70a6
JH
4677 (PERL_UNICODE_STD_FLAG | \
4678 PERL_UNICODE_INOUT_FLAG | \
4679 PERL_UNICODE_LOCALE_FLAG)
4680
4681#define PERL_UNICODE_ALL_FLAGS 0x00ff
4682
4683#define PERL_UNICODE_STDIN 'I'
4684#define PERL_UNICODE_STDOUT 'O'
4685#define PERL_UNICODE_STDERR 'E'
4686#define PERL_UNICODE_STD 'S'
4687#define PERL_UNICODE_IN 'i'
4688#define PERL_UNICODE_OUT 'o'
4689#define PERL_UNICODE_INOUT 'D'
4690#define PERL_UNICODE_ARGV 'A'
4691#define PERL_UNICODE_LOCALE 'L'
4692#define PERL_UNICODE_WIDESYSCALLS 'W'
4693
5835a535
JH
4694#define PERL_SIGNALS_UNSAFE_FLAG 0x0001
4695
4696/* From sigaction(2) (FreeBSD man page):
4697 * | Signal routines normally execute with the signal that
4698 * | caused their invocation blocked, but other signals may
4699 * | yet occur.
4700 * Emulation of this behavior (from within Perl) is enabled
4701 * by defining PERL_BLOCK_SIGNALS.
4702 */
4703#define PERL_BLOCK_SIGNALS
4704
4705#if defined(HAS_SIGPROCMASK) && defined(PERL_BLOCK_SIGNALS)
4706# define PERL_BLOCKSIG_ADD(set,sig) \
4707 sigset_t set; sigemptyset(&(set)); sigaddset(&(set), sig)
4708# define PERL_BLOCKSIG_BLOCK(set) \
4709 sigprocmask(SIG_BLOCK, &(set), NULL)
4710# define PERL_BLOCKSIG_UNBLOCK(set) \
4711 sigprocmask(SIG_UNBLOCK, &(set), NULL)
4712#endif /* HAS_SIGPROCMASK && PERL_BLOCK_SIGNALS */
4713
4714/* How about the old style of sigblock()? */
4715
4716#ifndef PERL_BLOCKSIG_ADD
4717# define PERL_BLOCKSIG_ADD(set, sig) NOOP
4718#endif
4719#ifndef PERL_BLOCKSIG_BLOCK
4720# define PERL_BLOCKSIG_BLOCK(set) NOOP
4721#endif
f0499ddf 4722#ifndef PERL_BLOCKSIG_UNBLOCK
5835a535
JH
4723# define PERL_BLOCKSIG_UNBLOCK(set) NOOP
4724#endif
4725
6b6e5432 4726/* Use instead of abs() since abs() forces its argument to be an int,
d34f9d2e 4727 * but also beware since this evaluates its argument twice, so no x++. */
6b6e5432
JH
4728#define PERL_ABS(x) ((x) < 0 ? -(x) : (x))
4729
4d8076ea 4730/* and finally... */
cceca5ed 4731#define PERL_PATCHLEVEL_H_IMPLICIT
4d8076ea 4732#include "patchlevel.h"
cceca5ed 4733#undef PERL_PATCHLEVEL_H_IMPLICIT
4d8076ea 4734
43999f95 4735/* Mention
d460ef45 4736
43999f95 4737 NV_PRESERVES_UV
fe749a9f 4738
fe749a9f
JH
4739 HAS_MKSTEMP
4740 HAS_MKSTEMPS
4741 HAS_MKDTEMP
4742
49dabb45
JH
4743 HAS_GETCWD
4744
d59b5429 4745 HAS_MMAP
fe749a9f
JH
4746 HAS_MPROTECT
4747 HAS_MSYNC
1e8c3fde 4748 HAS_MADVISE
fe749a9f
JH
4749 HAS_MUNMAP
4750 I_SYSMMAN
4751 Mmap_t
4752
6b4667fc
A
4753 NVef
4754 NVff
4755 NVgf
4756
4e0554ec 4757 HAS_UALARM
2d736872 4758 HAS_USLEEP
4e0554ec
JH
4759
4760 HAS_SETITIMER
4761 HAS_GETITIMER
4762
4763 HAS_SENDMSG
4764 HAS_RECVMSG
4765 HAS_READV
4766 HAS_WRITEV
4767 I_SYSUIO
4768 HAS_STRUCT_MSGHDR
4769 HAS_STRUCT_CMSGHDR
4770
2765b840 4771 HAS_NL_LANGINFO
0a7020c9 4772
ae0e3d3b 4773 HAS_DIRFD
2765b840 4774
43999f95
JH
4775 so that Configure picks them up. */
4776
c8743bff
NC
4777/* Source code compatibility cruft:
4778 PERL_XS_APIVERSION is not used, and has been superseded by inc_version_list
4779 It and PERL_PM_APIVERSION are retained for source compatibility in the
4780 5.8.x maintenance branch.
4781 */
4782
4783#define PERL_XS_APIVERSION "5.8.3"
4784#define PERL_PM_APIVERSION "5.005"
4785
85e6fe83 4786#endif /* Include guard */
ae0e3d3b 4787