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