[asperl] integrate latest win32 branch
[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
76e3520e 27#ifdef PERL_OBJECT
28class 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_
565764a8 46#define CPERLarg void
76e3520e 47#define CPERLarg_
48#define THIS
49#define THIS_
50#define CALLRUNOPS runops
51
52#endif /* PERL_OBJECT */
53
71be2cbc 54#define VOIDUSED 1
55#include "config.h"
56
57#include "embed.h"
58
326b05e3 59#undef START_EXTERN_C
60#undef END_EXTERN_C
61#undef EXTERN_C
32f822de 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
462e5cf6 72#ifdef OP_IN_REGISTER
73# ifdef __GNUC__
74# define stringify_immed(s) #s
75# define stringify(s) stringify_immed(s)
76register struct op *op asm(stringify(OP_IN_REGISTER));
77# endif
78#endif
79
728e2803 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))
169d69b2 88# if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__cplusplus)
728e2803 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
462e5cf6 103#define NOOP (void)0
104
61bb5906 105#define WITH_THR(s) STMT_START { dTHR; s; } STMT_END
ea0efc06 106
55497cff 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
79072805 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 */
ac58e20f 133
ee0007ab 134/* define this once if either system, instead of cluttering up the src */
68dc0745 135#if defined(MSDOS) || defined(atarist) || defined(WIN32)
ee0007ab 136#define DOSISH 1
137#endif
138
a0d0e21e 139#if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
352d5a3a 140# define STANDARD_C 1
141#endif
142
16de4a3e 143#if defined(__cplusplus) || defined(WIN32) || defined(__sgi) || defined(OS2) \
144 || defined(__DGUX)
68dc0745 145# define DONT_DECLARE_STD 1
146#endif
147
ee0964f1 148#if defined(NeXT) && !defined(_POSIX_SOURCE)
149# define MISSING_PID_T
150#endif
151
352d5a3a 152#if defined(HASVOLATILE) || defined(STANDARD_C)
79072805 153# ifdef __cplusplus
154# define VOL // to temporarily suppress warnings
155# else
156# define VOL volatile
157# endif
663a0e37 158#else
79072805 159# define VOL
663a0e37 160#endif
161
bbce6d69 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); }
a687059c 167
ee0964f1 168#ifdef MISSING_PID_T
169typedef int pid_t;
170#endif
171
a6e633de 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))
c07a80fd 181#else
a6e633de 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
663a0e37 220#endif
221
760ac839 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>
c07a80fd 225# endif
663a0e37 226#endif
227
760ac839 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"
76e3520e 243#include "perlmem.h"
6ad3d225 244#include "perllio.h"
245#include "perlsock.h"
246#include "perlproc.h"
247#include "perlenv.h"
248#include "perldir.h"
0c30d9ec 249
4633a7c4 250#ifdef USE_NEXT_CTYPE
0c30d9ec 251
252#if NX_CURRENT_COMPILER_RELEASE >= 400
253#include <objc/NXCType.h>
254#else /* NX_CURRENT_COMPILER_RELEASE < 400 */
a0d0e21e 255#include <appkit/NXCType.h>
0c30d9ec 256#endif /* NX_CURRENT_COMPILER_RELEASE >= 400 */
257
258#else /* !USE_NEXT_CTYPE */
fe14fcc3 259#include <ctype.h>
0c30d9ec 260#endif /* USE_NEXT_CTYPE */
a0d0e21e 261
262#ifdef METHOD /* Defined by OSF/1 v3.0 by ctype.h */
263#undef METHOD
a0d0e21e 264#endif
265
4633a7c4 266#ifdef I_LOCALE
36477c24 267# include <locale.h>
4633a7c4 268#endif
269
36477c24 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 */
a0d0e21e 283
fe14fcc3 284#include <setjmp.h>
79072805 285
a0d0e21e 286#ifdef I_SYS_PARAM
79072805 287# ifdef PARAM_NEEDS_TYPES
288# include <sys/types.h>
289# endif
290# include <sys/param.h>
352d5a3a 291#endif
79072805 292
293
294/* Use all the "standard" definitions? */
a0d0e21e 295#if defined(STANDARD_C) && defined(I_STDLIB)
79072805 296# include <stdlib.h>
ff68c719 297#endif
03a14243 298
c31fac66 299#define MEM_SIZE Size_t
300
55497cff 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. */
03a14243 303
4633a7c4 304#ifdef MYMALLOC
55497cff 305
4633a7c4 306# ifdef HIDEMYMALLOC
55497cff 307# define malloc Mymalloc
308# define calloc Mycalloc
4633a7c4 309# define realloc Myremalloc
55497cff 310# define free Myfree
c31fac66 311Malloc_t Mymalloc _((MEM_SIZE nbytes));
312Malloc_t Mycalloc _((MEM_SIZE elements, MEM_SIZE size));
313Malloc_t Myrealloc _((Malloc_t where, MEM_SIZE nbytes));
314Free_t Myfree _((Malloc_t where));
55497cff 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
c31fac66 321Malloc_t Perl_malloc _((MEM_SIZE nbytes));
322Malloc_t Perl_calloc _((MEM_SIZE elements, MEM_SIZE size));
323Malloc_t Perl_realloc _((Malloc_t where, MEM_SIZE nbytes));
324Free_t Perl_free _((Malloc_t where));
4633a7c4 325# endif
55497cff 326
327# undef safemalloc
328# undef safecalloc
329# undef saferealloc
330# undef safefree
331# define safemalloc malloc
332# define safecalloc calloc
4633a7c4 333# define saferealloc realloc
55497cff 334# define safefree free
335
336#endif /* MYMALLOC */
4633a7c4 337
ff68c719 338#if defined(STANDARD_C) && defined(I_STDDEF)
339# include <stddef.h>
71be2cbc 340# define STRUCT_OFFSET(s,m) offsetof(s,m)
ff68c719 341#else
71be2cbc 342# define STRUCT_OFFSET(s,m) (Size_t)(&(((s *)0)->m))
ff68c719 343#endif
344
a0d0e21e 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
16d20bd9 356#ifdef I_MEMORY
357# include <memory.h>
358#endif
359
fe14fcc3 360#ifdef HAS_MEMCPY
85e6fe83 361# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
fe14fcc3 362# ifndef memcpy
a0d0e21e 363 extern char * memcpy _((char*, char*, int));
ee0007ab 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 */
fe14fcc3 375
ee0007ab 376#ifdef HAS_MEMSET
85e6fe83 377# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
ee0007ab 378# ifndef memset
a0d0e21e 379 extern char *memset _((char*, int, int));
ee0007ab 380# endif
381# endif
ee0007ab 382#else
fc36a67e 383# define memset(d,c,l) my_memset(d,c,l)
ee0007ab 384#endif /* HAS_MEMSET */
385
85e6fe83 386#if !defined(HAS_MEMMOVE) && !defined(memmove)
2304df62 387# if defined(HAS_BCOPY) && defined(HAS_SAFE_BCOPY)
79072805 388# define memmove(d,s,l) bcopy(s,d,l)
389# else
2304df62 390# if defined(HAS_MEMCPY) && defined(HAS_SAFE_MEMCPY)
79072805 391# define memmove(d,s,l) memcpy(d,s,l)
ee0007ab 392# else
79072805 393# define memmove(d,s,l) my_bcopy(s,d,l)
ee0007ab 394# endif
352d5a3a 395# endif
d9d8d8de 396#endif
ee0007ab 397
36477c24 398#if defined(mips) && defined(ultrix) && !defined(__STDC__)
399# undef HAS_MEMCMP
400#endif
401
402#if defined(HAS_MEMCMP) && defined(HAS_SANE_MEMCMP)
85e6fe83 403# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
ee0007ab 404# ifndef memcmp
a0d0e21e 405 extern int memcmp _((char*, char*, int));
ee0007ab 406# endif
407# endif
36477c24 408# ifdef BUGGY_MSC
409 # pragma function(memcmp)
410# endif
ee0007ab 411#else
412# ifndef memcmp
ecfc5424 413# define memcmp my_memcmp
352d5a3a 414# endif
36477c24 415#endif /* HAS_MEMCMP && HAS_SANE_MEMCMP */
8d063cd8 416
fc36a67e 417#ifndef memzero
c635e13b 418# ifdef HAS_MEMSET
419# define memzero(d,l) memset(d,0,l)
79072805 420# else
c635e13b 421# ifdef HAS_BZERO
422# define memzero(d,l) bzero(d,l)
79072805 423# else
fc36a67e 424# define memzero(d,l) my_bzero(d,l)
79072805 425# endif
426# endif
d9d8d8de 427#endif
378cc40b 428
36477c24 429#ifndef HAS_BCMP
430# ifndef bcmp
431# define bcmp(s1,s2,l) memcmp(s1,s2,l)
79072805 432# endif
36477c24 433#endif /* !HAS_BCMP */
378cc40b 434
ae986130 435#ifdef I_NETINET_IN
79072805 436# include <netinet/in.h>
ae986130 437#endif
438
84902520 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
1aef975c 445#ifdef I_SYS_STAT
84902520 446# include <sys/stat.h>
1aef975c 447#endif
79072805 448
a0d0e21e 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))
79072805 459# undef S_ISDIR
460# undef S_ISCHR
461# undef S_ISBLK
462# undef S_ISREG
463# undef S_ISFIFO
464# undef S_ISLNK
ee0007ab 465#endif
135863df 466
663a0e37 467#ifdef I_TIME
468# include <time.h>
ffed7fef 469#endif
663a0e37 470
fe14fcc3 471#ifdef I_SYS_TIME
85e6fe83 472# ifdef I_SYS_TIME_KERNEL
663a0e37 473# define KERNEL
474# endif
475# include <sys/time.h>
85e6fe83 476# ifdef I_SYS_TIME_KERNEL
663a0e37 477# undef KERNEL
478# endif
a687059c 479#endif
135863df 480
55497cff 481#if defined(HAS_TIMES) && defined(I_SYS_TIMES)
85e6fe83 482# include <sys/times.h>
d9d8d8de 483#endif
8d063cd8 484
fe14fcc3 485#if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
79072805 486# undef HAS_STRERROR
663a0e37 487#endif
488
a0d0e21e 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
663a0e37 495#include <errno.h>
ed6116ce 496#ifdef HAS_SOCKET
85e6fe83 497# ifdef I_NET_ERRNO
ed6116ce 498# include <net/errno.h>
499# endif
500#endif
f86702cc 501
502#ifdef VMS
503# define SETERRNO(errcode,vmserrcode) \
504 STMT_START { \
505 set_errno(errcode); \
506 set_vaxc_errno(vmserrcode); \
507 } STMT_END
748a9306 508#else
f86702cc 509# define SETERRNO(errcode,vmserrcode) errno = (errcode)
748a9306 510#endif
ed6116ce 511
38a03e6e 512#ifdef USE_THREADS
513# define ERRSV (thr->errsv)
514# define ERRHV (thr->errhv)
940cb80d 515# define DEFSV THREADSV(0)
516# define SAVE_DEFSV save_threadsv(0)
38a03e6e 517#else
518# define ERRSV GvSV(errgv)
519# define ERRHV GvHV(errgv)
54b9620d 520# define DEFSV GvSV(defgv)
521# define SAVE_DEFSV SAVESPTR(GvSV(defgv))
38a03e6e 522#endif /* USE_THREADS */
523
55497cff 524#ifndef errno
79072805 525 extern int errno; /* ANSI allows errno to be an lvalue expr */
d9d8d8de 526#endif
663a0e37 527
2304df62 528#ifdef HAS_STRERROR
a0d0e21e 529# ifdef VMS
530 char *strerror _((int,...));
531# else
68dc0745 532#ifndef DONT_DECLARE_STD
a0d0e21e 533 char *strerror _((int));
68dc0745 534#endif
a0d0e21e 535# endif
2304df62 536# ifndef Strerror
537# define Strerror strerror
538# endif
539#else
540# ifdef HAS_SYS_ERRLIST
79072805 541 extern int sys_nerr;
542 extern char *sys_errlist[];
2304df62 543# ifndef Strerror
544# define Strerror(e) \
79072805 545 ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
2304df62 546# endif
79072805 547# endif
35c8bce7 548#endif
663a0e37 549
2304df62 550#ifdef I_SYS_IOCTL
79072805 551# ifndef _IOCTL_
552# include <sys/ioctl.h>
553# endif
a687059c 554#endif
555
ee0007ab 556#if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
79072805 557# ifdef HAS_SOCKETPAIR
558# undef HAS_SOCKETPAIR
559# endif
2304df62 560# ifdef I_NDBM
561# undef I_NDBM
79072805 562# endif
a687059c 563#endif
564
a687059c 565#if INTSIZE == 2
79072805 566# define htoni htons
567# define ntohi ntohs
a687059c 568#else
79072805 569# define htoni htonl
570# define ntohi ntohl
a687059c 571#endif
572
a0d0e21e 573/* Configure already sets Direntry_t */
35c8bce7 574#if defined(I_DIRENT)
663a0e37 575# include <dirent.h>
a0d0e21e 576# if defined(NeXT) && defined(I_SYS_DIR) /* NeXT needs dirent + sys/dir.h */
577# include <sys/dir.h>
578# endif
ae986130 579#else
fe14fcc3 580# ifdef I_SYS_NDIR
79a0689e 581# include <sys/ndir.h>
663a0e37 582# else
fe14fcc3 583# ifdef I_SYS_DIR
79a0689e 584# ifdef hp9000s500
585# include <ndir.h> /* may be wrong in the future */
586# else
587# include <sys/dir.h>
588# endif
663a0e37 589# endif
590# endif
4633a7c4 591#endif
a687059c 592
352d5a3a 593#ifdef FPUTS_BOTCH
594/* work around botch in SunOS 4.0.1 and 4.0.2 */
595# ifndef fputs
79072805 596# define fputs(sv,fp) fprintf(fp,"%s",sv)
352d5a3a 597# endif
598#endif
599
c623bd54 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
fe14fcc3 623# ifdef S_IFBLK
624# define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
625# else
626# define S_ISBLK(m) (0)
627# endif
c623bd54 628#endif
629
630#ifndef S_ISREG
631# define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
632#endif
633
634#ifndef S_ISFIFO
fe14fcc3 635# ifdef S_IFIFO
636# define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
637# else
638# define S_ISFIFO(m) (0)
639# endif
c623bd54 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
79072805 700#ifdef ff_next
701# undef ff_next
352d5a3a 702#endif
703
a0d0e21e 704#if defined(cray) || defined(gould) || defined(i860) || defined(pyr)
45d8adaa 705# define SLOPPYDIVIDE
706#endif
707
748a9306 708#ifdef UV
709#undef UV
710#endif
711
27d4fb96 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
f86702cc 725#ifdef cray
726# define Quad_t int
727#else
728# ifdef convex
729# define Quad_t long long
45d8adaa 730# else
ff0cee69 731# if BYTEORDER > 0xFFFF
ecfc5424 732# define Quad_t long
45d8adaa 733# endif
734# endif
f86702cc 735#endif
736
737#ifdef Quad_t
738# define HAS_QUAD
748a9306 739 typedef Quad_t IV;
740 typedef unsigned Quad_t UV;
27d4fb96 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
79072805 745#else
748a9306 746 typedef long IV;
747 typedef unsigned long UV;
27d4fb96 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
79072805 752#endif
753
760ac839 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
99abf803 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 */
27d4fb96 793
99abf803 794#define PERL_UCHAR_MIN ((unsigned char)0)
795
796#ifdef UCHAR_MAX
797# define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX)
27d4fb96 798#else
99abf803 799# ifdef MAXUCHAR
800# define PERL_UCHAR_MAX ((unsigned char)MAXUCHAR)
27d4fb96 801# else
99abf803 802# define PERL_UCHAR_MAX ((unsigned char)~(unsigned)0)
27d4fb96 803# endif
804#endif
99abf803 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 */
27d4fb96 814
99abf803 815#define PERL_USHORT_MIN ((unsigned short)0)
816
817#ifdef USHORT_MAX
818# define PERL_USHORT_MAX ((unsigned short)USHORT_MAX)
27d4fb96 819#else
99abf803 820# ifdef MAXUSHORT
821# define PERL_USHORT_MAX ((unsigned short)MAXUSHORT)
27d4fb96 822# else
99abf803 823# define PERL_USHORT_MAX ((unsigned short)~(unsigned)0)
27d4fb96 824# endif
825#endif
826
27d4fb96 827#ifdef SHORT_MAX
99abf803 828# define PERL_SHORT_MAX ((short)SHORT_MAX)
27d4fb96 829#else
830# ifdef MAXSHORT /* Often used in <values.h> */
99abf803 831# define PERL_SHORT_MAX ((short)MAXSHORT)
27d4fb96 832# else
99abf803 833# define PERL_SHORT_MAX ((short) (PERL_USHORT_MAX >> 1))
27d4fb96 834# endif
835#endif
836
837#ifdef SHORT_MIN
99abf803 838# define PERL_SHORT_MIN ((short)SHORT_MIN)
27d4fb96 839#else
840# ifdef MINSHORT
99abf803 841# define PERL_SHORT_MIN ((short)MINSHORT)
27d4fb96 842# else
843# define PERL_SHORT_MIN (-PERL_SHORT_MAX - ((3 & -1) == 3))
844# endif
845#endif
846
99abf803 847#ifdef UINT_MAX
848# define PERL_UINT_MAX ((unsigned int)UINT_MAX)
27d4fb96 849#else
99abf803 850# ifdef MAXUINT
851# define PERL_UINT_MAX ((unsigned int)MAXUINT)
27d4fb96 852# else
99abf803 853# define PERL_UINT_MAX (~(unsigned int)0)
27d4fb96 854# endif
855#endif
856
99abf803 857#define PERL_UINT_MIN ((unsigned int)0)
27d4fb96 858
859#ifdef INT_MAX
99abf803 860# define PERL_INT_MAX ((int)INT_MAX)
27d4fb96 861#else
862# ifdef MAXINT /* Often used in <values.h> */
99abf803 863# define PERL_INT_MAX ((int)MAXINT)
27d4fb96 864# else
99abf803 865# define PERL_INT_MAX ((int)(PERL_UINT_MAX >> 1))
27d4fb96 866# endif
867#endif
868
869#ifdef INT_MIN
99abf803 870# define PERL_INT_MIN ((int)INT_MIN)
27d4fb96 871#else
872# ifdef MININT
99abf803 873# define PERL_INT_MIN ((int)MININT)
27d4fb96 874# else
875# define PERL_INT_MIN (-PERL_INT_MAX - ((3 & -1) == 3))
876# endif
877#endif
878
99abf803 879#ifdef ULONG_MAX
880# define PERL_ULONG_MAX ((unsigned long)ULONG_MAX)
27d4fb96 881#else
99abf803 882# ifdef MAXULONG
883# define PERL_ULONG_MAX ((unsigned long)MAXULONG)
27d4fb96 884# else
99abf803 885# define PERL_ULONG_MAX (~(unsigned long)0)
27d4fb96 886# endif
887#endif
888
99abf803 889#define PERL_ULONG_MIN ((unsigned long)0L)
27d4fb96 890
760ac839 891#ifdef LONG_MAX
99abf803 892# define PERL_LONG_MAX ((long)LONG_MAX)
760ac839 893#else
894# ifdef MAXLONG /* Often used in <values.h> */
99abf803 895# define PERL_LONG_MAX ((long)MAXLONG)
760ac839 896# else
99abf803 897# define PERL_LONG_MAX ((long) (PERL_ULONG_MAX >> 1))
760ac839 898# endif
899#endif
900
901#ifdef LONG_MIN
99abf803 902# define PERL_LONG_MIN ((long)LONG_MIN)
760ac839 903#else
904# ifdef MINLONG
99abf803 905# define PERL_LONG_MIN ((long)MINLONG)
760ac839 906# else
27d4fb96 907# define PERL_LONG_MIN (-PERL_LONG_MAX - ((3 & -1) == 3))
760ac839 908# endif
909#endif
910
99abf803 911#ifdef HAS_QUAD
912
913# ifdef UQUAD_MAX
914# define PERL_UQUAD_MAX ((UV)UQUAD_MAX)
760ac839 915# else
99abf803 916# define PERL_UQUAD_MAX (~(UV)0)
760ac839 917# endif
760ac839 918
99abf803 919# define PERL_UQUAD_MIN ((UV)0)
27d4fb96 920
27d4fb96 921# ifdef QUAD_MAX
99abf803 922# define PERL_QUAD_MAX ((IV)QUAD_MAX)
27d4fb96 923# else
99abf803 924# define PERL_QUAD_MAX ((IV) (PERL_UQUAD_MAX >> 1))
27d4fb96 925# endif
926
927# ifdef QUAD_MIN
99abf803 928# define PERL_QUAD_MIN ((IV)QUAD_MIN)
27d4fb96 929# else
a6e633de 930# define PERL_QUAD_MIN (-PERL_QUAD_MAX - ((3 & -1) == 3))
27d4fb96 931# endif
932
79072805 933#endif
934
ee0007ab 935typedef MEM_SIZE STRLEN;
450a55e4 936
79072805 937typedef struct op OP;
938typedef struct cop COP;
939typedef struct unop UNOP;
940typedef struct binop BINOP;
941typedef struct listop LISTOP;
942typedef struct logop LOGOP;
943typedef struct condop CONDOP;
944typedef struct pmop PMOP;
945typedef struct svop SVOP;
946typedef struct gvop GVOP;
947typedef struct pvop PVOP;
79072805 948typedef struct loop LOOP;
949
950typedef struct Outrec Outrec;
93a17b20 951typedef struct interpreter PerlInterpreter;
3e3baf6d 952#ifndef __BORLANDC__
953typedef struct ff FF; /* XXX not defined anywhere, should go? */
954#endif
79072805 955typedef struct sv SV;
956typedef struct av AV;
957typedef struct hv HV;
958typedef struct cv CV;
378cc40b 959typedef struct regexp REGEXP;
79072805 960typedef struct gp GP;
0c30d9ec 961typedef struct gv GV;
8990e307 962typedef struct io IO;
c09156bb 963typedef struct context PERL_CONTEXT;
79072805 964typedef struct block BLOCK;
965
966typedef struct magic MAGIC;
ed6116ce 967typedef struct xrv XRV;
79072805 968typedef struct xpv XPV;
969typedef struct xpviv XPVIV;
ff68c719 970typedef struct xpvuv XPVUV;
79072805 971typedef struct xpvnv XPVNV;
972typedef struct xpvmg XPVMG;
973typedef struct xpvlv XPVLV;
974typedef struct xpvav XPVAV;
975typedef struct xpvhv XPVHV;
976typedef struct xpvgv XPVGV;
977typedef struct xpvcv XPVCV;
978typedef struct xpvbm XPVBM;
979typedef struct xpvfm XPVFM;
8990e307 980typedef struct xpvio XPVIO;
79072805 981typedef struct mgvtbl MGVTBL;
982typedef union any ANY;
8d063cd8 983
378cc40b 984#include "handy.h"
a0d0e21e 985
16d20bd9 986typedef 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])
93965878 989#define FILTER_ISREADER(idx) (idx >= AvFILLp(rsfp_filters))
16d20bd9 990
748a9306 991#ifdef DOSISH
4633a7c4 992# if defined(OS2)
993# include "os2ish.h"
994# else
748a9306 995# include "dosish.h"
4633a7c4 996# endif
a0d0e21e 997#else
748a9306 998# if defined(VMS)
999# include "vmsish.h"
1000# else
0c30d9ec 1001# if defined(PLAN9)
1002# include "./plan9/plan9ish.h"
1003# else
1004# include "unixish.h"
1005# endif
748a9306 1006# endif
32f822de 1007#endif
1008
1009/*
dd96f567 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>
32f822de 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
dd96f567 1023# ifdef OS2
1024# include "os2thread.h"
1025# else
1026# include <pthread.h>
c6ee37c5 1027typedef pthread_t perl_os_thread;
32f822de 1028typedef pthread_mutex_t perl_mutex;
1029typedef pthread_cond_t perl_cond;
1030typedef pthread_key_t perl_key;
dd96f567 1031# endif /* OS2 */
32f822de 1032# endif /* WIN32 */
1033# endif /* FAKE_THREADS */
1034#endif /* USE_THREADS */
1035
1036
3fc1aec6 1037
68dc0745 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
3fc1aec6 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)
748a9306 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
a0d0e21e 1105#endif
1106
79072805 1107union any {
1108 void* any_ptr;
1109 I32 any_i32;
a0d0e21e 1110 IV any_iv;
85e6fe83 1111 long any_long;
565764a8 1112 void (CPERLscope(*any_dptr)) _((void*));
79072805 1113};
1114
11343788 1115#ifdef USE_THREADS
52e1cb5e 1116#define ARGSproto struct perl_thread *thr
11343788 1117#else
1118#define ARGSproto void
1119#endif /* USE_THREADS */
1120
5aabfad6 1121/* Work around some cygwin32 problems with importing global symbols */
1122#if defined(CYGWIN32) && defined(DLLIMPORT)
1123# include "cw32imp.h"
1124#endif
1125
378cc40b 1126#include "regexp.h"
79072805 1127#include "sv.h"
378cc40b 1128#include "util.h"
8d063cd8 1129#include "form.h"
79072805 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"
8d063cd8 1139
7fae4e64 1140/* Current curly descriptor */
1141typedef struct curcur CURCUR;
1142struct 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
1154typedef struct _sublex_info SUBLEXINFO;
1155struct _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
76e3520e 1161#ifdef PERL_OBJECT
1162struct magic_state {
1163 SV* mgs_sv;
1164 U32 mgs_flags;
1165};
1166typedef struct magic_state MGS;
1167
1168typedef 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
1186typedef I32 CHECKPOINT;
1187#endif /* PERL_OBJECT */
1188
4633a7c4 1189/* work around some libPW problems */
1190#ifdef DOINIT
1191EXT char Error[1];
1192#endif
1193
450a55e4 1194#if defined(iAPX286) || defined(M_I286) || defined(I80286)
a687059c 1195# define I286
1196#endif
1197
fe14fcc3 1198#if defined(htonl) && !defined(HAS_HTONL)
1199#define HAS_HTONL
ae986130 1200#endif
fe14fcc3 1201#if defined(htons) && !defined(HAS_HTONS)
1202#define HAS_HTONS
ae986130 1203#endif
fe14fcc3 1204#if defined(ntohl) && !defined(HAS_NTOHL)
1205#define HAS_NTOHL
ae986130 1206#endif
fe14fcc3 1207#if defined(ntohs) && !defined(HAS_NTOHS)
1208#define HAS_NTOHS
ae986130 1209#endif
fe14fcc3 1210#ifndef HAS_HTONL
d9d8d8de 1211#if (BYTEORDER & 0xffff) != 0x4321
fe14fcc3 1212#define HAS_HTONS
1213#define HAS_HTONL
1214#define HAS_NTOHS
1215#define HAS_NTOHL
a687059c 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
d9d8d8de 1223#if (BYTEORDER & 0xffff) == 0x4321
fe14fcc3 1224#undef HAS_HTONS
1225#undef HAS_HTONL
1226#undef HAS_NTOHS
1227#undef HAS_NTOHL
a687059c 1228#endif
1229#endif
1230
988174c1 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
0f85fab0 1252#ifdef CASTNEGFLOAT
79072805 1253#define U_S(what) ((U16)(what))
0f85fab0 1254#define U_I(what) ((unsigned int)(what))
79072805 1255#define U_L(what) ((U32)(what))
0f85fab0 1256#else
32f822de 1257EXTERN_C U32 cast_ulong _((double));
232e078e 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)))
ee0007ab 1261#endif
1262
ed6116ce 1263#ifdef CASTI32
1264#define I_32(what) ((I32)(what))
a0d0e21e 1265#define I_V(what) ((IV)(what))
5d94fbed 1266#define U_V(what) ((UV)(what))
ed6116ce 1267#else
32f822de 1268START_EXTERN_C
a0d0e21e 1269I32 cast_i32 _((double));
a0d0e21e 1270IV cast_iv _((double));
5d94fbed 1271UV cast_uv _((double));
32f822de 1272END_EXTERN_C
a6e633de 1273#define I_32(what) (cast_i32((double)(what)))
1274#define I_V(what) (cast_iv((double)(what)))
5d94fbed 1275#define U_V(what) (cast_uv((double)(what)))
ed6116ce 1276#endif
1277
79072805 1278struct Outrec {
1279 I32 o_lines;
d9d8d8de 1280 char *o_str;
79072805 1281 U32 o_len;
8d063cd8 1282};
1283
352d5a3a 1284#ifndef MAXSYSFD
1285# define MAXSYSFD 2
1286#endif
ee0007ab 1287
f82b3d41 1288#ifndef TMPPATH
1289# define TMPPATH "/tmp/perl-eXXXXXX"
a0d0e21e 1290#endif
79072805 1291
1292#ifndef __cplusplus
a0d0e21e 1293Uid_t getuid _((void));
1294Uid_t geteuid _((void));
1295Gid_t getgid _((void));
1296Gid_t getegid _((void));
79072805 1297#endif
8d063cd8 1298
1299#ifdef DEBUGGING
0c30d9ec 1300#ifndef Perl_debug_log
760ac839 1301#define Perl_debug_log PerlIO_stderr()
0c30d9ec 1302#endif
d96024cf 1303#define YYDEBUG 1
79072805 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
0c30d9ec 1313#define DEBUG_m(a) if (curinterp && debug & 128) a
79072805 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
8990e307 1321#define DEBUG_D(a) if (debug & 32768) a
79072805 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)
8990e307 1340#define DEBUG_D(a)
8d063cd8 1341#endif
fe14fcc3 1342#define YYMAXDEPTH 300
8d063cd8 1343
a6e633de 1344#ifndef assert /* <assert.h> might have been included somehow */
79072805 1345#define assert(what) DEB( { \
1346 if (!(what)) { \
463ee0b2 1347 croak("Assertion failed: file \"%s\", line %d", \
79072805 1348 __FILE__, __LINE__); \
6ad3d225 1349 PerlProc_exit(1); \
79072805 1350 }})
a6e633de 1351#endif
8d063cd8 1352
450a55e4 1353struct ufuncs {
a0d0e21e 1354 I32 (*uf_val)_((IV, SV*));
1355 I32 (*uf_set)_((IV, SV*));
1356 IV uf_index;
450a55e4 1357};
1358
fe14fcc3 1359/* Fix these up for __STDC__ */
68dc0745 1360#ifndef DONT_DECLARE_STD
a0d0e21e 1361char *mktemp _((char*));
1362double atof _((const char*));
1363#endif
79072805 1364
352d5a3a 1365#ifndef STANDARD_C
fe14fcc3 1366/* All of these are in stdlib.h or time.h for ANSI C */
85e6fe83 1367Time_t time();
8d063cd8 1368struct tm *gmtime(), *localtime();
93a17b20 1369char *strchr(), *strrchr();
378cc40b 1370char *strcpy(), *strcat();
352d5a3a 1371#endif /* ! STANDARD_C */
8d063cd8 1372
79072805 1373
1374#ifdef I_MATH
1375# include <math.h>
1376#else
32f822de 1377START_EXTERN_C
a0d0e21e 1378 double exp _((double));
a0d0e21e 1379 double log _((double));
c635e13b 1380 double log10 _((double));
a0d0e21e 1381 double sqrt _((double));
c635e13b 1382 double frexp _((double,int*));
1383 double ldexp _((double,int));
a0d0e21e 1384 double modf _((double,double*));
1385 double sin _((double));
1386 double cos _((double));
1387 double atan2 _((double,double));
1388 double pow _((double,double));
32f822de 1389END_EXTERN_C
79072805 1390#endif
1391
a0d0e21e 1392#ifndef __cplusplus
26618a56 1393# ifdef __NeXT__ /* or whatever catches all NeXTs */
3fc1aec6 1394char *crypt (); /* Maybe more hosts will need the unprototyped version */
26618a56 1395# else
1396# if !defined(WIN32) || !defined(HAVE_DES_FCRYPT)
a0d0e21e 1397char *crypt _((const char*, const char*));
26618a56 1398# endif /* !WIN32 && !HAVE_CRYPT_SOURCE */
1399# endif /* !__NeXT__ */
1400# ifndef DONT_DECLARE_STD
1401# ifndef getenv
a0d0e21e 1402char *getenv _((const char*));
26618a56 1403# endif /* !getenv */
a0d0e21e 1404Off_t lseek _((int,Off_t,int));
26618a56 1405# endif /* !DONT_DECLARE_STD */
a0d0e21e 1406char *getlogin _((void));
26618a56 1407#endif /* !__cplusplus */
79072805 1408
16d20bd9 1409#ifdef UNLINK_ALL_VERSIONS /* Currently only makes sense for VMS */
378cc40b 1410#define UNLINK unlnk
a0d0e21e 1411I32 unlnk _((char*));
8d063cd8 1412#else
1413#define UNLINK unlink
1414#endif
a687059c 1415
fe14fcc3 1416#ifndef HAS_SETREUID
85e6fe83 1417# ifdef HAS_SETRESUID
1418# define setreuid(r,e) setresuid(r,e,(Uid_t)-1)
1419# define HAS_SETREUID
1420# endif
a687059c 1421#endif
fe14fcc3 1422#ifndef HAS_SETREGID
85e6fe83 1423# ifdef HAS_SETRESGID
1424# define setregid(r,e) setresgid(r,e,(Gid_t)-1)
1425# define HAS_SETREGID
1426# endif
a687059c 1427#endif
ee0007ab 1428
ff68c719 1429typedef Signal_t (*Sighandler_t) _((int));
1430
1431#ifdef HAS_SIGACTION
1432typedef struct sigaction Sigsave_t;
1433#else
1434typedef Sighandler_t Sigsave_t;
1435#endif
1436
ee0007ab 1437#define SCAN_DEF 0
1438#define SCAN_TR 1
1439#define SCAN_REPL 2
79072805 1440
1441#ifdef DEBUGGING
4633a7c4 1442# ifndef register
a0d0e21e 1443# define register
1444# endif
1445# define PAD_SV(po) pad_sv(po)
2ddcc7aa 1446# define RUNOPS_DEFAULT runops_debug
79072805 1447#else
a0d0e21e 1448# define PAD_SV(po) curpad[po]
2ddcc7aa 1449# define RUNOPS_DEFAULT runops_standard
79072805 1450#endif
1451
18f739ee 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
b6d9d515 1460
44a0ac01 1461/*
1462 * These need prototyping here because <proto.h> isn't
1463 * included until after runops is initialised.
1464 */
1465
76e3520e 1466#ifndef PERL_OBJECT
49f531da 1467typedef int runops_proc_t _((void));
44a0ac01 1468int runops_standard _((void));
1469#ifdef DEBUGGING
1470int runops_debug _((void));
1471#endif
76e3520e 1472#endif /* PERL_OBJECT */
44a0ac01 1473
940cb80d 1474/* _ (for $_) must be first in the following list (DEFSV requires it) */
54b9620d 1475#define THREADSV_NAMES "_123456789&`'+/.,\\\";^-%=|~:\001\005!@"
a863c7d1 1476
0c30d9ec 1477/* VMS doesn't use environ array and NeXT has problems with crt0.o globals */
1478#if !defined(VMS) && !(defined(NeXT) && defined(__DYNAMIC__))
16de4a3e 1479#if !defined(DONT_DECLARE_STD) \
1480 || (defined(__svr4__) && defined(__GNUC__) && defined(sun)) \
1481 || defined(__sgi) || defined(__DGUX)
79072805 1482extern char ** environ; /* environment variables supplied via exec */
a0d0e21e 1483#endif
0c30d9ec 1484#else
1485# if defined(NeXT) && defined(__DYNAMIC__)
1486
1487# include <mach-o/dyld.h>
1488EXT char *** environ_pointer;
1489# define environ (*environ_pointer)
1490# endif
1491#endif /* environ processing */
1492
79072805 1493
1494/* for tmp use in stupid debuggers */
1495EXT int * di;
1496EXT short * ds;
1497EXT char * dc;
1498
1499/* handy constants */
3e3baf6d 1500EXTCONST char warn_uninit[]
a0d0e21e 1501 INIT("Use of uninitialized value");
3e3baf6d 1502EXTCONST char warn_nosemi[]
463ee0b2 1503 INIT("Semicolon seems to be missing");
3e3baf6d 1504EXTCONST char warn_reserved[]
463ee0b2 1505 INIT("Unquoted string \"%s\" may clash with future reserved word");
3e3baf6d 1506EXTCONST char warn_nl[]
93a17b20 1507 INIT("Unsuccessful %s on filename containing newline");
3e3baf6d 1508EXTCONST char no_wrongref[]
a0d0e21e 1509 INIT("Can't use %s ref as %s ref");
3e3baf6d 1510EXTCONST char no_symref[]
748a9306 1511 INIT("Can't use string (\"%.32s\") as %s ref while \"strict refs\" in use");
3e3baf6d 1512EXTCONST char no_usym[]
8990e307 1513 INIT("Can't use an undefined value as %s reference");
3e3baf6d 1514EXTCONST char no_aelem[]
93a17b20 1515 INIT("Modification of non-creatable array value attempted, subscript %d");
3e3baf6d 1516EXTCONST char no_helem[]
93a17b20 1517 INIT("Modification of non-creatable hash value attempted, subscript \"%s\"");
3e3baf6d 1518EXTCONST char no_modify[]
93a17b20 1519 INIT("Modification of a read-only value attempted");
3e3baf6d 1520EXTCONST char no_mem[]
93a17b20 1521 INIT("Out of memory!\n");
3e3baf6d 1522EXTCONST char no_security[]
463ee0b2 1523 INIT("Insecure dependency in %s%s");
3e3baf6d 1524EXTCONST char no_sock_func[]
93a17b20 1525 INIT("Unsupported socket function \"%s\" called");
3e3baf6d 1526EXTCONST char no_dir_func[]
93a17b20 1527 INIT("Unsupported directory function \"%s\" called");
3e3baf6d 1528EXTCONST char no_func[]
93a17b20 1529 INIT("The %s function is unimplemented");
3e3baf6d 1530EXTCONST char no_myglob[]
748a9306 1531 INIT("\"my\" variable %s can't be in a package");
93a17b20 1532
79072805 1533#ifdef DOINIT
8e07c86e 1534EXT char *sig_name[] = { SIG_NAME };
1535EXT int sig_num[] = { SIG_NUM };
0c30d9ec 1536EXT SV * psig_ptr[sizeof(sig_num)/sizeof(*sig_num)];
1537EXT SV * psig_name[sizeof(sig_num)/sizeof(*sig_num)];
79072805 1538#else
1539EXT char *sig_name[];
8e07c86e 1540EXT int sig_num[];
0c30d9ec 1541EXT SV * psig_ptr[];
1542EXT SV * psig_name[];
79072805 1543#endif
1544
bbce6d69 1545/* fast case folding tables */
1546
79072805 1547#ifdef DOINIT
36477c24 1548EXTCONST unsigned char fold[] = {
79072805 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
71be2cbc 1583EXTCONST unsigned char fold[];
79072805 1584#endif
1585
1586#ifdef DOINIT
bbce6d69 1587EXT unsigned char fold_locale[] = {
79072805 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
bbce6d69 1622EXT unsigned char fold_locale[];
79072805 1623#endif
1624
1625#ifdef DOINIT
71be2cbc 1626EXTCONST unsigned char freq[] = { /* letter frequencies for mixed English/C */
79072805 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
71be2cbc 1661EXTCONST unsigned char freq[];
79072805 1662#endif
1663
8990e307 1664#ifdef DEBUGGING
1665#ifdef DOINIT
71be2cbc 1666EXTCONST char* block_type[] = {
8990e307 1667 "NULL",
1668 "SUB",
1669 "EVAL",
1670 "LOOP",
1671 "SUBST",
1672 "BLOCK",
1673};
1674#else
71be2cbc 1675EXTCONST char* block_type[];
8990e307 1676#endif
1677#endif
1678
79072805 1679/*****************************************************************************/
1680/* This lexer/parser stuff is currently global since yacc is hard to reenter */
1681/*****************************************************************************/
8990e307 1682/* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */
79072805 1683
a0d0e21e 1684#include "perly.h"
1685
fb73857a 1686#define LEX_NOTPARSING 11 /* borrowed from toke.c */
1687
79072805 1688typedef enum {
1689 XOPERATOR,
1690 XTERM,
79072805 1691 XREF,
8990e307 1692 XSTATE,
a0d0e21e 1693 XBLOCK,
1694 XTERMBLOCK
79072805 1695} expectation;
1696
85e6fe83 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
bbce6d69 1706#define HINT_LOCALE 0x00000800
85e6fe83 1707
d4cce5f1 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))
79072805 1712
22239a37 1713/* Set up PERLVAR macros for populating structs */
1714#define PERLVAR(var,type) type var;
1715#define PERLVARI(var,type,init) type var;
3fe35a81 1716#define PERLVARIC(var,type,init) type var;
22239a37 1717
76e3520e 1718#ifdef PERL_OBJECT
1719extern "C" CPerlObj* perl_alloc _((IPerlMem*, IPerlEnv*, IPerlStdIO*, IPerlLIO*, IPerlDir*, IPerlSock*, IPerlProc*));
1720
1721typedef 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
1729class CPerlObj {
1730public:
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
22239a37 1736#ifdef PERL_GLOBAL_STRUCT
1737struct perl_vars {
1738#include "perlvars.h"
1739};
1740
1741#ifdef PERL_CORE
1742EXT struct perl_vars Perl_Vars;
1743EXT struct perl_vars *Perl_VarsPtr INIT(&Perl_Vars);
1744#else
1745#if !defined(__GNUC__) || !defined(WIN32)
1746EXT
1747#endif
1748struct perl_vars *Perl_VarsPtr;
1749#define Perl_Vars (*((Perl_VarsPtr) ? Perl_VarsPtr : (Perl_VarsPtr = Perl_GetVars())))
1750#endif
1751#endif /* PERL_GLOBAL_STRUCT */
1752
8990e307 1753#ifdef MULTIPLICITY
d4cce5f1 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
79072805 1760struct interpreter {
d4cce5f1 1761#ifndef USE_THREADS
1762#include "thrdvar.h"
1763#endif
1764#include "intrpvar.h"
49f531da 1765};
d4cce5f1 1766
79072805 1767#else
49f531da 1768struct interpreter {
1769 char broiled;
1770};
79072805 1771#endif
1772
d4cce5f1 1773#ifdef USE_THREADS
1774/* If we have threads define a struct with all the variables
1775 * that have to be per-thread
49f531da 1776 */
8023c3ce 1777
79072805 1778
49f531da 1779struct perl_thread {
49f531da 1780#include "thrdvar.h"
79072805 1781};
d4cce5f1 1782
22fae026 1783typedef struct perl_thread *Thread;
1784
1785#else
1786typedef void *Thread;
22239a37 1787#endif
1788
1789/* Done with PERLVAR macros for now ... */
d4cce5f1 1790#undef PERLVAR
1791#undef PERLVARI
3fe35a81 1792#undef PERLVARIC
79072805 1793
22239a37 1794#include "thread.h"
79072805 1795#include "pp.h"
79072805 1796#include "proto.h"
1797
a0d0e21e 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
d4cce5f1 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);
3fe35a81 1817#define PERLVARIC(var,type,init) EXTCONST type var INIT(init);
d4cce5f1 1818
22239a37 1819#ifndef PERL_GLOBAL_STRUCT
d4cce5f1 1820#include "perlvars.h"
22239a37 1821#endif
d4cce5f1 1822
1823#ifndef MULTIPLICITY
d4cce5f1 1824
1825#ifndef USE_THREADS
1826#include "thrdvar.h"
1827#endif
1828
22239a37 1829#include "intrpvar.h"
1830#endif
1831
76e3520e 1832#ifdef PERL_OBJECT
1833#if defined(WIN32)
1834char** 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
22239a37 1846
d4cce5f1 1847#undef PERLVAR
1848#undef PERLVARI
0f3f18a6 1849#undef PERLVARIC
79072805 1850
a835ef8a 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 */
76e3520e 1858#ifndef PERL_OBJECT
a835ef8a 1859# include <win32iop.h>
76e3520e 1860#endif /* PERL_OBJECT */
a835ef8a 1861#endif /* WIN32 */
1862
79072805 1863#ifdef DOINIT
bbce6d69 1864
4633a7c4 1865EXT MGVTBL vtbl_sv = {magic_get,
463ee0b2 1866 magic_set,
1867 magic_len,
1868 0, 0};
fb73857a 1869EXT MGVTBL vtbl_env = {0, magic_set_all_env,
1870 0, magic_clear_all_env,
66b1d557 1871 0};
4633a7c4 1872EXT MGVTBL vtbl_envelem = {0, magic_setenv,
85e6fe83 1873 0, magic_clearenv,
1874 0};
4633a7c4 1875EXT MGVTBL vtbl_sig = {0, 0, 0, 0, 0};
0c30d9ec 1876EXT MGVTBL vtbl_sigelem = {magic_getsig,
1877 magic_setsig,
1878 0, magic_clearsig,
1879 0};
93965878 1880EXT MGVTBL vtbl_pack = {0, 0, magic_sizepack, magic_wipepack,
a0d0e21e 1881 0};
4633a7c4 1882EXT MGVTBL vtbl_packelem = {magic_getpack,
463ee0b2 1883 magic_setpack,
1884 0, magic_clearpack,
1885 0};
4633a7c4 1886EXT MGVTBL vtbl_dbline = {0, magic_setdbline,
463ee0b2 1887 0, 0, 0};
4633a7c4 1888EXT MGVTBL vtbl_isa = {0, magic_setisa,
fb73857a 1889 0, magic_setisa,
1890 0};
4633a7c4 1891EXT MGVTBL vtbl_isaelem = {0, magic_setisa,
463ee0b2 1892 0, 0, 0};
4633a7c4 1893EXT MGVTBL vtbl_arylen = {magic_getarylen,
463ee0b2 1894 magic_setarylen,
1895 0, 0, 0};
4633a7c4 1896EXT MGVTBL vtbl_glob = {magic_getglob,
463ee0b2 1897 magic_setglob,
1898 0, 0, 0};
4633a7c4 1899EXT MGVTBL vtbl_mglob = {0, magic_setmglob,
463ee0b2 1900 0, 0, 0};
99abf803 1901EXT MGVTBL vtbl_nkeys = {0, magic_setnkeys,
1902 0, 0, 0};
4633a7c4 1903EXT MGVTBL vtbl_taint = {magic_gettaint,magic_settaint,
463ee0b2 1904 0, 0, 0};
4633a7c4 1905EXT MGVTBL vtbl_substr = {0, magic_setsubstr,
463ee0b2 1906 0, 0, 0};
4633a7c4 1907EXT MGVTBL vtbl_vec = {0, magic_setvec,
463ee0b2 1908 0, 0, 0};
4633a7c4 1909EXT MGVTBL vtbl_pos = {magic_getpos,
a0d0e21e 1910 magic_setpos,
1911 0, 0, 0};
4633a7c4 1912EXT MGVTBL vtbl_bm = {0, magic_setbm,
463ee0b2 1913 0, 0, 0};
55497cff 1914EXT MGVTBL vtbl_fm = {0, magic_setfm,
1915 0, 0, 0};
4633a7c4 1916EXT MGVTBL vtbl_uvar = {magic_getuvar,
463ee0b2 1917 magic_setuvar,
1918 0, 0, 0};
f93b4edd 1919#ifdef USE_THREADS
1920EXT MGVTBL vtbl_mutex = {0, 0, 0, 0, magic_mutexfree};
1921#endif /* USE_THREADS */
68dc0745 1922EXT MGVTBL vtbl_defelem = {magic_getdefelem,magic_setdefelem,
1923 0, 0, magic_freedefelem};
a0d0e21e 1924
c277df42 1925EXT MGVTBL vtbl_regexp = {0,0,0,0, magic_freeregexp};
1926
36477c24 1927#ifdef USE_LOCALE_COLLATE
bbce6d69 1928EXT MGVTBL vtbl_collxfrm = {0,
1929 magic_setcollxfrm,
1930 0, 0, 0};
1931#endif
a0d0e21e 1932
1933#ifdef OVERLOAD
4633a7c4 1934EXT MGVTBL vtbl_amagic = {0, magic_setamagic,
748a9306 1935 0, 0, magic_setamagic};
4633a7c4 1936EXT MGVTBL vtbl_amagicelem = {0, magic_setamagic,
748a9306 1937 0, 0, magic_setamagic};
a0d0e21e 1938#endif /* OVERLOAD */
1939
bbce6d69 1940#else /* !DOINIT */
1941
79072805 1942EXT MGVTBL vtbl_sv;
1943EXT MGVTBL vtbl_env;
1944EXT MGVTBL vtbl_envelem;
1945EXT MGVTBL vtbl_sig;
1946EXT MGVTBL vtbl_sigelem;
463ee0b2 1947EXT MGVTBL vtbl_pack;
1948EXT MGVTBL vtbl_packelem;
79072805 1949EXT MGVTBL vtbl_dbline;
463ee0b2 1950EXT MGVTBL vtbl_isa;
1951EXT MGVTBL vtbl_isaelem;
79072805 1952EXT MGVTBL vtbl_arylen;
1953EXT MGVTBL vtbl_glob;
93a17b20 1954EXT MGVTBL vtbl_mglob;
99abf803 1955EXT MGVTBL vtbl_nkeys;
463ee0b2 1956EXT MGVTBL vtbl_taint;
79072805 1957EXT MGVTBL vtbl_substr;
1958EXT MGVTBL vtbl_vec;
a0d0e21e 1959EXT MGVTBL vtbl_pos;
79072805 1960EXT MGVTBL vtbl_bm;
55497cff 1961EXT MGVTBL vtbl_fm;
79072805 1962EXT MGVTBL vtbl_uvar;
a0d0e21e 1963
f93b4edd 1964#ifdef USE_THREADS
1965EXT MGVTBL vtbl_mutex;
1966#endif /* USE_THREADS */
1967
68dc0745 1968EXT MGVTBL vtbl_defelem;
c277df42 1969EXT MGVTBL vtbl_regexp;
a0d0e21e 1970
36477c24 1971#ifdef USE_LOCALE_COLLATE
bbce6d69 1972EXT MGVTBL vtbl_collxfrm;
1973#endif
a0d0e21e 1974
1975#ifdef OVERLOAD
1976EXT MGVTBL vtbl_amagic;
1977EXT MGVTBL vtbl_amagicelem;
1978#endif /* OVERLOAD */
1979
bbce6d69 1980#endif /* !DOINIT */
85e6fe83 1981
a0d0e21e 1982#ifdef OVERLOAD
c0315cdf 1983
a6006777 1984#define NofAMmeth 58
a0d0e21e 1985#ifdef DOINIT
a6006777 1986EXTCONST 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"
a0d0e21e 2016};
2017#else
a6006777 2018EXTCONST char * AMG_names[NofAMmeth];
a0d0e21e 2019#endif /* def INITAMAGIC */
2020
a6006777 2021struct am_table {
a0d0e21e 2022 long was_ok_sub;
2023 long was_ok_am;
a6006777 2024 U32 flags;
2025 CV* table[NofAMmeth];
a0d0e21e 2026 long fallback;
2027};
a6006777 2028struct am_table_short {
2029 long was_ok_sub;
2030 long was_ok_am;
2031 U32 flags;
2032};
a0d0e21e 2033typedef struct am_table AMT;
a6006777 2034typedef struct am_table_short AMTS;
a0d0e21e 2035
2036#define AMGfallNEVER 1
2037#define AMGfallNO 2
2038#define AMGfallYES 3
2039
a6006777 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
a0d0e21e 2045enum {
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,
76e3520e 2053 modulo_amg, modulo_ass_amg,
a0d0e21e 2054 pow_amg, pow_ass_amg,
2055 lshift_amg, lshift_ass_amg,
2056 rshift_amg, rshift_ass_amg,
748a9306 2057 band_amg, band_ass_amg,
2058 bor_amg, bor_ass_amg,
2059 bxor_amg, bxor_ass_amg,
a0d0e21e 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,
a0d0e21e 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,
748a9306 2073 concat_amg, concat_ass_amg,
2074 copy_amg, neg_amg
a0d0e21e 2075};
c0315cdf 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
a0d0e21e 2108#endif /* OVERLOAD */
2109
84902520 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
bbce6d69 2126
36477c24 2127#ifdef USE_LOCALE_NUMERIC
bbce6d69 2128
36477c24 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
bbce6d69 2140
36477c24 2141#else /* !USE_LOCALE_NUMERIC */
bbce6d69 2142
36477c24 2143#define SET_NUMERIC_STANDARD() /**/
2144#define SET_NUMERIC_LOCAL() /**/
bbce6d69 2145
36477c24 2146#endif /* !USE_LOCALE_NUMERIC */
a0d0e21e 2147
760ac839 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
a868473f 2156#ifndef PERL_SCRIPT_MODE
2157#define PERL_SCRIPT_MODE "r"
2158#endif
2159
fba3b22e 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 { \
940cb80d 2165 LOCK_SV_MUTEX; \
fba3b22e 2166 if (!nice_chunk) { \
2167 nice_chunk = (char*)(chunk); \
2168 nice_chunk_size = (chunk_size); \
2169 } \
940cb80d 2170 UNLOCK_SV_MUTEX; \
fba3b22e 2171 } while (0)
2172
49f531da 2173
85e6fe83 2174#endif /* Include guard */
a6e633de 2175