This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make PL_(top|body|form)target PVIVs
authorFather Chrysostomos <sprout@cpan.org>
Sun, 5 Aug 2012 07:15:52 +0000 (00:15 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 5 Aug 2012 20:18:50 +0000 (13:18 -0700)
These are only used for storing a string and an IV.

Making them into full-blown SVt_PVFMs is overkill.

FmLINES was only being used on these three scalars.  So make it use
the SvIVX field.  struct xpvfm no longer needs an xfm_lines member,
because SVt_PVFMs no longer use it.

This also causes a TODO test in taint.t to start passing, but I do
not fully understand why.  But at least that’s progress. :-)

dump.c
ext/B/B.xs
mg.c
perl.c
sv.h
t/op/taint.t

diff --git a/dump.c b/dump.c
index 022983d..c7a40a6 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -1924,8 +1924,6 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
            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));
-       if (type == SVt_PVFM)
-           Perl_dump_indent(aTHX_ level, file, "  LINES = %"IVdf"\n", (IV)FmLINES(sv));
        Perl_dump_indent(aTHX_ level, file, "  PADLIST = 0x%"UVxf"\n", PTR2UV(CvPADLIST(sv)));
        if (nest < maxnest) {
            do_dump_pad(level+1, file, CvPADLIST(sv), 0);
index b503611..9c9133b 100644 (file)
@@ -1446,8 +1446,6 @@ MODULE = B        PACKAGE = B::IV
 
 #define PVAV_max_ix    sv_SSize_tp | offsetof(struct xpvav, xav_max)
 
-#define PVFM_lines_ix  sv_IVp | offsetof(struct xpvfm, xfm_lines)
-
 #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)
@@ -1504,7 +1502,6 @@ IVX(sv)
        B::IO::IoTYPE = PVIO_type_ix
        B::IO::IoFLAGS = PVIO_flags_ix
        B::AV::MAX = PVAV_max_ix
-       B::FM::LINES = PVFM_lines_ix
        B::CV::STASH = PVCV_stash_ix
        B::CV::GV = PVCV_gv_ix
        B::CV::FILE = PVCV_file_ix
@@ -1961,6 +1958,17 @@ AvFLAGS(av)
 
 #endif
 
+MODULE = B     PACKAGE = B::FM         PREFIX = Fm
+
+#if PERL_VERSION > 7 || (PERL_VERSION == 7 && PERL_SUBVERSION >= 3)
+# undef FmLINES
+# define FmLINES(sv) 0
+#endif
+
+IV
+FmLINES(form)
+       B::FM   form
+
 MODULE = B     PACKAGE = B::CV         PREFIX = Cv
 
 U32
diff --git a/mg.c b/mg.c
index 3b4ed1c..2ac49bf 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -814,7 +814,8 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
 
     switch (*mg->mg_ptr) {
     case '\001':               /* ^A */
-       sv_setsv(sv, PL_bodytarget);
+       if (SvOK(PL_bodytarget)) sv_copypv(sv, PL_bodytarget);
+       else sv_setsv(sv, &PL_sv_undef);
        if (SvTAINTED(PL_bodytarget))
            SvTAINTED_on(sv);
        break;
@@ -2542,7 +2543,8 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
         }
         break;
     case '\001':       /* ^A */
-       sv_setsv(PL_bodytarget, sv);
+       if (SvOK(sv)) sv_copypv(PL_bodytarget, sv);
+       else SvOK_off(PL_bodytarget);
        FmLINES(PL_bodytarget) = 0;
        if (SvPOK(PL_bodytarget)) {
            char *s = SvPVX(PL_bodytarget);
diff --git a/perl.c b/perl.c
index d8b8aca..d836b0b 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -4137,9 +4137,9 @@ S_init_postdump_symbols(pTHX_ register int argc, register char **argv, register
 
     PERL_ARGS_ASSERT_INIT_POSTDUMP_SYMBOLS;
 
-    PL_toptarget = newSV_type(SVt_PVFM);
+    PL_toptarget = newSV_type(SVt_PVIV);
     sv_setpvs(PL_toptarget, "");
-    PL_bodytarget = newSV_type(SVt_PVFM);
+    PL_bodytarget = newSV_type(SVt_PVIV);
     sv_setpvs(PL_bodytarget, "");
     PL_formtarget = PL_bodytarget;
 
diff --git a/sv.h b/sv.h
index 056d43b..b2385d0 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -520,7 +520,6 @@ typedef U16 cv_flags_t;
 struct xpvfm {
     _XPV_HEAD;
     _XPVCV_COMMON;
-    IV         xfm_lines;
 };
 
 
@@ -1387,7 +1386,7 @@ sv_force_normal does nothing.
 
 #endif
 
-#define FmLINES(sv)    ((XPVFM*)  SvANY(sv))->xfm_lines
+#define FmLINES(sv)    ((XPVIV*)  SvANY(sv))->xiv_iv
 
 #define LvTYPE(sv)     ((XPVLV*)  SvANY(sv))->xlv_type
 #define LvTARG(sv)     ((XPVLV*)  SvANY(sv))->xlv_targ
index c8537fc..0e89c1f 100644 (file)
@@ -2050,10 +2050,7 @@ end
     formline('@' .('<'*5) . ' | @*', 'hallo', 'welt');
     isnt_tainted($^A, "accumulator still untainted");
     formline('@' .('<'*(5+$TAINT0)) . ' | @*', 'hallo', 'welt');
-    TODO: {
-        local $::TODO = "get magic handled too late?";
-        is_tainted($^A, "the accumulator should be tainted already");
-    }
+    is_tainted($^A, "the accumulator should be tainted already");
     is_tainted($^A, "tainted formline picture makes a tainted accumulator");
 }