This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Un-TODO some B tests
[perl5.git] / sv.h
diff --git a/sv.h b/sv.h
index 71389c9..ab09bba 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -158,11 +158,11 @@ Same as SvREFCNT_inc, but can only be used if you know I<sv>
 is not NULL.  Since we don't have to check the NULLness, it's faster
 and smaller.
 
-=for apidoc Am|SV*|SvREFCNT_inc_void|SV* sv
+=for apidoc Am|void|SvREFCNT_inc_void|SV* sv
 Same as SvREFCNT_inc, but can only be used if you don't need the
 return value.  The macro doesn't need to return a meaningful value.
 
-=for apidoc Am|SV*|SvREFCNT_inc_void_NN|SV* sv
+=for apidoc Am|void|SvREFCNT_inc_void_NN|SV* sv
 Same as SvREFCNT_inc, but can only be used if you don't need the return
 value, and you know that I<sv> is not NULL.  The macro doesn't need
 to return a meaningful value, or check for NULLness, so it's smaller
@@ -178,12 +178,15 @@ Same as SvREFCNT_inc_simple, but can only be used if you know I<sv>
 is not NULL.  Since we don't have to check the NULLness, it's faster
 and smaller.
 
-=for apidoc Am|SV*|SvREFCNT_inc_simple_void|SV* sv
+=for apidoc Am|void|SvREFCNT_inc_simple_void|SV* sv
 Same as SvREFCNT_inc_simple, but can only be used if you don't need the
 return value.  The macro doesn't need to return a meaningful value.
 
-=for apidoc Am|SV*|SvREFCNT_inc|SV* sv
-Increments the reference count of the given SV.
+=for apidoc Am|void|SvREFCNT_inc_simple_void_NN|SV* sv
+Same as SvREFCNT_inc, but can only be used if you don't need the return
+value, and you know that I<sv> is not NULL.  The macro doesn't need
+to return a meaningful value, or check for NULLness, so it's smaller
+and faster.
 
 =for apidoc Am|void|SvREFCNT_dec|SV* sv
 Decrements the reference count of the given SV.
@@ -240,7 +243,7 @@ perform the upgrade if necessary.  See C<svtype>.
 #endif
 
 /* These guys don't need the curly blocks */
-#define SvREFCNT_inc_simple_void(sv)   if (sv) (SvREFCNT(sv)++);
+#define SvREFCNT_inc_simple_void(sv)   STMT_START { if (sv) SvREFCNT(sv)++; } STMT_END
 #define SvREFCNT_inc_simple_NN(sv)     (++(SvREFCNT(sv)),(SV*)(sv))
 #define SvREFCNT_inc_void_NN(sv)       (void)(++SvREFCNT((SV*)(sv)))
 #define SvREFCNT_inc_simple_void_NN(sv)        (void)(++SvREFCNT((SV*)(sv)))
@@ -263,7 +266,7 @@ perform the upgrade if necessary.  See C<svtype>.
 #endif
 
 #define SVTYPEMASK     0xff
-#define SvTYPE(sv)     ((sv)->sv_flags & SVTYPEMASK)
+#define SvTYPE(sv)     (svtype)((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
@@ -284,6 +287,7 @@ perform the upgrade if necessary.  See C<svtype>.
 #define SVphv_CLONEABLE        0x00008000      /* PVHV (stashes) clone its objects */
 
 #define SVs_PADSTALE   0x00010000      /* lexical has gone out of scope */
+#define SVpad_STATE    0x00010000      /* pad name is a "state" var */
 #define SVs_PADTMP     0x00020000      /* in use as tmp */
 #define SVpad_TYPED    0x00020000      /* pad name is a Typed Lexical */
 #define SVs_PADMY      0x00040000      /* in use a "my" variable */
@@ -339,7 +343,8 @@ perform the upgrade if necessary.  See C<svtype>.
                                           keys live on shared string table */
 /* PVNV, PVMG, PVGV, presumably only inside pads */
 #define SVpad_NAME     0x40000000      /* This SV is a name in the PAD, so
-                                          SVpad_TYPED and SVpad_OUR apply */
+                                          SVpad_TYPED, SVpad_OUR and
+                                          SVpad_STATE apply */
 /* PVAV */
 #define SVpav_REAL     0x40000000      /* free old entries */
 /* PVHV */
@@ -837,7 +842,7 @@ Set the value of the RV pointer in sv to val.  See C<SvIV_set>.
 =for apidoc Am|void|SvMAGIC_set|SV* sv|MAGIC* val
 Set the value of the MAGIC pointer in sv to val.  See C<SvIV_set>.
 
-=for apidoc Am|void|SvSTASH_set|SV* sv|STASH* val
+=for apidoc Am|void|SvSTASH_set|SV* sv|HV* val
 Set the value of the STASH pointer in sv to val.  See C<SvIV_set>.
 
 =for apidoc Am|void|SvCUR_set|SV* sv|STRLEN len
@@ -947,7 +952,11 @@ in gv.h: */
                                    SvFLAGS(sv) |= (SVf_POK|SVp_POK))
 
 #define SvVOK(sv)              (SvMAGICAL(sv)                          \
+                                && mg_find(sv,PERL_MAGIC_vstring))
+/* returns the vstring magic, if any */
+#define SvVSTRING_mg(sv)       (SvMAGICAL(sv) \
                                 ? mg_find(sv,PERL_MAGIC_vstring) : NULL)
+
 #define SvOOK(sv)              (SvFLAGS(sv) & SVf_OOK)
 #define SvOOK_on(sv)           ((void)SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
 #define SvOOK_off(sv)          ((void)(SvOOK(sv) && sv_backoff(sv)))
@@ -1074,6 +1083,10 @@ the scalar's value cannot change unless written to.
        ((SvFLAGS(sv) & (SVpad_NAME|SVpad_OUR)) == (SVpad_NAME|SVpad_OUR))
 #define SvPAD_OUR_on(sv)       (SvFLAGS(sv) |= SVpad_NAME|SVpad_OUR)
 
+#define SvPAD_STATE(sv)        \
+       ((SvFLAGS(sv) & (SVpad_NAME|SVpad_STATE)) == (SVpad_NAME|SVpad_STATE))
+#define SvPAD_STATE_on(sv)     (SvFLAGS(sv) |= SVpad_NAME|SVpad_STATE)
+
 #define OURSTASH(sv)   \
        (SvPAD_OUR(sv) ? ((XPVMG*) SvANY(sv))->xmg_u.xmg_ourstash : NULL)
 #define OURSTASH_set(sv, st)                                   \
@@ -1164,6 +1177,8 @@ the scalar's value cannot change unless written to.
 #    define SvMAGIC(sv)                                                        \
        (*({ SV *const _svi = (SV *) sv;                                \
            assert(SvTYPE(_svi) >= SVt_PVMG);                           \
+           if(SvTYPE(_svi) == SVt_PVMG)                                \
+               assert(!SvPAD_OUR(_svi));                               \
            &(((XPVMG*) SvANY(_svi))->xmg_u.xmg_magic);                 \
          }))
 #    define SvSTASH(sv)                                                        \