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