home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2004 July / APC0407D2.iso / workshop / apache / files / ActivePerl-5.6.1.638-MSWin32-x86.msi / _8f156b9745a8b8ee165f4f32697ac012 < prev    next >
Encoding:
Text File  |  2004-04-13  |  96.7 KB  |  3,570 lines

  1. /*    perl.h
  2.  *
  3.  *    Copyright (c) 1987-2001, 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.  
  12. #ifdef PERL_FOR_X2P
  13. /*
  14.  * This file is being used for x2p stuff. 
  15.  * Above symbol is defined via -D in 'x2p/Makefile.SH'
  16.  * Decouple x2p stuff from some of perls more extreme eccentricities. 
  17.  */
  18. #undef MULTIPLICITY
  19. #undef USE_STDIO
  20. #define USE_STDIO
  21. #endif /* PERL_FOR_X2P */
  22.  
  23. #define VOIDUSED 1
  24. #include "config.h"
  25.  
  26. #if defined(USE_ITHREADS) && defined(USE_5005THREADS)
  27. #  include "error: USE_ITHREADS and USE_5005THREADS are incompatible"
  28. #endif
  29.  
  30. /* XXX This next guard can disappear if the sources are revised
  31.    to use USE_5005THREADS throughout. -- A.D  1/6/2000
  32. */
  33. #if defined(USE_ITHREADS) && defined(USE_THREADS)
  34. #  include "error: USE_ITHREADS and USE_THREADS are incompatible"
  35. #endif
  36.  
  37. /* See L<perlguts/"The Perl API"> for detailed notes on
  38.  * PERL_IMPLICIT_CONTEXT and PERL_IMPLICIT_SYS */
  39.  
  40. #ifdef USE_ITHREADS
  41. #  if !defined(MULTIPLICITY) && !defined(PERL_OBJECT)
  42. #    define MULTIPLICITY
  43. #  endif
  44. #endif
  45.  
  46. #ifdef USE_THREADS
  47. #  ifndef PERL_IMPLICIT_CONTEXT
  48. #    define PERL_IMPLICIT_CONTEXT
  49. #  endif
  50. #endif
  51.  
  52. #if defined(MULTIPLICITY)
  53. #  ifndef PERL_IMPLICIT_CONTEXT
  54. #    define PERL_IMPLICIT_CONTEXT
  55. #  endif
  56. #endif
  57.  
  58. #ifdef PERL_CAPI
  59. #  undef PERL_OBJECT
  60. #  ifndef MULTIPLICITY
  61. #    define MULTIPLICITY
  62. #  endif
  63. #  ifndef PERL_IMPLICIT_CONTEXT
  64. #    define PERL_IMPLICIT_CONTEXT
  65. #  endif
  66. #  ifndef PERL_IMPLICIT_SYS
  67. #    define PERL_IMPLICIT_SYS
  68. #  endif
  69. #endif
  70.  
  71. #ifdef PERL_OBJECT
  72. #  ifndef PERL_IMPLICIT_CONTEXT
  73. #    define PERL_IMPLICIT_CONTEXT
  74. #  endif
  75. #  ifndef PERL_IMPLICIT_SYS
  76. #    define PERL_IMPLICIT_SYS
  77. #  endif
  78. #endif
  79.  
  80. #ifdef PERL_OBJECT
  81.  
  82. /* PERL_OBJECT explained  - DickH and DougL @ ActiveState.com
  83.  
  84. Defining PERL_OBJECT turns on creation of a C++ object that
  85. contains all writable core perl global variables and functions.
  86. Stated another way, all necessary global variables and functions
  87. are members of a big C++ object. This object's class is CPerlObj.
  88. This allows a Perl Host to have multiple, independent perl
  89. interpreters in the same process space. This is very important on
  90. Win32 systems as the overhead of process creation is quite high --
  91. this could be even higher than the script compile and execute time
  92. for small scripts.
  93.  
  94. The perl executable implementation on Win32 is composed of perl.exe
  95. (the Perl Host) and perlX.dll. (the Perl Core). This allows the
  96. same Perl Core to easily be embedded in other applications that use
  97. the perl interpreter.
  98.  
  99. +-----------+
  100. | Perl Host |
  101. +-----------+
  102.       ^
  103.       |
  104.       v
  105. +-----------+   +-----------+
  106. | Perl Core |<->| Extension |
  107. +-----------+   +-----------+ ...
  108.  
  109. Defining PERL_OBJECT has the following effects:
  110.  
  111. PERL CORE
  112. 1. CPerlObj is defined (this is the PERL_OBJECT)
  113. 2. all static functions that needed to access either global
  114. variables or functions needed are made member functions
  115. 3. all writable static variables are made member variables
  116. 4. all global variables and functions are defined as:
  117.     #define var CPerlObj::PL_var
  118.     #define func CPerlObj::Perl_func
  119.     * these are in embed.h
  120. This necessitated renaming some local variables and functions that
  121. had the same name as a global variable or function. This was
  122. probably a _good_ thing anyway.
  123.  
  124.  
  125. EXTENSIONS
  126. 1. Access to global variables and perl functions is through a
  127. pointer to the PERL_OBJECT. This pointer type is CPerlObj*. This is
  128. made transparent to extension developers by the following macros:
  129.     #define var pPerl->PL_var
  130.     #define func pPerl->Perl_func
  131.     * these are done in objXSUB.h
  132. This requires that the extension be compiled as C++, which means
  133. that the code must be ANSI C and not K&R C. For K&R extensions,
  134. please see the C API notes located in Win32/GenCAPI.pl. This script
  135. creates a perlCAPI.lib that provides a K & R compatible C interface
  136. to the PERL_OBJECT.
  137. 2. Local variables and functions cannot have the same name as perl's
  138. variables or functions since the macros will redefine these. Look for
  139. this if you get some strange error message and it does not look like
  140. the code that you had written. This often happens with variables that
  141. are local to a function.
  142.  
  143. PERL HOST
  144. 1. The perl host is linked with perlX.lib to get perl_alloc. This
  145. function will return a pointer to CPerlObj (the PERL_OBJECT). It
  146. takes pointers to the various PerlXXX_YYY interfaces (see iperlsys.h
  147. for more information on this).
  148. 2. The perl host calls the same functions as normally would be
  149. called in setting up and running a perl script, except that the
  150. functions are now member functions of the PERL_OBJECT.
  151.  
  152. */
  153.  
  154.  
  155. class CPerlObj;
  156.  
  157. #define STATIC
  158. #define CPERLscope(x)        CPerlObj::x
  159. #define CALL_FPTR(fptr)        (aTHXo->*fptr)
  160.  
  161. #define pTHXo            CPerlObj *pPerl
  162. #define pTHXo_            pTHXo,
  163. #define aTHXo            this
  164. #define aTHXo_            this,
  165. #define PERL_OBJECT_THIS    aTHXo
  166. #define PERL_OBJECT_THIS_    aTHXo_
  167. #define dTHXoa(a)        pTHXo = (CPerlObj*)a
  168. #define dTHXo            pTHXo = PERL_GET_THX
  169.  
  170. #define pTHXx        void
  171. #define pTHXx_
  172. #define aTHXx
  173. #define aTHXx_
  174.  
  175. #else /* !PERL_OBJECT */
  176.  
  177. #ifdef PERL_IMPLICIT_CONTEXT
  178. #  ifdef USE_THREADS
  179. struct perl_thread;
  180. #    define pTHX    register struct perl_thread *thr
  181. #    define aTHX    thr
  182. #    define dTHR    dNOOP /* only backward compatibility */
  183. #    define dTHXa(a)    pTHX = (struct perl_thread*)a
  184. #  else
  185. #    ifndef MULTIPLICITY
  186. #      define MULTIPLICITY
  187. #    endif
  188. #    define pTHX    register PerlInterpreter *my_perl
  189. #    define aTHX    my_perl
  190. #    define dTHXa(a)    pTHX = (PerlInterpreter*)a
  191. #  endif
  192. #  define dTHX        pTHX = PERL_GET_THX
  193. #  define pTHX_        pTHX,
  194. #  define aTHX_        aTHX,
  195. #  define pTHX_1    2    
  196. #  define pTHX_2    3
  197. #  define pTHX_3    4
  198. #  define pTHX_4    5
  199. #endif
  200.  
  201. #define STATIC static
  202. #define CPERLscope(x) x
  203. #define CPERLarg void
  204. #define CPERLarg_
  205. #define _CPERLarg
  206. #define PERL_OBJECT_THIS
  207. #define _PERL_OBJECT_THIS
  208. #define PERL_OBJECT_THIS_
  209. #define CALL_FPTR(fptr) (*fptr)
  210.  
  211. #endif /* PERL_OBJECT */
  212.  
  213. #define CALLRUNOPS  CALL_FPTR(PL_runops)
  214. #define CALLREGCOMP CALL_FPTR(PL_regcompp)
  215. #define CALLREGEXEC CALL_FPTR(PL_regexecp)
  216. #define CALLREG_INTUIT_START CALL_FPTR(PL_regint_start)
  217. #define CALLREG_INTUIT_STRING CALL_FPTR(PL_regint_string)
  218. #define CALLREGFREE CALL_FPTR(PL_regfree)
  219.  
  220. #ifdef PERL_FLEXIBLE_EXCEPTIONS
  221. #  define CALLPROTECT CALL_FPTR(PL_protect)
  222. #endif
  223.  
  224. #define NOOP (void)0
  225. #define dNOOP extern int Perl___notused
  226.  
  227. #ifndef pTHX
  228. #  define pTHX        void
  229. #  define pTHX_
  230. #  define aTHX
  231. #  define aTHX_
  232. #  define dTHXa(a)    dNOOP
  233. #  define dTHX        dNOOP
  234. #  define pTHX_1    1    
  235. #  define pTHX_2    2
  236. #  define pTHX_3    3
  237. #  define pTHX_4    4
  238. #endif
  239.  
  240. #ifndef pTHXo
  241. #  define pTHXo        pTHX
  242. #  define pTHXo_    pTHX_
  243. #  define aTHXo        aTHX
  244. #  define aTHXo_    aTHX_
  245. #  define dTHXo        dTHX
  246. #  define dTHXoa(x)    dTHXa(x)
  247. #endif
  248.  
  249. #ifndef pTHXx
  250. #  define pTHXx        register PerlInterpreter *my_perl
  251. #  define pTHXx_    pTHXx,
  252. #  define aTHXx        my_perl
  253. #  define aTHXx_    aTHXx,
  254. #  define dTHXx        dTHX
  255. #endif
  256.  
  257. /* Under PERL_IMPLICIT_SYS (used in Windows for fork emulation)
  258.  * PerlIO_foo() expands to PL_StdIO->pFOO(PL_StdIO, ...).
  259.  * dTHXs is therefore needed for all functions using PerlIO_foo(). */
  260. #ifdef PERL_IMPLICIT_SYS
  261. #  define dTHXs        dTHX
  262. #else
  263. #  define dTHXs        dNOOP
  264. #endif
  265.  
  266. #undef START_EXTERN_C
  267. #undef END_EXTERN_C
  268. #undef EXTERN_C
  269. #ifdef __cplusplus
  270. #  define START_EXTERN_C extern "C" {
  271. #  define END_EXTERN_C }
  272. #  define EXTERN_C extern "C"
  273. #else
  274. #  define START_EXTERN_C 
  275. #  define END_EXTERN_C 
  276. #  define EXTERN_C extern
  277. #endif
  278.  
  279. #ifdef OP_IN_REGISTER
  280. #  ifdef __GNUC__
  281. #    define stringify_immed(s) #s
  282. #    define stringify(s) stringify_immed(s)
  283. register struct op *Perl_op asm(stringify(OP_IN_REGISTER));
  284. #  endif
  285. #endif
  286.  
  287. /* define this once if on sun, rather than cluttering up the src */
  288. #ifndef __sun__
  289. #  if defined(sun) || defined(__sun)
  290. #    define __sun__
  291. #  endif
  292. #endif
  293.  
  294. /*
  295.  * STMT_START { statements; } STMT_END;
  296.  * can be used as a single statement, as in
  297.  * if (x) STMT_START { ... } STMT_END; else ...
  298.  *
  299.  * Trying to select a version that gives no warnings...
  300.  */
  301. #if !(defined(STMT_START) && defined(STMT_END))
  302. # if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__cplusplus)
  303. #   define STMT_START    (void)(    /* gcc supports ``({ STATEMENTS; })'' */
  304. #   define STMT_END    )
  305. # else
  306. #  if (VOIDFLAGS) && defined(__sun__)
  307. #   define STMT_START    if (1)
  308. #   define STMT_END    else (void)0
  309. #  else
  310. #   define STMT_START    do
  311. #   define STMT_END    while (0)
  312. #  endif
  313. # endif
  314. #endif
  315.  
  316. #define WITH_THX(s) STMT_START { dTHX; s; } STMT_END
  317. #define WITH_THR(s) WITH_THX(s)
  318.  
  319. /*
  320.  * SOFT_CAST can be used for args to prototyped functions to retain some
  321.  * type checking; it only casts if the compiler does not know prototypes.
  322.  */
  323. #if defined(CAN_PROTOTYPE) && defined(DEBUGGING_COMPILE)
  324. #define SOFT_CAST(type)    
  325. #else
  326. #define SOFT_CAST(type)    (type)
  327. #endif
  328.  
  329. #ifndef BYTEORDER  /* Should never happen -- byteorder is in config.h */
  330. #   define BYTEORDER 0x1234
  331. #endif
  332.  
  333. /* Overall memory policy? */
  334. #ifndef CONSERVATIVE
  335. #   define LIBERAL 1
  336. #endif
  337.  
  338. #if 'A' == 65 && 'I' == 73 && 'J' == 74 && 'Z' == 90
  339. #define ASCIIish
  340. #else
  341. #undef  ASCIIish
  342. #endif
  343.  
  344. /*
  345.  * The following contortions are brought to you on behalf of all the
  346.  * standards, semi-standards, de facto standards, not-so-de-facto standards
  347.  * of the world, as well as all the other botches anyone ever thought of.
  348.  * The basic theory is that if we work hard enough here, the rest of the
  349.  * code can be a lot prettier.  Well, so much for theory.  Sorry, Henry...
  350.  */
  351.  
  352. /* define this once if either system, instead of cluttering up the src */
  353. #if defined(MSDOS) || defined(atarist) || defined(WIN32)
  354. #define DOSISH 1
  355. #endif
  356.  
  357. #if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus) || defined( EPOC)
  358. # define STANDARD_C 1
  359. #endif
  360.  
  361. #if defined(__cplusplus) || defined(WIN32) || defined(__sgi) || defined(OS2) || defined(__DGUX) || defined( EPOC) || defined(__QNX__)
  362. # define DONT_DECLARE_STD 1
  363. #endif
  364.  
  365. #if defined(HASVOLATILE) || defined(STANDARD_C)
  366. #   ifdef __cplusplus
  367. #    define VOL        // to temporarily suppress warnings
  368. #   else
  369. #    define VOL volatile
  370. #   endif
  371. #else
  372. #   define VOL
  373. #endif
  374.  
  375. #define TAINT        (PL_tainted = TRUE)
  376. #define TAINT_NOT    (PL_tainted = FALSE)
  377. #define TAINT_IF(c)    if (c) { PL_tainted = TRUE; }
  378. #define TAINT_ENV()    if (PL_tainting) { taint_env(); }
  379. #define TAINT_PROPER(s)    if (PL_tainting) { taint_proper(Nullch, s); }
  380.  
  381. /* XXX All process group stuff is handled in pp_sys.c.  Should these 
  382.    defines move there?  If so, I could simplify this a lot. --AD  9/96.
  383. */
  384. /* Process group stuff changed from traditional BSD to POSIX.
  385.    perlfunc.pod documents the traditional BSD-style syntax, so we'll
  386.    try to preserve that, if possible.
  387. */
  388. #ifdef HAS_SETPGID
  389. #  define BSD_SETPGRP(pid, pgrp)    setpgid((pid), (pgrp))
  390. #else
  391. #  if defined(HAS_SETPGRP) && defined(USE_BSD_SETPGRP)
  392. #    define BSD_SETPGRP(pid, pgrp)    setpgrp((pid), (pgrp))
  393. #  else
  394. #    ifdef HAS_SETPGRP2  /* DG/UX */
  395. #      define BSD_SETPGRP(pid, pgrp)    setpgrp2((pid), (pgrp))
  396. #    endif
  397. #  endif
  398. #endif
  399. #if defined(BSD_SETPGRP) && !defined(HAS_SETPGRP)
  400. #  define HAS_SETPGRP  /* Well, effectively it does . . . */
  401. #endif
  402.  
  403. /* getpgid isn't POSIX, but at least Solaris and Linux have it, and it makes
  404.     our life easier :-) so we'll try it.
  405. */
  406. #ifdef HAS_GETPGID
  407. #  define BSD_GETPGRP(pid)        getpgid((pid))
  408. #else
  409. #  if defined(HAS_GETPGRP) && defined(USE_BSD_GETPGRP)
  410. #    define BSD_GETPGRP(pid)        getpgrp((pid))
  411. #  else
  412. #    ifdef HAS_GETPGRP2  /* DG/UX */
  413. #      define BSD_GETPGRP(pid)        getpgrp2((pid))
  414. #    endif
  415. #  endif
  416. #endif
  417. #if defined(BSD_GETPGRP) && !defined(HAS_GETPGRP)
  418. #  define HAS_GETPGRP  /* Well, effectively it does . . . */
  419. #endif
  420.  
  421. /* These are not exact synonyms, since setpgrp() and getpgrp() may 
  422.    have different behaviors, but perl.h used to define USE_BSDPGRP
  423.    (prior to 5.003_05) so some extension might depend on it.
  424. */
  425. #if defined(USE_BSD_SETPGRP) || defined(USE_BSD_GETPGRP)
  426. #  ifndef USE_BSDPGRP
  427. #    define USE_BSDPGRP
  428. #  endif
  429. #endif
  430.  
  431. /* HP-UX 10.X CMA (Common Multithreaded Architecure) insists that
  432.    pthread.h must be included before all other header files.
  433. */
  434. #if (defined(USE_THREADS) || defined(USE_ITHREADS)) \
  435.     && defined(PTHREAD_H_FIRST) && defined(I_PTHREAD)
  436. #  include <pthread.h>
  437. #endif
  438.  
  439. #ifndef _TYPES_        /* If types.h defines this it's easy. */
  440. #   ifndef major        /* Does everyone's types.h define this? */
  441. #    include <sys/types.h>
  442. #   endif
  443. #endif
  444.  
  445. #ifdef __cplusplus
  446. #  ifndef I_STDARG
  447. #    define I_STDARG 1
  448. #  endif
  449. #endif
  450.  
  451. #ifdef I_STDARG
  452. #  include <stdarg.h>
  453. #else
  454. #  ifdef I_VARARGS
  455. #    include <varargs.h>
  456. #  endif
  457. #endif
  458.  
  459. #ifdef USE_NEXT_CTYPE
  460.  
  461. #if NX_CURRENT_COMPILER_RELEASE >= 500
  462. #  include <bsd/ctypes.h>
  463. #else
  464. #  if NX_CURRENT_COMPILER_RELEASE >= 400
  465. #    include <objc/NXCType.h>
  466. #  else /*  NX_CURRENT_COMPILER_RELEASE < 400 */
  467. #    include <appkit/NXCType.h>
  468. #  endif /*  NX_CURRENT_COMPILER_RELEASE >= 400 */
  469. #endif /*  NX_CURRENT_COMPILER_RELEASE >= 500 */
  470.  
  471. #else /* !USE_NEXT_CTYPE */
  472. #include <ctype.h>
  473. #endif /* USE_NEXT_CTYPE */
  474.  
  475. #ifdef METHOD     /* Defined by OSF/1 v3.0 by ctype.h */
  476. #undef METHOD
  477. #endif
  478.  
  479. #ifdef I_LOCALE
  480. #   include <locale.h>
  481. #endif
  482.  
  483. #if !defined(NO_LOCALE) && defined(HAS_SETLOCALE)
  484. #   define USE_LOCALE
  485. #   if !defined(NO_LOCALE_COLLATE) && defined(LC_COLLATE) \
  486.        && defined(HAS_STRXFRM)
  487. #    define USE_LOCALE_COLLATE
  488. #   endif
  489. #   if !defined(NO_LOCALE_CTYPE) && defined(LC_CTYPE)
  490. #    define USE_LOCALE_CTYPE
  491. #   endif
  492. #   if !defined(NO_LOCALE_NUMERIC) && defined(LC_NUMERIC)
  493. #    define USE_LOCALE_NUMERIC
  494. #   endif
  495. #endif /* !NO_LOCALE && HAS_SETLOCALE */
  496.  
  497. #include <setjmp.h>
  498.  
  499. #ifdef I_SYS_PARAM
  500. #   ifdef PARAM_NEEDS_TYPES
  501. #    include <sys/types.h>
  502. #   endif
  503. #   include <sys/param.h>
  504. #endif
  505.  
  506. /* Use all the "standard" definitions? */
  507. #if defined(STANDARD_C) && defined(I_STDLIB)
  508. #   include <stdlib.h>
  509. #endif
  510.  
  511. /* If this causes problems, set i_unistd=undef in the hint file.  */
  512. #ifdef I_UNISTD
  513. #   include <unistd.h>
  514. #endif
  515.  
  516. #ifdef PERL_MICRO /* Last chance to export Perl_my_swap */
  517. #  define MYSWAP
  518. #endif
  519.  
  520. #if !defined(PERL_FOR_X2P) && !defined(WIN32)
  521. #  include "embed.h"
  522. #endif
  523.  
  524. #define MEM_SIZE Size_t
  525.  
  526. #if defined(STANDARD_C) && defined(I_STDDEF)
  527. #   include <stddef.h>
  528. #   define STRUCT_OFFSET(s,m)  offsetof(s,m)
  529. #else
  530. #   define STRUCT_OFFSET(s,m)  (Size_t)(&(((s *)0)->m))
  531. #endif
  532.  
  533. #if defined(I_STRING) || defined(__cplusplus)
  534. #   include <string.h>
  535. #else
  536. #   include <strings.h>
  537. #endif
  538.  
  539. /* This comes after <stdlib.h> so we don't try to change the standard
  540.  * library prototypes; we'll use our own in proto.h instead. */
  541.  
  542. #ifdef MYMALLOC
  543. #  ifdef PERL_POLLUTE_MALLOC
  544. #   ifndef PERL_EXTMALLOC_DEF
  545. #    define Perl_malloc        malloc
  546. #    define Perl_calloc        calloc
  547. #    define Perl_realloc    realloc
  548. #    define Perl_mfree        free
  549. #   endif
  550. #  else
  551. #    define EMBEDMYMALLOC    /* for compatibility */
  552. #  endif
  553. Malloc_t Perl_malloc (MEM_SIZE nbytes);
  554. Malloc_t Perl_calloc (MEM_SIZE elements, MEM_SIZE size);
  555. Malloc_t Perl_realloc (Malloc_t where, MEM_SIZE nbytes);
  556. /* 'mfree' rather than 'free', since there is already a 'perl_free'
  557.  * that causes clashes with case-insensitive linkers */
  558. Free_t   Perl_mfree (Malloc_t where);
  559.  
  560. typedef struct perl_mstats perl_mstats_t;
  561.  
  562. #  define safemalloc  Perl_malloc
  563. #  define safecalloc  Perl_calloc
  564. #  define saferealloc Perl_realloc
  565. #  define safefree    Perl_mfree
  566. #else  /* MYMALLOC */
  567. #  define safemalloc  safesysmalloc
  568. #  define safecalloc  safesyscalloc
  569. #  define saferealloc safesysrealloc
  570. #  define safefree    safesysfree
  571. #endif /* MYMALLOC */
  572.  
  573. #if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
  574. #define strchr index
  575. #define strrchr rindex
  576. #endif
  577.  
  578. #ifdef I_MEMORY
  579. #  include <memory.h>
  580. #endif
  581.  
  582. #ifdef HAS_MEMCPY
  583. #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
  584. #    ifndef memcpy
  585.         extern char * memcpy (char*, char*, int);
  586. #    endif
  587. #  endif
  588. #else
  589. #   ifndef memcpy
  590. #    ifdef HAS_BCOPY
  591. #        define memcpy(d,s,l) bcopy(s,d,l)
  592. #    else
  593. #        define memcpy(d,s,l) my_bcopy(s,d,l)
  594. #    endif
  595. #   endif
  596. #endif /* HAS_MEMCPY */
  597.  
  598. #ifdef HAS_MEMSET
  599. #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
  600. #    ifndef memset
  601.     extern char *memset (char*, int, int);
  602. #    endif
  603. #  endif
  604. #else
  605. #  define memset(d,c,l) my_memset(d,c,l)
  606. #endif /* HAS_MEMSET */
  607.  
  608. #if !defined(HAS_MEMMOVE) && !defined(memmove)
  609. #   if defined(HAS_BCOPY) && defined(HAS_SAFE_BCOPY)
  610. #    define memmove(d,s,l) bcopy(s,d,l)
  611. #   else
  612. #    if defined(HAS_MEMCPY) && defined(HAS_SAFE_MEMCPY)
  613. #        define memmove(d,s,l) memcpy(d,s,l)
  614. #    else
  615. #        define memmove(d,s,l) my_bcopy(s,d,l)
  616. #    endif
  617. #   endif
  618. #endif
  619.  
  620. #if defined(mips) && defined(ultrix) && !defined(__STDC__)
  621. #   undef HAS_MEMCMP
  622. #endif
  623.  
  624. #if defined(HAS_MEMCMP) && defined(HAS_SANE_MEMCMP)
  625. #  if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
  626. #    ifndef memcmp
  627.     extern int memcmp (char*, char*, int);
  628. #    endif
  629. #  endif
  630. #  ifdef BUGGY_MSC
  631.   #  pragma function(memcmp)
  632. #  endif
  633. #else
  634. #   ifndef memcmp
  635. #    define memcmp     my_memcmp
  636. #   endif
  637. #endif /* HAS_MEMCMP && HAS_SANE_MEMCMP */
  638.  
  639. #ifndef memzero
  640. #   ifdef HAS_MEMSET
  641. #    define memzero(d,l) memset(d,0,l)
  642. #   else
  643. #    ifdef HAS_BZERO
  644. #        define memzero(d,l) bzero(d,l)
  645. #    else
  646. #        define memzero(d,l) my_bzero(d,l)
  647. #    endif
  648. #   endif
  649. #endif
  650.  
  651. #ifndef memchr
  652. #   ifndef HAS_MEMCHR
  653. #       define memchr(s,c,n) ninstr((char*)(s), ((char*)(s)) + n, &(c), &(c) + 1)
  654. #   endif
  655. #endif
  656.  
  657. #ifndef HAS_BCMP
  658. #   ifndef bcmp
  659. #    define bcmp(s1,s2,l) memcmp(s1,s2,l)
  660. #   endif
  661. #endif /* !HAS_BCMP */
  662.  
  663. #ifdef I_NETINET_IN
  664. #   include <netinet/in.h>
  665. #endif
  666.  
  667. #ifdef I_ARPA_INET
  668. #   include <arpa/inet.h>
  669. #endif
  670.  
  671. #if defined(SF_APPEND) && defined(USE_SFIO) && defined(I_SFIO)
  672. /* <sfio.h> defines SF_APPEND and <sys/stat.h> might define SF_APPEND
  673.  * (the neo-BSD seem to do this).  */
  674. #   undef SF_APPEND
  675. #endif
  676.  
  677. #ifdef I_SYS_STAT
  678. #   include <sys/stat.h>
  679. #endif
  680.  
  681. /* The stat macros for Amdahl UTS, Unisoft System V/88 (and derivatives
  682.    like UTekV) are broken, sometimes giving false positives.  Undefine
  683.    them here and let the code below set them to proper values.
  684.  
  685.    The ghs macro stands for GreenHills Software C-1.8.5 which
  686.    is the C compiler for sysV88 and the various derivatives.
  687.    This header file bug is corrected in gcc-2.5.8 and later versions.
  688.    --Kaveh Ghazi (ghazi@noc.rutgers.edu) 10/3/94.  */
  689.  
  690. #if defined(uts) || (defined(m88k) && defined(ghs))
  691. #   undef S_ISDIR
  692. #   undef S_ISCHR
  693. #   undef S_ISBLK
  694. #   undef S_ISREG
  695. #   undef S_ISFIFO
  696. #   undef S_ISLNK
  697. #endif
  698.  
  699. #ifdef I_TIME
  700. #   include <time.h>
  701. #endif
  702.  
  703. #ifdef I_SYS_TIME
  704. #   ifdef I_SYS_TIME_KERNEL
  705. #    define KERNEL
  706. #   endif
  707. #   include <sys/time.h>
  708. #   ifdef I_SYS_TIME_KERNEL
  709. #    undef KERNEL
  710. #   endif
  711. #endif
  712.  
  713. #if defined(HAS_TIMES) && defined(I_SYS_TIMES)
  714. #    include <sys/times.h>
  715. #endif
  716.  
  717. #if defined(HAS_STRERROR) && (!defined(HAS_MKDIR) || !defined(HAS_RMDIR))
  718. #   undef HAS_STRERROR
  719. #endif
  720.  
  721. #include <errno.h>
  722.  
  723. #if defined(WIN32) && (defined(PERL_OBJECT) || defined(PERL_IMPLICIT_SYS) || defined(PERL_CAPI))
  724. #  define WIN32SCK_IS_STDSCK        /* don't pull in custom wsock layer */
  725. #endif
  726.  
  727. #if defined(HAS_SOCKET) && !defined(VMS) /* VMS handles sockets via vmsish.h */
  728. # include <sys/socket.h>
  729. # if defined(USE_SOCKS) && defined(I_SOCKS)
  730. #   if !defined(INCLUDE_PROTOTYPES)
  731. #       define INCLUDE_PROTOTYPES /* for <socks.h> */
  732. #       define PERL_SOCKS_NEED_PROTOTYPES
  733. #   endif
  734. #   ifdef USE_THREADS
  735. #       define PERL_USE_THREADS /* store our value */
  736. #       undef USE_THREADS
  737. #   endif
  738. #   include <socks.h>
  739. #   ifdef USE_THREADS
  740. #       undef USE_THREADS /* socks.h does this on its own */
  741. #   endif
  742. #   ifdef PERL_USE_THREADS
  743. #       define USE_THREADS /* restore our value */
  744. #       undef PERL_USE_THREADS
  745. #   endif
  746. #   ifdef PERL_SOCKS_NEED_PROTOTYPES /* keep cpp space clean */
  747. #       undef INCLUDE_PROTOTYPES
  748. #       undef PERL_SOCKS_NEED_PROTOTYPES
  749. #   endif
  750. #   ifdef USE_64_BIT_ALL
  751. #       define SOCKS_64BIT_BUG /* until proven otherwise */
  752. #   endif
  753. # endif 
  754. # ifdef I_NETDB
  755. #  include <netdb.h>
  756. # endif
  757. # ifndef ENOTSOCK
  758. #  ifdef I_NET_ERRNO
  759. #   include <net/errno.h>
  760. #  endif
  761. # endif
  762. #endif
  763.  
  764. #ifdef SETERRNO
  765. # undef SETERRNO  /* SOCKS might have defined this */
  766. #endif
  767.  
  768. #ifdef VMS
  769. #   define SETERRNO(errcode,vmserrcode) \
  770.     STMT_START {            \
  771.         set_errno(errcode);        \
  772.         set_vaxc_errno(vmserrcode);    \
  773.     } STMT_END
  774. #else
  775. #   define SETERRNO(errcode,vmserrcode) (errno = (errcode))
  776. #endif
  777.  
  778. #ifdef USE_THREADS
  779. #  define ERRSV (thr->errsv)
  780. #  define DEFSV THREADSV(0)
  781. #  define SAVE_DEFSV save_threadsv(0)
  782. #else
  783. #  define ERRSV GvSV(PL_errgv)
  784. #  define DEFSV GvSV(PL_defgv)
  785. #  define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
  786. #endif /* USE_THREADS */
  787.  
  788. #define ERRHV GvHV(PL_errgv)    /* XXX unused, here for compatibility */
  789.  
  790. #ifndef errno
  791.     extern int errno;     /* ANSI allows errno to be an lvalue expr.
  792.                    * For example in multithreaded environments
  793.                    * something like this might happen:
  794.                    * extern int *_errno(void);
  795.                    * #define errno (*_errno()) */
  796. #endif
  797.  
  798. #ifdef HAS_STRERROR
  799. #       ifdef VMS
  800.     char *strerror (int,...);
  801. #       else
  802. #ifndef DONT_DECLARE_STD
  803.     char *strerror (int);
  804. #endif
  805. #       endif
  806. #       ifndef Strerror
  807. #           define Strerror strerror
  808. #       endif
  809. #else
  810. #    ifdef HAS_SYS_ERRLIST
  811.     extern int sys_nerr;
  812.     extern char *sys_errlist[];
  813. #       ifndef Strerror
  814. #           define Strerror(e) \
  815.         ((e) < 0 || (e) >= sys_nerr ? "(unknown)" : sys_errlist[e])
  816. #       endif
  817. #   endif
  818. #endif
  819.  
  820. #ifdef I_SYS_IOCTL
  821. #   ifndef _IOCTL_
  822. #    include <sys/ioctl.h>
  823. #   endif
  824. #endif
  825.  
  826. #if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
  827. #   ifdef HAS_SOCKETPAIR
  828. #    undef HAS_SOCKETPAIR
  829. #   endif
  830. #   ifdef I_NDBM
  831. #    undef I_NDBM
  832. #   endif
  833. #endif
  834.  
  835. #if INTSIZE == 2
  836. #   define htoni htons
  837. #   define ntohi ntohs
  838. #else
  839. #   define htoni htonl
  840. #   define ntohi ntohl
  841. #endif
  842.  
  843. /* Configure already sets Direntry_t */
  844. #if defined(I_DIRENT)
  845. #   include <dirent.h>
  846.     /* NeXT needs dirent + sys/dir.h */
  847. #   if  defined(I_SYS_DIR) && (defined(NeXT) || defined(__NeXT__))
  848. #    include <sys/dir.h>
  849. #   endif
  850. #else
  851. #   ifdef I_SYS_NDIR
  852. #    include <sys/ndir.h>
  853. #   else
  854. #    ifdef I_SYS_DIR
  855. #        ifdef hp9000s500
  856. #        include <ndir.h>    /* may be wrong in the future */
  857. #        else
  858. #        include <sys/dir.h>
  859. #        endif
  860. #    endif
  861. #   endif
  862. #endif
  863.  
  864. #ifdef FPUTS_BOTCH
  865. /* work around botch in SunOS 4.0.1 and 4.0.2 */
  866. #   ifndef fputs
  867. #    define fputs(sv,fp) fprintf(fp,"%s",sv)
  868. #   endif
  869. #endif
  870.  
  871. /*
  872.  * The following gobbledygook brought to you on behalf of __STDC__.
  873.  * (I could just use #ifndef __STDC__, but this is more bulletproof
  874.  * in the face of half-implementations.)
  875.  */
  876.  
  877. #ifdef I_SYSMODE
  878. #include <sys/mode.h>
  879. #endif
  880.  
  881. #ifndef S_IFMT
  882. #   ifdef _S_IFMT
  883. #    define S_IFMT _S_IFMT
  884. #   else
  885. #    define S_IFMT 0170000
  886. #   endif
  887. #endif
  888.  
  889. #ifndef S_ISDIR
  890. #   define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
  891. #endif
  892.  
  893. #ifndef S_ISCHR
  894. #   define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
  895. #endif
  896.  
  897. #ifndef S_ISBLK
  898. #   ifdef S_IFBLK
  899. #    define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
  900. #   else
  901. #    define S_ISBLK(m) (0)
  902. #   endif
  903. #endif
  904.  
  905. #ifndef S_ISREG
  906. #   define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
  907. #endif
  908.  
  909. #ifndef S_ISFIFO
  910. #   ifdef S_IFIFO
  911. #    define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
  912. #   else
  913. #    define S_ISFIFO(m) (0)
  914. #   endif
  915. #endif
  916.  
  917. #ifndef S_ISLNK
  918. #   ifdef _S_ISLNK
  919. #    define S_ISLNK(m) _S_ISLNK(m)
  920. #   else
  921. #    ifdef _S_IFLNK
  922. #        define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
  923. #    else
  924. #        ifdef S_IFLNK
  925. #        define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
  926. #        else
  927. #        define S_ISLNK(m) (0)
  928. #        endif
  929. #    endif
  930. #   endif
  931. #endif
  932.  
  933. #ifndef S_ISSOCK
  934. #   ifdef _S_ISSOCK
  935. #    define S_ISSOCK(m) _S_ISSOCK(m)
  936. #   else
  937. #    ifdef _S_IFSOCK
  938. #        define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
  939. #    else
  940. #        ifdef S_IFSOCK
  941. #        define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
  942. #        else
  943. #        define S_ISSOCK(m) (0)
  944. #        endif
  945. #    endif
  946. #   endif
  947. #endif
  948.  
  949. #ifndef S_IRUSR
  950. #   ifdef S_IREAD
  951. #    define S_IRUSR S_IREAD
  952. #    define S_IWUSR S_IWRITE
  953. #    define S_IXUSR S_IEXEC
  954. #   else
  955. #    define S_IRUSR 0400
  956. #    define S_IWUSR 0200
  957. #    define S_IXUSR 0100
  958. #   endif
  959. #endif
  960.  
  961. #ifndef S_IRGRP
  962. #   ifdef S_IRUSR
  963. #       define S_IRGRP (S_IRUSR>>3)
  964. #       define S_IWGRP (S_IWUSR>>3)
  965. #       define S_IXGRP (S_IXUSR>>3)
  966. #   else
  967. #       define S_IRGRP 0040
  968. #       define S_IWGRP 0020
  969. #       define S_IXGRP 0010
  970. #   endif
  971. #endif
  972.  
  973. #ifndef S_IROTH
  974. #   ifdef S_IRUSR
  975. #       define S_IROTH (S_IRUSR>>6)
  976. #       define S_IWOTH (S_IWUSR>>6)
  977. #       define S_IXOTH (S_IXUSR>>6)
  978. #   else
  979. #       define S_IROTH 0040
  980. #       define S_IWOTH 0020
  981. #       define S_IXOTH 0010
  982. #   endif
  983. #endif
  984.  
  985. #ifndef S_ISUID
  986. #   define S_ISUID 04000
  987. #endif
  988.  
  989. #ifndef S_ISGID
  990. #   define S_ISGID 02000
  991. #endif
  992.  
  993. #ifndef S_IRWXU
  994. #   define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR)
  995. #endif 
  996.  
  997. #ifndef S_IRWXG
  998. #   define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP)
  999. #endif 
  1000.  
  1001. #ifndef S_IRWXO
  1002. #   define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH)
  1003. #endif 
  1004.  
  1005. #ifndef S_IREAD
  1006. #   define S_IREAD S_IRUSR
  1007. #endif
  1008.  
  1009. #ifndef S_IWRITE
  1010. #   define S_IWRITE S_IWUSR
  1011. #endif
  1012.  
  1013. #ifndef S_IEXEC
  1014. #   define S_IEXEC S_IXUSR
  1015. #endif
  1016.  
  1017. #ifdef ff_next
  1018. #   undef ff_next
  1019. #endif
  1020.  
  1021. #if defined(cray) || defined(gould) || defined(i860) || defined(pyr)
  1022. #   define SLOPPYDIVIDE
  1023. #endif
  1024.  
  1025. #ifdef UV
  1026. #undef UV
  1027. #endif
  1028.  
  1029. /*
  1030.     The IV type is supposed to be long enough to hold any integral
  1031.     value or a pointer.
  1032.     --Andy Dougherty    August 1996
  1033. */
  1034.  
  1035. typedef IVTYPE IV;
  1036. typedef UVTYPE UV;
  1037.  
  1038. #if defined(USE_64_BIT_INT) && defined(HAS_QUAD)
  1039. #  if QUADKIND == QUAD_IS_INT64_T && defined(INT64_MAX)
  1040. #    define IV_MAX INT64_MAX
  1041. #    define IV_MIN INT64_MIN
  1042. #    define UV_MAX UINT64_MAX
  1043. #    ifndef UINT64_MIN
  1044. #      define UINT64_MIN 0
  1045. #    endif
  1046. #    define UV_MIN UINT64_MIN
  1047. #  else
  1048. #    define IV_MAX PERL_QUAD_MAX
  1049. #    define IV_MIN PERL_QUAD_MIN
  1050. #    define UV_MAX PERL_UQUAD_MAX
  1051. #    define UV_MIN PERL_UQUAD_MIN
  1052. #  endif
  1053. #  define IV_IS_QUAD
  1054. #  define UV_IS_QUAD
  1055. #else
  1056. #  if defined(INT32_MAX) && IVSIZE == 4
  1057. #    define IV_MAX INT32_MAX
  1058. #    define IV_MIN INT32_MIN
  1059. #    ifndef UINT32_MAX_BROKEN /* e.g. HP-UX with gcc messes this up */
  1060. #        define UV_MAX UINT32_MAX
  1061. #    else
  1062. #        define UV_MAX 4294967295U
  1063. #    endif
  1064. #    ifndef UINT32_MIN
  1065. #      define UINT32_MIN 0
  1066. #    endif
  1067. #    define UV_MIN UINT32_MIN
  1068. #  else
  1069. #    define IV_MAX PERL_LONG_MAX
  1070. #    define IV_MIN PERL_LONG_MIN
  1071. #    define UV_MAX PERL_ULONG_MAX
  1072. #    define UV_MIN PERL_ULONG_MIN
  1073. #  endif
  1074. #  if IVSIZE == 8
  1075. #    define IV_IS_QUAD
  1076. #    define UV_IS_QUAD
  1077. #    ifndef HAS_QUAD
  1078. #      define HAS_QUAD
  1079. #    endif
  1080. #  else
  1081. #    undef IV_IS_QUAD
  1082. #    undef UV_IS_QUAD
  1083. #    undef HAS_QUAD
  1084. #  endif
  1085. #endif
  1086.  
  1087. #define IV_DIG (BIT_DIGITS(IVSIZE * 8))
  1088. #define UV_DIG (BIT_DIGITS(UVSIZE * 8))
  1089.  
  1090. /*   
  1091.  *  The macros INT2PTR and NUM2PTR are (despite their names)
  1092.  *  bi-directional: they will convert int/float to or from pointers.
  1093.  *  However the conversion to int/float are named explicitly:
  1094.  *  PTR2IV, PTR2UV, PTR2NV.
  1095.  *
  1096.  *  For int conversions we do not need two casts if pointers are
  1097.  *  the same size as IV and UV.   Otherwise we need an explicit
  1098.  *  cast (PTRV) to avoid compiler warnings.
  1099.  */
  1100. #if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE)
  1101. #  define PTRV            UV
  1102. #  define INT2PTR(any,d)    (any)(d)
  1103. #else
  1104. #  if PTRSIZE == LONGSIZE 
  1105. #    define PTRV        unsigned long
  1106. #  else
  1107. #    define PTRV        unsigned
  1108. #  endif
  1109. #  define INT2PTR(any,d)    (any)(PTRV)(d)
  1110. #endif
  1111. #define NUM2PTR(any,d)    (any)(PTRV)(d)
  1112. #define PTR2IV(p)    INT2PTR(IV,p)
  1113. #define PTR2UV(p)    INT2PTR(UV,p)
  1114. #define PTR2NV(p)    NUM2PTR(NV,p)
  1115. #if PTRSIZE == LONGSIZE 
  1116. #  define PTR2ul(p)    (unsigned long)(p)
  1117. #else
  1118. #  define PTR2ul(p)    INT2PTR(unsigned long,p)    
  1119. #endif
  1120.   
  1121. #ifdef USE_LONG_DOUBLE
  1122. #  if defined(HAS_LONG_DOUBLE) && LONG_DOUBLESIZE == DOUBLESIZE
  1123. #      define LONG_DOUBLE_EQUALS_DOUBLE
  1124. #  endif
  1125. #  if !(defined(HAS_LONG_DOUBLE) && (LONG_DOUBLESIZE > DOUBLESIZE))
  1126. #     undef USE_LONG_DOUBLE /* Ouch! */
  1127. #  endif
  1128. #endif
  1129.  
  1130. #ifdef OVR_DBL_DIG
  1131. /* Use an overridden DBL_DIG */
  1132. # ifdef DBL_DIG
  1133. #  undef DBL_DIG
  1134. # endif
  1135. # define DBL_DIG OVR_DBL_DIG
  1136. #else
  1137. /* The following is all to get DBL_DIG, in order to pick a nice
  1138.    default value for printing floating point numbers in Gconvert.
  1139.    (see config.h)
  1140. */
  1141. #ifdef I_LIMITS
  1142. #include <limits.h>
  1143. #endif
  1144. #ifdef I_FLOAT
  1145. #include <float.h>
  1146. #endif
  1147. #ifndef HAS_DBL_DIG
  1148. #define DBL_DIG    15   /* A guess that works lots of places */
  1149. #endif
  1150. #endif
  1151. #ifdef I_FLOAT
  1152. #include <float.h>
  1153. #endif
  1154. #ifndef HAS_DBL_DIG
  1155. #define DBL_DIG    15   /* A guess that works lots of places */
  1156. #endif
  1157.  
  1158. #ifdef OVR_LDBL_DIG
  1159. /* Use an overridden LDBL_DIG */
  1160. # ifdef LDBL_DIG
  1161. #  undef LDBL_DIG
  1162. # endif
  1163. # define LDBL_DIG OVR_LDBL_DIG
  1164. #else
  1165. /* The following is all to get LDBL_DIG, in order to pick a nice
  1166.    default value for printing floating point numbers in Gconvert.
  1167.    (see config.h)
  1168. */
  1169. # ifdef I_LIMITS
  1170. #   include <limits.h>
  1171. # endif
  1172. # ifdef I_FLOAT
  1173. #  include <float.h>
  1174. # endif
  1175. # ifndef HAS_LDBL_DIG
  1176. #  if LONG_DOUBLESIZE == 10
  1177. #   define LDBL_DIG 18 /* assume IEEE */
  1178. #  else
  1179. #   if LONG_DOUBLESIZE == 12
  1180. #    define LDBL_DIG 18 /* gcc? */
  1181. #   else
  1182. #    if LONG_DOUBLESIZE == 16
  1183. #     define LDBL_DIG 33 /* assume IEEE */
  1184. #    else
  1185. #     if LONG_DOUBLESIZE == DOUBLESIZE
  1186. #      define LDBL_DIG DBL_DIG /* bummer */
  1187. #     endif
  1188. #    endif
  1189. #   endif
  1190. #  endif
  1191. # endif
  1192. #endif
  1193.  
  1194. typedef NVTYPE NV;
  1195.  
  1196. #ifdef I_IEEEFP
  1197. #   include <ieeefp.h>
  1198. #endif
  1199.  
  1200. #ifdef USE_LONG_DOUBLE
  1201. #   ifdef I_SUNMATH
  1202. #       include <sunmath.h>
  1203. #   endif
  1204. #   define NV_DIG LDBL_DIG
  1205. #   ifdef LDBL_MANT_DIG
  1206. #       define NV_MANT_DIG LDBL_MANT_DIG
  1207. #   endif
  1208. #   ifdef LDBL_MAX
  1209. #       define NV_MAX LDBL_MAX
  1210. #       define NV_MIN LDBL_MIN
  1211. #   else
  1212. #       ifdef HUGE_VALL
  1213. #           define NV_MAX HUGE_VALL
  1214. #       else
  1215. #           ifdef HUGE_VAL
  1216. #               define NV_MAX ((NV)HUGE_VAL)
  1217. #           endif
  1218. #       endif
  1219. #   endif
  1220. #   ifdef HAS_SQRTL
  1221. #       define Perl_cos cosl
  1222. #       define Perl_sin sinl
  1223. #       define Perl_sqrt sqrtl
  1224. #       define Perl_exp expl
  1225. #       define Perl_log logl
  1226. #       define Perl_atan2 atan2l
  1227. #       define Perl_pow powl
  1228. #       define Perl_floor floorl
  1229. #       define Perl_fmod fmodl
  1230. #   endif
  1231. /* e.g. libsunmath doesn't have modfl and frexpl as of mid-March 2000 */
  1232. #   ifdef HAS_MODFL
  1233. #       define Perl_modf(x,y) modfl(x,y)
  1234. #   else
  1235. #       define Perl_modf(x,y) ((long double)modf((double)(x),(double*)(y)))
  1236. #   endif
  1237. #   ifdef HAS_FREXPL
  1238. #       define Perl_frexp(x,y) frexpl(x,y)
  1239. #   else
  1240. #       define Perl_frexp(x,y) ((long double)frexp((double)(x),y))
  1241. #   endif
  1242. #   ifdef HAS_ISNANL
  1243. #       define Perl_isnan(x) isnanl(x)
  1244. #   else
  1245. #       ifdef HAS_ISNAN
  1246. #           define Perl_isnan(x) isnan((double)(x))
  1247. #       else
  1248. #           define Perl_isnan(x) ((x)!=(x))
  1249. #       endif
  1250. #   endif
  1251. #else
  1252. #   define NV_DIG DBL_DIG
  1253. #   ifdef DBL_MANT_DIG
  1254. #       define NV_MANT_DIG DBL_MANT_DIG
  1255. #   endif
  1256. #   ifdef DBL_MAX
  1257. #       define NV_MAX DBL_MAX
  1258. #       define NV_MIN DBL_MIN
  1259. #   else
  1260. #       ifdef HUGE_VAL
  1261. #           define NV_MAX HUGE_VAL
  1262. #       endif
  1263. #   endif
  1264. #   define Perl_cos cos
  1265. #   define Perl_sin sin
  1266. #   define Perl_sqrt sqrt
  1267. #   define Perl_exp exp
  1268. #   define Perl_log log
  1269. #   define Perl_atan2 atan2
  1270. #   define Perl_pow pow
  1271. #   define Perl_floor floor
  1272. #   define Perl_fmod fmod
  1273. #   define Perl_modf(x,y) modf(x,y)
  1274. #   define Perl_frexp(x,y) frexp(x,y)
  1275. #   ifdef HAS_ISNAN
  1276. #       define Perl_isnan(x) isnan(x)
  1277. #   else
  1278. #       define Perl_isnan(x) ((x)!=(x))
  1279. #   endif
  1280. #endif
  1281.  
  1282. #if !defined(Perl_atof) && defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE)
  1283. #   if !defined(Perl_atof) && defined(HAS_STRTOLD) 
  1284. #       define Perl_atof(s) (NV)strtold(s, (char**)NULL)
  1285. #   endif
  1286. #   if !defined(Perl_atof) && defined(HAS_ATOLF)
  1287. #       define Perl_atof (NV)atolf
  1288. #   endif
  1289. #   if !defined(Perl_atof) && defined(PERL_SCNfldbl)
  1290. #       define Perl_atof PERL_SCNfldbl
  1291. #       define Perl_atof2(s,f) sscanf((s), "%"PERL_SCNfldbl, &(f))
  1292. #   endif
  1293. #endif
  1294. #if !defined(Perl_atof)
  1295. #   define Perl_atof atof /* we assume atof being available anywhere */
  1296. #endif
  1297. #if !defined(Perl_atof2)
  1298. #   define Perl_atof2(s,f) ((f) = (NV)Perl_atof(s))
  1299. #endif
  1300.  
  1301. /* Previously these definitions used hardcoded figures. 
  1302.  * It is hoped these formula are more portable, although
  1303.  * no data one way or another is presently known to me.
  1304.  * The "PERL_" names are used because these calculated constants
  1305.  * do not meet the ANSI requirements for LONG_MAX, etc., which
  1306.  * need to be constants acceptable to #if - kja
  1307.  *    define PERL_LONG_MAX        2147483647L
  1308.  *    define PERL_LONG_MIN        (-LONG_MAX - 1)
  1309.  *    define PERL ULONG_MAX       4294967295L
  1310.  */
  1311.  
  1312. #ifdef I_LIMITS  /* Needed for cast_xxx() functions below. */
  1313. #  include <limits.h>
  1314. #else
  1315. #ifdef I_VALUES
  1316. #  include <values.h>
  1317. #endif
  1318. #endif
  1319.  
  1320. /*
  1321.  * Try to figure out max and min values for the integral types.  THE CORRECT
  1322.  * SOLUTION TO THIS MESS: ADAPT enquire.c FROM GCC INTO CONFIGURE.  The
  1323.  * following hacks are used if neither limits.h or values.h provide them:
  1324.  * U<TYPE>_MAX: for types >= int: ~(unsigned TYPE)0
  1325.  *              for types <  int:  (unsigned TYPE)~(unsigned)0
  1326.  *    The argument to ~ must be unsigned so that later signed->unsigned
  1327.  *    conversion can't modify the value's bit pattern (e.g. -0 -> +0),
  1328.  *    and it must not be smaller than int because ~ does integral promotion.
  1329.  * <type>_MAX: (<type>) (U<type>_MAX >> 1)
  1330.  * <type>_MIN: -<type>_MAX - <is_twos_complement_architecture: (3 & -1) == 3>.
  1331.  *    The latter is a hack which happens to work on some machines but
  1332.  *    does *not* catch any random system, or things like integer types
  1333.  *    with NaN if that is possible.
  1334.  *
  1335.  * All of the types are explicitly cast to prevent accidental loss of
  1336.  * numeric range, and in the hope that they will be less likely to confuse
  1337.  * over-eager optimizers.
  1338.  *
  1339.  */
  1340.  
  1341. #define PERL_UCHAR_MIN ((unsigned char)0)
  1342.  
  1343. #ifdef UCHAR_MAX
  1344. #  define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX)
  1345. #else
  1346. #  ifdef MAXUCHAR
  1347. #    define PERL_UCHAR_MAX ((unsigned char)MAXUCHAR)
  1348. #  else
  1349. #    define PERL_UCHAR_MAX       ((unsigned char)~(unsigned)0)
  1350. #  endif
  1351. #endif
  1352.  
  1353. /*
  1354.  * CHAR_MIN and CHAR_MAX are not included here, as the (char) type may be
  1355.  * ambiguous. It may be equivalent to (signed char) or (unsigned char)
  1356.  * depending on local options. Until Configure detects this (or at least
  1357.  * detects whether the "signed" keyword is available) the CHAR ranges
  1358.  * will not be included. UCHAR functions normally.
  1359.  *                                                           - kja
  1360.  */
  1361.  
  1362. #define PERL_USHORT_MIN ((unsigned short)0)
  1363.  
  1364. #ifdef USHORT_MAX
  1365. #  define PERL_USHORT_MAX ((unsigned short)USHORT_MAX)
  1366. #else
  1367. #  ifdef MAXUSHORT
  1368. #    define PERL_USHORT_MAX ((unsigned short)MAXUSHORT)
  1369. #  else
  1370. #    ifdef USHRT_MAX
  1371. #      define PERL_USHORT_MAX ((unsigned short)USHRT_MAX)
  1372. #    else
  1373. #      define PERL_USHORT_MAX       ((unsigned short)~(unsigned)0)
  1374. #    endif
  1375. #  endif
  1376. #endif
  1377.  
  1378. #ifdef SHORT_MAX
  1379. #  define PERL_SHORT_MAX ((short)SHORT_MAX)
  1380. #else
  1381. #  ifdef MAXSHORT    /* Often used in <values.h> */
  1382. #    define PERL_SHORT_MAX ((short)MAXSHORT)
  1383. #  else
  1384. #    ifdef SHRT_MAX
  1385. #      define PERL_SHORT_MAX ((short)SHRT_MAX)
  1386. #    else
  1387. #      define PERL_SHORT_MAX      ((short) (PERL_USHORT_MAX >> 1))
  1388. #    endif
  1389. #  endif
  1390. #endif
  1391.  
  1392. #ifdef SHORT_MIN
  1393. #  define PERL_SHORT_MIN ((short)SHORT_MIN)
  1394. #else
  1395. #  ifdef MINSHORT
  1396. #    define PERL_SHORT_MIN ((short)MINSHORT)
  1397. #  else
  1398. #    ifdef SHRT_MIN
  1399. #      define PERL_SHORT_MIN ((short)SHRT_MIN)
  1400. #    else
  1401. #      define PERL_SHORT_MIN        (-PERL_SHORT_MAX - ((3 & -1) == 3))
  1402. #    endif
  1403. #  endif
  1404. #endif
  1405.  
  1406. #ifdef UINT_MAX
  1407. #  define PERL_UINT_MAX ((unsigned int)UINT_MAX)
  1408. #else
  1409. #  ifdef MAXUINT
  1410. #    define PERL_UINT_MAX ((unsigned int)MAXUINT)
  1411. #  else
  1412. #    define PERL_UINT_MAX       (~(unsigned int)0)
  1413. #  endif
  1414. #endif
  1415.  
  1416. #define PERL_UINT_MIN ((unsigned int)0)
  1417.  
  1418. #ifdef INT_MAX
  1419. #  define PERL_INT_MAX ((int)INT_MAX)
  1420. #else
  1421. #  ifdef MAXINT    /* Often used in <values.h> */
  1422. #    define PERL_INT_MAX ((int)MAXINT)
  1423. #  else
  1424. #    define PERL_INT_MAX        ((int)(PERL_UINT_MAX >> 1))
  1425. #  endif
  1426. #endif
  1427.  
  1428. #ifdef INT_MIN
  1429. #  define PERL_INT_MIN ((int)INT_MIN)
  1430. #else
  1431. #  ifdef MININT
  1432. #    define PERL_INT_MIN ((int)MININT)
  1433. #  else
  1434. #    define PERL_INT_MIN        (-PERL_INT_MAX - ((3 & -1) == 3))
  1435. #  endif
  1436. #endif
  1437.  
  1438. #ifdef ULONG_MAX
  1439. #  define PERL_ULONG_MAX ((unsigned long)ULONG_MAX)
  1440. #else
  1441. #  ifdef MAXULONG
  1442. #    define PERL_ULONG_MAX ((unsigned long)MAXULONG)
  1443. #  else
  1444. #    define PERL_ULONG_MAX       (~(unsigned long)0)
  1445. #  endif
  1446. #endif
  1447.  
  1448. #define PERL_ULONG_MIN ((unsigned long)0L)
  1449.  
  1450. #ifdef LONG_MAX
  1451. #  define PERL_LONG_MAX ((long)LONG_MAX)
  1452. #else
  1453. #  ifdef MAXLONG    /* Often used in <values.h> */
  1454. #    define PERL_LONG_MAX ((long)MAXLONG)
  1455. #  else
  1456. #    define PERL_LONG_MAX        ((long) (PERL_ULONG_MAX >> 1))
  1457. #  endif
  1458. #endif
  1459.  
  1460. #ifdef LONG_MIN
  1461. #  define PERL_LONG_MIN ((long)LONG_MIN)
  1462. #else
  1463. #  ifdef MINLONG
  1464. #    define PERL_LONG_MIN ((long)MINLONG)
  1465. #  else
  1466. #    define PERL_LONG_MIN        (-PERL_LONG_MAX - ((3 & -1) == 3))
  1467. #  endif
  1468. #endif
  1469.  
  1470. #ifdef UV_IS_QUAD
  1471.  
  1472. #    define PERL_UQUAD_MAX    (~(UV)0)
  1473. #    define PERL_UQUAD_MIN    ((UV)0)
  1474. #    define PERL_QUAD_MAX     ((IV) (PERL_UQUAD_MAX >> 1))
  1475. #    define PERL_QUAD_MIN     (-PERL_QUAD_MAX - ((3 & -1) == 3))
  1476.  
  1477. #endif
  1478.  
  1479. struct perl_mstats {
  1480.     UV *nfree;
  1481.     UV *ntotal;
  1482.     IV topbucket, topbucket_ev, topbucket_odd, totfree, total, total_chain;
  1483.     IV total_sbrk, sbrks, sbrk_good, sbrk_slack, start_slack, sbrked_remains;
  1484.     IV minbucket;
  1485.     /* Level 1 info */
  1486.     UV *bucket_mem_size;
  1487.     UV *bucket_available_size;
  1488.     UV nbuckets;
  1489. };
  1490.  
  1491. typedef MEM_SIZE STRLEN;
  1492.  
  1493. typedef struct op OP;
  1494. typedef struct cop COP;
  1495. typedef struct unop UNOP;
  1496. typedef struct binop BINOP;
  1497. typedef struct listop LISTOP;
  1498. typedef struct logop LOGOP;
  1499. typedef struct pmop PMOP;
  1500. typedef struct svop SVOP;
  1501. typedef struct padop PADOP;
  1502. typedef struct pvop PVOP;
  1503. typedef struct loop LOOP;
  1504.  
  1505. typedef struct interpreter PerlInterpreter;
  1506. #ifdef UTS
  1507. #   define STRUCT_SV perl_sv /* Amdahl's <ksync.h> has struct sv */
  1508. #else
  1509. #   define STRUCT_SV sv
  1510. #endif
  1511. typedef struct STRUCT_SV SV;
  1512. typedef struct av AV;
  1513. typedef struct hv HV;
  1514. typedef struct cv CV;
  1515. typedef struct regexp REGEXP;
  1516. typedef struct gp GP;
  1517. typedef struct gv GV;
  1518. typedef struct io IO;
  1519. typedef struct context PERL_CONTEXT;
  1520. typedef struct block BLOCK;
  1521.  
  1522. typedef struct magic MAGIC;
  1523. typedef struct xrv XRV;
  1524. typedef struct xpv XPV;
  1525. typedef struct xpviv XPVIV;
  1526. typedef struct xpvuv XPVUV;
  1527. typedef struct xpvnv XPVNV;
  1528. typedef struct xpvmg XPVMG;
  1529. typedef struct xpvlv XPVLV;
  1530. typedef struct xpvav XPVAV;
  1531. typedef struct xpvhv XPVHV;
  1532. typedef struct xpvgv XPVGV;
  1533. typedef struct xpvcv XPVCV;
  1534. typedef struct xpvbm XPVBM;
  1535. typedef struct xpvfm XPVFM;
  1536. typedef struct xpvio XPVIO;
  1537. typedef struct mgvtbl MGVTBL;
  1538. typedef union any ANY;
  1539. typedef struct ptr_tbl_ent PTR_TBL_ENT_t;
  1540. typedef struct ptr_tbl PTR_TBL_t;
  1541.  
  1542. #include "handy.h"
  1543.  
  1544. #if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_RAWIO)
  1545. #   if LSEEKSIZE == 8 && !defined(USE_64_BIT_RAWIO)
  1546. #       define USE_64_BIT_RAWIO    /* implicit */
  1547. #   endif
  1548. #endif
  1549.  
  1550. /* Notice the use of HAS_FSEEKO: now we are obligated to always use
  1551.  * fseeko/ftello if possible.  Don't go #defining ftell to ftello yourself,
  1552.  * however, because operating systems like to do that themself. */
  1553. #ifndef FSEEKSIZE
  1554. #   ifdef HAS_FSEEKO
  1555. #       define FSEEKSIZE LSEEKSIZE
  1556. #   else
  1557. #       define FSEEKSIZE LONGSIZE
  1558. #   endif  
  1559. #endif
  1560.  
  1561. #if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_STDIO)
  1562. #   if FSEEKSIZE == 8 && !defined(USE_64_BIT_STDIO)
  1563. #       define USE_64_BIT_STDIO /* implicit */
  1564. #   endif
  1565. #endif
  1566.  
  1567. #ifdef USE_64_BIT_RAWIO
  1568. #   ifdef HAS_OFF64_T
  1569. #       undef Off_t
  1570. #       define Off_t off64_t
  1571. #       undef LSEEKSIZE
  1572. #       define LSEEKSIZE 8
  1573. #   endif
  1574. /* Most 64-bit environments have defines like _LARGEFILE_SOURCE that
  1575.  * will trigger defines like the ones below.  Some 64-bit environments,
  1576.  * however, do not.  Therefore we have to explicitly mix and match. */
  1577. #   if defined(USE_OPEN64)
  1578. #       define open open64
  1579. #   endif
  1580. #   if defined(USE_LSEEK64)
  1581. #       define lseek lseek64
  1582. #   else
  1583. #       if defined(USE_LLSEEK)
  1584. #           define lseek llseek
  1585. #       endif
  1586. #   endif
  1587. #   if defined(USE_STAT64)
  1588. #       define stat stat64
  1589. #   endif
  1590. #   if defined(USE_FSTAT64)
  1591. #       define fstat fstat64
  1592. #   endif
  1593. #   if defined(USE_LSTAT64)
  1594. #       define lstat lstat64
  1595. #   endif
  1596. #   if defined(USE_FLOCK64)
  1597. #       define flock flock64
  1598. #   endif
  1599. #   if defined(USE_LOCKF64)
  1600. #       define lockf lockf64
  1601. #   endif
  1602. #   if defined(USE_FCNTL64)
  1603. #       define fcntl fcntl64
  1604. #   endif
  1605. #   if defined(USE_TRUNCATE64)
  1606. #       define truncate truncate64
  1607. #   endif
  1608. #   if defined(USE_FTRUNCATE64)
  1609. #       define ftruncate ftruncate64
  1610. #   endif
  1611. #endif
  1612.  
  1613. #ifdef USE_64_BIT_STDIO
  1614. #   ifdef HAS_FPOS64_T
  1615. #       undef Fpos_t
  1616. #       define Fpos_t fpos64_t
  1617. #   endif
  1618. /* Most 64-bit environments have defines like _LARGEFILE_SOURCE that
  1619.  * will trigger defines like the ones below.  Some 64-bit environments,
  1620.  * however, do not. */
  1621. #   if defined(USE_FOPEN64)
  1622. #       define fopen fopen64
  1623. #   endif
  1624. #   if defined(USE_FSEEK64)
  1625. #       define fseek fseek64 /* don't do fseeko here, see perlio.c */
  1626. #   endif
  1627. #   if defined(USE_FTELL64)
  1628. #       define ftell ftell64 /* don't do ftello here, see perlio.c */
  1629. #   endif
  1630. #   if defined(USE_FSETPOS64)
  1631. #       define fsetpos fsetpos64
  1632. #   endif
  1633. #   if defined(USE_FGETPOS64)
  1634. #       define fgetpos fgetpos64
  1635. #   endif
  1636. #   if defined(USE_TMPFILE64)
  1637. #       define tmpfile tmpfile64
  1638. #   endif
  1639. #   if defined(USE_FREOPEN64)
  1640. #       define freopen freopen64
  1641. #   endif
  1642. #endif
  1643.  
  1644. #if defined(OS2)
  1645. #  include "iperlsys.h"
  1646. #endif
  1647.  
  1648. #if defined(__OPEN_VM)
  1649. # include "vmesa/vmesaish.h"
  1650. #endif
  1651.  
  1652. #ifdef DOSISH
  1653. # if defined(OS2)
  1654. #   include "os2ish.h"
  1655. # else
  1656. #   include "dosish.h"
  1657. # endif
  1658. #else
  1659. # if defined(VMS)
  1660. #   include "vmsish.h"
  1661. # else
  1662. #   if defined(PLAN9)
  1663. #     include "./plan9/plan9ish.h"
  1664. #   else
  1665. #     if defined(MPE)
  1666. #       include "mpeix/mpeixish.h"
  1667. #     else
  1668. #       if defined(__VOS__)
  1669. #         include "vosish.h"
  1670. #       else
  1671. #         if defined(EPOC)
  1672. #           include "epocish.h"
  1673. #         else
  1674. #           if defined(MACOS_TRADITIONAL)
  1675. #             include "macos/macish.h"
  1676. #          ifndef NO_ENVIRON_ARRAY
  1677. #               define NO_ENVIRON_ARRAY
  1678. #             endif
  1679. #           else
  1680. #             include "unixish.h"
  1681. #           endif
  1682. #         endif
  1683. #       endif
  1684. #     endif
  1685. #   endif
  1686. # endif
  1687. #endif
  1688.  
  1689. #ifndef NO_ENVIRON_ARRAY
  1690. #  define USE_ENVIRON_ARRAY
  1691. #endif
  1692.  
  1693. #ifndef PERL_SYS_INIT3
  1694. #  define PERL_SYS_INIT3(argvp,argcp,envp) PERL_SYS_INIT(argvp,argcp)
  1695. #endif
  1696.  
  1697. #ifndef MAXPATHLEN
  1698. #  ifdef PATH_MAX
  1699. #    ifdef _POSIX_PATH_MAX
  1700. #       if PATH_MAX > _POSIX_PATH_MAX
  1701. /* MAXPATHLEN is supposed to include the final null character,
  1702.  * as opposed to PATH_MAX and _POSIX_PATH_MAX. */
  1703. #         define MAXPATHLEN (PATH_MAX+1)
  1704. #       else
  1705. #         define MAXPATHLEN (_POSIX_PATH_MAX+1)
  1706. #       endif
  1707. #    else
  1708. #      define MAXPATHLEN (PATH_MAX+1)
  1709. #    endif
  1710. #  else
  1711. #    ifdef _POSIX_PATH_MAX
  1712. #       define MAXPATHLEN (_POSIX_PATH_MAX+1)
  1713. #    else
  1714. #       define MAXPATHLEN 1024    /* Err on the large side. */
  1715. #    endif
  1716. #  endif
  1717. #endif
  1718.  
  1719. /* 
  1720.  * USE_THREADS needs to be after unixish.h as <pthread.h> includes
  1721.  * <sys/signal.h> which defines NSIG - which will stop inclusion of <signal.h>
  1722.  * this results in many functions being undeclared which bothers C++
  1723.  * May make sense to have threads after "*ish.h" anyway
  1724.  */
  1725.  
  1726. #if defined(USE_THREADS) || defined(USE_ITHREADS)
  1727. #  if defined(USE_THREADS)
  1728.    /* pending resolution of licensing issues, we avoid the erstwhile
  1729.     * atomic.h everywhere */
  1730. #  define EMULATE_ATOMIC_REFCOUNTS
  1731. #  endif
  1732. #  ifdef FAKE_THREADS
  1733. #    include "fakethr.h"
  1734. #  else
  1735. #    ifdef WIN32
  1736. #      include <win32thread.h>
  1737. #    else
  1738. #      ifdef OS2
  1739. #        include "os2thread.h"
  1740. #      else
  1741. #        ifdef I_MACH_CTHREADS
  1742. #          include <mach/cthreads.h>
  1743. #          if (defined(NeXT) || defined(__NeXT__)) && defined(PERL_POLLUTE_MALLOC)
  1744. #            define MUTEX_INIT_CALLS_MALLOC
  1745. #          endif
  1746. typedef cthread_t    perl_os_thread;
  1747. typedef mutex_t        perl_mutex;
  1748. typedef condition_t    perl_cond;
  1749. typedef void *        perl_key;
  1750. #        else /* Posix threads */
  1751. #          ifdef I_PTHREAD
  1752. #            include <pthread.h>
  1753. #          endif
  1754. typedef pthread_t    perl_os_thread;
  1755. typedef pthread_mutex_t    perl_mutex;
  1756. typedef pthread_cond_t    perl_cond;
  1757. typedef pthread_key_t    perl_key;
  1758. #        endif /* I_MACH_CTHREADS */
  1759. #      endif /* OS2 */
  1760. #    endif /* WIN32 */
  1761. #  endif /* FAKE_THREADS */
  1762. #endif /* USE_THREADS || USE_ITHREADS */
  1763.  
  1764. #ifdef WIN32
  1765. #  include "win32.h"
  1766. #endif
  1767.  
  1768. #ifdef VMS
  1769. #   define STATUS_NATIVE    PL_statusvalue_vms
  1770. #   define STATUS_NATIVE_EXPORT \
  1771.     (((I32)PL_statusvalue_vms == -1 ? 44 : PL_statusvalue_vms) | (VMSISH_HUSHED ? 0x10000000 : 0))
  1772. #   define STATUS_NATIVE_SET(n)                        \
  1773.     STMT_START {                            \
  1774.         PL_statusvalue_vms = (n);                    \
  1775.         if ((I32)PL_statusvalue_vms == -1)                \
  1776.         PL_statusvalue = -1;                    \
  1777.         else if (PL_statusvalue_vms & STS$M_SUCCESS)        \
  1778.         PL_statusvalue = 0;                    \
  1779.         else if ((PL_statusvalue_vms & STS$M_SEVERITY) == 0)    \
  1780.         PL_statusvalue = 1 << 8;                \
  1781.         else                            \
  1782.         PL_statusvalue = (PL_statusvalue_vms & STS$M_SEVERITY) << 8;    \
  1783.     } STMT_END
  1784. #   define STATUS_POSIX    PL_statusvalue
  1785. #   ifdef VMSISH_STATUS
  1786. #    define STATUS_CURRENT    (VMSISH_STATUS ? STATUS_NATIVE : STATUS_POSIX)
  1787. #   else
  1788. #    define STATUS_CURRENT    STATUS_POSIX
  1789. #   endif
  1790. #   define STATUS_POSIX_SET(n)                \
  1791.     STMT_START {                    \
  1792.         PL_statusvalue = (n);                \
  1793.         if (PL_statusvalue != -1) {            \
  1794.         PL_statusvalue &= 0xFFFF;            \
  1795.         PL_statusvalue_vms = PL_statusvalue ? 44 : 1;    \
  1796.         }                        \
  1797.         else PL_statusvalue_vms = -1;            \
  1798.     } STMT_END
  1799. #   define STATUS_ALL_SUCCESS    (PL_statusvalue = 0, PL_statusvalue_vms = 1)
  1800. #   define STATUS_ALL_FAILURE    (PL_statusvalue = 1, PL_statusvalue_vms = 44)
  1801. #else
  1802. #   define STATUS_NATIVE    STATUS_POSIX
  1803. #   define STATUS_NATIVE_EXPORT    STATUS_POSIX
  1804. #   define STATUS_NATIVE_SET    STATUS_POSIX_SET
  1805. #   define STATUS_POSIX        PL_statusvalue
  1806. #   define STATUS_POSIX_SET(n)        \
  1807.     STMT_START {            \
  1808.         PL_statusvalue = (n);        \
  1809.         if (PL_statusvalue != -1)    \
  1810.         PL_statusvalue &= 0xFFFF;    \
  1811.     } STMT_END
  1812. #   define STATUS_CURRENT STATUS_POSIX
  1813. #   define STATUS_ALL_SUCCESS    (PL_statusvalue = 0)
  1814. #   define STATUS_ALL_FAILURE    (PL_statusvalue = 1)
  1815. #endif
  1816.  
  1817. /* flags in PL_exit_flags for nature of exit() */
  1818. #define PERL_EXIT_EXPECTED    0x01
  1819.  
  1820. #ifndef MEMBER_TO_FPTR
  1821. #  define MEMBER_TO_FPTR(name)        name
  1822. #endif
  1823.  
  1824. /* format to use for version numbers in file/directory names */
  1825. /* XXX move to Configure? */
  1826. #ifndef PERL_FS_VER_FMT
  1827. #  define PERL_FS_VER_FMT    "%d.%d.%d"
  1828. #endif
  1829.  
  1830. /* This defines a way to flush all output buffers.  This may be a
  1831.  * performance issue, so we allow people to disable it.
  1832.  */
  1833. #ifndef PERL_FLUSHALL_FOR_CHILD
  1834. # if defined(FFLUSH_NULL) || defined(USE_SFIO)
  1835. #  define PERL_FLUSHALL_FOR_CHILD    PerlIO_flush((PerlIO*)NULL)
  1836. # else
  1837. #  ifdef FFLUSH_ALL
  1838. #   define PERL_FLUSHALL_FOR_CHILD    my_fflush_all()
  1839. #  else
  1840. #   define PERL_FLUSHALL_FOR_CHILD    NOOP
  1841. #  endif
  1842. # endif
  1843. #endif
  1844.  
  1845. #ifndef PERL_WAIT_FOR_CHILDREN
  1846. #  define PERL_WAIT_FOR_CHILDREN    NOOP
  1847. #endif
  1848.  
  1849. /* the traditional thread-unsafe notion of "current interpreter". */
  1850. #ifndef PERL_SET_INTERP
  1851. #  define PERL_SET_INTERP(i)        (PL_curinterp = (PerlInterpreter*)(i))
  1852. #endif
  1853.  
  1854. #ifndef PERL_GET_INTERP
  1855. #  define PERL_GET_INTERP        (PL_curinterp)
  1856. #endif
  1857.  
  1858. #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_GET_THX)
  1859. #  ifdef USE_THREADS
  1860. #    define PERL_GET_THX        ((struct perl_thread *)PERL_GET_CONTEXT)
  1861. #  else
  1862. #  ifdef MULTIPLICITY
  1863. #    define PERL_GET_THX        ((PerlInterpreter *)PERL_GET_CONTEXT)
  1864. #  else
  1865. #  ifdef PERL_OBJECT
  1866. #    define PERL_GET_THX        ((CPerlObj *)PERL_GET_CONTEXT)
  1867. #  endif
  1868. #  endif
  1869. #  endif
  1870. #  define PERL_SET_THX(t)        PERL_SET_CONTEXT(t)
  1871. #endif
  1872.  
  1873. #ifndef SVf
  1874. #  ifdef CHECK_FORMAT
  1875. #    define SVf "p"
  1876. #  else
  1877. #    define SVf "_"
  1878. #  endif 
  1879. #endif
  1880.  
  1881. #ifndef UVf
  1882. #  ifdef CHECK_FORMAT
  1883. #    define UVf UVuf
  1884. #  else
  1885. #    define UVf "Vu"
  1886. #  endif 
  1887. #endif
  1888.  
  1889. #ifndef VDf
  1890. #  ifdef CHECK_FORMAT
  1891. #    define VDf "p"
  1892. #  else
  1893. #    define VDf "vd"
  1894. #  endif 
  1895. #endif
  1896.  
  1897. /* Some unistd.h's give a prototype for pause() even though
  1898.    HAS_PAUSE ends up undefined.  This causes the #define
  1899.    below to be rejected by the compiler.  Sigh.
  1900. */
  1901. #ifdef HAS_PAUSE
  1902. #define Pause    pause
  1903. #else
  1904. #define Pause() sleep((32767<<16)+32767)
  1905. #endif
  1906.  
  1907. #ifndef IOCPARM_LEN
  1908. #   ifdef IOCPARM_MASK
  1909.     /* on BSDish systes we're safe */
  1910. #    define IOCPARM_LEN(x)  (((x) >> 16) & IOCPARM_MASK)
  1911. #   else
  1912.     /* otherwise guess at what's safe */
  1913. #    define IOCPARM_LEN(x)    256
  1914. #   endif
  1915. #endif
  1916.  
  1917. #if defined(__CYGWIN__)
  1918. /* USEMYBINMODE
  1919.  *   This symbol, if defined, indicates that the program should
  1920.  *   use the routine my_binmode(FILE *fp, char iotype, int mode) to insure
  1921.  *   that a file is in "binary" mode -- that is, that no translation
  1922.  *   of bytes occurs on read or write operations.
  1923.  */
  1924. #  define USEMYBINMODE / **/
  1925. #  define my_binmode(fp, iotype, mode) \
  1926.             (PerlLIO_setmode(PerlIO_fileno(fp), mode) != -1 ? TRUE : FALSE)
  1927. #endif
  1928.  
  1929. #ifdef UNION_ANY_DEFINITION
  1930. UNION_ANY_DEFINITION;
  1931. #else
  1932. union any {
  1933.     void*    any_ptr;
  1934.     I32        any_i32;
  1935.     IV        any_iv;
  1936.     long    any_long;
  1937.     void    (*any_dptr) (void*);
  1938.     void    (*any_dxptr) (pTHXo_ void*);
  1939. };
  1940. #endif
  1941.  
  1942. #ifdef USE_THREADS
  1943. #define ARGSproto struct perl_thread *thr
  1944. #else
  1945. #define ARGSproto
  1946. #endif /* USE_THREADS */
  1947.  
  1948. typedef I32 (*filter_t) (pTHXo_ int, SV *, int);
  1949.  
  1950. #define FILTER_READ(idx, sv, len)  filter_read(idx, sv, len)
  1951. #define FILTER_DATA(idx)       (AvARRAY(PL_rsfp_filters)[idx])
  1952. #define FILTER_ISREADER(idx)       (idx >= AvFILLp(PL_rsfp_filters))
  1953.  
  1954. #if !defined(OS2)
  1955. #  include "iperlsys.h"
  1956. #endif
  1957. #include "regexp.h"
  1958. #include "sv.h"
  1959. #include "util.h"
  1960. #include "form.h"
  1961. #include "gv.h"
  1962. #include "cv.h"
  1963. #include "opnames.h"
  1964. #include "op.h"
  1965. #include "cop.h"
  1966. #include "av.h"
  1967. #include "hv.h"
  1968. #include "mg.h"
  1969. #include "scope.h"
  1970. #include "warnings.h"
  1971. #include "utf8.h"
  1972.  
  1973. /* Current curly descriptor */
  1974. typedef struct curcur CURCUR;
  1975. struct curcur {
  1976.     int        parenfloor;    /* how far back to strip paren data */
  1977.     int        cur;        /* how many instances of scan we've matched */
  1978.     int        min;        /* the minimal number of scans to match */
  1979.     int        max;        /* the maximal number of scans to match */
  1980.     int        minmod;        /* whether to work our way up or down */
  1981.     regnode *    scan;        /* the thing to match */
  1982.     regnode *    next;        /* what has to match after it */
  1983.     char *    lastloc;    /* where we started matching this scan */
  1984.     CURCUR *    oldcc;        /* current curly before we started this one */
  1985. };
  1986.  
  1987. typedef struct _sublex_info SUBLEXINFO;
  1988. struct _sublex_info {
  1989.     I32 super_state;    /* lexer state to save */
  1990.     I32 sub_inwhat;    /* "lex_inwhat" to use */
  1991.     OP *sub_op;        /* "lex_op" to use */
  1992.     char *super_bufptr;    /* PL_bufptr that was */
  1993.     char *super_bufend;    /* PL_bufend that was */
  1994. };
  1995.  
  1996. typedef struct magic_state MGS;    /* struct magic_state defined in mg.c */
  1997.  
  1998. struct scan_data_t;        /* Used in S_* functions in regcomp.c */
  1999. struct regnode_charclass_class;    /* Used in S_* functions in regcomp.c */
  2000.  
  2001. typedef I32 CHECKPOINT;
  2002.  
  2003. struct ptr_tbl_ent {
  2004.     struct ptr_tbl_ent*        next;
  2005.     void*            oldval;
  2006.     void*            newval;
  2007. };
  2008.  
  2009. struct ptr_tbl {
  2010.     struct ptr_tbl_ent**    tbl_ary;
  2011.     UV                tbl_max;
  2012.     UV                tbl_items;
  2013. };
  2014.  
  2015. #if defined(iAPX286) || defined(M_I286) || defined(I80286)
  2016. #   define I286
  2017. #endif
  2018.  
  2019. #if defined(htonl) && !defined(HAS_HTONL)
  2020. #define HAS_HTONL
  2021. #endif
  2022. #if defined(htons) && !defined(HAS_HTONS)
  2023. #define HAS_HTONS
  2024. #endif
  2025. #if defined(ntohl) && !defined(HAS_NTOHL)
  2026. #define HAS_NTOHL
  2027. #endif
  2028. #if defined(ntohs) && !defined(HAS_NTOHS)
  2029. #define HAS_NTOHS
  2030. #endif
  2031. #ifndef HAS_HTONL
  2032. #if (BYTEORDER & 0xffff) != 0x4321
  2033. #define HAS_HTONS
  2034. #define HAS_HTONL
  2035. #define HAS_NTOHS
  2036. #define HAS_NTOHL
  2037. #define MYSWAP
  2038. #define htons my_swap
  2039. #define htonl my_htonl
  2040. #define ntohs my_swap
  2041. #define ntohl my_ntohl
  2042. #endif
  2043. #else
  2044. #if (BYTEORDER & 0xffff) == 0x4321
  2045. #undef HAS_HTONS
  2046. #undef HAS_HTONL
  2047. #undef HAS_NTOHS
  2048. #undef HAS_NTOHL
  2049. #endif
  2050. #endif
  2051.  
  2052. /*
  2053.  * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
  2054.  * -DWS
  2055.  */
  2056. #if BYTEORDER != 0x1234
  2057. # define HAS_VTOHL
  2058. # define HAS_VTOHS
  2059. # define HAS_HTOVL
  2060. # define HAS_HTOVS
  2061. # if BYTEORDER == 0x4321 || BYTEORDER == 0x87654321
  2062. #  define vtohl(x)    ((((x)&0xFF)<<24)    \
  2063.             +(((x)>>24)&0xFF)    \
  2064.             +(((x)&0x0000FF00)<<8)    \
  2065.             +(((x)&0x00FF0000)>>8)    )
  2066. #  define vtohs(x)    ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
  2067. #  define htovl(x)    vtohl(x)
  2068. #  define htovs(x)    vtohs(x)
  2069. # endif
  2070.     /* otherwise default to functions in util.c */
  2071. #endif
  2072.  
  2073. #ifdef CASTNEGFLOAT
  2074. #define U_S(what) ((U16)(what))
  2075. #define U_I(what) ((unsigned int)(what))
  2076. #define U_L(what) ((U32)(what))
  2077. #else
  2078. #define U_S(what) ((U16)cast_ulong((NV)(what)))
  2079. #define U_I(what) ((unsigned int)cast_ulong((NV)(what)))
  2080. #define U_L(what) (cast_ulong((NV)(what)))
  2081. #endif
  2082.  
  2083. #ifdef CASTI32
  2084. #define I_32(what) ((I32)(what))
  2085. #define I_V(what) ((IV)(what))
  2086. #define U_V(what) ((UV)(what))
  2087. #else
  2088. #define I_32(what) (cast_i32((NV)(what)))
  2089. #define I_V(what) (cast_iv((NV)(what)))
  2090. #define U_V(what) (cast_uv((NV)(what)))
  2091. #endif
  2092.  
  2093. /* These do not care about the fractional part, only about the range. */
  2094. #define NV_WITHIN_IV(nv) (I_V(nv) >= IV_MIN && I_V(nv) <= IV_MAX)
  2095. #define NV_WITHIN_UV(nv) ((nv)>=0.0 && U_V(nv) >= UV_MIN && U_V(nv) <= UV_MAX)
  2096.  
  2097. /* Used with UV/IV arguments: */
  2098.                     /* XXXX: need to speed it up */
  2099. #define CLUMP_2UV(iv)    ((iv) < 0 ? 0 : (UV)(iv))
  2100. #define CLUMP_2IV(uv)    ((uv) > (UV)IV_MAX ? IV_MAX : (IV)(uv))
  2101.  
  2102. #ifndef MAXSYSFD
  2103. #   define MAXSYSFD 2
  2104. #endif
  2105.  
  2106. #ifndef __cplusplus
  2107. Uid_t getuid (void);
  2108. Uid_t geteuid (void);
  2109. Gid_t getgid (void);
  2110. Gid_t getegid (void);
  2111. #endif
  2112.  
  2113. #ifndef Perl_debug_log
  2114. #  define Perl_debug_log    PerlIO_stderr()
  2115. #endif
  2116.  
  2117. #ifndef Perl_error_log
  2118. #  define Perl_error_log    (PL_stderrgv            \
  2119.                  && GvIOp(PL_stderrgv)          \
  2120.                  && IoOFP(GvIOp(PL_stderrgv))    \
  2121.                  ? IoOFP(GvIOp(PL_stderrgv))    \
  2122.                  : PerlIO_stderr())
  2123. #endif
  2124.  
  2125. #ifdef DEBUGGING
  2126. #undef  YYDEBUG
  2127. #define YYDEBUG 1
  2128. #define DEB(a)                 a
  2129. #define DEBUG(a)   if (PL_debug)        a
  2130. #define DEBUG_p(a) if (PL_debug & 1)    a
  2131. #define DEBUG_s(a) if (PL_debug & 2)    a
  2132. #define DEBUG_l(a) if (PL_debug & 4)    a
  2133. #define DEBUG_t(a) if (PL_debug & 8)    a
  2134. #define DEBUG_o(a) if (PL_debug & 16)    a
  2135. #define DEBUG_c(a) if (PL_debug & 32)    a
  2136. #define DEBUG_P(a) if (PL_debug & 64)    a
  2137. #  if defined(PERL_OBJECT)
  2138. #    define DEBUG_m(a) if (PL_debug & 128)    a
  2139. #  else
  2140.      /* Temporarily turn off memory debugging in case the a
  2141.       * does memory allocation, either directly or indirectly. */
  2142. #    define DEBUG_m(a)  \
  2143.     STMT_START {                            \
  2144.         if (PERL_GET_INTERP) { dTHX; if (PL_debug & 128) {PL_debug&=~128; a; PL_debug|=128;} } \
  2145.     } STMT_END
  2146. #  endif
  2147. #define DEBUG_f(a) if (PL_debug & 256)    a
  2148. #define DEBUG_r(a) if (PL_debug & 512)    a
  2149. #define DEBUG_x(a) if (PL_debug & 1024)    a
  2150. #define DEBUG_u(a) if (PL_debug & 2048)    a
  2151. #define DEBUG_L(a) if (PL_debug & 4096)    a
  2152. #define DEBUG_H(a) if (PL_debug & 8192)    a
  2153. #define DEBUG_X(a) if (PL_debug & 16384)    a
  2154. #define DEBUG_D(a) if (PL_debug & 32768)    a
  2155. #  ifdef USE_THREADS
  2156. #    define DEBUG_S(a) if (PL_debug & (1<<16))    a
  2157. #  else
  2158. #    define DEBUG_S(a)
  2159. #  endif
  2160. #define DEBUG_T(a) if (PL_debug & (1<<17))    a
  2161. #else
  2162. #define DEB(a)
  2163. #define DEBUG(a)
  2164. #define DEBUG_p(a)
  2165. #define DEBUG_s(a)
  2166. #define DEBUG_l(a)
  2167. #define DEBUG_t(a)
  2168. #define DEBUG_o(a)
  2169. #define DEBUG_c(a)
  2170. #define DEBUG_P(a)
  2171. #define DEBUG_m(a)
  2172. #define DEBUG_f(a)
  2173. #define DEBUG_r(a)
  2174. #define DEBUG_x(a)
  2175. #define DEBUG_u(a)
  2176. #define DEBUG_S(a)
  2177. #define DEBUG_H(a)
  2178. #define DEBUG_X(a)
  2179. #define DEBUG_D(a)
  2180. #define DEBUG_S(a)
  2181. #define DEBUG_T(a)
  2182. #endif
  2183. #define YYMAXDEPTH 300
  2184.  
  2185. #ifndef assert  /* <assert.h> might have been included somehow */
  2186. #define assert(what)    DEB( {                        \
  2187.     if (!(what)) {                            \
  2188.         Perl_croak(aTHX_ "Assertion failed: file \"%s\", line %d",    \
  2189.         __FILE__, __LINE__);                    \
  2190.         PerlProc_exit(1);                        \
  2191.     }})
  2192. #endif
  2193.  
  2194. struct ufuncs {
  2195.     I32 (*uf_val)(IV, SV*);
  2196.     I32 (*uf_set)(IV, SV*);
  2197.     IV uf_index;
  2198. };
  2199.  
  2200. /* Fix these up for __STDC__ */
  2201. #ifndef DONT_DECLARE_STD
  2202. char *mktemp (char*);
  2203. #ifndef atof
  2204. double atof (const char*);
  2205. #endif
  2206. #endif
  2207.  
  2208. #ifndef STANDARD_C
  2209. /* All of these are in stdlib.h or time.h for ANSI C */
  2210. Time_t time();
  2211. struct tm *gmtime(), *localtime();
  2212. #if defined(OEMVS) || defined(__OPEN_VM)
  2213. char *(strchr)(), *(strrchr)();
  2214. char *(strcpy)(), *(strcat)();
  2215. #else
  2216. char *strchr(), *strrchr();
  2217. char *strcpy(), *strcat();
  2218. #endif
  2219. #endif /* ! STANDARD_C */
  2220.  
  2221.  
  2222. #ifdef I_MATH
  2223. #    include <math.h>
  2224. #else
  2225. START_EXTERN_C
  2226.         double exp (double);
  2227.         double log (double);
  2228.         double log10 (double);
  2229.         double sqrt (double);
  2230.         double frexp (double,int*);
  2231.         double ldexp (double,int);
  2232.         double modf (double,double*);
  2233.         double sin (double);
  2234.         double cos (double);
  2235.         double atan2 (double,double);
  2236.         double pow (double,double);
  2237. END_EXTERN_C
  2238. #endif
  2239.  
  2240. #ifndef __cplusplus
  2241. #  if defined(NeXT) || defined(__NeXT__) /* or whatever catches all NeXTs */
  2242. char *crypt ();       /* Maybe more hosts will need the unprototyped version */
  2243. #  else
  2244. #    if !defined(WIN32)
  2245. char *crypt (const char*, const char*);
  2246. #    endif /* !WIN32 */
  2247. #  endif /* !NeXT && !__NeXT__ */
  2248. #  ifndef DONT_DECLARE_STD
  2249. #    ifndef getenv
  2250. char *getenv (const char*);
  2251. #    endif /* !getenv */
  2252. #    if !defined(HAS_LSEEK_PROTO) && !defined(EPOC) && !defined(__hpux)
  2253. #      ifdef _FILE_OFFSET_BITS
  2254. #        if _FILE_OFFSET_BITS == 64
  2255. Off_t lseek (int,Off_t,int);
  2256. #        endif
  2257. #      endif
  2258. #    endif
  2259. #  endif /* !DONT_DECLARE_STD */
  2260. char *getlogin (void);
  2261. #endif /* !__cplusplus */
  2262.  
  2263. #ifdef UNLINK_ALL_VERSIONS /* Currently only makes sense for VMS */
  2264. #define UNLINK unlnk
  2265. I32 unlnk (char*);
  2266. #else
  2267. #define UNLINK PerlLIO_unlink
  2268. #endif
  2269.  
  2270. #ifndef HAS_SETREUID
  2271. #  ifdef HAS_SETRESUID
  2272. #    define setreuid(r,e) setresuid(r,e,(Uid_t)-1)
  2273. #    define HAS_SETREUID
  2274. #  endif
  2275. #endif
  2276. #ifndef HAS_SETREGID
  2277. #  ifdef HAS_SETRESGID
  2278. #    define setregid(r,e) setresgid(r,e,(Gid_t)-1)
  2279. #    define HAS_SETREGID
  2280. #  endif
  2281. #endif
  2282.  
  2283. /* Sighandler_t defined in iperlsys.h */
  2284.  
  2285. #ifdef HAS_SIGACTION
  2286. typedef struct sigaction Sigsave_t;
  2287. #else
  2288. typedef Sighandler_t Sigsave_t;
  2289. #endif
  2290.  
  2291. #define SCAN_DEF 0
  2292. #define SCAN_TR 1
  2293. #define SCAN_REPL 2
  2294.  
  2295. #ifdef DEBUGGING
  2296. # ifndef register
  2297. #  define register
  2298. # endif
  2299. # define PAD_SV(po) pad_sv(po)
  2300. # define RUNOPS_DEFAULT Perl_runops_debug
  2301. #else
  2302. # define PAD_SV(po) PL_curpad[po]
  2303. # define RUNOPS_DEFAULT Perl_runops_standard
  2304. #endif
  2305.  
  2306. #ifdef MYMALLOC
  2307. #  ifdef MUTEX_INIT_CALLS_MALLOC
  2308. #    define MALLOC_INIT                    \
  2309.     STMT_START {                    \
  2310.         PL_malloc_mutex = NULL;            \
  2311.         MUTEX_INIT(&PL_malloc_mutex);        \
  2312.     } STMT_END
  2313. #    define MALLOC_TERM                    \
  2314.     STMT_START {                    \
  2315.         perl_mutex tmp = PL_malloc_mutex;    \
  2316.         PL_malloc_mutex = NULL;            \
  2317.         MUTEX_DESTROY(&tmp);            \
  2318.     } STMT_END
  2319. #  else
  2320. #    define MALLOC_INIT MUTEX_INIT(&PL_malloc_mutex)
  2321. #    define MALLOC_TERM MUTEX_DESTROY(&PL_malloc_mutex)
  2322. #  endif
  2323. #else
  2324. #  define MALLOC_INIT
  2325. #  define MALLOC_TERM
  2326. #endif
  2327.  
  2328.  
  2329. typedef int (CPERLscope(*runops_proc_t)) (pTHX);
  2330. typedef OP* (CPERLscope(*PPADDR_t)[]) (pTHX);
  2331.  
  2332. /* _ (for $_) must be first in the following list (DEFSV requires it) */
  2333. #define THREADSV_NAMES "_123456789&`'+/.,\\\";^-%=|~:\001\005!@"
  2334.  
  2335. /* NeXT has problems with crt0.o globals */
  2336. #if defined(__DYNAMIC__) && \
  2337.     (defined(NeXT) || defined(__NeXT__) || defined(__APPLE__))
  2338. #  if defined(NeXT) || defined(__NeXT)
  2339. #    include <mach-o/dyld.h>
  2340. #    define environ (*environ_pointer)
  2341. EXT char *** environ_pointer;
  2342. #  else
  2343. #    if defined(__APPLE__) && defined(PERL_CORE)
  2344. #      include <crt_externs.h>    /* for the env array */
  2345. #      define environ (*_NSGetEnviron())
  2346. #    endif
  2347. #  endif
  2348. #else
  2349.    /* VMS and some other platforms don't use the environ array */
  2350. #  ifdef USE_ENVIRON_ARRAY
  2351. #    if !defined(DONT_DECLARE_STD) || \
  2352.         (defined(__svr4__) && defined(__GNUC__) && defined(sun)) || \
  2353.         defined(__sgi) || \
  2354.         defined(__DGUX) 
  2355. extern char **    environ;    /* environment variables supplied via exec */
  2356. #    endif
  2357. #  endif
  2358. #endif
  2359.  
  2360. START_EXTERN_C
  2361.  
  2362. /* handy constants */
  2363. EXTCONST char PL_warn_uninit[]
  2364.   INIT("Use of uninitialized value%s%s");
  2365. EXTCONST char PL_warn_nosemi[]
  2366.   INIT("Semicolon seems to be missing");
  2367. EXTCONST char PL_warn_reserved[]
  2368.   INIT("Unquoted string \"%s\" may clash with future reserved word");
  2369. EXTCONST char PL_warn_nl[]
  2370.   INIT("Unsuccessful %s on filename containing newline");
  2371. EXTCONST char PL_no_wrongref[]
  2372.   INIT("Can't use %s ref as %s ref");
  2373. EXTCONST char PL_no_symref[]
  2374.   INIT("Can't use string (\"%.32s\") as %s ref while \"strict refs\" in use");
  2375. EXTCONST char PL_no_usym[]
  2376.   INIT("Can't use an undefined value as %s reference");
  2377. EXTCONST char PL_no_aelem[]
  2378.   INIT("Modification of non-creatable array value attempted, subscript %d");
  2379. EXTCONST char PL_no_helem[]
  2380.   INIT("Modification of non-creatable hash value attempted, subscript \"%s\"");
  2381. EXTCONST char PL_no_modify[]
  2382.   INIT("Modification of a read-only value attempted");
  2383. EXTCONST char PL_no_mem[]
  2384.   INIT("Out of memory!\n");
  2385. EXTCONST char PL_no_security[]
  2386.   INIT("Insecure dependency in %s%s");
  2387. EXTCONST char PL_no_sock_func[]
  2388.   INIT("Unsupported socket function \"%s\" called");
  2389. EXTCONST char PL_no_dir_func[]
  2390.   INIT("Unsupported directory function \"%s\" called");
  2391. EXTCONST char PL_no_func[]
  2392.   INIT("The %s function is unimplemented");
  2393. EXTCONST char PL_no_myglob[]
  2394.   INIT("\"my\" variable %s can't be in a package");
  2395.  
  2396. EXTCONST char PL_uuemap[65]
  2397.   INIT("`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_");
  2398.  
  2399.  
  2400. #ifdef DOINIT
  2401. EXT char *PL_sig_name[] = { SIG_NAME };
  2402. EXT int   PL_sig_num[]  = { SIG_NUM };
  2403. #else
  2404. EXT char *PL_sig_name[];
  2405. EXT int   PL_sig_num[];
  2406. #endif
  2407.  
  2408. /* fast case folding tables */
  2409.  
  2410. #ifdef DOINIT
  2411. #ifdef EBCDIC
  2412. EXT unsigned char PL_fold[] = { /* fast EBCDIC case folding table */
  2413.     0,      1,      2,      3,      4,      5,      6,      7,
  2414.     8,      9,      10,     11,     12,     13,     14,     15,
  2415.     16,     17,     18,     19,     20,     21,     22,     23,
  2416.     24,     25,     26,     27,     28,     29,     30,     31,
  2417.     32,     33,     34,     35,     36,     37,     38,     39,
  2418.     40,     41,     42,     43,     44,     45,     46,     47,
  2419.     48,     49,     50,     51,     52,     53,     54,     55,
  2420.     56,     57,     58,     59,     60,     61,     62,     63,
  2421.     64,     65,     66,     67,     68,     69,     70,     71,
  2422.     72,     73,     74,     75,     76,     77,     78,     79,
  2423.     80,     81,     82,     83,     84,     85,     86,     87,
  2424.     88,     89,     90,     91,     92,     93,     94,     95,
  2425.     96,     97,     98,     99,     100,    101,    102,    103,
  2426.     104,    105,    106,    107,    108,    109,    110,    111,
  2427.     112,    113,    114,    115,    116,    117,    118,    119,
  2428.     120,    121,    122,    123,    124,    125,    126,    127,
  2429.     128,    'A',    'B',    'C',    'D',    'E',    'F',    'G',
  2430.     'H',    'I',    138,    139,    140,    141,    142,    143,
  2431.     144,    'J',    'K',    'L',    'M',    'N',    'O',    'P',
  2432.     'Q',    'R',    154,    155,    156,    157,    158,    159,
  2433.     160,    161,    'S',    'T',    'U',    'V',    'W',    'X',
  2434.     'Y',    'Z',    170,    171,    172,    173,    174,    175,
  2435.     176,    177,    178,    179,    180,    181,    182,    183,
  2436.     184,    185,    186,    187,    188,    189,    190,    191,
  2437.     192,    'a',    'b',    'c',    'd',    'e',    'f',    'g',
  2438.     'h',    'i',    202,    203,    204,    205,    206,    207,
  2439.     208,    'j',    'k',    'l',    'm',    'n',    'o',    'p',
  2440.     'q',    'r',    218,    219,    220,    221,    222,    223,
  2441.     224,    225,    's',    't',    'u',    'v',    'w',    'x',
  2442.     'y',    'z',    234,    235,    236,    237,    238,    239,
  2443.     240,    241,    242,    243,    244,    245,    246,    247,
  2444.     248,    249,    250,    251,    252,    253,    254,    255
  2445. };
  2446. #else   /* ascii rather than ebcdic */
  2447. EXTCONST  unsigned char PL_fold[] = {
  2448.     0,    1,    2,    3,    4,    5,    6,    7,
  2449.     8,    9,    10,    11,    12,    13,    14,    15,
  2450.     16,    17,    18,    19,    20,    21,    22,    23,
  2451.     24,    25,    26,    27,    28,    29,    30,    31,
  2452.     32,    33,    34,    35,    36,    37,    38,    39,
  2453.     40,    41,    42,    43,    44,    45,    46,    47,
  2454.     48,    49,    50,    51,    52,    53,    54,    55,
  2455.     56,    57,    58,    59,    60,    61,    62,    63,
  2456.     64,    'a',    'b',    'c',    'd',    'e',    'f',    'g',
  2457.     'h',    'i',    'j',    'k',    'l',    'm',    'n',    'o',
  2458.     'p',    'q',    'r',    's',    't',    'u',    'v',    'w',
  2459.     'x',    'y',    'z',    91,    92,    93,    94,    95,
  2460.     96,    'A',    'B',    'C',    'D',    'E',    'F',    'G',
  2461.     'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
  2462.     'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
  2463.     'X',    'Y',    'Z',    123,    124,    125,    126,    127,
  2464.     128,    129,    130,    131,    132,    133,    134,    135,
  2465.     136,    137,    138,    139,    140,    141,    142,    143,
  2466.     144,    145,    146,    147,    148,    149,    150,    151,
  2467.     152,    153,    154,    155,    156,    157,    158,    159,
  2468.     160,    161,    162,    163,    164,    165,    166,    167,
  2469.     168,    169,    170,    171,    172,    173,    174,    175,
  2470.     176,    177,    178,    179,    180,    181,    182,    183,
  2471.     184,    185,    186,    187,    188,    189,    190,    191,
  2472.     192,    193,    194,    195,    196,    197,    198,    199,
  2473.     200,    201,    202,    203,    204,    205,    206,    207,
  2474.     208,    209,    210,    211,    212,    213,    214,    215,
  2475.     216,    217,    218,    219,    220,    221,    222,    223,    
  2476.     224,    225,    226,    227,    228,    229,    230,    231,
  2477.     232,    233,    234,    235,    236,    237,    238,    239,
  2478.     240,    241,    242,    243,    244,    245,    246,    247,
  2479.     248,    249,    250,    251,    252,    253,    254,    255
  2480. };
  2481. #endif  /* !EBCDIC */
  2482. #else
  2483. EXTCONST unsigned char PL_fold[];
  2484. #endif
  2485.  
  2486. #ifdef DOINIT
  2487. EXT unsigned char PL_fold_locale[] = {
  2488.     0,    1,    2,    3,    4,    5,    6,    7,
  2489.     8,    9,    10,    11,    12,    13,    14,    15,
  2490.     16,    17,    18,    19,    20,    21,    22,    23,
  2491.     24,    25,    26,    27,    28,    29,    30,    31,
  2492.     32,    33,    34,    35,    36,    37,    38,    39,
  2493.     40,    41,    42,    43,    44,    45,    46,    47,
  2494.     48,    49,    50,    51,    52,    53,    54,    55,
  2495.     56,    57,    58,    59,    60,    61,    62,    63,
  2496.     64,    'a',    'b',    'c',    'd',    'e',    'f',    'g',
  2497.     'h',    'i',    'j',    'k',    'l',    'm',    'n',    'o',
  2498.     'p',    'q',    'r',    's',    't',    'u',    'v',    'w',
  2499.     'x',    'y',    'z',    91,    92,    93,    94,    95,
  2500.     96,    'A',    'B',    'C',    'D',    'E',    'F',    'G',
  2501.     'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
  2502.     'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
  2503.     'X',    'Y',    'Z',    123,    124,    125,    126,    127,
  2504.     128,    129,    130,    131,    132,    133,    134,    135,
  2505.     136,    137,    138,    139,    140,    141,    142,    143,
  2506.     144,    145,    146,    147,    148,    149,    150,    151,
  2507.     152,    153,    154,    155,    156,    157,    158,    159,
  2508.     160,    161,    162,    163,    164,    165,    166,    167,
  2509.     168,    169,    170,    171,    172,    173,    174,    175,
  2510.     176,    177,    178,    179,    180,    181,    182,    183,
  2511.     184,    185,    186,    187,    188,    189,    190,    191,
  2512.     192,    193,    194,    195,    196,    197,    198,    199,
  2513.     200,    201,    202,    203,    204,    205,    206,    207,
  2514.     208,    209,    210,    211,    212,    213,    214,    215,
  2515.     216,    217,    218,    219,    220,    221,    222,    223,    
  2516.     224,    225,    226,    227,    228,    229,    230,    231,
  2517.     232,    233,    234,    235,    236,    237,    238,    239,
  2518.     240,    241,    242,    243,    244,    245,    246,    247,
  2519.     248,    249,    250,    251,    252,    253,    254,    255
  2520. };
  2521. #else
  2522. EXT unsigned char PL_fold_locale[];
  2523. #endif
  2524.  
  2525. #ifdef DOINIT
  2526. #ifdef EBCDIC
  2527. EXT unsigned char PL_freq[] = {/* EBCDIC frequencies for mixed English/C */
  2528.     1,      2,      84,     151,    154,    155,    156,    157,
  2529.     165,    246,    250,    3,      158,    7,      18,     29,
  2530.     40,     51,     62,     73,     85,     96,     107,    118,
  2531.     129,    140,    147,    148,    149,    150,    152,    153,
  2532.     255,      6,      8,      9,     10,     11,     12,     13,
  2533.      14,     15,     24,     25,     26,     27,     28,    226,
  2534.      29,     30,     31,     32,     33,     43,     44,     45,
  2535.      46,     47,     48,     49,     50,     76,     77,     78,
  2536.      79,     80,     81,     82,     83,     84,     85,     86,
  2537.      87,     94,     95,    234,    181,    233,    187,    190,
  2538.     180,     96,     97,     98,     99,    100,    101,    102,
  2539.     104,    112,    182,    174,    236,    232,    229,    103,
  2540.     228,    226,    114,    115,    116,    117,    118,    119,
  2541.     120,    121,    122,    235,    176,    230,    194,    162,
  2542.     130,    131,    132,    133,    134,    135,    136,    137,
  2543.     138,    139,    201,    205,    163,    217,    220,    224,
  2544.     5,      248,    227,    244,    242,    255,    241,    231,
  2545.     240,    253,    16,     197,    19,     20,     21,     187,
  2546.     23,     169,    210,    245,    237,    249,    247,    239,
  2547.     168,    252,    34,     196,    36,     37,     38,     39,
  2548.     41,     42,     251,    254,    238,    223,    221,    213,
  2549.     225,    177,    52,     53,     54,     55,     56,     57,
  2550.     58,     59,     60,     61,     63,     64,     65,     66,
  2551.     67,     68,     69,     70,     71,     72,     74,     75,
  2552.     205,    208,    186,    202,    200,    218,    198,    179,
  2553.     178,    214,    88,     89,     90,     91,     92,     93,
  2554.     217,    166,    170,    207,    199,    209,    206,    204,
  2555.     160,    212,    105,    106,    108,    109,    110,    111,
  2556.     203,    113,    216,    215,    192,    175,    193,    243,
  2557.     172,    161,    123,    124,    125,    126,    127,    128,
  2558.     222,    219,    211,    195,    188,    193,    185,    184,
  2559.     191,    183,    141,    142,    143,    144,    145,    146
  2560. };
  2561. #else  /* ascii rather than ebcdic */
  2562. EXTCONST unsigned char PL_freq[] = {    /* letter frequencies for mixed English/C */
  2563.     1,    2,    84,    151,    154,    155,    156,    157,
  2564.     165,    246,    250,    3,    158,    7,    18,    29,
  2565.     40,    51,    62,    73,    85,    96,    107,    118,
  2566.     129,    140,    147,    148,    149,    150,    152,    153,
  2567.     255,    182,    224,    205,    174,    176,    180,    217,
  2568.     233,    232,    236,    187,    235,    228,    234,    226,
  2569.     222,    219,    211,    195,    188,    193,    185,    184,
  2570.     191,    183,    201,    229,    181,    220,    194,    162,
  2571.     163,    208,    186,    202,    200,    218,    198,    179,
  2572.     178,    214,    166,    170,    207,    199,    209,    206,
  2573.     204,    160,    212,    216,    215,    192,    175,    173,
  2574.     243,    172,    161,    190,    203,    189,    164,    230,
  2575.     167,    248,    227,    244,    242,    255,    241,    231,
  2576.     240,    253,    169,    210,    245,    237,    249,    247,
  2577.     239,    168,    252,    251,    254,    238,    223,    221,
  2578.     213,    225,    177,    197,    171,    196,    159,    4,
  2579.     5,    6,    8,    9,    10,    11,    12,    13,
  2580.     14,    15,    16,    17,    19,    20,    21,    22,
  2581.     23,    24,    25,    26,    27,    28,    30,    31,
  2582.     32,    33,    34,    35,    36,    37,    38,    39,
  2583.     41,    42,    43,    44,    45,    46,    47,    48,
  2584.     49,    50,    52,    53,    54,    55,    56,    57,
  2585.     58,    59,    60,    61,    63,    64,    65,    66,
  2586.     67,    68,    69,    70,    71,    72,    74,    75,
  2587.     76,    77,    78,    79,    80,    81,    82,    83,
  2588.     86,    87,    88,    89,    90,    91,    92,    93,
  2589.     94,    95,    97,    98,    99,    100,    101,    102,
  2590.     103,    104,    105,    106,    108,    109,    110,    111,
  2591.     112,    113,    114,    115,    116,    117,    119,    120,
  2592.     121,    122,    123,    124,    125,    126,    127,    128,
  2593.     130,    131,    132,    133,    134,    135,    136,    137,
  2594.     138,    139,    141,    142,    143,    144,    145,    146
  2595. };
  2596. #endif
  2597. #else
  2598. EXTCONST unsigned char PL_freq[];
  2599. #endif
  2600.  
  2601. #ifdef DEBUGGING
  2602. #ifdef DOINIT
  2603. EXTCONST char* PL_block_type[] = {
  2604.     "NULL",
  2605.     "SUB",
  2606.     "EVAL",
  2607.     "LOOP",
  2608.     "SUBST",
  2609.     "BLOCK",
  2610. };
  2611. #else
  2612. EXTCONST char* PL_block_type[];
  2613. #endif
  2614. #endif
  2615.  
  2616. END_EXTERN_C
  2617.  
  2618. /*****************************************************************************/
  2619. /* This lexer/parser stuff is currently global since yacc is hard to reenter */
  2620. /*****************************************************************************/
  2621. /* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */
  2622.  
  2623. #include "perly.h"
  2624.  
  2625. #define LEX_NOTPARSING        11    /* borrowed from toke.c */
  2626.  
  2627. typedef enum {
  2628.     XOPERATOR,
  2629.     XTERM,
  2630.     XREF,
  2631.     XSTATE,
  2632.     XBLOCK,
  2633.     XATTRBLOCK,
  2634.     XATTRTERM,
  2635.     XTERMBLOCK
  2636. } expectation;
  2637.  
  2638. enum {        /* pass one of these to get_vtbl */
  2639.     want_vtbl_sv,
  2640.     want_vtbl_env,
  2641.     want_vtbl_envelem,
  2642.     want_vtbl_sig,
  2643.     want_vtbl_sigelem,
  2644.     want_vtbl_pack,
  2645.     want_vtbl_packelem,
  2646.     want_vtbl_dbline,
  2647.     want_vtbl_isa,
  2648.     want_vtbl_isaelem,
  2649.     want_vtbl_arylen,
  2650.     want_vtbl_glob,
  2651.     want_vtbl_mglob,
  2652.     want_vtbl_nkeys,
  2653.     want_vtbl_taint,
  2654.     want_vtbl_substr,
  2655.     want_vtbl_vec,
  2656.     want_vtbl_pos,
  2657.     want_vtbl_bm,
  2658.     want_vtbl_fm,
  2659.     want_vtbl_uvar,
  2660.     want_vtbl_defelem,
  2661.     want_vtbl_regexp,
  2662.     want_vtbl_collxfrm,
  2663.     want_vtbl_amagic,
  2664.     want_vtbl_amagicelem,
  2665. #ifdef USE_THREADS
  2666.     want_vtbl_mutex,
  2667. #endif
  2668.     want_vtbl_regdata,
  2669.     want_vtbl_regdatum,
  2670.     want_vtbl_backref
  2671. };
  2672.  
  2673.                 /* Note: the lowest 8 bits are reserved for
  2674.                    stuffing into op->op_private */
  2675. #define HINT_PRIVATE_MASK    0x000000ff
  2676. #define HINT_INTEGER        0x00000001
  2677. #define HINT_STRICT_REFS    0x00000002
  2678. #define HINT_LOCALE        0x00000004
  2679. #define HINT_BYTE        0x00000008
  2680. /* #define HINT_notused10    0x00000010 */
  2681.                 /* Note: 20,40,80 used for NATIVE_HINTS */
  2682.  
  2683. #define HINT_BLOCK_SCOPE    0x00000100
  2684. #define HINT_STRICT_SUBS    0x00000200
  2685. #define HINT_STRICT_VARS    0x00000400
  2686.  
  2687. #define HINT_NEW_INTEGER    0x00001000
  2688. #define HINT_NEW_FLOAT        0x00002000
  2689. #define HINT_NEW_BINARY        0x00004000
  2690. #define HINT_NEW_STRING        0x00008000
  2691. #define HINT_NEW_RE        0x00010000
  2692. #define HINT_LOCALIZE_HH    0x00020000 /* %^H needs to be copied */
  2693.  
  2694. #define HINT_RE_TAINT        0x00100000
  2695. #define HINT_RE_EVAL        0x00200000
  2696.  
  2697. #define HINT_FILETEST_ACCESS    0x00400000
  2698. #define HINT_UTF8        0x00800000
  2699.  
  2700. /* Various states of an input record separator SV (rs, nrs) */
  2701. #define RsSNARF(sv)   (! SvOK(sv))
  2702. #define RsSIMPLE(sv)  (SvOK(sv) && (! SvPOK(sv) || SvCUR(sv)))
  2703. #define RsPARA(sv)    (SvPOK(sv) && ! SvCUR(sv))
  2704. #define RsRECORD(sv)  (SvROK(sv) && (SvIV(SvRV(sv)) > 0))
  2705.  
  2706. /* Enable variables which are pointers to functions */
  2707. typedef regexp*(CPERLscope(*regcomp_t)) (pTHX_ char* exp, char* xend, PMOP* pm);
  2708. typedef I32 (CPERLscope(*regexec_t)) (pTHX_ regexp* prog, char* stringarg,
  2709.                       char* strend, char* strbeg, I32 minend,
  2710.                       SV* screamer, void* data, U32 flags);
  2711. typedef char* (CPERLscope(*re_intuit_start_t)) (pTHX_ regexp *prog, SV *sv,
  2712.                         char *strpos, char *strend,
  2713.                         U32 flags,
  2714.                         struct re_scream_pos_data_s *d);
  2715. typedef SV*    (CPERLscope(*re_intuit_string_t)) (pTHX_ regexp *prog);
  2716. typedef void    (CPERLscope(*regfree_t)) (pTHX_ struct regexp* r);
  2717.  
  2718. typedef void (*DESTRUCTORFUNC_NOCONTEXT_t) (void*);
  2719. typedef void (*DESTRUCTORFUNC_t) (pTHXo_ void*);
  2720. typedef void (*SVFUNC_t) (pTHXo_ SV*);
  2721. typedef I32  (*SVCOMPARE_t) (pTHXo_ SV*, SV*);
  2722. typedef void (*XSINIT_t) (pTHXo);
  2723. typedef void (*ATEXIT_t) (pTHXo_ void*);
  2724. typedef void (*XSUBADDR_t) (pTHXo_ CV *);
  2725.  
  2726. /* Set up PERLVAR macros for populating structs */
  2727. #define PERLVAR(var,type) type var;
  2728. #define PERLVARA(var,n,type) type var[n];
  2729. #define PERLVARI(var,type,init) type var;
  2730. #define PERLVARIC(var,type,init) type var;
  2731.  
  2732. /* Interpreter exitlist entry */
  2733. typedef struct exitlistentry {
  2734.     void (*fn) (pTHXo_ void*);
  2735.     void *ptr;
  2736. } PerlExitListEntry;
  2737.  
  2738. #ifdef PERL_GLOBAL_STRUCT
  2739. struct perl_vars {
  2740. #  include "perlvars.h"
  2741. };
  2742.  
  2743. #  ifdef PERL_CORE
  2744. EXT struct perl_vars PL_Vars;
  2745. EXT struct perl_vars *PL_VarsPtr INIT(&PL_Vars);
  2746. #  else /* PERL_CORE */
  2747. #    if !defined(__GNUC__) || !defined(WIN32)
  2748. EXT
  2749. #    endif /* WIN32 */
  2750. struct perl_vars *PL_VarsPtr;
  2751. #    define PL_Vars (*((PL_VarsPtr) \
  2752.                ? PL_VarsPtr : (PL_VarsPtr = Perl_GetVars(aTHX))))
  2753. #  endif /* PERL_CORE */
  2754. #endif /* PERL_GLOBAL_STRUCT */
  2755.  
  2756. #if defined(MULTIPLICITY) || defined(PERL_OBJECT)
  2757. /* If we have multiple interpreters define a struct 
  2758.    holding variables which must be per-interpreter
  2759.    If we don't have threads anything that would have 
  2760.    be per-thread is per-interpreter.
  2761. */
  2762.  
  2763. struct interpreter {
  2764. #  ifndef USE_THREADS
  2765. #    include "thrdvar.h"
  2766. #  endif
  2767. #  include "intrpvar.h"
  2768. /*
  2769.  * The following is a buffer where new variables must
  2770.  * be defined to maintain binary compatibility with PERL_OBJECT
  2771.  */
  2772. PERLVARA(object_compatibility,30,    char)
  2773. };
  2774.  
  2775. #else
  2776. struct interpreter {
  2777.     char broiled;
  2778. };
  2779. #endif /* MULTIPLICITY || PERL_OBJECT */
  2780.  
  2781. #ifdef USE_THREADS
  2782. /* If we have threads define a struct with all the variables
  2783.  * that have to be per-thread
  2784.  */
  2785.  
  2786.  
  2787. struct perl_thread {
  2788. #include "thrdvar.h"
  2789. };
  2790.  
  2791. typedef struct perl_thread *Thread;
  2792.  
  2793. #else
  2794. typedef void *Thread;
  2795. #endif
  2796.  
  2797. /* Done with PERLVAR macros for now ... */
  2798. #undef PERLVAR
  2799. #undef PERLVARA
  2800. #undef PERLVARI
  2801. #undef PERLVARIC
  2802.  
  2803. #include "thread.h"
  2804. #include "pp.h"
  2805.  
  2806. #ifndef PERL_CALLCONV
  2807. #  define PERL_CALLCONV
  2808. #endif 
  2809.  
  2810. #ifndef NEXT30_NO_ATTRIBUTE
  2811. #  ifndef HASATTRIBUTE       /* disable GNU-cc attribute checking? */
  2812. #    ifdef  __attribute__      /* Avoid possible redefinition errors */
  2813. #      undef  __attribute__
  2814. #    endif
  2815. #    define __attribute__(attr)
  2816. #  endif
  2817. #endif
  2818.  
  2819. #ifdef PERL_OBJECT
  2820. #  define PERL_DECL_PROT
  2821. #endif
  2822.  
  2823. #undef PERL_CKDEF
  2824. #undef PERL_PPDEF
  2825. #define PERL_CKDEF(s)    OP *s (pTHX_ OP *o);
  2826. #define PERL_PPDEF(s)    OP *s (pTHX);
  2827.  
  2828. #include "proto.h"
  2829.  
  2830. #ifdef PERL_OBJECT
  2831. #  undef PERL_DECL_PROT
  2832. #endif
  2833.  
  2834. #ifndef PERL_OBJECT
  2835. /* this has structure inits, so it cannot be included before here */
  2836. #  include "opcode.h"
  2837. #endif
  2838.  
  2839. /* The following must follow proto.h as #defines mess up syntax */
  2840.  
  2841. #if !defined(PERL_FOR_X2P)
  2842. #  include "embedvar.h"
  2843. #endif
  2844.  
  2845. /* Now include all the 'global' variables 
  2846.  * If we don't have threads or multiple interpreters
  2847.  * these include variables that would have been their struct-s 
  2848.  */
  2849.                          
  2850. #define PERLVAR(var,type) EXT type PL_##var;
  2851. #define PERLVARA(var,n,type) EXT type PL_##var[n];
  2852. #define PERLVARI(var,type,init) EXT type  PL_##var INIT(init);
  2853. #define PERLVARIC(var,type,init) EXTCONST type PL_##var INIT(init);
  2854.  
  2855. #if !defined(MULTIPLICITY) && !defined(PERL_OBJECT)
  2856. START_EXTERN_C
  2857. #  include "intrpvar.h"
  2858. #  ifndef USE_THREADS
  2859. #    include "thrdvar.h"
  2860. #  endif
  2861. END_EXTERN_C
  2862. #endif
  2863.  
  2864. #ifdef PERL_OBJECT
  2865. #  include "embed.h"
  2866.  
  2867. #  ifdef DOINIT
  2868. #    include "INTERN.h"
  2869. #  else
  2870. #    include "EXTERN.h"
  2871. #  endif
  2872.  
  2873. /* this has structure inits, so it cannot be included before here */
  2874. #  include "opcode.h"
  2875.  
  2876. #else
  2877. #  if defined(WIN32)
  2878. #    include "embed.h"
  2879. #  endif
  2880. #endif  /* PERL_OBJECT */
  2881.  
  2882. #ifndef PERL_GLOBAL_STRUCT
  2883. START_EXTERN_C
  2884.  
  2885. #  include "perlvars.h"
  2886.  
  2887. END_EXTERN_C
  2888. #endif
  2889.  
  2890. #undef PERLVAR
  2891. #undef PERLVARA
  2892. #undef PERLVARI
  2893. #undef PERLVARIC
  2894.  
  2895. START_EXTERN_C
  2896.  
  2897. #ifdef DOINIT
  2898.  
  2899. EXT MGVTBL PL_vtbl_sv =    {MEMBER_TO_FPTR(Perl_magic_get),
  2900.                 MEMBER_TO_FPTR(Perl_magic_set),
  2901.                     MEMBER_TO_FPTR(Perl_magic_len),
  2902.                         0,    0};
  2903. EXT MGVTBL PL_vtbl_env =    {0,    MEMBER_TO_FPTR(Perl_magic_set_all_env),
  2904.                 0,    MEMBER_TO_FPTR(Perl_magic_clear_all_env),
  2905.                             0};
  2906. EXT MGVTBL PL_vtbl_envelem =    {0,    MEMBER_TO_FPTR(Perl_magic_setenv),
  2907.                     0,    MEMBER_TO_FPTR(Perl_magic_clearenv),
  2908.                             0};
  2909. EXT MGVTBL PL_vtbl_sig =    {0,    0,         0, 0, 0};
  2910. EXT MGVTBL PL_vtbl_sigelem =    {MEMBER_TO_FPTR(Perl_magic_getsig),
  2911.                     MEMBER_TO_FPTR(Perl_magic_setsig),
  2912.                     0,    MEMBER_TO_FPTR(Perl_magic_clearsig),
  2913.                             0};
  2914. EXT MGVTBL PL_vtbl_pack =    {0,    0,    MEMBER_TO_FPTR(Perl_magic_sizepack),    MEMBER_TO_FPTR(Perl_magic_wipepack),
  2915.                             0};
  2916. EXT MGVTBL PL_vtbl_packelem =    {MEMBER_TO_FPTR(Perl_magic_getpack),
  2917.                 MEMBER_TO_FPTR(Perl_magic_setpack),
  2918.                     0,    MEMBER_TO_FPTR(Perl_magic_clearpack),
  2919.                             0};
  2920. EXT MGVTBL PL_vtbl_dbline =    {0,    MEMBER_TO_FPTR(Perl_magic_setdbline),
  2921.                     0,    0,    0};
  2922. EXT MGVTBL PL_vtbl_isa =    {0,    MEMBER_TO_FPTR(Perl_magic_setisa),
  2923.                     0,    MEMBER_TO_FPTR(Perl_magic_setisa),
  2924.                             0};
  2925. EXT MGVTBL PL_vtbl_isaelem =    {0,    MEMBER_TO_FPTR(Perl_magic_setisa),
  2926.                     0,    0,    0};
  2927. EXT MGVTBL PL_vtbl_arylen =    {MEMBER_TO_FPTR(Perl_magic_getarylen),
  2928.                 MEMBER_TO_FPTR(Perl_magic_setarylen),
  2929.                     0,    0,    0};
  2930. EXT MGVTBL PL_vtbl_glob =    {MEMBER_TO_FPTR(Perl_magic_getglob),
  2931.                 MEMBER_TO_FPTR(Perl_magic_setglob),
  2932.                     0,    0,    0};
  2933. EXT MGVTBL PL_vtbl_mglob =    {0,    MEMBER_TO_FPTR(Perl_magic_setmglob),
  2934.                     0,    0,    0};
  2935. EXT MGVTBL PL_vtbl_nkeys =    {MEMBER_TO_FPTR(Perl_magic_getnkeys),
  2936.                 MEMBER_TO_FPTR(Perl_magic_setnkeys),
  2937.                     0,    0,    0};
  2938. EXT MGVTBL PL_vtbl_taint =    {MEMBER_TO_FPTR(Perl_magic_gettaint),MEMBER_TO_FPTR(Perl_magic_settaint),
  2939.                     0,    0,    0};
  2940. EXT MGVTBL PL_vtbl_substr =    {MEMBER_TO_FPTR(Perl_magic_getsubstr), MEMBER_TO_FPTR(Perl_magic_setsubstr),
  2941.                     0,    0,    0};
  2942. EXT MGVTBL PL_vtbl_vec =    {MEMBER_TO_FPTR(Perl_magic_getvec),
  2943.                 MEMBER_TO_FPTR(Perl_magic_setvec),
  2944.                     0,    0,    0};
  2945. EXT MGVTBL PL_vtbl_pos =    {MEMBER_TO_FPTR(Perl_magic_getpos),
  2946.                 MEMBER_TO_FPTR(Perl_magic_setpos),
  2947.                     0,    0,    0};
  2948. EXT MGVTBL PL_vtbl_bm =    {0,    MEMBER_TO_FPTR(Perl_magic_setbm),
  2949.                     0,    0,    0};
  2950. EXT MGVTBL PL_vtbl_fm =    {0,    MEMBER_TO_FPTR(Perl_magic_setfm),
  2951.                     0,    0,    0};
  2952. EXT MGVTBL PL_vtbl_uvar =    {MEMBER_TO_FPTR(Perl_magic_getuvar),
  2953.                 MEMBER_TO_FPTR(Perl_magic_setuvar),
  2954.                     0,    0,    0};
  2955. #ifdef USE_THREADS
  2956. EXT MGVTBL PL_vtbl_mutex =    {0,    0,    0,    0,    MEMBER_TO_FPTR(Perl_magic_mutexfree)};
  2957. #endif /* USE_THREADS */
  2958. EXT MGVTBL PL_vtbl_defelem = {MEMBER_TO_FPTR(Perl_magic_getdefelem),MEMBER_TO_FPTR(Perl_magic_setdefelem),
  2959.                     0,    0,    0};
  2960.  
  2961. EXT MGVTBL PL_vtbl_regexp = {0,0,0,0, MEMBER_TO_FPTR(Perl_magic_freeregexp)};
  2962. EXT MGVTBL PL_vtbl_regdata = {0, 0, MEMBER_TO_FPTR(Perl_magic_regdata_cnt), 0, 0};
  2963. EXT MGVTBL PL_vtbl_regdatum = {MEMBER_TO_FPTR(Perl_magic_regdatum_get),
  2964.                    MEMBER_TO_FPTR(Perl_magic_regdatum_set), 0, 0, 0};
  2965.  
  2966. #ifdef USE_LOCALE_COLLATE
  2967. EXT MGVTBL PL_vtbl_collxfrm = {0,
  2968.                 MEMBER_TO_FPTR(Perl_magic_setcollxfrm),
  2969.                     0,    0,    0};
  2970. #endif
  2971.  
  2972. EXT MGVTBL PL_vtbl_amagic =       {0,     MEMBER_TO_FPTR(Perl_magic_setamagic),
  2973.                                         0,      0,      MEMBER_TO_FPTR(Perl_magic_setamagic)};
  2974. EXT MGVTBL PL_vtbl_amagicelem =   {0,     MEMBER_TO_FPTR(Perl_magic_setamagic),
  2975.                                         0,      0,      MEMBER_TO_FPTR(Perl_magic_setamagic)};
  2976.  
  2977. EXT MGVTBL PL_vtbl_backref =       {0,    0,
  2978.                     0,    0,    MEMBER_TO_FPTR(Perl_magic_killbackrefs)};
  2979.  
  2980. #else /* !DOINIT */
  2981.  
  2982. EXT MGVTBL PL_vtbl_sv;
  2983. EXT MGVTBL PL_vtbl_env;
  2984. EXT MGVTBL PL_vtbl_envelem;
  2985. EXT MGVTBL PL_vtbl_sig;
  2986. EXT MGVTBL PL_vtbl_sigelem;
  2987. EXT MGVTBL PL_vtbl_pack;
  2988. EXT MGVTBL PL_vtbl_packelem;
  2989. EXT MGVTBL PL_vtbl_dbline;
  2990. EXT MGVTBL PL_vtbl_isa;
  2991. EXT MGVTBL PL_vtbl_isaelem;
  2992. EXT MGVTBL PL_vtbl_arylen;
  2993. EXT MGVTBL PL_vtbl_glob;
  2994. EXT MGVTBL PL_vtbl_mglob;
  2995. EXT MGVTBL PL_vtbl_nkeys;
  2996. EXT MGVTBL PL_vtbl_taint;
  2997. EXT MGVTBL PL_vtbl_substr;
  2998. EXT MGVTBL PL_vtbl_vec;
  2999. EXT MGVTBL PL_vtbl_pos;
  3000. EXT MGVTBL PL_vtbl_bm;
  3001. EXT MGVTBL PL_vtbl_fm;
  3002. EXT MGVTBL PL_vtbl_uvar;
  3003.  
  3004. #ifdef USE_THREADS
  3005. EXT MGVTBL PL_vtbl_mutex;
  3006. #endif /* USE_THREADS */
  3007.  
  3008. EXT MGVTBL PL_vtbl_defelem;
  3009. EXT MGVTBL PL_vtbl_regexp;
  3010. EXT MGVTBL PL_vtbl_regdata;
  3011. EXT MGVTBL PL_vtbl_regdatum;
  3012.  
  3013. #ifdef USE_LOCALE_COLLATE
  3014. EXT MGVTBL PL_vtbl_collxfrm;
  3015. #endif
  3016.  
  3017. EXT MGVTBL PL_vtbl_amagic;
  3018. EXT MGVTBL PL_vtbl_amagicelem;
  3019.  
  3020. EXT MGVTBL PL_vtbl_backref;
  3021.  
  3022. #endif /* !DOINIT */
  3023.  
  3024. enum {
  3025.   fallback_amg,        abs_amg,
  3026.   bool__amg,   nomethod_amg,
  3027.   string_amg,  numer_amg,
  3028.   add_amg,     add_ass_amg,
  3029.   subtr_amg,   subtr_ass_amg,
  3030.   mult_amg,    mult_ass_amg,
  3031.   div_amg,     div_ass_amg,
  3032.   modulo_amg,  modulo_ass_amg,
  3033.   pow_amg,     pow_ass_amg,
  3034.   lshift_amg,  lshift_ass_amg,
  3035.   rshift_amg,  rshift_ass_amg,
  3036.   band_amg,    band_ass_amg,
  3037.   bor_amg,     bor_ass_amg,
  3038.   bxor_amg,    bxor_ass_amg,
  3039.   lt_amg,      le_amg,
  3040.   gt_amg,      ge_amg,
  3041.   eq_amg,      ne_amg,
  3042.   ncmp_amg,    scmp_amg,
  3043.   slt_amg,     sle_amg,
  3044.   sgt_amg,     sge_amg,
  3045.   seq_amg,     sne_amg,
  3046.   not_amg,     compl_amg,
  3047.   inc_amg,     dec_amg,
  3048.   atan2_amg,   cos_amg,
  3049.   sin_amg,     exp_amg,
  3050.   log_amg,     sqrt_amg,
  3051.   repeat_amg,   repeat_ass_amg,
  3052.   concat_amg,  concat_ass_amg,
  3053.   copy_amg,    neg_amg,
  3054.   to_sv_amg,   to_av_amg,
  3055.   to_hv_amg,   to_gv_amg,
  3056.   to_cv_amg,   iter_amg,    
  3057.   max_amg_code
  3058.   /* Do not leave a trailing comma here.  C9X allows it, C89 doesn't. */
  3059. };
  3060.  
  3061. #define NofAMmeth max_amg_code
  3062.  
  3063. #ifdef DOINIT
  3064. EXTCONST char * PL_AMG_names[NofAMmeth] = {
  3065.   "fallback",    "abs",            /* "fallback" should be the first. */
  3066.   "bool",    "nomethod",
  3067.   "\"\"",    "0+",
  3068.   "+",        "+=",
  3069.   "-",        "-=",
  3070.   "*",        "*=",
  3071.   "/",        "/=",
  3072.   "%",        "%=",
  3073.   "**",        "**=",
  3074.   "<<",        "<<=",
  3075.   ">>",        ">>=",
  3076.   "&",        "&=",
  3077.   "|",        "|=",
  3078.   "^",        "^=",
  3079.   "<",        "<=",
  3080.   ">",        ">=",
  3081.   "==",        "!=",
  3082.   "<=>",    "cmp",
  3083.   "lt",        "le",
  3084.   "gt",        "ge",
  3085.   "eq",        "ne",
  3086.   "!",        "~",
  3087.   "++",        "--",
  3088.   "atan2",    "cos",
  3089.   "sin",    "exp",
  3090.   "log",    "sqrt",
  3091.   "x",        "x=",
  3092.   ".",        ".=",
  3093.   "=",        "neg",
  3094.   "${}",    "@{}",
  3095.   "%{}",    "*{}",
  3096.   "&{}",    "<>",
  3097. };
  3098. #else
  3099. EXTCONST char * PL_AMG_names[NofAMmeth];
  3100. #endif /* def INITAMAGIC */
  3101.  
  3102. END_EXTERN_C
  3103.  
  3104. struct am_table {
  3105.   long was_ok_sub;
  3106.   long was_ok_am;
  3107.   U32 flags;
  3108.   CV* table[NofAMmeth];
  3109.   long fallback;
  3110. };
  3111. struct am_table_short {
  3112.   long was_ok_sub;
  3113.   long was_ok_am;
  3114.   U32 flags;
  3115. };
  3116. typedef struct am_table AMT;
  3117. typedef struct am_table_short AMTS;
  3118.  
  3119. #define AMGfallNEVER    1
  3120. #define AMGfallNO    2
  3121. #define AMGfallYES    3
  3122.  
  3123. #define AMTf_AMAGIC        1
  3124. #define AMT_AMAGIC(amt)        ((amt)->flags & AMTf_AMAGIC)
  3125. #define AMT_AMAGIC_on(amt)    ((amt)->flags |= AMTf_AMAGIC)
  3126. #define AMT_AMAGIC_off(amt)    ((amt)->flags &= ~AMTf_AMAGIC)
  3127.  
  3128.  
  3129. /*
  3130.  * some compilers like to redefine cos et alia as faster
  3131.  * (and less accurate?) versions called F_cos et cetera (Quidquid
  3132.  * latine dictum sit, altum viditur.)  This trick collides with
  3133.  * the Perl overloading (amg).  The following #defines fool both.
  3134.  */
  3135.  
  3136. #ifdef _FASTMATH
  3137. #   ifdef atan2
  3138. #       define F_atan2_amg  atan2_amg
  3139. #   endif
  3140. #   ifdef cos
  3141. #       define F_cos_amg    cos_amg
  3142. #   endif
  3143. #   ifdef exp
  3144. #       define F_exp_amg    exp_amg
  3145. #   endif
  3146. #   ifdef log
  3147. #       define F_log_amg    log_amg
  3148. #   endif
  3149. #   ifdef pow
  3150. #       define F_pow_amg    pow_amg
  3151. #   endif
  3152. #   ifdef sin
  3153. #       define F_sin_amg    sin_amg
  3154. #   endif
  3155. #   ifdef sqrt
  3156. #       define F_sqrt_amg   sqrt_amg
  3157. #   endif
  3158. #endif /* _FASTMATH */
  3159.  
  3160. #define PERLDB_ALL        (PERLDBf_SUB    | PERLDBf_LINE    |    \
  3161.                  PERLDBf_NOOPT    | PERLDBf_INTER    |    \
  3162.                  PERLDBf_SUBLINE| PERLDBf_SINGLE|    \
  3163.                  PERLDBf_NAMEEVAL| PERLDBf_NAMEANON)
  3164.                     /* No _NONAME, _GOTO */
  3165. #define PERLDBf_SUB        0x01    /* Debug sub enter/exit */
  3166. #define PERLDBf_LINE        0x02    /* Keep line # */
  3167. #define PERLDBf_NOOPT        0x04    /* Switch off optimizations */
  3168. #define PERLDBf_INTER        0x08    /* Preserve more data for
  3169.                        later inspections  */
  3170. #define PERLDBf_SUBLINE        0x10    /* Keep subr source lines */
  3171. #define PERLDBf_SINGLE        0x20    /* Start with single-step on */
  3172. #define PERLDBf_NONAME        0x40    /* For _SUB: no name of the subr */
  3173. #define PERLDBf_GOTO        0x80    /* Report goto: call DB::goto */
  3174. #define PERLDBf_NAMEEVAL    0x100    /* Informative names for evals */
  3175. #define PERLDBf_NAMEANON    0x200    /* Informative names for anon subs */
  3176.  
  3177. #define PERLDB_SUB    (PL_perldb && (PL_perldb & PERLDBf_SUB))
  3178. #define PERLDB_LINE    (PL_perldb && (PL_perldb & PERLDBf_LINE))
  3179. #define PERLDB_NOOPT    (PL_perldb && (PL_perldb & PERLDBf_NOOPT))
  3180. #define PERLDB_INTER    (PL_perldb && (PL_perldb & PERLDBf_INTER))
  3181. #define PERLDB_SUBLINE    (PL_perldb && (PL_perldb & PERLDBf_SUBLINE))
  3182. #define PERLDB_SINGLE    (PL_perldb && (PL_perldb & PERLDBf_SINGLE))
  3183. #define PERLDB_SUB_NN    (PL_perldb && (PL_perldb & (PERLDBf_NONAME)))
  3184. #define PERLDB_GOTO    (PL_perldb && (PL_perldb & PERLDBf_GOTO))
  3185. #define PERLDB_NAMEEVAL    (PL_perldb && (PL_perldb & PERLDBf_NAMEEVAL))
  3186. #define PERLDB_NAMEANON    (PL_perldb && (PL_perldb & PERLDBf_NAMEANON))
  3187.  
  3188.  
  3189. #ifdef USE_LOCALE_NUMERIC
  3190.  
  3191. #define SET_NUMERIC_STANDARD() \
  3192.     set_numeric_standard();
  3193.  
  3194. #define SET_NUMERIC_LOCAL() \
  3195.     set_numeric_local();
  3196.  
  3197. #define IN_LOCALE_RUNTIME    (PL_curcop->op_private & HINT_LOCALE)
  3198. #define IN_LOCALE_COMPILETIME    (PL_hints & HINT_LOCALE)
  3199.  
  3200. #define IN_LOCALE \
  3201.     (PL_curcop == &PL_compiling ? IN_LOCALE_COMPILETIME : IN_LOCALE_RUNTIME)
  3202.  
  3203. #define IS_NUMERIC_RADIX(s, send)    \
  3204.     (PL_numeric_radix_sv \
  3205.      && IN_LOCALE \
  3206.      && SvCUR(PL_numeric_radix_sv) <= (STRLEN)((send)-(s)) \
  3207.      && memEQ(s, SvPVX(PL_numeric_radix_sv), SvCUR(PL_numeric_radix_sv)))
  3208.  
  3209. #define STORE_NUMERIC_LOCAL_SET_STANDARD() \
  3210.     bool was_local = PL_numeric_local && IN_LOCALE; \
  3211.     if (was_local) SET_NUMERIC_STANDARD();
  3212.  
  3213. #define STORE_NUMERIC_STANDARD_SET_LOCAL() \
  3214.     bool was_standard = PL_numeric_standard && IN_LOCALE; \
  3215.     if (was_standard) SET_NUMERIC_LOCAL();
  3216.  
  3217. #define RESTORE_NUMERIC_LOCAL() \
  3218.     if (was_local) SET_NUMERIC_LOCAL();
  3219.  
  3220. #define RESTORE_NUMERIC_STANDARD() \
  3221.     if (was_standard) SET_NUMERIC_STANDARD();
  3222.  
  3223. #define Atof                my_atof
  3224.  
  3225. #else /* !USE_LOCALE_NUMERIC */
  3226.  
  3227. #define SET_NUMERIC_STANDARD()      /**/
  3228. #define SET_NUMERIC_LOCAL()         /**/
  3229. #define IS_NUMERIC_RADIX(a, b)        (0)
  3230. #define STORE_NUMERIC_LOCAL_SET_STANDARD()    /**/
  3231. #define STORE_NUMERIC_STANDARD_SET_LOCAL()    /**/
  3232. #define RESTORE_NUMERIC_LOCAL()        /**/
  3233. #define RESTORE_NUMERIC_STANDARD()    /**/
  3234. #define Atof                Perl_atof
  3235.  
  3236. #endif /* !USE_LOCALE_NUMERIC */
  3237.  
  3238. #if !defined(Strtol) && defined(USE_64_BIT_INT) && defined(IV_IS_QUAD) && QUADKIND == QUAD_IS_LONG_LONG
  3239. #    ifdef __hpux
  3240. #        define strtoll __strtoll    /* secret handshake */
  3241. #    endif
  3242. #   if !defined(Strtol) && defined(HAS_STRTOLL)
  3243. #       define Strtol    strtoll
  3244. #   endif
  3245. /* is there atoq() anywhere? */
  3246. #endif
  3247. #if !defined(Strtol) && defined(HAS_STRTOL)
  3248. #   define Strtol    strtol
  3249. #endif
  3250. #ifndef Atol
  3251. /* It would be more fashionable to use Strtol() to define atol()
  3252.  * (as is done for Atoul(), see below) but for backward compatibility
  3253.  * we just assume atol(). */
  3254. #   if defined(USE_64_BIT_INT) && defined(IV_IS_QUAD) && QUADKIND == QUAD_IS_LONG_LONG && defined(HAS_ATOLL)
  3255. #       define Atol    atoll
  3256. #   else
  3257. #       define Atol    atol
  3258. #   endif
  3259. #endif
  3260.  
  3261. #if !defined(Strtoul) && defined(USE_64_BIT_INT) && defined(UV_IS_QUAD) && QUADKIND == QUAD_IS_LONG_LONG
  3262. #    ifdef __hpux
  3263. #        define strtoull __strtoull    /* secret handshake */
  3264. #    endif
  3265. #    if !defined(Strtoul) && defined(HAS_STRTOULL)
  3266. #       define Strtoul    strtoull
  3267. #    endif
  3268. #    if !defined(Strtoul) && defined(HAS_STRTOUQ)
  3269. #       define Strtoul    strtouq
  3270. #    endif
  3271. /* is there atouq() anywhere? */
  3272. #endif
  3273. #if !defined(Strtoul) && defined(HAS_STRTOUL)
  3274. #   define Strtoul    strtoul
  3275. #endif
  3276. #ifndef Atoul
  3277. #   define Atoul(s)    Strtoul(s, (char **)NULL, 10)
  3278. #endif
  3279.  
  3280. #if !defined(PERLIO_IS_STDIO) && defined(HASATTRIBUTE)
  3281. /* 
  3282.  * Now we have __attribute__ out of the way 
  3283.  * Remap printf 
  3284.  */
  3285. #undef printf
  3286. #define printf PerlIO_stdoutf
  3287. #endif
  3288.  
  3289. /* if these never got defined, they need defaults */
  3290. #ifndef PERL_SET_CONTEXT
  3291. #  define PERL_SET_CONTEXT(i)        PERL_SET_INTERP(i)
  3292. #endif
  3293.  
  3294. #ifndef PERL_GET_CONTEXT
  3295. #  define PERL_GET_CONTEXT        PERL_GET_INTERP
  3296. #endif
  3297.  
  3298. #ifndef PERL_GET_THX
  3299. #  define PERL_GET_THX            ((void*)NULL)
  3300. #endif
  3301.  
  3302. #ifndef PERL_SET_THX
  3303. #  define PERL_SET_THX(t)        NOOP
  3304. #endif
  3305.  
  3306. #ifndef PERL_SCRIPT_MODE
  3307. #define PERL_SCRIPT_MODE "r"
  3308. #endif
  3309.  
  3310. /*
  3311.  * Some operating systems are stingy with stack allocation,
  3312.  * so perl may have to guard against stack overflow.
  3313.  */
  3314. #ifndef PERL_STACK_OVERFLOW_CHECK
  3315. #define PERL_STACK_OVERFLOW_CHECK()  NOOP
  3316. #endif
  3317.  
  3318. /*
  3319.  * Some nonpreemptive operating systems find it convenient to
  3320.  * check for asynchronous conditions after each op execution.
  3321.  * Keep this check simple, or it may slow down execution
  3322.  * massively.
  3323.  */
  3324. #ifndef PERL_ASYNC_CHECK
  3325. #define PERL_ASYNC_CHECK()  NOOP
  3326. #endif
  3327.  
  3328. /*
  3329.  * On some operating systems, a memory allocation may succeed,
  3330.  * but put the process too close to the system's comfort limit.
  3331.  * In this case, PERL_ALLOC_CHECK frees the pointer and sets
  3332.  * it to NULL.
  3333.  */
  3334. #ifndef PERL_ALLOC_CHECK
  3335. #define PERL_ALLOC_CHECK(p)  NOOP
  3336. #endif
  3337.  
  3338. /*
  3339.  * nice_chunk and nice_chunk size need to be set
  3340.  * and queried under the protection of sv_mutex
  3341.  */
  3342. #define offer_nice_chunk(chunk, chunk_size) do {    \
  3343.     LOCK_SV_MUTEX;                    \
  3344.     if (!PL_nice_chunk) {                \
  3345.         PL_nice_chunk = (char*)(chunk);        \
  3346.         PL_nice_chunk_size = (chunk_size);        \
  3347.     }                        \
  3348.     else {                        \
  3349.         Safefree(chunk);                \
  3350.     }                        \
  3351.     UNLOCK_SV_MUTEX;                \
  3352.     } while (0)
  3353.  
  3354. #ifdef HAS_SEM
  3355. #   include <sys/ipc.h>
  3356. #   include <sys/sem.h>
  3357. #   ifndef HAS_UNION_SEMUN    /* Provide the union semun. */
  3358.     union semun {
  3359.     int        val;
  3360.     struct semid_ds    *buf;
  3361.     unsigned short    *array;
  3362.     };
  3363. #   endif
  3364. #   ifdef USE_SEMCTL_SEMUN
  3365. #    ifdef IRIX32_SEMUN_BROKEN_BY_GCC
  3366.             union gccbug_semun {
  3367.         int             val;
  3368.         struct semid_ds *buf;
  3369.         unsigned short  *array;
  3370.         char            __dummy[5];
  3371.         };
  3372. #           define semun gccbug_semun
  3373. #    endif
  3374. #       define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun)
  3375. #   else
  3376. #       ifdef USE_SEMCTL_SEMID_DS
  3377. #           ifdef EXTRA_F_IN_SEMUN_BUF
  3378. #               define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun.buff)
  3379. #           else
  3380. #               define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun.buf)
  3381. #           endif
  3382. #       endif
  3383. #   endif
  3384. #endif
  3385.  
  3386. /*
  3387.  * Boilerplate macros for initializing and accessing interpreter-local
  3388.  * data from C.  All statics in extensions should be reworked to use
  3389.  * this, if you want to make the extension thread-safe.  See ext/re/re.xs
  3390.  * for an example of the use of these macros.
  3391.  *
  3392.  * Code that uses these macros is responsible for the following:
  3393.  * 1. #define MY_CXT_KEY to a unique string, e.g. "DynaLoader_guts"
  3394.  * 2. Declare a typedef named my_cxt_t that is a structure that contains
  3395.  *    all the data that needs to be interpreter-local.
  3396.  * 3. Use the START_MY_CXT macro after the declaration of my_cxt_t.
  3397.  * 4. Use the MY_CXT_INIT macro such that it is called exactly once
  3398.  *    (typically put in the BOOT: section).
  3399.  * 5. Use the members of the my_cxt_t structure everywhere as
  3400.  *    MY_CXT.member.
  3401.  * 6. Use the dMY_CXT macro (a declaration) in all the functions that
  3402.  *    access MY_CXT.
  3403.  */
  3404.  
  3405. #if defined(PERL_IMPLICIT_CONTEXT)
  3406.  
  3407. /* This must appear in all extensions that define a my_cxt_t structure,
  3408.  * right after the definition (i.e. at file scope).  The non-threads
  3409.  * case below uses it to declare the data as static. */
  3410. #define START_MY_CXT
  3411.  
  3412. /* Fetches the SV that keeps the per-interpreter data. */
  3413. #define dMY_CXT_SV \
  3414.     SV *my_cxt_sv = *hv_fetch(PL_modglobal, MY_CXT_KEY,        \
  3415.                   sizeof(MY_CXT_KEY)-1, TRUE)
  3416.  
  3417. /* This declaration should be used within all functions that use the
  3418.  * interpreter-local data. */
  3419. #define dMY_CXT    \
  3420.     dMY_CXT_SV;                            \
  3421.     my_cxt_t *my_cxtp = INT2PTR(my_cxt_t*,SvUV(my_cxt_sv))
  3422.  
  3423. /* Creates and zeroes the per-interpreter data.
  3424.  * (We allocate my_cxtp in a Perl SV so that it will be released when
  3425.  * the interpreter goes away.) */
  3426. #define MY_CXT_INIT \
  3427.     dMY_CXT_SV;                            \
  3428.     /* newSV() allocates one more than needed */            \
  3429.     my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\
  3430.     Zero(my_cxtp, 1, my_cxt_t);                    \
  3431.     sv_setuv(my_cxt_sv, PTR2UV(my_cxtp))
  3432.  
  3433. /* This macro must be used to access members of the my_cxt_t structure.
  3434.  * e.g. MYCXT.some_data */
  3435. #define MY_CXT        (*my_cxtp)
  3436.  
  3437. /* Judicious use of these macros can reduce the number of times dMY_CXT
  3438.  * is used.  Use is similar to pTHX, aTHX etc. */
  3439. #define pMY_CXT        my_cxt_t *my_cxtp
  3440. #define pMY_CXT_    pMY_CXT,
  3441. #define _pMY_CXT    ,pMY_CXT
  3442. #define aMY_CXT        my_cxtp
  3443. #define aMY_CXT_    aMY_CXT,
  3444. #define _aMY_CXT    ,aMY_CXT
  3445.  
  3446. #else /* USE_ITHREADS */
  3447.  
  3448. #define START_MY_CXT    static my_cxt_t my_cxt;
  3449. #define dMY_CXT_SV    dNOOP
  3450. #define dMY_CXT        dNOOP
  3451. #define MY_CXT_INIT    NOOP
  3452. #define MY_CXT        my_cxt
  3453.  
  3454. #define pMY_CXT        void
  3455. #define pMY_CXT_
  3456. #define _pMY_CXT
  3457. #define aMY_CXT
  3458. #define aMY_CXT_
  3459. #define _aMY_CXT
  3460.  
  3461. #endif /* !defined(USE_ITHREADS) */
  3462.  
  3463. #ifdef I_FCNTL
  3464. #  include <fcntl.h>
  3465. #endif
  3466.  
  3467. #ifdef I_SYS_FILE
  3468. #  include <sys/file.h>
  3469. #endif
  3470.  
  3471. #ifndef O_RDONLY
  3472. /* Assume UNIX defaults */
  3473. #    define O_RDONLY    0000
  3474. #    define O_WRONLY    0001
  3475. #    define O_RDWR    0002
  3476. #    define O_CREAT    0100
  3477. #endif
  3478.  
  3479. #ifndef O_BINARY
  3480. #  define O_BINARY 0
  3481. #endif
  3482.  
  3483. #ifndef O_TEXT
  3484. #  define O_TEXT 0
  3485. #endif
  3486.  
  3487. #ifdef IAMSUID
  3488.  
  3489. #ifdef I_SYS_STATVFS
  3490. #   include <sys/statvfs.h>     /* for f?statvfs() */
  3491. #endif
  3492. #ifdef I_SYS_MOUNT
  3493. #   include <sys/mount.h>       /* for *BSD f?statfs() */
  3494. #endif
  3495. #ifdef I_MNTENT
  3496. #   include <mntent.h>          /* for getmntent() */
  3497. #endif
  3498. #ifdef I_SYS_STATFS
  3499. #   include <sys/statfs.h>      /* for some statfs() */
  3500. #endif
  3501. #ifdef I_SYS_VFS
  3502. #  ifdef __sgi
  3503. #    define sv IRIX_sv        /* kludge: IRIX has an sv of its own */
  3504. #  endif
  3505. #    include <sys/vfs.h>    /* for some statfs() */
  3506. #  ifdef __sgi
  3507. #    undef IRIX_sv
  3508. #  endif
  3509. #endif
  3510. #ifdef I_USTAT
  3511. #   include <ustat.h>           /* for ustat() */
  3512. #endif
  3513.  
  3514. #if !defined(PERL_MOUNT_NOSUID) && defined(MOUNT_NOSUID)
  3515. #    define PERL_MOUNT_NOSUID MOUNT_NOSUID
  3516. #endif
  3517. #if !defined(PERL_MOUNT_NOSUID) && defined(MNT_NOSUID)
  3518. #    define PERL_MOUNT_NOSUID MNT_NOSUID
  3519. #endif
  3520. #if !defined(PERL_MOUNT_NOSUID) && defined(MS_NOSUID)
  3521. #   define PERL_MOUNT_NOSUID MS_NOSUID
  3522. #endif
  3523. #if !defined(PERL_MOUNT_NOSUID) && defined(M_NOSUID)
  3524. #   define PERL_MOUNT_NOSUID M_NOSUID
  3525. #endif
  3526.  
  3527. #endif /* IAMSUID */
  3528.  
  3529. #ifdef I_LIBUTIL
  3530. #   include <libutil.h>        /* setproctitle() in some FreeBSDs */
  3531. #endif
  3532.  
  3533. #ifndef EXEC_ARGV_CAST
  3534. #define EXEC_ARGV_CAST(x) x
  3535. #endif
  3536.  
  3537. /* and finally... */
  3538. #define PERL_PATCHLEVEL_H_IMPLICIT
  3539. #include "patchlevel.h"
  3540. #undef PERL_PATCHLEVEL_H_IMPLICIT
  3541.  
  3542. /* Mention
  3543.    
  3544.    NV_PRESERVES_UV
  3545.  
  3546.    HAS_ICONV
  3547.    I_ICONV
  3548.  
  3549.    HAS_MKSTEMP
  3550.    HAS_MKSTEMPS
  3551.    HAS_MKDTEMP
  3552.  
  3553.    HAS_GETCWD
  3554.  
  3555.    HAS_MMAP
  3556.    HAS_MPROTECT
  3557.    HAS_MSYNC
  3558.    HAS_MADVISE
  3559.    HAS_MUNMAP
  3560.    I_SYSMMAN
  3561.    Mmap_t
  3562.  
  3563.    NVef
  3564.    NVff
  3565.    NVgf
  3566.  
  3567.    so that Configure picks them up. */
  3568.  
  3569. #endif /* Include guard */
  3570.