This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
It's a good job that Steve Hay is paying attention.
[perl5.git] / perl.h
diff --git a/perl.h b/perl.h
index f87bb5c..9cb8000 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -1,7 +1,7 @@
 /*    perl.h
  *
  *    Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- *    2000, 2001, 2002, 2003, by Larry Wall and others
+ *    2000, 2001, 2002, 2003, 2004, 2005 by Larry Wall and others
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
 #   include "config.h"
 #endif
 
+#if defined(USE_ITHREADS) && defined(USE_5005THREADS)
+#  include "error: USE_ITHREADS and USE_5005THREADS are incompatible"
+#endif
+
 /* See L<perlguts/"The Perl API"> for detailed notes on
  * PERL_IMPLICIT_CONTEXT and PERL_IMPLICIT_SYS */
 
 #  endif
 #endif
 
+#ifdef USE_5005THREADS
+#  ifndef PERL_IMPLICIT_CONTEXT
+#    define PERL_IMPLICIT_CONTEXT
+#  endif
+#endif
+
 #if defined(MULTIPLICITY)
 #  ifndef PERL_IMPLICIT_CONTEXT
 #    define PERL_IMPLICIT_CONTEXT
 #endif
 
 #ifdef PERL_IMPLICIT_CONTEXT
-#  ifndef MULTIPLICITY
-#    define MULTIPLICITY
+#  ifdef USE_5005THREADS
+struct perl_thread;
+#    define pTHX       register struct perl_thread *thr PERL_UNUSED_DECL
+#    define aTHX       thr
+#    define dTHR       dNOOP /* only backward compatibility */
+#    define dTHXa(a)   pTHX = (struct perl_thread*)a
+#  else
+#    ifndef MULTIPLICITY
+#      define MULTIPLICITY
+#    endif
+#    define pTHX       register PerlInterpreter *my_perl PERL_UNUSED_DECL
+#    define aTHX       my_perl
+#    define dTHXa(a)   pTHX = (PerlInterpreter*)a
 #  endif
-#  define pTHX register PerlInterpreter *my_perl PERL_UNUSED_DECL
-#  define aTHX my_perl
-#  define dTHXa(a)     pTHX = (PerlInterpreter*)a
 #  define dTHX         pTHX = PERL_GET_THX
 #  define pTHX_                pTHX,
 #  define aTHX_                aTHX,
@@ -208,7 +226,9 @@ register struct op *Perl_op asm(stringify(OP_IN_REGISTER));
 #endif
 
 #if defined(__STRICT_ANSI__) && defined(PERL_GCC_PEDANTIC)
-#   define PERL_GCC_BRACE_GROUPS_FORBIDDEN
+#  if !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)
+#    define PERL_GCC_BRACE_GROUPS_FORBIDDEN
+#  endif
 #endif
 
 /*
@@ -352,7 +372,8 @@ register struct op *Perl_op asm(stringify(OP_IN_REGISTER));
 /* HP-UX 10.X CMA (Common Multithreaded Architecure) insists that
    pthread.h must be included before all other header files.
 */
-#if defined(USE_ITHREADS) && defined(PTHREAD_H_FIRST) && defined(I_PTHREAD)
+#if (defined(USE_5005THREADS) || defined(USE_ITHREADS)) \
+    && defined(PTHREAD_H_FIRST) && defined(I_PTHREAD)
 #  include <pthread.h>
 #endif
 
@@ -449,6 +470,241 @@ int usleep(unsigned int);
 #  define MYSWAP
 #endif
 
