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)
1232 register PERL_CONTEXT *cx;
1237 if (PL_in_eval & EVAL_KEEPERR) {
1238 static char prefix[] = "\t(in cleanup) ";
1243 else if (SvCUR(err) >= sizeof(prefix)+msglen-1) {
1246 if (*e != *message || strNE(e,message))
1250 SvGROW(err, SvCUR(err)+sizeof(prefix)+msglen);
1251 sv_catpvn(err, prefix, sizeof(prefix)-1);
1252 sv_catpvn(err, message, msglen);
1253 if (ckWARN(WARN_MISC)) {
1254 STRLEN start = SvCUR(err)-msglen-sizeof(prefix)+1;
1255 Perl_warner(aTHX_ WARN_MISC, SvPVX(err)+start);
1260 sv_setpvn(ERRSV, message, msglen);
1264 message = SvPVx(ERRSV, msglen);
1266 while ((cxix = dopoptoeval(cxstack_ix)) < 0
1267 && PL_curstackinfo->si_prev)
1276 if (cxix < cxstack_ix)
1279 POPBLOCK(cx,PL_curpm);
1280 if (CxTYPE(cx) != CXt_EVAL) {
1281 PerlIO_write(Perl_error_log, "panic: die ", 11);
1282 PerlIO_write(Perl_error_log, message, msglen);
1287 if (gimme == G_SCALAR)
1288 *++newsp = &PL_sv_undef;
1289 PL_stack_sp = newsp;
1293 /* LEAVE could clobber PL_curcop (see save_re_context())
1294 * XXX it might be better to find a way to avoid messing with
1295 * PL_curcop in save_re_context() instead, but this is a more
1296 * minimal fix --GSAR */
1297 PL_curcop = cx->blk_oldcop;
1299 if (optype == OP_REQUIRE) {
1300 char* msg = SvPVx(ERRSV, n_a);
1301 DIE(aTHX_ "%sCompilation failed in require",
1302 *msg ? msg : "Unknown error\n");
1304 return pop_return();
1308 message = SvPVx(ERRSV, msglen);
1310 /* if STDERR is tied, print to it instead */
1311 if (PL_stderrgv && (io = GvIOp(PL_stderrgv))
1312 && (mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar))) {
1315 XPUSHs(SvTIED_obj((SV*)io, mg));
1316 XPUSHs(sv_2mortal(newSVpvn(message, msglen)));
1318 call_method("PRINT", G_SCALAR);
1323 /* SFIO can really mess with your errno */
1326 PerlIO *serr = Perl_error_log;
1328 PERL_WRITE_MSG_TO_CONSOLE(serr, message, msglen);
1329 (void)PerlIO_flush(serr);
1342 if (SvTRUE(left) != SvTRUE(right))
1354 RETURNOP(cLOGOP->op_other);
1363 RETURNOP(cLOGOP->op_other);
1369 register I32 cxix = dopoptosub(cxstack_ix);
1370 register PERL_CONTEXT *cx;
1371 register PERL_CONTEXT *ccstack = cxstack;
1372 PERL_SI *top_si = PL_curstackinfo;
1383 /* we may be in a higher stacklevel, so dig down deeper */
1384 while (cxix < 0 && top_si->si_type != PERLSI_MAIN) {
1385 top_si = top_si->si_prev;
1386 ccstack = top_si->si_cxstack;
1387 cxix = dopoptosub_at(ccstack, top_si->si_cxix);
1390 if (GIMME != G_ARRAY) {
1396 if (PL_DBsub && cxix >= 0 &&
1397 ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub))
1401 cxix = dopoptosub_at(ccstack, cxix - 1);
1404 cx = &ccstack[cxix];
1405 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1406 dbcxix = dopoptosub_at(ccstack, cxix - 1);
1407 /* We expect that ccstack[dbcxix] is CXt_SUB, anyway, the
1408 field below is defined for any cx. */
1409 if (PL_DBsub && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub))
1410 cx = &ccstack[dbcxix];
1413 stashname = CopSTASHPV(cx->blk_oldcop);
1414 if (GIMME != G_ARRAY) {
1417 PUSHs(&PL_sv_undef);
1420 sv_setpv(TARG, stashname);
1429 PUSHs(&PL_sv_undef);
1431 PUSHs(sv_2mortal(newSVpv(stashname, 0)));
1432 PUSHs(sv_2mortal(newSVpv(OutCopFILE(cx->blk_oldcop), 0)));
1433 PUSHs(sv_2mortal(newSViv((I32)CopLINE(cx->blk_oldcop))));
1436 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1437 /* So is ccstack[dbcxix]. */
1439 gv_efullname3(sv, CvGV(ccstack[cxix].blk_sub.cv), Nullch);
1440 PUSHs(sv_2mortal(sv));
1441 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1444 PUSHs(sv_2mortal(newSVpvn("(eval)",6)));
1445 PUSHs(sv_2mortal(newSViv(0)));
1447 gimme = (I32)cx->blk_gimme;
1448 if (gimme == G_VOID)
1449 PUSHs(&PL_sv_undef);
1451 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1452 if (CxTYPE(cx) == CXt_EVAL) {
1454 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1455 PUSHs(cx->blk_eval.cur_text);
1459 else if (cx->blk_eval.old_namesv) {
1460 PUSHs(sv_2mortal(newSVsv(cx->blk_eval.old_namesv)));
1463 /* eval BLOCK (try blocks have old_namesv == 0) */
1465 PUSHs(&PL_sv_undef);
1466 PUSHs(&PL_sv_undef);
1470 PUSHs(&PL_sv_undef);
1471 PUSHs(&PL_sv_undef);
1473 if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.hasargs
1474 && CopSTASH_eq(PL_curcop, PL_debstash))
1476 AV *ary = cx->blk_sub.argarray;
1477 int off = AvARRAY(ary) - AvALLOC(ary);
1481 PL_dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1484 AvREAL_off(PL_dbargs); /* XXX should be REIFY (see av.h) */
1487 if (AvMAX(PL_dbargs) < AvFILLp(ary) + off)
1488 av_extend(PL_dbargs, AvFILLp(ary) + off);
1489 Copy(AvALLOC(ary), AvARRAY(PL_dbargs), AvFILLp(ary) + 1 + off, SV*);
1490 AvFILLp(PL_dbargs) = AvFILLp(ary) + off;
1492 /* XXX only hints propagated via op_private are currently
1493 * visible (others are not easily accessible, since they
1494 * use the global PL_hints) */
1495 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->op_private &
1496 HINT_PRIVATE_MASK)));
1499 SV * old_warnings = cx->blk_oldcop->cop_warnings ;
1501 if (old_warnings == pWARN_NONE ||
1502 (old_warnings == pWARN_STD && (PL_dowarn & G_WARN_ON) == 0))
1503 mask = newSVpvn(WARN_NONEstring, WARNsize) ;
1504 else if (old_warnings == pWARN_ALL ||
1505 (old_warnings == pWARN_STD && PL_dowarn & G_WARN_ON))
1506 mask = newSVpvn(WARN_ALLstring, WARNsize) ;
1508 mask = newSVsv(old_warnings);
1509 PUSHs(sv_2mortal(mask));
1524 sv_reset(tmps, CopSTASH(PL_curcop));
1536 PL_curcop = (COP*)PL_op;
1537 TAINT_NOT; /* Each statement is presumed innocent */
1538 PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
1541 if (PL_op->op_private || SvIV(PL_DBsingle) || SvIV(PL_DBsignal) || SvIV(PL_DBtrace))
1545 register PERL_CONTEXT *cx;
1546 I32 gimme = G_ARRAY;
1553 DIE(aTHX_ "No DB::DB routine defined");
1555 if (CvDEPTH(cv) >= 1 && !(PL_debug & DEBUG_DB_RECURSE_FLAG))
1556 /* don't do recursive DB::DB call */
1568 push_return(PL_op->op_next);
1569 PUSHBLOCK(cx, CXt_SUB, SP);
1572 (void)SvREFCNT_inc(cv);
1573 SAVEVPTR(PL_curpad);
1574 PL_curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1575 RETURNOP(CvSTART(cv));
1589 register PERL_CONTEXT *cx;
1590 I32 gimme = GIMME_V;
1592 U32 cxtype = CXt_LOOP;
1600 #ifdef USE_5005THREADS
1601 if (PL_op->op_flags & OPf_SPECIAL) {
1602 svp = &THREADSV(PL_op->op_targ); /* per-thread variable */
1603 SAVEGENERICSV(*svp);
1607 #endif /* USE_5005THREADS */
1608 if (PL_op->op_targ) {
1609 #ifndef USE_ITHREADS
1610 svp = &PL_curpad[PL_op->op_targ]; /* "my" variable */
1613 SAVEPADSV(PL_op->op_targ);
1614 iterdata = INT2PTR(void*, PL_op->op_targ);
1615 cxtype |= CXp_PADVAR;
1620 svp = &GvSV(gv); /* symbol table variable */
1621 SAVEGENERICSV(*svp);
1624 iterdata = (void*)gv;
1630 PUSHBLOCK(cx, cxtype, SP);
1632 PUSHLOOP(cx, iterdata, MARK);
1634 PUSHLOOP(cx, svp, MARK);
1636 if (PL_op->op_flags & OPf_STACKED) {
1637 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1638 if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) {
1640 if (SvNIOKp(sv) || !SvPOKp(sv) ||
1641 SvNIOKp(cx->blk_loop.iterary) || !SvPOKp(cx->blk_loop.iterary) ||
1642 (looks_like_number(sv) && *SvPVX(sv) != '0' &&
1643 looks_like_number((SV*)cx->blk_loop.iterary) &&
1644 *SvPVX(cx->blk_loop.iterary) != '0'))
1646 if (SvNV(sv) < IV_MIN ||
1647 SvNV((SV*)cx->blk_loop.iterary) >= IV_MAX)
1648 DIE(aTHX_ "Range iterator outside integer range");
1649 cx->blk_loop.iterix = SvIV(sv);
1650 cx->blk_loop.itermax = SvIV((SV*)cx->blk_loop.iterary);
1653 cx->blk_loop.iterlval = newSVsv(sv);
1657 cx->blk_loop.iterary = PL_curstack;
1658 AvFILLp(PL_curstack) = SP - PL_stack_base;
1659 cx->blk_loop.iterix = MARK - PL_stack_base;
1668 register PERL_CONTEXT *cx;
1669 I32 gimme = GIMME_V;
1675 PUSHBLOCK(cx, CXt_LOOP, SP);
1676 PUSHLOOP(cx, 0, SP);
1684 register PERL_CONTEXT *cx;
1692 newsp = PL_stack_base + cx->blk_loop.resetsp;
1695 if (gimme == G_VOID)
1697 else if (gimme == G_SCALAR) {
1699 *++newsp = sv_mortalcopy(*SP);
1701 *++newsp = &PL_sv_undef;
1705 *++newsp = sv_mortalcopy(*++mark);
1706 TAINT_NOT; /* Each item is independent */
1712 POPLOOP(cx); /* Stack values are safe: release loop vars ... */
1713 PL_curpm = newpm; /* ... and pop $1 et al */
1725 register PERL_CONTEXT *cx;
1726 bool popsub2 = FALSE;
1727 bool clear_errsv = FALSE;
1734 if (PL_curstackinfo->si_type == PERLSI_SORT) {
1735 if (cxstack_ix == PL_sortcxix
1736 || dopoptosub(cxstack_ix) <= PL_sortcxix)
1738 if (cxstack_ix > PL_sortcxix)
1739 dounwind(PL_sortcxix);
1740 AvARRAY(PL_curstack)[1] = *SP;
1741 PL_stack_sp = PL_stack_base + 1;
1746 cxix = dopoptosub(cxstack_ix);
1748 DIE(aTHX_ "Can't return outside a subroutine");
1749 if (cxix < cxstack_ix)
1753 switch (CxTYPE(cx)) {
1758 if (!(PL_in_eval & EVAL_KEEPERR))
1764 if (optype == OP_REQUIRE &&
1765 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1767 /* Unassume the success we assumed earlier. */
1768 SV *nsv = cx->blk_eval.old_namesv;
1769 (void)hv_delete(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), G_DISCARD);
1770 DIE(aTHX_ "%s did not return a true value", SvPVX(nsv));
1777 DIE(aTHX_ "panic: return");
1781 if (gimme == G_SCALAR) {
1784 if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
1786 *++newsp = SvREFCNT_inc(*SP);
1791 sv = SvREFCNT_inc(*SP); /* FREETMPS could clobber it */
1793 *++newsp = sv_mortalcopy(sv);
1798 *++newsp = (SvTEMP(*SP)) ? *SP : sv_mortalcopy(*SP);
1801 *++newsp = sv_mortalcopy(*SP);
1804 *++newsp = &PL_sv_undef;
1806 else if (gimme == G_ARRAY) {
1807 while (++MARK <= SP) {
1808 *++newsp = (popsub2 && SvTEMP(*MARK))
1809 ? *MARK : sv_mortalcopy(*MARK);
1810 TAINT_NOT; /* Each item is independent */
1813 PL_stack_sp = newsp;
1815 /* Stack values are safe: */
1817 POPSUB(cx,sv); /* release CV and @_ ... */
1821 PL_curpm = newpm; /* ... and pop $1 et al */
1827 return pop_return();
1834 register PERL_CONTEXT *cx;
1844 if (PL_op->op_flags & OPf_SPECIAL) {
1845 cxix = dopoptoloop(cxstack_ix);
1847 DIE(aTHX_ "Can't \"last\" outside a loop block");
1850 cxix = dopoptolabel(cPVOP->op_pv);
1852 DIE(aTHX_ "Label not found for \"last %s\"", cPVOP->op_pv);
1854 if (cxix < cxstack_ix)
1859 switch (CxTYPE(cx)) {
1862 newsp = PL_stack_base + cx->blk_loop.resetsp;
1863 nextop = cx->blk_loop.last_op->op_next;
1867 nextop = pop_return();
1871 nextop = pop_return();
1875 nextop = pop_return();
1878 DIE(aTHX_ "panic: last");
1882 if (gimme == G_SCALAR) {
1884 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
1885 ? *SP : sv_mortalcopy(*SP);
1887 *++newsp = &PL_sv_undef;
1889 else if (gimme == G_ARRAY) {
1890 while (++MARK <= SP) {
1891 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
1892 ? *MARK : sv_mortalcopy(*MARK);
1893 TAINT_NOT; /* Each item is independent */
1899 /* Stack values are safe: */
1902 POPLOOP(cx); /* release loop vars ... */
1906 POPSUB(cx,sv); /* release CV and @_ ... */
1909 PL_curpm = newpm; /* ... and pop $1 et al */
1919 register PERL_CONTEXT *cx;
1922 if (PL_op->op_flags & OPf_SPECIAL) {
1923 cxix = dopoptoloop(cxstack_ix);
1925 DIE(aTHX_ "Can't \"next\" outside a loop block");
1928 cxix = dopoptolabel(cPVOP->op_pv);
1930 DIE(aTHX_ "Label not found for \"next %s\"", cPVOP->op_pv);
1932 if (cxix < cxstack_ix)
1935 /* clear off anything above the scope we're re-entering, but
1936 * save the rest until after a possible continue block */
1937 inner = PL_scopestack_ix;
1939 if (PL_scopestack_ix < inner)
1940 leave_scope(PL_scopestack[PL_scopestack_ix]);
1941 return cx->blk_loop.next_op;
1947 register PERL_CONTEXT *cx;
1950 if (PL_op->op_flags & OPf_SPECIAL) {
1951 cxix = dopoptoloop(cxstack_ix);
1953 DIE(aTHX_ "Can't \"redo\" outside a loop block");
1956 cxix = dopoptolabel(cPVOP->op_pv);
1958 DIE(aTHX_ "Label not found for \"redo %s\"", cPVOP->op_pv);
1960 if (cxix < cxstack_ix)
1964 oldsave = PL_scopestack[PL_scopestack_ix - 1];
1965 LEAVE_SCOPE(oldsave);
1966 return cx->blk_loop.redo_op;
1970 S_dofindlabel(pTHX_ OP *o, char *label, OP **opstack, OP **oplimit)
1974 static char too_deep[] = "Target of goto is too deeply nested";
1977 Perl_croak(aTHX_ too_deep);
1978 if (o->op_type == OP_LEAVE ||
1979 o->op_type == OP_SCOPE ||
1980 o->op_type == OP_LEAVELOOP ||
1981 o->op_type == OP_LEAVETRY)
1983 *ops++ = cUNOPo->op_first;
1985 Perl_croak(aTHX_ too_deep);
1988 if (o->op_flags & OPf_KIDS) {
1989 /* First try all the kids at this level, since that's likeliest. */
1990 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1991 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1992 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1995 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1996 if (kid == PL_lastgotoprobe)
1998 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
2000 (ops[-1]->op_type != OP_NEXTSTATE &&
2001 ops[-1]->op_type != OP_DBSTATE)))
2003 if ((o = dofindlabel(kid, label, ops, oplimit)))
2022 register PERL_CONTEXT *cx;
2023 #define GOTO_DEPTH 64
2024 OP *enterops[GOTO_DEPTH];
2026 int do_dump = (PL_op->op_type == OP_DUMP);
2027 static char must_have_label[] = "goto must have label";
2030 if (PL_op->op_flags & OPf_STACKED) {
2034 /* This egregious kludge implements goto &subroutine */
2035 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
2037 register PERL_CONTEXT *cx;
2038 CV* cv = (CV*)SvRV(sv);
2044 if (!CvROOT(cv) && !CvXSUB(cv)) {
2049 /* autoloaded stub? */
2050 if (cv != GvCV(gv) && (cv = GvCV(gv)))
2052 autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv),
2053 GvNAMELEN(gv), FALSE);
2054 if (autogv && (cv = GvCV(autogv)))
2056 tmpstr = sv_newmortal();
2057 gv_efullname3(tmpstr, gv, Nullch);
2058 DIE(aTHX_ "Goto undefined subroutine &%s",SvPVX(tmpstr));
2060 DIE(aTHX_ "Goto undefined subroutine");
2063 /* First do some returnish stuff. */
2064 cxix = dopoptosub(cxstack_ix);
2066 DIE(aTHX_ "Can't goto subroutine outside a subroutine");
2067 if (cxix < cxstack_ix)
2071 DIE(aTHX_ "Can't goto subroutine from an eval-string");
2073 if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.hasargs) {
2074 /* put @_ back onto stack */
2075 AV* av = cx->blk_sub.argarray;
2077 items = AvFILLp(av) + 1;
2079 EXTEND(PL_stack_sp, items); /* @_ could have been extended. */
2080 Copy(AvARRAY(av), PL_stack_sp, items, SV*);
2081 PL_stack_sp += items;
2082 #ifndef USE_5005THREADS
2083 SvREFCNT_dec(GvAV(PL_defgv));
2084 GvAV(PL_defgv) = cx->blk_sub.savearray;
2085 #endif /* USE_5005THREADS */
2086 /* abandon @_ if it got reified */
2088 (void)sv_2mortal((SV*)av); /* delay until return */
2090 av_extend(av, items-1);
2091 AvFLAGS(av) = AVf_REIFY;
2092 PL_curpad[0] = (SV*)(cx->blk_sub.argarray = av);
2095 else if (CvXSUB(cv)) { /* put GvAV(defgv) back onto stack */
2097 #ifdef USE_5005THREADS
2098 av = (AV*)PL_curpad[0];
2100 av = GvAV(PL_defgv);
2102 items = AvFILLp(av) + 1;
2104 EXTEND(PL_stack_sp, items); /* @_ could have been extended. */
2105 Copy(AvARRAY(av), PL_stack_sp, items, SV*);
2106 PL_stack_sp += items;
2108 if (CxTYPE(cx) == CXt_SUB &&
2109 !(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
2110 SvREFCNT_dec(cx->blk_sub.cv);
2111 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2112 LEAVE_SCOPE(oldsave);
2114 /* Now do some callish stuff. */
2117 #ifdef PERL_XSUB_OLDSTYLE
2118 if (CvOLDSTYLE(cv)) {
2119 I32 (*fp3)(int,int,int);
2124 fp3 = (I32(*)(int,int,int))CvXSUB(cv);
2125 items = (*fp3)(CvXSUBANY(cv).any_i32,
2126 mark - PL_stack_base + 1,
2128 SP = PL_stack_base + items;
2131 #endif /* PERL_XSUB_OLDSTYLE */
2136 PL_stack_sp--; /* There is no cv arg. */
2137 /* Push a mark for the start of arglist */
2139 (void)(*CvXSUB(cv))(aTHX_ cv);
2140 /* Pop the current context like a decent sub should */
2141 POPBLOCK(cx, PL_curpm);
2142 /* Do _not_ use PUTBACK, keep the XSUB's return stack! */
2145 return pop_return();
2148 AV* padlist = CvPADLIST(cv);
2149 SV** svp = AvARRAY(padlist);
2150 if (CxTYPE(cx) == CXt_EVAL) {
2151 PL_in_eval = cx->blk_eval.old_in_eval;
2152 PL_eval_root = cx->blk_eval.old_eval_root;
2153 cx->cx_type = CXt_SUB;
2154 cx->blk_sub.hasargs = 0;
2156 cx->blk_sub.cv = cv;
2157 cx->blk_sub.olddepth = CvDEPTH(cv);
2159 if (CvDEPTH(cv) < 2)
2160 (void)SvREFCNT_inc(cv);
2161 else { /* save temporaries on recursion? */
2162 if (CvDEPTH(cv) == 100 && ckWARN(WARN_RECURSION))
2163 sub_crush_depth(cv);
2164 if (CvDEPTH(cv) > AvFILLp(padlist)) {
2165 AV *newpad = newAV();
2166 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
2167 I32 ix = AvFILLp((AV*)svp[1]);
2168 I32 names_fill = AvFILLp((AV*)svp[0]);
2169 svp = AvARRAY(svp[0]);
2170 for ( ;ix > 0; ix--) {
2171 if (names_fill >= ix && svp[ix] != &PL_sv_undef) {
2172 char *name = SvPVX(svp[ix]);
2173 if ((SvFLAGS(svp[ix]) & SVf_FAKE)
2176 /* outer lexical or anon code */
2177 av_store(newpad, ix,
2178 SvREFCNT_inc(oldpad[ix]) );
2180 else { /* our own lexical */
2182 av_store(newpad, ix, sv = (SV*)newAV());
2183 else if (*name == '%')
2184 av_store(newpad, ix, sv = (SV*)newHV());
2186 av_store(newpad, ix, sv = NEWSV(0,0));
2190 else if (IS_PADGV(oldpad[ix]) || IS_PADCONST(oldpad[ix])) {
2191 av_store(newpad, ix, sv = SvREFCNT_inc(oldpad[ix]));
2194 av_store(newpad, ix, sv = NEWSV(0,0));
2198 if (cx->blk_sub.hasargs) {
2201 av_store(newpad, 0, (SV*)av);
2202 AvFLAGS(av) = AVf_REIFY;
2204 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
2205 AvFILLp(padlist) = CvDEPTH(cv);
2206 svp = AvARRAY(padlist);
2209 #ifdef USE_5005THREADS
2210 if (!cx->blk_sub.hasargs) {
2211 AV* av = (AV*)PL_curpad[0];
2213 items = AvFILLp(av) + 1;
2215 /* Mark is at the end of the stack. */
2217 Copy(AvARRAY(av), SP + 1, items, SV*);
2222 #endif /* USE_5005THREADS */
2223 SAVEVPTR(PL_curpad);
2224 PL_curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
2225 #ifndef USE_5005THREADS
2226 if (cx->blk_sub.hasargs)
2227 #endif /* USE_5005THREADS */
2229 AV* av = (AV*)PL_curpad[0];
2232 #ifndef USE_5005THREADS
2233 cx->blk_sub.savearray = GvAV(PL_defgv);
2234 GvAV(PL_defgv) = (AV*)SvREFCNT_inc(av);
2235 #endif /* USE_5005THREADS */
2236 cx->blk_sub.oldcurpad = PL_curpad;
2237 cx->blk_sub.argarray = av;
2240 if (items >= AvMAX(av) + 1) {
2242 if (AvARRAY(av) != ary) {
2243 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
2244 SvPVX(av) = (char*)ary;
2246 if (items >= AvMAX(av) + 1) {
2247 AvMAX(av) = items - 1;
2248 Renew(ary,items+1,SV*);
2250 SvPVX(av) = (char*)ary;
2253 Copy(mark,AvARRAY(av),items,SV*);
2254 AvFILLp(av) = items - 1;
2255 assert(!AvREAL(av));
2262 if (PERLDB_SUB) { /* Checking curstash breaks DProf. */
2264 * We do not care about using sv to call CV;
2265 * it's for informational purposes only.
2267 SV *sv = GvSV(PL_DBsub);
2270 if (PERLDB_SUB_NN) {
2271 SvIVX(sv) = PTR2IV(cv); /* Already upgraded, saved */
2274 gv_efullname3(sv, CvGV(cv), Nullch);
2277 && (gotocv = get_cv("DB::goto", FALSE)) ) {
2278 PUSHMARK( PL_stack_sp );
2279 call_sv((SV*)gotocv, G_SCALAR | G_NODEBUG);
2283 RETURNOP(CvSTART(cv));
2287 label = SvPV(sv,n_a);
2288 if (!(do_dump || *label))
2289 DIE(aTHX_ must_have_label);
2292 else if (PL_op->op_flags & OPf_SPECIAL) {
2294 DIE(aTHX_ must_have_label);
2297 label = cPVOP->op_pv;
2299 if (label && *label) {
2301 bool leaving_eval = FALSE;
2302 PERL_CONTEXT *last_eval_cx = 0;
2306 PL_lastgotoprobe = 0;
2308 for (ix = cxstack_ix; ix >= 0; ix--) {
2310 switch (CxTYPE(cx)) {
2312 leaving_eval = TRUE;
2313 if (CxREALEVAL(cx)) {
2314 gotoprobe = (last_eval_cx ?
2315 last_eval_cx->blk_eval.old_eval_root :
2320 /* else fall through */
2322 gotoprobe = cx->blk_oldcop->op_sibling;
2328 gotoprobe = cx->blk_oldcop->op_sibling;
2330 gotoprobe = PL_main_root;
2333 if (CvDEPTH(cx->blk_sub.cv)) {
2334 gotoprobe = CvROOT(cx->blk_sub.cv);
2340 DIE(aTHX_ "Can't \"goto\" out of a pseudo block");
2343 DIE(aTHX_ "panic: goto");
2344 gotoprobe = PL_main_root;
2348 retop = dofindlabel(gotoprobe, label,
2349 enterops, enterops + GOTO_DEPTH);
2353 PL_lastgotoprobe = gotoprobe;
2356 DIE(aTHX_ "Can't find label %s", label);
2358 /* if we're leaving an eval, check before we pop any frames
2359 that we're not going to punt, otherwise the error
2362 if (leaving_eval && *enterops && enterops[1]) {
2364 for (i = 1; enterops[i]; i++)
2365 if (enterops[i]->op_type == OP_ENTERITER)
2366 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2369 /* pop unwanted frames */
2371 if (ix < cxstack_ix) {
2378 oldsave = PL_scopestack[PL_scopestack_ix];
2379 LEAVE_SCOPE(oldsave);
2382 /* push wanted frames */
2384 if (*enterops && enterops[1]) {
2386 for (ix = 1; enterops[ix]; ix++) {
2387 PL_op = enterops[ix];
2388 /* Eventually we may want to stack the needed arguments
2389 * for each op. For now, we punt on the hard ones. */
2390 if (PL_op->op_type == OP_ENTERITER)
2391 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2392 CALL_FPTR(PL_op->op_ppaddr)(aTHX);
2400 if (!retop) retop = PL_main_start;
2402 PL_restartop = retop;
2403 PL_do_undump = TRUE;
2407 PL_restartop = 0; /* hmm, must be GNU unexec().. */
2408 PL_do_undump = FALSE;
2424 if (anum == 1 && (PL_op->op_private & OPpEXIT_VMSISH))
2426 VMSISH_HUSHED = VMSISH_HUSHED || (PL_op->op_private & OPpHUSH_VMSISH);
2429 PL_exit_flags |= PERL_EXIT_EXPECTED;
2431 PUSHs(&PL_sv_undef);
2439 NV value = SvNVx(GvSV(cCOP->cop_gv));
2440 register I32 match = I_32(value);
2443 if (((NV)match) > value)
2444 --match; /* was fractional--truncate other way */
2446 match -= cCOP->uop.scop.scop_offset;
2449 else if (match > cCOP->uop.scop.scop_max)
2450 match = cCOP->uop.scop.scop_max;
2451 PL_op = cCOP->uop.scop.scop_next[match];
2461 PL_op = PL_op->op_next; /* can't assume anything */
2464 match = *(SvPVx(GvSV(cCOP->cop_gv), n_a)) & 255;
2465 match -= cCOP->uop.scop.scop_offset;
2468 else if (match > cCOP->uop.scop.scop_max)
2469 match = cCOP->uop.scop.scop_max;
2470 PL_op = cCOP->uop.scop.scop_next[match];
2479 S_save_lines(pTHX_ AV *array, SV *sv)
2481 register char *s = SvPVX(sv);
2482 register char *send = SvPVX(sv) + SvCUR(sv);
2484 register I32 line = 1;
2486 while (s && s < send) {
2487 SV *tmpstr = NEWSV(85,0);
2489 sv_upgrade(tmpstr, SVt_PVMG);
2490 t = strchr(s, '\n');
2496 sv_setpvn(tmpstr, s, t - s);
2497 av_store(array, line++, tmpstr);
2502 #ifdef PERL_FLEXIBLE_EXCEPTIONS
2504 S_docatch_body(pTHX_ va_list args)
2506 return docatch_body();
2511 S_docatch_body(pTHX)
2518 S_docatch(pTHX_ OP *o)
2522 volatile PERL_SI *cursi = PL_curstackinfo;
2526 assert(CATCH_GET == TRUE);
2529 #ifdef PERL_FLEXIBLE_EXCEPTIONS
2531 CALLPROTECT(aTHX_ pcur_env, &ret, MEMBER_TO_FPTR(S_docatch_body));
2537 #ifndef PERL_FLEXIBLE_EXCEPTIONS
2543 if (PL_restartop && cursi == PL_curstackinfo) {
2544 PL_op = PL_restartop;
2561 Perl_sv_compile_2op(pTHX_ SV *sv, OP** startop, char *code, AV** avp)
2562 /* sv Text to convert to OP tree. */
2563 /* startop op_free() this to undo. */
2564 /* code Short string id of the caller. */
2566 dSP; /* Make POPBLOCK work. */
2569 I32 gimme = 0; /* SUSPECT - INITIALZE TO WHAT? NI-S */
2573 char tbuf[TYPE_DIGITS(long) + 12 + 10];
2574 char *tmpbuf = tbuf;
2580 /* switch to eval mode */
2582 if (PL_curcop == &PL_compiling) {
2583 SAVECOPSTASH_FREE(&PL_compiling);
2584 CopSTASH_set(&PL_compiling, PL_curstash);
2586 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
2587 SV *sv = sv_newmortal();
2588 Perl_sv_setpvf(aTHX_ sv, "_<(%.10seval %lu)[%s:%"IVdf"]",
2589 code, (unsigned long)++PL_evalseq,
2590 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
2594 sprintf(tmpbuf, "_<(%.10s_eval %lu)", code, (unsigned long)++PL_evalseq);
2595 SAVECOPFILE_FREE(&PL_compiling);
2596 CopFILE_set(&PL_compiling, tmpbuf+2);
2597 SAVECOPLINE(&PL_compiling);
2598 CopLINE_set(&PL_compiling, 1);
2599 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2600 deleting the eval's FILEGV from the stash before gv_check() runs
2601 (i.e. before run-time proper). To work around the coredump that
2602 ensues, we always turn GvMULTI_on for any globals that were
2603 introduced within evals. See force_ident(). GSAR 96-10-12 */
2604 safestr = savepv(tmpbuf);
2605 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
2607 #ifdef OP_IN_REGISTER
2612 PL_hints &= HINT_UTF8;
2615 PL_op->op_type = OP_ENTEREVAL;
2616 PL_op->op_flags = 0; /* Avoid uninit warning. */
2617 PUSHBLOCK(cx, CXt_EVAL|(PL_curcop == &PL_compiling ? 0 : CXp_REAL), SP);
2618 PUSHEVAL(cx, 0, Nullgv);
2619 rop = doeval(G_SCALAR, startop);
2620 POPBLOCK(cx,PL_curpm);
2623 (*startop)->op_type = OP_NULL;
2624 (*startop)->op_ppaddr = PL_ppaddr[OP_NULL];
2626 *avp = (AV*)SvREFCNT_inc(PL_comppad);
2628 if (PL_curcop == &PL_compiling)
2629 PL_compiling.op_private = PL_hints;
2630 #ifdef OP_IN_REGISTER
2636 /* With USE_5005THREADS, eval_owner must be held on entry to doeval */
2638 S_doeval(pTHX_ int gimme, OP** startop)
2646 PL_in_eval = ((saveop && saveop->op_type == OP_REQUIRE)
2647 ? (EVAL_INREQUIRE | (PL_in_eval & EVAL_INEVAL))
2652 /* set up a scratch pad */
2655 SAVEVPTR(PL_curpad);
2656 SAVESPTR(PL_comppad);
2657 SAVESPTR(PL_comppad_name);
2658 SAVEI32(PL_comppad_name_fill);
2659 SAVEI32(PL_min_intro_pending);
2660 SAVEI32(PL_max_intro_pending);
2663 for (i = cxstack_ix - 1; i >= 0; i--) {
2664 PERL_CONTEXT *cx = &cxstack[i];
2665 if (CxTYPE(cx) == CXt_EVAL)
2667 else if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
2668 caller = cx->blk_sub.cv;
2673 SAVESPTR(PL_compcv);
2674 PL_compcv = (CV*)NEWSV(1104,0);
2675 sv_upgrade((SV *)PL_compcv, SVt_PVCV);
2676 CvEVAL_on(PL_compcv);
2677 assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
2678 cxstack[cxstack_ix].blk_eval.cv = PL_compcv;
2680 #ifdef USE_5005THREADS
2681 CvOWNER(PL_compcv) = 0;
2682 New(666, CvMUTEXP(PL_compcv), 1, perl_mutex);
2683 MUTEX_INIT(CvMUTEXP(PL_compcv));
2684 #endif /* USE_5005THREADS */
2686 PL_comppad = newAV();
2687 av_push(PL_comppad, Nullsv);
2688 PL_curpad = AvARRAY(PL_comppad);
2689 PL_comppad_name = newAV();
2690 PL_comppad_name_fill = 0;
2691 PL_min_intro_pending = 0;
2693 #ifdef USE_5005THREADS
2694 av_store(PL_comppad_name, 0, newSVpvn("@_", 2));
2695 PL_curpad[0] = (SV*)newAV();
2696 SvPADMY_on(PL_curpad[0]); /* XXX Needed? */
2697 #endif /* USE_5005THREADS */
2699 comppadlist = newAV();
2700 AvREAL_off(comppadlist);
2701 av_store(comppadlist, 0, (SV*)PL_comppad_name);
2702 av_store(comppadlist, 1, (SV*)PL_comppad);
2703 CvPADLIST(PL_compcv) = comppadlist;
2706 (saveop->op_type != OP_REQUIRE && saveop->op_type != OP_DOFILE))
2708 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(caller);
2711 SAVEMORTALIZESV(PL_compcv); /* must remain until end of current statement */
2713 /* make sure we compile in the right package */
2715 if (CopSTASH_ne(PL_curcop, PL_curstash)) {
2716 SAVESPTR(PL_curstash);
2717 PL_curstash = CopSTASH(PL_curcop);
2719 SAVESPTR(PL_beginav);
2720 PL_beginav = newAV();
2721 SAVEFREESV(PL_beginav);
2722 SAVEI32(PL_error_count);
2724 /* try to compile it */
2726 PL_eval_root = Nullop;
2728 PL_curcop = &PL_compiling;
2729 PL_curcop->cop_arybase = 0;
2730 if (saveop && saveop->op_flags & OPf_SPECIAL)
2731 PL_in_eval |= EVAL_KEEPERR;
2734 if (yyparse() || PL_error_count || !PL_eval_root) {
2738 I32 optype = 0; /* Might be reset by POPEVAL. */
2743 op_free(PL_eval_root);
2744 PL_eval_root = Nullop;
2746 SP = PL_stack_base + POPMARK; /* pop original mark */
2748 POPBLOCK(cx,PL_curpm);
2754 if (optype == OP_REQUIRE) {
2755 char* msg = SvPVx(ERRSV, n_a);
2756 DIE(aTHX_ "%sCompilation failed in require",
2757 *msg ? msg : "Unknown error\n");
2760 char* msg = SvPVx(ERRSV, n_a);
2762 POPBLOCK(cx,PL_curpm);
2764 Perl_croak(aTHX_ "%sCompilation failed in regexp",
2765 (*msg ? msg : "Unknown error\n"));
2767 #ifdef USE_5005THREADS
2768 MUTEX_LOCK(&PL_eval_mutex);
2770 COND_SIGNAL(&PL_eval_cond);
2771 MUTEX_UNLOCK(&PL_eval_mutex);
2772 #endif /* USE_5005THREADS */
2775 CopLINE_set(&PL_compiling, 0);
2777 *startop = PL_eval_root;
2778 SvREFCNT_dec(CvOUTSIDE(PL_compcv));
2779 CvOUTSIDE(PL_compcv) = Nullcv;
2781 SAVEFREEOP(PL_eval_root);
2783 scalarvoid(PL_eval_root);
2784 else if (gimme & G_ARRAY)
2787 scalar(PL_eval_root);
2789 DEBUG_x(dump_eval());
2791 /* Register with debugger: */
2792 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2793 CV *cv = get_cv("DB::postponed", FALSE);
2797 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2799 call_sv((SV*)cv, G_DISCARD);
2803 /* compiled okay, so do it */
2805 CvDEPTH(PL_compcv) = 1;
2806 SP = PL_stack_base + POPMARK; /* pop original mark */
2807 PL_op = saveop; /* The caller may need it. */
2808 PL_lex_state = LEX_NOTPARSING; /* $^S needs this. */
2809 #ifdef USE_5005THREADS
2810 MUTEX_LOCK(&PL_eval_mutex);
2812 COND_SIGNAL(&PL_eval_cond);
2813 MUTEX_UNLOCK(&PL_eval_mutex);
2814 #endif /* USE_5005THREADS */
2816 RETURNOP(PL_eval_start);
2820 S_doopen_pmc(pTHX_ const char *name, const char *mode)
2822 STRLEN namelen = strlen(name);
2825 if (namelen > 3 && strEQ(name + namelen - 3, ".pm")) {
2826 SV *pmcsv = Perl_newSVpvf(aTHX_ "%s%c", name, 'c');
2827 char *pmc = SvPV_nolen(pmcsv);
2830 if (PerlLIO_stat(pmc, &pmcstat) < 0) {
2831 fp = PerlIO_open(name, mode);
2834 if (PerlLIO_stat(name, &pmstat) < 0 ||
2835 pmstat.st_mtime < pmcstat.st_mtime)
2837 fp = PerlIO_open(pmc, mode);
2840 fp = PerlIO_open(name, mode);
2843 SvREFCNT_dec(pmcsv);
2846 fp = PerlIO_open(name, mode);
2854 register PERL_CONTEXT *cx;
2858 char *tryname = Nullch;
2859 SV *namesv = Nullsv;
2861 I32 gimme = GIMME_V;
2862 PerlIO *tryrsfp = 0;
2864 int filter_has_file = 0;
2865 GV *filter_child_proc = 0;
2866 SV *filter_state = 0;
2874 if (SvPOK(sv) && SvNOK(sv) && SvNV(sv)) { /* require v5.6.1 */
2875 UV rev = 0, ver = 0, sver = 0;
2877 U8 *s = (U8*)SvPVX(sv);
2878 U8 *end = (U8*)SvPVX(sv) + SvCUR(sv);
2880 rev = utf8n_to_uvchr(s, end - s, &len, 0);
2883 ver = utf8n_to_uvchr(s, end - s, &len, 0);
2886 sver = utf8n_to_uvchr(s, end - s, &len, 0);
2889 if (PERL_REVISION < rev
2890 || (PERL_REVISION == rev
2891 && (PERL_VERSION < ver
2892 || (PERL_VERSION == ver
2893 && PERL_SUBVERSION < sver))))
2895 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--this is only "
2896 "v%d.%d.%d, stopped", rev, ver, sver, PERL_REVISION,
2897 PERL_VERSION, PERL_SUBVERSION);
2899 if (ckWARN(WARN_PORTABLE))
2900 Perl_warner(aTHX_ WARN_PORTABLE,
2901 "v-string in use/require non-portable");
2904 else if (!SvPOKp(sv)) { /* require 5.005_03 */
2905 if ((NV)PERL_REVISION + ((NV)PERL_VERSION/(NV)1000)
2906 + ((NV)PERL_SUBVERSION/(NV)1000000)
2907 + 0.00000099 < SvNV(sv))
2911 NV nver = (nrev - rev) * 1000;
2912 UV ver = (UV)(nver + 0.0009);
2913 NV nsver = (nver - ver) * 1000;
2914 UV sver = (UV)(nsver + 0.0009);
2916 /* help out with the "use 5.6" confusion */
2917 if (sver == 0 && (rev > 5 || (rev == 5 && ver >= 100))) {
2918 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--"
2919 "this is only v%d.%d.%d, stopped"
2920 " (did you mean v%"UVuf".%03"UVuf"?)",
2921 rev, ver, sver, PERL_REVISION, PERL_VERSION,
2922 PERL_SUBVERSION, rev, ver/100);
2925 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--"
2926 "this is only v%d.%d.%d, stopped",
2927 rev, ver, sver, PERL_REVISION, PERL_VERSION,
2934 name = SvPV(sv, len);
2935 if (!(name && len > 0 && *name))
2936 DIE(aTHX_ "Null filename used");
2937 TAINT_PROPER("require");
2938 if (PL_op->op_type == OP_REQUIRE &&
2939 (svp = hv_fetch(GvHVn(PL_incgv), name, len, 0)) &&
2940 *svp != &PL_sv_undef)
2943 /* prepare to compile file */
2945 if (path_is_absolute(name)) {
2947 tryrsfp = doopen_pmc(name,PERL_SCRIPT_MODE);
2950 AV *ar = GvAVn(PL_incgv);
2954 if ((unixname = tounixspec(name, Nullch)) != Nullch)
2957 namesv = NEWSV(806, 0);
2958 for (i = 0; i <= AvFILL(ar); i++) {
2959 SV *dirsv = *av_fetch(ar, i, TRUE);
2965 if (SvTYPE(SvRV(loader)) == SVt_PVAV
2966 && !sv_isobject(loader))
2968 loader = *av_fetch((AV *)SvRV(loader), 0, TRUE);
2971 Perl_sv_setpvf(aTHX_ namesv, "/loader/0x%"UVxf"/%s",
2972 PTR2UV(SvRV(dirsv)), name);
2973 tryname = SvPVX(namesv);
2984 if (sv_isobject(loader))
2985 count = call_method("INC", G_ARRAY);
2987 count = call_sv(loader, G_ARRAY);
2997 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVGV) {
3001 if (SvTYPE(arg) == SVt_PVGV) {
3002 IO *io = GvIO((GV *)arg);
3007 tryrsfp = IoIFP(io);
3008 if (IoTYPE(io) == IoTYPE_PIPE) {
3009 /* reading from a child process doesn't
3010 nest -- when returning from reading
3011 the inner module, the outer one is
3012 unreadable (closed?) I've tried to
3013 save the gv to manage the lifespan of
3014 the pipe, but this didn't help. XXX */
3015 filter_child_proc = (GV *)arg;
3016 (void)SvREFCNT_inc(filter_child_proc);
3019 if (IoOFP(io) && IoOFP(io) != IoIFP(io)) {
3020 PerlIO_close(IoOFP(io));
3032 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVCV) {
3034 (void)SvREFCNT_inc(filter_sub);
3037 filter_state = SP[i];
3038 (void)SvREFCNT_inc(filter_state);
3042 tryrsfp = PerlIO_open("/dev/null",
3057 filter_has_file = 0;
3058 if (filter_child_proc) {
3059 SvREFCNT_dec(filter_child_proc);
3060 filter_child_proc = 0;
3063 SvREFCNT_dec(filter_state);
3067 SvREFCNT_dec(filter_sub);
3072 if (!path_is_absolute(name)
3073 #ifdef MACOS_TRADITIONAL
3074 /* We consider paths of the form :a:b ambiguous and interpret them first
3075 as global then as local
3077 || (*name == ':' && name[1] != ':' && strchr(name+2, ':'))
3080 char *dir = SvPVx(dirsv, n_a);
3081 #ifdef MACOS_TRADITIONAL
3083 Perl_sv_setpvf(aTHX_ namesv, "%s%s", MacPerl_CanonDir(dir, buf), name+(name[0] == ':'));
3087 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
3089 sv_setpv(namesv, unixdir);
3090 sv_catpv(namesv, unixname);
3092 Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name);
3095 TAINT_PROPER("require");
3096 tryname = SvPVX(namesv);
3097 #ifdef MACOS_TRADITIONAL
3099 /* Convert slashes in the name part, but not the directory part, to colons */
3101 for (colon = tryname+strlen(dir); colon = strchr(colon, '/'); )
3105 tryrsfp = doopen_pmc(tryname, PERL_SCRIPT_MODE);
3107 if (tryname[0] == '.' && tryname[1] == '/')
3116 SAVECOPFILE_FREE(&PL_compiling);
3117 CopFILE_set(&PL_compiling, tryrsfp ? tryname : name);
3118 SvREFCNT_dec(namesv);
3120 if (PL_op->op_type == OP_REQUIRE) {
3121 char *msgstr = name;
3122 if (namesv) { /* did we lookup @INC? */
3123 SV *msg = sv_2mortal(newSVpv(msgstr,0));
3124 SV *dirmsgsv = NEWSV(0, 0);
3125 AV *ar = GvAVn(PL_incgv);
3127 sv_catpvn(msg, " in @INC", 8);
3128 if (instr(SvPVX(msg), ".h "))
3129 sv_catpv(msg, " (change .h to .ph maybe?)");
3130 if (instr(SvPVX(msg), ".ph "))
3131 sv_catpv(msg, " (did you run h2ph?)");
3132 sv_catpv(msg, " (@INC contains:");
3133 for (i = 0; i <= AvFILL(ar); i++) {
3134 char *dir = SvPVx(*av_fetch(ar, i, TRUE), n_a);
3135 Perl_sv_setpvf(aTHX_ dirmsgsv, " %s", dir);
3136 sv_catsv(msg, dirmsgsv);
3138 sv_catpvn(msg, ")", 1);
3139 SvREFCNT_dec(dirmsgsv);
3140 msgstr = SvPV_nolen(msg);
3142 DIE(aTHX_ "Can't locate %s", msgstr);
3148 SETERRNO(0, SS$_NORMAL);
3150 /* Assume success here to prevent recursive requirement. */
3152 /* Check whether a hook in @INC has already filled %INC */
3153 if (!hook_sv || !(svp = hv_fetch(GvHVn(PL_incgv), name, len, 0))) {
3154 (void)hv_store(GvHVn(PL_incgv), name, len,
3155 (hook_sv ? SvREFCNT_inc(hook_sv)
3156 : newSVpv(CopFILE(&PL_compiling), 0)),
3162 lex_start(sv_2mortal(newSVpvn("",0)));
3163 SAVEGENERICSV(PL_rsfp_filters);
3164 PL_rsfp_filters = Nullav;
3169 SAVESPTR(PL_compiling.cop_warnings);
3170 if (PL_dowarn & G_WARN_ALL_ON)
3171 PL_compiling.cop_warnings = pWARN_ALL ;
3172 else if (PL_dowarn & G_WARN_ALL_OFF)
3173 PL_compiling.cop_warnings = pWARN_NONE ;
3174 else if (PL_taint_warn)
3175 PL_compiling.cop_warnings = newSVpvn(WARN_TAINTstring, WARNsize);
3177 PL_compiling.cop_warnings = pWARN_STD ;
3178 SAVESPTR(PL_compiling.cop_io);
3179 PL_compiling.cop_io = Nullsv;
3181 if (filter_sub || filter_child_proc) {
3182 SV *datasv = filter_add(run_user_filter, Nullsv);
3183 IoLINES(datasv) = filter_has_file;
3184 IoFMT_GV(datasv) = (GV *)filter_child_proc;
3185 IoTOP_GV(datasv) = (GV *)filter_state;
3186 IoBOTTOM_GV(datasv) = (GV *)filter_sub;
3189 /* switch to eval mode */
3190 push_return(PL_op->op_next);
3191 PUSHBLOCK(cx, CXt_EVAL, SP);
3192 PUSHEVAL(cx, name, Nullgv);
3194 SAVECOPLINE(&PL_compiling);
3195 CopLINE_set(&PL_compiling, 0);
3198 #ifdef USE_5005THREADS
3199 MUTEX_LOCK(&PL_eval_mutex);
3200 if (PL_eval_owner && PL_eval_owner != thr)
3201 while (PL_eval_owner)
3202 COND_WAIT(&PL_eval_cond, &PL_eval_mutex);
3203 PL_eval_owner = thr;
3204 MUTEX_UNLOCK(&PL_eval_mutex);
3205 #endif /* USE_5005THREADS */
3207 /* Store and reset encoding. */
3208 encoding = PL_encoding;
3209 PL_encoding = Nullsv;
3211 op = DOCATCH(doeval(gimme, NULL));
3213 /* Restore encoding. */
3214 PL_encoding = encoding;
3221 return pp_require();
3227 register PERL_CONTEXT *cx;
3229 I32 gimme = GIMME_V, was = PL_sub_generation;
3230 char tbuf[TYPE_DIGITS(long) + 12];
3231 char *tmpbuf = tbuf;
3236 if (!SvPV(sv,len) || !len)
3238 TAINT_PROPER("eval");
3244 /* switch to eval mode */
3246 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
3247 SV *sv = sv_newmortal();
3248 Perl_sv_setpvf(aTHX_ sv, "_<(eval %lu)[%s:%"IVdf"]",
3249 (unsigned long)++PL_evalseq,
3250 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
3254 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++PL_evalseq);
3255 SAVECOPFILE_FREE(&PL_compiling);
3256 CopFILE_set(&PL_compiling, tmpbuf+2);
3257 SAVECOPLINE(&PL_compiling);
3258 CopLINE_set(&PL_compiling, 1);
3259 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
3260 deleting the eval's FILEGV from the stash before gv_check() runs
3261 (i.e. before run-time proper). To work around the coredump that
3262 ensues, we always turn GvMULTI_on for any globals that were
3263 introduced within evals. See force_ident(). GSAR 96-10-12 */
3264 safestr = savepv(tmpbuf);
3265 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
3267 PL_hints = PL_op->op_targ;
3268 SAVESPTR(PL_compiling.cop_warnings);
3269 if (specialWARN(PL_curcop->cop_warnings))
3270 PL_compiling.cop_warnings = PL_curcop->cop_warnings;
3272 PL_compiling.cop_warnings = newSVsv(PL_curcop->cop_warnings);
3273 SAVEFREESV(PL_compiling.cop_warnings);
3275 SAVESPTR(PL_compiling.cop_io);
3276 if (specialCopIO(PL_curcop->cop_io))
3277 PL_compiling.cop_io = PL_curcop->cop_io;
3279 PL_compiling.cop_io = newSVsv(PL_curcop->cop_io);
3280 SAVEFREESV(PL_compiling.cop_io);
3283 push_return(PL_op->op_next);
3284 PUSHBLOCK(cx, (CXt_EVAL|CXp_REAL), SP);
3285 PUSHEVAL(cx, 0, Nullgv);
3287 /* prepare to compile string */
3289 if (PERLDB_LINE && PL_curstash != PL_debstash)
3290 save_lines(CopFILEAV(&PL_compiling), PL_linestr);
3292 #ifdef USE_5005THREADS
3293 MUTEX_LOCK(&PL_eval_mutex);
3294 if (PL_eval_owner && PL_eval_owner != thr)
3295 while (PL_eval_owner)
3296 COND_WAIT(&PL_eval_cond, &PL_eval_mutex);
3297 PL_eval_owner = thr;
3298 MUTEX_UNLOCK(&PL_eval_mutex);
3299 #endif /* USE_5005THREADS */
3300 ret = doeval(gimme, NULL);
3301 if (PERLDB_INTER && was != PL_sub_generation /* Some subs defined here. */
3302 && ret != PL_op->op_next) { /* Successive compilation. */
3303 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
3305 return DOCATCH(ret);
3315 register PERL_CONTEXT *cx;
3317 U8 save_flags = PL_op -> op_flags;
3322 retop = pop_return();
3325 if (gimme == G_VOID)
3327 else if (gimme == G_SCALAR) {
3330 if (SvFLAGS(TOPs) & SVs_TEMP)
3333 *MARK = sv_mortalcopy(TOPs);
3337 *MARK = &PL_sv_undef;
3342 /* in case LEAVE wipes old return values */
3343 for (mark = newsp + 1; mark <= SP; mark++) {
3344 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
3345 *mark = sv_mortalcopy(*mark);
3346 TAINT_NOT; /* Each item is independent */
3350 PL_curpm = newpm; /* Don't pop $1 et al till now */
3353 assert(CvDEPTH(PL_compcv) == 1);
3355 CvDEPTH(PL_compcv) = 0;
3358 if (optype == OP_REQUIRE &&
3359 !(gimme == G_SCALAR ? SvTRUE(*SP) : SP > newsp))
3361 /* Unassume the success we assumed earlier. */
3362 SV *nsv = cx->blk_eval.old_namesv;
3363 (void)hv_delete(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), G_DISCARD);
3364 retop = Perl_die(aTHX_ "%s did not return a true value", SvPVX(nsv));
3365 /* die_where() did LEAVE, or we won't be here */
3369 if (!(save_flags & OPf_SPECIAL))
3379 register PERL_CONTEXT *cx;
3380 I32 gimme = GIMME_V;
3385 push_return(cLOGOP->op_other->op_next);
3386 PUSHBLOCK(cx, (CXt_EVAL|CXp_TRYBLOCK), SP);
3389 PL_in_eval = EVAL_INEVAL;
3392 return DOCATCH(PL_op->op_next);
3402 register PERL_CONTEXT *cx;
3410 if (gimme == G_VOID)
3412 else if (gimme == G_SCALAR) {
3415 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
3418 *MARK = sv_mortalcopy(TOPs);
3422 *MARK = &PL_sv_undef;
3427 /* in case LEAVE wipes old return values */
3428 for (mark = newsp + 1; mark <= SP; mark++) {
3429 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
3430 *mark = sv_mortalcopy(*mark);
3431 TAINT_NOT; /* Each item is independent */
3435 PL_curpm = newpm; /* Don't pop $1 et al till now */
3443 S_doparseform(pTHX_ SV *sv)
3446 register char *s = SvPV_force(sv, len);
3447 register char *send = s + len;
3448 register char *base = Nullch;
3449 register I32 skipspaces = 0;
3450 bool noblank = FALSE;
3451 bool repeat = FALSE;
3452 bool postspace = FALSE;
3460 Perl_croak(aTHX_ "Null picture in formline");
3462 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
3467 *fpc++ = FF_LINEMARK;
3468 noblank = repeat = FALSE;
3486 case ' ': case '\t':
3497 *fpc++ = FF_LITERAL;
3505 *fpc++ = skipspaces;
3509 *fpc++ = FF_NEWLINE;
3513 arg = fpc - linepc + 1;
3520 *fpc++ = FF_LINEMARK;
3521 noblank = repeat = FALSE;
3530 ischop = s[-1] == '^';
3536 arg = (s - base) - 1;
3538 *fpc++ = FF_LITERAL;
3547 *fpc++ = FF_LINEGLOB;
3549 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
3550 arg = ischop ? 512 : 0;
3560 arg |= 256 + (s - f);
3562 *fpc++ = s - base; /* fieldsize for FETCH */
3563 *fpc++ = FF_DECIMAL;
3566 else if (*s == '0' && s[1] == '#') { /* Zero padded decimals */
3567 arg = ischop ? 512 : 0;
3569 s++; /* skip the '0' first */
3578 arg |= 256 + (s - f);
3580 *fpc++ = s - base; /* fieldsize for FETCH */
3581 *fpc++ = FF_0DECIMAL;
3586 bool ismore = FALSE;
3589 while (*++s == '>') ;
3590 prespace = FF_SPACE;
3592 else if (*s == '|') {
3593 while (*++s == '|') ;
3594 prespace = FF_HALFSPACE;
3599 while (*++s == '<') ;
3602 if (*s == '.' && s[1] == '.' && s[2] == '.') {
3606 *fpc++ = s - base; /* fieldsize for FETCH */
3608 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
3626 { /* need to jump to the next word */
3628 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
3629 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
3630 s = SvPVX(sv) + SvCUR(sv) + z;
3632 Copy(fops, s, arg, U16);
3634 sv_magic(sv, Nullsv, PERL_MAGIC_fm, Nullch, 0);
3639 run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen)
3641 SV *datasv = FILTER_DATA(idx);
3642 int filter_has_file = IoLINES(datasv);
3643 GV *filter_child_proc = (GV *)IoFMT_GV(datasv);
3644 SV *filter_state = (SV *)IoTOP_GV(datasv);
3645 SV *filter_sub = (SV *)IoBOTTOM_GV(datasv);
3648 /* I was having segfault trouble under Linux 2.2.5 after a
3649 parse error occured. (Had to hack around it with a test
3650 for PL_error_count == 0.) Solaris doesn't segfault --
3651 not sure where the trouble is yet. XXX */
3653 if (filter_has_file) {
3654 len = FILTER_READ(idx+1, buf_sv, maxlen);
3657 if (filter_sub && len >= 0) {
3668 PUSHs(sv_2mortal(newSViv(maxlen)));
3670 PUSHs(filter_state);
3673 count = call_sv(filter_sub, G_SCALAR);
3689 IoLINES(datasv) = 0;
3690 if (filter_child_proc) {
3691 SvREFCNT_dec(filter_child_proc);
3692 IoFMT_GV(datasv) = Nullgv;
3695 SvREFCNT_dec(filter_state);
3696 IoTOP_GV(datasv) = Nullgv;
3699 SvREFCNT_dec(filter_sub);
3700 IoBOTTOM_GV(datasv) = Nullgv;
3702 filter_del(run_user_filter);
3708 /* perhaps someone can come up with a better name for
3709 this? it is not really "absolute", per se ... */
3711 S_path_is_absolute(pTHX_ char *name)
3713 if (PERL_FILE_IS_ABSOLUTE(name)
3714 #ifdef MACOS_TRADITIONAL
3715 || (*name == ':' && name[1] != ':' && strchr(name+2, ':')))
3717 || (*name == '.' && (name[1] == '/' ||
3718 (name[1] == '.' && name[2] == '/'))))