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) || defined(USE_5005THREADS)
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 != 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) && !defined(USE_5005THREADS)
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;
160 rxres_restore(&cx->sb_rxres, rx);
162 if (cx->sb_iters++) {
163 I32 saviters = cx->sb_iters;
164 if (cx->sb_iters > cx->sb_maxiters)
165 DIE(aTHX_ "Substitution loop");
167 if (!(cx->sb_rxtainted & 2) && SvTAINTED(TOPs))
168 cx->sb_rxtainted |= 2;
169 sv_catsv(dstr, POPs);
172 if (cx->sb_once || !CALLREGEXEC(aTHX_ rx, s, cx->sb_strend, orig,
173 s == m, cx->sb_targ, NULL,
174 ((cx->sb_rflags & REXEC_COPY_STR)
175 ? (REXEC_IGNOREPOS|REXEC_NOT_FIRST)
176 : (REXEC_COPY_STR|REXEC_IGNOREPOS|REXEC_NOT_FIRST))))
178 SV *targ = cx->sb_targ;
180 sv_catpvn(dstr, s, cx->sb_strend - s);
181 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
183 (void)SvOOK_off(targ);
184 Safefree(SvPVX(targ));
185 SvPVX(targ) = SvPVX(dstr);
186 SvCUR_set(targ, SvCUR(dstr));
187 SvLEN_set(targ, SvLEN(dstr));
193 TAINT_IF(cx->sb_rxtainted & 1);
194 PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
196 (void)SvPOK_only_UTF8(targ);
197 TAINT_IF(cx->sb_rxtainted);
201 LEAVE_SCOPE(cx->sb_oldsave);
203 RETURNOP(pm->op_next);
205 cx->sb_iters = saviters;
207 if (RX_MATCH_COPIED(rx) && rx->subbeg != orig) {
210 cx->sb_orig = orig = rx->subbeg;
212 cx->sb_strend = s + (cx->sb_strend - m);
214 cx->sb_m = m = rx->startp[0] + orig;
216 sv_catpvn(dstr, s, m-s);
217 cx->sb_s = rx->endp[0] + orig;
218 { /* Update the pos() information. */
219 SV *sv = cx->sb_targ;
222 if (SvTYPE(sv) < SVt_PVMG)
223 (void)SvUPGRADE(sv, SVt_PVMG);
224 if (!(mg = mg_find(sv, PERL_MAGIC_regex_global))) {
225 sv_magic(sv, Nullsv, PERL_MAGIC_regex_global, Nullch, 0);
226 mg = mg_find(sv, PERL_MAGIC_regex_global);
233 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
234 rxres_save(&cx->sb_rxres, rx);
235 RETURNOP(pm->op_pmreplstart);
239 Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx)
244 if (!p || p[1] < rx->nparens) {
245 i = 6 + rx->nparens * 2;
253 *p++ = PTR2UV(RX_MATCH_COPIED(rx) ? rx->subbeg : Nullch);
254 RX_MATCH_COPIED_off(rx);
258 *p++ = PTR2UV(rx->subbeg);
259 *p++ = (UV)rx->sublen;
260 for (i = 0; i <= rx->nparens; ++i) {
261 *p++ = (UV)rx->startp[i];
262 *p++ = (UV)rx->endp[i];
267 Perl_rxres_restore(pTHX_ void **rsp, REGEXP *rx)
272 if (RX_MATCH_COPIED(rx))
273 Safefree(rx->subbeg);
274 RX_MATCH_COPIED_set(rx, *p);
279 rx->subbeg = INT2PTR(char*,*p++);
280 rx->sublen = (I32)(*p++);
281 for (i = 0; i <= rx->nparens; ++i) {
282 rx->startp[i] = (I32)(*p++);
283 rx->endp[i] = (I32)(*p++);
288 Perl_rxres_free(pTHX_ void **rsp)
293 Safefree(INT2PTR(char*,*p));
301 dSP; dMARK; dORIGMARK;
302 register SV *tmpForm = *++MARK;
309 register SV *sv = Nullsv;
314 bool chopspace = (strchr(PL_chopset, ' ') != Nullch);
315 char *chophere = Nullch;
316 char *linemark = Nullch;
318 bool gotsome = FALSE;
320 STRLEN fudge = SvCUR(tmpForm) * (IN_BYTES ? 1 : 3) + 1;
321 bool item_is_utf = FALSE;
323 if (!SvMAGICAL(tmpForm) || !SvCOMPILED(tmpForm)) {
324 if (SvREADONLY(tmpForm)) {
325 SvREADONLY_off(tmpForm);
326 doparseform(tmpForm);
327 SvREADONLY_on(tmpForm);
330 doparseform(tmpForm);
333 SvPV_force(PL_formtarget, len);
334 t = SvGROW(PL_formtarget, len + fudge + 1); /* XXX SvCUR bad */
336 f = SvPV(tmpForm, len);
337 /* need to jump to the next word */
338 s = f + len + WORD_ALIGN - SvCUR(tmpForm) % WORD_ALIGN;
347 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
348 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
349 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
350 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
351 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
353 case FF_CHECKNL: name = "CHECKNL"; break;
354 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
355 case FF_SPACE: name = "SPACE"; break;
356 case FF_HALFSPACE: name = "HALFSPACE"; break;
357 case FF_ITEM: name = "ITEM"; break;
358 case FF_CHOP: name = "CHOP"; break;
359 case FF_LINEGLOB: name = "LINEGLOB"; break;
360 case FF_NEWLINE: name = "NEWLINE"; break;
361 case FF_MORE: name = "MORE"; break;
362 case FF_LINEMARK: name = "LINEMARK"; break;
363 case FF_END: name = "END"; break;
364 case FF_0DECIMAL: name = "0DECIMAL"; break;
367 PerlIO_printf(Perl_debug_log, "%-16s%ld\n", name, (long) arg);
369 PerlIO_printf(Perl_debug_log, "%-16s\n", name);
397 if (ckWARN(WARN_SYNTAX))
398 Perl_warner(aTHX_ WARN_SYNTAX, "Not enough format arguments");
403 item = s = SvPV(sv, len);
406 itemsize = sv_len_utf8(sv);
407 if (itemsize != len) {
409 if (itemsize > fieldsize) {
410 itemsize = fieldsize;
411 itembytes = itemsize;
412 sv_pos_u2b(sv, &itembytes, 0);
416 send = chophere = s + itembytes;
426 sv_pos_b2u(sv, &itemsize);
431 if (itemsize > fieldsize)
432 itemsize = fieldsize;
433 send = chophere = s + itemsize;
445 item = s = SvPV(sv, len);
448 itemsize = sv_len_utf8(sv);
449 if (itemsize != len) {
451 if (itemsize <= fieldsize) {
452 send = chophere = s + itemsize;
463 itemsize = fieldsize;
464 itembytes = itemsize;
465 sv_pos_u2b(sv, &itembytes, 0);
466 send = chophere = s + itembytes;
467 while (s < send || (s == send && isSPACE(*s))) {
477 if (strchr(PL_chopset, *s))
482 itemsize = chophere - item;
483 sv_pos_b2u(sv, &itemsize);
490 if (itemsize <= fieldsize) {
491 send = chophere = s + itemsize;
502 itemsize = fieldsize;
503 send = chophere = s + itemsize;
504 while (s < send || (s == send && isSPACE(*s))) {
514 if (strchr(PL_chopset, *s))
519 itemsize = chophere - item;
524 arg = fieldsize - itemsize;
533 arg = fieldsize - itemsize;
547 if (UTF8_IS_CONTINUED(*s)) {
548 STRLEN skip = UTF8SKIP(s);
565 if ( !((*t++ = *s++) & ~31) )
573 int ch = *t++ = *s++;
576 if ( !((*t++ = *s++) & ~31) )
585 while (*s && isSPACE(*s))
592 item = s = SvPV(sv, len);
594 item_is_utf = FALSE; /* XXX is this correct? */
606 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
607 sv_catpvn(PL_formtarget, item, itemsize);
608 SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
609 t = SvPVX(PL_formtarget) + SvCUR(PL_formtarget);
614 /* If the field is marked with ^ and the value is undefined,
617 if ((arg & 512) && !SvOK(sv)) {
625 /* Formats aren't yet marked for locales, so assume "yes". */
627 STORE_NUMERIC_STANDARD_SET_LOCAL();
628 #if defined(USE_LONG_DOUBLE)
630 sprintf(t, "%#*.*" PERL_PRIfldbl,
631 (int) fieldsize, (int) arg & 255, value);
633 sprintf(t, "%*.0" PERL_PRIfldbl, (int) fieldsize, value);
638 (int) fieldsize, (int) arg & 255, value);
641 (int) fieldsize, value);
644 RESTORE_NUMERIC_STANDARD();
650 /* If the field is marked with ^ and the value is undefined,
653 if ((arg & 512) && !SvOK(sv)) {
661 /* Formats aren't yet marked for locales, so assume "yes". */
663 STORE_NUMERIC_STANDARD_SET_LOCAL();
664 #if defined(USE_LONG_DOUBLE)
666 sprintf(t, "%#0*.*" PERL_PRIfldbl,
667 (int) fieldsize, (int) arg & 255, value);
668 /* is this legal? I don't have long doubles */
670 sprintf(t, "%0*.0" PERL_PRIfldbl, (int) fieldsize, value);
674 sprintf(t, "%#0*.*f",
675 (int) fieldsize, (int) arg & 255, value);
678 (int) fieldsize, value);
681 RESTORE_NUMERIC_STANDARD();
688 while (t-- > linemark && *t == ' ') ;
696 if (arg) { /* repeat until fields exhausted? */
698 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
699 lines += FmLINES(PL_formtarget);
702 if (strnEQ(linemark, linemark - arg, arg))
703 DIE(aTHX_ "Runaway format");
705 FmLINES(PL_formtarget) = lines;
707 RETURNOP(cLISTOP->op_first);
720 while (*s && isSPACE(*s) && s < send)
724 arg = fieldsize - itemsize;
731 if (strnEQ(s," ",3)) {
732 while (s > SvPVX(PL_formtarget) && isSPACE(s[-1]))
743 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
744 FmLINES(PL_formtarget) += lines;
756 if (PL_stack_base + *PL_markstack_ptr == SP) {
758 if (GIMME_V == G_SCALAR)
759 XPUSHs(sv_2mortal(newSViv(0)));
760 RETURNOP(PL_op->op_next->op_next);
762 PL_stack_sp = PL_stack_base + *PL_markstack_ptr + 1;
763 pp_pushmark(); /* push dst */
764 pp_pushmark(); /* push src */
765 ENTER; /* enter outer scope */
768 /* SAVE_DEFSV does *not* suffice here for USE_5005THREADS */
770 ENTER; /* enter inner scope */
773 src = PL_stack_base[*PL_markstack_ptr];
778 if (PL_op->op_type == OP_MAPSTART)
779 pp_pushmark(); /* push top */
780 return ((LOGOP*)PL_op->op_next)->op_other;
785 DIE(aTHX_ "panic: mapstart"); /* uses grepstart */
791 I32 items = (SP - PL_stack_base) - *PL_markstack_ptr; /* how many new items */
797 /* first, move source pointer to the next item in the source list */
798 ++PL_markstack_ptr[-1];
800 /* if there are new items, push them into the destination list */
802 /* might need to make room back there first */
803 if (items > PL_markstack_ptr[-1] - PL_markstack_ptr[-2]) {
804 /* XXX this implementation is very pessimal because the stack
805 * is repeatedly extended for every set of items. Is possible
806 * to do this without any stack extension or copying at all
807 * by maintaining a separate list over which the map iterates
808 * (like foreach does). --gsar */
810 /* everything in the stack after the destination list moves
811 * towards the end the stack by the amount of room needed */
812 shift = items - (PL_markstack_ptr[-1] - PL_markstack_ptr[-2]);
814 /* items to shift up (accounting for the moved source pointer) */
815 count = (SP - PL_stack_base) - (PL_markstack_ptr[-1] - 1);
817 /* This optimization is by Ben Tilly and it does
818 * things differently from what Sarathy (gsar)
819 * is describing. The downside of this optimization is
820 * that leaves "holes" (uninitialized and hopefully unused areas)
821 * to the Perl stack, but on the other hand this
822 * shouldn't be a problem. If Sarathy's idea gets
823 * implemented, this optimization should become
824 * irrelevant. --jhi */
826 shift = count; /* Avoid shifting too often --Ben Tilly */
831 PL_markstack_ptr[-1] += shift;
832 *PL_markstack_ptr += shift;
836 /* copy the new items down to the destination list */
837 dst = PL_stack_base + (PL_markstack_ptr[-2] += items) - 1;
839 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
841 LEAVE; /* exit inner scope */
844 if (PL_markstack_ptr[-1] > *PL_markstack_ptr) {
847 (void)POPMARK; /* pop top */
848 LEAVE; /* exit outer scope */
849 (void)POPMARK; /* pop src */
850 items = --*PL_markstack_ptr - PL_markstack_ptr[-1];
851 (void)POPMARK; /* pop dst */
852 SP = PL_stack_base + POPMARK; /* pop original mark */
853 if (gimme == G_SCALAR) {
857 else if (gimme == G_ARRAY)
864 ENTER; /* enter inner scope */
867 /* set $_ to the new source item */
868 src = PL_stack_base[PL_markstack_ptr[-1]];
872 RETURNOP(cLOGOP->op_other);
880 if (GIMME == G_ARRAY)
882 if (SvTRUEx(PAD_SV(PL_op->op_targ)))
883 return cLOGOP->op_other;
892 if (GIMME == G_ARRAY) {
893 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
897 SV *targ = PAD_SV(PL_op->op_targ);
900 if (PL_op->op_private & OPpFLIP_LINENUM) {
903 && (gp_io = GvIO(PL_last_in_gv))
904 && SvIV(sv) == (IV)IoLINES(gp_io);
909 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
910 if (PL_op->op_flags & OPf_SPECIAL) {
918 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
931 if (GIMME == G_ARRAY) {
937 if (SvGMAGICAL(left))
939 if (SvGMAGICAL(right))
942 if (SvNIOKp(left) || !SvPOKp(left) ||
943 SvNIOKp(right) || !SvPOKp(right) ||
944 (looks_like_number(left) && *SvPVX(left) != '0' &&
945 looks_like_number(right) && *SvPVX(right) != '0'))
947 if (SvNV(left) < IV_MIN || SvNV(right) > IV_MAX)
948 DIE(aTHX_ "Range iterator outside integer range");
959 sv = sv_2mortal(newSViv(i++));
964 SV *final = sv_mortalcopy(right);
966 char *tmps = SvPV(final, len);
968 sv = sv_mortalcopy(left);
970 while (!SvNIOKp(sv) && SvCUR(sv) <= len) {
972 if (strEQ(SvPVX(sv),tmps))
974 sv = sv_2mortal(newSVsv(sv));
981 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
983 if ((PL_op->op_private & OPpFLIP_LINENUM)
984 ? (GvIO(PL_last_in_gv)
985 && SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv)))
987 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
988 sv_catpv(targ, "E0");
999 S_dopoptolabel(pTHX_ char *label)
1002 register PERL_CONTEXT *cx;
1004 for (i = cxstack_ix; i >= 0; i--) {
1006 switch (CxTYPE(cx)) {
1008 if (ckWARN(WARN_EXITING))
1009 Perl_warner(aTHX_ WARN_EXITING, "Exiting substitution via %s",
1013 if (ckWARN(WARN_EXITING))
1014 Perl_warner(aTHX_ WARN_EXITING, "Exiting subroutine via %s",
1018 if (ckWARN(WARN_EXITING))
1019 Perl_warner(aTHX_ WARN_EXITING, "Exiting format via %s",
1023 if (ckWARN(WARN_EXITING))
1024 Perl_warner(aTHX_ WARN_EXITING, "Exiting eval via %s",
1028 if (ckWARN(WARN_EXITING))
1029 Perl_warner(aTHX_ WARN_EXITING, "Exiting pseudo-block via %s",
1033 if (!cx->blk_loop.label ||
1034 strNE(label, cx->blk_loop.label) ) {
1035 DEBUG_l(Perl_deb(aTHX_ "(Skipping label #%ld %s)\n",
1036 (long)i, cx->blk_loop.label));
1039 DEBUG_l( Perl_deb(aTHX_ "(Found label #%ld %s)\n", (long)i, label));
1047 Perl_dowantarray(pTHX)
1049 I32 gimme = block_gimme();
1050 return (gimme == G_VOID) ? G_SCALAR : gimme;
1054 Perl_block_gimme(pTHX)
1058 cxix = dopoptosub(cxstack_ix);
1062 switch (cxstack[cxix].blk_gimme) {
1070 Perl_croak(aTHX_ "panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
1077 Perl_is_lvalue_sub(pTHX)
1081 cxix = dopoptosub(cxstack_ix);
1082 assert(cxix >= 0); /* We should only be called from inside subs */
1084 if (cxstack[cxix].blk_sub.lval && CvLVALUE(cxstack[cxix].blk_sub.cv))
1085 return cxstack[cxix].blk_sub.lval;
1091 S_dopoptosub(pTHX_ I32 startingblock)
1093 return dopoptosub_at(cxstack, startingblock);
1097 S_dopoptosub_at(pTHX_ PERL_CONTEXT *cxstk, I32 startingblock)
1100 register PERL_CONTEXT *cx;
1101 for (i = startingblock; i >= 0; i--) {
1103 switch (CxTYPE(cx)) {
1109 DEBUG_l( Perl_deb(aTHX_ "(Found sub #%ld)\n", (long)i));
1117 S_dopoptoeval(pTHX_ I32 startingblock)
1120 register PERL_CONTEXT *cx;
1121 for (i = startingblock; i >= 0; i--) {
1123 switch (CxTYPE(cx)) {
1127 DEBUG_l( Perl_deb(aTHX_ "(Found eval #%ld)\n", (long)i));
1135 S_dopoptoloop(pTHX_ I32 startingblock)
1138 register PERL_CONTEXT *cx;
1139 for (i = startingblock; i >= 0; i--) {
1141 switch (CxTYPE(cx)) {
1143 if (ckWARN(WARN_EXITING))
1144 Perl_warner(aTHX_ WARN_EXITING, "Exiting substitution via %s",
1148 if (ckWARN(WARN_EXITING))
1149 Perl_warner(aTHX_ WARN_EXITING, "Exiting subroutine via %s",
1153 if (ckWARN(WARN_EXITING))
1154 Perl_warner(aTHX_ WARN_EXITING, "Exiting format via %s",
1158 if (ckWARN(WARN_EXITING))
1159 Perl_warner(aTHX_ WARN_EXITING, "Exiting eval via %s",
1163 if (ckWARN(WARN_EXITING))
1164 Perl_warner(aTHX_ WARN_EXITING, "Exiting pseudo-block via %s",
1168 DEBUG_l( Perl_deb(aTHX_ "(Found loop #%ld)\n", (long)i));
1176 Perl_dounwind(pTHX_ I32 cxix)
1178 register PERL_CONTEXT *cx;
1181 while (cxstack_ix > cxix) {
1183 cx = &cxstack[cxstack_ix];
1184 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n",
1185 (long) cxstack_ix, PL_block_type[CxTYPE(cx)]));
1186 /* Note: we don't need to restore the base context info till the end. */
1187 switch (CxTYPE(cx)) {
1190 continue; /* not break */
1212 Perl_qerror(pTHX_ SV *err)
1215 sv_catsv(ERRSV, err);
1217 sv_catsv(PL_errors, err);
1219 Perl_warn(aTHX_ "%"SVf, err);
1224 Perl_die_where(pTHX_ char *message, STRLEN msglen)
1229 register PERL_CONTEXT *cx;
1234 if (PL_in_eval & EVAL_KEEPERR) {
1235 static char prefix[] = "\t(in cleanup) ";
1240 else if (SvCUR(err) >= sizeof(prefix)+msglen-1) {
1243 if (*e != *message || strNE(e,message))
1247 SvGROW(err, SvCUR(err)+sizeof(prefix)+msglen);
1248 sv_catpvn(err, prefix, sizeof(prefix)-1);
1249 sv_catpvn(err, message, msglen);
1250 if (ckWARN(WARN_MISC)) {
1251 STRLEN start = SvCUR(err)-msglen-sizeof(prefix)+1;
1252 Perl_warner(aTHX_ WARN_MISC, SvPVX(err)+start);
1257 sv_setpvn(ERRSV, message, msglen);
1261 message = SvPVx(ERRSV, msglen);
1263 while ((cxix = dopoptoeval(cxstack_ix)) < 0
1264 && PL_curstackinfo->si_prev)
1273 if (cxix < cxstack_ix)
1276 POPBLOCK(cx,PL_curpm);
1277 if (CxTYPE(cx) != CXt_EVAL) {
1278 PerlIO_write(Perl_error_log, "panic: die ", 11);
1279 PerlIO_write(Perl_error_log, message, msglen);
1284 if (gimme == G_SCALAR)
1285 *++newsp = &PL_sv_undef;
1286 PL_stack_sp = newsp;
1290 /* LEAVE could clobber PL_curcop (see save_re_context())
1291 * XXX it might be better to find a way to avoid messing with
1292 * PL_curcop in save_re_context() instead, but this is a more
1293 * minimal fix --GSAR */
1294 PL_curcop = cx->blk_oldcop;
1296 if (optype == OP_REQUIRE) {
1297 char* msg = SvPVx(ERRSV, n_a);
1298 DIE(aTHX_ "%sCompilation failed in require",
1299 *msg ? msg : "Unknown error\n");
1301 return pop_return();
1305 message = SvPVx(ERRSV, msglen);
1308 /* SFIO can really mess with your errno */
1311 PerlIO *serr = Perl_error_log;
1313 PERL_WRITE_MSG_TO_CONSOLE(serr, message, msglen);
1314 (void)PerlIO_flush(serr);
1327 if (SvTRUE(left) != SvTRUE(right))
1339 RETURNOP(cLOGOP->op_other);
1348 RETURNOP(cLOGOP->op_other);
1354 register I32 cxix = dopoptosub(cxstack_ix);
1355 register PERL_CONTEXT *cx;
1356 register PERL_CONTEXT *ccstack = cxstack;
1357 PERL_SI *top_si = PL_curstackinfo;
1368 /* we may be in a higher stacklevel, so dig down deeper */
1369 while (cxix < 0 && top_si->si_type != PERLSI_MAIN) {
1370 top_si = top_si->si_prev;
1371 ccstack = top_si->si_cxstack;
1372 cxix = dopoptosub_at(ccstack, top_si->si_cxix);
1375 if (GIMME != G_ARRAY) {
1381 if (PL_DBsub && cxix >= 0 &&
1382 ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub))
1386 cxix = dopoptosub_at(ccstack, cxix - 1);
1389 cx = &ccstack[cxix];
1390 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1391 dbcxix = dopoptosub_at(ccstack, cxix - 1);
1392 /* We expect that ccstack[dbcxix] is CXt_SUB, anyway, the
1393 field below is defined for any cx. */
1394 if (PL_DBsub && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub))
1395 cx = &ccstack[dbcxix];
1398 stashname = CopSTASHPV(cx->blk_oldcop);
1399 if (GIMME != G_ARRAY) {
1402 PUSHs(&PL_sv_undef);
1405 sv_setpv(TARG, stashname);
1414 PUSHs(&PL_sv_undef);
1416 PUSHs(sv_2mortal(newSVpv(stashname, 0)));
1417 PUSHs(sv_2mortal(newSVpv(OutCopFILE(cx->blk_oldcop), 0)));
1418 PUSHs(sv_2mortal(newSViv((I32)CopLINE(cx->blk_oldcop))));
1421 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1422 /* So is ccstack[dbcxix]. */
1424 gv_efullname3(sv, CvGV(ccstack[cxix].blk_sub.cv), Nullch);
1425 PUSHs(sv_2mortal(sv));
1426 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1429 PUSHs(sv_2mortal(newSVpvn("(eval)",6)));
1430 PUSHs(sv_2mortal(newSViv(0)));
1432 gimme = (I32)cx->blk_gimme;
1433 if (gimme == G_VOID)
1434 PUSHs(&PL_sv_undef);
1436 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1437 if (CxTYPE(cx) == CXt_EVAL) {
1439 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1440 PUSHs(cx->blk_eval.cur_text);
1444 else if (cx->blk_eval.old_namesv) {
1445 PUSHs(sv_2mortal(newSVsv(cx->blk_eval.old_namesv)));
1448 /* eval BLOCK (try blocks have old_namesv == 0) */
1450 PUSHs(&PL_sv_undef);
1451 PUSHs(&PL_sv_undef);
1455 PUSHs(&PL_sv_undef);
1456 PUSHs(&PL_sv_undef);
1458 if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.hasargs
1459 && CopSTASH_eq(PL_curcop, PL_debstash))
1461 AV *ary = cx->blk_sub.argarray;
1462 int off = AvARRAY(ary) - AvALLOC(ary);
1466 PL_dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1469 AvREAL_off(PL_dbargs); /* XXX should be REIFY (see av.h) */
1472 if (AvMAX(PL_dbargs) < AvFILLp(ary) + off)
1473 av_extend(PL_dbargs, AvFILLp(ary) + off);
1474 Copy(AvALLOC(ary), AvARRAY(PL_dbargs), AvFILLp(ary) + 1 + off, SV*);
1475 AvFILLp(PL_dbargs) = AvFILLp(ary) + off;
1477 /* XXX only hints propagated via op_private are currently
1478 * visible (others are not easily accessible, since they
1479 * use the global PL_hints) */
1480 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->op_private &
1481 HINT_PRIVATE_MASK)));
1484 SV * old_warnings = cx->blk_oldcop->cop_warnings ;
1486 if (old_warnings == pWARN_NONE ||
1487 (old_warnings == pWARN_STD && (PL_dowarn & G_WARN_ON) == 0))
1488 mask = newSVpvn(WARN_NONEstring, WARNsize) ;
1489 else if (old_warnings == pWARN_ALL ||
1490 (old_warnings == pWARN_STD && PL_dowarn & G_WARN_ON))
1491 mask = newSVpvn(WARN_ALLstring, WARNsize) ;
1493 mask = newSVsv(old_warnings);
1494 PUSHs(sv_2mortal(mask));
1509 sv_reset(tmps, CopSTASH(PL_curcop));
1521 PL_curcop = (COP*)PL_op;
1522 TAINT_NOT; /* Each statement is presumed innocent */
1523 PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
1526 if (PL_op->op_private || SvIV(PL_DBsingle) || SvIV(PL_DBsignal) || SvIV(PL_DBtrace))
1530 register PERL_CONTEXT *cx;
1531 I32 gimme = G_ARRAY;
1538 DIE(aTHX_ "No DB::DB routine defined");
1540 if (CvDEPTH(cv) >= 1 && !(PL_debug & DEBUG_DB_RECURSE_FLAG))
1541 /* don't do recursive DB::DB call */
1553 push_return(PL_op->op_next);
1554 PUSHBLOCK(cx, CXt_SUB, SP);
1557 (void)SvREFCNT_inc(cv);
1558 SAVEVPTR(PL_curpad);
1559 PL_curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1560 RETURNOP(CvSTART(cv));
1574 register PERL_CONTEXT *cx;
1575 I32 gimme = GIMME_V;
1577 U32 cxtype = CXt_LOOP;
1585 #ifdef USE_5005THREADS
1586 if (PL_op->op_flags & OPf_SPECIAL) {
1587 svp = &THREADSV(PL_op->op_targ); /* per-thread variable */
1588 SAVEGENERICSV(*svp);
1592 #endif /* USE_5005THREADS */
1593 if (PL_op->op_targ) {
1594 #ifndef USE_ITHREADS
1595 svp = &PL_curpad[PL_op->op_targ]; /* "my" variable */
1598 SAVEPADSV(PL_op->op_targ);
1599 iterdata = INT2PTR(void*, PL_op->op_targ);
1600 cxtype |= CXp_PADVAR;
1605 svp = &GvSV(gv); /* symbol table variable */
1606 SAVEGENERICSV(*svp);
1609 iterdata = (void*)gv;
1615 PUSHBLOCK(cx, cxtype, SP);
1617 PUSHLOOP(cx, iterdata, MARK);
1619 PUSHLOOP(cx, svp, MARK);
1621 if (PL_op->op_flags & OPf_STACKED) {
1622 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1623 if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) {
1625 if (SvNIOKp(sv) || !SvPOKp(sv) ||
1626 SvNIOKp(cx->blk_loop.iterary) || !SvPOKp(cx->blk_loop.iterary) ||
1627 (looks_like_number(sv) && *SvPVX(sv) != '0' &&
1628 looks_like_number((SV*)cx->blk_loop.iterary) &&
1629 *SvPVX(cx->blk_loop.iterary) != '0'))
1631 if (SvNV(sv) < IV_MIN ||
1632 SvNV((SV*)cx->blk_loop.iterary) >= IV_MAX)
1633 DIE(aTHX_ "Range iterator outside integer range");
1634 cx->blk_loop.iterix = SvIV(sv);
1635 cx->blk_loop.itermax = SvIV((SV*)cx->blk_loop.iterary);
1638 cx->blk_loop.iterlval = newSVsv(sv);
1642 cx->blk_loop.iterary = PL_curstack;
1643 AvFILLp(PL_curstack) = SP - PL_stack_base;
1644 cx->blk_loop.iterix = MARK - PL_stack_base;
1653 register PERL_CONTEXT *cx;
1654 I32 gimme = GIMME_V;
1660 PUSHBLOCK(cx, CXt_LOOP, SP);
1661 PUSHLOOP(cx, 0, SP);
1669 register PERL_CONTEXT *cx;
1677 newsp = PL_stack_base + cx->blk_loop.resetsp;
1680 if (gimme == G_VOID)
1682 else if (gimme == G_SCALAR) {
1684 *++newsp = sv_mortalcopy(*SP);
1686 *++newsp = &PL_sv_undef;
1690 *++newsp = sv_mortalcopy(*++mark);
1691 TAINT_NOT; /* Each item is independent */
1697 POPLOOP(cx); /* Stack values are safe: release loop vars ... */
1698 PL_curpm = newpm; /* ... and pop $1 et al */
1710 register PERL_CONTEXT *cx;
1711 bool popsub2 = FALSE;
1712 bool clear_errsv = FALSE;
1719 if (PL_curstackinfo->si_type == PERLSI_SORT) {
1720 if (cxstack_ix == PL_sortcxix
1721 || dopoptosub(cxstack_ix) <= PL_sortcxix)
1723 if (cxstack_ix > PL_sortcxix)
1724 dounwind(PL_sortcxix);
1725 AvARRAY(PL_curstack)[1] = *SP;
1726 PL_stack_sp = PL_stack_base + 1;
1731 cxix = dopoptosub(cxstack_ix);
1733 DIE(aTHX_ "Can't return outside a subroutine");
1734 if (cxix < cxstack_ix)
1738 switch (CxTYPE(cx)) {
1743 if (!(PL_in_eval & EVAL_KEEPERR))
1749 if (optype == OP_REQUIRE &&
1750 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1752 /* Unassume the success we assumed earlier. */
1753 SV *nsv = cx->blk_eval.old_namesv;
1754 (void)hv_delete(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), G_DISCARD);
1755 DIE(aTHX_ "%s did not return a true value", SvPVX(nsv));
1762 DIE(aTHX_ "panic: return");
1766 if (gimme == G_SCALAR) {
1769 if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
1771 *++newsp = SvREFCNT_inc(*SP);
1776 sv = SvREFCNT_inc(*SP); /* FREETMPS could clobber it */
1778 *++newsp = sv_mortalcopy(sv);
1783 *++newsp = (SvTEMP(*SP)) ? *SP : sv_mortalcopy(*SP);
1786 *++newsp = sv_mortalcopy(*SP);
1789 *++newsp = &PL_sv_undef;
1791 else if (gimme == G_ARRAY) {
1792 while (++MARK <= SP) {
1793 *++newsp = (popsub2 && SvTEMP(*MARK))
1794 ? *MARK : sv_mortalcopy(*MARK);
1795 TAINT_NOT; /* Each item is independent */
1798 PL_stack_sp = newsp;
1800 /* Stack values are safe: */
1802 POPSUB(cx,sv); /* release CV and @_ ... */
1806 PL_curpm = newpm; /* ... and pop $1 et al */
1812 return pop_return();
1819 register PERL_CONTEXT *cx;
1829 if (PL_op->op_flags & OPf_SPECIAL) {
1830 cxix = dopoptoloop(cxstack_ix);
1832 DIE(aTHX_ "Can't \"last\" outside a loop block");
1835 cxix = dopoptolabel(cPVOP->op_pv);
1837 DIE(aTHX_ "Label not found for \"last %s\"", cPVOP->op_pv);
1839 if (cxix < cxstack_ix)
1844 switch (CxTYPE(cx)) {
1847 newsp = PL_stack_base + cx->blk_loop.resetsp;
1848 nextop = cx->blk_loop.last_op->op_next;
1852 nextop = pop_return();
1856 nextop = pop_return();
1860 nextop = pop_return();
1863 DIE(aTHX_ "panic: last");
1867 if (gimme == G_SCALAR) {
1869 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
1870 ? *SP : sv_mortalcopy(*SP);
1872 *++newsp = &PL_sv_undef;
1874 else if (gimme == G_ARRAY) {
1875 while (++MARK <= SP) {
1876 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
1877 ? *MARK : sv_mortalcopy(*MARK);
1878 TAINT_NOT; /* Each item is independent */
1884 /* Stack values are safe: */
1887 POPLOOP(cx); /* release loop vars ... */
1891 POPSUB(cx,sv); /* release CV and @_ ... */
1894 PL_curpm = newpm; /* ... and pop $1 et al */
1904 register PERL_CONTEXT *cx;
1907 if (PL_op->op_flags & OPf_SPECIAL) {
1908 cxix = dopoptoloop(cxstack_ix);
1910 DIE(aTHX_ "Can't \"next\" outside a loop block");
1913 cxix = dopoptolabel(cPVOP->op_pv);
1915 DIE(aTHX_ "Label not found for \"next %s\"", cPVOP->op_pv);
1917 if (cxix < cxstack_ix)
1920 /* clear off anything above the scope we're re-entering, but
1921 * save the rest until after a possible continue block */
1922 inner = PL_scopestack_ix;
1924 if (PL_scopestack_ix < inner)
1925 leave_scope(PL_scopestack[PL_scopestack_ix]);
1926 return cx->blk_loop.next_op;
1932 register PERL_CONTEXT *cx;
1935 if (PL_op->op_flags & OPf_SPECIAL) {
1936 cxix = dopoptoloop(cxstack_ix);
1938 DIE(aTHX_ "Can't \"redo\" outside a loop block");
1941 cxix = dopoptolabel(cPVOP->op_pv);
1943 DIE(aTHX_ "Label not found for \"redo %s\"", cPVOP->op_pv);
1945 if (cxix < cxstack_ix)
1949 oldsave = PL_scopestack[PL_scopestack_ix - 1];
1950 LEAVE_SCOPE(oldsave);
1951 return cx->blk_loop.redo_op;
1955 S_dofindlabel(pTHX_ OP *o, char *label, OP **opstack, OP **oplimit)
1959 static char too_deep[] = "Target of goto is too deeply nested";
1962 Perl_croak(aTHX_ too_deep);
1963 if (o->op_type == OP_LEAVE ||
1964 o->op_type == OP_SCOPE ||
1965 o->op_type == OP_LEAVELOOP ||
1966 o->op_type == OP_LEAVETRY)
1968 *ops++ = cUNOPo->op_first;
1970 Perl_croak(aTHX_ too_deep);
1973 if (o->op_flags & OPf_KIDS) {
1974 /* First try all the kids at this level, since that's likeliest. */
1975 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1976 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1977 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1980 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1981 if (kid == PL_lastgotoprobe)
1983 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1985 (ops[-1]->op_type != OP_NEXTSTATE &&
1986 ops[-1]->op_type != OP_DBSTATE)))
1988 if ((o = dofindlabel(kid, label, ops, oplimit)))
2007 register PERL_CONTEXT *cx;
2008 #define GOTO_DEPTH 64
2009 OP *enterops[GOTO_DEPTH];
2011 int do_dump = (PL_op->op_type == OP_DUMP);
2012 static char must_have_label[] = "goto must have label";
2015 if (PL_op->op_flags & OPf_STACKED) {
2019 /* This egregious kludge implements goto &subroutine */
2020 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
2022 register PERL_CONTEXT *cx;
2023 CV* cv = (CV*)SvRV(sv);
2029 if (!CvROOT(cv) && !CvXSUB(cv)) {
2034 /* autoloaded stub? */
2035 if (cv != GvCV(gv) && (cv = GvCV(gv)))
2037 autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv),
2038 GvNAMELEN(gv), FALSE);
2039 if (autogv && (cv = GvCV(autogv)))
2041 tmpstr = sv_newmortal();
2042 gv_efullname3(tmpstr, gv, Nullch);
2043 DIE(aTHX_ "Goto undefined subroutine &%s",SvPVX(tmpstr));
2045 DIE(aTHX_ "Goto undefined subroutine");
2048 /* First do some returnish stuff. */
2049 cxix = dopoptosub(cxstack_ix);
2051 DIE(aTHX_ "Can't goto subroutine outside a subroutine");
2052 if (cxix < cxstack_ix)
2056 DIE(aTHX_ "Can't goto subroutine from an eval-string");
2058 if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.hasargs) {
2059 /* put @_ back onto stack */
2060 AV* av = cx->blk_sub.argarray;
2062 items = AvFILLp(av) + 1;
2064 EXTEND(PL_stack_sp, items); /* @_ could have been extended. */
2065 Copy(AvARRAY(av), PL_stack_sp, items, SV*);
2066 PL_stack_sp += items;
2067 #ifndef USE_5005THREADS
2068 SvREFCNT_dec(GvAV(PL_defgv));
2069 GvAV(PL_defgv) = cx->blk_sub.savearray;
2070 #endif /* USE_5005THREADS */
2071 /* abandon @_ if it got reified */
2073 (void)sv_2mortal((SV*)av); /* delay until return */
2075 av_extend(av, items-1);
2076 AvFLAGS(av) = AVf_REIFY;
2077 PL_curpad[0] = (SV*)(cx->blk_sub.argarray = av);
2080 else if (CvXSUB(cv)) { /* put GvAV(defgv) back onto stack */
2082 #ifdef USE_5005THREADS
2083 av = (AV*)PL_curpad[0];
2085 av = GvAV(PL_defgv);
2087 items = AvFILLp(av) + 1;
2089 EXTEND(PL_stack_sp, items); /* @_ could have been extended. */
2090 Copy(AvARRAY(av), PL_stack_sp, items, SV*);
2091 PL_stack_sp += items;
2093 if (CxTYPE(cx) == CXt_SUB &&
2094 !(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
2095 SvREFCNT_dec(cx->blk_sub.cv);
2096 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2097 LEAVE_SCOPE(oldsave);
2099 /* Now do some callish stuff. */
2102 #ifdef PERL_XSUB_OLDSTYLE
2103 if (CvOLDSTYLE(cv)) {
2104 I32 (*fp3)(int,int,int);
2109 fp3 = (I32(*)(int,int,int))CvXSUB(cv);
2110 items = (*fp3)(CvXSUBANY(cv).any_i32,
2111 mark - PL_stack_base + 1,
2113 SP = PL_stack_base + items;
2116 #endif /* PERL_XSUB_OLDSTYLE */
2121 PL_stack_sp--; /* There is no cv arg. */
2122 /* Push a mark for the start of arglist */
2124 (void)(*CvXSUB(cv))(aTHX_ cv);
2125 /* Pop the current context like a decent sub should */
2126 POPBLOCK(cx, PL_curpm);
2127 /* Do _not_ use PUTBACK, keep the XSUB's return stack! */
2130 return pop_return();
2133 AV* padlist = CvPADLIST(cv);
2134 SV** svp = AvARRAY(padlist);
2135 if (CxTYPE(cx) == CXt_EVAL) {
2136 PL_in_eval = cx->blk_eval.old_in_eval;
2137 PL_eval_root = cx->blk_eval.old_eval_root;
2138 cx->cx_type = CXt_SUB;
2139 cx->blk_sub.hasargs = 0;
2141 cx->blk_sub.cv = cv;
2142 cx->blk_sub.olddepth = CvDEPTH(cv);
2144 if (CvDEPTH(cv) < 2)
2145 (void)SvREFCNT_inc(cv);
2146 else { /* save temporaries on recursion? */
2147 if (CvDEPTH(cv) == 100 && ckWARN(WARN_RECURSION))
2148 sub_crush_depth(cv);
2149 if (CvDEPTH(cv) > AvFILLp(padlist)) {
2150 AV *newpad = newAV();
2151 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
2152 I32 ix = AvFILLp((AV*)svp[1]);
2153 I32 names_fill = AvFILLp((AV*)svp[0]);
2154 svp = AvARRAY(svp[0]);
2155 for ( ;ix > 0; ix--) {
2156 if (names_fill >= ix && svp[ix] != &PL_sv_undef) {
2157 char *name = SvPVX(svp[ix]);
2158 if ((SvFLAGS(svp[ix]) & SVf_FAKE)
2161 /* outer lexical or anon code */
2162 av_store(newpad, ix,
2163 SvREFCNT_inc(oldpad[ix]) );
2165 else { /* our own lexical */
2167 av_store(newpad, ix, sv = (SV*)newAV());
2168 else if (*name == '%')
2169 av_store(newpad, ix, sv = (SV*)newHV());
2171 av_store(newpad, ix, sv = NEWSV(0,0));
2175 else if (IS_PADGV(oldpad[ix]) || IS_PADCONST(oldpad[ix])) {
2176 av_store(newpad, ix, sv = SvREFCNT_inc(oldpad[ix]));
2179 av_store(newpad, ix, sv = NEWSV(0,0));
2183 if (cx->blk_sub.hasargs) {
2186 av_store(newpad, 0, (SV*)av);
2187 AvFLAGS(av) = AVf_REIFY;
2189 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
2190 AvFILLp(padlist) = CvDEPTH(cv);
2191 svp = AvARRAY(padlist);
2194 #ifdef USE_5005THREADS
2195 if (!cx->blk_sub.hasargs) {
2196 AV* av = (AV*)PL_curpad[0];
2198 items = AvFILLp(av) + 1;
2200 /* Mark is at the end of the stack. */
2202 Copy(AvARRAY(av), SP + 1, items, SV*);
2207 #endif /* USE_5005THREADS */
2208 SAVEVPTR(PL_curpad);
2209 PL_curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
2210 #ifndef USE_5005THREADS
2211 if (cx->blk_sub.hasargs)
2212 #endif /* USE_5005THREADS */
2214 AV* av = (AV*)PL_curpad[0];
2217 #ifndef USE_5005THREADS
2218 cx->blk_sub.savearray = GvAV(PL_defgv);
2219 GvAV(PL_defgv) = (AV*)SvREFCNT_inc(av);
2220 #endif /* USE_5005THREADS */
2221 cx->blk_sub.oldcurpad = PL_curpad;
2222 cx->blk_sub.argarray = av;
2225 if (items >= AvMAX(av) + 1) {
2227 if (AvARRAY(av) != ary) {
2228 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
2229 SvPVX(av) = (char*)ary;
2231 if (items >= AvMAX(av) + 1) {
2232 AvMAX(av) = items - 1;
2233 Renew(ary,items+1,SV*);
2235 SvPVX(av) = (char*)ary;
2238 Copy(mark,AvARRAY(av),items,SV*);
2239 AvFILLp(av) = items - 1;
2240 assert(!AvREAL(av));
2247 if (PERLDB_SUB) { /* Checking curstash breaks DProf. */
2249 * We do not care about using sv to call CV;
2250 * it's for informational purposes only.
2252 SV *sv = GvSV(PL_DBsub);
2255 if (PERLDB_SUB_NN) {
2256 SvIVX(sv) = PTR2IV(cv); /* Already upgraded, saved */
2259 gv_efullname3(sv, CvGV(cv), Nullch);
2262 && (gotocv = get_cv("DB::goto", FALSE)) ) {
2263 PUSHMARK( PL_stack_sp );
2264 call_sv((SV*)gotocv, G_SCALAR | G_NODEBUG);
2268 RETURNOP(CvSTART(cv));
2272 label = SvPV(sv,n_a);
2273 if (!(do_dump || *label))
2274 DIE(aTHX_ must_have_label);
2277 else if (PL_op->op_flags & OPf_SPECIAL) {
2279 DIE(aTHX_ must_have_label);
2282 label = cPVOP->op_pv;
2284 if (label && *label) {
2286 bool leaving_eval = FALSE;
2287 PERL_CONTEXT *last_eval_cx = 0;
2291 PL_lastgotoprobe = 0;
2293 for (ix = cxstack_ix; ix >= 0; ix--) {
2295 switch (CxTYPE(cx)) {
2297 leaving_eval = TRUE;
2298 if (CxREALEVAL(cx)) {
2299 gotoprobe = (last_eval_cx ?
2300 last_eval_cx->blk_eval.old_eval_root :
2305 /* else fall through */
2307 gotoprobe = cx->blk_oldcop->op_sibling;
2313 gotoprobe = cx->blk_oldcop->op_sibling;
2315 gotoprobe = PL_main_root;
2318 if (CvDEPTH(cx->blk_sub.cv)) {
2319 gotoprobe = CvROOT(cx->blk_sub.cv);
2325 DIE(aTHX_ "Can't \"goto\" out of a pseudo block");
2328 DIE(aTHX_ "panic: goto");
2329 gotoprobe = PL_main_root;
2333 retop = dofindlabel(gotoprobe, label,
2334 enterops, enterops + GOTO_DEPTH);
2338 PL_lastgotoprobe = gotoprobe;
2341 DIE(aTHX_ "Can't find label %s", label);
2343 /* if we're leaving an eval, check before we pop any frames
2344 that we're not going to punt, otherwise the error
2347 if (leaving_eval && *enterops && enterops[1]) {
2349 for (i = 1; enterops[i]; i++)
2350 if (enterops[i]->op_type == OP_ENTERITER)
2351 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2354 /* pop unwanted frames */
2356 if (ix < cxstack_ix) {
2363 oldsave = PL_scopestack[PL_scopestack_ix];
2364 LEAVE_SCOPE(oldsave);
2367 /* push wanted frames */
2369 if (*enterops && enterops[1]) {
2371 for (ix = 1; enterops[ix]; ix++) {
2372 PL_op = enterops[ix];
2373 /* Eventually we may want to stack the needed arguments
2374 * for each op. For now, we punt on the hard ones. */
2375 if (PL_op->op_type == OP_ENTERITER)
2376 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2377 CALL_FPTR(PL_op->op_ppaddr)(aTHX);
2385 if (!retop) retop = PL_main_start;
2387 PL_restartop = retop;
2388 PL_do_undump = TRUE;
2392 PL_restartop = 0; /* hmm, must be GNU unexec().. */
2393 PL_do_undump = FALSE;
2409 if (anum == 1 && (PL_op->op_private & OPpEXIT_VMSISH))
2411 VMSISH_HUSHED = VMSISH_HUSHED || (PL_op->op_private & OPpHUSH_VMSISH);
2414 PL_exit_flags |= PERL_EXIT_EXPECTED;
2416 PUSHs(&PL_sv_undef);
2424 NV value = SvNVx(GvSV(cCOP->cop_gv));
2425 register I32 match = I_32(value);
2428 if (((NV)match) > value)
2429 --match; /* was fractional--truncate other way */
2431 match -= cCOP->uop.scop.scop_offset;
2434 else if (match > cCOP->uop.scop.scop_max)
2435 match = cCOP->uop.scop.scop_max;
2436 PL_op = cCOP->uop.scop.scop_next[match];
2446 PL_op = PL_op->op_next; /* can't assume anything */
2449 match = *(SvPVx(GvSV(cCOP->cop_gv), n_a)) & 255;
2450 match -= cCOP->uop.scop.scop_offset;
2453 else if (match > cCOP->uop.scop.scop_max)
2454 match = cCOP->uop.scop.scop_max;
2455 PL_op = cCOP->uop.scop.scop_next[match];
2464 S_save_lines(pTHX_ AV *array, SV *sv)
2466 register char *s = SvPVX(sv);
2467 register char *send = SvPVX(sv) + SvCUR(sv);
2469 register I32 line = 1;
2471 while (s && s < send) {
2472 SV *tmpstr = NEWSV(85,0);
2474 sv_upgrade(tmpstr, SVt_PVMG);
2475 t = strchr(s, '\n');
2481 sv_setpvn(tmpstr, s, t - s);
2482 av_store(array, line++, tmpstr);
2487 #ifdef PERL_FLEXIBLE_EXCEPTIONS
2489 S_docatch_body(pTHX_ va_list args)
2491 return docatch_body();
2496 S_docatch_body(pTHX)
2503 S_docatch(pTHX_ OP *o)
2507 volatile PERL_SI *cursi = PL_curstackinfo;
2511 assert(CATCH_GET == TRUE);
2514 #ifdef PERL_FLEXIBLE_EXCEPTIONS
2516 CALLPROTECT(aTHX_ pcur_env, &ret, MEMBER_TO_FPTR(S_docatch_body));
2522 #ifndef PERL_FLEXIBLE_EXCEPTIONS
2528 if (PL_restartop && cursi == PL_curstackinfo) {
2529 PL_op = PL_restartop;
2546 Perl_sv_compile_2op(pTHX_ SV *sv, OP** startop, char *code, AV** avp)
2547 /* sv Text to convert to OP tree. */
2548 /* startop op_free() this to undo. */
2549 /* code Short string id of the caller. */
2551 dSP; /* Make POPBLOCK work. */
2554 I32 gimme = 0; /* SUSPECT - INITIALZE TO WHAT? NI-S */
2558 char tbuf[TYPE_DIGITS(long) + 12 + 10];
2559 char *tmpbuf = tbuf;
2565 /* switch to eval mode */
2567 if (PL_curcop == &PL_compiling) {
2568 SAVECOPSTASH_FREE(&PL_compiling);
2569 CopSTASH_set(&PL_compiling, PL_curstash);
2571 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
2572 SV *sv = sv_newmortal();
2573 Perl_sv_setpvf(aTHX_ sv, "_<(%.10seval %lu)[%s:%"IVdf"]",
2574 code, (unsigned long)++PL_evalseq,
2575 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
2579 sprintf(tmpbuf, "_<(%.10s_eval %lu)", code, (unsigned long)++PL_evalseq);
2580 SAVECOPFILE_FREE(&PL_compiling);
2581 CopFILE_set(&PL_compiling, tmpbuf+2);
2582 SAVECOPLINE(&PL_compiling);
2583 CopLINE_set(&PL_compiling, 1);
2584 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2585 deleting the eval's FILEGV from the stash before gv_check() runs
2586 (i.e. before run-time proper). To work around the coredump that
2587 ensues, we always turn GvMULTI_on for any globals that were
2588 introduced within evals. See force_ident(). GSAR 96-10-12 */
2589 safestr = savepv(tmpbuf);
2590 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
2592 #ifdef OP_IN_REGISTER
2597 PL_hints &= HINT_UTF8;
2600 PL_op->op_type = OP_ENTEREVAL;
2601 PL_op->op_flags = 0; /* Avoid uninit warning. */
2602 PUSHBLOCK(cx, CXt_EVAL|(PL_curcop == &PL_compiling ? 0 : CXp_REAL), SP);
2603 PUSHEVAL(cx, 0, Nullgv);
2604 rop = doeval(G_SCALAR, startop);
2605 POPBLOCK(cx,PL_curpm);
2608 (*startop)->op_type = OP_NULL;
2609 (*startop)->op_ppaddr = PL_ppaddr[OP_NULL];
2611 *avp = (AV*)SvREFCNT_inc(PL_comppad);
2613 if (PL_curcop == &PL_compiling)
2614 PL_compiling.op_private = PL_hints;
2615 #ifdef OP_IN_REGISTER
2621 /* With USE_5005THREADS, eval_owner must be held on entry to doeval */
2623 S_doeval(pTHX_ int gimme, OP** startop)
2631 PL_in_eval = ((saveop && saveop->op_type == OP_REQUIRE)
2632 ? (EVAL_INREQUIRE | (PL_in_eval & EVAL_INEVAL))
2637 /* set up a scratch pad */
2640 SAVEVPTR(PL_curpad);
2641 SAVESPTR(PL_comppad);
2642 SAVESPTR(PL_comppad_name);
2643 SAVEI32(PL_comppad_name_fill);
2644 SAVEI32(PL_min_intro_pending);
2645 SAVEI32(PL_max_intro_pending);
2648 for (i = cxstack_ix - 1; i >= 0; i--) {
2649 PERL_CONTEXT *cx = &cxstack[i];
2650 if (CxTYPE(cx) == CXt_EVAL)
2652 else if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
2653 caller = cx->blk_sub.cv;
2658 SAVESPTR(PL_compcv);
2659 PL_compcv = (CV*)NEWSV(1104,0);
2660 sv_upgrade((SV *)PL_compcv, SVt_PVCV);
2661 CvEVAL_on(PL_compcv);
2662 assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
2663 cxstack[cxstack_ix].blk_eval.cv = PL_compcv;
2665 #ifdef USE_5005THREADS
2666 CvOWNER(PL_compcv) = 0;
2667 New(666, CvMUTEXP(PL_compcv), 1, perl_mutex);
2668 MUTEX_INIT(CvMUTEXP(PL_compcv));
2669 #endif /* USE_5005THREADS */
2671 PL_comppad = newAV();
2672 av_push(PL_comppad, Nullsv);
2673 PL_curpad = AvARRAY(PL_comppad);
2674 PL_comppad_name = newAV();
2675 PL_comppad_name_fill = 0;
2676 PL_min_intro_pending = 0;
2678 #ifdef USE_5005THREADS
2679 av_store(PL_comppad_name, 0, newSVpvn("@_", 2));
2680 PL_curpad[0] = (SV*)newAV();
2681 SvPADMY_on(PL_curpad[0]); /* XXX Needed? */
2682 #endif /* USE_5005THREADS */
2684 comppadlist = newAV();
2685 AvREAL_off(comppadlist);
2686 av_store(comppadlist, 0, (SV*)PL_comppad_name);
2687 av_store(comppadlist, 1, (SV*)PL_comppad);
2688 CvPADLIST(PL_compcv) = comppadlist;
2691 (saveop->op_type != OP_REQUIRE && saveop->op_type != OP_DOFILE))
2693 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(caller);
2696 SAVEMORTALIZESV(PL_compcv); /* must remain until end of current statement */
2698 /* make sure we compile in the right package */
2700 if (CopSTASH_ne(PL_curcop, PL_curstash)) {
2701 SAVESPTR(PL_curstash);
2702 PL_curstash = CopSTASH(PL_curcop);
2704 SAVESPTR(PL_beginav);
2705 PL_beginav = newAV();
2706 SAVEFREESV(PL_beginav);
2707 SAVEI32(PL_error_count);
2709 /* try to compile it */
2711 PL_eval_root = Nullop;
2713 PL_curcop = &PL_compiling;
2714 PL_curcop->cop_arybase = 0;
2715 if (saveop && saveop->op_flags & OPf_SPECIAL)
2716 PL_in_eval |= EVAL_KEEPERR;
2719 if (yyparse() || PL_error_count || !PL_eval_root) {
2723 I32 optype = 0; /* Might be reset by POPEVAL. */
2728 op_free(PL_eval_root);
2729 PL_eval_root = Nullop;
2731 SP = PL_stack_base + POPMARK; /* pop original mark */
2733 POPBLOCK(cx,PL_curpm);
2739 if (optype == OP_REQUIRE) {
2740 char* msg = SvPVx(ERRSV, n_a);
2741 DIE(aTHX_ "%sCompilation failed in require",
2742 *msg ? msg : "Unknown error\n");
2745 char* msg = SvPVx(ERRSV, n_a);
2747 POPBLOCK(cx,PL_curpm);
2749 Perl_croak(aTHX_ "%sCompilation failed in regexp",
2750 (*msg ? msg : "Unknown error\n"));
2752 #ifdef USE_5005THREADS
2753 MUTEX_LOCK(&PL_eval_mutex);
2755 COND_SIGNAL(&PL_eval_cond);
2756 MUTEX_UNLOCK(&PL_eval_mutex);
2757 #endif /* USE_5005THREADS */
2760 CopLINE_set(&PL_compiling, 0);
2762 *startop = PL_eval_root;
2763 SvREFCNT_dec(CvOUTSIDE(PL_compcv));
2764 CvOUTSIDE(PL_compcv) = Nullcv;
2766 SAVEFREEOP(PL_eval_root);
2768 scalarvoid(PL_eval_root);
2769 else if (gimme & G_ARRAY)
2772 scalar(PL_eval_root);
2774 DEBUG_x(dump_eval());
2776 /* Register with debugger: */
2777 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2778 CV *cv = get_cv("DB::postponed", FALSE);
2782 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2784 call_sv((SV*)cv, G_DISCARD);
2788 /* compiled okay, so do it */
2790 CvDEPTH(PL_compcv) = 1;
2791 SP = PL_stack_base + POPMARK; /* pop original mark */
2792 PL_op = saveop; /* The caller may need it. */
2793 PL_lex_state = LEX_NOTPARSING; /* $^S needs this. */
2794 #ifdef USE_5005THREADS
2795 MUTEX_LOCK(&PL_eval_mutex);
2797 COND_SIGNAL(&PL_eval_cond);
2798 MUTEX_UNLOCK(&PL_eval_mutex);
2799 #endif /* USE_5005THREADS */
2801 RETURNOP(PL_eval_start);
2805 S_doopen_pmc(pTHX_ const char *name, const char *mode)
2807 STRLEN namelen = strlen(name);
2810 if (namelen > 3 && strEQ(name + namelen - 3, ".pm")) {
2811 SV *pmcsv = Perl_newSVpvf(aTHX_ "%s%c", name, 'c');
2812 char *pmc = SvPV_nolen(pmcsv);
2815 if (PerlLIO_stat(pmc, &pmcstat) < 0) {
2816 fp = PerlIO_open(name, mode);
2819 if (PerlLIO_stat(name, &pmstat) < 0 ||
2820 pmstat.st_mtime < pmcstat.st_mtime)
2822 fp = PerlIO_open(pmc, mode);
2825 fp = PerlIO_open(name, mode);
2828 SvREFCNT_dec(pmcsv);
2831 fp = PerlIO_open(name, mode);
2839 register PERL_CONTEXT *cx;
2843 char *tryname = Nullch;
2844 SV *namesv = Nullsv;
2846 I32 gimme = GIMME_V;
2847 PerlIO *tryrsfp = 0;
2849 int filter_has_file = 0;
2850 GV *filter_child_proc = 0;
2851 SV *filter_state = 0;
2859 if (SvPOK(sv) && SvNOK(sv) && SvNV(sv)) { /* require v5.6.1 */
2860 UV rev = 0, ver = 0, sver = 0;
2862 U8 *s = (U8*)SvPVX(sv);
2863 U8 *end = (U8*)SvPVX(sv) + SvCUR(sv);
2865 rev = utf8n_to_uvchr(s, end - s, &len, 0);
2868 ver = utf8n_to_uvchr(s, end - s, &len, 0);
2871 sver = utf8n_to_uvchr(s, end - s, &len, 0);
2874 if (PERL_REVISION < rev
2875 || (PERL_REVISION == rev
2876 && (PERL_VERSION < ver
2877 || (PERL_VERSION == ver
2878 && PERL_SUBVERSION < sver))))
2880 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--this is only "
2881 "v%d.%d.%d, stopped", rev, ver, sver, PERL_REVISION,
2882 PERL_VERSION, PERL_SUBVERSION);
2884 if (ckWARN(WARN_PORTABLE))
2885 Perl_warner(aTHX_ WARN_PORTABLE,
2886 "v-string in use/require non-portable");
2889 else if (!SvPOKp(sv)) { /* require 5.005_03 */
2890 if ((NV)PERL_REVISION + ((NV)PERL_VERSION/(NV)1000)
2891 + ((NV)PERL_SUBVERSION/(NV)1000000)
2892 + 0.00000099 < SvNV(sv))
2896 NV nver = (nrev - rev) * 1000;
2897 UV ver = (UV)(nver + 0.0009);
2898 NV nsver = (nver - ver) * 1000;
2899 UV sver = (UV)(nsver + 0.0009);
2901 /* help out with the "use 5.6" confusion */
2902 if (sver == 0 && (rev > 5 || (rev == 5 && ver >= 100))) {
2903 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--"
2904 "this is only v%d.%d.%d, stopped"
2905 " (did you mean v%"UVuf".%03"UVuf"?)",
2906 rev, ver, sver, PERL_REVISION, PERL_VERSION,
2907 PERL_SUBVERSION, rev, ver/100);
2910 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--"
2911 "this is only v%d.%d.%d, stopped",
2912 rev, ver, sver, PERL_REVISION, PERL_VERSION,
2919 name = SvPV(sv, len);
2920 if (!(name && len > 0 && *name))
2921 DIE(aTHX_ "Null filename used");
2922 TAINT_PROPER("require");
2923 if (PL_op->op_type == OP_REQUIRE &&
2924 (svp = hv_fetch(GvHVn(PL_incgv), name, len, 0)) &&
2925 *svp != &PL_sv_undef)
2928 /* prepare to compile file */
2930 if (path_is_absolute(name)) {
2932 tryrsfp = doopen_pmc(name,PERL_SCRIPT_MODE);
2935 AV *ar = GvAVn(PL_incgv);
2939 if ((unixname = tounixspec(name, Nullch)) != Nullch)
2942 namesv = NEWSV(806, 0);
2943 for (i = 0; i <= AvFILL(ar); i++) {
2944 SV *dirsv = *av_fetch(ar, i, TRUE);
2950 if (SvTYPE(SvRV(loader)) == SVt_PVAV
2951 && !sv_isobject(loader))
2953 loader = *av_fetch((AV *)SvRV(loader), 0, TRUE);
2956 Perl_sv_setpvf(aTHX_ namesv, "/loader/0x%"UVxf"/%s",
2957 PTR2UV(SvRV(dirsv)), name);
2958 tryname = SvPVX(namesv);
2969 if (sv_isobject(loader))
2970 count = call_method("INC", G_ARRAY);
2972 count = call_sv(loader, G_ARRAY);
2982 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVGV) {
2986 if (SvTYPE(arg) == SVt_PVGV) {
2987 IO *io = GvIO((GV *)arg);
2992 tryrsfp = IoIFP(io);
2993 if (IoTYPE(io) == IoTYPE_PIPE) {
2994 /* reading from a child process doesn't
2995 nest -- when returning from reading
2996 the inner module, the outer one is
2997 unreadable (closed?) I've tried to
2998 save the gv to manage the lifespan of
2999 the pipe, but this didn't help. XXX */
3000 filter_child_proc = (GV *)arg;
3001 (void)SvREFCNT_inc(filter_child_proc);
3004 if (IoOFP(io) && IoOFP(io) != IoIFP(io)) {
3005 PerlIO_close(IoOFP(io));
3017 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVCV) {
3019 (void)SvREFCNT_inc(filter_sub);
3022 filter_state = SP[i];
3023 (void)SvREFCNT_inc(filter_state);
3027 tryrsfp = PerlIO_open("/dev/null",
3042 filter_has_file = 0;
3043 if (filter_child_proc) {
3044 SvREFCNT_dec(filter_child_proc);
3045 filter_child_proc = 0;
3048 SvREFCNT_dec(filter_state);
3052 SvREFCNT_dec(filter_sub);
3057 if (!path_is_absolute(name)
3058 #ifdef MACOS_TRADITIONAL
3059 /* We consider paths of the form :a:b ambiguous and interpret them first
3060 as global then as local
3062 || (*name == ':' && name[1] != ':' && strchr(name+2, ':'))
3065 char *dir = SvPVx(dirsv, n_a);
3066 #ifdef MACOS_TRADITIONAL
3068 Perl_sv_setpvf(aTHX_ namesv, "%s%s", MacPerl_CanonDir(dir, buf), name+(name[0] == ':'));
3072 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
3074 sv_setpv(namesv, unixdir);
3075 sv_catpv(namesv, unixname);
3077 Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name);
3080 TAINT_PROPER("require");
3081 tryname = SvPVX(namesv);
3082 #ifdef MACOS_TRADITIONAL
3084 /* Convert slashes in the name part, but not the directory part, to colons */
3086 for (colon = tryname+strlen(dir); colon = strchr(colon, '/'); )
3090 tryrsfp = doopen_pmc(tryname, PERL_SCRIPT_MODE);
3092 if (tryname[0] == '.' && tryname[1] == '/')
3101 SAVECOPFILE_FREE(&PL_compiling);
3102 CopFILE_set(&PL_compiling, tryrsfp ? tryname : name);
3103 SvREFCNT_dec(namesv);
3105 if (PL_op->op_type == OP_REQUIRE) {
3106 char *msgstr = name;
3107 if (namesv) { /* did we lookup @INC? */
3108 SV *msg = sv_2mortal(newSVpv(msgstr,0));
3109 SV *dirmsgsv = NEWSV(0, 0);
3110 AV *ar = GvAVn(PL_incgv);
3112 sv_catpvn(msg, " in @INC", 8);
3113 if (instr(SvPVX(msg), ".h "))
3114 sv_catpv(msg, " (change .h to .ph maybe?)");
3115 if (instr(SvPVX(msg), ".ph "))
3116 sv_catpv(msg, " (did you run h2ph?)");
3117 sv_catpv(msg, " (@INC contains:");
3118 for (i = 0; i <= AvFILL(ar); i++) {
3119 char *dir = SvPVx(*av_fetch(ar, i, TRUE), n_a);
3120 Perl_sv_setpvf(aTHX_ dirmsgsv, " %s", dir);
3121 sv_catsv(msg, dirmsgsv);
3123 sv_catpvn(msg, ")", 1);
3124 SvREFCNT_dec(dirmsgsv);
3125 msgstr = SvPV_nolen(msg);
3127 DIE(aTHX_ "Can't locate %s", msgstr);
3133 SETERRNO(0, SS$_NORMAL);
3135 /* Assume success here to prevent recursive requirement. */
3137 /* Check whether a hook in @INC has already filled %INC */
3138 if (!hook_sv || !(svp = hv_fetch(GvHVn(PL_incgv), name, len, 0))) {
3139 (void)hv_store(GvHVn(PL_incgv), name, len,
3140 (hook_sv ? SvREFCNT_inc(hook_sv)
3141 : newSVpv(CopFILE(&PL_compiling), 0)),
3147 lex_start(sv_2mortal(newSVpvn("",0)));
3148 SAVEGENERICSV(PL_rsfp_filters);
3149 PL_rsfp_filters = Nullav;
3154 SAVESPTR(PL_compiling.cop_warnings);
3155 if (PL_dowarn & G_WARN_ALL_ON)
3156 PL_compiling.cop_warnings = pWARN_ALL ;
3157 else if (PL_dowarn & G_WARN_ALL_OFF)
3158 PL_compiling.cop_warnings = pWARN_NONE ;
3159 else if (PL_taint_warn)
3160 PL_compiling.cop_warnings = newSVpvn(WARN_TAINTstring, WARNsize);
3162 PL_compiling.cop_warnings = pWARN_STD ;
3163 SAVESPTR(PL_compiling.cop_io);
3164 PL_compiling.cop_io = Nullsv;
3166 if (filter_sub || filter_child_proc) {
3167 SV *datasv = filter_add(run_user_filter, Nullsv);
3168 IoLINES(datasv) = filter_has_file;
3169 IoFMT_GV(datasv) = (GV *)filter_child_proc;
3170 IoTOP_GV(datasv) = (GV *)filter_state;
3171 IoBOTTOM_GV(datasv) = (GV *)filter_sub;
3174 /* switch to eval mode */
3175 push_return(PL_op->op_next);
3176 PUSHBLOCK(cx, CXt_EVAL, SP);
3177 PUSHEVAL(cx, name, Nullgv);
3179 SAVECOPLINE(&PL_compiling);
3180 CopLINE_set(&PL_compiling, 0);
3183 #ifdef USE_5005THREADS
3184 MUTEX_LOCK(&PL_eval_mutex);
3185 if (PL_eval_owner && PL_eval_owner != thr)
3186 while (PL_eval_owner)
3187 COND_WAIT(&PL_eval_cond, &PL_eval_mutex);
3188 PL_eval_owner = thr;
3189 MUTEX_UNLOCK(&PL_eval_mutex);
3190 #endif /* USE_5005THREADS */
3192 /* Store and reset encoding. */
3193 encoding = PL_encoding;
3194 PL_encoding = Nullsv;
3196 op = DOCATCH(doeval(gimme, NULL));
3198 /* Restore encoding. */
3199 PL_encoding = encoding;
3206 return pp_require();
3212 register PERL_CONTEXT *cx;
3214 I32 gimme = GIMME_V, was = PL_sub_generation;
3215 char tbuf[TYPE_DIGITS(long) + 12];
3216 char *tmpbuf = tbuf;
3221 if (!SvPV(sv,len) || !len)
3223 TAINT_PROPER("eval");
3229 /* switch to eval mode */
3231 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
3232 SV *sv = sv_newmortal();
3233 Perl_sv_setpvf(aTHX_ sv, "_<(eval %lu)[%s:%"IVdf"]",
3234 (unsigned long)++PL_evalseq,
3235 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
3239 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++PL_evalseq);
3240 SAVECOPFILE_FREE(&PL_compiling);
3241 CopFILE_set(&PL_compiling, tmpbuf+2);
3242 SAVECOPLINE(&PL_compiling);
3243 CopLINE_set(&PL_compiling, 1);
3244 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
3245 deleting the eval's FILEGV from the stash before gv_check() runs
3246 (i.e. before run-time proper). To work around the coredump that
3247 ensues, we always turn GvMULTI_on for any globals that were
3248 introduced within evals. See force_ident(). GSAR 96-10-12 */
3249 safestr = savepv(tmpbuf);
3250 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
3252 PL_hints = PL_op->op_targ;
3253 SAVESPTR(PL_compiling.cop_warnings);
3254 if (specialWARN(PL_curcop->cop_warnings))
3255 PL_compiling.cop_warnings = PL_curcop->cop_warnings;
3257 PL_compiling.cop_warnings = newSVsv(PL_curcop->cop_warnings);
3258 SAVEFREESV(PL_compiling.cop_warnings);
3260 SAVESPTR(PL_compiling.cop_io);
3261 if (specialCopIO(PL_curcop->cop_io))
3262 PL_compiling.cop_io = PL_curcop->cop_io;
3264 PL_compiling.cop_io = newSVsv(PL_curcop->cop_io);
3265 SAVEFREESV(PL_compiling.cop_io);
3268 push_return(PL_op->op_next);
3269 PUSHBLOCK(cx, (CXt_EVAL|CXp_REAL), SP);
3270 PUSHEVAL(cx, 0, Nullgv);
3272 /* prepare to compile string */
3274 if (PERLDB_LINE && PL_curstash != PL_debstash)
3275 save_lines(CopFILEAV(&PL_compiling), PL_linestr);
3277 #ifdef USE_5005THREADS
3278 MUTEX_LOCK(&PL_eval_mutex);
3279 if (PL_eval_owner && PL_eval_owner != thr)
3280 while (PL_eval_owner)
3281 COND_WAIT(&PL_eval_cond, &PL_eval_mutex);
3282 PL_eval_owner = thr;
3283 MUTEX_UNLOCK(&PL_eval_mutex);
3284 #endif /* USE_5005THREADS */
3285 ret = doeval(gimme, NULL);
3286 if (PERLDB_INTER && was != PL_sub_generation /* Some subs defined here. */
3287 && ret != PL_op->op_next) { /* Successive compilation. */
3288 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
3290 return DOCATCH(ret);
3300 register PERL_CONTEXT *cx;
3302 U8 save_flags = PL_op -> op_flags;
3307 retop = pop_return();
3310 if (gimme == G_VOID)
3312 else if (gimme == G_SCALAR) {
3315 if (SvFLAGS(TOPs) & SVs_TEMP)
3318 *MARK = sv_mortalcopy(TOPs);
3322 *MARK = &PL_sv_undef;
3327 /* in case LEAVE wipes old return values */
3328 for (mark = newsp + 1; mark <= SP; mark++) {
3329 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
3330 *mark = sv_mortalcopy(*mark);
3331 TAINT_NOT; /* Each item is independent */
3335 PL_curpm = newpm; /* Don't pop $1 et al till now */
3338 assert(CvDEPTH(PL_compcv) == 1);
3340 CvDEPTH(PL_compcv) = 0;
3343 if (optype == OP_REQUIRE &&
3344 !(gimme == G_SCALAR ? SvTRUE(*SP) : SP > newsp))
3346 /* Unassume the success we assumed earlier. */
3347 SV *nsv = cx->blk_eval.old_namesv;
3348 (void)hv_delete(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), G_DISCARD);
3349 retop = Perl_die(aTHX_ "%s did not return a true value", SvPVX(nsv));
3350 /* die_where() did LEAVE, or we won't be here */
3354 if (!(save_flags & OPf_SPECIAL))
3364 register PERL_CONTEXT *cx;
3365 I32 gimme = GIMME_V;
3370 push_return(cLOGOP->op_other->op_next);
3371 PUSHBLOCK(cx, (CXt_EVAL|CXp_TRYBLOCK), SP);
3374 PL_in_eval = EVAL_INEVAL;
3377 return DOCATCH(PL_op->op_next);
3387 register PERL_CONTEXT *cx;
3395 if (gimme == G_VOID)
3397 else if (gimme == G_SCALAR) {
3400 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
3403 *MARK = sv_mortalcopy(TOPs);
3407 *MARK = &PL_sv_undef;
3412 /* in case LEAVE wipes old return values */
3413 for (mark = newsp + 1; mark <= SP; mark++) {
3414 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
3415 *mark = sv_mortalcopy(*mark);
3416 TAINT_NOT; /* Each item is independent */
3420 PL_curpm = newpm; /* Don't pop $1 et al till now */
3428 S_doparseform(pTHX_ SV *sv)
3431 register char *s = SvPV_force(sv, len);
3432 register char *send = s + len;
3433 register char *base = Nullch;
3434 register I32 skipspaces = 0;
3435 bool noblank = FALSE;
3436 bool repeat = FALSE;
3437 bool postspace = FALSE;
3445 Perl_croak(aTHX_ "Null picture in formline");
3447 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
3452 *fpc++ = FF_LINEMARK;
3453 noblank = repeat = FALSE;
3471 case ' ': case '\t':
3482 *fpc++ = FF_LITERAL;
3490 *fpc++ = skipspaces;
3494 *fpc++ = FF_NEWLINE;
3498 arg = fpc - linepc + 1;
3505 *fpc++ = FF_LINEMARK;
3506 noblank = repeat = FALSE;
3515 ischop = s[-1] == '^';
3521 arg = (s - base) - 1;
3523 *fpc++ = FF_LITERAL;
3532 *fpc++ = FF_LINEGLOB;
3534 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
3535 arg = ischop ? 512 : 0;
3545 arg |= 256 + (s - f);
3547 *fpc++ = s - base; /* fieldsize for FETCH */
3548 *fpc++ = FF_DECIMAL;
3551 else if (*s == '0' && s[1] == '#') { /* Zero padded decimals */
3552 arg = ischop ? 512 : 0;
3554 s++; /* skip the '0' first */
3563 arg |= 256 + (s - f);
3565 *fpc++ = s - base; /* fieldsize for FETCH */
3566 *fpc++ = FF_0DECIMAL;
3571 bool ismore = FALSE;
3574 while (*++s == '>') ;
3575 prespace = FF_SPACE;
3577 else if (*s == '|') {
3578 while (*++s == '|') ;
3579 prespace = FF_HALFSPACE;
3584 while (*++s == '<') ;
3587 if (*s == '.' && s[1] == '.' && s[2] == '.') {
3591 *fpc++ = s - base; /* fieldsize for FETCH */
3593 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
3611 { /* need to jump to the next word */
3613 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
3614 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
3615 s = SvPVX(sv) + SvCUR(sv) + z;
3617 Copy(fops, s, arg, U16);
3619 sv_magic(sv, Nullsv, PERL_MAGIC_fm, Nullch, 0);
3624 run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen)
3626 SV *datasv = FILTER_DATA(idx);
3627 int filter_has_file = IoLINES(datasv);
3628 GV *filter_child_proc = (GV *)IoFMT_GV(datasv);
3629 SV *filter_state = (SV *)IoTOP_GV(datasv);
3630 SV *filter_sub = (SV *)IoBOTTOM_GV(datasv);
3633 /* I was having segfault trouble under Linux 2.2.5 after a
3634 parse error occured. (Had to hack around it with a test
3635 for PL_error_count == 0.) Solaris doesn't segfault --
3636 not sure where the trouble is yet. XXX */
3638 if (filter_has_file) {
3639 len = FILTER_READ(idx+1, buf_sv, maxlen);
3642 if (filter_sub && len >= 0) {
3653 PUSHs(sv_2mortal(newSViv(maxlen)));
3655 PUSHs(filter_state);
3658 count = call_sv(filter_sub, G_SCALAR);
3674 IoLINES(datasv) = 0;
3675 if (filter_child_proc) {
3676 SvREFCNT_dec(filter_child_proc);
3677 IoFMT_GV(datasv) = Nullgv;
3680 SvREFCNT_dec(filter_state);
3681 IoTOP_GV(datasv) = Nullgv;
3684 SvREFCNT_dec(filter_sub);
3685 IoBOTTOM_GV(datasv) = Nullgv;
3687 filter_del(run_user_filter);
3693 /* perhaps someone can come up with a better name for
3694 this? it is not really "absolute", per se ... */
3696 S_path_is_absolute(pTHX_ char *name)
3698 if (PERL_FILE_IS_ABSOLUTE(name)
3699 #ifdef MACOS_TRADITIONAL
3700 || (*name == ':' && name[1] != ':' && strchr(name+2, ':')))
3702 || (*name == '.' && (name[1] == '/' ||
3703 (name[1] == '.' && name[2] == '/'))))