This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Date: Tue, 01 Dec 1998 00:07:33 +0100
[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
a0d0e21e 11#define OVERLOAD
8d063cd8 12
760ac839
LW
13#ifdef PERL_FOR_X2P
14/*
15 * This file is being used for x2p stuff.
16 * Above symbol is defined via -D in 'x2p/Makefile.SH'
17 * Decouple x2p stuff from some of perls more extreme eccentricities.
18 */
760ac839 19#undef EMBED
55497cff 20#undef NO_EMBED
21#define NO_EMBED
22#undef MULTIPLICITY
760ac839
LW
23#undef USE_STDIO
24#define USE_STDIO
25#endif /* PERL_FOR_X2P */
26
76e3520e 27#ifdef PERL_OBJECT
3dfd1da1
GS
28
29/* PERL_OBJECT explained - DickH and DougL @ ActiveState.com
30
31Defining PERL_OBJECT turns on creation of a C++ object that
32contains all writable core perl global variables and functions.
33Stated another way, all necessary global variables and functions
34are members of a big C++ object. This object's class is CPerlObj.
35This allows a Perl Host to have multiple, independent perl
36interpreters in the same process space. This is very important on
37Win32 systems as the overhead of process creation is quite high --
38this could be even higher than the script compile and execute time
39for small scripts.
40
41The perl executable implementation on Win32 is composed of perl.exe
42(the Perl Host) and perlX.dll. (the Perl Core). This allows the
43same Perl Core to easily be embedded in other applications that use
44the perl interpreter.
45
46+-----------+
47| Perl Host |
48+-----------+
49 ^
50 |
51 v
52+-----------+ +-----------+
53| Perl Core |<->| Extension |
54+-----------+ +-----------+ ...
55
56Defining PERL_OBJECT has the following effects:
57
58PERL CORE
591. CPerlObj is defined (this is the PERL_OBJECT)
602. all static functions that needed to access either global
61variables or functions needed are made member functions
623. all writable static variables are made member variables
634. all global variables and functions are defined as:
64 #define var CPerlObj::Perl_var
65 #define func CPerlObj::Perl_func
66 * these are in objpp.h
67This necessitated renaming some local variables and functions that
68had the same name as a global variable or function. This was
69probably a _good_ thing anyway.
70
71
72EXTENSIONS
731. Access to global variables and perl functions is through a
74pointer to the PERL_OBJECT. This pointer type is CPerlObj*. This is
75made transparent to extension developers by the following macros:
76 #define var pPerl->Perl_var
77 #define func pPerl->Perl_func
6de196ee 78 * these are done in objXSUB.h
3dfd1da1
GS
79This requires that the extension be compiled as C++, which means
80that the code must be ANSI C and not K&R C. For K&R extensions,
81please see the C API notes located in Win32/GenCAPI.pl. This script
6de196ee 82creates a perlCAPI.lib that provides a K & R compatible C interface
3dfd1da1
GS
83to the PERL_OBJECT.
842. Local variables and functions cannot have the same name as perl's
85variables or functions since the macros will redefine these. Look for
86this if you get some strange error message and it does not look like
87the code that you had written. This often happens with variables that
88are local to a function.
89
90PERL HOST
911. The perl host is linked with perlX.lib to get perl_alloc. This
92function will return a pointer to CPerlObj (the PERL_OBJECT). It
0f4eea8f
DL
93takes pointers to the various PerlXXX_YYY interfaces (see iperlsys.h
94for more information on this).
3dfd1da1
GS
952. The perl host calls the same functions as normally would be
96called in setting up and running a perl script, except that the
97functions are now member functions of the PERL_OBJECT.
98
99*/
100
101
76e3520e
GS
102class CPerlObj;
103
104#define STATIC
105#define CPERLscope(x) CPerlObj::x
106#define CPERLproto CPerlObj *
e3b8966e 107#define _CPERLproto ,CPERLproto
76e3520e
GS
108#define CPERLarg CPerlObj *pPerl
109#define CPERLarg_ CPERLarg,
e3b8966e 110#define _CPERLarg ,CPERLarg
1d583055
GS
111#define PERL_OBJECT_THIS this
112#define _PERL_OBJECT_THIS ,this
113#define PERL_OBJECT_THIS_ this,
4c2891ed
GS
114#define CALLRUNOPS (this->*PL_runops)
115#define CALLREGCOMP (this->*PL_regcompp)
116#define CALLREGEXEC (this->*PL_regexecp)
76e3520e
GS
117
118#else /* !PERL_OBJECT */
119
120#define STATIC static
121#define CPERLscope(x) x
122#define CPERLproto
e3b8966e 123#define _CPERLproto
565764a8 124#define CPERLarg void
76e3520e 125#define CPERLarg_
e3b8966e 126#define _CPERLarg
1d583055
GS
127#define PERL_OBJECT_THIS
128#define _PERL_OBJECT_THIS
129#define PERL_OBJECT_THIS_
3280af22
NIS
130#define CALLRUNOPS PL_runops
131#define CALLREGCOMP (*PL_regcompp)
132#define CALLREGEXEC (*PL_regexecp)
76e3520e
GS
133
134#endif /* PERL_OBJECT */
135
71be2cbc 136#define VOIDUSED 1
137#include "config.h"
138
139#include "embed.h"
140
326b05e3
GS
141#undef START_EXTERN_C
142#undef END_EXTERN_C
143#undef EXTERN_C
32f822de
GS
144#ifdef __cplusplus
145# define START_EXTERN_C extern "C" {
146# define END_EXTERN_C }
147# define EXTERN_C extern "C"
148#else
149# define START_EXTERN_C
150# define END_EXTERN_C
151# define EXTERN_C
152#endif
153
462e5cf6
MB
154#ifdef OP_IN_REGISTER
155# ifdef __GNUC__
156# define stringify_immed(s) #s
157# define stringify(s) stringify_immed(s)
d1ca3daa
GA
158#ifdef EMBED
159register struct op *Perl_op asm(stringify(OP_IN_REGISTER));
160#else
462e5cf6 161register struct op *op asm(stringify(OP_IN_REGISTER));
d1ca3daa 162#endif
462e5cf6
MB
163# endif
164#endif
165
728e2803 166/*
167 * STMT_START { statements; } STMT_END;
168 * can be used as a single statement, as in
169 * if (x) STMT_START { ... } STMT_END; else ...
170 *
171 * Trying to select a version that gives no warnings...
172 */
173#if !(defined(STMT_START) && defined(STMT_END))
169d69b2 174# if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__cplusplus)
728e2803 175# define STMT_START (void)( /* gcc supports ``({ STATEMENTS; })'' */
176# define STMT_END )
177# else
178 /* Now which other defined()s do we need here ??? */
179# if (VOIDFLAGS) && (defined(sun) || defined(__sun__))
180# define STMT_START if (1)
181# define STMT_END else (void)0
182# else
183# define STMT_START do
184# define STMT_END while (0)
185# endif
186# endif
187#endif
188
462e5cf6
MB
189#define NOOP (void)0
190
61bb5906 191#define WITH_THR(s) STMT_START { dTHR; s; } STMT_END
ea0efc06 192
55497cff 193/*
194 * SOFT_CAST can be used for args to prototyped functions to retain some
195 * type checking; it only casts if the compiler does not know prototypes.
196 */
197#if defined(CAN_PROTOTYPE) && defined(DEBUGGING_COMPILE)
198#define SOFT_CAST(type)
199#else
200#define SOFT_CAST(type) (type)
201#endif
79072805 202
6ee623d5 203#ifndef BYTEORDER /* Should never happen -- byteorder is in config.h */
79072805
LW
204# define BYTEORDER 0x1234
205#endif
206
207/* Overall memory policy? */
208#ifndef CONSERVATIVE
209# define LIBERAL 1
210#endif
211
b1e066e5
JH
212#if 'A' == 65 && 'I' == 73 && 'J' == 74 && 'Z' == 90
213#define ASCIIish
214#else
215#undef ASCIIish
216#endif
217
79072805
LW
218/*
219 * The following contortions are brought to you on behalf of all the
220 * standards, semi-standards, de facto standards, not-so-de-facto standards
221 * of the world, as well as all the other botches anyone ever thought of.
222 * The basic theory is that if we work hard enough here, the rest of the
223 * code can be a lot prettier. Well, so much for theory. Sorry, Henry...
224 */
ac58e20f 225
ee0007ab 226/* define this once if either system, instead of cluttering up the src */
68dc0745 227#if defined(MSDOS) || defined(atarist) || defined(WIN32)
ee0007ab
LW
228#define DOSISH 1
229#endif
230
a0d0e21e 231#if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
352d5a3a
LW
232# define STANDARD_C 1
233#endif
234
09b7f37c 235#if defined(__cplusplus) || defined(WIN32) || defined(__sgi) || defined(OS2) || defined(__DGUX)
68dc0745 236# define DONT_DECLARE_STD 1
237#endif
238
352d5a3a 239#if defined(HASVOLATILE) || defined(STANDARD_C)
79072805
LW
240# ifdef __cplusplus
241# define VOL // to temporarily suppress warnings
242# else
243# define VOL volatile
244# endif
663a0e37 245#else
79072805 246# define VOL
663a0e37
LW
247#endif
248
3280af22
NIS
249#define TAINT (PL_tainted = TRUE)
250#define TAINT_NOT (PL_tainted = FALSE)
251#define TAINT_IF(c) if (c) { PL_tainted = TRUE; }
252#define TAINT_ENV() if (PL_tainting) { taint_env(); }
0c005962 253#define TAINT_PROPER(s) if (PL_tainting) { taint_proper(Nullch, s); }
a687059c 254
a6e633de 255/* XXX All process group stuff is handled in pp_sys.c. Should these
256 defines move there? If so, I could simplify this a lot. --AD 9/96.
257*/
258/* Process group stuff changed from traditional BSD to POSIX.
259 perlfunc.pod documents the traditional BSD-style syntax, so we'll
260 try to preserve that, if possible.
261*/
262#ifdef HAS_SETPGID
263# define BSD_SETPGRP(pid, pgrp) setpgid((pid), (pgrp))
c07a80fd 264#else
a6e633de 265# if defined(HAS_SETPGRP) && defined(USE_BSD_SETPGRP)
266# define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp))
267# else
268# ifdef HAS_SETPGRP2 /* DG/UX */
269# define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp))
270# endif
271# endif
272#endif
273#if defined(BSD_SETPGRP) && !defined(HAS_SETPGRP)
274# define HAS_SETPGRP /* Well, effectively it does . . . */
275#endif
276
277/* getpgid isn't POSIX, but at least Solaris and Linux have it, and it makes
278 our life easier :-) so we'll try it.
279*/
280#ifdef HAS_GETPGID
281# define BSD_GETPGRP(pid) getpgid((pid))
282#else
283# if defined(HAS_GETPGRP) && defined(USE_BSD_GETPGRP)
284# define BSD_GETPGRP(pid) getpgrp((pid))
285# else
286# ifdef HAS_GETPGRP2 /* DG/UX */
287# define BSD_GETPGRP(pid) getpgrp2((pid))
288# endif
289# endif
290#endif
291#if defined(BSD_GETPGRP) && !defined(HAS_GETPGRP)
292# define HAS_GETPGRP /* Well, effectively it does . . . */
293#endif
294
295/* These are not exact synonyms, since setpgrp() and getpgrp() may
296 have different behaviors, but perl.h used to define USE_BSDPGRP
297 (prior to 5.003_05) so some extension might depend on it.
298*/
299#if defined(USE_BSD_SETPGRP) || defined(USE_BSD_GETPGRP)
300# ifndef USE_BSDPGRP
301# define USE_BSDPGRP
302# endif
663a0e37
LW
303#endif
304
760ac839
LW
305#ifndef _TYPES_ /* If types.h defines this it's easy. */
306# ifndef major /* Does everyone's types.h define this? */
307# include <sys/types.h>
c07a80fd 308# endif
663a0e37
LW
309#endif
310
760ac839
LW
311#ifdef __cplusplus
312# ifndef I_STDARG
313# define I_STDARG 1
314# endif
315#endif
316
317#ifdef I_STDARG
318# include <stdarg.h>
319#else
320# ifdef I_VARARGS
321# include <varargs.h>
322# endif
323#endif
324
0f4eea8f 325#include "iperlsys.h"
0c30d9ec 326
4633a7c4 327#ifdef USE_NEXT_CTYPE
0c30d9ec 328
329#if NX_CURRENT_COMPILER_RELEASE >= 400
330#include <objc/NXCType.h>
331#else /* NX_CURRENT_COMPILER_RELEASE < 400 */
a0d0e21e 332#include <appkit/NXCType.h>
0c30d9ec 333#endif /* NX_CURRENT_COMPILER_RELEASE >= 400 */
334
335#else /* !USE_NEXT_CTYPE */
fe14fcc3 336#include <ctype.h>
0c30d9ec 337#endif /* USE_NEXT_CTYPE */
a0d0e21e
LW
338
339#ifdef METHOD /* Defined by OSF/1 v3.0 by ctype.h */
340#undef METHOD
a0d0e21e
LW
341#endif
342
4633a7c4 343#ifdef I_LOCALE
36477c24 344# include <locale.h>
4633a7c4
LW
345#endif
346
36477c24 347#if !defined(NO_LOCALE) && defined(HAS_SETLOCALE)
348# define USE_LOCALE
349# if !defined(NO_LOCALE_COLLATE) && defined(LC_COLLATE) \
350 && defined(HAS_STRXFRM)
351# define USE_LOCALE_COLLATE
352# endif
353# if !defined(NO_LOCALE_CTYPE) && defined(LC_CTYPE)
354# define USE_LOCALE_CTYPE
355# endif
356# if !defined(NO_LOCALE_NUMERIC) && defined(LC_NUMERIC)
357# define USE_LOCALE_NUMERIC
358# endif
359#endif /* !NO_LOCALE && HAS_SETLOCALE */
a0d0e21e 360
fe14fcc3 361#include <setjmp.h>
79072805 362
a0d0e21e 363#ifdef I_SYS_PARAM
79072805
LW
364# ifdef PARAM_NEEDS_TYPES
365# include <sys/types.h>
366# endif
367# include <sys/param.h>
352d5a3a 368#endif
79072805
LW
369
370
371/* Use all the "standard" definitions? */
a0d0e21e 372#if defined(STANDARD_C) && defined(I_STDLIB)
79072805 373# include <stdlib.h>
ff68c719 374#endif
03a14243 375
c31fac66
GS
376#define MEM_SIZE Size_t
377
55497cff 378/* This comes after <stdlib.h> so we don't try to change the standard
379 * library prototypes; we'll use our own in proto.h instead. */
03a14243 380
4633a7c4 381#ifdef MYMALLOC
55497cff 382
4633a7c4 383# ifdef HIDEMYMALLOC
55497cff 384# define malloc Mymalloc
385# define calloc Mycalloc
429a5e67 386# define realloc Myrealloc
55497cff 387# define free Myfree
c31fac66
GS
388Malloc_t Mymalloc _((MEM_SIZE nbytes));
389Malloc_t Mycalloc _((MEM_SIZE elements, MEM_SIZE size));
390Malloc_t Myrealloc _((Malloc_t where, MEM_SIZE nbytes));
391Free_t Myfree _((Malloc_t where));
55497cff 392# endif
393# ifdef EMBEDMYMALLOC
394# define malloc Perl_malloc
395# define calloc Perl_calloc
396# define realloc Perl_realloc
429a5e67
DS
397/* VMS' external symbols are case-insensitive, and there's already a */
398/* perl_free in perl.h */
399#ifdef VMS
400# define free Perl_myfree
401#else
55497cff 402# define free Perl_free
429a5e67 403#endif
c31fac66
GS
404Malloc_t Perl_malloc _((MEM_SIZE nbytes));
405Malloc_t Perl_calloc _((MEM_SIZE elements, MEM_SIZE size));
406Malloc_t Perl_realloc _((Malloc_t where, MEM_SIZE nbytes));
429a5e67
DS
407#ifdef VMS
408Free_t Perl_myfree _((Malloc_t where));
409#else
c31fac66 410Free_t Perl_free _((Malloc_t where));
429a5e67 411#endif
4633a7c4 412# endif
55497cff 413
414# undef safemalloc
415# undef safecalloc
416# undef saferealloc
417# undef safefree
418# define safemalloc malloc
419# define safecalloc calloc
4633a7c4 420# define saferealloc realloc
55497cff 421# define safefree free
422
423#endif /* MYMALLOC */
4633a7c4 424
ff68c719 425#if defined(STANDARD_C) && defined(I_STDDEF)
426# include <stddef.h>
71be2cbc 427# define STRUCT_OFFSET(s,m) offsetof(s,m)
ff68c719 428#else
71be2cbc 429# define STRUCT_OFFSET(s,m) (Size_t)(&(((s *)0)->m))
ff68c719 430#endif
431
a0d0e21e
LW
432#if defined(I_STRING) || defined(__cplusplus)
433# include <string.h>
434#else
435# include <strings.h>
436#endif
437
438#if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
439#define strchr index
440#define strrchr rindex
441#endif
442
16d20bd9
AD
443#ifdef I_MEMORY
444# include <memory.h>
445#endif
446
fe14fcc3 447#ifdef HAS_MEMCPY
85e6fe83 448# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
fe14fcc3 449# ifndef memcpy
a0d0e21e 450 extern char * memcpy _((char*, char*, int));
ee0007ab
LW
451# endif
452# endif
453#else
454# ifndef memcpy
455# ifdef HAS_BCOPY
456# define memcpy(d,s,l) bcopy(s,d,l)
457# else
458# define memcpy(d,s,l) my_bcopy(s,d,l)
459# endif
460# endif
461#endif /* HAS_MEMCPY */
fe14fcc3 462
ee0007ab 463#ifdef HAS_MEMSET
85e6fe83 464# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
ee0007ab 465# ifndef memset
a0d0e21e 466 extern char *memset _((char*, int, int));
ee0007ab
LW
467# endif
468# endif
ee0007ab 469#else
fc36a67e 470# define memset(d,c,l) my_memset(d,c,l)
ee0007ab
LW
471#endif /* HAS_MEMSET */
472
85e6fe83 473#if !defined(HAS_MEMMOVE) && !defined(memmove)
2304df62 474# if defined(HAS_BCOPY) && defined(HAS_SAFE_BCOPY)
79072805
LW
475# define memmove(d,s,l) bcopy(s,d,l)
476# else
2304df62 477# if defined(HAS_MEMCPY) && defined(HAS_SAFE_MEMCPY)
79072805 478# define memmove(d,s,l) memcpy(d,s,l)
ee0007ab 479# else
79072805 480# define memmove(d,s,l) my_bcopy(s,d,l)
ee0007ab 481# endif
352d5a3a 482# endif
d9d8d8de 483#endif
ee0007ab 484
36477c24 485#if defined(mips) && defined(ultrix) && !defined(__STDC__)
486# undef HAS_MEMCMP
487#endif
488
489#if defined(HAS_MEMCMP) && defined(HAS_SANE_MEMCMP)
85e6fe83 490# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
ee0007ab 491# ifndef memcmp
a0d0e21e 492 extern int memcmp _((char*, char*, int));
ee0007ab
LW
493# endif
494# endif
36477c24 495# ifdef BUGGY_MSC
496 # pragma function(memcmp)
497# endif
ee0007ab
LW
498#else
499# ifndef memcmp
ecfc5424 500# define memcmp my_memcmp
352d5a3a 501# endif
36477c24 502#endif /* HAS_MEMCMP && HAS_SANE_MEMCMP */
8d063cd8 503
fc36a67e 504#ifndef memzero
c635e13b 505# ifdef HAS_MEMSET
506# define memzero(d,l) memset(d,0,l)
79072805 507# else
c635e13b 508# ifdef HAS_BZERO
509# define memzero(d,l) bzero(d,l)
79072805 510# else
fc36a67e 511# define memzero(d,l) my_bzero(d,l)
79072805
LW
512# endif
513# endif
d9d8d8de 514#endif
378cc40b 515
36477c24 516#ifndef HAS_BCMP
517# ifndef bcmp
518# define bcmp(s1,s2,l) memcmp(s1,s2,l)
79072805 519# endif
36477c24 520#endif /* !HAS_BCMP */
378cc40b 521
ae986130 522#ifdef I_NETINET_IN
79072805 523# include <netinet/in.h>
ae986130
LW
524#endif
525
28e8609d
JH
526#ifdef I_ARPA_INET
527# include <arpa/inet.h>
528#endif
529
84902520
TB
530#if defined(SF_APPEND) && defined(USE_SFIO) && defined(I_SFIO)
531/* <sfio.h> defines SF_APPEND and <sys/stat.h> might define SF_APPEND
532 * (the neo-BSD seem to do this). */
533# undef SF_APPEND
534#endif
535
1aef975c 536#ifdef I_SYS_STAT
84902520 537# include <sys/stat.h>
1aef975c 538#endif
79072805 539
a0d0e21e
LW
540/* The stat macros for Amdahl UTS, Unisoft System V/88 (and derivatives
541 like UTekV) are broken, sometimes giving false positives. Undefine
542 them here and let the code below set them to proper values.
543
544 The ghs macro stands for GreenHills Software C-1.8.5 which
545 is the C compiler for sysV88 and the various derivatives.
546 This header file bug is corrected in gcc-2.5.8 and later versions.
547 --Kaveh Ghazi (ghazi@noc.rutgers.edu) 10/3/94. */
548
549#if defined(uts) || (defined(m88k) && defined(ghs))
79072805
LW
550# undef S_ISDIR
551# undef S_ISCHR
552# undef S_ISBLK
553# undef S_ISREG
554# undef S_ISFIFO
555# undef S_ISLNK
ee0007ab 556#endif
135863df 557
663a0e37
LW
558#ifdef I_TIME
559# include <time.h>
ffed7fef 560#endif
663a0e37 561
fe14fcc3 562#ifdef I_SYS_TIME
85e6fe83 563# ifdef I_SYS_TIME_KERNEL
663a0e37
LW
564# define KERNEL
565# endif
566# include <sys/time.h>
85e6fe83 567# ifdef I_SYS_TIME_KERNEL
663a0e37
LW
568# undef KERNEL
569# endif
a687059c 570#endif
135863df 571
55497cff 572#if defined(HAS_TIMES) && defined(I_SYS_TIMES)
85e6fe83 573# include <sys/times.h>
d9d8d8de 574#endif
8d063cd8 575
fe14fcc3 576#if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
79072805 577# undef HAS_STRERROR
663a0e37
LW
578#endif
579
580#include <errno.h>
ed6116ce 581#ifdef HAS_SOCKET
85e6fe83 582# ifdef I_NET_ERRNO
ed6116ce
LW
583# include <net/errno.h>
584# endif
585#endif
f86702cc 586
587#ifdef VMS
588# define SETERRNO(errcode,vmserrcode) \
589 STMT_START { \
590 set_errno(errcode); \
591 set_vaxc_errno(vmserrcode); \
592 } STMT_END
748a9306 593#else
1f6b3999 594# define SETERRNO(errcode,vmserrcode) (errno = (errcode))
748a9306 595#endif
ed6116ce 596
38a03e6e
MB
597#ifdef USE_THREADS
598# define ERRSV (thr->errsv)
599# define ERRHV (thr->errhv)
940cb80d
MB
600# define DEFSV THREADSV(0)
601# define SAVE_DEFSV save_threadsv(0)
38a03e6e 602#else
3280af22
NIS
603# define ERRSV GvSV(PL_errgv)
604# define ERRHV GvHV(PL_errgv)
605# define DEFSV GvSV(PL_defgv)
606# define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
38a03e6e
MB
607#endif /* USE_THREADS */
608
55497cff 609#ifndef errno
79072805 610 extern int errno; /* ANSI allows errno to be an lvalue expr */
d9d8d8de 611#endif
663a0e37 612
2304df62 613#ifdef HAS_STRERROR
a0d0e21e
LW
614# ifdef VMS
615 char *strerror _((int,...));
616# else
68dc0745 617#ifndef DONT_DECLARE_STD
a0d0e21e 618 char *strerror _((int));
68dc0745 619#endif
a0d0e21e 620# endif
2304df62
AD
621# ifndef Strerror
622# define Strerror strerror
623# endif
624#else
625# ifdef HAS_SYS_ERRLIST
79072805
LW
626 extern int sys_nerr;
627 extern char *sys_errlist[];
2304df62
AD
628# ifndef Strerror
629# define Strerror(e) \
79072805 630 ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
2304df62 631# endif
79072805 632# endif
35c8bce7 633#endif
663a0e37 634
2304df62 635#ifdef I_SYS_IOCTL
79072805
LW
636# ifndef _IOCTL_
637# include <sys/ioctl.h>
638# endif
a687059c
LW
639#endif
640
ee0007ab 641#if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
79072805
LW
642# ifdef HAS_SOCKETPAIR
643# undef HAS_SOCKETPAIR
644# endif
2304df62
AD
645# ifdef I_NDBM
646# undef I_NDBM
79072805 647# endif
a687059c
LW
648#endif
649
a687059c 650#if INTSIZE == 2
79072805
LW
651# define htoni htons
652# define ntohi ntohs
a687059c 653#else
79072805
LW
654# define htoni htonl
655# define ntohi ntohl
a687059c
LW
656#endif
657
a0d0e21e 658/* Configure already sets Direntry_t */
35c8bce7 659#if defined(I_DIRENT)
663a0e37 660# include <dirent.h>
a0d0e21e
LW
661# if defined(NeXT) && defined(I_SYS_DIR) /* NeXT needs dirent + sys/dir.h */
662# include <sys/dir.h>
663# endif
ae986130 664#else
fe14fcc3 665# ifdef I_SYS_NDIR
79a0689e 666# include <sys/ndir.h>
663a0e37 667# else
fe14fcc3 668# ifdef I_SYS_DIR
79a0689e
LW
669# ifdef hp9000s500
670# include <ndir.h> /* may be wrong in the future */
671# else
672# include <sys/dir.h>
673# endif
663a0e37
LW
674# endif
675# endif
4633a7c4 676#endif
a687059c 677
352d5a3a
LW
678#ifdef FPUTS_BOTCH
679/* work around botch in SunOS 4.0.1 and 4.0.2 */
680# ifndef fputs
79072805 681# define fputs(sv,fp) fprintf(fp,"%s",sv)
352d5a3a
LW
682# endif
683#endif
684
c623bd54
LW
685/*
686 * The following gobbledygook brought to you on behalf of __STDC__.
687 * (I could just use #ifndef __STDC__, but this is more bulletproof
688 * in the face of half-implementations.)
689 */
690
691#ifndef S_IFMT
692# ifdef _S_IFMT
693# define S_IFMT _S_IFMT
694# else
695# define S_IFMT 0170000
696# endif
697#endif
698
699#ifndef S_ISDIR
700# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
701#endif
702
703#ifndef S_ISCHR
704# define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
705#endif
706
707#ifndef S_ISBLK
fe14fcc3
LW
708# ifdef S_IFBLK
709# define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
710# else
711# define S_ISBLK(m) (0)
712# endif
c623bd54
LW
713#endif
714
715#ifndef S_ISREG
716# define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
717#endif
718
719#ifndef S_ISFIFO
fe14fcc3
LW
720# ifdef S_IFIFO
721# define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
722# else
723# define S_ISFIFO(m) (0)
724# endif
c623bd54
LW
725#endif
726
727#ifndef S_ISLNK
728# ifdef _S_ISLNK
729# define S_ISLNK(m) _S_ISLNK(m)
730# else
731# ifdef _S_IFLNK
732# define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
733# else
734# ifdef S_IFLNK
735# define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
736# else
737# define S_ISLNK(m) (0)
738# endif
739# endif
740# endif
741#endif
742
743#ifndef S_ISSOCK
744# ifdef _S_ISSOCK
745# define S_ISSOCK(m) _S_ISSOCK(m)
746# else
747# ifdef _S_IFSOCK
748# define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
749# else
750# ifdef S_IFSOCK
751# define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
752# else
753# define S_ISSOCK(m) (0)
754# endif
755# endif
756# endif
757#endif
758
759#ifndef S_IRUSR
760# ifdef S_IREAD
761# define S_IRUSR S_IREAD
762# define S_IWUSR S_IWRITE
763# define S_IXUSR S_IEXEC
764# else
765# define S_IRUSR 0400
766# define S_IWUSR 0200
767# define S_IXUSR 0100
768# endif
769# define S_IRGRP (S_IRUSR>>3)
770# define S_IWGRP (S_IWUSR>>3)
771# define S_IXGRP (S_IXUSR>>3)
772# define S_IROTH (S_IRUSR>>6)
773# define S_IWOTH (S_IWUSR>>6)
774# define S_IXOTH (S_IXUSR>>6)
775#endif
776
777#ifndef S_ISUID
778# define S_ISUID 04000
779#endif
780
781#ifndef S_ISGID
782# define S_ISGID 02000
783#endif
784
79072805
LW
785#ifdef ff_next
786# undef ff_next
352d5a3a
LW
787#endif
788
a0d0e21e 789#if defined(cray) || defined(gould) || defined(i860) || defined(pyr)
45d8adaa
LW
790# define SLOPPYDIVIDE
791#endif
792
748a9306
LW
793#ifdef UV
794#undef UV
795#endif
796
27d4fb96 797/* XXX QUAD stuff is not currently supported on most systems.
798 Specifically, perl internals don't support long long. Among
799 the many problems is that some compilers support long long,
800 but the underlying library functions (such as sprintf) don't.
801 Some things do work (such as quad pack/unpack on convex);
802 also some systems use long long for the fpos_t typedef. That
803 seems to work too.
804
805 The IV type is supposed to be long enough to hold any integral
806 value or a pointer.
807 --Andy Dougherty August 1996
808*/
809
f86702cc 810#ifdef cray
811# define Quad_t int
812#else
813# ifdef convex
814# define Quad_t long long
45d8adaa 815# else
6ee623d5 816# if LONGSIZE == 8
ecfc5424 817# define Quad_t long
45d8adaa
LW
818# endif
819# endif
f86702cc 820#endif
821
6ee623d5
GS
822/* XXX Experimental set-up for long long. Just add -DUSE_LONG_LONG
823 to your ccflags. --Andy Dougherty 4/1998
824*/
825#ifdef USE_LONG_LONG
826# if defined(HAS_LONG_LONG) && LONGLONGSIZE == 8
827# define Quad_t long long
828# endif
829#endif
830
f86702cc 831#ifdef Quad_t
832# define HAS_QUAD
748a9306
LW
833 typedef Quad_t IV;
834 typedef unsigned Quad_t UV;
27d4fb96 835# define IV_MAX PERL_QUAD_MAX
836# define IV_MIN PERL_QUAD_MIN
837# define UV_MAX PERL_UQUAD_MAX
838# define UV_MIN PERL_UQUAD_MIN
79072805 839#else
748a9306
LW
840 typedef long IV;
841 typedef unsigned long UV;
27d4fb96 842# define IV_MAX PERL_LONG_MAX
843# define IV_MIN PERL_LONG_MIN
844# define UV_MAX PERL_ULONG_MAX
845# define UV_MIN PERL_ULONG_MIN
79072805
LW
846#endif
847
760ac839
LW
848/* Previously these definitions used hardcoded figures.
849 * It is hoped these formula are more portable, although
850 * no data one way or another is presently known to me.
851 * The "PERL_" names are used because these calculated constants
852 * do not meet the ANSI requirements for LONG_MAX, etc., which
853 * need to be constants acceptable to #if - kja
854 * define PERL_LONG_MAX 2147483647L
855 * define PERL_LONG_MIN (-LONG_MAX - 1)
856 * define PERL ULONG_MAX 4294967295L
857 */
858
859#ifdef I_LIMITS /* Needed for cast_xxx() functions below. */
860# include <limits.h>
861#else
862#ifdef I_VALUES
863# include <values.h>
864#endif
865#endif
866
99abf803 867/*
868 * Try to figure out max and min values for the integral types. THE CORRECT
869 * SOLUTION TO THIS MESS: ADAPT enquire.c FROM GCC INTO CONFIGURE. The
870 * following hacks are used if neither limits.h or values.h provide them:
871 * U<TYPE>_MAX: for types >= int: ~(unsigned TYPE)0
872 * for types < int: (unsigned TYPE)~(unsigned)0
873 * The argument to ~ must be unsigned so that later signed->unsigned
874 * conversion can't modify the value's bit pattern (e.g. -0 -> +0),
875 * and it must not be smaller than int because ~ does integral promotion.
876 * <type>_MAX: (<type>) (U<type>_MAX >> 1)
877 * <type>_MIN: -<type>_MAX - <is_twos_complement_architecture: (3 & -1) == 3>.
878 * The latter is a hack which happens to work on some machines but
879 * does *not* catch any random system, or things like integer types
880 * with NaN if that is possible.
881 *
882 * All of the types are explicitly cast to prevent accidental loss of
883 * numeric range, and in the hope that they will be less likely to confuse
884 * over-eager optimizers.
885 *
886 */
27d4fb96 887
99abf803 888#define PERL_UCHAR_MIN ((unsigned char)0)
889
890#ifdef UCHAR_MAX
891# define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX)
27d4fb96 892#else
99abf803 893# ifdef MAXUCHAR
894# define PERL_UCHAR_MAX ((unsigned char)MAXUCHAR)
27d4fb96 895# else
99abf803 896# define PERL_UCHAR_MAX ((unsigned char)~(unsigned)0)
27d4fb96 897# endif
898#endif
99abf803 899
900/*
901 * CHAR_MIN and CHAR_MAX are not included here, as the (char) type may be
902 * ambiguous. It may be equivalent to (signed char) or (unsigned char)
903 * depending on local options. Until Configure detects this (or at least
904 * detects whether the "signed" keyword is available) the CHAR ranges
905 * will not be included. UCHAR functions normally.
906 * - kja
907 */
27d4fb96 908
99abf803 909#define PERL_USHORT_MIN ((unsigned short)0)
910
911#ifdef USHORT_MAX
912# define PERL_USHORT_MAX ((unsigned short)USHORT_MAX)
27d4fb96 913#else
99abf803 914# ifdef MAXUSHORT
915# define PERL_USHORT_MAX ((unsigned short)MAXUSHORT)
27d4fb96 916# else
ef2f54b0
CB
917# ifdef USHRT_MAX
918# define PERL_USHORT_MAX ((unsigned short)USHRT_MAX)
919# else
920# define PERL_USHORT_MAX ((unsigned short)~(unsigned)0)
921# endif
27d4fb96 922# endif
923#endif
924
27d4fb96 925#ifdef SHORT_MAX
99abf803 926# define PERL_SHORT_MAX ((short)SHORT_MAX)
27d4fb96 927#else
928# ifdef MAXSHORT /* Often used in <values.h> */
99abf803 929# define PERL_SHORT_MAX ((short)MAXSHORT)
27d4fb96 930# else
ef2f54b0
CB
931# ifdef SHRT_MAX
932# define PERL_SHORT_MAX ((short)SHRT_MAX)
933# else
934# define PERL_SHORT_MAX ((short) (PERL_USHORT_MAX >> 1))
935# endif
27d4fb96 936# endif
937#endif
938
939#ifdef SHORT_MIN
99abf803 940# define PERL_SHORT_MIN ((short)SHORT_MIN)
27d4fb96 941#else
942# ifdef MINSHORT
99abf803 943# define PERL_SHORT_MIN ((short)MINSHORT)
27d4fb96 944# else
ef2f54b0
CB
945# ifdef SHRT_MIN
946# define PERL_SHORT_MIN ((short)SHRT_MIN)
947# else
948# define PERL_SHORT_MIN (-PERL_SHORT_MAX - ((3 & -1) == 3))
949# endif
27d4fb96 950# endif
951#endif
952
99abf803 953#ifdef UINT_MAX
954# define PERL_UINT_MAX ((unsigned int)UINT_MAX)
27d4fb96 955#else
99abf803 956# ifdef MAXUINT
957# define PERL_UINT_MAX ((unsigned int)MAXUINT)
27d4fb96 958# else
99abf803 959# define PERL_UINT_MAX (~(unsigned int)0)
27d4fb96 960# endif
961#endif
962
99abf803 963#define PERL_UINT_MIN ((unsigned int)0)
27d4fb96 964
965#ifdef INT_MAX
99abf803 966# define PERL_INT_MAX ((int)INT_MAX)
27d4fb96 967#else
968# ifdef MAXINT /* Often used in <values.h> */
99abf803 969# define PERL_INT_MAX ((int)MAXINT)
27d4fb96 970# else
99abf803 971# define PERL_INT_MAX ((int)(PERL_UINT_MAX >> 1))
27d4fb96 972# endif
973#endif
974
975#ifdef INT_MIN
99abf803 976# define PERL_INT_MIN ((int)INT_MIN)
27d4fb96 977#else
978# ifdef MININT
99abf803 979# define PERL_INT_MIN ((int)MININT)
27d4fb96 980# else
981# define PERL_INT_MIN (-PERL_INT_MAX - ((3 & -1) == 3))
982# endif
983#endif
984
99abf803 985#ifdef ULONG_MAX
986# define PERL_ULONG_MAX ((unsigned long)ULONG_MAX)
27d4fb96 987#else
99abf803 988# ifdef MAXULONG
989# define PERL_ULONG_MAX ((unsigned long)MAXULONG)
27d4fb96 990# else
99abf803 991# define PERL_ULONG_MAX (~(unsigned long)0)
27d4fb96 992# endif
993#endif
994
99abf803 995#define PERL_ULONG_MIN ((unsigned long)0L)
27d4fb96 996
760ac839 997#ifdef LONG_MAX
99abf803 998# define PERL_LONG_MAX ((long)LONG_MAX)
760ac839
LW
999#else
1000# ifdef MAXLONG /* Often used in <values.h> */
99abf803 1001# define PERL_LONG_MAX ((long)MAXLONG)
760ac839 1002# else
99abf803 1003# define PERL_LONG_MAX ((long) (PERL_ULONG_MAX >> 1))
760ac839
LW
1004# endif
1005#endif
1006
1007#ifdef LONG_MIN
99abf803 1008# define PERL_LONG_MIN ((long)LONG_MIN)
760ac839
LW
1009#else
1010# ifdef MINLONG
99abf803 1011# define PERL_LONG_MIN ((long)MINLONG)
760ac839 1012# else
27d4fb96 1013# define PERL_LONG_MIN (-PERL_LONG_MAX - ((3 & -1) == 3))
760ac839
LW
1014# endif
1015#endif
1016
99abf803 1017#ifdef HAS_QUAD
1018
1019# ifdef UQUAD_MAX
1020# define PERL_UQUAD_MAX ((UV)UQUAD_MAX)
760ac839 1021# else
99abf803 1022# define PERL_UQUAD_MAX (~(UV)0)
760ac839 1023# endif
760ac839 1024
99abf803 1025# define PERL_UQUAD_MIN ((UV)0)
27d4fb96 1026
27d4fb96 1027# ifdef QUAD_MAX
99abf803 1028# define PERL_QUAD_MAX ((IV)QUAD_MAX)
27d4fb96 1029# else
99abf803 1030# define PERL_QUAD_MAX ((IV) (PERL_UQUAD_MAX >> 1))
27d4fb96 1031# endif
1032
1033# ifdef QUAD_MIN
99abf803 1034# define PERL_QUAD_MIN ((IV)QUAD_MIN)
27d4fb96 1035# else
a6e633de 1036# define PERL_QUAD_MIN (-PERL_QUAD_MAX - ((3 & -1) == 3))
27d4fb96 1037# endif
1038
79072805
LW
1039#endif
1040
ee0007ab 1041typedef MEM_SIZE STRLEN;
450a55e4 1042
79072805
LW
1043typedef struct op OP;
1044typedef struct cop COP;
1045typedef struct unop UNOP;
1046typedef struct binop BINOP;
1047typedef struct listop LISTOP;
1048typedef struct logop LOGOP;
1049typedef struct condop CONDOP;
1050typedef struct pmop PMOP;
1051typedef struct svop SVOP;
1052typedef struct gvop GVOP;
1053typedef struct pvop PVOP;
79072805
LW
1054typedef struct loop LOOP;
1055
1056typedef struct Outrec Outrec;
93a17b20 1057typedef struct interpreter PerlInterpreter;
3e3baf6d
TB
1058#ifndef __BORLANDC__
1059typedef struct ff FF; /* XXX not defined anywhere, should go? */
1060#endif
79072805
LW
1061typedef struct sv SV;
1062typedef struct av AV;
1063typedef struct hv HV;
1064typedef struct cv CV;
378cc40b 1065typedef struct regexp REGEXP;
79072805 1066typedef struct gp GP;
0c30d9ec 1067typedef struct gv GV;
8990e307 1068typedef struct io IO;
c09156bb 1069typedef struct context PERL_CONTEXT;
79072805
LW
1070typedef struct block BLOCK;
1071
1072typedef struct magic MAGIC;
ed6116ce 1073typedef struct xrv XRV;
79072805
LW
1074typedef struct xpv XPV;
1075typedef struct xpviv XPVIV;
ff68c719 1076typedef struct xpvuv XPVUV;
79072805
LW
1077typedef struct xpvnv XPVNV;
1078typedef struct xpvmg XPVMG;
1079typedef struct xpvlv XPVLV;
1080typedef struct xpvav XPVAV;
1081typedef struct xpvhv XPVHV;
1082typedef struct xpvgv XPVGV;
1083typedef struct xpvcv XPVCV;
1084typedef struct xpvbm XPVBM;
1085typedef struct xpvfm XPVFM;
8990e307 1086typedef struct xpvio XPVIO;
79072805
LW
1087typedef struct mgvtbl MGVTBL;
1088typedef union any ANY;
8d063cd8 1089
378cc40b 1090#include "handy.h"
a0d0e21e 1091
873ef191
GS
1092#ifdef PERL_OBJECT
1093typedef I32 (*filter_t) _((CPerlObj*, int, SV *, int));
1094#else
16d20bd9 1095typedef I32 (*filter_t) _((int, SV *, int));
873ef191
GS
1096#endif
1097
16d20bd9 1098#define FILTER_READ(idx, sv, len) filter_read(idx, sv, len)
3280af22
NIS
1099#define FILTER_DATA(idx) (AvARRAY(PL_rsfp_filters)[idx])
1100#define FILTER_ISREADER(idx) (idx >= AvFILLp(PL_rsfp_filters))
16d20bd9 1101
748a9306 1102#ifdef DOSISH
4633a7c4
LW
1103# if defined(OS2)
1104# include "os2ish.h"
1105# else
748a9306 1106# include "dosish.h"
4633a7c4 1107# endif
a0d0e21e 1108#else
748a9306
LW
1109# if defined(VMS)
1110# include "vmsish.h"
1111# else
0c30d9ec 1112# if defined(PLAN9)
1113# include "./plan9/plan9ish.h"
1114# else
1d84e8df
JH
1115# if defined(MPE)
1116# include "mpeix/mpeixish.h"
1117# else
f756a9d6
PG
1118# if defined(__VOS__)
1119# include "vosish.h"
1120# else
1121# include "unixish.h"
1122# endif
1d84e8df 1123# endif
0c30d9ec 1124# endif
748a9306 1125# endif
32f822de
GS
1126#endif
1127
ac4c12e7
GS
1128#ifndef FUNC_NAME_TO_PTR
1129#define FUNC_NAME_TO_PTR(name) name
1130#endif
1131
32f822de 1132/*
dd96f567
IZ
1133 * USE_THREADS needs to be after unixish.h as <pthread.h> includes
1134 * <sys/signal.h> which defines NSIG - which will stop inclusion of <signal.h>
32f822de
GS
1135 * this results in many functions being undeclared which bothers C++
1136 * May make sense to have threads after "*ish.h" anyway
1137 */
1138
1139#ifdef USE_THREADS
79d59c5f
GS
1140 /* pending resolution of licensing issues, we avoid the erstwhile
1141 * atomic.h everywhere */
1142# define EMULATE_ATOMIC_REFCOUNTS
1143
32f822de
GS
1144# ifdef FAKE_THREADS
1145# include "fakethr.h"
1146# else
1147# ifdef WIN32
1148# include <win32thread.h>
1149# else
dd96f567
IZ
1150# ifdef OS2
1151# include "os2thread.h"
1152# else
1153# include <pthread.h>
c6ee37c5 1154typedef pthread_t perl_os_thread;
32f822de
GS
1155typedef pthread_mutex_t perl_mutex;
1156typedef pthread_cond_t perl_cond;
1157typedef pthread_key_t perl_key;
dd96f567 1158# endif /* OS2 */
32f822de
GS
1159# endif /* WIN32 */
1160# endif /* FAKE_THREADS */
1161#endif /* USE_THREADS */
1162
1163
3fc1aec6 1164
68dc0745 1165#ifdef VMS
6b88bc9c 1166# define STATUS_NATIVE PL_statusvalue_vms
68dc0745 1167# define STATUS_NATIVE_EXPORT \
6b88bc9c 1168 ((I32)PL_statusvalue_vms == -1 ? 44 : PL_statusvalue_vms)
68dc0745 1169# define STATUS_NATIVE_SET(n) \
1170 STMT_START { \
6b88bc9c
GS
1171 PL_statusvalue_vms = (n); \
1172 if ((I32)PL_statusvalue_vms == -1) \
3280af22 1173 PL_statusvalue = -1; \
6b88bc9c 1174 else if (PL_statusvalue_vms & STS$M_SUCCESS) \
3280af22 1175 PL_statusvalue = 0; \
6b88bc9c
GS
1176 else if ((PL_statusvalue_vms & STS$M_SEVERITY) == 0) \
1177 PL_statusvalue = 1 << 8; \
68dc0745 1178 else \
6b88bc9c 1179 PL_statusvalue = (PL_statusvalue_vms & STS$M_SEVERITY) << 8; \
68dc0745 1180 } STMT_END
3280af22 1181# define STATUS_POSIX PL_statusvalue
68dc0745 1182# ifdef VMSISH_STATUS
1183# define STATUS_CURRENT (VMSISH_STATUS ? STATUS_NATIVE : STATUS_POSIX)
1184# else
1185# define STATUS_CURRENT STATUS_POSIX
1186# endif
1187# define STATUS_POSIX_SET(n) \
1188 STMT_START { \
3280af22
NIS
1189 PL_statusvalue = (n); \
1190 if (PL_statusvalue != -1) { \
1191 PL_statusvalue &= 0xFFFF; \
6b88bc9c 1192 PL_statusvalue_vms = PL_statusvalue ? 44 : 1; \
68dc0745 1193 } \
6b88bc9c 1194 else PL_statusvalue_vms = -1; \
68dc0745 1195 } STMT_END
6b88bc9c
GS
1196# define STATUS_ALL_SUCCESS (PL_statusvalue = 0, PL_statusvalue_vms = 1)
1197# define STATUS_ALL_FAILURE (PL_statusvalue = 1, PL_statusvalue_vms = 44)
68dc0745 1198#else
1199# define STATUS_NATIVE STATUS_POSIX
1200# define STATUS_NATIVE_EXPORT STATUS_POSIX
1201# define STATUS_NATIVE_SET STATUS_POSIX_SET
3280af22 1202# define STATUS_POSIX PL_statusvalue
68dc0745 1203# define STATUS_POSIX_SET(n) \
1204 STMT_START { \
3280af22
NIS
1205 PL_statusvalue = (n); \
1206 if (PL_statusvalue != -1) \
1207 PL_statusvalue &= 0xFFFF; \
68dc0745 1208 } STMT_END
1209# define STATUS_CURRENT STATUS_POSIX
3280af22
NIS
1210# define STATUS_ALL_SUCCESS (PL_statusvalue = 0)
1211# define STATUS_ALL_FAILURE (PL_statusvalue = 1)
68dc0745 1212#endif
1213
3fc1aec6 1214/* Some unistd.h's give a prototype for pause() even though
1215 HAS_PAUSE ends up undefined. This causes the #define
1216 below to be rejected by the compmiler. Sigh.
1217*/
1218#ifdef HAS_PAUSE
1219#define Pause pause
1220#else
1221#define Pause() sleep((32767<<16)+32767)
748a9306
LW
1222#endif
1223
1224#ifndef IOCPARM_LEN
1225# ifdef IOCPARM_MASK
1226 /* on BSDish systes we're safe */
1227# define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
1228# else
1229 /* otherwise guess at what's safe */
1230# define IOCPARM_LEN(x) 256
1231# endif
a0d0e21e
LW
1232#endif
1233
0f4eea8f
DL
1234#ifdef UNION_ANY_DEFINITION
1235UNION_ANY_DEFINITION;
1236#else
79072805
LW
1237union any {
1238 void* any_ptr;
1239 I32 any_i32;
a0d0e21e 1240 IV any_iv;
85e6fe83 1241 long any_long;
565764a8 1242 void (CPERLscope(*any_dptr)) _((void*));
79072805 1243};
0f4eea8f 1244#endif
79072805 1245
11343788 1246#ifdef USE_THREADS
52e1cb5e 1247#define ARGSproto struct perl_thread *thr
11343788
MB
1248#else
1249#define ARGSproto void
1250#endif /* USE_THREADS */
1251
5aabfad6 1252/* Work around some cygwin32 problems with importing global symbols */
1253#if defined(CYGWIN32) && defined(DLLIMPORT)
1254# include "cw32imp.h"
1255#endif
1256
378cc40b 1257#include "regexp.h"
79072805 1258#include "sv.h"
378cc40b 1259#include "util.h"
8d063cd8 1260#include "form.h"
79072805
LW
1261#include "gv.h"
1262#include "cv.h"
1263#include "opcode.h"
1264#include "op.h"
1265#include "cop.h"
1266#include "av.h"
1267#include "hv.h"
1268#include "mg.h"
1269#include "scope.h"
d613ef02
GS
1270#include "bytecode.h"
1271#include "byterun.h"
8d063cd8 1272
7fae4e64
GS
1273/* Current curly descriptor */
1274typedef struct curcur CURCUR;
1275struct curcur {
1276 int parenfloor; /* how far back to strip paren data */
1277 int cur; /* how many instances of scan we've matched */
1278 int min; /* the minimal number of scans to match */
1279 int max; /* the maximal number of scans to match */
1280 int minmod; /* whether to work our way up or down */
1281 regnode * scan; /* the thing to match */
1282 regnode * next; /* what has to match after it */
1283 char * lastloc; /* where we started matching this scan */
1284 CURCUR * oldcc; /* current curly before we started this one */
1285};
1286
1287typedef struct _sublex_info SUBLEXINFO;
1288struct _sublex_info {
1289 I32 super_state; /* lexer state to save */
1290 I32 sub_inwhat; /* "lex_inwhat" to use */
1291 OP *sub_op; /* "lex_op" to use */
1292};
1293
76e3520e
GS
1294#ifdef PERL_OBJECT
1295struct magic_state {
1296 SV* mgs_sv;
1297 U32 mgs_flags;
1298};
1299typedef struct magic_state MGS;
1300
1301typedef struct {
1302 I32 len_min;
1303 I32 len_delta;
1304 I32 pos_min;
1305 I32 pos_delta;
1306 SV *last_found;
1307 I32 last_end; /* min value, <0 unless valid. */
1308 I32 last_start_min;
1309 I32 last_start_max;
1310 SV **longest; /* Either &l_fixed, or &l_float. */
1311 SV *longest_fixed;
1312 I32 offset_fixed;
1313 SV *longest_float;
1314 I32 offset_float_min;
1315 I32 offset_float_max;
1316 I32 flags;
1317} scan_data_t;
1318
1319typedef I32 CHECKPOINT;
1320#endif /* PERL_OBJECT */
1321
4633a7c4
LW
1322/* work around some libPW problems */
1323#ifdef DOINIT
1324EXT char Error[1];
1325#endif
1326
450a55e4 1327#if defined(iAPX286) || defined(M_I286) || defined(I80286)
a687059c
LW
1328# define I286
1329#endif
1330
fe14fcc3
LW
1331#if defined(htonl) && !defined(HAS_HTONL)
1332#define HAS_HTONL
ae986130 1333#endif
fe14fcc3
LW
1334#if defined(htons) && !defined(HAS_HTONS)
1335#define HAS_HTONS
ae986130 1336#endif
fe14fcc3
LW
1337#if defined(ntohl) && !defined(HAS_NTOHL)
1338#define HAS_NTOHL
ae986130 1339#endif
fe14fcc3
LW
1340#if defined(ntohs) && !defined(HAS_NTOHS)
1341#define HAS_NTOHS
ae986130 1342#endif
fe14fcc3 1343#ifndef HAS_HTONL
d9d8d8de 1344#if (BYTEORDER & 0xffff) != 0x4321
fe14fcc3
LW
1345#define HAS_HTONS
1346#define HAS_HTONL
1347#define HAS_NTOHS
1348#define HAS_NTOHL
a687059c
LW
1349#define MYSWAP
1350#define htons my_swap
1351#define htonl my_htonl
1352#define ntohs my_swap
1353#define ntohl my_ntohl
1354#endif
1355#else
d9d8d8de 1356#if (BYTEORDER & 0xffff) == 0x4321
fe14fcc3
LW
1357#undef HAS_HTONS
1358#undef HAS_HTONL
1359#undef HAS_NTOHS
1360#undef HAS_NTOHL
a687059c
LW
1361#endif
1362#endif
1363
988174c1
LW
1364/*
1365 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
1366 * -DWS
1367 */
1368#if BYTEORDER != 0x1234
1369# define HAS_VTOHL
1370# define HAS_VTOHS
1371# define HAS_HTOVL
1372# define HAS_HTOVS
1373# if BYTEORDER == 0x4321
1374# define vtohl(x) ((((x)&0xFF)<<24) \
1375 +(((x)>>24)&0xFF) \
1376 +(((x)&0x0000FF00)<<8) \
1377 +(((x)&0x00FF0000)>>8) )
1378# define vtohs(x) ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
1379# define htovl(x) vtohl(x)
1380# define htovs(x) vtohs(x)
1381# endif
1382 /* otherwise default to functions in util.c */
1383#endif
1384
0f85fab0 1385#ifdef CASTNEGFLOAT
79072805 1386#define U_S(what) ((U16)(what))
0f85fab0 1387#define U_I(what) ((unsigned int)(what))
79072805 1388#define U_L(what) ((U32)(what))
0f85fab0 1389#else
32f822de 1390EXTERN_C U32 cast_ulong _((double));
232e078e
AD
1391#define U_S(what) ((U16)cast_ulong((double)(what)))
1392#define U_I(what) ((unsigned int)cast_ulong((double)(what)))
1393#define U_L(what) (cast_ulong((double)(what)))
ee0007ab
LW
1394#endif
1395
ed6116ce
LW
1396#ifdef CASTI32
1397#define I_32(what) ((I32)(what))
a0d0e21e 1398#define I_V(what) ((IV)(what))
5d94fbed 1399#define U_V(what) ((UV)(what))
ed6116ce 1400#else
32f822de 1401START_EXTERN_C
a0d0e21e 1402I32 cast_i32 _((double));
a0d0e21e 1403IV cast_iv _((double));
5d94fbed 1404UV cast_uv _((double));
32f822de 1405END_EXTERN_C
a6e633de 1406#define I_32(what) (cast_i32((double)(what)))
1407#define I_V(what) (cast_iv((double)(what)))
5d94fbed 1408#define U_V(what) (cast_uv((double)(what)))
ed6116ce
LW
1409#endif
1410
79072805
LW
1411struct Outrec {
1412 I32 o_lines;
d9d8d8de 1413 char *o_str;
79072805 1414 U32 o_len;
8d063cd8
LW
1415};
1416
352d5a3a
LW
1417#ifndef MAXSYSFD
1418# define MAXSYSFD 2
1419#endif
ee0007ab 1420
f82b3d41 1421#ifndef TMPPATH
1422# define TMPPATH "/tmp/perl-eXXXXXX"
a0d0e21e 1423#endif
79072805
LW
1424
1425#ifndef __cplusplus
a0d0e21e
LW
1426Uid_t getuid _((void));
1427Uid_t geteuid _((void));
1428Gid_t getgid _((void));
1429Gid_t getegid _((void));
79072805 1430#endif
8d063cd8
LW
1431
1432#ifdef DEBUGGING
0c30d9ec 1433#ifndef Perl_debug_log
760ac839 1434#define Perl_debug_log PerlIO_stderr()
0c30d9ec 1435#endif
9d116dd7 1436#undef YYDEBUG
d96024cf 1437#define YYDEBUG 1
79072805 1438#define DEB(a) a
3280af22
NIS
1439#define DEBUG(a) if (PL_debug) a
1440#define DEBUG_p(a) if (PL_debug & 1) a
1441#define DEBUG_s(a) if (PL_debug & 2) a
1442#define DEBUG_l(a) if (PL_debug & 4) a
1443#define DEBUG_t(a) if (PL_debug & 8) a
1444#define DEBUG_o(a) if (PL_debug & 16) a
1445#define DEBUG_c(a) if (PL_debug & 32) a
1446#define DEBUG_P(a) if (PL_debug & 64) a
1447#define DEBUG_m(a) if (PL_curinterp && PL_debug & 128) a
1448#define DEBUG_f(a) if (PL_debug & 256) a
1449#define DEBUG_r(a) if (PL_debug & 512) a
1450#define DEBUG_x(a) if (PL_debug & 1024) a
1451#define DEBUG_u(a) if (PL_debug & 2048) a
1452#define DEBUG_L(a) if (PL_debug & 4096) a
1453#define DEBUG_H(a) if (PL_debug & 8192) a
1454#define DEBUG_X(a) if (PL_debug & 16384) a
1455#define DEBUG_D(a) if (PL_debug & 32768) a
8b73bbec
IZ
1456# ifdef USE_THREADS
1457# define DEBUG_S(a) if (PL_debug & (1<<16)) a
1458# else
1459# define DEBUG_S(a)
1460# endif
79072805
LW
1461#else
1462#define DEB(a)
1463#define DEBUG(a)
1464#define DEBUG_p(a)
1465#define DEBUG_s(a)
1466#define DEBUG_l(a)
1467#define DEBUG_t(a)
1468#define DEBUG_o(a)
1469#define DEBUG_c(a)
1470#define DEBUG_P(a)
1471#define DEBUG_m(a)
1472#define DEBUG_f(a)
1473#define DEBUG_r(a)
1474#define DEBUG_x(a)
1475#define DEBUG_u(a)
8b73bbec 1476#define DEBUG_S(a)
79072805
LW
1477#define DEBUG_H(a)
1478#define DEBUG_X(a)
8990e307 1479#define DEBUG_D(a)
8b73bbec 1480#define DEBUG_S(a)
8d063cd8 1481#endif
fe14fcc3 1482#define YYMAXDEPTH 300
8d063cd8 1483
a6e633de 1484#ifndef assert /* <assert.h> might have been included somehow */
79072805
LW
1485#define assert(what) DEB( { \
1486 if (!(what)) { \
463ee0b2 1487 croak("Assertion failed: file \"%s\", line %d", \
79072805 1488 __FILE__, __LINE__); \
6ad3d225 1489 PerlProc_exit(1); \
79072805 1490 }})
a6e633de 1491#endif
8d063cd8 1492
450a55e4 1493struct ufuncs {
a0d0e21e
LW
1494 I32 (*uf_val)_((IV, SV*));
1495 I32 (*uf_set)_((IV, SV*));
1496 IV uf_index;
450a55e4
LW
1497};
1498
fe14fcc3 1499/* Fix these up for __STDC__ */
68dc0745 1500#ifndef DONT_DECLARE_STD
a0d0e21e
LW
1501char *mktemp _((char*));
1502double atof _((const char*));
1503#endif
79072805 1504
352d5a3a 1505#ifndef STANDARD_C
fe14fcc3 1506/* All of these are in stdlib.h or time.h for ANSI C */
85e6fe83 1507Time_t time();
8d063cd8 1508struct tm *gmtime(), *localtime();
9d116dd7
JH
1509#ifdef OEMVS
1510char *(strchr)(), *(strrchr)();
1511char *(strcpy)(), *(strcat)();
1512#else
93a17b20 1513char *strchr(), *strrchr();
378cc40b 1514char *strcpy(), *strcat();
9d116dd7 1515#endif
352d5a3a 1516#endif /* ! STANDARD_C */
8d063cd8 1517
79072805
LW
1518
1519#ifdef I_MATH
1520# include <math.h>
1521#else
32f822de 1522START_EXTERN_C
a0d0e21e 1523 double exp _((double));
a0d0e21e 1524 double log _((double));
c635e13b 1525 double log10 _((double));
a0d0e21e 1526 double sqrt _((double));
c635e13b 1527 double frexp _((double,int*));
1528 double ldexp _((double,int));
a0d0e21e
LW
1529 double modf _((double,double*));
1530 double sin _((double));
1531 double cos _((double));
1532 double atan2 _((double,double));
1533 double pow _((double,double));
32f822de 1534END_EXTERN_C
79072805
LW
1535#endif
1536
a0d0e21e 1537#ifndef __cplusplus
26618a56 1538# ifdef __NeXT__ /* or whatever catches all NeXTs */
3fc1aec6 1539char *crypt (); /* Maybe more hosts will need the unprototyped version */
26618a56
GS
1540# else
1541# if !defined(WIN32) || !defined(HAVE_DES_FCRYPT)
a0d0e21e 1542char *crypt _((const char*, const char*));
26618a56
GS
1543# endif /* !WIN32 && !HAVE_CRYPT_SOURCE */
1544# endif /* !__NeXT__ */
1545# ifndef DONT_DECLARE_STD
1546# ifndef getenv
a0d0e21e 1547char *getenv _((const char*));
26618a56 1548# endif /* !getenv */
a0d0e21e 1549Off_t lseek _((int,Off_t,int));
26618a56 1550# endif /* !DONT_DECLARE_STD */
a0d0e21e 1551char *getlogin _((void));
26618a56 1552#endif /* !__cplusplus */
79072805 1553
16d20bd9 1554#ifdef UNLINK_ALL_VERSIONS /* Currently only makes sense for VMS */
378cc40b 1555#define UNLINK unlnk
a0d0e21e 1556I32 unlnk _((char*));
8d063cd8
LW
1557#else
1558#define UNLINK unlink
1559#endif
a687059c 1560
fe14fcc3 1561#ifndef HAS_SETREUID
85e6fe83
LW
1562# ifdef HAS_SETRESUID
1563# define setreuid(r,e) setresuid(r,e,(Uid_t)-1)
1564# define HAS_SETREUID
1565# endif
a687059c 1566#endif
fe14fcc3 1567#ifndef HAS_SETREGID
85e6fe83
LW
1568# ifdef HAS_SETRESGID
1569# define setregid(r,e) setresgid(r,e,(Gid_t)-1)
1570# define HAS_SETREGID
1571# endif
a687059c 1572#endif
ee0007ab 1573
ff68c719 1574typedef Signal_t (*Sighandler_t) _((int));
1575
1576#ifdef HAS_SIGACTION
1577typedef struct sigaction Sigsave_t;
1578#else
1579typedef Sighandler_t Sigsave_t;
1580#endif
1581
ee0007ab
LW
1582#define SCAN_DEF 0
1583#define SCAN_TR 1
1584#define SCAN_REPL 2
79072805
LW
1585
1586#ifdef DEBUGGING
4633a7c4 1587# ifndef register
a0d0e21e
LW
1588# define register
1589# endif
1590# define PAD_SV(po) pad_sv(po)
2ddcc7aa 1591# define RUNOPS_DEFAULT runops_debug
79072805 1592#else
6b88bc9c 1593# define PAD_SV(po) PL_curpad[po]
2ddcc7aa 1594# define RUNOPS_DEFAULT runops_standard
79072805
LW
1595#endif
1596
18f739ee 1597#ifdef MYMALLOC
51dc0457
NIS
1598# define MALLOC_INIT MUTEX_INIT(&PL_malloc_mutex)
1599# define MALLOC_TERM MUTEX_DESTROY(&PL_malloc_mutex)
18f739ee
IZ
1600#else
1601# define MALLOC_INIT
1602# define MALLOC_TERM
1603#endif
1604
b6d9d515 1605
44a0ac01
MB
1606/*
1607 * These need prototyping here because <proto.h> isn't
1608 * included until after runops is initialised.
1609 */
1610
76e3520e 1611#ifndef PERL_OBJECT
49f531da 1612typedef int runops_proc_t _((void));
44a0ac01
MB
1613int runops_standard _((void));
1614#ifdef DEBUGGING
1615int runops_debug _((void));
1616#endif
76e3520e 1617#endif /* PERL_OBJECT */
44a0ac01 1618
940cb80d 1619/* _ (for $_) must be first in the following list (DEFSV requires it) */
54b9620d 1620#define THREADSV_NAMES "_123456789&`'+/.,\\\";^-%=|~:\001\005!@"
a863c7d1 1621
0c30d9ec 1622/* VMS doesn't use environ array and NeXT has problems with crt0.o globals */
1623#if !defined(VMS) && !(defined(NeXT) && defined(__DYNAMIC__))
16de4a3e
RS
1624#if !defined(DONT_DECLARE_STD) \
1625 || (defined(__svr4__) && defined(__GNUC__) && defined(sun)) \
1626 || defined(__sgi) || defined(__DGUX)
79072805 1627extern char ** environ; /* environment variables supplied via exec */
a0d0e21e 1628#endif
0c30d9ec 1629#else
1630# if defined(NeXT) && defined(__DYNAMIC__)
1631
1632# include <mach-o/dyld.h>
1633EXT char *** environ_pointer;
1634# define environ (*environ_pointer)
1635# endif
1636#endif /* environ processing */
1637
79072805
LW
1638
1639/* for tmp use in stupid debuggers */
1640EXT int * di;
1641EXT short * ds;
1642EXT char * dc;
1643
1644/* handy constants */
3e3baf6d 1645EXTCONST char warn_uninit[]
a0d0e21e 1646 INIT("Use of uninitialized value");
3e3baf6d 1647EXTCONST char warn_nosemi[]
463ee0b2 1648 INIT("Semicolon seems to be missing");
3e3baf6d 1649EXTCONST char warn_reserved[]
463ee0b2 1650 INIT("Unquoted string \"%s\" may clash with future reserved word");
3e3baf6d 1651EXTCONST char warn_nl[]
93a17b20 1652 INIT("Unsuccessful %s on filename containing newline");
3e3baf6d 1653EXTCONST char no_wrongref[]
a0d0e21e 1654 INIT("Can't use %s ref as %s ref");
3e3baf6d 1655EXTCONST char no_symref[]
748a9306 1656 INIT("Can't use string (\"%.32s\") as %s ref while \"strict refs\" in use");
3e3baf6d 1657EXTCONST char no_usym[]
8990e307 1658 INIT("Can't use an undefined value as %s reference");
3e3baf6d 1659EXTCONST char no_aelem[]
93a17b20 1660 INIT("Modification of non-creatable array value attempted, subscript %d");
3e3baf6d 1661EXTCONST char no_helem[]
93a17b20 1662 INIT("Modification of non-creatable hash value attempted, subscript \"%s\"");
3e3baf6d 1663EXTCONST char no_modify[]
93a17b20 1664 INIT("Modification of a read-only value attempted");
3e3baf6d 1665EXTCONST char no_mem[]
93a17b20 1666 INIT("Out of memory!\n");
3e3baf6d 1667EXTCONST char no_security[]
463ee0b2 1668 INIT("Insecure dependency in %s%s");
3e3baf6d 1669EXTCONST char no_sock_func[]
93a17b20 1670 INIT("Unsupported socket function \"%s\" called");
3e3baf6d 1671EXTCONST char no_dir_func[]
93a17b20 1672 INIT("Unsupported directory function \"%s\" called");
3e3baf6d 1673EXTCONST char no_func[]
93a17b20 1674 INIT("The %s function is unimplemented");
3e3baf6d 1675EXTCONST char no_myglob[]
748a9306 1676 INIT("\"my\" variable %s can't be in a package");
93a17b20 1677
79072805 1678#ifdef DOINIT
8e07c86e
AD
1679EXT char *sig_name[] = { SIG_NAME };
1680EXT int sig_num[] = { SIG_NUM };
0c30d9ec 1681EXT SV * psig_ptr[sizeof(sig_num)/sizeof(*sig_num)];
1682EXT SV * psig_name[sizeof(sig_num)/sizeof(*sig_num)];
79072805
LW
1683#else
1684EXT char *sig_name[];
8e07c86e 1685EXT int sig_num[];
0c30d9ec 1686EXT SV * psig_ptr[];
1687EXT SV * psig_name[];
79072805
LW
1688#endif
1689
bbce6d69 1690/* fast case folding tables */
1691
79072805 1692#ifdef DOINIT
9d116dd7
JH
1693#ifdef EBCDIC
1694EXT unsigned char fold[] = { /* fast EBCDIC case folding table */
1695 0, 1, 2, 3, 4, 5, 6, 7,
1696 8, 9, 10, 11, 12, 13, 14, 15,
1697 16, 17, 18, 19, 20, 21, 22, 23,
1698 24, 25, 26, 27, 28, 29, 30, 31,
1699 32, 33, 34, 35, 36, 37, 38, 39,
1700 40, 41, 42, 43, 44, 45, 46, 47,
1701 48, 49, 50, 51, 52, 53, 54, 55,
1702 56, 57, 58, 59, 60, 61, 62, 63,
1703 64, 65, 66, 67, 68, 69, 70, 71,
1704 72, 73, 74, 75, 76, 77, 78, 79,
1705 80, 81, 82, 83, 84, 85, 86, 87,
1706 88, 89, 90, 91, 92, 93, 94, 95,
1707 96, 97, 98, 99, 100, 101, 102, 103,
1708 104, 105, 106, 107, 108, 109, 110, 111,
1709 112, 113, 114, 115, 116, 117, 118, 119,
1710 120, 121, 122, 123, 124, 125, 126, 127,
1711 128, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
1712 'H', 'I', 138, 139, 140, 141, 142, 143,
1713 144, 'J', 'K', 'L', 'M', 'N', 'O', 'P',
1714 'Q', 'R', 154, 155, 156, 157, 158, 159,
1715 160, 161, 'S', 'T', 'U', 'V', 'W', 'X',
1716 'Y', 'Z', 170, 171, 172, 173, 174, 175,
1717 176, 177, 178, 179, 180, 181, 182, 183,
1718 184, 185, 186, 187, 188, 189, 190, 191,
1719 192, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
1720 'h', 'i', 202, 203, 204, 205, 206, 207,
1721 208, 'j', 'k', 'l', 'm', 'n', 'o', 'p',
1722 'q', 'r', 218, 219, 220, 221, 222, 223,
1723 224, 225, 's', 't', 'u', 'v', 'w', 'x',
1724 'y', 'z', 234, 235, 236, 237, 238, 239,
1725 240, 241, 242, 243, 244, 245, 246, 247,
1726 248, 249, 250, 251, 252, 253, 254, 255
1727};
1728#else /* ascii rather than ebcdic */
36477c24 1729EXTCONST unsigned char fold[] = {
79072805
LW
1730 0, 1, 2, 3, 4, 5, 6, 7,
1731 8, 9, 10, 11, 12, 13, 14, 15,
1732 16, 17, 18, 19, 20, 21, 22, 23,
1733 24, 25, 26, 27, 28, 29, 30, 31,
1734 32, 33, 34, 35, 36, 37, 38, 39,
1735 40, 41, 42, 43, 44, 45, 46, 47,
1736 48, 49, 50, 51, 52, 53, 54, 55,
1737 56, 57, 58, 59, 60, 61, 62, 63,
1738 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
1739 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
1740 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
1741 'x', 'y', 'z', 91, 92, 93, 94, 95,
1742 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
1743 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
1744 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
1745 'X', 'Y', 'Z', 123, 124, 125, 126, 127,
1746 128, 129, 130, 131, 132, 133, 134, 135,
1747 136, 137, 138, 139, 140, 141, 142, 143,
1748 144, 145, 146, 147, 148, 149, 150, 151,
1749 152, 153, 154, 155, 156, 157, 158, 159,
1750 160, 161, 162, 163, 164, 165, 166, 167,
1751 168, 169, 170, 171, 172, 173, 174, 175,
1752 176, 177, 178, 179, 180, 181, 182, 183,
1753 184, 185, 186, 187, 188, 189, 190, 191,
1754 192, 193, 194, 195, 196, 197, 198, 199,
1755 200, 201, 202, 203, 204, 205, 206, 207,
1756 208, 209, 210, 211, 212, 213, 214, 215,
1757 216, 217, 218, 219, 220, 221, 222, 223,
1758 224, 225, 226, 227, 228, 229, 230, 231,
1759 232, 233, 234, 235, 236, 237, 238, 239,
1760 240, 241, 242, 243, 244, 245, 246, 247,
1761 248, 249, 250, 251, 252, 253, 254, 255
1762};
9d116dd7 1763#endif /* !EBCDIC */
79072805 1764#else
71be2cbc 1765EXTCONST unsigned char fold[];
79072805
LW
1766#endif
1767
1768#ifdef DOINIT
bbce6d69 1769EXT unsigned char fold_locale[] = {
79072805
LW
1770 0, 1, 2, 3, 4, 5, 6, 7,
1771 8, 9, 10, 11, 12, 13, 14, 15,
1772 16, 17, 18, 19, 20, 21, 22, 23,
1773 24, 25, 26, 27, 28, 29, 30, 31,
1774 32, 33, 34, 35, 36, 37, 38, 39,
1775 40, 41, 42, 43, 44, 45, 46, 47,
1776 48, 49, 50, 51, 52, 53, 54, 55,
1777 56, 57, 58, 59, 60, 61, 62, 63,
1778 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
1779 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
1780 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
1781 'x', 'y', 'z', 91, 92, 93, 94, 95,
1782 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
1783 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
1784 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
1785 'X', 'Y', 'Z', 123, 124, 125, 126, 127,
1786 128, 129, 130, 131, 132, 133, 134, 135,
1787 136, 137, 138, 139, 140, 141, 142, 143,
1788 144, 145, 146, 147, 148, 149, 150, 151,
1789 152, 153, 154, 155, 156, 157, 158, 159,
1790 160, 161, 162, 163, 164, 165, 166, 167,
1791 168, 169, 170, 171, 172, 173, 174, 175,
1792 176, 177, 178, 179, 180, 181, 182, 183,
1793 184, 185, 186, 187, 188, 189, 190, 191,
1794 192, 193, 194, 195, 196, 197, 198, 199,
1795 200, 201, 202, 203, 204, 205, 206, 207,
1796 208, 209, 210, 211, 212, 213, 214, 215,
1797 216, 217, 218, 219, 220, 221, 222, 223,
1798 224, 225, 226, 227, 228, 229, 230, 231,
1799 232, 233, 234, 235, 236, 237, 238, 239,
1800 240, 241, 242, 243, 244, 245, 246, 247,
1801 248, 249, 250, 251, 252, 253, 254, 255
1802};
1803#else
bbce6d69 1804EXT unsigned char fold_locale[];
79072805
LW
1805#endif
1806
1807#ifdef DOINIT
9d116dd7
JH
1808#ifdef EBCDIC
1809EXT unsigned char freq[] = {/* EBCDIC frequencies for mixed English/C */
1810 1, 2, 84, 151, 154, 155, 156, 157,
1811 165, 246, 250, 3, 158, 7, 18, 29,
1812 40, 51, 62, 73, 85, 96, 107, 118,
1813 129, 140, 147, 148, 149, 150, 152, 153,
1814 255, 6, 8, 9, 10, 11, 12, 13,
1815 14, 15, 24, 25, 26, 27, 28, 226,
1816 29, 30, 31, 32, 33, 43, 44, 45,
1817 46, 47, 48, 49, 50, 76, 77, 78,
1818 79, 80, 81, 82, 83, 84, 85, 86,
1819 87, 94, 95, 234, 181, 233, 187, 190,
1820 180, 96, 97, 98, 99, 100, 101, 102,
1821 104, 112, 182, 174, 236, 232, 229, 103,
1822 228, 226, 114, 115, 116, 117, 118, 119,
1823 120, 121, 122, 235, 176, 230, 194, 162,
1824 130, 131, 132, 133, 134, 135, 136, 137,
1825 138, 139, 201, 205, 163, 217, 220, 224,
1826 5, 248, 227, 244, 242, 255, 241, 231,
1827 240, 253, 16, 197, 19, 20, 21, 187,
1828 23, 169, 210, 245, 237, 249, 247, 239,
1829 168, 252, 34, 196, 36, 37, 38, 39,
1830 41, 42, 251, 254, 238, 223, 221, 213,
1831 225, 177, 52, 53, 54, 55, 56, 57,
1832 58, 59, 60, 61, 63, 64, 65, 66,
1833 67, 68, 69, 70, 71, 72, 74, 75,
1834 205, 208, 186, 202, 200, 218, 198, 179,
1835 178, 214, 88, 89, 90, 91, 92, 93,
1836 217, 166, 170, 207, 199, 209, 206, 204,
1837 160, 212, 105, 106, 108, 109, 110, 111,
1838 203, 113, 216, 215, 192, 175, 193, 243,
1839 172, 161, 123, 124, 125, 126, 127, 128,
1840 222, 219, 211, 195, 188, 193, 185, 184,
1841 191, 183, 141, 142, 143, 144, 145, 146
1842};
1843#else /* ascii rather than ebcdic */
71be2cbc 1844EXTCONST unsigned char freq[] = { /* letter frequencies for mixed English/C */
79072805
LW
1845 1, 2, 84, 151, 154, 155, 156, 157,
1846 165, 246, 250, 3, 158, 7, 18, 29,
1847 40, 51, 62, 73, 85, 96, 107, 118,
1848 129, 140, 147, 148, 149, 150, 152, 153,
1849 255, 182, 224, 205, 174, 176, 180, 217,
1850 233, 232, 236, 187, 235, 228, 234, 226,
1851 222, 219, 211, 195, 188, 193, 185, 184,
1852 191, 183, 201, 229, 181, 220, 194, 162,
1853 163, 208, 186, 202, 200, 218, 198, 179,
1854 178, 214, 166, 170, 207, 199, 209, 206,
1855 204, 160, 212, 216, 215, 192, 175, 173,
1856 243, 172, 161, 190, 203, 189, 164, 230,
1857 167, 248, 227, 244, 242, 255, 241, 231,
1858 240, 253, 169, 210, 245, 237, 249, 247,
1859 239, 168, 252, 251, 254, 238, 223, 221,
1860 213, 225, 177, 197, 171, 196, 159, 4,
1861 5, 6, 8, 9, 10, 11, 12, 13,
1862 14, 15, 16, 17, 19, 20, 21, 22,
1863 23, 24, 25, 26, 27, 28, 30, 31,
1864 32, 33, 34, 35, 36, 37, 38, 39,
1865 41, 42, 43, 44, 45, 46, 47, 48,
1866 49, 50, 52, 53, 54, 55, 56, 57,
1867 58, 59, 60, 61, 63, 64, 65, 66,
1868 67, 68, 69, 70, 71, 72, 74, 75,
1869 76, 77, 78, 79, 80, 81, 82, 83,
1870 86, 87, 88, 89, 90, 91, 92, 93,
1871 94, 95, 97, 98, 99, 100, 101, 102,
1872 103, 104, 105, 106, 108, 109, 110, 111,
1873 112, 113, 114, 115, 116, 117, 119, 120,
1874 121, 122, 123, 124, 125, 126, 127, 128,
1875 130, 131, 132, 133, 134, 135, 136, 137,
1876 138, 139, 141, 142, 143, 144, 145, 146
1877};
9d116dd7 1878#endif
79072805 1879#else
71be2cbc 1880EXTCONST unsigned char freq[];
79072805
LW
1881#endif
1882
8990e307
LW
1883#ifdef DEBUGGING
1884#ifdef DOINIT
71be2cbc 1885EXTCONST char* block_type[] = {
8990e307
LW
1886 "NULL",
1887 "SUB",
1888 "EVAL",
1889 "LOOP",
1890 "SUBST",
1891 "BLOCK",
1892};
1893#else
71be2cbc 1894EXTCONST char* block_type[];
8990e307
LW
1895#endif
1896#endif
1897
79072805
LW
1898/*****************************************************************************/
1899/* This lexer/parser stuff is currently global since yacc is hard to reenter */
1900/*****************************************************************************/
8990e307 1901/* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */
79072805 1902
a0d0e21e
LW
1903#include "perly.h"
1904
fb73857a 1905#define LEX_NOTPARSING 11 /* borrowed from toke.c */
1906
79072805
LW
1907typedef enum {
1908 XOPERATOR,
1909 XTERM,
79072805 1910 XREF,
8990e307 1911 XSTATE,
a0d0e21e
LW
1912 XBLOCK,
1913 XTERMBLOCK
79072805
LW
1914} expectation;
1915
f9caadc6
DL
1916enum { /* pass one of these to get_vtbl */
1917 want_vtbl_sv,
1918 want_vtbl_env,
1919 want_vtbl_envelem,
1920 want_vtbl_sig,
1921 want_vtbl_sigelem,
1922 want_vtbl_pack,
1923 want_vtbl_packelem,
1924 want_vtbl_dbline,
1925 want_vtbl_isa,
1926 want_vtbl_isaelem,
1927 want_vtbl_arylen,
1928 want_vtbl_glob,
1929 want_vtbl_mglob,
1930 want_vtbl_nkeys,
1931 want_vtbl_taint,
1932 want_vtbl_substr,
1933 want_vtbl_vec,
1934 want_vtbl_pos,
1935 want_vtbl_bm,
1936 want_vtbl_fm,
1937 want_vtbl_uvar,
1938 want_vtbl_defelem,
1939 want_vtbl_regexp,
1940 want_vtbl_collxfrm,
1941 want_vtbl_amagic,
0a42b372 1942 want_vtbl_amagicelem
f9caadc6 1943#ifdef USE_THREADS
0a42b372
GB
1944 ,
1945 want_vtbl_mutex
f9caadc6
DL
1946#endif
1947};
1948
85e6fe83
LW
1949
1950 /* Note: the lowest 8 bits are reserved for
1951 stuffing into op->op_private */
1952#define HINT_INTEGER 0x00000001
1953#define HINT_STRICT_REFS 0x00000002
1954
1955#define HINT_BLOCK_SCOPE 0x00000100
1956#define HINT_STRICT_SUBS 0x00000200
1957#define HINT_STRICT_VARS 0x00000400
bbce6d69 1958#define HINT_LOCALE 0x00000800
85e6fe83 1959
b3ac6de7
IZ
1960#define HINT_NEW_INTEGER 0x00001000
1961#define HINT_NEW_FLOAT 0x00002000
1962#define HINT_NEW_BINARY 0x00004000
1963#define HINT_NEW_STRING 0x00008000
1964#define HINT_NEW_RE 0x00010000
1965#define HINT_LOCALIZE_HH 0x00020000 /* %^H needs to be copied */
1966
b3eb6a9b 1967#define HINT_RE_TAINT 0x00100000
e4d48cc9 1968#define HINT_RE_EVAL 0x00200000
b3eb6a9b 1969
d4cce5f1
NIS
1970/* Various states of an input record separator SV (rs, nrs) */
1971#define RsSNARF(sv) (! SvOK(sv))
1972#define RsSIMPLE(sv) (SvOK(sv) && SvCUR(sv))
1973#define RsPARA(sv) (SvOK(sv) && ! SvCUR(sv))
5b2b9c68 1974#define RsRECORD(sv) (SvROK(sv) && (SvIV(SvRV(sv)) > 0))
79072805 1975
56953603 1976/* Enable variables which are pointers to functions */
15e52e56
GS
1977#ifdef PERL_OBJECT
1978typedef regexp*(CPerlObj::*regcomp_t) _((char* exp, char* xend, PMOP* pm));
1979typedef I32 (CPerlObj::*regexec_t) _((regexp* prog, char* stringarg,
1980 char* strend, char* strbeg,
1981 I32 minend, SV* screamer, void* data,
1982 U32 flags));
1983#else
56953603
IZ
1984typedef regexp*(*regcomp_t) _((char* exp, char* xend, PMOP* pm));
1985typedef I32 (*regexec_t) _((regexp* prog, char* stringarg, char* strend, char*
1986 strbeg, I32 minend, SV* screamer, void* data,
1987 U32 flags));
1988
15e52e56
GS
1989#endif
1990
22239a37
NIS
1991/* Set up PERLVAR macros for populating structs */
1992#define PERLVAR(var,type) type var;
1993#define PERLVARI(var,type,init) type var;
3fe35a81 1994#define PERLVARIC(var,type,init) type var;
22239a37 1995
58a50f62
GS
1996/* Interpreter exitlist entry */
1997typedef struct exitlistentry {
1998#ifdef PERL_OBJECT
1999 void (*fn) _((CPerlObj*, void*));
2000#else
2001 void (*fn) _((void*));
2002#endif
2003 void *ptr;
2004} PerlExitListEntry;
2005
76e3520e
GS
2006#ifdef PERL_OBJECT
2007extern "C" CPerlObj* perl_alloc _((IPerlMem*, IPerlEnv*, IPerlStdIO*, IPerlLIO*, IPerlDir*, IPerlSock*, IPerlProc*));
2008
2009typedef int (CPerlObj::*runops_proc_t) _((void));
2010#undef EXT
2011#define EXT
2012#undef EXTCONST
2013#define EXTCONST
2014#undef INIT
2015#define INIT(x)
2016
2017class CPerlObj {
2018public:
2019 CPerlObj(IPerlMem*, IPerlEnv*, IPerlStdIO*, IPerlLIO*, IPerlDir*, IPerlSock*, IPerlProc*);
2020 void Init(void);
2021 void* operator new(size_t nSize, IPerlMem *pvtbl);
2022#endif /* PERL_OBJECT */
2023
22239a37
NIS
2024#ifdef PERL_GLOBAL_STRUCT
2025struct perl_vars {
2026#include "perlvars.h"
2027};
2028
2029#ifdef PERL_CORE
533c011a
NIS
2030EXT struct perl_vars PL_Vars;
2031EXT struct perl_vars *PL_VarsPtr INIT(&PL_Vars);
2032#else /* PERL_CORE */
22239a37
NIS
2033#if !defined(__GNUC__) || !defined(WIN32)
2034EXT
533c011a
NIS
2035#endif /* WIN32 */
2036struct perl_vars *PL_VarsPtr;
2037#define PL_Vars (*((PL_VarsPtr) ? PL_VarsPtr : (PL_VarsPtr = Perl_GetVars())))
2038#endif /* PERL_CORE */
22239a37
NIS
2039#endif /* PERL_GLOBAL_STRUCT */
2040
8990e307 2041#ifdef MULTIPLICITY
d4cce5f1
NIS
2042/* If we have multiple interpreters define a struct
2043 holding variables which must be per-interpreter
2044 If we don't have threads anything that would have
2045 be per-thread is per-interpreter.
2046*/
2047
79072805 2048struct interpreter {
d4cce5f1
NIS
2049#ifndef USE_THREADS
2050#include "thrdvar.h"
2051#endif
2052#include "intrpvar.h"
49f531da 2053};
d4cce5f1 2054
79072805 2055#else
49f531da
NIS
2056struct interpreter {
2057 char broiled;
2058};
79072805
LW
2059#endif
2060
d4cce5f1
NIS
2061#ifdef USE_THREADS
2062/* If we have threads define a struct with all the variables
2063 * that have to be per-thread
49f531da 2064 */
8023c3ce 2065
79072805 2066
49f531da 2067struct perl_thread {
49f531da 2068#include "thrdvar.h"
79072805 2069};
d4cce5f1 2070
22fae026
TM
2071typedef struct perl_thread *Thread;
2072
2073#else
2074typedef void *Thread;
22239a37
NIS
2075#endif
2076
2077/* Done with PERLVAR macros for now ... */
d4cce5f1
NIS
2078#undef PERLVAR
2079#undef PERLVARI
3fe35a81 2080#undef PERLVARIC
79072805 2081
22239a37 2082#include "thread.h"
79072805 2083#include "pp.h"
79072805
LW
2084#include "proto.h"
2085
a0d0e21e
LW
2086#ifdef EMBED
2087#define Perl_sv_setptrobj(rv,ptr,name) Perl_sv_setref_iv(rv,name,(IV)ptr)
2088#define Perl_sv_setptrref(rv,ptr) Perl_sv_setref_iv(rv,Nullch,(IV)ptr)
2089#else
2090#define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,(IV)ptr)
2091#define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,(IV)ptr)
2092#endif
2093
d4cce5f1
NIS
2094/* The following must follow proto.h as #defines mess up syntax */
2095
2096#include "embedvar.h"
2097
2098/* Now include all the 'global' variables
2099 * If we don't have threads or multiple interpreters
2100 * these include variables that would have been their struct-s
2101 */
533c011a
NIS
2102
2103#define PERLVAR(var,type) EXT type PL_##var;
2104#define PERLVARI(var,type,init) EXT type PL_##var INIT(init);
2105#define PERLVARIC(var,type,init) EXTCONST type PL_##var INIT(init);
d4cce5f1 2106
22239a37 2107#ifndef PERL_GLOBAL_STRUCT
d4cce5f1 2108#include "perlvars.h"
22239a37 2109#endif
d4cce5f1
NIS
2110
2111#ifndef MULTIPLICITY
d4cce5f1 2112
066ef5b5
GS
2113# include "intrpvar.h"
2114# ifndef USE_THREADS
2115# include "thrdvar.h"
2116# endif
d4cce5f1 2117
22239a37
NIS
2118#endif
2119
76e3520e 2120#ifdef PERL_OBJECT
d0c1b099
GS
2121/*
2122 * The following is a buffer where new variables must
2123 * be defined to maintain binary compatibility with PERL_OBJECT
2124 * for 5.005
2125 */
2126PERLVAR(object_compatibility[30], char)
76e3520e
GS
2127};
2128
2129#include "objpp.h"
2130#ifdef DOINIT
2131#include "INTERN.h"
2132#else
2133#include "EXTERN.h"
2134#endif
2135#endif /* PERL_OBJECT */
2136
22239a37 2137
d4cce5f1
NIS
2138#undef PERLVAR
2139#undef PERLVARI
0f3f18a6 2140#undef PERLVARIC
79072805 2141
a835ef8a
NIS
2142#if defined(HASATTRIBUTE) && defined(WIN32)
2143/*
2144 * This provides a layer of functions and macros to ensure extensions will
2145 * get to use the same RTL functions as the core.
2146 * It has to go here or #define of printf messes up __attribute__
2147 * stuff in proto.h
2148 */
76e3520e 2149#ifndef PERL_OBJECT
a835ef8a 2150# include <win32iop.h>
76e3520e 2151#endif /* PERL_OBJECT */
a835ef8a
NIS
2152#endif /* WIN32 */
2153
79072805 2154#ifdef DOINIT
bbce6d69 2155
4633a7c4 2156EXT MGVTBL vtbl_sv = {magic_get,
463ee0b2
LW
2157 magic_set,
2158 magic_len,
2159 0, 0};
fb73857a 2160EXT MGVTBL vtbl_env = {0, magic_set_all_env,
2161 0, magic_clear_all_env,
66b1d557 2162 0};
4633a7c4 2163EXT MGVTBL vtbl_envelem = {0, magic_setenv,
85e6fe83
LW
2164 0, magic_clearenv,
2165 0};
4633a7c4 2166EXT MGVTBL vtbl_sig = {0, 0, 0, 0, 0};
0c30d9ec 2167EXT MGVTBL vtbl_sigelem = {magic_getsig,
2168 magic_setsig,
2169 0, magic_clearsig,
2170 0};
93965878 2171EXT MGVTBL vtbl_pack = {0, 0, magic_sizepack, magic_wipepack,
a0d0e21e 2172 0};
4633a7c4 2173EXT MGVTBL vtbl_packelem = {magic_getpack,
463ee0b2
LW
2174 magic_setpack,
2175 0, magic_clearpack,
2176 0};
4633a7c4 2177EXT MGVTBL vtbl_dbline = {0, magic_setdbline,
463ee0b2 2178 0, 0, 0};
4633a7c4 2179EXT MGVTBL vtbl_isa = {0, magic_setisa,
fb73857a 2180 0, magic_setisa,
2181 0};
4633a7c4 2182EXT MGVTBL vtbl_isaelem = {0, magic_setisa,
463ee0b2 2183 0, 0, 0};
4633a7c4 2184EXT MGVTBL vtbl_arylen = {magic_getarylen,
463ee0b2
LW
2185 magic_setarylen,
2186 0, 0, 0};
4633a7c4 2187EXT MGVTBL vtbl_glob = {magic_getglob,
463ee0b2
LW
2188 magic_setglob,
2189 0, 0, 0};
4633a7c4 2190EXT MGVTBL vtbl_mglob = {0, magic_setmglob,
463ee0b2 2191 0, 0, 0};
6ff81951
GS
2192EXT MGVTBL vtbl_nkeys = {magic_getnkeys,
2193 magic_setnkeys,
99abf803 2194 0, 0, 0};
4633a7c4 2195EXT MGVTBL vtbl_taint = {magic_gettaint,magic_settaint,
463ee0b2 2196 0, 0, 0};
6ff81951 2197EXT MGVTBL vtbl_substr = {magic_getsubstr, magic_setsubstr,
463ee0b2 2198 0, 0, 0};
6ff81951
GS
2199EXT MGVTBL vtbl_vec = {magic_getvec,
2200 magic_setvec,
463ee0b2 2201 0, 0, 0};
4633a7c4 2202EXT MGVTBL vtbl_pos = {magic_getpos,
a0d0e21e
LW
2203 magic_setpos,
2204 0, 0, 0};
4633a7c4 2205EXT MGVTBL vtbl_bm = {0, magic_setbm,
463ee0b2 2206 0, 0, 0};
55497cff 2207EXT MGVTBL vtbl_fm = {0, magic_setfm,
2208 0, 0, 0};
4633a7c4 2209EXT MGVTBL vtbl_uvar = {magic_getuvar,
463ee0b2
LW
2210 magic_setuvar,
2211 0, 0, 0};
f93b4edd
MB
2212#ifdef USE_THREADS
2213EXT MGVTBL vtbl_mutex = {0, 0, 0, 0, magic_mutexfree};
2214#endif /* USE_THREADS */
68dc0745 2215EXT MGVTBL vtbl_defelem = {magic_getdefelem,magic_setdefelem,
02270b4e 2216 0, 0, 0};
a0d0e21e 2217
227a8b4b 2218EXT MGVTBL vtbl_regexp = {0,0,0,0, magic_freeregexp};
c277df42 2219
36477c24 2220#ifdef USE_LOCALE_COLLATE
bbce6d69 2221EXT MGVTBL vtbl_collxfrm = {0,
2222 magic_setcollxfrm,
2223 0, 0, 0};
2224#endif
a0d0e21e
LW
2225
2226#ifdef OVERLOAD
4633a7c4 2227EXT MGVTBL vtbl_amagic = {0, magic_setamagic,
748a9306 2228 0, 0, magic_setamagic};
4633a7c4 2229EXT MGVTBL vtbl_amagicelem = {0, magic_setamagic,
748a9306 2230 0, 0, magic_setamagic};
a0d0e21e
LW
2231#endif /* OVERLOAD */
2232
bbce6d69 2233#else /* !DOINIT */
2234
79072805
LW
2235EXT MGVTBL vtbl_sv;
2236EXT MGVTBL vtbl_env;
2237EXT MGVTBL vtbl_envelem;
2238EXT MGVTBL vtbl_sig;
2239EXT MGVTBL vtbl_sigelem;
463ee0b2
LW
2240EXT MGVTBL vtbl_pack;
2241EXT MGVTBL vtbl_packelem;
79072805 2242EXT MGVTBL vtbl_dbline;
463ee0b2
LW
2243EXT MGVTBL vtbl_isa;
2244EXT MGVTBL vtbl_isaelem;
79072805
LW
2245EXT MGVTBL vtbl_arylen;
2246EXT MGVTBL vtbl_glob;
93a17b20 2247EXT MGVTBL vtbl_mglob;
99abf803 2248EXT MGVTBL vtbl_nkeys;
463ee0b2 2249EXT MGVTBL vtbl_taint;
79072805
LW
2250EXT MGVTBL vtbl_substr;
2251EXT MGVTBL vtbl_vec;
a0d0e21e 2252EXT MGVTBL vtbl_pos;
79072805 2253EXT MGVTBL vtbl_bm;
55497cff 2254EXT MGVTBL vtbl_fm;
79072805 2255EXT MGVTBL vtbl_uvar;
a0d0e21e 2256
f93b4edd
MB
2257#ifdef USE_THREADS
2258EXT MGVTBL vtbl_mutex;
2259#endif /* USE_THREADS */
2260
68dc0745 2261EXT MGVTBL vtbl_defelem;
c277df42 2262EXT MGVTBL vtbl_regexp;
a0d0e21e 2263
36477c24 2264#ifdef USE_LOCALE_COLLATE
bbce6d69 2265EXT MGVTBL vtbl_collxfrm;
2266#endif
a0d0e21e
LW
2267
2268#ifdef OVERLOAD
2269EXT MGVTBL vtbl_amagic;
2270EXT MGVTBL vtbl_amagicelem;
2271#endif /* OVERLOAD */
2272
bbce6d69 2273#endif /* !DOINIT */
85e6fe83 2274
a0d0e21e 2275#ifdef OVERLOAD
c0315cdf 2276
a6006777 2277#define NofAMmeth 58
a0d0e21e 2278#ifdef DOINIT
a6006777 2279EXTCONST char * AMG_names[NofAMmeth] = {
2280 "fallback", "abs", /* "fallback" should be the first. */
2281 "bool", "nomethod",
2282 "\"\"", "0+",
2283 "+", "+=",
2284 "-", "-=",
2285 "*", "*=",
2286 "/", "/=",
2287 "%", "%=",
2288 "**", "**=",
2289 "<<", "<<=",
2290 ">>", ">>=",
2291 "&", "&=",
2292 "|", "|=",
2293 "^", "^=",
2294 "<", "<=",
2295 ">", ">=",
2296 "==", "!=",
2297 "<=>", "cmp",
2298 "lt", "le",
2299 "gt", "ge",
2300 "eq", "ne",
2301 "!", "~",
2302 "++", "--",
2303 "atan2", "cos",
2304 "sin", "exp",
2305 "log", "sqrt",
2306 "x", "x=",
2307 ".", ".=",
2308 "=", "neg"
a0d0e21e
LW
2309};
2310#else
a6006777 2311EXTCONST char * AMG_names[NofAMmeth];
a0d0e21e
LW
2312#endif /* def INITAMAGIC */
2313
a6006777 2314struct am_table {
a0d0e21e
LW
2315 long was_ok_sub;
2316 long was_ok_am;
a6006777 2317 U32 flags;
2318 CV* table[NofAMmeth];
a0d0e21e
LW
2319 long fallback;
2320};
a6006777 2321struct am_table_short {
2322 long was_ok_sub;
2323 long was_ok_am;
2324 U32 flags;
2325};
a0d0e21e 2326typedef struct am_table AMT;
a6006777 2327typedef struct am_table_short AMTS;
a0d0e21e
LW
2328
2329#define AMGfallNEVER 1
2330#define AMGfallNO 2
2331#define AMGfallYES 3
2332
a6006777 2333#define AMTf_AMAGIC 1
2334#define AMT_AMAGIC(amt) ((amt)->flags & AMTf_AMAGIC)
2335#define AMT_AMAGIC_on(amt) ((amt)->flags |= AMTf_AMAGIC)
2336#define AMT_AMAGIC_off(amt) ((amt)->flags &= ~AMTf_AMAGIC)
2337
a0d0e21e
LW
2338enum {
2339 fallback_amg, abs_amg,
2340 bool__amg, nomethod_amg,
2341 string_amg, numer_amg,
2342 add_amg, add_ass_amg,
2343 subtr_amg, subtr_ass_amg,
2344 mult_amg, mult_ass_amg,
2345 div_amg, div_ass_amg,
76e3520e 2346 modulo_amg, modulo_ass_amg,
a0d0e21e
LW
2347 pow_amg, pow_ass_amg,
2348 lshift_amg, lshift_ass_amg,
2349 rshift_amg, rshift_ass_amg,
748a9306
LW
2350 band_amg, band_ass_amg,
2351 bor_amg, bor_ass_amg,
2352 bxor_amg, bxor_ass_amg,
a0d0e21e
LW
2353 lt_amg, le_amg,
2354 gt_amg, ge_amg,
2355 eq_amg, ne_amg,
2356 ncmp_amg, scmp_amg,
2357 slt_amg, sle_amg,
2358 sgt_amg, sge_amg,
2359 seq_amg, sne_amg,
a0d0e21e
LW
2360 not_amg, compl_amg,
2361 inc_amg, dec_amg,
2362 atan2_amg, cos_amg,
2363 sin_amg, exp_amg,
2364 log_amg, sqrt_amg,
2365 repeat_amg, repeat_ass_amg,
748a9306
LW
2366 concat_amg, concat_ass_amg,
2367 copy_amg, neg_amg
a0d0e21e 2368};
c0315cdf
JH
2369
2370/*
2371 * some compilers like to redefine cos et alia as faster
2372 * (and less accurate?) versions called F_cos et cetera (Quidquid
2373 * latine dictum sit, altum viditur.) This trick collides with
2374 * the Perl overloading (amg). The following #defines fool both.
2375 */
2376
2377#ifdef _FASTMATH
2378# ifdef atan2
2379# define F_atan2_amg atan2_amg
2380# endif
2381# ifdef cos
2382# define F_cos_amg cos_amg
2383# endif
2384# ifdef exp
2385# define F_exp_amg exp_amg
2386# endif
2387# ifdef log
2388# define F_log_amg log_amg
2389# endif
2390# ifdef pow
2391# define F_pow_amg pow_amg
2392# endif
2393# ifdef sin
2394# define F_sin_amg sin_amg
2395# endif
2396# ifdef sqrt
2397# define F_sqrt_amg sqrt_amg
2398# endif
2399#endif /* _FASTMATH */
2400
a0d0e21e
LW
2401#endif /* OVERLOAD */
2402
491527d0 2403#define PERLDB_ALL 0x3f /* No _NONAME, _GOTO */
84902520
TB
2404#define PERLDBf_SUB 0x01 /* Debug sub enter/exit. */
2405#define PERLDBf_LINE 0x02 /* Keep line #. */
2406#define PERLDBf_NOOPT 0x04 /* Switch off optimizations. */
2407#define PERLDBf_INTER 0x08 /* Preserve more data for
2408 later inspections. */
2409#define PERLDBf_SUBLINE 0x10 /* Keep subr source lines. */
2410#define PERLDBf_SINGLE 0x20 /* Start with single-step on. */
491527d0
GS
2411#define PERLDBf_NONAME 0x40 /* For _SUB: no name of the subr. */
2412#define PERLDBf_GOTO 0x80 /* Report goto: call DB::goto. */
84902520 2413
3280af22
NIS
2414#define PERLDB_SUB (PL_perldb && (PL_perldb & PERLDBf_SUB))
2415#define PERLDB_LINE (PL_perldb && (PL_perldb & PERLDBf_LINE))
2416#define PERLDB_NOOPT (PL_perldb && (PL_perldb & PERLDBf_NOOPT))
2417#define PERLDB_INTER (PL_perldb && (PL_perldb & PERLDBf_INTER))
2418#define PERLDB_SUBLINE (PL_perldb && (PL_perldb & PERLDBf_SUBLINE))
2419#define PERLDB_SINGLE (PL_perldb && (PL_perldb & PERLDBf_SINGLE))
2420#define PERLDB_SUB_NN (PL_perldb && (PL_perldb & (PERLDBf_NONAME)))
2421#define PERLDB_GOTO (PL_perldb && (PL_perldb & PERLDBf_GOTO))
84902520 2422
bbce6d69 2423
36477c24 2424#ifdef USE_LOCALE_NUMERIC
bbce6d69 2425
36477c24 2426#define SET_NUMERIC_STANDARD() \
2427 STMT_START { \
3280af22 2428 if (! PL_numeric_standard) \
36477c24 2429 perl_set_numeric_standard(); \
2430 } STMT_END
2431
2432#define SET_NUMERIC_LOCAL() \
2433 STMT_START { \
3280af22 2434 if (! PL_numeric_local) \
36477c24 2435 perl_set_numeric_local(); \
2436 } STMT_END
bbce6d69 2437
36477c24 2438#else /* !USE_LOCALE_NUMERIC */
bbce6d69 2439
36477c24 2440#define SET_NUMERIC_STANDARD() /**/
2441#define SET_NUMERIC_LOCAL() /**/
bbce6d69 2442
36477c24 2443#endif /* !USE_LOCALE_NUMERIC */
a0d0e21e 2444
e5c9fcd0 2445#if !defined(PERLIO_IS_STDIO) && defined(HASATTRIBUTE)
760ac839
LW
2446/*
2447 * Now we have __attribute__ out of the way
2448 * Remap printf
2449 */
2450#define printf PerlIO_stdoutf
2451#endif
2452
a868473f
NIS
2453#ifndef PERL_SCRIPT_MODE
2454#define PERL_SCRIPT_MODE "r"
2455#endif
2456
fba3b22e
MB
2457/*
2458 * nice_chunk and nice_chunk size need to be set
2459 * and queried under the protection of sv_mutex
2460 */
2461#define offer_nice_chunk(chunk, chunk_size) do { \
940cb80d 2462 LOCK_SV_MUTEX; \
3280af22
NIS
2463 if (!PL_nice_chunk) { \
2464 PL_nice_chunk = (char*)(chunk); \
2465 PL_nice_chunk_size = (chunk_size); \
fba3b22e 2466 } \
fc80cf79
GS
2467 else { \
2468 Safefree(chunk); \
2469 } \
940cb80d 2470 UNLOCK_SV_MUTEX; \
fba3b22e
MB
2471 } while (0)
2472
bd89102f
AD
2473#ifdef HAS_SEM
2474# include <sys/ipc.h>
2475# include <sys/sem.h>
2476# ifndef HAS_UNION_SEMUN /* Provide the union semun. */
2477 union semun {
2478 int val;
2479 struct semid_ds *buf;
2480 unsigned short *array;
2481 };
2482# endif
2483# ifdef USE_SEMCTL_SEMUN
2484# define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun)
2485# else
2486# ifdef USE_SEMCTL_SEMID_DS
2487# define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun.buf)
2488# endif
2489# endif
2490# ifndef Semctl /* Place our bets on the semun horse. */
2491# define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun)
2492# endif
2493#endif
49f531da 2494
85e6fe83 2495#endif /* Include guard */