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