X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/f07626add3eda6dfda7c5f6fe05cbe1c9293ccd2..df70e763aeb1c1a87b080f81716c3769cc156280:/pp_ctl.c?ds=sidebyside diff --git a/pp_ctl.c b/pp_ctl.c index b8c0842..f8190e3 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -83,7 +83,7 @@ PP(pp_regcomp) REGEXP *re = NULL; REGEXP *new_re; const regexp_engine *eng; - bool is_bare_re; + bool is_bare_re= FALSE; if (PL_op->op_flags & OPf_STACKED) { dMARK; @@ -107,16 +107,29 @@ PP(pp_regcomp) assert (re != (REGEXP*) &PL_sv_undef); eng = re ? RX_ENGINE(re) : current_re_engine(); + /* + In the below logic: these are basically the same - check if this regcomp is part of a split. + + (PL_op->op_pmflags & PMf_split ) + (PL_op->op_next->op_type == OP_PUSHRE) + + We could add a new mask for this and copy the PMf_split, if we did + some bit definition fiddling first. + + For now we leave this + */ + new_re = (eng->op_comp ? eng->op_comp : &Perl_re_op_compile )(aTHX_ args, nargs, pm->op_code_list, eng, re, &is_bare_re, - (pm->op_pmflags & RXf_PMf_COMPILETIME), + (pm->op_pmflags & RXf_PMf_FLAGCOPYMASK), pm->op_pmflags | (PL_op->op_flags & OPf_SPECIAL ? PMf_USE_RE_EVAL : 0)); + if (pm->op_pmflags & PMf_HAS_CV) - ((struct regexp *)SvANY(new_re))->qr_anoncv + ReANY(new_re)->qr_anoncv = (CV*) SvREFCNT_inc(PAD_SV(PL_op->op_targ)); if (is_bare_re) { @@ -129,7 +142,7 @@ PP(pp_regcomp) some day. */ if (pm->op_type == OP_MATCH) { SV *lhs; - const bool was_tainted = PL_tainted; + const bool was_tainted = TAINT_get; if (pm->op_flags & OPf_STACKED) lhs = args[-1]; else if (pm->op_private & OPpTARGET_MY) @@ -138,22 +151,27 @@ PP(pp_regcomp) SvGETMAGIC(lhs); /* Restore the previous value of PL_tainted (which may have been modified by get-magic), to avoid incorrectly setting the - RXf_TAINTED flag further down. */ - PL_tainted = was_tainted; + RXf_TAINTED flag with RX_TAINT_on further down. */ + TAINT_set(was_tainted); +#if NO_TAINT_SUPPORT + PERL_UNUSED_VAR(was_tainted); +#endif } tmp = reg_temp_copy(NULL, new_re); ReREFCNT_dec(new_re); new_re = tmp; } + if (re != new_re) { ReREFCNT_dec(re); PM_SETRE(pm, new_re); } + #ifndef INCOMPLETE_TAINTS - if (PL_tainting && PL_tainted) { + if (TAINTING_get && TAINT_get) { SvTAINTED_on((SV*)new_re); - RX_EXTFLAGS(new_re) |= RXf_TAINTED; + RX_TAINT_on(new_re); } #endif @@ -196,7 +214,6 @@ PP(pp_substcont) } rxres_restore(&cx->sb_rxres, rx); - RX_MATCH_UTF8_set(rx, DO_UTF8(cx->sb_targ)); if (cx->sb_iters++) { const I32 saviters = cx->sb_iters; @@ -209,14 +226,10 @@ PP(pp_substcont) if (SvTAINTED(TOPs)) cx->sb_rxtainted |= SUBST_TAINT_REPL; sv_catsv_nomg(dstr, POPs); - /* XXX: adjust for positive offsets of \G for instance s/(.)\G//g with positive pos() */ - s -= RX_GOFS(rx); - - /* Are we done */ if (CxONCE(cx) || s < orig || - !CALLREGEXEC(rx, s, cx->sb_strend, orig, - (s == m) + RX_GOFS(rx), cx->sb_targ, NULL, - (REXEC_IGNOREPOS|REXEC_NOT_FIRST))) + !CALLREGEXEC(rx, s, cx->sb_strend, orig, + (s == m), cx->sb_targ, NULL, + (REXEC_IGNOREPOS|REXEC_NOT_FIRST|REXEC_FAIL_ON_UNDERFLOW))) { SV *targ = cx->sb_targ; @@ -237,12 +250,9 @@ PP(pp_substcont) targ = dstr; } else { - if (SvIsCOW(targ)) { - sv_force_normal_flags(targ, SV_COW_DROP_PV); - } else - { - SvPV_free(targ); - } + SV_CHECK_THINKFIRST_COW_DROP(targ); + if (isGV(targ)) Perl_croak_no_modify(); + SvPV_free(targ); SvPV_set(targ, SvPVX(dstr)); SvCUR_set(targ, SvCUR(dstr)); SvLEN_set(targ, SvLEN(dstr)); @@ -250,6 +260,7 @@ PP(pp_substcont) SvUTF8_on(targ); SvPV_set(dstr, NULL); + PL_tainted = 0; mPUSHi(saviters - 1); (void)SvPOK_only_UTF8(targ); @@ -258,7 +269,7 @@ PP(pp_substcont) /* update the taint state of various various variables in * preparation for final exit. * See "how taint works" above pp_subst() */ - if (PL_tainting) { + if (TAINTING_get) { if ((cx->sb_rxtainted & SUBST_TAINT_PAT) || ((cx->sb_rxtainted & (SUBST_TAINT_STR|SUBST_TAINT_RETAINT)) == (SUBST_TAINT_STR|SUBST_TAINT_RETAINT)) @@ -270,8 +281,10 @@ PP(pp_substcont) ) SvTAINTED_on(TOPs); /* taint return value */ /* needed for mg_set below */ - PL_tainted = cBOOL(cx->sb_rxtainted & - (SUBST_TAINT_STR|SUBST_TAINT_PAT|SUBST_TAINT_REPL)); + TAINT_set( + cBOOL(cx->sb_rxtainted & + (SUBST_TAINT_STR|SUBST_TAINT_PAT|SUBST_TAINT_REPL)) + ); SvTAINT(TARG); } /* PL_tainted must be correctly set for this mg_set */ @@ -279,6 +292,7 @@ PP(pp_substcont) TAINT_NOT; LEAVE_SCOPE(cx->sb_oldsave); POPSUBST(cx); + PERL_ASYNC_CHECK(); RETURNOP(pm->op_next); assert(0); /* NOTREACHED */ } @@ -304,14 +318,8 @@ PP(pp_substcont) SV * const sv = (pm->op_pmflags & PMf_NONDESTRUCT) ? cx->sb_dstr : cx->sb_targ; MAGIC *mg; - SvUPGRADE(sv, SVt_PVMG); - if (!(mg = mg_find(sv, PERL_MAGIC_regex_global))) { -#ifdef PERL_OLD_COPY_ON_WRITE - if (SvIsCOW(sv)) - sv_force_normal_flags(sv, 0); -#endif - mg = sv_magicext(sv, NULL, PERL_MAGIC_regex_global, &PL_vtbl_mglob, - NULL, 0); + if (!(mg = mg_find_mglob(sv))) { + mg = sv_magicext_mglob(sv); } mg->mg_len = m - orig; } @@ -320,7 +328,7 @@ PP(pp_substcont) /* update the taint state of various various variables in preparation * for calling the code block. * See "how taint works" above pp_subst() */ - if (PL_tainting) { + if (TAINTING_get) { if (RX_MATCH_TAINTED(rx)) /* run time pattern taint, eg locale */ cx->sb_rxtainted |= SUBST_TAINT_PAT; @@ -351,7 +359,7 @@ Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx) PERL_UNUSED_CONTEXT; if (!p || p[1] < RX_NPARENS(rx)) { -#ifdef PERL_OLD_COPY_ON_WRITE +#ifdef PERL_ANY_COW i = 7 + (RX_NPARENS(rx)+1) * 2; #else i = 6 + (RX_NPARENS(rx)+1) * 2; @@ -368,7 +376,7 @@ Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx) RX_MATCH_COPIED_off(rx); *p++ = RX_NPARENS(rx); -#ifdef PERL_OLD_COPY_ON_WRITE +#ifdef PERL_ANY_COW *p++ = PTR2UV(RX_SAVED_COPY(rx)); RX_SAVED_COPY(rx) = NULL; #endif @@ -397,7 +405,7 @@ S_rxres_restore(pTHX_ void **rsp, REGEXP *rx) *p++ = 0; RX_NPARENS(rx) = *p++; -#ifdef PERL_OLD_COPY_ON_WRITE +#ifdef PERL_ANY_COW if (RX_SAVED_COPY(rx)) SvREFCNT_dec (RX_SAVED_COPY(rx)); RX_SAVED_COPY(rx) = INT2PTR(SV*,*p); @@ -425,14 +433,14 @@ S_rxres_free(pTHX_ void **rsp) if (p) { void *tmp = INT2PTR(char*,*p); #ifdef PERL_POISON -#ifdef PERL_OLD_COPY_ON_WRITE +#ifdef PERL_ANY_COW U32 i = 9 + p[1] * 2; #else U32 i = 8 + p[1] * 2; #endif #endif -#ifdef PERL_OLD_COPY_ON_WRITE +#ifdef PERL_ANY_COW SvREFCNT_dec (INT2PTR(SV*,p[2])); #endif #ifdef PERL_POISON @@ -978,6 +986,10 @@ PP(pp_grepstart) SAVEVPTR(PL_curpm); src = PL_stack_base[*PL_markstack_ptr]; + if (SvPADTMP(src) && !IS_PADGV(src)) { + src = PL_stack_base[*PL_markstack_ptr] = sv_mortalcopy(src); + PL_tmps_floor++; + } SvTEMP_off(src); if (PL_op->op_private & OPpGREP_LEX) PAD_SVl(PL_op->op_targ) = src; @@ -1126,6 +1138,7 @@ PP(pp_mapwhile) /* set $_ to the new source item */ src = PL_stack_base[PL_markstack_ptr[-1]]; + if (SvPADTMP(src) && !IS_PADGV(src)) src = sv_mortalcopy(src); SvTEMP_off(src); if (PL_op->op_private & OPpGREP_LEX) PAD_SVl(PL_op->op_targ) = src; @@ -1420,8 +1433,14 @@ S_dopoptosub_at(pTHX_ const PERL_CONTEXT *cxstk, I32 startingblock) switch (CxTYPE(cx)) { default: continue; - case CXt_EVAL: case CXt_SUB: + /* in sub foo { /(?{...})/ }, foo ends up on the CX stack + * twice; the first for the normal foo() call, and the second + * for a faked up re-entry into the sub to execute the + * code block. Hide this faked entry from the world. */ + if (cx->cx_type & CXp_SUB_RE_FAKE) + continue; + case CXt_EVAL: case CXt_FORMAT: DEBUG_l( Perl_deb(aTHX_ "(dopoptosub_at(): found sub at cx=%ld)\n", (long)i)); return i; @@ -1635,6 +1654,11 @@ Perl_die_unwind(pTHX_ SV *msv) sv_setsv(ERRSV, exceptsv); } + if (in_eval & EVAL_KEEPERR) { + Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "\t(in cleanup) %"SVf, + SVfARG(exceptsv)); + } + while ((cxix = dopoptoeval(cxstack_ix)) < 0 && PL_curstackinfo->si_prev) { @@ -1693,13 +1717,8 @@ Perl_die_unwind(pTHX_ SV *msv) SVfARG(exceptsv ? exceptsv : newSVpvs_flags("Unknown error\n", SVs_TEMP))); } - if (in_eval & EVAL_KEEPERR) { - Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "\t(in cleanup) %"SVf, - SVfARG(exceptsv)); - } - else { + if (!(in_eval & EVAL_KEEPERR)) sv_setsv(ERRSV, exceptsv); - } PL_restartjmpenv = restartjmpenv; PL_restartop = restartop; JMPENV_JUMP(3); @@ -1896,9 +1915,6 @@ PP(pp_caller) Copy(AvALLOC(ary), AvARRAY(PL_dbargs), AvFILLp(ary) + 1 + off, SV*); AvFILLp(PL_dbargs) = AvFILLp(ary) + off; } - /* XXX only hints propagated via op_private are currently - * visible (others are not easily accessible, since they - * use the global PL_hints) */ mPUSHi(CopHINTS_get(cx->blk_oldcop)); { SV * mask ; @@ -1936,9 +1952,13 @@ PP(pp_reset) { dVAR; dSP; - const char * const tmps = - (MAXARG < 1 || (!TOPs && !POPs)) ? (const char *)"" : POPpconstx; - sv_reset(tmps, CopSTASH(PL_curcop)); + const char * tmps; + STRLEN len = 0; + if (MAXARG < 1 || (!TOPs && !POPs)) + tmps = NULL, len = 0; + else + tmps = SvPVx_const(POPs, len); + sv_resetpvn(tmps, len, CopSTASH(PL_curcop)); PUSHs(&PL_sv_yes); RETURN; } @@ -1963,9 +1983,12 @@ PP(pp_dbstate) const I32 gimme = G_ARRAY; U8 hasargs; GV * const gv = PL_DBgv; - CV * const cv = GvCV(gv); + CV * cv = NULL; - if (!cv) + if (gv && isGV_with_GP(gv)) + cv = GvCV(gv); + + if (!cv || (!CvROOT(cv) && !CvXSUB(cv))) DIE(aTHX_ "No DB::DB routine defined"); if (CvDEPTH(cv) >= 1 && !(PL_debug & DEBUG_DB_RECURSE_FLAG)) @@ -1993,8 +2016,12 @@ PP(pp_dbstate) PUSHSUB_DB(cx); cx->blk_sub.retop = PL_op->op_next; CvDEPTH(cv)++; + if (CvDEPTH(cv) >= 2) { + PERL_STACK_OVERFLOW_CHECK(); + pad_push(CvPADLIST(cv), CvDEPTH(cv)); + } SAVECOMPPAD(); - PAD_SET_CUR_NOSAVE(CvPADLIST(cv), 1); + PAD_SET_CUR_NOSAVE(CvPADLIST(cv), CvDEPTH(cv)); RETURNOP(CvSTART(cv)); } } @@ -2650,6 +2677,7 @@ PP(pp_next) if (PL_scopestack_ix < inner) leave_scope(PL_scopestack[PL_scopestack_ix]); PL_curcop = cx->blk_oldcop; + PERL_ASYNC_CHECK(); return (cx)->blk_loop.my_op->op_nextop; } @@ -2673,6 +2701,7 @@ PP(pp_redo) LEAVE_SCOPE(oldsave); FREETMPS; PL_curcop = cx->blk_oldcop; + PERL_ASYNC_CHECK(); return redo_op; } @@ -2681,12 +2710,12 @@ S_dofindlabel(pTHX_ OP *o, const char *label, STRLEN len, U32 flags, OP **opstac { dVAR; OP **ops = opstack; - static const char too_deep[] = "Target of goto is too deeply nested"; + static const char* const too_deep = "Target of goto is too deeply nested"; PERL_ARGS_ASSERT_DOFINDLABEL; if (ops >= oplimit) - Perl_croak(aTHX_ too_deep); + Perl_croak(aTHX_ "%s", too_deep); if (o->op_type == OP_LEAVE || o->op_type == OP_SCOPE || o->op_type == OP_LEAVELOOP || @@ -2695,7 +2724,7 @@ S_dofindlabel(pTHX_ OP *o, const char *label, STRLEN len, U32 flags, OP **opstac { *ops++ = cUNOPo->op_first; if (ops >= oplimit) - Perl_croak(aTHX_ too_deep); + Perl_croak(aTHX_ "%s", too_deep); } *ops = 0; if (o->op_flags & OPf_KIDS) { @@ -2753,20 +2782,19 @@ PP(pp_goto) STRLEN label_len = 0; U32 label_flags = 0; const bool do_dump = (PL_op->op_type == OP_DUMP); - static const char must_have_label[] = "goto must have label"; + static const char* const must_have_label = "goto must have label"; if (PL_op->op_flags & OPf_STACKED) { SV * const sv = POPs; + SvGETMAGIC(sv); /* This egregious kludge implements goto &subroutine */ if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) { I32 cxix; PERL_CONTEXT *cx; CV *cv = MUTABLE_CV(SvRV(sv)); - SV** mark; - I32 items = 0; + AV *arg = GvAV(PL_defgv); I32 oldsave; - bool reified = 0; retry: if (!CvROOT(cv) && !CvXSUB(cv)) { @@ -2793,14 +2821,18 @@ PP(pp_goto) SvREFCNT_inc_simple_void(cv); /* avoid premature free during unwind */ FREETMPS; cxix = dopoptosub(cxstack_ix); - if (cxix < 0) - DIE(aTHX_ "Can't goto subroutine outside a subroutine"); - if (cxix < cxstack_ix) + if (cxix < cxstack_ix) { + if (cxix < 0) { + SvREFCNT_dec(cv); + DIE(aTHX_ "Can't goto subroutine outside a subroutine"); + } dounwind(cxix); + } TOPBLOCK(cx); SPAGAIN; /* ban goto in eval: see <20050521150056.GC20213@iabyn.com> */ if (CxTYPE(cx) == CXt_EVAL) { + SvREFCNT_dec(cv); if (CxREALEVAL(cx)) /* diag_listed_as: Can't goto subroutine from an eval-%s */ DIE(aTHX_ "Can't goto subroutine from an eval-string"); @@ -2809,35 +2841,25 @@ PP(pp_goto) DIE(aTHX_ "Can't goto subroutine from an eval-block"); } else if (CxMULTICALL(cx)) + { + SvREFCNT_dec(cv); DIE(aTHX_ "Can't goto subroutine from a sort sub (or similar callback)"); + } if (CxTYPE(cx) == CXt_SUB && CxHASARGS(cx)) { - /* put @_ back onto stack */ AV* av = cx->blk_sub.argarray; - items = AvFILLp(av) + 1; - EXTEND(SP, items+1); /* @_ could have been extended. */ - Copy(AvARRAY(av), SP + 1, items, SV*); - SvREFCNT_dec(GvAV(PL_defgv)); - GvAV(PL_defgv) = cx->blk_sub.savearray; - CLEAR_ARGARRAY(av); - /* abandon @_ if it got reified */ - if (AvREAL(av)) { - reified = 1; + /* abandon the original @_ if it got reified or if it is + the same as the current @_ */ + if (AvREAL(av) || av == arg) { SvREFCNT_dec(av); av = newAV(); - av_extend(av, items-1); AvREIFY_only(av); PAD_SVl(0) = MUTABLE_SV(cx->blk_sub.argarray = av); } + else CLEAR_ARGARRAY(av); } - else if (CvISXSUB(cv)) { /* put GvAV(defgv) back onto stack */ - AV* const av = GvAV(PL_defgv); - items = AvFILLp(av) + 1; - EXTEND(SP, items+1); /* @_ could have been extended. */ - Copy(AvARRAY(av), SP + 1, items, SV*); - } - mark = SP; - SP += items; + /* We donate this refcount later to the callee’s pad. */ + SvREFCNT_inc_simple_void(arg); if (CxTYPE(cx) == CXt_SUB && !(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth)) SvREFCNT_dec(cx->blk_sub.cv); @@ -2848,6 +2870,7 @@ PP(pp_goto) * our precious cv. See bug #99850. */ if (!CvROOT(cv) && !CvXSUB(cv)) { const GV * const gv = CvGV(cv); + SvREFCNT_dec(arg); if (gv) { SV * const tmpstr = sv_newmortal(); gv_efullname3(tmpstr, gv, NULL); @@ -2862,12 +2885,30 @@ PP(pp_goto) SAVEFREESV(cv); /* later, undo the 'avoid premature free' hack */ if (CvISXSUB(cv)) { OP* const retop = cx->blk_sub.retop; - SV **newsp PERL_UNUSED_DECL; - I32 gimme PERL_UNUSED_DECL; - if (reified) { + SV **newsp; + I32 gimme; + const SSize_t items = AvFILLp(arg) + 1; + SV** mark; + + PERL_UNUSED_VAR(newsp); + PERL_UNUSED_VAR(gimme); + + /* put GvAV(defgv) back onto stack */ + EXTEND(SP, items+1); /* @_ could have been extended. */ + Copy(AvARRAY(arg), SP + 1, items, SV*); + mark = SP; + SP += items; + if (AvREAL(arg)) { I32 index; for (index=0; indexblk_sub.savearray; + SvREFCNT_dec(arg); } /* XS subs don't have a CxSUB, so pop it */ @@ -2877,15 +2918,11 @@ PP(pp_goto) PUTBACK; (void)(*CvXSUB(cv))(aTHX_ cv); LEAVE; + PERL_ASYNC_CHECK(); return retop; } else { PADLIST * const padlist = CvPADLIST(cv); - if (CxTYPE(cx) == CXt_EVAL) { - PL_in_eval = CxOLD_IN_EVAL(cx); - PL_eval_root = cx->blk_eval.old_eval_root; - cx->cx_type = CXt_SUB; - } cx->blk_sub.cv = cv; cx->blk_sub.olddepth = CvDEPTH(cv); @@ -2902,41 +2939,26 @@ PP(pp_goto) PAD_SET_CUR_NOSAVE(padlist, CvDEPTH(cv)); if (CxHASARGS(cx)) { - AV *const av = MUTABLE_AV(PAD_SVl(0)); - - cx->blk_sub.savearray = GvAV(PL_defgv); - GvAV(PL_defgv) = MUTABLE_AV(SvREFCNT_inc_simple(av)); CX_CURPAD_SAVE(cx->blk_sub); - cx->blk_sub.argarray = av; - if (items >= AvMAX(av) + 1) { - SV **ary = AvALLOC(av); - if (AvARRAY(av) != ary) { - AvMAX(av) += AvARRAY(av) - AvALLOC(av); - AvARRAY(av) = ary; - } - if (items >= AvMAX(av) + 1) { - AvMAX(av) = items - 1; - Renew(ary,items+1,SV*); - AvALLOC(av) = ary; - AvARRAY(av) = ary; - } - } - ++mark; - Copy(mark,AvARRAY(av),items,SV*); - AvFILLp(av) = items - 1; - assert(!AvREAL(av)); - if (reified) { - /* transfer 'ownership' of refcnts to new @_ */ - AvREAL_on(av); - AvREIFY_off(av); - } - while (items--) { - if (*mark) - SvTEMP_off(*mark); - mark++; + /* cx->blk_sub.argarray has no reference count, so we + need something to hang on to our argument array so + that cx->blk_sub.argarray does not end up pointing + to freed memory as the result of undef *_. So put + it in the callee’s pad, donating our refer- + ence count. */ + SvREFCNT_dec(PAD_SVl(0)); + PAD_SVl(0) = (SV *)(cx->blk_sub.argarray = arg); + + /* GvAV(PL_defgv) might have been modified on scope + exit, so restore it. */ + if (arg != GvAV(PL_defgv)) { + AV * const av = GvAV(PL_defgv); + GvAV(PL_defgv) = (AV *)SvREFCNT_inc_simple(arg); + SvREFCNT_dec(av); } } + else SvREFCNT_dec(arg); if (PERLDB_SUB) { /* Checking curstash breaks DProf. */ Perl_get_db_sub(aTHX_ NULL, cv); if (PERLDB_GOTO) { @@ -2948,11 +2970,12 @@ PP(pp_goto) } } } + PERL_ASYNC_CHECK(); RETURNOP(CvSTART(cv)); } } else { - label = SvPV_const(sv, label_len); + label = SvPV_nomg_const(sv, label_len); label_flags = SvUTF8(sv); } } @@ -2961,7 +2984,7 @@ PP(pp_goto) label_flags = (cPVOP->op_private & OPpPV_IS_UTF8) ? SVf_UTF8 : 0; label_len = strlen(label); } - if (!(do_dump || label_len)) DIE(aTHX_ must_have_label); + if (!(do_dump || label_len)) DIE(aTHX_ "%s", must_have_label); PERL_ASYNC_CHECK(); @@ -3039,9 +3062,8 @@ PP(pp_goto) PL_lastgotoprobe = gotoprobe; } if (!retop) - DIE(aTHX_ "Can't find label %"SVf, - SVfARG(newSVpvn_flags(label, label_len, - SVs_TEMP | label_flags))); + DIE(aTHX_ "Can't find label %"UTF8f, + UTF8fARG(label_flags, label_len, label)); /* if we're leaving an eval, check before we pop any frames that we're not going to punt, otherwise the error @@ -3103,6 +3125,7 @@ PP(pp_goto) PL_do_undump = FALSE; } + PERL_ASYNC_CHECK(); RETURNOP(retop); } @@ -3248,7 +3271,11 @@ Perl_find_runcv_where(pTHX_ U8 cond, IV arg, U32 *db_seqp) int level = 0; if (db_seqp) - *db_seqp = PL_curcop->cop_seq; + *db_seqp = + PL_curcop == &PL_compiling + ? PL_cop_seqmax + : PL_curcop->cop_seq; + for (si = PL_curstackinfo; si; si = si->si_prev) { I32 ix; for (ix = si->si_cxix; ix >= 0; ix--) { @@ -3261,6 +3288,8 @@ Perl_find_runcv_where(pTHX_ U8 cond, IV arg, U32 *db_seqp) *db_seqp = cx->blk_oldcop->cop_seq; continue; } + if (cx->cx_type & CXp_SUB_RE) + continue; } else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx)) cv = cx->blk_eval.cv; @@ -3268,7 +3297,8 @@ Perl_find_runcv_where(pTHX_ U8 cond, IV arg, U32 *db_seqp) switch (cond) { case FIND_RUNCV_padid_eq: if (!CvPADLIST(cv) - || CvPADLIST(cv)->xpadl_id != (U32)arg) continue; + || PadlistNAMES(CvPADLIST(cv)) != INT2PTR(PADNAMELIST *, arg)) + continue; return cv; case FIND_RUNCV_level_eq: if (level++ != arg) continue; @@ -3339,7 +3369,9 @@ S_doeval(pTHX_ int gimme, CV* outside, U32 seq, HV *hh) PL_in_eval = (in_require ? (EVAL_INREQUIRE | (PL_in_eval & EVAL_INEVAL)) - : EVAL_INEVAL); + : (EVAL_INEVAL | + ((PL_op->op_private & OPpEVAL_RE_REPARSING) + ? EVAL_RE_REPARSING : 0))); PUSHMARK(SP); @@ -3365,7 +3397,9 @@ S_doeval(pTHX_ int gimme, CV* outside, U32 seq, HV *hh) if (CopSTASH_ne(PL_curcop, PL_curstash)) { SAVEGENERICSV(PL_curstash); - PL_curstash = (HV *)SvREFCNT_inc_simple(CopSTASH(PL_curcop)); + PL_curstash = (HV *)CopSTASH(PL_curcop); + if (SvTYPE(PL_curstash) != SVt_PVHV) PL_curstash = NULL; + else SvREFCNT_inc_simple_void(PL_curstash); } /* XXX:ajgo do we really need to alloc an AV for begin/checkunit */ SAVESPTR(PL_beginav); @@ -3401,6 +3435,15 @@ S_doeval(pTHX_ int gimme, CV* outside, U32 seq, HV *hh) else { PL_hints = saveop->op_private & OPpEVAL_COPHH ? oldcurcop->cop_hints : saveop->op_targ; + + /* making 'use re eval' not be in scope when compiling the + * qr/mabye_has_runtime_code_block/ ensures that we don't get + * infinite recursion when S_has_runtime_code() gives a false + * positive: the second time round, HINT_RE_EVAL isn't set so we + * don't bother calling S_has_runtime_code() */ + if (PL_in_eval & EVAL_RE_REPARSING) + PL_hints &= ~HINT_RE_EVAL; + if (hh) { /* SAVEHINTS created a new HV in PL_hintgv, which we need to GC */ SvREFCNT_dec(GvHV(PL_hintgv)); @@ -3445,6 +3488,7 @@ S_doeval(pTHX_ int gimme, CV* outside, U32 seq, HV *hh) PERL_CONTEXT *cx; I32 optype; /* Used by POPEVAL. */ SV *namesv; + SV *errsv = NULL; cx = NULL; namesv = NULL; @@ -3456,7 +3500,6 @@ S_doeval(pTHX_ int gimme, CV* outside, U32 seq, HV *hh) PL_op = saveop; if (yystatus != 3) { if (PL_eval_root) { - cv_forget_slab(evalcv); op_free(PL_eval_root); PL_eval_root = NULL; } @@ -3468,6 +3511,7 @@ S_doeval(pTHX_ int gimme, CV* outside, U32 seq, HV *hh) LEAVE_with_name("eval"); /* pp_entereval knows about this LEAVE. */ } + errsv = ERRSV; if (in_require) { if (!cx) { /* If cx is still NULL, it means that we didn't go in the @@ -3481,13 +3525,13 @@ S_doeval(pTHX_ int gimme, CV* outside, U32 seq, HV *hh) SvUTF8(namesv) ? -(I32)SvCUR(namesv) : (I32)SvCUR(namesv), &PL_sv_undef, 0); Perl_croak(aTHX_ "%"SVf"Compilation failed in require", - SVfARG(ERRSV - ? ERRSV + SVfARG(errsv + ? errsv : newSVpvs_flags("Unknown error\n", SVs_TEMP))); } else { - if (!*(SvPVx_nolen_const(ERRSV))) { - sv_setpvs(ERRSV, "Compilation error"); + if (!*(SvPV_nolen_const(errsv))) { + sv_setpvs(errsv, "Compilation error"); } } if (gimme != G_ARRAY) PUSHs(&PL_sv_undef); @@ -3577,6 +3621,32 @@ S_doopen_pm(pTHX_ SV *name) # define doopen_pm(name) check_type_and_open(name) #endif /* !PERL_DISABLE_PMC */ +/* require doesn't search for absolute names, or when the name is + explicity relative the current directory */ +PERL_STATIC_INLINE bool +S_path_is_searchable(const char *name) +{ + PERL_ARGS_ASSERT_PATH_IS_SEARCHABLE; + + if (PERL_FILE_IS_ABSOLUTE(name) +#ifdef WIN32 + || (*name == '.' && ((name[1] == '/' || + (name[1] == '.' && name[2] == '/')) + || (name[1] == '\\' || + ( name[1] == '.' && name[2] == '\\'))) + ) +#else + || (*name == '.' && (name[1] == '/' || + (name[1] == '.' && name[2] == '/'))) +#endif + ) + { + return FALSE; + } + else + return TRUE; +} + PP(pp_require) { dVAR; dSP; @@ -3604,11 +3674,12 @@ PP(pp_require) SV *encoding; OP *op; int saved_errno; + bool path_searchable; sv = POPs; if ( (SvNIOKp(sv) || SvVOK(sv)) && PL_op->op_type != OP_DOFILE) { sv = sv_2mortal(new_version(sv)); - if (!sv_derived_from(PL_patchlevel, "version")) + if (!Perl_sv_derived_from_pvn(aTHX_ PL_patchlevel, STR_WITH_LEN("version"), 0)) upg_version(PL_patchlevel, TRUE); if (cUNOP->op_first->op_type == OP_CONST && cUNOP->op_first->op_private & OPpCONST_NOVER) { if ( vcmp(sv,PL_patchlevel) <= 0 ) @@ -3668,6 +3739,7 @@ PP(pp_require) DIE(aTHX_ "Null filename used"); TAINT_PROPER("require"); + path_searchable = path_is_searchable(name); #ifdef VMS /* The key in the %ENV hash is in the syntax of file passed as the argument @@ -3707,12 +3779,12 @@ PP(pp_require) /* prepare to compile file */ - if (path_is_absolute(name)) { + if (!path_searchable) { /* At this point, name is SvPVX(sv) */ tryname = name; tryrsfp = doopen_pm(sv); } - if (!tryrsfp && !(errno == EACCES && path_is_absolute(name))) { + if (!tryrsfp && !(errno == EACCES && !path_searchable)) { AV * const ar = GvAVn(PL_incgv); I32 i; #ifdef VMS @@ -3765,7 +3837,6 @@ PP(pp_require) if (SvROK(arg) && (SvTYPE(SvRV(arg)) <= SVt_PVLV) && !isGV_with_GP(SvRV(arg))) { filter_cache = SvRV(arg); - SvREFCNT_inc_simple_void_NN(filter_cache); if (i < count) { arg = SP[i++]; @@ -3828,10 +3899,7 @@ PP(pp_require) } filter_has_file = 0; - if (filter_cache) { - SvREFCNT_dec(filter_cache); - filter_cache = NULL; - } + filter_cache = NULL; if (filter_state) { SvREFCNT_dec(filter_state); filter_state = NULL; @@ -3842,8 +3910,7 @@ PP(pp_require) } } else { - if (!path_is_absolute(name) - ) { + if (path_searchable) { const char *dir; STRLEN dirlen; @@ -3884,7 +3951,12 @@ PP(pp_require) memcpy(tmp, dir, dirlen); tmp +=dirlen; - *tmp++ = '/'; + + /* Avoid '//' */ + if (!dirlen || *(tmp-1) != '/') { + *tmp++ = '/'; + } + /* name came from an SV, so it will have a '\0' at the end that we can copy as part of this memcpy(). */ memcpy(tmp, name, len + 1); @@ -3900,7 +3972,7 @@ PP(pp_require) if (tryrsfp) { if (tryname[0] == '.' && tryname[1] == '/') { ++tryname; - while (*++tryname == '/'); + while (*++tryname == '/') {} } break; } @@ -3928,22 +4000,36 @@ PP(pp_require) if (namesv) { /* did we lookup @INC? */ AV * const ar = GvAVn(PL_incgv); I32 i; + SV *const msg = newSVpvs_flags("", SVs_TEMP); SV *const inc = newSVpvs_flags("", SVs_TEMP); for (i = 0; i <= AvFILL(ar); i++) { sv_catpvs(inc, " "); sv_catsv(inc, *av_fetch(ar, i, TRUE)); } + if (len >= 4 && memEQ(name + len - 3, ".pm", 4)) { + const char *c, *e = name + len - 3; + sv_catpv(msg, " (you may need to install the "); + for (c = name; c < e; c++) { + if (*c == '/') { + sv_catpvn(msg, "::", 2); + } + else { + sv_catpvn(msg, c, 1); + } + } + sv_catpv(msg, " module)"); + } + else if (len >= 2 && memEQ(name + len - 2, ".h", 3)) { + sv_catpv(msg, " (change .h to .ph maybe?) (did you run h2ph?)"); + } + else if (len >= 3 && memEQ(name + len - 3, ".ph", 4)) { + sv_catpv(msg, " (did you run h2ph?)"); + } /* diag_listed_as: Can't locate %s */ DIE(aTHX_ - "Can't locate %s in @INC%s%s (@INC contains:%" SVf ")", - name, - (len >= 2 && memEQ(name + len - 2, ".h", 3) - ? " (change .h to .ph maybe?) (did you run h2ph?)" : ""), - (len >= 3 && memEQ(name + len - 3, ".ph", 4) - ? " (did you run h2ph?)" : ""), - inc - ); + "Can't locate %s in @INC%" SVf " (@INC contains:%" SVf ")", + name, msg, inc); } } DIE(aTHX_ "Can't locate %s", name); @@ -3979,7 +4065,10 @@ PP(pp_require) than hanging another SV from it. In turn, filter_add() optionally takes the SV to use as the filter (or creates a new SV if passed NULL), so simply pass in whatever value filter_cache has. */ - SV * const datasv = filter_add(S_run_user_filter, filter_cache); + SV * const fc = filter_cache ? newSV(0) : NULL; + SV *datasv; + if (fc) sv_copypv(fc, filter_cache); + datasv = filter_add(S_run_user_filter, fc); IoLINES(datasv) = filter_has_file; IoTOP_GV(datasv) = MUTABLE_GV(filter_state); IoBOTTOM_GV(datasv) = MUTABLE_GV(filter_sub); @@ -4916,10 +5005,13 @@ PP(pp_leavewhen) leave_scope(PL_scopestack[PL_scopestack_ix]); PL_curcop = cx->blk_oldcop; + PERL_ASYNC_CHECK(); return cx->blk_loop.my_op->op_nextop; } - else + else { + PERL_ASYNC_CHECK(); RETURNOP(cx->blk_givwhen.leave_op); + } } PP(pp_continue) @@ -5351,11 +5443,14 @@ S_run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen) if (count > 0) { SV *out = POPs; + SvGETMAGIC(out); if (SvOK(out)) { status = SvIV(out); } - else if (SvTRUE(ERRSV)) { - err = newSVsv(ERRSV); + else { + SV * const errsv = ERRSV; + if (SvTRUE_NN(errsv)) + err = newSVsv(errsv); } } @@ -5364,8 +5459,13 @@ S_run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen) LEAVE_with_name("call_filter_sub"); } + if (SvGMAGICAL(upstream)) { + mg_get(upstream); + if (upstream == buf_sv) mg_free(buf_sv); + } + if (SvIsCOW(upstream)) sv_force_normal(upstream); if(!err && SvOK(upstream)) { - got_p = SvPV(upstream, got_len); + got_p = SvPV_nomg(upstream, got_len); if (umaxlen) { if (got_len > umaxlen) { prune_from = got_p + umaxlen; @@ -5396,7 +5496,12 @@ S_run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen) if (SvUTF8(upstream)) { SvUTF8_on(cache); } - SvCUR_set(upstream, got_len - cached_len); + if (SvPOK(upstream)) SvCUR_set(upstream, got_len - cached_len); + else + /* Cannot just use sv_setpvn, as that could free the buffer + before we have a chance to assign it. */ + sv_usepvn(upstream, savepvn(got_p, got_len - cached_len), + got_len - cached_len); *prune_from = 0; /* Can't yet be EOF */ if (status == 0) @@ -5408,9 +5513,10 @@ S_run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen) concatenate it then we get a warning about use of uninitialised value. */ if (!err && upstream != buf_sv && - (SvOK(upstream) || SvGMAGICAL(upstream))) { - sv_catsv(buf_sv, upstream); + SvOK(upstream)) { + sv_catsv_nomg(buf_sv, upstream); } + else if (SvOK(upstream)) (void)SvPV_force_nolen(buf_sv); if (status <= 0) { IoLINES(datasv) = 0; @@ -5437,32 +5543,6 @@ S_run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen) return status; } -/* perhaps someone can come up with a better name for - this? it is not really "absolute", per se ... */ -static bool -S_path_is_absolute(const char *name) -{ - PERL_ARGS_ASSERT_PATH_IS_ABSOLUTE; - - if (PERL_FILE_IS_ABSOLUTE(name) -#ifdef WIN32 - || (*name == '.' && ((name[1] == '/' || - (name[1] == '.' && name[2] == '/')) - || (name[1] == '\\' || - ( name[1] == '.' && name[2] == '\\'))) - ) -#else - || (*name == '.' && (name[1] == '/' || - (name[1] == '.' && name[2] == '/'))) -#endif - ) - { - return TRUE; - } - else - return FALSE; -} - /* * Local variables: * c-indentation-style: bsd