In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/630b72b081fe290d04732279e069c327eea82b09?hp=eed484f95050ad51c720521f68c6341a14bf5638>
- Log ----------------------------------------------------------------- commit 630b72b081fe290d04732279e069c327eea82b09 Author: Daniel Dragan <[email protected]> Date: Fri Nov 23 16:15:04 2012 -0500 SvPVXtrue single eval->multiple eval Make SvTRUE and SvPVXtrue smaller and faster in machine code on non GCC compilers. This commit implements my posts here, http://www.nntp.perl.org/group/perl.perl5.porters/2012/11/msg195720.html and in my commit message in commit 4cc783efe0 . SvPVXtrue was added in commit 4bac9ae47b . No reason was given why SvPVXtrue is single eval, but its only use is in multi eval SvTRUE. A non GCC compiler will write to PL_Xpv and PL_Sv, and still keep the SV * and PV *s in a register for the next operations/instructions. The writes to PL_Xpv and PL_Sv are needless. The use of PL_Xpv and PL_Sv is self explanatory C lang wise. As said in the ML post, this commit causes overall code bloat because of incorrect uses of passing macro args that make calls (ERRSV for example) to SvTRUE. This will have to be fixed in the future. All of the pp opcode funcs decrease tiny bit in size after this commit. See the ML list post for details. M sv.h commit b899e89d91e81e631e553a5b805e8d068828dbf0 Author: Father Chrysostomos <[email protected]> Date: Fri Nov 23 17:54:09 2012 -0800 Stop toke.c:S_scan_const from leaking Fatal warnings and errors can cause the string buffer used when scanning a quote-like operator to leak. This commit fixes it by using the savestack. There are still a few leaks from that code path that are not fixed by this. M t/op/svleak.t M toke.c ----------------------------------------------------------------------- Summary of changes: sv.h | 20 +++++++++++--------- t/op/svleak.t | 6 ++++-- toke.c | 10 ++++++---- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/sv.h b/sv.h index fe29a41..e636eca 100644 --- a/sv.h +++ b/sv.h @@ -1733,11 +1733,6 @@ Like sv_utf8_upgrade, but doesn't do magic on C<sv>. # define SvPVbytex_nolen(sv) ({SV *_sv = (sv); SvPVbyte_nolen(_sv); }) # define SvTRUEx(sv) ({SV *_sv = (sv); SvTRUE(_sv); }) # define SvTRUEx_nomg(sv) ({SV *_sv = (sv); SvTRUE_nomg(_sv); }) -# define SvPVXtrue(sv) \ - ({XPV *nxpv; \ - (nxpv = (XPV*)SvANY(sv)) \ - && (nxpv->xpv_cur > 1 \ - || (nxpv->xpv_cur && *(sv)->sv_u.svu_pv != '0'));}) #else /* __GNUC__ */ @@ -1756,12 +1751,19 @@ Like sv_utf8_upgrade, but doesn't do magic on C<sv>. # define SvPVbytex_nolen(sv) ((PL_Sv = (sv)), SvPVbyte_nolen(PL_Sv)) # define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv)) # define SvTRUEx_nomg(sv) ((PL_Sv = (sv)), SvTRUE_nomg(PL_Sv)) -# define SvPVXtrue(sv) \ - ((PL_Xpv = (XPV*)SvANY(PL_Sv = (sv))) \ - && (PL_Xpv->xpv_cur > 1 \ - || (PL_Xpv->xpv_cur && *PL_Sv->sv_u.svu_pv != '0'))) #endif /* __GNU__ */ +#define SvPVXtrue(sv) ( \ + ((XPV*)SvANY((sv))) \ + && ( \ + ((XPV*)SvANY((sv)))->xpv_cur > 1 \ + || ( \ + ((XPV*)SvANY((sv)))->xpv_cur \ + && *(sv)->sv_u.svu_pv != '0' \ + ) \ + ) \ +) + #define SvIsCOW(sv) (SvFLAGS(sv) & SVf_IsCOW) #define SvIsCOW_on(sv) (SvFLAGS(sv) |= SVf_IsCOW) #define SvIsCOW_off(sv) (SvFLAGS(sv) &= ~SVf_IsCOW) diff --git a/t/op/svleak.t b/t/op/svleak.t index 2a2e31c..11ce8de 100644 --- a/t/op/svleak.t +++ b/t/op/svleak.t @@ -72,13 +72,13 @@ leak(5, 1, sub {push @a,1;}, "basic check 3 of leak test infrastructure"); # Fatal warnings my $f = "use warnings FATAL =>"; my $all = "$f 'all';"; -$::TODO = 'still leaks'; eleak(2, 0, "$f 'deprecated'; qq|\\c\{|", 'qq|\c{| with fatal warnings'); eleak(2, 0, "$f 'syntax'; qq|\\c`|", 'qq|\c`| with fatal warnings'); eleak(2, 0, "$all /\$\\ /", '/$\ / with fatal warnings'); eleak(2, 0, "$all s//\\1/", 's//\1/ with fatal warnings'); eleak(2, 0, "$all qq|\\i|", 'qq|\i| with fatal warnings'); eleak(2, 0, "$f 'digit'; qq|\\o{9}|", 'qq|\o{9}| with fatal warnings'); +$::TODO = 'still leaks'; eleak(2, 0, "$f 'misc'; sub foo{} sub foo:lvalue", 'ignored :lvalue with fatal warnings'); eleak(2, 0, "no warnings; use feature ':all'; $f 'misc'; @@ -272,14 +272,16 @@ eleak(2, 0, 'no warnings; 2 2;BEGIN{}', } eleak(2, 0, "\"\$\0\356\"", 'qq containing $ <null> something'); eleak(2, 0, 'END OF TERMS AND CONDITIONS', 'END followed by words'); -$::TODO = 'still leaks'; eleak(2, 0, "qq|\\c|;"x10, '"too many errors" from qq"\c"'); +$::TODO = 'still leaks'; eleak(2, 0, "qq|\\N{%}|"x10, '"too many errors" from qq"\N{%}"'); +undef $::TODO; eleak(2, 0, "qq|\\o|;"x10, '"too many errors" from qq"\o"'); eleak(2, 0, "qq|\\x{|;"x10, '"too many errors" from qq"\x{"'); eleak(2, 0, "qq|\\N|;"x10, '"too many errors" from qq"\N"'); eleak(2, 0, "qq|\\N{|;"x10, '"too many errors" from qq"\N{"'); eleak(2, 0, "qq|\\N{U+GETG}|;"x10,'"too many errors" from qq"\N{U+JUNK}"'); +$::TODO = 'still leaks'; eleak(2, 0, "qq|\\N{au}|;"x10, '"too many errors" from qq"\N{invalid}"'); undef $::TODO; diff --git a/toke.c b/toke.c index 902f83c..32367bc 100644 --- a/toke.c +++ b/toke.c @@ -2966,6 +2966,9 @@ S_scan_const(pTHX_ char *start) this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF); } + /* Protect sv from errors and fatal warnings. */ + ENTER_with_name("scan_const"); + SAVEFREESV(sv); while (s < send || dorange) { @@ -3037,7 +3040,6 @@ S_scan_const(pTHX_ char *start) #endif if (min > max) { - SvREFCNT_dec(sv); Perl_croak(aTHX_ "Invalid range \"%c-%c\" in transliteration operator", (char)min, (char)max); @@ -3096,7 +3098,6 @@ S_scan_const(pTHX_ char *start) /* range begins (ignore - as first or last char) */ else if (*s == '-' && s+1 < send && s != start) { if (didrange) { - SvREFCNT_dec(sv); Perl_croak(aTHX_ "Ambiguous range in transliteration operator"); } if (has_utf8 @@ -3723,6 +3724,7 @@ S_scan_const(pTHX_ char *start) /* return the substring (via pl_yylval) only if we parsed anything */ if (s > PL_bufptr) { + SvREFCNT_inc_simple_void_NN(sv); if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) { const char *const key = PL_lex_inpat ? "qr" : "q"; const STRLEN keylen = PL_lex_inpat ? 2 : 1; @@ -3747,8 +3749,8 @@ S_scan_const(pTHX_ char *start) type, typelen); } pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv); - } else - SvREFCNT_dec(sv); + } + LEAVE_with_name("scan_const"); return s; } -- Perl5 Master Repository
