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