3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 * 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * Now far ahead the Road has gone,
13 * And I must follow, if I can,
14 * Pursuing it with eager feet,
15 * Until it joins some larger way
16 * Where many paths and errands meet.
17 * And whither then? I cannot say.
19 * [Bilbo on p.35 of _The Lord of the Rings_, I/i: "A Long-Expected Party"]
22 /* This file contains control-oriented pp ("push/pop") functions that
23 * execute the opcodes that make up a perl program. A typical pp function
24 * expects to find its arguments on the stack, and usually pushes its
25 * results onto the stack, hence the 'pp' terminology. Each OP structure
26 * contains a pointer to the relevant pp_foo() function.
28 * Control-oriented means things like pp_enteriter() and pp_next(), which
29 * alter the flow of control of the program.
34 #define PERL_IN_PP_CTL_C
38 #define dopopto_cursub() \
39 (PL_curstackinfo->si_cxsubix >= 0 \
40 ? PL_curstackinfo->si_cxsubix \
41 : dopoptosub_at(cxstack, cxstack_ix))
43 #define dopoptosub(plop) dopoptosub_at(cxstack, (plop))
49 const PERL_CONTEXT *cx;
52 if (PL_op->op_private & OPpOFFBYONE) {
53 if (!(cx = caller_cx(1,NULL))) RETPUSHUNDEF;
56 cxix = dopopto_cursub();
62 switch (cx->blk_gimme) {
81 PMOP *pm = cPMOPx(cLOGOP->op_other);
86 const regexp_engine *eng;
87 bool is_bare_re= FALSE;
89 if (PL_op->op_flags & OPf_STACKED) {
99 /* prevent recompiling under /o and ithreads. */
100 #if defined(USE_ITHREADS)
101 if (pm->op_pmflags & PMf_KEEP && PM_GETRE(pm)) {
108 assert (re != (REGEXP*) &PL_sv_undef);
109 eng = re ? RX_ENGINE(re) : current_re_engine();
111 new_re = (eng->op_comp
113 : &Perl_re_op_compile
114 )(aTHX_ args, nargs, pm->op_code_list, eng, re,
116 (pm->op_pmflags & RXf_PMf_FLAGCOPYMASK),
118 (PL_op->op_flags & OPf_SPECIAL ? PMf_USE_RE_EVAL : 0));
120 if (pm->op_pmflags & PMf_HAS_CV)
121 ReANY(new_re)->qr_anoncv
122 = (CV*) SvREFCNT_inc(PAD_SV(PL_op->op_targ));
126 /* The match's LHS's get-magic might need to access this op's regexp
127 (e.g. $' =~ /$re/ while foo; see bug 70764). So we must call
128 get-magic now before we replace the regexp. Hopefully this hack can
129 be replaced with the approach described at
130 http://www.nntp.perl.org/group/perl.perl5.porters/2007/03/msg122415.html
132 if (pm->op_type == OP_MATCH) {
134 const bool was_tainted = TAINT_get;
135 if (pm->op_flags & OPf_STACKED)
137 else if (pm->op_targ)
138 lhs = PAD_SV(pm->op_targ);
141 /* Restore the previous value of PL_tainted (which may have been
142 modified by get-magic), to avoid incorrectly setting the
143 RXf_TAINTED flag with RX_TAINT_on further down. */
144 TAINT_set(was_tainted);
145 #ifdef NO_TAINT_SUPPORT
146 PERL_UNUSED_VAR(was_tainted);
149 tmp = reg_temp_copy(NULL, new_re);
150 ReREFCNT_dec(new_re);
156 PM_SETRE(pm, new_re);
160 assert(TAINTING_get || !TAINT_get);
162 SvTAINTED_on((SV*)new_re);
166 /* handle the empty pattern */
167 if (!RX_PRELEN(PM_GETRE(pm)) && PL_curpm) {
168 if (PL_curpm == PL_reg_curpm) {
169 if (PL_curpm_under && PL_curpm_under == PL_reg_curpm) {
170 Perl_croak(aTHX_ "Infinite recursion via empty pattern");
175 #if !defined(USE_ITHREADS)
176 /* can't change the optree at runtime either */
177 /* PMf_KEEP is handled differently under threads to avoid these problems */
178 if (pm->op_pmflags & PMf_KEEP) {
179 cLOGOP->op_first->op_next = PL_op->op_next;
191 PERL_CONTEXT *cx = CX_CUR();
192 PMOP * const pm = cPMOPx(cLOGOP->op_other);
193 SV * const dstr = cx->sb_dstr;
196 char *orig = cx->sb_orig;
197 REGEXP * const rx = cx->sb_rx;
199 REGEXP *old = PM_GETRE(pm);
206 PM_SETRE(pm,ReREFCNT_inc(rx));
209 rxres_restore(&cx->sb_rxres, rx);
211 if (cx->sb_iters++) {
212 const SSize_t saviters = cx->sb_iters;
213 if (cx->sb_iters > cx->sb_maxiters)
214 DIE(aTHX_ "Substitution loop");
216 SvGETMAGIC(TOPs); /* possibly clear taint on $1 etc: #67962 */
218 /* See "how taint works": pp_subst() in pp_hot.c */
219 sv_catsv_nomg(dstr, POPs);
220 if (UNLIKELY(TAINT_get))
221 cx->sb_rxtainted |= SUBST_TAINT_REPL;
222 if (CxONCE(cx) || s < orig ||
223 !CALLREGEXEC(rx, s, cx->sb_strend, orig,
224 (s == m), cx->sb_targ, NULL,
225 (REXEC_IGNOREPOS|REXEC_NOT_FIRST|REXEC_FAIL_ON_UNDERFLOW)))
227 SV *targ = cx->sb_targ;
229 assert(cx->sb_strend >= s);
230 if(cx->sb_strend > s) {
231 if (DO_UTF8(dstr) && !SvUTF8(targ))
232 sv_catpvn_nomg_utf8_upgrade(dstr, s, cx->sb_strend - s, nsv);
234 sv_catpvn_nomg(dstr, s, cx->sb_strend - s);
236 if (RX_MATCH_TAINTED(rx)) /* run time pattern taint, eg locale */
237 cx->sb_rxtainted |= SUBST_TAINT_PAT;
239 if (pm->op_pmflags & PMf_NONDESTRUCT) {
241 /* From here on down we're using the copy, and leaving the
242 original untouched. */
246 SV_CHECK_THINKFIRST_COW_DROP(targ);
247 if (isGV(targ)) Perl_croak_no_modify();
249 SvPV_set(targ, SvPVX(dstr));
250 SvCUR_set(targ, SvCUR(dstr));
251 SvLEN_set(targ, SvLEN(dstr));
254 SvPV_set(dstr, NULL);
257 mPUSHi(saviters - 1);
259 (void)SvPOK_only_UTF8(targ);
262 /* update the taint state of various variables in
263 * preparation for final exit.
264 * See "how taint works": pp_subst() in pp_hot.c */
266 if ((cx->sb_rxtainted & SUBST_TAINT_PAT) ||
267 ((cx->sb_rxtainted & (SUBST_TAINT_STR|SUBST_TAINT_RETAINT))
268 == (SUBST_TAINT_STR|SUBST_TAINT_RETAINT))
270 (RX_MATCH_TAINTED_on(rx)); /* taint $1 et al */
272 if (!(cx->sb_rxtainted & SUBST_TAINT_BOOLRET)
273 && (cx->sb_rxtainted & (SUBST_TAINT_STR|SUBST_TAINT_PAT))
275 SvTAINTED_on(TOPs); /* taint return value */
276 /* needed for mg_set below */
278 cBOOL(cx->sb_rxtainted &
279 (SUBST_TAINT_STR|SUBST_TAINT_PAT|SUBST_TAINT_REPL))
282 /* sv_magic(), when adding magic (e.g.taint magic), also
283 * recalculates any pos() magic, converting any byte offset
284 * to utf8 offset. Make sure pos() is reset before this
285 * happens rather than using the now invalid value (since
286 * we've just replaced targ's pvx buffer with the
287 * potentially shorter dstr buffer). Normally (i.e. in
288 * non-taint cases), pos() gets removed a few lines later
289 * with the SvSETMAGIC().
293 mg = mg_find_mglob(targ);
295 MgBYTEPOS_set(mg, targ, SvPVX(targ), -1);
301 /* PL_tainted must be correctly set for this mg_set */
310 RETURNOP(pm->op_next);
311 NOT_REACHED; /* NOTREACHED */
313 cx->sb_iters = saviters;
315 if (RX_MATCH_COPIED(rx) && RX_SUBBEG(rx) != orig) {
318 assert(!RX_SUBOFFSET(rx));
319 cx->sb_orig = orig = RX_SUBBEG(rx);
321 cx->sb_strend = s + (cx->sb_strend - m);
323 cx->sb_m = m = RX_OFFS_START(rx,0) + orig;
325 if (DO_UTF8(dstr) && !SvUTF8(cx->sb_targ))
326 sv_catpvn_nomg_utf8_upgrade(dstr, s, m - s, nsv);
328 sv_catpvn_nomg(dstr, s, m-s);
330 cx->sb_s = RX_OFFS_END(rx,0) + orig;
331 { /* Update the pos() information. */
333 = (pm->op_pmflags & PMf_NONDESTRUCT) ? cx->sb_dstr : cx->sb_targ;
336 /* the string being matched against may no longer be a string,
337 * e.g. $_=0; s/.../$_++/ge */
340 SvPV_force_nomg_nolen(sv);
342 if (!(mg = mg_find_mglob(sv))) {
343 mg = sv_magicext_mglob(sv);
345 MgBYTEPOS_set(mg, sv, SvPVX(sv), m - orig);
348 (void)ReREFCNT_inc(rx);
349 /* update the taint state of various variables in preparation
350 * for calling the code block.
351 * See "how taint works": pp_subst() in pp_hot.c */
353 if (RX_MATCH_TAINTED(rx)) /* run time pattern taint, eg locale */
354 cx->sb_rxtainted |= SUBST_TAINT_PAT;
356 if ((cx->sb_rxtainted & SUBST_TAINT_PAT) ||
357 ((cx->sb_rxtainted & (SUBST_TAINT_STR|SUBST_TAINT_RETAINT))
358 == (SUBST_TAINT_STR|SUBST_TAINT_RETAINT))
360 (RX_MATCH_TAINTED_on(rx)); /* taint $1 et al */
362 if (cx->sb_iters > 1 && (cx->sb_rxtainted &
363 (SUBST_TAINT_STR|SUBST_TAINT_PAT|SUBST_TAINT_REPL)))
364 SvTAINTED_on((pm->op_pmflags & PMf_NONDESTRUCT)
365 ? cx->sb_dstr : cx->sb_targ);
368 rxres_save(&cx->sb_rxres, rx);
370 RETURNOP(pm->op_pmstashstartu.op_pmreplstart);
374 Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx)
379 PERL_ARGS_ASSERT_RXRES_SAVE;
382 /* deal with regexp_paren_pair items */
383 if (!p || p[1] < RX_NPARENS(rx)) {
385 i = 7 + (RX_NPARENS(rx)+1) * 2;
387 i = 6 + (RX_NPARENS(rx)+1) * 2;
396 /* what (if anything) to free on croak */
397 *p++ = PTR2UV(RX_MATCH_COPIED(rx) ? RX_SUBBEG(rx) : NULL);
398 RX_MATCH_COPIED_off(rx);
399 *p++ = RX_NPARENS(rx);
402 *p++ = PTR2UV(RX_SAVED_COPY(rx));
403 RX_SAVED_COPY(rx) = NULL;
406 *p++ = PTR2UV(RX_SUBBEG(rx));
407 *p++ = (UV)RX_SUBLEN(rx);
408 *p++ = (UV)RX_SUBOFFSET(rx);
409 *p++ = (UV)RX_SUBCOFFSET(rx);
410 for (i = 0; i <= RX_NPARENS(rx); ++i) {
411 *p++ = (UV)RX_OFFSp(rx)[i].start;
412 *p++ = (UV)RX_OFFSp(rx)[i].end;
417 S_rxres_restore(pTHX_ void **rsp, REGEXP *rx)
422 PERL_ARGS_ASSERT_RXRES_RESTORE;
425 RX_MATCH_COPY_FREE(rx);
426 RX_MATCH_COPIED_set(rx, *p);
428 RX_NPARENS(rx) = *p++;
431 if (RX_SAVED_COPY(rx))
432 SvREFCNT_dec (RX_SAVED_COPY(rx));
433 RX_SAVED_COPY(rx) = INT2PTR(SV*,*p);
437 RX_SUBBEG(rx) = INT2PTR(char*,*p++);
438 RX_SUBLEN(rx) = (I32)(*p++);
439 RX_SUBOFFSET(rx) = (I32)*p++;
440 RX_SUBCOFFSET(rx) = (I32)*p++;
441 for (i = 0; i <= RX_NPARENS(rx); ++i) {
442 RX_OFFSp(rx)[i].start = (I32)(*p++);
443 RX_OFFSp(rx)[i].end = (I32)(*p++);
448 S_rxres_free(pTHX_ void **rsp)
450 UV * const p = (UV*)*rsp;
452 PERL_ARGS_ASSERT_RXRES_FREE;
456 void *tmp = INT2PTR(char*,*p);
459 U32 i = 9 + p[1] * 2;
461 U32 i = 8 + p[1] * 2;
466 SvREFCNT_dec (INT2PTR(SV*,p[2]));
469 PoisonFree(p, i, sizeof(UV));
478 #define FORM_NUM_BLANK (1<<30)
479 #define FORM_NUM_POINT (1<<29)
483 dSP; dMARK; dORIGMARK;
484 SV * const tmpForm = *++MARK;
485 SV *formsv; /* contains text of original format */
486 U32 *fpc; /* format ops program counter */
487 char *t; /* current append position in target string */
488 const char *f; /* current position in format string */
490 SV *sv = NULL; /* current item */
491 const char *item = NULL;/* string value of current item */
492 I32 itemsize = 0; /* length (chars) of item, possibly truncated */
493 I32 itembytes = 0; /* as itemsize, but length in bytes */
494 I32 fieldsize = 0; /* width of current field */
495 I32 lines = 0; /* number of lines that have been output */
496 bool chopspace = (strchr(PL_chopset, ' ') != NULL); /* does $: have space */
497 const char *chophere = NULL; /* where to chop current item */
498 STRLEN linemark = 0; /* pos of start of line in output */
500 bool gotsome = FALSE; /* seen at least one non-blank item on this line */
501 STRLEN len; /* length of current sv */
502 STRLEN linemax; /* estimate of output size in bytes */
503 bool item_is_utf8 = FALSE;
504 bool targ_is_utf8 = FALSE;
507 U8 *source; /* source of bytes to append */
508 STRLEN to_copy; /* how may bytes to append */
509 char trans; /* what chars to translate */
510 bool copied_form = FALSE; /* have we duplicated the form? */
512 mg = doparseform(tmpForm);
514 fpc = (U32*)mg->mg_ptr;
515 /* the actual string the format was compiled from.
516 * with overload etc, this may not match tmpForm */
520 SvPV_force(PL_formtarget, len);
521 if (SvTAINTED(tmpForm) || SvTAINTED(formsv))
522 SvTAINTED_on(PL_formtarget);
523 if (DO_UTF8(PL_formtarget))
525 /* this is an initial estimate of how much output buffer space
526 * to allocate. It may be exceeded later */
527 linemax = (SvCUR(formsv) * (IN_BYTES ? 1 : 3) + 1);
528 t = SvGROW(PL_formtarget, len + linemax + 1);
529 /* XXX from now onwards, SvCUR(PL_formtarget) is invalid */
531 f = SvPV_const(formsv, len);
535 const char *name = "???";
538 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
539 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
540 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
541 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
542 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
544 case FF_CHECKNL: name = "CHECKNL"; break;
545 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
546 case FF_SPACE: name = "SPACE"; break;
547 case FF_HALFSPACE: name = "HALFSPACE"; break;
548 case FF_ITEM: name = "ITEM"; break;
549 case FF_CHOP: name = "CHOP"; break;
550 case FF_LINEGLOB: name = "LINEGLOB"; break;
551 case FF_NEWLINE: name = "NEWLINE"; break;
552 case FF_MORE: name = "MORE"; break;
553 case FF_LINEMARK: name = "LINEMARK"; break;
554 case FF_END: name = "END"; break;
555 case FF_0DECIMAL: name = "0DECIMAL"; break;
556 case FF_LINESNGL: name = "LINESNGL"; break;
559 PerlIO_printf(Perl_debug_log, "%-16s%ld\n", name, (long) arg);
561 PerlIO_printf(Perl_debug_log, "%-16s\n", name);
564 case FF_LINEMARK: /* start (or end) of a line */
565 linemark = t - SvPVX(PL_formtarget);
570 case FF_LITERAL: /* append <arg> literal chars */
575 item_is_utf8 = (targ_is_utf8)
576 ? cBOOL(DO_UTF8(formsv))
577 : cBOOL(SvUTF8(formsv));
580 case FF_SKIP: /* skip <arg> chars in format */
584 case FF_FETCH: /* get next item and set field size to <arg> */
593 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Not enough format arguments");
596 SvTAINTED_on(PL_formtarget);
599 case FF_CHECKNL: /* find max len of item (up to \n) that fits field */
601 const char *s = item = SvPV_const(sv, len);
602 const char *send = s + len;
605 item_is_utf8 = DO_UTF8(sv);
617 if (itemsize == fieldsize)
620 itembytes = s - item;
625 case FF_CHECKCHOP: /* like CHECKNL, but up to highest split point */
627 const char *s = item = SvPV_const(sv, len);
628 const char *send = s + len;
632 item_is_utf8 = DO_UTF8(sv);
634 /* look for a legal split position */
642 /* provisional split point */
646 /* we delay testing fieldsize until after we've
647 * processed the possible split char directly
648 * following the last field char; so if fieldsize=3
649 * and item="a b cdef", we consume "a b", not "a".
650 * Ditto further down.
652 if (size == fieldsize)
656 if (size == fieldsize)
658 if (strchr(PL_chopset, *s)) {
659 /* provisional split point */
660 /* for a non-space split char, we include
661 * the split char; hence the '+1' */
675 if (!chophere || s == send) {
679 itembytes = chophere - item;
684 case FF_SPACE: /* append padding space (diff of field, item size) */
685 arg = fieldsize - itemsize;
693 case FF_HALFSPACE: /* like FF_SPACE, but only append half as many */
694 arg = fieldsize - itemsize;
703 case FF_ITEM: /* append a text item, while blanking ctrl chars */
709 case FF_CHOP: /* (for ^*) chop the current item */
710 if (sv != &PL_sv_no) {
711 const char *s = chophere;
713 ((sv == tmpForm || SvSMAGICAL(sv))
714 || (SvGMAGICAL(tmpForm) && !sv_only_taint_gmagic(tmpForm))) ) {
715 /* sv and tmpForm are either the same SV, or magic might allow modification
716 of tmpForm when sv is modified, so copy */
717 SV *newformsv = sv_mortalcopy(formsv);
720 f = SvPV_nolen(newformsv) + (f - SvPV_nolen(formsv));
721 Newx(new_compiled, mg->mg_len / sizeof(U32), U32);
722 memcpy(new_compiled, mg->mg_ptr, mg->mg_len);
723 SAVEFREEPV(new_compiled);
724 fpc = new_compiled + (fpc - (U32*)mg->mg_ptr);
736 /* tied, overloaded or similar strangeness.
737 * Do it the hard way */
738 sv_setpvn(sv, s, len - (s-item));
744 case FF_LINESNGL: /* process ^* */
748 case FF_LINEGLOB: /* process @* */
750 const bool oneline = fpc[-1] == FF_LINESNGL;
751 const char *s = item = SvPV_const(sv, len);
752 const char *const send = s + len;
754 item_is_utf8 = DO_UTF8(sv);
765 to_copy = s - item - 1;
779 /* append to_copy bytes from source to PL_formstring.
780 * item_is_utf8 implies source is utf8.
781 * if trans, translate certain characters during the copy */
786 SvCUR_set(PL_formtarget,
787 t - SvPVX_const(PL_formtarget));
789 if (targ_is_utf8 && !item_is_utf8) {
790 source = tmp = bytes_to_utf8(source, &to_copy);
793 if (item_is_utf8 && !targ_is_utf8) {
795 /* Upgrade targ to UTF8, and then we reduce it to
796 a problem we have a simple solution for.
797 Don't need get magic. */
798 sv_utf8_upgrade_nomg(PL_formtarget);
800 /* re-calculate linemark */
801 s = (U8*)SvPVX(PL_formtarget);
802 /* the bytes we initially allocated to append the
803 * whole line may have been gobbled up during the
804 * upgrade, so allocate a whole new line's worth
808 s += UTF8_SAFE_SKIP(s,
809 (U8 *) SvEND(PL_formtarget));
810 linemark = s - (U8*)SvPVX(PL_formtarget);
812 /* Easy. They agree. */
813 assert (item_is_utf8 == targ_is_utf8);
816 /* @* and ^* are the only things that can exceed
817 * the linemax, so grow by the output size, plus
818 * a whole new form's worth in case of any further
820 grow = linemax + to_copy;
822 SvGROW(PL_formtarget, SvCUR(PL_formtarget) + grow + 1);
823 t = SvPVX(PL_formtarget) + SvCUR(PL_formtarget);
825 Copy(source, t, to_copy, char);
827 /* blank out ~ or control chars, depending on trans.
828 * works on bytes not chars, so relies on not
829 * matching utf8 continuation bytes */
831 U8 *send = s + to_copy;
834 if (trans == '~' ? (ch == '~') : isCNTRL(ch))
841 SvCUR_set(PL_formtarget, SvCUR(PL_formtarget) + to_copy);
847 case FF_0DECIMAL: /* like FF_DECIMAL but for 0### */
850 ((arg & FORM_NUM_POINT) ? "%#0*.*" NVff : "%0*.*" NVff);
853 case FF_DECIMAL: /* do @##, ^##, where <arg>=(precision|flags) */
856 ((arg & FORM_NUM_POINT) ? "%#*.*" NVff : "%*.*" NVff);
858 /* If the field is marked with ^ and the value is undefined,
860 if ((arg & FORM_NUM_BLANK) && !SvOK(sv)) {
868 /* overflow evidence */
869 if (num_overflow(value, fieldsize, arg)) {
875 /* Formats aren't yet marked for locales, so assume "yes". */
877 Size_t max = SvLEN(PL_formtarget) - (t - SvPVX(PL_formtarget));
879 arg &= ~(FORM_NUM_POINT|FORM_NUM_BLANK);
883 if (!quadmath_format_valid(fmt))
884 Perl_croak_nocontext("panic: quadmath invalid format \"%s\"", fmt);
885 WITH_LC_NUMERIC_SET_TO_NEEDED(
886 len = quadmath_snprintf(t, max, fmt, (int) fieldsize,
890 Perl_croak_nocontext("panic: quadmath_snprintf failed, format \"%s\"", fmt);
893 /* we generate fmt ourselves so it is safe */
894 GCC_DIAG_IGNORE_STMT(-Wformat-nonliteral);
895 len = my_snprintf(t, max, fmt, (int) fieldsize, (int) arg, value);
896 GCC_DIAG_RESTORE_STMT;
898 PERL_MY_SNPRINTF_POST_GUARD(len, max);
903 case FF_NEWLINE: /* delete trailing spaces, then append \n */
905 while (t-- > (SvPVX(PL_formtarget) + linemark) && *t == ' ') ;
910 case FF_BLANK: /* for arg==0: do '~'; for arg>0 : do '~~' */
913 if (arg) { /* repeat until fields exhausted? */
919 t = SvPVX(PL_formtarget) + linemark;
924 case FF_MORE: /* replace long end of string with '...' */
926 const char *s = chophere;
927 const char *send = item + len;
929 while (isSPACE(*s) && (s < send))
934 arg = fieldsize - itemsize;
941 if (strBEGINs(s1," ")) {
942 while (s1 > SvPVX_const(PL_formtarget) && isSPACE(s1[-1]))
952 case FF_END: /* tidy up, then return */
954 assert(t < SvPVX_const(PL_formtarget) + SvLEN(PL_formtarget));
956 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
958 SvUTF8_on(PL_formtarget);
959 FmLINES(PL_formtarget) += lines;
961 if (fpc[-1] == FF_BLANK)
962 RETURNOP(cLISTOP->op_first);
969 /* also used for: pp_mapstart() */
972 /* See the code comments at the start of pp_grepwhile() and
973 * pp_mapwhile() for an explanation of how the stack is used
974 * during a grep or map.
980 if (PL_stack_base + TOPMARK == SP) {
982 if (GIMME_V == G_SCALAR)
984 RETURNOP(PL_op->op_next->op_next);
986 PL_stack_sp = PL_stack_base + TOPMARK + 1;
987 PUSHMARK(PL_stack_sp); /* push dst */
988 PUSHMARK(PL_stack_sp); /* push src */
989 ENTER_with_name("grep"); /* enter outer scope */
993 ENTER_with_name("grep_item"); /* enter inner scope */
996 src = PL_stack_base[TOPMARK];
998 src = PL_stack_base[TOPMARK] = sv_mortalcopy(src);
1005 if (PL_op->op_type == OP_MAPSTART)
1006 PUSHMARK(PL_stack_sp); /* push top */
1007 return cLOGOPx(PL_op->op_next)->op_other;
1010 /* pp_grepwhile() lives in pp_hot.c */
1014 /* Understanding the stack during a map.
1016 * 'map expr, args' is implemented in the form of
1018 * grepstart; // which handles map too
1024 * The stack examples below are in the form of 'perl -Ds' output,
1025 * where any stack element indexed by PL_markstack_ptr[i] has a star
1026 * just to the right of it. In addition, the corresponding i value
1027 * is displayed under the indexed stack element.
1029 * On entry to mapwhile, the stack looks like this:
1031 * => * A1..An X1 * X2..Xn C * R1..Rn * E1..En
1032 * [-3] [-2] [-1] [0]
1035 * A1..An Accumulated results from all previous iterations of expr
1036 * X1..Xn Random garbage
1037 * C The current (just processed) arg, still aliased to $_.
1038 * R1..Rn The args remaining to be processed.
1039 * E1..En the (list) result of the just-executed map expression.
1041 * Note that it is easiest to think of stack marks [-1] and [-2] as both
1042 * being one too high, and so it would make more sense to have had the
1045 * => * A1..An * X1..Xn * C R1..Rn * E1..En
1046 * [-3] [-2] [-1] [0]
1048 * where the stack is divided neatly into 4 groups:
1049 * - accumulated results
1050 * - discards and/or holes proactively created for later result storage
1051 * - being, or yet to be, processed,
1052 * - results of last expr
1053 * But off-by-one is the way it is currently, and it works as long as
1054 * we keep it consistent and bear it in mind.
1056 * pp_mapwhile() does the following:
1058 * - If there isn't enough space in the X1..Xn zone to insert the
1059 * expression results, grow the stack and shift up everything above C.
1060 * - move E1..En to just above An
1061 * - at the same time, manipulate the tmps stack so that temporaries
1062 * from executing expr can be freed without prematurely freeing
1064 * - if on last iteration, pop all the marks, reset the stack pointer
1065 * and update the return args based on caller context.
1066 * - else alias $_ to the next arg.
1071 const U8 gimme = GIMME_V;
1072 I32 items = (SP - PL_stack_base) - TOPMARK; /* how many new items */
1078 /* first, move source pointer to the next item in the source list */
1079 ++PL_markstack_ptr[-1];
1081 /* if there are new items, push them into the destination list */
1082 if (items && gimme != G_VOID) {
1083 /* might need to make room back there first */
1084 if (items > PL_markstack_ptr[-1] - PL_markstack_ptr[-2]) {
1085 /* XXX this implementation is very pessimal because the stack
1086 * is repeatedly extended for every set of items. Is possible
1087 * to do this without any stack extension or copying at all
1088 * by maintaining a separate list over which the map iterates
1089 * (like foreach does). --gsar */
1091 /* everything in the stack after the destination list moves
1092 * towards the end the stack by the amount of room needed */
1093 shift = items - (PL_markstack_ptr[-1] - PL_markstack_ptr[-2]);
1095 /* items to shift up (accounting for the moved source pointer) */
1096 count = (SP - PL_stack_base) - (PL_markstack_ptr[-1] - 1);
1098 /* This optimization is by Ben Tilly and it does
1099 * things differently from what Sarathy (gsar)
1100 * is describing. The downside of this optimization is
1101 * that leaves "holes" (uninitialized and hopefully unused areas)
1102 * to the Perl stack, but on the other hand this
1103 * shouldn't be a problem. If Sarathy's idea gets
1104 * implemented, this optimization should become
1105 * irrelevant. --jhi */
1107 shift = count; /* Avoid shifting too often --Ben Tilly */
1111 dst = (SP += shift);
1112 PL_markstack_ptr[-1] += shift;
1113 *PL_markstack_ptr += shift;
1117 /* copy the new items down to the destination list */
1118 dst = PL_stack_base + (PL_markstack_ptr[-2] += items) - 1;
1119 if (gimme == G_LIST) {
1120 /* add returned items to the collection (making mortal copies
1121 * if necessary), then clear the current temps stack frame
1122 * *except* for those items. We do this splicing the items
1123 * into the start of the tmps frame (so some items may be on
1124 * the tmps stack twice), then moving PL_tmps_floor above
1125 * them, then freeing the frame. That way, the only tmps that
1126 * accumulate over iterations are the return values for map.
1127 * We have to do to this way so that everything gets correctly
1128 * freed if we die during the map.
1132 /* make space for the slice */
1133 EXTEND_MORTAL(items);
1134 tmpsbase = PL_tmps_floor + 1;
1135 Move(PL_tmps_stack + tmpsbase,
1136 PL_tmps_stack + tmpsbase + items,
1137 PL_tmps_ix - PL_tmps_floor,
1139 PL_tmps_ix += items;
1144 sv = sv_mortalcopy(sv);
1146 PL_tmps_stack[tmpsbase++] = SvREFCNT_inc_simple(sv);
1148 /* clear the stack frame except for the items */
1149 PL_tmps_floor += items;
1151 /* FREETMPS may have cleared the TEMP flag on some of the items */
1154 SvTEMP_on(PL_tmps_stack[--tmpsbase]);
1157 /* scalar context: we don't care about which values map returns
1158 * (we use undef here). And so we certainly don't want to do mortal
1159 * copies of meaningless values. */
1160 while (items-- > 0) {
1162 *dst-- = &PL_sv_undef;
1170 LEAVE_with_name("grep_item"); /* exit inner scope */
1173 if (PL_markstack_ptr[-1] > TOPMARK) {
1175 (void)POPMARK; /* pop top */
1176 LEAVE_with_name("grep"); /* exit outer scope */
1177 (void)POPMARK; /* pop src */
1178 items = --*PL_markstack_ptr - PL_markstack_ptr[-1];
1179 (void)POPMARK; /* pop dst */
1180 SP = PL_stack_base + POPMARK; /* pop original mark */
1181 if (gimme == G_SCALAR) {
1185 else if (gimme == G_LIST)
1192 ENTER_with_name("grep_item"); /* enter inner scope */
1195 /* set $_ to the new source item */
1196 src = PL_stack_base[PL_markstack_ptr[-1]];
1197 if (SvPADTMP(src)) {
1198 src = sv_mortalcopy(src);
1203 RETURNOP(cLOGOP->op_other);
1212 if (GIMME_V == G_LIST)
1215 if (SvTRUE_NN(targ))
1216 return cLOGOP->op_other;
1225 if (GIMME_V == G_LIST) {
1226 RETURNOP(cLOGOPx(cUNOP->op_first)->op_other);
1230 SV * const targ = PAD_SV(PL_op->op_targ);
1233 if (PL_op->op_private & OPpFLIP_LINENUM) {
1234 if (GvIO(PL_last_in_gv)) {
1235 flip = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
1238 GV * const gv = gv_fetchpvs(".", GV_ADD|GV_NOTQUAL, SVt_PV);
1240 flip = SvIV(sv) == SvIV(GvSV(gv));
1243 flip = SvTRUE_NN(sv);
1246 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
1247 if (PL_op->op_flags & OPf_SPECIAL) {
1255 RETURNOP(cLOGOPx(cUNOP->op_first)->op_other);
1264 /* This code tries to decide if "$left .. $right" should use the
1265 magical string increment, or if the range is numeric. Initially,
1266 an exception was made for *any* string beginning with "0" (see
1267 [#18165], AMS 20021031), but now that is only applied when the
1268 string's length is also >1 - see the rules now documented in
1271 #define RANGE_IS_NUMERIC(left,right) ( \
1272 SvNIOKp(left) || (SvOK(left) && !SvPOKp(left)) || \
1273 SvNIOKp(right) || (SvOK(right) && !SvPOKp(right)) || \
1274 (((!SvOK(left) && SvOK(right)) || ((!SvOK(left) || \
1275 looks_like_number(left)) && SvPOKp(left) \
1276 && !(*SvPVX_const(left) == '0' && SvCUR(left)>1 ) )) \
1277 && (!SvOK(right) || looks_like_number(right))))
1283 if (GIMME_V == G_LIST) {
1289 if (RANGE_IS_NUMERIC(left,right)) {
1291 if ((SvOK(left) && !SvIOK(left) && SvNV_nomg(left) < IV_MIN) ||
1292 (SvOK(right) && (SvIOK(right)
1293 ? SvIsUV(right) && SvUV(right) > IV_MAX
1294 : SvNV_nomg(right) > (NV) IV_MAX)))
1295 DIE(aTHX_ "Range iterator outside integer range");
1296 i = SvIV_nomg(left);
1297 j = SvIV_nomg(right);
1299 /* Dance carefully around signed max. */
1300 bool overflow = (i <= 0 && j > SSize_t_MAX + i - 1);
1303 /* The wraparound of signed integers is undefined
1304 * behavior, but here we aim for count >=1, and
1305 * negative count is just wrong. */
1307 #if IVSIZE > Size_t_size
1314 Perl_croak(aTHX_ "Out of memory during list extend");
1321 SV * const sv = sv_2mortal(newSViv(i));
1323 if (n) /* avoid incrementing above IV_MAX */
1329 const char * const lpv = SvPV_nomg_const(left, llen);
1330 const char * const tmps = SvPV_nomg_const(right, len);
1332 SV *sv = newSVpvn_flags(lpv, llen, SvUTF8(left)|SVs_TEMP);
1333 if (DO_UTF8(right) && IN_UNI_8_BIT)
1334 len = sv_len_utf8_nomg(right);
1335 while (!SvNIOKp(sv) && SvCUR(sv) <= len) {
1337 if (strEQ(SvPVX_const(sv),tmps))
1339 sv = sv_2mortal(newSVsv(sv));
1346 SV * const targ = PAD_SV(cUNOP->op_first->op_targ);
1350 if (PL_op->op_private & OPpFLIP_LINENUM) {
1351 if (GvIO(PL_last_in_gv)) {
1352 flop = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
1355 GV * const gv = gv_fetchpvs(".", GV_ADD|GV_NOTQUAL, SVt_PV);
1356 if (gv && GvSV(gv)) flop = SvIV(sv) == SvIV(GvSV(gv));
1360 flop = SvTRUE_NN(sv);
1364 sv_setiv(PAD_SV(cUNOPx(cUNOP->op_first)->op_first->op_targ), 0);
1365 sv_catpvs(targ, "E0");
1375 static const char * const context_name[] = {
1377 NULL, /* CXt_WHEN never actually needs "block" */
1378 NULL, /* CXt_BLOCK never actually needs "block" */
1379 NULL, /* CXt_GIVEN never actually needs "block" */
1380 NULL, /* CXt_LOOP_PLAIN never actually needs "loop" */
1381 NULL, /* CXt_LOOP_LAZYIV never actually needs "loop" */
1382 NULL, /* CXt_LOOP_LAZYSV never actually needs "loop" */
1383 NULL, /* CXt_LOOP_LIST never actually needs "loop" */
1384 NULL, /* CXt_LOOP_ARY never actually needs "loop" */
1393 S_dopoptolabel(pTHX_ const char *label, STRLEN len, U32 flags)
1397 PERL_ARGS_ASSERT_DOPOPTOLABEL;
1399 for (i = cxstack_ix; i >= 0; i--) {
1400 const PERL_CONTEXT * const cx = &cxstack[i];
1401 switch (CxTYPE(cx)) {
1410 /* diag_listed_as: Exiting subroutine via %s */
1411 Perl_ck_warner(aTHX_ packWARN(WARN_EXITING), "Exiting %s via %s",
1412 context_name[CxTYPE(cx)], OP_NAME(PL_op));
1413 if (CxTYPE(cx) == CXt_NULL) /* sort BLOCK */
1416 case CXt_LOOP_PLAIN:
1417 case CXt_LOOP_LAZYIV:
1418 case CXt_LOOP_LAZYSV:
1422 STRLEN cx_label_len = 0;
1423 U32 cx_label_flags = 0;
1424 const char *cx_label = CxLABEL_len_flags(cx, &cx_label_len, &cx_label_flags);
1426 ( (cx_label_flags & SVf_UTF8) != (flags & SVf_UTF8) ) ?
1429 (const U8*)cx_label, cx_label_len,
1430 (const U8*)label, len) == 0)
1432 (const U8*)label, len,
1433 (const U8*)cx_label, cx_label_len) == 0)
1434 : (len == cx_label_len && ((cx_label == label)
1435 || memEQ(cx_label, label, len))) )) {
1436 DEBUG_l(Perl_deb(aTHX_ "(poptolabel(): skipping label at cx=%ld %s)\n",
1437 (long)i, cx_label));
1440 DEBUG_l( Perl_deb(aTHX_ "(poptolabel(): found label at cx=%ld %s)\n", (long)i, label));
1449 =for apidoc_section $callback
1450 =for apidoc dowantarray
1452 Implements the deprecated L<perlapi/C<GIMME>>.
1458 Perl_dowantarray(pTHX)
1460 const U8 gimme = block_gimme();
1461 return (gimme == G_VOID) ? G_SCALAR : gimme;
1464 /* note that this function has mostly been superseded by Perl_gimme_V */
1467 Perl_block_gimme(pTHX)
1469 const I32 cxix = dopopto_cursub();
1474 gimme = (cxstack[cxix].blk_gimme & G_WANT);
1476 Perl_croak(aTHX_ "panic: bad gimme: %d\n", gimme);
1481 =for apidoc is_lvalue_sub
1483 Returns non-zero if the sub calling this function is being called in an lvalue
1484 context. Returns 0 otherwise.
1490 Perl_is_lvalue_sub(pTHX)
1492 const I32 cxix = dopopto_cursub();
1493 assert(cxix >= 0); /* We should only be called from inside subs */
1495 if (CxLVAL(cxstack + cxix) && CvLVALUE(cxstack[cxix].blk_sub.cv))
1496 return CxLVAL(cxstack + cxix);
1501 /* only used by cx_pushsub() */
1503 Perl_was_lvalue_sub(pTHX)
1505 const I32 cxix = dopoptosub(cxstack_ix-1);
1506 assert(cxix >= 0); /* We should only be called from inside subs */
1508 if (CxLVAL(cxstack + cxix) && CvLVALUE(cxstack[cxix].blk_sub.cv))
1509 return CxLVAL(cxstack + cxix);
1515 S_dopoptosub_at(pTHX_ const PERL_CONTEXT *cxstk, I32 startingblock)
1519 PERL_ARGS_ASSERT_DOPOPTOSUB_AT;
1521 PERL_UNUSED_CONTEXT;
1524 for (i = startingblock; i >= 0; i--) {
1525 const PERL_CONTEXT * const cx = &cxstk[i];
1526 switch (CxTYPE(cx)) {
1530 /* in sub foo { /(?{...})/ }, foo ends up on the CX stack
1531 * twice; the first for the normal foo() call, and the second
1532 * for a faked up re-entry into the sub to execute the
1533 * code block. Hide this faked entry from the world. */
1534 if (cx->cx_type & CXp_SUB_RE_FAKE)
1536 DEBUG_l( Perl_deb(aTHX_ "(dopoptosub_at(): found sub at cx=%ld)\n", (long)i));
1542 DEBUG_l( Perl_deb(aTHX_ "(dopoptosub_at(): found sub at cx=%ld)\n", (long)i));
1546 DEBUG_l( Perl_deb(aTHX_ "(dopoptosub_at(): found sub at cx=%ld)\n", (long)i));
1554 S_dopoptoeval(pTHX_ I32 startingblock)
1557 for (i = startingblock; i >= 0; i--) {
1558 const PERL_CONTEXT *cx = &cxstack[i];
1559 switch (CxTYPE(cx)) {
1563 DEBUG_l( Perl_deb(aTHX_ "(dopoptoeval(): found eval at cx=%ld)\n", (long)i));
1571 S_dopoptoloop(pTHX_ I32 startingblock)
1574 for (i = startingblock; i >= 0; i--) {
1575 const PERL_CONTEXT * const cx = &cxstack[i];
1576 switch (CxTYPE(cx)) {
1585 /* diag_listed_as: Exiting subroutine via %s */
1586 Perl_ck_warner(aTHX_ packWARN(WARN_EXITING), "Exiting %s via %s",
1587 context_name[CxTYPE(cx)], OP_NAME(PL_op));
1588 if ((CxTYPE(cx)) == CXt_NULL) /* sort BLOCK */
1591 case CXt_LOOP_PLAIN:
1592 case CXt_LOOP_LAZYIV:
1593 case CXt_LOOP_LAZYSV:
1596 DEBUG_l( Perl_deb(aTHX_ "(dopoptoloop(): found loop at cx=%ld)\n", (long)i));
1603 /* find the next GIVEN or FOR (with implicit $_) loop context block */
1606 S_dopoptogivenfor(pTHX_ I32 startingblock)
1609 for (i = startingblock; i >= 0; i--) {
1610 const PERL_CONTEXT *cx = &cxstack[i];
1611 switch (CxTYPE(cx)) {
1615 DEBUG_l( Perl_deb(aTHX_ "(dopoptogivenfor(): found given at cx=%ld)\n", (long)i));
1617 case CXt_LOOP_PLAIN:
1618 assert(!(cx->cx_type & CXp_FOR_DEF));
1620 case CXt_LOOP_LAZYIV:
1621 case CXt_LOOP_LAZYSV:
1624 if (cx->cx_type & CXp_FOR_DEF) {
1625 DEBUG_l( Perl_deb(aTHX_ "(dopoptogivenfor(): found foreach at cx=%ld)\n", (long)i));
1634 S_dopoptowhen(pTHX_ I32 startingblock)
1637 for (i = startingblock; i >= 0; i--) {
1638 const PERL_CONTEXT *cx = &cxstack[i];
1639 switch (CxTYPE(cx)) {
1643 DEBUG_l( Perl_deb(aTHX_ "(dopoptowhen(): found when at cx=%ld)\n", (long)i));
1650 /* dounwind(): pop all contexts above (but not including) cxix.
1651 * Note that it clears the savestack frame associated with each popped
1652 * context entry, but doesn't free any temps.
1653 * It does a cx_popblock() of the last frame that it pops, and leaves
1654 * cxstack_ix equal to cxix.
1658 Perl_dounwind(pTHX_ I32 cxix)
1660 if (!PL_curstackinfo) /* can happen if die during thread cloning */
1663 while (cxstack_ix > cxix) {
1664 PERL_CONTEXT *cx = CX_CUR();
1666 CX_DEBUG(cx, "UNWIND");
1667 /* Note: we don't need to restore the base context info till the end. */
1671 switch (CxTYPE(cx)) {
1674 /* CXt_SUBST is not a block context type, so skip the
1675 * cx_popblock(cx) below */
1676 if (cxstack_ix == cxix + 1) {
1687 case CXt_LOOP_PLAIN:
1688 case CXt_LOOP_LAZYIV:
1689 case CXt_LOOP_LAZYSV:
1703 /* these two don't have a POPFOO() */
1709 if (cxstack_ix == cxix + 1) {
1718 Perl_qerror(pTHX_ SV *err)
1720 PERL_ARGS_ASSERT_QERROR;
1723 if (PL_in_eval & EVAL_KEEPERR) {
1724 Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "\t(in cleanup) %" SVf,
1728 sv_catsv(ERRSV, err);
1732 sv_catsv(PL_errors, err);
1734 Perl_warn(aTHX_ "%" SVf, SVfARG(err));
1737 ++PL_parser->error_count;
1741 if ( PL_parser && (err == NULL ||
1742 PL_parser->error_count >= PERL_STOP_PARSING_AFTER_N_ERRORS)
1744 const char * const name = OutCopFILE(PL_curcop);
1746 U8 raw_error_count = PERL_PARSE_ERROR_COUNT(PL_parser->error_count);
1753 abort_execution(errsv, name);
1756 if (raw_error_count >= PERL_STOP_PARSING_AFTER_N_ERRORS) {
1758 Perl_croak(aTHX_ "%" SVf "%s has too many errors.\n",
1759 SVfARG(errsv), name);
1761 Perl_croak(aTHX_ "%s has too many errors.\n", name);
1768 /* pop a CXt_EVAL context and in addition, if it was a require then
1770 * 0: do nothing extra;
1771 * 1: undef $INC{$name}; croak "$name did not return a true value";
1772 * 2: delete $INC{$name}; croak "$errsv: Compilation failed in require"
1776 S_pop_eval_context_maybe_croak(pTHX_ PERL_CONTEXT *cx, SV *errsv, int action)
1778 SV *namesv = NULL; /* init to avoid dumb compiler warning */
1782 do_croak = action && (CxOLD_OP_TYPE(cx) == OP_REQUIRE);
1784 /* keep namesv alive after cx_popeval() */
1785 namesv = cx->blk_eval.old_namesv;
1786 cx->blk_eval.old_namesv = NULL;
1795 HV *inc_hv = GvHVn(PL_incgv);
1798 (void)hv_delete_ent(inc_hv, namesv, G_DISCARD, 0);
1799 fmt = "%" SVf " did not return a true value";
1803 (void)hv_store_ent(inc_hv, namesv, &PL_sv_undef, 0);
1804 fmt = "%" SVf "Compilation failed in require";
1806 errsv = newSVpvs_flags("Unknown error\n", SVs_TEMP);
1809 Perl_croak(aTHX_ fmt, SVfARG(errsv));
1814 /* die_unwind(): this is the final destination for the various croak()
1815 * functions. If we're in an eval, unwind the context and other stacks
1816 * back to the top-most CXt_EVAL and set $@ to msv; otherwise print msv
1817 * to STDERR and initiate an exit. Note that if the CXt_EVAL popped back
1818 * to is a require the exception will be rethrown, as requires don't
1819 * actually trap exceptions.
1823 Perl_die_unwind(pTHX_ SV *msv)
1826 U8 in_eval = PL_in_eval;
1827 PERL_ARGS_ASSERT_DIE_UNWIND;
1832 /* We need to keep this SV alive through all the stack unwinding
1833 * and FREETMPSing below, while ensuing that it doesn't leak
1834 * if we call out to something which then dies (e.g. sub STORE{die}
1835 * when unlocalising a tied var). So we do a dance with
1836 * mortalising and SAVEFREEing.
1838 if (PL_phase == PERL_PHASE_DESTRUCT) {
1839 exceptsv = sv_mortalcopy(exceptsv);
1841 exceptsv = sv_2mortal(SvREFCNT_inc_simple_NN(exceptsv));
1845 * Historically, perl used to set ERRSV ($@) early in the die
1846 * process and rely on it not getting clobbered during unwinding.
1847 * That sucked, because it was liable to get clobbered, so the
1848 * setting of ERRSV used to emit the exception from eval{} has
1849 * been moved to much later, after unwinding (see just before
1850 * JMPENV_JUMP below). However, some modules were relying on the
1851 * early setting, by examining $@ during unwinding to use it as
1852 * a flag indicating whether the current unwinding was caused by
1853 * an exception. It was never a reliable flag for that purpose,
1854 * being totally open to false positives even without actual
1855 * clobberage, but was useful enough for production code to
1856 * semantically rely on it.
1858 * We'd like to have a proper introspective interface that
1859 * explicitly describes the reason for whatever unwinding
1860 * operations are currently in progress, so that those modules
1861 * work reliably and $@ isn't further overloaded. But we don't
1862 * have one yet. In its absence, as a stopgap measure, ERRSV is
1863 * now *additionally* set here, before unwinding, to serve as the
1864 * (unreliable) flag that it used to.
1866 * This behaviour is temporary, and should be removed when a
1867 * proper way to detect exceptional unwinding has been developed.
1868 * As of 2010-12, the authors of modules relying on the hack
1869 * are aware of the issue, because the modules failed on
1870 * perls 5.13.{1..7} which had late setting of $@ without this
1871 * early-setting hack.
1873 if (!(in_eval & EVAL_KEEPERR)) {
1874 /* remove any read-only/magic from the SV, so we don't
1875 get infinite recursion when setting ERRSV */
1877 sv_setsv_flags(ERRSV, exceptsv,
1878 (SV_GMAGIC|SV_DO_COW_SVSETSV|SV_NOSTEAL));
1881 if (in_eval & EVAL_KEEPERR) {
1882 Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "\t(in cleanup) %" SVf,
1886 while ((cxix = dopoptoeval(cxstack_ix)) < 0
1887 && PL_curstackinfo->si_prev)
1897 JMPENV *restartjmpenv;
1900 if (cxix < cxstack_ix)
1904 assert(CxTYPE(cx) == CXt_EVAL);
1906 /* return false to the caller of eval */
1907 oldsp = PL_stack_base + cx->blk_oldsp;
1908 gimme = cx->blk_gimme;
1909 if (gimme == G_SCALAR)
1910 *++oldsp = &PL_sv_undef;
1911 PL_stack_sp = oldsp;
1913 restartjmpenv = cx->blk_eval.cur_top_env;
1914 restartop = cx->blk_eval.retop;
1916 /* We need a FREETMPS here to avoid late-called destructors
1917 * clobbering $@ *after* we set it below, e.g.
1918 * sub DESTROY { eval { die "X" } }
1919 * eval { my $x = bless []; die $x = 0, "Y" };
1921 * Here the clearing of the $x ref mortalises the anon array,
1922 * which needs to be freed *before* $& is set to "Y",
1923 * otherwise it gets overwritten with "X".
1925 * However, the FREETMPS will clobber exceptsv, so preserve it
1926 * on the savestack for now.
1928 SAVEFREESV(SvREFCNT_inc_simple_NN(exceptsv));
1930 /* now we're about to pop the savestack, so re-mortalise it */
1931 sv_2mortal(SvREFCNT_inc_simple_NN(exceptsv));
1933 /* Note that unlike pp_entereval, pp_require isn't supposed to
1934 * trap errors. So if we're a require, after we pop the
1935 * CXt_EVAL that pp_require pushed, rethrow the error with
1936 * croak(exceptsv). This is all handled by the call below when
1939 S_pop_eval_context_maybe_croak(aTHX_ cx, exceptsv, 2);
1941 if (!(in_eval & EVAL_KEEPERR)) {
1943 sv_setsv(ERRSV, exceptsv);
1945 PL_restartjmpenv = restartjmpenv;
1946 PL_restartop = restartop;
1948 NOT_REACHED; /* NOTREACHED */
1952 write_to_stderr(exceptsv);
1954 NOT_REACHED; /* NOTREACHED */
1960 if (SvTRUE_NN(left) != SvTRUE_NN(right))
1968 =for apidoc_section $CV
1970 =for apidoc caller_cx
1972 The XSUB-writer's equivalent of L<caller()|perlfunc/caller>. The
1973 returned C<PERL_CONTEXT> structure can be interrogated to find all the
1974 information returned to Perl by C<caller>. Note that XSUBs don't get a
1975 stack frame, so C<caller_cx(0, NULL)> will return information for the
1976 immediately-surrounding Perl code.
1978 This function skips over the automatic calls to C<&DB::sub> made on the
1979 behalf of the debugger. If the stack frame requested was a sub called by
1980 C<DB::sub>, the return value will be the frame for the call to
1981 C<DB::sub>, since that has the correct line number/etc. for the call
1982 site. If I<dbcxp> is non-C<NULL>, it will be set to a pointer to the
1983 frame for the sub call itself.
1988 const PERL_CONTEXT *
1989 Perl_caller_cx(pTHX_ I32 count, const PERL_CONTEXT **dbcxp)
1991 I32 cxix = dopopto_cursub();
1992 const PERL_CONTEXT *cx;
1993 const PERL_CONTEXT *ccstack = cxstack;
1994 const PERL_SI *top_si = PL_curstackinfo;
1997 /* we may be in a higher stacklevel, so dig down deeper */
1998 while (cxix < 0 && top_si->si_type != PERLSI_MAIN) {
1999 top_si = top_si->si_prev;
2000 ccstack = top_si->si_cxstack;
2001 cxix = dopoptosub_at(ccstack, top_si->si_cxix);
2005 /* caller() should not report the automatic calls to &DB::sub */
2006 if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 &&
2007 ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub))
2011 cxix = dopoptosub_at(ccstack, cxix - 1);
2014 cx = &ccstack[cxix];
2015 if (dbcxp) *dbcxp = cx;
2017 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
2018 const I32 dbcxix = dopoptosub_at(ccstack, cxix - 1);
2019 /* We expect that ccstack[dbcxix] is CXt_SUB, anyway, the
2020 field below is defined for any cx. */
2021 /* caller() should not report the automatic calls to &DB::sub */
2022 if (PL_DBsub && GvCV(PL_DBsub) && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub))
2023 cx = &ccstack[dbcxix];
2032 const PERL_CONTEXT *cx;
2033 const PERL_CONTEXT *dbcx;
2035 const HEK *stash_hek;
2037 bool has_arg = MAXARG && TOPs;
2046 cx = caller_cx(count + cBOOL(PL_op->op_private & OPpOFFBYONE), &dbcx);
2048 if (gimme != G_LIST) {
2055 CX_DEBUG(cx, "CALLER");
2056 assert(CopSTASH(cx->blk_oldcop));
2057 stash_hek = SvTYPE(CopSTASH(cx->blk_oldcop)) == SVt_PVHV
2058 ? HvNAME_HEK((HV*)CopSTASH(cx->blk_oldcop))
2060 if (gimme != G_LIST) {
2063 PUSHs(&PL_sv_undef);
2066 sv_sethek(TARG, stash_hek);
2075 PUSHs(&PL_sv_undef);
2078 sv_sethek(TARG, stash_hek);
2081 mPUSHs(newSVpv(OutCopFILE(cx->blk_oldcop), 0));
2082 lcop = closest_cop(cx->blk_oldcop, OpSIBLING(cx->blk_oldcop),
2083 cx->blk_sub.retop, TRUE);
2085 lcop = cx->blk_oldcop;
2086 mPUSHu(CopLINE(lcop));
2089 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
2090 /* So is ccstack[dbcxix]. */
2091 if (CvHASGV(dbcx->blk_sub.cv)) {
2092 PUSHs(cv_name(dbcx->blk_sub.cv, 0, 0));
2093 PUSHs(boolSV(CxHASARGS(cx)));
2096 PUSHs(newSVpvs_flags("(unknown)", SVs_TEMP));
2097 PUSHs(boolSV(CxHASARGS(cx)));
2101 PUSHs(newSVpvs_flags("(eval)", SVs_TEMP));
2104 gimme = cx->blk_gimme;
2105 if (gimme == G_VOID)
2106 PUSHs(&PL_sv_undef);
2108 PUSHs(boolSV((gimme & G_WANT) == G_LIST));
2109 if (CxTYPE(cx) == CXt_EVAL) {
2111 if (CxOLD_OP_TYPE(cx) == OP_ENTEREVAL) {
2112 SV *cur_text = cx->blk_eval.cur_text;
2113 if (SvCUR(cur_text) >= 2) {
2114 PUSHs(newSVpvn_flags(SvPVX(cur_text), SvCUR(cur_text)-2,
2115 SvUTF8(cur_text)|SVs_TEMP));
2118 /* I think this is will always be "", but be sure */
2119 PUSHs(sv_2mortal(newSVsv(cur_text)));
2125 else if (cx->blk_eval.old_namesv) {
2126 mPUSHs(newSVsv(cx->blk_eval.old_namesv));
2129 /* eval BLOCK (try blocks have old_namesv == 0) */
2131 PUSHs(&PL_sv_undef);
2132 PUSHs(&PL_sv_undef);
2136 PUSHs(&PL_sv_undef);
2137 PUSHs(&PL_sv_undef);
2139 if (CxTYPE(cx) == CXt_SUB && CxHASARGS(cx)
2140 && CopSTASH_eq(PL_curcop, PL_debstash))
2142 /* slot 0 of the pad contains the original @_ */
2143 AV * const ary = MUTABLE_AV(AvARRAY(MUTABLE_AV(
2144 PadlistARRAY(CvPADLIST(cx->blk_sub.cv))[
2145 cx->blk_sub.olddepth+1]))[0]);
2146 const SSize_t off = AvARRAY(ary) - AvALLOC(ary);
2148 Perl_init_dbargs(aTHX);
2150 if (AvMAX(PL_dbargs) < AvFILLp(ary) + off)
2151 av_extend(PL_dbargs, AvFILLp(ary) + off);
2152 if (AvFILLp(ary) + 1 + off)
2153 Copy(AvALLOC(ary), AvARRAY(PL_dbargs), AvFILLp(ary) + 1 + off, SV*);
2154 AvFILLp(PL_dbargs) = AvFILLp(ary) + off;
2156 mPUSHi(CopHINTS_get(cx->blk_oldcop));
2159 char *old_warnings = cx->blk_oldcop->cop_warnings;
2161 if (old_warnings == pWARN_NONE)
2162 mask = newSVpvn(WARN_NONEstring, WARNsize) ;
2163 else if (old_warnings == pWARN_STD && (PL_dowarn & G_WARN_ON) == 0)
2164 mask = &PL_sv_undef ;
2165 else if (old_warnings == pWARN_ALL ||
2166 (old_warnings == pWARN_STD && PL_dowarn & G_WARN_ON)) {
2167 mask = newSVpvn(WARN_ALLstring, WARNsize) ;
2170 mask = newSVpvn(old_warnings, RCPV_LEN(old_warnings));
2174 PUSHs(cx->blk_oldcop->cop_hints_hash ?
2175 sv_2mortal(newRV_noinc(MUTABLE_SV(cop_hints_2hv(cx->blk_oldcop, 0))))
2185 if (MAXARG < 1 || (!TOPs && !POPs)) {
2187 tmps = NULL, len = 0;
2190 tmps = SvPVx_const(POPs, len);
2191 sv_resetpvn(tmps, len, CopSTASH(PL_curcop));
2196 /* like pp_nextstate, but used instead when the debugger is active */
2200 PL_curcop = (COP*)PL_op;
2201 TAINT_NOT; /* Each statement is presumed innocent */
2202 PL_stack_sp = PL_stack_base + CX_CUR()->blk_oldsp;
2207 if (PL_op->op_flags & OPf_SPECIAL /* breakpoint */
2208 || PL_DBsingle_iv || PL_DBsignal_iv || PL_DBtrace_iv)
2212 const U8 gimme = G_LIST;
2213 GV * const gv = PL_DBgv;
2216 if (gv && isGV_with_GP(gv))
2219 if (!cv || (!CvROOT(cv) && !CvXSUB(cv)))
2220 DIE(aTHX_ "No DB::DB routine defined");
2222 if (CvDEPTH(cv) >= 1 && !(PL_debug & DEBUG_DB_RECURSE_FLAG))
2223 /* don't do recursive DB::DB call */
2233 (void)(*CvXSUB(cv))(aTHX_ cv);
2239 cx = cx_pushblock(CXt_SUB, gimme, SP, PL_savestack_ix);
2240 cx_pushsub(cx, cv, PL_op->op_next, 0);
2241 /* OP_DBSTATE's op_private holds hint bits rather than
2242 * the lvalue-ish flags seen in OP_ENTERSUB. So cancel
2243 * any CxLVAL() flags that have now been mis-calculated */
2250 if (CvDEPTH(cv) >= 2)
2251 pad_push(CvPADLIST(cv), CvDEPTH(cv));
2252 PAD_SET_CUR_NOSAVE(CvPADLIST(cv), CvDEPTH(cv));
2253 RETURNOP(CvSTART(cv));
2265 (void)cx_pushblock(CXt_BLOCK, gimme, PL_stack_sp, PL_savestack_ix);
2277 assert(CxTYPE(cx) == CXt_BLOCK);
2279 if (PL_op->op_flags & OPf_SPECIAL)
2280 /* fake block should preserve $1 et al; e.g. /(...)/ while ...; */
2281 cx->blk_oldpm = PL_curpm;
2283 oldsp = PL_stack_base + cx->blk_oldsp;
2284 gimme = cx->blk_gimme;
2286 if (gimme == G_VOID)
2287 PL_stack_sp = oldsp;
2289 leave_adjust_stacks(oldsp, oldsp, gimme,
2290 PL_op->op_private & OPpLVALUE ? 3 : 1);
2300 S_outside_integer(pTHX_ SV *sv)
2303 const NV nv = SvNV_nomg(sv);
2304 if (Perl_isinfnan(nv))
2306 #ifdef NV_PRESERVES_UV
2307 if (nv < (NV)IV_MIN || nv > (NV)IV_MAX)
2310 if (nv <= (NV)IV_MIN)
2313 ((nv > (NV)UV_MAX ||
2314 SvUV_nomg(sv) > (UV)IV_MAX)))
2325 const U8 gimme = GIMME_V;
2326 void *itervarp; /* GV or pad slot of the iteration variable */
2327 SV *itersave; /* the old var in the iterator var slot */
2330 if (PL_op->op_targ) { /* "my" variable */
2331 itervarp = &PAD_SVl(PL_op->op_targ);
2332 itersave = *(SV**)itervarp;
2334 if (PL_op->op_private & OPpLVAL_INTRO) { /* for my $x (...) */
2335 /* the SV currently in the pad slot is never live during
2336 * iteration (the slot is always aliased to one of the items)
2337 * so it's always stale */
2338 SvPADSTALE_on(itersave);
2340 SvREFCNT_inc_simple_void_NN(itersave);
2341 cxflags = CXp_FOR_PAD;
2344 SV * const sv = POPs;
2345 itervarp = (void *)sv;
2346 if (LIKELY(isGV(sv))) { /* symbol table variable */
2347 SvREFCNT_inc_simple_void(sv);
2348 itersave = GvSV(sv);
2349 SvREFCNT_inc_simple_void(itersave);
2350 cxflags = CXp_FOR_GV;
2351 if (PL_op->op_private & OPpITER_DEF)
2352 cxflags |= CXp_FOR_DEF;
2354 else { /* LV ref: for \$foo (...) */
2355 assert(SvTYPE(sv) == SVt_PVMG);
2356 assert(SvMAGIC(sv));
2357 assert(SvMAGIC(sv)->mg_type == PERL_MAGIC_lvref);
2359 cxflags = CXp_FOR_LVREF;
2360 SvREFCNT_inc_simple_void(sv);
2363 /* OPpITER_DEF (implicit $_) should only occur with a GV iter var */
2364 assert((cxflags & CXp_FOR_GV) || !(PL_op->op_private & OPpITER_DEF));
2366 /* Note that this context is initially set as CXt_NULL. Further on
2367 * down it's changed to one of the CXt_LOOP_*. Before it's changed,
2368 * there mustn't be anything in the blk_loop substruct that requires
2369 * freeing or undoing, in case we die in the meantime. And vice-versa.
2371 cx = cx_pushblock(cxflags, gimme, MARK, PL_savestack_ix);
2372 cx_pushloop_for(cx, itervarp, itersave);
2374 if (PL_op->op_flags & OPf_STACKED) {
2375 /* OPf_STACKED implies either a single array: for(@), with a
2376 * single AV on the stack, or a range: for (1..5), with 1 and 5 on
2378 SV *maybe_ary = POPs;
2379 if (SvTYPE(maybe_ary) != SVt_PVAV) {
2382 SV * const right = maybe_ary;
2383 if (UNLIKELY(cxflags & CXp_FOR_LVREF))
2384 DIE(aTHX_ "Assigned value is not a reference");
2387 if (RANGE_IS_NUMERIC(sv,right)) {
2388 cx->cx_type |= CXt_LOOP_LAZYIV;
2389 if (S_outside_integer(aTHX_ sv) ||
2390 S_outside_integer(aTHX_ right))
2391 DIE(aTHX_ "Range iterator outside integer range");
2392 cx->blk_loop.state_u.lazyiv.cur = SvIV_nomg(sv);
2393 cx->blk_loop.state_u.lazyiv.end = SvIV_nomg(right);
2396 cx->cx_type |= CXt_LOOP_LAZYSV;
2397 cx->blk_loop.state_u.lazysv.cur = newSVsv(sv);
2398 cx->blk_loop.state_u.lazysv.end = right;
2399 SvREFCNT_inc_simple_void_NN(right);
2400 (void) SvPV_force_nolen(cx->blk_loop.state_u.lazysv.cur);
2401 /* This will do the upgrade to SVt_PV, and warn if the value
2402 is uninitialised. */
2403 (void) SvPV_nolen_const(right);
2404 /* Doing this avoids a check every time in pp_iter in pp_hot.c
2405 to replace !SvOK() with a pointer to "". */
2407 SvREFCNT_dec(right);
2408 cx->blk_loop.state_u.lazysv.end = &PL_sv_no;
2412 else /* SvTYPE(maybe_ary) == SVt_PVAV */ {
2413 /* for (@array) {} */
2414 cx->cx_type |= CXt_LOOP_ARY;
2415 cx->blk_loop.state_u.ary.ary = MUTABLE_AV(maybe_ary);
2416 SvREFCNT_inc_simple_void_NN(maybe_ary);
2417 cx->blk_loop.state_u.ary.ix =
2418 (PL_op->op_private & OPpITER_REVERSED) ?
2419 AvFILL(cx->blk_loop.state_u.ary.ary) + 1 :
2422 /* EXTEND(SP, 1) not needed in this branch because we just did POPs */
2424 else { /* iterating over items on the stack */
2425 cx->cx_type |= CXt_LOOP_LIST;
2426 cx->blk_oldsp = SP - PL_stack_base;
2427 cx->blk_loop.state_u.stack.basesp = MARK - PL_stack_base;
2428 cx->blk_loop.state_u.stack.ix =
2429 (PL_op->op_private & OPpITER_REVERSED)
2431 : cx->blk_loop.state_u.stack.basesp;
2432 /* pre-extend stack so pp_iter doesn't have to check every time
2433 * it pushes yes/no */
2443 const U8 gimme = GIMME_V;
2445 cx = cx_pushblock(CXt_LOOP_PLAIN, gimme, PL_stack_sp, PL_savestack_ix);
2446 cx_pushloop_plain(cx);
2459 assert(CxTYPE_is_LOOP(cx));
2460 oldsp = PL_stack_base + cx->blk_oldsp;
2461 base = CxTYPE(cx) == CXt_LOOP_LIST
2462 ? PL_stack_base + cx->blk_loop.state_u.stack.basesp
2464 gimme = cx->blk_gimme;
2466 if (gimme == G_VOID)
2469 leave_adjust_stacks(oldsp, base, gimme,
2470 PL_op->op_private & OPpLVALUE ? 3 : 1);
2473 cx_poploop(cx); /* Stack values are safe: release loop vars ... */
2481 /* This duplicates most of pp_leavesub, but with additional code to handle
2482 * return args in lvalue context. It was forked from pp_leavesub to
2483 * avoid slowing down that function any further.
2485 * Any changes made to this function may need to be copied to pp_leavesub
2488 * also tail-called by pp_return
2499 assert(CxTYPE(cx) == CXt_SUB);
2501 if (CxMULTICALL(cx)) {
2502 /* entry zero of a stack is always PL_sv_undef, which
2503 * simplifies converting a '()' return into undef in scalar context */
2504 assert(PL_stack_sp > PL_stack_base || *PL_stack_base == &PL_sv_undef);
2508 gimme = cx->blk_gimme;
2509 oldsp = PL_stack_base + cx->blk_oldsp; /* last arg of previous frame */
2511 if (gimme == G_VOID)
2512 PL_stack_sp = oldsp;
2514 U8 lval = CxLVAL(cx);
2515 bool is_lval = (lval && !(lval & OPpENTERSUB_INARGS));
2516 const char *what = NULL;
2518 if (gimme == G_SCALAR) {
2520 /* check for bad return arg */
2521 if (oldsp < PL_stack_sp) {
2522 SV *sv = *PL_stack_sp;
2523 if ((SvPADTMP(sv) || SvREADONLY(sv))) {
2525 SvREADONLY(sv) ? (sv == &PL_sv_undef) ? "undef"
2526 : "a readonly value" : "a temporary";
2531 /* sub:lvalue{} will take us here. */
2536 "Can't return %s from lvalue subroutine", what);
2540 leave_adjust_stacks(oldsp, oldsp, gimme, is_lval ? 3 : 2);
2542 if (lval & OPpDEREF) {
2543 /* lval_sub()->{...} and similar */
2547 TOPs = vivify_ref(TOPs, CxLVAL(cx) & OPpDEREF);
2553 assert(gimme == G_LIST);
2554 assert (!(lval & OPpDEREF));
2557 /* scan for bad return args */
2559 for (p = PL_stack_sp; p > oldsp; p--) {
2561 /* the PL_sv_undef exception is to allow things like
2562 * this to work, where PL_sv_undef acts as 'skip'
2563 * placeholder on the LHS of list assigns:
2564 * sub foo :lvalue { undef }
2565 * ($a, undef, foo(), $b) = 1..4;
2567 if (sv != &PL_sv_undef && (SvPADTMP(sv) || SvREADONLY(sv)))
2569 /* Might be flattened array after $#array = */
2570 what = SvREADONLY(sv)
2571 ? "a readonly value" : "a temporary";
2577 leave_adjust_stacks(oldsp, oldsp, gimme, is_lval ? 3 : 2);
2582 cx_popsub(cx); /* Stack values are safe: release CV and @_ ... */
2584 retop = cx->blk_sub.retop;
2590 static const char *S_defer_blockname(PERL_CONTEXT *cx)
2592 return (cx->cx_type & CXp_FINALLY) ? "finally" : "defer";
2600 I32 cxix = dopopto_cursub();
2602 assert(cxstack_ix >= 0);
2603 if (cxix < cxstack_ix) {
2605 /* Check for defer { return; } */
2606 for(i = cxstack_ix; i > cxix; i--) {
2607 if(CxTYPE(&cxstack[i]) == CXt_DEFER)
2608 /* diag_listed_as: Can't "%s" out of a "defer" block */
2609 /* diag_listed_as: Can't "%s" out of a "finally" block */
2610 Perl_croak(aTHX_ "Can't \"%s\" out of a \"%s\" block",
2611 "return", S_defer_blockname(&cxstack[i]));
2614 if (!( PL_curstackinfo->si_type == PERLSI_SORT
2615 || ( PL_curstackinfo->si_type == PERLSI_MULTICALL
2616 && (cxstack[0].cx_type & CXp_SUB_RE_FAKE))
2619 DIE(aTHX_ "Can't return outside a subroutine");
2621 * a sort block, which is a CXt_NULL not a CXt_SUB;
2622 * or a /(?{...})/ block.
2623 * Handle specially. */
2624 assert(CxTYPE(&cxstack[0]) == CXt_NULL
2625 || ( CxTYPE(&cxstack[0]) == CXt_SUB
2626 && (cxstack[0].cx_type & CXp_SUB_RE_FAKE)));
2627 if (cxstack_ix > 0) {
2628 /* See comment below about context popping. Since we know
2629 * we're scalar and not lvalue, we can preserve the return
2630 * value in a simpler fashion than there. */
2632 assert(cxstack[0].blk_gimme == G_SCALAR);
2633 if ( (sp != PL_stack_base)
2634 && !(SvFLAGS(sv) & (SVs_TEMP|SVs_PADTMP))
2636 *SP = sv_mortalcopy(sv);
2639 /* caller responsible for popping cxstack[0] */
2643 /* There are contexts that need popping. Doing this may free the
2644 * return value(s), so preserve them first: e.g. popping the plain
2645 * loop here would free $x:
2646 * sub f { { my $x = 1; return $x } }
2647 * We may also need to shift the args down; for example,
2648 * for (1,2) { return 3,4 }
2649 * leaves 1,2,3,4 on the stack. Both these actions will be done by
2650 * leave_adjust_stacks(), along with freeing any temps. Note that
2651 * whoever we tail-call (e.g. pp_leaveeval) will also call
2652 * leave_adjust_stacks(); however, the second call is likely to
2653 * just see a bunch of SvTEMPs with a ref count of 1, and so just
2654 * pass them through, rather than copying them again. So this
2655 * isn't as inefficient as it sounds.
2657 cx = &cxstack[cxix];
2659 if (cx->blk_gimme != G_VOID)
2660 leave_adjust_stacks(MARK, PL_stack_base + cx->blk_oldsp,
2662 CxTYPE(cx) == CXt_SUB && CvLVALUE(cx->blk_sub.cv)
2666 cx = &cxstack[cxix]; /* CX stack may have been realloced */
2669 /* Like in the branch above, we need to handle any extra junk on
2670 * the stack. But because we're not also popping extra contexts, we
2671 * don't have to worry about prematurely freeing args. So we just
2672 * need to do the bare minimum to handle junk, and leave the main
2673 * arg processing in the function we tail call, e.g. pp_leavesub.
2674 * In list context we have to splice out the junk; in scalar
2675 * context we can leave as-is (pp_leavesub will later return the
2676 * top stack element). But for an empty arg list, e.g.
2677 * for (1,2) { return }
2678 * we need to set sp = oldsp so that pp_leavesub knows to push
2679 * &PL_sv_undef onto the stack.
2682 cx = &cxstack[cxix];
2683 oldsp = PL_stack_base + cx->blk_oldsp;
2684 if (oldsp != MARK) {
2685 SSize_t nargs = SP - MARK;
2687 if (cx->blk_gimme == G_LIST) {
2688 /* shift return args to base of call stack frame */
2689 Move(MARK + 1, oldsp + 1, nargs, SV*);
2690 PL_stack_sp = oldsp + nargs;
2694 PL_stack_sp = oldsp;
2698 /* fall through to a normal exit */
2699 switch (CxTYPE(cx)) {
2701 return CxEVALBLOCK(cx)
2702 ? Perl_pp_leavetry(aTHX)
2703 : Perl_pp_leaveeval(aTHX);
2705 return CvLVALUE(cx->blk_sub.cv)
2706 ? Perl_pp_leavesublv(aTHX)
2707 : Perl_pp_leavesub(aTHX);
2709 return Perl_pp_leavewrite(aTHX);
2711 DIE(aTHX_ "panic: return, type=%u", (unsigned) CxTYPE(cx));
2715 /* find the enclosing loop or labelled loop and dounwind() back to it. */
2717 static PERL_CONTEXT *
2721 if (PL_op->op_flags & OPf_SPECIAL) {
2722 cxix = dopoptoloop(cxstack_ix);
2724 /* diag_listed_as: Can't "last" outside a loop block */
2725 Perl_croak(aTHX_ "Can't \"%s\" outside a loop block",
2734 if (PL_op->op_flags & OPf_STACKED) {
2738 label = SvPV(sv, label_len);
2739 label_flags = SvUTF8(sv);
2742 sv = NULL; /* not needed, but shuts up compiler warn */
2743 label = cPVOP->op_pv;
2744 label_len = strlen(label);
2745 label_flags = (cPVOP->op_private & OPpPV_IS_UTF8) ? SVf_UTF8 : 0;
2748 cxix = dopoptolabel(label, label_len, label_flags);
2750 /* diag_listed_as: Label not found for "last %s" */
2751 Perl_croak(aTHX_ "Label not found for \"%s %" SVf "\"",
2753 SVfARG(PL_op->op_flags & OPf_STACKED
2756 : newSVpvn_flags(label,
2758 label_flags | SVs_TEMP)));
2760 if (cxix < cxstack_ix) {
2762 /* Check for defer { last ... } etc */
2763 for(i = cxstack_ix; i > cxix; i--) {
2764 if(CxTYPE(&cxstack[i]) == CXt_DEFER)
2765 /* diag_listed_as: Can't "%s" out of a "defer" block */
2766 /* diag_listed_as: Can't "%s" out of a "finally" block */
2767 Perl_croak(aTHX_ "Can't \"%s\" out of a \"%s\" block",
2768 OP_NAME(PL_op), S_defer_blockname(&cxstack[i]));
2772 return &cxstack[cxix];
2781 cx = S_unwind_loop(aTHX);
2783 assert(CxTYPE_is_LOOP(cx));
2784 PL_stack_sp = PL_stack_base
2785 + (CxTYPE(cx) == CXt_LOOP_LIST
2786 ? cx->blk_loop.state_u.stack.basesp
2792 /* Stack values are safe: */
2794 cx_poploop(cx); /* release loop vars ... */
2796 nextop = cx->blk_loop.my_op->op_lastop->op_next;
2806 /* if not a bare 'next' in the main scope, search for it */
2808 if (!((PL_op->op_flags & OPf_SPECIAL) && CxTYPE_is_LOOP(cx)))
2809 cx = S_unwind_loop(aTHX);
2812 PL_curcop = cx->blk_oldcop;
2814 return (cx)->blk_loop.my_op->op_nextop;
2819 PERL_CONTEXT *cx = S_unwind_loop(aTHX);
2820 OP* redo_op = cx->blk_loop.my_op->op_redoop;
2822 if (redo_op->op_type == OP_ENTER) {
2823 /* pop one less context to avoid $x being freed in while (my $x..) */
2826 assert(CxTYPE(cx) == CXt_BLOCK);
2827 redo_op = redo_op->op_next;
2833 PL_curcop = cx->blk_oldcop;
2838 #define UNENTERABLE (OP *)1
2839 #define GOTO_DEPTH 64
2842 S_dofindlabel(pTHX_ OP *o, const char *label, STRLEN len, U32 flags, OP **opstack, OP **oplimit)
2845 static const char* const too_deep = "Target of goto is too deeply nested";
2847 PERL_ARGS_ASSERT_DOFINDLABEL;
2850 Perl_croak(aTHX_ "%s", too_deep);
2851 if (o->op_type == OP_LEAVE ||
2852 o->op_type == OP_SCOPE ||
2853 o->op_type == OP_LEAVELOOP ||
2854 o->op_type == OP_LEAVESUB ||
2855 o->op_type == OP_LEAVETRY ||
2856 o->op_type == OP_LEAVEGIVEN)
2858 *ops++ = cUNOPo->op_first;
2860 else if (oplimit - opstack < GOTO_DEPTH) {
2861 if (o->op_flags & OPf_KIDS
2862 && cUNOPo->op_first->op_type == OP_PUSHMARK) {
2863 *ops++ = UNENTERABLE;
2865 else if (o->op_flags & OPf_KIDS && PL_opargs[o->op_type]
2866 && OP_CLASS(o) != OA_LOGOP
2867 && o->op_type != OP_LINESEQ
2868 && o->op_type != OP_SREFGEN
2869 && o->op_type != OP_ENTEREVAL
2870 && o->op_type != OP_GLOB
2871 && o->op_type != OP_RV2CV) {
2872 OP * const kid = cUNOPo->op_first;
2873 if (OP_GIMME(kid, 0) != G_SCALAR || OpHAS_SIBLING(kid))
2874 *ops++ = UNENTERABLE;
2878 Perl_croak(aTHX_ "%s", too_deep);
2880 if (o->op_flags & OPf_KIDS) {
2882 OP * const kid1 = cUNOPo->op_first;
2883 /* First try all the kids at this level, since that's likeliest. */
2884 for (kid = cUNOPo->op_first; kid; kid = OpSIBLING(kid)) {
2885 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
2886 STRLEN kid_label_len;
2887 U32 kid_label_flags;
2888 const char *kid_label = CopLABEL_len_flags(kCOP,
2889 &kid_label_len, &kid_label_flags);
2891 ( (kid_label_flags & SVf_UTF8) != (flags & SVf_UTF8) ) ?
2894 (const U8*)kid_label, kid_label_len,
2895 (const U8*)label, len) == 0)
2897 (const U8*)label, len,
2898 (const U8*)kid_label, kid_label_len) == 0)
2899 : ( len == kid_label_len && ((kid_label == label)
2900 || memEQ(kid_label, label, len)))))
2904 for (kid = cUNOPo->op_first; kid; kid = OpSIBLING(kid)) {
2905 bool first_kid_of_binary = FALSE;
2906 if (kid == PL_lastgotoprobe)
2908 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
2911 else if (ops[-1] != UNENTERABLE
2912 && (ops[-1]->op_type == OP_NEXTSTATE ||
2913 ops[-1]->op_type == OP_DBSTATE))
2918 if (kid == kid1 && ops != opstack && ops[-1] == UNENTERABLE) {
2919 first_kid_of_binary = TRUE;
2922 if ((o = dofindlabel(kid, label, len, flags, ops, oplimit))) {
2923 if (kid->op_type == OP_PUSHDEFER)
2924 Perl_croak(aTHX_ "Can't \"goto\" into a \"defer\" block");
2927 if (first_kid_of_binary)
2928 *ops++ = UNENTERABLE;
2937 S_check_op_type(pTHX_ OP * const o)
2939 /* Eventually we may want to stack the needed arguments
2940 * for each op. For now, we punt on the hard ones. */
2941 /* XXX This comment seems to me like wishful thinking. --sprout */
2942 if (o == UNENTERABLE)
2944 "Can't \"goto\" into a binary or list expression");
2945 if (o->op_type == OP_ENTERITER)
2947 "Can't \"goto\" into the middle of a foreach loop");
2948 if (o->op_type == OP_ENTERGIVEN)
2950 "Can't \"goto\" into a \"given\" block");
2953 /* also used for: pp_dump() */
2961 OP *enterops[GOTO_DEPTH];
2962 const char *label = NULL;
2963 STRLEN label_len = 0;
2964 U32 label_flags = 0;
2965 const bool do_dump = (PL_op->op_type == OP_DUMP);
2966 static const char* const must_have_label = "goto must have label";
2968 if (PL_op->op_flags & OPf_STACKED) {
2969 /* goto EXPR or goto &foo */
2971 SV * const sv = POPs;
2974 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
2975 /* This egregious kludge implements goto &subroutine */
2978 CV *cv = MUTABLE_CV(SvRV(sv));
2979 AV *arg = GvAV(PL_defgv);
2982 while (!CvROOT(cv) && !CvXSUB(cv)) {
2983 const GV * const gv = CvGV(cv);
2987 /* autoloaded stub? */
2988 if (cv != GvCV(gv) && (cv = GvCV(gv)))
2990 autogv = gv_autoload_pvn(GvSTASH(gv), GvNAME(gv),
2992 GvNAMEUTF8(gv) ? SVf_UTF8 : 0);
2993 if (autogv && (cv = GvCV(autogv)))
2995 tmpstr = sv_newmortal();
2996 gv_efullname3(tmpstr, gv, NULL);
2997 DIE(aTHX_ "Goto undefined subroutine &%" SVf, SVfARG(tmpstr));
2999 DIE(aTHX_ "Goto undefined subroutine");
3002 cxix = dopopto_cursub();
3004 DIE(aTHX_ "Can't goto subroutine outside a subroutine");
3006 cx = &cxstack[cxix];
3007 /* ban goto in eval: see <20050521150056.GC20213@iabyn.com> */
3008 if (CxTYPE(cx) == CXt_EVAL) {
3010 /* diag_listed_as: Can't goto subroutine from an eval-%s */
3011 DIE(aTHX_ "Can't goto subroutine from an eval-string");
3013 /* diag_listed_as: Can't goto subroutine from an eval-%s */
3014 DIE(aTHX_ "Can't goto subroutine from an eval-block");
3016 else if (CxMULTICALL(cx))
3017 DIE(aTHX_ "Can't goto subroutine from a sort sub (or similar callback)");
3019 /* Check for defer { goto &...; } */
3020 for(ix = cxstack_ix; ix > cxix; ix--) {
3021 if(CxTYPE(&cxstack[ix]) == CXt_DEFER)
3022 /* diag_listed_as: Can't "%s" out of a "defer" block */
3023 Perl_croak(aTHX_ "Can't \"%s\" out of a \"%s\" block",
3024 "goto", S_defer_blockname(&cxstack[ix]));
3027 /* First do some returnish stuff. */
3029 SvREFCNT_inc_simple_void(cv); /* avoid premature free during unwind */
3031 if (cxix < cxstack_ix) {
3038 /* protect @_ during save stack unwind. */
3040 SvREFCNT_inc_NN(sv_2mortal(MUTABLE_SV(arg)));
3042 assert(PL_scopestack_ix == cx->blk_oldscopesp);
3045 if (CxTYPE(cx) == CXt_SUB && CxHASARGS(cx)) {
3046 /* this is part of cx_popsub_args() */
3047 AV* av = MUTABLE_AV(PAD_SVl(0));
3048 assert(AvARRAY(MUTABLE_AV(
3049 PadlistARRAY(CvPADLIST(cx->blk_sub.cv))[
3050 CvDEPTH(cx->blk_sub.cv)])) == PL_curpad);
3052 /* we are going to donate the current @_ from the old sub
3053 * to the new sub. This first part of the donation puts a
3054 * new empty AV in the pad[0] slot of the old sub,
3055 * unless pad[0] and @_ differ (e.g. if the old sub did
3056 * local *_ = []); in which case clear the old pad[0]
3057 * array in the usual way */
3058 if (av == arg || AvREAL(av))
3059 clear_defarray(av, av == arg);
3060 else CLEAR_ARGARRAY(av);
3063 /* don't restore PL_comppad here. It won't be needed if the
3064 * sub we're going to is non-XS, but restoring it early then
3065 * croaking (e.g. the "Goto undefined subroutine" below)
3066 * means the CX block gets processed again in dounwind,
3067 * but this time with the wrong PL_comppad */
3069 /* A destructor called during LEAVE_SCOPE could have undefined
3070 * our precious cv. See bug #99850. */
3071 if (!CvROOT(cv) && !CvXSUB(cv)) {
3072 const GV * const gv = CvGV(cv);
3074 SV * const tmpstr = sv_newmortal();
3075 gv_efullname3(tmpstr, gv, NULL);
3076 DIE(aTHX_ "Goto undefined subroutine &%" SVf,
3079 DIE(aTHX_ "Goto undefined subroutine");
3082 if (CxTYPE(cx) == CXt_SUB) {
3083 CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth;
3084 /*on XS calls defer freeing the old CV as it could
3085 * prematurely set PL_op to NULL, which could cause
3086 * e..g XS subs using GIMME_V to SEGV */
3088 old_cv = cx->blk_sub.cv;
3090 SvREFCNT_dec_NN(cx->blk_sub.cv);
3093 /* Now do some callish stuff. */
3095 const SSize_t items = arg ? AvFILL(arg) + 1 : 0;
3096 const bool m = arg ? cBOOL(SvRMAGICAL(arg)) : 0;
3102 SAVEFREESV(cv); /* later, undo the 'avoid premature free' hack */
3104 SAVEFREESV(old_cv); /* ditto, deferred freeing of old CV */
3106 /* put GvAV(defgv) back onto stack */
3108 EXTEND(SP, items+1); /* @_ could have been extended. */
3113 bool r = cBOOL(AvREAL(arg));
3114 for (index=0; index<items; index++)
3118 SV ** const svp = av_fetch(arg, index, 0);
3119 sv = svp ? *svp : NULL;
3121 else sv = AvARRAY(arg)[index];
3123 ? r ? SvREFCNT_inc_NN(sv_2mortal(sv)) : sv
3124 : sv_2mortal(newSVavdefelem(arg, index, 1));
3128 if (CxTYPE(cx) == CXt_SUB && CxHASARGS(cx)) {
3129 /* Restore old @_ */
3130 CX_POP_SAVEARRAY(cx);
3133 retop = cx->blk_sub.retop;
3134 PL_comppad = cx->blk_sub.prevcomppad;
3135 PL_curpad = LIKELY(PL_comppad) ? AvARRAY(PL_comppad) : NULL;
3137 /* Make a temporary a copy of the current GOTO op on the C
3138 * stack, but with a modified gimme (we can't modify the
3139 * real GOTO op as that's not thread-safe). This allows XS
3140 * users of GIMME_V to get the correct calling context,
3141 * even though there is no longer a CXt_SUB frame to
3142 * provide that information.
3144 Copy(PL_op, &fake_goto_op, 1, UNOP);
3145 fake_goto_op.op_flags =
3146 (fake_goto_op.op_flags & ~OPf_WANT)
3147 | (cx->blk_gimme & G_WANT);
3148 PL_op = (OP*)&fake_goto_op;
3150 /* XS subs don't have a CXt_SUB, so pop it;
3151 * this is a cx_popblock(), less all the stuff we already did
3152 * for cx_topblock() earlier */
3153 PL_curcop = cx->blk_oldcop;
3154 /* this is cx_popsub, less all the stuff we already did */
3155 PL_curstackinfo->si_cxsubix = cx->blk_sub.old_cxsubix;
3159 /* Push a mark for the start of arglist */
3162 (void)(*CvXSUB(cv))(aTHX_ cv);
3167 PADLIST * const padlist = CvPADLIST(cv);
3169 SAVEFREESV(cv); /* later, undo the 'avoid premature free' hack */
3171 /* partial unrolled cx_pushsub(): */
3173 cx->blk_sub.cv = cv;
3174 cx->blk_sub.olddepth = CvDEPTH(cv);
3177 SvREFCNT_inc_simple_void_NN(cv);
3178 if (CvDEPTH(cv) > 1) {
3179 if (CvDEPTH(cv) == PERL_SUB_DEPTH_WARN && ckWARN(WARN_RECURSION))
3180 sub_crush_depth(cv);
3181 pad_push(padlist, CvDEPTH(cv));
3183 PL_curcop = cx->blk_oldcop;
3184 PAD_SET_CUR_NOSAVE(padlist, CvDEPTH(cv));
3187 /* second half of donating @_ from the old sub to the
3188 * new sub: abandon the original pad[0] AV in the
3189 * new sub, and replace it with the donated @_.
3190 * pad[0] takes ownership of the extra refcount
3191 * we gave arg earlier */
3193 SvREFCNT_dec(PAD_SVl(0));
3194 PAD_SVl(0) = (SV *)arg;
3195 SvREFCNT_inc_simple_void_NN(arg);
3198 /* GvAV(PL_defgv) might have been modified on scope
3199 exit, so point it at arg again. */
3200 if (arg != GvAV(PL_defgv)) {
3201 AV * const av = GvAV(PL_defgv);
3202 GvAV(PL_defgv) = (AV *)SvREFCNT_inc_simple(arg);
3207 if (PERLDB_SUB) { /* Checking curstash breaks DProf. */
3208 Perl_get_db_sub(aTHX_ NULL, cv);
3210 CV * const gotocv = get_cvs("DB::goto", 0);
3212 PUSHMARK( PL_stack_sp );
3213 call_sv(MUTABLE_SV(gotocv), G_SCALAR | G_NODEBUG);
3218 retop = CvSTART(cv);
3219 goto putback_return;
3224 label = SvPV_nomg_const(sv, label_len);
3225 label_flags = SvUTF8(sv);
3228 else if (!(PL_op->op_flags & OPf_SPECIAL)) {
3229 /* goto LABEL or dump LABEL */
3230 label = cPVOP->op_pv;
3231 label_flags = (cPVOP->op_private & OPpPV_IS_UTF8) ? SVf_UTF8 : 0;
3232 label_len = strlen(label);
3234 if (!(do_dump || label_len)) DIE(aTHX_ "%s", must_have_label);
3239 OP *gotoprobe = NULL;
3240 bool leaving_eval = FALSE;
3241 bool in_block = FALSE;
3242 bool pseudo_block = FALSE;
3243 PERL_CONTEXT *last_eval_cx = NULL;
3247 PL_lastgotoprobe = NULL;
3249 for (ix = cxstack_ix; ix >= 0; ix--) {
3251 switch (CxTYPE(cx)) {
3253 leaving_eval = TRUE;
3254 if (!CxEVALBLOCK(cx)) {
3255 gotoprobe = (last_eval_cx ?
3256 last_eval_cx->blk_eval.old_eval_root :
3261 /* else fall through */
3262 case CXt_LOOP_PLAIN:
3263 case CXt_LOOP_LAZYIV:
3264 case CXt_LOOP_LAZYSV:
3269 gotoprobe = OpSIBLING(cx->blk_oldcop);
3275 gotoprobe = OpSIBLING(cx->blk_oldcop);
3278 gotoprobe = PL_main_root;
3281 gotoprobe = CvROOT(cx->blk_sub.cv);
3282 pseudo_block = cBOOL(CxMULTICALL(cx));
3286 DIE(aTHX_ "Can't \"goto\" out of a pseudo block");
3288 /* diag_listed_as: Can't "%s" out of a "defer" block */
3289 DIE(aTHX_ "Can't \"%s\" out of a \"%s\" block", "goto", S_defer_blockname(cx));
3292 DIE(aTHX_ "panic: goto, type=%u, ix=%ld",
3293 CxTYPE(cx), (long) ix);
3294 gotoprobe = PL_main_root;
3300 retop = dofindlabel(gotoprobe, label, label_len, label_flags,
3301 enterops, enterops + GOTO_DEPTH);
3304 if ( (sibl1 = OpSIBLING(gotoprobe)) &&
3305 sibl1->op_type == OP_UNSTACK &&
3306 (sibl2 = OpSIBLING(sibl1)))
3308 retop = dofindlabel(sibl2,
3309 label, label_len, label_flags, enterops,
3310 enterops + GOTO_DEPTH);
3316 DIE(aTHX_ "Can't \"goto\" out of a pseudo block");
3317 PL_lastgotoprobe = gotoprobe;
3320 DIE(aTHX_ "Can't find label %" UTF8f,
3321 UTF8fARG(label_flags, label_len, label));
3323 /* if we're leaving an eval, check before we pop any frames
3324 that we're not going to punt, otherwise the error
3327 if (leaving_eval && *enterops && enterops[1]) {
3329 for (i = 1; enterops[i]; i++)
3330 S_check_op_type(aTHX_ enterops[i]);
3333 if (*enterops && enterops[1]) {
3334 I32 i = enterops[1] != UNENTERABLE
3335 && enterops[1]->op_type == OP_ENTER && in_block
3339 deprecate(WARN_DEPRECATED__GOTO_CONSTRUCT, "Use of \"goto\" to jump into a construct");
3342 /* pop unwanted frames */
3344 if (ix < cxstack_ix) {
3346 DIE(aTHX_ "panic: docatch: illegal ix=%ld", (long)ix);
3352 /* push wanted frames */
3354 if (*enterops && enterops[1]) {
3355 OP * const oldop = PL_op;
3356 ix = enterops[1] != UNENTERABLE
3357 && enterops[1]->op_type == OP_ENTER && in_block
3360 for (; enterops[ix]; ix++) {
3361 PL_op = enterops[ix];
3362 S_check_op_type(aTHX_ PL_op);
3363 DEBUG_l( Perl_deb(aTHX_ "pp_goto: Entering %s\n",
3365 PL_op->op_ppaddr(aTHX);
3373 if (!retop) retop = PL_main_start;
3375 PL_restartop = retop;
3376 PL_do_undump = TRUE;
3380 PL_restartop = 0; /* hmm, must be GNU unexec().. */
3381 PL_do_undump = FALSE;
3399 anum = 0; (void)POPs;
3405 && SvTRUE(cop_hints_fetch_pvs(PL_curcop, "vmsish_exit", 0)))
3408 VMSISH_HUSHED || (PL_curcop->op_private & OPpHUSH_VMSISH);
3411 PL_exit_flags |= PERL_EXIT_EXPECTED;
3413 PUSHs(&PL_sv_undef);
3420 S_save_lines(pTHX_ AV *array, SV *sv)
3422 const char *s = SvPVX_const(sv);
3423 const char * const send = SvPVX_const(sv) + SvCUR(sv);
3426 PERL_ARGS_ASSERT_SAVE_LINES;
3428 while (s && s < send) {
3430 SV * const tmpstr = newSV_type(SVt_PVMG);
3432 t = (const char *)memchr(s, '\n', send - s);
3438 sv_setpvn_fresh(tmpstr, s, t - s);
3439 av_store(array, line++, tmpstr);
3447 Interpose, for the current op and RUNOPS loop,
3449 - a new JMPENV stack catch frame, and
3450 - an inner RUNOPS loop to run all the remaining ops following the
3453 Then handle any exceptions raised while in that loop.
3454 For a caught eval at this level, re-enter the loop with the specified
3455 restart op (i.e. the op following the OP_LEAVETRY etc); otherwise re-throw
3458 docatch() is intended to be used like this:
3463 return docatch(Perl_pp_entertry);
3465 ... rest of function ...
3466 return PL_op->op_next;
3469 If a new catch frame isn't needed, the op behaves normally. Otherwise it
3470 calls docatch(), which recursively calls pp_entertry(), this time with
3471 CATCH_GET() false, so the rest of the body of the entertry is run. Then
3472 docatch() calls CALLRUNOPS() which executes all the ops following the
3473 entertry. When the loop finally finishes, control returns to docatch(),
3474 which pops the JMPENV and returns to the parent pp_entertry(), which
3475 itself immediately returns. Note that *all* subsequent ops are run within
3476 the inner RUNOPS loop, not just the body of the eval. For example, in
3478 sub TIEARRAY { eval {1}; my $x }
3481 at the point the 'my' is executed, the C stack will look something like:
3484 #9 perl_run() # JMPENV_PUSH level 1 here
3486 #7 Perl_runops_standard() # main RUNOPS loop
3489 #4 Perl_runops_standard() # unguarded RUNOPS loop: no new JMPENV
3490 #3 Perl_pp_entertry()
3491 #2 S_docatch() # JMPENV_PUSH level 2 here
3492 #1 Perl_runops_standard() # docatch()'s RUNOPs loop
3495 Basically, any section of the perl core which starts a RUNOPS loop may
3496 make a promise that it will catch any exceptions and restart the loop if
3497 necessary. If it's not prepared to do that (like call_sv() isn't), then
3498 it sets CATCH_GET() to true, so that any later eval-like code knows to
3499 set up a new handler and loop (via docatch()).
3501 See L<perlinterp/"Exception handing"> for further details.
3507 S_docatch(pTHX_ Perl_ppaddr_t firstpp)
3510 OP * const oldop = PL_op;
3518 case 0: /* normal flow-of-control return from JMPENV_PUSH */
3520 /* re-run the current op, this time executing the full body of the
3522 PL_op = firstpp(aTHX);
3529 case 3: /* an exception raised within an eval */
3530 if (PL_restartjmpenv == PL_top_env) {
3531 /* die caught by an inner eval - continue inner loop */
3535 PL_restartjmpenv = NULL;
3536 PL_op = PL_restartop;
3545 JMPENV_JUMP(ret); /* re-throw the exception */
3546 NOT_REACHED; /* NOTREACHED */
3555 =for apidoc find_runcv
3557 Locate the CV corresponding to the currently executing sub or eval.
3558 If C<db_seqp> is non_null, skip CVs that are in the DB package and populate
3559 C<*db_seqp> with the cop sequence number at the point that the DB:: code was
3560 entered. (This allows debuggers to eval in the scope of the breakpoint
3561 rather than in the scope of the debugger itself.)
3567 Perl_find_runcv(pTHX_ U32 *db_seqp)
3569 return Perl_find_runcv_where(aTHX_ 0, 0, db_seqp);
3572 /* If this becomes part of the API, it might need a better name. */
3574 Perl_find_runcv_where(pTHX_ U8 cond, IV arg, U32 *db_seqp)
3581 PL_curcop == &PL_compiling
3583 : PL_curcop->cop_seq;
3585 for (si = PL_curstackinfo; si; si = si->si_prev) {
3587 for (ix = si->si_cxix; ix >= 0; ix--) {
3588 const PERL_CONTEXT *cx = &(si->si_cxstack[ix]);
3590 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
3591 cv = cx->blk_sub.cv;
3592 /* skip DB:: code */
3593 if (db_seqp && PL_debstash && CvSTASH(cv) == PL_debstash) {
3594 *db_seqp = cx->blk_oldcop->cop_seq;
3597 if (cx->cx_type & CXp_SUB_RE)
3600 else if (CxTYPE(cx) == CXt_EVAL && !CxEVALBLOCK(cx))
3601 cv = cx->blk_eval.cv;
3604 case FIND_RUNCV_padid_eq:
3606 || CvPADLIST(cv)->xpadl_id != (U32)arg)
3609 case FIND_RUNCV_level_eq:
3610 if (level++ != arg) continue;
3618 return cond == FIND_RUNCV_padid_eq ? NULL : PL_main_cv;
3624 * Run yyparse() in a setjmp wrapper. Returns:
3625 * 0: yyparse() successful
3626 * 1: yyparse() failed
3629 * This is used to trap Perl_croak() calls that are executed
3630 * during the compilation process and before the code has been
3631 * completely compiled. It is expected to be called from
3632 * doeval_compile() only. The parameter 'caller_op' is
3633 * only used in DEBUGGING to validate the logic is working
3636 * See also try_run_unitcheck().
3640 S_try_yyparse(pTHX_ int gramtype, OP *caller_op)
3642 /* if we die during compilation PL_restartop and PL_restartjmpenv
3643 * will be set by Perl_die_unwind(). We need to restore their values
3644 * if that happens as they are intended for the case where the code
3645 * compiles and dies during execution, not where it dies during
3646 * compilation. PL_restartop and caller_op->op_next should be the
3647 * same anyway, and when compilation fails then caller_op->op_next is
3648 * used as the next op after the compile.
3650 JMPENV *restartjmpenv = PL_restartjmpenv;
3651 OP *restartop = PL_restartop;
3654 PERL_UNUSED_ARG(caller_op); /* only used in debugging builds */
3656 assert(CxTYPE(CX_CUR()) == CXt_EVAL);
3660 ret = yyparse(gramtype) ? 1 : 0;
3663 /* yyparse() died and we trapped the error. We need to restore
3664 * the old PL_restartjmpenv and PL_restartop values. */
3665 assert(PL_restartop == caller_op->op_next); /* we expect these to match */
3666 PL_restartjmpenv = restartjmpenv;
3667 PL_restartop = restartop;
3672 NOT_REACHED; /* NOTREACHED */
3678 /* S_try_run_unitcheck()
3680 * Run PL_unitcheckav in a setjmp wrapper via call_list.
3682 * 0: unitcheck blocks ran without error
3683 * 3: a unitcheck block died
3685 * This is used to trap Perl_croak() calls that are executed
3686 * during UNITCHECK blocks executed after the compilation
3687 * process has completed but before the code itself has been
3688 * executed via the normal run loops. It is expected to be called
3689 * from doeval_compile() only. The parameter 'caller_op' is
3690 * only used in DEBUGGING to validate the logic is working
3693 * See also try_yyparse().
3696 S_try_run_unitcheck(pTHX_ OP* caller_op)
3698 /* if we die during compilation PL_restartop and PL_restartjmpenv
3699 * will be set by Perl_die_unwind(). We need to restore their values
3700 * if that happens as they are intended for the case where the code
3701 * compiles and dies during execution, not where it dies during
3702 * compilation. UNITCHECK runs after compilation completes, and
3703 * if it dies we will execute the PL_restartop anyway via the
3704 * failed compilation code path. PL_restartop and caller_op->op_next
3705 * should be the same anyway, and when compilation fails then
3706 * caller_op->op_next is used as the next op after the compile.
3708 JMPENV *restartjmpenv = PL_restartjmpenv;
3709 OP *restartop = PL_restartop;
3712 PERL_UNUSED_ARG(caller_op); /* only used in debugging builds */
3714 assert(CxTYPE(CX_CUR()) == CXt_EVAL);
3718 call_list(PL_scopestack_ix, PL_unitcheckav);
3721 /* call_list died */
3722 /* call_list() died and we trapped the error. We should restore
3723 * the old PL_restartjmpenv and PL_restartop values, as they are
3724 * used only in the case where the code was actually run.
3725 * The assert validates that we will still execute the PL_restartop.
3727 assert(PL_restartop == caller_op->op_next); /* we expect these to match */
3728 PL_restartjmpenv = restartjmpenv;
3729 PL_restartop = restartop;
3734 NOT_REACHED; /* NOTREACHED */
3740 /* Compile a require/do or an eval ''.
3742 * outside is the lexically enclosing CV (if any) that invoked us.
3743 * seq is the current COP scope value.
3744 * hh is the saved hints hash, if any.
3746 * Returns a bool indicating whether the compile was successful; if so,
3747 * PL_eval_start contains the first op of the compiled code; otherwise,
3750 * This function is called from two places: pp_require and pp_entereval.
3751 * These can be distinguished by whether PL_op is entereval.
3755 S_doeval_compile(pTHX_ U8 gimme, CV* outside, U32 seq, HV *hh)
3758 OP * const saveop = PL_op;
3759 bool clear_hints = saveop->op_type != OP_ENTEREVAL;
3760 COP * const oldcurcop = PL_curcop;
3761 bool in_require = (saveop->op_type == OP_REQUIRE);
3765 PL_in_eval = (in_require
3766 ? (EVAL_INREQUIRE | (PL_in_eval & EVAL_INEVAL))
3768 ((PL_op->op_private & OPpEVAL_RE_REPARSING)
3769 ? EVAL_RE_REPARSING : 0)));
3773 evalcv = MUTABLE_CV(newSV_type(SVt_PVCV));
3775 assert(CxTYPE(CX_CUR()) == CXt_EVAL);
3776 CX_CUR()->blk_eval.cv = evalcv;
3777 CX_CUR()->blk_gimme = gimme;
3779 CvOUTSIDE_SEQ(evalcv) = seq;
3780 CvOUTSIDE(evalcv) = MUTABLE_CV(SvREFCNT_inc_simple(outside));
3782 /* set up a scratch pad */
3784 CvPADLIST_set(evalcv, pad_new(padnew_SAVE));
3785 PL_op = NULL; /* avoid PL_op and PL_curpad referring to different CVs */
3788 SAVEMORTALIZESV(evalcv); /* must remain until end of current statement */
3790 /* make sure we compile in the right package */
3792 if (CopSTASH_ne(PL_curcop, PL_curstash)) {
3793 SAVEGENERICSV(PL_curstash);
3794 PL_curstash = (HV *)CopSTASH(PL_curcop);
3795 if (SvTYPE(PL_curstash) != SVt_PVHV) PL_curstash = NULL;
3797 SvREFCNT_inc_simple_void(PL_curstash);
3798 save_item(PL_curstname);
3799 sv_sethek(PL_curstname, HvNAME_HEK(PL_curstash));
3802 /* XXX:ajgo do we really need to alloc an AV for begin/checkunit */
3803 SAVESPTR(PL_beginav);
3804 PL_beginav = newAV();
3805 SAVEFREESV(PL_beginav);
3806 SAVESPTR(PL_unitcheckav);
3807 PL_unitcheckav = newAV();
3808 SAVEFREESV(PL_unitcheckav);
3811 ENTER_with_name("evalcomp");
3812 SAVESPTR(PL_compcv);
3815 /* try to compile it */
3817 PL_eval_root = NULL;
3818 PL_curcop = &PL_compiling;
3819 if ((saveop->op_type != OP_REQUIRE) && (saveop->op_flags & OPf_SPECIAL))
3820 PL_in_eval |= EVAL_KEEPERR;
3826 PL_hints = HINTS_DEFAULT;
3827 PL_prevailing_version = 0;
3828 hv_clear(GvHV(PL_hintgv));
3832 PL_hints = saveop->op_private & OPpEVAL_COPHH
3833 ? oldcurcop->cop_hints : (U32)saveop->op_targ;
3835 /* making 'use re eval' not be in scope when compiling the
3836 * qr/mabye_has_runtime_code_block/ ensures that we don't get
3837 * infinite recursion when S_has_runtime_code() gives a false
3838 * positive: the second time round, HINT_RE_EVAL isn't set so we
3839 * don't bother calling S_has_runtime_code() */
3840 if (PL_in_eval & EVAL_RE_REPARSING)
3841 PL_hints &= ~HINT_RE_EVAL;
3844 /* SAVEHINTS created a new HV in PL_hintgv, which we need to GC */
3845 SvREFCNT_dec(GvHV(PL_hintgv));
3846 GvHV(PL_hintgv) = hh;
3847 FETCHFEATUREBITSHH(hh);
3850 SAVECOMPILEWARNINGS();
3852 if (PL_dowarn & G_WARN_ALL_ON)
3853 PL_compiling.cop_warnings = pWARN_ALL ;
3854 else if (PL_dowarn & G_WARN_ALL_OFF)
3855 PL_compiling.cop_warnings = pWARN_NONE ;
3857 PL_compiling.cop_warnings = pWARN_STD ;
3860 PL_compiling.cop_warnings =
3861 DUP_WARNINGS(oldcurcop->cop_warnings);
3862 cophh_free(CopHINTHASH_get(&PL_compiling));
3863 if (Perl_cop_fetch_label(aTHX_ oldcurcop, NULL, NULL)) {
3864 /* The label, if present, is the first entry on the chain. So rather
3865 than writing a blank label in front of it (which involves an
3866 allocation), just use the next entry in the chain. */
3867 PL_compiling.cop_hints_hash
3868 = cophh_copy(oldcurcop->cop_hints_hash->refcounted_he_next);
3869 /* Check the assumption that this removed the label. */
3870 assert(Perl_cop_fetch_label(aTHX_ &PL_compiling, NULL, NULL) == NULL);
3873 PL_compiling.cop_hints_hash = cophh_copy(oldcurcop->cop_hints_hash);
3876 CALL_BLOCK_HOOKS(bhk_eval, saveop);
3878 /* we should never be CATCH_GET true here, as our immediate callers should
3879 * always handle that case. */
3881 /* compile the code */
3884 yystatus = (!in_require)
3885 ? S_try_yyparse(aTHX_ GRAMPROG, saveop)
3886 : yyparse(GRAMPROG);
3888 if (yystatus || PL_parser->error_count || !PL_eval_root) {
3893 if (yystatus != 3) {
3894 /* note that if yystatus == 3, then the require/eval died during
3895 * compilation, so the EVAL CX block has already been popped, and
3896 * various vars restored. This block applies similar steps after
3897 * the other "failed to compile" cases in yyparse, eg, where
3898 * yystatus=1, "failed, but did not die". */
3901 invoke_exception_hook(ERRSV,FALSE);
3903 op_free(PL_eval_root);
3904 PL_eval_root = NULL;
3906 SP = PL_stack_base + POPMARK; /* pop original mark */
3908 assert(CxTYPE(cx) == CXt_EVAL);
3909 /* If we are in an eval we need to make sure that $SIG{__DIE__}
3910 * handler is invoked so we simulate that part of the
3911 * Perl_die_unwind() process. In a require we will croak
3912 * so it will happen there. */
3913 /* pop the CXt_EVAL, and if was a require, croak */
3914 S_pop_eval_context_maybe_croak(aTHX_ cx, ERRSV, 2);
3917 /* die_unwind() re-croaks when in require, having popped the
3918 * require EVAL context. So we should never catch a require
3920 assert(!in_require);
3923 if (!*(SvPV_nolen_const(errsv)))
3924 sv_setpvs(errsv, "Compilation error");
3927 if (gimme != G_LIST) PUSHs(&PL_sv_undef);
3932 /* Compilation successful. Now clean up */
3934 LEAVE_with_name("evalcomp");
3936 CopLINE_set(&PL_compiling, 0);
3937 SAVEFREEOP(PL_eval_root);
3938 cv_forget_slab(evalcv);
3940 DEBUG_x(dump_eval());
3942 /* Register with debugger: */
3943 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
3944 CV * const cv = get_cvs("DB::postponed", 0);
3948 XPUSHs(MUTABLE_SV(CopFILEGV(&PL_compiling)));
3950 call_sv(MUTABLE_SV(cv), G_DISCARD);
3954 if (PL_unitcheckav && av_count(PL_unitcheckav)>0) {
3955 OP *es = PL_eval_start;
3956 /* TODO: are we sure we shouldn't do S_try_run_unitcheck()
3957 * when `in_require` is true? */
3959 call_list(PL_scopestack_ix, PL_unitcheckav);
3961 else if (S_try_run_unitcheck(aTHX_ saveop)) {
3962 /* there was an error! */
3968 if (!*(SvPV_nolen_const(errsv))) {
3969 /* This happens when using:
3970 * eval qq# UNITCHECK { die "\x00"; } #;
3972 sv_setpvs(errsv, "Unit check error");
3975 if (gimme != G_LIST) PUSHs(&PL_sv_undef);
3982 CvDEPTH(evalcv) = 1;
3983 SP = PL_stack_base + POPMARK; /* pop original mark */
3984 PL_op = saveop; /* The caller may need it. */
3985 PL_parser->lex_state = LEX_NOTPARSING; /* $^S needs this. */
3991 /* Return NULL if the file doesn't exist or isn't a file;
3992 * else return PerlIO_openn().
3996 S_check_type_and_open(pTHX_ SV *name)
4001 const char *p = SvPV_const(name, len);
4004 PERL_ARGS_ASSERT_CHECK_TYPE_AND_OPEN;
4006 /* checking here captures a reasonable error message when
4007 * PERL_DISABLE_PMC is true, but when PMC checks are enabled, the
4008 * user gets a confusing message about looking for the .pmc file
4009 * rather than for the .pm file so do the check in S_doopen_pm when
4010 * PMC is on instead of here. S_doopen_pm calls this func.
4011 * This check prevents a \0 in @INC causing problems.
4013 #ifdef PERL_DISABLE_PMC
4014 if (!IS_SAFE_PATHNAME(p, len, "require"))
4018 /* on Win32 stat is expensive (it does an open() and close() twice and
4019 a couple other IO calls), the open will fail with a dir on its own with
4020 errno EACCES, so only do a stat to separate a dir from a real EACCES
4021 caused by user perms */
4023 st_rc = PerlLIO_stat(p, &st);
4029 if(S_ISBLK(st.st_mode)) {
4033 else if(S_ISDIR(st.st_mode)) {
4042 retio = PerlIO_openn(aTHX_ ":", PERL_SCRIPT_MODE, -1, 0, 0, NULL, 1, &name);
4044 /* EACCES stops the INC search early in pp_require to implement
4045 feature RT #113422 */
4046 if(!retio && errno == EACCES) { /* exists but probably a directory */
4048 st_rc = PerlLIO_stat(p, &st);
4050 if(S_ISDIR(st.st_mode))
4052 else if(S_ISBLK(st.st_mode))
4063 /* doopen_pm(): return the equivalent of PerlIO_openn() on the given name,
4064 * but first check for bad names (\0) and non-files.
4065 * Also if the filename ends in .pm and unless PERL_DISABLE_PMC,
4066 * try loading Foo.pmc first.
4068 #ifndef PERL_DISABLE_PMC
4070 S_doopen_pm(pTHX_ SV *name)
4073 const char *p = SvPV_const(name, namelen);
4075 PERL_ARGS_ASSERT_DOOPEN_PM;
4077 /* check the name before trying for the .pmc name to avoid the
4078 * warning referring to the .pmc which the user probably doesn't
4079 * know or care about
4081 if (!IS_SAFE_PATHNAME(p, namelen, "require"))
4084 if (memENDPs(p, namelen, ".pm")) {
4085 SV *const pmcsv = sv_newmortal();
4088 SvSetSV_nosteal(pmcsv,name);
4089 sv_catpvs(pmcsv, "c");
4091 pmcio = check_type_and_open(pmcsv);
4095 return check_type_and_open(name);
4098 # define doopen_pm(name) check_type_and_open(name)
4099 #endif /* !PERL_DISABLE_PMC */
4101 /* require doesn't search in @INC for absolute names, or when the name is
4102 explicitly relative the current directory: i.e. ./, ../ */
4103 PERL_STATIC_INLINE bool
4104 S_path_is_searchable(const char *name)
4106 PERL_ARGS_ASSERT_PATH_IS_SEARCHABLE;
4108 if (PERL_FILE_IS_ABSOLUTE(name)
4110 || (*name == '.' && ((name[1] == '/' ||
4111 (name[1] == '.' && name[2] == '/'))
4112 || (name[1] == '\\' ||
4113 ( name[1] == '.' && name[2] == '\\')))
4116 || (*name == '.' && (name[1] == '/' ||
4117 (name[1] == '.' && name[2] == '/')))
4128 /* implement 'require 5.010001' */
4131 S_require_version(pTHX_ SV *sv)
4135 sv = sv_2mortal(new_version(sv));
4136 if (!Perl_sv_derived_from_pvn(aTHX_ PL_patchlevel, STR_WITH_LEN("version"), 0))
4137 upg_version(PL_patchlevel, TRUE);
4138 if (cUNOP->op_first->op_type == OP_CONST && cUNOP->op_first->op_private & OPpCONST_NOVER) {
4139 if ( vcmp(sv,PL_patchlevel) <= 0 )
4140 DIE(aTHX_ "Perls since %" SVf " too modern--this is %" SVf ", stopped",
4141 SVfARG(sv_2mortal(vnormal(sv))),
4142 SVfARG(sv_2mortal(vnormal(PL_patchlevel)))
4146 if ( vcmp(sv,PL_patchlevel) > 0 ) {
4149 SV * const req = SvRV(sv);
4150 SV * const pv = *hv_fetchs(MUTABLE_HV(req), "original", FALSE);
4152 /* get the left hand term */
4153 lav = MUTABLE_AV(SvRV(*hv_fetchs(MUTABLE_HV(req), "version", FALSE)));
4155 first = SvIV(*av_fetch(lav,0,0));
4156 if ( first > (int)PERL_REVISION /* probably 'use 6.0' */
4157 || hv_exists(MUTABLE_HV(req), "qv", 2 ) /* qv style */
4158 || av_count(lav) > 2 /* FP with > 3 digits */
4159 || strstr(SvPVX(pv),".0") /* FP with leading 0 */
4161 DIE(aTHX_ "Perl %" SVf " required--this is only "
4162 "%" SVf ", stopped",
4163 SVfARG(sv_2mortal(vnormal(req))),
4164 SVfARG(sv_2mortal(vnormal(PL_patchlevel)))
4167 else { /* probably 'use 5.10' or 'use 5.8' */
4171 if (av_count(lav) > 1)
4172 second = SvIV(*av_fetch(lav,1,0));
4174 second /= second >= 600 ? 100 : 10;
4175 hintsv = Perl_newSVpvf(aTHX_ "v%d.%d.0",
4176 (int)first, (int)second);
4177 upg_version(hintsv, TRUE);
4179 DIE(aTHX_ "Perl %" SVf " required (did you mean %" SVf "?)"
4180 "--this is only %" SVf ", stopped",
4181 SVfARG(sv_2mortal(vnormal(req))),
4182 SVfARG(sv_2mortal(vnormal(sv_2mortal(hintsv)))),
4183 SVfARG(sv_2mortal(vnormal(PL_patchlevel)))
4192 /* Handle C<require Foo::Bar>, C<require "Foo/Bar.pm"> and C<do "Foo.pm">.
4193 * The first form will have already been converted at compile time to
4194 * the second form */
4197 S_require_file(pTHX_ SV *sv)
4207 int vms_unixname = 0;
4210 /* tryname is the actual pathname (with @INC prefix) which was loaded.
4211 * It's stored as a value in %INC, and used for error messages */
4212 const char *tryname = NULL;
4213 SV *namesv = NULL; /* SV equivalent of tryname */
4214 const U8 gimme = GIMME_V;
4215 int filter_has_file = 0;
4216 PerlIO *tryrsfp = NULL;
4217 SV *filter_cache = NULL;
4218 SV *filter_state = NULL;
4219 SV *filter_sub = NULL;
4223 bool path_searchable;
4224 I32 old_savestack_ix;
4225 const bool op_is_require = PL_op->op_type == OP_REQUIRE;
4226 const char *const op_name = op_is_require ? "require" : "do";
4227 SV ** svp_cached = NULL;
4229 assert(op_is_require || PL_op->op_type == OP_DOFILE);
4232 DIE(aTHX_ "Missing or undefined argument to %s", op_name);
4233 name = SvPV_nomg_const(sv, len);
4234 if (!(name && len > 0 && *name))
4235 DIE(aTHX_ "Missing or undefined argument to %s", op_name);
4238 PL_hook__require__before
4239 && SvROK(PL_hook__require__before)
4240 && SvTYPE(SvRV(PL_hook__require__before)) == SVt_PVCV
4242 SV* name_sv = sv_mortalcopy(sv);
4243 SV *post_hook__require__before_sv = NULL;
4245 ENTER_with_name("call_PRE_REQUIRE");
4249 PUSHs(name_sv); /* always use the object for method calls */
4251 int count = call_sv(PL_hook__require__before, G_SCALAR);
4253 if (count && SvOK(*SP) && SvROK(*SP) && SvTYPE(SvRV(*SP)) == SVt_PVCV)
4254 post_hook__require__before_sv = SvREFCNT_inc_simple_NN(*SP);
4255 if (!sv_streq(name_sv,sv)) {
4256 /* they modified the name argument, so do some sleight of hand */
4257 name = SvPV_nomg_const(name_sv, len);
4258 if (!(name && len > 0 && *name))
4259 DIE(aTHX_ "Missing or undefined argument to %s via %%{^HOOK}{require__before}",
4261 sv = SvREFCNT_inc_simple_NN(name_sv);
4264 LEAVE_with_name("call_PRE_REQUIRE");
4265 if (post_hook__require__before_sv) {
4266 MORTALDESTRUCTOR_SV(post_hook__require__before_sv, newSVsv(sv));
4270 PL_hook__require__after
4271 && SvROK(PL_hook__require__after)
4272 && SvTYPE(SvRV(PL_hook__require__after)) == SVt_PVCV
4274 MORTALDESTRUCTOR_SV(PL_hook__require__after, newSVsv(sv));
4278 /* try to return earlier (save the SAFE_PATHNAME check) if INC already got the name */
4279 if (op_is_require) {
4280 /* can optimize to only perform one single lookup */
4281 svp_cached = hv_fetch(GvHVn(PL_incgv), (char*) name, len, 0);
4282 if ( svp_cached && (SvGETMAGIC(*svp_cached), SvOK(*svp_cached)) ) RETPUSHYES;
4286 if (!IS_SAFE_PATHNAME(name, len, op_name)) {
4287 if (!op_is_require) {
4291 DIE(aTHX_ "Can't locate %s: %s",
4292 pv_escape(newSVpvs_flags("",SVs_TEMP),name,len,len*2,
4293 NULL, SvUTF8(sv)?PERL_PV_ESCAPE_UNI:0),
4296 TAINT_PROPER(op_name);
4298 path_searchable = path_is_searchable(name);
4301 /* The key in the %ENV hash is in the syntax of file passed as the argument
4302 * usually this is in UNIX format, but sometimes in VMS format, which
4303 * can result in a module being pulled in more than once.
4304 * To prevent this, the key must be stored in UNIX format if the VMS
4305 * name can be translated to UNIX.
4309 tounixspec(name, SvPVX(sv_2mortal(newSVpv("", VMS_MAXRSS-1)))))
4311 unixlen = strlen(unixname);
4317 /* if not VMS or VMS name can not be translated to UNIX, pass it
4320 unixname = (char *) name;
4323 if (op_is_require) {
4324 /* reuse the previous hv_fetch result if possible */
4325 SV * const * const svp = svp_cached ? svp_cached : hv_fetch(GvHVn(PL_incgv), unixname, unixlen, 0);
4327 /* we already did a get magic if this was cached */
4333 DIE(aTHX_ "Attempt to reload %s aborted.\n"
4334 "Compilation failed in require", unixname);
4337 /*XXX OPf_KIDS should always be true? -dapm 4/2017 */
4338 if (PL_op->op_flags & OPf_KIDS) {
4339 SVOP * const kid = cSVOPx(cUNOP->op_first);
4341 if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
4342 /* Make sure that a bareword module name (e.g. ::Foo::Bar)
4343 * doesn't map to a naughty pathname like /Foo/Bar.pm.
4344 * Note that the parser will normally detect such errors
4345 * at compile time before we reach here, but
4346 * Perl_load_module() can fake up an identical optree
4347 * without going near the parser, and being able to put
4348 * anything as the bareword. So we include a duplicate set
4349 * of checks here at runtime.
4351 const STRLEN package_len = len - 3;
4352 const char slashdot[2] = {'/', '.'};
4354 const char backslashdot[2] = {'\\', '.'};
4357 /* Disallow *purported* barewords that map to absolute
4358 filenames, filenames relative to the current or parent
4359 directory, or (*nix) hidden filenames. Also sanity check
4360 that the generated filename ends .pm */
4361 if (!path_searchable || len < 3 || name[0] == '.'
4362 || !memEQs(name + package_len, len - package_len, ".pm"))
4363 DIE(aTHX_ "Bareword in require maps to disallowed filename \"%" SVf "\"", sv);
4364 if (memchr(name, 0, package_len)) {
4365 /* diag_listed_as: Bareword in require contains "%s" */
4366 DIE(aTHX_ "Bareword in require contains \"\\0\"");
4368 if (ninstr(name, name + package_len, slashdot,
4369 slashdot + sizeof(slashdot))) {
4370 /* diag_listed_as: Bareword in require contains "%s" */
4371 DIE(aTHX_ "Bareword in require contains \"/.\"");
4374 if (ninstr(name, name + package_len, backslashdot,
4375 backslashdot + sizeof(backslashdot))) {
4376 /* diag_listed_as: Bareword in require contains "%s" */
4377 DIE(aTHX_ "Bareword in require contains \"\\.\"");
4384 PERL_DTRACE_PROBE_FILE_LOADING(unixname);
4386 /* Try to locate and open a file, possibly using @INC */
4388 /* with "/foo/bar.pm", "./foo.pm" and "../foo/bar.pm", try to load
4389 * the file directly rather than via @INC ... */
4390 if (!path_searchable) {
4391 /* At this point, name is SvPVX(sv) */
4393 tryrsfp = doopen_pm(sv);
4396 /* ... but if we fail, still search @INC for code references;
4397 * these are applied even on non-searchable paths (except
4398 * if we got EACESS).
4400 * For searchable paths, just search @INC normally
4402 AV *inc_checked = (AV*)sv_2mortal((SV*)newAV());
4403 if (!tryrsfp && !(errno == EACCES && !path_searchable)) {
4409 AV *incdir_av = (AV*)sv_2mortal((SV*)newAV());
4410 SV *nsv = sv; /* non const copy we can change if necessary */
4411 namesv = newSV_type(SVt_PV);
4412 AV *inc_ar = GvAVn(PL_incgv);
4413 SSize_t incdir_continue_inc_idx = -1;
4417 (AvFILL(incdir_av)>=0 /* we have INCDIR items pending */
4418 || inc_idx <= AvFILL(inc_ar)); /* @INC entries remain */
4423 /* do we have any pending INCDIR items? */
4424 if (AvFILL(incdir_av)>=0) {
4425 /* yep, shift it out */
4426 dirsv = av_shift(incdir_av);
4427 if (AvFILL(incdir_av)<0) {
4428 /* incdir is now empty, continue from where
4429 * we left off after we process this entry */
4430 inc_idx = incdir_continue_inc_idx;
4433 dirsv = *av_fetch(inc_ar, inc_idx, TRUE);
4436 if (SvGMAGICAL(dirsv)) {
4438 dirsv = newSVsv_nomg(dirsv);
4440 /* on the other hand, since we aren't copying we do need
4442 SvREFCNT_inc(dirsv);
4447 av_push(inc_checked, dirsv);
4453 UV diruv = PTR2UV(SvRV(dirsv));
4455 if (SvTYPE(SvRV(loader)) == SVt_PVAV
4456 && !SvOBJECT(SvRV(loader)))
4458 loader = *av_fetch(MUTABLE_AV(SvRV(loader)), 0, TRUE);
4459 if (SvGMAGICAL(loader)) {
4461 SV *l = sv_newmortal();
4462 sv_setsv_nomg(l, loader);
4467 if (SvPADTMP(nsv)) {
4468 nsv = sv_newmortal();
4469 SvSetSV_nosteal(nsv,sv);
4472 const char *method = NULL;
4473 bool is_incdir = FALSE;
4474 SV * inc_idx_sv = save_scalar(PL_incgv);
4475 sv_setiv(inc_idx_sv,inc_idx);
4476 if (sv_isobject(loader)) {
4477 /* if it is an object and it has an INC method, then
4480 HV *pkg = SvSTASH(SvRV(loader));
4481 GV * gv = gv_fetchmethod_pvn_flags(pkg, "INC", 3, GV_AUTOLOAD);
4482 if (gv && isGV(gv)) {
4485 /* no point to autoload here, it would have been found above */
4486 gv = gv_fetchmethod_pvn_flags(pkg, "INCDIR", 6, 0);
4487 if (gv && isGV(gv)) {
4492 /* But if we have no method, check if this is a
4493 * coderef, if it is then we treat it as an
4494 * unblessed coderef would be treated: we
4495 * execute it. If it is some other and it is in
4496 * an array ref wrapper, then really we don't
4497 * know what to do with it, (why use the
4498 * wrapper?) and we throw an exception to help
4499 * debug. If it is not in a wrapper assume it
4500 * has an overload and treat it as a string.
4501 * Maybe in the future we can detect if it does
4502 * have overloading and throw an error if not.
4505 if (SvTYPE(SvRV(loader)) != SVt_PVCV) {
4506 if (amagic_applies(loader,string_amg,AMGf_unary))
4507 goto treat_as_string;
4509 croak("Can't locate object method \"INC\", nor"
4510 " \"INCDIR\" nor string overload via"
4511 " package %" HvNAMEf_QUOTEDPREFIX " %s"
4515 : "in object in ARRAY hook"
4522 Perl_sv_setpvf(aTHX_ namesv, "/loader/0x%" UVxf "/%s",
4524 tryname = SvPVX_const(namesv);
4527 ENTER_with_name("call_INC_hook");
4529 EXTEND(SP, 2 + ((method && (loader != dirsv)) ? 1 : 0));
4531 PUSHs(method ? loader : dirsv); /* always use the object for method calls */
4533 if (method && (loader != dirsv)) /* add the args array for method calls */
4537 count = call_method(method, G_LIST|G_EVAL);
4539 count = call_sv(loader, G_LIST|G_EVAL);
4550 /* push the stringified returned items into the
4551 * incdir_av array for processing immediately
4552 * afterwards. we deliberately stringify or copy
4553 * "special" arguments, so that overload logic for
4554 * instance applies, but so that the end result is
4555 * stable. We speficially do *not* support returning
4556 * coderefs from an INCDIR call. */
4564 char *pv = SvPV(arg,l);
4565 arg = newSVpvn(pv,l);
4567 else if (SvGMAGICAL(arg)) {
4568 arg = newSVsv_nomg(arg);
4573 av_push(incdir_av, arg);
4575 /* We copy $INC into incdir_continue_inc_idx
4576 * so that when we finish processing the items
4577 * we just inserted into incdir_av we can continue
4578 * as though we had just finished executing the INCDIR
4579 * hook. We honour $INC here just like we would for
4580 * an INC hook, the hook might have rewritten @INC
4581 * at the same time as returning something to us.
4583 inc_idx_sv = GvSVn(PL_incgv);
4584 incdir_continue_inc_idx = SvOK(inc_idx_sv)
4585 ? SvIV(inc_idx_sv) : -1;
4592 if (SvROK(arg) && (SvTYPE(SvRV(arg)) <= SVt_PVLV)
4593 && !isGV_with_GP(SvRV(arg))) {
4594 filter_cache = SvRV(arg);
4601 if (SvROK(arg) && isGV_with_GP(SvRV(arg))) {
4605 if (isGV_with_GP(arg)) {
4606 IO * const io = GvIO((const GV *)arg);
4611 tryrsfp = IoIFP(io);
4612 if (IoOFP(io) && IoOFP(io) != IoIFP(io)) {
4613 PerlIO_close(IoOFP(io));
4624 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVCV) {
4626 SvREFCNT_inc_simple_void_NN(filter_sub);
4629 filter_state = SP[i];
4630 SvREFCNT_inc_simple_void(filter_state);
4634 if (!tryrsfp && (filter_cache || filter_sub)) {
4635 tryrsfp = PerlIO_open(BIT_BUCKET,
4642 if (SvTRUE(errsv) && !SvROK(errsv)) {
4644 char *pv= SvPV(errsv,l);
4645 /* Heuristic to tell if this error message
4646 * includes the standard line number info:
4647 * check if the line ends in digit dot newline.
4648 * If it does then we add some extra info so
4649 * its obvious this is coming from a hook.
4650 * If it is a user generated error we try to
4651 * leave it alone. l>12 is to ensure the
4652 * other checks are in string, but also
4653 * accounts for "at ... line 1.\n" to a
4654 * certain extent. Really we should check
4655 * further, but this is good enough for back
4658 if (l>=12 && pv[l-1] == '\n' && pv[l-2] == '.' && isDIGIT(pv[l-3]))
4659 sv_catpvf(errsv, "%s %s hook died--halting @INC search",
4660 method ? method : "INC",
4661 method ? "method" : "sub");
4666 /* FREETMPS may free our filter_cache */
4667 SvREFCNT_inc_simple_void(filter_cache);
4670 Let the hook override which @INC entry we visit
4671 next by setting $INC to a different value than it
4672 was before we called the hook. If they have
4673 completely rewritten the array they might want us
4674 to start traversing from the beginning, which is
4675 represented by -1. We use undef as an equivalent of
4676 -1. This can't be used as a way to call a hook
4677 twice, as we still dedupe.
4678 We have to do this before we LEAVE, as we localized
4679 $INC before we called the hook.
4681 inc_idx_sv = GvSVn(PL_incgv);
4682 inc_idx = SvOK(inc_idx_sv) ? SvIV(inc_idx_sv) : -1;
4686 LEAVE_with_name("call_INC_hook");
4689 It is possible that @INC has been replaced and that inc_ar
4690 now points at a freed AV. So we have to refresh it from
4693 inc_ar = GvAVn(PL_incgv);
4695 /* Now re-mortalize it. */
4696 sv_2mortal(filter_cache);
4698 /* Adjust file name if the hook has set an %INC entry.
4699 This needs to happen after the FREETMPS above. */
4700 svp = hv_fetch(GvHVn(PL_incgv), name, len, 0);
4701 /* we have to make sure that the value is not undef
4702 * or the empty string, if it is then we should not
4703 * set tryname to it as this will break error messages.
4705 * This might happen if an @INC hook evals the module
4706 * which was required in the first place and which
4707 * triggered the @INC hook, and that eval dies.
4708 * See https://github.com/Perl/perl5/issues/20535
4710 if (svp && SvOK(*svp)) {
4712 const char *tmp_pv = SvPV_const(*svp,len);
4713 /* we also guard against the deliberate empty string.
4714 * We do not guard against '0', if people want to set their
4715 * file name to 0 that is up to them. */
4725 filter_has_file = 0;
4726 filter_cache = NULL;
4728 SvREFCNT_dec_NN(filter_state);
4729 filter_state = NULL;
4732 SvREFCNT_dec_NN(filter_sub);
4738 if (path_searchable) {
4739 /* match against a plain @INC element (non-searchable
4740 * paths are only matched against refs in @INC) */
4744 dir = SvPV_nomg_const(dirsv, dirlen);
4750 if (!IS_SAFE_SYSCALL(dir, dirlen, "@INC entry", op_name))
4754 tounixpath(dir, SvPVX(sv_2mortal(newSVpv("", VMS_MAXRSS-1)))))
4757 sv_setpv(namesv, unixdir);
4758 sv_catpv(namesv, unixname);
4760 /* The equivalent of
4761 Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name);
4762 but without the need to parse the format string, or
4763 call strlen on either pointer, and with the correct
4764 allocation up front. */
4766 char *tmp = SvGROW(namesv, dirlen + len + 2);
4768 memcpy(tmp, dir, dirlen);
4771 /* Avoid '<dir>//<file>' */
4772 if (!dirlen || *(tmp-1) != '/') {
4775 /* So SvCUR_set reports the correct length below */
4779 /* name came from an SV, so it will have a '\0' at the
4780 end that we can copy as part of this memcpy(). */
4781 memcpy(tmp, name, len + 1);
4783 SvCUR_set(namesv, dirlen + len + 1);
4787 TAINT_PROPER(op_name);
4788 tryname = SvPVX_const(namesv);
4789 tryrsfp = doopen_pm(namesv);
4791 if (tryname[0] == '.' && tryname[1] == '/') {
4793 while (*++tryname == '/') {}
4797 else if (errno == EMFILE || errno == EACCES) {
4798 /* no point in trying other paths if out of handles;
4799 * on the other hand, if we couldn't open one of the
4800 * files, then going on with the search could lead to
4801 * unexpected results; see perl #113422
4810 /* at this point we've ether opened a file (tryrsfp) or set errno */
4812 saved_errno = errno; /* sv_2mortal can realloc things */
4815 /* we failed; croak if require() or return undef if do() */
4816 if (op_is_require) {
4817 if(saved_errno == EMFILE || saved_errno == EACCES) {
4818 /* diag_listed_as: Can't locate %s */
4819 DIE(aTHX_ "Can't locate %s: %s: %s",
4820 name, tryname, Strerror(saved_errno));
4822 if (path_searchable) { /* did we lookup @INC? */
4824 SV *const msg = newSVpvs_flags("", SVs_TEMP);
4825 SV *const inc = newSVpvs_flags("", SVs_TEMP);
4826 for (i = 0; i <= AvFILL(inc_checked); i++) {
4827 SV **svp= av_fetch(inc_checked, i, TRUE);
4828 if (!svp || !*svp) continue;
4829 sv_catpvs(inc, " ");
4830 sv_catsv(inc, *svp);
4832 if (memENDPs(name, len, ".pm")) {
4833 const char *e = name + len - (sizeof(".pm") - 1);
4835 bool utf8 = cBOOL(SvUTF8(sv));
4837 /* if the filename, when converted from "Foo/Bar.pm"
4838 * form back to Foo::Bar form, makes a valid
4839 * package name (i.e. parseable by C<require
4840 * Foo::Bar>), then emit a hint.
4842 * this loop is modelled after the one in
4846 if (utf8 && isIDFIRST_utf8_safe(c, e)) {
4848 while (c < e && isIDCONT_utf8_safe(
4849 (const U8*) c, (const U8*) e))
4852 else if (isWORDCHAR_A(*c)) {
4853 while (c < e && isWORDCHAR_A(*c))
4862 if (c == e && isIDFIRST_lazy_if_safe(name, e, utf8)) {
4863 sv_catpvs(msg, " (you may need to install the ");
4864 for (c = name; c < e; c++) {
4866 sv_catpvs(msg, "::");
4869 sv_catpvn(msg, c, 1);
4872 sv_catpvs(msg, " module)");
4875 else if (memENDs(name, len, ".h")) {
4876 sv_catpvs(msg, " (change .h to .ph maybe?) (did you run h2ph?)");
4878 else if (memENDs(name, len, ".ph")) {
4879 sv_catpvs(msg, " (did you run h2ph?)");
4882 /* diag_listed_as: Can't locate %s */
4884 "Can't locate %s in @INC%" SVf " (@INC entries checked:%" SVf ")",
4888 DIE(aTHX_ "Can't locate %s", name);
4891 #ifdef DEFAULT_INC_EXCLUDES_DOT
4895 /* the complication is to match the logic from doopen_pm() so
4896 * we don't treat do "sda1" as a previously successful "do".
4898 bool do_warn = namesv && ckWARN_d(WARN_DEPRECATED__DOT_IN_INC)
4899 && PerlLIO_stat(name, &st) == 0 && !S_ISDIR(st.st_mode) && !S_ISBLK(st.st_mode)
4900 && (io = PerlIO_openn(aTHX_ ":", PERL_SCRIPT_MODE, -1, 0, 0, NULL, 1, &sv)) != NULL;
4906 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED__DOT_IN_INC),
4907 "do \"%s\" failed, '.' is no longer in @INC; "
4908 "did you mean do \"./%s\"?",
4917 SETERRNO(0, SS_NORMAL);
4919 /* Update %INC. Assume success here to prevent recursive requirement. */
4920 /* name is never assigned to again, so len is still strlen(name) */
4921 /* Check whether a hook in @INC has already filled %INC */
4923 (void)hv_store(GvHVn(PL_incgv),
4924 unixname, unixlen, newSVpv(tryname,0),0);
4926 /* store the hook in the sv, note we have to *copy* hook_sv,
4927 * we don't want modifications to it to change @INC - see GH #20577
4929 SV** const svp = hv_fetch(GvHVn(PL_incgv), unixname, unixlen, 0);
4931 (void)hv_store(GvHVn(PL_incgv),
4932 unixname, unixlen, newSVsv(hook_sv), 0 );
4935 /* Now parse the file */
4937 old_savestack_ix = PL_savestack_ix;
4938 SAVECOPFILE_FREE(&PL_compiling);
4939 CopFILE_set(&PL_compiling, tryname);
4940 lex_start(NULL, tryrsfp, 0);
4942 if (filter_sub || filter_cache) {
4943 /* We can use the SvPV of the filter PVIO itself as our cache, rather
4944 than hanging another SV from it. In turn, filter_add() optionally
4945 takes the SV to use as the filter (or creates a new SV if passed
4946 NULL), so simply pass in whatever value filter_cache has. */
4947 SV * const fc = filter_cache ? newSV_type(SVt_NULL) : NULL;
4949 if (fc) sv_copypv(fc, filter_cache);
4950 datasv = filter_add(S_run_user_filter, fc);
4951 IoLINES(datasv) = filter_has_file;
4952 IoTOP_GV(datasv) = MUTABLE_GV(filter_state);
4953 IoBOTTOM_GV(datasv) = MUTABLE_GV(filter_sub);
4956 /* switch to eval mode */
4958 cx = cx_pushblock(CXt_EVAL, gimme, SP, old_savestack_ix);
4959 cx_pusheval(cx, PL_op->op_next, newSVpv(name, 0));
4961 SAVECOPLINE(&PL_compiling);
4962 CopLINE_set(&PL_compiling, 0);
4966 if (doeval_compile(gimme, NULL, PL_curcop->cop_seq, NULL))
4969 op = PL_op->op_next;
4971 PERL_DTRACE_PROBE_FILE_LOADED(unixname);
4977 /* also used for: pp_dofile() */
4981 /* If a suitable JMPENV catch frame isn't present, call docatch(),
4983 * - add such a frame, and
4984 * - start a new RUNOPS loop, which will (as the first op to run),
4985 * recursively call this pp function again.
4986 * The main body of this function is then executed by the inner call.
4989 return docatch(Perl_pp_require);
4996 return ((SvNIOKp(sv) || SvVOK(sv)) && PL_op->op_type != OP_DOFILE)
4997 ? S_require_version(aTHX_ sv)
4998 : S_require_file(aTHX_ sv);
5003 /* This is a op added to hold the hints hash for
5004 pp_entereval. The hash can be modified by the code
5005 being eval'ed, so we return a copy instead. */
5010 mXPUSHs(MUTABLE_SV(hv_copy_hints_hv(MUTABLE_HV(cSVOP_sv))));
5022 char tbuf[TYPE_DIGITS(long) + 12];
5030 I32 old_savestack_ix;
5032 /* If a suitable JMPENV catch frame isn't present, call docatch(),
5034 * - add such a frame, and
5035 * - start a new RUNOPS loop, which will (as the first op to run),
5036 * recursively call this pp function again.
5037 * The main body of this function is then executed by the inner call.
5040 return docatch(Perl_pp_entereval);
5045 was = PL_breakable_sub_gen;
5046 saved_delete = FALSE;
5050 bytes = PL_op->op_private & OPpEVAL_BYTES;
5052 if (PL_op->op_private & OPpEVAL_HAS_HH) {
5053 saved_hh = MUTABLE_HV(SvREFCNT_inc(POPs));
5055 else if (PL_hints & HINT_LOCALIZE_HH || (
5056 PL_op->op_private & OPpEVAL_COPHH
5057 && PL_curcop->cop_hints & HINT_LOCALIZE_HH
5059 saved_hh = cop_hints_2hv(PL_curcop, 0);
5060 hv_magic(saved_hh, NULL, PERL_MAGIC_hints);
5064 /* make sure we've got a plain PV (no overload etc) before testing
5065 * for taint. Making a copy here is probably overkill, but better
5066 * safe than sorry */
5068 const char * const p = SvPV_const(sv, len);
5070 sv = newSVpvn_flags(p, len, SVs_TEMP | SvUTF8(sv));
5071 lex_flags |= LEX_START_COPIED;
5073 if (bytes && SvUTF8(sv))
5074 SvPVbyte_force(sv, len);
5076 else if (bytes && SvUTF8(sv)) {
5077 /* Don't modify someone else's scalar */
5080 (void)sv_2mortal(sv);
5081 SvPVbyte_force(sv,len);
5082 lex_flags |= LEX_START_COPIED;
5085 TAINT_IF(SvTAINTED(sv));
5086 TAINT_PROPER("eval");
5088 old_savestack_ix = PL_savestack_ix;
5090 lex_start(sv, NULL, lex_flags | (PL_op->op_private & OPpEVAL_UNICODE
5091 ? LEX_IGNORE_UTF8_HINTS
5092 : bytes ? LEX_EVALBYTES : LEX_START_SAME_FILTER
5096 /* switch to eval mode */
5098 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
5099 SV * const temp_sv = sv_newmortal();
5100 Perl_sv_setpvf(aTHX_ temp_sv, "_<(eval %lu)[%s:%" LINE_Tf "]",
5101 (unsigned long)++PL_evalseq,
5102 CopFILE(PL_curcop), CopLINE(PL_curcop));
5103 tmpbuf = SvPVX(temp_sv);
5104 len = SvCUR(temp_sv);
5107 len = my_snprintf(tmpbuf, sizeof(tbuf), "_<(eval %lu)", (unsigned long)++PL_evalseq);
5108 SAVECOPFILE_FREE(&PL_compiling);
5109 CopFILE_set(&PL_compiling, tmpbuf+2);
5110 SAVECOPLINE(&PL_compiling);
5111 CopLINE_set(&PL_compiling, 1);
5112 /* special case: an eval '' executed within the DB package gets lexically
5113 * placed in the first non-DB CV rather than the current CV - this
5114 * allows the debugger to execute code, find lexicals etc, in the