This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
don't create empty directories in installperl
[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
8ada0baa
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(); }
253#define TAINT_PROPER(s) if (PL_tainting) { taint_proper(no_security, 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
f86702cc 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
1118# include "unixish.h"
1119# endif
0c30d9ec 1120# endif
748a9306 1121# endif
32f822de
GS
1122#endif
1123
ac4c12e7
GS
1124#ifndef FUNC_NAME_TO_PTR
1125#define FUNC_NAME_TO_PTR(name) name
1126#endif
1127
32f822de 1128/*
dd96f567
IZ
1129 * USE_THREADS needs to be after unixish.h as <pthread.h> includes
1130 * <sys/signal.h> which defines NSIG - which will stop inclusion of <signal.h>
32f822de
GS
1131 * this results in many functions being undeclared which bothers C++
1132 * May make sense to have threads after "*ish.h" anyway
1133 */
1134
1135#ifdef USE_THREADS
79d59c5f
GS
1136 /* pending resolution of licensing issues, we avoid the erstwhile
1137 * atomic.h everywhere */
1138# define EMULATE_ATOMIC_REFCOUNTS
1139
32f822de
GS
1140# ifdef FAKE_THREADS
1141# include "fakethr.h"
1142# else
1143# ifdef WIN32
1144# include <win32thread.h>
1145# else
dd96f567
IZ
1146# ifdef OS2
1147# include "os2thread.h"
1148# else
1149# include <pthread.h>
c6ee37c5 1150typedef pthread_t perl_os_thread;
32f822de
GS
1151typedef pthread_mutex_t perl_mutex;
1152typedef pthread_cond_t perl_cond;
1153typedef pthread_key_t perl_key;
dd96f567 1154# endif /* OS2 */
32f822de
GS
1155# endif /* WIN32 */
1156# endif /* FAKE_THREADS */
1157#endif /* USE_THREADS */
1158
1159
3fc1aec6 1160
68dc0745 1161#ifdef VMS
6b88bc9c 1162# define STATUS_NATIVE PL_statusvalue_vms
68dc0745 1163# define STATUS_NATIVE_EXPORT \
6b88bc9c 1164 ((I32)PL_statusvalue_vms == -1 ? 44 : PL_statusvalue_vms)
68dc0745 1165# define STATUS_NATIVE_SET(n) \
1166 STMT_START { \
6b88bc9c
GS
1167 PL_statusvalue_vms = (n); \
1168 if ((I32)PL_statusvalue_vms == -1) \
3280af22 1169 PL_statusvalue = -1; \
6b88bc9c 1170 else if (PL_statusvalue_vms & STS$M_SUCCESS) \
3280af22 1171 PL_statusvalue = 0; \
6b88bc9c
GS
1172 else if ((PL_statusvalue_vms & STS$M_SEVERITY) == 0) \
1173 PL_statusvalue = 1 << 8; \
68dc0745 1174 else \
6b88bc9c 1175 PL_statusvalue = (PL_statusvalue_vms & STS$M_SEVERITY) << 8; \
68dc0745 1176 } STMT_END
3280af22 1177# define STATUS_POSIX PL_statusvalue
68dc0745 1178# ifdef VMSISH_STATUS
1179# define STATUS_CURRENT (VMSISH_STATUS ? STATUS_NATIVE : STATUS_POSIX)
1180# else
1181# define STATUS_CURRENT STATUS_POSIX
1182# endif
1183# define STATUS_POSIX_SET(n) \
1184 STMT_START { \
3280af22
NIS
1185 PL_statusvalue = (n); \
1186 if (PL_statusvalue != -1) { \
1187 PL_statusvalue &= 0xFFFF; \
6b88bc9c 1188 PL_statusvalue_vms = PL_statusvalue ? 44 : 1; \
68dc0745 1189 } \
6b88bc9c 1190 else PL_statusvalue_vms = -1; \
68dc0745 1191 } STMT_END
6b88bc9c
GS
1192# define STATUS_ALL_SUCCESS (PL_statusvalue = 0, PL_statusvalue_vms = 1)
1193# define STATUS_ALL_FAILURE (PL_statusvalue = 1, PL_statusvalue_vms = 44)
68dc0745 1194#else
1195# define STATUS_NATIVE STATUS_POSIX
1196# define STATUS_NATIVE_EXPORT STATUS_POSIX
1197# define STATUS_NATIVE_SET STATUS_POSIX_SET
3280af22 1198# define STATUS_POSIX PL_statusvalue
68dc0745 1199# define STATUS_POSIX_SET(n) \
1200 STMT_START { \
3280af22
NIS
1201 PL_statusvalue = (n); \
1202 if (PL_statusvalue != -1) \
1203 PL_statusvalue &= 0xFFFF; \
68dc0745 1204 } STMT_END
1205# define STATUS_CURRENT STATUS_POSIX
3280af22
NIS
1206# define STATUS_ALL_SUCCESS (PL_statusvalue = 0)
1207# define STATUS_ALL_FAILURE (PL_statusvalue = 1)
68dc0745 1208#endif
1209
3fc1aec6 1210/* Some unistd.h's give a prototype for pause() even though
1211 HAS_PAUSE ends up undefined. This causes the #define
1212 below to be rejected by the compmiler. Sigh.
1213*/
1214#ifdef HAS_PAUSE
1215#define Pause pause
1216#else
1217#define Pause() sleep((32767<<16)+32767)
748a9306
LW
1218#endif
1219
1220#ifndef IOCPARM_LEN
1221# ifdef IOCPARM_MASK
1222 /* on BSDish systes we're safe */
1223# define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
1224# else
1225 /* otherwise guess at what's safe */
1226# define IOCPARM_LEN(x) 256
1227# endif
a0d0e21e
LW
1228#endif
1229
0f4eea8f
DL
1230#ifdef UNION_ANY_DEFINITION
1231UNION_ANY_DEFINITION;
1232#else
79072805
LW
1233union any {
1234 void* any_ptr;
1235 I32 any_i32;
a0d0e21e 1236 IV any_iv;
85e6fe83 1237 long any_long;
565764a8 1238 void (CPERLscope(*any_dptr)) _((void*));
79072805 1239};
0f4eea8f 1240#endif
79072805 1241
11343788 1242#ifdef USE_THREADS
52e1cb5e 1243#define ARGSproto struct perl_thread *thr
11343788
MB
1244#else
1245#define ARGSproto void
1246#endif /* USE_THREADS */
1247
5aabfad6 1248/* Work around some cygwin32 problems with importing global symbols */
1249#if defined(CYGWIN32) && defined(DLLIMPORT)
1250# include "cw32imp.h"
1251#endif
1252
378cc40b 1253#include "regexp.h"
79072805 1254#include "sv.h"
378cc40b 1255#include "util.h"
8d063cd8 1256#include "form.h"
79072805
LW
1257#include "gv.h"
1258#include "cv.h"
1259#include "opcode.h"
1260#include "op.h"
1261#include "cop.h"
1262#include "av.h"
1263#include "hv.h"
1264#include "mg.h"
1265#include "scope.h"
599cee73 1266#include "warning.h"
d613ef02
GS
1267#include "bytecode.h"
1268#include "byterun.h"
a0ed51b3 1269#include "utf8.h"
8d063cd8 1270
7fae4e64
GS
1271/* Current curly descriptor */
1272typedef struct curcur CURCUR;
1273struct curcur {
1274 int parenfloor; /* how far back to strip paren data */
1275 int cur; /* how many instances of scan we've matched */
1276 int min; /* the minimal number of scans to match */
1277 int max; /* the maximal number of scans to match */
1278 int minmod; /* whether to work our way up or down */
1279 regnode * scan; /* the thing to match */
1280 regnode * next; /* what has to match after it */
1281 char * lastloc; /* where we started matching this scan */
1282 CURCUR * oldcc; /* current curly before we started this one */
1283};
1284
1285typedef struct _sublex_info SUBLEXINFO;
1286struct _sublex_info {
1287 I32 super_state; /* lexer state to save */
1288 I32 sub_inwhat; /* "lex_inwhat" to use */
1289 OP *sub_op; /* "lex_op" to use */
1290};
1291
76e3520e
GS
1292#ifdef PERL_OBJECT
1293struct magic_state {
1294 SV* mgs_sv;
1295 U32 mgs_flags;
1296};
1297typedef struct magic_state MGS;
1298
1299typedef struct {
1300 I32 len_min;
1301 I32 len_delta;
1302 I32 pos_min;
1303 I32 pos_delta;
1304 SV *last_found;
1305 I32 last_end; /* min value, <0 unless valid. */
1306 I32 last_start_min;
1307 I32 last_start_max;
1308 SV **longest; /* Either &l_fixed, or &l_float. */
1309 SV *longest_fixed;
1310 I32 offset_fixed;
1311 SV *longest_float;
1312 I32 offset_float_min;
1313 I32 offset_float_max;
1314 I32 flags;
1315} scan_data_t;
1316
1317typedef I32 CHECKPOINT;
1318#endif /* PERL_OBJECT */
1319
4633a7c4
LW
1320/* work around some libPW problems */
1321#ifdef DOINIT
1322EXT char Error[1];
1323#endif
1324
450a55e4 1325#if defined(iAPX286) || defined(M_I286) || defined(I80286)
a687059c
LW
1326# define I286
1327#endif
1328
fe14fcc3
LW
1329#if defined(htonl) && !defined(HAS_HTONL)
1330#define HAS_HTONL
ae986130 1331#endif
fe14fcc3
LW
1332#if defined(htons) && !defined(HAS_HTONS)
1333#define HAS_HTONS
ae986130 1334#endif
fe14fcc3
LW
1335#if defined(ntohl) && !defined(HAS_NTOHL)
1336#define HAS_NTOHL
ae986130 1337#endif
fe14fcc3
LW
1338#if defined(ntohs) && !defined(HAS_NTOHS)
1339#define HAS_NTOHS
ae986130 1340#endif
fe14fcc3 1341#ifndef HAS_HTONL
d9d8d8de 1342#if (BYTEORDER & 0xffff) != 0x4321
fe14fcc3
LW
1343#define HAS_HTONS
1344#define HAS_HTONL
1345#define HAS_NTOHS
1346#define HAS_NTOHL
a687059c
LW
1347#define MYSWAP
1348#define htons my_swap
1349#define htonl my_htonl
1350#define ntohs my_swap
1351#define ntohl my_ntohl
1352#endif
1353#else
d9d8d8de 1354#if (BYTEORDER & 0xffff) == 0x4321
fe14fcc3
LW
1355#undef HAS_HTONS
1356#undef HAS_HTONL
1357#undef HAS_NTOHS
1358#undef HAS_NTOHL
a687059c
LW
1359#endif
1360#endif
1361
988174c1
LW
1362/*
1363 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
1364 * -DWS
1365 */
1366#if BYTEORDER != 0x1234
1367# define HAS_VTOHL
1368# define HAS_VTOHS
1369# define HAS_HTOVL
1370# define HAS_HTOVS
1371# if BYTEORDER == 0x4321
1372# define vtohl(x) ((((x)&0xFF)<<24) \
1373 +(((x)>>24)&0xFF) \
1374 +(((x)&0x0000FF00)<<8) \
1375 +(((x)&0x00FF0000)>>8) )
1376# define vtohs(x) ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
1377# define htovl(x) vtohl(x)
1378# define htovs(x) vtohs(x)
1379# endif
1380 /* otherwise default to functions in util.c */
1381#endif
1382
0f85fab0 1383#ifdef CASTNEGFLOAT
79072805 1384#define U_S(what) ((U16)(what))
0f85fab0 1385#define U_I(what) ((unsigned int)(what))
79072805 1386#define U_L(what) ((U32)(what))
0f85fab0 1387#else
32f822de 1388EXTERN_C U32 cast_ulong _((double));
232e078e
AD
1389#define U_S(what) ((U16)cast_ulong((double)(what)))
1390#define U_I(what) ((unsigned int)cast_ulong((double)(what)))
1391#define U_L(what) (cast_ulong((double)(what)))
ee0007ab
LW
1392#endif
1393
ed6116ce
LW
1394#ifdef CASTI32
1395#define I_32(what) ((I32)(what))
a0d0e21e 1396#define I_V(what) ((IV)(what))
5d94fbed 1397#define U_V(what) ((UV)(what))
ed6116ce 1398#else
32f822de 1399START_EXTERN_C
a0d0e21e 1400I32 cast_i32 _((double));
a0d0e21e 1401IV cast_iv _((double));
5d94fbed 1402UV cast_uv _((double));
32f822de 1403END_EXTERN_C
a6e633de 1404#define I_32(what) (cast_i32((double)(what)))
1405#define I_V(what) (cast_iv((double)(what)))
5d94fbed 1406#define U_V(what) (cast_uv((double)(what)))
ed6116ce
LW
1407#endif
1408
79072805
LW
1409struct Outrec {
1410 I32 o_lines;
d9d8d8de 1411 char *o_str;
79072805 1412 U32 o_len;
8d063cd8
LW
1413};
1414
352d5a3a
LW
1415#ifndef MAXSYSFD
1416# define MAXSYSFD 2
1417#endif
ee0007ab 1418
f82b3d41 1419#ifndef TMPPATH
1420# define TMPPATH "/tmp/perl-eXXXXXX"
a0d0e21e 1421#endif
79072805
LW
1422
1423#ifndef __cplusplus
a0d0e21e
LW
1424Uid_t getuid _((void));
1425Uid_t geteuid _((void));
1426Gid_t getgid _((void));
1427Gid_t getegid _((void));
79072805 1428#endif
8d063cd8
LW
1429
1430#ifdef DEBUGGING
0c30d9ec 1431#ifndef Perl_debug_log
760ac839 1432#define Perl_debug_log PerlIO_stderr()
0c30d9ec 1433#endif
9d116dd7 1434#undef YYDEBUG
d96024cf 1435#define YYDEBUG 1
79072805 1436#define DEB(a) a
3280af22
NIS
1437#define DEBUG(a) if (PL_debug) a
1438#define DEBUG_p(a) if (PL_debug & 1) a
1439#define DEBUG_s(a) if (PL_debug & 2) a
1440#define DEBUG_l(a) if (PL_debug & 4) a
1441#define DEBUG_t(a) if (PL_debug & 8) a
1442#define DEBUG_o(a) if (PL_debug & 16) a
1443#define DEBUG_c(a) if (PL_debug & 32) a
1444#define DEBUG_P(a) if (PL_debug & 64) a
1445#define DEBUG_m(a) if (PL_curinterp && PL_debug & 128) a
1446#define DEBUG_f(a) if (PL_debug & 256) a
1447#define DEBUG_r(a) if (PL_debug & 512) a
1448#define DEBUG_x(a) if (PL_debug & 1024) a
1449#define DEBUG_u(a) if (PL_debug & 2048) a
1450#define DEBUG_L(a) if (PL_debug & 4096) a
1451#define DEBUG_H(a) if (PL_debug & 8192) a
1452#define DEBUG_X(a) if (PL_debug & 16384) a
1453#define DEBUG_D(a) if (PL_debug & 32768) a
8b73bbec
IZ
1454# ifdef USE_THREADS
1455# define DEBUG_S(a) if (PL_debug & (1<<16)) a
1456# else
1457# define DEBUG_S(a)
1458# endif
79072805
LW
1459#else
1460#define DEB(a)
1461#define DEBUG(a)
1462#define DEBUG_p(a)
1463#define DEBUG_s(a)
1464#define DEBUG_l(a)
1465#define DEBUG_t(a)
1466#define DEBUG_o(a)
1467#define DEBUG_c(a)
1468#define DEBUG_P(a)
1469#define DEBUG_m(a)
1470#define DEBUG_f(a)
1471#define DEBUG_r(a)
1472#define DEBUG_x(a)
1473#define DEBUG_u(a)
8b73bbec 1474#define DEBUG_S(a)
79072805
LW
1475#define DEBUG_H(a)
1476#define DEBUG_X(a)
8990e307 1477#define DEBUG_D(a)
8b73bbec 1478#define DEBUG_S(a)
8d063cd8 1479#endif
fe14fcc3 1480#define YYMAXDEPTH 300
8d063cd8 1481
a6e633de 1482#ifndef assert /* <assert.h> might have been included somehow */
79072805
LW
1483#define assert(what) DEB( { \
1484 if (!(what)) { \
463ee0b2 1485 croak("Assertion failed: file \"%s\", line %d", \
79072805 1486 __FILE__, __LINE__); \
6ad3d225 1487 PerlProc_exit(1); \
79072805 1488 }})
a6e633de 1489#endif
8d063cd8 1490
450a55e4 1491struct ufuncs {
a0d0e21e
LW
1492 I32 (*uf_val)_((IV, SV*));
1493 I32 (*uf_set)_((IV, SV*));
1494 IV uf_index;
450a55e4
LW
1495};
1496
fe14fcc3 1497/* Fix these up for __STDC__ */
68dc0745 1498#ifndef DONT_DECLARE_STD
a0d0e21e
LW
1499char *mktemp _((char*));
1500double atof _((const char*));
1501#endif
79072805 1502
352d5a3a 1503#ifndef STANDARD_C
fe14fcc3 1504/* All of these are in stdlib.h or time.h for ANSI C */
85e6fe83 1505Time_t time();
8d063cd8 1506struct tm *gmtime(), *localtime();
9d116dd7
JH
1507#ifdef OEMVS
1508char *(strchr)(), *(strrchr)();
1509char *(strcpy)(), *(strcat)();
1510#else
93a17b20 1511char *strchr(), *strrchr();
378cc40b 1512char *strcpy(), *strcat();
9d116dd7 1513#endif
352d5a3a 1514#endif /* ! STANDARD_C */
8d063cd8 1515
79072805
LW
1516
1517#ifdef I_MATH
1518# include <math.h>
1519#else
32f822de 1520START_EXTERN_C
a0d0e21e 1521 double exp _((double));
a0d0e21e 1522 double log _((double));
c635e13b 1523 double log10 _((double));
a0d0e21e 1524 double sqrt _((double));
c635e13b 1525 double frexp _((double,int*));
1526 double ldexp _((double,int));
a0d0e21e
LW
1527 double modf _((double,double*));
1528 double sin _((double));
1529 double cos _((double));
1530 double atan2 _((double,double));
1531 double pow _((double,double));
32f822de 1532END_EXTERN_C
79072805
LW
1533#endif
1534
a0d0e21e 1535#ifndef __cplusplus
26618a56 1536# ifdef __NeXT__ /* or whatever catches all NeXTs */
3fc1aec6 1537char *crypt (); /* Maybe more hosts will need the unprototyped version */
26618a56
GS
1538# else
1539# if !defined(WIN32) || !defined(HAVE_DES_FCRYPT)
a0d0e21e 1540char *crypt _((const char*, const char*));
26618a56
GS
1541# endif /* !WIN32 && !HAVE_CRYPT_SOURCE */
1542# endif /* !__NeXT__ */
1543# ifndef DONT_DECLARE_STD
1544# ifndef getenv
a0d0e21e 1545char *getenv _((const char*));
26618a56 1546# endif /* !getenv */
a0d0e21e 1547Off_t lseek _((int,Off_t,int));
26618a56 1548# endif /* !DONT_DECLARE_STD */
a0d0e21e 1549char *getlogin _((void));
26618a56 1550#endif /* !__cplusplus */
79072805 1551
16d20bd9 1552#ifdef UNLINK_ALL_VERSIONS /* Currently only makes sense for VMS */
378cc40b 1553#define UNLINK unlnk
a0d0e21e 1554I32 unlnk _((char*));
8d063cd8
LW
1555#else
1556#define UNLINK unlink
1557#endif
a687059c 1558
fe14fcc3 1559#ifndef HAS_SETREUID
85e6fe83
LW
1560# ifdef HAS_SETRESUID
1561# define setreuid(r,e) setresuid(r,e,(Uid_t)-1)
1562# define HAS_SETREUID
1563# endif
a687059c 1564#endif
fe14fcc3 1565#ifndef HAS_SETREGID
85e6fe83
LW
1566# ifdef HAS_SETRESGID
1567# define setregid(r,e) setresgid(r,e,(Gid_t)-1)
1568# define HAS_SETREGID
1569# endif
a687059c 1570#endif
ee0007ab 1571
ff68c719 1572typedef Signal_t (*Sighandler_t) _((int));
1573
1574#ifdef HAS_SIGACTION
1575typedef struct sigaction Sigsave_t;
1576#else
1577typedef Sighandler_t Sigsave_t;
1578#endif
1579
ee0007ab
LW
1580#define SCAN_DEF 0
1581#define SCAN_TR 1
1582#define SCAN_REPL 2
79072805
LW
1583
1584#ifdef DEBUGGING
4633a7c4 1585# ifndef register
a0d0e21e
LW
1586# define register
1587# endif
1588# define PAD_SV(po) pad_sv(po)
2ddcc7aa 1589# define RUNOPS_DEFAULT runops_debug
79072805 1590#else
6b88bc9c 1591# define PAD_SV(po) PL_curpad[po]
2ddcc7aa 1592# define RUNOPS_DEFAULT runops_standard
79072805
LW
1593#endif
1594
18f739ee 1595#ifdef MYMALLOC
51dc0457
NIS
1596# define MALLOC_INIT MUTEX_INIT(&PL_malloc_mutex)
1597# define MALLOC_TERM MUTEX_DESTROY(&PL_malloc_mutex)
18f739ee
IZ
1598#else
1599# define MALLOC_INIT
1600# define MALLOC_TERM
1601#endif
1602
b6d9d515 1603
44a0ac01
MB
1604/*
1605 * These need prototyping here because <proto.h> isn't
1606 * included until after runops is initialised.
1607 */
1608
76e3520e 1609#ifndef PERL_OBJECT
49f531da 1610typedef int runops_proc_t _((void));
44a0ac01
MB
1611int runops_standard _((void));
1612#ifdef DEBUGGING
1613int runops_debug _((void));
1614#endif
76e3520e 1615#endif /* PERL_OBJECT */
44a0ac01 1616
940cb80d 1617/* _ (for $_) must be first in the following list (DEFSV requires it) */
54b9620d 1618#define THREADSV_NAMES "_123456789&`'+/.,\\\";^-%=|~:\001\005!@"
a863c7d1 1619
0c30d9ec 1620/* VMS doesn't use environ array and NeXT has problems with crt0.o globals */
1621#if !defined(VMS) && !(defined(NeXT) && defined(__DYNAMIC__))
16de4a3e
RS
1622#if !defined(DONT_DECLARE_STD) \
1623 || (defined(__svr4__) && defined(__GNUC__) && defined(sun)) \
1624 || defined(__sgi) || defined(__DGUX)
79072805 1625extern char ** environ; /* environment variables supplied via exec */
a0d0e21e 1626#endif
0c30d9ec 1627#else
1628# if defined(NeXT) && defined(__DYNAMIC__)
1629
1630# include <mach-o/dyld.h>
1631EXT char *** environ_pointer;
1632# define environ (*environ_pointer)
1633# endif
1634#endif /* environ processing */
1635
79072805
LW
1636
1637/* for tmp use in stupid debuggers */
1638EXT int * di;
1639EXT short * ds;
1640EXT char * dc;
1641
1642/* handy constants */
3e3baf6d 1643EXTCONST char warn_uninit[]
a0d0e21e 1644 INIT("Use of uninitialized value");
3e3baf6d 1645EXTCONST char warn_nosemi[]
463ee0b2 1646 INIT("Semicolon seems to be missing");
3e3baf6d 1647EXTCONST char warn_reserved[]
463ee0b2 1648 INIT("Unquoted string \"%s\" may clash with future reserved word");
3e3baf6d 1649EXTCONST char warn_nl[]
93a17b20 1650 INIT("Unsuccessful %s on filename containing newline");
3e3baf6d 1651EXTCONST char no_wrongref[]
a0d0e21e 1652 INIT("Can't use %s ref as %s ref");
3e3baf6d 1653EXTCONST char no_symref[]
748a9306 1654 INIT("Can't use string (\"%.32s\") as %s ref while \"strict refs\" in use");
3e3baf6d 1655EXTCONST char no_usym[]
8990e307 1656 INIT("Can't use an undefined value as %s reference");
3e3baf6d 1657EXTCONST char no_aelem[]
93a17b20 1658 INIT("Modification of non-creatable array value attempted, subscript %d");
3e3baf6d 1659EXTCONST char no_helem[]
93a17b20 1660 INIT("Modification of non-creatable hash value attempted, subscript \"%s\"");
3e3baf6d 1661EXTCONST char no_modify[]
93a17b20 1662 INIT("Modification of a read-only value attempted");
3e3baf6d 1663EXTCONST char no_mem[]
93a17b20 1664 INIT("Out of memory!\n");
3e3baf6d 1665EXTCONST char no_security[]
463ee0b2 1666 INIT("Insecure dependency in %s%s");
3e3baf6d 1667EXTCONST char no_sock_func[]
93a17b20 1668 INIT("Unsupported socket function \"%s\" called");
3e3baf6d 1669EXTCONST char no_dir_func[]
93a17b20 1670 INIT("Unsupported directory function \"%s\" called");
3e3baf6d 1671EXTCONST char no_func[]
93a17b20 1672 INIT("The %s function is unimplemented");
3e3baf6d 1673EXTCONST char no_myglob[]
748a9306 1674 INIT("\"my\" variable %s can't be in a package");
93a17b20 1675
79072805 1676#ifdef DOINIT
8e07c86e
AD
1677EXT char *sig_name[] = { SIG_NAME };
1678EXT int sig_num[] = { SIG_NUM };
0c30d9ec 1679EXT SV * psig_ptr[sizeof(sig_num)/sizeof(*sig_num)];
1680EXT SV * psig_name[sizeof(sig_num)/sizeof(*sig_num)];
79072805
LW
1681#else
1682EXT char *sig_name[];
8e07c86e 1683EXT int sig_num[];
0c30d9ec 1684EXT SV * psig_ptr[];
1685EXT SV * psig_name[];
79072805
LW
1686#endif
1687
bbce6d69 1688/* fast case folding tables */
1689
79072805 1690#ifdef DOINIT
9d116dd7
JH
1691#ifdef EBCDIC
1692EXT unsigned char fold[] = { /* fast EBCDIC case folding table */
1693 0, 1, 2, 3, 4, 5, 6, 7,
1694 8, 9, 10, 11, 12, 13, 14, 15,
1695 16, 17, 18, 19, 20, 21, 22, 23,
1696 24, 25, 26, 27, 28, 29, 30, 31,
1697 32, 33, 34, 35, 36, 37, 38, 39,
1698 40, 41, 42, 43, 44, 45, 46, 47,
1699 48, 49, 50, 51, 52, 53, 54, 55,
1700 56, 57, 58, 59, 60, 61, 62, 63,
1701 64, 65, 66, 67, 68, 69, 70, 71,
1702 72, 73, 74, 75, 76, 77, 78, 79,
1703 80, 81, 82, 83, 84, 85, 86, 87,
1704 88, 89, 90, 91, 92, 93, 94, 95,
1705 96, 97, 98, 99, 100, 101, 102, 103,
1706 104, 105, 106, 107, 108, 109, 110, 111,
1707 112, 113, 114, 115, 116, 117, 118, 119,
1708 120, 121, 122, 123, 124, 125, 126, 127,
1709 128, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
1710 'H', 'I', 138, 139, 140, 141, 142, 143,
1711 144, 'J', 'K', 'L', 'M', 'N', 'O', 'P',
1712 'Q', 'R', 154, 155, 156, 157, 158, 159,
1713 160, 161, 'S', 'T', 'U', 'V', 'W', 'X',
1714 'Y', 'Z', 170, 171, 172, 173, 174, 175,
1715 176, 177, 178, 179, 180, 181, 182, 183,
1716 184, 185, 186, 187, 188, 189, 190, 191,
1717 192, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
1718 'h', 'i', 202, 203, 204, 205, 206, 207,
1719 208, 'j', 'k', 'l', 'm', 'n', 'o', 'p',
1720 'q', 'r', 218, 219, 220, 221, 222, 223,
1721 224, 225, 's', 't', 'u', 'v', 'w', 'x',
1722 'y', 'z', 234, 235, 236, 237, 238, 239,
1723 240, 241, 242, 243, 244, 245, 246, 247,
1724 248, 249, 250, 251, 252, 253, 254, 255
1725};
1726#else /* ascii rather than ebcdic */
36477c24 1727EXTCONST unsigned char fold[] = {
79072805
LW
1728 0, 1, 2, 3, 4, 5, 6, 7,
1729 8, 9, 10, 11, 12, 13, 14, 15,
1730 16, 17, 18, 19, 20, 21, 22, 23,
1731 24, 25, 26, 27, 28, 29, 30, 31,
1732 32, 33, 34, 35, 36, 37, 38, 39,
1733 40, 41, 42, 43, 44, 45, 46, 47,
1734 48, 49, 50, 51, 52, 53, 54, 55,
1735 56, 57, 58, 59, 60, 61, 62, 63,
1736 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
1737 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
1738 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
1739 'x', 'y', 'z', 91, 92, 93, 94, 95,
1740 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
1741 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
1742 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
1743 'X', 'Y', 'Z', 123, 124, 125, 126, 127,
1744 128, 129, 130, 131, 132, 133, 134, 135,
1745 136, 137, 138, 139, 140, 141, 142, 143,
1746 144, 145, 146, 147, 148, 149, 150, 151,
1747 152, 153, 154, 155, 156, 157, 158, 159,
1748 160, 161, 162, 163, 164, 165, 166, 167,
1749 168, 169, 170, 171, 172, 173, 174, 175,
1750 176, 177, 178, 179, 180, 181, 182, 183,
1751 184, 185, 186, 187, 188, 189, 190, 191,
1752 192, 193, 194, 195, 196, 197, 198, 199,
1753 200, 201, 202, 203, 204, 205, 206, 207,
1754 208, 209, 210, 211, 212, 213, 214, 215,
1755 216, 217, 218, 219, 220, 221, 222, 223,
1756 224, 225, 226, 227, 228, 229, 230, 231,
1757 232, 233, 234, 235, 236, 237, 238, 239,
1758 240, 241, 242, 243, 244, 245, 246, 247,
1759 248, 249, 250, 251, 252, 253, 254, 255
1760};
9d116dd7 1761#endif /* !EBCDIC */
79072805 1762#else
71be2cbc 1763EXTCONST unsigned char fold[];
79072805
LW
1764#endif
1765
1766#ifdef DOINIT
bbce6d69 1767EXT unsigned char fold_locale[] = {
79072805
LW
1768 0, 1, 2, 3, 4, 5, 6, 7,
1769 8, 9, 10, 11, 12, 13, 14, 15,
1770 16, 17, 18, 19, 20, 21, 22, 23,
1771 24, 25, 26, 27, 28, 29, 30, 31,
1772 32, 33, 34, 35, 36, 37, 38, 39,
1773 40, 41, 42, 43, 44, 45, 46, 47,
1774 48, 49, 50, 51, 52, 53, 54, 55,
1775 56, 57, 58, 59, 60, 61, 62, 63,
1776 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
1777 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
1778 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
1779 'x', 'y', 'z', 91, 92, 93, 94, 95,
1780 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
1781 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
1782 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
1783 'X', 'Y', 'Z', 123, 124, 125, 126, 127,
1784 128, 129, 130, 131, 132, 133, 134, 135,
1785 136, 137, 138, 139, 140, 141, 142, 143,
1786 144, 145, 146, 147, 148, 149, 150, 151,
1787 152, 153, 154, 155, 156, 157, 158, 159,
1788 160, 161, 162, 163, 164, 165, 166, 167,
1789 168, 169, 170, 171, 172, 173, 174, 175,
1790 176, 177, 178, 179, 180, 181, 182, 183,
1791 184, 185, 186, 187, 188, 189, 190, 191,
1792 192, 193, 194, 195, 196, 197, 198, 199,
1793 200, 201, 202, 203, 204, 205, 206, 207,
1794 208, 209, 210, 211, 212, 213, 214, 215,
1795 216, 217, 218, 219, 220, 221, 222, 223,
1796 224, 225, 226, 227, 228, 229, 230, 231,
1797 232, 233, 234, 235, 236, 237, 238, 239,
1798 240, 241, 242, 243, 244, 245, 246, 247,
1799 248, 249, 250, 251, 252, 253, 254, 255
1800};
1801#else
bbce6d69 1802EXT unsigned char fold_locale[];
79072805
LW
1803#endif
1804
1805#ifdef DOINIT
9d116dd7
JH
1806#ifdef EBCDIC
1807EXT unsigned char freq[] = {/* EBCDIC frequencies for mixed English/C */
1808 1, 2, 84, 151, 154, 155, 156, 157,
1809 165, 246, 250, 3, 158, 7, 18, 29,
1810 40, 51, 62, 73, 85, 96, 107, 118,
1811 129, 140, 147, 148, 149, 150, 152, 153,
1812 255, 6, 8, 9, 10, 11, 12, 13,
1813 14, 15, 24, 25, 26, 27, 28, 226,
1814 29, 30, 31, 32, 33, 43, 44, 45,
1815 46, 47, 48, 49, 50, 76, 77, 78,
1816 79, 80, 81, 82, 83, 84, 85, 86,
1817 87, 94, 95, 234, 181, 233, 187, 190,
1818 180, 96, 97, 98, 99, 100, 101, 102,
1819 104, 112, 182, 174, 236, 232, 229, 103,
1820 228, 226, 114, 115, 116, 117, 118, 119,
1821 120, 121, 122, 235, 176, 230, 194, 162,
1822 130, 131, 132, 133, 134, 135, 136, 137,
1823 138, 139, 201, 205, 163, 217, 220, 224,
1824 5, 248, 227, 244, 242, 255, 241, 231,
1825 240, 253, 16, 197, 19, 20, 21, 187,
1826 23, 169, 210, 245, 237, 249, 247, 239,
1827 168, 252, 34, 196, 36, 37, 38, 39,
1828 41, 42, 251, 254, 238, 223, 221, 213,
1829 225, 177, 52, 53, 54, 55, 56, 57,
1830 58, 59, 60, 61, 63, 64, 65, 66,
1831 67, 68, 69, 70, 71, 72, 74, 75,
1832 205, 208, 186, 202, 200, 218, 198, 179,
1833 178, 214, 88, 89, 90, 91, 92, 93,
1834 217, 166, 170, 207, 199, 209, 206, 204,
1835 160, 212, 105, 106, 108, 109, 110, 111,
1836 203, 113, 216, 215, 192, 175, 193, 243,
1837 172, 161, 123, 124, 125, 126, 127, 128,
1838 222, 219, 211, 195, 188, 193, 185, 184,
1839 191, 183, 141, 142, 143, 144, 145, 146
1840};
1841#else /* ascii rather than ebcdic */
71be2cbc 1842EXTCONST unsigned char freq[] = { /* letter frequencies for mixed English/C */
79072805
LW
1843 1, 2, 84, 151, 154, 155, 156, 157,
1844 165, 246, 250, 3, 158, 7, 18, 29,
1845 40, 51, 62, 73, 85, 96, 107, 118,
1846 129, 140, 147, 148, 149, 150, 152, 153,
1847 255, 182, 224, 205, 174, 176, 180, 217,
1848 233, 232, 236, 187, 235, 228, 234, 226,
1849 222, 219, 211, 195, 188, 193, 185, 184,
1850 191, 183, 201, 229, 181, 220, 194, 162,
1851 163, 208, 186, 202, 200, 218, 198, 179,
1852 178, 214, 166, 170, 207, 199, 209, 206,
1853 204, 160, 212, 216, 215, 192, 175, 173,
1854 243, 172, 161, 190, 203, 189, 164, 230,
1855 167, 248, 227, 244, 242, 255, 241, 231,
1856 240, 253, 169, 210, 245, 237, 249, 247,
1857 239, 168, 252, 251, 254, 238, 223, 221,
1858 213, 225, 177, 197, 171, 196, 159, 4,
1859 5, 6, 8, 9, 10, 11, 12, 13,
1860 14, 15, 16, 17, 19, 20, 21, 22,
1861 23, 24, 25, 26, 27, 28, 30, 31,
1862 32, 33, 34, 35, 36, 37, 38, 39,
1863 41, 42, 43, 44, 45, 46, 47, 48,
1864 49, 50, 52, 53, 54, 55, 56, 57,
1865 58, 59, 60, 61, 63, 64, 65, 66,
1866 67, 68, 69, 70, 71, 72, 74, 75,
1867 76, 77, 78, 79, 80, 81, 82, 83,
1868 86, 87, 88, 89, 90, 91, 92, 93,
1869 94, 95, 97, 98, 99, 100, 101, 102,
1870 103, 104, 105, 106, 108, 109, 110, 111,
1871 112, 113, 114, 115, 116, 117, 119, 120,
1872 121, 122, 123, 124, 125, 126, 127, 128,
1873 130, 131, 132, 133, 134, 135, 136, 137,
1874 138, 139, 141, 142, 143, 144, 145, 146
1875};
9d116dd7 1876#endif
79072805 1877#else
71be2cbc 1878EXTCONST unsigned char freq[];
79072805
LW
1879#endif
1880
8990e307
LW
1881#ifdef DEBUGGING
1882#ifdef DOINIT
71be2cbc 1883EXTCONST char* block_type[] = {
8990e307
LW
1884 "NULL",
1885 "SUB",
1886 "EVAL",
1887 "LOOP",
1888 "SUBST",
1889 "BLOCK",
1890};
1891#else
71be2cbc 1892EXTCONST char* block_type[];
8990e307
LW
1893#endif
1894#endif
1895
79072805
LW
1896/*****************************************************************************/
1897/* This lexer/parser stuff is currently global since yacc is hard to reenter */
1898/*****************************************************************************/
8990e307 1899/* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */
79072805 1900
a0d0e21e
LW
1901#include "perly.h"
1902
fb73857a 1903#define LEX_NOTPARSING 11 /* borrowed from toke.c */
1904
79072805
LW
1905typedef enum {
1906 XOPERATOR,
1907 XTERM,
79072805 1908 XREF,
8990e307 1909 XSTATE,
a0d0e21e
LW
1910 XBLOCK,
1911 XTERMBLOCK
79072805
LW
1912} expectation;
1913
85e6fe83
LW
1914
1915 /* Note: the lowest 8 bits are reserved for
1916 stuffing into op->op_private */
1917#define HINT_INTEGER 0x00000001
1918#define HINT_STRICT_REFS 0x00000002
a0ed51b3
LW
1919/* #define HINT_notused4 0x00000004 */
1920#define HINT_UTF8 0x00000008
1921/* #define HINT_notused10 0x00000010 */
1922 /* Note: 20,40,80 used for NATIVE_HINTS */
85e6fe83
LW
1923
1924#define HINT_BLOCK_SCOPE 0x00000100
1925#define HINT_STRICT_SUBS 0x00000200
1926#define HINT_STRICT_VARS 0x00000400
bbce6d69 1927#define HINT_LOCALE 0x00000800
85e6fe83 1928
b3ac6de7
IZ
1929#define HINT_NEW_INTEGER 0x00001000
1930#define HINT_NEW_FLOAT 0x00002000
1931#define HINT_NEW_BINARY 0x00004000
1932#define HINT_NEW_STRING 0x00008000
1933#define HINT_NEW_RE 0x00010000
1934#define HINT_LOCALIZE_HH 0x00020000 /* %^H needs to be copied */
1935
b3eb6a9b 1936#define HINT_RE_TAINT 0x00100000
e4d48cc9 1937#define HINT_RE_EVAL 0x00200000
b3eb6a9b 1938
d4cce5f1
NIS
1939/* Various states of an input record separator SV (rs, nrs) */
1940#define RsSNARF(sv) (! SvOK(sv))
1941#define RsSIMPLE(sv) (SvOK(sv) && SvCUR(sv))
1942#define RsPARA(sv) (SvOK(sv) && ! SvCUR(sv))
5b2b9c68 1943#define RsRECORD(sv) (SvROK(sv) && (SvIV(SvRV(sv)) > 0))
79072805 1944
56953603 1945/* Enable variables which are pointers to functions */
15e52e56
GS
1946#ifdef PERL_OBJECT
1947typedef regexp*(CPerlObj::*regcomp_t) _((char* exp, char* xend, PMOP* pm));
1948typedef I32 (CPerlObj::*regexec_t) _((regexp* prog, char* stringarg,
1949 char* strend, char* strbeg,
1950 I32 minend, SV* screamer, void* data,
1951 U32 flags));
1952#else
56953603
IZ
1953typedef regexp*(*regcomp_t) _((char* exp, char* xend, PMOP* pm));
1954typedef I32 (*regexec_t) _((regexp* prog, char* stringarg, char* strend, char*
1955 strbeg, I32 minend, SV* screamer, void* data,
1956 U32 flags));
1957
15e52e56
GS
1958#endif
1959
22239a37
NIS
1960/* Set up PERLVAR macros for populating structs */
1961#define PERLVAR(var,type) type var;
1962#define PERLVARI(var,type,init) type var;
3fe35a81 1963#define PERLVARIC(var,type,init) type var;
22239a37 1964
58a50f62
GS
1965/* Interpreter exitlist entry */
1966typedef struct exitlistentry {
1967#ifdef PERL_OBJECT
1968 void (*fn) _((CPerlObj*, void*));
1969#else
1970 void (*fn) _((void*));
1971#endif
1972 void *ptr;
1973} PerlExitListEntry;
1974
76e3520e
GS
1975#ifdef PERL_OBJECT
1976extern "C" CPerlObj* perl_alloc _((IPerlMem*, IPerlEnv*, IPerlStdIO*, IPerlLIO*, IPerlDir*, IPerlSock*, IPerlProc*));
1977
1978typedef int (CPerlObj::*runops_proc_t) _((void));
1979#undef EXT
1980#define EXT
1981#undef EXTCONST
1982#define EXTCONST
1983#undef INIT
1984#define INIT(x)
1985
1986class CPerlObj {
1987public:
1988 CPerlObj(IPerlMem*, IPerlEnv*, IPerlStdIO*, IPerlLIO*, IPerlDir*, IPerlSock*, IPerlProc*);
1989 void Init(void);
1990 void* operator new(size_t nSize, IPerlMem *pvtbl);
1991#endif /* PERL_OBJECT */
1992
22239a37
NIS
1993#ifdef PERL_GLOBAL_STRUCT
1994struct perl_vars {
1995#include "perlvars.h"
1996};
1997
1998#ifdef PERL_CORE
533c011a
NIS
1999EXT struct perl_vars PL_Vars;
2000EXT struct perl_vars *PL_VarsPtr INIT(&PL_Vars);
2001#else /* PERL_CORE */
22239a37
NIS
2002#if !defined(__GNUC__) || !defined(WIN32)
2003EXT
533c011a
NIS
2004#endif /* WIN32 */
2005struct perl_vars *PL_VarsPtr;
2006#define PL_Vars (*((PL_VarsPtr) ? PL_VarsPtr : (PL_VarsPtr = Perl_GetVars())))
2007#endif /* PERL_CORE */
22239a37
NIS
2008#endif /* PERL_GLOBAL_STRUCT */
2009
8990e307 2010#ifdef MULTIPLICITY
d4cce5f1
NIS
2011/* If we have multiple interpreters define a struct
2012 holding variables which must be per-interpreter
2013 If we don't have threads anything that would have
2014 be per-thread is per-interpreter.
2015*/
2016
79072805 2017struct interpreter {
d4cce5f1
NIS
2018#ifndef USE_THREADS
2019#include "thrdvar.h"
2020#endif
2021#include "intrpvar.h"
49f531da 2022};
d4cce5f1 2023
79072805 2024#else
49f531da
NIS
2025struct interpreter {
2026 char broiled;
2027};
79072805
LW
2028#endif
2029
d4cce5f1
NIS
2030#ifdef USE_THREADS
2031/* If we have threads define a struct with all the variables
2032 * that have to be per-thread
49f531da 2033 */
8023c3ce 2034
79072805 2035
49f531da 2036struct perl_thread {
49f531da 2037#include "thrdvar.h"
79072805 2038};
d4cce5f1 2039
22fae026
TM
2040typedef struct perl_thread *Thread;
2041
2042#else
2043typedef void *Thread;
22239a37
NIS
2044#endif
2045
2046/* Done with PERLVAR macros for now ... */
d4cce5f1
NIS
2047#undef PERLVAR
2048#undef PERLVARI
3fe35a81 2049#undef PERLVARIC
79072805 2050
22239a37 2051#include "thread.h"
79072805 2052#include "pp.h"
79072805
LW
2053#include "proto.h"
2054
a0d0e21e
LW
2055#ifdef EMBED
2056#define Perl_sv_setptrobj(rv,ptr,name) Perl_sv_setref_iv(rv,name,(IV)ptr)
2057#define Perl_sv_setptrref(rv,ptr) Perl_sv_setref_iv(rv,Nullch,(IV)ptr)
2058#else
2059#define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,(IV)ptr)
2060#define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,(IV)ptr)
2061#endif
2062
d4cce5f1
NIS
2063/* The following must follow proto.h as #defines mess up syntax */
2064
2065#include "embedvar.h"
2066
2067/* Now include all the 'global' variables
2068 * If we don't have threads or multiple interpreters
2069 * these include variables that would have been their struct-s
2070 */
533c011a
NIS
2071
2072#define PERLVAR(var,type) EXT type PL_##var;
2073#define PERLVARI(var,type,init) EXT type PL_##var INIT(init);
2074#define PERLVARIC(var,type,init) EXTCONST type PL_##var INIT(init);
d4cce5f1 2075
22239a37 2076#ifndef PERL_GLOBAL_STRUCT
d4cce5f1 2077#include "perlvars.h"
22239a37 2078#endif
d4cce5f1
NIS
2079
2080#ifndef MULTIPLICITY
d4cce5f1 2081
066ef5b5
GS
2082# include "intrpvar.h"
2083# ifndef USE_THREADS
2084# include "thrdvar.h"
2085# endif
d4cce5f1 2086
22239a37
NIS
2087#endif
2088
76e3520e 2089#ifdef PERL_OBJECT
d0c1b099
GS
2090/*
2091 * The following is a buffer where new variables must
2092 * be defined to maintain binary compatibility with PERL_OBJECT
2093 * for 5.005
2094 */
2095PERLVAR(object_compatibility[30], char)
76e3520e
GS
2096};
2097
2098#include "objpp.h"
2099#ifdef DOINIT
2100#include "INTERN.h"
2101#else
2102#include "EXTERN.h"
2103#endif
2104#endif /* PERL_OBJECT */
2105
22239a37 2106
d4cce5f1
NIS
2107#undef PERLVAR
2108#undef PERLVARI
0f3f18a6 2109#undef PERLVARIC
79072805 2110
a835ef8a
NIS
2111#if defined(HASATTRIBUTE) && defined(WIN32)
2112/*
2113 * This provides a layer of functions and macros to ensure extensions will
2114 * get to use the same RTL functions as the core.
2115 * It has to go here or #define of printf messes up __attribute__
2116 * stuff in proto.h
2117 */
76e3520e 2118#ifndef PERL_OBJECT
a835ef8a 2119# include <win32iop.h>
76e3520e 2120#endif /* PERL_OBJECT */
a835ef8a
NIS
2121#endif /* WIN32 */
2122
79072805 2123#ifdef DOINIT
bbce6d69 2124
4633a7c4 2125EXT MGVTBL vtbl_sv = {magic_get,
463ee0b2
LW
2126 magic_set,
2127 magic_len,
2128 0, 0};
fb73857a 2129EXT MGVTBL vtbl_env = {0, magic_set_all_env,
2130 0, magic_clear_all_env,
66b1d557 2131 0};
4633a7c4 2132EXT MGVTBL vtbl_envelem = {0, magic_setenv,
85e6fe83
LW
2133 0, magic_clearenv,
2134 0};
4633a7c4 2135EXT MGVTBL vtbl_sig = {0, 0, 0, 0, 0};
0c30d9ec 2136EXT MGVTBL vtbl_sigelem = {magic_getsig,
2137 magic_setsig,
2138 0, magic_clearsig,
2139 0};
93965878 2140EXT MGVTBL vtbl_pack = {0, 0, magic_sizepack, magic_wipepack,
a0d0e21e 2141 0};
4633a7c4 2142EXT MGVTBL vtbl_packelem = {magic_getpack,
463ee0b2
LW
2143 magic_setpack,
2144 0, magic_clearpack,
2145 0};
4633a7c4 2146EXT MGVTBL vtbl_dbline = {0, magic_setdbline,
463ee0b2 2147 0, 0, 0};
4633a7c4 2148EXT MGVTBL vtbl_isa = {0, magic_setisa,
fb73857a 2149 0, magic_setisa,
2150 0};
4633a7c4 2151EXT MGVTBL vtbl_isaelem = {0, magic_setisa,
463ee0b2 2152 0, 0, 0};
4633a7c4 2153EXT MGVTBL vtbl_arylen = {magic_getarylen,
463ee0b2
LW
2154 magic_setarylen,
2155 0, 0, 0};
4633a7c4 2156EXT MGVTBL vtbl_glob = {magic_getglob,
463ee0b2
LW
2157 magic_setglob,
2158 0, 0, 0};
4633a7c4 2159EXT MGVTBL vtbl_mglob = {0, magic_setmglob,
463ee0b2 2160 0, 0, 0};
6ff81951
GS
2161EXT MGVTBL vtbl_nkeys = {magic_getnkeys,
2162 magic_setnkeys,
99abf803 2163 0, 0, 0};
4633a7c4 2164EXT MGVTBL vtbl_taint = {magic_gettaint,magic_settaint,
463ee0b2 2165 0, 0, 0};
6ff81951 2166EXT MGVTBL vtbl_substr = {magic_getsubstr, magic_setsubstr,
463ee0b2 2167 0, 0, 0};
6ff81951
GS
2168EXT MGVTBL vtbl_vec = {magic_getvec,
2169 magic_setvec,
463ee0b2 2170 0, 0, 0};
4633a7c4 2171EXT MGVTBL vtbl_pos = {magic_getpos,
a0d0e21e
LW
2172 magic_setpos,
2173 0, 0, 0};
4633a7c4 2174EXT MGVTBL vtbl_bm = {0, magic_setbm,
463ee0b2 2175 0, 0, 0};
55497cff 2176EXT MGVTBL vtbl_fm = {0, magic_setfm,
2177 0, 0, 0};
4633a7c4 2178EXT MGVTBL vtbl_uvar = {magic_getuvar,
463ee0b2
LW
2179 magic_setuvar,
2180 0, 0, 0};
f93b4edd
MB
2181#ifdef USE_THREADS
2182EXT MGVTBL vtbl_mutex = {0, 0, 0, 0, magic_mutexfree};
2183#endif /* USE_THREADS */
68dc0745 2184EXT MGVTBL vtbl_defelem = {magic_getdefelem,magic_setdefelem,
02270b4e 2185 0, 0, 0};
a0d0e21e 2186
227a8b4b 2187EXT MGVTBL vtbl_regexp = {0,0,0,0, magic_freeregexp};
6cef1e77
IZ
2188EXT MGVTBL vtbl_regdata = {0, 0, magic_regdata_cnt, 0, 0};
2189EXT MGVTBL vtbl_regdatum = {magic_regdatum_get, 0, 0, 0, 0};
c277df42 2190
36477c24 2191#ifdef USE_LOCALE_COLLATE
bbce6d69 2192EXT MGVTBL vtbl_collxfrm = {0,
2193 magic_setcollxfrm,
2194 0, 0, 0};
2195#endif
a0d0e21e
LW
2196
2197#ifdef OVERLOAD
4633a7c4 2198EXT MGVTBL vtbl_amagic = {0, magic_setamagic,
748a9306 2199 0, 0, magic_setamagic};
4633a7c4 2200EXT MGVTBL vtbl_amagicelem = {0, magic_setamagic,
748a9306 2201 0, 0, magic_setamagic};
a0d0e21e
LW
2202#endif /* OVERLOAD */
2203
bbce6d69 2204#else /* !DOINIT */
2205
79072805
LW
2206EXT MGVTBL vtbl_sv;
2207EXT MGVTBL vtbl_env;
2208EXT MGVTBL vtbl_envelem;
2209EXT MGVTBL vtbl_sig;
2210EXT MGVTBL vtbl_sigelem;
463ee0b2
LW
2211EXT MGVTBL vtbl_pack;
2212EXT MGVTBL vtbl_packelem;
79072805 2213EXT MGVTBL vtbl_dbline;
463ee0b2
LW
2214EXT MGVTBL vtbl_isa;
2215EXT MGVTBL vtbl_isaelem;
79072805
LW
2216EXT MGVTBL vtbl_arylen;
2217EXT MGVTBL vtbl_glob;
93a17b20 2218EXT MGVTBL vtbl_mglob;
99abf803 2219EXT MGVTBL vtbl_nkeys;
463ee0b2 2220EXT MGVTBL vtbl_taint;
79072805
LW
2221EXT MGVTBL vtbl_substr;
2222EXT MGVTBL vtbl_vec;
a0d0e21e 2223EXT MGVTBL vtbl_pos;
79072805 2224EXT MGVTBL vtbl_bm;
55497cff 2225EXT MGVTBL vtbl_fm;
79072805 2226EXT MGVTBL vtbl_uvar;
a0d0e21e 2227
f93b4edd
MB
2228#ifdef USE_THREADS
2229EXT MGVTBL vtbl_mutex;
2230#endif /* USE_THREADS */
2231
68dc0745 2232EXT MGVTBL vtbl_defelem;
c277df42 2233EXT MGVTBL vtbl_regexp;
6cef1e77
IZ
2234EXT MGVTBL vtbl_regdata;
2235EXT MGVTBL vtbl_regdatum;
a0d0e21e 2236
36477c24 2237#ifdef USE_LOCALE_COLLATE
bbce6d69 2238EXT MGVTBL vtbl_collxfrm;
2239#endif
a0d0e21e
LW
2240
2241#ifdef OVERLOAD
2242EXT MGVTBL vtbl_amagic;
2243EXT MGVTBL vtbl_amagicelem;
2244#endif /* OVERLOAD */
2245
bbce6d69 2246#endif /* !DOINIT */
85e6fe83 2247
a0d0e21e 2248#ifdef OVERLOAD
c0315cdf 2249
a6006777 2250#define NofAMmeth 58
a0d0e21e 2251#ifdef DOINIT
a6006777 2252EXTCONST char * AMG_names[NofAMmeth] = {
2253 "fallback", "abs", /* "fallback" should be the first. */
2254 "bool", "nomethod",
2255 "\"\"", "0+",
2256 "+", "+=",
2257 "-", "-=",
2258 "*", "*=",
2259 "/", "/=",
2260 "%", "%=",
2261 "**", "**=",
2262 "<<", "<<=",
2263 ">>", ">>=",
2264 "&", "&=",
2265 "|", "|=",
2266 "^", "^=",
2267 "<", "<=",
2268 ">", ">=",
2269 "==", "!=",
2270 "<=>", "cmp",
2271 "lt", "le",
2272 "gt", "ge",
2273 "eq", "ne",
2274 "!", "~",
2275 "++", "--",
2276 "atan2", "cos",
2277 "sin", "exp",
2278 "log", "sqrt",
2279 "x", "x=",
2280 ".", ".=",
2281 "=", "neg"
a0d0e21e
LW
2282};
2283#else
a6006777 2284EXTCONST char * AMG_names[NofAMmeth];
a0d0e21e
LW
2285#endif /* def INITAMAGIC */
2286
a6006777 2287struct am_table {
a0d0e21e
LW
2288 long was_ok_sub;
2289 long was_ok_am;
a6006777 2290 U32 flags;
2291 CV* table[NofAMmeth];
a0d0e21e
LW
2292 long fallback;
2293};
a6006777 2294struct am_table_short {
2295 long was_ok_sub;
2296 long was_ok_am;
2297 U32 flags;
2298};
a0d0e21e 2299typedef struct am_table AMT;
a6006777 2300typedef struct am_table_short AMTS;
a0d0e21e
LW
2301
2302#define AMGfallNEVER 1
2303#define AMGfallNO 2
2304#define AMGfallYES 3
2305
a6006777 2306#define AMTf_AMAGIC 1
2307#define AMT_AMAGIC(amt) ((amt)->flags & AMTf_AMAGIC)
2308#define AMT_AMAGIC_on(amt) ((amt)->flags |= AMTf_AMAGIC)
2309#define AMT_AMAGIC_off(amt) ((amt)->flags &= ~AMTf_AMAGIC)
2310
a0d0e21e
LW
2311enum {
2312 fallback_amg, abs_amg,
2313 bool__amg, nomethod_amg,
2314 string_amg, numer_amg,
2315 add_amg, add_ass_amg,
2316 subtr_amg, subtr_ass_amg,
2317 mult_amg, mult_ass_amg,
2318 div_amg, div_ass_amg,
76e3520e 2319 modulo_amg, modulo_ass_amg,
a0d0e21e
LW
2320 pow_amg, pow_ass_amg,
2321 lshift_amg, lshift_ass_amg,
2322 rshift_amg, rshift_ass_amg,
748a9306
LW
2323 band_amg, band_ass_amg,
2324 bor_amg, bor_ass_amg,
2325 bxor_amg, bxor_ass_amg,
a0d0e21e
LW
2326 lt_amg, le_amg,
2327 gt_amg, ge_amg,
2328 eq_amg, ne_amg,
2329 ncmp_amg, scmp_amg,
2330 slt_amg, sle_amg,
2331 sgt_amg, sge_amg,
2332 seq_amg, sne_amg,
a0d0e21e
LW
2333 not_amg, compl_amg,
2334 inc_amg, dec_amg,
2335 atan2_amg, cos_amg,
2336 sin_amg, exp_amg,
2337 log_amg, sqrt_amg,
2338 repeat_amg, repeat_ass_amg,
748a9306
LW
2339 concat_amg, concat_ass_amg,
2340 copy_amg, neg_amg
a0d0e21e 2341};
c0315cdf
JH
2342
2343/*
2344 * some compilers like to redefine cos et alia as faster
2345 * (and less accurate?) versions called F_cos et cetera (Quidquid
2346 * latine dictum sit, altum viditur.) This trick collides with
2347 * the Perl overloading (amg). The following #defines fool both.
2348 */
2349
2350#ifdef _FASTMATH
2351# ifdef atan2
2352# define F_atan2_amg atan2_amg
2353# endif
2354# ifdef cos
2355# define F_cos_amg cos_amg
2356# endif
2357# ifdef exp
2358# define F_exp_amg exp_amg
2359# endif
2360# ifdef log
2361# define F_log_amg log_amg
2362# endif
2363# ifdef pow
2364# define F_pow_amg pow_amg
2365# endif
2366# ifdef sin
2367# define F_sin_amg sin_amg
2368# endif
2369# ifdef sqrt
2370# define F_sqrt_amg sqrt_amg
2371# endif
2372#endif /* _FASTMATH */
2373
a0d0e21e
LW
2374#endif /* OVERLOAD */
2375
491527d0 2376#define PERLDB_ALL 0x3f /* No _NONAME, _GOTO */
84902520
TB
2377#define PERLDBf_SUB 0x01 /* Debug sub enter/exit. */
2378#define PERLDBf_LINE 0x02 /* Keep line #. */
2379#define PERLDBf_NOOPT 0x04 /* Switch off optimizations. */
2380#define PERLDBf_INTER 0x08 /* Preserve more data for
2381 later inspections. */
2382#define PERLDBf_SUBLINE 0x10 /* Keep subr source lines. */
2383#define PERLDBf_SINGLE 0x20 /* Start with single-step on. */
491527d0
GS
2384#define PERLDBf_NONAME 0x40 /* For _SUB: no name of the subr. */
2385#define PERLDBf_GOTO 0x80 /* Report goto: call DB::goto. */
84902520 2386
3280af22
NIS
2387#define PERLDB_SUB (PL_perldb && (PL_perldb & PERLDBf_SUB))
2388#define PERLDB_LINE (PL_perldb && (PL_perldb & PERLDBf_LINE))
2389#define PERLDB_NOOPT (PL_perldb && (PL_perldb & PERLDBf_NOOPT))
2390#define PERLDB_INTER (PL_perldb && (PL_perldb & PERLDBf_INTER))
2391#define PERLDB_SUBLINE (PL_perldb && (PL_perldb & PERLDBf_SUBLINE))
2392#define PERLDB_SINGLE (PL_perldb && (PL_perldb & PERLDBf_SINGLE))
2393#define PERLDB_SUB_NN (PL_perldb && (PL_perldb & (PERLDBf_NONAME)))
2394#define PERLDB_GOTO (PL_perldb && (PL_perldb & PERLDBf_GOTO))
84902520 2395
bbce6d69 2396
36477c24 2397#ifdef USE_LOCALE_NUMERIC
bbce6d69 2398
36477c24 2399#define SET_NUMERIC_STANDARD() \
2400 STMT_START { \
3280af22 2401 if (! PL_numeric_standard) \
36477c24 2402 perl_set_numeric_standard(); \
2403 } STMT_END
2404
2405#define SET_NUMERIC_LOCAL() \
2406 STMT_START { \
3280af22 2407 if (! PL_numeric_local) \
36477c24 2408 perl_set_numeric_local(); \
2409 } STMT_END
bbce6d69 2410
36477c24 2411#else /* !USE_LOCALE_NUMERIC */
bbce6d69 2412
36477c24 2413#define SET_NUMERIC_STANDARD() /**/
2414#define SET_NUMERIC_LOCAL() /**/
bbce6d69 2415
36477c24 2416#endif /* !USE_LOCALE_NUMERIC */
a0d0e21e 2417
e5c9fcd0 2418#if !defined(PERLIO_IS_STDIO) && defined(HASATTRIBUTE)
760ac839
LW
2419/*
2420 * Now we have __attribute__ out of the way
2421 * Remap printf
2422 */
2423#define printf PerlIO_stdoutf
2424#endif
2425
a868473f
NIS
2426#ifndef PERL_SCRIPT_MODE
2427#define PERL_SCRIPT_MODE "r"
2428#endif
2429
fba3b22e
MB
2430/*
2431 * nice_chunk and nice_chunk size need to be set
2432 * and queried under the protection of sv_mutex
2433 */
2434#define offer_nice_chunk(chunk, chunk_size) do { \
940cb80d 2435 LOCK_SV_MUTEX; \
3280af22
NIS
2436 if (!PL_nice_chunk) { \
2437 PL_nice_chunk = (char*)(chunk); \
2438 PL_nice_chunk_size = (chunk_size); \
fba3b22e 2439 } \
fc80cf79
GS
2440 else { \
2441 Safefree(chunk); \
2442 } \
940cb80d 2443 UNLOCK_SV_MUTEX; \
fba3b22e
MB
2444 } while (0)
2445
bd89102f
AD
2446#ifdef HAS_SEM
2447# include <sys/ipc.h>
2448# include <sys/sem.h>
2449# ifndef HAS_UNION_SEMUN /* Provide the union semun. */
2450 union semun {
2451 int val;
2452 struct semid_ds *buf;
2453 unsigned short *array;
2454 };
2455# endif
2456# ifdef USE_SEMCTL_SEMUN
2457# define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun)
2458# else
2459# ifdef USE_SEMCTL_SEMID_DS
2460# define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun.buf)
2461# endif
2462# endif
2463# ifndef Semctl /* Place our bets on the semun horse. */
2464# define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun)
2465# endif
2466#endif
49f531da 2467
85e6fe83 2468#endif /* Include guard */