This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
s/usethreads/use5005threads/g
[perl5.git] / perl.h
CommitLineData
a0d0e21e 1/* perl.h
a687059c 2 *
9607fc9c 3 * Copyright (c) 1987-1997, Larry Wall
a687059c 4 *
352d5a3a
LW
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
8d063cd8 7 *
8d063cd8 8 */
85e6fe83
LW
9#ifndef H_PERL
10#define H_PERL 1
8d063cd8 11
760ac839
LW
12#ifdef PERL_FOR_X2P
13/*
14 * This file is being used for x2p stuff.
15 * Above symbol is defined via -D in 'x2p/Makefile.SH'
16 * Decouple x2p stuff from some of perls more extreme eccentricities.
17 */
55497cff 18#undef MULTIPLICITY
760ac839
LW
19#undef USE_STDIO
20#define USE_STDIO
21#endif /* PERL_FOR_X2P */
22
0cb96387
GS
23#define VOIDUSED 1
24#include "config.h"
25
aaacdc8b
GS
26#if defined(USE_ITHREADS) && defined(USE_5005THREADS)
27# include "error: USE_ITHREADS and USE_5005THREADS are incompatible"
28#endif
29
30/* XXX This next guard can disappear if the sources are revised
31 to use USE_5005THREADS throughout. -- A.D 1/6/2000
32*/
33#if defined(USE_ITHREADS) && defined(USE_THREADS)
34# include "error: USE_ITHREADS and USE_THREADS are incompatible"
35#endif
36
2c2d71f5
JH
37/* See L<perlguts/"The Perl API"> for detailed notes on
38 * PERL_IMPLICIT_CONTEXT and PERL_IMPLICIT_SYS */
39
0cb96387 40#ifdef USE_THREADS
c5be433b
GS
41# ifndef PERL_IMPLICIT_CONTEXT
42# define PERL_IMPLICIT_CONTEXT
43# endif
c5be433b
GS
44#endif
45
c5be433b
GS
46#if defined(MULTIPLICITY)
47# ifndef PERL_IMPLICIT_CONTEXT
48# define PERL_IMPLICIT_CONTEXT
49# endif
c5be433b
GS
50#endif
51
52#ifdef PERL_CAPI
53# undef PERL_OBJECT
54# ifndef PERL_IMPLICIT_CONTEXT
55# define PERL_IMPLICIT_CONTEXT
56# endif
57# ifndef PERL_IMPLICIT_SYS
58# define PERL_IMPLICIT_SYS
59# endif
60#endif
61
62#ifdef PERL_OBJECT
63# ifndef PERL_IMPLICIT_CONTEXT
64# define PERL_IMPLICIT_CONTEXT
65# endif
66# ifndef PERL_IMPLICIT_SYS
67# define PERL_IMPLICIT_SYS
68# endif
0cb96387
GS
69#endif
70
76e3520e 71#ifdef PERL_OBJECT
3dfd1da1
GS
72
73/* PERL_OBJECT explained - DickH and DougL @ ActiveState.com
74
75Defining PERL_OBJECT turns on creation of a C++ object that
76contains all writable core perl global variables and functions.
77Stated another way, all necessary global variables and functions
78are members of a big C++ object. This object's class is CPerlObj.
79This allows a Perl Host to have multiple, independent perl
80interpreters in the same process space. This is very important on
81Win32 systems as the overhead of process creation is quite high --
82this could be even higher than the script compile and execute time
83for small scripts.
84
85The perl executable implementation on Win32 is composed of perl.exe
86(the Perl Host) and perlX.dll. (the Perl Core). This allows the
87same Perl Core to easily be embedded in other applications that use
88the perl interpreter.
89
90+-----------+
91| Perl Host |
92+-----------+
93 ^
32e30700
GS
94 |
95 v
3dfd1da1
GS
96+-----------+ +-----------+
97| Perl Core |<->| Extension |
98+-----------+ +-----------+ ...
99
100Defining PERL_OBJECT has the following effects:
101
102PERL CORE
1031. CPerlObj is defined (this is the PERL_OBJECT)
1042. all static functions that needed to access either global
105variables or functions needed are made member functions
1063. all writable static variables are made member variables
1074. all global variables and functions are defined as:
22c35a8c 108 #define var CPerlObj::PL_var
3dfd1da1 109 #define func CPerlObj::Perl_func
22c35a8c 110 * these are in embed.h
3dfd1da1
GS
111This necessitated renaming some local variables and functions that
112had the same name as a global variable or function. This was
113probably a _good_ thing anyway.
114
115
116EXTENSIONS
1171. Access to global variables and perl functions is through a
118pointer to the PERL_OBJECT. This pointer type is CPerlObj*. This is
119made transparent to extension developers by the following macros:
22c35a8c 120 #define var pPerl->PL_var
3dfd1da1 121 #define func pPerl->Perl_func
6de196ee 122 * these are done in objXSUB.h
3dfd1da1
GS
123This requires that the extension be compiled as C++, which means
124that the code must be ANSI C and not K&R C. For K&R extensions,
125please see the C API notes located in Win32/GenCAPI.pl. This script
6de196ee 126creates a perlCAPI.lib that provides a K & R compatible C interface
3dfd1da1
GS
127to the PERL_OBJECT.
1282. Local variables and functions cannot have the same name as perl's
129variables or functions since the macros will redefine these. Look for
130this if you get some strange error message and it does not look like
131the code that you had written. This often happens with variables that
132are local to a function.
133
134PERL HOST
1351. The perl host is linked with perlX.lib to get perl_alloc. This
136function will return a pointer to CPerlObj (the PERL_OBJECT). It
0f4eea8f
DL
137takes pointers to the various PerlXXX_YYY interfaces (see iperlsys.h
138for more information on this).
3dfd1da1
GS
1392. The perl host calls the same functions as normally would be
140called in setting up and running a perl script, except that the
141functions are now member functions of the PERL_OBJECT.
142
143*/
144
145
76e3520e
GS
146class CPerlObj;
147
148#define STATIC
c5be433b 149#define CPERLscope(x) CPerlObj::x
7766f137 150#define CALL_FPTR(fptr) (aTHXo->*fptr)
c5be433b
GS
151
152#define pTHXo CPerlObj *pPerl
153#define pTHXo_ pTHXo,
c5be433b
GS
154#define aTHXo this
155#define aTHXo_ this,
0cb96387
GS
156#define PERL_OBJECT_THIS aTHXo
157#define PERL_OBJECT_THIS_ aTHXo_
54aff467
GS
158#define dTHXoa(a) pTHXo = a
159#define dTHXo dTHXoa(PERL_GET_THX)
0cb96387
GS
160
161#define pTHXx void
162#define pTHXx_
0cb96387
GS
163#define aTHXx
164#define aTHXx_
0cb96387 165
76e3520e
GS
166#else /* !PERL_OBJECT */
167
c5be433b
GS
168#ifdef PERL_IMPLICIT_CONTEXT
169# ifdef USE_THREADS
170struct perl_thread;
171# define pTHX register struct perl_thread *thr
172# define aTHX thr
c5be433b
GS
173# define dTHR dNOOP
174# else
f63b9778
GS
175# ifndef MULTIPLICITY
176# define MULTIPLICITY
177# endif
c5be433b
GS
178# define pTHX register PerlInterpreter *my_perl
179# define aTHX my_perl
c5be433b 180# endif
54aff467
GS
181# define dTHXa(a) pTHX = a
182# define dTHX dTHXa(PERL_GET_THX)
c5be433b 183# define pTHX_ pTHX,
c5be433b 184# define aTHX_ aTHX,
c5be433b
GS
185#endif
186
76e3520e
GS
187#define STATIC static
188#define CPERLscope(x) x
565764a8 189#define CPERLarg void
76e3520e 190#define CPERLarg_
e3b8966e 191#define _CPERLarg
1d583055
GS
192#define PERL_OBJECT_THIS
193#define _PERL_OBJECT_THIS
194#define PERL_OBJECT_THIS_
312caa8e 195#define CALL_FPTR(fptr) (*fptr)
76e3520e
GS
196
197#endif /* PERL_OBJECT */
198
312caa8e
CS
199#define CALLRUNOPS CALL_FPTR(PL_runops)
200#define CALLREGCOMP CALL_FPTR(PL_regcompp)
201#define CALLREGEXEC CALL_FPTR(PL_regexecp)
f722798b
IZ
202#define CALLREG_INTUIT_START CALL_FPTR(PL_regint_start)
203#define CALLREG_INTUIT_STRING CALL_FPTR(PL_regint_string)
204#define CALLREGFREE CALL_FPTR(PL_regfree)
312caa8e
CS
205#define CALLPROTECT CALL_FPTR(PL_protect)
206
0cb96387
GS
207#define NOOP (void)0
208#define dNOOP extern int Perl___notused
71be2cbc 209
0cb96387
GS
210#ifndef pTHX
211# define pTHX void
212# define pTHX_
0cb96387
GS
213# define aTHX
214# define aTHX_
0cb96387
GS
215# define dTHXa(a) dNOOP
216# define dTHX dNOOP
217#endif
218
219#ifndef pTHXo
220# define pTHXo pTHX
221# define pTHXo_ pTHX_
0cb96387
GS
222# define aTHXo aTHX
223# define aTHXo_ aTHX_
c5be433b 224# define dTHXo dTHX
0cb96387
GS
225#endif
226
227#ifndef pTHXx
228# define pTHXx register PerlInterpreter *my_perl
229# define pTHXx_ pTHXx,
0cb96387
GS
230# define aTHXx my_perl
231# define aTHXx_ aTHXx,
c5be433b 232# define dTHXx dTHX
22c35a8c 233#endif
71be2cbc 234
326b05e3
GS
235#undef START_EXTERN_C
236#undef END_EXTERN_C
237#undef EXTERN_C
32f822de
GS
238#ifdef __cplusplus
239# define START_EXTERN_C extern "C" {
240# define END_EXTERN_C }
241# define EXTERN_C extern "C"
242#else
243# define START_EXTERN_C
244# define END_EXTERN_C
73c4f7a1 245# define EXTERN_C extern
32f822de
GS
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
728e2803
PP
256/*
257 * STMT_START { statements; } STMT_END;
258 * can be used as a single statement, as in
259 * if (x) STMT_START { ... } STMT_END; else ...
260 *
261 * Trying to select a version that gives no warnings...
262 */
263#if !(defined(STMT_START) && defined(STMT_END))
169d69b2 264# if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__cplusplus)
728e2803
PP
265# define STMT_START (void)( /* gcc supports ``({ STATEMENTS; })'' */
266# define STMT_END )
267# else
268 /* Now which other defined()s do we need here ??? */
269# if (VOIDFLAGS) && (defined(sun) || defined(__sun__))
270# define STMT_START if (1)
271# define STMT_END else (void)0
272# else
273# define STMT_START do
274# define STMT_END while (0)
275# endif
276# endif
277#endif
278
0cb96387 279#define WITH_THX(s) STMT_START { dTHX; s; } STMT_END
61bb5906 280#define WITH_THR(s) STMT_START { dTHR; s; } STMT_END
ea0efc06 281
55497cff
PP
282/*
283 * SOFT_CAST can be used for args to prototyped functions to retain some
284 * type checking; it only casts if the compiler does not know prototypes.
285 */
286#if defined(CAN_PROTOTYPE) && defined(DEBUGGING_COMPILE)
287#define SOFT_CAST(type)
288#else
289#define SOFT_CAST(type) (type)
290#endif
79072805 291
6ee623d5 292#ifndef BYTEORDER /* Should never happen -- byteorder is in config.h */
79072805
LW
293# define BYTEORDER 0x1234
294#endif
295
296/* Overall memory policy? */
297#ifndef CONSERVATIVE
298# define LIBERAL 1
299#endif
300
8ada0baa
JH
301#if 'A' == 65 && 'I' == 73 && 'J' == 74 && 'Z' == 90
302#define ASCIIish
303#else
304#undef ASCIIish
305#endif
306
79072805
LW
307/*
308 * The following contortions are brought to you on behalf of all the
309 * standards, semi-standards, de facto standards, not-so-de-facto standards
310 * of the world, as well as all the other botches anyone ever thought of.
311 * The basic theory is that if we work hard enough here, the rest of the
312 * code can be a lot prettier. Well, so much for theory. Sorry, Henry...
313 */
ac58e20f 314
ee0007ab 315/* define this once if either system, instead of cluttering up the src */
1cab015a 316#if defined(MSDOS) || defined(atarist) || defined(WIN32)
ee0007ab
LW
317#define DOSISH 1
318#endif
319
4d2c4e07 320#if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus) || defined( EPOC)
352d5a3a
LW
321# define STANDARD_C 1
322#endif
323
8b0db79d 324#if defined(__cplusplus) || defined(WIN32) || defined(__sgi) || defined(OS2) || defined(__DGUX) || defined( EPOC) || defined(__QNX__)
68dc0745
PP
325# define DONT_DECLARE_STD 1
326#endif
327
352d5a3a 328#if defined(HASVOLATILE) || defined(STANDARD_C)
79072805
LW
329# ifdef __cplusplus
330# define VOL // to temporarily suppress warnings
331# else
332# define VOL volatile
333# endif
663a0e37 334#else
79072805 335# define VOL
663a0e37
LW
336#endif
337
3280af22
NIS
338#define TAINT (PL_tainted = TRUE)
339#define TAINT_NOT (PL_tainted = FALSE)
340#define TAINT_IF(c) if (c) { PL_tainted = TRUE; }
341#define TAINT_ENV() if (PL_tainting) { taint_env(); }
22c35a8c 342#define TAINT_PROPER(s) if (PL_tainting) { taint_proper(Nullch, s); }
a687059c 343
a6e633de
PP
344/* XXX All process group stuff is handled in pp_sys.c. Should these
345 defines move there? If so, I could simplify this a lot. --AD 9/96.
346*/
347/* Process group stuff changed from traditional BSD to POSIX.
348 perlfunc.pod documents the traditional BSD-style syntax, so we'll
349 try to preserve that, if possible.
350*/
351#ifdef HAS_SETPGID
352# define BSD_SETPGRP(pid, pgrp) setpgid((pid), (pgrp))
c07a80fd 353#else
a6e633de
PP
354# if defined(HAS_SETPGRP) && defined(USE_BSD_SETPGRP)
355# define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp))
356# else
357# ifdef HAS_SETPGRP2 /* DG/UX */
358# define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp))
359# endif
360# endif
361#endif
362#if defined(BSD_SETPGRP) && !defined(HAS_SETPGRP)
363# define HAS_SETPGRP /* Well, effectively it does . . . */
364#endif
365
366/* getpgid isn't POSIX, but at least Solaris and Linux have it, and it makes
367 our life easier :-) so we'll try it.
368*/
369#ifdef HAS_GETPGID
370# define BSD_GETPGRP(pid) getpgid((pid))
371#else
372# if defined(HAS_GETPGRP) && defined(USE_BSD_GETPGRP)
373# define BSD_GETPGRP(pid) getpgrp((pid))
374# else
375# ifdef HAS_GETPGRP2 /* DG/UX */
376# define BSD_GETPGRP(pid) getpgrp2((pid))
377# endif
378# endif
379#endif
380#if defined(BSD_GETPGRP) && !defined(HAS_GETPGRP)
381# define HAS_GETPGRP /* Well, effectively it does . . . */
382#endif
383
384/* These are not exact synonyms, since setpgrp() and getpgrp() may
385 have different behaviors, but perl.h used to define USE_BSDPGRP
386 (prior to 5.003_05) so some extension might depend on it.
387*/
388#if defined(USE_BSD_SETPGRP) || defined(USE_BSD_GETPGRP)
389# ifndef USE_BSDPGRP
390# define USE_BSDPGRP
391# endif
663a0e37
LW
392#endif
393
8ac5a1fe
MH
394/* HP-UX 10.X CMA (Common Multithreaded Architecure) insists that
395 pthread.h must be included before all other header files.
396*/
1feb2720
GS
397#if (defined(USE_THREADS) || defined(USE_ITHREADS)) \
398 && defined(PTHREAD_H_FIRST) && defined(I_PTHREAD)
8ac5a1fe
MH
399# include <pthread.h>
400#endif
401
760ac839
LW
402#ifndef _TYPES_ /* If types.h defines this it's easy. */
403# ifndef major /* Does everyone's types.h define this? */
404# include <sys/types.h>
c07a80fd 405# endif
663a0e37
LW
406#endif
407
760ac839
LW
408#ifdef __cplusplus
409# ifndef I_STDARG
410# define I_STDARG 1
411# endif
412#endif
413
414#ifdef I_STDARG
415# include <stdarg.h>
416#else
417# ifdef I_VARARGS
418# include <varargs.h>
419# endif
420#endif
421
4633a7c4 422#ifdef USE_NEXT_CTYPE
0c30d9ec 423
092bebab
JH
424#if NX_CURRENT_COMPILER_RELEASE >= 500
425# include <bsd/ctypes.h>
426#else
427# if NX_CURRENT_COMPILER_RELEASE >= 400
428# include <objc/NXCType.h>
429# else /* NX_CURRENT_COMPILER_RELEASE < 400 */
430# include <appkit/NXCType.h>
431# endif /* NX_CURRENT_COMPILER_RELEASE >= 400 */
432#endif /* NX_CURRENT_COMPILER_RELEASE >= 500 */
0c30d9ec
PP
433
434#else /* !USE_NEXT_CTYPE */
fe14fcc3 435#include <ctype.h>
0c30d9ec 436#endif /* USE_NEXT_CTYPE */
a0d0e21e
LW
437
438#ifdef METHOD /* Defined by OSF/1 v3.0 by ctype.h */
439#undef METHOD
a0d0e21e
LW
440#endif
441
4633a7c4 442#ifdef I_LOCALE
36477c24 443# include <locale.h>
4633a7c4
LW
444#endif
445
36477c24
PP
446#if !defined(NO_LOCALE) && defined(HAS_SETLOCALE)
447# define USE_LOCALE
448# if !defined(NO_LOCALE_COLLATE) && defined(LC_COLLATE) \
449 && defined(HAS_STRXFRM)
450# define USE_LOCALE_COLLATE
451# endif
452# if !defined(NO_LOCALE_CTYPE) && defined(LC_CTYPE)
453# define USE_LOCALE_CTYPE
454# endif
455# if !defined(NO_LOCALE_NUMERIC) && defined(LC_NUMERIC)
456# define USE_LOCALE_NUMERIC
457# endif
458#endif /* !NO_LOCALE && HAS_SETLOCALE */
a0d0e21e 459
fe14fcc3 460#include <setjmp.h>
79072805 461
a0d0e21e 462#ifdef I_SYS_PARAM
79072805
LW
463# ifdef PARAM_NEEDS_TYPES
464# include <sys/types.h>
465# endif
466# include <sys/param.h>
352d5a3a 467#endif
79072805
LW
468
469
470/* Use all the "standard" definitions? */
a0d0e21e 471#if defined(STANDARD_C) && defined(I_STDLIB)
79072805 472# include <stdlib.h>
ff68c719 473#endif
03a14243 474
d18c6117 475#if !defined(PERL_FOR_X2P) && !defined(WIN32)
cea2e8a9
GS
476# include "embed.h"
477#endif
478
c31fac66
GS
479#define MEM_SIZE Size_t
480
51371543
GS
481#if defined(STANDARD_C) && defined(I_STDDEF)
482# include <stddef.h>
483# define STRUCT_OFFSET(s,m) offsetof(s,m)
484#else
485# define STRUCT_OFFSET(s,m) (Size_t)(&(((s *)0)->m))
486#endif
487
488#if defined(I_STRING) || defined(__cplusplus)
489# include <string.h>
490#else
491# include <strings.h>
492#endif
493
55497cff
PP
494/* This comes after <stdlib.h> so we don't try to change the standard
495 * library prototypes; we'll use our own in proto.h instead. */
03a14243 496
4633a7c4 497#ifdef MYMALLOC
86058a2d 498# ifdef PERL_POLLUTE_MALLOC
ee13e175 499# ifndef PERL_EXTMALLOC_DEF
86058a2d
GS
500# define Perl_malloc malloc
501# define Perl_calloc calloc
502# define Perl_realloc realloc
503# define Perl_mfree free
ee13e175 504# endif
86058a2d
GS
505# else
506# define EMBEDMYMALLOC /* for compatibility */
507# endif
20ce7b12
GS
508Malloc_t Perl_malloc (MEM_SIZE nbytes);
509Malloc_t Perl_calloc (MEM_SIZE elements, MEM_SIZE size);
510Malloc_t Perl_realloc (Malloc_t where, MEM_SIZE nbytes);
86058a2d
GS
511/* 'mfree' rather than 'free', since there is already a 'perl_free'
512 * that causes clashes with case-insensitive linkers */
20ce7b12 513Free_t Perl_mfree (Malloc_t where);
55497cff 514
651b9576
GS
515# define safemalloc Perl_malloc
516# define safecalloc Perl_calloc
517# define saferealloc Perl_realloc
518# define safefree Perl_mfree
f2517201
GS
519#else /* MYMALLOC */
520# define safemalloc safesysmalloc
521# define safecalloc safesyscalloc
522# define saferealloc safesysrealloc
523# define safefree safesysfree
55497cff 524#endif /* MYMALLOC */
4633a7c4 525
a0d0e21e
LW
526#if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
527#define strchr index
528#define strrchr rindex
529#endif
530
16d20bd9
AD
531#ifdef I_MEMORY
532# include <memory.h>
533#endif
534
fe14fcc3 535#ifdef HAS_MEMCPY
85e6fe83 536# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
fe14fcc3 537# ifndef memcpy
20ce7b12 538 extern char * memcpy (char*, char*, int);
ee0007ab
LW
539# endif
540# endif
541#else
542# ifndef memcpy
543# ifdef HAS_BCOPY
544# define memcpy(d,s,l) bcopy(s,d,l)
545# else
546# define memcpy(d,s,l) my_bcopy(s,d,l)
547# endif
548# endif
549#endif /* HAS_MEMCPY */
fe14fcc3 550
ee0007ab 551#ifdef HAS_MEMSET
85e6fe83 552# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
ee0007ab 553# ifndef memset
20ce7b12 554 extern char *memset (char*, int, int);
ee0007ab
LW
555# endif
556# endif
ee0007ab 557#else
fc36a67e 558# define memset(d,c,l) my_memset(d,c,l)
ee0007ab
LW
559#endif /* HAS_MEMSET */
560
85e6fe83 561#if !defined(HAS_MEMMOVE) && !defined(memmove)
2304df62 562# if defined(HAS_BCOPY) && defined(HAS_SAFE_BCOPY)
79072805
LW
563# define memmove(d,s,l) bcopy(s,d,l)
564# else
2304df62 565# if defined(HAS_MEMCPY) && defined(HAS_SAFE_MEMCPY)
79072805 566# define memmove(d,s,l) memcpy(d,s,l)
ee0007ab 567# else
79072805 568# define memmove(d,s,l) my_bcopy(s,d,l)
ee0007ab 569# endif
352d5a3a 570# endif
d9d8d8de 571#endif
ee0007ab 572
36477c24
PP
573#if defined(mips) && defined(ultrix) && !defined(__STDC__)
574# undef HAS_MEMCMP
575#endif
576
577#if defined(HAS_MEMCMP) && defined(HAS_SANE_MEMCMP)
85e6fe83 578# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
ee0007ab 579# ifndef memcmp
20ce7b12 580 extern int memcmp (char*, char*, int);
ee0007ab
LW
581# endif
582# endif
36477c24
PP
583# ifdef BUGGY_MSC
584 # pragma function(memcmp)
585# endif
ee0007ab
LW
586#else
587# ifndef memcmp
ecfc5424 588# define memcmp my_memcmp
352d5a3a 589# endif
36477c24 590#endif /* HAS_MEMCMP && HAS_SANE_MEMCMP */
8d063cd8 591
fc36a67e 592#ifndef memzero
c635e13b
PP
593# ifdef HAS_MEMSET
594# define memzero(d,l) memset(d,0,l)
79072805 595# else
c635e13b
PP
596# ifdef HAS_BZERO
597# define memzero(d,l) bzero(d,l)
79072805 598# else
fc36a67e 599# define memzero(d,l) my_bzero(d,l)
79072805
LW
600# endif
601# endif
d9d8d8de 602#endif
378cc40b 603
0f27ced1
JH
604#ifndef memchr
605# ifndef HAS_MEMCHR
606# define memchr(s,c,n) ninstr((char*)(s), ((char*)(s)) + n, &(c), &(c) + 1)
607# endif
608#endif
609
36477c24
PP
610#ifndef HAS_BCMP
611# ifndef bcmp
612# define bcmp(s1,s2,l) memcmp(s1,s2,l)
79072805 613# endif
36477c24 614#endif /* !HAS_BCMP */
378cc40b 615
ae986130 616#ifdef I_NETINET_IN
79072805 617# include <netinet/in.h>
ae986130
LW
618#endif
619
28e8609d
JH
620#ifdef I_ARPA_INET
621# include <arpa/inet.h>
622#endif
623
84902520
TB
624#if defined(SF_APPEND) && defined(USE_SFIO) && defined(I_SFIO)
625/* <sfio.h> defines SF_APPEND and <sys/stat.h> might define SF_APPEND
626 * (the neo-BSD seem to do this). */
627# undef SF_APPEND
628#endif
629
1aef975c 630#ifdef I_SYS_STAT
84902520 631# include <sys/stat.h>
1aef975c 632#endif
79072805 633
a0d0e21e
LW
634/* The stat macros for Amdahl UTS, Unisoft System V/88 (and derivatives
635 like UTekV) are broken, sometimes giving false positives. Undefine
636 them here and let the code below set them to proper values.
637
638 The ghs macro stands for GreenHills Software C-1.8.5 which
639 is the C compiler for sysV88 and the various derivatives.
640 This header file bug is corrected in gcc-2.5.8 and later versions.
641 --Kaveh Ghazi (ghazi@noc.rutgers.edu) 10/3/94. */
642
643#if defined(uts) || (defined(m88k) && defined(ghs))
79072805
LW
644# undef S_ISDIR
645# undef S_ISCHR
646# undef S_ISBLK
647# undef S_ISREG
648# undef S_ISFIFO
649# undef S_ISLNK
ee0007ab 650#endif
135863df 651
663a0e37
LW
652#ifdef I_TIME
653# include <time.h>
ffed7fef 654#endif
663a0e37 655
fe14fcc3 656#ifdef I_SYS_TIME
85e6fe83 657# ifdef I_SYS_TIME_KERNEL
663a0e37
LW
658# define KERNEL
659# endif
660# include <sys/time.h>
85e6fe83 661# ifdef I_SYS_TIME_KERNEL
663a0e37
LW
662# undef KERNEL
663# endif
a687059c 664#endif
135863df 665
55497cff 666#if defined(HAS_TIMES) && defined(I_SYS_TIMES)
85e6fe83 667# include <sys/times.h>
d9d8d8de 668#endif
8d063cd8 669
fe14fcc3 670#if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
79072805 671# undef HAS_STRERROR
663a0e37
LW
672#endif
673
674#include <errno.h>
ed6116ce 675#ifdef HAS_SOCKET
85e6fe83 676# ifdef I_NET_ERRNO
ed6116ce
LW
677# include <net/errno.h>
678# endif
679#endif
f86702cc
PP
680
681#ifdef VMS
682# define SETERRNO(errcode,vmserrcode) \
683 STMT_START { \
684 set_errno(errcode); \
685 set_vaxc_errno(vmserrcode); \
686 } STMT_END
748a9306 687#else
aba27d88 688# define SETERRNO(errcode,vmserrcode) (errno = (errcode))
748a9306 689#endif
ed6116ce 690
38a03e6e
MB
691#ifdef USE_THREADS
692# define ERRSV (thr->errsv)
940cb80d
MB
693# define DEFSV THREADSV(0)
694# define SAVE_DEFSV save_threadsv(0)
38a03e6e 695#else
3280af22 696# define ERRSV GvSV(PL_errgv)
3280af22
NIS
697# define DEFSV GvSV(PL_defgv)
698# define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
38a03e6e
MB
699#endif /* USE_THREADS */
700
98eae8f5
GS
701#define ERRHV GvHV(PL_errgv) /* XXX unused, here for compatibility */
702
55497cff 703#ifndef errno
5ff3f7a4
GS
704 extern int errno; /* ANSI allows errno to be an lvalue expr.
705 * For example in multithreaded environments
706 * something like this might happen:
707 * extern int *_errno(void);
708 * #define errno (*_errno()) */
d9d8d8de 709#endif
663a0e37 710
2304df62 711#ifdef HAS_STRERROR
a0d0e21e 712# ifdef VMS
20ce7b12 713 char *strerror (int,...);
a0d0e21e 714# else
68dc0745 715#ifndef DONT_DECLARE_STD
20ce7b12 716 char *strerror (int);
68dc0745 717#endif
a0d0e21e 718# endif
2304df62
AD
719# ifndef Strerror
720# define Strerror strerror
721# endif
722#else
723# ifdef HAS_SYS_ERRLIST
79072805
LW
724 extern int sys_nerr;
725 extern char *sys_errlist[];
2304df62
AD
726# ifndef Strerror
727# define Strerror(e) \
79072805 728 ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
2304df62 729# endif
79072805 730# endif
35c8bce7 731#endif
663a0e37 732
2304df62 733#ifdef I_SYS_IOCTL
79072805
LW
734# ifndef _IOCTL_
735# include <sys/ioctl.h>
736# endif
a687059c
LW
737#endif
738
ee0007ab 739#if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
79072805
LW
740# ifdef HAS_SOCKETPAIR
741# undef HAS_SOCKETPAIR
742# endif
2304df62
AD
743# ifdef I_NDBM
744# undef I_NDBM
79072805 745# endif
a687059c
LW
746#endif
747
a687059c 748#if INTSIZE == 2
79072805
LW
749# define htoni htons
750# define ntohi ntohs
a687059c 751#else
79072805
LW
752# define htoni htonl
753# define ntohi ntohl
a687059c
LW
754#endif
755
a0d0e21e 756/* Configure already sets Direntry_t */
35c8bce7 757#if defined(I_DIRENT)
663a0e37 758# include <dirent.h>
8f1f23e8
W
759 /* NeXT needs dirent + sys/dir.h */
760# if defined(I_SYS_DIR) && (defined(NeXT) || defined(__NeXT__))
a0d0e21e
LW
761# include <sys/dir.h>
762# endif
ae986130 763#else
fe14fcc3 764# ifdef I_SYS_NDIR
79a0689e 765# include <sys/ndir.h>
663a0e37 766# else
fe14fcc3 767# ifdef I_SYS_DIR
79a0689e
LW
768# ifdef hp9000s500
769# include <ndir.h> /* may be wrong in the future */
770# else
771# include <sys/dir.h>
772# endif
663a0e37
LW
773# endif
774# endif
4633a7c4 775#endif
a687059c 776
352d5a3a
LW
777#ifdef FPUTS_BOTCH
778/* work around botch in SunOS 4.0.1 and 4.0.2 */
779# ifndef fputs
79072805 780# define fputs(sv,fp) fprintf(fp,"%s",sv)
352d5a3a
LW
781# endif
782#endif
783
c623bd54
LW
784/*
785 * The following gobbledygook brought to you on behalf of __STDC__.
786 * (I could just use #ifndef __STDC__, but this is more bulletproof
787 * in the face of half-implementations.)
788 */
789
790#ifndef S_IFMT
791# ifdef _S_IFMT
792# define S_IFMT _S_IFMT
793# else
794# define S_IFMT 0170000
795# endif
796#endif
797
798#ifndef S_ISDIR
799# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
800#endif
801
802#ifndef S_ISCHR
803# define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
804#endif
805
806#ifndef S_ISBLK
fe14fcc3
LW
807# ifdef S_IFBLK
808# define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
809# else
810# define S_ISBLK(m) (0)
811# endif
c623bd54
LW
812#endif
813
814#ifndef S_ISREG
815# define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
816#endif
817
818#ifndef S_ISFIFO
fe14fcc3
LW
819# ifdef S_IFIFO
820# define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
821# else
822# define S_ISFIFO(m) (0)
823# endif
c623bd54
LW
824#endif
825
826#ifndef S_ISLNK
827# ifdef _S_ISLNK
828# define S_ISLNK(m) _S_ISLNK(m)
829# else
830# ifdef _S_IFLNK
831# define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
832# else
833# ifdef S_IFLNK
834# define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
835# else
836# define S_ISLNK(m) (0)
837# endif
838# endif
839# endif
840#endif
841
842#ifndef S_ISSOCK
843# ifdef _S_ISSOCK
844# define S_ISSOCK(m) _S_ISSOCK(m)
845# else
846# ifdef _S_IFSOCK
847# define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
848# else
849# ifdef S_IFSOCK
850# define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
851# else
852# define S_ISSOCK(m) (0)
853# endif
854# endif
855# endif
856#endif
857
858#ifndef S_IRUSR
859# ifdef S_IREAD
860# define S_IRUSR S_IREAD
861# define S_IWUSR S_IWRITE
862# define S_IXUSR S_IEXEC
863# else
864# define S_IRUSR 0400
865# define S_IWUSR 0200
866# define S_IXUSR 0100
867# endif
868# define S_IRGRP (S_IRUSR>>3)
869# define S_IWGRP (S_IWUSR>>3)
870# define S_IXGRP (S_IXUSR>>3)
871# define S_IROTH (S_IRUSR>>6)
872# define S_IWOTH (S_IWUSR>>6)
873# define S_IXOTH (S_IXUSR>>6)
874#endif
875
876#ifndef S_ISUID
877# define S_ISUID 04000
878#endif
879
880#ifndef S_ISGID
881# define S_ISGID 02000
882#endif
883
79072805
LW
884#ifdef ff_next
885# undef ff_next
352d5a3a
LW
886#endif
887
a0d0e21e 888#if defined(cray) || defined(gould) || defined(i860) || defined(pyr)
45d8adaa
LW
889# define SLOPPYDIVIDE
890#endif
891
748a9306
LW
892#ifdef UV
893#undef UV
894#endif
895
05f13f53 896/*
27d4fb96
PP
897 The IV type is supposed to be long enough to hold any integral
898 value or a pointer.
899 --Andy Dougherty August 1996
900*/
901
a22e52b9
JH
902typedef IVTYPE IV;
903typedef UVTYPE UV;
8175356b 904
de1c2614 905#if defined(USE_64_BITS) && defined(HAS_QUAD)
6b8eaf93 906# if QUADKIND == QUAD_IS_INT64_T && defined(INT64_MAX)
5ff3f7a4
GS
907# define IV_MAX INT64_MAX
908# define IV_MIN INT64_MIN
909# define UV_MAX UINT64_MAX
cae7ae48
JH
910# ifndef UINT64_MIN
911# define UINT64_MIN 0
912# endif
5ff3f7a4
GS
913# define UV_MIN UINT64_MIN
914# else
915# define IV_MAX PERL_QUAD_MAX
916# define IV_MIN PERL_QUAD_MIN
917# define UV_MAX PERL_UQUAD_MAX
918# define UV_MIN PERL_UQUAD_MIN
919# endif
cf2093f6
JH
920# define IV_IS_QUAD
921# define UV_IS_QUAD
79072805 922#else
8175356b 923# if defined(INT32_MAX) && IVSIZE == 4
5ff3f7a4
GS
924# define IV_MAX INT32_MAX
925# define IV_MIN INT32_MIN
716026f9
DL
926# ifndef UINT32_MAX_BROKEN /* e.g. HP-UX with gcc messes this up */
927# define UV_MAX UINT32_MAX
928# else
929# define UV_MAX 4294967295U
930# endif
cae7ae48
JH
931# ifndef UINT32_MIN
932# define UINT32_MIN 0
933# endif
5ff3f7a4
GS
934# define UV_MIN UINT32_MIN
935# else
936# define IV_MAX PERL_LONG_MAX
937# define IV_MIN PERL_LONG_MIN
938# define UV_MAX PERL_ULONG_MAX
939# define UV_MIN PERL_ULONG_MIN
940# endif
8175356b 941# if IVSIZE == 8
cf2093f6
JH
942# define IV_IS_QUAD
943# define UV_IS_QUAD
de1c2614
JH
944# ifndef HAS_QUAD
945# define HAS_QUAD
946# endif
cf2093f6
JH
947# else
948# undef IV_IS_QUAD
949# undef UV_IS_QUAD
de1c2614 950# undef HAS_QUAD
cf2093f6 951# endif
79072805 952#endif
d7d93a81 953
cae7ae48 954#define IV_DIG (BIT_DIGITS(IVSIZE * 8))
22ec83e3 955#define UV_DIG (BIT_DIGITS(UVSIZE * 8))
56431972 956
26bb67e2
JH
957/*
958 * The macros INT2PTR and NUM2PTR are (despite their names)
959 * bi-directional: they will convert int/float to or from pointers.
960 * However the conversion to int/float are named explicitly:
961 * PTR2IV, PTR2UV, PTR2NV.
962 *
963 * For int conversions we do not need two casts if pointers are
964 * the same size as IV and UV. Otherwise we need an explicit
965 * cast (PTRV) to avoid compiler warnings.
966 */
56431972
RB
967#if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE)
968# define PTRV UV
969# define INT2PTR(any,d) (any)(d)
970#else
42718184 971# if PTRSIZE == LONGSIZE
56431972 972# define PTRV unsigned long
42718184 973# else
56431972 974# define PTRV unsigned
42718184 975# endif
56431972 976# define INT2PTR(any,d) (any)(PTRV)(d)
42718184 977#endif
56431972
RB
978#define NUM2PTR(any,d) (any)(PTRV)(d)
979#define PTR2IV(p) INT2PTR(IV,p)
980#define PTR2UV(p) INT2PTR(UV,p)
981#define PTR2NV(p) NUM2PTR(NV,p)
42718184 982
65202027 983#ifdef USE_LONG_DOUBLE
68d4903c 984# if !(defined(HAS_LONG_DOUBLE) && (LONG_DOUBLESIZE > DOUBLESIZE))
2d4389e4 985# undef USE_LONG_DOUBLE /* Ouch! */
65202027
DS
986# endif
987#endif
988
2d4389e4
JH
989#ifdef OVR_DBL_DIG
990/* Use an overridden DBL_DIG */
991# ifdef DBL_DIG
992# undef DBL_DIG
993# endif
994# define DBL_DIG OVR_DBL_DIG
995#else
996/* The following is all to get DBL_DIG, in order to pick a nice
997 default value for printing floating point numbers in Gconvert.
998 (see config.h)
999*/
1000#ifdef I_LIMITS
1001#include <limits.h>
1002#endif
1003#ifdef I_FLOAT
1004#include <float.h>
1005#endif
1006#ifndef HAS_DBL_DIG
1007#define DBL_DIG 15 /* A guess that works lots of places */
1008#endif
1009#endif
cbca01e1
JH
1010#ifdef I_FLOAT
1011#include <float.h>
1012#endif
1013#ifndef HAS_DBL_DIG
1014#define DBL_DIG 15 /* A guess that works lots of places */
1015#endif
2d4389e4
JH
1016
1017#ifdef OVR_LDBL_DIG
1018/* Use an overridden LDBL_DIG */
1019# ifdef LDBL_DIG
1020# undef LDBL_DIG
1021# endif
1022# define LDBL_DIG OVR_LDBL_DIG
1023#else
1024/* The following is all to get LDBL_DIG, in order to pick a nice
1025 default value for printing floating point numbers in Gconvert.
1026 (see config.h)
1027*/
68d4903c
JH
1028# ifdef I_LIMITS
1029# include <limits.h>
1030# endif
1031# ifdef I_FLOAT
1032# include <float.h>
1033# endif
1034# ifndef HAS_LDBL_DIG
1035# if LONG_DOUBLESIZE == 10
1036# define LDBL_DIG 18 /* assume IEEE */
1037# else
1038# if LONG_DOUBLESIZE == 12
1039# define LDBL_DIG 18 /* gcc? */
1040# else
1041# if LONG_DOUBLESIZE == 16
1042# define LDBL_DIG 33 /* assume IEEE */
1043# else
1044# if LONG_DOUBLESIZE == DOUBLESIZE
1045# define LDBL_DIG DBL_DIG /* bummer */
1046# endif
1047# endif
1048# endif
1049# endif
1050# endif
2d4389e4
JH
1051#endif
1052
a22e52b9 1053typedef NVTYPE NV;
8175356b 1054
65202027 1055#ifdef USE_LONG_DOUBLE
2d4389e4 1056# define NV_DIG LDBL_DIG
68d4903c
JH
1057# ifdef HAS_SQRTL
1058# define Perl_modf modfl
1059# define Perl_frexp frexpl
1060# define Perl_cos cosl
1061# define Perl_sin sinl
1062# define Perl_sqrt sqrtl
1063# define Perl_exp expl
1064# define Perl_log logl
1065# define Perl_atan2 atan2l
1066# define Perl_pow powl
1067# define Perl_floor floorl
1068# define Perl_fmod fmodl
1069# endif
65202027 1070#else
2d4389e4 1071# define NV_DIG DBL_DIG
65202027
DS
1072# define Perl_modf modf
1073# define Perl_frexp frexp
1074# define Perl_cos cos
1075# define Perl_sin sin
1076# define Perl_sqrt sqrt
1077# define Perl_exp exp
1078# define Perl_log log
1079# define Perl_atan2 atan2
1080# define Perl_pow pow
1081# define Perl_floor floor
65202027
DS
1082# define Perl_fmod fmod
1083#endif
1084
cf2093f6
JH
1085#if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE) && defined(HAS_ATOLF)
1086# define Perl_atof atolf
1087#else
1088# define Perl_atof atof
1089#endif
1090
760ac839
LW
1091/* Previously these definitions used hardcoded figures.
1092 * It is hoped these formula are more portable, although
1093 * no data one way or another is presently known to me.
1094 * The "PERL_" names are used because these calculated constants
1095 * do not meet the ANSI requirements for LONG_MAX, etc., which
1096 * need to be constants acceptable to #if - kja
1097 * define PERL_LONG_MAX 2147483647L
1098 * define PERL_LONG_MIN (-LONG_MAX - 1)
1099 * define PERL ULONG_MAX 4294967295L
1100 */
1101
1102#ifdef I_LIMITS /* Needed for cast_xxx() functions below. */
1103# include <limits.h>
1104#else
1105#ifdef I_VALUES
1106# include <values.h>
1107#endif
1108#endif
1109
99abf803
PP
1110/*
1111 * Try to figure out max and min values for the integral types. THE CORRECT
1112 * SOLUTION TO THIS MESS: ADAPT enquire.c FROM GCC INTO CONFIGURE. The
1113 * following hacks are used if neither limits.h or values.h provide them:
1114 * U<TYPE>_MAX: for types >= int: ~(unsigned TYPE)0
1115 * for types < int: (unsigned TYPE)~(unsigned)0
1116 * The argument to ~ must be unsigned so that later signed->unsigned
1117 * conversion can't modify the value's bit pattern (e.g. -0 -> +0),
1118 * and it must not be smaller than int because ~ does integral promotion.
1119 * <type>_MAX: (<type>) (U<type>_MAX >> 1)
1120 * <type>_MIN: -<type>_MAX - <is_twos_complement_architecture: (3 & -1) == 3>.
1121 * The latter is a hack which happens to work on some machines but
1122 * does *not* catch any random system, or things like integer types
1123 * with NaN if that is possible.
1124 *
1125 * All of the types are explicitly cast to prevent accidental loss of
1126 * numeric range, and in the hope that they will be less likely to confuse
1127 * over-eager optimizers.
1128 *
1129 */
27d4fb96 1130
99abf803
PP
1131#define PERL_UCHAR_MIN ((unsigned char)0)
1132
1133#ifdef UCHAR_MAX
1134# define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX)
27d4fb96 1135#else
99abf803
PP
1136# ifdef MAXUCHAR
1137# define PERL_UCHAR_MAX ((unsigned char)MAXUCHAR)
27d4fb96 1138# else
99abf803 1139# define PERL_UCHAR_MAX ((unsigned char)~(unsigned)0)
27d4fb96
PP
1140# endif
1141#endif
99abf803
PP
1142
1143/*
1144 * CHAR_MIN and CHAR_MAX are not included here, as the (char) type may be
1145 * ambiguous. It may be equivalent to (signed char) or (unsigned char)
1146 * depending on local options. Until Configure detects this (or at least
1147 * detects whether the "signed" keyword is available) the CHAR ranges
1148 * will not be included. UCHAR functions normally.
1149 * - kja
1150 */
27d4fb96 1151
99abf803
PP
1152#define PERL_USHORT_MIN ((unsigned short)0)
1153
1154#ifdef USHORT_MAX
1155# define PERL_USHORT_MAX ((unsigned short)USHORT_MAX)
27d4fb96 1156#else
99abf803
PP
1157# ifdef MAXUSHORT
1158# define PERL_USHORT_MAX ((unsigned short)MAXUSHORT)
27d4fb96 1159# else
ef2f54b0
CB
1160# ifdef USHRT_MAX
1161# define PERL_USHORT_MAX ((unsigned short)USHRT_MAX)
1162# else
1163# define PERL_USHORT_MAX ((unsigned short)~(unsigned)0)
1164# endif
27d4fb96
PP
1165# endif
1166#endif
1167
27d4fb96 1168#ifdef SHORT_MAX
99abf803 1169# define PERL_SHORT_MAX ((short)SHORT_MAX)
27d4fb96
PP
1170#else
1171# ifdef MAXSHORT /* Often used in <values.h> */
99abf803 1172# define PERL_SHORT_MAX ((short)MAXSHORT)
27d4fb96 1173# else
ef2f54b0
CB
1174# ifdef SHRT_MAX
1175# define PERL_SHORT_MAX ((short)SHRT_MAX)
1176# else
1177# define PERL_SHORT_MAX ((short) (PERL_USHORT_MAX >> 1))
1178# endif
27d4fb96
PP
1179# endif
1180#endif
1181
1182#ifdef SHORT_MIN
99abf803 1183# define PERL_SHORT_MIN ((short)SHORT_MIN)
27d4fb96
PP
1184#else
1185# ifdef MINSHORT
99abf803 1186# define PERL_SHORT_MIN ((short)MINSHORT)
27d4fb96 1187# else
ef2f54b0
CB
1188# ifdef SHRT_MIN
1189# define PERL_SHORT_MIN ((short)SHRT_MIN)
1190# else
1191# define PERL_SHORT_MIN (-PERL_SHORT_MAX - ((3 & -1) == 3))
1192# endif
27d4fb96
PP
1193# endif
1194#endif
1195
99abf803
PP
1196#ifdef UINT_MAX
1197# define PERL_UINT_MAX ((unsigned int)UINT_MAX)
27d4fb96 1198#else
99abf803
PP
1199# ifdef MAXUINT
1200# define PERL_UINT_MAX ((unsigned int)MAXUINT)
27d4fb96 1201# else
99abf803 1202# define PERL_UINT_MAX (~(unsigned int)0)
27d4fb96
PP
1203# endif
1204#endif
1205
99abf803 1206#define PERL_UINT_MIN ((unsigned int)0)
27d4fb96
PP
1207
1208#ifdef INT_MAX
99abf803 1209# define PERL_INT_MAX ((int)INT_MAX)
27d4fb96
PP
1210#else
1211# ifdef MAXINT /* Often used in <values.h> */
99abf803 1212# define PERL_INT_MAX ((int)MAXINT)
27d4fb96 1213# else
99abf803 1214# define PERL_INT_MAX ((int)(PERL_UINT_MAX >> 1))
27d4fb96
PP
1215# endif
1216#endif
1217
1218#ifdef INT_MIN
99abf803 1219# define PERL_INT_MIN ((int)INT_MIN)
27d4fb96
PP
1220#else
1221# ifdef MININT
99abf803 1222# define PERL_INT_MIN ((int)MININT)
27d4fb96
PP
1223# else
1224# define PERL_INT_MIN (-PERL_INT_MAX - ((3 & -1) == 3))
1225# endif
1226#endif
1227
99abf803
PP
1228#ifdef ULONG_MAX
1229# define PERL_ULONG_MAX ((unsigned long)ULONG_MAX)
27d4fb96 1230#else
99abf803
PP
1231# ifdef MAXULONG
1232# define PERL_ULONG_MAX ((unsigned long)MAXULONG)
27d4fb96 1233# else
99abf803 1234# define PERL_ULONG_MAX (~(unsigned long)0)
27d4fb96
PP
1235# endif
1236#endif
1237
99abf803 1238#define PERL_ULONG_MIN ((unsigned long)0L)
27d4fb96 1239
760ac839 1240#ifdef LONG_MAX
99abf803 1241# define PERL_LONG_MAX ((long)LONG_MAX)
760ac839
LW
1242#else
1243# ifdef MAXLONG /* Often used in <values.h> */
99abf803 1244# define PERL_LONG_MAX ((long)MAXLONG)
760ac839 1245# else
99abf803 1246# define PERL_LONG_MAX ((long) (PERL_ULONG_MAX >> 1))
760ac839
LW
1247# endif
1248#endif
1249
1250#ifdef LONG_MIN
99abf803 1251# define PERL_LONG_MIN ((long)LONG_MIN)
760ac839
LW
1252#else
1253# ifdef MINLONG
99abf803 1254# define PERL_LONG_MIN ((long)MINLONG)
760ac839 1255# else
27d4fb96 1256# define PERL_LONG_MIN (-PERL_LONG_MAX - ((3 & -1) == 3))
760ac839
LW
1257# endif
1258#endif
1259
d7d93a81 1260#ifdef UV_IS_QUAD
99abf803
PP
1261
1262# ifdef UQUAD_MAX
1263# define PERL_UQUAD_MAX ((UV)UQUAD_MAX)
760ac839 1264# else
99abf803 1265# define PERL_UQUAD_MAX (~(UV)0)
760ac839 1266# endif
760ac839 1267
99abf803 1268# define PERL_UQUAD_MIN ((UV)0)
27d4fb96 1269
27d4fb96 1270# ifdef QUAD_MAX
99abf803 1271# define PERL_QUAD_MAX ((IV)QUAD_MAX)
27d4fb96 1272# else
99abf803 1273# define PERL_QUAD_MAX ((IV) (PERL_UQUAD_MAX >> 1))
27d4fb96
PP
1274# endif
1275
1276# ifdef QUAD_MIN
99abf803 1277# define PERL_QUAD_MIN ((IV)QUAD_MIN)
27d4fb96 1278# else
a6e633de 1279# define PERL_QUAD_MIN (-PERL_QUAD_MAX - ((3 & -1) == 3))
27d4fb96
PP
1280# endif
1281
79072805
LW
1282#endif
1283
ee0007ab 1284typedef MEM_SIZE STRLEN;
450a55e4 1285
79072805
LW
1286typedef struct op OP;
1287typedef struct cop COP;
1288typedef struct unop UNOP;
1289typedef struct binop BINOP;
1290typedef struct listop LISTOP;
1291typedef struct logop LOGOP;
79072805
LW
1292typedef struct pmop PMOP;
1293typedef struct svop SVOP;
7934575e 1294typedef struct padop PADOP;
79072805 1295typedef struct pvop PVOP;
79072805
LW
1296typedef struct loop LOOP;
1297
93a17b20 1298typedef struct interpreter PerlInterpreter;
79072805
LW
1299typedef struct sv SV;
1300typedef struct av AV;
1301typedef struct hv HV;
1302typedef struct cv CV;
378cc40b 1303typedef struct regexp REGEXP;
79072805 1304typedef struct gp GP;
0c30d9ec 1305typedef struct gv GV;
8990e307 1306typedef struct io IO;
c09156bb 1307typedef struct context PERL_CONTEXT;
79072805
LW
1308typedef struct block BLOCK;
1309
1310typedef struct magic MAGIC;
ed6116ce 1311typedef struct xrv XRV;
79072805
LW
1312typedef struct xpv XPV;
1313typedef struct xpviv XPVIV;
ff68c719 1314typedef struct xpvuv XPVUV;
79072805
LW
1315typedef struct xpvnv XPVNV;
1316typedef struct xpvmg XPVMG;
1317typedef struct xpvlv XPVLV;
1318typedef struct xpvav XPVAV;
1319typedef struct xpvhv XPVHV;
1320typedef struct xpvgv XPVGV;
1321typedef struct xpvcv XPVCV;
1322typedef struct xpvbm XPVBM;
1323typedef struct xpvfm XPVFM;
8990e307 1324typedef struct xpvio XPVIO;
79072805
LW
1325typedef struct mgvtbl MGVTBL;
1326typedef union any ANY;
5f7fde29
GS
1327typedef struct ptr_tbl_ent PTR_TBL_ENT_t;
1328typedef struct ptr_tbl PTR_TBL_t;
8d063cd8 1329
378cc40b 1330#include "handy.h"
a0d0e21e 1331
6b8eaf93
JH
1332#ifndef NO_LARGE_FILES
1333# define USE_LARGE_FILES /* If available. */
d9b3e12d
JH
1334#endif
1335
6b8eaf93
JH
1336#if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_RAWIO)
1337# define USE_64_BIT_RAWIO /* explicit */
1338# if LSEEKSIZE == 8 && !defined(USE_64_BIT_RAWIO)
1339# define USE_64_BIT_RAWIO /* implicit */
1340# endif
4564133c
JH
1341#endif
1342
6b8eaf93
JH
1343/* Notice the use of HAS_FSEEKO: now we are obligated to always use
1344 * fseeko/ftello if possible. Don't go #defining ftell to ftello yourself,
1345 * however, because operating systems like to do that themself. */
1346#ifndef FSEEKSIZE
1347# ifdef HAS_FSEEKO
1348# define FSEEKSIZE LSEEKSIZE
1349# else
1350# define FSEEKSIZE LONGSIZE
1351# endif
1352#endif
1353
1354#if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_STDIO)
1355# define USE_64_BIT_STDIO /* explicit */
1356# if FSEEKSIZE == 8 && !defined(USE_64_BIT_STDIO)
1357# define USE_64_BIT_STDIO /* implicit */
1358# endif
1359#endif
4564133c 1360
09458382 1361#ifdef USE_64_BIT_RAWIO
d9b3e12d
JH
1362# ifdef HAS_OFF64_T
1363# undef Off_t
1364# define Off_t off64_t
1365# undef LSEEKSIZE
1366# define LSEEKSIZE 8
5ff3f7a4 1367# endif
d9b3e12d
JH
1368/* Most 64-bit environments have defines like _LARGEFILE_SOURCE that
1369 * will trigger defines like the ones below. Some 64-bit environments,
09458382 1370 * however, do not. Therefore we have to explicitly mix and match. */
d9b3e12d
JH
1371# if defined(USE_OPEN64)
1372# define open open64
5ff3f7a4 1373# endif
d9b3e12d
JH
1374# if defined(USE_LSEEK64)
1375# define lseek lseek64
6b8eaf93
JH
1376# else
1377# if defined(USE_LLSEEK)
1378# define lseek llseek
1379# endif
d9b3e12d
JH
1380# endif
1381# if defined(USE_STAT64)
1382# define stat stat64
1383# endif
1384# if defined(USE_FSTAT64)
1385# define fstat fstat64
1386# endif
1387# if defined(USE_LSTAT64)
1388# define lstat lstat64
1389# endif
1390# if defined(USE_FLOCK64)
1391# define flock flock64
1392# endif
1393# if defined(USE_LOCKF64)
1394# define lockf lockf64
1395# endif
1396# if defined(USE_FCNTL64)
1397# define fcntl fcntl64
1398# endif
1399# if defined(USE_TRUNCATE64)
1400# define truncate truncate64
1401# endif
1402# if defined(USE_FTRUNCATE64)
1403# define ftruncate ftruncate64
1404# endif
1405#endif
1406
1407#ifdef USE_64_BIT_STDIO
1408# ifdef HAS_FPOS64_T
1409# undef Fpos_t
1410# define Fpos_t fpos64_t
1411# endif
1412/* Most 64-bit environments have defines like _LARGEFILE_SOURCE that
1413 * will trigger defines like the ones below. Some 64-bit environments,
1414 * however, do not. */
1415# if defined(USE_FOPEN64)
1416# define fopen fopen64
1417# endif
1418# if defined(USE_FSEEK64)
6b8eaf93 1419# define fseek fseek64 /* don't do fseeko here, see perlio.c */
d9b3e12d
JH
1420# endif
1421# if defined(USE_FTELL64)
6b8eaf93 1422# define ftell ftell64 /* don't do ftello here, see perlio.c */
d9b3e12d
JH
1423# endif
1424# if defined(USE_FSETPOS64)
1425# define fsetpos fsetpos64
1426# endif
1427# if defined(USE_FGETPOS64)
1428# define fgetpos fgetpos64
1429# endif
1430# if defined(USE_TMPFILE64)
1431# define tmpfile tmpfile64
1432# endif
1433# if defined(USE_FREOPEN64)
1434# define freopen freopen64
5ff3f7a4
GS
1435# endif
1436#endif
1437
2c2d71f5
JH
1438#if defined(OS2)
1439# include "iperlsys.h"
1440#endif
1441
6f71a643
JH
1442#if defined(__OPEN_VM)
1443# include "vmesa/vmesaish.h"
1444#endif
1445
748a9306 1446#ifdef DOSISH
4633a7c4
LW
1447# if defined(OS2)
1448# include "os2ish.h"
1449# else
748a9306 1450# include "dosish.h"
4633a7c4 1451# endif
a0d0e21e 1452#else
748a9306
LW
1453# if defined(VMS)
1454# include "vmsish.h"
1455# else
0c30d9ec
PP
1456# if defined(PLAN9)
1457# include "./plan9/plan9ish.h"
1458# else
1d84e8df
JH
1459# if defined(MPE)
1460# include "mpeix/mpeixish.h"
1461# else
495c5fdc
GP
1462# if defined(__VOS__)
1463# include "vosish.h"
1464# else
4d2c4e07
OF
1465# if defined(EPOC)
1466# include "epocish.h"
1467# else
cd39f2b6
JH
1468# if defined(MACOS_TRADITIONAL)
1469# include "macos/macish.h"
1470# else
1471# include "unixish.h"
1472# endif
4d2c4e07 1473# endif
495c5fdc 1474# endif
1d84e8df 1475# endif
0c30d9ec 1476# endif
748a9306 1477# endif
32f822de
GS
1478#endif
1479
ed344e4f
IZ
1480#ifndef PERL_SYS_INIT3
1481# define PERL_SYS_INIT3(argvp,argcp,envp) PERL_SYS_INIT(argvp,argcp)
1482#endif
1483
0f31cffe
GS
1484#ifndef MAXPATHLEN
1485# ifdef PATH_MAX
b990c8b2
JH
1486# ifdef _POSIX_PATH_MAX
1487# if PATH_MAX > _POSIX_PATH_MAX
1488/* MAXPATHLEN is supposed to include the final null character,
1489 * as opposed to PATH_MAX and _POSIX_PATH_MAX. */
1490# define MAXPATHLEN (PATH_MAX+1)
1491# else
1492# define MAXPATHLEN (_POSIX_PATH_MAX+1)
1493# endif
1494# else
1495# define MAXPATHLEN (PATH_MAX+1)
1496# endif
0f31cffe 1497# else
b990c8b2
JH
1498# ifdef _POSIX_PATH_MAX
1499# define MAXPATHLEN (_POSIX_PATH_MAX+1)
1500# else
1501# define MAXPATHLEN 1024 /* Err on the large side. */
1502# endif
0f31cffe
GS
1503# endif
1504#endif
1505
32f822de 1506/*
dd96f567
IZ
1507 * USE_THREADS needs to be after unixish.h as <pthread.h> includes
1508 * <sys/signal.h> which defines NSIG - which will stop inclusion of <signal.h>
32f822de
GS
1509 * this results in many functions being undeclared which bothers C++
1510 * May make sense to have threads after "*ish.h" anyway
1511 */
1512
1feb2720
GS
1513#if defined(USE_THREADS) || defined(USE_ITHREADS)
1514# if defined(USE_THREADS)
79d59c5f
GS
1515 /* pending resolution of licensing issues, we avoid the erstwhile
1516 * atomic.h everywhere */
1517# define EMULATE_ATOMIC_REFCOUNTS
1feb2720 1518# endif
32f822de
GS
1519# ifdef FAKE_THREADS
1520# include "fakethr.h"
1521# else
1522# ifdef WIN32
1523# include <win32thread.h>
1524# else
dd96f567
IZ
1525# ifdef OS2
1526# include "os2thread.h"
1527# else
7f3d1cf1 1528# ifdef I_MACH_CTHREADS
bdd66968 1529# include <mach/cthreads.h>
8f1f23e8 1530# if (defined(NeXT) || defined(__NeXT__)) && defined(PERL_POLLUTE_MALLOC)
772fe5b3
HM
1531# define MUTEX_INIT_CALLS_MALLOC
1532# endif
7f3d1cf1
BH
1533typedef cthread_t perl_os_thread;
1534typedef mutex_t perl_mutex;
1535typedef condition_t perl_cond;
1536typedef void * perl_key;
1537# else /* Posix threads */
1f5ae88c
JH
1538# ifdef I_PTHREAD
1539# include <pthread.h>
1540# endif
7f3d1cf1
BH
1541typedef pthread_t perl_os_thread;
1542typedef pthread_mutex_t perl_mutex;
1543typedef pthread_cond_t perl_cond;
1544typedef pthread_key_t perl_key;
1545# endif /* I_MACH_CTHREADS */
dd96f567 1546# endif /* OS2 */
32f822de
GS
1547# endif /* WIN32 */
1548# endif /* FAKE_THREADS */
1feb2720 1549#endif /* USE_THREADS || USE_ITHREADS */
c5be433b
GS
1550
1551#ifdef WIN32
1feb2720 1552# include "win32.h"
c5be433b
GS
1553#endif
1554
68dc0745 1555#ifdef VMS
6b88bc9c 1556# define STATUS_NATIVE PL_statusvalue_vms
68dc0745 1557# define STATUS_NATIVE_EXPORT \
6b88bc9c 1558 ((I32)PL_statusvalue_vms == -1 ? 44 : PL_statusvalue_vms)
68dc0745
PP
1559# define STATUS_NATIVE_SET(n) \
1560 STMT_START { \
6b88bc9c
GS
1561 PL_statusvalue_vms = (n); \
1562 if ((I32)PL_statusvalue_vms == -1) \
3280af22 1563 PL_statusvalue = -1; \
6b88bc9c 1564 else if (PL_statusvalue_vms & STS$M_SUCCESS) \
3280af22 1565 PL_statusvalue = 0; \
6b88bc9c
GS
1566 else if ((PL_statusvalue_vms & STS$M_SEVERITY) == 0) \
1567 PL_statusvalue = 1 << 8; \
68dc0745 1568 else \
6b88bc9c 1569 PL_statusvalue = (PL_statusvalue_vms & STS$M_SEVERITY) << 8; \
68dc0745 1570 } STMT_END
3280af22 1571# define STATUS_POSIX PL_statusvalue
68dc0745
PP
1572# ifdef VMSISH_STATUS
1573# define STATUS_CURRENT (VMSISH_STATUS ? STATUS_NATIVE : STATUS_POSIX)
1574# else
1575# define STATUS_CURRENT STATUS_POSIX
1576# endif
1577# define STATUS_POSIX_SET(n) \
1578 STMT_START { \
3280af22
NIS
1579 PL_statusvalue = (n); \
1580 if (PL_statusvalue != -1) { \
1581 PL_statusvalue &= 0xFFFF; \
6b88bc9c 1582 PL_statusvalue_vms = PL_statusvalue ? 44 : 1; \
68dc0745 1583 } \
6b88bc9c 1584 else PL_statusvalue_vms = -1; \
68dc0745 1585 } STMT_END
6b88bc9c
GS
1586# define STATUS_ALL_SUCCESS (PL_statusvalue = 0, PL_statusvalue_vms = 1)
1587# define STATUS_ALL_FAILURE (PL_statusvalue = 1, PL_statusvalue_vms = 44)
68dc0745
PP
1588#else
1589# define STATUS_NATIVE STATUS_POSIX
1590# define STATUS_NATIVE_EXPORT STATUS_POSIX
1591# define STATUS_NATIVE_SET STATUS_POSIX_SET
3280af22 1592# define STATUS_POSIX PL_statusvalue
68dc0745
PP
1593# define STATUS_POSIX_SET(n) \
1594 STMT_START { \
3280af22
NIS
1595 PL_statusvalue = (n); \
1596 if (PL_statusvalue != -1) \
1597 PL_statusvalue &= 0xFFFF; \
68dc0745
PP
1598 } STMT_END
1599# define STATUS_CURRENT STATUS_POSIX
3280af22
NIS
1600# define STATUS_ALL_SUCCESS (PL_statusvalue = 0)
1601# define STATUS_ALL_FAILURE (PL_statusvalue = 1)
68dc0745
PP
1602#endif
1603
cc3604b1
GS
1604/* flags in PL_exit_flags for nature of exit() */
1605#define PERL_EXIT_EXPECTED 0x01
1606
0b94c7bb 1607#ifndef MEMBER_TO_FPTR
a7cb1f99
GS
1608# define MEMBER_TO_FPTR(name) name
1609#endif
1610
1611/* format to use for version numbers in file/directory names */
1612#ifndef PERL_FS_VER_FMT
1613# define PERL_FS_VER_FMT "%"UVuf".%"UVuf".%"UVuf
0b94c7bb
GS
1614#endif
1615
45bc9206
GS
1616/* This defines a way to flush all output buffers. This may be a
1617 * performance issue, so we allow people to disable it.
45bc9206
GS
1618 */
1619#ifndef PERL_FLUSHALL_FOR_CHILD
767df6a1 1620# if defined(FFLUSH_NULL) || defined(USE_SFIO)
66fe083f 1621# define PERL_FLUSHALL_FOR_CHILD PerlIO_flush((PerlIO*)NULL)
767df6a1
JH
1622# else
1623# ifdef FFLUSH_ALL
1624# define PERL_FLUSHALL_FOR_CHILD my_fflush_all()
e2dbf222 1625# else
c5be433b 1626# define PERL_FLUSHALL_FOR_CHILD NOOP
767df6a1 1627# endif
66fe083f 1628# endif
45bc9206
GS
1629#endif
1630
7766f137
GS
1631#ifndef PERL_WAIT_FOR_CHILDREN
1632# define PERL_WAIT_FOR_CHILDREN NOOP
1633#endif
1634
651a3225
GS
1635/* the traditional thread-unsafe notion of "current interpreter".
1636 * XXX todo: a thread-safe version that fetches it from TLS (akin to THR)
1637 * needs to be defined elsewhere (conditional on pthread_getspecific()
1638 * availability). */
c5be433b
GS
1639#ifndef PERL_SET_INTERP
1640# define PERL_SET_INTERP(i) (PL_curinterp = (PerlInterpreter*)(i))
1641#endif
1642
1643#ifndef PERL_GET_INTERP
1644# define PERL_GET_INTERP (PL_curinterp)
1645#endif
1646
54aff467
GS
1647#if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_GET_THX)
1648# ifdef USE_THREADS
1649# define PERL_GET_THX THR
1650# else
1651# ifdef MULTIPLICITY
1652# define PERL_GET_THX PERL_GET_INTERP
1653# else
1654# ifdef PERL_OBJECT
1655# define PERL_GET_THX ((CPerlObj*)PERL_GET_INTERP)
1656# else
1657# define PERL_GET_THX ((void*)0)
1658# endif
1659# endif
1660# endif
1661#endif
1662
3fc1aec6
PP
1663/* Some unistd.h's give a prototype for pause() even though
1664 HAS_PAUSE ends up undefined. This causes the #define
1665 below to be rejected by the compmiler. Sigh.
1666*/
1667#ifdef HAS_PAUSE
1668#define Pause pause
1669#else
1670#define Pause() sleep((32767<<16)+32767)
748a9306
LW
1671#endif
1672
1673#ifndef IOCPARM_LEN
1674# ifdef IOCPARM_MASK
1675 /* on BSDish systes we're safe */
1676# define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
1677# else
1678 /* otherwise guess at what's safe */
1679# define IOCPARM_LEN(x) 256
1680# endif
a0d0e21e
LW
1681#endif
1682
2c2d71f5 1683#if defined(CYGWIN)
521e0776
GS
1684/* USEMYBINMODE
1685 * This symbol, if defined, indicates that the program should
1686 * use the routine my_binmode(FILE *fp, char iotype) to insure
1687 * that a file is in "binary" mode -- that is, that no translation
1688 * of bytes occurs on read or write operations.
1689 */
1690# define USEMYBINMODE / **/
1691# define my_binmode(fp, iotype) \
2c2d71f5 1692 (PerlLIO_setmode(PerlIO_fileno(fp), O_BINARY) != -1 ? TRUE : FALSE)
5aabfad6
PP
1693#endif
1694
cea2e8a9
GS
1695#ifdef UNION_ANY_DEFINITION
1696UNION_ANY_DEFINITION;
1697#else
1698union any {
1699 void* any_ptr;
1700 I32 any_i32;
1701 IV any_iv;
1702 long any_long;
c76ac1ee
GS
1703 void (*any_dptr) (void*);
1704 void (*any_dxptr) (pTHXo_ void*);
cea2e8a9
GS
1705};
1706#endif
1707
1708#ifdef USE_THREADS
1709#define ARGSproto struct perl_thread *thr
1710#else
1711#define ARGSproto
1712#endif /* USE_THREADS */
1713
0cb96387 1714typedef I32 (*filter_t) (pTHXo_ int, SV *, int);
cea2e8a9
GS
1715
1716#define FILTER_READ(idx, sv, len) filter_read(idx, sv, len)
1717#define FILTER_DATA(idx) (AvARRAY(PL_rsfp_filters)[idx])
1718#define FILTER_ISREADER(idx) (idx >= AvFILLp(PL_rsfp_filters))
1719
2c2d71f5
JH
1720#if !defined(OS2)
1721# include "iperlsys.h"
1722#endif
378cc40b 1723#include "regexp.h"
79072805 1724#include "sv.h"
378cc40b 1725#include "util.h"
8d063cd8 1726#include "form.h"
79072805
LW
1727#include "gv.h"
1728#include "cv.h"
abdd5c84 1729#include "opnames.h"
79072805
LW
1730#include "op.h"
1731#include "cop.h"
1732#include "av.h"
1733#include "hv.h"
1734#include "mg.h"
1735#include "scope.h"
4438c4b7 1736#include "warnings.h"
a0ed51b3 1737#include "utf8.h"
8d063cd8 1738
7fae4e64
GS
1739/* Current curly descriptor */
1740typedef struct curcur CURCUR;
1741struct curcur {
1742 int parenfloor; /* how far back to strip paren data */
1743 int cur; /* how many instances of scan we've matched */
1744 int min; /* the minimal number of scans to match */
1745 int max; /* the maximal number of scans to match */
1746 int minmod; /* whether to work our way up or down */
1747 regnode * scan; /* the thing to match */
1748 regnode * next; /* what has to match after it */
1749 char * lastloc; /* where we started matching this scan */
1750 CURCUR * oldcc; /* current curly before we started this one */
1751};
1752
1753typedef struct _sublex_info SUBLEXINFO;
1754struct _sublex_info {
1755 I32 super_state; /* lexer state to save */
1756 I32 sub_inwhat; /* "lex_inwhat" to use */
1757 OP *sub_op; /* "lex_op" to use */
0244c3a4
GS
1758 char *super_bufptr; /* PL_bufptr that was */
1759 char *super_bufend; /* PL_bufend that was */
7fae4e64
GS
1760};
1761
455ece5e 1762typedef struct magic_state MGS; /* struct magic_state defined in mg.c */
76e3520e 1763
2c2d71f5 1764struct scan_data_t; /* Used in S_* functions in regcomp.c */
653099ff 1765struct regnode_charclass_class; /* Used in S_* functions in regcomp.c */
76e3520e
GS
1766
1767typedef I32 CHECKPOINT;
76e3520e 1768
5f7fde29
GS
1769struct ptr_tbl_ent {
1770 struct ptr_tbl_ent* next;
1771 void* oldval;
1772 void* newval;
d18c6117
GS
1773};
1774
5f7fde29
GS
1775struct ptr_tbl {
1776 struct ptr_tbl_ent** tbl_ary;
1777 UV tbl_max;
1778 UV tbl_items;
d18c6117
GS
1779};
1780
450a55e4 1781#if defined(iAPX286) || defined(M_I286) || defined(I80286)
a687059c
LW
1782# define I286
1783#endif
1784
fe14fcc3
LW
1785#if defined(htonl) && !defined(HAS_HTONL)
1786#define HAS_HTONL
ae986130 1787#endif
fe14fcc3
LW
1788#if defined(htons) && !defined(HAS_HTONS)
1789#define HAS_HTONS
ae986130 1790#endif
fe14fcc3
LW
1791#if defined(ntohl) && !defined(HAS_NTOHL)
1792#define HAS_NTOHL
ae986130 1793#endif
fe14fcc3
LW
1794#if defined(ntohs) && !defined(HAS_NTOHS)
1795#define HAS_NTOHS
ae986130 1796#endif
fe14fcc3 1797#ifndef HAS_HTONL
d9d8d8de 1798#if (BYTEORDER & 0xffff) != 0x4321
fe14fcc3
LW
1799#define HAS_HTONS
1800#define HAS_HTONL
1801#define HAS_NTOHS
1802#define HAS_NTOHL
a687059c
LW
1803#define MYSWAP
1804#define htons my_swap
1805#define htonl my_htonl
1806#define ntohs my_swap
1807#define ntohl my_ntohl
1808#endif
1809#else
d9d8d8de 1810#if (BYTEORDER & 0xffff) == 0x4321
fe14fcc3
LW
1811#undef HAS_HTONS
1812#undef HAS_HTONL
1813#undef HAS_NTOHS
1814#undef HAS_NTOHL
a687059c
LW
1815#endif
1816#endif
1817
988174c1
LW
1818/*
1819 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
1820 * -DWS
1821 */
1822#if BYTEORDER != 0x1234
1823# define HAS_VTOHL
1824# define HAS_VTOHS
1825# define HAS_HTOVL
1826# define HAS_HTOVS
c67712b2 1827# if BYTEORDER == 0x4321 || BYTEORDER == 0x87654321
988174c1
LW
1828# define vtohl(x) ((((x)&0xFF)<<24) \
1829 +(((x)>>24)&0xFF) \
1830 +(((x)&0x0000FF00)<<8) \
1831 +(((x)&0x00FF0000)>>8) )
1832# define vtohs(x) ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
1833# define htovl(x) vtohl(x)
1834# define htovs(x) vtohs(x)
1835# endif
1836 /* otherwise default to functions in util.c */
1837#endif
1838
0f85fab0 1839#ifdef CASTNEGFLOAT
79072805 1840#define U_S(what) ((U16)(what))
0f85fab0 1841#define U_I(what) ((unsigned int)(what))
79072805 1842#define U_L(what) ((U32)(what))
0f85fab0 1843#else
65202027
DS
1844#define U_S(what) ((U16)cast_ulong((NV)(what)))
1845#define U_I(what) ((unsigned int)cast_ulong((NV)(what)))
1846#define U_L(what) (cast_ulong((NV)(what)))
ee0007ab
LW
1847#endif
1848
ed6116ce
LW
1849#ifdef CASTI32
1850#define I_32(what) ((I32)(what))
a0d0e21e 1851#define I_V(what) ((IV)(what))
5d94fbed 1852#define U_V(what) ((UV)(what))
ed6116ce 1853#else
65202027
DS
1854#define I_32(what) (cast_i32((NV)(what)))
1855#define I_V(what) (cast_iv((NV)(what)))
1856#define U_V(what) (cast_uv((NV)(what)))
ed6116ce
LW
1857#endif
1858
2d4389e4
JH
1859/* These do not care about the fractional part, only about the range. */
1860#define NV_WITHIN_IV(nv) (I_V(nv) >= IV_MIN && I_V(nv) <= IV_MAX)
24db6c0d 1861#define NV_WITHIN_UV(nv) ((nv)>=0.0 && U_V(nv) >= UV_MIN && U_V(nv) <= UV_MAX)
2d4389e4 1862
25da4f38
IZ
1863/* Used with UV/IV arguments: */
1864 /* XXXX: need to speed it up */
1865#define CLUMP_2UV(iv) ((iv) < 0 ? 0 : (UV)(iv))
1866#define CLUMP_2IV(uv) ((uv) > (UV)IV_MAX ? IV_MAX : (IV)(uv))
1867
352d5a3a
LW
1868#ifndef MAXSYSFD
1869# define MAXSYSFD 2
1870#endif
ee0007ab 1871
79072805 1872#ifndef __cplusplus
20ce7b12
GS
1873Uid_t getuid (void);
1874Uid_t geteuid (void);
1875Gid_t getgid (void);
1876Gid_t getegid (void);
79072805 1877#endif
8d063cd8 1878
0c30d9ec 1879#ifndef Perl_debug_log
bf49b057
GS
1880# define Perl_debug_log PerlIO_stderr()
1881#endif
1882
1883#ifndef Perl_error_log
1884# define Perl_error_log (PL_stderrgv \
42de951c 1885 && IoOFP(GvIOp(PL_stderrgv)) \
bf49b057
GS
1886 ? IoOFP(GvIOp(PL_stderrgv)) \
1887 : PerlIO_stderr())
0c30d9ec 1888#endif
3967c732
JD
1889
1890#ifdef DEBUGGING
9d116dd7 1891#undef YYDEBUG
d96024cf 1892#define YYDEBUG 1
79072805 1893#define DEB(a) a
3280af22
NIS
1894#define DEBUG(a) if (PL_debug) a
1895#define DEBUG_p(a) if (PL_debug & 1) a
1896#define DEBUG_s(a) if (PL_debug & 2) a
1897#define DEBUG_l(a) if (PL_debug & 4) a
1898#define DEBUG_t(a) if (PL_debug & 8) a
1899#define DEBUG_o(a) if (PL_debug & 16) a
1900#define DEBUG_c(a) if (PL_debug & 32) a
1901#define DEBUG_P(a) if (PL_debug & 64) a
0672f40e 1902# if defined(PERL_OBJECT)
c850101c
JD
1903# define DEBUG_m(a) if (PL_debug & 128) a
1904# else
0b250b9e
GS
1905# define DEBUG_m(a) \
1906 STMT_START { \
1907 if (PERL_GET_INTERP) { dTHX; if (PL_debug & 128) { a; } } \
1908 } STMT_END
c850101c 1909# endif
3280af22
NIS
1910#define DEBUG_f(a) if (PL_debug & 256) a
1911#define DEBUG_r(a) if (PL_debug & 512) a
1912#define DEBUG_x(a) if (PL_debug & 1024) a
1913#define DEBUG_u(a) if (PL_debug & 2048) a
1914#define DEBUG_L(a) if (PL_debug & 4096) a
1915#define DEBUG_H(a) if (PL_debug & 8192) a
1916#define DEBUG_X(a) if (PL_debug & 16384) a
1917#define DEBUG_D(a) if (PL_debug & 32768) a
8b73bbec
IZ
1918# ifdef USE_THREADS
1919# define DEBUG_S(a) if (PL_debug & (1<<16)) a
1920# else
1921# define DEBUG_S(a)
1922# endif
79072805
LW
1923#else
1924#define DEB(a)
1925#define DEBUG(a)
1926#define DEBUG_p(a)
1927#define DEBUG_s(a)
1928#define DEBUG_l(a)
1929#define DEBUG_t(a)
1930#define DEBUG_o(a)
1931#define DEBUG_c(a)
1932#define DEBUG_P(a)
1933#define DEBUG_m(a)
1934#define DEBUG_f(a)
1935#define DEBUG_r(a)
1936#define DEBUG_x(a)
1937#define DEBUG_u(a)
8b73bbec 1938#define DEBUG_S(a)
79072805
LW
1939#define DEBUG_H(a)
1940#define DEBUG_X(a)
8990e307 1941#define DEBUG_D(a)
8b73bbec 1942#define DEBUG_S(a)
8d063cd8 1943#endif
fe14fcc3 1944#define YYMAXDEPTH 300
8d063cd8 1945
a6e633de 1946#ifndef assert /* <assert.h> might have been included somehow */
79072805
LW
1947#define assert(what) DEB( { \
1948 if (!(what)) { \
cea2e8a9 1949 Perl_croak(aTHX_ "Assertion failed: file \"%s\", line %d", \
79072805 1950 __FILE__, __LINE__); \
cea2e8a9 1951 PerlProc_exit(1); \
79072805 1952 }})
a6e633de 1953#endif
8d063cd8 1954
450a55e4 1955struct ufuncs {
20ce7b12
GS
1956 I32 (*uf_val)(IV, SV*);
1957 I32 (*uf_set)(IV, SV*);
a0d0e21e 1958 IV uf_index;
450a55e4
LW
1959};
1960
fe14fcc3 1961/* Fix these up for __STDC__ */
68dc0745 1962#ifndef DONT_DECLARE_STD
20ce7b12 1963char *mktemp (char*);
37bd1396 1964#ifndef atof
20ce7b12 1965double atof (const char*);
a0d0e21e 1966#endif
37bd1396 1967#endif
79072805 1968
352d5a3a 1969#ifndef STANDARD_C
fe14fcc3 1970/* All of these are in stdlib.h or time.h for ANSI C */
85e6fe83 1971Time_t time();
8d063cd8 1972struct tm *gmtime(), *localtime();
092bebab 1973#if defined(OEMVS) || defined(__OPEN_VM)
9d116dd7
JH
1974char *(strchr)(), *(strrchr)();
1975char *(strcpy)(), *(strcat)();
1976#else
93a17b20 1977char *strchr(), *strrchr();
378cc40b 1978char *strcpy(), *strcat();
9d116dd7 1979#endif
352d5a3a 1980#endif /* ! STANDARD_C */
8d063cd8 1981
79072805
LW
1982
1983#ifdef I_MATH
1984# include <math.h>
1985#else
32f822de 1986START_EXTERN_C
20ce7b12
GS
1987 double exp (double);
1988 double log (double);
1989 double log10 (double);
1990 double sqrt (double);
1991 double frexp (double,int*);
1992 double ldexp (double,int);
1993 double modf (double,double*);
1994 double sin (double);
1995 double cos (double);
1996 double atan2 (double,double);
1997 double pow (double,double);
32f822de 1998END_EXTERN_C
79072805
LW
1999#endif
2000
a0d0e21e 2001#ifndef __cplusplus
8f1f23e8 2002# if defined(NeXT) || defined(__NeXT__) /* or whatever catches all NeXTs */
3fc1aec6 2003char *crypt (); /* Maybe more hosts will need the unprototyped version */
26618a56 2004# else
5014db98 2005# if !defined(WIN32)
20ce7b12 2006char *crypt (const char*, const char*);
5014db98 2007# endif /* !WIN32 */
8f1f23e8 2008# endif /* !NeXT && !__NeXT__ */
26618a56
GS
2009# ifndef DONT_DECLARE_STD
2010# ifndef getenv
20ce7b12 2011char *getenv (const char*);
26618a56 2012# endif /* !getenv */
4d2c4e07 2013#ifndef EPOC
20ce7b12 2014Off_t lseek (int,Off_t,int);
4d2c4e07 2015#endif
26618a56 2016# endif /* !DONT_DECLARE_STD */
20ce7b12 2017char *getlogin (void);
26618a56 2018#endif /* !__cplusplus */
79072805 2019
16d20bd9 2020#ifdef UNLINK_ALL_VERSIONS /* Currently only makes sense for VMS */
378cc40b 2021#define UNLINK unlnk
20ce7b12 2022I32 unlnk (char*);
8d063cd8 2023#else
80252599 2024#define UNLINK PerlLIO_unlink
8d063cd8 2025#endif
a687059c 2026
fe14fcc3 2027#ifndef HAS_SETREUID
85e6fe83
LW
2028# ifdef HAS_SETRESUID
2029# define setreuid(r,e) setresuid(r,e,(Uid_t)-1)
2030# define HAS_SETREUID
2031# endif
a687059c 2032#endif
fe14fcc3 2033#ifndef HAS_SETREGID
85e6fe83
LW
2034# ifdef HAS_SETRESGID
2035# define setregid(r,e) setresgid(r,e,(Gid_t)-1)
2036# define HAS_SETREGID
2037# endif
a687059c 2038#endif
ee0007ab 2039
d543acb6 2040/* Sighandler_t defined in iperlsys.h */
ff68c719
PP
2041
2042#ifdef HAS_SIGACTION
2043typedef struct sigaction Sigsave_t;
2044#else
2045typedef Sighandler_t Sigsave_t;
2046#endif
2047
ee0007ab
LW
2048#define SCAN_DEF 0
2049#define SCAN_TR 1
2050#define SCAN_REPL 2
79072805
LW
2051
2052#ifdef DEBUGGING
4633a7c4 2053# ifndef register
a0d0e21e
LW
2054# define register
2055# endif
2056# define PAD_SV(po) pad_sv(po)
cea2e8a9 2057# define RUNOPS_DEFAULT Perl_runops_debug
79072805 2058#else
6b88bc9c 2059# define PAD_SV(po) PL_curpad[po]
cea2e8a9 2060# define RUNOPS_DEFAULT Perl_runops_standard
79072805
LW
2061#endif
2062
18f739ee 2063#ifdef MYMALLOC
772fe5b3 2064# ifdef MUTEX_INIT_CALLS_MALLOC
3541dd58
HM
2065# define MALLOC_INIT \
2066 STMT_START { \
2067 PL_malloc_mutex = NULL; \
2068 MUTEX_INIT(&PL_malloc_mutex); \
2069 } STMT_END
2070# define MALLOC_TERM \
2071 STMT_START { \
2072 perl_mutex tmp = PL_malloc_mutex; \
2073 PL_malloc_mutex = NULL; \
2074 MUTEX_DESTROY(&tmp); \
2075 } STMT_END
2076# else
2077# define MALLOC_INIT MUTEX_INIT(&PL_malloc_mutex)
2078# define MALLOC_TERM MUTEX_DESTROY(&PL_malloc_mutex)
2079# endif
18f739ee
IZ
2080#else
2081# define MALLOC_INIT
2082# define MALLOC_TERM
2083#endif
2084
b6d9d515 2085
0cb96387
GS
2086typedef int (CPERLscope(*runops_proc_t)) (pTHX);
2087typedef OP* (CPERLscope(*PPADDR_t)[]) (pTHX);
22c35a8c 2088
940cb80d 2089/* _ (for $_) must be first in the following list (DEFSV requires it) */
54b9620d 2090#define THREADSV_NAMES "_123456789&`'+/.,\\\";^-%=|~:\001\005!@"
a863c7d1 2091
8f1f23e8
W
2092/* NeXT has problems with crt0.o globals */
2093#if defined(__DYNAMIC__) && \
2094 (defined(NeXT) || defined(__NeXT__) || defined(__APPLE__))
2095# if defined(NeXT) || defined(__NeXT)
2096# include <mach-o/dyld.h>
2097# define environ (*environ_pointer)
0c30d9ec 2098EXT char *** environ_pointer;
8f1f23e8
W
2099# else
2100# if defined(__APPLE__)
2101# include <crt_externs.h> /* for the env array */
2102# define environ (*_NSGetEnviron())
2103# endif
0c30d9ec 2104# endif
8f1f23e8
W
2105#else
2106 /* VMS and some other platforms don't use the environ array */
a6c40364
GS
2107# if !defined(VMS)
2108# if !defined(DONT_DECLARE_STD) || \
2109 (defined(__svr4__) && defined(__GNUC__) && defined(sun)) || \
2110 defined(__sgi) || \
4d2c4e07 2111 defined(__DGUX) || defined(EPOC)
8f1f23e8 2112extern char ** environ; /* environment variables supplied via exec */
a6c40364 2113# endif
8f1f23e8
W
2114# endif
2115#endif
79072805 2116
73c4f7a1
GS
2117START_EXTERN_C
2118
79072805 2119/* handy constants */
22c35a8c 2120EXTCONST char PL_warn_uninit[]
b89fed5f 2121 INIT("Use of uninitialized value%s%s");
22c35a8c 2122EXTCONST char PL_warn_nosemi[]
463ee0b2 2123 INIT("Semicolon seems to be missing");
22c35a8c 2124EXTCONST char PL_warn_reserved[]
463ee0b2 2125 INIT("Unquoted string \"%s\" may clash with future reserved word");
22c35a8c 2126EXTCONST char PL_warn_nl[]
93a17b20 2127 INIT("Unsuccessful %s on filename containing newline");
22c35a8c 2128EXTCONST char PL_no_wrongref[]
a0d0e21e 2129 INIT("Can't use %s ref as %s ref");
22c35a8c 2130EXTCONST char PL_no_symref[]
748a9306 2131 INIT("Can't use string (\"%.32s\") as %s ref while \"strict refs\" in use");
22c35a8c 2132EXTCONST char PL_no_usym[]
8990e307 2133 INIT("Can't use an undefined value as %s reference");
22c35a8c 2134EXTCONST char PL_no_aelem[]
93a17b20 2135 INIT("Modification of non-creatable array value attempted, subscript %d");
22c35a8c 2136EXTCONST char PL_no_helem[]
93a17b20 2137 INIT("Modification of non-creatable hash value attempted, subscript \"%s\"");
22c35a8c 2138EXTCONST char PL_no_modify[]
93a17b20 2139 INIT("Modification of a read-only value attempted");
22c35a8c 2140EXTCONST char PL_no_mem[]
93a17b20 2141 INIT("Out of memory!\n");
22c35a8c 2142EXTCONST char PL_no_security[]
463ee0b2 2143 INIT("Insecure dependency in %s%s");
22c35a8c 2144EXTCONST char PL_no_sock_func[]
93a17b20 2145 INIT("Unsupported socket function \"%s\" called");
22c35a8c 2146EXTCONST char PL_no_dir_func[]
93a17b20 2147 INIT("Unsupported directory function \"%s\" called");
22c35a8c 2148EXTCONST char PL_no_func[]
93a17b20 2149 INIT("The %s function is unimplemented");
22c35a8c 2150EXTCONST char PL_no_myglob[]
748a9306 2151 INIT("\"my\" variable %s can't be in a package");
93a17b20 2152
7575fa06 2153EXTCONST char PL_uuemap[65]
80252599
GS
2154 INIT("`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_");
2155
2156
79072805 2157#ifdef DOINIT
22c35a8c
GS
2158EXT char *PL_sig_name[] = { SIG_NAME };
2159EXT int PL_sig_num[] = { SIG_NUM };
79072805 2160#else
22c35a8c
GS
2161EXT char *PL_sig_name[];
2162EXT int PL_sig_num[];
79072805
LW
2163#endif
2164
bbce6d69
PP
2165/* fast case folding tables */
2166
79072805 2167#ifdef DOINIT
9d116dd7 2168#ifdef EBCDIC
22c35a8c 2169EXT unsigned char PL_fold[] = { /* fast EBCDIC case folding table */
9d116dd7
JH
2170 0, 1, 2, 3, 4, 5, 6, 7,
2171 8, 9, 10, 11, 12, 13, 14, 15,
2172 16, 17, 18, 19, 20, 21, 22, 23,
2173 24, 25, 26, 27, 28, 29, 30, 31,
2174 32, 33, 34, 35, 36, 37, 38, 39,
2175 40, 41, 42, 43, 44, 45, 46, 47,
2176 48, 49, 50, 51, 52, 53, 54, 55,
2177 56, 57, 58, 59, 60, 61, 62, 63,
2178 64, 65, 66, 67, 68, 69, 70, 71,
2179 72, 73, 74, 75, 76, 77, 78, 79,
2180 80, 81, 82, 83, 84, 85, 86, 87,
2181 88, 89, 90, 91, 92, 93, 94, 95,
2182 96, 97, 98, 99, 100, 101, 102, 103,
2183 104, 105, 106, 107, 108, 109, 110, 111,
2184 112, 113, 114, 115, 116, 117, 118, 119,
2185 120, 121, 122, 123, 124, 125, 126, 127,
2186 128, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
2187 'H', 'I', 138, 139, 140, 141, 142, 143,
2188 144, 'J', 'K', 'L', 'M', 'N', 'O', 'P',
2189 'Q', 'R', 154, 155, 156, 157, 158, 159,
2190 160, 161, 'S', 'T', 'U', 'V', 'W', 'X',
2191 'Y', 'Z', 170, 171, 172, 173, 174, 175,
2192 176, 177, 178, 179, 180, 181, 182, 183,
2193 184, 185, 186, 187, 188, 189, 190, 191,
2194 192, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
2195 'h', 'i', 202, 203, 204, 205, 206, 207,
2196 208, 'j', 'k', 'l', 'm', 'n', 'o', 'p',
2197 'q', 'r', 218, 219, 220, 221, 222, 223,
2198 224, 225, 's', 't', 'u', 'v', 'w', 'x',
2199 'y', 'z', 234, 235, 236, 237, 238, 239,
2200 240, 241, 242, 243, 244, 245, 246, 247,
2201 248, 249, 250, 251, 252, 253, 254, 255
2202};
2203#else /* ascii rather than ebcdic */
22c35a8c 2204EXTCONST unsigned char PL_fold[] = {
79072805
LW
2205 0, 1, 2, 3, 4, 5, 6, 7,
2206 8, 9, 10, 11, 12, 13, 14, 15,
2207 16, 17, 18, 19, 20, 21, 22, 23,
2208 24, 25, 26, 27, 28, 29, 30, 31,
2209 32, 33, 34, 35, 36, 37, 38, 39,
2210 40, 41, 42, 43, 44, 45, 46, 47,
2211 48, 49, 50, 51, 52, 53, 54, 55,
2212 56, 57, 58, 59, 60, 61, 62, 63,
2213 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
2214 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
2215 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
2216 'x', 'y', 'z', 91, 92, 93, 94, 95,
2217 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
2218 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
2219 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
2220 'X', 'Y', 'Z', 123, 124, 125, 126, 127,
2221 128, 129, 130, 131, 132, 133, 134, 135,
2222 136, 137, 138, 139, 140, 141, 142, 143,
2223 144, 145, 146, 147, 148, 149, 150, 151,
2224 152, 153, 154, 155, 156, 157, 158, 159,
2225 160, 161, 162, 163, 164, 165, 166, 167,
2226 168, 169, 170, 171, 172, 173, 174, 175,
2227 176, 177, 178, 179, 180, 181, 182, 183,
2228 184, 185, 186, 187, 188, 189, 190, 191,
2229 192, 193, 194, 195, 196, 197, 198, 199,
2230 200, 201, 202, 203, 204, 205, 206, 207,
2231 208, 209, 210, 211, 212, 213, 214, 215,
2232 216, 217, 218, 219, 220, 221, 222, 223,
2233 224, 225, 226, 227, 228, 229, 230, 231,
2234 232, 233, 234, 235, 236, 237, 238, 239,
2235 240, 241, 242, 243, 244, 245, 246, 247,
2236 248, 249, 250, 251, 252, 253, 254, 255
2237};
9d116dd7 2238#endif /* !EBCDIC */
79072805 2239#else
22c35a8c 2240EXTCONST unsigned char PL_fold[];
79072805
LW
2241#endif
2242
2243#ifdef DOINIT
22c35a8c 2244EXT unsigned char PL_fold_locale[] = {
79072805
LW
2245 0, 1, 2, 3, 4, 5, 6, 7,
2246 8, 9, 10, 11, 12, 13, 14, 15,
2247 16, 17, 18, 19, 20, 21, 22, 23,
2248 24, 25, 26, 27, 28, 29, 30, 31,
2249 32, 33, 34, 35, 36, 37, 38, 39,
2250 40, 41, 42, 43, 44, 45, 46, 47,
2251 48, 49, 50, 51, 52, 53, 54, 55,
2252 56, 57, 58, 59, 60, 61, 62, 63,
2253 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
2254 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
2255 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
2256 'x', 'y', 'z', 91, 92, 93, 94, 95,
2257 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
2258 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
2259 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
2260 'X', 'Y', 'Z', 123, 124, 125, 126, 127,
2261 128, 129, 130, 131, 132, 133, 134, 135,
2262 136, 137, 138, 139, 140, 141, 142, 143,
2263 144, 145, 146, 147, 148, 149, 150, 151,
2264 152, 153, 154, 155, 156, 157, 158, 159,
2265 160, 161, 162, 163, 164, 165, 166, 167,
2266 168, 169, 170, 171, 172, 173, 174, 175,
2267 176, 177, 178, 179, 180, 181, 182, 183,
2268 184, 185, 186, 187, 188, 189, 190, 191,
2269 192, 193, 194, 195, 196, 197, 198, 199,
2270 200, 201, 202, 203, 204, 205, 206, 207,
2271 208, 209, 210, 211, 212, 213, 214, 215,
2272 216, 217, 218, 219, 220, 221, 222, 223,
2273 224, 225, 226, 227, 228, 229, 230, 231,
2274 232, 233, 234, 235, 236, 237, 238, 239,
2275 240, 241, 242, 243, 244, 245, 246, 247,
2276 248, 249, 250, 251, 252, 253, 254, 255
2277};
2278#else
22c35a8c 2279EXT unsigned char PL_fold_locale[];
79072805
LW
2280#endif
2281
2282#ifdef DOINIT
9d116dd7 2283#ifdef EBCDIC
22c35a8c 2284EXT unsigned char PL_freq[] = {/* EBCDIC frequencies for mixed English/C */
9d116dd7
JH
2285 1, 2, 84, 151, 154, 155, 156, 157,
2286 165, 246, 250, 3, 158, 7, 18, 29,
2287 40, 51, 62, 73, 85, 96, 107, 118,
2288 129, 140, 147, 148, 149, 150, 152, 153,
2289 255, 6, 8, 9, 10, 11, 12, 13,
2290 14, 15, 24, 25, 26, 27, 28, 226,
2291 29, 30, 31, 32, 33, 43, 44, 45,
2292 46, 47, 48, 49, 50, 76, 77, 78,
2293 79, 80, 81, 82, 83, 84, 85, 86,
2294 87, 94, 95, 234, 181, 233, 187, 190,
2295 180, 96, 97, 98, 99, 100, 101, 102,
2296 104, 112, 182, 174, 236, 232, 229, 103,
2297 228, 226, 114, 115, 116, 117, 118, 119,
2298 120, 121, 122, 235, 176, 230, 194, 162,
2299 130, 131, 132, 133, 134, 135, 136, 137,
2300 138, 139, 201, 205, 163, 217, 220, 224,
2301 5, 248, 227, 244, 242, 255, 241, 231,
2302 240, 253, 16, 197, 19, 20, 21, 187,
2303 23, 169, 210, 245, 237, 249, 247, 239,
2304 168, 252, 34, 196, 36, 37, 38, 39,
2305 41, 42, 251, 254, 238, 223, 221, 213,
2306 225, 177, 52, 53, 54, 55, 56, 57,
2307 58, 59, 60, 61, 63, 64, 65, 66,
2308 67, 68, 69, 70, 71, 72, 74, 75,
2309 205, 208, 186, 202, 200, 218, 198, 179,
2310 178, 214, 88, 89, 90, 91, 92, 93,
2311 217, 166, 170, 207, 199, 209, 206, 204,
2312 160, 212, 105, 106, 108, 109, 110, 111,
2313 203, 113, 216, 215, 192, 175, 193, 243,
2314 172, 161, 123, 124, 125, 126, 127, 128,
2315 222, 219, 211, 195, 188, 193, 185, 184,
2316 191, 183, 141, 142, 143, 144, 145, 146
2317};
2318#else /* ascii rather than ebcdic */
22c35a8c 2319EXTCONST unsigned char PL_freq[] = { /* letter frequencies for mixed English/C */
79072805
LW
2320 1, 2, 84, 151, 154, 155, 156, 157,
2321 165, 246, 250, 3, 158, 7, 18, 29,
2322 40, 51, 62, 73, 85, 96, 107, 118,
2323 129, 140, 147, 148, 149, 150, 152, 153,
2324 255, 182, 224, 205, 174, 176, 180, 217,
2325 233, 232, 236, 187, 235, 228, 234, 226,
2326 222, 219, 211, 195, 188, 193, 185, 184,
2327 191, 183, 201, 229, 181, 220, 194, 162,
2328 163, 208, 186, 202, 200, 218, 198, 179,
2329 178, 214, 166, 170, 207, 199, 209, 206,
2330 204, 160, 212, 216, 215, 192, 175, 173,
2331 243, 172, 161, 190, 203, 189, 164, 230,
2332 167, 248, 227, 244, 242, 255, 241, 231,
2333 240, 253, 169, 210, 245, 237, 249, 247,
2334 239, 168, 252, 251, 254, 238, 223, 221,
2335 213, 225, 177, 197, 171, 196, 159, 4,
2336 5, 6, 8, 9, 10, 11, 12, 13,
2337 14, 15, 16, 17, 19, 20, 21, 22,
2338 23, 24, 25, 26, 27, 28, 30, 31,
2339 32, 33, 34, 35, 36, 37, 38, 39,
2340 41, 42, 43, 44, 45, 46, 47, 48,
2341 49, 50, 52, 53, 54, 55, 56, 57,
2342 58, 59, 60, 61, 63, 64, 65, 66,
2343 67, 68, 69, 70, 71, 72, 74, 75,
2344 76, 77, 78, 79, 80, 81, 82, 83,
2345 86, 87, 88, 89, 90, 91, 92, 93,
2346 94, 95, 97, 98, 99, 100, 101, 102,
2347 103, 104, 105, 106, 108, 109, 110, 111,
2348 112, 113, 114, 115, 116, 117, 119, 120,
2349 121, 122, 123, 124, 125, 126, 127, 128,
2350 130, 131, 132, 133, 134, 135, 136, 137,
2351 138, 139, 141, 142, 143, 144, 145, 146
2352};
9d116dd7 2353#endif
79072805 2354#else
22c35a8c 2355EXTCONST unsigned char PL_freq[];
79072805
LW
2356#endif
2357
8990e307
LW
2358#ifdef DEBUGGING
2359#ifdef DOINIT
22c35a8c 2360EXTCONST char* PL_block_type[] = {
8990e307
LW
2361 "NULL",
2362 "SUB",
2363 "EVAL",
2364 "LOOP",
2365 "SUBST",
2366 "BLOCK",
2367};
2368#else
22c35a8c 2369EXTCONST char* PL_block_type[];
8990e307
LW
2370#endif
2371#endif
2372
73c4f7a1
GS
2373END_EXTERN_C
2374
79072805
LW
2375/*****************************************************************************/
2376/* This lexer/parser stuff is currently global since yacc is hard to reenter */
2377/*****************************************************************************/
8990e307 2378/* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */
79072805 2379
a0d0e21e
LW
2380#include "perly.h"
2381
fb73857a
PP
2382#define LEX_NOTPARSING 11 /* borrowed from toke.c */
2383
79072805
LW
2384typedef enum {
2385 XOPERATOR,
2386 XTERM,
79072805 2387 XREF,
8990e307 2388 XSTATE,
a0d0e21e 2389 XBLOCK,
09bef843
SB
2390 XATTRBLOCK,
2391 XATTRTERM,
a0d0e21e 2392 XTERMBLOCK
79072805
LW
2393} expectation;
2394
dc9e4912
GS
2395enum { /* pass one of these to get_vtbl */
2396 want_vtbl_sv,
2397 want_vtbl_env,
2398 want_vtbl_envelem,
2399 want_vtbl_sig,
2400 want_vtbl_sigelem,
2401 want_vtbl_pack,
2402 want_vtbl_packelem,
2403 want_vtbl_dbline,
2404 want_vtbl_isa,
2405 want_vtbl_isaelem,
2406 want_vtbl_arylen,
2407 want_vtbl_glob,
2408 want_vtbl_mglob,
2409 want_vtbl_nkeys,
2410 want_vtbl_taint,
2411 want_vtbl_substr,
2412 want_vtbl_vec,
2413 want_vtbl_pos,
2414 want_vtbl_bm,
2415 want_vtbl_fm,
2416 want_vtbl_uvar,
2417 want_vtbl_defelem,
2418 want_vtbl_regexp,
2419 want_vtbl_collxfrm,
2420 want_vtbl_amagic,
2421 want_vtbl_amagicelem,
2422#ifdef USE_THREADS
2423 want_vtbl_mutex,
2424#endif
2425 want_vtbl_regdata,
810b8aa5
GS
2426 want_vtbl_regdatum,
2427 want_vtbl_backref
dc9e4912
GS
2428};
2429
85e6fe83
LW
2430 /* Note: the lowest 8 bits are reserved for
2431 stuffing into op->op_private */
f3aa04c2 2432#define HINT_PRIVATE_MASK 0x000000ff
85e6fe83
LW
2433#define HINT_INTEGER 0x00000001
2434#define HINT_STRICT_REFS 0x00000002
a0ed51b3
LW
2435/* #define HINT_notused4 0x00000004 */
2436#define HINT_UTF8 0x00000008
5bc28da9 2437#define HINT_BYTE 0x00000010
a0ed51b3 2438 /* Note: 20,40,80 used for NATIVE_HINTS */
85e6fe83
LW
2439
2440#define HINT_BLOCK_SCOPE 0x00000100
2441#define HINT_STRICT_SUBS 0x00000200
2442#define HINT_STRICT_VARS 0x00000400
bbce6d69 2443#define HINT_LOCALE 0x00000800
85e6fe83 2444
b3ac6de7
IZ
2445#define HINT_NEW_INTEGER 0x00001000
2446#define HINT_NEW_FLOAT 0x00002000
2447#define HINT_NEW_BINARY 0x00004000
2448#define HINT_NEW_STRING 0x00008000
2449#define HINT_NEW_RE 0x00010000
2450#define HINT_LOCALIZE_HH 0x00020000 /* %^H needs to be copied */
2451
b3eb6a9b 2452#define HINT_RE_TAINT 0x00100000
e4d48cc9 2453#define HINT_RE_EVAL 0x00200000
b3eb6a9b 2454
5ff3f7a4
GS
2455#define HINT_FILETEST_ACCESS 0x00400000
2456
d4cce5f1
NIS
2457/* Various states of an input record separator SV (rs, nrs) */
2458#define RsSNARF(sv) (! SvOK(sv))
af7d13df
G
2459#define RsSIMPLE(sv) (SvOK(sv) && (! SvPOK(sv) || SvCUR(sv)))
2460#define RsPARA(sv) (SvPOK(sv) && ! SvCUR(sv))
5b2b9c68 2461#define RsRECORD(sv) (SvROK(sv) && (SvIV(SvRV(sv)) > 0))
79072805 2462
56953603 2463/* Enable variables which are pointers to functions */
0cb96387
GS
2464typedef regexp*(CPERLscope(*regcomp_t)) (pTHX_ char* exp, char* xend, PMOP* pm);
2465typedef I32 (CPERLscope(*regexec_t)) (pTHX_ regexp* prog, char* stringarg,
2466 char* strend, char* strbeg, I32 minend,
2467 SV* screamer, void* data, U32 flags);
f722798b
IZ
2468typedef char* (CPERLscope(*re_intuit_start_t)) (pTHX_ regexp *prog, SV *sv,
2469 char *strpos, char *strend,
2470 U32 flags,
2471 struct re_scream_pos_data_s *d);
2472typedef SV* (CPERLscope(*re_intuit_string_t)) (pTHX_ regexp *prog);
2473typedef void (CPERLscope(*regfree_t)) (pTHX_ struct regexp* r);
56953603 2474
51371543
GS
2475#ifdef USE_PURE_BISON
2476int Perl_yylex(pTHX_ YYSTYPE *lvalp, int *lcharp);
2477#endif
2478
c76ac1ee 2479typedef void (*DESTRUCTORFUNC_NOCONTEXT_t) (void*);
51371543
GS
2480typedef void (*DESTRUCTORFUNC_t) (pTHXo_ void*);
2481typedef void (*SVFUNC_t) (pTHXo_ SV*);
2482typedef I32 (*SVCOMPARE_t) (pTHXo_ SV*, SV*);
2483typedef void (*XSINIT_t) (pTHXo);
2484typedef void (*ATEXIT_t) (pTHXo_ void*);
2485typedef void (*XSUBADDR_t) (pTHXo_ CV *);
15e52e56 2486
22239a37
NIS
2487/* Set up PERLVAR macros for populating structs */
2488#define PERLVAR(var,type) type var;
51371543 2489#define PERLVARA(var,n,type) type var[n];
22239a37 2490#define PERLVARI(var,type,init) type var;
3fe35a81 2491#define PERLVARIC(var,type,init) type var;
22239a37 2492
58a50f62
GS
2493/* Interpreter exitlist entry */
2494typedef struct exitlistentry {
0cb96387 2495 void (*fn) (pTHXo_ void*);
58a50f62
GS
2496 void *ptr;
2497} PerlExitListEntry;
2498
22239a37
NIS
2499#ifdef PERL_GLOBAL_STRUCT
2500struct perl_vars {
7766f137 2501# include "perlvars.h"
22239a37
NIS
2502};
2503
7766f137 2504# ifdef PERL_CORE
533c011a
NIS
2505EXT struct perl_vars PL_Vars;
2506EXT struct perl_vars *PL_VarsPtr INIT(&PL_Vars);
7766f137
GS
2507# else /* PERL_CORE */
2508# if !defined(__GNUC__) || !defined(WIN32)
22239a37 2509EXT
7766f137 2510# endif /* WIN32 */
533c011a 2511struct perl_vars *PL_VarsPtr;
7766f137
GS
2512# define PL_Vars (*((PL_VarsPtr) \
2513 ? PL_VarsPtr : (PL_VarsPtr = Perl_GetVars(aTHX))))
2514# endif /* PERL_CORE */
22239a37
NIS
2515#endif /* PERL_GLOBAL_STRUCT */
2516
7766f137 2517#if defined(MULTIPLICITY) || defined(PERL_OBJECT)
d4cce5f1
NIS
2518/* If we have multiple interpreters define a struct
2519 holding variables which must be per-interpreter
2520 If we don't have threads anything that would have
2521 be per-thread is per-interpreter.
2522*/
2523
79072805 2524struct interpreter {
7766f137
GS
2525# ifndef USE_THREADS
2526# include "thrdvar.h"
2527# endif
2528# include "intrpvar.h"
2529/*
2530 * The following is a buffer where new variables must
2531 * be defined to maintain binary compatibility with PERL_OBJECT
2532 */
2533PERLVARA(object_compatibility,30, char)
49f531da 2534};
d4cce5f1 2535
79072805 2536#else
49f531da
NIS
2537struct interpreter {
2538 char broiled;
2539};
7766f137 2540#endif /* MULTIPLICITY || PERL_OBJECT */
79072805 2541
d4cce5f1
NIS
2542#ifdef USE_THREADS
2543/* If we have threads define a struct with all the variables
2544 * that have to be per-thread
49f531da 2545 */
8023c3ce 2546
79072805 2547
49f531da 2548struct perl_thread {
49f531da 2549#include "thrdvar.h"
79072805 2550};
d4cce5f1 2551
22fae026
TM
2552typedef struct perl_thread *Thread;
2553
2554#else
2555typedef void *Thread;
22239a37
NIS
2556#endif
2557
2558/* Done with PERLVAR macros for now ... */
d4cce5f1 2559#undef PERLVAR
51371543 2560#undef PERLVARA
d4cce5f1 2561#undef PERLVARI
3fe35a81 2562#undef PERLVARIC
79072805 2563
22239a37 2564#include "thread.h"
79072805 2565#include "pp.h"
864dbfa3
GS
2566
2567#ifndef PERL_CALLCONV
2568# define PERL_CALLCONV
2569#endif
2570
864dbfa3
GS
2571#ifndef NEXT30_NO_ATTRIBUTE
2572# ifndef HASATTRIBUTE /* disable GNU-cc attribute checking? */
2573# ifdef __attribute__ /* Avoid possible redefinition errors */
2574# undef __attribute__
2575# endif
2576# define __attribute__(attr)
2577# endif
2578#endif
2579
0cb96387 2580#ifdef PERL_OBJECT
7766f137 2581# define PERL_DECL_PROT
0cb96387 2582#endif
864dbfa3 2583
0cb96387
GS
2584#undef PERL_CKDEF
2585#undef PERL_PPDEF
2586#define PERL_CKDEF(s) OP *s (pTHX_ OP *o);
2587#define PERL_PPDEF(s) OP *s (pTHX);
0cb96387 2588
7766f137 2589#include "proto.h"
864dbfa3 2590
0cb96387 2591#ifdef PERL_OBJECT
7766f137 2592# undef PERL_DECL_PROT
0cb96387
GS
2593#endif
2594
864dbfa3 2595#ifndef PERL_OBJECT
0cb96387
GS
2596/* this has structure inits, so it cannot be included before here */
2597# include "opcode.h"
864dbfa3
GS
2598#endif
2599
d4cce5f1
NIS
2600/* The following must follow proto.h as #defines mess up syntax */
2601
22c35a8c
GS
2602#if !defined(PERL_FOR_X2P)
2603# include "embedvar.h"
2604#endif
d4cce5f1
NIS
2605
2606/* Now include all the 'global' variables
2607 * If we don't have threads or multiple interpreters
2608 * these include variables that would have been their struct-s
2609 */
533c011a
NIS
2610
2611#define PERLVAR(var,type) EXT type PL_##var;
51371543 2612#define PERLVARA(var,n,type) EXT type PL_##var[n];
533c011a
NIS
2613#define PERLVARI(var,type,init) EXT type PL_##var INIT(init);
2614#define PERLVARIC(var,type,init) EXTCONST type PL_##var INIT(init);
d4cce5f1 2615
7766f137
GS
2616#if !defined(MULTIPLICITY) && !defined(PERL_OBJECT)
2617START_EXTERN_C
066ef5b5
GS
2618# include "intrpvar.h"
2619# ifndef USE_THREADS
2620# include "thrdvar.h"
2621# endif
7766f137 2622END_EXTERN_C
22239a37
NIS
2623#endif
2624
76e3520e 2625#ifdef PERL_OBJECT
22c35a8c 2626# include "embed.h"
76e3520e 2627
22c35a8c
GS
2628# ifdef DOINIT
2629# include "INTERN.h"
2630# else
2631# include "EXTERN.h"
2632# endif
2633
2634/* this has structure inits, so it cannot be included before here */
2635# include "opcode.h"
2636
d18c6117
GS
2637#else
2638# if defined(WIN32)
2639# include "embed.h"
2640# endif
22c35a8c 2641#endif /* PERL_OBJECT */
22239a37 2642
c5be433b
GS
2643#ifndef PERL_GLOBAL_STRUCT
2644START_EXTERN_C
2645
2646# include "perlvars.h"
2647
2648END_EXTERN_C
2649#endif
2650
d4cce5f1 2651#undef PERLVAR
51371543 2652#undef PERLVARA
d4cce5f1 2653#undef PERLVARI
0f3f18a6 2654#undef PERLVARIC
79072805 2655
73c4f7a1
GS
2656START_EXTERN_C
2657
79072805 2658#ifdef DOINIT
bbce6d69 2659
2b260de0
GS
2660EXT MGVTBL PL_vtbl_sv = {MEMBER_TO_FPTR(Perl_magic_get),
2661 MEMBER_TO_FPTR(Perl_magic_set),
2662 MEMBER_TO_FPTR(Perl_magic_len),
463ee0b2 2663 0, 0};
2b260de0
GS
2664EXT MGVTBL PL_vtbl_env = {0, MEMBER_TO_FPTR(Perl_magic_set_all_env),
2665 0, MEMBER_TO_FPTR(Perl_magic_clear_all_env),
66b1d557 2666 0};
2b260de0
GS
2667EXT MGVTBL PL_vtbl_envelem = {0, MEMBER_TO_FPTR(Perl_magic_setenv),
2668 0, MEMBER_TO_FPTR(Perl_magic_clearenv),
85e6fe83 2669 0};
22c35a8c 2670EXT MGVTBL PL_vtbl_sig = {0, 0, 0, 0, 0};
2b260de0
GS
2671EXT MGVTBL PL_vtbl_sigelem = {MEMBER_TO_FPTR(Perl_magic_getsig),
2672 MEMBER_TO_FPTR(Perl_magic_setsig),
2673 0, MEMBER_TO_FPTR(Perl_magic_clearsig),
0c30d9ec 2674 0};
2b260de0 2675EXT MGVTBL PL_vtbl_pack = {0, 0, MEMBER_TO_FPTR(Perl_magic_sizepack), MEMBER_TO_FPTR(Perl_magic_wipepack),
a0d0e21e 2676 0};
2b260de0
GS
2677EXT MGVTBL PL_vtbl_packelem = {MEMBER_TO_FPTR(Perl_magic_getpack),
2678 MEMBER_TO_FPTR(Perl_magic_setpack),
2679 0, MEMBER_TO_FPTR(Perl_magic_clearpack),
463ee0b2 2680 0};
2b260de0 2681EXT MGVTBL PL_vtbl_dbline = {0, MEMBER_TO_FPTR(Perl_magic_setdbline),
463ee0b2 2682 0, 0, 0};
2b260de0
GS
2683EXT MGVTBL PL_vtbl_isa = {0, MEMBER_TO_FPTR(Perl_magic_setisa),
2684 0, MEMBER_TO_FPTR(Perl_magic_setisa),
fb73857a 2685 0};
2b260de0 2686EXT MGVTBL PL_vtbl_isaelem = {0, MEMBER_TO_FPTR(Perl_magic_setisa),
463ee0b2 2687 0, 0, 0};
2b260de0
GS
2688EXT MGVTBL PL_vtbl_arylen = {MEMBER_TO_FPTR(Perl_magic_getarylen),
2689 MEMBER_TO_FPTR(Perl_magic_setarylen),
463ee0b2 2690 0, 0, 0};
2b260de0
GS
2691EXT MGVTBL PL_vtbl_glob = {MEMBER_TO_FPTR(Perl_magic_getglob),
2692 MEMBER_TO_FPTR(Perl_magic_setglob),
463ee0b2 2693 0, 0, 0};
2b260de0 2694EXT MGVTBL PL_vtbl_mglob = {0, MEMBER_TO_FPTR(Perl_magic_setmglob),
463ee0b2 2695 0, 0, 0};
2b260de0
GS
2696EXT MGVTBL PL_vtbl_nkeys = {MEMBER_TO_FPTR(Perl_magic_getnkeys),
2697 MEMBER_TO_FPTR(Perl_magic_setnkeys),
99abf803 2698 0, 0, 0};
2b260de0 2699EXT MGVTBL PL_vtbl_taint = {MEMBER_TO_FPTR(Perl_magic_gettaint),MEMBER_TO_FPTR(Perl_magic_settaint),
463ee0b2 2700 0, 0, 0};
2b260de0 2701EXT MGVTBL PL_vtbl_substr = {MEMBER_TO_FPTR(Perl_magic_getsubstr), MEMBER_TO_FPTR(Perl_magic_setsubstr),
463ee0b2 2702 0, 0, 0};
2b260de0
GS
2703EXT MGVTBL PL_vtbl_vec = {MEMBER_TO_FPTR(Perl_magic_getvec),
2704 MEMBER_TO_FPTR(Perl_magic_setvec),
463ee0b2 2705 0, 0, 0};
2b260de0
GS
2706EXT MGVTBL PL_vtbl_pos = {MEMBER_TO_FPTR(Perl_magic_getpos),
2707 MEMBER_TO_FPTR(Perl_magic_setpos),
a0d0e21e 2708 0, 0, 0};
2b260de0 2709EXT MGVTBL PL_vtbl_bm = {0, MEMBER_TO_FPTR(Perl_magic_setbm),
463ee0b2 2710 0, 0, 0};
2b260de0 2711EXT MGVTBL PL_vtbl_fm = {0, MEMBER_TO_FPTR(Perl_magic_setfm),
55497cff 2712 0, 0, 0};
2b260de0
GS
2713EXT MGVTBL PL_vtbl_uvar = {MEMBER_TO_FPTR(Perl_magic_getuvar),
2714 MEMBER_TO_FPTR(Perl_magic_setuvar),
463ee0b2 2715 0, 0, 0};
f93b4edd 2716#ifdef USE_THREADS
2b260de0 2717EXT MGVTBL PL_vtbl_mutex = {0, 0, 0, 0, MEMBER_TO_FPTR(Perl_magic_mutexfree)};
f93b4edd 2718#endif /* USE_THREADS */
2b260de0 2719EXT MGVTBL PL_vtbl_defelem = {MEMBER_TO_FPTR(Perl_magic_getdefelem),MEMBER_TO_FPTR(Perl_magic_setdefelem),
02270b4e 2720 0, 0, 0};
a0d0e21e 2721
2b260de0
GS
2722EXT MGVTBL PL_vtbl_regexp = {0,0,0,0, MEMBER_TO_FPTR(Perl_magic_freeregexp)};
2723EXT MGVTBL PL_vtbl_regdata = {0, 0, MEMBER_TO_FPTR(Perl_magic_regdata_cnt), 0, 0};
2724EXT MGVTBL PL_vtbl_regdatum = {MEMBER_TO_FPTR(Perl_magic_regdatum_get), 0, 0, 0, 0};
c277df42 2725
36477c24 2726#ifdef USE_LOCALE_COLLATE
22c35a8c 2727EXT MGVTBL PL_vtbl_collxfrm = {0,
2b260de0 2728 MEMBER_TO_FPTR(Perl_magic_setcollxfrm),
bbce6d69
PP
2729 0, 0, 0};
2730#endif
a0d0e21e 2731
2b260de0
GS
2732EXT MGVTBL PL_vtbl_amagic = {0, MEMBER_TO_FPTR(Perl_magic_setamagic),
2733 0, 0, MEMBER_TO_FPTR(Perl_magic_setamagic)};
2734EXT MGVTBL PL_vtbl_amagicelem = {0, MEMBER_TO_FPTR(Perl_magic_setamagic),
2735 0, 0, MEMBER_TO_FPTR(Perl_magic_setamagic)};
a0d0e21e 2736
810b8aa5 2737EXT MGVTBL PL_vtbl_backref = {0, 0,
2b260de0 2738 0, 0, MEMBER_TO_FPTR(Perl_magic_killbackrefs)};
810b8aa5 2739
bbce6d69
PP
2740#else /* !DOINIT */
2741
22c35a8c
GS
2742EXT MGVTBL PL_vtbl_sv;
2743EXT MGVTBL PL_vtbl_env;
2744EXT MGVTBL PL_vtbl_envelem;
2745EXT MGVTBL PL_vtbl_sig;
2746EXT MGVTBL PL_vtbl_sigelem;
2747EXT MGVTBL PL_vtbl_pack;
2748EXT MGVTBL PL_vtbl_packelem;
2749EXT MGVTBL PL_vtbl_dbline;
2750EXT MGVTBL PL_vtbl_isa;
2751EXT MGVTBL PL_vtbl_isaelem;
2752EXT MGVTBL PL_vtbl_arylen;
2753EXT MGVTBL PL_vtbl_glob;
2754EXT MGVTBL PL_vtbl_mglob;
2755EXT MGVTBL PL_vtbl_nkeys;
2756EXT MGVTBL PL_vtbl_taint;
2757EXT MGVTBL PL_vtbl_substr;
2758EXT MGVTBL PL_vtbl_vec;
2759EXT MGVTBL PL_vtbl_pos;
2760EXT MGVTBL PL_vtbl_bm;
2761EXT MGVTBL PL_vtbl_fm;
2762EXT MGVTBL PL_vtbl_uvar;
a0d0e21e 2763
f93b4edd 2764#ifdef USE_THREADS
22c35a8c 2765EXT MGVTBL PL_vtbl_mutex;
f93b4edd
MB
2766#endif /* USE_THREADS */
2767
22c35a8c
GS
2768EXT MGVTBL PL_vtbl_defelem;
2769EXT MGVTBL PL_vtbl_regexp;
2770EXT MGVTBL PL_vtbl_regdata;
2771EXT MGVTBL PL_vtbl_regdatum;
a0d0e21e 2772
36477c24 2773#ifdef USE_LOCALE_COLLATE
22c35a8c 2774EXT MGVTBL PL_vtbl_collxfrm;
bbce6d69 2775#endif
a0d0e21e 2776
22c35a8c
GS
2777EXT MGVTBL PL_vtbl_amagic;
2778EXT MGVTBL PL_vtbl_amagicelem;
a0d0e21e 2779
810b8aa5
GS
2780EXT MGVTBL PL_vtbl_backref;
2781
bbce6d69 2782#endif /* !DOINIT */
85e6fe83 2783
f5284f61
IZ
2784enum {
2785 fallback_amg, abs_amg,
2786 bool__amg, nomethod_amg,
2787 string_amg, numer_amg,
2788 add_amg, add_ass_amg,
2789 subtr_amg, subtr_ass_amg,
2790 mult_amg, mult_ass_amg,
2791 div_amg, div_ass_amg,
2792 modulo_amg, modulo_ass_amg,
2793 pow_amg, pow_ass_amg,
2794 lshift_amg, lshift_ass_amg,
2795 rshift_amg, rshift_ass_amg,
2796 band_amg, band_ass_amg,
2797 bor_amg, bor_ass_amg,
2798 bxor_amg, bxor_ass_amg,
2799 lt_amg, le_amg,
2800 gt_amg, ge_amg,
2801 eq_amg, ne_amg,
2802 ncmp_amg, scmp_amg,
2803 slt_amg, sle_amg,
2804 sgt_amg, sge_amg,
2805 seq_amg, sne_amg,
2806 not_amg, compl_amg,
2807 inc_amg, dec_amg,
2808 atan2_amg, cos_amg,
2809 sin_amg, exp_amg,
2810 log_amg, sqrt_amg,
2811 repeat_amg, repeat_ass_amg,
2812 concat_amg, concat_ass_amg,
2813 copy_amg, neg_amg,
2814 to_sv_amg, to_av_amg,
2815 to_hv_amg, to_gv_amg,
2816 to_cv_amg, iter_amg,
64a0062a
JH
2817 max_amg_code
2818 /* Do not leave a trailing comma here. C9X allows it, C89 doesn't. */
f5284f61
IZ
2819};
2820
2821#define NofAMmeth max_amg_code
2822
a0d0e21e 2823#ifdef DOINIT
22c35a8c 2824EXTCONST char * PL_AMG_names[NofAMmeth] = {
a6006777
PP
2825 "fallback", "abs", /* "fallback" should be the first. */
2826 "bool", "nomethod",
2827 "\"\"", "0+",
2828 "+", "+=",
2829 "-", "-=",
2830 "*", "*=",
2831 "/", "/=",
2832 "%", "%=",
2833 "**", "**=",
2834 "<<", "<<=",
2835 ">>", ">>=",
2836 "&", "&=",
2837 "|", "|=",
2838 "^", "^=",
2839 "<", "<=",
2840 ">", ">=",
2841 "==", "!=",
2842 "<=>", "cmp",
2843 "lt", "le",
2844 "gt", "ge",
2845 "eq", "ne",
2846 "!", "~",
2847 "++", "--",
2848 "atan2", "cos",
2849 "sin", "exp",
2850 "log", "sqrt",
2851 "x", "x=",
2852 ".", ".=",
f5284f61
IZ
2853 "=", "neg",
2854 "${}", "@{}",
2855 "%{}", "*{}",
2856 "&{}", "<>",
a0d0e21e
LW
2857};
2858#else
22c35a8c 2859EXTCONST char * PL_AMG_names[NofAMmeth];
a0d0e21e
LW
2860#endif /* def INITAMAGIC */
2861
73c4f7a1
GS
2862END_EXTERN_C
2863
a6006777 2864struct am_table {
a0d0e21e
LW
2865 long was_ok_sub;
2866 long was_ok_am;
a6006777
PP
2867 U32 flags;
2868 CV* table[NofAMmeth];
a0d0e21e
LW
2869 long fallback;
2870};
a6006777
PP
2871struct am_table_short {
2872 long was_ok_sub;
2873 long was_ok_am;
2874 U32 flags;
2875};
a0d0e21e 2876typedef struct am_table AMT;
a6006777 2877typedef struct am_table_short AMTS;
a0d0e21e
LW
2878
2879#define AMGfallNEVER 1
2880#define AMGfallNO 2
2881#define AMGfallYES 3
2882
a6006777
PP
2883#define AMTf_AMAGIC 1
2884#define AMT_AMAGIC(amt) ((amt)->flags & AMTf_AMAGIC)
2885#define AMT_AMAGIC_on(amt) ((amt)->flags |= AMTf_AMAGIC)
2886#define AMT_AMAGIC_off(amt) ((amt)->flags &= ~AMTf_AMAGIC)
2887
c0315cdf
JH
2888
2889/*
2890 * some compilers like to redefine cos et alia as faster
2891 * (and less accurate?) versions called F_cos et cetera (Quidquid
2892 * latine dictum sit, altum viditur.) This trick collides with
2893 * the Perl overloading (amg). The following #defines fool both.
2894 */
2895
2896#ifdef _FASTMATH
2897# ifdef atan2
2898# define F_atan2_amg atan2_amg
2899# endif
2900# ifdef cos
2901# define F_cos_amg cos_amg
2902# endif
2903# ifdef exp
2904# define F_exp_amg exp_amg
2905# endif
2906# ifdef log
2907# define F_log_amg log_amg
2908# endif
2909# ifdef pow
2910# define F_pow_amg pow_amg
2911# endif
2912# ifdef sin
2913# define F_sin_amg sin_amg
2914# endif
2915# ifdef sqrt
2916# define F_sqrt_amg sqrt_amg
2917# endif
2918#endif /* _FASTMATH */
2919
491527d0 2920#define PERLDB_ALL 0x3f /* No _NONAME, _GOTO */
84902520
TB
2921#define PERLDBf_SUB 0x01 /* Debug sub enter/exit. */
2922#define PERLDBf_LINE 0x02 /* Keep line #. */
2923#define PERLDBf_NOOPT 0x04 /* Switch off optimizations. */
2924#define PERLDBf_INTER 0x08 /* Preserve more data for
2925 later inspections. */
2926#define PERLDBf_SUBLINE 0x10 /* Keep subr source lines. */
2927#define PERLDBf_SINGLE 0x20 /* Start with single-step on. */
491527d0
GS
2928#define PERLDBf_NONAME 0x40 /* For _SUB: no name of the subr. */
2929#define PERLDBf_GOTO 0x80 /* Report goto: call DB::goto. */
84902520 2930
3280af22
NIS
2931#define PERLDB_SUB (PL_perldb && (PL_perldb & PERLDBf_SUB))
2932#define PERLDB_LINE (PL_perldb && (PL_perldb & PERLDBf_LINE))
2933#define PERLDB_NOOPT (PL_perldb && (PL_perldb & PERLDBf_NOOPT))
2934#define PERLDB_INTER (PL_perldb && (PL_perldb & PERLDBf_INTER))
2935#define PERLDB_SUBLINE (PL_perldb && (PL_perldb & PERLDBf_SUBLINE))
2936#define PERLDB_SINGLE (PL_perldb && (PL_perldb & PERLDBf_SINGLE))
2937#define PERLDB_SUB_NN (PL_perldb && (PL_perldb & (PERLDBf_NONAME)))
2938#define PERLDB_GOTO (PL_perldb && (PL_perldb & PERLDBf_GOTO))
84902520 2939
bbce6d69 2940
36477c24 2941#ifdef USE_LOCALE_NUMERIC
bbce6d69 2942
36477c24
PP
2943#define SET_NUMERIC_STANDARD() \
2944 STMT_START { \
864dbfa3
GS
2945 if (! PL_numeric_standard) \
2946 set_numeric_standard(); \
36477c24
PP
2947 } STMT_END
2948
2949#define SET_NUMERIC_LOCAL() \
2950 STMT_START { \
3280af22 2951 if (! PL_numeric_local) \
864dbfa3 2952 set_numeric_local(); \
36477c24 2953 } STMT_END
bbce6d69 2954
097ee67d
JH
2955#define IS_NUMERIC_RADIX(c) \
2956 ((PL_hints & HINT_LOCALE) && \
2957 PL_numeric_radix && (c) == PL_numeric_radix)
2958
2959#define RESTORE_NUMERIC_LOCAL() if ((PL_hints & HINT_LOCALE) && PL_numeric_standard) SET_NUMERIC_LOCAL()
2960#define RESTORE_NUMERIC_STANDARD() if ((PL_hints & HINT_LOCALE) && PL_numeric_local) SET_NUMERIC_STANDARD()
5b877257 2961#define Atof my_atof
097ee67d 2962
36477c24 2963#else /* !USE_LOCALE_NUMERIC */
bbce6d69 2964
097ee67d
JH
2965#define SET_NUMERIC_STANDARD() /**/
2966#define SET_NUMERIC_LOCAL() /**/
2967#define IS_NUMERIC_RADIX(c) (0)
2968#define RESTORE_NUMERIC_LOCAL() /**/
2969#define RESTORE_NUMERIC_STANDARD() /**/
65202027 2970#define Atof Perl_atof
bbce6d69 2971
36477c24 2972#endif /* !USE_LOCALE_NUMERIC */
a0d0e21e 2973
cf2093f6
JH
2974#if defined(USE_LONG_LONG) && defined(HAS_LONG_LONG) && defined(HAS_ATOLL)
2975#define Atol atoll
2976#else
2977#define Atol atol
2978#endif
2979
2980#if defined(USE_LONG_LONG) && defined(HAS_LONG_LONG) && defined(HAS_STRTOULL)
2981#define Strtoul strtoull
2982#else
2983#define Strtoul strtoul
2984#endif
2985
e5c9fcd0 2986#if !defined(PERLIO_IS_STDIO) && defined(HASATTRIBUTE)
760ac839
LW
2987/*
2988 * Now we have __attribute__ out of the way
2989 * Remap printf
2990 */
39455587 2991#undef printf
760ac839
LW
2992#define printf PerlIO_stdoutf
2993#endif
2994
a868473f
NIS
2995#ifndef PERL_SCRIPT_MODE
2996#define PERL_SCRIPT_MODE "r"
2997#endif
2998
fba3b22e 2999/*
da927450
JH
3000 * Some operating systems are stingy with stack allocation,
3001 * so perl may have to guard against stack overflow.
3002 */
3003#ifndef PERL_STACK_OVERFLOW_CHECK
c2af87cb 3004#define PERL_STACK_OVERFLOW_CHECK() NOOP
da927450
JH
3005#endif
3006
3007/*
3008 * Some nonpreemptive operating systems find it convenient to
3009 * check for asynchronous conditions after each op execution.
3010 * Keep this check simple, or it may slow down execution
3011 * massively.
3012 */
3013#ifndef PERL_ASYNC_CHECK
c2af87cb 3014#define PERL_ASYNC_CHECK() NOOP
da927450
JH
3015#endif
3016
3017/*
3018 * On some operating systems, a memory allocation may succeed,
3019 * but put the process too close to the system's comfort limit.
3020 * In this case, PERL_ALLOC_CHECK frees the pointer and sets
3021 * it to NULL.
3022 */
3023#ifndef PERL_ALLOC_CHECK
c2af87cb 3024#define PERL_ALLOC_CHECK(p) NOOP
da927450
JH
3025#endif
3026
3027/*
fba3b22e
MB
3028 * nice_chunk and nice_chunk size need to be set
3029 * and queried under the protection of sv_mutex
3030 */
3031#define offer_nice_chunk(chunk, chunk_size) do { \
940cb80d 3032 LOCK_SV_MUTEX; \
3280af22
NIS
3033 if (!PL_nice_chunk) { \
3034 PL_nice_chunk = (char*)(chunk); \
3035 PL_nice_chunk_size = (chunk_size); \
fba3b22e 3036 } \
fc80cf79
GS
3037 else { \
3038 Safefree(chunk); \
3039 } \
940cb80d 3040 UNLOCK_SV_MUTEX; \
fba3b22e
MB
3041 } while (0)
3042
bd89102f
AD
3043#ifdef HAS_SEM
3044# include <sys/ipc.h>
3045# include <sys/sem.h>
3046# ifndef HAS_UNION_SEMUN /* Provide the union semun. */
3047 union semun {
dbba660d
TC
3048 int val;
3049 struct semid_ds *buf;
3050 unsigned short *array;
bd89102f
AD
3051 };
3052# endif
3053# ifdef USE_SEMCTL_SEMUN
dbba660d
TC
3054# ifdef IRIX32_SEMUN_BROKEN_BY_GCC
3055 union gccbug_semun {
3056 int val;
3057 struct semid_ds *buf;
3058 unsigned short *array;
3059 char __dummy[5];
3060 };
3061# define semun gccbug_semun
3062# endif
bd89102f
AD
3063# define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun)
3064# else
3065# ifdef USE_SEMCTL_SEMID_DS
3066# define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun.buf)
3067# endif
3068# endif
bd89102f 3069#endif
49f531da 3070
104d25b7
JH
3071#ifdef IAMSUID
3072
3073#ifdef I_SYS_STATVFS
32b3cf08
JH
3074# include <sys/statvfs.h> /* for f?statvfs() */
3075#endif
3076#ifdef I_SYS_MOUNT
3077# include <sys/mount.h> /* for *BSD f?statfs() */
3078#endif
3079#ifdef I_MNTENT
3080# include <mntent.h> /* for getmntent() */
104d25b7 3081#endif
0545a864
JH
3082#ifdef I_SYS_STATFS
3083# include <sys/statfs.h> /* for some statfs() */
3084#endif
3085#ifdef I_SYS_VFS
8d9e1a19
GS
3086# ifdef __sgi
3087# define sv IRIX_sv /* kludge: IRIX has an sv of its own */
3088# endif
3089# include <sys/vfs.h> /* for some statfs() */
3090# ifdef __sgi
3091# undef IRIX_sv
3092# endif
0545a864
JH
3093#endif
3094#ifdef I_USTAT
3095# include <ustat.h> /* for ustat() */
3096#endif
3097
3098#if !defined(PERL_MOUNT_NOSUID) && defined(MOUNT_NOSUID)
3099# define PERL_MOUNT_NOSUID MOUNT_NOSUID
3100#endif
3101#if !defined(PERL_MOUNT_NOSUID) && defined(MNT_NOSUID)
3102# define PERL_MOUNT_NOSUID MNT_NOSUID
3103#endif
3104#if !defined(PERL_MOUNT_NOSUID) && defined(MS_NOSUID)
3105# define PERL_MOUNT_NOSUID MS_NOSUID
3106#endif
3107#if !defined(PERL_MOUNT_NOSUID) && defined(M_NOSUID)
3108# define PERL_MOUNT_NOSUID M_NOSUID
3109#endif
104d25b7
JH
3110
3111#endif /* IAMSUID */
3112
4d8076ea 3113/* and finally... */
cceca5ed 3114#define PERL_PATCHLEVEL_H_IMPLICIT
4d8076ea 3115#include "patchlevel.h"
cceca5ed 3116#undef PERL_PATCHLEVEL_H_IMPLICIT
4d8076ea 3117
85e6fe83 3118#endif /* Include guard */