home *** CD-ROM | disk | FTP | other *** search
/ Chip: Windows 2000 Professional Resource Kit / W2KPRK.iso / apps / perl / ActivePerl.exe / data.z / perl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-14  |  69.0 KB  |  2,593 lines

  1. /*    perl.h
  2.  *
  3.  *    Copyright (c) 1987-1999, Larry Wall
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  */
  9. #ifndef H_PERL
  10. #define H_PERL 1
  11. #define OVERLOAD
  12.  
  13. #ifdef PERL_FOR_X2P
  14. /*
  15.  * This file is being used for x2p stuff. 
  16.  * Above symbol is defined via -D in 'x2p/Makefile.SH'
  17.  * Decouple x2p stuff from some of perls more extreme eccentricities. 
  18.  */
  19. #undef EMBED
  20. #undef NO_EMBED
  21. #define NO_EMBED
  22. #undef MULTIPLICITY
  23. #undef USE_STDIO
  24. #define USE_STDIO
  25. #endif /* PERL_FOR_X2P */
  26.  
  27. #ifdef PERL_OBJECT
  28.  
  29. /* PERL_OBJECT explained  - DickH and DougL @ ActiveState.com
  30.  
  31. Defining PERL_OBJECT turns on creation of a C++ object that
  32. contains all writable core perl global variables and functions.
  33. Stated another way, all necessary global variables and functions
  34. are members of a big C++ object. This object's class is CPerlObj.
  35. This allows a Perl Host to have multiple, independent perl
  36. interpreters in the same process space. This is very important on
  37. Win32 systems as the overhead of process creation is quite high --
  38. this could be even higher than the script compile and execute time
  39. for small scripts.
  40.  
  41. The perl executable implementation on Win32 is composed of perl.exe
  42. (the Perl Host) and perlX.dll. (the Perl Core). This allows the
  43. same Perl Core to easily be embedded in other applications that use
  44. the perl interpreter.
  45.  
  46. +-----------+
  47. | Perl Host |
  48. +-----------+
  49.       ^
  50.       |
  51.       v
  52. +-----------+   +-----------+
  53. | Perl Core |<->| Extension |
  54. +-----------+   +-----------+ ...
  55.  
  56. Defining PERL_OBJECT has the following effects:
  57.  
  58. PERL CORE
  59. 1. CPerlObj is defined (this is the PERL_OBJECT)
  60. 2. all static functions that needed to access either global
  61. variables or functions needed are made member functions
  62. 3. all writable static variables are made member variables
  63. 4. 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
  67. This necessitated renaming some local variables and functions that
  68. had the same name as a global variable or function. This was
  69. probably a _good_ thing anyway.
  70.  
  71.  
  72. EXTENSIONS
  73. 1. Access to global variables and perl functions is through a
  74. pointer to the PERL_OBJECT. This pointer type is CPerlObj*. This is
  75. made transparent to extension developers by the following macros:
  76.     #define var pPerl->Perl_var
  77.     #define func pPerl->Perl_func
  78.     * these are done in objXSUB.h
  79. This requires that the extension be compiled as C++, which means
  80. that the code must be ANSI C and not K&R C. For K&R extensions,
  81. please see the C API notes located in Win32/GenCAPI.pl. This script
  82. creates a perlCAPI.lib that provides a K & R compatible C interface
  83. to the PERL_OBJECT.
  84. 2. Local variables and functions cannot have the same name as perl's
  85. variables or functions since the macros will redefine these. Look for
  86. this if you get some strange error message and it does not look like
  87. the code that you had written. This often happens with variables that
  88. are local to a function.
  89.  
  90. PERL HOST
  91. 1. The perl host is linked with perlX.lib to get perl_alloc. This
  92. function will return a pointer to CPerlObj (the PERL_OBJECT). It
  93. takes pointers to the various PerlXXX_YYY interfaces (see iperlsys.h
  94. for more information on this).
  95. 2. The perl host calls the same functions as normally would be
  96. called in setting up and running a perl script, except that the
  97. functions are now member functions of the PERL_OBJECT.
  98.  
  99. */
  100.  
  101.  
  102. class CPerlObj;
  103.  
  104. #define STATIC
  105. #define CPERLscope(x) CPerlObj::x
  106. #define CPERLproto CPerlObj *
  107. #define _CPERLproto ,CPERLproto
  108. #define CPERLarg CPerlObj *pPerl
  109. #define CPERLarg_ CPERLarg,
  110. #define _CPERLarg ,CPERLarg
  111. #define PERL_OBJECT_THIS this
  112. #define _PERL_OBJECT_THIS ,this
  113. #define PERL_OBJECT_THIS_ this,
  114. #define CALLRUNOPS (this->*PL_runops)
  115. #define CALLREGCOMP (this->*PL_regcompp)
  116. #define CALLREGEXEC (this->*PL_regexecp)
  117.  
  118. #else /* !PERL_OBJECT */
  119.  
  120. #define STATIC static
  121. #define CPERLscope(x) x
  122. #define CPERLproto
  123. #define _CPERLproto
  124. #define CPERLarg void
  125. #define CPERLarg_
  126. #define _CPERLarg
  127. #define PERL_OBJECT_THIS
  128. #define _PERL_OBJECT_THIS
  129. #define PERL_OBJECT_THIS_
  130. #define CALLRUNOPS PL_runops
  131. #define CALLREGCOMP (*PL_regcompp)
  132. #define CALLREGEXEC (*PL_regexecp)
  133.  
  134. #endif /* PERL_OBJECT */
  135.  
  136. #define VOIDUSED 1
  137. #include "config.h"
  138.  
  139. #include "embed.h"
  140.  
  141. #undef START_EXTERN_C
  142. #undef END_EXTERN_C
  143. #undef EXTERN_C
  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.  
  154. #ifdef OP_IN_REGISTER
  155. #  ifdef __GNUC__
  156. #    define stringify_immed(s) #s
  157. #    define stringify(s) stringify_immed(s)
  158. #ifdef EMBED
  159. register struct op *Perl_op asm(stringify(OP_IN_REGISTER));
  160. #else
  161. register struct op *op asm(stringify(OP_IN_REGISTER));
  162. #endif
  163. #  endif
  164. #endif
  165.  
  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))
  174. # if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__cplusplus)
  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.  
  189. #define NOOP (void)0
  190.  
  191. #define WITH_THR(s) STMT_START { dTHR; s; } STMT_END
  192.  
  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
  202.  
  203. #ifndef BYTEORDER  /* Should never happen -- byteorder is in config.h */
  204. #   define BYTEORDER 0x1234
  205. #endif
  206.  
  207. /* Overall memory policy? */
  208. #ifndef CONSERVATIVE
  209. #   define LIBERAL 1
  210. #endif
  211.  
  212. #if 'A' == 65 && 'I' == 73 && 'J' == 74 && 'Z' == 90
  213. #define ASCIIish
  214. #else
  215. #undef  ASCIIish
  216. #endif
  217.  
  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.  */
  225.  
  226. /* define this once if either system, instead of cluttering up the src */
  227. #if defined(MSDOS) || defined(atarist) || defined(WIN32)
  228. #define DOSISH 1
  229. #endif
  230.  
  231. #if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
  232. # define STANDARD_C 1
  233. #endif
  234.  
  235. #if defined(__cplusplus) || defined(WIN32) || defined(__sgi) || defined(OS2) || defined(__DGUX)
  236. # define DONT_DECLARE_STD 1
  237. #endif
  238.  
  239. #if defined(HASVOLATILE) || defined(STANDARD_C)
  240. #   ifdef __cplusplus
  241. #    define VOL        // to temporarily suppress warnings
  242. #   else
  243. #    define VOL volatile
  244. #   endif
  245. #else
  246. #   define VOL
  247. #endif
  248.  
  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(); }
  253. #define TAINT_PROPER(s)    if (PL_tainting) { taint_proper(Nullch, s); }
  254.  
  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))
  264. #else
  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
  303. #endif
  304.  
  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>
  308. #   endif
  309. #endif
  310.  
  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.  
  325. #include "iperlsys.h"
  326.  
  327. #ifdef USE_NEXT_CTYPE
  328.  
  329. #if NX_CURRENT_COMPILER_RELEASE >= 400
  330. #include <objc/NXCType.h>
  331. #else /*  NX_CURRENT_COMPILER_RELEASE < 400 */
  332. #include <appkit/NXCType.h>
  333. #endif /*  NX_CURRENT_COMPILER_RELEASE >= 400 */
  334.  
  335. #else /* !USE_NEXT_CTYPE */
  336. #include <ctype.h>
  337. #endif /* USE_NEXT_CTYPE */
  338.  
  339. #ifdef METHOD     /* Defined by OSF/1 v3.0 by ctype.h */
  340. #undef METHOD
  341. #endif
  342.  
  343. #ifdef I_LOCALE
  344. #   include <locale.h>
  345. #endif
  346.  
  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 */
  360.  
  361. #include <setjmp.h>
  362.  
  363. #ifdef I_SYS_PARAM
  364. #   ifdef PARAM_NEEDS_TYPES
  365. #    include <sys/types.h>
  366. #   endif
  367. #   include <sys/param.h>
  368. #endif
  369.  
  370.  
  371. /* Use all the "standard" definitions? */
  372. #if defined(STANDARD_C) && defined(I_STDLIB)
  373. #   include <stdlib.h>
  374. #endif
  375.  
  376. #define MEM_SIZE Size_t
  377.  
  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. */
  380.  
  381. #ifdef MYMALLOC
  382.  
  383. #   ifdef HIDEMYMALLOC
  384. #    define malloc  Mymalloc
  385. #    define calloc  Mycalloc
  386. #    define realloc Myrealloc
  387. #    define free    Myfree
  388. Malloc_t Mymalloc _((MEM_SIZE nbytes));
  389. Malloc_t Mycalloc _((MEM_SIZE elements, MEM_SIZE size));
  390. Malloc_t Myrealloc _((Malloc_t where, MEM_SIZE nbytes));
  391. Free_t   Myfree _((Malloc_t where));
  392. #   endif
  393. #   ifdef EMBEDMYMALLOC
  394. #    define malloc  Perl_malloc
  395. #    define calloc  Perl_calloc
  396. #    define realloc Perl_realloc
  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
  402. #    define free    Perl_free
  403. #endif
  404. Malloc_t Perl_malloc _((MEM_SIZE nbytes));
  405. Malloc_t Perl_calloc _((MEM_SIZE elements, MEM_SIZE size));
  406. Malloc_t Perl_realloc _((Malloc_t where, MEM_SIZE nbytes));
  407. #ifdef VMS
  408. Free_t   Perl_myfree _((Malloc_t where));
  409. #else
  410. Free_t   Perl_free _((Malloc_t where));
  411. #endif
  412. #   endif
  413.  
  414. #   undef safemalloc
  415. #   undef safecalloc
  416. #   undef saferealloc
  417. #   undef safefree
  418. #   define safemalloc  malloc
  419. #   define safecalloc  calloc
  420. #   define saferealloc realloc
  421. #   define safefree    free
  422.  
  423. #endif /* MYMALLOC */
  424.  
  425. #if defined(STANDARD_C) && defined(I_STDDEF)
  426. #   include <stddef.h>
  427. #   define STRUCT_OFFSET(s,m)  offsetof(s,m)
  428. #else
  429. #   define STRUCT_OFFSET(s,m)  (Size_t)(&(((s *)0)->m))
  430. #endif
  431.  
  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.  
  443. #ifdef I_MEMORY
  444. #  include <memory.h>
  445. #endif
  446.  
  447. #ifdef HAS_MEMCPY
  448. #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
  449. #    ifndef memcpy
  450.         extern char * memcpy _((char*, char*, int));
  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 */
  462.  
  463. #ifdef HAS_MEMSET
  464. #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
  465. #    ifndef memset
  466.     extern char *memset _((char*, int, int));
  467. #    endif
  468. #  endif
  469. #else
  470. #  define memset(d,c,l) my_memset(d,c,l)
  471. #endif /* HAS_MEMSET */
  472.  
  473. #if !defined(HAS_MEMMOVE) && !defined(memmove)
  474. #   if defined(HAS_BCOPY) && defined(HAS_SAFE_BCOPY)
  475. #    define memmove(d,s,l) bcopy(s,d,l)
  476. #   else
  477. #    if defined(HAS_MEMCPY) && defined(HAS_SAFE_MEMCPY)
  478. #        define memmove(d,s,l) memcpy(d,s,l)
  479. #    else
  480. #        define memmove(d,s,l) my_bcopy(s,d,l)
  481. #    endif
  482. #   endif
  483. #endif
  484.  
  485. #if defined(mips) && defined(ultrix) && !defined(__STDC__)
  486. #   undef HAS_MEMCMP
  487. #endif
  488.  
  489. #if defined(HAS_MEMCMP) && defined(HAS_SANE_MEMCMP)
  490. #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
  491. #    ifndef memcmp
  492.     extern int memcmp _((char*, char*, int));
  493. #    endif
  494. #  endif
  495. #  ifdef BUGGY_MSC
  496.   #  pragma function(memcmp)
  497. #  endif
  498. #else
  499. #   ifndef memcmp
  500. #    define memcmp     my_memcmp
  501. #   endif
  502. #endif /* HAS_MEMCMP && HAS_SANE_MEMCMP */
  503.  
  504. #ifndef memzero
  505. #   ifdef HAS_MEMSET
  506. #    define memzero(d,l) memset(d,0,l)
  507. #   else
  508. #    ifdef HAS_BZERO
  509. #        define memzero(d,l) bzero(d,l)
  510. #    else
  511. #        define memzero(d,l) my_bzero(d,l)
  512. #    endif
  513. #   endif
  514. #endif
  515.  
  516. #ifndef HAS_BCMP
  517. #   ifndef bcmp
  518. #    define bcmp(s1,s2,l) memcmp(s1,s2,l)
  519. #   endif
  520. #endif /* !HAS_BCMP */
  521.  
  522. #ifdef I_NETINET_IN
  523. #   include <netinet/in.h>
  524. #endif
  525.  
  526. #ifdef I_ARPA_INET
  527. #   include <arpa/inet.h>
  528. #endif
  529.  
  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.  
  536. #ifdef I_SYS_STAT
  537. #   include <sys/stat.h>
  538. #endif
  539.  
  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))
  550. #   undef S_ISDIR
  551. #   undef S_ISCHR
  552. #   undef S_ISBLK
  553. #   undef S_ISREG
  554. #   undef S_ISFIFO
  555. #   undef S_ISLNK
  556. #endif
  557.  
  558. #ifdef I_TIME
  559. #   include <time.h>
  560. #endif
  561.  
  562. #ifdef I_SYS_TIME
  563. #   ifdef I_SYS_TIME_KERNEL
  564. #    define KERNEL
  565. #   endif
  566. #   include <sys/time.h>
  567. #   ifdef I_SYS_TIME_KERNEL
  568. #    undef KERNEL
  569. #   endif
  570. #endif
  571.  
  572. #if defined(HAS_TIMES) && defined(I_SYS_TIMES)
  573. #    include <sys/times.h>
  574. #endif
  575.  
  576. #if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
  577. #   undef HAS_STRERROR
  578. #endif
  579.  
  580. #include <errno.h>
  581. #ifdef HAS_SOCKET
  582. #   ifdef I_NET_ERRNO
  583. #     include <net/errno.h>
  584. #   endif
  585. #endif
  586.  
  587. #ifdef VMS
  588. #   define SETERRNO(errcode,vmserrcode) \
  589.     STMT_START {            \
  590.         set_errno(errcode);        \
  591.         set_vaxc_errno(vmserrcode);    \
  592.     } STMT_END
  593. #else
  594. #   define SETERRNO(errcode,vmserrcode) (errno = (errcode))
  595. #endif
  596.  
  597. #ifdef USE_THREADS
  598. #  define ERRSV (thr->errsv)
  599. #  define ERRHV (thr->errhv)
  600. #  define DEFSV THREADSV(0)
  601. #  define SAVE_DEFSV save_threadsv(0)
  602. #else
  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))
  607. #endif /* USE_THREADS */
  608.  
  609. #ifndef errno
  610.     extern int errno;     /* ANSI allows errno to be an lvalue expr */
  611. #endif
  612.  
  613. #ifdef HAS_STRERROR
  614. #       ifdef VMS
  615.     char *strerror _((int,...));
  616. #       else
  617. #ifndef DONT_DECLARE_STD
  618.     char *strerror _((int));
  619. #endif
  620. #       endif
  621. #       ifndef Strerror
  622. #           define Strerror strerror
  623. #       endif
  624. #else
  625. #    ifdef HAS_SYS_ERRLIST
  626.     extern int sys_nerr;
  627.     extern char *sys_errlist[];
  628. #       ifndef Strerror
  629. #           define Strerror(e) \
  630.         ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
  631. #       endif
  632. #   endif
  633. #endif
  634.  
  635. #ifdef I_SYS_IOCTL
  636. #   ifndef _IOCTL_
  637. #    include <sys/ioctl.h>
  638. #   endif
  639. #endif
  640.  
  641. #if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
  642. #   ifdef HAS_SOCKETPAIR
  643. #    undef HAS_SOCKETPAIR
  644. #   endif
  645. #   ifdef I_NDBM
  646. #    undef I_NDBM
  647. #   endif
  648. #endif
  649.  
  650. #if INTSIZE == 2
  651. #   define htoni htons
  652. #   define ntohi ntohs
  653. #else
  654. #   define htoni htonl
  655. #   define ntohi ntohl
  656. #endif
  657.  
  658. /* Configure already sets Direntry_t */
  659. #if defined(I_DIRENT)
  660. #   include <dirent.h>
  661. #   if defined(NeXT) && defined(I_SYS_DIR) /* NeXT needs dirent + sys/dir.h */
  662. #    include <sys/dir.h>
  663. #   endif
  664. #else
  665. #   ifdef I_SYS_NDIR
  666. #    include <sys/ndir.h>
  667. #   else
  668. #    ifdef I_SYS_DIR
  669. #        ifdef hp9000s500
  670. #        include <ndir.h>    /* may be wrong in the future */
  671. #        else
  672. #        include <sys/dir.h>
  673. #        endif
  674. #    endif
  675. #   endif
  676. #endif
  677.  
  678. #ifdef FPUTS_BOTCH
  679. /* work around botch in SunOS 4.0.1 and 4.0.2 */
  680. #   ifndef fputs
  681. #    define fputs(sv,fp) fprintf(fp,"%s",sv)
  682. #   endif
  683. #endif
  684.  
  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
  708. #   ifdef S_IFBLK
  709. #    define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
  710. #   else
  711. #    define S_ISBLK(m) (0)
  712. #   endif
  713. #endif
  714.  
  715. #ifndef S_ISREG
  716. #   define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
  717. #endif
  718.  
  719. #ifndef S_ISFIFO
  720. #   ifdef S_IFIFO
  721. #    define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
  722. #   else
  723. #    define S_ISFIFO(m) (0)
  724. #   endif
  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.  
  785. #ifdef ff_next
  786. #   undef ff_next
  787. #endif
  788.  
  789. #if defined(cray) || defined(gould) || defined(i860) || defined(pyr)
  790. #   define SLOPPYDIVIDE
  791. #endif
  792.  
  793. #ifdef UV
  794. #undef UV
  795. #endif
  796.  
  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.  
  810. #ifdef cray
  811. #   define Quad_t int
  812. #else
  813. #   ifdef convex
  814. #    define Quad_t long long
  815. #   else
  816. #    if LONGSIZE == 8
  817. #        define Quad_t long
  818. #    endif
  819. #   endif
  820. #endif
  821.  
  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.  
  831. #ifdef Quad_t
  832. #   define HAS_QUAD
  833.     typedef Quad_t IV;
  834.     typedef unsigned Quad_t UV;
  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
  839. #else
  840.     typedef long IV;
  841.     typedef unsigned long UV;
  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
  846. #endif
  847.  
  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.  
  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.  */
  887.  
  888. #define PERL_UCHAR_MIN ((unsigned char)0)
  889.  
  890. #ifdef UCHAR_MAX
  891. #  define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX)
  892. #else
  893. #  ifdef MAXUCHAR
  894. #    define PERL_UCHAR_MAX ((unsigned char)MAXUCHAR)
  895. #  else
  896. #    define PERL_UCHAR_MAX       ((unsigned char)~(unsigned)0)
  897. #  endif
  898. #endif
  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.  */
  908.  
  909. #define PERL_USHORT_MIN ((unsigned short)0)
  910.  
  911. #ifdef USHORT_MAX
  912. #  define PERL_USHORT_MAX ((unsigned short)USHORT_MAX)
  913. #else
  914. #  ifdef MAXUSHORT
  915. #    define PERL_USHORT_MAX ((unsigned short)MAXUSHORT)
  916. #  else
  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
  922. #  endif
  923. #endif
  924.  
  925. #ifdef SHORT_MAX
  926. #  define PERL_SHORT_MAX ((short)SHORT_MAX)
  927. #else
  928. #  ifdef MAXSHORT    /* Often used in <values.h> */
  929. #    define PERL_SHORT_MAX ((short)MAXSHORT)
  930. #  else
  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
  936. #  endif
  937. #endif
  938.  
  939. #ifdef SHORT_MIN
  940. #  define PERL_SHORT_MIN ((short)SHORT_MIN)
  941. #else
  942. #  ifdef MINSHORT
  943. #    define PERL_SHORT_MIN ((short)MINSHORT)
  944. #  else
  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
  950. #  endif
  951. #endif
  952.  
  953. #ifdef UINT_MAX
  954. #  define PERL_UINT_MAX ((unsigned int)UINT_MAX)
  955. #else
  956. #  ifdef MAXUINT
  957. #    define PERL_UINT_MAX ((unsigned int)MAXUINT)
  958. #  else
  959. #    define PERL_UINT_MAX       (~(unsigned int)0)
  960. #  endif
  961. #endif
  962.  
  963. #define PERL_UINT_MIN ((unsigned int)0)
  964.  
  965. #ifdef INT_MAX
  966. #  define PERL_INT_MAX ((int)INT_MAX)
  967. #else
  968. #  ifdef MAXINT    /* Often used in <values.h> */
  969. #    define PERL_INT_MAX ((int)MAXINT)
  970. #  else
  971. #    define PERL_INT_MAX        ((int)(PERL_UINT_MAX >> 1))
  972. #  endif
  973. #endif
  974.  
  975. #ifdef INT_MIN
  976. #  define PERL_INT_MIN ((int)INT_MIN)
  977. #else
  978. #  ifdef MININT
  979. #    define PERL_INT_MIN ((int)MININT)
  980. #  else
  981. #    define PERL_INT_MIN        (-PERL_INT_MAX - ((3 & -1) == 3))
  982. #  endif
  983. #endif
  984.  
  985. #ifdef ULONG_MAX
  986. #  define PERL_ULONG_MAX ((unsigned long)ULONG_MAX)
  987. #else
  988. #  ifdef MAXULONG
  989. #    define PERL_ULONG_MAX ((unsigned long)MAXULONG)
  990. #  else
  991. #    define PERL_ULONG_MAX       (~(unsigned long)0)
  992. #  endif
  993. #endif
  994.  
  995. #define PERL_ULONG_MIN ((unsigned long)0L)
  996.  
  997. #ifdef LONG_MAX
  998. #  define PERL_LONG_MAX ((long)LONG_MAX)
  999. #else
  1000. #  ifdef MAXLONG    /* Often used in <values.h> */
  1001. #    define PERL_LONG_MAX ((long)MAXLONG)
  1002. #  else
  1003. #    define PERL_LONG_MAX        ((long) (PERL_ULONG_MAX >> 1))
  1004. #  endif
  1005. #endif
  1006.  
  1007. #ifdef LONG_MIN
  1008. #  define PERL_LONG_MIN ((long)LONG_MIN)
  1009. #else
  1010. #  ifdef MINLONG
  1011. #    define PERL_LONG_MIN ((long)MINLONG)
  1012. #  else
  1013. #    define PERL_LONG_MIN        (-PERL_LONG_MAX - ((3 & -1) == 3))
  1014. #  endif
  1015. #endif
  1016.  
  1017. #ifdef HAS_QUAD
  1018.  
  1019. #  ifdef UQUAD_MAX
  1020. #    define PERL_UQUAD_MAX ((UV)UQUAD_MAX)
  1021. #  else
  1022. #    define PERL_UQUAD_MAX    (~(UV)0)
  1023. #  endif
  1024.  
  1025. #  define PERL_UQUAD_MIN ((UV)0)
  1026.  
  1027. #  ifdef QUAD_MAX
  1028. #    define PERL_QUAD_MAX ((IV)QUAD_MAX)
  1029. #  else
  1030. #    define PERL_QUAD_MAX     ((IV) (PERL_UQUAD_MAX >> 1))
  1031. #  endif
  1032.  
  1033. #  ifdef QUAD_MIN
  1034. #    define PERL_QUAD_MIN ((IV)QUAD_MIN)
  1035. #  else
  1036. #    define PERL_QUAD_MIN     (-PERL_QUAD_MAX - ((3 & -1) == 3))
  1037. #  endif
  1038.  
  1039. #endif
  1040.  
  1041. typedef MEM_SIZE STRLEN;
  1042.  
  1043. typedef struct op OP;
  1044. typedef struct cop COP;
  1045. typedef struct unop UNOP;
  1046. typedef struct binop BINOP;
  1047. typedef struct listop LISTOP;
  1048. typedef struct logop LOGOP;
  1049. typedef struct condop CONDOP;
  1050. typedef struct pmop PMOP;
  1051. typedef struct svop SVOP;
  1052. typedef struct gvop GVOP;
  1053. typedef struct pvop PVOP;
  1054. typedef struct loop LOOP;
  1055.  
  1056. typedef struct Outrec Outrec;
  1057. typedef struct interpreter PerlInterpreter;
  1058. #ifndef __BORLANDC__
  1059. typedef struct ff FF;        /* XXX not defined anywhere, should go? */
  1060. #endif
  1061. typedef struct sv SV;
  1062. typedef struct av AV;
  1063. typedef struct hv HV;
  1064. typedef struct cv CV;
  1065. typedef struct regexp REGEXP;
  1066. typedef struct gp GP;
  1067. typedef struct gv GV;
  1068. typedef struct io IO;
  1069. typedef struct context PERL_CONTEXT;
  1070. typedef struct block BLOCK;
  1071.  
  1072. typedef struct magic MAGIC;
  1073. typedef struct xrv XRV;
  1074. typedef struct xpv XPV;
  1075. typedef struct xpviv XPVIV;
  1076. typedef struct xpvuv XPVUV;
  1077. typedef struct xpvnv XPVNV;
  1078. typedef struct xpvmg XPVMG;
  1079. typedef struct xpvlv XPVLV;
  1080. typedef struct xpvav XPVAV;
  1081. typedef struct xpvhv XPVHV;
  1082. typedef struct xpvgv XPVGV;
  1083. typedef struct xpvcv XPVCV;
  1084. typedef struct xpvbm XPVBM;
  1085. typedef struct xpvfm XPVFM;
  1086. typedef struct xpvio XPVIO;
  1087. typedef struct mgvtbl MGVTBL;
  1088. typedef union any ANY;
  1089.  
  1090. #include "handy.h"
  1091.  
  1092. #ifdef PERL_OBJECT
  1093. typedef I32 (*filter_t) _((CPerlObj*, int, SV *, int));
  1094. #else
  1095. typedef I32 (*filter_t) _((int, SV *, int));
  1096. #endif
  1097.  
  1098. #define FILTER_READ(idx, sv, len)  filter_read(idx, sv, len)
  1099. #define FILTER_DATA(idx)       (AvARRAY(PL_rsfp_filters)[idx])
  1100. #define FILTER_ISREADER(idx)       (idx >= AvFILLp(PL_rsfp_filters))
  1101.  
  1102. #ifdef DOSISH
  1103. # if defined(OS2)
  1104. #   include "os2ish.h"
  1105. # else
  1106. #   include "dosish.h"
  1107. # endif
  1108. #else
  1109. # if defined(VMS)
  1110. #   include "vmsish.h"
  1111. # else
  1112. #   if defined(PLAN9)
  1113. #     include "./plan9/plan9ish.h"
  1114. #   else
  1115. #     if defined(MPE)
  1116. #       include "mpeix/mpeixish.h"
  1117. #     else
  1118. #       if defined(__VOS__)
  1119. #         include "vosish.h"
  1120. #       else
  1121. #         include "unixish.h"
  1122. #       endif
  1123. #     endif
  1124. #   endif
  1125. # endif
  1126. #endif         
  1127.  
  1128. #ifndef FUNC_NAME_TO_PTR
  1129. #define FUNC_NAME_TO_PTR(name)        name
  1130. #endif
  1131.  
  1132. /* 
  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>
  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
  1140.    /* pending resolution of licensing issues, we avoid the erstwhile
  1141.     * atomic.h everywhere */
  1142. #  define EMULATE_ATOMIC_REFCOUNTS
  1143.  
  1144. #  ifdef FAKE_THREADS
  1145. #    include "fakethr.h"
  1146. #  else
  1147. #    ifdef WIN32
  1148. #      include <win32thread.h>
  1149. #    else
  1150. #      ifdef OS2
  1151. #        include "os2thread.h"
  1152. #      else
  1153. #        ifdef I_MACH_CTHREADS
  1154. #          include <mach/cthreads.h>
  1155. #          ifdef NeXT
  1156. #            define MUTEX_INIT_CALLS_MALLOC
  1157. #          endif
  1158. typedef cthread_t    perl_os_thread;
  1159. typedef mutex_t        perl_mutex;
  1160. typedef condition_t    perl_cond;
  1161. typedef void *        perl_key;
  1162. #        else /* Posix threads */
  1163. #          include <pthread.h>
  1164. typedef pthread_t    perl_os_thread;
  1165. typedef pthread_mutex_t    perl_mutex;
  1166. typedef pthread_cond_t    perl_cond;
  1167. typedef pthread_key_t    perl_key;
  1168. #        endif /* I_MACH_CTHREADS */
  1169. #      endif /* OS2 */
  1170. #    endif /* WIN32 */
  1171. #  endif /* FAKE_THREADS */
  1172. #endif /* USE_THREADS */
  1173.  
  1174.  
  1175.   
  1176. #ifdef VMS
  1177. #   define STATUS_NATIVE    PL_statusvalue_vms
  1178. #   define STATUS_NATIVE_EXPORT \
  1179.     ((I32)PL_statusvalue_vms == -1 ? 44 : PL_statusvalue_vms)
  1180. #   define STATUS_NATIVE_SET(n)                        \
  1181.     STMT_START {                            \
  1182.         PL_statusvalue_vms = (n);                    \
  1183.         if ((I32)PL_statusvalue_vms == -1)                \
  1184.         PL_statusvalue = -1;                    \
  1185.         else if (PL_statusvalue_vms & STS$M_SUCCESS)        \
  1186.         PL_statusvalue = 0;                    \
  1187.         else if ((PL_statusvalue_vms & STS$M_SEVERITY) == 0)    \
  1188.         PL_statusvalue = 1 << 8;                \
  1189.         else                            \
  1190.         PL_statusvalue = (PL_statusvalue_vms & STS$M_SEVERITY) << 8;    \
  1191.     } STMT_END
  1192. #   define STATUS_POSIX    PL_statusvalue
  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 {                    \
  1200.         PL_statusvalue = (n);                \
  1201.         if (PL_statusvalue != -1) {            \
  1202.         PL_statusvalue &= 0xFFFF;            \
  1203.         PL_statusvalue_vms = PL_statusvalue ? 44 : 1;    \
  1204.         }                        \
  1205.         else PL_statusvalue_vms = -1;            \
  1206.     } STMT_END
  1207. #   define STATUS_ALL_SUCCESS    (PL_statusvalue = 0, PL_statusvalue_vms = 1)
  1208. #   define STATUS_ALL_FAILURE    (PL_statusvalue = 1, PL_statusvalue_vms = 44)
  1209. #else
  1210. #   define STATUS_NATIVE    STATUS_POSIX
  1211. #   define STATUS_NATIVE_EXPORT    STATUS_POSIX
  1212. #   define STATUS_NATIVE_SET    STATUS_POSIX_SET
  1213. #   define STATUS_POSIX        PL_statusvalue
  1214. #   define STATUS_POSIX_SET(n)        \
  1215.     STMT_START {            \
  1216.         PL_statusvalue = (n);        \
  1217.         if (PL_statusvalue != -1)    \
  1218.         PL_statusvalue &= 0xFFFF;    \
  1219.     } STMT_END
  1220. #   define STATUS_CURRENT STATUS_POSIX
  1221. #   define STATUS_ALL_SUCCESS    (PL_statusvalue = 0)
  1222. #   define STATUS_ALL_FAILURE    (PL_statusvalue = 1)
  1223. #endif
  1224.  
  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)
  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
  1243. #endif
  1244.  
  1245. #ifdef UNION_ANY_DEFINITION
  1246. UNION_ANY_DEFINITION;
  1247. #else
  1248. union any {
  1249.     void*    any_ptr;
  1250.     I32        any_i32;
  1251.     IV        any_iv;
  1252.     long    any_long;
  1253.     void    (CPERLscope(*any_dptr)) _((void*));
  1254. };
  1255. #endif
  1256.  
  1257. #ifdef USE_THREADS
  1258. #define ARGSproto struct perl_thread *thr
  1259. #else
  1260. #define ARGSproto void
  1261. #endif /* USE_THREADS */
  1262.  
  1263. /* Work around some cygwin32 problems with importing global symbols */
  1264. #if defined(CYGWIN32) && defined(DLLIMPORT) 
  1265. #   include "cw32imp.h"
  1266. #endif
  1267.  
  1268. #include "regexp.h"
  1269. #include "sv.h"
  1270. #include "util.h"
  1271. #include "form.h"
  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"
  1281. #include "bytecode.h"
  1282. #include "byterun.h"
  1283.  
  1284. /* Current curly descriptor */
  1285. typedef struct curcur CURCUR;
  1286. struct 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.  
  1298. typedef struct _sublex_info SUBLEXINFO;
  1299. struct _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.  
  1305. #ifdef PERL_OBJECT
  1306. struct magic_state {
  1307.     SV* mgs_sv;
  1308.     U32 mgs_flags;
  1309. };
  1310. typedef struct magic_state MGS;
  1311.  
  1312. typedef 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.  
  1330. typedef I32 CHECKPOINT;
  1331. #endif /* PERL_OBJECT */
  1332.  
  1333. /* work around some libPW problems */
  1334. #ifdef DOINIT
  1335. EXT char Error[1];
  1336. #endif
  1337.  
  1338. #if defined(iAPX286) || defined(M_I286) || defined(I80286)
  1339. #   define I286
  1340. #endif
  1341.  
  1342. #if defined(htonl) && !defined(HAS_HTONL)
  1343. #define HAS_HTONL
  1344. #endif
  1345. #if defined(htons) && !defined(HAS_HTONS)
  1346. #define HAS_HTONS
  1347. #endif
  1348. #if defined(ntohl) && !defined(HAS_NTOHL)
  1349. #define HAS_NTOHL
  1350. #endif
  1351. #if defined(ntohs) && !defined(HAS_NTOHS)
  1352. #define HAS_NTOHS
  1353. #endif
  1354. #ifndef HAS_HTONL
  1355. #if (BYTEORDER & 0xffff) != 0x4321
  1356. #define HAS_HTONS
  1357. #define HAS_HTONL
  1358. #define HAS_NTOHS
  1359. #define HAS_NTOHL
  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
  1367. #if (BYTEORDER & 0xffff) == 0x4321
  1368. #undef HAS_HTONS
  1369. #undef HAS_HTONL
  1370. #undef HAS_NTOHS
  1371. #undef HAS_NTOHL
  1372. #endif
  1373. #endif
  1374.  
  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
  1384. # if BYTEORDER == 0x4321 || BYTEORDER == 0x87654321
  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.  
  1396. #ifdef CASTNEGFLOAT
  1397. #define U_S(what) ((U16)(what))
  1398. #define U_I(what) ((unsigned int)(what))
  1399. #define U_L(what) ((U32)(what))
  1400. #else
  1401. EXTERN_C U32 cast_ulong _((double));
  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)))
  1405. #endif
  1406.  
  1407. #ifdef CASTI32
  1408. #define I_32(what) ((I32)(what))
  1409. #define I_V(what) ((IV)(what))
  1410. #define U_V(what) ((UV)(what))
  1411. #else
  1412. START_EXTERN_C
  1413. I32 cast_i32 _((double));
  1414. IV cast_iv _((double));
  1415. UV cast_uv _((double));
  1416. END_EXTERN_C
  1417. #define I_32(what) (cast_i32((double)(what)))
  1418. #define I_V(what) (cast_iv((double)(what)))
  1419. #define U_V(what) (cast_uv((double)(what)))
  1420. #endif
  1421.  
  1422. struct Outrec {
  1423.     I32        o_lines;
  1424.     char    *o_str;
  1425.     U32        o_len;
  1426. };
  1427.  
  1428. #ifndef MAXSYSFD
  1429. #   define MAXSYSFD 2
  1430. #endif
  1431.  
  1432. #ifndef TMPPATH
  1433. #  define TMPPATH "/tmp/perl-eXXXXXX"
  1434. #endif
  1435.  
  1436. #ifndef __cplusplus
  1437. Uid_t getuid _((void));
  1438. Uid_t geteuid _((void));
  1439. Gid_t getgid _((void));
  1440. Gid_t getegid _((void));
  1441. #endif
  1442.  
  1443. #ifdef DEBUGGING
  1444. #ifndef Perl_debug_log
  1445. #define Perl_debug_log    PerlIO_stderr()
  1446. #endif
  1447. #undef  YYDEBUG
  1448. #define YYDEBUG 1
  1449. #define DEB(a)                 a
  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
  1467. #  ifdef USE_THREADS
  1468. #    define DEBUG_S(a) if (PL_debug & (1<<16))    a
  1469. #  else
  1470. #    define DEBUG_S(a)
  1471. #  endif
  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)
  1487. #define DEBUG_S(a)
  1488. #define DEBUG_H(a)
  1489. #define DEBUG_X(a)
  1490. #define DEBUG_D(a)
  1491. #define DEBUG_S(a)
  1492. #endif
  1493. #define YYMAXDEPTH 300
  1494.  
  1495. #ifndef assert  /* <assert.h> might have been included somehow */
  1496. #define assert(what)    DEB( {                        \
  1497.     if (!(what)) {                            \
  1498.         croak("Assertion failed: file \"%s\", line %d",        \
  1499.         __FILE__, __LINE__);                    \
  1500.         PerlProc_exit(1);                            \
  1501.     }})
  1502. #endif
  1503.  
  1504. struct ufuncs {
  1505.     I32 (*uf_val)_((IV, SV*));
  1506.     I32 (*uf_set)_((IV, SV*));
  1507.     IV uf_index;
  1508. };
  1509.  
  1510. /* Fix these up for __STDC__ */
  1511. #ifndef DONT_DECLARE_STD
  1512. char *mktemp _((char*));
  1513. double atof _((const char*));
  1514. #endif
  1515.  
  1516. #ifndef STANDARD_C
  1517. /* All of these are in stdlib.h or time.h for ANSI C */
  1518. Time_t time();
  1519. struct tm *gmtime(), *localtime();
  1520. #ifdef OEMVS
  1521. char *(strchr)(), *(strrchr)();
  1522. char *(strcpy)(), *(strcat)();
  1523. #else
  1524. char *strchr(), *strrchr();
  1525. char *strcpy(), *strcat();
  1526. #endif
  1527. #endif /* ! STANDARD_C */
  1528.  
  1529.  
  1530. #ifdef I_MATH
  1531. #    include <math.h>
  1532. #else
  1533. START_EXTERN_C
  1534.         double exp _((double));
  1535.         double log _((double));
  1536.         double log10 _((double));
  1537.         double sqrt _((double));
  1538.         double frexp _((double,int*));
  1539.         double ldexp _((double,int));
  1540.         double modf _((double,double*));
  1541.         double sin _((double));
  1542.         double cos _((double));
  1543.         double atan2 _((double,double));
  1544.         double pow _((double,double));
  1545. END_EXTERN_C
  1546. #endif
  1547.  
  1548. #ifndef __cplusplus
  1549. #  ifdef __NeXT__ /* or whatever catches all NeXTs */
  1550. char *crypt ();       /* Maybe more hosts will need the unprototyped version */
  1551. #  else
  1552. #    if !defined(WIN32) || !defined(HAVE_DES_FCRYPT)
  1553. char *crypt _((const char*, const char*));
  1554. #    endif /* !WIN32 && !HAVE_CRYPT_SOURCE */
  1555. #  endif /* !__NeXT__ */
  1556. #  ifndef DONT_DECLARE_STD
  1557. #    ifndef getenv
  1558. char *getenv _((const char*));
  1559. #    endif /* !getenv */
  1560. Off_t lseek _((int,Off_t,int));
  1561. #  endif /* !DONT_DECLARE_STD */
  1562. char *getlogin _((void));
  1563. #endif /* !__cplusplus */
  1564.  
  1565. #ifdef UNLINK_ALL_VERSIONS /* Currently only makes sense for VMS */
  1566. #define UNLINK unlnk
  1567. I32 unlnk _((char*));
  1568. #else
  1569. #define UNLINK PerlLIO_unlink
  1570. #endif
  1571.  
  1572. #ifndef HAS_SETREUID
  1573. #  ifdef HAS_SETRESUID
  1574. #    define setreuid(r,e) setresuid(r,e,(Uid_t)-1)
  1575. #    define HAS_SETREUID
  1576. #  endif
  1577. #endif
  1578. #ifndef HAS_SETREGID
  1579. #  ifdef HAS_SETRESGID
  1580. #    define setregid(r,e) setresgid(r,e,(Gid_t)-1)
  1581. #    define HAS_SETREGID
  1582. #  endif
  1583. #endif
  1584.  
  1585. typedef Signal_t (*Sighandler_t) _((int));
  1586.  
  1587. #ifdef HAS_SIGACTION
  1588. typedef struct sigaction Sigsave_t;
  1589. #else
  1590. typedef Sighandler_t Sigsave_t;
  1591. #endif
  1592.  
  1593. #define SCAN_DEF 0
  1594. #define SCAN_TR 1
  1595. #define SCAN_REPL 2
  1596.  
  1597. #ifdef DEBUGGING
  1598. # ifndef register
  1599. #  define register
  1600. # endif
  1601. # define PAD_SV(po) pad_sv(po)
  1602. # define RUNOPS_DEFAULT runops_debug
  1603. #else
  1604. # define PAD_SV(po) PL_curpad[po]
  1605. # define RUNOPS_DEFAULT runops_standard
  1606. #endif
  1607.  
  1608. #ifdef MYMALLOC
  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
  1625. #else
  1626. #  define MALLOC_INIT
  1627. #  define MALLOC_TERM
  1628. #endif
  1629.  
  1630.  
  1631. /*
  1632.  * These need prototyping here because <proto.h> isn't
  1633.  * included until after runops is initialised.
  1634.  */
  1635.  
  1636. #ifndef PERL_OBJECT
  1637. typedef int runops_proc_t _((void));
  1638. int runops_standard _((void));
  1639. #ifdef DEBUGGING
  1640. int runops_debug _((void));
  1641. #endif
  1642. #endif  /* PERL_OBJECT */
  1643.  
  1644. /* _ (for $_) must be first in the following list (DEFSV requires it) */
  1645. #define THREADSV_NAMES "_123456789&`'+/.,\\\";^-%=|~:\001\005!@"
  1646.  
  1647. /* VMS doesn't use environ array and NeXT has problems with crt0.o globals */
  1648. #if !defined(VMS) && !(defined(NeXT) && defined(__DYNAMIC__))
  1649. #if !defined(DONT_DECLARE_STD) \
  1650.     || (defined(__svr4__) && defined(__GNUC__) && defined(sun)) \
  1651.     || defined(__sgi) || defined(__DGUX)
  1652. extern char **    environ;    /* environment variables supplied via exec */
  1653. #endif
  1654. #else
  1655. #  if defined(NeXT) && defined(__DYNAMIC__)
  1656.  
  1657. #  include <mach-o/dyld.h>
  1658. EXT char *** environ_pointer;
  1659. #  define environ (*environ_pointer)
  1660. #  endif
  1661. #endif /* environ processing */
  1662.  
  1663.  
  1664. /* for tmp use in stupid debuggers */
  1665. EXT int *    di;
  1666. EXT short *    ds;
  1667. EXT char *    dc;
  1668.  
  1669. /* handy constants */
  1670. EXTCONST char warn_uninit[]
  1671.   INIT("Use of uninitialized value");
  1672. EXTCONST char warn_nosemi[]
  1673.   INIT("Semicolon seems to be missing");
  1674. EXTCONST char warn_reserved[]
  1675.   INIT("Unquoted string \"%s\" may clash with future reserved word");
  1676. EXTCONST char warn_nl[]
  1677.   INIT("Unsuccessful %s on filename containing newline");
  1678. EXTCONST char no_wrongref[]
  1679.   INIT("Can't use %s ref as %s ref");
  1680. EXTCONST char no_symref[]
  1681.   INIT("Can't use string (\"%.32s\") as %s ref while \"strict refs\" in use");
  1682. EXTCONST char no_usym[]
  1683.   INIT("Can't use an undefined value as %s reference");
  1684. EXTCONST char no_aelem[]
  1685.   INIT("Modification of non-creatable array value attempted, subscript %d");
  1686. EXTCONST char no_helem[]
  1687.   INIT("Modification of non-creatable hash value attempted, subscript \"%s\"");
  1688. EXTCONST char no_modify[]
  1689.   INIT("Modification of a read-only value attempted");
  1690. EXTCONST char no_mem[]
  1691.   INIT("Out of memory!\n");
  1692. EXTCONST char no_security[]
  1693.   INIT("Insecure dependency in %s%s");
  1694. EXTCONST char no_sock_func[]
  1695.   INIT("Unsupported socket function \"%s\" called");
  1696. EXTCONST char no_dir_func[]
  1697.   INIT("Unsupported directory function \"%s\" called");
  1698. EXTCONST char no_func[]
  1699.   INIT("The %s function is unimplemented");
  1700. EXTCONST char no_myglob[]
  1701.   INIT("\"my\" variable %s can't be in a package");
  1702.  
  1703. #ifdef DOINIT
  1704. EXT char *sig_name[] = { SIG_NAME };
  1705. EXT int   sig_num[]  = { SIG_NUM };
  1706. #  ifndef PERL_OBJECT
  1707. EXT SV    * psig_ptr[sizeof(sig_num)/sizeof(*sig_num)];
  1708. EXT SV  * psig_name[sizeof(sig_num)/sizeof(*sig_num)];
  1709. #  endif
  1710. #else
  1711. EXT char *sig_name[];
  1712. EXT int   sig_num[];
  1713. #  ifndef PERL_OBJECT
  1714. EXT SV  * psig_ptr[];
  1715. EXT SV  * psig_name[];
  1716. #  endif
  1717. #endif
  1718.  
  1719.  
  1720. /* fast case folding tables */
  1721.  
  1722. #ifdef DOINIT
  1723. #ifdef EBCDIC
  1724. EXT unsigned char fold[] = { /* fast EBCDIC case folding table */
  1725.     0,      1,      2,      3,      4,      5,      6,      7,
  1726.     8,      9,      10,     11,     12,     13,     14,     15,
  1727.     16,     17,     18,     19,     20,     21,     22,     23,
  1728.     24,     25,     26,     27,     28,     29,     30,     31,
  1729.     32,     33,     34,     35,     36,     37,     38,     39,
  1730.     40,     41,     42,     43,     44,     45,     46,     47,
  1731.     48,     49,     50,     51,     52,     53,     54,     55,
  1732.     56,     57,     58,     59,     60,     61,     62,     63,
  1733.     64,     65,     66,     67,     68,     69,     70,     71,
  1734.     72,     73,     74,     75,     76,     77,     78,     79,
  1735.     80,     81,     82,     83,     84,     85,     86,     87,
  1736.     88,     89,     90,     91,     92,     93,     94,     95,
  1737.     96,     97,     98,     99,     100,    101,    102,    103,
  1738.     104,    105,    106,    107,    108,    109,    110,    111,
  1739.     112,    113,    114,    115,    116,    117,    118,    119,
  1740.     120,    121,    122,    123,    124,    125,    126,    127,
  1741.     128,    'A',    'B',    'C',    'D',    'E',    'F',    'G',
  1742.     'H',    'I',    138,    139,    140,    141,    142,    143,
  1743.     144,    'J',    'K',    'L',    'M',    'N',    'O',    'P',
  1744.     'Q',    'R',    154,    155,    156,    157,    158,    159,
  1745.     160,    161,    'S',    'T',    'U',    'V',    'W',    'X',
  1746.     'Y',    'Z',    170,    171,    172,    173,    174,    175,
  1747.     176,    177,    178,    179,    180,    181,    182,    183,
  1748.     184,    185,    186,    187,    188,    189,    190,    191,
  1749.     192,    'a',    'b',    'c',    'd',    'e',    'f',    'g',
  1750.     'h',    'i',    202,    203,    204,    205,    206,    207,
  1751.     208,    'j',    'k',    'l',    'm',    'n',    'o',    'p',
  1752.     'q',    'r',    218,    219,    220,    221,    222,    223,
  1753.     224,    225,    's',    't',    'u',    'v',    'w',    'x',
  1754.     'y',    'z',    234,    235,    236,    237,    238,    239,
  1755.     240,    241,    242,    243,    244,    245,    246,    247,
  1756.     248,    249,    250,    251,    252,    253,    254,    255
  1757. };
  1758. #else   /* ascii rather than ebcdic */
  1759. EXTCONST  unsigned char fold[] = {
  1760.     0,    1,    2,    3,    4,    5,    6,    7,
  1761.     8,    9,    10,    11,    12,    13,    14,    15,
  1762.     16,    17,    18,    19,    20,    21,    22,    23,
  1763.     24,    25,    26,    27,    28,    29,    30,    31,
  1764.     32,    33,    34,    35,    36,    37,    38,    39,
  1765.     40,    41,    42,    43,    44,    45,    46,    47,
  1766.     48,    49,    50,    51,    52,    53,    54,    55,
  1767.     56,    57,    58,    59,    60,    61,    62,    63,
  1768.     64,    'a',    'b',    'c',    'd',    'e',    'f',    'g',
  1769.     'h',    'i',    'j',    'k',    'l',    'm',    'n',    'o',
  1770.     'p',    'q',    'r',    's',    't',    'u',    'v',    'w',
  1771.     'x',    'y',    'z',    91,    92,    93,    94,    95,
  1772.     96,    'A',    'B',    'C',    'D',    'E',    'F',    'G',
  1773.     'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
  1774.     'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
  1775.     'X',    'Y',    'Z',    123,    124,    125,    126,    127,
  1776.     128,    129,    130,    131,    132,    133,    134,    135,
  1777.     136,    137,    138,    139,    140,    141,    142,    143,
  1778.     144,    145,    146,    147,    148,    149,    150,    151,
  1779.     152,    153,    154,    155,    156,    157,    158,    159,
  1780.     160,    161,    162,    163,    164,    165,    166,    167,
  1781.     168,    169,    170,    171,    172,    173,    174,    175,
  1782.     176,    177,    178,    179,    180,    181,    182,    183,
  1783.     184,    185,    186,    187,    188,    189,    190,    191,
  1784.     192,    193,    194,    195,    196,    197,    198,    199,
  1785.     200,    201,    202,    203,    204,    205,    206,    207,
  1786.     208,    209,    210,    211,    212,    213,    214,    215,
  1787.     216,    217,    218,    219,    220,    221,    222,    223,    
  1788.     224,    225,    226,    227,    228,    229,    230,    231,
  1789.     232,    233,    234,    235,    236,    237,    238,    239,
  1790.     240,    241,    242,    243,    244,    245,    246,    247,
  1791.     248,    249,    250,    251,    252,    253,    254,    255
  1792. };
  1793. #endif  /* !EBCDIC */
  1794. #else
  1795. EXTCONST unsigned char fold[];
  1796. #endif
  1797.  
  1798. #ifdef DOINIT
  1799. EXT unsigned char fold_locale[] = {
  1800.     0,    1,    2,    3,    4,    5,    6,    7,
  1801.     8,    9,    10,    11,    12,    13,    14,    15,
  1802.     16,    17,    18,    19,    20,    21,    22,    23,
  1803.     24,    25,    26,    27,    28,    29,    30,    31,
  1804.     32,    33,    34,    35,    36,    37,    38,    39,
  1805.     40,    41,    42,    43,    44,    45,    46,    47,
  1806.     48,    49,    50,    51,    52,    53,    54,    55,
  1807.     56,    57,    58,    59,    60,    61,    62,    63,
  1808.     64,    'a',    'b',    'c',    'd',    'e',    'f',    'g',
  1809.     'h',    'i',    'j',    'k',    'l',    'm',    'n',    'o',
  1810.     'p',    'q',    'r',    's',    't',    'u',    'v',    'w',
  1811.     'x',    'y',    'z',    91,    92,    93,    94,    95,
  1812.     96,    'A',    'B',    'C',    'D',    'E',    'F',    'G',
  1813.     'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
  1814.     'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
  1815.     'X',    'Y',    'Z',    123,    124,    125,    126,    127,
  1816.     128,    129,    130,    131,    132,    133,    134,    135,
  1817.     136,    137,    138,    139,    140,    141,    142,    143,
  1818.     144,    145,    146,    147,    148,    149,    150,    151,
  1819.     152,    153,    154,    155,    156,    157,    158,    159,
  1820.     160,    161,    162,    163,    164,    165,    166,    167,
  1821.     168,    169,    170,    171,    172,    173,    174,    175,
  1822.     176,    177,    178,    179,    180,    181,    182,    183,
  1823.     184,    185,    186,    187,    188,    189,    190,    191,
  1824.     192,    193,    194,    195,    196,    197,    198,    199,
  1825.     200,    201,    202,    203,    204,    205,    206,    207,
  1826.     208,    209,    210,    211,    212,    213,    214,    215,
  1827.     216,    217,    218,    219,    220,    221,    222,    223,    
  1828.     224,    225,    226,    227,    228,    229,    230,    231,
  1829.     232,    233,    234,    235,    236,    237,    238,    239,
  1830.     240,    241,    242,    243,    244,    245,    246,    247,
  1831.     248,    249,    250,    251,    252,    253,    254,    255
  1832. };
  1833. #else
  1834. EXT unsigned char fold_locale[];
  1835. #endif
  1836.  
  1837. #ifdef DOINIT
  1838. #ifdef EBCDIC
  1839. EXT unsigned char freq[] = {/* EBCDIC frequencies for mixed English/C */
  1840.     1,      2,      84,     151,    154,    155,    156,    157,
  1841.     165,    246,    250,    3,      158,    7,      18,     29,
  1842.     40,     51,     62,     73,     85,     96,     107,    118,
  1843.     129,    140,    147,    148,    149,    150,    152,    153,
  1844.     255,      6,      8,      9,     10,     11,     12,     13,
  1845.      14,     15,     24,     25,     26,     27,     28,    226,
  1846.      29,     30,     31,     32,     33,     43,     44,     45,
  1847.      46,     47,     48,     49,     50,     76,     77,     78,
  1848.      79,     80,     81,     82,     83,     84,     85,     86,
  1849.      87,     94,     95,    234,    181,    233,    187,    190,
  1850.     180,     96,     97,     98,     99,    100,    101,    102,
  1851.     104,    112,    182,    174,    236,    232,    229,    103,
  1852.     228,    226,    114,    115,    116,    117,    118,    119,
  1853.     120,    121,    122,    235,    176,    230,    194,    162,
  1854.     130,    131,    132,    133,    134,    135,    136,    137,
  1855.     138,    139,    201,    205,    163,    217,    220,    224,
  1856.     5,      248,    227,    244,    242,    255,    241,    231,
  1857.     240,    253,    16,     197,    19,     20,     21,     187,
  1858.     23,     169,    210,    245,    237,    249,    247,    239,
  1859.     168,    252,    34,     196,    36,     37,     38,     39,
  1860.     41,     42,     251,    254,    238,    223,    221,    213,
  1861.     225,    177,    52,     53,     54,     55,     56,     57,
  1862.     58,     59,     60,     61,     63,     64,     65,     66,
  1863.     67,     68,     69,     70,     71,     72,     74,     75,
  1864.     205,    208,    186,    202,    200,    218,    198,    179,
  1865.     178,    214,    88,     89,     90,     91,     92,     93,
  1866.     217,    166,    170,    207,    199,    209,    206,    204,
  1867.     160,    212,    105,    106,    108,    109,    110,    111,
  1868.     203,    113,    216,    215,    192,    175,    193,    243,
  1869.     172,    161,    123,    124,    125,    126,    127,    128,
  1870.     222,    219,    211,    195,    188,    193,    185,    184,
  1871.     191,    183,    141,    142,    143,    144,    145,    146
  1872. };
  1873. #else  /* ascii rather than ebcdic */
  1874. EXTCONST unsigned char freq[] = {    /* letter frequencies for mixed English/C */
  1875.     1,    2,    84,    151,    154,    155,    156,    157,
  1876.     165,    246,    250,    3,    158,    7,    18,    29,
  1877.     40,    51,    62,    73,    85,    96,    107,    118,
  1878.     129,    140,    147,    148,    149,    150,    152,    153,
  1879.     255,    182,    224,    205,    174,    176,    180,    217,
  1880.     233,    232,    236,    187,    235,    228,    234,    226,
  1881.     222,    219,    211,    195,    188,    193,    185,    184,
  1882.     191,    183,    201,    229,    181,    220,    194,    162,
  1883.     163,    208,    186,    202,    200,    218,    198,    179,
  1884.     178,    214,    166,    170,    207,    199,    209,    206,
  1885.     204,    160,    212,    216,    215,    192,    175,    173,
  1886.     243,    172,    161,    190,    203,    189,    164,    230,
  1887.     167,    248,    227,    244,    242,    255,    241,    231,
  1888.     240,    253,    169,    210,    245,    237,    249,    247,
  1889.     239,    168,    252,    251,    254,    238,    223,    221,
  1890.     213,    225,    177,    197,    171,    196,    159,    4,
  1891.     5,    6,    8,    9,    10,    11,    12,    13,
  1892.     14,    15,    16,    17,    19,    20,    21,    22,
  1893.     23,    24,    25,    26,    27,    28,    30,    31,
  1894.     32,    33,    34,    35,    36,    37,    38,    39,
  1895.     41,    42,    43,    44,    45,    46,    47,    48,
  1896.     49,    50,    52,    53,    54,    55,    56,    57,
  1897.     58,    59,    60,    61,    63,    64,    65,    66,
  1898.     67,    68,    69,    70,    71,    72,    74,    75,
  1899.     76,    77,    78,    79,    80,    81,    82,    83,
  1900.     86,    87,    88,    89,    90,    91,    92,    93,
  1901.     94,    95,    97,    98,    99,    100,    101,    102,
  1902.     103,    104,    105,    106,    108,    109,    110,    111,
  1903.     112,    113,    114,    115,    116,    117,    119,    120,
  1904.     121,    122,    123,    124,    125,    126,    127,    128,
  1905.     130,    131,    132,    133,    134,    135,    136,    137,
  1906.     138,    139,    141,    142,    143,    144,    145,    146
  1907. };
  1908. #endif
  1909. #else
  1910. EXTCONST unsigned char freq[];
  1911. #endif
  1912.  
  1913. #ifdef DEBUGGING
  1914. #ifdef DOINIT
  1915. EXTCONST char* block_type[] = {
  1916.     "NULL",
  1917.     "SUB",
  1918.     "EVAL",
  1919.     "LOOP",
  1920.     "SUBST",
  1921.     "BLOCK",
  1922. };
  1923. #else
  1924. EXTCONST char* block_type[];
  1925. #endif
  1926. #endif
  1927.  
  1928. /*****************************************************************************/
  1929. /* This lexer/parser stuff is currently global since yacc is hard to reenter */
  1930. /*****************************************************************************/
  1931. /* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */
  1932.  
  1933. #include "perly.h"
  1934.  
  1935. #define LEX_NOTPARSING        11    /* borrowed from toke.c */
  1936.  
  1937. typedef enum {
  1938.     XOPERATOR,
  1939.     XTERM,
  1940.     XREF,
  1941.     XSTATE,
  1942.     XBLOCK,
  1943.     XTERMBLOCK
  1944. } expectation;
  1945.  
  1946. enum {        /* pass one of these to get_vtbl */
  1947.     want_vtbl_sv,
  1948.     want_vtbl_env,
  1949.     want_vtbl_envelem,
  1950.     want_vtbl_sig,
  1951.     want_vtbl_sigelem,
  1952.     want_vtbl_pack,
  1953.     want_vtbl_packelem,
  1954.     want_vtbl_dbline,
  1955.     want_vtbl_isa,
  1956.     want_vtbl_isaelem,
  1957.     want_vtbl_arylen,
  1958.     want_vtbl_glob,
  1959.     want_vtbl_mglob,
  1960.     want_vtbl_nkeys,
  1961.     want_vtbl_taint,
  1962.     want_vtbl_substr,
  1963.     want_vtbl_vec,
  1964.     want_vtbl_pos,
  1965.     want_vtbl_bm,
  1966.     want_vtbl_fm,
  1967.     want_vtbl_uvar,
  1968.     want_vtbl_defelem,
  1969.     want_vtbl_regexp,
  1970.     want_vtbl_collxfrm,
  1971.     want_vtbl_amagic,
  1972.     want_vtbl_amagicelem
  1973. #ifdef USE_THREADS
  1974.     ,
  1975.     want_vtbl_mutex
  1976. #endif
  1977. };
  1978.  
  1979.  
  1980.                 /* Note: the lowest 8 bits are reserved for
  1981.                    stuffing into op->op_private */
  1982. #define HINT_INTEGER        0x00000001
  1983. #define HINT_STRICT_REFS    0x00000002
  1984.  
  1985. #define HINT_BLOCK_SCOPE    0x00000100
  1986. #define HINT_STRICT_SUBS    0x00000200
  1987. #define HINT_STRICT_VARS    0x00000400
  1988. #define HINT_LOCALE        0x00000800
  1989.  
  1990. #define HINT_NEW_INTEGER    0x00001000
  1991. #define HINT_NEW_FLOAT        0x00002000
  1992. #define HINT_NEW_BINARY        0x00004000
  1993. #define HINT_NEW_STRING        0x00008000
  1994. #define HINT_NEW_RE        0x00010000
  1995. #define HINT_LOCALIZE_HH    0x00020000 /* %^H needs to be copied */
  1996.  
  1997. #define HINT_RE_TAINT        0x00100000
  1998. #define HINT_RE_EVAL        0x00200000
  1999.  
  2000. /* Various states of an input record separator SV (rs, nrs) */
  2001. #define RsSNARF(sv)   (! SvOK(sv))
  2002. #define RsSIMPLE(sv)  (SvOK(sv) && SvCUR(sv))
  2003. #define RsPARA(sv)    (SvOK(sv) && ! SvCUR(sv))
  2004. #define RsRECORD(sv)  (SvROK(sv) && (SvIV(SvRV(sv)) > 0))
  2005.  
  2006. /* Enable variables which are pointers to functions */
  2007. #ifdef PERL_OBJECT
  2008. typedef regexp*(CPerlObj::*regcomp_t) _((char* exp, char* xend, PMOP* pm));
  2009. typedef I32 (CPerlObj::*regexec_t) _((regexp* prog, char* stringarg,
  2010.                       char* strend, char* strbeg,
  2011.                       I32 minend, SV* screamer, void* data,
  2012.                       U32 flags));
  2013. #else
  2014. typedef regexp*(*regcomp_t) _((char* exp, char* xend, PMOP* pm));
  2015. typedef I32 (*regexec_t) _((regexp* prog, char* stringarg, char* strend, char*
  2016.                 strbeg, I32 minend, SV* screamer, void* data, 
  2017.                 U32 flags));
  2018.  
  2019. #endif
  2020.  
  2021. /* Set up PERLVAR macros for populating structs */
  2022. #define PERLVAR(var,type) type var;
  2023. #define PERLVARI(var,type,init) type var;
  2024. #define PERLVARIC(var,type,init) type var;
  2025.  
  2026. /* Interpreter exitlist entry */
  2027. typedef struct exitlistentry {
  2028. #ifdef PERL_OBJECT
  2029.     void (*fn) _((CPerlObj*, void*));
  2030. #else
  2031.     void (*fn) _((void*));
  2032. #endif
  2033.     void *ptr;
  2034. } PerlExitListEntry;
  2035.  
  2036. #ifdef PERL_OBJECT
  2037. extern "C" CPerlObj* perl_alloc _((IPerlMem*, IPerlEnv*, IPerlStdIO*, IPerlLIO*, IPerlDir*, IPerlSock*, IPerlProc*));
  2038.  
  2039. typedef int (CPerlObj::*runops_proc_t) _((void));
  2040. #undef EXT
  2041. #define EXT
  2042. #undef EXTCONST
  2043. #define EXTCONST
  2044. #undef INIT
  2045. #define INIT(x)
  2046.  
  2047. const int perl_object_sig_num[]  = { SIG_NUM };
  2048. const int PSIG_SIZE = (sizeof(perl_object_sig_num)/sizeof(*perl_object_sig_num));
  2049.  
  2050.  
  2051. class CPerlObj {
  2052. public:
  2053.     CPerlObj(IPerlMem*, IPerlEnv*, IPerlStdIO*, IPerlLIO*, IPerlDir*, IPerlSock*, IPerlProc*);
  2054.     void Init(void);
  2055.     void* operator new(size_t nSize, IPerlMem *pvtbl);
  2056. #endif /* PERL_OBJECT */
  2057.  
  2058. #ifdef PERL_GLOBAL_STRUCT
  2059. struct perl_vars {
  2060. #include "perlvars.h"
  2061. };
  2062.  
  2063. #ifdef PERL_CORE
  2064. EXT struct perl_vars PL_Vars;
  2065. EXT struct perl_vars *PL_VarsPtr INIT(&PL_Vars);
  2066. #else /* PERL_CORE */
  2067. #if !defined(__GNUC__) || !defined(WIN32)
  2068. EXT
  2069. #endif /* WIN32 */
  2070. struct perl_vars *PL_VarsPtr;
  2071. #define PL_Vars (*((PL_VarsPtr) ? PL_VarsPtr : (PL_VarsPtr =  Perl_GetVars())))
  2072. #endif /* PERL_CORE */
  2073. #endif /* PERL_GLOBAL_STRUCT */
  2074.  
  2075. #ifdef MULTIPLICITY
  2076. /* If we have multiple interpreters define a struct 
  2077.    holding variables which must be per-interpreter
  2078.    If we don't have threads anything that would have 
  2079.    be per-thread is per-interpreter.
  2080. */
  2081.  
  2082. struct interpreter {
  2083. #ifndef USE_THREADS
  2084. #include "thrdvar.h"
  2085. #endif
  2086. #include "intrpvar.h"
  2087. };
  2088.  
  2089. #else
  2090. struct interpreter {
  2091.     char broiled;
  2092. };
  2093. #endif
  2094.  
  2095. #ifdef USE_THREADS
  2096. /* If we have threads define a struct with all the variables
  2097.  * that have to be per-thread
  2098.  */
  2099.  
  2100.  
  2101. struct perl_thread {
  2102. #include "thrdvar.h"
  2103. };
  2104.  
  2105. typedef struct perl_thread *Thread;
  2106.  
  2107. #else
  2108. typedef void *Thread;
  2109. #endif
  2110.  
  2111. /* Done with PERLVAR macros for now ... */
  2112. #undef PERLVAR
  2113. #undef PERLVARI
  2114. #undef PERLVARIC
  2115.  
  2116. #include "thread.h"
  2117. #include "pp.h"
  2118. #include "proto.h"
  2119.  
  2120. #ifdef EMBED
  2121. #define Perl_sv_setptrobj(rv,ptr,name) Perl_sv_setref_iv(rv,name,(IV)ptr)
  2122. #define Perl_sv_setptrref(rv,ptr) Perl_sv_setref_iv(rv,Nullch,(IV)ptr)
  2123. #else
  2124. #define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,(IV)ptr)
  2125. #define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,(IV)ptr)
  2126. #endif
  2127.  
  2128. /* The following must follow proto.h as #defines mess up syntax */
  2129.  
  2130. #include "embedvar.h"
  2131.  
  2132. /* Now include all the 'global' variables 
  2133.  * If we don't have threads or multiple interpreters
  2134.  * these include variables that would have been their struct-s 
  2135.  */
  2136.                          
  2137. #define PERLVAR(var,type) EXT type PL_##var;
  2138. #define PERLVARI(var,type,init) EXT type  PL_##var INIT(init);
  2139. #define PERLVARIC(var,type,init) EXTCONST type PL_##var INIT(init);
  2140.  
  2141. #ifndef PERL_GLOBAL_STRUCT
  2142. #include "perlvars.h"
  2143. #endif
  2144.  
  2145. #ifndef MULTIPLICITY
  2146.  
  2147. #  include "intrpvar.h"
  2148. #  ifndef USE_THREADS
  2149. #    include "thrdvar.h"
  2150. #  endif
  2151.  
  2152. #endif
  2153.  
  2154. #ifdef PERL_OBJECT
  2155. /* from perly.c */
  2156. #undef  yydebug
  2157. #undef  yynerrs
  2158. #undef  yyerrflag
  2159. #undef  yychar
  2160. #undef  yyssp
  2161. #undef  yyvsp
  2162. #undef  yyval
  2163. #undef  yylval
  2164. #define yydebug        PL_yydebug
  2165. #define yynerrs        PL_yynerrs
  2166. #define yyerrflag   PL_yyerrflag
  2167. #define yychar        PL_yychar
  2168. #define yyssp        PL_yyssp
  2169. #define yyvsp        PL_yyvsp
  2170. #define yyval        PL_yyval
  2171. #define yylval        PL_yylval
  2172. PERLVAR(yydebug,        int)
  2173. PERLVAR(yynerrs,        int)
  2174. PERLVAR(yyerrflag,        int)
  2175. PERLVAR(yychar,            int)
  2176. PERLVAR(yyssp,            short*)
  2177. PERLVAR(yyvsp,            YYSTYPE*)
  2178. PERLVAR(yyval,            YYSTYPE)
  2179. PERLVAR(yylval,            YYSTYPE)
  2180.  
  2181. #define efloatbuf        PL_efloatbuf
  2182. #define efloatsize        PL_efloatsize
  2183. PERLVAR(efloatbuf,        char *)
  2184. PERLVAR(efloatsize,        STRLEN)
  2185.  
  2186. #define glob_index        PL_glob_index
  2187. #define srand_called    PL_srand_called
  2188. #define uudmap            PL_uudmap
  2189. #define bitcount        PL_bitcount
  2190. #define filter_debug    PL_filter_debug
  2191. PERLVAR(glob_index,        int)
  2192. PERLVAR(srand_called,    bool)
  2193. PERLVAR(uudmap[256],    char)
  2194. PERLVAR(bitcount,        char*)
  2195. PERLVAR(filter_debug,    int)
  2196. PERLVAR(super_bufptr,    char*)    /* PL_bufptr that was */
  2197. PERLVAR(super_bufend,    char*)    /* PL_bufend that was */
  2198.  
  2199. #define psig_ptr        PL_psig_ptr
  2200. #define psig_name        PL_psig_name
  2201. PERLVAR(psig_ptr[PSIG_SIZE], SV*);
  2202. PERLVAR(psig_name[PSIG_SIZE], SV*);
  2203.  
  2204. /*
  2205.  * The following is a buffer where new variables must
  2206.  * be defined to maintain binary compatibility with PERL_OBJECT
  2207.  * for 5.005
  2208.  */
  2209. PERLVAR(object_compatibility[30],    char)
  2210. };
  2211.  
  2212. #include "objpp.h"
  2213. #ifdef DOINIT
  2214. #include "INTERN.h"
  2215. #else
  2216. #include "EXTERN.h"
  2217. #endif
  2218. #endif  /* PERL_OBJECT */
  2219.  
  2220.  
  2221. #undef PERLVAR
  2222. #undef PERLVARI
  2223. #undef PERLVARIC
  2224.  
  2225. #if defined(HASATTRIBUTE) && defined(WIN32)
  2226. /*
  2227.  * This provides a layer of functions and macros to ensure extensions will
  2228.  * get to use the same RTL functions as the core.
  2229.  * It has to go here or #define of printf messes up __attribute__
  2230.  * stuff in proto.h  
  2231.  */
  2232. #ifndef PERL_OBJECT
  2233. #  include <win32iop.h>
  2234. #endif  /* PERL_OBJECT */
  2235. #endif    /* WIN32 */
  2236.  
  2237. #ifdef DOINIT
  2238.  
  2239. EXT MGVTBL vtbl_sv =    {magic_get,
  2240.                 magic_set,
  2241.                     magic_len,
  2242.                         0,    0};
  2243. EXT MGVTBL vtbl_env =    {0,    magic_set_all_env,
  2244.                 0,    magic_clear_all_env,
  2245.                             0};
  2246. EXT MGVTBL vtbl_envelem =    {0,    magic_setenv,
  2247.                     0,    magic_clearenv,
  2248.                             0};
  2249. EXT MGVTBL vtbl_sig =    {0,    0,         0, 0, 0};
  2250. EXT MGVTBL vtbl_sigelem =    {magic_getsig,
  2251.                     magic_setsig,
  2252.                     0,    magic_clearsig,
  2253.                             0};
  2254. EXT MGVTBL vtbl_pack =    {0,    0,    magic_sizepack,    magic_wipepack,
  2255.                             0};
  2256. EXT MGVTBL vtbl_packelem =    {magic_getpack,
  2257.                 magic_setpack,
  2258.                     0,    magic_clearpack,
  2259.                             0};
  2260. EXT MGVTBL vtbl_dbline =    {0,    magic_setdbline,
  2261.                     0,    0,    0};
  2262. EXT MGVTBL vtbl_isa =    {0,    magic_setisa,
  2263.                     0,    magic_setisa,
  2264.                             0};
  2265. EXT MGVTBL vtbl_isaelem =    {0,    magic_setisa,
  2266.                     0,    0,    0};
  2267. EXT MGVTBL vtbl_arylen =    {magic_getarylen,
  2268.                 magic_setarylen,
  2269.                     0,    0,    0};
  2270. EXT MGVTBL vtbl_glob =    {magic_getglob,
  2271.                 magic_setglob,
  2272.                     0,    0,    0};
  2273. EXT MGVTBL vtbl_mglob =    {0,    magic_setmglob,
  2274.                     0,    0,    0};
  2275. EXT MGVTBL vtbl_nkeys =    {magic_getnkeys,
  2276.                 magic_setnkeys,
  2277.                     0,    0,    0};
  2278. EXT MGVTBL vtbl_taint =    {magic_gettaint,magic_settaint,
  2279.                     0,    0,    0};
  2280. EXT MGVTBL vtbl_substr =    {magic_getsubstr, magic_setsubstr,
  2281.                     0,    0,    0};
  2282. EXT MGVTBL vtbl_vec =    {magic_getvec,
  2283.                 magic_setvec,
  2284.                     0,    0,    0};
  2285. EXT MGVTBL vtbl_pos =    {magic_getpos,
  2286.                 magic_setpos,
  2287.                     0,    0,    0};
  2288. EXT MGVTBL vtbl_bm =    {0,    magic_setbm,
  2289.                     0,    0,    0};
  2290. EXT MGVTBL vtbl_fm =    {0,    magic_setfm,
  2291.                     0,    0,    0};
  2292. EXT MGVTBL vtbl_uvar =    {magic_getuvar,
  2293.                 magic_setuvar,
  2294.                     0,    0,    0};
  2295. #ifdef USE_THREADS
  2296. EXT MGVTBL vtbl_mutex =    {0,    0,    0,    0,    magic_mutexfree};
  2297. #endif /* USE_THREADS */
  2298. EXT MGVTBL vtbl_defelem = {magic_getdefelem,magic_setdefelem,
  2299.                     0,    0,    0};
  2300.  
  2301. EXT MGVTBL vtbl_regexp = {0,0,0,0, magic_freeregexp};
  2302.  
  2303. #ifdef USE_LOCALE_COLLATE
  2304. EXT MGVTBL vtbl_collxfrm = {0,
  2305.                 magic_setcollxfrm,
  2306.                     0,    0,    0};
  2307. #endif
  2308.  
  2309. #ifdef OVERLOAD
  2310. EXT MGVTBL vtbl_amagic =       {0,     magic_setamagic,
  2311.                                         0,      0,      magic_setamagic};
  2312. EXT MGVTBL vtbl_amagicelem =   {0,     magic_setamagic,
  2313.                                         0,      0,      magic_setamagic};
  2314. #endif /* OVERLOAD */
  2315.  
  2316. #else /* !DOINIT */
  2317.  
  2318. EXT MGVTBL vtbl_sv;
  2319. EXT MGVTBL vtbl_env;
  2320. EXT MGVTBL vtbl_envelem;
  2321. EXT MGVTBL vtbl_sig;
  2322. EXT MGVTBL vtbl_sigelem;
  2323. EXT MGVTBL vtbl_pack;
  2324. EXT MGVTBL vtbl_packelem;
  2325. EXT MGVTBL vtbl_dbline;
  2326. EXT MGVTBL vtbl_isa;
  2327. EXT MGVTBL vtbl_isaelem;
  2328. EXT MGVTBL vtbl_arylen;
  2329. EXT MGVTBL vtbl_glob;
  2330. EXT MGVTBL vtbl_mglob;
  2331. EXT MGVTBL vtbl_nkeys;
  2332. EXT MGVTBL vtbl_taint;
  2333. EXT MGVTBL vtbl_substr;
  2334. EXT MGVTBL vtbl_vec;
  2335. EXT MGVTBL vtbl_pos;
  2336. EXT MGVTBL vtbl_bm;
  2337. EXT MGVTBL vtbl_fm;
  2338. EXT MGVTBL vtbl_uvar;
  2339.  
  2340. #ifdef USE_THREADS
  2341. EXT MGVTBL vtbl_mutex;
  2342. #endif /* USE_THREADS */
  2343.  
  2344. EXT MGVTBL vtbl_defelem;
  2345. EXT MGVTBL vtbl_regexp;
  2346.  
  2347. #ifdef USE_LOCALE_COLLATE
  2348. EXT MGVTBL vtbl_collxfrm;
  2349. #endif
  2350.  
  2351. #ifdef OVERLOAD
  2352. EXT MGVTBL vtbl_amagic;
  2353. EXT MGVTBL vtbl_amagicelem;
  2354. #endif /* OVERLOAD */
  2355.  
  2356. #endif /* !DOINIT */
  2357.  
  2358. #ifdef OVERLOAD
  2359.  
  2360. #define NofAMmeth 58
  2361. #ifdef DOINIT
  2362. EXTCONST char * AMG_names[NofAMmeth] = {
  2363.   "fallback",    "abs",            /* "fallback" should be the first. */
  2364.   "bool",    "nomethod",
  2365.   "\"\"",    "0+",
  2366.   "+",        "+=",
  2367.   "-",        "-=",
  2368.   "*",        "*=",
  2369.   "/",        "/=",
  2370.   "%",        "%=",
  2371.   "**",        "**=",
  2372.   "<<",        "<<=",
  2373.   ">>",        ">>=",
  2374.   "&",        "&=",
  2375.   "|",        "|=",
  2376.   "^",        "^=",
  2377.   "<",        "<=",
  2378.   ">",        ">=",
  2379.   "==",        "!=",
  2380.   "<=>",    "cmp",
  2381.   "lt",        "le",
  2382.   "gt",        "ge",
  2383.   "eq",        "ne",
  2384.   "!",        "~",
  2385.   "++",        "--",
  2386.   "atan2",    "cos",
  2387.   "sin",    "exp",
  2388.   "log",    "sqrt",
  2389.   "x",        "x=",
  2390.   ".",        ".=",
  2391.   "=",        "neg"
  2392. };
  2393. #else
  2394. EXTCONST char * AMG_names[NofAMmeth];
  2395. #endif /* def INITAMAGIC */
  2396.  
  2397. struct am_table {
  2398.   long was_ok_sub;
  2399.   long was_ok_am;
  2400.   U32 flags;
  2401.   CV* table[NofAMmeth];
  2402.   long fallback;
  2403. };
  2404. struct am_table_short {
  2405.   long was_ok_sub;
  2406.   long was_ok_am;
  2407.   U32 flags;
  2408. };
  2409. typedef struct am_table AMT;
  2410. typedef struct am_table_short AMTS;
  2411.  
  2412. #define AMGfallNEVER    1
  2413. #define AMGfallNO    2
  2414. #define AMGfallYES    3
  2415.  
  2416. #define AMTf_AMAGIC        1
  2417. #define AMT_AMAGIC(amt)        ((amt)->flags & AMTf_AMAGIC)
  2418. #define AMT_AMAGIC_on(amt)    ((amt)->flags |= AMTf_AMAGIC)
  2419. #define AMT_AMAGIC_off(amt)    ((amt)->flags &= ~AMTf_AMAGIC)
  2420.  
  2421. enum {
  2422.   fallback_amg,    abs_amg,
  2423.   bool__amg,    nomethod_amg,
  2424.   string_amg,    numer_amg,
  2425.   add_amg,    add_ass_amg,
  2426.   subtr_amg,    subtr_ass_amg,
  2427.   mult_amg,    mult_ass_amg,
  2428.   div_amg,    div_ass_amg,
  2429.   modulo_amg,    modulo_ass_amg,
  2430.   pow_amg,    pow_ass_amg,
  2431.   lshift_amg,    lshift_ass_amg,
  2432.   rshift_amg,    rshift_ass_amg,
  2433.   band_amg,    band_ass_amg,
  2434.   bor_amg,    bor_ass_amg,
  2435.   bxor_amg,    bxor_ass_amg,
  2436.   lt_amg,    le_amg,
  2437.   gt_amg,    ge_amg,
  2438.   eq_amg,    ne_amg,
  2439.   ncmp_amg,    scmp_amg,
  2440.   slt_amg,    sle_amg,
  2441.   sgt_amg,    sge_amg,
  2442.   seq_amg,    sne_amg,
  2443.   not_amg,    compl_amg,
  2444.   inc_amg,    dec_amg,
  2445.   atan2_amg,    cos_amg,
  2446.   sin_amg,    exp_amg,
  2447.   log_amg,    sqrt_amg,
  2448.   repeat_amg,   repeat_ass_amg,
  2449.   concat_amg,    concat_ass_amg,
  2450.   copy_amg,    neg_amg
  2451. };
  2452.  
  2453. /*
  2454.  * some compilers like to redefine cos et alia as faster
  2455.  * (and less accurate?) versions called F_cos et cetera (Quidquid
  2456.  * latine dictum sit, altum viditur.)  This trick collides with
  2457.  * the Perl overloading (amg).  The following #defines fool both.
  2458.  */
  2459.  
  2460. #ifdef _FASTMATH
  2461. #   ifdef atan2
  2462. #       define F_atan2_amg  atan2_amg
  2463. #   endif
  2464. #   ifdef cos
  2465. #       define F_cos_amg    cos_amg
  2466. #   endif
  2467. #   ifdef exp
  2468. #       define F_exp_amg    exp_amg
  2469. #   endif
  2470. #   ifdef log
  2471. #       define F_log_amg    log_amg
  2472. #   endif
  2473. #   ifdef pow
  2474. #       define F_pow_amg    pow_amg
  2475. #   endif
  2476. #   ifdef sin
  2477. #       define F_sin_amg    sin_amg
  2478. #   endif
  2479. #   ifdef sqrt
  2480. #       define F_sqrt_amg   sqrt_amg
  2481. #   endif
  2482. #endif /* _FASTMATH */
  2483.  
  2484. #endif /* OVERLOAD */
  2485.  
  2486. #define PERLDB_ALL    0x3f        /* No _NONAME, _GOTO */
  2487. #define PERLDBf_SUB    0x01        /* Debug sub enter/exit. */
  2488. #define PERLDBf_LINE    0x02        /* Keep line #. */
  2489. #define PERLDBf_NOOPT    0x04        /* Switch off optimizations. */
  2490. #define PERLDBf_INTER    0x08        /* Preserve more data for
  2491.                        later inspections.  */
  2492. #define PERLDBf_SUBLINE    0x10        /* Keep subr source lines. */
  2493. #define PERLDBf_SINGLE    0x20        /* Start with single-step on. */
  2494. #define PERLDBf_NONAME    0x40        /* For _SUB: no name of the subr. */
  2495. #define PERLDBf_GOTO    0x80        /* Report goto: call DB::goto. */
  2496.  
  2497. #define PERLDB_SUB    (PL_perldb && (PL_perldb & PERLDBf_SUB))
  2498. #define PERLDB_LINE    (PL_perldb && (PL_perldb & PERLDBf_LINE))
  2499. #define PERLDB_NOOPT    (PL_perldb && (PL_perldb & PERLDBf_NOOPT))
  2500. #define PERLDB_INTER    (PL_perldb && (PL_perldb & PERLDBf_INTER))
  2501. #define PERLDB_SUBLINE    (PL_perldb && (PL_perldb & PERLDBf_SUBLINE))
  2502. #define PERLDB_SINGLE    (PL_perldb && (PL_perldb & PERLDBf_SINGLE))
  2503. #define PERLDB_SUB_NN    (PL_perldb && (PL_perldb & (PERLDBf_NONAME)))
  2504. #define PERLDB_GOTO    (PL_perldb && (PL_perldb & PERLDBf_GOTO))
  2505.  
  2506.  
  2507. #ifdef USE_LOCALE_NUMERIC
  2508.  
  2509. #define SET_NUMERIC_STANDARD() \
  2510.     STMT_START {                \
  2511.     if (! PL_numeric_standard)            \
  2512.         perl_set_numeric_standard();    \
  2513.     } STMT_END
  2514.  
  2515. #define SET_NUMERIC_LOCAL() \
  2516.     STMT_START {                \
  2517.     if (! PL_numeric_local)            \
  2518.         perl_set_numeric_local();        \
  2519.     } STMT_END
  2520.  
  2521. #else /* !USE_LOCALE_NUMERIC */
  2522.  
  2523. #define SET_NUMERIC_STANDARD()  /**/
  2524. #define SET_NUMERIC_LOCAL()     /**/
  2525.  
  2526. #endif /* !USE_LOCALE_NUMERIC */
  2527.  
  2528. #if !defined(PERLIO_IS_STDIO) && defined(HASATTRIBUTE)
  2529. /* 
  2530.  * Now we have __attribute__ out of the way 
  2531.  * Remap printf 
  2532.  */
  2533. #define printf PerlIO_stdoutf
  2534. #endif
  2535.  
  2536. #ifndef PERL_SCRIPT_MODE
  2537. #define PERL_SCRIPT_MODE "r"
  2538. #endif
  2539.  
  2540. /*
  2541.  * nice_chunk and nice_chunk size need to be set
  2542.  * and queried under the protection of sv_mutex
  2543.  */
  2544. #define offer_nice_chunk(chunk, chunk_size) do {    \
  2545.     LOCK_SV_MUTEX;                    \
  2546.     if (!PL_nice_chunk) {                \
  2547.         PL_nice_chunk = (char*)(chunk);        \
  2548.         PL_nice_chunk_size = (chunk_size);        \
  2549.     }                        \
  2550.     else {                        \
  2551.         Safefree(chunk);                \
  2552.     }                        \
  2553.     UNLOCK_SV_MUTEX;                \
  2554.     } while (0)
  2555.  
  2556. #ifdef HAS_SEM
  2557. #   include <sys/ipc.h>
  2558. #   include <sys/sem.h>
  2559. #   ifndef HAS_UNION_SEMUN    /* Provide the union semun. */
  2560.     union semun {
  2561.     int val;
  2562.     struct semid_ds *buf;
  2563.     unsigned short *array;
  2564.     };
  2565. #   endif
  2566. #   ifdef USE_SEMCTL_SEMUN
  2567. #       define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun)
  2568. #   else
  2569. #       ifdef USE_SEMCTL_SEMID_DS
  2570. #           define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun.buf)
  2571. #       endif
  2572. #   endif
  2573. #   ifndef Semctl    /* Place our bets on the semun horse. */
  2574. #       define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun)
  2575. #   endif
  2576. #endif
  2577.  
  2578. #ifdef IAMSUID
  2579.  
  2580. #ifdef I_SYS_STATVFS
  2581. #   include <sys/statvfs.h>     /* for f?statvfs() */
  2582. #endif
  2583. #ifdef I_SYS_MOUNT
  2584. #   include <sys/mount.h>       /* for *BSD f?statfs() */
  2585. #endif
  2586. #ifdef I_MNTENT
  2587. #   include <mntent.h>          /* for getmntent() */
  2588. #endif
  2589.  
  2590. #endif /* IAMSUID */
  2591.  
  2592. #endif /* Include guard */
  2593.