+#ifdef PERL_CORE
+
+/* macros for correct constant construction */
+# if INTSIZE >= 2
+#  define U16_CONST(x) ((U16)x##U)
+# else
+#  define U16_CONST(x) ((U16)x##UL)
+# endif
+
+# if INTSIZE >= 4
+#  define U32_CONST(x) ((U32)x##U)
+# else
+#  define U32_CONST(x) ((U32)x##UL)
+# endif
+
+# ifdef HAS_QUAD
+#  if INTSIZE >= 8
+#   define U64_CONST(x) ((U64)x##U)
+#  elif LONGSIZE >= 8
+#   define U64_CONST(x) ((U64)x##UL)
+#  elif QUADKIND == QUAD_IS_LONG_LONG
+#   define U64_CONST(x) ((U64)x##ULL)
+#  else /* best guess we can make */
+#   define U64_CONST(x) ((U64)x##UL)
+#  endif
+# endif
+
+/* byte-swapping functions for big-/little-endian conversion */
+# define _swab_16_(x) ((U16)( \
+         (((U16)(x) & U16_CONST(0x00ff)) << 8) | \
+         (((U16)(x) & U16_CONST(0xff00)) >> 8) ))
+
+# define _swab_32_(x) ((U32)( \
+         (((U32)(x) & U32_CONST(0x000000ff)) << 24) | \
+         (((U32)(x) & U32_CONST(0x0000ff00)) <<  8) | \
+         (((U32)(x) & U32_CONST(0x00ff0000)) >>  8) | \
+         (((U32)(x) & U32_CONST(0xff000000)) >> 24) ))
+
+# ifdef HAS_QUAD
+#  define _swab_64_(x) ((U64)( \
+          (((U64)(x) & U64_CONST(0x00000000000000ff)) << 56) | \
+          (((U64)(x) & U64_CONST(0x000000000000ff00)) << 40) | \
+          (((U64)(x) & U64_CONST(0x0000000000ff0000)) << 24) | \
+          (((U64)(x) & U64_CONST(0x00000000ff000000)) <<  8) | \
+          (((U64)(x) & U64_CONST(0x000000ff00000000)) >>  8) | \
+          (((U64)(x) & U64_CONST(0x0000ff0000000000)) >> 24) | \
+          (((U64)(x) & U64_CONST(0x00ff000000000000)) >> 40) | \
+          (((U64)(x) & U64_CONST(0xff00000000000000)) >> 56) ))
+# endif
+
+/*----------------------------------------------------------------------------*/
+# if BYTEORDER == 0x1234 || BYTEORDER == 0x12345678  /*     little-endian     */
+/*----------------------------------------------------------------------------*/
+#  define my_htole16(x)                (x)
+#  define my_letoh16(x)                (x)
+#  define my_htole32(x)                (x)
+#  define my_letoh32(x)                (x)
+#  define my_htobe16(x)                _swab_16_(x)
+#  define my_betoh16(x)                _swab_16_(x)
+#  define my_htobe32(x)                _swab_32_(x)
+#  define my_betoh32(x)                _swab_32_(x)
+#  ifdef HAS_QUAD
+#   define my_htole64(x)       (x)
+#   define my_letoh64(x)       (x)
+#   define my_htobe64(x)       _swab_64_(x)
+#   define my_betoh64(x)       _swab_64_(x)
+#  endif
+#  define my_htoles(x)         (x)
+#  define my_letohs(x)         (x)
+#  define my_htolei(x)         (x)
+#  define my_letohi(x)         (x)
+#  define my_htolel(x)         (x)
+#  define my_letohl(x)         (x)
+#  if SHORTSIZE == 1
+#   define my_htobes(x)                (x)
+#   define my_betohs(x)                (x)
+#  elif SHORTSIZE == 2
+#   define my_htobes(x)                _swab_16_(x)
+#   define my_betohs(x)                _swab_16_(x)
+#  elif SHORTSIZE == 4
+#   define my_htobes(x)                _swab_32_(x)
+#   define my_betohs(x)                _swab_32_(x)
+#  elif SHORTSIZE == 8
+#   define my_htobes(x)                _swab_64_(x)
+#   define my_betohs(x)                _swab_64_(x)
+#  else
+#   define PERL_NEED_MY_HTOBES
+#   define PERL_NEED_MY_BETOHS
+#  endif
+#  if INTSIZE == 1
+#   define my_htobei(x)                (x)
+#   define my_betohi(x)                (x)
+#  elif INTSIZE == 2
+#   define my_htobei(x)                _swab_16_(x)
+#   define my_betohi(x)                _swab_16_(x)
+#  elif INTSIZE == 4
+#   define my_htobei(x)                _swab_32_(x)
+#   define my_betohi(x)                _swab_32_(x)
+#  elif INTSIZE == 8
+#   define my_htobei(x)                _swab_64_(x)
+#   define my_betohi(x)                _swab_64_(x)
+#  else
+#   define PERL_NEED_MY_HTOBEI
+#   define PERL_NEED_MY_BETOHI
+#  endif
+#  if LONGSIZE == 1
+#   define my_htobel(x)                (x)
+#   define my_betohl(x)                (x)
+#  elif LONGSIZE == 2
+#   define my_htobel(x)                _swab_16_(x)
+#   define my_betohl(x)                _swab_16_(x)
+#  elif LONGSIZE == 4
+#   define my_htobel(x)                _swab_32_(x)
+#   define my_betohl(x)                _swab_32_(x)
+#  elif LONGSIZE == 8
+#   define my_htobel(x)                _swab_64_(x)
+#   define my_betohl(x)                _swab_64_(x)
+#  else
+#   define PERL_NEED_MY_HTOBEL
+#   define PERL_NEED_MY_BETOHL
+#  endif
+#  define my_htolen(p,n)       NOOP
+#  define my_letohn(p,n)       NOOP
+#  define my_htoben(p,n)       my_swabn(p,n)
+#  define my_betohn(p,n)       my_swabn(p,n)
+/*----------------------------------------------------------------------------*/
+# elif BYTEORDER == 0x4321 || BYTEORDER == 0x87654321  /*     big-endian      */
+/*----------------------------------------------------------------------------*/
+#  define my_htobe16(x)                (x)
+#  define my_betoh16(x)                (x)
+#  define my_htobe32(x)                (x)
+#  define my_betoh32(x)                (x)
+#  define my_htole16(x)                _swab_16_(x)
+#  define my_letoh16(x)                _swab_16_(x)
+#  define my_htole32(x)                _swab_32_(x)
+#  define my_letoh32(x)                _swab_32_(x)
+#  ifdef HAS_QUAD
+#   define my_htobe64(x)       (x)
+#   define my_betoh64(x)       (x)
+#   define my_htole64(x)       _swab_64_(x)
+#   define my_letoh64(x)       _swab_64_(x)
+#  endif
+#  define my_htobes(x)         (x)
+#  define my_betohs(x)         (x)
+#  define my_htobei(x)         (x)
+#  define my_betohi(x)         (x)
+#  define my_htobel(x)         (x)
+#  define my_betohl(x)         (x)
+#  if SHORTSIZE == 1
+#   define my_htoles(x)                (x)
+#   define my_letohs(x)                (x)
+#  elif SHORTSIZE == 2
+#   define my_htoles(x)                _swab_16_(x)
+#   define my_letohs(x)                _swab_16_(x)
+#  elif SHORTSIZE == 4
+#   define my_htoles(x)                _swab_32_(x)
+#   define my_letohs(x)                _swab_32_(x)
+#  elif SHORTSIZE == 8
+#   define my_htoles(x)                _swab_64_(x)
+#   define my_letohs(x)                _swab_64_(x)
+#  else
+#   define PERL_NEED_MY_HTOLES
+#   define PERL_NEED_MY_LETOHS
+#  endif
+#  if INTSIZE == 1
+#   define my_htolei(x)                (x)
+#   define my_letohi(x)                (x)
+#  elif INTSIZE == 2
+#   define my_htolei(x)                _swab_16_(x)
+#   define my_letohi(x)                _swab_16_(x)
+#  elif INTSIZE == 4
+#   define my_htolei(x)                _swab_32_(x)
+#   define my_letohi(x)                _swab_32_(x)
+#  elif INTSIZE == 8
+#   define my_htolei(x)                _swab_64_(x)
+#   define my_letohi(x)                _swab_64_(x)
+#  else
+#   define PERL_NEED_MY_HTOLEI
+#   define PERL_NEED_MY_LETOHI
+#  endif
+#  if LONGSIZE == 1
+#   define my_htolel(x)                (x)
+#   define my_letohl(x)                (x)
+#  elif LONGSIZE == 2
+#   define my_htolel(x)                _swab_16_(x)
+#   define my_letohl(x)                _swab_16_(x)
+#  elif LONGSIZE == 4
+#   define my_htolel(x)                _swab_32_(x)
+#   define my_letohl(x)                _swab_32_(x)
+#  elif LONGSIZE == 8
+#   define my_htolel(x)                _swab_64_(x)
+#   define my_letohl(x)                _swab_64_(x)
+#  else
+#   define PERL_NEED_MY_HTOLEL
+#   define PERL_NEED_MY_LETOHL
+#  endif
+#  define my_htolen(p,n)       my_swabn(p,n)
+#  define my_letohn(p,n)       my_swabn(p,n)
+#  define my_htoben(p,n)       NOOP
+#  define my_betohn(p,n)       NOOP
+/*----------------------------------------------------------------------------*/
+# else /*                       all other byte-orders                         */
+/*----------------------------------------------------------------------------*/
+#  define PERL_NEED_MY_HTOLE16
+#  define PERL_NEED_MY_LETOH16
+#  define PERL_NEED_MY_HTOBE16
+#  define PERL_NEED_MY_BETOH16
+#  define PERL_NEED_MY_HTOLE32
+#  define PERL_NEED_MY_LETOH32
+#  define PERL_NEED_MY_HTOBE32
+#  define PERL_NEED_MY_BETOH32
+#  ifdef HAS_QUAD
+#   define PERL_NEED_MY_HTOLE64
+#   define PERL_NEED_MY_LETOH64
+#   define PERL_NEED_MY_HTOBE64
+#   define PERL_NEED_MY_BETOH64
+#  endif
+#  define PERL_NEED_MY_HTOLES
+#  define PERL_NEED_MY_LETOHS
+#  define PERL_NEED_MY_HTOBES
+#  define PERL_NEED_MY_BETOHS
+#  define PERL_NEED_MY_HTOLEI
+#  define PERL_NEED_MY_LETOHI
+#  define PERL_NEED_MY_HTOBEI
+#  define PERL_NEED_MY_BETOHI
+#  define PERL_NEED_MY_HTOLEL
+#  define PERL_NEED_MY_LETOHL
+#  define PERL_NEED_MY_HTOBEL
+#  define PERL_NEED_MY_BETOHL
+/*----------------------------------------------------------------------------*/
+# endif /*                     end of byte-order macros                       */
+/*----------------------------------------------------------------------------*/
+
+#endif /* PERL_CORE */
+
 /* Cannot include embed.h here on Win32 as win32.h has not 
    yet been included and defines some config variables e.g. HAVE_INTERP_INTERN
  */
