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
37 #define DOCATCH(o) ((CATCH_GET == TRUE) ? docatch(o) : (o))
39 #define dopoptosub(plop) dopoptosub_at(cxstack, (plop))
48 cxix = dopoptosub(cxstack_ix);
52 switch (cxstack[cxix].blk_gimme) {
65 /* XXXX Should store the old value to allow for tie/overload - and
66 restore in regcomp, where marked with XXXX. */
76 register PMOP *pm = (PMOP*)cLOGOP->op_other;
80 /* prevent recompiling under /o and ithreads. */
81 #if defined(USE_ITHREADS)
82 if (pm->op_pmflags & PMf_KEEP && PM_GETRE(pm)) {
83 if (PL_op->op_flags & OPf_STACKED) {
93 #define tryAMAGICregexp(rx) \
96 if (SvROK(rx) && SvAMAGIC(rx)) { \
97 SV *sv = AMG_CALLunary(rx, regexp_amg); \
101 if (SvTYPE(sv) != SVt_REGEXP) \
102 Perl_croak(aTHX_ "Overloaded qr did not return a REGEXP"); \
109 if (PL_op->op_flags & OPf_STACKED) {
110 /* multiple args; concatenate them */
112 tmpstr = PAD_SV(ARGTARG);
113 sv_setpvs(tmpstr, "");
114 while (++MARK <= SP) {
118 tryAMAGICregexp(msv);
120 if ((SvAMAGIC(tmpstr) || SvAMAGIC(msv)) &&
121 (sv = amagic_call(tmpstr, msv, concat_amg, AMGf_assign)))
123 sv_setsv(tmpstr, sv);
126 sv_catsv_nomg(tmpstr, msv);
133 tryAMAGICregexp(tmpstr);
136 #undef tryAMAGICregexp
139 SV * const sv = SvRV(tmpstr);
140 if (SvTYPE(sv) == SVt_REGEXP)
143 else if (SvTYPE(tmpstr) == SVt_REGEXP)
144 re = (REGEXP*) tmpstr;
147 /* The match's LHS's get-magic might need to access this op's reg-
148 exp (as is sometimes the case with $'; see bug 70764). So we
149 must call get-magic now before we replace the regexp. Hopeful-
150 ly this hack can be replaced with the approach described at
151 http://www.nntp.perl.org/group/perl.perl5.porters/2007/03
152 /msg122415.html some day. */
153 if(pm->op_type == OP_MATCH) {
155 const bool was_tainted = PL_tainted;
156 if (pm->op_flags & OPf_STACKED)
158 else if (pm->op_private & OPpTARGET_MY)
159 lhs = PAD_SV(pm->op_targ);
162 /* Restore the previous value of PL_tainted (which may have been
163 modified by get-magic), to avoid incorrectly setting the
164 RXf_TAINTED flag further down. */
165 PL_tainted = was_tainted;
168 re = reg_temp_copy(NULL, re);
169 ReREFCNT_dec(PM_GETRE(pm));
174 const char *t = SvOK(tmpstr) ? SvPV_nomg_const(tmpstr, len) : "";
177 assert (re != (REGEXP*) &PL_sv_undef);
179 /* Check against the last compiled regexp. */
180 if (!re || !RX_PRECOMP(re) || RX_PRELEN(re) != len ||
181 memNE(RX_PRECOMP(re), t, len))
183 const regexp_engine *eng = re ? RX_ENGINE(re) : NULL;
184 U32 pm_flags = pm->op_pmflags & RXf_PMf_COMPILETIME;
188 PM_SETRE(pm, (REGEXP*) &PL_sv_undef);
190 PM_SETRE(pm, NULL); /* crucial if regcomp aborts */
192 } else if (PL_curcop->cop_hints_hash) {
193 SV *ptr = cop_hints_fetch_pvs(PL_curcop, "regcomp", 0);
194 if (ptr && SvIOK(ptr) && SvIV(ptr))
195 eng = INT2PTR(regexp_engine*,SvIV(ptr));
198 if (PL_op->op_flags & OPf_SPECIAL)
199 PL_reginterp_cnt = I32_MAX; /* Mark as safe. */
201 if (DO_UTF8(tmpstr)) {
202 assert (SvUTF8(tmpstr));
203 } else if (SvUTF8(tmpstr)) {
204 /* Not doing UTF-8, despite what the SV says. Is this only if
205 we're trapped in use 'bytes'? */
206 /* Make a copy of the octet sequence, but without the flag on,
207 as the compiler now honours the SvUTF8 flag on tmpstr. */
209 const char *const p = SvPV(tmpstr, len);
210 tmpstr = newSVpvn_flags(p, len, SVs_TEMP);
212 else if (SvAMAGIC(tmpstr)) {
213 /* make a copy to avoid extra stringifies */
214 tmpstr = newSVpvn_flags(t, len, SVs_TEMP | SvUTF8(tmpstr));
217 /* If it is gmagical, create a mortal copy, but without calling
218 get-magic, as we have already done that. */
219 if(SvGMAGICAL(tmpstr)) {
220 SV *mortalcopy = sv_newmortal();
221 sv_setsv_flags(mortalcopy, tmpstr, 0);
226 PM_SETRE(pm, CALLREGCOMP_ENG(eng, tmpstr, pm_flags));
228 PM_SETRE(pm, CALLREGCOMP(tmpstr, pm_flags));
230 PL_reginterp_cnt = 0; /* XXXX Be extra paranoid - needed
231 inside tie/overload accessors. */
237 #ifndef INCOMPLETE_TAINTS
240 SvTAINTED_on((SV*)re);
241 RX_EXTFLAGS(re) |= RXf_TAINTED;
246 if (!RX_PRELEN(PM_GETRE(pm)) && PL_curpm)
250 #if !defined(USE_ITHREADS)
251 /* can't change the optree at runtime either */
252 /* PMf_KEEP is handled differently under threads to avoid these problems */
253 if (pm->op_pmflags & PMf_KEEP) {
254 pm->op_private &= ~OPpRUNTIME; /* no point compiling again */
255 cLOGOP->op_first->op_next = PL_op->op_next;
265 register PERL_CONTEXT *cx = &cxstack[cxstack_ix];
266 register PMOP * const pm = (PMOP*) cLOGOP->op_other;
267 register SV * const dstr = cx->sb_dstr;
268 register char *s = cx->sb_s;
269 register char *m = cx->sb_m;
270 char *orig = cx->sb_orig;
271 register REGEXP * const rx = cx->sb_rx;
273 REGEXP *old = PM_GETRE(pm);
280 PM_SETRE(pm,ReREFCNT_inc(rx));
283 rxres_restore(&cx->sb_rxres, rx);
284 RX_MATCH_UTF8_set(rx, DO_UTF8(cx->sb_targ));
286 if (cx->sb_iters++) {
287 const I32 saviters = cx->sb_iters;
288 if (cx->sb_iters > cx->sb_maxiters)
289 DIE(aTHX_ "Substitution loop");
291 SvGETMAGIC(TOPs); /* possibly clear taint on $1 etc: #67962 */
293 /* See "how taint works" above pp_subst() */
295 cx->sb_rxtainted |= SUBST_TAINT_REPL;
296 sv_catsv_nomg(dstr, POPs);
297 /* XXX: adjust for positive offsets of \G for instance s/(.)\G//g with positive pos() */
301 if (CxONCE(cx) || s < orig ||
302 !CALLREGEXEC(rx, s, cx->sb_strend, orig,
303 (s == m) + RX_GOFS(rx), cx->sb_targ, NULL,
304 ((cx->sb_rflags & REXEC_COPY_STR)
305 ? (REXEC_IGNOREPOS|REXEC_NOT_FIRST)
306 : (REXEC_COPY_STR|REXEC_IGNOREPOS|REXEC_NOT_FIRST))))
308 SV * const targ = cx->sb_targ;
310 assert(cx->sb_strend >= s);
311 if(cx->sb_strend > s) {
312 if (DO_UTF8(dstr) && !SvUTF8(targ))
313 sv_catpvn_utf8_upgrade(dstr, s, cx->sb_strend - s, nsv);
315 sv_catpvn(dstr, s, cx->sb_strend - s);
317 if (RX_MATCH_TAINTED(rx)) /* run time pattern taint, eg locale */
318 cx->sb_rxtainted |= SUBST_TAINT_PAT;
320 #ifdef PERL_OLD_COPY_ON_WRITE
322 sv_force_normal_flags(targ, SV_COW_DROP_PV);
328 SvPV_set(targ, SvPVX(dstr));
329 SvCUR_set(targ, SvCUR(dstr));
330 SvLEN_set(targ, SvLEN(dstr));
333 SvPV_set(dstr, NULL);
335 if (pm->op_pmflags & PMf_NONDESTRUCT)
338 mPUSHi(saviters - 1);
340 (void)SvPOK_only_UTF8(targ);
342 /* update the taint state of various various variables in
343 * preparation for final exit.
344 * See "how taint works" above pp_subst() */
346 if ((cx->sb_rxtainted & SUBST_TAINT_PAT) ||
347 ((cx->sb_rxtainted & (SUBST_TAINT_STR|SUBST_TAINT_RETAINT))
348 == (SUBST_TAINT_STR|SUBST_TAINT_RETAINT))
350 (RX_MATCH_TAINTED_on(rx)); /* taint $1 et al */
352 if (!(cx->sb_rxtainted & SUBST_TAINT_BOOLRET)
353 && (cx->sb_rxtainted & (SUBST_TAINT_STR|SUBST_TAINT_PAT))
355 SvTAINTED_on(TOPs); /* taint return value */
356 /* needed for mg_set below */
357 PL_tainted = cBOOL(cx->sb_rxtainted &
358 (SUBST_TAINT_STR|SUBST_TAINT_PAT|SUBST_TAINT_REPL));
361 /* PL_tainted must be correctly set for this mg_set */
364 LEAVE_SCOPE(cx->sb_oldsave);
366 RETURNOP(pm->op_next);
369 cx->sb_iters = saviters;
371 if (RX_MATCH_COPIED(rx) && RX_SUBBEG(rx) != orig) {
374 cx->sb_orig = orig = RX_SUBBEG(rx);
376 cx->sb_strend = s + (cx->sb_strend - m);
378 cx->sb_m = m = RX_OFFS(rx)[0].start + orig;
380 if (DO_UTF8(dstr) && !SvUTF8(cx->sb_targ))
381 sv_catpvn_utf8_upgrade(dstr, s, m - s, nsv);
383 sv_catpvn(dstr, s, m-s);
385 cx->sb_s = RX_OFFS(rx)[0].end + orig;
386 { /* Update the pos() information. */
387 SV * const sv = cx->sb_targ;
389 SvUPGRADE(sv, SVt_PVMG);
390 if (!(mg = mg_find(sv, PERL_MAGIC_regex_global))) {
391 #ifdef PERL_OLD_COPY_ON_WRITE
393 sv_force_normal_flags(sv, 0);
395 mg = sv_magicext(sv, NULL, PERL_MAGIC_regex_global, &PL_vtbl_mglob,
398 mg->mg_len = m - orig;
401 (void)ReREFCNT_inc(rx);
402 /* update the taint state of various various variables in preparation
403 * for calling the code block.
404 * See "how taint works" above pp_subst() */
406 if (RX_MATCH_TAINTED(rx)) /* run time pattern taint, eg locale */
407 cx->sb_rxtainted |= SUBST_TAINT_PAT;
409 if ((cx->sb_rxtainted & SUBST_TAINT_PAT) ||
410 ((cx->sb_rxtainted & (SUBST_TAINT_STR|SUBST_TAINT_RETAINT))
411 == (SUBST_TAINT_STR|SUBST_TAINT_RETAINT))
413 (RX_MATCH_TAINTED_on(rx)); /* taint $1 et al */
415 if (cx->sb_iters > 1 && (cx->sb_rxtainted &
416 (SUBST_TAINT_STR|SUBST_TAINT_PAT|SUBST_TAINT_REPL)))
417 SvTAINTED_on(cx->sb_targ);
420 rxres_save(&cx->sb_rxres, rx);
422 RETURNOP(pm->op_pmstashstartu.op_pmreplstart);
426 Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx)
431 PERL_ARGS_ASSERT_RXRES_SAVE;
434 if (!p || p[1] < RX_NPARENS(rx)) {
435 #ifdef PERL_OLD_COPY_ON_WRITE
436 i = 7 + RX_NPARENS(rx) * 2;
438 i = 6 + RX_NPARENS(rx) * 2;
447 *p++ = PTR2UV(RX_MATCH_COPIED(rx) ? RX_SUBBEG(rx) : NULL);
448 RX_MATCH_COPIED_off(rx);
450 #ifdef PERL_OLD_COPY_ON_WRITE
451 *p++ = PTR2UV(RX_SAVED_COPY(rx));
452 RX_SAVED_COPY(rx) = NULL;
455 *p++ = RX_NPARENS(rx);
457 *p++ = PTR2UV(RX_SUBBEG(rx));
458 *p++ = (UV)RX_SUBLEN(rx);
459 for (i = 0; i <= RX_NPARENS(rx); ++i) {
460 *p++ = (UV)RX_OFFS(rx)[i].start;
461 *p++ = (UV)RX_OFFS(rx)[i].end;
466 S_rxres_restore(pTHX_ void **rsp, REGEXP *rx)
471 PERL_ARGS_ASSERT_RXRES_RESTORE;
474 RX_MATCH_COPY_FREE(rx);
475 RX_MATCH_COPIED_set(rx, *p);
478 #ifdef PERL_OLD_COPY_ON_WRITE
479 if (RX_SAVED_COPY(rx))
480 SvREFCNT_dec (RX_SAVED_COPY(rx));
481 RX_SAVED_COPY(rx) = INT2PTR(SV*,*p);
485 RX_NPARENS(rx) = *p++;
487 RX_SUBBEG(rx) = INT2PTR(char*,*p++);
488 RX_SUBLEN(rx) = (I32)(*p++);
489 for (i = 0; i <= RX_NPARENS(rx); ++i) {
490 RX_OFFS(rx)[i].start = (I32)(*p++);
491 RX_OFFS(rx)[i].end = (I32)(*p++);
496 S_rxres_free(pTHX_ void **rsp)
498 UV * const p = (UV*)*rsp;
500 PERL_ARGS_ASSERT_RXRES_FREE;
505 void *tmp = INT2PTR(char*,*p);
508 PoisonFree(*p, 1, sizeof(*p));
510 Safefree(INT2PTR(char*,*p));
512 #ifdef PERL_OLD_COPY_ON_WRITE
514 SvREFCNT_dec (INT2PTR(SV*,p[1]));
524 dVAR; dSP; dMARK; dORIGMARK;
525 register SV * const tmpForm = *++MARK;
530 register SV *sv = NULL;
531 const char *item = NULL;
535 bool chopspace = (strchr(PL_chopset, ' ') != NULL);
536 const char *chophere = NULL;
537 char *linemark = NULL;
539 bool gotsome = FALSE;
541 const STRLEN fudge = SvPOKp(tmpForm)
542 ? (SvCUR(tmpForm) * (IN_BYTES ? 1 : 3) + 1) : 0;
543 bool item_is_utf8 = FALSE;
544 bool targ_is_utf8 = FALSE;
549 if (SvTYPE(tmpForm) >= SVt_PVMG) {
550 /* This might, of course, still return NULL. */
551 mg = mg_find(tmpForm, PERL_MAGIC_fm);
553 sv_upgrade(tmpForm, SVt_PVMG);
557 if (SvREADONLY(tmpForm)) {
558 SvREADONLY_off(tmpForm);
559 mg = doparseform(tmpForm);
560 SvREADONLY_on(tmpForm);
563 mg = doparseform(tmpForm);
566 fpc = (U32*)mg->mg_ptr;
568 SvPV_force(PL_formtarget, len);
569 if (SvTAINTED(tmpForm))
570 SvTAINTED_on(PL_formtarget);
571 if (DO_UTF8(PL_formtarget))
573 t = SvGROW(PL_formtarget, len + fudge + 1); /* XXX SvCUR bad */
575 f = SvPV_const(tmpForm, len);
579 const char *name = "???";
582 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
583 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
584 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
585 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
586 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
588 case FF_CHECKNL: name = "CHECKNL"; break;
589 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
590 case FF_SPACE: name = "SPACE"; break;
591 case FF_HALFSPACE: name = "HALFSPACE"; break;
592 case FF_ITEM: name = "ITEM"; break;
593 case FF_CHOP: name = "CHOP"; break;
594 case FF_LINEGLOB: name = "LINEGLOB"; break;
595 case FF_NEWLINE: name = "NEWLINE"; break;
596 case FF_MORE: name = "MORE"; break;
597 case FF_LINEMARK: name = "LINEMARK"; break;
598 case FF_END: name = "END"; break;
599 case FF_0DECIMAL: name = "0DECIMAL"; break;
600 case FF_LINESNGL: name = "LINESNGL"; break;
603 PerlIO_printf(Perl_debug_log, "%-16s%ld\n", name, (long) arg);
605 PerlIO_printf(Perl_debug_log, "%-16s\n", name);
616 if (targ_is_utf8 && !SvUTF8(tmpForm)) {
617 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
619 sv_catpvn_utf8_upgrade(PL_formtarget, f, arg, nsv);
620 t = SvEND(PL_formtarget);
624 if (!targ_is_utf8 && DO_UTF8(tmpForm)) {
625 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
627 sv_utf8_upgrade_flags_grow(PL_formtarget, SV_GMAGIC, fudge + 1);
628 t = SvEND(PL_formtarget);
648 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Not enough format arguments");
651 SvTAINTED_on(PL_formtarget);
657 const char *s = item = SvPV_const(sv, len);
660 itemsize = sv_len_utf8(sv);
661 if (itemsize != (I32)len) {
663 if (itemsize > fieldsize) {
664 itemsize = fieldsize;
665 itembytes = itemsize;
666 sv_pos_u2b(sv, &itembytes, 0);
670 send = chophere = s + itembytes;
680 sv_pos_b2u(sv, &itemsize);
684 item_is_utf8 = FALSE;
685 if (itemsize > fieldsize)
686 itemsize = fieldsize;
687 send = chophere = s + itemsize;
701 const char *s = item = SvPV_const(sv, len);
704 itemsize = sv_len_utf8(sv);
705 if (itemsize != (I32)len) {
707 if (itemsize <= fieldsize) {
708 const char *send = chophere = s + itemsize;
721 itemsize = fieldsize;
722 itembytes = itemsize;
723 sv_pos_u2b(sv, &itembytes, 0);
724 send = chophere = s + itembytes;
725 while (s < send || (s == send && isSPACE(*s))) {
735 if (strchr(PL_chopset, *s))
740 itemsize = chophere - item;
741 sv_pos_b2u(sv, &itemsize);
747 item_is_utf8 = FALSE;
748 if (itemsize <= fieldsize) {
749 const char *const send = chophere = s + itemsize;
762 itemsize = fieldsize;
763 send = chophere = s + itemsize;
764 while (s < send || (s == send && isSPACE(*s))) {
774 if (strchr(PL_chopset, *s))
779 itemsize = chophere - item;
785 arg = fieldsize - itemsize;
794 arg = fieldsize - itemsize;
805 const char *s = item;
809 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
811 sv_utf8_upgrade_flags_grow(PL_formtarget, SV_GMAGIC,
813 t = SvEND(PL_formtarget);
817 if (UTF8_IS_CONTINUED(*s)) {
818 STRLEN skip = UTF8SKIP(s);
835 if ( !((*t++ = *s++) & ~31) )
841 if (targ_is_utf8 && !item_is_utf8) {
842 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
844 sv_catpvn_utf8_upgrade(PL_formtarget, s, arg, nsv);
845 for (; t < SvEND(PL_formtarget); t++) {
858 const int ch = *t++ = *s++;
861 if ( !((*t++ = *s++) & ~31) )
870 const char *s = chophere;
884 const bool oneline = fpc[-1] == FF_LINESNGL;
885 const char *s = item = SvPV_const(sv, len);
886 item_is_utf8 = DO_UTF8(sv);
889 STRLEN to_copy = itemsize;
890 const char *const send = s + len;
891 const U8 *source = (const U8 *) s;
895 chophere = s + itemsize;
899 to_copy = s - SvPVX_const(sv) - 1;
911 if (targ_is_utf8 && !item_is_utf8) {
912 source = tmp = bytes_to_utf8(source, &to_copy);
913 SvCUR_set(PL_formtarget,
914 t - SvPVX_const(PL_formtarget));
916 if (item_is_utf8 && !targ_is_utf8) {
917 /* Upgrade targ to UTF8, and then we reduce it to
918 a problem we have a simple solution for. */
919 SvCUR_set(PL_formtarget,
920 t - SvPVX_const(PL_formtarget));
922 /* Don't need get magic. */
923 sv_utf8_upgrade_nomg(PL_formtarget);
925 SvCUR_set(PL_formtarget,
926 t - SvPVX_const(PL_formtarget));
929 /* Easy. They agree. */
930 assert (item_is_utf8 == targ_is_utf8);
932 SvGROW(PL_formtarget,
933 SvCUR(PL_formtarget) + to_copy + fudge + 1);
934 t = SvPVX(PL_formtarget) + SvCUR(PL_formtarget);
936 Copy(source, t, to_copy, char);
938 SvCUR_set(PL_formtarget, SvCUR(PL_formtarget) + to_copy);
940 if (SvGMAGICAL(sv)) {
941 /* Mustn't call sv_pos_b2u() as it does a second
942 mg_get(). Is this a bug? Do we need a _flags()
944 itemsize = utf8_length(source, source + itemsize);
946 sv_pos_b2u(sv, &itemsize);
958 #if defined(USE_LONG_DOUBLE)
961 "%#0*.*" PERL_PRIfldbl : "%0*.*" PERL_PRIfldbl);
965 "%#0*.*f" : "%0*.*f");
970 #if defined(USE_LONG_DOUBLE)
972 ((arg & 256) ? "%#*.*" PERL_PRIfldbl : "%*.*" PERL_PRIfldbl);
975 ((arg & 256) ? "%#*.*f" : "%*.*f");
978 /* If the field is marked with ^ and the value is undefined,
980 if ((arg & 512) && !SvOK(sv)) {
988 /* overflow evidence */
989 if (num_overflow(value, fieldsize, arg)) {
995 /* Formats aren't yet marked for locales, so assume "yes". */
997 STORE_NUMERIC_STANDARD_SET_LOCAL();
998 my_snprintf(t, SvLEN(PL_formtarget) - (t - SvPVX(PL_formtarget)), fmt, (int) fieldsize, (int) arg & 255, value);
999 RESTORE_NUMERIC_STANDARD();
1006 while (t-- > linemark && *t == ' ') ;
1014 if (arg) { /* repeat until fields exhausted? */
1016 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
1017 lines += FmLINES(PL_formtarget);
1019 SvUTF8_on(PL_formtarget);
1020 FmLINES(PL_formtarget) = lines;
1022 RETURNOP(cLISTOP->op_first);
1033 const char *s = chophere;
1034 const char *send = item + len;
1036 while (isSPACE(*s) && (s < send))
1041 arg = fieldsize - itemsize;
1048 if (strnEQ(s1," ",3)) {
1049 while (s1 > SvPVX_const(PL_formtarget) && isSPACE(s1[-1]))
1060 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
1062 SvUTF8_on(PL_formtarget);
1063 FmLINES(PL_formtarget) += lines;
1075 if (PL_stack_base + *PL_markstack_ptr == SP) {
1077 if (GIMME_V == G_SCALAR)
1079 RETURNOP(PL_op->op_next->op_next);
1081 PL_stack_sp = PL_stack_base + *PL_markstack_ptr + 1;
1082 Perl_pp_pushmark(aTHX); /* push dst */
1083 Perl_pp_pushmark(aTHX); /* push src */
1084 ENTER_with_name("grep"); /* enter outer scope */
1087 if (PL_op->op_private & OPpGREP_LEX)
1088 SAVESPTR(PAD_SVl(PL_op->op_targ));
1091 ENTER_with_name("grep_item"); /* enter inner scope */
1094 src = PL_stack_base[*PL_markstack_ptr];
1096 if (PL_op->op_private & OPpGREP_LEX)
1097 PAD_SVl(PL_op->op_targ) = src;
1102 if (PL_op->op_type == OP_MAPSTART)
1103 Perl_pp_pushmark(aTHX); /* push top */
1104 return ((LOGOP*)PL_op->op_next)->op_other;
1110 const I32 gimme = GIMME_V;
1111 I32 items = (SP - PL_stack_base) - *PL_markstack_ptr; /* how many new items */
1117 /* first, move source pointer to the next item in the source list */
1118 ++PL_markstack_ptr[-1];
1120 /* if there are new items, push them into the destination list */
1121 if (items && gimme != G_VOID) {
1122 /* might need to make room back there first */
1123 if (items > PL_markstack_ptr[-1] - PL_markstack_ptr[-2]) {
1124 /* XXX this implementation is very pessimal because the stack
1125 * is repeatedly extended for every set of items. Is possible
1126 * to do this without any stack extension or copying at all
1127 * by maintaining a separate list over which the map iterates
1128 * (like foreach does). --gsar */
1130 /* everything in the stack after the destination list moves
1131 * towards the end the stack by the amount of room needed */
1132 shift = items - (PL_markstack_ptr[-1] - PL_markstack_ptr[-2]);
1134 /* items to shift up (accounting for the moved source pointer) */
1135 count = (SP - PL_stack_base) - (PL_markstack_ptr[-1] - 1);
1137 /* This optimization is by Ben Tilly and it does
1138 * things differently from what Sarathy (gsar)
1139 * is describing. The downside of this optimization is
1140 * that leaves "holes" (uninitialized and hopefully unused areas)
1141 * to the Perl stack, but on the other hand this
1142 * shouldn't be a problem. If Sarathy's idea gets
1143 * implemented, this optimization should become
1144 * irrelevant. --jhi */
1146 shift = count; /* Avoid shifting too often --Ben Tilly */
1150 dst = (SP += shift);
1151 PL_markstack_ptr[-1] += shift;
1152 *PL_markstack_ptr += shift;
1156 /* copy the new items down to the destination list */
1157 dst = PL_stack_base + (PL_markstack_ptr[-2] += items) - 1;
1158 if (gimme == G_ARRAY) {
1159 /* add returned items to the collection (making mortal copies
1160 * if necessary), then clear the current temps stack frame
1161 * *except* for those items. We do this splicing the items
1162 * into the start of the tmps frame (so some items may be on
1163 * the tmps stack twice), then moving PL_tmps_floor above
1164 * them, then freeing the frame. That way, the only tmps that
1165 * accumulate over iterations are the return values for map.
1166 * We have to do to this way so that everything gets correctly
1167 * freed if we die during the map.
1171 /* make space for the slice */
1172 EXTEND_MORTAL(items);
1173 tmpsbase = PL_tmps_floor + 1;
1174 Move(PL_tmps_stack + tmpsbase,
1175 PL_tmps_stack + tmpsbase + items,
1176 PL_tmps_ix - PL_tmps_floor,
1178 PL_tmps_ix += items;
1183 sv = sv_mortalcopy(sv);
1185 PL_tmps_stack[tmpsbase++] = SvREFCNT_inc_simple(sv);
1187 /* clear the stack frame except for the items */
1188 PL_tmps_floor += items;
1190 /* FREETMPS may have cleared the TEMP flag on some of the items */
1193 SvTEMP_on(PL_tmps_stack[--tmpsbase]);
1196 /* scalar context: we don't care about which values map returns
1197 * (we use undef here). And so we certainly don't want to do mortal
1198 * copies of meaningless values. */
1199 while (items-- > 0) {
1201 *dst-- = &PL_sv_undef;
1209 LEAVE_with_name("grep_item"); /* exit inner scope */
1212 if (PL_markstack_ptr[-1] > *PL_markstack_ptr) {
1214 (void)POPMARK; /* pop top */
1215 LEAVE_with_name("grep"); /* exit outer scope */
1216 (void)POPMARK; /* pop src */
1217 items = --*PL_markstack_ptr - PL_markstack_ptr[-1];
1218 (void)POPMARK; /* pop dst */
1219 SP = PL_stack_base + POPMARK; /* pop original mark */
1220 if (gimme == G_SCALAR) {
1221 if (PL_op->op_private & OPpGREP_LEX) {
1222 SV* sv = sv_newmortal();
1223 sv_setiv(sv, items);
1231 else if (gimme == G_ARRAY)
1238 ENTER_with_name("grep_item"); /* enter inner scope */
1241 /* set $_ to the new source item */
1242 src = PL_stack_base[PL_markstack_ptr[-1]];
1244 if (PL_op->op_private & OPpGREP_LEX)
1245 PAD_SVl(PL_op->op_targ) = src;
1249 RETURNOP(cLOGOP->op_other);
1258 if (GIMME == G_ARRAY)
1260 if (SvTRUEx(PAD_SV(PL_op->op_targ)))
1261 return cLOGOP->op_other;
1271 if (GIMME == G_ARRAY) {
1272 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
1276 SV * const targ = PAD_SV(PL_op->op_targ);
1279 if (PL_op->op_private & OPpFLIP_LINENUM) {
1280 if (GvIO(PL_last_in_gv)) {
1281 flip = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
1284 GV * const gv = gv_fetchpvs(".", GV_ADD|GV_NOTQUAL, SVt_PV);
1286 flip = SvIV(sv) == SvIV(GvSV(gv));
1292 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
1293 if (PL_op->op_flags & OPf_SPECIAL) {
1301 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
1304 sv_setpvs(TARG, "");
1310 /* This code tries to decide if "$left .. $right" should use the
1311 magical string increment, or if the range is numeric (we make
1312 an exception for .."0" [#18165]). AMS 20021031. */
1314 #define RANGE_IS_NUMERIC(left,right) ( \
1315 SvNIOKp(left) || (SvOK(left) && !SvPOKp(left)) || \
1316 SvNIOKp(right) || (SvOK(right) && !SvPOKp(right)) || \
1317 (((!SvOK(left) && SvOK(right)) || ((!SvOK(left) || \
1318 looks_like_number(left)) && SvPOKp(left) && *SvPVX_const(left) != '0')) \
1319 && (!SvOK(right) || looks_like_number(right))))
1325 if (GIMME == G_ARRAY) {
1331 if (RANGE_IS_NUMERIC(left,right)) {
1334 if ((SvOK(left) && SvNV(left) < IV_MIN) ||
1335 (SvOK(right) && SvNV(right) > IV_MAX))
1336 DIE(aTHX_ "Range iterator outside integer range");
1347 SV * const sv = sv_2mortal(newSViv(i++));
1352 SV * const final = sv_mortalcopy(right);
1354 const char * const tmps = SvPV_const(final, len);
1356 SV *sv = sv_mortalcopy(left);
1357 SvPV_force_nolen(sv);
1358 while (!SvNIOKp(sv) && SvCUR(sv) <= len) {
1360 if (strEQ(SvPVX_const(sv),tmps))
1362 sv = sv_2mortal(newSVsv(sv));
1369 SV * const targ = PAD_SV(cUNOP->op_first->op_targ);
1373 if (PL_op->op_private & OPpFLIP_LINENUM) {
1374 if (GvIO(PL_last_in_gv)) {
1375 flop = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
1378 GV * const gv = gv_fetchpvs(".", GV_ADD|GV_NOTQUAL, SVt_PV);
1379 if (gv && GvSV(gv)) flop = SvIV(sv) == SvIV(GvSV(gv));
1387 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
1388 sv_catpvs(targ, "E0");
1398 static const char * const context_name[] = {
1400 NULL, /* CXt_WHEN never actually needs "block" */
1401 NULL, /* CXt_BLOCK never actually needs "block" */
1402 NULL, /* CXt_GIVEN never actually needs "block" */
1403 NULL, /* CXt_LOOP_FOR never actually needs "loop" */
1404 NULL, /* CXt_LOOP_PLAIN never actually needs "loop" */
1405 NULL, /* CXt_LOOP_LAZYSV never actually needs "loop" */
1406 NULL, /* CXt_LOOP_LAZYIV never actually needs "loop" */
1414 S_dopoptolabel(pTHX_ const char *label)
1419 PERL_ARGS_ASSERT_DOPOPTOLABEL;
1421 for (i = cxstack_ix; i >= 0; i--) {
1422 register const PERL_CONTEXT * const cx = &cxstack[i];
1423 switch (CxTYPE(cx)) {
1429 Perl_ck_warner(aTHX_ packWARN(WARN_EXITING), "Exiting %s via %s",
1430 context_name[CxTYPE(cx)], OP_NAME(PL_op));
1431 if (CxTYPE(cx) == CXt_NULL)
1434 case CXt_LOOP_LAZYIV:
1435 case CXt_LOOP_LAZYSV:
1437 case CXt_LOOP_PLAIN:
1439 const char *cx_label = CxLABEL(cx);
1440 if (!cx_label || strNE(label, cx_label) ) {
1441 DEBUG_l(Perl_deb(aTHX_ "(poptolabel(): skipping label at cx=%ld %s)\n",
1442 (long)i, cx_label));
1445 DEBUG_l( Perl_deb(aTHX_ "(poptolabel(): found label at cx=%ld %s)\n", (long)i, label));
1456 Perl_dowantarray(pTHX)
1459 const I32 gimme = block_gimme();
1460 return (gimme == G_VOID) ? G_SCALAR : gimme;
1464 Perl_block_gimme(pTHX)
1467 const I32 cxix = dopoptosub(cxstack_ix);
1471 switch (cxstack[cxix].blk_gimme) {
1479 Perl_croak(aTHX_ "panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
1486 Perl_is_lvalue_sub(pTHX)
1489 const I32 cxix = dopoptosub(cxstack_ix);
1490 assert(cxix >= 0); /* We should only be called from inside subs */
1492 if (CxLVAL(cxstack + cxix) && CvLVALUE(cxstack[cxix].blk_sub.cv))
1493 return CxLVAL(cxstack + cxix);
1499 S_dopoptosub_at(pTHX_ const PERL_CONTEXT *cxstk, I32 startingblock)
1504 PERL_ARGS_ASSERT_DOPOPTOSUB_AT;
1506 for (i = startingblock; i >= 0; i--) {
1507 register const PERL_CONTEXT * const cx = &cxstk[i];
1508 switch (CxTYPE(cx)) {
1514 DEBUG_l( Perl_deb(aTHX_ "(dopoptosub_at(): found sub at cx=%ld)\n", (long)i));
1522 S_dopoptoeval(pTHX_ I32 startingblock)
1526 for (i = startingblock; i >= 0; i--) {
1527 register const PERL_CONTEXT *cx = &cxstack[i];
1528 switch (CxTYPE(cx)) {
1532 DEBUG_l( Perl_deb(aTHX_ "(dopoptoeval(): found eval at cx=%ld)\n", (long)i));
1540 S_dopoptoloop(pTHX_ I32 startingblock)
1544 for (i = startingblock; i >= 0; i--) {
1545 register const PERL_CONTEXT * const cx = &cxstack[i];
1546 switch (CxTYPE(cx)) {
1552 Perl_ck_warner(aTHX_ packWARN(WARN_EXITING), "Exiting %s via %s",
1553 context_name[CxTYPE(cx)], OP_NAME(PL_op));
1554 if ((CxTYPE(cx)) == CXt_NULL)
1557 case CXt_LOOP_LAZYIV:
1558 case CXt_LOOP_LAZYSV:
1560 case CXt_LOOP_PLAIN:
1561 DEBUG_l( Perl_deb(aTHX_ "(dopoptoloop(): found loop at cx=%ld)\n", (long)i));
1569 S_dopoptogiven(pTHX_ I32 startingblock)
1573 for (i = startingblock; i >= 0; i--) {
1574 register const PERL_CONTEXT *cx = &cxstack[i];
1575 switch (CxTYPE(cx)) {
1579 DEBUG_l( Perl_deb(aTHX_ "(dopoptogiven(): found given at cx=%ld)\n", (long)i));
1581 case CXt_LOOP_PLAIN:
1582 assert(!CxFOREACHDEF(cx));
1584 case CXt_LOOP_LAZYIV:
1585 case CXt_LOOP_LAZYSV:
1587 if (CxFOREACHDEF(cx)) {
1588 DEBUG_l( Perl_deb(aTHX_ "(dopoptogiven(): found foreach at cx=%ld)\n", (long)i));
1597 S_dopoptowhen(pTHX_ I32 startingblock)
1601 for (i = startingblock; i >= 0; i--) {
1602 register const PERL_CONTEXT *cx = &cxstack[i];
1603 switch (CxTYPE(cx)) {
1607 DEBUG_l( Perl_deb(aTHX_ "(dopoptowhen(): found when at cx=%ld)\n", (long)i));
1615 Perl_dounwind(pTHX_ I32 cxix)
1620 while (cxstack_ix > cxix) {
1622 register PERL_CONTEXT *cx = &cxstack[cxstack_ix];
1623 DEBUG_CX("UNWIND"); \
1624 /* Note: we don't need to restore the base context info till the end. */
1625 switch (CxTYPE(cx)) {
1628 continue; /* not break */
1636 case CXt_LOOP_LAZYIV:
1637 case CXt_LOOP_LAZYSV:
1639 case CXt_LOOP_PLAIN:
1650 PERL_UNUSED_VAR(optype);
1654 Perl_qerror(pTHX_ SV *err)
1658 PERL_ARGS_ASSERT_QERROR;
1661 if (PL_in_eval & EVAL_KEEPERR) {
1662 Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "\t(in cleanup) %s",
1663 SvPV_nolen_const(err));
1666 sv_catsv(ERRSV, err);
1669 sv_catsv(PL_errors, err);
1671 Perl_warn(aTHX_ "%"SVf, SVfARG(err));
1673 ++PL_parser->error_count;
1677 Perl_die_unwind(pTHX_ SV *msv)
1680 SV *exceptsv = sv_mortalcopy(msv);
1681 U8 in_eval = PL_in_eval;
1682 PERL_ARGS_ASSERT_DIE_UNWIND;
1689 * Historically, perl used to set ERRSV ($@) early in the die
1690 * process and rely on it not getting clobbered during unwinding.
1691 * That sucked, because it was liable to get clobbered, so the
1692 * setting of ERRSV used to emit the exception from eval{} has
1693 * been moved to much later, after unwinding (see just before
1694 * JMPENV_JUMP below). However, some modules were relying on the
1695 * early setting, by examining $@ during unwinding to use it as
1696 * a flag indicating whether the current unwinding was caused by
1697 * an exception. It was never a reliable flag for that purpose,
1698 * being totally open to false positives even without actual
1699 * clobberage, but was useful enough for production code to
1700 * semantically rely on it.
1702 * We'd like to have a proper introspective interface that
1703 * explicitly describes the reason for whatever unwinding
1704 * operations are currently in progress, so that those modules
1705 * work reliably and $@ isn't further overloaded. But we don't
1706 * have one yet. In its absence, as a stopgap measure, ERRSV is
1707 * now *additionally* set here, before unwinding, to serve as the
1708 * (unreliable) flag that it used to.
1710 * This behaviour is temporary, and should be removed when a
1711 * proper way to detect exceptional unwinding has been developed.
1712 * As of 2010-12, the authors of modules relying on the hack
1713 * are aware of the issue, because the modules failed on
1714 * perls 5.13.{1..7} which had late setting of $@ without this
1715 * early-setting hack.
1717 if (!(in_eval & EVAL_KEEPERR)) {
1718 SvTEMP_off(exceptsv);
1719 sv_setsv(ERRSV, exceptsv);
1722 while ((cxix = dopoptoeval(cxstack_ix)) < 0
1723 && PL_curstackinfo->si_prev)
1732 register PERL_CONTEXT *cx;
1735 JMPENV *restartjmpenv;
1738 if (cxix < cxstack_ix)
1741 POPBLOCK(cx,PL_curpm);
1742 if (CxTYPE(cx) != CXt_EVAL) {
1744 const char* message = SvPVx_const(exceptsv, msglen);
1745 PerlIO_write(Perl_error_log, (const char *)"panic: die ", 11);
1746 PerlIO_write(Perl_error_log, message, msglen);
1750 namesv = cx->blk_eval.old_namesv;
1751 oldcop = cx->blk_oldcop;
1752 restartjmpenv = cx->blk_eval.cur_top_env;
1753 restartop = cx->blk_eval.retop;
1755 if (gimme == G_SCALAR)
1756 *++newsp = &PL_sv_undef;
1757 PL_stack_sp = newsp;
1761 /* LEAVE could clobber PL_curcop (see save_re_context())
1762 * XXX it might be better to find a way to avoid messing with
1763 * PL_curcop in save_re_context() instead, but this is a more
1764 * minimal fix --GSAR */
1767 if (optype == OP_REQUIRE) {
1768 const char* const msg = SvPVx_nolen_const(exceptsv);
1769 (void)hv_store(GvHVn(PL_incgv),
1770 SvPVX_const(namesv), SvCUR(namesv),
1772 /* note that unlike pp_entereval, pp_require isn't
1773 * supposed to trap errors. So now that we've popped the
1774 * EVAL that pp_require pushed, and processed the error
1775 * message, rethrow the error */
1776 Perl_croak(aTHX_ "%sCompilation failed in require",
1777 *msg ? msg : "Unknown error\n");
1779 if (in_eval & EVAL_KEEPERR) {
1780 Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "\t(in cleanup) %s",
1781 SvPV_nolen_const(exceptsv));
1784 sv_setsv(ERRSV, exceptsv);
1786 PL_restartjmpenv = restartjmpenv;
1787 PL_restartop = restartop;
1793 write_to_stderr(exceptsv);
1800 dVAR; dSP; dPOPTOPssrl;
1801 if (SvTRUE(left) != SvTRUE(right))
1808 =for apidoc caller_cx
1810 The XSUB-writer's equivalent of L<caller()|perlfunc/caller>. The
1811 returned C<PERL_CONTEXT> structure can be interrogated to find all the
1812 information returned to Perl by C<caller>. Note that XSUBs don't get a
1813 stack frame, so C<caller_cx(0, NULL)> will return information for the
1814 immediately-surrounding Perl code.
1816 This function skips over the automatic calls to C<&DB::sub> made on the
1817 behalf of the debugger. If the stack frame requested was a sub called by
1818 C<DB::sub>, the return value will be the frame for the call to
1819 C<DB::sub>, since that has the correct line number/etc. for the call
1820 site. If I<dbcxp> is non-C<NULL>, it will be set to a pointer to the
1821 frame for the sub call itself.
1826 const PERL_CONTEXT *
1827 Perl_caller_cx(pTHX_ I32 count, const PERL_CONTEXT **dbcxp)
1829 register I32 cxix = dopoptosub(cxstack_ix);
1830 register const PERL_CONTEXT *cx;
1831 register const PERL_CONTEXT *ccstack = cxstack;
1832 const PERL_SI *top_si = PL_curstackinfo;
1835 /* we may be in a higher stacklevel, so dig down deeper */
1836 while (cxix < 0 && top_si->si_type != PERLSI_MAIN) {
1837 top_si = top_si->si_prev;
1838 ccstack = top_si->si_cxstack;
1839 cxix = dopoptosub_at(ccstack, top_si->si_cxix);
1843 /* caller() should not report the automatic calls to &DB::sub */
1844 if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 &&
1845 ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub))
1849 cxix = dopoptosub_at(ccstack, cxix - 1);
1852 cx = &ccstack[cxix];
1853 if (dbcxp) *dbcxp = cx;
1855 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1856 const I32 dbcxix = dopoptosub_at(ccstack, cxix - 1);
1857 /* We expect that ccstack[dbcxix] is CXt_SUB, anyway, the
1858 field below is defined for any cx. */
1859 /* caller() should not report the automatic calls to &DB::sub */
1860 if (PL_DBsub && GvCV(PL_DBsub) && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub))
1861 cx = &ccstack[dbcxix];
1871 register const PERL_CONTEXT *cx;
1872 const PERL_CONTEXT *dbcx;
1874 const char *stashname;
1880 cx = caller_cx(count, &dbcx);
1882 if (GIMME != G_ARRAY) {
1889 stashname = CopSTASHPV(cx->blk_oldcop);
1890 if (GIMME != G_ARRAY) {
1893 PUSHs(&PL_sv_undef);
1896 sv_setpv(TARG, stashname);
1905 PUSHs(&PL_sv_undef);
1907 mPUSHs(newSVpv(stashname, 0));
1908 mPUSHs(newSVpv(OutCopFILE(cx->blk_oldcop), 0));
1909 mPUSHi((I32)CopLINE(cx->blk_oldcop));
1912 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1913 GV * const cvgv = CvGV(dbcx->blk_sub.cv);
1914 /* So is ccstack[dbcxix]. */
1916 SV * const sv = newSV(0);
1917 gv_efullname3(sv, cvgv, NULL);
1919 PUSHs(boolSV(CxHASARGS(cx)));
1922 PUSHs(newSVpvs_flags("(unknown)", SVs_TEMP));
1923 PUSHs(boolSV(CxHASARGS(cx)));
1927 PUSHs(newSVpvs_flags("(eval)", SVs_TEMP));
1930 gimme = (I32)cx->blk_gimme;
1931 if (gimme == G_VOID)
1932 PUSHs(&PL_sv_undef);
1934 PUSHs(boolSV((gimme & G_WANT) == G_ARRAY));
1935 if (CxTYPE(cx) == CXt_EVAL) {
1937 if (CxOLD_OP_TYPE(cx) == OP_ENTEREVAL) {
1938 PUSHs(cx->blk_eval.cur_text);
1942 else if (cx->blk_eval.old_namesv) {
1943 mPUSHs(newSVsv(cx->blk_eval.old_namesv));
1946 /* eval BLOCK (try blocks have old_namesv == 0) */
1948 PUSHs(&PL_sv_undef);
1949 PUSHs(&PL_sv_undef);
1953 PUSHs(&PL_sv_undef);
1954 PUSHs(&PL_sv_undef);
1956 if (CxTYPE(cx) == CXt_SUB && CxHASARGS(cx)
1957 && CopSTASH_eq(PL_curcop, PL_debstash))
1959 AV * const ary = cx->blk_sub.argarray;
1960 const int off = AvARRAY(ary) - AvALLOC(ary);
1963 Perl_init_dbargs(aTHX);
1965 if (AvMAX(PL_dbargs) < AvFILLp(ary) + off)
1966 av_extend(PL_dbargs, AvFILLp(ary) + off);
1967 Copy(AvALLOC(ary), AvARRAY(PL_dbargs), AvFILLp(ary) + 1 + off, SV*);
1968 AvFILLp(PL_dbargs) = AvFILLp(ary) + off;
1970 /* XXX only hints propagated via op_private are currently
1971 * visible (others are not easily accessible, since they
1972 * use the global PL_hints) */
1973 mPUSHi(CopHINTS_get(cx->blk_oldcop));
1976 STRLEN * const old_warnings = cx->blk_oldcop->cop_warnings ;
1978 if (old_warnings == pWARN_NONE ||
1979 (old_warnings == pWARN_STD && (PL_dowarn & G_WARN_ON) == 0))
1980 mask = newSVpvn(WARN_NONEstring, WARNsize) ;
1981 else if (old_warnings == pWARN_ALL ||
1982 (old_warnings == pWARN_STD && PL_dowarn & G_WARN_ON)) {
1983 /* Get the bit mask for $warnings::Bits{all}, because
1984 * it could have been extended by warnings::register */
1986 HV * const bits = get_hv("warnings::Bits", 0);
1987 if (bits && (bits_all=hv_fetchs(bits, "all", FALSE))) {
1988 mask = newSVsv(*bits_all);
1991 mask = newSVpvn(WARN_ALLstring, WARNsize) ;
1995 mask = newSVpvn((char *) (old_warnings + 1), old_warnings[0]);
1999 PUSHs(cx->blk_oldcop->cop_hints_hash ?
2000 sv_2mortal(newRV_noinc(MUTABLE_SV(cop_hints_2hv(cx->blk_oldcop, 0))))
2009 const char * const tmps = (MAXARG < 1) ? (const char *)"" : POPpconstx;
2010 sv_reset(tmps, CopSTASH(PL_curcop));
2015 /* like pp_nextstate, but used instead when the debugger is active */
2020 PL_curcop = (COP*)PL_op;
2021 TAINT_NOT; /* Each statement is presumed innocent */
2022 PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
2027 if (PL_op->op_flags & OPf_SPECIAL /* breakpoint */
2028 || SvIV(PL_DBsingle) || SvIV(PL_DBsignal) || SvIV(PL_DBtrace))
2031 register PERL_CONTEXT *cx;
2032 const I32 gimme = G_ARRAY;
2034 GV * const gv = PL_DBgv;
2035 register CV * const cv = GvCV(gv);
2038 DIE(aTHX_ "No DB::DB routine defined");
2040 if (CvDEPTH(cv) >= 1 && !(PL_debug & DEBUG_DB_RECURSE_FLAG))
2041 /* don't do recursive DB::DB call */
2056 (void)(*CvXSUB(cv))(aTHX_ cv);
2063 PUSHBLOCK(cx, CXt_SUB, SP);
2065 cx->blk_sub.retop = PL_op->op_next;
2068 PAD_SET_CUR_NOSAVE(CvPADLIST(cv), 1);
2069 RETURNOP(CvSTART(cv));
2079 register PERL_CONTEXT *cx;
2080 const I32 gimme = GIMME_V;
2081 void *itervar; /* location of the iteration variable */
2082 U8 cxtype = CXt_LOOP_FOR;
2084 ENTER_with_name("loop1");
2087 if (PL_op->op_targ) { /* "my" variable */
2088 if (PL_op->op_private & OPpLVAL_INTRO) { /* for my $x (...) */
2089 SvPADSTALE_off(PAD_SVl(PL_op->op_targ));
2090 SAVESETSVFLAGS(PAD_SVl(PL_op->op_targ),
2091 SVs_PADSTALE, SVs_PADSTALE);
2093 SAVEPADSVANDMORTALIZE(PL_op->op_targ);
2095 itervar = PL_comppad;
2097 itervar = &PAD_SVl(PL_op->op_targ);
2100 else { /* symbol table variable */
2101 GV * const gv = MUTABLE_GV(POPs);
2102 SV** svp = &GvSV(gv);
2103 save_pushptrptr(gv, SvREFCNT_inc(*svp), SAVEt_GVSV);
2105 itervar = (void *)gv;
2108 if (PL_op->op_private & OPpITER_DEF)
2109 cxtype |= CXp_FOR_DEF;
2111 ENTER_with_name("loop2");
2113 PUSHBLOCK(cx, cxtype, SP);
2114 PUSHLOOP_FOR(cx, itervar, MARK);
2115 if (PL_op->op_flags & OPf_STACKED) {
2116 SV *maybe_ary = POPs;
2117 if (SvTYPE(maybe_ary) != SVt_PVAV) {
2119 SV * const right = maybe_ary;
2122 if (RANGE_IS_NUMERIC(sv,right)) {
2123 cx->cx_type &= ~CXTYPEMASK;
2124 cx->cx_type |= CXt_LOOP_LAZYIV;
2125 /* Make sure that no-one re-orders cop.h and breaks our
2127 assert(CxTYPE(cx) == CXt_LOOP_LAZYIV);
2128 #ifdef NV_PRESERVES_UV
2129 if ((SvOK(sv) && ((SvNV(sv) < (NV)IV_MIN) ||
2130 (SvNV(sv) > (NV)IV_MAX)))
2132 (SvOK(right) && ((SvNV(right) > (NV)IV_MAX) ||
2133 (SvNV(right) < (NV)IV_MIN))))
2135 if ((SvOK(sv) && ((SvNV(sv) <= (NV)IV_MIN)
2138 ((SvUV(sv) > (UV)IV_MAX) ||
2139 (SvNV(sv) > (NV)UV_MAX)))))
2141 (SvOK(right) && ((SvNV(right) <= (NV)IV_MIN)
2143 ((SvNV(right) > 0) &&
2144 ((SvUV(right) > (UV)IV_MAX) ||
2145 (SvNV(right) > (NV)UV_MAX))))))
2147 DIE(aTHX_ "Range iterator outside integer range");
2148 cx->blk_loop.state_u.lazyiv.cur = SvIV(sv);
2149 cx->blk_loop.state_u.lazyiv.end = SvIV(right);
2151 /* for correct -Dstv display */
2152 cx->blk_oldsp = sp - PL_stack_base;
2156 cx->cx_type &= ~CXTYPEMASK;
2157 cx->cx_type |= CXt_LOOP_LAZYSV;
2158 /* Make sure that no-one re-orders cop.h and breaks our
2160 assert(CxTYPE(cx) == CXt_LOOP_LAZYSV);
2161 cx->blk_loop.state_u.lazysv.cur = newSVsv(sv);
2162 cx->blk_loop.state_u.lazysv.end = right;
2163 SvREFCNT_inc(right);
2164 (void) SvPV_force_nolen(cx->blk_loop.state_u.lazysv.cur);
2165 /* This will do the upgrade to SVt_PV, and warn if the value
2166 is uninitialised. */
2167 (void) SvPV_nolen_const(right);
2168 /* Doing this avoids a check every time in pp_iter in pp_hot.c
2169 to replace !SvOK() with a pointer to "". */
2171 SvREFCNT_dec(right);
2172 cx->blk_loop.state_u.lazysv.end = &PL_sv_no;
2176 else /* SvTYPE(maybe_ary) == SVt_PVAV */ {
2177 cx->blk_loop.state_u.ary.ary = MUTABLE_AV(maybe_ary);
2178 SvREFCNT_inc(maybe_ary);
2179 cx->blk_loop.state_u.ary.ix =
2180 (PL_op->op_private & OPpITER_REVERSED) ?
2181 AvFILL(cx->blk_loop.state_u.ary.ary) + 1 :
2185 else { /* iterating over items on the stack */
2186 cx->blk_loop.state_u.ary.ary = NULL; /* means to use the stack */
2187 if (PL_op->op_private & OPpITER_REVERSED) {
2188 cx->blk_loop.state_u.ary.ix = cx->blk_oldsp + 1;
2191 cx->blk_loop.state_u.ary.ix = MARK - PL_stack_base;
2201 register PERL_CONTEXT *cx;
2202 const I32 gimme = GIMME_V;
2204 ENTER_with_name("loop1");
2206 ENTER_with_name("loop2");
2208 PUSHBLOCK(cx, CXt_LOOP_PLAIN, SP);
2209 PUSHLOOP_PLAIN(cx, SP);
2217 register PERL_CONTEXT *cx;
2224 assert(CxTYPE_is_LOOP(cx));
2226 newsp = PL_stack_base + cx->blk_loop.resetsp;
2229 if (gimme == G_VOID)
2231 else if (gimme == G_SCALAR) {
2233 *++newsp = sv_mortalcopy(*SP);
2235 *++newsp = &PL_sv_undef;
2239 *++newsp = sv_mortalcopy(*++mark);
2240 TAINT_NOT; /* Each item is independent */
2246 POPLOOP(cx); /* Stack values are safe: release loop vars ... */
2247 PL_curpm = newpm; /* ... and pop $1 et al */
2249 LEAVE_with_name("loop2");
2250 LEAVE_with_name("loop1");
2258 register PERL_CONTEXT *cx;
2259 bool popsub2 = FALSE;
2260 bool clear_errsv = FALSE;
2269 const I32 cxix = dopoptosub(cxstack_ix);
2272 if (CxMULTICALL(cxstack)) { /* In this case we must be in a
2273 * sort block, which is a CXt_NULL
2276 PL_stack_base[1] = *PL_stack_sp;
2277 PL_stack_sp = PL_stack_base + 1;
2281 DIE(aTHX_ "Can't return outside a subroutine");
2283 if (cxix < cxstack_ix)
2286 if (CxMULTICALL(&cxstack[cxix])) {
2287 gimme = cxstack[cxix].blk_gimme;
2288 if (gimme == G_VOID)
2289 PL_stack_sp = PL_stack_base;
2290 else if (gimme == G_SCALAR) {
2291 PL_stack_base[1] = *PL_stack_sp;
2292 PL_stack_sp = PL_stack_base + 1;
2298 switch (CxTYPE(cx)) {
2301 retop = cx->blk_sub.retop;
2302 cxstack_ix++; /* preserve cx entry on stack for use by POPSUB */
2305 if (!(PL_in_eval & EVAL_KEEPERR))
2308 namesv = cx->blk_eval.old_namesv;
2309 retop = cx->blk_eval.retop;
2312 if (optype == OP_REQUIRE &&
2313 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
2315 /* Unassume the success we assumed earlier. */
2316 (void)hv_delete(GvHVn(PL_incgv),
2317 SvPVX_const(namesv), SvCUR(namesv),
2319 DIE(aTHX_ "%"SVf" did not return a true value", SVfARG(namesv));
2324 retop = cx->blk_sub.retop;
2327 DIE(aTHX_ "panic: return");
2331 if (gimme == G_SCALAR) {
2334 if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
2336 *++newsp = SvREFCNT_inc(*SP);
2341 sv = SvREFCNT_inc(*SP); /* FREETMPS could clobber it */
2343 *++newsp = sv_mortalcopy(sv);
2348 *++newsp = (SvTEMP(*SP)) ? *SP : sv_mortalcopy(*SP);
2351 *++newsp = sv_mortalcopy(*SP);
2354 *++newsp = &PL_sv_undef;
2356 else if (gimme == G_ARRAY) {
2357 while (++MARK <= SP) {
2358 *++newsp = (popsub2 && SvTEMP(*MARK))
2359 ? *MARK : sv_mortalcopy(*MARK);
2360 TAINT_NOT; /* Each item is independent */
2363 PL_stack_sp = newsp;
2366 /* Stack values are safe: */
2369 POPSUB(cx,sv); /* release CV and @_ ... */
2373 PL_curpm = newpm; /* ... and pop $1 et al */
2386 register PERL_CONTEXT *cx;
2397 if (PL_op->op_flags & OPf_SPECIAL) {
2398 cxix = dopoptoloop(cxstack_ix);
2400 DIE(aTHX_ "Can't \"last\" outside a loop block");
2403 cxix = dopoptolabel(cPVOP->op_pv);
2405 DIE(aTHX_ "Label not found for \"last %s\"", cPVOP->op_pv);
2407 if (cxix < cxstack_ix)
2411 cxstack_ix++; /* temporarily protect top context */
2413 switch (CxTYPE(cx)) {
2414 case CXt_LOOP_LAZYIV:
2415 case CXt_LOOP_LAZYSV:
2417 case CXt_LOOP_PLAIN:
2419 newsp = PL_stack_base + cx->blk_loop.resetsp;
2420 nextop = cx->blk_loop.my_op->op_lastop->op_next;
2424 nextop = cx->blk_sub.retop;
2428 nextop = cx->blk_eval.retop;
2432 nextop = cx->blk_sub.retop;
2435 DIE(aTHX_ "panic: last");
2439 if (gimme == G_SCALAR) {
2441 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
2442 ? *SP : sv_mortalcopy(*SP);
2444 *++newsp = &PL_sv_undef;
2446 else if (gimme == G_ARRAY) {
2447 while (++MARK <= SP) {
2448 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
2449 ? *MARK : sv_mortalcopy(*MARK);
2450 TAINT_NOT; /* Each item is independent */
2458 /* Stack values are safe: */
2460 case CXt_LOOP_LAZYIV:
2461 case CXt_LOOP_PLAIN:
2462 case CXt_LOOP_LAZYSV:
2464 POPLOOP(cx); /* release loop vars ... */
2468 POPSUB(cx,sv); /* release CV and @_ ... */
2471 PL_curpm = newpm; /* ... and pop $1 et al */
2474 PERL_UNUSED_VAR(optype);
2475 PERL_UNUSED_VAR(gimme);
2483 register PERL_CONTEXT *cx;
2486 if (PL_op->op_flags & OPf_SPECIAL) {
2487 cxix = dopoptoloop(cxstack_ix);
2489 DIE(aTHX_ "Can't \"next\" outside a loop block");
2492 cxix = dopoptolabel(cPVOP->op_pv);
2494 DIE(aTHX_ "Label not found for \"next %s\"", cPVOP->op_pv);
2496 if (cxix < cxstack_ix)
2499 /* clear off anything above the scope we're re-entering, but
2500 * save the rest until after a possible continue block */
2501 inner = PL_scopestack_ix;
2503 if (PL_scopestack_ix < inner)
2504 leave_scope(PL_scopestack[PL_scopestack_ix]);
2505 PL_curcop = cx->blk_oldcop;
2506 return (cx)->blk_loop.my_op->op_nextop;
2513 register PERL_CONTEXT *cx;
2517 if (PL_op->op_flags & OPf_SPECIAL) {
2518 cxix = dopoptoloop(cxstack_ix);
2520 DIE(aTHX_ "Can't \"redo\" outside a loop block");
2523 cxix = dopoptolabel(cPVOP->op_pv);
2525 DIE(aTHX_ "Label not found for \"redo %s\"", cPVOP->op_pv);
2527 if (cxix < cxstack_ix)
2530 redo_op = cxstack[cxix].blk_loop.my_op->op_redoop;
2531 if (redo_op->op_type == OP_ENTER) {
2532 /* pop one less context to avoid $x being freed in while (my $x..) */
2534 assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_BLOCK);
2535 redo_op = redo_op->op_next;
2539 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2540 LEAVE_SCOPE(oldsave);
2542 PL_curcop = cx->blk_oldcop;
2547 S_dofindlabel(pTHX_ OP *o, const char *label, OP **opstack, OP **oplimit)
2551 static const char too_deep[] = "Target of goto is too deeply nested";
2553 PERL_ARGS_ASSERT_DOFINDLABEL;
2556 Perl_croak(aTHX_ too_deep);
2557 if (o->op_type == OP_LEAVE ||
2558 o->op_type == OP_SCOPE ||
2559 o->op_type == OP_LEAVELOOP ||
2560 o->op_type == OP_LEAVESUB ||
2561 o->op_type == OP_LEAVETRY)
2563 *ops++ = cUNOPo->op_first;
2565 Perl_croak(aTHX_ too_deep);
2568 if (o->op_flags & OPf_KIDS) {
2570 /* First try all the kids at this level, since that's likeliest. */
2571 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
2572 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
2573 const char *kid_label = CopLABEL(kCOP);
2574 if (kid_label && strEQ(kid_label, label))
2578 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
2579 if (kid == PL_lastgotoprobe)
2581 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
2584 else if (ops[-1]->op_type == OP_NEXTSTATE ||
2585 ops[-1]->op_type == OP_DBSTATE)
2590 if ((o = dofindlabel(kid, label, ops, oplimit)))
2603 register PERL_CONTEXT *cx;
2604 #define GOTO_DEPTH 64
2605 OP *enterops[GOTO_DEPTH];
2606 const char *label = NULL;
2607 const bool do_dump = (PL_op->op_type == OP_DUMP);
2608 static const char must_have_label[] = "goto must have label";
2610 if (PL_op->op_flags & OPf_STACKED) {
2611 SV * const sv = POPs;
2613 /* This egregious kludge implements goto &subroutine */
2614 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
2616 register PERL_CONTEXT *cx;
2617 CV *cv = MUTABLE_CV(SvRV(sv));
2624 if (!CvROOT(cv) && !CvXSUB(cv)) {
2625 const GV * const gv = CvGV(cv);
2629 /* autoloaded stub? */
2630 if (cv != GvCV(gv) && (cv = GvCV(gv)))
2632 autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv),
2633 GvNAMELEN(gv), FALSE);
2634 if (autogv && (cv = GvCV(autogv)))
2636 tmpstr = sv_newmortal();
2637 gv_efullname3(tmpstr, gv, NULL);
2638 DIE(aTHX_ "Goto undefined subroutine &%"SVf"", SVfARG(tmpstr));
2640 DIE(aTHX_ "Goto undefined subroutine");
2643 /* First do some returnish stuff. */
2644 SvREFCNT_inc_simple_void(cv); /* avoid premature free during unwind */
2646 cxix = dopoptosub(cxstack_ix);
2648 DIE(aTHX_ "Can't goto subroutine outside a subroutine");
2649 if (cxix < cxstack_ix)
2653 /* ban goto in eval: see <20050521150056.GC20213@iabyn.com> */
2654 if (CxTYPE(cx) == CXt_EVAL) {
2656 DIE(aTHX_ "Can't goto subroutine from an eval-string");
2658 DIE(aTHX_ "Can't goto subroutine from an eval-block");
2660 else if (CxMULTICALL(cx))
2661 DIE(aTHX_ "Can't goto subroutine from a sort sub (or similar callback)");
2662 if (CxTYPE(cx) == CXt_SUB && CxHASARGS(cx)) {
2663 /* put @_ back onto stack */
2664 AV* av = cx->blk_sub.argarray;
2666 items = AvFILLp(av) + 1;
2667 EXTEND(SP, items+1); /* @_ could have been extended. */
2668 Copy(AvARRAY(av), SP + 1, items, SV*);
2669 SvREFCNT_dec(GvAV(PL_defgv));
2670 GvAV(PL_defgv) = cx->blk_sub.savearray;
2672 /* abandon @_ if it got reified */
2677 av_extend(av, items-1);
2679 PAD_SVl(0) = MUTABLE_SV(cx->blk_sub.argarray = av);
2682 else if (CvISXSUB(cv)) { /* put GvAV(defgv) back onto stack */
2683 AV* const av = GvAV(PL_defgv);
2684 items = AvFILLp(av) + 1;
2685 EXTEND(SP, items+1); /* @_ could have been extended. */
2686 Copy(AvARRAY(av), SP + 1, items, SV*);
2690 if (CxTYPE(cx) == CXt_SUB &&
2691 !(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
2692 SvREFCNT_dec(cx->blk_sub.cv);
2693 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2694 LEAVE_SCOPE(oldsave);
2696 /* Now do some callish stuff. */
2698 SAVEFREESV(cv); /* later, undo the 'avoid premature free' hack */
2700 OP* const retop = cx->blk_sub.retop;
2705 for (index=0; index<items; index++)
2706 sv_2mortal(SP[-index]);
2709 /* XS subs don't have a CxSUB, so pop it */
2710 POPBLOCK(cx, PL_curpm);
2711 /* Push a mark for the start of arglist */
2714 (void)(*CvXSUB(cv))(aTHX_ cv);
2719 AV* const padlist = CvPADLIST(cv);
2720 if (CxTYPE(cx) == CXt_EVAL) {
2721 PL_in_eval = CxOLD_IN_EVAL(cx);
2722 PL_eval_root = cx->blk_eval.old_eval_root;
2723 cx->cx_type = CXt_SUB;
2725 cx->blk_sub.cv = cv;
2726 cx->blk_sub.olddepth = CvDEPTH(cv);
2729 if (CvDEPTH(cv) < 2)
2730 SvREFCNT_inc_simple_void_NN(cv);
2732 if (CvDEPTH(cv) == PERL_SUB_DEPTH_WARN && ckWARN(WARN_RECURSION))
2733 sub_crush_depth(cv);
2734 pad_push(padlist, CvDEPTH(cv));
2737 PAD_SET_CUR_NOSAVE(padlist, CvDEPTH(cv));
2740 AV *const av = MUTABLE_AV(PAD_SVl(0));
2742 cx->blk_sub.savearray = GvAV(PL_defgv);
2743 GvAV(PL_defgv) = MUTABLE_AV(SvREFCNT_inc_simple(av));
2744 CX_CURPAD_SAVE(cx->blk_sub);
2745 cx->blk_sub.argarray = av;
2747 if (items >= AvMAX(av) + 1) {
2748 SV **ary = AvALLOC(av);
2749 if (AvARRAY(av) != ary) {
2750 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
2753 if (items >= AvMAX(av) + 1) {
2754 AvMAX(av) = items - 1;
2755 Renew(ary,items+1,SV*);
2761 Copy(mark,AvARRAY(av),items,SV*);
2762 AvFILLp(av) = items - 1;
2763 assert(!AvREAL(av));
2765 /* transfer 'ownership' of refcnts to new @_ */
2775 if (PERLDB_SUB) { /* Checking curstash breaks DProf. */
2776 Perl_get_db_sub(aTHX_ NULL, cv);
2778 CV * const gotocv = get_cvs("DB::goto", 0);
2780 PUSHMARK( PL_stack_sp );
2781 call_sv(MUTABLE_SV(gotocv), G_SCALAR | G_NODEBUG);
2786 RETURNOP(CvSTART(cv));
2790 label = SvPV_nolen_const(sv);
2791 if (!(do_dump || *label))
2792 DIE(aTHX_ must_have_label);
2795 else if (PL_op->op_flags & OPf_SPECIAL) {
2797 DIE(aTHX_ must_have_label);
2800 label = cPVOP->op_pv;
2804 if (label && *label) {
2805 OP *gotoprobe = NULL;
2806 bool leaving_eval = FALSE;
2807 bool in_block = FALSE;
2808 PERL_CONTEXT *last_eval_cx = NULL;
2812 PL_lastgotoprobe = NULL;
2814 for (ix = cxstack_ix; ix >= 0; ix--) {
2816 switch (CxTYPE(cx)) {
2818 leaving_eval = TRUE;
2819 if (!CxTRYBLOCK(cx)) {
2820 gotoprobe = (last_eval_cx ?
2821 last_eval_cx->blk_eval.old_eval_root :
2826 /* else fall through */
2827 case CXt_LOOP_LAZYIV:
2828 case CXt_LOOP_LAZYSV:
2830 case CXt_LOOP_PLAIN:
2833 gotoprobe = cx->blk_oldcop->op_sibling;
2839 gotoprobe = cx->blk_oldcop->op_sibling;
2842 gotoprobe = PL_main_root;
2845 if (CvDEPTH(cx->blk_sub.cv) && !CxMULTICALL(cx)) {
2846 gotoprobe = CvROOT(cx->blk_sub.cv);
2852 DIE(aTHX_ "Can't \"goto\" out of a pseudo block");
2855 DIE(aTHX_ "panic: goto");
2856 gotoprobe = PL_main_root;
2860 retop = dofindlabel(gotoprobe, label,
2861 enterops, enterops + GOTO_DEPTH);
2864 if (gotoprobe->op_sibling &&
2865 gotoprobe->op_sibling->op_type == OP_UNSTACK &&
2866 gotoprobe->op_sibling->op_sibling) {
2867 retop = dofindlabel(gotoprobe->op_sibling->op_sibling,
2868 label, enterops, enterops + GOTO_DEPTH);
2873 PL_lastgotoprobe = gotoprobe;
2876 DIE(aTHX_ "Can't find label %s", label);
2878 /* if we're leaving an eval, check before we pop any frames
2879 that we're not going to punt, otherwise the error
2882 if (leaving_eval && *enterops && enterops[1]) {
2884 for (i = 1; enterops[i]; i++)
2885 if (enterops[i]->op_type == OP_ENTERITER)
2886 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2889 if (*enterops && enterops[1]) {
2890 I32 i = enterops[1]->op_type == OP_ENTER && in_block ? 2 : 1;
2892 deprecate("\"goto\" to jump into a construct");
2895 /* pop unwanted frames */
2897 if (ix < cxstack_ix) {
2904 oldsave = PL_scopestack[PL_scopestack_ix];
2905 LEAVE_SCOPE(oldsave);
2908 /* push wanted frames */
2910 if (*enterops && enterops[1]) {
2911 OP * const oldop = PL_op;
2912 ix = enterops[1]->op_type == OP_ENTER && in_block ? 2 : 1;
2913 for (; enterops[ix]; ix++) {
2914 PL_op = enterops[ix];
2915 /* Eventually we may want to stack the needed arguments
2916 * for each op. For now, we punt on the hard ones. */
2917 if (PL_op->op_type == OP_ENTERITER)
2918 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2919 PL_op->op_ppaddr(aTHX);
2927 if (!retop) retop = PL_main_start;
2929 PL_restartop = retop;
2930 PL_do_undump = TRUE;
2934 PL_restartop = 0; /* hmm, must be GNU unexec().. */
2935 PL_do_undump = FALSE;
2952 if (anum == 1 && (PL_op->op_private & OPpEXIT_VMSISH))
2954 VMSISH_HUSHED = VMSISH_HUSHED || (PL_op->op_private & OPpHUSH_VMSISH);
2957 PL_exit_flags |= PERL_EXIT_EXPECTED;
2959 /* KLUDGE: disable exit 0 in BEGIN blocks when we're just compiling */
2960 if (anum || !(PL_minus_c && PL_madskills))
2965 PUSHs(&PL_sv_undef);
2972 S_save_lines(pTHX_ AV *array, SV *sv)
2974 const char *s = SvPVX_const(sv);
2975 const char * const send = SvPVX_const(sv) + SvCUR(sv);
2978 PERL_ARGS_ASSERT_SAVE_LINES;
2980 while (s && s < send) {
2982 SV * const tmpstr = newSV_type(SVt_PVMG);
2984 t = (const char *)memchr(s, '\n', send - s);
2990 sv_setpvn(tmpstr, s, t - s);
2991 av_store(array, line++, tmpstr);
2999 Check for the cases 0 or 3 of cur_env.je_ret, only used inside an eval context.
3001 0 is used as continue inside eval,
3003 3 is used for a die caught by an inner eval - continue inner loop
3005 See cop.h: je_mustcatch, when set at any runlevel to TRUE, means eval ops must
3006 establish a local jmpenv to handle exception traps.
3011 S_docatch(pTHX_ OP *o)
3015 OP * const oldop = PL_op;
3019 assert(CATCH_GET == TRUE);
3026 assert(cxstack_ix >= 0);
3027 assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
3028 cxstack[cxstack_ix].blk_eval.cur_top_env = PL_top_env;
3033 /* die caught by an inner eval - continue inner loop */
3034 if (PL_restartop && PL_restartjmpenv == PL_top_env) {
3035 PL_restartjmpenv = NULL;
3036 PL_op = PL_restartop;
3052 /* James Bond: Do you expect me to talk?
3053 Auric Goldfinger: No, Mr. Bond. I expect you to die.
3055 This code is an ugly hack, doesn't work with lexicals in subroutines that are
3056 called more than once, and is only used by regcomp.c, for (?{}) blocks.
3058 Currently it is not used outside the core code. Best if it stays that way.
3060 Hence it's now deprecated, and will be removed.
3063 Perl_sv_compile_2op(pTHX_ SV *sv, OP** startop, const char *code, PAD** padp)
3064 /* sv Text to convert to OP tree. */
3065 /* startop op_free() this to undo. */
3066 /* code Short string id of the caller. */
3068 PERL_ARGS_ASSERT_SV_COMPILE_2OP;
3069 return Perl_sv_compile_2op_is_broken(aTHX_ sv, startop, code, padp);
3072 /* Don't use this. It will go away without warning once the regexp engine is
3073 refactored not to use it. */
3075 Perl_sv_compile_2op_is_broken(pTHX_ SV *sv, OP **startop, const char *code,
3078 dVAR; dSP; /* Make POPBLOCK work. */
3084 char tbuf[TYPE_DIGITS(long) + 12 + 10];
3085 char *tmpbuf = tbuf;
3088 CV* runcv = NULL; /* initialise to avoid compiler warnings */
3092 PERL_ARGS_ASSERT_SV_COMPILE_2OP_IS_BROKEN;
3094 ENTER_with_name("eval");
3095 lex_start(sv, NULL, LEX_START_SAME_FILTER);
3097 /* switch to eval mode */
3099 if (IN_PERL_COMPILETIME) {
3100 SAVECOPSTASH_FREE(&PL_compiling);
3101 CopSTASH_set(&PL_compiling, PL_curstash);
3103 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
3104 SV * const sv = sv_newmortal();
3105 Perl_sv_setpvf(aTHX_ sv, "_<(%.10seval %lu)[%s:%"IVdf"]",
3106 code, (unsigned long)++PL_evalseq,
3107 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
3112 len = my_snprintf(tmpbuf, sizeof(tbuf), "_<(%.10s_eval %lu)", code,
3113 (unsigned long)++PL_evalseq);
3114 SAVECOPFILE_FREE(&PL_compiling);
3115 CopFILE_set(&PL_compiling, tmpbuf+2);
3116 SAVECOPLINE(&PL_compiling);
3117 CopLINE_set(&PL_compiling, 1);
3118 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
3119 deleting the eval's FILEGV from the stash before gv_check() runs
3120 (i.e. before run-time proper). To work around the coredump that
3121 ensues, we always turn GvMULTI_on for any globals that were
3122 introduced within evals. See force_ident(). GSAR 96-10-12 */
3123 safestr = savepvn(tmpbuf, len);
3124 SAVEDELETE(PL_defstash, safestr, len);
3126 #ifdef OP_IN_REGISTER
3132 /* we get here either during compilation, or via pp_regcomp at runtime */
3133 runtime = IN_PERL_RUNTIME;
3136 runcv = find_runcv(NULL);
3138 /* At run time, we have to fetch the hints from PL_curcop. */
3139 PL_hints = PL_curcop->cop_hints;
3140 if (PL_hints & HINT_LOCALIZE_HH) {
3141 /* SAVEHINTS created a new HV in PL_hintgv, which we
3143 SvREFCNT_dec(GvHV(PL_hintgv));
3145 refcounted_he_chain_2hv(PL_curcop->cop_hints_hash, 0);
3146 hv_magic(GvHV(PL_hintgv), NULL, PERL_MAGIC_hints);
3148 SAVECOMPILEWARNINGS();
3149 PL_compiling.cop_warnings = DUP_WARNINGS(PL_curcop->cop_warnings);
3150 cophh_free(CopHINTHASH_get(&PL_compiling));
3151 /* XXX Does this need to avoid copying a label? */
3152 PL_compiling.cop_hints_hash
3153 = cophh_copy(PL_curcop->cop_hints_hash);
3157 PL_op->op_type = OP_ENTEREVAL;
3158 PL_op->op_flags = 0; /* Avoid uninit warning. */
3159 PUSHBLOCK(cx, CXt_EVAL|(IN_PERL_COMPILETIME ? 0 : CXp_REAL), SP);
3161 need_catch = CATCH_GET;
3165 (void) doeval(G_SCALAR, startop, runcv, PL_curcop->cop_seq);
3167 (void) doeval(G_SCALAR, startop, PL_compcv, PL_cop_seqmax);
3168 CATCH_SET(need_catch);
3169 POPBLOCK(cx,PL_curpm);
3172 (*startop)->op_type = OP_NULL;
3173 (*startop)->op_ppaddr = PL_ppaddr[OP_NULL];
3174 /* XXX DAPM do this properly one year */
3175 *padp = MUTABLE_AV(SvREFCNT_inc_simple(PL_comppad));
3176 LEAVE_with_name("eval");
3177 if (IN_PERL_COMPILETIME)
3178 CopHINTS_set(&PL_compiling, PL_hints);
3179 #ifdef OP_IN_REGISTER
3182 PERL_UNUSED_VAR(newsp);
3183 PERL_UNUSED_VAR(optype);
3185 return PL_eval_start;
3190 =for apidoc find_runcv
3192 Locate the CV corresponding to the currently executing sub or eval.
3193 If db_seqp is non_null, skip CVs that are in the DB package and populate
3194 *db_seqp with the cop sequence number at the point that the DB:: code was
3195 entered. (allows debuggers to eval in the scope of the breakpoint rather
3196 than in the scope of the debugger itself).
3202 Perl_find_runcv(pTHX_ U32 *db_seqp)
3208 *db_seqp = PL_curcop->cop_seq;
3209 for (si = PL_curstackinfo; si; si = si->si_prev) {
3211 for (ix = si->si_cxix; ix >= 0; ix--) {
3212 const PERL_CONTEXT *cx = &(si->si_cxstack[ix]);
3213 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
3214 CV * const cv = cx->blk_sub.cv;
3215 /* skip DB:: code */
3216 if (db_seqp && PL_debstash && CvSTASH(cv) == PL_debstash) {
3217 *db_seqp = cx->blk_oldcop->cop_seq;
3222 else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx))
3230 /* Run yyparse() in a setjmp wrapper. Returns:
3231 * 0: yyparse() successful
3232 * 1: yyparse() failed
3236 S_try_yyparse(pTHX_ int gramtype)
3241 assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
3245 ret = yyparse(gramtype) ? 1 : 0;
3259 /* Compile a require/do, an eval '', or a /(?{...})/.
3260 * In the last case, startop is non-null, and contains the address of
3261 * a pointer that should be set to the just-compiled code.
3262 * outside is the lexically enclosing CV (if any) that invoked us.
3263 * Returns a bool indicating whether the compile was successful; if so,
3264 * PL_eval_start contains the first op of the compiled ocde; otherwise,
3265 * pushes undef (also croaks if startop != NULL).
3269 S_doeval(pTHX_ int gimme, OP** startop, CV* outside, U32 seq)
3272 OP * const saveop = PL_op;
3273 bool in_require = (saveop && saveop->op_type == OP_REQUIRE);
3276 PL_in_eval = (in_require
3277 ? (EVAL_INREQUIRE | (PL_in_eval & EVAL_INEVAL))
3282 SAVESPTR(PL_compcv);
3283 PL_compcv = MUTABLE_CV(newSV_type(SVt_PVCV));
3284 CvEVAL_on(PL_compcv);
3285 assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
3286 cxstack[cxstack_ix].blk_eval.cv = PL_compcv;
3288 CvOUTSIDE_SEQ(PL_compcv) = seq;
3289 CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outside));
3291 /* set up a scratch pad */
3293 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE);
3294 PL_op = NULL; /* avoid PL_op and PL_curpad referring to different CVs */
3298 SAVEMORTALIZESV(PL_compcv); /* must remain until end of current statement */
3300 /* make sure we compile in the right package */
3302 if (CopSTASH_ne(PL_curcop, PL_curstash)) {
3303 SAVESPTR(PL_curstash);
3304 PL_curstash = CopSTASH(PL_curcop);
3306 /* XXX:ajgo do we really need to alloc an AV for begin/checkunit */
3307 SAVESPTR(PL_beginav);
3308 PL_beginav = newAV();
3309 SAVEFREESV(PL_beginav);
3310 SAVESPTR(PL_unitcheckav);
3311 PL_unitcheckav = newAV();
3312 SAVEFREESV(PL_unitcheckav);
3315 SAVEBOOL(PL_madskills);
3319 /* try to compile it */
3321 PL_eval_root = NULL;
3322 PL_curcop = &PL_compiling;
3323 CopARYBASE_set(PL_curcop, 0);
3324 if (saveop && (saveop->op_type != OP_REQUIRE) && (saveop->op_flags & OPf_SPECIAL))
3325 PL_in_eval |= EVAL_KEEPERR;
3329 CALL_BLOCK_HOOKS(bhk_eval, saveop);
3331 /* note that yyparse() may raise an exception, e.g. C<BEGIN{die}>,
3332 * so honour CATCH_GET and trap it here if necessary */
3334 yystatus = (!in_require && CATCH_GET) ? S_try_yyparse(aTHX_ GRAMPROG) : yyparse(GRAMPROG);
3336 if (yystatus || PL_parser->error_count || !PL_eval_root) {
3337 SV **newsp; /* Used by POPBLOCK. */
3338 PERL_CONTEXT *cx = NULL;
3339 I32 optype; /* Used by POPEVAL. */
3343 PERL_UNUSED_VAR(newsp);
3344 PERL_UNUSED_VAR(optype);
3346 /* note that if yystatus == 3, then the EVAL CX block has already
3347 * been popped, and various vars restored */
3349 if (yystatus != 3) {
3351 op_free(PL_eval_root);
3352 PL_eval_root = NULL;
3354 SP = PL_stack_base + POPMARK; /* pop original mark */
3356 POPBLOCK(cx,PL_curpm);
3358 namesv = cx->blk_eval.old_namesv;
3362 LEAVE_with_name("eval"); /* pp_entereval knows about this LEAVE. */
3364 msg = SvPVx_nolen_const(ERRSV);
3367 /* If cx is still NULL, it means that we didn't go in the
3368 * POPEVAL branch. */
3369 cx = &cxstack[cxstack_ix];
3370 assert(CxTYPE(cx) == CXt_EVAL);
3371 namesv = cx->blk_eval.old_namesv;
3373 (void)hv_store(GvHVn(PL_incgv),
3374 SvPVX_const(namesv), SvCUR(namesv),
3376 Perl_croak(aTHX_ "%sCompilation failed in require",
3377 *msg ? msg : "Unknown error\n");
3380 if (yystatus != 3) {
3381 POPBLOCK(cx,PL_curpm);
3384 Perl_croak(aTHX_ "%sCompilation failed in regexp",
3385 (*msg ? msg : "Unknown error\n"));
3389 sv_setpvs(ERRSV, "Compilation error");
3392 PUSHs(&PL_sv_undef);
3396 CopLINE_set(&PL_compiling, 0);
3398 *startop = PL_eval_root;
3400 SAVEFREEOP(PL_eval_root);
3402 /* Set the context for this new optree.
3403 * Propagate the context from the eval(). */
3404 if ((gimme & G_WANT) == G_VOID)
3405 scalarvoid(PL_eval_root);
3406 else if ((gimme & G_WANT) == G_ARRAY)
3409 scalar(PL_eval_root);
3411 DEBUG_x(dump_eval());
3413 /* Register with debugger: */
3414 if (PERLDB_INTER && saveop && saveop->op_type == OP_REQUIRE) {
3415 CV * const cv = get_cvs("DB::postponed", 0);
3419 XPUSHs(MUTABLE_SV(CopFILEGV(&PL_compiling)));
3421 call_sv(MUTABLE_SV(cv), G_DISCARD);
3425 if (PL_unitcheckav) {
3426 OP *es = PL_eval_start;
3427 call_list(PL_scopestack_ix, PL_unitcheckav);
3431 /* compiled okay, so do it */
3433 CvDEPTH(PL_compcv) = 1;
3434 SP = PL_stack_base + POPMARK; /* pop original mark */
3435 PL_op = saveop; /* The caller may need it. */
3436 PL_parser->lex_state = LEX_NOTPARSING; /* $^S needs this. */
3443 S_check_type_and_open(pTHX_ SV *name)
3446 const char *p = SvPV_nolen_const(name);
3447 const int st_rc = PerlLIO_stat(p, &st);
3449 PERL_ARGS_ASSERT_CHECK_TYPE_AND_OPEN;
3451 if (st_rc < 0 || S_ISDIR(st.st_mode) || S_ISBLK(st.st_mode)) {
3455 #if !defined(PERLIO_IS_STDIO) && !defined(USE_SFIO)
3456 return PerlIO_openn(aTHX_ NULL, PERL_SCRIPT_MODE, -1, 0, 0, NULL, 1, &name);
3458 return PerlIO_open(p, PERL_SCRIPT_MODE);
3462 #ifndef PERL_DISABLE_PMC
3464 S_doopen_pm(pTHX_ SV *name)
3467 const char *p = SvPV_const(name, namelen);
3469 PERL_ARGS_ASSERT_DOOPEN_PM;
3471 if (namelen > 3 && memEQs(p + namelen - 3, 3, ".pm")) {
3472 SV *const pmcsv = sv_newmortal();
3475 SvSetSV_nosteal(pmcsv,name);
3476 sv_catpvn(pmcsv, "c", 1);
3478 if (PerlLIO_stat(SvPV_nolen_const(pmcsv), &pmcstat) >= 0)
3479 return check_type_and_open(pmcsv);
3481 return check_type_and_open(name);
3484 # define doopen_pm(name) check_type_and_open(name)
3485 #endif /* !PERL_DISABLE_PMC */
3490 register PERL_CONTEXT *cx;
3497 int vms_unixname = 0;
3499 const char *tryname = NULL;
3501 const I32 gimme = GIMME_V;
3502 int filter_has_file = 0;
3503 PerlIO *tryrsfp = NULL;
3504 SV *filter_cache = NULL;
3505 SV *filter_state = NULL;
3506 SV *filter_sub = NULL;
3512 if ( (SvNIOKp(sv) || SvVOK(sv)) && PL_op->op_type != OP_DOFILE) {
3513 sv = sv_2mortal(new_version(sv));
3514 if (!sv_derived_from(PL_patchlevel, "version"))
3515 upg_version(PL_patchlevel, TRUE);
3516 if (cUNOP->op_first->op_type == OP_CONST && cUNOP->op_first->op_private & OPpCONST_NOVER) {
3517 if ( vcmp(sv,PL_patchlevel) <= 0 )
3518 DIE(aTHX_ "Perls since %"SVf" too modern--this is %"SVf", stopped",
3519 SVfARG(sv_2mortal(vnormal(sv))),
3520 SVfARG(sv_2mortal(vnormal(PL_patchlevel)))
3524 if ( vcmp(sv,PL_patchlevel) > 0 ) {
3527 SV * const req = SvRV(sv);
3528 SV * const pv = *hv_fetchs(MUTABLE_HV(req), "original", FALSE);
3530 /* get the left hand term */
3531 lav = MUTABLE_AV(SvRV(*hv_fetchs(MUTABLE_HV(req), "version", FALSE)));
3533 first = SvIV(*av_fetch(lav,0,0));
3534 if ( first > (int)PERL_REVISION /* probably 'use 6.0' */
3535 || hv_exists(MUTABLE_HV(req), "qv", 2 ) /* qv style */
3536 || av_len(lav) > 1 /* FP with > 3 digits */
3537 || strstr(SvPVX(pv),".0") /* FP with leading 0 */
3539 DIE(aTHX_ "Perl %"SVf" required--this is only "
3541 SVfARG(sv_2mortal(vnormal(req))),
3542 SVfARG(sv_2mortal(vnormal(PL_patchlevel)))
3545 else { /* probably 'use 5.10' or 'use 5.8' */
3550 second = SvIV(*av_fetch(lav,1,0));
3552 second /= second >= 600 ? 100 : 10;
3553 hintsv = Perl_newSVpvf(aTHX_ "v%d.%d.0",
3554 (int)first, (int)second);
3555 upg_version(hintsv, TRUE);
3557 DIE(aTHX_ "Perl %"SVf" required (did you mean %"SVf"?)"
3558 "--this is only %"SVf", stopped",
3559 SVfARG(sv_2mortal(vnormal(req))),
3560 SVfARG(sv_2mortal(vnormal(sv_2mortal(hintsv)))),
3561 SVfARG(sv_2mortal(vnormal(PL_patchlevel)))
3569 name = SvPV_const(sv, len);
3570 if (!(name && len > 0 && *name))
3571 DIE(aTHX_ "Null filename used");
3572 TAINT_PROPER("require");
3576 /* The key in the %ENV hash is in the syntax of file passed as the argument
3577 * usually this is in UNIX format, but sometimes in VMS format, which
3578 * can result in a module being pulled in more than once.
3579 * To prevent this, the key must be stored in UNIX format if the VMS
3580 * name can be translated to UNIX.
3582 if ((unixname = tounixspec(name, NULL)) != NULL) {
3583 unixlen = strlen(unixname);
3589 /* if not VMS or VMS name can not be translated to UNIX, pass it
3592 unixname = (char *) name;
3595 if (PL_op->op_type == OP_REQUIRE) {
3596 SV * const * const svp = hv_fetch(GvHVn(PL_incgv),
3597 unixname, unixlen, 0);
3599 if (*svp != &PL_sv_undef)
3602 DIE(aTHX_ "Attempt to reload %s aborted.\n"
3603 "Compilation failed in require", unixname);
3607 /* prepare to compile file */
3609 if (path_is_absolute(name)) {
3610 /* At this point, name is SvPVX(sv) */
3612 tryrsfp = doopen_pm(sv);
3615 AV * const ar = GvAVn(PL_incgv);
3621 namesv = newSV_type(SVt_PV);
3622 for (i = 0; i <= AvFILL(ar); i++) {
3623 SV * const dirsv = *av_fetch(ar, i, TRUE);
3625 if (SvTIED_mg((const SV *)ar, PERL_MAGIC_tied))
3632 if (SvTYPE(SvRV(loader)) == SVt_PVAV
3633 && !sv_isobject(loader))
3635 loader = *av_fetch(MUTABLE_AV(SvRV(loader)), 0, TRUE);
3638 Perl_sv_setpvf(aTHX_ namesv, "/loader/0x%"UVxf"/%s",
3639 PTR2UV(SvRV(dirsv)), name);
3640 tryname = SvPVX_const(namesv);
3643 ENTER_with_name("call_INC");
3651 if (sv_isobject(loader))
3652 count = call_method("INC", G_ARRAY);
3654 count = call_sv(loader, G_ARRAY);
3664 if (SvROK(arg) && (SvTYPE(SvRV(arg)) <= SVt_PVLV)
3665 && !isGV_with_GP(SvRV(arg))) {
3666 filter_cache = SvRV(arg);
3667 SvREFCNT_inc_simple_void_NN(filter_cache);
3674 if (SvROK(arg) && isGV_with_GP(SvRV(arg))) {
3678 if (isGV_with_GP(arg)) {
3679 IO * const io = GvIO((const GV *)arg);
3684 tryrsfp = IoIFP(io);
3685 if (IoOFP(io) && IoOFP(io) != IoIFP(io)) {
3686 PerlIO_close(IoOFP(io));
3697 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVCV) {
3699 SvREFCNT_inc_simple_void_NN(filter_sub);
3702 filter_state = SP[i];
3703 SvREFCNT_inc_simple_void(filter_state);
3707 if (!tryrsfp && (filter_cache || filter_sub)) {
3708 tryrsfp = PerlIO_open(BIT_BUCKET,
3716 LEAVE_with_name("call_INC");
3718 /* Adjust file name if the hook has set an %INC entry.
3719 This needs to happen after the FREETMPS above. */
3720 svp = hv_fetch(GvHVn(PL_incgv), name, len, 0);
3722 tryname = SvPV_nolen_const(*svp);
3729 filter_has_file = 0;
3731 SvREFCNT_dec(filter_cache);
3732 filter_cache = NULL;
3735 SvREFCNT_dec(filter_state);
3736 filter_state = NULL;
3739 SvREFCNT_dec(filter_sub);
3744 if (!path_is_absolute(name)
3750 dir = SvPV_const(dirsv, dirlen);
3758 if ((unixdir = tounixpath(dir, NULL)) == NULL)
3760 sv_setpv(namesv, unixdir);
3761 sv_catpv(namesv, unixname);
3763 # ifdef __SYMBIAN32__
3764 if (PL_origfilename[0] &&
3765 PL_origfilename[1] == ':' &&
3766 !(dir[0] && dir[1] == ':'))
3767 Perl_sv_setpvf(aTHX_ namesv,
3772 Perl_sv_setpvf(aTHX_ namesv,
3776 /* The equivalent of
3777 Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name);
3778 but without the need to parse the format string, or
3779 call strlen on either pointer, and with the correct
3780 allocation up front. */
3782 char *tmp = SvGROW(namesv, dirlen + len + 2);
3784 memcpy(tmp, dir, dirlen);
3787 /* name came from an SV, so it will have a '\0' at the
3788 end that we can copy as part of this memcpy(). */
3789 memcpy(tmp, name, len + 1);
3791 SvCUR_set(namesv, dirlen + len + 1);
3796 TAINT_PROPER("require");
3797 tryname = SvPVX_const(namesv);
3798 tryrsfp = doopen_pm(namesv);
3800 if (tryname[0] == '.' && tryname[1] == '/') {
3802 while (*++tryname == '/');
3806 else if (errno == EMFILE)
3807 /* no point in trying other paths if out of handles */
3816 if (PL_op->op_type == OP_REQUIRE) {
3817 if(errno == EMFILE) {
3818 /* diag_listed_as: Can't locate %s */
3819 DIE(aTHX_ "Can't locate %s: %s", name, Strerror(errno));
3821 if (namesv) { /* did we lookup @INC? */
3822 AV * const ar = GvAVn(PL_incgv);
3824 SV *const inc = newSVpvs_flags("", SVs_TEMP);
3825 for (i = 0; i <= AvFILL(ar); i++) {
3826 sv_catpvs(inc, " ");
3827 sv_catsv(inc, *av_fetch(ar, i, TRUE));
3830 /* diag_listed_as: Can't locate %s */
3832 "Can't locate %s in @INC%s%s (@INC contains:%" SVf ")",
3834 (memEQ(name + len - 2, ".h", 3)
3835 ? " (change .h to .ph maybe?) (did you run h2ph?)" : ""),
3836 (memEQ(name + len - 3, ".ph", 4)
3837 ? " (did you run h2ph?)" : ""),
3842 DIE(aTHX_ "Can't locate %s", name);
3848 SETERRNO(0, SS_NORMAL);
3850 /* Assume success here to prevent recursive requirement. */
3851 /* name is never assigned to again, so len is still strlen(name) */
3852 /* Check whether a hook in @INC has already filled %INC */
3854 (void)hv_store(GvHVn(PL_incgv),
3855 unixname, unixlen, newSVpv(tryname,0),0);
3857 SV** const svp = hv_fetch(GvHVn(PL_incgv), unixname, unixlen, 0);
3859 (void)hv_store(GvHVn(PL_incgv),
3860 unixname, unixlen, SvREFCNT_inc_simple(hook_sv), 0 );
3863 ENTER_with_name("eval");
3865 SAVECOPFILE_FREE(&PL_compiling);
3866 CopFILE_set(&PL_compiling, tryname);
3867 lex_start(NULL, tryrsfp, 0);
3871 hv_clear(GvHV(PL_hintgv));
3873 SAVECOMPILEWARNINGS();
3874 if (PL_dowarn & G_WARN_ALL_ON)
3875 PL_compiling.cop_warnings = pWARN_ALL ;
3876 else if (PL_dowarn & G_WARN_ALL_OFF)
3877 PL_compiling.cop_warnings = pWARN_NONE ;
3879 PL_compiling.cop_warnings = pWARN_STD ;
3881 if (filter_sub || filter_cache) {
3882 /* We can use the SvPV of the filter PVIO itself as our cache, rather
3883 than hanging another SV from it. In turn, filter_add() optionally
3884 takes the SV to use as the filter (or creates a new SV if passed
3885 NULL), so simply pass in whatever value filter_cache has. */
3886 SV * const datasv = filter_add(S_run_user_filter, filter_cache);
3887 IoLINES(datasv) = filter_has_file;
3888 IoTOP_GV(datasv) = MUTABLE_GV(filter_state);
3889 IoBOTTOM_GV(datasv) = MUTABLE_GV(filter_sub);
3892 /* switch to eval mode */
3893 PUSHBLOCK(cx, CXt_EVAL, SP);
3895 cx->blk_eval.retop = PL_op->op_next;
3897 SAVECOPLINE(&PL_compiling);
3898 CopLINE_set(&PL_compiling, 0);
3902 /* Store and reset encoding. */
3903 encoding = PL_encoding;
3906 if (doeval(gimme, NULL, NULL, PL_curcop->cop_seq))
3907 op = DOCATCH(PL_eval_start);
3909 op = PL_op->op_next;
3911 /* Restore encoding. */
3912 PL_encoding = encoding;
3917 /* This is a op added to hold the hints hash for
3918 pp_entereval. The hash can be modified by the code
3919 being eval'ed, so we return a copy instead. */
3925 mXPUSHs(MUTABLE_SV(hv_copy_hints_hv(MUTABLE_HV(cSVOP_sv))));
3933 register PERL_CONTEXT *cx;
3935 const I32 gimme = GIMME_V;
3936 const U32 was = PL_breakable_sub_gen;
3937 char tbuf[TYPE_DIGITS(long) + 12];
3938 bool saved_delete = FALSE;
3939 char *tmpbuf = tbuf;
3943 HV *saved_hh = NULL;
3945 if (PL_op->op_private & OPpEVAL_HAS_HH) {
3946 saved_hh = MUTABLE_HV(SvREFCNT_inc(POPs));
3950 /* make sure we've got a plain PV (no overload etc) before testing
3951 * for taint. Making a copy here is probably overkill, but better
3952 * safe than sorry */
3954 const char * const p = SvPV_const(sv, len);
3956 sv = newSVpvn_flags(p, len, SVs_TEMP | SvUTF8(sv));
3959 TAINT_IF(SvTAINTED(sv));
3960 TAINT_PROPER("eval");
3962 ENTER_with_name("eval");
3963 lex_start(sv, NULL, LEX_START_SAME_FILTER);
3966 /* switch to eval mode */
3968 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
3969 SV * const temp_sv = sv_newmortal();
3970 Perl_sv_setpvf(aTHX_ temp_sv, "_<(eval %lu)[%s:%"IVdf"]",
3971 (unsigned long)++PL_evalseq,
3972 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
3973 tmpbuf = SvPVX(temp_sv);
3974 len = SvCUR(temp_sv);
3977 len = my_snprintf(tmpbuf, sizeof(tbuf), "_<(eval %lu)", (unsigned long)++PL_evalseq);
3978 SAVECOPFILE_FREE(&PL_compiling);
3979 CopFILE_set(&PL_compiling, tmpbuf+2);
3980 SAVECOPLINE(&PL_compiling);
3981 CopLINE_set(&PL_compiling, 1);
3982 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
3983 deleting the eval's FILEGV from the stash before gv_check() runs
3984 (i.e. before run-time proper). To work around the coredump that
3985 ensues, we always turn GvMULTI_on for any globals that were
3986 introduced within evals. See force_ident(). GSAR 96-10-12 */
3988 PL_hints = PL_op->op_targ;
3990 /* SAVEHINTS created a new HV in PL_hintgv, which we need to GC */
3991 SvREFCNT_dec(GvHV(PL_hintgv));
3992 GvHV(PL_hintgv) = saved_hh;
3994 SAVECOMPILEWARNINGS();
3995 PL_compiling.cop_warnings = DUP_WARNINGS(PL_curcop->cop_warnings);
3996 cophh_free(CopHINTHASH_get(&PL_compiling));
3997 if (Perl_fetch_cop_label(aTHX_ PL_curcop, NULL, NULL)) {
3998 /* The label, if present, is the first entry on the chain. So rather
3999 than writing a blank label in front of it (which involves an
4000 allocation), just use the next entry in the chain. */
4001 PL_compiling.cop_hints_hash
4002 = cophh_copy(PL_curcop->cop_hints_hash->refcounted_he_next);
4003 /* Check the assumption that this removed the label. */
4004 assert(Perl_fetch_cop_label(aTHX_ &PL_compiling, NULL, NULL) == NULL);
4007 PL_compiling.cop_hints_hash = cophh_copy(PL_curcop->cop_hints_hash);
4008 /* special case: an eval '' executed within the DB package gets lexically
4009 * placed in the first non-DB CV rather than the current CV - this
4010 * allows the debugger to execute code, find lexicals etc, in the
4011 * scope of the code being debugged. Passing &seq gets find_runcv
4012 * to do the dirty work for us */
4013 runcv = find_runcv(&seq);
4015 PUSHBLOCK(cx, (CXt_EVAL|CXp_REAL), SP);
4017 cx->blk_eval.retop = PL_op->op_next;
4019 /* prepare to compile string */
4021 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
4022 save_lines(CopFILEAV(&PL_compiling), PL_parser->linestr);
4024 char *const safestr = savepvn(tmpbuf, len);
4025 SAVEDELETE(PL_defstash, safestr, len);
4026 saved_delete = TRUE;
4031 if (doeval(gimme, NULL, runcv, seq)) {
4032 if (was != PL_breakable_sub_gen /* Some subs defined here. */
4033 ? (PERLDB_LINE || PERLDB_SAVESRC)
4034 : PERLDB_SAVESRC_NOSUBS) {
4035 /* Retain the filegv we created. */
4036 } else if (!saved_delete) {
4037 char *const safestr = savepvn(tmpbuf, len);
4038 SAVEDELETE(PL_defstash, safestr, len);
4040 return DOCATCH(PL_eval_start);
4042 /* We have already left the scope set up earlier thanks to the LEAVE
4044 if (was != PL_breakable_sub_gen /* Some subs defined here. */
4045 ? (PERLDB_LINE || PERLDB_SAVESRC)
4046 : PERLDB_SAVESRC_INVALID) {
4047 /* Retain the filegv we created. */
4048 } else if (!saved_delete) {
4049 (void)hv_delete(PL_defstash, tmpbuf, len, G_DISCARD);
4051 return PL_op->op_next;
4062 register PERL_CONTEXT *cx;
4064 const U8 save_flags = PL_op -> op_flags;
4071 namesv = cx->blk_eval.old_namesv;
4072 retop = cx->blk_eval.retop;
4075 if (gimme == G_VOID)
4077 else if (gimme == G_SCALAR) {
4080 if (SvFLAGS(TOPs) & SVs_TEMP)
4083 *MARK = sv_mortalcopy(TOPs);
4087 *MARK = &PL_sv_undef;
4092 /* in case LEAVE wipes old return values */
4093 for (mark = newsp + 1; mark <= SP; mark++) {
4094 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
4095 *mark = sv_mortalcopy(*mark);
4096 TAINT_NOT; /* Each item is independent */
4100 PL_curpm = newpm; /* Don't pop $1 et al till now */
4103 assert(CvDEPTH(PL_compcv) == 1);
4105 CvDEPTH(PL_compcv) = 0;
4107 if (optype == OP_REQUIRE &&
4108 !(gimme == G_SCALAR ? SvTRUE(*SP) : SP > newsp))
4110 /* Unassume the success we assumed earlier. */
4111 (void)hv_delete(GvHVn(PL_incgv),
4112 SvPVX_const(namesv), SvCUR(namesv),
4114 retop = Perl_die(aTHX_ "%"SVf" did not return a true value",
4116 /* die_unwind() did LEAVE, or we won't be here */
4119 LEAVE_with_name("eval");
4120 if (!(save_flags & OPf_SPECIAL)) {
4128 /* Common code for Perl_call_sv and Perl_fold_constants, put here to keep it
4129 close to the related Perl_create_eval_scope. */
4131 Perl_delete_eval_scope(pTHX)
4136 register PERL_CONTEXT *cx;
4142 LEAVE_with_name("eval_scope");
4143 PERL_UNUSED_VAR(newsp);
4144 PERL_UNUSED_VAR(gimme);
4145 PERL_UNUSED_VAR(optype);
4148 /* Common-ish code salvaged from Perl_call_sv and pp_entertry, because it was
4149 also needed by Perl_fold_constants. */
4151 Perl_create_eval_scope(pTHX_ U32 flags)
4154 const I32 gimme = GIMME_V;
4156 ENTER_with_name("eval_scope");
4159 PUSHBLOCK(cx, (CXt_EVAL|CXp_TRYBLOCK), PL_stack_sp);
4162 PL_in_eval = EVAL_INEVAL;
4163 if (flags & G_KEEPERR)
4164 PL_in_eval |= EVAL_KEEPERR;
4167 if (flags & G_FAKINGEVAL) {
4168 PL_eval_root = PL_op; /* Only needed so that goto works right. */
4176 PERL_CONTEXT * const cx = create_eval_scope(0);
4177 cx->blk_eval.retop = cLOGOP->op_other->op_next;
4178 return DOCATCH(PL_op->op_next);
4187 register PERL_CONTEXT *cx;
4193 PERL_UNUSED_VAR(optype);
4196 if (gimme == G_VOID)
4198 else if (gimme == G_SCALAR) {
4202 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
4205 *MARK = sv_mortalcopy(TOPs);
4209 *MARK = &PL_sv_undef;
4214 /* in case LEAVE wipes old return values */
4216 for (mark = newsp + 1; mark <= SP; mark++) {
4217 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
4218 *mark = sv_mortalcopy(*mark);
4219 TAINT_NOT; /* Each item is independent */
4223 PL_curpm = newpm; /* Don't pop $1 et al till now */
4225 LEAVE_with_name("eval_scope");
4233 register PERL_CONTEXT *cx;
4234 const I32 gimme = GIMME_V;
4236 ENTER_with_name("given");
4239 sv_setsv(PAD_SV(PL_op->op_targ), POPs);
4241 PUSHBLOCK(cx, CXt_GIVEN, SP);
4250 register PERL_CONTEXT *cx;
4254 PERL_UNUSED_CONTEXT;
4257 assert(CxTYPE(cx) == CXt_GIVEN);
4260 if (gimme == G_VOID)
4262 else if (gimme == G_SCALAR) {
4266 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
4269 *MARK = sv_mortalcopy(TOPs);
4273 *MARK = &PL_sv_undef;
4278 /* in case LEAVE wipes old return values */
4280 for (mark = newsp + 1; mark <= SP; mark++) {
4281 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
4282 *mark = sv_mortalcopy(*mark);
4283 TAINT_NOT; /* Each item is independent */
4287 PL_curpm = newpm; /* Don't pop $1 et al till now */
4289 LEAVE_with_name("given");
4293 /* Helper routines used by pp_smartmatch */
4295 S_make_matcher(pTHX_ REGEXP *re)
4298 PMOP *matcher = (PMOP *) newPMOP(OP_MATCH, OPf_WANT_SCALAR | OPf_STACKED);
4300 PERL_ARGS_ASSERT_MAKE_MATCHER;
4302 PM_SETRE(matcher, ReREFCNT_inc(re));
4304 SAVEFREEOP((OP *) matcher);
4305 ENTER_with_name("matcher"); SAVETMPS;
4311 S_matcher_matches_sv(pTHX_ PMOP *matcher, SV *sv)
4316 PERL_ARGS_ASSERT_MATCHER_MATCHES_SV;
4318 PL_op = (OP *) matcher;
4321 (void) Perl_pp_match(aTHX);
4323 return (SvTRUEx(POPs));
4327 S_destroy_matcher(pTHX_ PMOP *matcher)
4331 PERL_ARGS_ASSERT_DESTROY_MATCHER;
4332 PERL_UNUSED_ARG(matcher);
4335 LEAVE_with_name("matcher");
4338 /* Do a smart match */
4341 DEBUG_M(Perl_deb(aTHX_ "Starting smart match resolution\n"));
4342 return do_smartmatch(NULL, NULL);
4345 /* This version of do_smartmatch() implements the
4346 * table of smart matches that is found in perlsyn.
4349 S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other)
4354 bool object_on_left = FALSE;
4355 SV *e = TOPs; /* e is for 'expression' */
4356 SV *d = TOPm1s; /* d is for 'default', as in PL_defgv */
4358 /* Take care only to invoke mg_get() once for each argument.
4359 * Currently we do this by copying the SV if it's magical. */
4362 d = sv_mortalcopy(d);
4369 e = sv_mortalcopy(e);
4371 /* First of all, handle overload magic of the rightmost argument */
4374 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Object\n"));
4375 DEBUG_M(Perl_deb(aTHX_ " attempting overload\n"));
4377 tmpsv = amagic_call(d, e, smart_amg, 0);
4384 DEBUG_M(Perl_deb(aTHX_ " failed to run overload method; continuing...\n"));
4387 SP -= 2; /* Pop the values */
4392 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-undef\n"));
4399 if (sv_isobject(e) && (SvTYPE(SvRV(e)) != SVt_REGEXP)) {
4400 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Object\n"));
4401 Perl_croak(aTHX_ "Smart matching a non-overloaded object breaks encapsulation");
4403 if (sv_isobject(d) && (SvTYPE(SvRV(d)) != SVt_REGEXP))
4404 object_on_left = TRUE;
4407 if (SvROK(e) && SvTYPE(SvRV(e)) == SVt_PVCV) {
4409 if (object_on_left) {
4410 goto sm_any_sub; /* Treat objects like scalars */
4412 else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVHV) {
4413 /* Test sub truth for each key */
4415 bool andedresults = TRUE;
4416 HV *hv = (HV*) SvRV(d);
4417 I32 numkeys = hv_iterinit(hv);
4418 DEBUG_M(Perl_deb(aTHX_ " applying rule Hash-CodeRef\n"));
4421 while ( (he = hv_iternext(hv)) ) {
4422 DEBUG_M(Perl_deb(aTHX_ " testing hash key...\n"));
4423 ENTER_with_name("smartmatch_hash_key_test");
4426 PUSHs(hv_iterkeysv(he));
4428 c = call_sv(e, G_SCALAR);
4431 andedresults = FALSE;
4433 andedresults = SvTRUEx(POPs) && andedresults;
4435 LEAVE_with_name("smartmatch_hash_key_test");
4442 else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVAV) {
4443 /* Test sub truth for each element */
4445 bool andedresults = TRUE;
4446 AV *av = (AV*) SvRV(d);
4447 const I32 len = av_len(av);
4448 DEBUG_M(Perl_deb(aTHX_ " applying rule Array-CodeRef\n"));
4451 for (i = 0; i <= len; ++i) {
4452 SV * const * const svp = av_fetch(av, i, FALSE);
4453 DEBUG_M(Perl_deb(aTHX_ " testing array element...\n"));
4454 ENTER_with_name("smartmatch_array_elem_test");
4460 c = call_sv(e, G_SCALAR);
4463 andedresults = FALSE;
4465 andedresults = SvTRUEx(POPs) && andedresults;
4467 LEAVE_with_name("smartmatch_array_elem_test");
4476 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-CodeRef\n"));
4477 ENTER_with_name("smartmatch_coderef");
4482 c = call_sv(e, G_SCALAR);
4486 else if (SvTEMP(TOPs))
4487 SvREFCNT_inc_void(TOPs);
4489 LEAVE_with_name("smartmatch_coderef");
4494 else if (SvROK(e) && SvTYPE(SvRV(e)) == SVt_PVHV) {
4495 if (object_on_left) {
4496 goto sm_any_hash; /* Treat objects like scalars */
4498 else if (!SvOK(d)) {
4499 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Hash ($a undef)\n"));
4502 else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVHV) {
4503 /* Check that the key-sets are identical */
4505 HV *other_hv = MUTABLE_HV(SvRV(d));
4507 bool other_tied = FALSE;
4508 U32 this_key_count = 0,
4509 other_key_count = 0;
4510 HV *hv = MUTABLE_HV(SvRV(e));
4512 DEBUG_M(Perl_deb(aTHX_ " applying rule Hash-Hash\n"));
4513 /* Tied hashes don't know how many keys they have. */
4514 if (SvTIED_mg((SV*)hv, PERL_MAGIC_tied)) {
4517 else if (SvTIED_mg((const SV *)other_hv, PERL_MAGIC_tied)) {
4518 HV * const temp = other_hv;
4523 if (SvTIED_mg((const SV *)other_hv, PERL_MAGIC_tied))
4526 if (!tied && HvUSEDKEYS((const HV *) hv) != HvUSEDKEYS(other_hv))
4529 /* The hashes have the same number of keys, so it suffices
4530 to check that one is a subset of the other. */
4531 (void) hv_iterinit(hv);
4532 while ( (he = hv_iternext(hv)) ) {
4533 SV *key = hv_iterkeysv(he);
4535 DEBUG_M(Perl_deb(aTHX_ " comparing hash key...\n"));
4538 if(!hv_exists_ent(other_hv, key, 0)) {
4539 (void) hv_iterinit(hv); /* reset iterator */
4545 (void) hv_iterinit(other_hv);
4546 while ( hv_iternext(other_hv) )
4550 other_key_count = HvUSEDKEYS(other_hv);
4552 if (this_key_count != other_key_count)
4557 else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVAV) {
4558 AV * const other_av = MUTABLE_AV(SvRV(d));
4559 const I32 other_len = av_len(other_av) + 1;
4561 HV *hv = MUTABLE_HV(SvRV(e));
4563 DEBUG_M(Perl_deb(aTHX_ " applying rule Array-Hash\n"));
4564 for (i = 0; i < other_len; ++i) {
4565 SV ** const svp = av_fetch(other_av, i, FALSE);
4566 DEBUG_M(Perl_deb(aTHX_ " checking for key existence...\n"));
4567 if (svp) { /* ??? When can this not happen? */
4568 if (hv_exists_ent(hv, *svp, 0))
4574 else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_REGEXP) {
4575 DEBUG_M(Perl_deb(aTHX_ " applying rule Regex-Hash\n"));
4578 PMOP * const matcher = make_matcher((REGEXP*) SvRV(d));
4580 HV *hv = MUTABLE_HV(SvRV(e));
4582 (void) hv_iterinit(hv);
4583 while ( (he = hv_iternext(hv)) ) {
4584 DEBUG_M(Perl_deb(aTHX_ " testing key against pattern...\n"));
4585 if (matcher_matches_sv(matcher, hv_iterkeysv(he))) {
4586 (void) hv_iterinit(hv);
4587 destroy_matcher(matcher);
4591 destroy_matcher(matcher);
4597 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Hash\n"));
4598 if (hv_exists_ent(MUTABLE_HV(SvRV(e)), d, 0))
4605 else if (SvROK(e) && SvTYPE(SvRV(e)) == SVt_PVAV) {
4606 if (object_on_left) {
4607 goto sm_any_array; /* Treat objects like scalars */
4609 else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVHV) {
4610 AV * const other_av = MUTABLE_AV(SvRV(e));
4611 const I32 other_len = av_len(other_av) + 1;
4614 DEBUG_M(Perl_deb(aTHX_ " applying rule Hash-Array\n"));
4615 for (i = 0; i < other_len; ++i) {
4616 SV ** const svp = av_fetch(other_av, i, FALSE);
4618 DEBUG_M(Perl_deb(aTHX_ " testing for key existence...\n"));
4619 if (svp) { /* ??? When can this not happen? */
4620 if (hv_exists_ent(MUTABLE_HV(SvRV(d)), *svp, 0))
4626 if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVAV) {
4627 AV *other_av = MUTABLE_AV(SvRV(d));
4628 DEBUG_M(Perl_deb(aTHX_ " applying rule Array-Array\n"));
4629 if (av_len(MUTABLE_AV(SvRV(e))) != av_len(other_av))
4633 const I32 other_len = av_len(other_av);
4635 if (NULL == seen_this) {
4636 seen_this = newHV();
4637 (void) sv_2mortal(MUTABLE_SV(seen_this));
4639 if (NULL == seen_other) {
4640 seen_other = newHV();
4641 (void) sv_2mortal(MUTABLE_SV(seen_other));
4643 for(i = 0; i <= other_len; ++i) {
4644 SV * const * const this_elem = av_fetch(MUTABLE_AV(SvRV(e)), i, FALSE);
4645 SV * const * const other_elem = av_fetch(other_av, i, FALSE);
4647 if (!this_elem || !other_elem) {
4648 if ((this_elem && SvOK(*this_elem))
4649 || (other_elem && SvOK(*other_elem)))
4652 else if (hv_exists_ent(seen_this,
4653 sv_2mortal(newSViv(PTR2IV(*this_elem))), 0) ||
4654 hv_exists_ent(seen_other,
4655 sv_2mortal(newSViv(PTR2IV(*other_elem))), 0))
4657 if (*this_elem != *other_elem)
4661 (void)hv_store_ent(seen_this,
4662 sv_2mortal(newSViv(PTR2IV(*this_elem))),
4664 (void)hv_store_ent(seen_other,
4665 sv_2mortal(newSViv(PTR2IV(*other_elem))),
4671 DEBUG_M(Perl_deb(aTHX_ " recursively comparing array element...\n"));
4672 (void) do_smartmatch(seen_this, seen_other);
4674 DEBUG_M(Perl_deb(aTHX_ " recursion finished\n"));
4683 else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_REGEXP) {
4684 DEBUG_M(Perl_deb(aTHX_ " applying rule Regex-Array\n"));
4687 PMOP * const matcher = make_matcher((REGEXP*) SvRV(d));
4688 const I32 this_len = av_len(MUTABLE_AV(SvRV(e)));
4691 for(i = 0; i <= this_len; ++i) {
4692 SV * const * const svp = av_fetch(MUTABLE_AV(SvRV(e)), i, FALSE);
4693 DEBUG_M(Perl_deb(aTHX_ " testing element against pattern...\n"));
4694 if (svp && matcher_matches_sv(matcher, *svp)) {
4695 destroy_matcher(matcher);
4699 destroy_matcher(matcher);
4703 else if (!SvOK(d)) {
4704 /* undef ~~ array */
4705 const I32 this_len = av_len(MUTABLE_AV(SvRV(e)));
4708 DEBUG_M(Perl_deb(aTHX_ " applying rule Undef-Array\n"));
4709 for (i = 0; i <= this_len; ++i) {
4710 SV * const * const svp = av_fetch(MUTABLE_AV(SvRV(e)), i, FALSE);
4711 DEBUG_M(Perl_deb(aTHX_ " testing for undef element...\n"));
4712 if (!svp || !SvOK(*svp))
4721 const I32 this_len = av_len(MUTABLE_AV(SvRV(e)));
4723 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Array\n"));
4724 for (i = 0; i <= this_len; ++i) {
4725 SV * const * const svp = av_fetch(MUTABLE_AV(SvRV(e)), i, FALSE);
4732 /* infinite recursion isn't supposed to happen here */
4733 DEBUG_M(Perl_deb(aTHX_ " recursively testing array element...\n"));
4734 (void) do_smartmatch(NULL, NULL);
4736 DEBUG_M(Perl_deb(aTHX_ " recursion finished\n"));
4745 else if (SvROK(e) && SvTYPE(SvRV(e)) == SVt_REGEXP) {
4746 if (!object_on_left && SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVHV) {
4747 SV *t = d; d = e; e = t;
4748 DEBUG_M(Perl_deb(aTHX_ " applying rule Hash-Regex\n"));
4751 else if (!object_on_left && SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVAV) {
4752 SV *t = d; d = e; e = t;
4753 DEBUG_M(Perl_deb(aTHX_ " applying rule Array-Regex\n"));
4754 goto sm_regex_array;
4757 PMOP * const matcher = make_matcher((REGEXP*) SvRV(e));
4759 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Regex\n"));
4761 PUSHs(matcher_matches_sv(matcher, d)
4764 destroy_matcher(matcher);
4769 /* See if there is overload magic on left */
4770 else if (object_on_left && SvAMAGIC(d)) {
4772 DEBUG_M(Perl_deb(aTHX_ " applying rule Object-Any\n"));
4773 DEBUG_M(Perl_deb(aTHX_ " attempting overload\n"));
4776 tmpsv = amagic_call(d, e, smart_amg, AMGf_noright);
4784 DEBUG_M(Perl_deb(aTHX_ " failed to run overload method; falling back...\n"));
4787 else if (!SvOK(d)) {
4788 /* undef ~~ scalar ; we already know that the scalar is SvOK */
4789 DEBUG_M(Perl_deb(aTHX_ " applying rule undef-Any\n"));
4794 if (SvNIOK(e) || (SvPOK(e) && looks_like_number(e) && SvNIOK(d))) {
4795 DEBUG_M(if (SvNIOK(e))
4796 Perl_deb(aTHX_ " applying rule Any-Num\n");
4798 Perl_deb(aTHX_ " applying rule Num-numish\n");
4800 /* numeric comparison */
4803 if (CopHINTS_get(PL_curcop) & HINT_INTEGER)
4804 (void) Perl_pp_i_eq(aTHX);
4806 (void) Perl_pp_eq(aTHX);
4814 /* As a last resort, use string comparison */
4815 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Any\n"));
4818 return Perl_pp_seq(aTHX);
4824 register PERL_CONTEXT *cx;
4825 const I32 gimme = GIMME_V;
4827 /* This is essentially an optimization: if the match
4828 fails, we don't want to push a context and then
4829 pop it again right away, so we skip straight
4830 to the op that follows the leavewhen.
4831 RETURNOP calls PUTBACK which restores the stack pointer after the POPs.
4833 if ((0 == (PL_op->op_flags & OPf_SPECIAL)) && !SvTRUEx(POPs))
4834 RETURNOP(cLOGOP->op_other->op_next);
4836 ENTER_with_name("eval");
4839 PUSHBLOCK(cx, CXt_WHEN, SP);
4848 register PERL_CONTEXT *cx;
4854 assert(CxTYPE(cx) == CXt_WHEN);
4859 PL_curpm = newpm; /* pop $1 et al */
4861 LEAVE_with_name("eval");
4869 register PERL_CONTEXT *cx;
4872 cxix = dopoptowhen(cxstack_ix);
4874 DIE(aTHX_ "Can't \"continue\" outside a when block");
4875 if (cxix < cxstack_ix)
4878 /* clear off anything above the scope we're re-entering */
4879 inner = PL_scopestack_ix;
4881 if (PL_scopestack_ix < inner)
4882 leave_scope(PL_scopestack[PL_scopestack_ix]);
4883 PL_curcop = cx->blk_oldcop;
4884 return cx->blk_givwhen.leave_op;
4891 register PERL_CONTEXT *cx;
4895 cxix = dopoptogiven(cxstack_ix);
4897 if (PL_op->op_flags & OPf_SPECIAL)
4898 DIE(aTHX_ "Can't use when() outside a topicalizer");
4900 DIE(aTHX_ "Can't \"break\" outside a given block");
4902 if (CxFOREACH(&cxstack[cxix]) && (0 == (PL_op->op_flags & OPf_SPECIAL)))
4903 DIE(aTHX_ "Can't \"break\" in a loop topicalizer");
4905 if (cxix < cxstack_ix)
4908 /* clear off anything above the scope we're re-entering */
4909 inner = PL_scopestack_ix;
4911 if (PL_scopestack_ix < inner)
4912 leave_scope(PL_scopestack[PL_scopestack_ix]);
4913 PL_curcop = cx->blk_oldcop;
4916 return (cx)->blk_loop.my_op->op_nextop;
4918 /* RETURNOP calls PUTBACK which restores the old old sp */
4919 RETURNOP(cx->blk_givwhen.leave_op);
4923 S_doparseform(pTHX_ SV *sv)
4926 register char *s = SvPV_force(sv, len);
4927 register char * const send = s + len;
4928 register char *base = NULL;
4929 register I32 skipspaces = 0;
4930 bool noblank = FALSE;
4931 bool repeat = FALSE;
4932 bool postspace = FALSE;
4938 bool unchopnum = FALSE;
4939 int maxops = 12; /* FF_LINEMARK + FF_END + 10 (\0 without preceding \n) */
4942 PERL_ARGS_ASSERT_DOPARSEFORM;
4945 Perl_croak(aTHX_ "Null picture in formline");
4947 /* estimate the buffer size needed */
4948 for (base = s; s <= send; s++) {
4949 if (*s == '\n' || *s == '@' || *s == '^')
4955 Newx(fops, maxops, U32);
4960 *fpc++ = FF_LINEMARK;
4961 noblank = repeat = FALSE;
4979 case ' ': case '\t':
4986 } /* else FALL THROUGH */
4994 *fpc++ = FF_LITERAL;
5002 *fpc++ = (U16)skipspaces;
5006 *fpc++ = FF_NEWLINE;
5010 arg = fpc - linepc + 1;
5017 *fpc++ = FF_LINEMARK;
5018 noblank = repeat = FALSE;
5027 ischop = s[-1] == '^';
5033 arg = (s - base) - 1;
5035 *fpc++ = FF_LITERAL;
5043 *fpc++ = 2; /* skip the @* or ^* */
5045 *fpc++ = FF_LINESNGL;
5048 *fpc++ = FF_LINEGLOB;
5050 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
5051 arg = ischop ? 512 : 0;
5056 const char * const f = ++s;
5059 arg |= 256 + (s - f);
5061 *fpc++ = s - base; /* fieldsize for FETCH */
5062 *fpc++ = FF_DECIMAL;
5064 unchopnum |= ! ischop;
5066 else if (*s == '0' && s[1] == '#') { /* Zero padded decimals */
5067 arg = ischop ? 512 : 0;
5069 s++; /* skip the '0' first */
5073 const char * const f = ++s;
5076 arg |= 256 + (s - f);
5078 *fpc++ = s - base; /* fieldsize for FETCH */
5079 *fpc++ = FF_0DECIMAL;
5081 unchopnum |= ! ischop;
5085 bool ismore = FALSE;
5088 while (*++s == '>') ;
5089 prespace = FF_SPACE;
5091 else if (*s == '|') {
5092 while (*++s == '|') ;
5093 prespace = FF_HALFSPACE;
5098 while (*++s == '<') ;
5101 if (*s == '.' && s[1] == '.' && s[2] == '.') {
5105 *fpc++ = s - base; /* fieldsize for FETCH */
5107 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
5110 *fpc++ = (U16)prespace;
5124 assert (fpc <= fops + maxops); /* ensure our buffer estimate was valid */
5127 /* If we pass the length in to sv_magicext() it will copy the buffer for us.
5128 We don't need that, so by setting the length on return we "donate" the
5129 buffer to the magic, avoiding an allocation. We could realloc() the
5130 buffer to the exact size used, but that feels like it's not worth it
5131 (particularly if the rumours are true and some realloc() implementations
5132 don't shrink blocks). However, set the true length used in mg_len so that
5133 mg_dup only allocates and copies what's actually needed. */
5134 mg = sv_magicext(sv, NULL, PERL_MAGIC_fm, &PL_vtbl_fm,
5135 (const char *const) fops, 0);
5136 mg->mg_len = arg * sizeof(U32);
5138 if (unchopnum && repeat)
5139 Perl_die(aTHX_ "Repeated format line will never terminate (~~ and @#)");
5146 S_num_overflow(NV value, I32 fldsize, I32 frcsize)
5148 /* Can value be printed in fldsize chars, using %*.*f ? */
5152 int intsize = fldsize - (value < 0 ? 1 : 0);
5159 while (intsize--) pwr *= 10.0;
5160 while (frcsize--) eps /= 10.0;
5163 if (value + eps >= pwr)
5166 if (value - eps <= -pwr)
5173 S_run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen)
5176 SV * const datasv = FILTER_DATA(idx);
5177 const int filter_has_file = IoLINES(datasv);
5178 SV * const filter_state = MUTABLE_SV(IoTOP_GV(datasv));
5179 SV * const filter_sub = MUTABLE_SV(IoBOTTOM_GV(datasv));
5184 char *prune_from = NULL;
5185 bool read_from_cache = FALSE;
5188 PERL_ARGS_ASSERT_RUN_USER_FILTER;
5190 assert(maxlen >= 0);
5193 /* I was having segfault trouble under Linux 2.2.5 after a
5194 parse error occured. (Had to hack around it with a test
5195 for PL_parser->error_count == 0.) Solaris doesn't segfault --
5196 not sure where the trouble is yet. XXX */
5199 SV *const cache = datasv;
5202 const char *cache_p = SvPV(cache, cache_len);
5206 /* Running in block mode and we have some cached data already.
5208 if (cache_len >= umaxlen) {
5209 /* In fact, so much data we don't even need to call
5214 const char *const first_nl =
5215 (const char *)memchr(cache_p, '\n', cache_len);
5217 take = first_nl + 1 - cache_p;
5221 sv_catpvn(buf_sv, cache_p, take);
5222 sv_chop(cache, cache_p + take);
5223 /* Definitely not EOF */
5227 sv_catsv(buf_sv, cache);
5229 umaxlen -= cache_len;
5232 read_from_cache = TRUE;
5236 /* Filter API says that the filter appends to the contents of the buffer.
5237 Usually the buffer is "", so the details don't matter. But if it's not,
5238 then clearly what it contains is already filtered by this filter, so we
5239 don't want to pass it in a second time.
5240 I'm going to use a mortal in case the upstream filter croaks. */
5241 upstream = ((SvOK(buf_sv) && sv_len(buf_sv)) || SvGMAGICAL(buf_sv))
5242 ? sv_newmortal() : buf_sv;
5243 SvUPGRADE(upstream, SVt_PV);
5245 if (filter_has_file) {
5246 status = FILTER_READ(idx+1, upstream, 0);
5249 if (filter_sub && status >= 0) {
5253 ENTER_with_name("call_filter_sub");
5258 DEFSV_set(upstream);
5262 PUSHs(filter_state);
5265 count = call_sv(filter_sub, G_SCALAR);
5277 LEAVE_with_name("call_filter_sub");
5280 if(SvOK(upstream)) {
5281 got_p = SvPV(upstream, got_len);
5283 if (got_len > umaxlen) {
5284 prune_from = got_p + umaxlen;
5287 char *const first_nl = (char *)memchr(got_p, '\n', got_len);
5288 if (first_nl && first_nl + 1 < got_p + got_len) {
5289 /* There's a second line here... */
5290 prune_from = first_nl + 1;
5295 /* Oh. Too long. Stuff some in our cache. */
5296 STRLEN cached_len = got_p + got_len - prune_from;
5297 SV *const cache = datasv;
5300 /* Cache should be empty. */
5301 assert(!SvCUR(cache));
5304 sv_setpvn(cache, prune_from, cached_len);
5305 /* If you ask for block mode, you may well split UTF-8 characters.
5306 "If it breaks, you get to keep both parts"
5307 (Your code is broken if you don't put them back together again
5308 before something notices.) */
5309 if (SvUTF8(upstream)) {
5312 SvCUR_set(upstream, got_len - cached_len);
5314 /* Can't yet be EOF */
5319 /* If they are at EOF but buf_sv has something in it, then they may never
5320 have touched the SV upstream, so it may be undefined. If we naively
5321 concatenate it then we get a warning about use of uninitialised value.
5323 if (upstream != buf_sv && (SvOK(upstream) || SvGMAGICAL(upstream))) {
5324 sv_catsv(buf_sv, upstream);
5328 IoLINES(datasv) = 0;
5330 SvREFCNT_dec(filter_state);
5331 IoTOP_GV(datasv) = NULL;
5334 SvREFCNT_dec(filter_sub);
5335 IoBOTTOM_GV(datasv) = NULL;
5337 filter_del(S_run_user_filter);
5339 if (status == 0 && read_from_cache) {
5340 /* If we read some data from the cache (and by getting here it implies
5341 that we emptied the cache) then we aren't yet at EOF, and mustn't
5342 report that to our caller. */
5348 /* perhaps someone can come up with a better name for
5349 this? it is not really "absolute", per se ... */
5351 S_path_is_absolute(const char *name)
5353 PERL_ARGS_ASSERT_PATH_IS_ABSOLUTE;
5355 if (PERL_FILE_IS_ABSOLUTE(name)
5357 || (*name == '.' && ((name[1] == '/' ||
5358 (name[1] == '.' && name[2] == '/'))
5359 || (name[1] == '\\' ||
5360 ( name[1] == '.' && name[2] == '\\')))
5363 || (*name == '.' && (name[1] == '/' ||
5364 (name[1] == '.' && name[2] == '/')))
5376 * c-indentation-style: bsd
5378 * indent-tabs-mode: t
5381 * ex: set ts=8 sts=4 sw=4 noet: