X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pp.c;h=ca9b3d99ad6f981d2174a60fd5957a448ff1baab;hb=ea581a515b67cceacd5ceea839a0bff72973e0b1;hp=374f3550e2226790e9fc2c79aadaed1e29dbebc7;hpb=5186cc1225228b10ef0f8c5cf7d34fbcf0e84174;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pp.c b/pp.c index 374f355..ca9b3d9 100644 --- a/pp.c +++ b/pp.c @@ -143,11 +143,11 @@ PP(pp_rv2gv) SvREFCNT_inc_void_NN(sv); sv = (SV*) gv; } - else if (SvTYPE(sv) != SVt_PVGV) + else if (!isGV_with_GP(sv)) DIE(aTHX_ "Not a GLOB reference"); } else { - if (SvTYPE(sv) != SVt_PVGV) { + if (!isGV_with_GP(sv)) { if (SvGMAGICAL(sv)) { mg_get(sv); if (SvROK(sv)) @@ -218,12 +218,14 @@ PP(pp_rv2gv) /* Helper function for pp_rv2sv and pp_rv2av */ GV * -Perl_softref2xv(pTHX_ SV *const sv, const char *const what, const U32 type, - SV ***spp) +Perl_softref2xv(pTHX_ SV *const sv, const char *const what, + const svtype type, SV ***spp) { dVAR; GV *gv; + PERL_ARGS_ASSERT_SOFTREF2XV; + if (PL_op->op_private & HINT_STRICT_REFS) { if (SvOK(sv)) Perl_die(aTHX_ PL_no_symref_sv, sv, what); @@ -283,7 +285,7 @@ PP(pp_rv2sv) else { gv = (GV*)sv; - if (SvTYPE(gv) != SVt_PVGV) { + if (!isGV_with_GP(gv)) { if (SvGMAGICAL(sv)) { mg_get(sv); if (SvROK(sv)) @@ -509,6 +511,8 @@ S_refto(pTHX_ SV *sv) dVAR; SV* rv; + PERL_ARGS_ASSERT_REFTO; + if (SvTYPE(sv) == SVt_PVLV && LvTYPE(sv) == 'y') { if (LvTARGLEN(sv)) vivify_defelem(sv); @@ -818,9 +822,11 @@ PP(pp_undef) } break; case SVt_PVGV: - if (SvFAKE(sv)) + if (SvFAKE(sv)) { SvSetMagicSV(sv, &PL_sv_undef); - else { + break; + } + else if (isGV_with_GP(sv)) { GP *gp; HV *stash; @@ -838,8 +844,9 @@ PP(pp_undef) GvLINE(sv) = CopLINE(PL_curcop); GvEGV(sv) = (GV*)sv; GvMULTI_on(sv); + break; } - break; + /* FALL THROUGH */ default: if (SvTYPE(sv) >= SVt_PV && SvPVX_const(sv) && SvLEN(sv)) { SvPV_free(sv); @@ -856,7 +863,7 @@ PP(pp_undef) PP(pp_predec) { dVAR; dSP; - if (SvTYPE(TOPs) >= SVt_PVGV && SvTYPE(TOPs) != SVt_PVLV) + if (SvTYPE(TOPs) >= SVt_PVAV || isGV_with_GP(TOPs)) DIE(aTHX_ PL_no_modify); if (!SvREADONLY(TOPs) && SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs) && SvIVX(TOPs) != IV_MIN) @@ -873,7 +880,7 @@ PP(pp_predec) PP(pp_postinc) { dVAR; dSP; dTARGET; - if (SvTYPE(TOPs) >= SVt_PVGV && SvTYPE(TOPs) != SVt_PVLV) + if (SvTYPE(TOPs) >= SVt_PVAV || isGV_with_GP(TOPs)) DIE(aTHX_ PL_no_modify); sv_setsv(TARG, TOPs); if (!SvREADONLY(TOPs) && SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs) @@ -895,7 +902,7 @@ PP(pp_postinc) PP(pp_postdec) { dVAR; dSP; dTARGET; - if (SvTYPE(TOPs) >= SVt_PVGV && SvTYPE(TOPs) != SVt_PVLV) + if (SvTYPE(TOPs) >= SVt_PVAV || isGV_with_GP(TOPs)) DIE(aTHX_ PL_no_modify); sv_setsv(TARG, TOPs); if (!SvREADONLY(TOPs) && SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs) @@ -3018,25 +3025,33 @@ PP(pp_length) dVAR; dSP; dTARGET; SV * const sv = TOPs; - if (SvAMAGIC(sv)) { - /* For an overloaded scalar, we can't know in advance if it's going to - be UTF-8 or not. Also, we can't call sv_len_utf8 as it likes to - cache the length. Maybe that should be a documented feature of it. + if (SvGAMAGIC(sv)) { + /* For an overloaded or magic scalar, we can't know in advance if + it's going to be UTF-8 or not. Also, we can't call sv_len_utf8 as + it likes to cache the length. Maybe that should be a documented + feature of it. */ STRLEN len; - const char *const p = SvPV_const(sv, len); + const char *const p + = sv_2pv_flags(sv, &len, + SV_UNDEF_RETURNS_NULL|SV_CONST_RETURN|SV_GMAGIC); - if (DO_UTF8(sv)) { + if (!p) + SETs(&PL_sv_undef); + else if (DO_UTF8(sv)) { SETi(utf8_length((U8*)p, (U8*)p + len)); } else SETi(len); - + } else if (SvOK(sv)) { + /* Neither magic nor overloaded. */ + if (DO_UTF8(sv)) + SETi(sv_len_utf8(sv)); + else + SETi(sv_len(sv)); + } else { + SETs(&PL_sv_undef); } - else if (DO_UTF8(sv)) - SETi(sv_len_utf8(sv)); - else - SETi(sv_len(sv)); RETURN; } @@ -3166,7 +3181,9 @@ PP(pp_substr) repl = SvPV_const(repl_sv_copy, repl_len); repl_is_utf8 = DO_UTF8(repl_sv_copy) && SvCUR(sv); } - sv_insert(sv, pos, rem, repl, repl_len); + if (!SvOK(sv)) + sv_setpvs(sv, ""); + sv_insert_flags(sv, pos, rem, repl, repl_len, 0); if (repl_is_utf8) SvUTF8_on(sv); if (repl_sv_copy) @@ -3185,7 +3202,7 @@ PP(pp_substr) else if (SvOK(sv)) /* is it defined ? */ (void)SvPOK_only_UTF8(sv); else - sv_setpvn(sv,"",0); /* avoid lexical reincarnation */ + sv_setpvs(sv, ""); /* avoid lexical reincarnation */ } if (SvTYPE(TARG) < SVt_PVLV) { @@ -3520,6 +3537,8 @@ PP(pp_ucfirst) if (SvOK(source)) { s = (const U8*)SvPV_nomg_const(source, slen); } else { + if (ckWARN(WARN_UNINITIALIZED)) + report_uninit(source); s = (const U8*)""; slen = 0; } @@ -3644,6 +3663,8 @@ PP(pp_uc) if (SvOK(source)) { s = (const U8*)SvPV_nomg_const(source, len); } else { + if (ckWARN(WARN_UNINITIALIZED)) + report_uninit(source); s = (const U8*)""; len = 0; } @@ -3744,6 +3765,8 @@ PP(pp_lc) if (SvOK(source)) { s = (const U8*)SvPV_nomg_const(source, len); } else { + if (ckWARN(WARN_UNINITIALIZED)) + report_uninit(source); s = (const U8*)""; len = 0; } @@ -4584,13 +4607,18 @@ PP(pp_reverse) SvUTF8_off(TARG); /* decontaminate */ if (SP - MARK > 1) do_join(TARG, &PL_sv_no, MARK, SP); - else + else { sv_setsv(TARG, (SP > MARK) ? *SP : (padoff_du = find_rundefsvoffset(), (padoff_du == NOT_IN_PAD || PAD_COMPNAME_FLAGS_isOUR(padoff_du)) ? DEFSV : PAD_SVl(padoff_du))); + + if (! SvOK(TARG) && ckWARN(WARN_UNINITIALIZED)) + report_uninit(TARG); + } + up = SvPV_force(TARG, len); if (len > 1) { if (DO_UTF8(TARG)) { /* first reverse each character */ @@ -4654,7 +4682,7 @@ PP(pp_split) I32 base; const I32 gimme = GIMME_V; const I32 oldsave = PL_savestack_ix; - I32 make_mortal = 1; + U32 make_mortal = SVs_TEMP; bool multiline = 0; MAGIC *mg = NULL; @@ -4753,9 +4781,8 @@ PP(pp_split) if (m >= strend) break; - dstr = newSVpvn_utf8(s, m-s, do_utf8); - if (make_mortal) - sv_2mortal(dstr); + dstr = newSVpvn_flags(s, m-s, + (do_utf8 ? SVf_UTF8 : 0) | make_mortal); XPUSHs(dstr); /* skip the whitespace found last */ @@ -4784,9 +4811,8 @@ PP(pp_split) m++; if (m >= strend) break; - dstr = newSVpvn_utf8(s, m-s, do_utf8); - if (make_mortal) - sv_2mortal(dstr); + dstr = newSVpvn_flags(s, m-s, + (do_utf8 ? SVf_UTF8 : 0) | make_mortal); XPUSHs(dstr); s = m; } @@ -4811,10 +4837,7 @@ PP(pp_split) /* keep track of how many bytes we skip over */ m = s; s += UTF8SKIP(s); - dstr = newSVpvn_utf8(m, s-m, TRUE); - - if (make_mortal) - sv_2mortal(dstr); + dstr = newSVpvn_flags(m, s-m, SVf_UTF8 | make_mortal); PUSHs(dstr); @@ -4852,9 +4875,8 @@ PP(pp_split) ; if (m >= strend) break; - dstr = newSVpvn_utf8(s, m-s, do_utf8); - if (make_mortal) - sv_2mortal(dstr); + dstr = newSVpvn_flags(s, m-s, + (do_utf8 ? SVf_UTF8 : 0) | make_mortal); XPUSHs(dstr); /* The rx->minlen is in characters but we want to step * s ahead by bytes. */ @@ -4869,9 +4891,8 @@ PP(pp_split) (m = fbm_instr((unsigned char*)s, (unsigned char*)strend, csv, multiline ? FBMrf_MULTILINE : 0)) ) { - dstr = newSVpvn_utf8(s, m-s, do_utf8); - if (make_mortal) - sv_2mortal(dstr); + dstr = newSVpvn_flags(s, m-s, + (do_utf8 ? SVf_UTF8 : 0) | make_mortal); XPUSHs(dstr); /* The rx->minlen is in characters but we want to step * s ahead by bytes. */ @@ -4902,9 +4923,8 @@ PP(pp_split) strend = s + (strend - m); } m = RX_OFFS(rx)[0].start + orig; - dstr = newSVpvn_utf8(s, m-s, do_utf8); - if (make_mortal) - sv_2mortal(dstr); + dstr = newSVpvn_flags(s, m-s, + (do_utf8 ? SVf_UTF8 : 0) | make_mortal); XPUSHs(dstr); if (RX_NPARENS(rx)) { I32 i; @@ -4916,12 +4936,12 @@ PP(pp_split) parens that didn't match -- they should be set to undef, not the empty string */ if (m >= orig && s >= orig) { - dstr = newSVpvn_utf8(s, m-s, do_utf8); + dstr = newSVpvn_flags(s, m-s, + (do_utf8 ? SVf_UTF8 : 0) + | make_mortal); } else dstr = &PL_sv_undef; /* undef, not "" */ - if (make_mortal) - sv_2mortal(dstr); XPUSHs(dstr); } } @@ -4936,9 +4956,7 @@ PP(pp_split) /* keep field after final delim? */ if (s < strend || (iters && origlimit)) { const STRLEN l = strend - s; - dstr = newSVpvn_utf8(s, l, do_utf8); - if (make_mortal) - sv_2mortal(dstr); + dstr = newSVpvn_flags(s, l, (do_utf8 ? SVf_UTF8 : 0) | make_mortal); XPUSHs(dstr); iters++; }