@@ -516,7 +772,7 @@ int usleep(unsigned int);
 #  define MALLOC_CHECK_TAINT(argc,argv,env)
 #endif /* MYMALLOC */
 
-#define TOO_LATE_FOR_(ch,s)    Perl_croak(aTHX_ "Too late for \"-%c\" option%s", (char)(ch), s)
+#define TOO_LATE_FOR_(ch,s)    Perl_croak(aTHX_ "\"-%c\" is on the #! line, it must also be used on the command line%s", (char)(ch), s)
 #define TOO_LATE_FOR(ch)       TOO_LATE_FOR_(ch, "")
 #define MALLOC_TOO_LATE_FOR(ch)        TOO_LATE_FOR_(ch, " with $ENV{PERL_MALLOC_OPT}")
 #define MALLOC_CHECK_TAINT2(argc,argv) MALLOC_CHECK_TAINT(argc,argv,NULL)
@@ -693,7 +949,18 @@ int usleep(unsigned int);
 #       define INCLUDE_PROTOTYPES /* for <socks.h> */
 #       define PERL_SOCKS_NEED_PROTOTYPES
 #   endif
+#   ifdef USE_5005THREADS
+#       define PERL_USE_THREADS /* store our value */
+#       undef USE_5005THREADS
+#   endif
 #   include <socks.h>
