This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[5.005_03-MT6]Patch: time passes
[perl5.git] / perl.h
CommitLineData
a0d0e21e 1/* perl.h
a687059c 2 *
9607fc9c 3 * Copyright (c) 1987-1997, Larry Wall
a687059c 4 *
352d5a3a
LW
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
LW
9#ifndef H_PERL
10#define H_PERL 1
a0d0e21e 11#define OVERLOAD
8d063cd8 12
760ac839
LW
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
LW
23#undef USE_STDIO
24#define USE_STDIO
25#endif /* PERL_FOR_X2P */
26
76e3520e 27#ifdef PERL_OBJECT
3dfd1da1
GS
28
29/* PERL_OBJECT explained - DickH and DougL @ ActiveState.com
30
31Defining PERL_OBJECT turns on creation of a C++ object that
32contains all writable core perl global variables and functions.
33Stated another way, all necessary global variables and functions
34are members of a big C++ object. This object's class is CPerlObj.
35This allows a Perl Host to have multiple, independent perl
36interpreters in the same process space. This is very important on
37Win32 systems as the overhead of process creation is quite high --
38this could be even higher than the script compile and execute time
39for small scripts.
40
41The perl executable implementation on Win32 is composed of perl.exe
42(the Perl Host) and perlX.dll. (the Perl Core). This allows the
43same Perl Core to easily be embedded in other applications that use
44the perl interpreter.
45
46+-----------+
47| Perl Host |
48+-----------+
49 ^
50 |
51 v
52+-----------+ +-----------+
53| Perl Core |<->| Extension |
54+-----------+ +-----------+ ...
55
56Defining PERL_OBJECT has the following effects:
57
58PERL CORE
591. CPerlObj is defined (this is the PERL_OBJECT)
602. all static functions that needed to access either global
61variables or functions needed are made member functions
623. all writable static variables are made member variables
634. all global variables and functions are defined as:
64 #define var CPerlObj::Perl_var
65 #define func CPerlObj::Perl_func
66 * these are in objpp.h
67This necessitated renaming some local variables and functions that
68had the same name as a global variable or function. This was
69probably a _good_ thing anyway.
70
71
72EXTENSIONS
731. Access to global variables and perl functions is through a
74pointer to the PERL_OBJECT. This pointer type is CPerlObj*. This is
75made transparent to extension developers by the following macros:
76 #define var pPerl->Perl_var
77 #define func pPerl->Perl_func
6de196ee 78 * these are done in objXSUB.h
3dfd1da1
GS
79This requires that the extension be compiled as C++, which means
80that the code must be ANSI C and not K&R C. For K&R extensions,
81please see the C API notes located in Win32/GenCAPI.pl. This script
6de196ee 82creates a perlCAPI.lib that provides a K & R compatible C interface
3dfd1da1
GS
83to the PERL_OBJECT.
842. Local variables and functions cannot have the same name as perl's
85variables or functions since the macros will redefine these. Look for
86this if you get some strange error message and it does not look like
87the code that you had written. This often happens with variables that
88are local to a function.
89
90PERL HOST
911. The perl host is linked with perlX.lib to get perl_alloc. This
92function will return a pointer to CPerlObj (the PERL_OBJECT). It
0f4eea8f
DL
93takes pointers to the various PerlXXX_YYY interfaces (see iperlsys.h
94for more information on this).
3dfd1da1
GS
952. The perl host calls the same functions as normally would be
96called in setting up and running a perl script, except that the
97functions are now member functions of the PERL_OBJECT.
98
99*/
100
101
76e3520e
GS
102class CPerlObj;
103
104#define STATIC
105#define CPERLscope(x) CPerlObj::x
106#define CPERLproto CPerlObj *
e3b8966e 107#define _CPERLproto ,CPERLproto
76e3520e
GS
108#define CPERLarg CPerlObj *pPerl
109#define CPERLarg_ CPERLarg,
e3b8966e 110#define _CPERLarg ,CPERLarg
1d583055
GS
111#define PERL_OBJECT_THIS this
112#define _PERL_OBJECT_THIS ,this
113#define PERL_OBJECT_THIS_ this,
4c2891ed
GS
114#define CALLRUNOPS (this->*PL_runops)
115#define CALLREGCOMP (this->*PL_regcompp)
116#define CALLREGEXEC (this->*PL_regexecp)
76e3520e
GS
117
118#else /* !PERL_OBJECT */
119
120#define STATIC static
121#define CPERLscope(x) x
122#define CPERLproto
e3b8966e 123#define _CPERLproto
565764a8 124#define CPERLarg void
76e3520e 125#define CPERLarg_
e3b8966e 126#define _CPERLarg
1d583055
GS
127#define PERL_OBJECT_THIS
128#define _PERL_OBJECT_THIS
129#define PERL_OBJECT_THIS_
3280af22
NIS
130#define CALLRUNOPS PL_runops
131#define CALLREGCOMP (*PL_regcompp)
132#define CALLREGEXEC (*PL_regexecp)
76e3520e
GS
133
134#endif /* PERL_OBJECT */
135
71be2cbc 136#define VOIDUSED 1
137#include "config.h"
138
139#include "embed.h"
140
326b05e3
GS
141#undef START_EXTERN_C
142#undef END_EXTERN_C
143#undef EXTERN_C
32f822de
GS
144#ifdef __cplusplus
145# define START_EXTERN_C extern "C" {
146# define END_EXTERN_C }
147# define EXTERN_C extern "C"
148#else
149# define START_EXTERN_C
150# define END_EXTERN_C
151# define EXTERN_C
152#endif
153
462e5cf6
MB
154#ifdef OP_IN_REGISTER
155# ifdef __GNUC__
156# define stringify_immed(s) #s
157# define stringify(s) stringify_immed(s)
d1ca3daa
GA
158#ifdef EMBED
159register struct op *Perl_op asm(stringify(OP_IN_REGISTER));
160#else
462e5cf6 161register struct op *op asm(stringify(OP_IN_REGISTER));
d1ca3daa 162#endif
462e5cf6
MB
163# endif
164#endif
165
728e2803 166/*
167 * STMT_START { statements; } STMT_END;
168 * can be used as a single statement, as in
169 * if (x) STMT_START { ... } STMT_END; else ...
170 *
171 * Trying to select a version that gives no warnings...
172 */
173#if !(defined(STMT_START) && defined(STMT_END))
169d69b2 174# if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__cplusplus)
728e2803 175# define STMT_START (void)( /* gcc supports ``({ STATEMENTS; })'' */
176# define STMT_END )
177# else
178 /* Now which other defined()s do we need here ??? */
179# if (VOIDFLAGS) && (defined(sun) || defined(__sun__))
180# define STMT_START if (1)
181# define STMT_END else (void)0
182# else
183# define STMT_START do
184# define STMT_END while (0)
185# endif
186# endif
187#endif
188
462e5cf6
MB
189#define NOOP (void)0
190
61bb5906 191#define WITH_THR(s) STMT_START { dTHR; s; } STMT_END
ea0efc06 192
55497cff 193/*
194 * SOFT_CAST can be used for args to prototyped functions to retain some
195 * type checking; it only casts if the compiler does not know prototypes.
196 */
197#if defined(CAN_PROTOTYPE) && defined(DEBUGGING_COMPILE)
198#define SOFT_CAST(type)
199#else
200#define SOFT_CAST(type) (type)
201#endif
79072805 202
6ee623d5 203#ifndef BYTEORDER /* Should never happen -- byteorder is in config.h */
79072805
LW
204# define BYTEORDER 0x1234
205#endif
206
207/* Overall memory policy? */
208#ifndef CONSERVATIVE
209# define LIBERAL 1
210#endif
211
b1e066e5
JH
212#if 'A' == 65 && 'I' == 73 && 'J' == 74 && 'Z' == 90
213#define ASCIIish
214#else
215#undef ASCIIish
216#endif
217
79072805
LW
218/*
219 * The following contortions are brought to you on behalf of all the
220 * standards, semi-standards, de facto standards, not-so-de-facto standards
221 * of the world, as well as all the other botches anyone ever thought of.
222 * The basic theory is that if we work hard enough here, the rest of the
223 * code can be a lot prettier. Well, so much for theory. Sorry, Henry...
224 */
ac58e20f 225
ee0007ab 226/* define this once if either system, instead of cluttering up the src */
68dc0745 227#if defined(MSDOS) || defined(atarist) || defined(WIN32)
ee0007ab
LW
228#define DOSISH 1
229#endif
230
a0d0e21e 231#if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
352d5a3a
LW
232# define STANDARD_C 1
233#endif
234
09b7f37c 235#if defined(__cplusplus) || defined(WIN32) || defined(__sgi) || defined(OS2) || defined(__DGUX)
68dc0745 236# define DONT_DECLARE_STD 1
237#endif
238
352d5a3a 239#if defined(HASVOLATILE) || defined(STANDARD_C)
79072805
LW
240# ifdef __cplusplus
241# define VOL // to temporarily suppress warnings
242# else
243# define VOL volatile
244# endif
663a0e37 245#else
79072805 246# define VOL
663a0e37
LW
247#endif
248
3280af22
NIS
249#define TAINT (PL_tainted = TRUE)
250#define TAINT_NOT (PL_tainted = FALSE)
251#define TAINT_IF(c) if (c) { PL_tainted = TRUE; }
252#define TAINT_ENV() if (PL_tainting) { taint_env(); }
0c005962 253#define TAINT_PROPER(s) if (PL_tainting) { taint_proper(Nullch, s); }
a687059c 254
a6e633de 255/* XXX All process group stuff is handled in pp_sys.c. Should these
256 defines move there? If so, I could simplify this a lot. --AD 9/96.
257*/
258/* Process group stuff changed from traditional BSD to POSIX.
259 perlfunc.pod documents the traditional BSD-style syntax, so we'll
260 try to preserve that, if possible.
261*/
262#ifdef HAS_SETPGID
263# define BSD_SETPGRP(pid, pgrp) setpgid((pid), (pgrp))
c07a80fd 264#else
a6e633de 265# if defined(HAS_SETPGRP) && defined(USE_BSD_SETPGRP)
266# define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp))
267# else
268# ifdef HAS_SETPGRP2 /* DG/UX */
269# define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp))
270# endif
271# endif
272#endif
273#if defined(BSD_SETPGRP) && !defined(HAS_SETPGRP)
274# define HAS_SETPGRP /* Well, effectively it does . . . */
275#endif
276
277/* getpgid isn't POSIX, but at least Solaris and Linux have it, and it makes
278 our life easier :-) so we'll try it.
279*/
280#ifdef HAS_GETPGID
281# define BSD_GETPGRP(pid) getpgid((pid))
282#else
283# if defined(HAS_GETPGRP) && defined(USE_BSD_GETPGRP)
284# define BSD_GETPGRP(pid) getpgrp((pid))
285# else
286# ifdef HAS_GETPGRP2 /* DG/UX */
287# define BSD_GETPGRP(pid) getpgrp2((pid))
288# endif
289# endif
290#endif
291#if defined(BSD_GETPGRP) && !defined(HAS_GETPGRP)
292# define HAS_GETPGRP /* Well, effectively it does . . . */
293#endif
294
295/* These are not exact synonyms, since setpgrp() and getpgrp() may
296 have different behaviors, but perl.h used to define USE_BSDPGRP
297 (prior to 5.003_05) so some extension might depend on it.
298*/
299#if defined(USE_BSD_SETPGRP) || defined(USE_BSD_GETPGRP)
300# ifndef USE_BSDPGRP
301# define USE_BSDPGRP
302# endif
663a0e37
LW
303#endif
304
760ac839
LW
305#ifndef _TYPES_ /* If types.h defines this it's easy. */
306# ifndef major /* Does everyone's types.h define this? */
307# include <sys/types.h>
c07a80fd 308# endif
663a0e37
LW
309#endif
310
760ac839
LW
311#ifdef __cplusplus
312# ifndef I_STDARG
313# define I_STDARG 1
314# endif
315#endif
316
317#ifdef I_STDARG
318# include <stdarg.h>
319#else
320# ifdef I_VARARGS
321# include <varargs.h>
322# endif
323#endif
324
0f4eea8f 325#include "iperlsys.h"
0c30d9ec 326
4633a7c4 327#ifdef USE_NEXT_CTYPE
0c30d9ec 328
329#if NX_CURRENT_COMPILER_RELEASE >= 400
330#include <objc/NXCType.h>
331#else /* NX_CURRENT_COMPILER_RELEASE < 400 */
a0d0e21e 332#include <appkit/NXCType.h>
0c30d9ec 333#endif /* NX_CURRENT_COMPILER_RELEASE >= 400 */
334
335#else /* !USE_NEXT_CTYPE */
fe14fcc3 336#include <ctype.h>
0c30d9ec 337#endif /* USE_NEXT_CTYPE */
a0d0e21e
LW
338
339#ifdef METHOD /* Defined by OSF/1 v3.0 by ctype.h */
340#undef METHOD
a0d0e21e
LW
341#endif
342
4633a7c4 343#ifdef I_LOCALE
36477c24 344# include <locale.h>
4633a7c4
LW
345#endif
346
36477c24 347#if !defined(NO_LOCALE) && defined(HAS_SETLOCALE)
348# define USE_LOCALE
349# if !defined(NO_LOCALE_COLLATE) && defined(LC_COLLATE) \
350 && defined(HAS_STRXFRM)
351# define USE_LOCALE_COLLATE
352# endif
353# if !defined(NO_LOCALE_CTYPE) && defined(LC_CTYPE)
354# define USE_LOCALE_CTYPE
355# endif
356# if !defined(NO_LOCALE_NUMERIC) && defined(LC_NUMERIC)
357# define USE_LOCALE_NUMERIC
358# endif
359#endif /* !NO_LOCALE && HAS_SETLOCALE */
a0d0e21e 360
fe14fcc3 361#include <setjmp.h>
79072805 362
a0d0e21e 363#ifdef I_SYS_PARAM
79072805
LW
364# ifdef PARAM_NEEDS_TYPES
365# include <sys/types.h>
366# endif
367# include <sys/param.h>
352d5a3a 368#endif
79072805
LW
369
370
371/* Use all the "standard" definitions? */
a0d0e21e 372#if defined(STANDARD_C) && defined(I_STDLIB)
79072805 373# include <stdlib.h>
ff68c719 374#endif
03a14243 375
c31fac66
GS
376#define MEM_SIZE Size_t
377
55497cff 378/* This comes after <stdlib.h> so we don't try to change the standard
379 * library prototypes; we'll use our own in proto.h instead. */
03a14243 380
4633a7c4 381#ifdef MYMALLOC
55497cff 382
4633a7c4 383# ifdef HIDEMYMALLOC
55497cff 384# define malloc Mymalloc
385# define calloc Mycalloc
429a5e67 386# define realloc Myrealloc
55497cff 387# define free Myfree
c31fac66
GS
388Malloc_t Mymalloc _((MEM_SIZE nbytes));
389Malloc_t Mycalloc _((MEM_SIZE elements, MEM_SIZE size));
390Malloc_t Myrealloc _((Malloc_t where, MEM_SIZE nbytes));
391Free_t Myfree _((Malloc_t where));
55497cff 392# endif
393# ifdef EMBEDMYMALLOC
394# define malloc Perl_malloc
395# define calloc Perl_calloc
396# define realloc Perl_realloc
429a5e67
DS
397/* VMS' external symbols are case-insensitive, and there's already a */
398/* perl_free in perl.h */
399#ifdef VMS
400# define free Perl_myfree
401#else
55497cff 402# define free Perl_free
429a5e67 403#endif
c31fac66
GS
404Malloc_t Perl_malloc _((MEM_SIZE nbytes));
405Malloc_t Perl_calloc _((MEM_SIZE elements, MEM_SIZE size));
406Malloc_t Perl_realloc _((Malloc_t where, MEM_SIZE nbytes));
429a5e67
DS
407#ifdef VMS
408Free_t Perl_myfree _((Malloc_t where));
409#else
c31fac66 410Free_t Perl_free _((Malloc_t where));
429a5e67 411#endif
4633a7c4 412# endif
55497cff 413
414# undef safemalloc
415# undef safecalloc
416# undef saferealloc
417# undef safefree
418# define safemalloc malloc
419# define safecalloc calloc
4633a7c4 420# define saferealloc realloc
55497cff 421# define safefree free
422
423#endif /* MYMALLOC */
4633a7c4 424
ff68c719 425#if defined(STANDARD_C) && defined(I_STDDEF)
426# include <stddef.h>
71be2cbc 427# define STRUCT_OFFSET(s,m) offsetof(s,m)
ff68c719 428#else
71be2cbc 429# define STRUCT_OFFSET(s,m) (Size_t)(&(((s *)0)->m))
ff68c719 430#endif
431
a0d0e21e
LW
432#if defined(I_STRING) || defined(__cplusplus)
433# include <string.h>
434#else
435# include <strings.h>
436#endif
437
438#if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
439#define strchr index
440#define strrchr rindex
441#endif
442
16d20bd9
AD
443#ifdef I_MEMORY
444# include <memory.h>
445#endif
446
fe14fcc3 447#ifdef HAS_MEMCPY
85e6fe83 448# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
fe14fcc3 449# ifndef memcpy
a0d0e21e 450 extern char * memcpy _((char*, char*, int));
ee0007ab
LW
451# endif
452# endif
453#else
454# ifndef memcpy
455# ifdef HAS_BCOPY
456# define memcpy(d,s,l) bcopy(s,d,l)
457# else
458# define memcpy(d,s,l) my_bcopy(s,d,l)
459# endif
460# endif
461#endif /* HAS_MEMCPY */
fe14fcc3 462
ee0007ab 463#ifdef HAS_MEMSET
85e6fe83 464# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
ee0007ab 465# ifndef memset
a0d0e21e 466 extern char *memset _((char*, int, int));
ee0007ab
LW
467# endif
468# endif
ee0007ab 469#else
fc36a67e 470# define memset(d,c,l) my_memset(d,c,l)
ee0007ab
LW
471#endif /* HAS_MEMSET */
472
85e6fe83 473#if !defined(HAS_MEMMOVE) && !defined(memmove)
2304df62 474# if defined(HAS_BCOPY) && defined(HAS_SAFE_BCOPY)
79072805
LW
475# define memmove(d,s,l) bcopy(s,d,l)
476# else
2304df62 477# if defined(HAS_MEMCPY) && defined(HAS_SAFE_MEMCPY)
79072805 478# define memmove(d,s,l) memcpy(d,s,l)
ee0007ab 479# else
79072805 480# define memmove(d,s,l) my_bcopy(s,d,l)
ee0007ab 481# endif
352d5a3a 482# endif
d9d8d8de 483#endif
ee0007ab 484
36477c24 485#if defined(mips) && defined(ultrix) && !defined(__STDC__)
486# undef HAS_MEMCMP
487#endif
488
489#if defined(HAS_MEMCMP) && defined(HAS_SANE_MEMCMP)
85e6fe83 490# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
ee0007ab 491# ifndef memcmp
a0d0e21e 492 extern int memcmp _((char*, char*, int));
ee0007ab
LW
493# endif
494# endif
36477c24 495# ifdef BUGGY_MSC
496 # pragma function(memcmp)
497# endif
ee0007ab
LW
498#else
499# ifndef memcmp
ecfc5424 500# define memcmp my_memcmp
352d5a3a 501# endif
36477c24 502#endif /* HAS_MEMCMP && HAS_SANE_MEMCMP */
8d063cd8 503
fc36a67e 504#ifndef memzero
c635e13b 505# ifdef HAS_MEMSET
506# define memzero(d,l) memset(d,0,l)
79072805 507# else
c635e13b 508# ifdef HAS_BZERO
509# define memzero(d,l) bzero(d,l)
79072805 510# else
fc36a67e 511# define memzero(d,l) my_bzero(d,l)
79072805
LW
512# endif
513# endif
d9d8d8de 514#endif
378cc40b 515
36477c24 516#ifndef HAS_BCMP
517# ifndef bcmp
518# define bcmp(s1,s2,l) memcmp(s1,s2,l)
79072805 519# endif
36477c24 520#endif /* !HAS_BCMP */
378cc40b 521
ae986130 522#ifdef I_NETINET_IN
79072805 523# include <netinet/in.h>
ae986130
LW
524#endif
525
28e8609d
JH
526#ifdef I_ARPA_INET
527# include <arpa/inet.h>
528#endif
529
84902520
TB
530#if defined(SF_APPEND) && defined(USE_SFIO) && defined(I_SFIO)
531/* <sfio.h> defines SF_APPEND and <sys/stat.h> might define SF_APPEND
532 * (the neo-BSD seem to do this). */
533# undef SF_APPEND
534#endif
535
1aef975c 536#ifdef I_SYS_STAT
84902520 537# include <sys/stat.h>
1aef975c 538#endif
79072805 539
a0d0e21e
LW
540/* The stat macros for Amdahl UTS, Unisoft System V/88 (and derivatives
541 like UTekV) are broken, sometimes giving false positives. Undefine
542 them here and let the code below set them to proper values.
543
544 The ghs macro stands for GreenHills Software C-1.8.5 which
545 is the C compiler for sysV88 and the various derivatives.
546 This header file bug is corrected in gcc-2.5.8 and later versions.
547 --Kaveh Ghazi (ghazi@noc.rutgers.edu) 10/3/94. */
548
549#if defined(uts) || (defined(m88k) && defined(ghs))
79072805
LW
550# undef S_ISDIR
551# undef S_ISCHR
552# undef S_ISBLK
553# undef S_ISREG
554# undef S_ISFIFO
555# undef S_ISLNK
ee0007ab 556#endif
135863df 557
663a0e37
LW
558#ifdef I_TIME
559# include <time.h>
ffed7fef 560#endif
663a0e37 561
fe14fcc3 562#ifdef I_SYS_TIME
85e6fe83 563# ifdef I_SYS_TIME_KERNEL
663a0e37
LW
564# define KERNEL
565# endif
566# include <sys/time.h>
85e6fe83 567# ifdef I_SYS_TIME_KERNEL
663a0e37
LW
568# undef KERNEL
569# endif
a687059c 570#endif
135863df 571
55497cff 572#if defined(HAS_TIMES) && defined(I_SYS_TIMES)
85e6fe83 573# include <sys/times.h>
d9d8d8de 574#endif
8d063cd8 575
fe14fcc3 576#if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
79072805 577# undef HAS_STRERROR
663a0e37
LW
578#endif
579
580#include <errno.h>
ed6116ce 581#ifdef HAS_SOCKET
85e6fe83 582# ifdef I_NET_ERRNO
ed6116ce
LW
583# include <net/errno.h>
584# endif
585#endif
f86702cc 586
587#ifdef VMS
588# define SETERRNO(errcode,vmserrcode) \
589 STMT_START { \
590 set_errno(errcode); \
591 set_vaxc_errno(vmserrcode); \
592 } STMT_END
748a9306 593#else
1f6b3999 594# define SETERRNO(errcode,vmserrcode) (errno = (errcode))
748a9306 595#endif
ed6116ce 596
38a03e6e
MB
597#ifdef USE_THREADS
598# define ERRSV (thr->errsv)
599# define ERRHV (thr->errhv)
940cb80d
MB
600# define DEFSV THREADSV(0)
601# define SAVE_DEFSV save_threadsv(0)
38a03e6e 602#else
3280af22
NIS
603# define ERRSV GvSV(PL_errgv)
604# define ERRHV GvHV(PL_errgv)
605# define DEFSV GvSV(PL_defgv)
606# define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
38a03e6e
MB
607#endif /* USE_THREADS */
608
55497cff 609#ifndef errno
79072805 610 extern int errno; /* ANSI allows errno to be an lvalue expr */
d9d8d8de 611#endif
663a0e37 612
2304df62 613#ifdef HAS_STRERROR
a0d0e21e
LW
614# ifdef VMS
615 char *strerror _((int,...));
616# else
68dc0745 617#ifndef DONT_DECLARE_STD
a0d0e21e 618 char *strerror _((int));
68dc0745 619#endif
a0d0e21e 620# endif
2304df62
AD
621# ifndef Strerror
622# define Strerror strerror
623# endif
624#else
625# ifdef HAS_SYS_ERRLIST
79072805
LW
626 extern int sys_nerr;
627 extern char *sys_errlist[];
2304df62
AD
628# ifndef Strerror
629# define Strerror(e) \
79072805 630 ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
2304df62 631# endif
79072805 632# endif
35c8bce7 633#endif
663a0e37 634
2304df62 635#ifdef I_SYS_IOCTL
79072805
LW
636# ifndef _IOCTL_
637# include <sys/ioctl.h>
638# endif
a687059c
LW
639#endif
640
ee0007ab 641#if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
79072805
LW
642# ifdef HAS_SOCKETPAIR
643# undef HAS_SOCKETPAIR
644# endif
2304df62
AD
645# ifdef I_NDBM
646# undef I_NDBM
79072805 647# endif
a687059c
LW
648#endif
649
a687059c 650#if INTSIZE == 2
79072805
LW
651# define htoni htons
652# define ntohi ntohs
a687059c 653#else
79072805
LW
654# define htoni htonl
655# define ntohi ntohl
a687059c
LW
656#endif
657
a0d0e21e 658/* Configure already sets Direntry_t */
35c8bce7 659#if defined(I_DIRENT)
663a0e37 660# include <dirent.h>
a0d0e21e
LW
661# if defined(NeXT) && defined(I_SYS_DIR) /* NeXT needs dirent + sys/dir.h */
662# include <sys/dir.h>
663# endif
ae986130 664#else
fe14fcc3 665# ifdef I_SYS_NDIR
79a0689e 666# include <sys/ndir.h>
663a0e37 667# else
fe14fcc3 668# ifdef I_SYS_DIR
79a0689e
LW
669# ifdef hp9000s500
670# include <ndir.h> /* may be wrong in the future */
671# else
672# include <sys/dir.h>
673# endif
663a0e37
LW
674# endif
675# endif
4633a7c4 676#endif
a687059c 677
352d5a3a
LW
678#ifdef FPUTS_BOTCH
679/* work around botch in SunOS 4.0.1 and 4.0.2 */
680# ifndef fputs
79072805 681# define fputs(sv,fp) fprintf(fp,"%s",sv)
352d5a3a
LW
682# endif
683#endif
684
c623bd54
LW
685/*
686 * The following gobbledygook brought to you on behalf of __STDC__.
687 * (I could just use #ifndef __STDC__, but this is more bulletproof
688 * in the face of half-implementations.)
689 */
690
691#ifndef S_IFMT
692# ifdef _S_IFMT
693# define S_IFMT _S_IFMT
694# else
695# define S_IFMT 0170000
696# endif
697#endif
698
699#ifndef S_ISDIR
700# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
701#endif
702
703#ifndef S_ISCHR
704# define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
705#endif
706
707#ifndef S_ISBLK
fe14fcc3
LW
708# ifdef S_IFBLK
709# define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
710# else
711# define S_ISBLK(m) (0)
712# endif
c623bd54
LW
713#endif
714
715#ifndef S_ISREG
716# define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
717#endif
718
719#ifndef S_ISFIFO
fe14fcc3
LW
720# ifdef S_IFIFO
721# define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
722# else
723# define S_ISFIFO(m) (0)
724# endif
c623bd54
LW
725#endif
726
727#ifndef S_ISLNK
728# ifdef _S_ISLNK
729# define S_ISLNK(m) _S_ISLNK(m)
730# else
731# ifdef _S_IFLNK
732# define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
733# else
734# ifdef S_IFLNK
735# define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
736# else
737# define S_ISLNK(m) (0)
738# endif
739# endif
740# endif
741#endif
742
743#ifndef S_ISSOCK
744# ifdef _S_ISSOCK
745# define S_ISSOCK(m) _S_ISSOCK(m)
746# else
747# ifdef _S_IFSOCK
748# define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
749# else
750# ifdef S_IFSOCK
751# define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
752# else
753# define S_ISSOCK(m) (0)
754# endif
755# endif
756# endif
757#endif
758
759#ifndef S_IRUSR
760# ifdef S_IREAD
761# define S_IRUSR S_IREAD
762# define S_IWUSR S_IWRITE
763# define S_IXUSR S_IEXEC
764# else
765# define S_IRUSR 0400
766# define S_IWUSR 0200
767# define S_IXUSR 0100
768# endif
769# define S_IRGRP (S_IRUSR>>3)
770# define S_IWGRP (S_IWUSR>>3)
771# define S_IXGRP (S_IXUSR>>3)
772# define S_IROTH (S_IRUSR>>6)
773# define S_IWOTH (S_IWUSR>>6)
774# define S_IXOTH (S_IXUSR>>6)
775#endif
776
777#ifndef S_ISUID
778# define S_ISUID 04000
779#endif
780
781#ifndef S_ISGID
782# define S_ISGID 02000
783#endif
784
79072805
LW
785#ifdef ff_next
786# undef ff_next
352d5a3a
LW
787#endif
788
a0d0e21e 789#if defined(cray) || defined(gould) || defined(i860) || defined(pyr)
45d8adaa
LW
790# define SLOPPYDIVIDE
791#endif
792
748a9306
LW
793#ifdef UV
794#undef UV
795#endif
796
27d4fb96 797/* XXX QUAD stuff is not currently supported on most systems.
798 Specifically, perl internals don't support long long. Among
799 the many problems is that some compilers support long long,
800 but the underlying library functions (such as sprintf) don't.
801 Some things do work (such as quad pack/unpack on convex);
802 also some systems use long long for the fpos_t typedef. That
803 seems to work too.
804
805 The IV type is supposed to be long enough to hold any integral
806 value or a pointer.
807 --Andy Dougherty August 1996
808*/
809
f86702cc 810#ifdef cray
811# define Quad_t int
812#else
813# ifdef convex
814# define Quad_t long long
45d8adaa 815# else
6ee623d5 816# if LONGSIZE == 8
ecfc5424 817# define Quad_t long
45d8adaa
LW
818# endif
819# endif
f86702cc 820#endif
821
6ee623d5
GS
822/* XXX Experimental set-up for long long. Just add -DUSE_LONG_LONG
823 to your ccflags. --Andy Dougherty 4/1998
824*/
825#ifdef USE_LONG_LONG
826# if defined(HAS_LONG_LONG) && LONGLONGSIZE == 8
827# define Quad_t long long
828# endif
829#endif
830
f86702cc 831#ifdef Quad_t
832# define HAS_QUAD
748a9306
LW
833 typedef Quad_t IV;
834 typedef unsigned Quad_t UV;
27d4fb96 835# define IV_MAX PERL_QUAD_MAX
836# define IV_MIN PERL_QUAD_MIN
837# define UV_MAX PERL_UQUAD_MAX
838# define UV_MIN PERL_UQUAD_MIN
79072805 839#else
748a9306
LW
840 typedef long IV;
841 typedef unsigned long UV;
27d4fb96 842# define IV_MAX PERL_LONG_MAX
843# define IV_MIN PERL_LONG_MIN
844# define UV_MAX PERL_ULONG_MAX
845# define UV_MIN PERL_ULONG_MIN
79072805
LW
846#endif
847
760ac839
LW
848/* Previously these definitions used hardcoded figures.
849 * It is hoped these formula are more portable, although
850 * no data one way or another is presently known to me.
851 * The "PERL_" names are used because these calculated constants
852 * do not meet the ANSI requirements for LONG_MAX, etc., which
853 * need to be constants acceptable to #if - kja
854 * define PERL_LONG_MAX 2147483647L
855 * define PERL_LONG_MIN (-LONG_MAX - 1)
856 * define PERL ULONG_MAX 4294967295L
857 */
858
859#ifdef I_LIMITS /* Needed for cast_xxx() functions below. */
860# include <limits.h>
861#else
862#ifdef I_VALUES
863# include <values.h>
864#endif
865#endif
866
99abf803 867/*
868 * Try to figure out max and min values for the integral types. THE CORRECT
869 * SOLUTION TO THIS MESS: ADAPT enquire.c FROM GCC INTO CONFIGURE. The
870 * following hacks are used if neither limits.h or values.h provide them:
871 * U<TYPE>_MAX: for types >= int: ~(unsigned TYPE)0
872 * for types < int: (unsigned TYPE)~(unsigned)0
873 * The argument to ~ must be unsigned so that later signed->unsigned
874 * conversion can't modify the value's bit pattern (e.g. -0 -> +0),
875 * and it must not be smaller than int because ~ does integral promotion.
876 * <type>_MAX: (<type>) (U<type>_MAX >> 1)
877 * <type>_MIN: -<type>_MAX - <is_twos_complement_architecture: (3 & -1) == 3>.
878 * The latter is a hack which happens to work on some machines but
879 * does *not* catch any random system, or things like integer types
880 * with NaN if that is possible.
881 *
882 * All of the types are explicitly cast to prevent accidental loss of
883 * numeric range, and in the hope that they will be less likely to confuse
884 * over-eager optimizers.
885 *
886 */
27d4fb96 887
99abf803 888#define PERL_UCHAR_MIN ((unsigned char)0)
889
890#ifdef UCHAR_MAX
891# define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX)
27d4fb96 892#else
99abf803 893# ifdef MAXUCHAR
894# define PERL_UCHAR_MAX ((unsigned char)MAXUCHAR)
27d4fb96 895# else
99abf803 896# define PERL_UCHAR_MAX ((unsigned char)~(unsigned)0)
27d4fb96 897# endif
898#endif
99abf803 899
900/*
901 * CHAR_MIN and CHAR_MAX are not included here, as the (char) type may be
902 * ambiguous. It may be equivalent to (signed char) or (unsigned char)
903 * depending on local options. Until Configure detects this (or at least
904 * detects whether the "signed" keyword is available) the CHAR ranges
905 * will not be included. UCHAR functions normally.
906 * - kja
907 */
27d4fb96 908
99abf803 909#define PERL_USHORT_MIN ((unsigned short)0)
910
911#ifdef USHORT_MAX
912# define PERL_USHORT_MAX ((unsigned short)USHORT_MAX)
27d4fb96 913#else
99abf803 914# ifdef MAXUSHORT
915# define PERL_USHORT_MAX ((unsigned short)MAXUSHORT)
27d4fb96 916# else
ef2f54b0
CB
917# ifdef USHRT_MAX
918# define PERL_USHORT_MAX ((unsigned short)USHRT_MAX)
919# else
920# define PERL_USHORT_MAX ((unsigned short)~(unsigned)0)
921# endif
27d4fb96 922# endif
923#endif
924
27d4fb96 925#ifdef SHORT_MAX
99abf803 926# define PERL_SHORT_MAX ((short)SHORT_MAX)
27d4fb96 927#else
928# ifdef MAXSHORT /* Often used in <values.h> */
99abf803 929# define PERL_SHORT_MAX ((short)MAXSHORT)
27d4fb96 930# else
ef2f54b0
CB
931# ifdef SHRT_MAX
932# define PERL_SHORT_MAX ((short)SHRT_MAX)
933# else
934# define PERL_SHORT_MAX ((short) (PERL_USHORT_MAX >> 1))
935# endif
27d4fb96 936# endif
937#endif
938
939#ifdef SHORT_MIN
99abf803 940# define PERL_SHORT_MIN ((short)SHORT_MIN)
27d4fb96 941#else
942# ifdef MINSHORT
99abf803 943# define PERL_SHORT_MIN ((short)MINSHORT)
27d4fb96 944# else
ef2f54b0
CB
945# ifdef SHRT_MIN
946# define PERL_SHORT_MIN ((short)SHRT_MIN)
947# else
948# define PERL_SHORT_MIN (-PERL_SHORT_MAX - ((3 & -1) == 3))
949# endif
27d4fb96 950# endif
951#endif
952
99abf803 953#ifdef UINT_MAX
954# define PERL_UINT_MAX ((unsigned int)UINT_MAX)
27d4fb96 955#else
99abf803 956# ifdef MAXUINT
957# define PERL_UINT_MAX ((unsigned int)MAXUINT)
27d4fb96 958# else
99abf803 959# define PERL_UINT_MAX (~(unsigned int)0)
27d4fb96 960# endif
961#endif
962
99abf803 963#define PERL_UINT_MIN ((unsigned int)0)
27d4fb96 964
965#ifdef INT_MAX
99abf803 966# define PERL_INT_MAX ((int)INT_MAX)
27d4fb96 967#else
968# ifdef MAXINT /* Often used in <values.h> */
99abf803 969# define PERL_INT_MAX ((int)MAXINT)
27d4fb96 970# else
99abf803 971# define PERL_INT_MAX ((int)(PERL_UINT_MAX >> 1))
27d4fb96 972# endif
973#endif
974
975#ifdef INT_MIN
99abf803 976# define PERL_INT_MIN ((int)INT_MIN)
27d4fb96 977#else
978# ifdef MININT
99abf803 979# define PERL_INT_MIN ((int)MININT)
27d4fb96 980# else
981# define PERL_INT_MIN (-PERL_INT_MAX - ((3 & -1) == 3))
982# endif
983#endif
984
99abf803 985#ifdef ULONG_MAX
986# define PERL_ULONG_MAX ((unsigned long)ULONG_MAX)
27d4fb96 987#else
99abf803 988# ifdef MAXULONG
989# define PERL_ULONG_MAX ((unsigned long)MAXULONG)
27d4fb96 990# else
99abf803 991# define PERL_ULONG_MAX (~(unsigned long)0)
27d4fb96 992# endif
993#endif
994
99abf803 995#define PERL_ULONG_MIN ((unsigned long)0L)
27d4fb96 996
760ac839 997#ifdef LONG_MAX
99abf803 998# define PERL_LONG_MAX ((long)LONG_MAX)
760ac839
LW
999#else
1000# ifdef MAXLONG /* Often used in <values.h> */
99abf803 1001# define PERL_LONG_MAX ((long)MAXLONG)
760ac839 1002# else
99abf803 1003# define PERL_LONG_MAX ((long) (PERL_ULONG_MAX >> 1))
760ac839
LW
1004# endif
1005#endif
1006
1007#ifdef LONG_MIN
99abf803 1008# define PERL_LONG_MIN ((long)LONG_MIN)
760ac839
LW
1009#else
1010# ifdef MINLONG
99abf803 1011# define PERL_LONG_MIN ((long)MINLONG)
760ac839 1012# else
27d4fb96 1013# define PERL_LONG_MIN (-PERL_LONG_MAX - ((3 & -1) == 3))
760ac839
LW
1014# endif
1015#endif
1016
99abf803 1017#ifdef HAS_QUAD
1018
1019# ifdef UQUAD_MAX
1020# define PERL_UQUAD_MAX ((UV)UQUAD_MAX)
760ac839 1021# else
99abf803 1022# define PERL_UQUAD_MAX (~(UV)0)
760ac839 1023# endif
760ac839 1024
99abf803 1025# define PERL_UQUAD_MIN ((UV)0)
27d4fb96 1026
27d4fb96 1027# ifdef QUAD_MAX
99abf803 1028# define PERL_QUAD_MAX ((IV)QUAD_MAX)
27d4fb96 1029# else
99abf803 1030# define PERL_QUAD_MAX ((IV) (PERL_UQUAD_MAX >> 1))
27d4fb96 1031# endif
1032
1033# ifdef QUAD_MIN
99abf803 1034# define PERL_QUAD_MIN ((IV)QUAD_MIN)
27d4fb96 1035# else
a6e633de 1036# define PERL_QUAD_MIN (-PERL_QUAD_MAX - ((3 & -1) == 3))
27d4fb96 1037# endif
1038
79072805
LW
1039#endif
1040
ee0007ab 1041typedef MEM_SIZE STRLEN;
450a55e4 1042
79072805
LW
1043typedef struct op OP;
1044typedef struct cop COP;
1045typedef struct unop UNOP;
1046typedef struct binop BINOP;
1047typedef struct listop LISTOP;
1048typedef struct logop LOGOP;
1049typedef struct condop CONDOP;
1050typedef struct pmop PMOP;
1051typedef struct svop SVOP;
1052typedef struct gvop GVOP;
1053typedef struct pvop PVOP;
79072805
LW
1054typedef struct loop LOOP;
1055
1056typedef struct Outrec Outrec;
93a17b20 1057typedef struct interpreter PerlInterpreter;
3e3baf6d
TB
1058#ifndef __BORLANDC__
1059typedef struct ff FF; /* XXX not defined anywhere, should go? */
1060#endif
79072805
LW
1061typedef struct sv SV;
1062typedef struct av AV;
1063typedef struct hv HV;
1064typedef struct cv CV;
378cc40b 1065typedef struct regexp REGEXP;
79072805 1066typedef struct gp GP;
0c30d9ec 1067typedef struct gv GV;
8990e307 1068typedef struct io IO;
c09156bb 1069typedef struct context PERL_CONTEXT;
79072805
LW
1070typedef struct block BLOCK;
1071
1072typedef struct magic MAGIC;
ed6116ce 1073typedef struct xrv XRV;
79072805
LW
1074typedef struct xpv XPV;
1075typedef struct xpviv XPVIV;
ff68c719 1076typedef struct xpvuv XPVUV;
79072805
LW
1077typedef struct xpvnv XPVNV;
1078typedef struct xpvmg XPVMG;
1079typedef struct xpvlv XPVLV;
1080typedef struct xpvav XPVAV;
1081typedef struct xpvhv XPVHV;
1082typedef struct xpvgv XPVGV;
1083typedef struct xpvcv XPVCV;
1084typedef struct xpvbm XPVBM;
1085typedef struct xpvfm XPVFM;
8990e307 1086typedef struct xpvio XPVIO;
79072805
LW
1087typedef struct mgvtbl MGVTBL;
1088typedef union any ANY;
8d063cd8 1089
378cc40b 1090#include "handy.h"
a0d0e21e 1091
873ef191
GS
1092#ifdef PERL_OBJECT
1093typedef I32 (*filter_t) _((CPerlObj*, int, SV *, int));
1094#else
16d20bd9 1095typedef I32 (*filter_t) _((int, SV *, int));
873ef191
GS
1096#endif
1097
16d20bd9 1098#define FILTER_READ(idx, sv, len) filter_read(idx, sv, len)
3280af22
NIS
1099#define FILTER_DATA(idx) (AvARRAY(PL_rsfp_filters)[idx])
1100#define FILTER_ISREADER(idx) (idx >= AvFILLp(PL_rsfp_filters))
16d20bd9 1101
748a9306 1102#ifdef DOSISH
4633a7c4
LW
1103# if defined(OS2)
1104# include "os2ish.h"
1105# else
748a9306 1106# include "dosish.h"
4633a7c4 1107# endif
a0d0e21e 1108#else
748a9306
LW
1109# if defined(VMS)
1110# include "vmsish.h"
1111# else
0c30d9ec 1112# if defined(PLAN9)
1113# include "./plan9/plan9ish.h"
1114# else
1d84e8df
JH
1115# if defined(MPE)
1116# include "mpeix/mpeixish.h"
1117# else
f756a9d6
PG
1118# if defined(__VOS__)
1119# include "vosish.h"
1120# else
1121# include "unixish.h"
1122# endif
1d84e8df 1123# endif
0c30d9ec 1124# endif
748a9306 1125# endif
32f822de
GS
1126#endif
1127
ac4c12e7
GS
1128#ifndef FUNC_NAME_TO_PTR
1129#define FUNC_NAME_TO_PTR(name) name
1130#endif
1131
32f822de 1132/*
dd96f567
IZ
1133 * USE_THREADS needs to be after unixish.h as <pthread.h> includes
1134 * <sys/signal.h> which defines NSIG - which will stop inclusion of <signal.h>
32f822de
GS
1135 * this results in many functions being undeclared which bothers C++
1136 * May make sense to have threads after "*ish.h" anyway
1137 */
1138
1139#ifdef USE_THREADS
79d59c5f
GS
1140 /* pending resolution of licensing issues, we avoid the erstwhile
1141 * atomic.h everywhere */
1142# define EMULATE_ATOMIC_REFCOUNTS
1143
32f822de
GS
1144# ifdef FAKE_THREADS
1145# include "fakethr.h"
1146# else
1147# ifdef WIN32
1148# include <win32thread.h>
1149# else
dd96f567
IZ
1150# ifdef OS2
1151# include "os2thread.h"
1152# else
6a9db2ce
BH
1153# ifdef I_MACH_CTHREADS
1154# include <mach/cthreads.h>
1155# ifdef NeXT
1156# define MUTEX_INIT_CALLS_MALLOC
1157# endif
1158typedef cthread_t perl_os_thread;
1159typedef mutex_t perl_mutex;
1160typedef condition_t perl_cond;
1161typedef void * perl_key;
1162# else /* Posix threads */
1163# include <pthread.h>
1164typedef pthread_t perl_os_thread;
1165typedef pthread_mutex_t perl_mutex;
1166typedef pthread_cond_t perl_cond;
1167typedef pthread_key_t perl_key;
1168# endif /* I_MACH_CTHREADS */
dd96f567 1169# endif /* OS2 */
32f822de
GS
1170# endif /* WIN32 */
1171# endif /* FAKE_THREADS */
1172#endif /* USE_THREADS */
1173
1174
3fc1aec6 1175
68dc0745 1176#ifdef VMS
6b88bc9c 1177# define STATUS_NATIVE PL_statusvalue_vms
68dc0745 1178# define STATUS_NATIVE_EXPORT \
6b88bc9c 1179 ((I32)PL_statusvalue_vms == -1 ? 44 : PL_statusvalue_vms)
68dc0745 1180# define STATUS_NATIVE_SET(n) \
1181 STMT_START { \
6b88bc9c
GS
1182 PL_statusvalue_vms = (n); \
1183 if ((I32)PL_statusvalue_vms == -1) \
3280af22 1184 PL_statusvalue = -1; \
6b88bc9c 1185 else if (PL_statusvalue_vms & STS$M_SUCCESS) \
3280af22 1186 PL_statusvalue = 0; \
6b88bc9c
GS
1187 else if ((PL_statusvalue_vms & STS$M_SEVERITY) == 0) \
1188 PL_statusvalue = 1 << 8; \
68dc0745 1189 else \
6b88bc9c 1190 PL_statusvalue = (PL_statusvalue_vms & STS$M_SEVERITY) << 8; \
68dc0745 1191 } STMT_END
3280af22 1192# define STATUS_POSIX PL_statusvalue
68dc0745 1193# ifdef VMSISH_STATUS
1194# define STATUS_CURRENT (VMSISH_STATUS ? STATUS_NATIVE : STATUS_POSIX)
1195# else
1196# define STATUS_CURRENT STATUS_POSIX
1197# endif
1198# define STATUS_POSIX_SET(n) \
1199 STMT_START { \
3280af22
NIS
1200 PL_statusvalue = (n); \
1201 if (PL_statusvalue != -1) { \
1202 PL_statusvalue &= 0xFFFF; \
6b88bc9c 1203 PL_statusvalue_vms = PL_statusvalue ? 44 : 1; \
68dc0745 1204 } \
6b88bc9c 1205 else PL_statusvalue_vms = -1; \
68dc0745 1206 } STMT_END
6b88bc9c
GS
1207# define STATUS_ALL_SUCCESS (PL_statusvalue = 0, PL_statusvalue_vms = 1)
1208# define STATUS_ALL_FAILURE (PL_statusvalue = 1, PL_statusvalue_vms = 44)
68dc0745 1209#else
1210# define STATUS_NATIVE STATUS_POSIX
1211# define STATUS_NATIVE_EXPORT STATUS_POSIX
1212# define STATUS_NATIVE_SET STATUS_POSIX_SET
3280af22 1213# define STATUS_POSIX PL_statusvalue
68dc0745 1214# define STATUS_POSIX_SET(n) \
1215 STMT_START { \
3280af22
NIS
1216 PL_statusvalue = (n); \
1217 if (PL_statusvalue != -1) \
1218 PL_statusvalue &= 0xFFFF; \
68dc0745 1219 } STMT_END
1220# define STATUS_CURRENT STATUS_POSIX
3280af22
NIS
1221# define STATUS_ALL_SUCCESS (PL_statusvalue = 0)
1222# define STATUS_ALL_FAILURE (PL_statusvalue = 1)
68dc0745 1223#endif
1224
3fc1aec6 1225/* Some unistd.h's give a prototype for pause() even though
1226 HAS_PAUSE ends up undefined. This causes the #define
1227 below to be rejected by the compmiler. Sigh.
1228*/
1229#ifdef HAS_PAUSE
1230#define Pause pause
1231#else
1232#define Pause() sleep((32767<<16)+32767)
748a9306
LW
1233#endif
1234
1235#ifndef IOCPARM_LEN
1236# ifdef IOCPARM_MASK
1237 /* on BSDish systes we're safe */
1238# define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
1239# else
1240 /* otherwise guess at what's safe */
1241# define IOCPARM_LEN(x) 256
1242# endif
a0d0e21e
LW
1243#endif
1244
0f4eea8f
DL
1245#ifdef UNION_ANY_DEFINITION
1246UNION_ANY_DEFINITION;
1247#else
79072805
LW
1248union any {
1249 void* any_ptr;
1250 I32 any_i32;
a0d0e21e 1251 IV any_iv;
85e6fe83 1252 long any_long;
565764a8 1253 void (CPERLscope(*any_dptr)) _((void*));
79072805 1254};
0f4eea8f 1255#endif
79072805 1256
11343788 1257#ifdef USE_THREADS
52e1cb5e 1258#define ARGSproto struct perl_thread *thr
11343788
MB
1259#else
1260#define ARGSproto void
1261#endif /* USE_THREADS */
1262
5aabfad6 1263/* Work around some cygwin32 problems with importing global symbols */
1264#if defined(CYGWIN32) && defined(DLLIMPORT)
1265# include "cw32imp.h"
1266#endif
1267
378cc40b 1268#include "regexp.h"
79072805 1269#include "sv.h"
378cc40b 1270#include "util.h"
8d063cd8 1271#include "form.h"
79072805
LW
1272#include "gv.h"
1273#include "cv.h"
1274#include "opcode.h"
1275#include "op.h"
1276#include "cop.h"
1277#include "av.h"
1278#include "hv.h"
1279#include "mg.h"
1280#include "scope.h"
d613ef02
GS
1281#include "bytecode.h"
1282#include "byterun.h"
8d063cd8 1283
7fae4e64
GS
1284/* Current curly descriptor */
1285typedef struct curcur CURCUR;
1286struct curcur {
1287 int parenfloor; /* how far back to strip paren data */
1288 int cur; /* how many instances of scan we've matched */
1289 int min; /* the minimal number of scans to match */
1290 int max; /* the maximal number of scans to match */
1291 int minmod; /* whether to work our way up or down */
1292 regnode * scan; /* the thing to match */
1293 regnode * next; /* what has to match after it */
1294 char * lastloc; /* where we started matching this scan */
1295 CURCUR * oldcc; /* current curly before we started this one */
1296};
1297
1298typedef struct _sublex_info SUBLEXINFO;
1299struct _sublex_info {
1300 I32 super_state; /* lexer state to save */
1301 I32 sub_inwhat; /* "lex_inwhat" to use */
1302 OP *sub_op; /* "lex_op" to use */
1303};
1304
76e3520e
GS
1305#ifdef PERL_OBJECT
1306struct magic_state {
1307 SV* mgs_sv;
1308 U32 mgs_flags;
1309};
1310typedef struct magic_state MGS;
1311
1312typedef struct {
1313 I32 len_min;
1314 I32 len_delta;
1315 I32 pos_min;
1316 I32 pos_delta;
1317 SV *last_found;
1318 I32 last_end; /* min value, <0 unless valid. */
1319 I32 last_start_min;
1320 I32 last_start_max;
1321 SV **longest; /* Either &l_fixed, or &l_float. */
1322 SV *longest_fixed;
1323 I32 offset_fixed;
1324 SV *longest_float;
1325 I32 offset_float_min;
1326 I32 offset_float_max;
1327 I32 flags;
1328} scan_data_t;
1329
1330typedef I32 CHECKPOINT;
1331#endif /* PERL_OBJECT */
1332
4633a7c4
LW
1333/* work around some libPW problems */
1334#ifdef DOINIT
1335EXT char Error[1];
1336#endif
1337
450a55e4 1338#if defined(iAPX286) || defined(M_I286) || defined(I80286)
a687059c
LW
1339# define I286
1340#endif
1341
fe14fcc3
LW
1342#if defined(htonl) && !defined(HAS_HTONL)
1343#define HAS_HTONL
ae986130 1344#endif
fe14fcc3
LW
1345#if defined(htons) && !defined(HAS_HTONS)
1346#define HAS_HTONS
ae986130 1347#endif
fe14fcc3
LW
1348#if defined(ntohl) && !defined(HAS_NTOHL)
1349#define HAS_NTOHL
ae986130 1350#endif
fe14fcc3
LW
1351#if defined(ntohs) && !defined(HAS_NTOHS)
1352#define HAS_NTOHS
ae986130 1353#endif
fe14fcc3 1354#ifndef HAS_HTONL
d9d8d8de 1355#if (BYTEORDER & 0xffff) != 0x4321
fe14fcc3
LW
1356#define HAS_HTONS
1357#define HAS_HTONL
1358#define HAS_NTOHS
1359#define HAS_NTOHL
a687059c
LW
1360#define MYSWAP
1361#define htons my_swap
1362#define htonl my_htonl
1363#define ntohs my_swap
1364#define ntohl my_ntohl
1365#endif
1366#else
d9d8d8de 1367#if (BYTEORDER & 0xffff) == 0x4321
fe14fcc3
LW
1368#undef HAS_HTONS
1369#undef HAS_HTONL
1370#undef HAS_NTOHS
1371#undef HAS_NTOHL
a687059c
LW
1372#endif
1373#endif
1374
988174c1
LW
1375/*
1376 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
1377 * -DWS
1378 */
1379#if BYTEORDER != 0x1234
1380# define HAS_VTOHL
1381# define HAS_VTOHS
1382# define HAS_HTOVL
1383# define HAS_HTOVS
eb1b3f19 1384# if BYTEORDER == 0x4321 || BYTEORDER == 0x87654321
988174c1
LW
1385# define vtohl(x) ((((x)&0xFF)<<24) \
1386 +(((x)>>24)&0xFF) \
1387 +(((x)&0x0000FF00)<<8) \
1388 +(((x)&0x00FF0000)>>8) )
1389# define vtohs(x) ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
1390# define htovl(x) vtohl(x)
1391# define htovs(x) vtohs(x)
1392# endif
1393 /* otherwise default to functions in util.c */
1394#endif
1395
0f85fab0 1396#ifdef CASTNEGFLOAT
79072805 1397#define U_S(what) ((U16)(what))
0f85fab0 1398#define U_I(what) ((unsigned int)(what))
79072805 1399#define U_L(what) ((U32)(what))
0f85fab0 1400#else
32f822de 1401EXTERN_C U32 cast_ulong _((double));
232e078e
AD
1402#define U_S(what) ((U16)cast_ulong((double)(what)))
1403#define U_I(what) ((unsigned int)cast_ulong((double)(what)))
1404#define U_L(what) (cast_ulong((double)(what)))
ee0007ab
LW
1405#endif
1406
ed6116ce
LW
1407#ifdef CASTI32
1408#define I_32(what) ((I32)(what))
a0d0e21e 1409#define I_V(what) ((IV)(what))
5d94fbed 1410#define U_V(what) ((UV)(what))
ed6116ce 1411#else
32f822de 1412START_EXTERN_C
a0d0e21e 1413I32 cast_i32 _((double));
a0d0e21e 1414IV cast_iv _((double));
5d94fbed 1415UV cast_uv _((double));
32f822de 1416END_EXTERN_C
a6e633de 1417#define I_32(what) (cast_i32((double)(what)))
1418#define I_V(what) (cast_iv((double)(what)))
5d94fbed 1419#define U_V(what) (cast_uv((double)(what)))
ed6116ce
LW
1420#endif
1421
79072805
LW
1422struct Outrec {
1423 I32 o_lines;
d9d8d8de 1424 char *o_str;
79072805 1425 U32 o_len;
8d063cd8
LW
1426};
1427
352d5a3a
LW
1428#ifndef MAXSYSFD
1429# define MAXSYSFD 2
1430#endif
ee0007ab 1431
f82b3d41 1432#ifndef TMPPATH
1433# define TMPPATH "/tmp/perl-eXXXXXX"
a0d0e21e 1434#endif
79072805
LW
1435
1436#ifndef __cplusplus
a0d0e21e
LW
1437Uid_t getuid _((void));
1438Uid_t geteuid _((void));
1439Gid_t getgid _((void));
1440Gid_t getegid _((void));
79072805 1441#endif
8d063cd8
LW
1442
1443#ifdef DEBUGGING
0c30d9ec 1444#ifndef Perl_debug_log
760ac839 1445#define Perl_debug_log PerlIO_stderr()
0c30d9ec 1446#endif
9d116dd7 1447#undef YYDEBUG
d96024cf 1448#define YYDEBUG 1
79072805 1449#define DEB(a) a
3280af22
NIS
1450#define DEBUG(a) if (PL_debug) a
1451#define DEBUG_p(a) if (PL_debug & 1) a
1452#define DEBUG_s(a) if (PL_debug & 2) a
1453#define DEBUG_l(a) if (PL_debug & 4) a
1454#define DEBUG_t(a) if (PL_debug & 8) a
1455#define DEBUG_o(a) if (PL_debug & 16) a
1456#define DEBUG_c(a) if (PL_debug & 32) a
1457#define DEBUG_P(a) if (PL_debug & 64) a
1458#define DEBUG_m(a) if (PL_curinterp && PL_debug & 128) a
1459#define DEBUG_f(a) if (PL_debug & 256) a
1460#define DEBUG_r(a) if (PL_debug & 512) a
1461#define DEBUG_x(a) if (PL_debug & 1024) a
1462#define DEBUG_u(a) if (PL_debug & 2048) a
1463#define DEBUG_L(a) if (PL_debug & 4096) a
1464#define DEBUG_H(a) if (PL_debug & 8192) a
1465#define DEBUG_X(a) if (PL_debug & 16384) a
1466#define DEBUG_D(a) if (PL_debug & 32768) a
8b73bbec
IZ
1467# ifdef USE_THREADS
1468# define DEBUG_S(a) if (PL_debug & (1<<16)) a
1469# else
1470# define DEBUG_S(a)
1471# endif
79072805
LW
1472#else
1473#define DEB(a)
1474#define DEBUG(a)
1475#define DEBUG_p(a)
1476#define DEBUG_s(a)
1477#define DEBUG_l(a)
1478#define DEBUG_t(a)
1479#define DEBUG_o(a)
1480#define DEBUG_c(a)
1481#define DEBUG_P(a)
1482#define DEBUG_m(a)
1483#define DEBUG_f(a)
1484#define DEBUG_r(a)
1485#define DEBUG_x(a)
1486#define DEBUG_u(a)
8b73bbec 1487#define DEBUG_S(a)
79072805
LW
1488#define DEBUG_H(a)
1489#define DEBUG_X(a)
8990e307 1490#define DEBUG_D(a)
8b73bbec 1491#define DEBUG_S(a)
8d063cd8 1492#endif
fe14fcc3 1493#define YYMAXDEPTH 300
8d063cd8 1494
a6e633de 1495#ifndef assert /* <assert.h> might have been included somehow */
79072805
LW
1496#define assert(what) DEB( { \
1497 if (!(what)) { \
463ee0b2 1498 croak("Assertion failed: file \"%s\", line %d", \
79072805 1499 __FILE__, __LINE__); \
6ad3d225 1500 PerlProc_exit(1); \
79072805 1501 }})
a6e633de 1502#endif
8d063cd8 1503
450a55e4 1504struct ufuncs {
a0d0e21e
LW
1505 I32 (*uf_val)_((IV, SV*));
1506 I32 (*uf_set)_((IV, SV*));
1507 IV uf_index;
450a55e4
LW
1508};
1509
fe14fcc3 1510/* Fix these up for __STDC__ */
68dc0745 1511#ifndef DONT_DECLARE_STD
a0d0e21e
LW
1512char *mktemp _((char*));
1513double atof _((const char*));
1514#endif
79072805 1515
352d5a3a 1516#ifndef STANDARD_C
fe14fcc3 1517/* All of these are in stdlib.h or time.h for ANSI C */
85e6fe83 1518Time_t time();
8d063cd8 1519struct tm *gmtime(), *localtime();
9d116dd7
JH
1520#ifdef OEMVS
1521char *(strchr)(), *(strrchr)();
1522char *(strcpy)(), *(strcat)();
1523#else
93a17b20 1524char *strchr(), *strrchr();
378cc40b 1525char *strcpy(), *strcat();
9d116dd7 1526#endif
352d5a3a 1527#endif /* ! STANDARD_C */
8d063cd8 1528
79072805
LW
1529
1530#ifdef I_MATH
1531# include <math.h>
1532#else
32f822de 1533START_EXTERN_C
a0d0e21e 1534 double exp _((double));
a0d0e21e 1535 double log _((double));
c635e13b 1536 double log10 _((double));
a0d0e21e 1537 double sqrt _((double));
c635e13b 1538 double frexp _((double,int*));
1539 double ldexp _((double,int));
a0d0e21e
LW
1540 double modf _((double,double*));
1541 double sin _((double));
1542 double cos _((double));
1543 double atan2 _((double,double));
1544 double pow _((double,double));
32f822de 1545END_EXTERN_C
79072805
LW
1546#endif
1547
a0d0e21e 1548#ifndef __cplusplus
26618a56 1549# ifdef __NeXT__ /* or whatever catches all NeXTs */
3fc1aec6 1550char *crypt (); /* Maybe more hosts will need the unprototyped version */
26618a56
GS
1551# else
1552# if !defined(WIN32) || !defined(HAVE_DES_FCRYPT)
a0d0e21e 1553char *crypt _((const char*, const char*));
26618a56
GS
1554# endif /* !WIN32 && !HAVE_CRYPT_SOURCE */
1555# endif /* !__NeXT__ */
1556# ifndef DONT_DECLARE_STD
1557# ifndef getenv
a0d0e21e 1558char *getenv _((const char*));
26618a56 1559# endif /* !getenv */
a0d0e21e 1560Off_t lseek _((int,Off_t,int));
26618a56 1561# endif /* !DONT_DECLARE_STD */
a0d0e21e 1562char *getlogin _((void));
26618a56 1563#endif /* !__cplusplus */
79072805 1564
16d20bd9 1565#ifdef UNLINK_ALL_VERSIONS /* Currently only makes sense for VMS */
378cc40b 1566#define UNLINK unlnk
a0d0e21e 1567I32 unlnk _((char*));
8d063cd8 1568#else
52254258 1569#define UNLINK PerlLIO_unlink
8d063cd8 1570#endif
a687059c 1571
fe14fcc3 1572#ifndef HAS_SETREUID
85e6fe83
LW
1573# ifdef HAS_SETRESUID
1574# define setreuid(r,e) setresuid(r,e,(Uid_t)-1)
1575# define HAS_SETREUID
1576# endif
a687059c 1577#endif
fe14fcc3 1578#ifndef HAS_SETREGID
85e6fe83
LW
1579# ifdef HAS_SETRESGID
1580# define setregid(r,e) setresgid(r,e,(Gid_t)-1)
1581# define HAS_SETREGID
1582# endif
a687059c 1583#endif
ee0007ab 1584
ff68c719 1585typedef Signal_t (*Sighandler_t) _((int));
1586
1587#ifdef HAS_SIGACTION
1588typedef struct sigaction Sigsave_t;
1589#else
1590typedef Sighandler_t Sigsave_t;
1591#endif
1592
ee0007ab
LW
1593#define SCAN_DEF 0
1594#define SCAN_TR 1
1595#define SCAN_REPL 2
79072805
LW
1596
1597#ifdef DEBUGGING
4633a7c4 1598# ifndef register
a0d0e21e
LW
1599# define register
1600# endif
1601# define PAD_SV(po) pad_sv(po)
2ddcc7aa 1602# define RUNOPS_DEFAULT runops_debug
79072805 1603#else
6b88bc9c 1604# define PAD_SV(po) PL_curpad[po]
2ddcc7aa 1605# define RUNOPS_DEFAULT runops_standard
79072805
LW
1606#endif
1607
18f739ee 1608#ifdef MYMALLOC
6a9db2ce
BH
1609# ifdef MUTEX_INIT_CALLS_MALLOC
1610# define MALLOC_INIT \
1611 STMT_START { \
1612 PL_malloc_mutex = NULL; \
1613 MUTEX_INIT(&PL_malloc_mutex); \
1614 } STMT_END
1615# define MALLOC_TERM \
1616 STMT_START { \
1617 perl_mutex tmp = PL_malloc_mutex; \
1618 PL_malloc_mutex = NULL; \
1619 MUTEX_DESTROY(&tmp); \
1620 } STMT_END
1621# else
1622# define MALLOC_INIT MUTEX_INIT(&PL_malloc_mutex)
1623# define MALLOC_TERM MUTEX_DESTROY(&PL_malloc_mutex)
1624# endif
18f739ee
IZ
1625#else
1626# define MALLOC_INIT
1627# define MALLOC_TERM
1628#endif
1629
b6d9d515 1630
44a0ac01
MB
1631/*
1632 * These need prototyping here because <proto.h> isn't
1633 * included until after runops is initialised.
1634 */
1635
76e3520e 1636#ifndef PERL_OBJECT
49f531da 1637typedef int runops_proc_t _((void));
44a0ac01
MB
1638int runops_standard _((void));
1639#ifdef DEBUGGING
1640int runops_debug _((void));
1641#endif
76e3520e 1642#endif /* PERL_OBJECT */
44a0ac01 1643
940cb80d 1644/* _ (for $_) must be first in the following list (DEFSV requires it) */
54b9620d 1645#define THREADSV_NAMES "_123456789&`'+/.,\\\";^-%=|~:\001\005!@"
a863c7d1 1646
0c30d9ec 1647/* VMS doesn't use environ array and NeXT has problems with crt0.o globals */
1648#if !defined(VMS) && !(defined(NeXT) && defined(__DYNAMIC__))
16de4a3e
RS
1649#if !defined(DONT_DECLARE_STD) \
1650 || (defined(__svr4__) && defined(__GNUC__) && defined(sun)) \
1651 || defined(__sgi) || defined(__DGUX)
79072805 1652extern char ** environ; /* environment variables supplied via exec */
a0d0e21e 1653#endif
0c30d9ec 1654#else
1655# if defined(NeXT) && defined(__DYNAMIC__)
1656
1657# include <mach-o/dyld.h>
1658EXT char *** environ_pointer;
1659# define environ (*environ_pointer)
1660# endif
1661#endif /* environ processing */
1662
79072805
LW
1663
1664/* for tmp use in stupid debuggers */
1665EXT int * di;
1666EXT short * ds;
1667EXT char * dc;
1668
1669/* handy constants */
3e3baf6d 1670EXTCONST char warn_uninit[]
a0d0e21e 1671 INIT("Use of uninitialized value");
3e3baf6d 1672EXTCONST char warn_nosemi[]
463ee0b2 1673 INIT("Semicolon seems to be missing");
3e3baf6d 1674EXTCONST char warn_reserved[]
463ee0b2 1675 INIT("Unquoted string \"%s\" may clash with future reserved word");
3e3baf6d 1676EXTCONST char warn_nl[]
93a17b20 1677 INIT("Unsuccessful %s on filename containing newline");
3e3baf6d 1678EXTCONST char no_wrongref[]
a0d0e21e 1679 INIT("Can't use %s ref as %s ref");
3e3baf6d 1680EXTCONST char no_symref[]
748a9306 1681 INIT("Can't use string (\"%.32s\") as %s ref while \"strict refs\" in use");
3e3baf6d 1682EXTCONST char no_usym[]
8990e307 1683 INIT("Can't use an undefined value as %s reference");
3e3baf6d 1684EXTCONST char no_aelem[]
93a17b20 1685 INIT("Modification of non-creatable array value attempted, subscript %d");
3e3baf6d 1686EXTCONST char no_helem[]
93a17b20 1687 INIT("Modification of non-creatable hash value attempted, subscript \"%s\"");
3e3baf6d 1688EXTCONST char no_modify[]
93a17b20 1689 INIT("Modification of a read-only value attempted");
3e3baf6d 1690EXTCONST char no_mem[]
93a17b20 1691 INIT("Out of memory!\n");
3e3baf6d 1692EXTCONST char no_security[]
463ee0b2 1693 INIT("Insecure dependency in %s%s");
3e3baf6d 1694EXTCONST char no_sock_func[]
93a17b20 1695 INIT("Unsupported socket function \"%s\" called");
3e3baf6d 1696EXTCONST char no_dir_func[]
93a17b20 1697 INIT("Unsupported directory function \"%s\" called");
3e3baf6d 1698EXTCONST char no_func[]
93a17b20 1699 INIT("The %s function is unimplemented");
3e3baf6d 1700EXTCONST char no_myglob[]
748a9306 1701 INIT("\"my\" variable %s can't be in a package");
93a17b20 1702
79072805 1703#ifdef DOINIT
8e07c86e
AD
1704EXT char *sig_name[] = { SIG_NAME };
1705EXT int sig_num[] = { SIG_NUM };
0c30d9ec 1706EXT SV * psig_ptr[sizeof(sig_num)/sizeof(*sig_num)];
1707EXT SV * psig_name[sizeof(sig_num)/sizeof(*sig_num)];
79072805
LW
1708#else
1709EXT char *sig_name[];
8e07c86e 1710EXT int sig_num[];
0c30d9ec 1711EXT SV * psig_ptr[];
1712EXT SV * psig_name[];
79072805
LW
1713#endif
1714
bbce6d69 1715/* fast case folding tables */
1716
79072805 1717#ifdef DOINIT
9d116dd7
JH
1718#ifdef EBCDIC
1719EXT unsigned char fold[] = { /* fast EBCDIC case folding table */
1720 0, 1, 2, 3, 4, 5, 6, 7,
1721 8, 9, 10, 11, 12, 13, 14, 15,
1722 16, 17, 18, 19, 20, 21, 22, 23,
1723 24, 25, 26, 27, 28, 29, 30, 31,
1724 32, 33, 34, 35, 36, 37, 38, 39,
1725 40, 41, 42, 43, 44, 45, 46, 47,
1726 48, 49, 50, 51, 52, 53, 54, 55,
1727 56, 57, 58, 59, 60, 61, 62, 63,
1728 64, 65, 66, 67, 68, 69, 70, 71,
1729 72, 73, 74, 75, 76, 77, 78, 79,
1730 80, 81, 82, 83, 84, 85, 86, 87,
1731 88, 89, 90, 91, 92, 93, 94, 95,
1732 96, 97, 98, 99, 100, 101, 102, 103,
1733 104, 105, 106, 107, 108, 109, 110, 111,
1734 112, 113, 114, 115, 116, 117, 118, 119,
1735 120, 121, 122, 123, 124, 125, 126, 127,
1736 128, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
1737 'H', 'I', 138, 139, 140, 141, 142, 143,
1738 144, 'J', 'K', 'L', 'M', 'N', 'O', 'P',
1739 'Q', 'R', 154, 155, 156, 157, 158, 159,
1740 160, 161, 'S', 'T', 'U', 'V', 'W', 'X',
1741 'Y', 'Z', 170, 171, 172, 173, 174, 175,
1742 176, 177, 178, 179, 180, 181, 182, 183,
1743 184, 185, 186, 187, 188, 189, 190, 191,
1744 192, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
1745 'h', 'i', 202, 203, 204, 205, 206, 207,
1746 208, 'j', 'k', 'l', 'm', 'n', 'o', 'p',
1747 'q', 'r', 218, 219, 220, 221, 222, 223,
1748 224, 225, 's', 't', 'u', 'v', 'w', 'x',
1749 'y', 'z', 234, 235, 236, 237, 238, 239,
1750 240, 241, 242, 243, 244, 245, 246, 247,
1751 248, 249, 250, 251, 252, 253, 254, 255
1752};
1753#else /* ascii rather than ebcdic */
36477c24 1754EXTCONST unsigned char fold[] = {
79072805
LW
1755 0, 1, 2, 3, 4, 5, 6, 7,
1756 8, 9, 10, 11, 12, 13, 14, 15,
1757 16, 17, 18, 19, 20, 21, 22, 23,
1758 24, 25, 26, 27, 28, 29, 30, 31,
1759 32, 33, 34, 35, 36, 37, 38, 39,
1760 40, 41, 42, 43, 44, 45, 46, 47,
1761 48, 49, 50, 51, 52, 53, 54, 55,
1762 56, 57, 58, 59, 60, 61, 62, 63,
1763 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
1764 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
1765 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
1766 'x', 'y', 'z', 91, 92, 93, 94, 95,
1767 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
1768 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
1769 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
1770 'X', 'Y', 'Z', 123, 124, 125, 126, 127,
1771 128, 129, 130, 131, 132, 133, 134, 135,
1772 136, 137, 138, 139, 140, 141, 142, 143,
1773 144, 145, 146, 147, 148, 149, 150, 151,
1774 152, 153, 154, 155, 156, 157, 158, 159,
1775 160, 161, 162, 163, 164, 165, 166, 167,
1776 168, 169, 170, 171, 172, 173, 174, 175,
1777 176, 177, 178, 179, 180, 181, 182, 183,
1778 184, 185, 186, 187, 188, 189, 190, 191,
1779 192, 193, 194, 195, 196, 197, 198, 199,
1780 200, 201, 202, 203, 204, 205, 206, 207,
1781 208, 209, 210, 211, 212, 213, 214, 215,
1782 216, 217, 218, 219, 220, 221, 222, 223,
1783 224, 225, 226, 227, 228, 229, 230, 231,
1784 232, 233, 234, 235, 236, 237, 238, 239,
1785 240, 241, 242, 243, 244, 245, 246, 247,
1786 248, 249, 250, 251, 252, 253, 254, 255
1787};
9d116dd7 1788#endif /* !EBCDIC */
79072805 1789#else
71be2cbc 1790EXTCONST unsigned char fold[];
79072805
LW
1791#endif
1792
1793#ifdef DOINIT
bbce6d69 1794EXT unsigned char fold_locale[] = {
79072805
LW
1795 0, 1, 2, 3, 4, 5, 6, 7,
1796 8, 9, 10, 11, 12, 13, 14, 15,
1797 16, 17, 18, 19, 20, 21, 22, 23,
1798 24, 25, 26, 27, 28, 29, 30, 31,
1799 32, 33, 34, 35, 36, 37, 38, 39,
1800 40, 41, 42, 43, 44, 45, 46, 47,
1801 48, 49, 50, 51, 52, 53, 54, 55,
1802 56, 57, 58, 59, 60, 61, 62, 63,
1803 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
1804 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
1805 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
1806 'x', 'y', 'z', 91, 92, 93, 94, 95,
1807 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
1808 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
1809 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
1810 'X', 'Y', 'Z', 123, 124, 125, 126, 127,
1811 128, 129, 130, 131, 132, 133, 134, 135,
1812 136, 137, 138, 139, 140, 141, 142, 143,
1813 144, 145, 146, 147, 148, 149, 150, 151,
1814 152, 153, 154, 155, 156, 157, 158, 159,
1815 160, 161, 162, 163, 164, 165, 166, 167,
1816 168, 169, 170, 171, 172, 173, 174, 175,
1817 176, 177, 178, 179, 180, 181, 182, 183,
1818 184, 185, 186, 187, 188, 189, 190, 191,
1819 192, 193, 194, 195, 196, 197, 198, 199,
1820 200, 201, 202, 203, 204, 205, 206, 207,
1821 208, 209, 210, 211, 212, 213, 214, 215,
1822 216, 217, 218, 219, 220, 221, 222, 223,
1823 224, 225, 226, 227, 228, 229, 230, 231,
1824 232, 233, 234, 235, 236, 237, 238, 239,
1825 240, 241, 242, 243, 244, 245, 246, 247,
1826 248, 249, 250, 251, 252, 253, 254, 255
1827};
1828#else
bbce6d69 1829EXT unsigned char fold_locale[];
79072805
LW
1830#endif
1831
1832#ifdef DOINIT
9d116dd7
JH
1833#ifdef EBCDIC
1834EXT unsigned char freq[] = {/* EBCDIC frequencies for mixed English/C */
1835 1, 2, 84, 151, 154, 155, 156, 157,
1836 165, 246, 250, 3, 158, 7, 18, 29,
1837 40, 51, 62, 73, 85, 96, 107, 118,
1838 129, 140, 147, 148, 149, 150, 152, 153,
1839 255, 6, 8, 9, 10, 11, 12, 13,
1840 14, 15, 24, 25, 26, 27, 28, 226,
1841 29, 30, 31, 32, 33, 43, 44, 45,
1842 46, 47, 48, 49, 50, 76, 77, 78,
1843 79, 80, 81, 82, 83, 84, 85, 86,
1844 87, 94, 95, 234, 181, 233, 187, 190,
1845 180, 96, 97, 98, 99, 100, 101, 102,
1846 104, 112, 182, 174, 236, 232, 229, 103,
1847 228, 226, 114, 115, 116, 117, 118, 119,
1848 120, 121, 122, 235, 176, 230, 194, 162,
1849 130, 131, 132, 133, 134, 135, 136, 137,
1850 138, 139, 201, 205, 163, 217, 220, 224,
1851 5, 248, 227, 244, 242, 255, 241, 231,
1852 240, 253, 16, 197, 19, 20, 21, 187,
1853 23, 169, 210, 245, 237, 249, 247, 239,
1854 168, 252, 34, 196, 36, 37, 38, 39,
1855 41, 42, 251, 254, 238, 223, 221, 213,
1856 225, 177, 52, 53, 54, 55, 56, 57,
1857 58, 59, 60, 61, 63, 64, 65, 66,
1858 67, 68, 69, 70, 71, 72, 74, 75,
1859 205, 208, 186, 202, 200, 218, 198, 179,
1860 178, 214, 88, 89, 90, 91, 92, 93,
1861 217, 166, 170, 207, 199, 209, 206, 204,
1862 160, 212, 105, 106, 108, 109, 110, 111,
1863 203, 113, 216, 215, 192, 175, 193, 243,
1864 172, 161, 123, 124, 125, 126, 127, 128,
1865 222, 219, 211, 195, 188, 193, 185, 184,
1866 191, 183, 141, 142, 143, 144, 145, 146
1867};
1868#else /* ascii rather than ebcdic */
71be2cbc 1869EXTCONST unsigned char freq[] = { /* letter frequencies for mixed English/C */
79072805
LW
1870 1, 2, 84, 151, 154, 155, 156, 157,
1871 165, 246, 250, 3, 158, 7, 18, 29,
1872 40, 51, 62, 73, 85, 96, 107, 118,
1873 129, 140, 147, 148, 149, 150, 152, 153,
1874 255, 182, 224, 205, 174, 176, 180, 217,
1875 233, 232, 236, 187, 235, 228, 234, 226,
1876 222, 219, 211, 195, 188, 193, 185, 184,
1877 191, 183, 201, 229, 181, 220, 194, 162,
1878 163, 208, 186, 202, 200, 218, 198, 179,
1879 178, 214, 166, 170, 207, 199, 209, 206,
1880 204, 160, 212, 216, 215, 192, 175, 173,
1881 243, 172, 161, 190, 203, 189, 164, 230,
1882 167, 248, 227, 244, 242, 255, 241, 231,
1883 240, 253, 169, 210, 245, 237, 249, 247,
1884 239, 168, 252, 251, 254, 238, 223, 221,
1885 213, 225, 177, 197, 171, 196, 159, 4,
1886 5, 6, 8, 9, 10, 11, 12, 13,
1887 14, 15, 16, 17, 19, 20, 21, 22,
1888 23, 24, 25, 26, 27, 28, 30, 31,
1889 32, 33, 34, 35, 36, 37, 38, 39,
1890 41, 42, 43, 44, 45, 46, 47, 48,
1891 49, 50, 52, 53, 54, 55, 56, 57,
1892 58, 59, 60, 61, 63, 64, 65, 66,
1893 67, 68, 69, 70, 71, 72, 74, 75,
1894 76, 77, 78, 79, 80, 81, 82, 83,
1895 86, 87, 88, 89, 90, 91, 92, 93,
1896 94, 95, 97, 98, 99, 100, 101, 102,
1897 103, 104, 105, 106, 108, 109, 110, 111,
1898 112, 113, 114, 115, 116, 117, 119, 120,
1899 121, 122, 123, 124, 125, 126, 127, 128,
1900 130, 131, 132, 133, 134, 135, 136, 137,
1901 138, 139, 141, 142, 143, 144, 145, 146
1902};
9d116dd7 1903#endif
79072805 1904#else
71be2cbc 1905EXTCONST unsigned char freq[];
79072805
LW
1906#endif
1907
8990e307
LW
1908#ifdef DEBUGGING
1909#ifdef DOINIT
71be2cbc 1910EXTCONST char* block_type[] = {
8990e307
LW
1911 "NULL",
1912 "SUB",
1913 "EVAL",
1914 "LOOP",
1915 "SUBST",
1916 "BLOCK",
1917};
1918#else
71be2cbc 1919EXTCONST char* block_type[];
8990e307
LW
1920#endif
1921#endif
1922
79072805
LW
1923/*****************************************************************************/
1924/* This lexer/parser stuff is currently global since yacc is hard to reenter */
1925/*****************************************************************************/
8990e307 1926/* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */
79072805 1927
a0d0e21e
LW
1928#include "perly.h"
1929
fb73857a 1930#define LEX_NOTPARSING 11 /* borrowed from toke.c */
1931
79072805
LW
1932typedef enum {
1933 XOPERATOR,
1934 XTERM,
79072805 1935 XREF,
8990e307 1936 XSTATE,
a0d0e21e
LW
1937 XBLOCK,
1938 XTERMBLOCK
79072805
LW
1939} expectation;
1940
f9caadc6
DL
1941enum { /* pass one of these to get_vtbl */
1942 want_vtbl_sv,
1943 want_vtbl_env,
1944 want_vtbl_envelem,
1945 want_vtbl_sig,
1946 want_vtbl_sigelem,
1947 want_vtbl_pack,
1948 want_vtbl_packelem,
1949 want_vtbl_dbline,
1950 want_vtbl_isa,
1951 want_vtbl_isaelem,
1952 want_vtbl_arylen,
1953 want_vtbl_glob,
1954 want_vtbl_mglob,
1955 want_vtbl_nkeys,
1956 want_vtbl_taint,
1957 want_vtbl_substr,
1958 want_vtbl_vec,
1959 want_vtbl_pos,
1960 want_vtbl_bm,
1961 want_vtbl_fm,
1962 want_vtbl_uvar,
1963 want_vtbl_defelem,
1964 want_vtbl_regexp,
1965 want_vtbl_collxfrm,
1966 want_vtbl_amagic,
0a42b372 1967 want_vtbl_amagicelem
f9caadc6 1968#ifdef USE_THREADS
0a42b372
GB
1969 ,
1970 want_vtbl_mutex
f9caadc6
DL
1971#endif
1972};
1973
85e6fe83
LW
1974
1975 /* Note: the lowest 8 bits are reserved for
1976 stuffing into op->op_private */
1977#define HINT_INTEGER 0x00000001
1978#define HINT_STRICT_REFS 0x00000002
1979
1980#define HINT_BLOCK_SCOPE 0x00000100
1981#define HINT_STRICT_SUBS 0x00000200
1982#define HINT_STRICT_VARS 0x00000400
bbce6d69 1983#define HINT_LOCALE 0x00000800
85e6fe83 1984
b3ac6de7
IZ
1985#define HINT_NEW_INTEGER 0x00001000
1986#define HINT_NEW_FLOAT 0x00002000
1987#define HINT_NEW_BINARY 0x00004000
1988#define HINT_NEW_STRING 0x00008000
1989#define HINT_NEW_RE 0x00010000
1990#define HINT_LOCALIZE_HH 0x00020000 /* %^H needs to be copied */
1991
b3eb6a9b 1992#define HINT_RE_TAINT 0x00100000
e4d48cc9 1993#define HINT_RE_EVAL 0x00200000
b3eb6a9b 1994
d4cce5f1
NIS
1995/* Various states of an input record separator SV (rs, nrs) */
1996#define RsSNARF(sv) (! SvOK(sv))
1997#define RsSIMPLE(sv) (SvOK(sv) && SvCUR(sv))
1998#define RsPARA(sv) (SvOK(sv) && ! SvCUR(sv))
5b2b9c68 1999#define RsRECORD(sv) (SvROK(sv) && (SvIV(SvRV(sv)) > 0))
79072805 2000
56953603 2001/* Enable variables which are pointers to functions */
15e52e56
GS
2002#ifdef PERL_OBJECT
2003typedef regexp*(CPerlObj::*regcomp_t) _((char* exp, char* xend, PMOP* pm));
2004typedef I32 (CPerlObj::*regexec_t) _((regexp* prog, char* stringarg,
2005 char* strend, char* strbeg,
2006 I32 minend, SV* screamer, void* data,
2007 U32 flags));
2008#else
56953603
IZ
2009typedef regexp*(*regcomp_t) _((char* exp, char* xend, PMOP* pm));
2010typedef I32 (*regexec_t) _((regexp* prog, char* stringarg, char* strend, char*
2011 strbeg, I32 minend, SV* screamer, void* data,
2012 U32 flags));
2013
15e52e56
GS
2014#endif
2015
22239a37
NIS
2016/* Set up PERLVAR macros for populating structs */
2017#define PERLVAR(var,type) type var;
2018#define PERLVARI(var,type,init) type var;
3fe35a81 2019#define PERLVARIC(var,type,init) type var;
22239a37 2020
58a50f62
GS
2021/* Interpreter exitlist entry */
2022typedef struct exitlistentry {
2023#ifdef PERL_OBJECT
2024 void (*fn) _((CPerlObj*, void*));
2025#else
2026 void (*fn) _((void*));
2027#endif
2028 void *ptr;
2029} PerlExitListEntry;
2030
76e3520e
GS
2031#ifdef PERL_OBJECT
2032extern "C" CPerlObj* perl_alloc _((IPerlMem*, IPerlEnv*, IPerlStdIO*, IPerlLIO*, IPerlDir*, IPerlSock*, IPerlProc*));
2033
2034typedef int (CPerlObj::*runops_proc_t) _((void));
2035#undef EXT
2036#define EXT
2037#undef EXTCONST
2038#define EXTCONST
2039#undef INIT
2040#define INIT(x)
2041
2042class CPerlObj {
2043public:
2044 CPerlObj(IPerlMem*, IPerlEnv*, IPerlStdIO*, IPerlLIO*, IPerlDir*, IPerlSock*, IPerlProc*);
2045 void Init(void);
2046 void* operator new(size_t nSize, IPerlMem *pvtbl);
2047#endif /* PERL_OBJECT */
2048
22239a37
NIS
2049#ifdef PERL_GLOBAL_STRUCT
2050struct perl_vars {
2051#include "perlvars.h"
2052};
2053
2054#ifdef PERL_CORE
533c011a
NIS
2055EXT struct perl_vars PL_Vars;
2056EXT struct perl_vars *PL_VarsPtr INIT(&PL_Vars);
2057#else /* PERL_CORE */
22239a37
NIS
2058#if !defined(__GNUC__) || !defined(WIN32)
2059EXT
533c011a
NIS
2060#endif /* WIN32 */
2061struct perl_vars *PL_VarsPtr;
2062#define PL_Vars (*((PL_VarsPtr) ? PL_VarsPtr : (PL_VarsPtr = Perl_GetVars())))
2063#endif /* PERL_CORE */
22239a37
NIS
2064#endif /* PERL_GLOBAL_STRUCT */
2065
8990e307 2066#ifdef MULTIPLICITY
d4cce5f1
NIS
2067/* If we have multiple interpreters define a struct
2068 holding variables which must be per-interpreter
2069 If we don't have threads anything that would have
2070 be per-thread is per-interpreter.
2071*/
2072
79072805 2073struct interpreter {
d4cce5f1
NIS
2074#ifndef USE_THREADS
2075#include "thrdvar.h"
2076#endif
2077#include "intrpvar.h"
49f531da 2078};
d4cce5f1 2079
79072805 2080#else
49f531da
NIS
2081struct interpreter {
2082 char broiled;
2083};
79072805
LW
2084#endif
2085
d4cce5f1
NIS
2086#ifdef USE_THREADS
2087/* If we have threads define a struct with all the variables
2088 * that have to be per-thread
49f531da 2089 */
8023c3ce 2090
79072805 2091
49f531da 2092struct perl_thread {
49f531da 2093#include "thrdvar.h"
79072805 2094};
d4cce5f1 2095
22fae026
TM
2096typedef struct perl_thread *Thread;
2097
2098#else
2099typedef void *Thread;
22239a37
NIS
2100#endif
2101
2102/* Done with PERLVAR macros for now ... */
d4cce5f1
NIS
2103#undef PERLVAR
2104#undef PERLVARI
3fe35a81 2105#undef PERLVARIC
79072805 2106
22239a37 2107#include "thread.h"
79072805 2108#include "pp.h"
79072805
LW
2109#include "proto.h"
2110
a0d0e21e
LW
2111#ifdef EMBED
2112#define Perl_sv_setptrobj(rv,ptr,name) Perl_sv_setref_iv(rv,name,(IV)ptr)
2113#define Perl_sv_setptrref(rv,ptr) Perl_sv_setref_iv(rv,Nullch,(IV)ptr)
2114#else
2115#define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,(IV)ptr)
2116#define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,(IV)ptr)
2117#endif
2118
d4cce5f1
NIS
2119/* The following must follow proto.h as #defines mess up syntax */
2120
2121#include "embedvar.h"
2122
2123/* Now include all the 'global' variables
2124 * If we don't have threads or multiple interpreters
2125 * these include variables that would have been their struct-s
2126 */
533c011a
NIS
2127
2128#define PERLVAR(var,type) EXT type PL_##var;
2129#define PERLVARI(var,type,init) EXT type PL_##var INIT(init);
2130#define PERLVARIC(var,type,init) EXTCONST type PL_##var INIT(init);
d4cce5f1 2131
22239a37 2132#ifndef PERL_GLOBAL_STRUCT
d4cce5f1 2133#include "perlvars.h"
22239a37 2134#endif
d4cce5f1
NIS
2135
2136#ifndef MULTIPLICITY
d4cce5f1 2137
066ef5b5
GS
2138# include "intrpvar.h"
2139# ifndef USE_THREADS
2140# include "thrdvar.h"
2141# endif
d4cce5f1 2142
22239a37
NIS
2143#endif
2144
76e3520e 2145#ifdef PERL_OBJECT
52254258
GS
2146/* from perly.c */
2147#undef yydebug
2148#undef yynerrs
2149#undef yyerrflag
2150#undef yychar
2151#undef yyssp
2152#undef yyvsp
2153#undef yyval
2154#undef yylval
2155#define yydebug PL_yydebug
2156#define yynerrs PL_yynerrs
2157#define yyerrflag PL_yyerrflag
2158#define yychar PL_yychar
2159#define yyssp PL_yyssp
2160#define yyvsp PL_yyvsp
2161#define yyval PL_yyval
2162#define yylval PL_yylval
2163PERLVAR(yydebug, int)
2164PERLVAR(yynerrs, int)
2165PERLVAR(yyerrflag, int)
2166PERLVAR(yychar, int)
2167PERLVAR(yyssp, short*)
2168PERLVAR(yyvsp, YYSTYPE*)
2169PERLVAR(yyval, YYSTYPE)
2170PERLVAR(yylval, YYSTYPE)
2171
2172#define efloatbuf PL_efloatbuf
2173#define efloatsize PL_efloatsize
2174PERLVAR(efloatbuf, char *)
2175PERLVAR(efloatsize, STRLEN)
2176
2177#define glob_index PL_glob_index
2178#define srand_called PL_srand_called
2179#define uudmap PL_uudmap
2180#define bitcount PL_bitcount
2181#define filter_debug PL_filter_debug
2182PERLVAR(glob_index, int)
2183PERLVAR(srand_called, bool)
2184PERLVAR(uudmap[256], char)
2185PERLVAR(bitcount, char*)
2186PERLVAR(filter_debug, int)
2187
2188
d0c1b099
GS
2189/*
2190 * The following is a buffer where new variables must
2191 * be defined to maintain binary compatibility with PERL_OBJECT
2192 * for 5.005
2193 */
2194PERLVAR(object_compatibility[30], char)
76e3520e
GS
2195};
2196
2197#include "objpp.h"
2198#ifdef DOINIT
2199#include "INTERN.h"
2200#else
2201#include "EXTERN.h"
2202#endif
2203#endif /* PERL_OBJECT */
2204
22239a37 2205
d4cce5f1
NIS
2206#undef PERLVAR
2207#undef PERLVARI
0f3f18a6 2208#undef PERLVARIC
79072805 2209
a835ef8a
NIS
2210#if defined(HASATTRIBUTE) && defined(WIN32)
2211/*
2212 * This provides a layer of functions and macros to ensure extensions will
2213 * get to use the same RTL functions as the core.
2214 * It has to go here or #define of printf messes up __attribute__
2215 * stuff in proto.h
2216 */
76e3520e 2217#ifndef PERL_OBJECT
a835ef8a 2218# include <win32iop.h>
76e3520e 2219#endif /* PERL_OBJECT */
a835ef8a
NIS
2220#endif /* WIN32 */
2221
79072805 2222#ifdef DOINIT
bbce6d69 2223
4633a7c4 2224EXT MGVTBL vtbl_sv = {magic_get,
463ee0b2
LW
2225 magic_set,
2226 magic_len,
2227 0, 0};
fb73857a 2228EXT MGVTBL vtbl_env = {0, magic_set_all_env,
2229 0, magic_clear_all_env,
66b1d557 2230 0};
4633a7c4 2231EXT MGVTBL vtbl_envelem = {0, magic_setenv,
85e6fe83
LW
2232 0, magic_clearenv,
2233 0};
4633a7c4 2234EXT MGVTBL vtbl_sig = {0, 0, 0, 0, 0};
0c30d9ec 2235EXT MGVTBL vtbl_sigelem = {magic_getsig,
2236 magic_setsig,
2237 0, magic_clearsig,
2238 0};
93965878 2239EXT MGVTBL vtbl_pack = {0, 0, magic_sizepack, magic_wipepack,
a0d0e21e 2240 0};
4633a7c4 2241EXT MGVTBL vtbl_packelem = {magic_getpack,
463ee0b2
LW
2242 magic_setpack,
2243 0, magic_clearpack,
2244 0};
4633a7c4 2245EXT MGVTBL vtbl_dbline = {0, magic_setdbline,
463ee0b2 2246 0, 0, 0};
4633a7c4 2247EXT MGVTBL vtbl_isa = {0, magic_setisa,
fb73857a 2248 0, magic_setisa,
2249 0};
4633a7c4 2250EXT MGVTBL vtbl_isaelem = {0, magic_setisa,
463ee0b2 2251 0, 0, 0};
4633a7c4 2252EXT MGVTBL vtbl_arylen = {magic_getarylen,
463ee0b2
LW
2253 magic_setarylen,
2254 0, 0, 0};
4633a7c4 2255EXT MGVTBL vtbl_glob = {magic_getglob,
463ee0b2
LW
2256 magic_setglob,
2257 0, 0, 0};
4633a7c4 2258EXT MGVTBL vtbl_mglob = {0, magic_setmglob,
463ee0b2 2259 0, 0, 0};
6ff81951
GS
2260EXT MGVTBL vtbl_nkeys = {magic_getnkeys,
2261 magic_setnkeys,
99abf803 2262 0, 0, 0};
4633a7c4 2263EXT MGVTBL vtbl_taint = {magic_gettaint,magic_settaint,
463ee0b2 2264 0, 0, 0};
6ff81951 2265EXT MGVTBL vtbl_substr = {magic_getsubstr, magic_setsubstr,
463ee0b2 2266 0, 0, 0};
6ff81951
GS
2267EXT MGVTBL vtbl_vec = {magic_getvec,
2268 magic_setvec,
463ee0b2 2269 0, 0, 0};
4633a7c4 2270EXT MGVTBL vtbl_pos = {magic_getpos,
a0d0e21e
LW
2271 magic_setpos,
2272 0, 0, 0};
4633a7c4 2273EXT MGVTBL vtbl_bm = {0, magic_setbm,
463ee0b2 2274 0, 0, 0};
55497cff 2275EXT MGVTBL vtbl_fm = {0, magic_setfm,
2276 0, 0, 0};
4633a7c4 2277EXT MGVTBL vtbl_uvar = {magic_getuvar,
463ee0b2
LW
2278 magic_setuvar,
2279 0, 0, 0};
f93b4edd
MB
2280#ifdef USE_THREADS
2281EXT MGVTBL vtbl_mutex = {0, 0, 0, 0, magic_mutexfree};
2282#endif /* USE_THREADS */
68dc0745 2283EXT MGVTBL vtbl_defelem = {magic_getdefelem,magic_setdefelem,
02270b4e 2284 0, 0, 0};
a0d0e21e 2285
227a8b4b 2286EXT MGVTBL vtbl_regexp = {0,0,0,0, magic_freeregexp};
c277df42 2287
36477c24 2288#ifdef USE_LOCALE_COLLATE
bbce6d69 2289EXT MGVTBL vtbl_collxfrm = {0,
2290 magic_setcollxfrm,
2291 0, 0, 0};
2292#endif
a0d0e21e
LW
2293
2294#ifdef OVERLOAD
4633a7c4 2295EXT MGVTBL vtbl_amagic = {0, magic_setamagic,
748a9306 2296 0, 0, magic_setamagic};
4633a7c4 2297EXT MGVTBL vtbl_amagicelem = {0, magic_setamagic,
748a9306 2298 0, 0, magic_setamagic};
a0d0e21e
LW
2299#endif /* OVERLOAD */
2300
bbce6d69 2301#else /* !DOINIT */
2302
79072805
LW
2303EXT MGVTBL vtbl_sv;
2304EXT MGVTBL vtbl_env;
2305EXT MGVTBL vtbl_envelem;
2306EXT MGVTBL vtbl_sig;
2307EXT MGVTBL vtbl_sigelem;
463ee0b2
LW
2308EXT MGVTBL vtbl_pack;
2309EXT MGVTBL vtbl_packelem;
79072805 2310EXT MGVTBL vtbl_dbline;
463ee0b2
LW
2311EXT MGVTBL vtbl_isa;
2312EXT MGVTBL vtbl_isaelem;
79072805
LW
2313EXT MGVTBL vtbl_arylen;
2314EXT MGVTBL vtbl_glob;
93a17b20 2315EXT MGVTBL vtbl_mglob;
99abf803 2316EXT MGVTBL vtbl_nkeys;
463ee0b2 2317EXT MGVTBL vtbl_taint;
79072805
LW
2318EXT MGVTBL vtbl_substr;
2319EXT MGVTBL vtbl_vec;
a0d0e21e 2320EXT MGVTBL vtbl_pos;
79072805 2321EXT MGVTBL vtbl_bm;
55497cff 2322EXT MGVTBL vtbl_fm;
79072805 2323EXT MGVTBL vtbl_uvar;
a0d0e21e 2324
f93b4edd
MB
2325#ifdef USE_THREADS
2326EXT MGVTBL vtbl_mutex;
2327#endif /* USE_THREADS */
2328
68dc0745 2329EXT MGVTBL vtbl_defelem;
c277df42 2330EXT MGVTBL vtbl_regexp;
a0d0e21e 2331
36477c24 2332#ifdef USE_LOCALE_COLLATE
bbce6d69 2333EXT MGVTBL vtbl_collxfrm;
2334#endif
a0d0e21e
LW
2335
2336#ifdef OVERLOAD
2337EXT MGVTBL vtbl_amagic;
2338EXT MGVTBL vtbl_amagicelem;
2339#endif /* OVERLOAD */
2340
bbce6d69 2341#endif /* !DOINIT */
85e6fe83 2342
a0d0e21e 2343#ifdef OVERLOAD
c0315cdf 2344
a6006777 2345#define NofAMmeth 58
a0d0e21e 2346#ifdef DOINIT
a6006777 2347EXTCONST char * AMG_names[NofAMmeth] = {
2348 "fallback", "abs", /* "fallback" should be the first. */
2349 "bool", "nomethod",
2350 "\"\"", "0+",
2351 "+", "+=",
2352 "-", "-=",
2353 "*", "*=",
2354 "/", "/=",
2355 "%", "%=",
2356 "**", "**=",
2357 "<<", "<<=",
2358 ">>", ">>=",
2359 "&", "&=",
2360 "|", "|=",
2361 "^", "^=",
2362 "<", "<=",
2363 ">", ">=",
2364 "==", "!=",
2365 "<=>", "cmp",
2366 "lt", "le",
2367 "gt", "ge",
2368 "eq", "ne",
2369 "!", "~",
2370 "++", "--",
2371 "atan2", "cos",
2372 "sin", "exp",
2373 "log", "sqrt",
2374 "x", "x=",
2375 ".", ".=",
2376 "=", "neg"
a0d0e21e
LW
2377};
2378#else
a6006777 2379EXTCONST char * AMG_names[NofAMmeth];
a0d0e21e
LW
2380#endif /* def INITAMAGIC */
2381
a6006777 2382struct am_table {
a0d0e21e
LW
2383 long was_ok_sub;
2384 long was_ok_am;
a6006777 2385 U32 flags;
2386 CV* table[NofAMmeth];
a0d0e21e
LW
2387 long fallback;
2388};
a6006777 2389struct am_table_short {
2390 long was_ok_sub;
2391 long was_ok_am;
2392 U32 flags;
2393};
a0d0e21e 2394typedef struct am_table AMT;
a6006777 2395typedef struct am_table_short AMTS;
a0d0e21e
LW
2396
2397#define AMGfallNEVER 1
2398#define AMGfallNO 2
2399#define AMGfallYES 3
2400
a6006777 2401#define AMTf_AMAGIC 1
2402#define AMT_AMAGIC(amt) ((amt)->flags & AMTf_AMAGIC)
2403#define AMT_AMAGIC_on(amt) ((amt)->flags |= AMTf_AMAGIC)
2404#define AMT_AMAGIC_off(amt) ((amt)->flags &= ~AMTf_AMAGIC)
2405
a0d0e21e
LW
2406enum {
2407 fallback_amg, abs_amg,
2408 bool__amg, nomethod_amg,
2409 string_amg, numer_amg,
2410 add_amg, add_ass_amg,
2411 subtr_amg, subtr_ass_amg,
2412 mult_amg, mult_ass_amg,
2413 div_amg, div_ass_amg,
76e3520e 2414 modulo_amg, modulo_ass_amg,
a0d0e21e
LW
2415 pow_amg, pow_ass_amg,
2416 lshift_amg, lshift_ass_amg,
2417 rshift_amg, rshift_ass_amg,
748a9306
LW
2418 band_amg, band_ass_amg,
2419 bor_amg, bor_ass_amg,
2420 bxor_amg, bxor_ass_amg,
a0d0e21e
LW
2421 lt_amg, le_amg,
2422 gt_amg, ge_amg,
2423 eq_amg, ne_amg,
2424 ncmp_amg, scmp_amg,
2425 slt_amg, sle_amg,
2426 sgt_amg, sge_amg,
2427 seq_amg, sne_amg,
a0d0e21e
LW
2428 not_amg, compl_amg,
2429 inc_amg, dec_amg,
2430 atan2_amg, cos_amg,
2431 sin_amg, exp_amg,
2432 log_amg, sqrt_amg,
2433 repeat_amg, repeat_ass_amg,
748a9306
LW
2434 concat_amg, concat_ass_amg,
2435 copy_amg, neg_amg
a0d0e21e 2436};
c0315cdf
JH
2437
2438/*
2439 * some compilers like to redefine cos et alia as faster
2440 * (and less accurate?) versions called F_cos et cetera (Quidquid
2441 * latine dictum sit, altum viditur.) This trick collides with
2442 * the Perl overloading (amg). The following #defines fool both.
2443 */
2444
2445#ifdef _FASTMATH
2446# ifdef atan2
2447# define F_atan2_amg atan2_amg
2448# endif
2449# ifdef cos
2450# define F_cos_amg cos_amg
2451# endif
2452# ifdef exp
2453# define F_exp_amg exp_amg
2454# endif
2455# ifdef log
2456# define F_log_amg log_amg
2457# endif
2458# ifdef pow
2459# define F_pow_amg pow_amg
2460# endif
2461# ifdef sin
2462# define F_sin_amg sin_amg
2463# endif
2464# ifdef sqrt
2465# define F_sqrt_amg sqrt_amg
2466# endif
2467#endif /* _FASTMATH */
2468
a0d0e21e
LW
2469#endif /* OVERLOAD */
2470
491527d0 2471#define PERLDB_ALL 0x3f /* No _NONAME, _GOTO */
84902520
TB
2472#define PERLDBf_SUB 0x01 /* Debug sub enter/exit. */
2473#define PERLDBf_LINE 0x02 /* Keep line #. */
2474#define PERLDBf_NOOPT 0x04 /* Switch off optimizations. */
2475#define PERLDBf_INTER 0x08 /* Preserve more data for
2476 later inspections. */
2477#define PERLDBf_SUBLINE 0x10 /* Keep subr source lines. */
2478#define PERLDBf_SINGLE 0x20 /* Start with single-step on. */
491527d0
GS
2479#define PERLDBf_NONAME 0x40 /* For _SUB: no name of the subr. */
2480#define PERLDBf_GOTO 0x80 /* Report goto: call DB::goto. */
84902520 2481
3280af22
NIS
2482#define PERLDB_SUB (PL_perldb && (PL_perldb & PERLDBf_SUB))
2483#define PERLDB_LINE (PL_perldb && (PL_perldb & PERLDBf_LINE))
2484#define PERLDB_NOOPT (PL_perldb && (PL_perldb & PERLDBf_NOOPT))
2485#define PERLDB_INTER (PL_perldb && (PL_perldb & PERLDBf_INTER))
2486#define PERLDB_SUBLINE (PL_perldb && (PL_perldb & PERLDBf_SUBLINE))
2487#define PERLDB_SINGLE (PL_perldb && (PL_perldb & PERLDBf_SINGLE))
2488#define PERLDB_SUB_NN (PL_perldb && (PL_perldb & (PERLDBf_NONAME)))
2489#define PERLDB_GOTO (PL_perldb && (PL_perldb & PERLDBf_GOTO))
84902520 2490
bbce6d69 2491
36477c24 2492#ifdef USE_LOCALE_NUMERIC
bbce6d69 2493
36477c24 2494#define SET_NUMERIC_STANDARD() \
2495 STMT_START { \
3280af22 2496 if (! PL_numeric_standard) \
36477c24 2497 perl_set_numeric_standard(); \
2498 } STMT_END
2499
2500#define SET_NUMERIC_LOCAL() \
2501 STMT_START { \
3280af22 2502 if (! PL_numeric_local) \
36477c24 2503 perl_set_numeric_local(); \
2504 } STMT_END
bbce6d69 2505
36477c24 2506#else /* !USE_LOCALE_NUMERIC */
bbce6d69 2507
36477c24 2508#define SET_NUMERIC_STANDARD() /**/
2509#define SET_NUMERIC_LOCAL() /**/
bbce6d69 2510
36477c24 2511#endif /* !USE_LOCALE_NUMERIC */
a0d0e21e 2512
e5c9fcd0 2513#if !defined(PERLIO_IS_STDIO) && defined(HASATTRIBUTE)
760ac839
LW
2514/*
2515 * Now we have __attribute__ out of the way
2516 * Remap printf
2517 */
2518#define printf PerlIO_stdoutf
2519#endif
2520
a868473f
NIS
2521#ifndef PERL_SCRIPT_MODE
2522#define PERL_SCRIPT_MODE "r"
2523#endif
2524
fba3b22e
MB
2525/*
2526 * nice_chunk and nice_chunk size need to be set
2527 * and queried under the protection of sv_mutex
2528 */
2529#define offer_nice_chunk(chunk, chunk_size) do { \
940cb80d 2530 LOCK_SV_MUTEX; \
3280af22
NIS
2531 if (!PL_nice_chunk) { \
2532 PL_nice_chunk = (char*)(chunk); \
2533 PL_nice_chunk_size = (chunk_size); \
fba3b22e 2534 } \
fc80cf79
GS
2535 else { \
2536 Safefree(chunk); \
2537 } \
940cb80d 2538 UNLOCK_SV_MUTEX; \
fba3b22e
MB
2539 } while (0)
2540
bd89102f
AD
2541#ifdef HAS_SEM
2542# include <sys/ipc.h>
2543# include <sys/sem.h>
2544# ifndef HAS_UNION_SEMUN /* Provide the union semun. */
2545 union semun {
2546 int val;
2547 struct semid_ds *buf;
2548 unsigned short *array;
2549 };
2550# endif
2551# ifdef USE_SEMCTL_SEMUN
2552# define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun)
2553# else
2554# ifdef USE_SEMCTL_SEMID_DS
2555# define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun.buf)
2556# endif
2557# endif
2558# ifndef Semctl /* Place our bets on the semun horse. */
2559# define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun)
2560# endif
2561#endif
49f531da 2562
465fbd0a
JH
2563#ifdef IAMSUID
2564
2565#ifdef I_SYS_STATVFS
f82e96e5
JH
2566# include <sys/statvfs.h> /* for f?statvfs() */
2567#endif
2568#ifdef I_SYS_MOUNT
2569# include <sys/mount.h> /* for *BSD f?statfs() */
2570#endif
2571#ifdef I_MNTENT
2572# include <mntent.h> /* for getmntent() */
465fbd0a
JH
2573#endif
2574
2575#endif /* IAMSUID */
2576
85e6fe83 2577#endif /* Include guard */