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