+#   ifdef USE_5005THREADS
+#       undef USE_5005THREADS /* socks.h does this on its own */
+#   endif
+#   ifdef PERL_USE_THREADS
+#       define USE_5005THREADS /* restore our value */
+#       undef PERL_USE_THREADS
+#   endif
 #   ifdef PERL_SOCKS_NEED_PROTOTYPES /* keep cpp space clean */
 #       undef INCLUDE_PROTOTYPES
 #       undef PERL_SOCKS_NEED_PROTOTYPES
@@ -761,9 +1028,15 @@ int sockatmark(int);
 #   define SS_NORMAL           0
 #endif
 
-#define ERRSV GvSV(PL_errgv)
-#define DEFSV GvSV(PL_defgv)
-#define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
+#ifdef USE_5005THREADS
+#  define ERRSV (thr->errsv)
+#  define DEFSV THREADSV(0)
+#  define SAVE_DEFSV save_threadsv(0)
+#else
+#  define ERRSV GvSV(PL_errgv)
+#  define DEFSV GvSV(PL_defgv)
+#  define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
+#endif /* USE_5005THREADS */
 
 #define ERRHV GvHV(PL_errgv)   /* XXX unused, here for compatibility */
 
@@ -1091,6 +1364,13 @@ typedef UVTYPE UV;
 #  endif
 #endif
 
+#ifndef HAS_QUAD
+# undef PERL_NEED_MY_HTOLE64
+# undef PERL_NEED_MY_LETOH64
+# undef PERL_NEED_MY_HTOBE64
+# undef PERL_NEED_MY_BETOH64
+#endif
+
 #if defined(uts) || defined(UTS)
 #      undef UV_MAX
 #      define UV_MAX (4294967295u)
@@ -1291,7 +1571,7 @@ typedef NVTYPE NV;
 /* eg glibc 2.2 series seems to provide modfl on ppc and arm, but has no
    prototype in <math.h> */
 #       ifndef HAS_MODFL_PROTO
-long double modfl(long double, long double *);
+EXTERN_C long double modfl(long double, long double *);
 #      endif
 #   else
 #       if defined(HAS_AINTL) && defined(HAS_COPYSIGNL)
@@ -1767,7 +2047,6 @@ typedef struct ptr_tbl_ent PTR_TBL_ENT_t;
 typedef struct ptr_tbl PTR_TBL_t;
 typedef struct clone_params CLONE_PARAMS;
 
-
 #include "handy.h"
 
 #if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_RAWIO)
@@ -1998,13 +2277,19 @@ typedef struct clone_params CLONE_PARAMS;
 #  endif
 #endif
 
-/* USE_5005THREADS needs to be after unixish.h as <pthread.h> includes
+/*
+ * USE_5005THREADS needs to be after unixish.h as <pthread.h> includes
  * <sys/signal.h> which defines NSIG - which will stop inclusion of <signal.h>
  * this results in many functions being undeclared which bothers C++
  * May make sense to have threads after "*ish.h" anyway
  */
 
