blead 25801: Symbian batch of today
[p5sagit/p5-mst-13.2.git] / sv.h
diff --git a/sv.h b/sv.h
index 003e041..1e6c86a 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -69,18 +69,26 @@ typedef struct hek HEK;
 
 /* Using C's structural equivalence to help emulate C++ inheritance here... */
 
+/* start with 2 sv-head building blocks */
+#define _SV_HEAD(ptrtype) \
+    ptrtype    sv_any;         /* pointer to body */   \
+    U32                sv_refcnt;      /* how many references to us */ \
+    U32                sv_flags        /* what we are */
+
+#define _SV_HEAD_UNION \
+    union {                            \
+       IV      svu_iv;                 \
+       UV      svu_uv;                 \
+       SV*     svu_rv;         /* pointer to another SV */             \
+       char*   svu_pv;         /* pointer to malloced string */        \
+       SV**    svu_array;              \
+       HE**    svu_hash;               \
+    }  sv_u
+
+
 struct STRUCT_SV {             /* struct sv { */
-    void*      sv_any;         /* pointer to something */
-    U32                sv_refcnt;      /* how many references to us */
-    U32                sv_flags;       /* what we are */
-    union {
-       IV      svu_iv;
-       UV      svu_uv;
-       SV*     svu_rv;         /* pointer to another SV */
-       char*   svu_pv;         /* pointer to malloced string */
-       SV**    svu_array;
-       HE**    svu_hash;
-    }          sv_u;
+    _SV_HEAD(void*);
+    _SV_HEAD_UNION;
 #ifdef DEBUG_LEAKING_SCALARS
     unsigned   sv_debug_optype:9;      /* the type of OP that allocated us */
     unsigned   sv_debug_inpad:1;       /* was allocated in a pad for an OP */
@@ -91,75 +99,33 @@ struct STRUCT_SV {          /* struct sv { */
 };
 
 struct gv {
-    XPVGV*     sv_any;         /* pointer to something */
-    U32                sv_refcnt;      /* how many references to us */
-    U32                sv_flags;       /* what we are */
-    union {
-       IV      svu_iv;
-       UV      svu_uv;
-       SV*     svu_rv;
-       char*   svu_pv;
-       SV**    svu_array;
-       HE**    svu_hash;
-    }          sv_u;
+    _SV_HEAD(XPVGV*);          /* pointer to xpvgv body */
+    _SV_HEAD_UNION;
 };
 
 struct cv {
-    XPVCV*     sv_any;         /* pointer to something */
-    U32                sv_refcnt;      /* how many references to us */
-    U32                sv_flags;       /* what we are */
-    union {
-       IV      svu_iv;
-       UV      svu_uv;
-       SV*     svu_rv;
-       char*   svu_pv;
-       SV**    svu_array;
-       HE**    svu_hash;
-    }          sv_u;
+    _SV_HEAD(XPVCV*);          /* pointer to xpvcv body */
+    _SV_HEAD_UNION;
 };
 
 struct av {
-    XPVAV*     sv_any;         /* pointer to something */
-    U32                sv_refcnt;      /* how many references to us */
-    U32                sv_flags;       /* what we are */
-    union {
-       IV      svu_iv;
-       UV      svu_uv;
-       SV*     svu_rv;
-       char*   svu_pv;         /* pointer to first array element */
-       SV**    svu_array;
-       HE**    svu_hash;
-    }          sv_u;
+    _SV_HEAD(XPVAV*);          /* pointer to xpvcv body */
+    _SV_HEAD_UNION;
 };
 
 struct hv {
-    XPVHV*     sv_any;         /* pointer to something */
-    U32                sv_refcnt;      /* how many references to us */
-    U32                sv_flags;       /* what we are */
-    union {
-       IV      svu_iv;
-       UV      svu_uv;
-       SV*     svu_rv;
-       char*   svu_pv;
-       SV**    svu_array;
-       HE**    svu_hash;
-    }          sv_u;
+    _SV_HEAD(XPVHV*);          /* pointer to xpvhv body */
+    _SV_HEAD_UNION;
 };
 
 struct io {
-    XPVIO*     sv_any;         /* pointer to something */
-    U32                sv_refcnt;      /* how many references to us */
-    U32                sv_flags;       /* what we are */
-    union {
-       IV      svu_iv;
-       UV      svu_uv;
-       SV*     svu_rv;
-       char*   svu_pv;
-       SV**    svu_array;
-       HE**    svu_hash;
-    }          sv_u;
+    _SV_HEAD(XPVIO*);          /* pointer to xpvio body */
+    _SV_HEAD_UNION;
 };
 
+#undef _SV_HEAD
+#undef _SV_HEAD_UNION          /* insure no pollution */
+
 /*
 =head1 SV Manipulation Functions
 
@@ -892,8 +858,6 @@ in gv.h: */
 #  else
 #  define SvPVX(sv) SvPVX_mutable(sv)
 #  endif
-#  define SvPVX_mutable(sv)    (0 + (sv)->sv_u.svu_pv)
-#  define SvPVX_const(sv)      ((const char*)(0 + (sv)->sv_u.svu_pv))
 #  define SvCUR(sv) (0 + ((XPV*) SvANY(sv))->xpv_cur)
 #  define SvLEN(sv) (0 + ((XPV*) SvANY(sv))->xpv_len)
 #  define SvEND(sv) ((sv)->sv_u.svu_pv + ((XPV*)SvANY(sv))->xpv_cur)
@@ -919,8 +883,6 @@ in gv.h: */
 #  define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
 #  define SvNVX(sv) ((XPVNV*) SvANY(sv))->xnv_nv
 #  define SvPVX(sv) ((sv)->sv_u.svu_pv)
-#  define SvPVX_mutable(sv)    SvPVX(sv)
-#  define SvPVX_const(sv)      ((const char*)SvPVX(sv))
 #  define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
 #  define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
 #  define SvEND(sv) ((sv)->sv_u.svu_pv + ((XPV*)SvANY(sv))->xpv_cur)
@@ -934,6 +896,11 @@ in gv.h: */
 #  endif
 #endif
 
+/* 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))
+
 #define SvIVXx(sv) SvIVX(sv)
 #define SvUVXx(sv) SvUVX(sv)
 #define SvNVXx(sv) SvNVX(sv)
@@ -1221,6 +1188,10 @@ Like C<sv_catsv> but doesn't process magic.
     ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
      ? ((lp = SvCUR(sv)), SvPVX_const(sv)) : \
      (const char*) sv_2pv_flags(sv, &lp, flags|SV_CONST_RETURN))
+#define SvPV_flags_const_nolen(sv, flags) \
+    ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
+     ? SvPVX_const(sv) : \
+     (const char*) sv_2pv_flags(sv, 0, flags|SV_CONST_RETURN))
 #define SvPV_flags_mutable(sv, lp, flags) \
     ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
      ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) : \
@@ -1231,6 +1202,7 @@ Like C<sv_catsv> but doesn't process magic.
 #define SvPV_force_mutable(sv, lp) SvPV_force_flags_mutable(sv, lp, SV_GMAGIC)
 
 #define SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0)
+#define SvPV_force_nomg_nolen(sv) SvPV_force_flags_nolen(sv, 0)
 
 #define SvPV_force_flags(sv, lp, flags) \
     ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
@@ -1253,6 +1225,7 @@ Like C<sv_catsv> but doesn't process magic.
 
 #define SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0)
 #define SvPV_nomg_const(sv, lp) SvPV_flags_const(sv, lp, 0)
+#define SvPV_nomg_const_nolen(sv) SvPV_flags_const_nolen(sv, 0)
 
 /* ----*/