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