-#if defined(USE_ITHREADS)
+#if defined(USE_5005THREADS) || defined(USE_ITHREADS)
+#  if defined(USE_5005THREADS)
+   /* pending resolution of licensing issues, we avoid the erstwhile
+    * atomic.h everywhere */
+#  define EMULATE_ATOMIC_REFCOUNTS
+#  endif
 #  ifdef NETWARE
 #   include <nw5thread.h>
 #  else
@@ -2039,7 +2324,7 @@ typedef pthread_key_t     perl_key;
 #    endif /* WIN32 */
 #  endif /* FAKE_THREADS */
 #endif /* NETWARE */
-#endif /* USE_ITHREADS */
+#endif /* USE_5005THREADS || USE_ITHREADS */
 
 #if defined(WIN32)
 #  include "win32.h"
@@ -2143,48 +2428,57 @@ typedef pthread_key_t   perl_key;
 #endif
 
 #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_GET_THX)
+#  ifdef USE_5005THREADS
+#    define PERL_GET_THX               ((struct perl_thread *)PERL_GET_CONTEXT)
+#  else
 #  ifdef MULTIPLICITY
 #    define PERL_GET_THX               ((PerlInterpreter *)PERL_GET_CONTEXT)
 #  endif
+#  endif
 #  define PERL_SET_THX(t)              PERL_SET_CONTEXT(t)
 #endif
 
 #ifndef SVf
 #  ifdef CHECK_FORMAT
-#    define SVf "p"
-#    ifndef SVf256
-#      define SVf256 SVf
-#    endif
+#    define SVf "-p"
 #  else
 #    define SVf "_"
 #  endif
 #endif
 
-#ifndef SVf256
-#  define SVf256 ".256"SVf
-#endif
-
-#ifndef UVf
+#ifndef SVf_precision
 #  ifdef CHECK_FORMAT
-#    define UVf UVuf
+#    define SVf_precision(n) "-" n "p"
 #  else
-#    define UVf "Vu"
+#    define SVf_precision(n) "." n "_"
 #  endif
 #endif
 
 #ifndef VDf
 #  ifdef CHECK_FORMAT
-#    define VDf "p"
+#    define VDf "-1p"
 #  else
 #    define VDf "vd"
 #  endif
 #endif
 
-#ifndef Nullformat
+#ifndef SVf32
+#  define SVf32 SVf_precision("32")
+#endif
+
+#ifndef SVf256
+#  define SVf256 SVf_precision("256")
+#endif
+#ifndef UVf
+#  define UVf UVuf
+#endif
+
+#ifndef DieNull
 #  ifdef CHECK_FORMAT
-#    define Nullformat "%s",""
+#    define DieNull Perl_vdie(aTHX_ Nullch, Null(va_list *))
 #  else
-#    define Nullformat Nullch
+#    define DieNull Perl_die(aTHX_ Nullch)
 #  endif
 #endif
 
@@ -2247,6 +2541,12 @@ union any {
 };
 #endif
 
+#ifdef USE_5005THREADS
+#define ARGSproto struct perl_thread *thr
+#else
+#define ARGSproto
+#endif /* USE_5005THREADS */
+
 typedef I32 (*filter_t) (pTHX_ int, SV *, int);
 
 #define FILTER_READ(idx, sv, len)  filter_read(idx, sv, len)
@@ -2501,7 +2801,6 @@ Gid_t getegid (void);
 #define DEBUG_r_FLAG           0x00000200 /*    512 */
 #define DEBUG_x_FLAG           0x00000400 /*   1024 */
 #define DEBUG_u_FLAG           0x00000800 /*   2048 */
-                                          /*  spare */
 #define DEBUG_H_FLAG           0x00002000 /*   8192 */
 #define DEBUG_X_FLAG           0x00004000 /*  16384 */
 #define DEBUG_D_FLAG           0x00008000 /*  32768 */
@@ -2510,10 +2809,7 @@ Gid_t getegid (void);
 #define DEBUG_R_FLAG           0x00040000 /* 262144 */
 #define DEBUG_J_FLAG           0x00080000 /* 524288 */
 #define DEBUG_v_FLAG           0x00100000 /*1048576 */
-#define DEBUG_C_FLAG           0x00200000 /*2097152 */
-#define DEBUG_A_FLAG           0x00400000 /*4194304 */
-#define DEBUG_q_FLAG           0x00800000 /*8388608 */
-#define DEBUG_MASK             0x00FFEFFF /* mask of all the standard flags */
+#define DEBUG_MASK             0x001FEFFF /* mask of all the standard flags */
 
 #define DEBUG_DB_RECURSE_FLAG  0x40000000
 #define DEBUG_TOP_FLAG         0x80000000 /* XXX what's this for ??? Signal
