X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pp_ctl.c;h=e9b4bfc79cea3f21d97b63f963d1bead4162d43f;hb=6abfca009fc00780b1546304f40b7d5b81f3cb76;hp=f4364acdb710a96faaf25b66f700e07f00fd3783;hpb=502c6561fcd473b7da3277363169d75f16ac2f8b;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pp_ctl.c b/pp_ctl.c index f4364ac..e9b4bfc 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -9,12 +9,14 @@ */ /* - * Now far ahead the Road has gone, - * And I must follow, if I can, - * Pursuing it with eager feet, - * Until it joins some larger way - * Where many paths and errands meet. - * And whither then? I cannot say. + * Now far ahead the Road has gone, + * And I must follow, if I can, + * Pursuing it with eager feet, + * Until it joins some larger way + * Where many paths and errands meet. + * And whither then? I cannot say. + * + * [Bilbo on p.35 of _The Lord of the Rings_, I/i: "A Long-Expected Party"] */ /* This file contains control-oriented pp ("push/pop") functions that @@ -95,7 +97,7 @@ PP(pp_regcomp) /* multiple args; concatentate them */ dMARK; dORIGMARK; tmpstr = PAD_SV(ARGTARG); - sv_setpvn(tmpstr, "", 0); + sv_setpvs(tmpstr, ""); while (++MARK <= SP) { if (PL_amagic_generation) { SV *sv; @@ -355,8 +357,8 @@ Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx) } } -void -Perl_rxres_restore(pTHX_ void **rsp, REGEXP *rx) +static void +S_rxres_restore(pTHX_ void **rsp, REGEXP *rx) { UV *p = (UV*)*rsp; U32 i; @@ -385,8 +387,8 @@ Perl_rxres_restore(pTHX_ void **rsp, REGEXP *rx) } } -void -Perl_rxres_free(pTHX_ void **rsp) +static void +S_rxres_free(pTHX_ void **rsp) { UV * const p = (UV*)*rsp; @@ -986,7 +988,7 @@ PP(pp_grepstart) if (PL_op->op_private & OPpGREP_LEX) PAD_SVl(PL_op->op_targ) = src; else - DEFSV = src; + DEFSV_set(src); PUTBACK; if (PL_op->op_type == OP_MAPSTART) @@ -1097,7 +1099,7 @@ PP(pp_mapwhile) if (PL_op->op_private & OPpGREP_LEX) PAD_SVl(PL_op->op_targ) = src; else - DEFSV = src; + DEFSV_set(src); RETURNOP(cLOGOP->op_other); } @@ -1154,7 +1156,7 @@ PP(pp_flip) RETURNOP(((LOGOP*)cUNOP->op_first)->op_other); } } - sv_setpvn(TARG, "", 0); + sv_setpvs(TARG, ""); SETs(targ); RETURN; } @@ -1537,7 +1539,7 @@ Perl_die_where(pTHX_ const char *message, STRLEN msglen) SV * const err = ERRSV; const char *e = NULL; if (!SvPOK(err)) - sv_setpvn(err,"",0); + sv_setpvs(err,""); else if (SvCUR(err) >= sizeof(prefix)+msglen-1) { STRLEN len; e = SvPV_const(err, len); @@ -1551,7 +1553,8 @@ Perl_die_where(pTHX_ const char *message, STRLEN msglen) sv_catpvn(err, message, msglen); if (ckWARN(WARN_MISC)) { const STRLEN start = SvCUR(err)-msglen-sizeof(prefix)+1; - Perl_warner(aTHX_ packWARN(WARN_MISC), SvPVX_const(err)+start); + Perl_warner(aTHX_ packWARN(WARN_MISC), "%s", + SvPVX_const(err)+start); } } } @@ -1791,8 +1794,8 @@ PP(pp_caller) PUSHs(cx->blk_oldcop->cop_hints_hash ? sv_2mortal(newRV_noinc( - (SV*)Perl_refcounted_he_chain_2hv(aTHX_ - cx->blk_oldcop->cop_hints_hash))) + MUTABLE_SV(Perl_refcounted_he_chain_2hv(aTHX_ + cx->blk_oldcop->cop_hints_hash)))) : &PL_sv_undef); RETURN; } @@ -1894,7 +1897,7 @@ PP(pp_enteriter) #endif } else { - GV * const gv = (GV*)POPs; + GV * const gv = MUTABLE_GV(POPs); svp = &GvSV(gv); /* symbol table variable */ SAVEGENERICSV(*svp); *svp = newSV(0); @@ -2474,7 +2477,7 @@ PP(pp_goto) av = newAV(); av_extend(av, items-1); AvREIFY_only(av); - PAD_SVl(0) = (SV*)(cx->blk_sub.argarray = av); + PAD_SVl(0) = MUTABLE_SV(cx->blk_sub.argarray = av); } } else if (CvISXSUB(cv)) { /* put GvAV(defgv) back onto stack */ @@ -2576,7 +2579,7 @@ PP(pp_goto) CV * const gotocv = get_cv("DB::goto", FALSE); if (gotocv) { PUSHMARK( PL_stack_sp ); - call_sv((SV*)gotocv, G_SCALAR | G_NODEBUG); + call_sv(MUTABLE_SV(gotocv), G_SCALAR | G_NODEBUG); PL_stack_sp--; } } @@ -2761,7 +2764,7 @@ S_save_lines(pTHX_ AV *array, SV *sv) const char *t; SV * const tmpstr = newSV_type(SVt_PVMG); - t = strchr(s, '\n'); + t = (const char *)memchr(s, '\n', send - s); if (t) t++; else @@ -3045,7 +3048,7 @@ S_doeval(pTHX_ int gimme, OP** startop, CV* outside, U32 seq) POPEVAL(cx); } lex_end(); - LEAVE; + LEAVE; /* pp_entereval knows about this LEAVE. */ msg = SvPVx_nolen_const(ERRSV); if (optype == OP_REQUIRE) { @@ -3100,9 +3103,9 @@ S_doeval(pTHX_ int gimme, OP** startop, CV* outside, U32 seq) if (cv) { dSP; PUSHMARK(SP); - XPUSHs((SV*)CopFILEGV(&PL_compiling)); + XPUSHs(MUTABLE_SV(CopFILEGV(&PL_compiling))); PUTBACK; - call_sv((SV*)cv, G_DISCARD); + call_sv(MUTABLE_SV(cv), G_DISCARD); } } @@ -3324,7 +3327,7 @@ PP(pp_require) for (i = 0; i <= AvFILL(ar); i++) { SV * const dirsv = *av_fetch(ar, i, TRUE); - if (SvTIED_mg((SV*)ar, PERL_MAGIC_tied)) + if (SvTIED_mg((const SV *)ar, PERL_MAGIC_tied)) mg_get(dirsv); if (SvROK(dirsv)) { int count; @@ -3383,7 +3386,7 @@ PP(pp_require) } if (isGV_with_GP(arg)) { - IO * const io = GvIO((GV *)arg); + IO * const io = GvIO((const GV *)arg); ++filter_has_file; @@ -3601,9 +3604,9 @@ PP(pp_require) if (filter_sub || filter_cache) { SV * const datasv = filter_add(S_run_user_filter, NULL); IoLINES(datasv) = filter_has_file; - IoTOP_GV(datasv) = (GV *)filter_state; - IoBOTTOM_GV(datasv) = (GV *)filter_sub; - IoFMT_GV(datasv) = (GV *)filter_cache; + IoTOP_GV(datasv) = MUTABLE_GV(filter_state); + IoBOTTOM_GV(datasv) = MUTABLE_GV(filter_sub); + IoFMT_GV(datasv) = MUTABLE_GV(filter_cache); } /* switch to eval mode */ @@ -3639,7 +3642,7 @@ PP(pp_hintseval) { dVAR; dSP; - mXPUSHs((SV*)Perl_hv_copy_hints_hv(aTHX_ MUTABLE_HV(cSVOP_sv))); + mXPUSHs(MUTABLE_SV(Perl_hv_copy_hints_hv(aTHX_ MUTABLE_HV(cSVOP_sv)))); RETURN; } @@ -3650,18 +3653,14 @@ PP(pp_entereval) register PERL_CONTEXT *cx; SV *sv; const I32 gimme = GIMME_V; - const I32 was = PL_sub_generation; + const U32 was = PL_breakable_sub_gen; char tbuf[TYPE_DIGITS(long) + 12]; char *tmpbuf = tbuf; - char *safestr; STRLEN len; - bool ok; CV* runcv; U32 seq; HV *saved_hh = NULL; - const char * const fakestr = "_<(eval )"; - const int fakelen = 9 + 1; - + if (PL_op->op_private & OPpEVAL_HAS_HH) { saved_hh = MUTABLE_HV(SvREFCNT_inc(POPs)); } @@ -3695,8 +3694,6 @@ PP(pp_entereval) (i.e. before run-time proper). To work around the coredump that ensues, we always turn GvMULTI_on for any globals that were introduced within evals. See force_ident(). GSAR 96-10-12 */ - safestr = savepvn(tmpbuf, len); - SAVEDELETE(PL_defstash, safestr, len); SAVEHINTS(); PL_hints = PL_op->op_targ; if (saved_hh) @@ -3725,16 +3722,32 @@ PP(pp_entereval) /* prepare to compile string */ - if (PERLDB_LINE && PL_curstash != PL_debstash) + if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash) save_lines(CopFILEAV(&PL_compiling), PL_parser->linestr); PUTBACK; - ok = doeval(gimme, NULL, runcv, seq); - if (PERLDB_INTER && was != (I32)PL_sub_generation /* Some subs defined here. */ - && ok) { - /* Copy in anything fake and short. */ - my_strlcpy(safestr, fakestr, fakelen); + + if (doeval(gimme, NULL, runcv, seq)) { + if (was != PL_breakable_sub_gen /* Some subs defined here. */ + ? (PERLDB_LINE || PERLDB_SAVESRC) + : PERLDB_SAVESRC_NOSUBS) { + /* Retain the filegv we created. */ + } else { + char *const safestr = savepvn(tmpbuf, len); + SAVEDELETE(PL_defstash, safestr, len); + } + return DOCATCH(PL_eval_start); + } else { + /* We have already left the scope set up earler thanks to the LEAVE + in doeval(). */ + if (was != PL_breakable_sub_gen /* Some subs defined here. */ + ? (PERLDB_LINE || PERLDB_SAVESRC) + : PERLDB_SAVESRC_INVALID) { + /* Retain the filegv we created. */ + } else { + (void)hv_delete(PL_defstash, tmpbuf, len, G_DISCARD); + } + return PL_op->op_next; } - return ok ? DOCATCH(PL_eval_start) : PL_op->op_next; } PP(pp_leaveeval) @@ -4118,13 +4131,13 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other) if (SvTIED_mg(This, PERL_MAGIC_tied)) { tied = TRUE; } - else if (SvTIED_mg((SV *) other_hv, PERL_MAGIC_tied)) { + else if (SvTIED_mg((const SV *)other_hv, PERL_MAGIC_tied)) { HV * const temp = other_hv; other_hv = MUTABLE_HV(This); - This = (SV *) temp; + This = MUTABLE_SV(temp); tied = TRUE; } - if (SvTIED_mg((SV *) other_hv, PERL_MAGIC_tied)) + if (SvTIED_mg((const SV *)other_hv, PERL_MAGIC_tied)) other_tied = TRUE; if (!tied && HvUSEDKEYS((const HV *) This) != HvUSEDKEYS(other_hv)) @@ -4209,11 +4222,11 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other) if (NULL == seen_this) { seen_this = newHV(); - (void) sv_2mortal((SV *) seen_this); + (void) sv_2mortal(MUTABLE_SV(seen_this)); } if (NULL == seen_other) { seen_this = newHV(); - (void) sv_2mortal((SV *) seen_other); + (void) sv_2mortal(MUTABLE_SV(seen_other)); } for(i = 0; i <= other_len; ++i) { SV * const * const this_elem = av_fetch(MUTABLE_AV(This), i, FALSE); @@ -4738,8 +4751,8 @@ S_run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen) dVAR; SV * const datasv = FILTER_DATA(idx); const int filter_has_file = IoLINES(datasv); - SV * const filter_state = (SV *)IoTOP_GV(datasv); - SV * const filter_sub = (SV *)IoBOTTOM_GV(datasv); + SV * const filter_state = MUTABLE_SV(IoTOP_GV(datasv)); + SV * const filter_sub = MUTABLE_SV(IoBOTTOM_GV(datasv)); int status = 0; SV *upstream; STRLEN got_len; @@ -4759,7 +4772,7 @@ S_run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen) not sure where the trouble is yet. XXX */ if (IoFMT_GV(datasv)) { - SV *const cache = (SV *)IoFMT_GV(datasv); + SV *const cache = MUTABLE_SV(IoFMT_GV(datasv)); if (SvOK(cache)) { STRLEN cache_len; const char *cache_p = SvPV(cache, cache_len); @@ -4818,7 +4831,7 @@ S_run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen) SAVETMPS; EXTEND(SP, 2); - DEFSV = upstream; + DEFSV_set(upstream); PUSHMARK(SP); mPUSHi(0); if (filter_state) { @@ -4858,10 +4871,10 @@ S_run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen) if (prune_from) { /* Oh. Too long. Stuff some in our cache. */ STRLEN cached_len = got_p + got_len - prune_from; - SV *cache = (SV *)IoFMT_GV(datasv); + SV *cache = MUTABLE_SV(IoFMT_GV(datasv)); if (!cache) { - IoFMT_GV(datasv) = (GV*) (cache = newSV(got_len - umaxlen)); + IoFMT_GV(datasv) = MUTABLE_GV((cache = newSV(got_len - umaxlen))); } else if (SvOK(cache)) { /* Cache should be empty. */ assert(!SvCUR(cache));