3 * Copyright (c) 1991-2002, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * Now far ahead the Road has gone,
12 * And I must follow, if I can,
13 * Pursuing it with eager feet,
14 * Until it joins some larger way
15 * Where many paths and errands meet.
16 * And whither then? I cannot say.
20 #define PERL_IN_PP_CTL_C
24 #define WORD_ALIGN sizeof(U16)
27 #define DOCATCH(o) ((CATCH_GET == TRUE) ? docatch(o) : (o))
29 static I32 run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen);
37 cxix = dopoptosub(cxstack_ix);
41 switch (cxstack[cxix].blk_gimme) {
58 /* XXXX Should store the old value to allow for tie/overload - and
59 restore in regcomp, where marked with XXXX. */
67 register PMOP *pm = (PMOP*)cLOGOP->op_other;
71 MAGIC *mg = Null(MAGIC*);
75 /* prevent recompiling under /o and ithreads. */
76 #if defined(USE_ITHREADS)
77 if (pm->op_pmflags & PMf_KEEP && PM_GETRE(pm))
82 SV *sv = SvRV(tmpstr);
84 mg = mg_find(sv, PERL_MAGIC_qr);
87 regexp *re = (regexp *)mg->mg_obj;
88 ReREFCNT_dec(PM_GETRE(pm));
89 PM_SETRE(pm, ReREFCNT_inc(re));
92 t = SvPV(tmpstr, len);
94 /* Check against the last compiled regexp. */
95 if (!PM_GETRE(pm) || !PM_GETRE(pm)->precomp ||
96 PM_GETRE(pm)->prelen != (I32)len ||
97 memNE(PM_GETRE(pm)->precomp, t, len))
100 ReREFCNT_dec(PM_GETRE(pm));
101 PM_SETRE(pm, Null(REGEXP*)); /* crucial if regcomp aborts */
103 if (PL_op->op_flags & OPf_SPECIAL)
104 PL_reginterp_cnt = I32_MAX; /* Mark as safe. */
106 pm->op_pmflags = pm->op_pmpermflags; /* reset case sensitivity */
108 pm->op_pmdynflags |= PMdf_DYN_UTF8;
110 pm->op_pmdynflags &= ~PMdf_DYN_UTF8;
111 if (pm->op_pmdynflags & PMdf_UTF8)
112 t = (char*)bytes_to_utf8((U8*)t, &len);
114 PM_SETRE(pm, CALLREGCOMP(aTHX_ t, t + len, pm));
115 if (!DO_UTF8(tmpstr) && (pm->op_pmdynflags & PMdf_UTF8))
117 PL_reginterp_cnt = 0; /* XXXX Be extra paranoid - needed
118 inside tie/overload accessors. */
122 #ifndef INCOMPLETE_TAINTS
125 pm->op_pmdynflags |= PMdf_TAINTED;
127 pm->op_pmdynflags &= ~PMdf_TAINTED;
131 if (!PM_GETRE(pm)->prelen && PL_curpm)
133 else if (strEQ("\\s+", PM_GETRE(pm)->precomp))
134 pm->op_pmflags |= PMf_WHITE;
136 pm->op_pmflags &= ~PMf_WHITE;
138 /* XXX runtime compiled output needs to move to the pad */
139 if (pm->op_pmflags & PMf_KEEP) {
140 pm->op_private &= ~OPpRUNTIME; /* no point compiling again */
141 #if !defined(USE_ITHREADS)
142 /* XXX can't change the optree at runtime either */
143 cLOGOP->op_first->op_next = PL_op->op_next;
152 register PMOP *pm = (PMOP*) cLOGOP->op_other;
153 register PERL_CONTEXT *cx = &cxstack[cxstack_ix];
154 register SV *dstr = cx->sb_dstr;
155 register char *s = cx->sb_s;
156 register char *m = cx->sb_m;
157 char *orig = cx->sb_orig;
158 register REGEXP *rx = cx->sb_rx;
161 rxres_restore(&cx->sb_rxres, rx);
162 RX_MATCH_UTF8_set(rx, SvUTF8(cx->sb_targ));
164 if (cx->sb_iters++) {
165 I32 saviters = cx->sb_iters;
166 if (cx->sb_iters > cx->sb_maxiters)
167 DIE(aTHX_ "Substitution loop");
169 if (!(cx->sb_rxtainted & 2) && SvTAINTED(TOPs))
170 cx->sb_rxtainted |= 2;
171 sv_catsv(dstr, POPs);
174 if (cx->sb_once || !CALLREGEXEC(aTHX_ rx, s, cx->sb_strend, orig,
175 s == m, cx->sb_targ, NULL,
176 ((cx->sb_rflags & REXEC_COPY_STR)
177 ? (REXEC_IGNOREPOS|REXEC_NOT_FIRST)
178 : (REXEC_COPY_STR|REXEC_IGNOREPOS|REXEC_NOT_FIRST))))
180 SV *targ = cx->sb_targ;
182 if (DO_UTF8(dstr) && !SvUTF8(targ))
183 sv_catpvn_utf8_upgrade(dstr, s, cx->sb_strend - s, nsv);
185 sv_catpvn(dstr, s, cx->sb_strend - s);
186 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
188 #ifdef PERL_COPY_ON_WRITE
190 sv_force_normal_flags(targ, SV_COW_DROP_PV);
194 (void)SvOOK_off(targ);
196 Safefree(SvPVX(targ));
198 SvPVX(targ) = SvPVX(dstr);
199 SvCUR_set(targ, SvCUR(dstr));
200 SvLEN_set(targ, SvLEN(dstr));
206 TAINT_IF(cx->sb_rxtainted & 1);
207 PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
209 (void)SvPOK_only_UTF8(targ);
210 TAINT_IF(cx->sb_rxtainted);
214 LEAVE_SCOPE(cx->sb_oldsave);
216 RETURNOP(pm->op_next);
218 cx->sb_iters = saviters;
220 if (RX_MATCH_COPIED(rx) && rx->subbeg != orig) {
223 cx->sb_orig = orig = rx->subbeg;
225 cx->sb_strend = s + (cx->sb_strend - m);
227 cx->sb_m = m = rx->startp[0] + orig;
229 if (DO_UTF8(dstr) && !SvUTF8(cx->sb_targ))
230 sv_catpvn_utf8_upgrade(dstr, s, m - s, nsv);
232 sv_catpvn(dstr, s, m-s);
234 cx->sb_s = rx->endp[0] + orig;
235 { /* Update the pos() information. */
236 SV *sv = cx->sb_targ;
239 if (SvTYPE(sv) < SVt_PVMG)
240 (void)SvUPGRADE(sv, SVt_PVMG);
241 if (!(mg = mg_find(sv, PERL_MAGIC_regex_global))) {
242 sv_magic(sv, Nullsv, PERL_MAGIC_regex_global, Nullch, 0);
243 mg = mg_find(sv, PERL_MAGIC_regex_global);
250 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
251 rxres_save(&cx->sb_rxres, rx);
252 RETURNOP(pm->op_pmreplstart);
256 Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx)
261 if (!p || p[1] < rx->nparens) {
262 #ifdef PERL_COPY_ON_WRITE
263 i = 7 + rx->nparens * 2;
265 i = 6 + rx->nparens * 2;
274 *p++ = PTR2UV(RX_MATCH_COPIED(rx) ? rx->subbeg : Nullch);
275 RX_MATCH_COPIED_off(rx);
277 #ifdef PERL_COPY_ON_WRITE
278 *p++ = PTR2UV(rx->saved_copy);
279 rx->saved_copy = Nullsv;
284 *p++ = PTR2UV(rx->subbeg);
285 *p++ = (UV)rx->sublen;
286 for (i = 0; i <= rx->nparens; ++i) {
287 *p++ = (UV)rx->startp[i];
288 *p++ = (UV)rx->endp[i];
293 Perl_rxres_restore(pTHX_ void **rsp, REGEXP *rx)
298 RX_MATCH_COPY_FREE(rx);
299 RX_MATCH_COPIED_set(rx, *p);
302 #ifdef PERL_COPY_ON_WRITE
304 SvREFCNT_dec (rx->saved_copy);
305 rx->saved_copy = INT2PTR(SV*,*p);
311 rx->subbeg = INT2PTR(char*,*p++);
312 rx->sublen = (I32)(*p++);
313 for (i = 0; i <= rx->nparens; ++i) {
314 rx->startp[i] = (I32)(*p++);
315 rx->endp[i] = (I32)(*p++);
320 Perl_rxres_free(pTHX_ void **rsp)
325 Safefree(INT2PTR(char*,*p));
326 #ifdef PERL_COPY_ON_WRITE
328 SvREFCNT_dec (INT2PTR(SV*,p[1]));
338 dSP; dMARK; dORIGMARK;
339 register SV *tmpForm = *++MARK;
346 register SV *sv = Nullsv;
351 bool chopspace = (strchr(PL_chopset, ' ') != Nullch);
352 char *chophere = Nullch;
353 char *linemark = Nullch;
355 bool gotsome = FALSE;
357 STRLEN fudge = SvCUR(tmpForm) * (IN_BYTES ? 1 : 3) + 1;
358 bool item_is_utf = FALSE;
360 if (!SvMAGICAL(tmpForm) || !SvCOMPILED(tmpForm)) {
361 if (SvREADONLY(tmpForm)) {
362 SvREADONLY_off(tmpForm);
363 doparseform(tmpForm);
364 SvREADONLY_on(tmpForm);
367 doparseform(tmpForm);
370 SvPV_force(PL_formtarget, len);
371 t = SvGROW(PL_formtarget, len + fudge + 1); /* XXX SvCUR bad */
373 f = SvPV(tmpForm, len);
374 /* need to jump to the next word */
375 s = f + len + WORD_ALIGN - SvCUR(tmpForm) % WORD_ALIGN;
384 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
385 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
386 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
387 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
388 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
390 case FF_CHECKNL: name = "CHECKNL"; break;
391 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
392 case FF_SPACE: name = "SPACE"; break;
393 case FF_HALFSPACE: name = "HALFSPACE"; break;
394 case FF_ITEM: name = "ITEM"; break;
395 case FF_CHOP: name = "CHOP"; break;
396 case FF_LINEGLOB: name = "LINEGLOB"; break;
397 case FF_NEWLINE: name = "NEWLINE"; break;
398 case FF_MORE: name = "MORE"; break;
399 case FF_LINEMARK: name = "LINEMARK"; break;
400 case FF_END: name = "END"; break;
401 case FF_0DECIMAL: name = "0DECIMAL"; break;
404 PerlIO_printf(Perl_debug_log, "%-16s%ld\n", name, (long) arg);
406 PerlIO_printf(Perl_debug_log, "%-16s\n", name);
434 if (ckWARN(WARN_SYNTAX))
435 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Not enough format arguments");
440 item = s = SvPV(sv, len);
443 itemsize = sv_len_utf8(sv);
444 if (itemsize != (I32)len) {
446 if (itemsize > fieldsize) {
447 itemsize = fieldsize;
448 itembytes = itemsize;
449 sv_pos_u2b(sv, &itembytes, 0);
453 send = chophere = s + itembytes;
463 sv_pos_b2u(sv, &itemsize);
468 if (itemsize > fieldsize)
469 itemsize = fieldsize;
470 send = chophere = s + itemsize;
482 item = s = SvPV(sv, len);
485 itemsize = sv_len_utf8(sv);
486 if (itemsize != (I32)len) {
488 if (itemsize <= fieldsize) {
489 send = chophere = s + itemsize;
500 itemsize = fieldsize;
501 itembytes = itemsize;
502 sv_pos_u2b(sv, &itembytes, 0);
503 send = chophere = s + itembytes;
504 while (s < send || (s == send && isSPACE(*s))) {
514 if (strchr(PL_chopset, *s))
519 itemsize = chophere - item;
520 sv_pos_b2u(sv, &itemsize);
527 if (itemsize <= fieldsize) {
528 send = chophere = s + itemsize;
539 itemsize = fieldsize;
540 send = chophere = s + itemsize;
541 while (s < send || (s == send && isSPACE(*s))) {
551 if (strchr(PL_chopset, *s))
556 itemsize = chophere - item;
561 arg = fieldsize - itemsize;
570 arg = fieldsize - itemsize;
584 if (UTF8_IS_CONTINUED(*s)) {
585 STRLEN skip = UTF8SKIP(s);
602 if ( !((*t++ = *s++) & ~31) )
610 int ch = *t++ = *s++;
613 if ( !((*t++ = *s++) & ~31) )
622 while (*s && isSPACE(*s))
629 item = s = SvPV(sv, len);
631 item_is_utf = FALSE; /* XXX is this correct? */
643 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
644 sv_catpvn(PL_formtarget, item, itemsize);
645 SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
646 t = SvPVX(PL_formtarget) + SvCUR(PL_formtarget);
651 /* If the field is marked with ^ and the value is undefined,
654 if ((arg & 512) && !SvOK(sv)) {
662 /* Formats aren't yet marked for locales, so assume "yes". */
664 STORE_NUMERIC_STANDARD_SET_LOCAL();
665 #if defined(USE_LONG_DOUBLE)
667 sprintf(t, "%#*.*" PERL_PRIfldbl,
668 (int) fieldsize, (int) arg & 255, value);
670 sprintf(t, "%*.0" PERL_PRIfldbl, (int) fieldsize, value);
675 (int) fieldsize, (int) arg & 255, value);
678 (int) fieldsize, value);
681 RESTORE_NUMERIC_STANDARD();
687 /* If the field is marked with ^ and the value is undefined,
690 if ((arg & 512) && !SvOK(sv)) {
698 /* Formats aren't yet marked for locales, so assume "yes". */
700 STORE_NUMERIC_STANDARD_SET_LOCAL();
701 #if defined(USE_LONG_DOUBLE)
703 sprintf(t, "%#0*.*" PERL_PRIfldbl,
704 (int) fieldsize, (int) arg & 255, value);
705 /* is this legal? I don't have long doubles */
707 sprintf(t, "%0*.0" PERL_PRIfldbl, (int) fieldsize, value);
711 sprintf(t, "%#0*.*f",
712 (int) fieldsize, (int) arg & 255, value);
715 (int) fieldsize, value);
718 RESTORE_NUMERIC_STANDARD();
725 while (t-- > linemark && *t == ' ') ;
733 if (arg) { /* repeat until fields exhausted? */
735 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
736 lines += FmLINES(PL_formtarget);
739 if (strnEQ(linemark, linemark - arg, arg))
740 DIE(aTHX_ "Runaway format");
742 FmLINES(PL_formtarget) = lines;
744 RETURNOP(cLISTOP->op_first);
757 while (*s && isSPACE(*s) && s < send)
761 arg = fieldsize - itemsize;
768 if (strnEQ(s," ",3)) {
769 while (s > SvPVX(PL_formtarget) && isSPACE(s[-1]))
780 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
781 FmLINES(PL_formtarget) += lines;
793 if (PL_stack_base + *PL_markstack_ptr == SP) {
795 if (GIMME_V == G_SCALAR)
796 XPUSHs(sv_2mortal(newSViv(0)));
797 RETURNOP(PL_op->op_next->op_next);
799 PL_stack_sp = PL_stack_base + *PL_markstack_ptr + 1;
800 pp_pushmark(); /* push dst */
801 pp_pushmark(); /* push src */
802 ENTER; /* enter outer scope */
805 /* SAVE_DEFSV does *not* suffice here for USE_5005THREADS */
807 ENTER; /* enter inner scope */
810 src = PL_stack_base[*PL_markstack_ptr];
815 if (PL_op->op_type == OP_MAPSTART)
816 pp_pushmark(); /* push top */
817 return ((LOGOP*)PL_op->op_next)->op_other;
822 DIE(aTHX_ "panic: mapstart"); /* uses grepstart */
828 I32 items = (SP - PL_stack_base) - *PL_markstack_ptr; /* how many new items */
834 /* first, move source pointer to the next item in the source list */
835 ++PL_markstack_ptr[-1];
837 /* if there are new items, push them into the destination list */
839 /* might need to make room back there first */
840 if (items > PL_markstack_ptr[-1] - PL_markstack_ptr[-2]) {
841 /* XXX this implementation is very pessimal because the stack
842 * is repeatedly extended for every set of items. Is possible
843 * to do this without any stack extension or copying at all
844 * by maintaining a separate list over which the map iterates
845 * (like foreach does). --gsar */
847 /* everything in the stack after the destination list moves
848 * towards the end the stack by the amount of room needed */
849 shift = items - (PL_markstack_ptr[-1] - PL_markstack_ptr[-2]);
851 /* items to shift up (accounting for the moved source pointer) */
852 count = (SP - PL_stack_base) - (PL_markstack_ptr[-1] - 1);
854 /* This optimization is by Ben Tilly and it does
855 * things differently from what Sarathy (gsar)
856 * is describing. The downside of this optimization is
857 * that leaves "holes" (uninitialized and hopefully unused areas)
858 * to the Perl stack, but on the other hand this
859 * shouldn't be a problem. If Sarathy's idea gets
860 * implemented, this optimization should become
861 * irrelevant. --jhi */
863 shift = count; /* Avoid shifting too often --Ben Tilly */
868 PL_markstack_ptr[-1] += shift;
869 *PL_markstack_ptr += shift;
873 /* copy the new items down to the destination list */
874 dst = PL_stack_base + (PL_markstack_ptr[-2] += items) - 1;
876 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
878 LEAVE; /* exit inner scope */
881 if (PL_markstack_ptr[-1] > *PL_markstack_ptr) {
884 (void)POPMARK; /* pop top */
885 LEAVE; /* exit outer scope */
886 (void)POPMARK; /* pop src */
887 items = --*PL_markstack_ptr - PL_markstack_ptr[-1];
888 (void)POPMARK; /* pop dst */
889 SP = PL_stack_base + POPMARK; /* pop original mark */
890 if (gimme == G_SCALAR) {
894 else if (gimme == G_ARRAY)
901 ENTER; /* enter inner scope */
904 /* set $_ to the new source item */
905 src = PL_stack_base[PL_markstack_ptr[-1]];
909 RETURNOP(cLOGOP->op_other);
917 if (GIMME == G_ARRAY)
919 if (SvTRUEx(PAD_SV(PL_op->op_targ)))
920 return cLOGOP->op_other;
929 if (GIMME == G_ARRAY) {
930 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
934 SV *targ = PAD_SV(PL_op->op_targ);
937 if (PL_op->op_private & OPpFLIP_LINENUM) {
938 if (GvIO(PL_last_in_gv)) {
939 flip = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
942 GV *gv = gv_fetchpv(".", TRUE, SVt_PV);
943 if (gv && GvSV(gv)) flip = SvIV(sv) == SvIV(GvSV(gv));
949 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
950 if (PL_op->op_flags & OPf_SPECIAL) {
958 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
971 if (GIMME == G_ARRAY) {
977 if (SvGMAGICAL(left))
979 if (SvGMAGICAL(right))
982 /* This code tries to decide if "$left .. $right" should use the
983 magical string increment, or if the range is numeric (we make
984 an exception for .."0" [#18165]). AMS 20021031. */
986 if (SvNIOKp(left) || !SvPOKp(left) ||
987 SvNIOKp(right) || !SvPOKp(right) ||
988 (looks_like_number(left) && *SvPVX(left) != '0' &&
989 looks_like_number(right)))
991 if (SvNV(left) < IV_MIN || SvNV(right) > IV_MAX)
992 DIE(aTHX_ "Range iterator outside integer range");
1003 sv = sv_2mortal(newSViv(i++));
1008 SV *final = sv_mortalcopy(right);
1010 char *tmps = SvPV(final, len);
1012 sv = sv_mortalcopy(left);
1014 while (!SvNIOKp(sv) && SvCUR(sv) <= len) {
1016 if (strEQ(SvPVX(sv),tmps))
1018 sv = sv_2mortal(newSVsv(sv));
1025 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
1029 if (PL_op->op_private & OPpFLIP_LINENUM) {
1030 if (GvIO(PL_last_in_gv)) {
1031 flop = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
1034 GV *gv = gv_fetchpv(".", TRUE, SVt_PV);
1035 if (gv && GvSV(gv)) flop = SvIV(sv) == SvIV(GvSV(gv));
1043 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
1044 sv_catpv(targ, "E0");
1054 static char *context_name[] = {
1065 S_dopoptolabel(pTHX_ char *label)
1068 register PERL_CONTEXT *cx;
1070 for (i = cxstack_ix; i >= 0; i--) {
1072 switch (CxTYPE(cx)) {
1078 if (ckWARN(WARN_EXITING))
1079 Perl_warner(aTHX_ packWARN(WARN_EXITING), "Exiting %s via %s",
1080 context_name[CxTYPE(cx)], OP_NAME(PL_op));
1081 if (CxTYPE(cx) == CXt_NULL)
1085 if (!cx->blk_loop.label ||
1086 strNE(label, cx->blk_loop.label) ) {
1087 DEBUG_l(Perl_deb(aTHX_ "(Skipping label #%ld %s)\n",
1088 (long)i, cx->blk_loop.label));
1091 DEBUG_l( Perl_deb(aTHX_ "(Found label #%ld %s)\n", (long)i, label));
1099 Perl_dowantarray(pTHX)
1101 I32 gimme = block_gimme();
1102 return (gimme == G_VOID) ? G_SCALAR : gimme;
1106 Perl_block_gimme(pTHX)
1110 cxix = dopoptosub(cxstack_ix);
1114 switch (cxstack[cxix].blk_gimme) {
1122 Perl_croak(aTHX_ "panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
1129 Perl_is_lvalue_sub(pTHX)
1133 cxix = dopoptosub(cxstack_ix);
1134 assert(cxix >= 0); /* We should only be called from inside subs */
1136 if (cxstack[cxix].blk_sub.lval && CvLVALUE(cxstack[cxix].blk_sub.cv))
1137 return cxstack[cxix].blk_sub.lval;
1143 S_dopoptosub(pTHX_ I32 startingblock)
1145 return dopoptosub_at(cxstack, startingblock);
1149 S_dopoptosub_at(pTHX_ PERL_CONTEXT *cxstk, I32 startingblock)
1152 register PERL_CONTEXT *cx;
1153 for (i = startingblock; i >= 0; i--) {
1155 switch (CxTYPE(cx)) {
1161 DEBUG_l( Perl_deb(aTHX_ "(Found sub #%ld)\n", (long)i));
1169 S_dopoptoeval(pTHX_ I32 startingblock)
1172 register PERL_CONTEXT *cx;
1173 for (i = startingblock; i >= 0; i--) {
1175 switch (CxTYPE(cx)) {
1179 DEBUG_l( Perl_deb(aTHX_ "(Found eval #%ld)\n", (long)i));
1187 S_dopoptoloop(pTHX_ I32 startingblock)
1190 register PERL_CONTEXT *cx;
1191 for (i = startingblock; i >= 0; i--) {
1193 switch (CxTYPE(cx)) {
1199 if (ckWARN(WARN_EXITING))
1200 Perl_warner(aTHX_ packWARN(WARN_EXITING), "Exiting %s via %s",
1201 context_name[CxTYPE(cx)], OP_NAME(PL_op));
1202 if ((CxTYPE(cx)) == CXt_NULL)
1206 DEBUG_l( Perl_deb(aTHX_ "(Found loop #%ld)\n", (long)i));
1214 Perl_dounwind(pTHX_ I32 cxix)
1216 register PERL_CONTEXT *cx;
1219 while (cxstack_ix > cxix) {
1221 cx = &cxstack[cxstack_ix];
1222 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n",
1223 (long) cxstack_ix, PL_block_type[CxTYPE(cx)]));
1224 /* Note: we don't need to restore the base context info till the end. */
1225 switch (CxTYPE(cx)) {
1228 continue; /* not break */
1250 Perl_qerror(pTHX_ SV *err)
1253 sv_catsv(ERRSV, err);
1255 sv_catsv(PL_errors, err);
1257 Perl_warn(aTHX_ "%"SVf, err);
1262 Perl_die_where(pTHX_ char *message, STRLEN msglen)
1270 register PERL_CONTEXT *cx;
1275 if (PL_in_eval & EVAL_KEEPERR) {
1276 static char prefix[] = "\t(in cleanup) ";
1281 else if (SvCUR(err) >= sizeof(prefix)+msglen-1) {
1284 if (*e != *message || strNE(e,message))
1288 SvGROW(err, SvCUR(err)+sizeof(prefix)+msglen);
1289 sv_catpvn(err, prefix, sizeof(prefix)-1);
1290 sv_catpvn(err, message, msglen);
1291 if (ckWARN(WARN_MISC)) {
1292 STRLEN start = SvCUR(err)-msglen-sizeof(prefix)+1;
1293 Perl_warner(aTHX_ packWARN(WARN_MISC), SvPVX(err)+start);
1298 sv_setpvn(ERRSV, message, msglen);
1302 message = SvPVx(ERRSV, msglen);
1304 while ((cxix = dopoptoeval(cxstack_ix)) < 0
1305 && PL_curstackinfo->si_prev)
1314 if (cxix < cxstack_ix)
1317 POPBLOCK(cx,PL_curpm);
1318 if (CxTYPE(cx) != CXt_EVAL) {
1319 PerlIO_write(Perl_error_log, "panic: die ", 11);
1320 PerlIO_write(Perl_error_log, message, msglen);
1325 if (gimme == G_SCALAR)
1326 *++newsp = &PL_sv_undef;
1327 PL_stack_sp = newsp;
1331 /* LEAVE could clobber PL_curcop (see save_re_context())
1332 * XXX it might be better to find a way to avoid messing with
1333 * PL_curcop in save_re_context() instead, but this is a more
1334 * minimal fix --GSAR */
1335 PL_curcop = cx->blk_oldcop;
1337 if (optype == OP_REQUIRE) {
1338 char* msg = SvPVx(ERRSV, n_a);
1339 DIE(aTHX_ "%sCompilation failed in require",
1340 *msg ? msg : "Unknown error\n");
1342 return pop_return();
1346 message = SvPVx(ERRSV, msglen);
1348 /* if STDERR is tied, print to it instead */
1349 if (PL_stderrgv && (io = GvIOp(PL_stderrgv))
1350 && (mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar))) {
1353 XPUSHs(SvTIED_obj((SV*)io, mg));
1354 XPUSHs(sv_2mortal(newSVpvn(message, msglen)));
1356 call_method("PRINT", G_SCALAR);
1361 /* SFIO can really mess with your errno */
1364 PerlIO *serr = Perl_error_log;
1366 PERL_WRITE_MSG_TO_CONSOLE(serr, message, msglen);
1367 (void)PerlIO_flush(serr);
1380 if (SvTRUE(left) != SvTRUE(right))
1392 RETURNOP(cLOGOP->op_other);
1401 RETURNOP(cLOGOP->op_other);
1410 if (!sv || !SvANY(sv)) {
1411 RETURNOP(cLOGOP->op_other);
1414 switch (SvTYPE(sv)) {
1416 if (AvMAX(sv) >= 0 || SvGMAGICAL(sv) || (SvRMAGICAL(sv) && mg_find(sv, PERL_MAGIC_tied)))
1420 if (HvARRAY(sv) || SvGMAGICAL(sv) || (SvRMAGICAL(sv) && mg_find(sv, PERL_MAGIC_tied)))
1424 if (CvROOT(sv) || CvXSUB(sv))
1434 RETURNOP(cLOGOP->op_other);
1440 register I32 cxix = dopoptosub(cxstack_ix);
1441 register PERL_CONTEXT *cx;
1442 register PERL_CONTEXT *ccstack = cxstack;
1443 PERL_SI *top_si = PL_curstackinfo;
1454 /* we may be in a higher stacklevel, so dig down deeper */
1455 while (cxix < 0 && top_si->si_type != PERLSI_MAIN) {
1456 top_si = top_si->si_prev;
1457 ccstack = top_si->si_cxstack;
1458 cxix = dopoptosub_at(ccstack, top_si->si_cxix);
1461 if (GIMME != G_ARRAY) {
1467 if (PL_DBsub && cxix >= 0 &&
1468 ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub))
1472 cxix = dopoptosub_at(ccstack, cxix - 1);
1475 cx = &ccstack[cxix];
1476 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1477 dbcxix = dopoptosub_at(ccstack, cxix - 1);
1478 /* We expect that ccstack[dbcxix] is CXt_SUB, anyway, the
1479 field below is defined for any cx. */
1480 if (PL_DBsub && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub))
1481 cx = &ccstack[dbcxix];
1484 stashname = CopSTASHPV(cx->blk_oldcop);
1485 if (GIMME != G_ARRAY) {
1488 PUSHs(&PL_sv_undef);
1491 sv_setpv(TARG, stashname);
1500 PUSHs(&PL_sv_undef);
1502 PUSHs(sv_2mortal(newSVpv(stashname, 0)));
1503 PUSHs(sv_2mortal(newSVpv(OutCopFILE(cx->blk_oldcop), 0)));
1504 PUSHs(sv_2mortal(newSViv((I32)CopLINE(cx->blk_oldcop))));
1507 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1508 GV *cvgv = CvGV(ccstack[cxix].blk_sub.cv);
1509 /* So is ccstack[dbcxix]. */
1512 gv_efullname3(sv, cvgv, Nullch);
1513 PUSHs(sv_2mortal(sv));
1514 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1517 PUSHs(sv_2mortal(newSVpvn("(unknown)",9)));
1518 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1522 PUSHs(sv_2mortal(newSVpvn("(eval)",6)));
1523 PUSHs(sv_2mortal(newSViv(0)));
1525 gimme = (I32)cx->blk_gimme;
1526 if (gimme == G_VOID)
1527 PUSHs(&PL_sv_undef);
1529 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1530 if (CxTYPE(cx) == CXt_EVAL) {
1532 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1533 PUSHs(cx->blk_eval.cur_text);
1537 else if (cx->blk_eval.old_namesv) {
1538 PUSHs(sv_2mortal(newSVsv(cx->blk_eval.old_namesv)));
1541 /* eval BLOCK (try blocks have old_namesv == 0) */
1543 PUSHs(&PL_sv_undef);
1544 PUSHs(&PL_sv_undef);
1548 PUSHs(&PL_sv_undef);
1549 PUSHs(&PL_sv_undef);
1551 if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.hasargs
1552 && CopSTASH_eq(PL_curcop, PL_debstash))
1554 AV *ary = cx->blk_sub.argarray;
1555 int off = AvARRAY(ary) - AvALLOC(ary);
1559 PL_dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1562 AvREAL_off(PL_dbargs); /* XXX should be REIFY (see av.h) */
1565 if (AvMAX(PL_dbargs) < AvFILLp(ary) + off)
1566 av_extend(PL_dbargs, AvFILLp(ary) + off);
1567 Copy(AvALLOC(ary), AvARRAY(PL_dbargs), AvFILLp(ary) + 1 + off, SV*);
1568 AvFILLp(PL_dbargs) = AvFILLp(ary) + off;
1570 /* XXX only hints propagated via op_private are currently
1571 * visible (others are not easily accessible, since they
1572 * use the global PL_hints) */
1573 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->op_private &
1574 HINT_PRIVATE_MASK)));
1577 SV * old_warnings = cx->blk_oldcop->cop_warnings ;
1579 if (old_warnings == pWARN_NONE ||
1580 (old_warnings == pWARN_STD && (PL_dowarn & G_WARN_ON) == 0))
1581 mask = newSVpvn(WARN_NONEstring, WARNsize) ;
1582 else if (old_warnings == pWARN_ALL ||
1583 (old_warnings == pWARN_STD && PL_dowarn & G_WARN_ON))
1584 mask = newSVpvn(WARN_ALLstring, WARNsize) ;
1586 mask = newSVsv(old_warnings);
1587 PUSHs(sv_2mortal(mask));
1602 sv_reset(tmps, CopSTASH(PL_curcop));
1612 /* like pp_nextstate, but used instead when the debugger is active */
1616 PL_curcop = (COP*)PL_op;
1617 TAINT_NOT; /* Each statement is presumed innocent */
1618 PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
1621 if (PL_op->op_flags & OPf_SPECIAL /* breakpoint */
1622 || SvIV(PL_DBsingle) || SvIV(PL_DBsignal) || SvIV(PL_DBtrace))
1626 register PERL_CONTEXT *cx;
1627 I32 gimme = G_ARRAY;
1634 DIE(aTHX_ "No DB::DB routine defined");
1636 if (CvDEPTH(cv) >= 1 && !(PL_debug & DEBUG_DB_RECURSE_FLAG))
1637 /* don't do recursive DB::DB call */
1649 push_return(PL_op->op_next);
1650 PUSHBLOCK(cx, CXt_SUB, SP);
1653 (void)SvREFCNT_inc(cv);
1654 PAD_SET_CUR(CvPADLIST(cv),1);
1655 RETURNOP(CvSTART(cv));
1669 register PERL_CONTEXT *cx;
1670 I32 gimme = GIMME_V;
1672 U32 cxtype = CXt_LOOP;
1680 if (PL_op->op_targ) {
1681 #ifndef USE_ITHREADS
1682 svp = &PAD_SVl(PL_op->op_targ); /* "my" variable */
1685 SAVEPADSV(PL_op->op_targ);
1686 iterdata = INT2PTR(void*, PL_op->op_targ);
1687 cxtype |= CXp_PADVAR;
1692 svp = &GvSV(gv); /* symbol table variable */
1693 SAVEGENERICSV(*svp);
1696 iterdata = (void*)gv;
1702 PUSHBLOCK(cx, cxtype, SP);
1704 PUSHLOOP(cx, iterdata, MARK);
1706 PUSHLOOP(cx, svp, MARK);
1708 if (PL_op->op_flags & OPf_STACKED) {
1709 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1710 if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) {
1712 /* See comment in pp_flop() */
1713 if (SvNIOKp(sv) || !SvPOKp(sv) ||
1714 SvNIOKp(cx->blk_loop.iterary) || !SvPOKp(cx->blk_loop.iterary) ||
1715 (looks_like_number(sv) && *SvPVX(sv) != '0' &&
1716 looks_like_number((SV*)cx->blk_loop.iterary)))
1718 if (SvNV(sv) < IV_MIN ||
1719 SvNV((SV*)cx->blk_loop.iterary) >= IV_MAX)
1720 DIE(aTHX_ "Range iterator outside integer range");
1721 cx->blk_loop.iterix = SvIV(sv);
1722 cx->blk_loop.itermax = SvIV((SV*)cx->blk_loop.iterary);
1725 cx->blk_loop.iterlval = newSVsv(sv);
1729 cx->blk_loop.iterary = PL_curstack;
1730 AvFILLp(PL_curstack) = SP - PL_stack_base;
1731 cx->blk_loop.iterix = MARK - PL_stack_base;
1740 register PERL_CONTEXT *cx;
1741 I32 gimme = GIMME_V;
1747 PUSHBLOCK(cx, CXt_LOOP, SP);
1748 PUSHLOOP(cx, 0, SP);
1756 register PERL_CONTEXT *cx;
1764 newsp = PL_stack_base + cx->blk_loop.resetsp;
1767 if (gimme == G_VOID)
1769 else if (gimme == G_SCALAR) {
1771 *++newsp = sv_mortalcopy(*SP);
1773 *++newsp = &PL_sv_undef;
1777 *++newsp = sv_mortalcopy(*++mark);
1778 TAINT_NOT; /* Each item is independent */
1784 POPLOOP(cx); /* Stack values are safe: release loop vars ... */
1785 PL_curpm = newpm; /* ... and pop $1 et al */
1797 register PERL_CONTEXT *cx;
1798 bool popsub2 = FALSE;
1799 bool clear_errsv = FALSE;
1806 if (PL_curstackinfo->si_type == PERLSI_SORT) {
1807 if (cxstack_ix == PL_sortcxix
1808 || dopoptosub(cxstack_ix) <= PL_sortcxix)
1810 if (cxstack_ix > PL_sortcxix)
1811 dounwind(PL_sortcxix);
1812 AvARRAY(PL_curstack)[1] = *SP;
1813 PL_stack_sp = PL_stack_base + 1;
1818 cxix = dopoptosub(cxstack_ix);
1820 DIE(aTHX_ "Can't return outside a subroutine");
1821 if (cxix < cxstack_ix)
1825 switch (CxTYPE(cx)) {
1830 if (!(PL_in_eval & EVAL_KEEPERR))
1836 if (optype == OP_REQUIRE &&
1837 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1839 /* Unassume the success we assumed earlier. */
1840 SV *nsv = cx->blk_eval.old_namesv;
1841 (void)hv_delete(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), G_DISCARD);
1842 DIE(aTHX_ "%"SVf" did not return a true value", nsv);
1849 DIE(aTHX_ "panic: return");
1853 if (gimme == G_SCALAR) {
1856 if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
1858 *++newsp = SvREFCNT_inc(*SP);
1863 sv = SvREFCNT_inc(*SP); /* FREETMPS could clobber it */
1865 *++newsp = sv_mortalcopy(sv);
1870 *++newsp = (SvTEMP(*SP)) ? *SP : sv_mortalcopy(*SP);
1873 *++newsp = sv_mortalcopy(*SP);
1876 *++newsp = &PL_sv_undef;
1878 else if (gimme == G_ARRAY) {
1879 while (++MARK <= SP) {
1880 *++newsp = (popsub2 && SvTEMP(*MARK))
1881 ? *MARK : sv_mortalcopy(*MARK);
1882 TAINT_NOT; /* Each item is independent */
1885 PL_stack_sp = newsp;
1887 /* Stack values are safe: */
1889 POPSUB(cx,sv); /* release CV and @_ ... */
1893 PL_curpm = newpm; /* ... and pop $1 et al */
1899 return pop_return();
1906 register PERL_CONTEXT *cx;
1916 if (PL_op->op_flags & OPf_SPECIAL) {
1917 cxix = dopoptoloop(cxstack_ix);
1919 DIE(aTHX_ "Can't \"last\" outside a loop block");
1922 cxix = dopoptolabel(cPVOP->op_pv);
1924 DIE(aTHX_ "Label not found for \"last %s\"", cPVOP->op_pv);
1926 if (cxix < cxstack_ix)
1931 switch (CxTYPE(cx)) {
1934 newsp = PL_stack_base + cx->blk_loop.resetsp;
1935 nextop = cx->blk_loop.last_op->op_next;
1939 nextop = pop_return();
1943 nextop = pop_return();
1947 nextop = pop_return();
1950 DIE(aTHX_ "panic: last");
1954 if (gimme == G_SCALAR) {
1956 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
1957 ? *SP : sv_mortalcopy(*SP);
1959 *++newsp = &PL_sv_undef;
1961 else if (gimme == G_ARRAY) {
1962 while (++MARK <= SP) {
1963 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
1964 ? *MARK : sv_mortalcopy(*MARK);
1965 TAINT_NOT; /* Each item is independent */
1971 /* Stack values are safe: */
1974 POPLOOP(cx); /* release loop vars ... */
1978 POPSUB(cx,sv); /* release CV and @_ ... */
1981 PL_curpm = newpm; /* ... and pop $1 et al */
1991 register PERL_CONTEXT *cx;
1994 if (PL_op->op_flags & OPf_SPECIAL) {
1995 cxix = dopoptoloop(cxstack_ix);
1997 DIE(aTHX_ "Can't \"next\" outside a loop block");
2000 cxix = dopoptolabel(cPVOP->op_pv);
2002 DIE(aTHX_ "Label not found for \"next %s\"", cPVOP->op_pv);
2004 if (cxix < cxstack_ix)
2007 /* clear off anything above the scope we're re-entering, but
2008 * save the rest until after a possible continue block */
2009 inner = PL_scopestack_ix;
2011 if (PL_scopestack_ix < inner)
2012 leave_scope(PL_scopestack[PL_scopestack_ix]);
2013 return cx->blk_loop.next_op;
2019 register PERL_CONTEXT *cx;
2022 if (PL_op->op_flags & OPf_SPECIAL) {
2023 cxix = dopoptoloop(cxstack_ix);
2025 DIE(aTHX_ "Can't \"redo\" outside a loop block");
2028 cxix = dopoptolabel(cPVOP->op_pv);
2030 DIE(aTHX_ "Label not found for \"redo %s\"", cPVOP->op_pv);
2032 if (cxix < cxstack_ix)
2036 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2037 LEAVE_SCOPE(oldsave);
2038 return cx->blk_loop.redo_op;
2042 S_dofindlabel(pTHX_ OP *o, char *label, OP **opstack, OP **oplimit)
2046 static char too_deep[] = "Target of goto is too deeply nested";
2049 Perl_croak(aTHX_ too_deep);
2050 if (o->op_type == OP_LEAVE ||
2051 o->op_type == OP_SCOPE ||
2052 o->op_type == OP_LEAVELOOP ||
2053 o->op_type == OP_LEAVESUB ||
2054 o->op_type == OP_LEAVETRY)
2056 *ops++ = cUNOPo->op_first;
2058 Perl_croak(aTHX_ too_deep);
2061 if (o->op_flags & OPf_KIDS) {
2062 /* First try all the kids at this level, since that's likeliest. */
2063 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
2064 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
2065 kCOP->cop_label && strEQ(kCOP->cop_label, label))
2068 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
2069 if (kid == PL_lastgotoprobe)
2071 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
2074 else if (ops[-1]->op_type == OP_NEXTSTATE ||
2075 ops[-1]->op_type == OP_DBSTATE)
2080 if ((o = dofindlabel(kid, label, ops, oplimit)))
2099 register PERL_CONTEXT *cx;
2100 #define GOTO_DEPTH 64
2101 OP *enterops[GOTO_DEPTH];
2103 int do_dump = (PL_op->op_type == OP_DUMP);
2104 static char must_have_label[] = "goto must have label";
2107 if (PL_op->op_flags & OPf_STACKED) {
2111 /* This egregious kludge implements goto &subroutine */
2112 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
2114 register PERL_CONTEXT *cx;
2115 CV* cv = (CV*)SvRV(sv);
2121 if (!CvROOT(cv) && !CvXSUB(cv)) {
2126 /* autoloaded stub? */
2127 if (cv != GvCV(gv) && (cv = GvCV(gv)))
2129 autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv),
2130 GvNAMELEN(gv), FALSE);
2131 if (autogv && (cv = GvCV(autogv)))
2133 tmpstr = sv_newmortal();
2134 gv_efullname3(tmpstr, gv, Nullch);
2135 DIE(aTHX_ "Goto undefined subroutine &%"SVf"",tmpstr);
2137 DIE(aTHX_ "Goto undefined subroutine");
2140 /* First do some returnish stuff. */
2142 cxix = dopoptosub(cxstack_ix);
2144 DIE(aTHX_ "Can't goto subroutine outside a subroutine");
2145 if (cxix < cxstack_ix)
2149 DIE(aTHX_ "Can't goto subroutine from an eval-string");
2151 if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.hasargs) {
2152 /* put @_ back onto stack */
2153 AV* av = cx->blk_sub.argarray;
2155 items = AvFILLp(av) + 1;
2157 EXTEND(PL_stack_sp, items); /* @_ could have been extended. */
2158 Copy(AvARRAY(av), PL_stack_sp, items, SV*);
2159 PL_stack_sp += items;
2160 SvREFCNT_dec(GvAV(PL_defgv));
2161 GvAV(PL_defgv) = cx->blk_sub.savearray;
2162 /* abandon @_ if it got reified */
2164 (void)sv_2mortal((SV*)av); /* delay until return */
2166 av_extend(av, items-1);
2167 AvFLAGS(av) = AVf_REIFY;
2168 PAD_SVl(0) = (SV*)(cx->blk_sub.argarray = av);
2171 else if (CvXSUB(cv)) { /* put GvAV(defgv) back onto stack */
2173 av = GvAV(PL_defgv);
2174 items = AvFILLp(av) + 1;
2176 EXTEND(PL_stack_sp, items); /* @_ could have been extended. */
2177 Copy(AvARRAY(av), PL_stack_sp, items, SV*);
2178 PL_stack_sp += items;
2180 if (CxTYPE(cx) == CXt_SUB &&
2181 !(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
2182 SvREFCNT_dec(cx->blk_sub.cv);
2183 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2184 LEAVE_SCOPE(oldsave);
2186 /* Now do some callish stuff. */
2189 #ifdef PERL_XSUB_OLDSTYLE
2190 if (CvOLDSTYLE(cv)) {
2191 I32 (*fp3)(int,int,int);
2196 fp3 = (I32(*)(int,int,int))CvXSUB(cv);
2197 items = (*fp3)(CvXSUBANY(cv).any_i32,
2198 mark - PL_stack_base + 1,
2200 SP = PL_stack_base + items;
2203 #endif /* PERL_XSUB_OLDSTYLE */
2208 PL_stack_sp--; /* There is no cv arg. */
2209 /* Push a mark for the start of arglist */
2211 (void)(*CvXSUB(cv))(aTHX_ cv);
2212 /* Pop the current context like a decent sub should */
2213 POPBLOCK(cx, PL_curpm);
2214 /* Do _not_ use PUTBACK, keep the XSUB's return stack! */
2217 return pop_return();
2220 AV* padlist = CvPADLIST(cv);
2221 if (CxTYPE(cx) == CXt_EVAL) {
2222 PL_in_eval = cx->blk_eval.old_in_eval;
2223 PL_eval_root = cx->blk_eval.old_eval_root;
2224 cx->cx_type = CXt_SUB;
2225 cx->blk_sub.hasargs = 0;
2227 cx->blk_sub.cv = cv;
2228 cx->blk_sub.olddepth = (U16)CvDEPTH(cv);
2231 if (CvDEPTH(cv) < 2)
2232 (void)SvREFCNT_inc(cv);
2234 if (CvDEPTH(cv) == 100 && ckWARN(WARN_RECURSION))
2235 sub_crush_depth(cv);
2236 pad_push(padlist, CvDEPTH(cv), cx->blk_sub.hasargs);
2238 PAD_SET_CUR(padlist, CvDEPTH(cv));
2239 if (cx->blk_sub.hasargs)
2241 AV* av = (AV*)PAD_SVl(0);
2244 cx->blk_sub.savearray = GvAV(PL_defgv);
2245 GvAV(PL_defgv) = (AV*)SvREFCNT_inc(av);
2246 CX_CURPAD_SAVE(cx->blk_sub);
2247 cx->blk_sub.argarray = av;
2250 if (items >= AvMAX(av) + 1) {
2252 if (AvARRAY(av) != ary) {
2253 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
2254 SvPVX(av) = (char*)ary;
2256 if (items >= AvMAX(av) + 1) {
2257 AvMAX(av) = items - 1;
2258 Renew(ary,items+1,SV*);
2260 SvPVX(av) = (char*)ary;
2263 Copy(mark,AvARRAY(av),items,SV*);
2264 AvFILLp(av) = items - 1;
2265 assert(!AvREAL(av));
2272 if (PERLDB_SUB) { /* Checking curstash breaks DProf. */
2274 * We do not care about using sv to call CV;
2275 * it's for informational purposes only.
2277 SV *sv = GvSV(PL_DBsub);
2280 if (PERLDB_SUB_NN) {
2281 SvIVX(sv) = PTR2IV(cv); /* Already upgraded, saved */
2284 gv_efullname3(sv, CvGV(cv), Nullch);
2287 && (gotocv = get_cv("DB::goto", FALSE)) ) {
2288 PUSHMARK( PL_stack_sp );
2289 call_sv((SV*)gotocv, G_SCALAR | G_NODEBUG);
2293 RETURNOP(CvSTART(cv));
2297 label = SvPV(sv,n_a);
2298 if (!(do_dump || *label))
2299 DIE(aTHX_ must_have_label);
2302 else if (PL_op->op_flags & OPf_SPECIAL) {
2304 DIE(aTHX_ must_have_label);
2307 label = cPVOP->op_pv;
2309 if (label && *label) {
2311 bool leaving_eval = FALSE;
2312 bool in_block = FALSE;
2313 PERL_CONTEXT *last_eval_cx = 0;
2317 PL_lastgotoprobe = 0;
2319 for (ix = cxstack_ix; ix >= 0; ix--) {
2321 switch (CxTYPE(cx)) {
2323 leaving_eval = TRUE;
2324 if (CxREALEVAL(cx)) {
2325 gotoprobe = (last_eval_cx ?
2326 last_eval_cx->blk_eval.old_eval_root :
2331 /* else fall through */
2333 gotoprobe = cx->blk_oldcop->op_sibling;
2339 gotoprobe = cx->blk_oldcop->op_sibling;
2342 gotoprobe = PL_main_root;
2345 if (CvDEPTH(cx->blk_sub.cv)) {
2346 gotoprobe = CvROOT(cx->blk_sub.cv);
2352 DIE(aTHX_ "Can't \"goto\" out of a pseudo block");
2355 DIE(aTHX_ "panic: goto");
2356 gotoprobe = PL_main_root;
2360 retop = dofindlabel(gotoprobe, label,
2361 enterops, enterops + GOTO_DEPTH);
2365 PL_lastgotoprobe = gotoprobe;
2368 DIE(aTHX_ "Can't find label %s", label);
2370 /* if we're leaving an eval, check before we pop any frames
2371 that we're not going to punt, otherwise the error
2374 if (leaving_eval && *enterops && enterops[1]) {
2376 for (i = 1; enterops[i]; i++)
2377 if (enterops[i]->op_type == OP_ENTERITER)
2378 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2381 /* pop unwanted frames */
2383 if (ix < cxstack_ix) {
2390 oldsave = PL_scopestack[PL_scopestack_ix];
2391 LEAVE_SCOPE(oldsave);
2394 /* push wanted frames */
2396 if (*enterops && enterops[1]) {
2398 ix = enterops[1]->op_type == OP_ENTER && in_block ? 2 : 1;
2399 for (; enterops[ix]; ix++) {
2400 PL_op = enterops[ix];
2401 /* Eventually we may want to stack the needed arguments
2402 * for each op. For now, we punt on the hard ones. */
2403 if (PL_op->op_type == OP_ENTERITER)
2404 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2405 CALL_FPTR(PL_op->op_ppaddr)(aTHX);
2413 if (!retop) retop = PL_main_start;
2415 PL_restartop = retop;
2416 PL_do_undump = TRUE;
2420 PL_restartop = 0; /* hmm, must be GNU unexec().. */
2421 PL_do_undump = FALSE;
2437 if (anum == 1 && (PL_op->op_private & OPpEXIT_VMSISH))
2439 VMSISH_HUSHED = VMSISH_HUSHED || (PL_op->op_private & OPpHUSH_VMSISH);
2442 PL_exit_flags |= PERL_EXIT_EXPECTED;
2444 PUSHs(&PL_sv_undef);
2452 NV value = SvNVx(GvSV(cCOP->cop_gv));
2453 register I32 match = I_32(value);
2456 if (((NV)match) > value)
2457 --match; /* was fractional--truncate other way */
2459 match -= cCOP->uop.scop.scop_offset;
2462 else if (match > cCOP->uop.scop.scop_max)
2463 match = cCOP->uop.scop.scop_max;
2464 PL_op = cCOP->uop.scop.scop_next[match];
2474 PL_op = PL_op->op_next; /* can't assume anything */
2477 match = *(SvPVx(GvSV(cCOP->cop_gv), n_a)) & 255;
2478 match -= cCOP->uop.scop.scop_offset;
2481 else if (match > cCOP->uop.scop.scop_max)
2482 match = cCOP->uop.scop.scop_max;
2483 PL_op = cCOP->uop.scop.scop_next[match];
2492 S_save_lines(pTHX_ AV *array, SV *sv)
2494 register char *s = SvPVX(sv);
2495 register char *send = SvPVX(sv) + SvCUR(sv);
2497 register I32 line = 1;
2499 while (s && s < send) {
2500 SV *tmpstr = NEWSV(85,0);
2502 sv_upgrade(tmpstr, SVt_PVMG);
2503 t = strchr(s, '\n');
2509 sv_setpvn(tmpstr, s, t - s);
2510 av_store(array, line++, tmpstr);
2515 #ifdef PERL_FLEXIBLE_EXCEPTIONS
2517 S_docatch_body(pTHX_ va_list args)
2519 return docatch_body();
2524 S_docatch_body(pTHX)
2531 S_docatch(pTHX_ OP *o)
2536 volatile PERL_SI *cursi = PL_curstackinfo;
2540 assert(CATCH_GET == TRUE);
2544 /* Normally, the leavetry at the end of this block of ops will
2545 * pop an op off the return stack and continue there. By setting
2546 * the op to Nullop, we force an exit from the inner runops()
2549 retop = pop_return();
2550 push_return(Nullop);
2552 #ifdef PERL_FLEXIBLE_EXCEPTIONS
2554 CALLPROTECT(aTHX_ pcur_env, &ret, MEMBER_TO_FPTR(S_docatch_body));
2560 #ifndef PERL_FLEXIBLE_EXCEPTIONS
2566 /* die caught by an inner eval - continue inner loop */
2567 if (PL_restartop && cursi == PL_curstackinfo) {
2568 PL_op = PL_restartop;
2572 /* a die in this eval - continue in outer loop */
2588 Perl_sv_compile_2op(pTHX_ SV *sv, OP** startop, char *code, PAD** padp)
2589 /* sv Text to convert to OP tree. */
2590 /* startop op_free() this to undo. */
2591 /* code Short string id of the caller. */
2593 dSP; /* Make POPBLOCK work. */
2596 I32 gimme = 0; /* SUSPECT - INITIALZE TO WHAT? NI-S */
2600 char tbuf[TYPE_DIGITS(long) + 12 + 10];
2601 char *tmpbuf = tbuf;
2604 CV* runcv = Nullcv; /* initialise to avoid compiler warnings */
2609 /* switch to eval mode */
2611 if (PL_curcop == &PL_compiling) {
2612 SAVECOPSTASH_FREE(&PL_compiling);
2613 CopSTASH_set(&PL_compiling, PL_curstash);
2615 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
2616 SV *sv = sv_newmortal();
2617 Perl_sv_setpvf(aTHX_ sv, "_<(%.10seval %lu)[%s:%"IVdf"]",
2618 code, (unsigned long)++PL_evalseq,
2619 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
2623 sprintf(tmpbuf, "_<(%.10s_eval %lu)", code, (unsigned long)++PL_evalseq);
2624 SAVECOPFILE_FREE(&PL_compiling);
2625 CopFILE_set(&PL_compiling, tmpbuf+2);
2626 SAVECOPLINE(&PL_compiling);
2627 CopLINE_set(&PL_compiling, 1);
2628 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2629 deleting the eval's FILEGV from the stash before gv_check() runs
2630 (i.e. before run-time proper). To work around the coredump that
2631 ensues, we always turn GvMULTI_on for any globals that were
2632 introduced within evals. See force_ident(). GSAR 96-10-12 */
2633 safestr = savepv(tmpbuf);
2634 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
2636 #ifdef OP_IN_REGISTER
2641 PL_hints &= HINT_UTF8;
2643 /* we get here either during compilation, or via pp_regcomp at runtime */
2644 runtime = PL_op && (PL_op->op_type == OP_REGCOMP);
2646 runcv = find_runcv(NULL);
2649 PL_op->op_type = OP_ENTEREVAL;
2650 PL_op->op_flags = 0; /* Avoid uninit warning. */
2651 PUSHBLOCK(cx, CXt_EVAL|(PL_curcop == &PL_compiling ? 0 : CXp_REAL), SP);
2652 PUSHEVAL(cx, 0, Nullgv);
2655 rop = doeval(G_SCALAR, startop, runcv, PL_curcop->cop_seq);
2657 rop = doeval(G_SCALAR, startop, PL_compcv, PL_cop_seqmax);
2658 POPBLOCK(cx,PL_curpm);
2661 (*startop)->op_type = OP_NULL;
2662 (*startop)->op_ppaddr = PL_ppaddr[OP_NULL];
2664 /* XXX DAPM do this properly one year */
2665 *padp = (AV*)SvREFCNT_inc(PL_comppad);
2667 if (PL_curcop == &PL_compiling)
2668 PL_compiling.op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);
2669 #ifdef OP_IN_REGISTER
2677 =for apidoc find_runcv
2679 Locate the CV corresponding to the currently executing sub or eval.
2680 If db_seqp is non_null, skip CVs that are in the DB package and populate
2681 *db_seqp with the cop sequence number at the point that the DB:: code was
2682 entered. (allows debuggers to eval in the scope of the breakpoint rather
2683 than in in the scope of the debuger itself).
2689 Perl_find_runcv(pTHX_ U32 *db_seqp)
2696 *db_seqp = PL_curcop->cop_seq;
2697 for (si = PL_curstackinfo; si; si = si->si_prev) {
2698 for (ix = si->si_cxix; ix >= 0; ix--) {
2699 cx = &(si->si_cxstack[ix]);
2700 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
2701 CV *cv = cx->blk_sub.cv;
2702 /* skip DB:: code */
2703 if (db_seqp && PL_debstash && CvSTASH(cv) == PL_debstash) {
2704 *db_seqp = cx->blk_oldcop->cop_seq;
2709 else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx))
2717 /* Compile a require/do, an eval '', or a /(?{...})/.
2718 * In the last case, startop is non-null, and contains the address of
2719 * a pointer that should be set to the just-compiled code.
2720 * outside is the lexically enclosing CV (if any) that invoked us.
2723 /* With USE_5005THREADS, eval_owner must be held on entry to doeval */
2725 S_doeval(pTHX_ int gimme, OP** startop, CV* outside, U32 seq)
2730 PL_in_eval = ((saveop && saveop->op_type == OP_REQUIRE)
2731 ? (EVAL_INREQUIRE | (PL_in_eval & EVAL_INEVAL))
2736 SAVESPTR(PL_compcv);
2737 PL_compcv = (CV*)NEWSV(1104,0);
2738 sv_upgrade((SV *)PL_compcv, SVt_PVCV);
2739 CvEVAL_on(PL_compcv);
2740 assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
2741 cxstack[cxstack_ix].blk_eval.cv = PL_compcv;
2743 CvOUTSIDE_SEQ(PL_compcv) = seq;
2744 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outside);
2746 /* set up a scratch pad */
2748 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE);
2751 SAVEMORTALIZESV(PL_compcv); /* must remain until end of current statement */
2753 /* make sure we compile in the right package */
2755 if (CopSTASH_ne(PL_curcop, PL_curstash)) {
2756 SAVESPTR(PL_curstash);
2757 PL_curstash = CopSTASH(PL_curcop);
2759 SAVESPTR(PL_beginav);
2760 PL_beginav = newAV();
2761 SAVEFREESV(PL_beginav);
2762 SAVEI32(PL_error_count);
2764 /* try to compile it */
2766 PL_eval_root = Nullop;
2768 PL_curcop = &PL_compiling;
2769 PL_curcop->cop_arybase = 0;
2770 if (saveop && saveop->op_flags & OPf_SPECIAL)
2771 PL_in_eval |= EVAL_KEEPERR;
2774 if (yyparse() || PL_error_count || !PL_eval_root) {
2778 I32 optype = 0; /* Might be reset by POPEVAL. */
2783 op_free(PL_eval_root);
2784 PL_eval_root = Nullop;
2786 SP = PL_stack_base + POPMARK; /* pop original mark */
2788 POPBLOCK(cx,PL_curpm);
2794 if (optype == OP_REQUIRE) {
2795 char* msg = SvPVx(ERRSV, n_a);
2796 DIE(aTHX_ "%sCompilation failed in require",
2797 *msg ? msg : "Unknown error\n");
2800 char* msg = SvPVx(ERRSV, n_a);
2802 POPBLOCK(cx,PL_curpm);
2804 Perl_croak(aTHX_ "%sCompilation failed in regexp",
2805 (*msg ? msg : "Unknown error\n"));
2808 char* msg = SvPVx(ERRSV, n_a);
2810 sv_setpv(ERRSV, "Compilation error");
2815 CopLINE_set(&PL_compiling, 0);
2817 *startop = PL_eval_root;
2819 SAVEFREEOP(PL_eval_root);
2821 scalarvoid(PL_eval_root);
2822 else if (gimme & G_ARRAY)
2825 scalar(PL_eval_root);
2827 DEBUG_x(dump_eval());
2829 /* Register with debugger: */
2830 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2831 CV *cv = get_cv("DB::postponed", FALSE);
2835 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2837 call_sv((SV*)cv, G_DISCARD);
2841 /* compiled okay, so do it */
2843 CvDEPTH(PL_compcv) = 1;
2844 SP = PL_stack_base + POPMARK; /* pop original mark */
2845 PL_op = saveop; /* The caller may need it. */
2846 PL_lex_state = LEX_NOTPARSING; /* $^S needs this. */
2848 RETURNOP(PL_eval_start);
2852 S_doopen_pmc(pTHX_ const char *name, const char *mode)
2854 STRLEN namelen = strlen(name);
2857 if (namelen > 3 && strEQ(name + namelen - 3, ".pm")) {
2858 SV *pmcsv = Perl_newSVpvf(aTHX_ "%s%c", name, 'c');
2859 char *pmc = SvPV_nolen(pmcsv);
2862 if (PerlLIO_stat(pmc, &pmcstat) < 0) {
2863 fp = PerlIO_open(name, mode);
2866 if (PerlLIO_stat(name, &pmstat) < 0 ||
2867 pmstat.st_mtime < pmcstat.st_mtime)
2869 fp = PerlIO_open(pmc, mode);
2872 fp = PerlIO_open(name, mode);
2875 SvREFCNT_dec(pmcsv);
2878 fp = PerlIO_open(name, mode);
2886 register PERL_CONTEXT *cx;
2890 char *tryname = Nullch;
2891 SV *namesv = Nullsv;
2893 I32 gimme = GIMME_V;
2894 PerlIO *tryrsfp = 0;
2896 int filter_has_file = 0;
2897 GV *filter_child_proc = 0;
2898 SV *filter_state = 0;
2905 if (SvNIOKp(sv) && PL_op->op_type != OP_DOFILE) {
2906 if (SvPOK(sv) && SvNOK(sv) && SvNV(sv)) { /* require v5.6.1 */
2907 UV rev = 0, ver = 0, sver = 0;
2909 U8 *s = (U8*)SvPVX(sv);
2910 U8 *end = (U8*)SvPVX(sv) + SvCUR(sv);
2912 rev = utf8n_to_uvchr(s, end - s, &len, 0);
2915 ver = utf8n_to_uvchr(s, end - s, &len, 0);
2918 sver = utf8n_to_uvchr(s, end - s, &len, 0);
2921 if (PERL_REVISION < rev
2922 || (PERL_REVISION == rev
2923 && (PERL_VERSION < ver
2924 || (PERL_VERSION == ver
2925 && PERL_SUBVERSION < sver))))
2927 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--this is only "
2928 "v%d.%d.%d, stopped", rev, ver, sver, PERL_REVISION,
2929 PERL_VERSION, PERL_SUBVERSION);
2931 if (ckWARN(WARN_PORTABLE))
2932 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
2933 "v-string in use/require non-portable");
2936 else if (!SvPOKp(sv)) { /* require 5.005_03 */
2937 if ((NV)PERL_REVISION + ((NV)PERL_VERSION/(NV)1000)
2938 + ((NV)PERL_SUBVERSION/(NV)1000000)
2939 + 0.00000099 < SvNV(sv))
2943 NV nver = (nrev - rev) * 1000;
2944 UV ver = (UV)(nver + 0.0009);
2945 NV nsver = (nver - ver) * 1000;
2946 UV sver = (UV)(nsver + 0.0009);
2948 /* help out with the "use 5.6" confusion */
2949 if (sver == 0 && (rev > 5 || (rev == 5 && ver >= 100))) {
2950 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required"
2951 " (did you mean v%"UVuf".%03"UVuf"?)--"
2952 "this is only v%d.%d.%d, stopped",
2953 rev, ver, sver, rev, ver/100,
2954 PERL_REVISION, PERL_VERSION, PERL_SUBVERSION);
2957 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--"
2958 "this is only v%d.%d.%d, stopped",
2959 rev, ver, sver, PERL_REVISION, PERL_VERSION,
2966 name = SvPV(sv, len);
2967 if (!(name && len > 0 && *name))
2968 DIE(aTHX_ "Null filename used");
2969 TAINT_PROPER("require");
2970 if (PL_op->op_type == OP_REQUIRE &&
2971 (svp = hv_fetch(GvHVn(PL_incgv), name, len, 0)) &&
2972 *svp != &PL_sv_undef)
2975 /* prepare to compile file */
2977 if (path_is_absolute(name)) {
2979 tryrsfp = doopen_pmc(name,PERL_SCRIPT_MODE);
2981 #ifdef MACOS_TRADITIONAL
2985 MacPerl_CanonDir(name, newname, 1);
2986 if (path_is_absolute(newname)) {
2988 tryrsfp = doopen_pmc(newname,PERL_SCRIPT_MODE);
2993 AV *ar = GvAVn(PL_incgv);
2997 if ((unixname = tounixspec(name, Nullch)) != Nullch)
3000 namesv = NEWSV(806, 0);
3001 for (i = 0; i <= AvFILL(ar); i++) {
3002 SV *dirsv = *av_fetch(ar, i, TRUE);
3008 if (SvTYPE(SvRV(loader)) == SVt_PVAV
3009 && !sv_isobject(loader))
3011 loader = *av_fetch((AV *)SvRV(loader), 0, TRUE);
3014 Perl_sv_setpvf(aTHX_ namesv, "/loader/0x%"UVxf"/%s",
3015 PTR2UV(SvRV(dirsv)), name);
3016 tryname = SvPVX(namesv);
3027 if (sv_isobject(loader))
3028 count = call_method("INC", G_ARRAY);
3030 count = call_sv(loader, G_ARRAY);
3040 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVGV) {
3044 if (SvTYPE(arg) == SVt_PVGV) {
3045 IO *io = GvIO((GV *)arg);
3050 tryrsfp = IoIFP(io);
3051 if (IoTYPE(io) == IoTYPE_PIPE) {
3052 /* reading from a child process doesn't
3053 nest -- when returning from reading
3054 the inner module, the outer one is
3055 unreadable (closed?) I've tried to
3056 save the gv to manage the lifespan of
3057 the pipe, but this didn't help. XXX */
3058 filter_child_proc = (GV *)arg;
3059 (void)SvREFCNT_inc(filter_child_proc);
3062 if (IoOFP(io) && IoOFP(io) != IoIFP(io)) {
3063 PerlIO_close(IoOFP(io));
3075 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVCV) {
3077 (void)SvREFCNT_inc(filter_sub);
3080 filter_state = SP[i];
3081 (void)SvREFCNT_inc(filter_state);
3085 tryrsfp = PerlIO_open("/dev/null",
3100 filter_has_file = 0;
3101 if (filter_child_proc) {
3102 SvREFCNT_dec(filter_child_proc);
3103 filter_child_proc = 0;
3106 SvREFCNT_dec(filter_state);
3110 SvREFCNT_dec(filter_sub);
3115 if (!path_is_absolute(name)
3116 #ifdef MACOS_TRADITIONAL
3117 /* We consider paths of the form :a:b ambiguous and interpret them first
3118 as global then as local
3120 || (*name == ':' && name[1] != ':' && strchr(name+2, ':'))
3123 char *dir = SvPVx(dirsv, n_a);
3124 #ifdef MACOS_TRADITIONAL
3128 MacPerl_CanonDir(name, buf2, 1);
3129 Perl_sv_setpvf(aTHX_ namesv, "%s%s", MacPerl_CanonDir(dir, buf1, 0), buf2+(buf2[0] == ':'));
3133 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
3135 sv_setpv(namesv, unixdir);
3136 sv_catpv(namesv, unixname);
3138 Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name);
3141 TAINT_PROPER("require");
3142 tryname = SvPVX(namesv);
3143 tryrsfp = doopen_pmc(tryname, PERL_SCRIPT_MODE);
3145 if (tryname[0] == '.' && tryname[1] == '/')
3154 SAVECOPFILE_FREE(&PL_compiling);
3155 CopFILE_set(&PL_compiling, tryrsfp ? tryname : name);
3156 SvREFCNT_dec(namesv);
3158 if (PL_op->op_type == OP_REQUIRE) {
3159 char *msgstr = name;
3160 if (namesv) { /* did we lookup @INC? */
3161 SV *msg = sv_2mortal(newSVpv(msgstr,0));
3162 SV *dirmsgsv = NEWSV(0, 0);
3163 AV *ar = GvAVn(PL_incgv);
3165 sv_catpvn(msg, " in @INC", 8);
3166 if (instr(SvPVX(msg), ".h "))
3167 sv_catpv(msg, " (change .h to .ph maybe?)");
3168 if (instr(SvPVX(msg), ".ph "))
3169 sv_catpv(msg, " (did you run h2ph?)");
3170 sv_catpv(msg, " (@INC contains:");
3171 for (i = 0; i <= AvFILL(ar); i++) {
3172 char *dir = SvPVx(*av_fetch(ar, i, TRUE), n_a);
3173 Perl_sv_setpvf(aTHX_ dirmsgsv, " %s", dir);
3174 sv_catsv(msg, dirmsgsv);
3176 sv_catpvn(msg, ")", 1);
3177 SvREFCNT_dec(dirmsgsv);
3178 msgstr = SvPV_nolen(msg);
3180 DIE(aTHX_ "Can't locate %s", msgstr);
3186 SETERRNO(0, SS_NORMAL);
3188 /* Assume success here to prevent recursive requirement. */
3190 /* Check whether a hook in @INC has already filled %INC */
3191 if (!hook_sv || !(svp = hv_fetch(GvHVn(PL_incgv), name, len, 0))) {
3192 (void)hv_store(GvHVn(PL_incgv), name, len,
3193 (hook_sv ? SvREFCNT_inc(hook_sv)
3194 : newSVpv(CopFILE(&PL_compiling), 0)),
3200 lex_start(sv_2mortal(newSVpvn("",0)));
3201 SAVEGENERICSV(PL_rsfp_filters);
3202 PL_rsfp_filters = Nullav;
3207 SAVESPTR(PL_compiling.cop_warnings);
3208 if (PL_dowarn & G_WARN_ALL_ON)
3209 PL_compiling.cop_warnings = pWARN_ALL ;
3210 else if (PL_dowarn & G_WARN_ALL_OFF)
3211 PL_compiling.cop_warnings = pWARN_NONE ;
3212 else if (PL_taint_warn)
3213 PL_compiling.cop_warnings = newSVpvn(WARN_TAINTstring, WARNsize);
3215 PL_compiling.cop_warnings = pWARN_STD ;
3216 SAVESPTR(PL_compiling.cop_io);
3217 PL_compiling.cop_io = Nullsv;
3219 if (filter_sub || filter_child_proc) {
3220 SV *datasv = filter_add(run_user_filter, Nullsv);
3221 IoLINES(datasv) = filter_has_file;
3222 IoFMT_GV(datasv) = (GV *)filter_child_proc;
3223 IoTOP_GV(datasv) = (GV *)filter_state;
3224 IoBOTTOM_GV(datasv) = (GV *)filter_sub;
3227 /* switch to eval mode */
3228 push_return(PL_op->op_next);
3229 PUSHBLOCK(cx, CXt_EVAL, SP);
3230 PUSHEVAL(cx, name, Nullgv);
3232 SAVECOPLINE(&PL_compiling);
3233 CopLINE_set(&PL_compiling, 0);
3237 /* Store and reset encoding. */
3238 encoding = PL_encoding;
3239 PL_encoding = Nullsv;
3241 op = DOCATCH(doeval(gimme, NULL, Nullcv, PL_curcop->cop_seq));
3243 /* Restore encoding. */
3244 PL_encoding = encoding;
3251 return pp_require();
3257 register PERL_CONTEXT *cx;
3259 I32 gimme = GIMME_V, was = PL_sub_generation;
3260 char tbuf[TYPE_DIGITS(long) + 12];
3261 char *tmpbuf = tbuf;
3270 TAINT_PROPER("eval");
3276 /* switch to eval mode */
3278 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
3279 SV *sv = sv_newmortal();
3280 Perl_sv_setpvf(aTHX_ sv, "_<(eval %lu)[%s:%"IVdf"]",
3281 (unsigned long)++PL_evalseq,
3282 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
3286 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++PL_evalseq);
3287 SAVECOPFILE_FREE(&PL_compiling);
3288 CopFILE_set(&PL_compiling, tmpbuf+2);
3289 SAVECOPLINE(&PL_compiling);
3290 CopLINE_set(&PL_compiling, 1);
3291 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
3292 deleting the eval's FILEGV from the stash before gv_check() runs
3293 (i.e. before run-time proper). To work around the coredump that
3294 ensues, we always turn GvMULTI_on for any globals that were
3295 introduced within evals. See force_ident(). GSAR 96-10-12 */
3296 safestr = savepv(tmpbuf);
3297 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
3299 PL_hints = PL_op->op_targ;
3300 SAVESPTR(PL_compiling.cop_warnings);
3301 if (specialWARN(PL_curcop->cop_warnings))
3302 PL_compiling.cop_warnings = PL_curcop->cop_warnings;
3304 PL_compiling.cop_warnings = newSVsv(PL_curcop->cop_warnings);
3305 SAVEFREESV(PL_compiling.cop_warnings);
3307 SAVESPTR(PL_compiling.cop_io);
3308 if (specialCopIO(PL_curcop->cop_io))
3309 PL_compiling.cop_io = PL_curcop->cop_io;
3311 PL_compiling.cop_io = newSVsv(PL_curcop->cop_io);
3312 SAVEFREESV(PL_compiling.cop_io);
3314 /* special case: an eval '' executed within the DB package gets lexically
3315 * placed in the first non-DB CV rather than the current CV - this
3316 * allows the debugger to execute code, find lexicals etc, in the
3317 * scope of the code being debugged. Passing &seq gets find_runcv
3318 * to do the dirty work for us */
3319 runcv = find_runcv(&seq);
3321 push_return(PL_op->op_next);
3322 PUSHBLOCK(cx, (CXt_EVAL|CXp_REAL), SP);
3323 PUSHEVAL(cx, 0, Nullgv);
3325 /* prepare to compile string */
3327 if (PERLDB_LINE && PL_curstash != PL_debstash)
3328 save_lines(CopFILEAV(&PL_compiling), PL_linestr);
3330 ret = doeval(gimme, NULL, runcv, seq);
3331 if (PERLDB_INTER && was != (I32)PL_sub_generation /* Some subs defined here. */
3332 && ret != PL_op->op_next) { /* Successive compilation. */
3333 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
3335 return DOCATCH(ret);
3345 register PERL_CONTEXT *cx;
3347 U8 save_flags = PL_op -> op_flags;
3352 retop = pop_return();
3355 if (gimme == G_VOID)
3357 else if (gimme == G_SCALAR) {
3360 if (SvFLAGS(TOPs) & SVs_TEMP)
3363 *MARK = sv_mortalcopy(TOPs);
3367 *MARK = &PL_sv_undef;
3372 /* in case LEAVE wipes old return values */
3373 for (mark = newsp + 1; mark <= SP; mark++) {
3374 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
3375 *mark = sv_mortalcopy(*mark);
3376 TAINT_NOT; /* Each item is independent */
3380 PL_curpm = newpm; /* Don't pop $1 et al till now */
3383 assert(CvDEPTH(PL_compcv) == 1);
3385 CvDEPTH(PL_compcv) = 0;
3388 if (optype == OP_REQUIRE &&
3389 !(gimme == G_SCALAR ? SvTRUE(*SP) : SP > newsp))
3391 /* Unassume the success we assumed earlier. */
3392 SV *nsv = cx->blk_eval.old_namesv;
3393 (void)hv_delete(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), G_DISCARD);
3394 retop = Perl_die(aTHX_ "%"SVf" did not return a true value", nsv);
3395 /* die_where() did LEAVE, or we won't be here */
3399 if (!(save_flags & OPf_SPECIAL))
3409 register PERL_CONTEXT *cx;
3410 I32 gimme = GIMME_V;
3415 push_return(cLOGOP->op_other->op_next);
3416 PUSHBLOCK(cx, (CXt_EVAL|CXp_TRYBLOCK), SP);
3419 PL_in_eval = EVAL_INEVAL;
3422 return DOCATCH(PL_op->op_next);
3433 register PERL_CONTEXT *cx;
3438 retop = pop_return();
3441 if (gimme == G_VOID)
3443 else if (gimme == G_SCALAR) {
3446 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
3449 *MARK = sv_mortalcopy(TOPs);
3453 *MARK = &PL_sv_undef;
3458 /* in case LEAVE wipes old return values */
3459 for (mark = newsp + 1; mark <= SP; mark++) {
3460 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
3461 *mark = sv_mortalcopy(*mark);
3462 TAINT_NOT; /* Each item is independent */
3466 PL_curpm = newpm; /* Don't pop $1 et al till now */
3474 S_doparseform(pTHX_ SV *sv)
3477 register char *s = SvPV_force(sv, len);
3478 register char *send = s + len;
3479 register char *base = Nullch;
3480 register I32 skipspaces = 0;
3481 bool noblank = FALSE;
3482 bool repeat = FALSE;
3483 bool postspace = FALSE;
3491 Perl_croak(aTHX_ "Null picture in formline");
3493 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
3498 *fpc++ = FF_LINEMARK;
3499 noblank = repeat = FALSE;
3517 case ' ': case '\t':
3528 *fpc++ = FF_LITERAL;
3536 *fpc++ = (U16)skipspaces;
3540 *fpc++ = FF_NEWLINE;
3544 arg = fpc - linepc + 1;
3551 *fpc++ = FF_LINEMARK;
3552 noblank = repeat = FALSE;
3561 ischop = s[-1] == '^';
3567 arg = (s - base) - 1;
3569 *fpc++ = FF_LITERAL;
3578 *fpc++ = FF_LINEGLOB;
3580 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
3581 arg = ischop ? 512 : 0;
3591 arg |= 256 + (s - f);
3593 *fpc++ = s - base; /* fieldsize for FETCH */
3594 *fpc++ = FF_DECIMAL;
3597 else if (*s == '0' && s[1] == '#') { /* Zero padded decimals */
3598 arg = ischop ? 512 : 0;
3600 s++; /* skip the '0' first */
3609 arg |= 256 + (s - f);
3611 *fpc++ = s - base; /* fieldsize for FETCH */
3612 *fpc++ = FF_0DECIMAL;
3617 bool ismore = FALSE;
3620 while (*++s == '>') ;
3621 prespace = FF_SPACE;
3623 else if (*s == '|') {
3624 while (*++s == '|') ;
3625 prespace = FF_HALFSPACE;
3630 while (*++s == '<') ;
3633 if (*s == '.' && s[1] == '.' && s[2] == '.') {
3637 *fpc++ = s - base; /* fieldsize for FETCH */
3639 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
3642 *fpc++ = (U16)prespace;
3657 { /* need to jump to the next word */
3659 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
3660 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
3661 s = SvPVX(sv) + SvCUR(sv) + z;
3663 Copy(fops, s, arg, U16);
3665 sv_magic(sv, Nullsv, PERL_MAGIC_fm, Nullch, 0);
3670 run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen)
3672 SV *datasv = FILTER_DATA(idx);
3673 int filter_has_file = IoLINES(datasv);
3674 GV *filter_child_proc = (GV *)IoFMT_GV(datasv);
3675 SV *filter_state = (SV *)IoTOP_GV(datasv);
3676 SV *filter_sub = (SV *)IoBOTTOM_GV(datasv);
3679 /* I was having segfault trouble under Linux 2.2.5 after a
3680 parse error occured. (Had to hack around it with a test
3681 for PL_error_count == 0.) Solaris doesn't segfault --
3682 not sure where the trouble is yet. XXX */
3684 if (filter_has_file) {
3685 len = FILTER_READ(idx+1, buf_sv, maxlen);
3688 if (filter_sub && len >= 0) {
3699 PUSHs(sv_2mortal(newSViv(maxlen)));
3701 PUSHs(filter_state);
3704 count = call_sv(filter_sub, G_SCALAR);
3720 IoLINES(datasv) = 0;
3721 if (filter_child_proc) {
3722 SvREFCNT_dec(filter_child_proc);
3723 IoFMT_GV(datasv) = Nullgv;
3726 SvREFCNT_dec(filter_state);
3727 IoTOP_GV(datasv) = Nullgv;
3730 SvREFCNT_dec(filter_sub);
3731 IoBOTTOM_GV(datasv) = Nullgv;
3733 filter_del(run_user_filter);
3739 /* perhaps someone can come up with a better name for
3740 this? it is not really "absolute", per se ... */
3742 S_path_is_absolute(pTHX_ char *name)
3744 if (PERL_FILE_IS_ABSOLUTE(name)
3745 #ifdef MACOS_TRADITIONAL
3748 || (*name == '.' && (name[1] == '/' ||
3749 (name[1] == '.' && name[2] == '/'))))