@@ -2539,11 +2835,9 @@ Gid_t getegid (void);
 #  define DEBUG_R_TEST_ (PL_debug & DEBUG_R_FLAG)
 #  define DEBUG_J_TEST_ (PL_debug & DEBUG_J_FLAG)
 #  define DEBUG_v_TEST_ (PL_debug & DEBUG_v_FLAG)
-#  define DEBUG_C_TEST_ (PL_debug & DEBUG_C_FLAG)
-#  define DEBUG_A_TEST_ (PL_debug & DEBUG_A_FLAG)
-#  define DEBUG_q_TEST_ (PL_debug & DEBUG_q_FLAG)
 #  define DEBUG_Xv_TEST_ (DEBUG_X_TEST_ && DEBUG_v_TEST_)
 
+
 #ifdef DEBUGGING
 
 #  undef  YYDEBUG
@@ -2570,9 +2864,6 @@ Gid_t getegid (void);
 #  define DEBUG_R_TEST DEBUG_R_TEST_
 #  define DEBUG_J_TEST DEBUG_J_TEST_
 #  define DEBUG_v_TEST DEBUG_v_TEST_
-#  define DEBUG_C_TEST DEBUG_C_TEST_
-#  define DEBUG_A_TEST DEBUG_A_TEST_
-#  define DEBUG_q_TEST DEBUG_q_TEST_
 
 #  define PERL_DEB(a)                  a
 #  define PERL_DEBUG(a) if (PL_debug)  a
@@ -2605,14 +2896,15 @@ Gid_t getegid (void);
 #  define DEBUG_Xv(a) DEBUG__(DEBUG_Xv_TEST, a)
 #  define DEBUG_D(a) DEBUG__(DEBUG_D_TEST, a)
 
-#  define DEBUG_S(a)
+#  ifdef USE_5005THREADS
+#    define DEBUG_S(a) DEBUG__(DEBUG_S_TEST, a)
+#  else
+#    define DEBUG_S(a)
+#  endif
 
 #  define DEBUG_T(a) DEBUG__(DEBUG_T_TEST, a)
 #  define DEBUG_R(a) DEBUG__(DEBUG_R_TEST, a)
 #  define DEBUG_v(a) DEBUG__(DEBUG_v_TEST, a)
-#  define DEBUG_C(a) DEBUG__(DEBUG_C_TEST, a)
-#  define DEBUG_A(a) DEBUG__(DEBUG_A_TEST, a)
-#  define DEBUG_q(a) DEBUG__(DEBUG_q_TEST, a)
 
 #else /* DEBUGGING */
 
@@ -2637,9 +2929,6 @@ Gid_t getegid (void);
 #  define DEBUG_R_TEST (0)
 #  define DEBUG_J_TEST (0)
 #  define DEBUG_v_TEST (0)
-#  define DEBUG_C_TEST (0)
-#  define DEBUG_A_TEST (0)
-#  define DEBUG_q_TEST (0)
 
 #  define PERL_DEB(a)
 #  define PERL_DEBUG(a)
@@ -2663,9 +2952,6 @@ Gid_t getegid (void);
 #  define DEBUG_T(a)
 #  define DEBUG_R(a)
 #  define DEBUG_v(a)
-#  define DEBUG_C(a)
-#  define DEBUG_A(a)
-#  define DEBUG_q(a)
 #endif /* DEBUGGING */
 
 
@@ -2714,8 +3000,8 @@ Gid_t getegid (void);
 #define PERL_MAGIC_taint         't' /* Taintedness */
 #define PERL_MAGIC_uvar                  'U' /* Available for use by extensions */
 #define PERL_MAGIC_uvar_elem     'u' /* Reserved for use by extensions */
-#define PERL_MAGIC_vec           'v' /* vec() lvalue */
 #define PERL_MAGIC_vstring       'V' /* SV was vstring literal */
+#define PERL_MAGIC_vec           'v' /* vec() lvalue */
 #define PERL_MAGIC_utf8                  'w' /* Cached UTF-8 information */
 #define PERL_MAGIC_substr        'x' /* substr() lvalue */
 #define PERL_MAGIC_defelem       'y' /* Shadow "foreach" iterator variable /
@@ -3034,6 +3320,10 @@ EXTCONST char PL_no_myglob[]
   INIT("\"my\" variable %s can't be in a package");
 EXTCONST char PL_no_localize_ref[]
   INIT("Can't localize through a reference");
+#ifdef PERL_MALLOC_WRAP
+EXTCONST char PL_memory_wrap[]
+  INIT("panic: memory wrap");
+#endif
 
 EXTCONST char PL_uuemap[65]
   INIT("`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_");
