This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add a depth field to formats
authorFather Chrysostomos <sprout@cpan.org>
Sun, 5 Aug 2012 07:48:00 +0000 (00:48 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 5 Aug 2012 20:18:58 +0000 (13:18 -0700)
Instead of lengthening the struct, we can reuse SvCUR, which is cur-
rently unused.

cv.h
dump.c
ext/B/B.xs
sv.h

diff --git a/cv.h b/cv.h
index e2644e1..a94d248 100644 (file)
--- a/cv.h
+++ b/cv.h
@@ -61,13 +61,21 @@ See L<perlguts/Autoloading with XSUBs>.
     (CvFILE(sv) = CopFILE(cop), CvDYNFILE_off(sv))
 #endif
 #define CvFILEGV(sv)   (gv_fetchfile(CvFILE(sv)))
+PERL_STATIC_INLINE I32 *
+S_CvDEPTHp(const CV * const sv)
+{
+    return SvTYPE(sv) == SVt_PVCV
+       ? &((XPVCV*)SvANY(sv))->xcv_depth
+       : &((XPVCV*)SvANY(sv))->xpv_cur_u.xpvcuru_fmdepth;
+}
 #if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)
 #  define CvDEPTH(sv) (*({const CV *const _cvdepth = (const CV *)sv; \
-                         assert(SvTYPE(_cvdepth) == SVt_PVCV);  \
-                         &((XPVCV*)SvANY(_cvdepth))->xcv_depth; \
+                         assert(SvTYPE(_cvdepth) == SVt_PVCV         \
+                             || SvTYPE(_cvdepth) == SVt_PVFM);        \
+                         S_CvDEPTHp(_cvdepth);                         \
                        }))
 #else
-#  define CvDEPTH(sv)  ((XPVCV*)MUTABLE_PTR(SvANY(sv)))->xcv_depth
+#  define CvDEPTH(sv)  *S_CvDEPTHp((const CV *)sv)
 #endif
 #define CvPADLIST(sv)  ((XPVCV*)MUTABLE_PTR(SvANY(sv)))->xcv_padlist
 #define CvOUTSIDE(sv)  ((XPVCV*)MUTABLE_PTR(SvANY(sv)))->xcv_outside
diff --git a/dump.c b/dump.c
index ca5d125..0c5cc75 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -1920,8 +1920,7 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
        }
        do_gvgv_dump(level, file, "  GVGV::GV", CvGV(sv));
        Perl_dump_indent(aTHX_ level, file, "  FILE = \"%s\"\n", CvFILE(sv));
-       if (type == SVt_PVCV)
-           Perl_dump_indent(aTHX_ level, file, "  DEPTH = %"IVdf"\n", (IV)CvDEPTH(sv));
+       Perl_dump_indent(aTHX_ level, file, "  DEPTH = %"IVdf"\n", (IV)CvDEPTH(sv));
        Perl_dump_indent(aTHX_ level, file, "  FLAGS = 0x%"UVxf"\n", (UV)CvFLAGS(sv));
        Perl_dump_indent(aTHX_ level, file, "  OUTSIDE_SEQ = %"UVuf"\n", (UV)CvOUTSIDE_SEQ(sv));
        Perl_dump_indent(aTHX_ level, file, "  PADLIST = 0x%"UVxf"\n", PTR2UV(CvPADLIST(sv)));
index 9c9133b..2c3d7f8 100644 (file)
@@ -1449,7 +1449,6 @@ MODULE = B        PACKAGE = B::IV
 #define PVCV_stash_ix  sv_SVp | offsetof(struct xpvcv, xcv_stash) 
 #define PVCV_gv_ix     sv_SVp | offsetof(struct xpvcv, xcv_gv)
 #define PVCV_file_ix   sv_char_pp | offsetof(struct xpvcv, xcv_file)
-#define PVCV_depth_ix  sv_I32p | offsetof(struct xpvcv, xcv_depth)
 #define PVCV_padlist_ix        sv_SVp | offsetof(struct xpvcv, xcv_padlist)
 #define PVCV_outside_ix        sv_SVp | offsetof(struct xpvcv, xcv_outside)
 #define PVCV_outside_seq_ix sv_U32p | offsetof(struct xpvcv, xcv_outside_seq)
@@ -1505,7 +1504,6 @@ IVX(sv)
        B::CV::STASH = PVCV_stash_ix
        B::CV::GV = PVCV_gv_ix
        B::CV::FILE = PVCV_file_ix
-       B::CV::DEPTH = PVCV_depth_ix
        B::CV::PADLIST = PVCV_padlist_ix
        B::CV::OUTSIDE = PVCV_outside_ix
        B::CV::OUTSIDE_SEQ = PVCV_outside_seq_ix
@@ -1984,6 +1982,10 @@ CvSTART(cv)
        PUSHs(make_op_object(aTHX_ CvISXSUB(cv) ? NULL
                             : ix ? CvROOT(cv) : CvSTART(cv)));
 
+I32
+CvDEPTH(cv)
+        B::CV   cv
+
 void
 CvXSUB(cv)
        B::CV   cv
diff --git a/sv.h b/sv.h
index b2385d0..4c9bc55 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -415,9 +415,14 @@ perform the upgrade if necessary.  See C<svtype>.
 #define _XPV_HEAD                                                      \
     HV*                xmg_stash;      /* class package */                     \
     union _xmgu        xmg_u;                                                  \
-    STRLEN     xpv_cur;        /* length of svu_pv as a C string */    \
+    union {                                                            \
+       STRLEN  xpvcuru_cur;    /* length of svu_pv as a C string */    \
+       I32     xpvcuru_fmdepth;                                        \
+    }          xpv_cur_u;                                              \
     STRLEN     xpv_len         /* allocated size */
 
+#define xpv_cur        xpv_cur_u.xpvcuru_cur
+
 union _xnvu {
     NV     xnv_nv;             /* numeric value, if any */
     HV *    xgv_stash;