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