This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.000 patch.0i: fix glaring mistakes in patches a-h
[perl5.git] / perl.h
CommitLineData
a0d0e21e 1/* perl.h
a687059c 2 *
a0d0e21e 3 * Copyright (c) 1987-1994, 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
79072805
LW
13#include "embed.h"
14
85e6fe83 15#define VOIDUSED 1
ac58e20f 16#include "config.h"
79072805
LW
17
18#ifndef BYTEORDER
19# define BYTEORDER 0x1234
20#endif
21
22/* Overall memory policy? */
23#ifndef CONSERVATIVE
24# define LIBERAL 1
25#endif
26
27/*
28 * The following contortions are brought to you on behalf of all the
29 * standards, semi-standards, de facto standards, not-so-de-facto standards
30 * of the world, as well as all the other botches anyone ever thought of.
31 * The basic theory is that if we work hard enough here, the rest of the
32 * code can be a lot prettier. Well, so much for theory. Sorry, Henry...
33 */
ac58e20f 34
45d8adaa
LW
35#ifdef MYMALLOC
36# ifdef HIDEMYMALLOC
37# define malloc Mymalloc
38# define realloc Myremalloc
39# define free Myfree
40# endif
41# define safemalloc malloc
42# define saferealloc realloc
43# define safefree free
44#endif
45
46/* work around some libPW problems */
45d8adaa 47#ifdef DOINIT
a0d0e21e 48EXT char Error[1];
45d8adaa
LW
49#endif
50
ee0007ab
LW
51/* define this once if either system, instead of cluttering up the src */
52#if defined(MSDOS) || defined(atarist)
53#define DOSISH 1
54#endif
55
a0d0e21e 56#if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
352d5a3a
LW
57# define STANDARD_C 1
58#endif
59
60#if defined(HASVOLATILE) || defined(STANDARD_C)
79072805
LW
61# ifdef __cplusplus
62# define VOL // to temporarily suppress warnings
63# else
64# define VOL volatile
65# endif
663a0e37 66#else
79072805 67# define VOL
663a0e37
LW
68#endif
69
463ee0b2
LW
70#define TAINT_IF(c) (tainted |= (c))
71#define TAINT_NOT (tainted = 0)
72#define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s)
73#define TAINT_ENV() if (tainting) taint_env()
a687059c 74
fe14fcc3 75#ifndef HAS_VFORK
03a14243
LW
76# define vfork fork
77#endif
78
fe14fcc3
LW
79#ifdef HAS_GETPGRP2
80# ifndef HAS_GETPGRP
81# define HAS_GETPGRP
663a0e37 82# endif
663a0e37
LW
83#endif
84
fe14fcc3
LW
85#ifdef HAS_SETPGRP2
86# ifndef HAS_SETPGRP
87# define HAS_SETPGRP
663a0e37 88# endif
663a0e37
LW
89#endif
90
fe14fcc3 91#include <stdio.h>
a0d0e21e
LW
92#ifdef USE_NEXT_CTYPE
93#include <appkit/NXCType.h>
94#else
fe14fcc3 95#include <ctype.h>
a0d0e21e
LW
96#endif
97
98#ifdef METHOD /* Defined by OSF/1 v3.0 by ctype.h */
99#undef METHOD
100#endif
101
fe14fcc3 102#include <setjmp.h>
79072805 103
a0d0e21e 104#ifdef I_SYS_PARAM
79072805
LW
105# ifdef PARAM_NEEDS_TYPES
106# include <sys/types.h>
107# endif
108# include <sys/param.h>
352d5a3a 109#endif
79072805
LW
110
111
112/* Use all the "standard" definitions? */
a0d0e21e 113#if defined(STANDARD_C) && defined(I_STDLIB)
79072805 114# include <stdlib.h>
352d5a3a 115#endif /* STANDARD_C */
03a14243 116
a0d0e21e
LW
117#define MEM_SIZE Size_t
118
119#if defined(I_STRING) || defined(__cplusplus)
120# include <string.h>
121#else
122# include <strings.h>
123#endif
124
125#if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
126#define strchr index
127#define strrchr rindex
128#endif
129
130#if defined(mips) && defined(ultrix) && !defined(__STDC__)
79072805 131# undef HAS_MEMCMP
663a0e37 132#endif
fe14fcc3
LW
133
134#ifdef HAS_MEMCPY
85e6fe83 135# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
fe14fcc3 136# ifndef memcpy
a0d0e21e 137 extern char * memcpy _((char*, char*, int));
ee0007ab
LW
138# endif
139# endif
140#else
141# ifndef memcpy
142# ifdef HAS_BCOPY
143# define memcpy(d,s,l) bcopy(s,d,l)
144# else
145# define memcpy(d,s,l) my_bcopy(s,d,l)
146# endif
147# endif
148#endif /* HAS_MEMCPY */
fe14fcc3 149
ee0007ab 150#ifdef HAS_MEMSET
85e6fe83 151# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
ee0007ab 152# ifndef memset
a0d0e21e 153 extern char *memset _((char*, int, int));
ee0007ab
LW
154# endif
155# endif
156# define memzero(d,l) memset(d,0,l)
157#else
158# ifndef memzero
159# ifdef HAS_BZERO
160# define memzero(d,l) bzero(d,l)
161# else
162# define memzero(d,l) my_bzero(d,l)
163# endif
352d5a3a 164# endif
ee0007ab
LW
165#endif /* HAS_MEMSET */
166
167#ifdef HAS_MEMCMP
85e6fe83 168# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
ee0007ab 169# ifndef memcmp
a0d0e21e 170 extern int memcmp _((char*, char*, int));
ee0007ab
LW
171# endif
172# endif
173#else
174# ifndef memcmp
ecfc5424 175# define memcmp my_memcmp
352d5a3a 176# endif
ee0007ab 177#endif /* HAS_MEMCMP */
8d063cd8 178
ee0007ab
LW
179/* we prefer bcmp slightly for comparisons that don't care about ordering */
180#ifndef HAS_BCMP
352d5a3a
LW
181# ifndef bcmp
182# define bcmp(s1,s2,l) memcmp(s1,s2,l)
183# endif
ee0007ab
LW
184#endif /* HAS_BCMP */
185
85e6fe83 186#if !defined(HAS_MEMMOVE) && !defined(memmove)
2304df62 187# if defined(HAS_BCOPY) && defined(HAS_SAFE_BCOPY)
79072805
LW
188# define memmove(d,s,l) bcopy(s,d,l)
189# else
2304df62 190# if defined(HAS_MEMCPY) && defined(HAS_SAFE_MEMCPY)
79072805
LW
191# define memmove(d,s,l) memcpy(d,s,l)
192# else
193# define memmove(d,s,l) my_bcopy(s,d,l)
194# endif
195# endif
d9d8d8de 196#endif
378cc40b
LW
197
198#ifndef _TYPES_ /* If types.h defines this it's easy. */
79072805
LW
199# ifndef major /* Does everyone's types.h define this? */
200# include <sys/types.h>
201# endif
378cc40b
LW
202#endif
203
ae986130 204#ifdef I_NETINET_IN
79072805 205# include <netinet/in.h>
ae986130
LW
206#endif
207
8d063cd8 208#include <sys/stat.h>
79072805 209
a0d0e21e
LW
210/* The stat macros for Amdahl UTS, Unisoft System V/88 (and derivatives
211 like UTekV) are broken, sometimes giving false positives. Undefine
212 them here and let the code below set them to proper values.
213
214 The ghs macro stands for GreenHills Software C-1.8.5 which
215 is the C compiler for sysV88 and the various derivatives.
216 This header file bug is corrected in gcc-2.5.8 and later versions.
217 --Kaveh Ghazi (ghazi@noc.rutgers.edu) 10/3/94. */
218
219#if defined(uts) || (defined(m88k) && defined(ghs))
79072805
LW
220# undef S_ISDIR
221# undef S_ISCHR
222# undef S_ISBLK
223# undef S_ISREG
224# undef S_ISFIFO
225# undef S_ISLNK
ee0007ab 226#endif
135863df 227
663a0e37
LW
228#ifdef I_TIME
229# include <time.h>
ffed7fef 230#endif
663a0e37 231
fe14fcc3 232#ifdef I_SYS_TIME
85e6fe83 233# ifdef I_SYS_TIME_KERNEL
663a0e37
LW
234# define KERNEL
235# endif
236# include <sys/time.h>
85e6fe83 237# ifdef I_SYS_TIME_KERNEL
663a0e37
LW
238# undef KERNEL
239# endif
a687059c 240#endif
135863df 241
d9d8d8de 242#ifndef MSDOS
a0d0e21e 243# if defined(HAS_TIMES) && defined(I_SYS_TIMES)
85e6fe83
LW
244# include <sys/times.h>
245# endif
d9d8d8de 246#endif
8d063cd8 247
fe14fcc3 248#if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
79072805 249# undef HAS_STRERROR
663a0e37
LW
250#endif
251
a0d0e21e
LW
252#ifndef HAS_MKFIFO
253# ifndef mkfifo
254# define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
255# endif
256#endif /* !HAS_MKFIFO */
257
663a0e37 258#include <errno.h>
ed6116ce 259#ifdef HAS_SOCKET
85e6fe83 260# ifdef I_NET_ERRNO
ed6116ce
LW
261# include <net/errno.h>
262# endif
263#endif
264
d9d8d8de 265#ifndef MSDOS
79072805
LW
266# ifndef errno
267 extern int errno; /* ANSI allows errno to be an lvalue expr */
268# endif
d9d8d8de 269#endif
663a0e37 270
2304df62 271#ifdef HAS_STRERROR
a0d0e21e
LW
272# ifdef VMS
273 char *strerror _((int,...));
274# else
275 char *strerror _((int));
276# endif
2304df62
AD
277# ifndef Strerror
278# define Strerror strerror
279# endif
280#else
281# ifdef HAS_SYS_ERRLIST
79072805
LW
282 extern int sys_nerr;
283 extern char *sys_errlist[];
2304df62
AD
284# ifndef Strerror
285# define Strerror(e) \
79072805 286 ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
2304df62 287# endif
79072805 288# endif
35c8bce7 289#endif
663a0e37 290
2304df62 291#ifdef I_SYS_IOCTL
79072805
LW
292# ifndef _IOCTL_
293# include <sys/ioctl.h>
294# endif
a687059c
LW
295#endif
296
ee0007ab 297#if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
79072805
LW
298# ifdef HAS_SOCKETPAIR
299# undef HAS_SOCKETPAIR
300# endif
2304df62
AD
301# ifdef I_NDBM
302# undef I_NDBM
79072805 303# endif
a687059c
LW
304#endif
305
a687059c 306#if INTSIZE == 2
79072805
LW
307# define htoni htons
308# define ntohi ntohs
a687059c 309#else
79072805
LW
310# define htoni htonl
311# define ntohi ntohl
a687059c
LW
312#endif
313
a0d0e21e 314/* Configure already sets Direntry_t */
35c8bce7 315#if defined(I_DIRENT)
663a0e37 316# include <dirent.h>
a0d0e21e
LW
317# if defined(NeXT) && defined(I_SYS_DIR) /* NeXT needs dirent + sys/dir.h */
318# include <sys/dir.h>
319# endif
ae986130 320#else
fe14fcc3 321# ifdef I_SYS_NDIR
79a0689e 322# include <sys/ndir.h>
663a0e37 323# else
fe14fcc3 324# ifdef I_SYS_DIR
79a0689e
LW
325# ifdef hp9000s500
326# include <ndir.h> /* may be wrong in the future */
327# else
328# include <sys/dir.h>
329# endif
663a0e37
LW
330# endif
331# endif
a0d0e21e 332#endif
a687059c 333
352d5a3a
LW
334#ifdef FPUTS_BOTCH
335/* work around botch in SunOS 4.0.1 and 4.0.2 */
336# ifndef fputs
79072805 337# define fputs(sv,fp) fprintf(fp,"%s",sv)
352d5a3a
LW
338# endif
339#endif
340
c623bd54
LW
341/*
342 * The following gobbledygook brought to you on behalf of __STDC__.
343 * (I could just use #ifndef __STDC__, but this is more bulletproof
344 * in the face of half-implementations.)
345 */
346
347#ifndef S_IFMT
348# ifdef _S_IFMT
349# define S_IFMT _S_IFMT
350# else
351# define S_IFMT 0170000
352# endif
353#endif
354
355#ifndef S_ISDIR
356# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
357#endif
358
359#ifndef S_ISCHR
360# define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
361#endif
362
363#ifndef S_ISBLK
fe14fcc3
LW
364# ifdef S_IFBLK
365# define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
366# else
367# define S_ISBLK(m) (0)
368# endif
c623bd54
LW
369#endif
370
371#ifndef S_ISREG
372# define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
373#endif
374
375#ifndef S_ISFIFO
fe14fcc3
LW
376# ifdef S_IFIFO
377# define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
378# else
379# define S_ISFIFO(m) (0)
380# endif
c623bd54
LW
381#endif
382
383#ifndef S_ISLNK
384# ifdef _S_ISLNK
385# define S_ISLNK(m) _S_ISLNK(m)
386# else
387# ifdef _S_IFLNK
388# define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
389# else
390# ifdef S_IFLNK
391# define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
392# else
393# define S_ISLNK(m) (0)
394# endif
395# endif
396# endif
397#endif
398
399#ifndef S_ISSOCK
400# ifdef _S_ISSOCK
401# define S_ISSOCK(m) _S_ISSOCK(m)
402# else
403# ifdef _S_IFSOCK
404# define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
405# else
406# ifdef S_IFSOCK
407# define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
408# else
409# define S_ISSOCK(m) (0)
410# endif
411# endif
412# endif
413#endif
414
415#ifndef S_IRUSR
416# ifdef S_IREAD
417# define S_IRUSR S_IREAD
418# define S_IWUSR S_IWRITE
419# define S_IXUSR S_IEXEC
420# else
421# define S_IRUSR 0400
422# define S_IWUSR 0200
423# define S_IXUSR 0100
424# endif
425# define S_IRGRP (S_IRUSR>>3)
426# define S_IWGRP (S_IWUSR>>3)
427# define S_IXGRP (S_IXUSR>>3)
428# define S_IROTH (S_IRUSR>>6)
429# define S_IWOTH (S_IWUSR>>6)
430# define S_IXOTH (S_IXUSR>>6)
431#endif
432
433#ifndef S_ISUID
434# define S_ISUID 04000
435#endif
436
437#ifndef S_ISGID
438# define S_ISGID 02000
439#endif
440
79072805
LW
441#ifdef ff_next
442# undef ff_next
352d5a3a
LW
443#endif
444
a0d0e21e 445#if defined(cray) || defined(gould) || defined(i860) || defined(pyr)
45d8adaa
LW
446# define SLOPPYDIVIDE
447#endif
448
988174c1 449#if defined(cray) || defined(convex) || defined (uts) || BYTEORDER > 0xffff
ecfc5424 450# define HAS_QUAD
45d8adaa
LW
451#endif
452
ecfc5424 453#ifdef HAS_QUAD
45d8adaa 454# ifdef cray
ecfc5424 455# define Quad_t int
45d8adaa 456# else
988174c1 457# if defined(convex) || defined (uts)
ecfc5424 458# define Quad_t long long
45d8adaa 459# else
ecfc5424 460# define Quad_t long
45d8adaa
LW
461# endif
462# endif
463#endif
464
79072805
LW
465#ifdef VOIDSIG
466# define VOIDRET void
467#else
468# define VOIDRET int
469#endif
470
471#ifdef DOSISH
472# include "dosish.h"
473#else
a0d0e21e
LW
474# if defined(VMS)
475# include "vmsish.h"
476# else
79072805 477# include "unixish.h"
a0d0e21e 478# endif
79072805
LW
479#endif
480
481#ifndef HAS_PAUSE
482#define pause() sleep((32767<<16)+32767)
483#endif
484
485#ifndef IOCPARM_LEN
486# ifdef IOCPARM_MASK
487 /* on BSDish systes we're safe */
488# define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
489# else
490 /* otherwise guess at what's safe */
491# define IOCPARM_LEN(x) 256
492# endif
493#endif
494
ee0007ab 495typedef MEM_SIZE STRLEN;
450a55e4 496
79072805
LW
497typedef struct op OP;
498typedef struct cop COP;
499typedef struct unop UNOP;
500typedef struct binop BINOP;
501typedef struct listop LISTOP;
502typedef struct logop LOGOP;
503typedef struct condop CONDOP;
504typedef struct pmop PMOP;
505typedef struct svop SVOP;
506typedef struct gvop GVOP;
507typedef struct pvop PVOP;
508typedef struct cvop CVOP;
509typedef struct loop LOOP;
510
511typedef struct Outrec Outrec;
512typedef struct lstring Lstring;
93a17b20 513typedef struct interpreter PerlInterpreter;
79072805 514typedef struct ff FF;
79072805
LW
515typedef struct sv SV;
516typedef struct av AV;
517typedef struct hv HV;
518typedef struct cv CV;
378cc40b 519typedef struct regexp REGEXP;
79072805
LW
520typedef struct gp GP;
521typedef struct sv GV;
8990e307 522typedef struct io IO;
79072805
LW
523typedef struct context CONTEXT;
524typedef struct block BLOCK;
525
526typedef struct magic MAGIC;
ed6116ce 527typedef struct xrv XRV;
79072805
LW
528typedef struct xpv XPV;
529typedef struct xpviv XPVIV;
530typedef struct xpvnv XPVNV;
531typedef struct xpvmg XPVMG;
532typedef struct xpvlv XPVLV;
533typedef struct xpvav XPVAV;
534typedef struct xpvhv XPVHV;
535typedef struct xpvgv XPVGV;
536typedef struct xpvcv XPVCV;
537typedef struct xpvbm XPVBM;
538typedef struct xpvfm XPVFM;
8990e307 539typedef struct xpvio XPVIO;
79072805
LW
540typedef struct mgvtbl MGVTBL;
541typedef union any ANY;
8d063cd8 542
a0d0e21e
LW
543typedef FILE * (*cryptswitch_t) _((FILE *rfp));
544
378cc40b 545#include "handy.h"
a0d0e21e 546
ecfc5424
AD
547#ifdef HAS_QUAD
548typedef Quad_t IV;
a0d0e21e
LW
549#else
550typedef long IV;
551#endif
552
79072805
LW
553union any {
554 void* any_ptr;
555 I32 any_i32;
a0d0e21e 556 IV any_iv;
85e6fe83 557 long any_long;
a0d0e21e 558 void (*any_dptr) _((void*));
79072805
LW
559};
560
378cc40b 561#include "regexp.h"
79072805 562#include "sv.h"
378cc40b 563#include "util.h"
8d063cd8 564#include "form.h"
79072805
LW
565#include "gv.h"
566#include "cv.h"
567#include "opcode.h"
568#include "op.h"
569#include "cop.h"
570#include "av.h"
571#include "hv.h"
572#include "mg.h"
573#include "scope.h"
8d063cd8 574
450a55e4 575#if defined(iAPX286) || defined(M_I286) || defined(I80286)
a687059c
LW
576# define I286
577#endif
578
fe14fcc3
LW
579#if defined(htonl) && !defined(HAS_HTONL)
580#define HAS_HTONL
ae986130 581#endif
fe14fcc3
LW
582#if defined(htons) && !defined(HAS_HTONS)
583#define HAS_HTONS
ae986130 584#endif
fe14fcc3
LW
585#if defined(ntohl) && !defined(HAS_NTOHL)
586#define HAS_NTOHL
ae986130 587#endif
fe14fcc3
LW
588#if defined(ntohs) && !defined(HAS_NTOHS)
589#define HAS_NTOHS
ae986130 590#endif
fe14fcc3 591#ifndef HAS_HTONL
d9d8d8de 592#if (BYTEORDER & 0xffff) != 0x4321
fe14fcc3
LW
593#define HAS_HTONS
594#define HAS_HTONL
595#define HAS_NTOHS
596#define HAS_NTOHL
a687059c
LW
597#define MYSWAP
598#define htons my_swap
599#define htonl my_htonl
600#define ntohs my_swap
601#define ntohl my_ntohl
602#endif
603#else
d9d8d8de 604#if (BYTEORDER & 0xffff) == 0x4321
fe14fcc3
LW
605#undef HAS_HTONS
606#undef HAS_HTONL
607#undef HAS_NTOHS
608#undef HAS_NTOHL
a687059c
LW
609#endif
610#endif
611
988174c1
LW
612/*
613 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
614 * -DWS
615 */
616#if BYTEORDER != 0x1234
617# define HAS_VTOHL
618# define HAS_VTOHS
619# define HAS_HTOVL
620# define HAS_HTOVS
621# if BYTEORDER == 0x4321
622# define vtohl(x) ((((x)&0xFF)<<24) \
623 +(((x)>>24)&0xFF) \
624 +(((x)&0x0000FF00)<<8) \
625 +(((x)&0x00FF0000)>>8) )
626# define vtohs(x) ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
627# define htovl(x) vtohl(x)
628# define htovs(x) vtohs(x)
629# endif
630 /* otherwise default to functions in util.c */
631#endif
632
0f85fab0 633#ifdef CASTNEGFLOAT
79072805 634#define U_S(what) ((U16)(what))
0f85fab0 635#define U_I(what) ((unsigned int)(what))
79072805 636#define U_L(what) ((U32)(what))
0f85fab0 637#else
a0d0e21e 638U32 cast_ulong _((double));
79072805
LW
639#define U_S(what) ((U16)cast_ulong(what))
640#define U_I(what) ((unsigned int)cast_ulong(what))
641#define U_L(what) (cast_ulong(what))
ee0007ab
LW
642#endif
643
ed6116ce
LW
644#ifdef CASTI32
645#define I_32(what) ((I32)(what))
a0d0e21e 646#define I_V(what) ((IV)(what))
ed6116ce 647#else
a0d0e21e 648I32 cast_i32 _((double));
ed6116ce 649#define I_32(what) (cast_i32(what))
a0d0e21e
LW
650IV cast_iv _((double));
651#define I_V(what) (cast_iv(what))
ed6116ce
LW
652#endif
653
79072805
LW
654struct Outrec {
655 I32 o_lines;
d9d8d8de 656 char *o_str;
79072805 657 U32 o_len;
8d063cd8
LW
658};
659
352d5a3a
LW
660#ifndef MAXSYSFD
661# define MAXSYSFD 2
662#endif
ee0007ab 663
a0d0e21e 664#ifdef DOSISH
57ebbfd0 665#define TMPPATH "plXXXXXX"
a0d0e21e
LW
666#else
667#ifdef VMS
668#define TMPPATH "/sys$scratch/perl-eXXXXXX"
669#else
670#define TMPPATH "/tmp/perl-eXXXXXX"
671#endif
672#endif
79072805
LW
673
674#ifndef __cplusplus
a0d0e21e
LW
675Uid_t getuid _((void));
676Uid_t geteuid _((void));
677Gid_t getgid _((void));
678Gid_t getegid _((void));
79072805 679#endif
8d063cd8
LW
680
681#ifdef DEBUGGING
d96024cf 682#define YYDEBUG 1
79072805
LW
683#define DEB(a) a
684#define DEBUG(a) if (debug) a
685#define DEBUG_p(a) if (debug & 1) a
686#define DEBUG_s(a) if (debug & 2) a
687#define DEBUG_l(a) if (debug & 4) a
688#define DEBUG_t(a) if (debug & 8) a
689#define DEBUG_o(a) if (debug & 16) a
690#define DEBUG_c(a) if (debug & 32) a
691#define DEBUG_P(a) if (debug & 64) a
692#define DEBUG_m(a) if (debug & 128) a
693#define DEBUG_f(a) if (debug & 256) a
694#define DEBUG_r(a) if (debug & 512) a
695#define DEBUG_x(a) if (debug & 1024) a
696#define DEBUG_u(a) if (debug & 2048) a
697#define DEBUG_L(a) if (debug & 4096) a
698#define DEBUG_H(a) if (debug & 8192) a
699#define DEBUG_X(a) if (debug & 16384) a
8990e307 700#define DEBUG_D(a) if (debug & 32768) a
79072805
LW
701#else
702#define DEB(a)
703#define DEBUG(a)
704#define DEBUG_p(a)
705#define DEBUG_s(a)
706#define DEBUG_l(a)
707#define DEBUG_t(a)
708#define DEBUG_o(a)
709#define DEBUG_c(a)
710#define DEBUG_P(a)
711#define DEBUG_m(a)
712#define DEBUG_f(a)
713#define DEBUG_r(a)
714#define DEBUG_x(a)
715#define DEBUG_u(a)
716#define DEBUG_L(a)
717#define DEBUG_H(a)
718#define DEBUG_X(a)
8990e307 719#define DEBUG_D(a)
8d063cd8 720#endif
fe14fcc3 721#define YYMAXDEPTH 300
8d063cd8 722
79072805
LW
723#define assert(what) DEB( { \
724 if (!(what)) { \
463ee0b2 725 croak("Assertion failed: file \"%s\", line %d", \
79072805
LW
726 __FILE__, __LINE__); \
727 exit(1); \
728 }})
8d063cd8 729
450a55e4 730struct ufuncs {
a0d0e21e
LW
731 I32 (*uf_val)_((IV, SV*));
732 I32 (*uf_set)_((IV, SV*));
733 IV uf_index;
450a55e4
LW
734};
735
fe14fcc3 736/* Fix these up for __STDC__ */
a0d0e21e
LW
737#ifndef __cplusplus
738char *mktemp _((char*));
739double atof _((const char*));
740#endif
79072805 741
352d5a3a 742#ifndef STANDARD_C
fe14fcc3 743/* All of these are in stdlib.h or time.h for ANSI C */
85e6fe83 744Time_t time();
8d063cd8 745struct tm *gmtime(), *localtime();
93a17b20 746char *strchr(), *strrchr();
378cc40b 747char *strcpy(), *strcat();
352d5a3a 748#endif /* ! STANDARD_C */
8d063cd8 749
79072805
LW
750
751#ifdef I_MATH
752# include <math.h>
753#else
754# ifdef __cplusplus
755 extern "C" {
756# endif
a0d0e21e
LW
757 double exp _((double));
758 double fmod _((double,double));
759 double log _((double));
760 double sqrt _((double));
761 double modf _((double,double*));
762 double sin _((double));
763 double cos _((double));
764 double atan2 _((double,double));
765 double pow _((double,double));
79072805
LW
766# ifdef __cplusplus
767 };
768# endif
769#endif
770
75f92628
AD
771#ifndef HAS_FMOD
772# ifdef HAS_DREM
773# define fmod(x,y) drem((x),(y))
774# else
775# define USE_MY_FMOD
776# define fmod(x,y) my_fmod(x,y)
777# endif
a0d0e21e 778#endif
79072805 779
a0d0e21e
LW
780#ifndef __cplusplus
781char *crypt _((const char*, const char*));
782char *getenv _((const char*));
783Off_t lseek _((int,Off_t,int));
784char *getlogin _((void));
785#endif
79072805 786
8d063cd8 787#ifdef EUNICE
378cc40b 788#define UNLINK unlnk
a0d0e21e 789I32 unlnk _((char*));
8d063cd8
LW
790#else
791#define UNLINK unlink
792#endif
a687059c 793
fe14fcc3 794#ifndef HAS_SETREUID
85e6fe83
LW
795# ifdef HAS_SETRESUID
796# define setreuid(r,e) setresuid(r,e,(Uid_t)-1)
797# define HAS_SETREUID
798# endif
a687059c 799#endif
fe14fcc3 800#ifndef HAS_SETREGID
85e6fe83
LW
801# ifdef HAS_SETRESGID
802# define setregid(r,e) setresgid(r,e,(Gid_t)-1)
803# define HAS_SETREGID
804# endif
a687059c 805#endif
ee0007ab
LW
806
807#define SCAN_DEF 0
808#define SCAN_TR 1
809#define SCAN_REPL 2
79072805
LW
810
811#ifdef DEBUGGING
a0d0e21e
LW
812# ifndef register
813# define register
814# endif
815# define PAD_SV(po) pad_sv(po)
79072805 816#else
a0d0e21e 817# define PAD_SV(po) curpad[po]
79072805
LW
818#endif
819
820/****************/
821/* Truly global */
822/****************/
823
824/* global state */
a0d0e21e
LW
825EXT PerlInterpreter * curinterp; /* currently running interpreter */
826#ifndef VMS /* VMS doesn't use environ array */
79072805 827extern char ** environ; /* environment variables supplied via exec */
a0d0e21e 828#endif
79072805
LW
829EXT int uid; /* current real user id */
830EXT int euid; /* current effective user id */
831EXT int gid; /* current real group id */
832EXT int egid; /* current effective group id */
833EXT bool nomemok; /* let malloc context handle nomem */
834EXT U32 an; /* malloc sequence number */
463ee0b2
LW
835EXT U32 cop_seqmax; /* statement sequence number */
836EXT U32 op_seqmax; /* op sequence number */
8990e307 837EXT U32 evalseq; /* eval sequence number */
463ee0b2 838EXT U32 sub_generation; /* inc to force methods to be looked up again */
79072805
LW
839EXT char ** origenviron;
840EXT U32 origalen;
a0d0e21e 841EXT U32 * profiledata;
79072805 842
a0d0e21e
LW
843EXT XPV* xiv_arenaroot; /* list of allocated xiv areas */
844EXT IV ** xiv_root; /* free xiv list--shared by interpreters */
8990e307
LW
845EXT double * xnv_root; /* free xnv list--shared by interpreters */
846EXT XRV * xrv_root; /* free xrv list--shared by interpreters */
847EXT XPV * xpv_root; /* free xpv list--shared by interpreters */
848
79072805
LW
849/* Stack for currently executing thread--context switch must handle this. */
850EXT SV ** stack_base; /* stack->array_ary */
851EXT SV ** stack_sp; /* stack pointer now */
852EXT SV ** stack_max; /* stack->array_ary + stack->array_max */
853
854/* likewise for these */
855
856EXT OP * op; /* current op--oughta be in a global register */
857
858EXT I32 * scopestack; /* blocks we've entered */
859EXT I32 scopestack_ix;
860EXT I32 scopestack_max;
861
862EXT ANY* savestack; /* to save non-local values on */
863EXT I32 savestack_ix;
864EXT I32 savestack_max;
865
866EXT OP ** retstack; /* returns we've pushed */
867EXT I32 retstack_ix;
868EXT I32 retstack_max;
869
870EXT I32 * markstack; /* stackmarks we're remembering */
871EXT I32 * markstack_ptr; /* stackmarks we're remembering */
872EXT I32 * markstack_max; /* stackmarks we're remembering */
873
874EXT SV ** curpad;
875
876/* temp space */
877EXT SV * Sv;
878EXT XPV * Xpv;
879EXT char buf[1024];
880EXT char tokenbuf[256];
881EXT struct stat statbuf;
ecfc5424 882#ifdef HAS_TIMES
79072805
LW
883EXT struct tms timesbuf;
884#endif
463ee0b2 885EXT STRLEN na; /* for use in SvPV when length is Not Applicable */
79072805
LW
886
887/* for tmp use in stupid debuggers */
888EXT int * di;
889EXT short * ds;
890EXT char * dc;
891
892/* handy constants */
893EXT char * Yes INIT("1");
894EXT char * No INIT("");
895EXT char * hexdigit INIT("0123456789abcdef0123456789ABCDEFx");
79072805
LW
896EXT char * patleave INIT("\\.^$@dDwWsSbB+*?|()-nrtfeaxc0123456789[{]}");
897EXT char * vert INIT("|");
898
8990e307 899EXT char warn_uninit[]
a0d0e21e 900 INIT("Use of uninitialized value");
463ee0b2
LW
901EXT char warn_nosemi[]
902 INIT("Semicolon seems to be missing");
903EXT char warn_reserved[]
904 INIT("Unquoted string \"%s\" may clash with future reserved word");
905EXT char warn_nl[]
93a17b20 906 INIT("Unsuccessful %s on filename containing newline");
a0d0e21e
LW
907EXT char no_wrongref[]
908 INIT("Can't use %s ref as %s ref");
909EXT char no_symref[]
910 INIT("Can't use a string as %s ref while \"strict refs\" in use");
93a17b20 911EXT char no_usym[]
8990e307 912 INIT("Can't use an undefined value as %s reference");
93a17b20
LW
913EXT char no_aelem[]
914 INIT("Modification of non-creatable array value attempted, subscript %d");
915EXT char no_helem[]
916 INIT("Modification of non-creatable hash value attempted, subscript \"%s\"");
917EXT char no_modify[]
918 INIT("Modification of a read-only value attempted");
919EXT char no_mem[]
920 INIT("Out of memory!\n");
921EXT char no_security[]
463ee0b2 922 INIT("Insecure dependency in %s%s");
93a17b20
LW
923EXT char no_sock_func[]
924 INIT("Unsupported socket function \"%s\" called");
925EXT char no_dir_func[]
926 INIT("Unsupported directory function \"%s\" called");
927EXT char no_func[]
928 INIT("The %s function is unimplemented");
929
79072805
LW
930EXT SV sv_undef;
931EXT SV sv_no;
932EXT SV sv_yes;
933#ifdef CSH
934 EXT char * cshname INIT(CSH);
935 EXT I32 cshlen;
936#endif
937
938#ifdef DOINIT
939EXT char *sig_name[] = {
940 SIG_NAME,0
941};
942#else
943EXT char *sig_name[];
944#endif
945
946#ifdef DOINIT
79072805
LW
947EXT unsigned char fold[] = { /* fast case folding table */
948 0, 1, 2, 3, 4, 5, 6, 7,
949 8, 9, 10, 11, 12, 13, 14, 15,
950 16, 17, 18, 19, 20, 21, 22, 23,
951 24, 25, 26, 27, 28, 29, 30, 31,
952 32, 33, 34, 35, 36, 37, 38, 39,
953 40, 41, 42, 43, 44, 45, 46, 47,
954 48, 49, 50, 51, 52, 53, 54, 55,
955 56, 57, 58, 59, 60, 61, 62, 63,
956 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
957 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
958 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
959 'x', 'y', 'z', 91, 92, 93, 94, 95,
960 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
961 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
962 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
963 'X', 'Y', 'Z', 123, 124, 125, 126, 127,
964 128, 129, 130, 131, 132, 133, 134, 135,
965 136, 137, 138, 139, 140, 141, 142, 143,
966 144, 145, 146, 147, 148, 149, 150, 151,
967 152, 153, 154, 155, 156, 157, 158, 159,
968 160, 161, 162, 163, 164, 165, 166, 167,
969 168, 169, 170, 171, 172, 173, 174, 175,
970 176, 177, 178, 179, 180, 181, 182, 183,
971 184, 185, 186, 187, 188, 189, 190, 191,
972 192, 193, 194, 195, 196, 197, 198, 199,
973 200, 201, 202, 203, 204, 205, 206, 207,
974 208, 209, 210, 211, 212, 213, 214, 215,
975 216, 217, 218, 219, 220, 221, 222, 223,
976 224, 225, 226, 227, 228, 229, 230, 231,
977 232, 233, 234, 235, 236, 237, 238, 239,
978 240, 241, 242, 243, 244, 245, 246, 247,
979 248, 249, 250, 251, 252, 253, 254, 255
980};
981#else
982EXT unsigned char fold[];
983#endif
984
985#ifdef DOINIT
986EXT unsigned char freq[] = { /* letter frequencies for mixed English/C */
987 1, 2, 84, 151, 154, 155, 156, 157,
988 165, 246, 250, 3, 158, 7, 18, 29,
989 40, 51, 62, 73, 85, 96, 107, 118,
990 129, 140, 147, 148, 149, 150, 152, 153,
991 255, 182, 224, 205, 174, 176, 180, 217,
992 233, 232, 236, 187, 235, 228, 234, 226,
993 222, 219, 211, 195, 188, 193, 185, 184,
994 191, 183, 201, 229, 181, 220, 194, 162,
995 163, 208, 186, 202, 200, 218, 198, 179,
996 178, 214, 166, 170, 207, 199, 209, 206,
997 204, 160, 212, 216, 215, 192, 175, 173,
998 243, 172, 161, 190, 203, 189, 164, 230,
999 167, 248, 227, 244, 242, 255, 241, 231,
1000 240, 253, 169, 210, 245, 237, 249, 247,
1001 239, 168, 252, 251, 254, 238, 223, 221,
1002 213, 225, 177, 197, 171, 196, 159, 4,
1003 5, 6, 8, 9, 10, 11, 12, 13,
1004 14, 15, 16, 17, 19, 20, 21, 22,
1005 23, 24, 25, 26, 27, 28, 30, 31,
1006 32, 33, 34, 35, 36, 37, 38, 39,
1007 41, 42, 43, 44, 45, 46, 47, 48,
1008 49, 50, 52, 53, 54, 55, 56, 57,
1009 58, 59, 60, 61, 63, 64, 65, 66,
1010 67, 68, 69, 70, 71, 72, 74, 75,
1011 76, 77, 78, 79, 80, 81, 82, 83,
1012 86, 87, 88, 89, 90, 91, 92, 93,
1013 94, 95, 97, 98, 99, 100, 101, 102,
1014 103, 104, 105, 106, 108, 109, 110, 111,
1015 112, 113, 114, 115, 116, 117, 119, 120,
1016 121, 122, 123, 124, 125, 126, 127, 128,
1017 130, 131, 132, 133, 134, 135, 136, 137,
1018 138, 139, 141, 142, 143, 144, 145, 146
1019};
1020#else
1021EXT unsigned char freq[];
1022#endif
1023
8990e307
LW
1024#ifdef DEBUGGING
1025#ifdef DOINIT
1026EXT char* block_type[] = {
1027 "NULL",
1028 "SUB",
1029 "EVAL",
1030 "LOOP",
1031 "SUBST",
1032 "BLOCK",
1033};
1034#else
1035EXT char* block_type[];
1036#endif
1037#endif
1038
79072805
LW
1039/*****************************************************************************/
1040/* This lexer/parser stuff is currently global since yacc is hard to reenter */
1041/*****************************************************************************/
8990e307 1042/* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */
79072805 1043
a0d0e21e
LW
1044#include "perly.h"
1045
79072805
LW
1046typedef enum {
1047 XOPERATOR,
1048 XTERM,
79072805 1049 XREF,
8990e307 1050 XSTATE,
a0d0e21e
LW
1051 XBLOCK,
1052 XTERMBLOCK
79072805
LW
1053} expectation;
1054
a0d0e21e
LW
1055EXT U32 lex_state; /* next token is determined */
1056EXT U32 lex_defer; /* state after determined token */
1057EXT expectation lex_expect; /* expect after determined token */
1058EXT I32 lex_brackets; /* bracket count */
1059EXT I32 lex_formbrack; /* bracket count at outer format level */
1060EXT I32 lex_fakebrack; /* outer bracket is mere delimiter */
1061EXT I32 lex_casemods; /* casemod count */
1062EXT I32 lex_dojoin; /* doing an array interpolation */
1063EXT I32 lex_starts; /* how many interps done on level */
1064EXT SV * lex_stuff; /* runtime pattern from m// or s/// */
1065EXT SV * lex_repl; /* runtime replacement from s/// */
1066EXT OP * lex_op; /* extra info to pass back on op */
1067EXT OP * lex_inpat; /* in pattern $) and $| are special */
1068EXT I32 lex_inwhat; /* what kind of quoting are we in */
1069EXT char * lex_brackstack; /* what kind of brackets to pop */
1070EXT char * lex_casestack; /* what kind of case mods in effect */
1071
1072/* What we know when we're in LEX_KNOWNEXT state. */
1073EXT YYSTYPE nextval[5]; /* value of next token, if any */
1074EXT I32 nexttype[5]; /* type of next token */
1075EXT I32 nexttoke;
1076
79072805
LW
1077EXT FILE * VOL rsfp INIT(Nullfp);
1078EXT SV * linestr;
1079EXT char * bufptr;
1080EXT char * oldbufptr;
1081EXT char * oldoldbufptr;
1082EXT char * bufend;
8990e307 1083EXT expectation expect INIT(XSTATE); /* how to interpret ambiguous tokens */
a0d0e21e 1084EXT char * autoboot_preamble INIT(Nullch);
79072805
LW
1085
1086EXT I32 multi_start; /* 1st line of multi-line string */
1087EXT I32 multi_end; /* last line of multi-line string */
1088EXT I32 multi_open; /* delimiter of said string */
1089EXT I32 multi_close; /* delimiter of said string */
1090
1091EXT GV * scrgv;
1092EXT I32 error_count; /* how many errors so far, max 10 */
1093EXT I32 subline; /* line this subroutine began on */
1094EXT SV * subname; /* name of current subroutine */
1095
93a17b20 1096EXT AV * comppad; /* storage for lexically scoped temporaries */
8990e307
LW
1097EXT AV * comppad_name; /* variable names for "my" variables */
1098EXT I32 comppad_name_fill;/* last "introduced" variable offset */
1099EXT I32 min_intro_pending;/* start of vars to introduce */
1100EXT I32 max_intro_pending;/* end of vars to introduce */
79072805 1101EXT I32 padix; /* max used index in current "register" pad */
a0d0e21e
LW
1102EXT I32 padix_floor; /* how low may inner block reset padix */
1103EXT bool pad_reset_pending; /* reset pad on next attempted alloc */
79072805
LW
1104EXT COP compiling;
1105
79072805
LW
1106EXT I32 thisexpr; /* name id for nothing_in_common() */
1107EXT char * last_uni; /* position of last named-unary operator */
1108EXT char * last_lop; /* position of last list operator */
8990e307 1109EXT OPCODE last_lop_op; /* last list operator */
93a17b20 1110EXT bool in_my; /* we're compiling a "my" declaration */
79072805
LW
1111#ifdef FCRYPT
1112EXT I32 cryptseen; /* has fast crypt() been initialized? */
1113#endif
1114
85e6fe83
LW
1115EXT U32 hints; /* various compilation flags */
1116
1117 /* Note: the lowest 8 bits are reserved for
1118 stuffing into op->op_private */
1119#define HINT_INTEGER 0x00000001
1120#define HINT_STRICT_REFS 0x00000002
1121
1122#define HINT_BLOCK_SCOPE 0x00000100
1123#define HINT_STRICT_SUBS 0x00000200
1124#define HINT_STRICT_VARS 0x00000400
1125
79072805
LW
1126/**************************************************************************/
1127/* This regexp stuff is global since it always happens within 1 expr eval */
1128/**************************************************************************/
1129
1130EXT char * regprecomp; /* uncompiled string. */
1131EXT char * regparse; /* Input-scan pointer. */
1132EXT char * regxend; /* End of input for compile */
1133EXT I32 regnpar; /* () count. */
1134EXT char * regcode; /* Code-emit pointer; &regdummy = don't. */
1135EXT I32 regsize; /* Code size. */
a0d0e21e 1136EXT I32 regnaughty; /* How bad is this pattern? */
79072805
LW
1137EXT I32 regsawback; /* Did we see \1, ...? */
1138
1139EXT char * reginput; /* String-input pointer. */
79072805
LW
1140EXT char * regbol; /* Beginning of input, for ^ check. */
1141EXT char * regeol; /* End of input, for $ check. */
1142EXT char ** regstartp; /* Pointer to startp array. */
1143EXT char ** regendp; /* Ditto for endp. */
a0d0e21e 1144EXT U32 * reglastparen; /* Similarly for lastparen. */
79072805 1145EXT char * regtill; /* How far we are required to go. */
a0d0e21e
LW
1146EXT U16 regflags; /* are we folding, multilining? */
1147EXT char regprev; /* char before regbol, \n if none */
79072805
LW
1148
1149/***********************************************/
1150/* Global only to current interpreter instance */
1151/***********************************************/
1152
8990e307 1153#ifdef MULTIPLICITY
79072805
LW
1154#define IEXT
1155#define IINIT(x)
1156struct interpreter {
1157#else
1158#define IEXT EXT
1159#define IINIT(x) INIT(x)
1160#endif
1161
1162/* pseudo environmental stuff */
1163IEXT int Iorigargc;
1164IEXT char ** Iorigargv;
1165IEXT GV * Ienvgv;
1166IEXT GV * Isiggv;
1167IEXT GV * Iincgv;
1168IEXT char * Iorigfilename;
1169
1170/* switches */
1171IEXT char * Icddir;
1172IEXT bool Iminus_c;
1173IEXT char Ipatchlevel[6];
1174IEXT char * Inrs IINIT("\n");
1175IEXT U32 Inrschar IINIT('\n'); /* final char of rs, or 0777 if none */
1176IEXT I32 Inrslen IINIT(1);
2304df62 1177IEXT char * Isplitstr IINIT(" ");
79072805
LW
1178IEXT bool Ipreprocess;
1179IEXT bool Iminus_n;
1180IEXT bool Iminus_p;
1181IEXT bool Iminus_l;
1182IEXT bool Iminus_a;
2304df62 1183IEXT bool Iminus_F;
79072805
LW
1184IEXT bool Idoswitches;
1185IEXT bool Idowarn;
1186IEXT bool Idoextract;
79072805
LW
1187IEXT bool Isawampersand; /* must save all match strings */
1188IEXT bool Isawstudy; /* do fbm_instr on all strings */
1189IEXT bool Isawi; /* study must assume case insensitive */
1190IEXT bool Isawvec;
1191IEXT bool Iunsafe;
1192IEXT bool Ido_undump; /* -u or dump seen? */
1193IEXT char * Iinplace;
1194IEXT char * Ie_tmpname;
1195IEXT FILE * Ie_fp;
1196IEXT VOL U32 Idebug;
1197IEXT U32 Iperldb;
1198
1199/* magical thingies */
85e6fe83 1200IEXT Time_t Ibasetime; /* $^T */
79072805
LW
1201IEXT SV * Iformfeed; /* $^L */
1202IEXT char * Ichopset IINIT(" \n-"); /* $: */
1203IEXT char * Irs IINIT("\n"); /* $/ */
1204IEXT U32 Irschar IINIT('\n'); /* final char of rs, or 0777 if none */
8990e307 1205IEXT STRLEN Irslen IINIT(1);
79072805
LW
1206IEXT bool Irspara;
1207IEXT char * Iofs; /* $, */
8990e307 1208IEXT STRLEN Iofslen;
79072805 1209IEXT char * Iors; /* $\ */
8990e307 1210IEXT STRLEN Iorslen;
79072805
LW
1211IEXT char * Iofmt; /* $# */
1212IEXT I32 Imaxsysfd IINIT(MAXSYSFD); /* top fd to pass to subprocesses */
1213IEXT int Imultiline; /* $*--do strings hold >1 line? */
1214IEXT U16 Istatusvalue; /* $? */
1215
1216IEXT struct stat Istatcache; /* _ */
1217IEXT GV * Istatgv;
1218IEXT SV * Istatname IINIT(Nullsv);
1219
1220/* shortcuts to various I/O objects */
1221IEXT GV * Istdingv;
1222IEXT GV * Ilast_in_gv;
1223IEXT GV * Idefgv;
1224IEXT GV * Iargvgv;
1225IEXT GV * Idefoutgv;
79072805
LW
1226IEXT GV * Iargvoutgv;
1227
1228/* shortcuts to regexp stuff */
1229IEXT GV * Ileftgv;
1230IEXT GV * Iampergv;
1231IEXT GV * Irightgv;
1232IEXT PMOP * Icurpm; /* what to do \ interps from */
79072805
LW
1233IEXT I32 * Iscreamfirst;
1234IEXT I32 * Iscreamnext;
1235IEXT I32 Imaxscream IINIT(-1);
1236IEXT SV * Ilastscream;
1237
1238/* shortcuts to debugging objects */
1239IEXT GV * IDBgv;
1240IEXT GV * IDBline;
1241IEXT GV * IDBsub;
1242IEXT SV * IDBsingle;
1243IEXT SV * IDBtrace;
1244IEXT SV * IDBsignal;
1245IEXT AV * Ilineary; /* lines of script for debugger */
1246IEXT AV * Idbargs; /* args to call listed by caller function */
1247
1248/* symbol tables */
1249IEXT HV * Idefstash; /* main symbol table */
1250IEXT HV * Icurstash; /* symbol table for current package */
1251IEXT HV * Idebstash; /* symbol table for perldb package */
1252IEXT SV * Icurstname; /* name of current package */
93a17b20
LW
1253IEXT AV * Ibeginav; /* names of BEGIN subroutines */
1254IEXT AV * Iendav; /* names of END subroutines */
1255IEXT AV * Ipad; /* storage for lexically scoped temporaries */
1256IEXT AV * Ipadname; /* variable names for "my" variables */
79072805
LW
1257
1258/* memory management */
79072805
LW
1259IEXT SV ** Itmps_stack;
1260IEXT I32 Itmps_ix IINIT(-1);
1261IEXT I32 Itmps_floor IINIT(-1);
8990e307
LW
1262IEXT I32 Itmps_max;
1263IEXT I32 Isv_count; /* how many SV* are currently allocated */
a0d0e21e 1264IEXT I32 Isv_objcount; /* how many objects are currently allocated */
8990e307
LW
1265IEXT SV* Isv_root; /* storage for SVs belonging to interp */
1266IEXT SV* Isv_arenaroot; /* list of areas for garbage collection */
79072805
LW
1267
1268/* funky return mechanisms */
1269IEXT I32 Ilastspbase;
1270IEXT I32 Ilastsize;
1271IEXT int Iforkprocess; /* so do_open |- can return proc# */
1272
1273/* subprocess state */
1274IEXT AV * Ifdpid; /* keep fd-to-pid mappings for my_popen */
1275IEXT HV * Ipidstatus; /* keep pid-to-status mappings for waitpid */
1276
1277/* internal state */
463ee0b2
LW
1278IEXT VOL int Iin_eval; /* trap "fatal" errors? */
1279IEXT OP * Irestartop; /* Are we propagating an error from croak? */
79072805 1280IEXT int Idelaymagic; /* ($<,$>) = ... */
2304df62 1281IEXT bool Idirty; /* In the middle of tearing things down? */
79072805 1282IEXT bool Ilocalizing; /* are we processing a local() list? */
79072805 1283IEXT bool Itainted; /* using variables controlled by $< */
463ee0b2 1284IEXT bool Itainting; /* doing taint checks */
79072805
LW
1285
1286/* trace state */
1287IEXT I32 Idlevel;
1288IEXT I32 Idlmax IINIT(128);
1289IEXT char * Idebname;
1290IEXT char * Idebdelim;
1291
1292/* current interpreter roots */
463ee0b2
LW
1293IEXT OP * Imain_root;
1294IEXT OP * Imain_start;
1295IEXT OP * Ieval_root;
1296IEXT OP * Ieval_start;
79072805
LW
1297
1298/* runtime control stuff */
1299IEXT COP * VOL Icurcop IINIT(&compiling);
1300IEXT line_t Icopline IINIT(NOLINE);
1301IEXT CONTEXT * Icxstack;
1302IEXT I32 Icxstack_ix IINIT(-1);
1303IEXT I32 Icxstack_max IINIT(128);
1304IEXT jmp_buf Itop_env;
a0d0e21e 1305IEXT I32 Irunlevel;
79072805
LW
1306
1307/* stack stuff */
1308IEXT AV * Istack; /* THE STACK */
1309IEXT AV * Imainstack; /* the stack when nothing funny is happening */
1310IEXT SV ** Imystack_base; /* stack->array_ary */
1311IEXT SV ** Imystack_sp; /* stack pointer now */
1312IEXT SV ** Imystack_max; /* stack->array_ary + stack->array_max */
1313
1314/* format accumulators */
463ee0b2
LW
1315IEXT SV * Iformtarget;
1316IEXT SV * Ibodytarget;
1317IEXT SV * Itoptarget;
79072805
LW
1318
1319/* statics moved here for shared library purposes */
93a17b20 1320IEXT SV Istrchop; /* return value from chop */
79072805
LW
1321IEXT int Ifilemode; /* so nextargv() can preserve mode */
1322IEXT int Ilastfd; /* what to preserve mode on */
1323IEXT char * Ioldname; /* what to preserve mode on */
1324IEXT char ** IArgv; /* stuff to free from do_aexec, vfork safe */
1325IEXT char * ICmd; /* stuff to free from do_aexec, vfork safe */
1326IEXT OP * Isortcop; /* user defined sort routine */
1327IEXT HV * Isortstash; /* which is in some package or other */
1328IEXT GV * Ifirstgv; /* $a */
1329IEXT GV * Isecondgv; /* $b */
1330IEXT AV * Isortstack; /* temp stack during pp_sort() */
1331IEXT AV * Isignalstack; /* temp stack during sighandler() */
1332IEXT SV * Imystrk; /* temp key string for do_each() */
1333IEXT I32 Idumplvl; /* indentation level on syntax tree dump */
79072805
LW
1334IEXT PMOP * Ioldlastpm; /* for saving regexp context during debugger */
1335IEXT I32 Igensym; /* next symbol for getsym() to define */
1336IEXT bool Ipreambled;
1337IEXT int Ilaststatval IINIT(-1);
1338IEXT I32 Ilaststype IINIT(OP_STAT);
1339
1340#undef IEXT
1341#undef IINIT
1342
8990e307 1343#ifdef MULTIPLICITY
79072805
LW
1344};
1345#else
1346struct interpreter {
1347 char broiled;
1348};
1349#endif
1350
1351#include "pp.h"
1352
1353#ifdef __cplusplus
1354extern "C" {
1355#endif
1356
a0d0e21e
LW
1357#ifdef __cplusplus
1358# ifndef I_STDARG
1359# define I_STDARG 1
1360# endif
1361#endif
1362
1363#ifdef I_STDARG
2304df62
AD
1364# include <stdarg.h>
1365#else
1366# ifdef I_VARARGS
1367# include <varargs.h>
1368# endif
1369#endif
1370
79072805
LW
1371#include "proto.h"
1372
a0d0e21e
LW
1373#ifdef EMBED
1374#define Perl_sv_setptrobj(rv,ptr,name) Perl_sv_setref_iv(rv,name,(IV)ptr)
1375#define Perl_sv_setptrref(rv,ptr) Perl_sv_setref_iv(rv,Nullch,(IV)ptr)
1376#else
1377#define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,(IV)ptr)
1378#define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,(IV)ptr)
1379#endif
1380
79072805
LW
1381#ifdef __cplusplus
1382};
1383#endif
1384
93a17b20 1385/* The following must follow proto.h */
79072805
LW
1386
1387#ifdef DOINIT
463ee0b2
LW
1388MGVTBL vtbl_sv = {magic_get,
1389 magic_set,
1390 magic_len,
1391 0, 0};
1392MGVTBL vtbl_env = {0, 0, 0, 0, 0};
1393MGVTBL vtbl_envelem = {0, magic_setenv,
85e6fe83
LW
1394 0, magic_clearenv,
1395 0};
463ee0b2
LW
1396MGVTBL vtbl_sig = {0, 0, 0, 0, 0};
1397MGVTBL vtbl_sigelem = {0, magic_setsig,
1398 0, 0, 0};
a0d0e21e
LW
1399MGVTBL vtbl_pack = {0, 0, 0, magic_wipepack,
1400 0};
463ee0b2
LW
1401MGVTBL vtbl_packelem = {magic_getpack,
1402 magic_setpack,
1403 0, magic_clearpack,
1404 0};
1405MGVTBL vtbl_dbline = {0, magic_setdbline,
1406 0, 0, 0};
1407MGVTBL vtbl_isa = {0, magic_setisa,
1408 0, 0, 0};
1409MGVTBL vtbl_isaelem = {0, magic_setisa,
1410 0, 0, 0};
1411MGVTBL vtbl_arylen = {magic_getarylen,
1412 magic_setarylen,
1413 0, 0, 0};
1414MGVTBL vtbl_glob = {magic_getglob,
1415 magic_setglob,
1416 0, 0, 0};
1417MGVTBL vtbl_mglob = {0, magic_setmglob,
1418 0, 0, 0};
1419MGVTBL vtbl_taint = {magic_gettaint,magic_settaint,
1420 0, 0, 0};
1421MGVTBL vtbl_substr = {0, magic_setsubstr,
1422 0, 0, 0};
1423MGVTBL vtbl_vec = {0, magic_setvec,
1424 0, 0, 0};
a0d0e21e
LW
1425MGVTBL vtbl_pos = {magic_getpos,
1426 magic_setpos,
1427 0, 0, 0};
463ee0b2
LW
1428MGVTBL vtbl_bm = {0, magic_setbm,
1429 0, 0, 0};
1430MGVTBL vtbl_uvar = {magic_getuvar,
1431 magic_setuvar,
1432 0, 0, 0};
a0d0e21e
LW
1433
1434#ifdef OVERLOAD
1435MGVTBL vtbl_amagic = {0, magic_setamagic,
1436 0, 0, 0};
1437MGVTBL vtbl_amagicelem = {0, magic_setamagic,
1438 0, 0, 0};
1439#endif /* OVERLOAD */
1440
79072805
LW
1441#else
1442EXT MGVTBL vtbl_sv;
1443EXT MGVTBL vtbl_env;
1444EXT MGVTBL vtbl_envelem;
1445EXT MGVTBL vtbl_sig;
1446EXT MGVTBL vtbl_sigelem;
463ee0b2
LW
1447EXT MGVTBL vtbl_pack;
1448EXT MGVTBL vtbl_packelem;
79072805 1449EXT MGVTBL vtbl_dbline;
463ee0b2
LW
1450EXT MGVTBL vtbl_isa;
1451EXT MGVTBL vtbl_isaelem;
79072805
LW
1452EXT MGVTBL vtbl_arylen;
1453EXT MGVTBL vtbl_glob;
93a17b20 1454EXT MGVTBL vtbl_mglob;
463ee0b2 1455EXT MGVTBL vtbl_taint;
79072805
LW
1456EXT MGVTBL vtbl_substr;
1457EXT MGVTBL vtbl_vec;
a0d0e21e 1458EXT MGVTBL vtbl_pos;
79072805
LW
1459EXT MGVTBL vtbl_bm;
1460EXT MGVTBL vtbl_uvar;
a0d0e21e
LW
1461
1462#ifdef OVERLOAD
1463EXT MGVTBL vtbl_amagic;
1464EXT MGVTBL vtbl_amagicelem;
1465#endif /* OVERLOAD */
1466
79072805 1467#endif
85e6fe83 1468
a0d0e21e
LW
1469#ifdef OVERLOAD
1470EXT long amagic_generation;
1471
1472#define NofAMmeth 27
1473#ifdef DOINIT
1474EXT char * AMG_names[NofAMmeth][2] = {
1475 {"fallback","abs"},
1476 {"bool", "nomethod"},
1477 {"\"\"", "0+"},
1478 {"+","+="},
1479 {"-","-="},
1480 {"*", "*="},
1481 {"/", "/="},
1482 {"%", "%="},
1483 {"**", "**="},
1484 {"<<", "<<="},
1485 {">>", ">>="},
1486 {"<", "<="},
1487 {">", ">="},
1488 {"==", "!="},
1489 {"<=>", "cmp"},
1490 {"lt", "le"},
1491 {"gt", "ge"},
1492 {"eq", "ne"},
1493 {"&", "^"},
1494 {"|", "neg"},
1495 {"!", "~"},
1496 {"++", "--"},
1497 {"atan2", "cos"},
1498 {"sin", "exp"},
1499 {"log", "sqrt"},
1500 {"x","x="},
1501 {".",".="}
1502};
1503#else
1504EXT char * AMG_names[NofAMmeth][2];
1505#endif /* def INITAMAGIC */
1506
1507struct am_table {
1508 long was_ok_sub;
1509 long was_ok_am;
1510 CV* table[NofAMmeth*2];
1511 long fallback;
1512};
1513typedef struct am_table AMT;
1514
1515#define AMGfallNEVER 1
1516#define AMGfallNO 2
1517#define AMGfallYES 3
1518
1519enum {
1520 fallback_amg, abs_amg,
1521 bool__amg, nomethod_amg,
1522 string_amg, numer_amg,
1523 add_amg, add_ass_amg,
1524 subtr_amg, subtr_ass_amg,
1525 mult_amg, mult_ass_amg,
1526 div_amg, div_ass_amg,
1527 mod_amg, mod_ass_amg,
1528 pow_amg, pow_ass_amg,
1529 lshift_amg, lshift_ass_amg,
1530 rshift_amg, rshift_ass_amg,
1531 lt_amg, le_amg,
1532 gt_amg, ge_amg,
1533 eq_amg, ne_amg,
1534 ncmp_amg, scmp_amg,
1535 slt_amg, sle_amg,
1536 sgt_amg, sge_amg,
1537 seq_amg, sne_amg,
1538 band_amg, bxor_amg,
1539 bor_amg, neg_amg,
1540 not_amg, compl_amg,
1541 inc_amg, dec_amg,
1542 atan2_amg, cos_amg,
1543 sin_amg, exp_amg,
1544 log_amg, sqrt_amg,
1545 repeat_amg, repeat_ass_amg,
1546 concat_amg, concat_ass_amg
1547};
1548#endif /* OVERLOAD */
1549
85e6fe83 1550#endif /* Include guard */