@@ -3284,9 +3574,7 @@ typedef enum {
     XBLOCK,
     XATTRBLOCK,
     XATTRTERM,
-    XTERMBLOCK,
-    XTERMORDORDOR /* evil hack */
-    /* update exp_name[] in toke.c if adding to this enum */
+    XTERMBLOCK
 } expectation;
 
 enum {         /* pass one of these to get_vtbl */
@@ -3316,6 +3604,9 @@ enum {            /* pass one of these to get_vtbl */
     want_vtbl_collxfrm,
     want_vtbl_amagic,
     want_vtbl_amagicelem,
+#ifdef USE_5005THREADS
+    want_vtbl_mutex,
+#endif
     want_vtbl_regdata,
     want_vtbl_regdatum,
     want_vtbl_backref,
@@ -3351,10 +3642,6 @@ enum {           /* pass one of these to get_vtbl */
 #define HINT_FILETEST_ACCESS   0x00400000 /* filetest pragma */
 #define HINT_UTF8              0x00800000 /* utf8 pragma */
 
-/* assertions pragma */
-#define HINT_ASSERTING          0x01000000
-#define HINT_ASSERTIONSSEEN     0x02000000
-
 /* The following are stored in $sort::hints, not in PL_hints */
 #define HINT_SORT_SORT_BITS    0x000000FF /* allow 256 different ones */
 #define HINT_SORT_QUICKSORT    0x00000001
@@ -3437,7 +3724,9 @@ struct perl_vars *PL_VarsPtr;
 */
 
 struct interpreter {
-#  include "thrdvar.h"
+#  ifndef USE_5005THREADS
+#    include "thrdvar.h"
+#  endif
 #  include "intrpvar.h"
 /*
  * The following is a buffer where new variables must
@@ -3452,7 +3741,21 @@ struct interpreter {
 };
 #endif /* MULTIPLICITY */
 
+#ifdef USE_5005THREADS
+/* If we have threads define a struct with all the variables
+ * that have to be per-thread
+ */
+
+
+struct perl_thread {
+#include "thrdvar.h"
+};
+
+typedef struct perl_thread *Thread;
+
+#else
 typedef void *Thread;
+#endif
 
 /* Done with PERLVAR macros for now ... */
 #undef PERLVAR
@@ -3472,11 +3775,12 @@ typedef struct {
   char*    patend;   /* one after last char   */
   char*    grpbeg;   /* 1st char of ()-group  */
   char*    grpend;   /* end of ()-group       */
-  I32      code;     /* template code (!)     */
+  I32      code;     /* template code (!<>)   */
   I32      length;   /* length/repeat count   */
   howlen_t howlen;   /* how length is given   */ 
   int      level;    /* () nesting level      */
   U32      flags;    /* /=4, comma=2, pack=1  */
+                     /*   and group modifiers */
 } tempsym_t;
 
 #include "thread.h"
@@ -3524,7 +3828,9 @@ typedef struct {
 #if !defined(MULTIPLICITY)
 START_EXTERN_C
 #  include "intrpvar.h"
-#  include "thrdvar.h"
+#  ifndef USE_5005THREADS
+#    include "thrdvar.h"
+#  endif
 END_EXTERN_C
 #endif
 
@@ -3541,6 +3847,8 @@ START_EXTERN_C
 END_EXTERN_C
 #endif
 
+#include "reentr.inc"
+
 #undef PERLVAR
 #undef PERLVARA
 #undef PERLVARI
@@ -3614,6 +3922,10 @@ EXT MGVTBL PL_vtbl_fm =  {0,     MEMBER_TO_FPTR(Perl_magic_setfm),
 EXT MGVTBL PL_vtbl_uvar =      {MEMBER_TO_FPTR(Perl_magic_getuvar),
                                MEMBER_TO_FPTR(Perl_magic_setuvar),
                                        0,      0,      0};
+#ifdef USE_5005THREADS
+EXT MGVTBL PL_vtbl_mutex =     {0,     0,      0,      0,      
+                                       MEMBER_TO_FPTR(Perl_magic_mutexfree)};
+#endif /* USE_5005THREADS */
 EXT MGVTBL PL_vtbl_defelem = {MEMBER_TO_FPTR(Perl_magic_getdefelem),
                                        MEMBER_TO_FPTR(Perl_magic_setdefelem),
                                        0,      0,      0};
@@ -3669,6 +3981,10 @@ EXT MGVTBL PL_vtbl_fm;
 EXT MGVTBL PL_vtbl_uvar;
 EXT MGVTBL PL_vtbl_ovrld;
 
+#ifdef USE_5005THREADS
+EXT MGVTBL PL_vtbl_mutex;
+#endif /* USE_5005THREADS */
+
 EXT MGVTBL PL_vtbl_defelem;
 EXT MGVTBL PL_vtbl_regexp;
 EXT MGVTBL PL_vtbl_regdata;
@@ -3838,8 +4154,8 @@ typedef struct am_table_short AMTS;
 #define PERLDB_ALL             (PERLDBf_SUB    | PERLDBf_LINE  |       \
                                 PERLDBf_NOOPT  | PERLDBf_INTER |       \
                                 PERLDBf_SUBLINE| PERLDBf_SINGLE|       \
-                                PERLDBf_NAMEEVAL| PERLDBf_NAMEANON )
-                                       /* No _NONAME, _GOTO, _ASSERTION */
+                                PERLDBf_NAMEEVAL| PERLDBf_NAMEANON)
+                                       /* No _NONAME, _GOTO */
 #define PERLDBf_SUB            0x01    /* Debug sub enter/exit */
 #define PERLDBf_LINE           0x02    /* Keep line # */
 #define PERLDBf_NOOPT          0x04    /* Switch off optimizations */
@@ -3851,7 +4167,6 @@ typedef struct am_table_short AMTS;
 #define PERLDBf_GOTO           0x80    /* Report goto: call DB::goto */
 #define PERLDBf_NAMEEVAL       0x100   /* Informative names for evals */
 #define PERLDBf_NAMEANON       0x200   /* Informative names for anon subs */
-#define PERLDBf_ASSERTION       0x400   /* Debug assertion subs enter/exit */
 
 #define PERLDB_SUB     (PL_perldb && (PL_perldb & PERLDBf_SUB))
 #define PERLDB_LINE    (PL_perldb && (PL_perldb & PERLDBf_LINE))
@@ -3863,7 +4178,7 @@ typedef struct am_table_short AMTS;
 #define PERLDB_GOTO    (PL_perldb && (PL_perldb & PERLDBf_GOTO))
 #define PERLDB_NAMEEVAL        (PL_perldb && (PL_perldb & PERLDBf_NAMEEVAL))
 #define PERLDB_NAMEANON        (PL_perldb && (PL_perldb & PERLDBf_NAMEANON))
-#define PERLDB_ASSERTION (PL_perldb && (PL_perldb & PERLDBf_ASSERTION))
+
 
 #ifdef USE_LOCALE_NUMERIC
 
@@ -4123,6 +4438,13 @@ typedef struct am_table_short AMTS;
        Zero(my_cxtp, 1, my_cxt_t);                                     \
        sv_setuv(my_cxt_sv, PTR2UV(my_cxtp))
 
+/* Clones the per-interpreter data. */
+#define MY_CXT_CLONE \
+       dMY_CXT_SV;                                                     \
+       my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\
+       Copy(INT2PTR(my_cxt_t*, SvUV(my_cxt_sv)), my_cxtp, 1, my_cxt_t);\
+       sv_setuv(my_cxt_sv, PTR2UV(my_cxtp))
+
 /* This macro must be used to access members of the my_cxt_t structure.
  * e.g. MYCXT.some_data */
 #define MY_CXT         (*my_cxtp)
@@ -4142,6 +4464,7 @@ typedef struct am_table_short AMTS;
 #define dMY_CXT_SV     dNOOP
 #define dMY_CXT                dNOOP
 #define MY_CXT_INIT    NOOP
+#define MY_CXT_CLONE   NOOP
 #define MY_CXT         my_cxt
 
 #define pMY_CXT                void
@@ -4245,6 +4568,19 @@ int flock(int fd, int op);
 #   define PERL_MOUNT_NOSUID M_NOSUID
 #endif
 
+#if !defined(PERL_MOUNT_NOEXEC) && defined(MOUNT_NOEXEC)
+#    define PERL_MOUNT_NOEXEC MOUNT_NOEXEC
+#endif
+#if !defined(PERL_MOUNT_NOEXEC) && defined(MNT_NOEXEC)
+#    define PERL_MOUNT_NOEXEC MNT_NOEXEC
+#endif
+#if !defined(PERL_MOUNT_NOEXEC) && defined(MS_NOEXEC)
+#   define PERL_MOUNT_NOEXEC MS_NOEXEC
+#endif
+#if !defined(PERL_MOUNT_NOEXEC) && defined(M_NOEXEC)
+#   define PERL_MOUNT_NOEXEC M_NOEXEC
+#endif
+
 #endif /* IAMSUID */
 
 #ifdef I_LIBUTIL
@@ -4438,5 +4774,14 @@ extern void moncontrol(int);
 
    so that Configure picks them up. */
 
+/* Source code compatibility cruft:
+   PERL_XS_APIVERSION is not used, and has been superseded by inc_version_list
+   It and PERL_PM_APIVERSION are retained for source compatibility in the
+   5.8.x maintenance branch.
+ */
+
+#define PERL_XS_APIVERSION "5.8.3"
+#define PERL_PM_APIVERSION "5.005"
+
 #endif /* Include guard */