pre-likely cleanup
[p5sagit/p5-mst-13.2.git] / sv.h
diff --git a/sv.h b/sv.h
index 77731c4..acb4fe6 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -59,9 +59,16 @@ typedef enum {
        SVt_PVHV,       /* 12 */
        SVt_PVCV,       /* 13 */
        SVt_PVFM,       /* 14 */
-       SVt_PVIO        /* 15 */
+       SVt_PVIO,       /* 15 */
+       SVt_LAST        /* keep last in enum. used to size arrays */
 } svtype;
 
+#ifdef PERL_IN_SV_C
+#define PTE_SVSLOT     SVt_RV
+#endif
+#if defined(PERL_IN_HV_C) || defined(PERL_IN_XS_APITEST)
+#define HE_SVSLOT      SVt_NULL
+#endif
 
 /* typedefs to eliminate some typing */
 typedef struct he HE;
@@ -109,7 +116,7 @@ struct cv {
 };
 
 struct av {
-    _SV_HEAD(XPVAV*);          /* pointer to xpvcv body */
+    _SV_HEAD(XPVAV*);          /* pointer to xpvav body */
     _SV_HEAD_UNION;
 };
 
@@ -124,7 +131,7 @@ struct io {
 };
 
 #undef _SV_HEAD
-#undef _SV_HEAD_UNION          /* insure no pollution */
+#undef _SV_HEAD_UNION          /* ensure no pollution */
 
 /*
 =head1 SV Manipulation Functions
@@ -185,6 +192,11 @@ perform the upgrade if necessary.  See C<svtype>.
 #define SVTYPEMASK     0xff
 #define SvTYPE(sv)     ((sv)->sv_flags & SVTYPEMASK)
 
+/* Sadly there are some parts of the core that have pointers to already-freed
+   SV heads, and rely on being able to tell that they are now free. So mark
+   them all by using a consistent macro.  */
+#define SvIS_FREED(sv) ((sv)->sv_flags == SVTYPEMASK)
+
 #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= (mt) || (sv_upgrade(sv, mt), 1))
 
 #define SVs_PADSTALE   0x00000100      /* lexical has gone out of scope */
@@ -887,11 +899,6 @@ in gv.h: */
 #  define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
 #  define SvEND(sv) ((sv)->sv_u.svu_pv + ((XPV*)SvANY(sv))->xpv_cur)
 
-/* Given that these two are new, there can't be any existing code using them
- *  as LVALUEs  */
-#define SvPVX_mutable(sv)      (0 + (sv)->sv_u.svu_pv)
-#define SvPVX_const(sv)                ((const char*)(0 + (sv)->sv_u.svu_pv))
-
 #  ifdef DEBUGGING
 #    define SvMAGIC(sv)        (*(assert(SvTYPE(sv) >= SVt_PVMG), &((XPVMG*)  SvANY(sv))->xmg_magic))
 #    define SvSTASH(sv)        (*(assert(SvTYPE(sv) >= SVt_PVMG), &((XPVMG*)  SvANY(sv))->xmg_stash))
@@ -901,6 +908,18 @@ in gv.h: */
 #  endif
 #endif
 
+#ifndef PERL_POISON
+/* Given that these two are new, there can't be any existing code using them
+ *  as LVALUEs  */
+#  define SvPVX_mutable(sv)    (0 + (sv)->sv_u.svu_pv)
+#  define SvPVX_const(sv)      ((const char*)(0 + (sv)->sv_u.svu_pv))
+#else
+/* Except for the poison code, which uses & to scribble over the pointer after
+   free() is called.  */
+#  define SvPVX_mutable(sv)    ((sv)->sv_u.svu_pv)
+#  define SvPVX_const(sv)      ((const char*)((sv)->sv_u.svu_pv))
+#endif
+
 #define SvIVXx(sv) SvIVX(sv)
 #define SvUVXx(sv) SvUVX(sv)
 #define SvNVXx(sv) SvNVX(sv)
@@ -1034,6 +1053,8 @@ Taints an SV if tainting is enabled.
 =cut
 */
 
+#define sv_taint(sv)     sv_magic((sv), Nullsv, PERL_MAGIC_taint, Nullch, 0)
+
 #define SvTAINTED(sv)    (SvMAGICAL(sv) && sv_tainted(sv))
 #define SvTAINTED_on(sv)  STMT_START{ if(PL_tainting){sv_taint(sv);}   }STMT_END
 #define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END
@@ -1346,6 +1367,10 @@ Like C<sv_catsv> but doesn't process magic.
 #define SV_NOSTEAL             16
 #define SV_CONST_RETURN                32
 #define SV_MUTABLE_RETURN      64
+#define SV_SMAGIC              128
+
+#define sv_unref(sv)           sv_unref_flags(sv, 0)
+#define sv_force_normal(sv)    sv_force_normal_flags(sv, 0)
 
 /* We are about to replace the SV's current value. So if it's copy on write
    we need to normalise it. Use the SV_COW_DROP_PV flag hint to say that
@@ -1386,8 +1411,14 @@ Like C<sv_catsv> but doesn't process magic.
 #define sv_setsv_nomg(dsv, ssv) sv_setsv_flags(dsv, ssv, 0)
 #define sv_catsv(dsv, ssv) sv_catsv_flags(dsv, ssv, SV_GMAGIC)
 #define sv_catsv_nomg(dsv, ssv) sv_catsv_flags(dsv, ssv, 0)
+#define sv_catsv_mg(dsv, ssv) sv_catsv_flags(dsv, ssv, SV_GMAGIC|SV_SMAGIC)
 #define sv_catpvn(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, SV_GMAGIC)
+#define sv_catpvn_mg(sv, sstr, slen) \
+       sv_catpvn_flags(sv, sstr, slen, SV_GMAGIC|SV_SMAGIC);
 #define sv_2pv(sv, lp) sv_2pv_flags(sv, lp, SV_GMAGIC)
+#define sv_2pv_nolen(sv) sv_2pv(sv, 0)
+#define sv_2pvbyte_nolen(sv) sv_2pvbyte(sv, 0)
+#define sv_2pvutf8_nolen(sv) sv_2pvutf8(sv, 0)
 #define sv_2pv_nomg(sv, lp) sv_2pv_flags(sv, lp, 0)
 #define sv_pvn_force(sv, lp) sv_pvn_force_flags(sv, lp, SV_GMAGIC)
 #define sv_utf8_upgrade(sv) sv_utf8_upgrade_flags(sv, SV_GMAGIC)