In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/095b19d150eee57ee8501177d6950002977ef74c?hp=7e2a0d4586762cf28c9cdfb3c49d57d805879ac9>
- Log ----------------------------------------------------------------- commit 095b19d150eee57ee8501177d6950002977ef74c Author: Nicholas Clark <[email protected]> Date: Wed Jul 11 20:24:14 2012 +0200 In Perl_scalarvoid(), avoid creating a temporary SV for simple messages. If using an SV to generate a potentially UTF-8 error message, pass that SV onward to the code that generates warnings, and use a SV-specific format. Otherwise use a %s format and pass the char * pointer directly to Perl_ck_warner(). This avoids creating a temporary SV just to hold a fixed ASCII string, but retains the ability to generate clean UTF-8 error messages. ----------------------------------------------------------------------- Summary of changes: op.c | 36 ++++++++++++++++++++++-------------- 1 files changed, 22 insertions(+), 14 deletions(-) diff --git a/op.c b/op.c index 8fc0312..6cfff4f 100644 --- a/op.c +++ b/op.c @@ -1165,8 +1165,8 @@ Perl_scalarvoid(pTHX_ OP *o) { dVAR; OP *kid; + SV *useless_sv = NULL; const char* useless = NULL; - U32 useless_is_utf8 = 0; SV* sv; U8 want; @@ -1367,19 +1367,19 @@ Perl_scalarvoid(pTHX_ OP *o) useless = NULL; else { SV * const dsv = newSVpvs(""); - SV* msv = sv_2mortal(Perl_newSVpvf(aTHX_ - "a constant (%s)", - pv_pretty(dsv, maybe_macro, SvCUR(sv), 32, NULL, NULL, - PERL_PV_PRETTY_DUMP | PERL_PV_ESCAPE_NOCLEAR | PERL_PV_ESCAPE_UNI_DETECT ))); + useless_sv + = Perl_newSVpvf(aTHX_ + "a constant (%s)", + pv_pretty(dsv, maybe_macro, + SvCUR(sv), 32, NULL, NULL, + PERL_PV_PRETTY_DUMP + | PERL_PV_ESCAPE_NOCLEAR + | PERL_PV_ESCAPE_UNI_DETECT)); SvREFCNT_dec(dsv); - useless = SvPV_nolen(msv); - useless_is_utf8 = SvUTF8(msv); } } else if (SvOK(sv)) { - SV* msv = sv_2mortal(Perl_newSVpvf(aTHX_ - "a constant (%"SVf")", sv)); - useless = SvPV_nolen(msv); + useless_sv = Perl_newSVpvf(aTHX_ "a constant (%"SVf")", sv); } else useless = "a constant (undef)"; @@ -1506,10 +1506,18 @@ Perl_scalarvoid(pTHX_ OP *o) case OP_SCALAR: return scalar(o); } - if (useless) - Perl_ck_warner(aTHX_ packWARN(WARN_VOID), "Useless use of %"SVf" in void context", - newSVpvn_flags(useless, strlen(useless), - SVs_TEMP | ( useless_is_utf8 ? SVf_UTF8 : 0 ))); + + if (useless_sv) { + /* mortalise it, in case warnings are fatal. */ + Perl_ck_warner(aTHX_ packWARN(WARN_VOID), + "Useless use of %"SVf" in void context", + sv_2mortal(useless_sv)); + } + else if (useless) { + Perl_ck_warner(aTHX_ packWARN(WARN_VOID), + "Useless use of %s in void context", + useless); + } return o; } -- Perl5 Master Repository
