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