3 * Copyright (c) 1991-1997, 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.
23 #define WORD_ALIGN sizeof(U16)
26 #define DOCATCH(o) ((CATCH_GET == TRUE) ? docatch(o) : (o))
28 static OP *docatch _((OP *o));
29 static OP *dofindlabel _((OP *o, char *label, OP **opstack, OP **oplimit));
30 static void doparseform _((SV *sv));
31 static I32 dopoptoeval _((I32 startingblock));
32 static I32 dopoptolabel _((char *label));
33 static I32 dopoptoloop _((I32 startingblock));
34 static I32 dopoptosub _((I32 startingblock));
35 static void save_lines _((AV *array, SV *sv));
36 static int sortcv _((const void *, const void *));
37 static int sortcmp _((const void *, const void *));
38 static int sortcmp_locale _((const void *, const void *));
39 static OP *doeval _((int gimme, OP** startop));
49 cxix = dopoptosub(cxstack_ix);
53 switch (cxstack[cxix].blk_gimme) {
70 register PMOP *pm = (PMOP*)cLOGOP->op_other;
74 MAGIC *mg = Null(MAGIC*);
78 SV *sv = SvRV(tmpstr);
80 mg = mg_find(sv, 'r');
83 regexp *re = (regexp *)mg->mg_obj;
84 ReREFCNT_dec(pm->op_pmregexp);
85 pm->op_pmregexp = ReREFCNT_inc(re);
88 t = SvPV(tmpstr, len);
90 /* JMR: Check against the last compiled regexp */
91 if ( ! pm->op_pmregexp || ! pm->op_pmregexp->precomp
92 || strnNE(pm->op_pmregexp->precomp, t, len)
93 || pm->op_pmregexp->precomp[len]) {
94 if (pm->op_pmregexp) {
95 ReREFCNT_dec(pm->op_pmregexp);
96 pm->op_pmregexp = Null(REGEXP*); /* crucial if regcomp aborts */
99 pm->op_pmflags = pm->op_pmpermflags; /* reset case sensitivity */
100 pm->op_pmregexp = pregcomp(t, t + len, pm);
104 if (!pm->op_pmregexp->prelen && curpm)
106 else if (strEQ("\\s+", pm->op_pmregexp->precomp))
107 pm->op_pmflags |= PMf_WHITE;
109 if (pm->op_pmflags & PMf_KEEP) {
110 pm->op_private &= ~OPpRUNTIME; /* no point compiling again */
111 cLOGOP->op_first->op_next = op->op_next;
119 register PMOP *pm = (PMOP*) cLOGOP->op_other;
120 register PERL_CONTEXT *cx = &cxstack[cxstack_ix];
121 register SV *dstr = cx->sb_dstr;
122 register char *s = cx->sb_s;
123 register char *m = cx->sb_m;
124 char *orig = cx->sb_orig;
125 register REGEXP *rx = cx->sb_rx;
127 rxres_restore(&cx->sb_rxres, rx);
129 if (cx->sb_iters++) {
130 if (cx->sb_iters > cx->sb_maxiters)
131 DIE("Substitution loop");
133 if (!cx->sb_rxtainted)
134 cx->sb_rxtainted = SvTAINTED(TOPs);
135 sv_catsv(dstr, POPs);
138 if (cx->sb_once || !regexec_flags(rx, s, cx->sb_strend, orig,
139 s == m, Nullsv, NULL,
140 cx->sb_safebase ? 0 : REXEC_COPY_STR))
142 SV *targ = cx->sb_targ;
143 sv_catpvn(dstr, s, cx->sb_strend - s);
145 TAINT_IF(cx->sb_rxtainted || RX_MATCH_TAINTED(rx));
147 (void)SvOOK_off(targ);
148 Safefree(SvPVX(targ));
149 SvPVX(targ) = SvPVX(dstr);
150 SvCUR_set(targ, SvCUR(dstr));
151 SvLEN_set(targ, SvLEN(dstr));
154 (void)SvPOK_only(targ);
158 PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
159 LEAVE_SCOPE(cx->sb_oldsave);
161 RETURNOP(pm->op_next);
164 if (rx->subbase && rx->subbase != orig) {
167 cx->sb_orig = orig = rx->subbase;
169 cx->sb_strend = s + (cx->sb_strend - m);
171 cx->sb_m = m = rx->startp[0];
172 sv_catpvn(dstr, s, m-s);
173 cx->sb_s = rx->endp[0];
174 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
175 rxres_save(&cx->sb_rxres, rx);
176 RETURNOP(pm->op_pmreplstart);
180 rxres_save(void **rsp, REGEXP *rx)
185 if (!p || p[1] < rx->nparens) {
186 i = 6 + rx->nparens * 2;
194 *p++ = (UV)rx->subbase;
195 rx->subbase = Nullch;
199 *p++ = (UV)rx->subbeg;
200 *p++ = (UV)rx->subend;
201 for (i = 0; i <= rx->nparens; ++i) {
202 *p++ = (UV)rx->startp[i];
203 *p++ = (UV)rx->endp[i];
208 rxres_restore(void **rsp, REGEXP *rx)
213 Safefree(rx->subbase);
214 rx->subbase = (char*)(*p);
219 rx->subbeg = (char*)(*p++);
220 rx->subend = (char*)(*p++);
221 for (i = 0; i <= rx->nparens; ++i) {
222 rx->startp[i] = (char*)(*p++);
223 rx->endp[i] = (char*)(*p++);
228 rxres_free(void **rsp)
233 Safefree((char*)(*p));
241 djSP; dMARK; dORIGMARK;
242 register SV *form = *++MARK;
254 bool chopspace = (strchr(chopset, ' ') != Nullch);
261 if (!SvMAGICAL(form) || !SvCOMPILED(form)) {
262 SvREADONLY_off(form);
266 SvPV_force(formtarget, len);
267 t = SvGROW(formtarget, len + SvCUR(form) + 1); /* XXX SvCUR bad */
270 /* need to jump to the next word */
271 s = f + len + WORD_ALIGN - SvCUR(form) % WORD_ALIGN;
280 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
281 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
282 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
283 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
284 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
286 case FF_CHECKNL: name = "CHECKNL"; break;
287 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
288 case FF_SPACE: name = "SPACE"; break;
289 case FF_HALFSPACE: name = "HALFSPACE"; break;
290 case FF_ITEM: name = "ITEM"; break;
291 case FF_CHOP: name = "CHOP"; break;
292 case FF_LINEGLOB: name = "LINEGLOB"; break;
293 case FF_NEWLINE: name = "NEWLINE"; break;
294 case FF_MORE: name = "MORE"; break;
295 case FF_LINEMARK: name = "LINEMARK"; break;
296 case FF_END: name = "END"; break;
299 PerlIO_printf(PerlIO_stderr(), "%-16s%ld\n", name, (long) arg);
301 PerlIO_printf(PerlIO_stderr(), "%-16s\n", name);
330 warn("Not enough format arguments");
335 item = s = SvPV(sv, len);
337 if (itemsize > fieldsize)
338 itemsize = fieldsize;
339 send = chophere = s + itemsize;
351 item = s = SvPV(sv, len);
353 if (itemsize <= fieldsize) {
354 send = chophere = s + itemsize;
365 itemsize = fieldsize;
366 send = chophere = s + itemsize;
367 while (s < send || (s == send && isSPACE(*s))) {
377 if (strchr(chopset, *s))
382 itemsize = chophere - item;
387 arg = fieldsize - itemsize;
396 arg = fieldsize - itemsize;
410 int ch = *t++ = *s++;
414 if ( !((*t++ = *s++) & ~31) )
424 while (*s && isSPACE(*s))
431 item = s = SvPV(sv, len);
444 SvCUR_set(formtarget, t - SvPVX(formtarget));
445 sv_catpvn(formtarget, item, itemsize);
446 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(form) + 1);
447 t = SvPVX(formtarget) + SvCUR(formtarget);
452 /* If the field is marked with ^ and the value is undefined,
455 if ((arg & 512) && !SvOK(sv)) {
463 /* Formats aren't yet marked for locales, so assume "yes". */
466 sprintf(t, "%#*.*f", (int) fieldsize, (int) arg & 255, value);
468 sprintf(t, "%*.0f", (int) fieldsize, value);
475 while (t-- > linemark && *t == ' ') ;
483 if (arg) { /* repeat until fields exhausted? */
485 SvCUR_set(formtarget, t - SvPVX(formtarget));
486 lines += FmLINES(formtarget);
489 if (strnEQ(linemark, linemark - arg, arg))
490 DIE("Runaway format");
492 FmLINES(formtarget) = lines;
494 RETURNOP(cLISTOP->op_first);
505 arg = fieldsize - itemsize;
512 if (strnEQ(s," ",3)) {
513 while (s > SvPVX(formtarget) && isSPACE(s[-1]))
524 SvCUR_set(formtarget, t - SvPVX(formtarget));
525 FmLINES(formtarget) += lines;
537 if (stack_base + *markstack_ptr == sp) {
539 if (GIMME_V == G_SCALAR)
541 RETURNOP(op->op_next->op_next);
543 stack_sp = stack_base + *markstack_ptr + 1;
544 pp_pushmark(ARGS); /* push dst */
545 pp_pushmark(ARGS); /* push src */
546 ENTER; /* enter outer scope */
549 SAVESPTR(GvSV(defgv));
551 ENTER; /* enter inner scope */
554 src = stack_base[*markstack_ptr];
559 if (op->op_type == OP_MAPSTART)
560 pp_pushmark(ARGS); /* push top */
561 return ((LOGOP*)op->op_next)->op_other;
566 DIE("panic: mapstart"); /* uses grepstart */
572 I32 diff = (sp - stack_base) - *markstack_ptr;
580 if (diff > markstack_ptr[-1] - markstack_ptr[-2]) {
581 shift = diff - (markstack_ptr[-1] - markstack_ptr[-2]);
582 count = (sp - stack_base) - markstack_ptr[-1] + 2;
587 markstack_ptr[-1] += shift;
588 *markstack_ptr += shift;
592 dst = stack_base + (markstack_ptr[-2] += diff) - 1;
595 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
597 LEAVE; /* exit inner scope */
600 if (markstack_ptr[-1] > *markstack_ptr) {
604 (void)POPMARK; /* pop top */
605 LEAVE; /* exit outer scope */
606 (void)POPMARK; /* pop src */
607 items = --*markstack_ptr - markstack_ptr[-1];
608 (void)POPMARK; /* pop dst */
609 SP = stack_base + POPMARK; /* pop original mark */
610 if (gimme == G_SCALAR) {
614 else if (gimme == G_ARRAY)
621 ENTER; /* enter inner scope */
624 src = stack_base[markstack_ptr[-1]];
628 RETURNOP(cLOGOP->op_other);
635 djSP; dMARK; dORIGMARK;
637 SV **myorigmark = ORIGMARK;
643 OP* nextop = op->op_next;
645 if (gimme != G_ARRAY) {
650 if (op->op_flags & OPf_STACKED) {
652 if (op->op_flags & OPf_SPECIAL) {
653 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
654 kid = kUNOP->op_first; /* pass rv2gv */
655 kid = kUNOP->op_first; /* pass leave */
656 sortcop = kid->op_next;
657 stash = curcop->cop_stash;
660 cv = sv_2cv(*++MARK, &stash, &gv, 0);
661 if (!(cv && CvROOT(cv))) {
663 SV *tmpstr = sv_newmortal();
664 gv_efullname3(tmpstr, gv, Nullch);
665 if (cv && CvXSUB(cv))
666 DIE("Xsub \"%s\" called in sort", SvPVX(tmpstr));
667 DIE("Undefined sort subroutine \"%s\" called",
672 DIE("Xsub called in sort");
673 DIE("Undefined subroutine in sort");
675 DIE("Not a CODE reference in sort");
677 sortcop = CvSTART(cv);
678 SAVESPTR(CvROOT(cv)->op_ppaddr);
679 CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
682 curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
687 stash = curcop->cop_stash;
691 while (MARK < SP) { /* This may or may not shift down one here. */
693 if (*up = *++MARK) { /* Weed out nulls. */
695 if (!sortcop && !SvPOK(*up))
696 (void)sv_2pv(*up, &na);
700 max = --up - myorigmark;
706 bool oldcatch = CATCH_GET;
714 AvREAL_off(sortstack);
715 av_extend(sortstack, 32);
718 SWITCHSTACK(curstack, sortstack);
719 if (sortstash != stash) {
720 firstgv = gv_fetchpv("a", TRUE, SVt_PV);
721 secondgv = gv_fetchpv("b", TRUE, SVt_PV);
725 SAVESPTR(GvSV(firstgv));
726 SAVESPTR(GvSV(secondgv));
728 PUSHBLOCK(cx, CXt_NULL, stack_base);
729 if (!(op->op_flags & OPf_SPECIAL)) {
730 bool hasargs = FALSE;
731 cx->cx_type = CXt_SUB;
732 cx->blk_gimme = G_SCALAR;
735 (void)SvREFCNT_inc(cv); /* in preparation for POPSUB */
737 sortcxix = cxstack_ix;
739 qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
742 SWITCHSTACK(sortstack, oldstack);
749 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
750 qsort((char*)(ORIGMARK+1), max, sizeof(SV*),
751 (op->op_private & OPpLOCALE) ? sortcmp_locale : sortcmp);
754 stack_sp = ORIGMARK + max;
762 if (GIMME == G_ARRAY)
763 return cCONDOP->op_true;
764 return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
771 if (GIMME == G_ARRAY) {
772 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
776 SV *targ = PAD_SV(op->op_targ);
778 if ((op->op_private & OPpFLIP_LINENUM)
779 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
781 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
782 if (op->op_flags & OPf_SPECIAL) {
790 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
803 if (GIMME == G_ARRAY) {
809 if (SvNIOKp(left) || !SvPOKp(left) ||
810 (looks_like_number(left) && *SvPVX(left) != '0') )
815 EXTEND_MORTAL(max - i + 1);
816 EXTEND(SP, max - i + 1);
819 sv = sv_2mortal(newSViv(i++));
824 SV *final = sv_mortalcopy(right);
826 char *tmps = SvPV(final, len);
828 sv = sv_mortalcopy(left);
829 while (!SvNIOKp(sv) && SvCUR(sv) <= len &&
830 strNE(SvPVX(sv),tmps) ) {
832 sv = sv_2mortal(newSVsv(sv));
835 if (strEQ(SvPVX(sv),tmps))
841 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
843 if ((op->op_private & OPpFLIP_LINENUM)
844 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
846 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
847 sv_catpv(targ, "E0");
858 dopoptolabel(char *label)
862 register PERL_CONTEXT *cx;
864 for (i = cxstack_ix; i >= 0; i--) {
866 switch (cx->cx_type) {
869 warn("Exiting substitution via %s", op_name[op->op_type]);
873 warn("Exiting subroutine via %s", op_name[op->op_type]);
877 warn("Exiting eval via %s", op_name[op->op_type]);
881 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
884 if (!cx->blk_loop.label ||
885 strNE(label, cx->blk_loop.label) ) {
886 DEBUG_l(deb("(Skipping label #%ld %s)\n",
887 (long)i, cx->blk_loop.label));
890 DEBUG_l( deb("(Found label #%ld %s)\n", (long)i, label));
900 I32 gimme = block_gimme();
901 return (gimme == G_VOID) ? G_SCALAR : gimme;
910 cxix = dopoptosub(cxstack_ix);
914 switch (cxstack[cxix].blk_gimme) {
920 croak("panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
927 dopoptosub(I32 startingblock)
931 register PERL_CONTEXT *cx;
932 for (i = startingblock; i >= 0; i--) {
934 switch (cx->cx_type) {
939 DEBUG_l( deb("(Found sub #%ld)\n", (long)i));
947 dopoptoeval(I32 startingblock)
951 register PERL_CONTEXT *cx;
952 for (i = startingblock; i >= 0; i--) {
954 switch (cx->cx_type) {
958 DEBUG_l( deb("(Found eval #%ld)\n", (long)i));
966 dopoptoloop(I32 startingblock)
970 register PERL_CONTEXT *cx;
971 for (i = startingblock; i >= 0; i--) {
973 switch (cx->cx_type) {
976 warn("Exiting substitution via %s", op_name[op->op_type]);
980 warn("Exiting subroutine via %s", op_name[op->op_type]);
984 warn("Exiting eval via %s", op_name[op->op_type]);
988 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
991 DEBUG_l( deb("(Found loop #%ld)\n", (long)i));
1002 register PERL_CONTEXT *cx;
1006 while (cxstack_ix > cxix) {
1007 cx = &cxstack[cxstack_ix];
1008 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n",
1009 (long) cxstack_ix+1, block_type[cx->cx_type]));
1010 /* Note: we don't need to restore the base context info till the end. */
1011 switch (cx->cx_type) {
1014 continue; /* not break */
1032 die_where(char *message)
1037 register PERL_CONTEXT *cx;
1043 STRLEN klen = strlen(message);
1045 svp = hv_fetch(ERRHV, message, klen, TRUE);
1048 static char prefix[] = "\t(in cleanup) ";
1049 sv_upgrade(*svp, SVt_IV);
1050 (void)SvIOK_only(*svp);
1051 SvGROW(ERRSV, SvCUR(ERRSV)+sizeof(prefix)+klen);
1052 sv_catpvn(ERRSV, prefix, sizeof(prefix)-1);
1053 sv_catpvn(ERRSV, message, klen);
1059 sv_setpv(ERRSV, message);
1061 cxix = dopoptoeval(cxstack_ix);
1065 if (cxix < cxstack_ix)
1069 if (cx->cx_type != CXt_EVAL) {
1070 PerlIO_printf(PerlIO_stderr(), "panic: die %s", message);
1075 if (gimme == G_SCALAR)
1076 *++newsp = &sv_undef;
1081 if (optype == OP_REQUIRE) {
1082 char* msg = SvPVx(ERRSV, na);
1083 DIE("%s", *msg ? msg : "Compilation failed in require");
1085 return pop_return();
1088 PerlIO_printf(PerlIO_stderr(), "%s",message);
1089 PerlIO_flush(PerlIO_stderr());
1098 if (SvTRUE(left) != SvTRUE(right))
1110 RETURNOP(cLOGOP->op_other);
1119 RETURNOP(cLOGOP->op_other);
1125 register I32 cxix = dopoptosub(cxstack_ix);
1126 register PERL_CONTEXT *cx;
1137 if (GIMME != G_ARRAY)
1141 if (DBsub && cxix >= 0 &&
1142 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1146 cxix = dopoptosub(cxix - 1);
1148 cx = &cxstack[cxix];
1149 if (cxstack[cxix].cx_type == CXt_SUB) {
1150 dbcxix = dopoptosub(cxix - 1);
1151 /* We expect that cxstack[dbcxix] is CXt_SUB, anyway, the
1152 field below is defined for any cx. */
1153 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1154 cx = &cxstack[dbcxix];
1157 if (GIMME != G_ARRAY) {
1160 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1165 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1166 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1167 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1170 if (cx->cx_type == CXt_SUB) { /* So is cxstack[dbcxix]. */
1172 gv_efullname3(sv, CvGV(cxstack[cxix].blk_sub.cv), Nullch);
1173 PUSHs(sv_2mortal(sv));
1174 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1177 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1178 PUSHs(sv_2mortal(newSViv(0)));
1180 gimme = (I32)cx->blk_gimme;
1181 if (gimme == G_VOID)
1184 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1185 if (cx->cx_type == CXt_EVAL) {
1186 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1187 PUSHs(cx->blk_eval.cur_text);
1190 else if (cx->blk_eval.old_name) { /* Try blocks have old_name == 0. */
1191 /* Require, put the name. */
1192 PUSHs(sv_2mortal(newSVpv(cx->blk_eval.old_name, 0)));
1196 else if (cx->cx_type == CXt_SUB &&
1197 cx->blk_sub.hasargs &&
1198 curcop->cop_stash == debstash)
1200 AV *ary = cx->blk_sub.argarray;
1201 int off = AvARRAY(ary) - AvALLOC(ary);
1205 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1208 AvREAL_off(dbargs); /* XXX Should be REIFY */
1211 if (AvMAX(dbargs) < AvFILL(ary) + off)
1212 av_extend(dbargs, AvFILL(ary) + off);
1213 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1214 AvFILL(dbargs) = AvFILL(ary) + off;
1220 sortcv(const void *a, const void *b)
1223 SV * const *str1 = (SV * const *)a;
1224 SV * const *str2 = (SV * const *)b;
1225 I32 oldsaveix = savestack_ix;
1226 I32 oldscopeix = scopestack_ix;
1228 GvSV(firstgv) = *str1;
1229 GvSV(secondgv) = *str2;
1230 stack_sp = stack_base;
1233 if (stack_sp != stack_base + 1)
1234 croak("Sort subroutine didn't return single value");
1235 if (!SvNIOKp(*stack_sp))
1236 croak("Sort subroutine didn't return a numeric value");
1237 result = SvIV(*stack_sp);
1238 while (scopestack_ix > oldscopeix) {
1241 leave_scope(oldsaveix);
1246 sortcmp(const void *a, const void *b)
1248 return sv_cmp(*(SV * const *)a, *(SV * const *)b);
1252 sortcmp_locale(const void *a, const void *b)
1254 return sv_cmp_locale(*(SV * const *)a, *(SV * const *)b);
1266 sv_reset(tmps, curcop->cop_stash);
1279 TAINT_NOT; /* Each statement is presumed innocent */
1280 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1283 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1287 register PERL_CONTEXT *cx;
1288 I32 gimme = G_ARRAY;
1295 DIE("No DB::DB routine defined");
1297 if (CvDEPTH(cv) >= 1 && !(debug & (1<<30))) /* don't do recursive DB::DB call */
1309 push_return(op->op_next);
1310 PUSHBLOCK(cx, CXt_SUB, sp);
1313 (void)SvREFCNT_inc(cv);
1315 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1316 RETURNOP(CvSTART(cv));
1330 register PERL_CONTEXT *cx;
1331 I32 gimme = GIMME_V;
1338 svp = &curpad[op->op_targ]; /* "my" variable */
1340 svp = &GvSV((GV*)POPs); /* symbol table variable */
1346 PUSHBLOCK(cx, CXt_LOOP, SP);
1347 PUSHLOOP(cx, svp, MARK);
1348 if (op->op_flags & OPf_STACKED)
1349 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1351 cx->blk_loop.iterary = curstack;
1352 AvFILL(curstack) = sp - stack_base;
1353 cx->blk_loop.iterix = MARK - stack_base;
1362 register PERL_CONTEXT *cx;
1363 I32 gimme = GIMME_V;
1369 PUSHBLOCK(cx, CXt_LOOP, SP);
1370 PUSHLOOP(cx, 0, SP);
1378 register PERL_CONTEXT *cx;
1379 struct block_loop cxloop;
1387 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1390 if (gimme == G_VOID)
1392 else if (gimme == G_SCALAR) {
1394 *++newsp = sv_mortalcopy(*SP);
1396 *++newsp = &sv_undef;
1400 *++newsp = sv_mortalcopy(*++mark);
1401 TAINT_NOT; /* Each item is independent */
1407 POPLOOP2(); /* Stack values are safe: release loop vars ... */
1408 curpm = newpm; /* ... and pop $1 et al */
1420 register PERL_CONTEXT *cx;
1421 struct block_sub cxsub;
1422 bool popsub2 = FALSE;
1428 if (curstack == sortstack) {
1429 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) <= sortcxix) {
1430 if (cxstack_ix > sortcxix)
1432 AvARRAY(curstack)[1] = *SP;
1433 stack_sp = stack_base + 1;
1438 cxix = dopoptosub(cxstack_ix);
1440 DIE("Can't return outside a subroutine");
1441 if (cxix < cxstack_ix)
1445 switch (cx->cx_type) {
1447 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1452 if (optype == OP_REQUIRE &&
1453 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1455 /* Unassume the success we assumed earlier. */
1456 char *name = cx->blk_eval.old_name;
1457 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1458 DIE("%s did not return a true value", name);
1462 DIE("panic: return");
1466 if (gimme == G_SCALAR) {
1468 *++newsp = (popsub2 && SvTEMP(*SP))
1469 ? *SP : sv_mortalcopy(*SP);
1471 *++newsp = &sv_undef;
1473 else if (gimme == G_ARRAY) {
1474 while (++MARK <= SP) {
1475 *++newsp = (popsub2 && SvTEMP(*MARK))
1476 ? *MARK : sv_mortalcopy(*MARK);
1477 TAINT_NOT; /* Each item is independent */
1482 /* Stack values are safe: */
1484 POPSUB2(); /* release CV and @_ ... */
1486 curpm = newpm; /* ... and pop $1 et al */
1489 return pop_return();
1496 register PERL_CONTEXT *cx;
1497 struct block_loop cxloop;
1498 struct block_sub cxsub;
1505 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1507 if (op->op_flags & OPf_SPECIAL) {
1508 cxix = dopoptoloop(cxstack_ix);
1510 DIE("Can't \"last\" outside a block");
1513 cxix = dopoptolabel(cPVOP->op_pv);
1515 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1517 if (cxix < cxstack_ix)
1521 switch (cx->cx_type) {
1523 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1525 nextop = cxloop.last_op->op_next;
1528 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1530 nextop = pop_return();
1534 nextop = pop_return();
1541 if (gimme == G_SCALAR) {
1543 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
1544 ? *SP : sv_mortalcopy(*SP);
1546 *++newsp = &sv_undef;
1548 else if (gimme == G_ARRAY) {
1549 while (++MARK <= SP) {
1550 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
1551 ? *MARK : sv_mortalcopy(*MARK);
1552 TAINT_NOT; /* Each item is independent */
1558 /* Stack values are safe: */
1561 POPLOOP2(); /* release loop vars ... */
1565 POPSUB2(); /* release CV and @_ ... */
1568 curpm = newpm; /* ... and pop $1 et al */
1577 register PERL_CONTEXT *cx;
1580 if (op->op_flags & OPf_SPECIAL) {
1581 cxix = dopoptoloop(cxstack_ix);
1583 DIE("Can't \"next\" outside a block");
1586 cxix = dopoptolabel(cPVOP->op_pv);
1588 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1590 if (cxix < cxstack_ix)
1594 oldsave = scopestack[scopestack_ix - 1];
1595 LEAVE_SCOPE(oldsave);
1596 return cx->blk_loop.next_op;
1602 register PERL_CONTEXT *cx;
1605 if (op->op_flags & OPf_SPECIAL) {
1606 cxix = dopoptoloop(cxstack_ix);
1608 DIE("Can't \"redo\" outside a block");
1611 cxix = dopoptolabel(cPVOP->op_pv);
1613 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1615 if (cxix < cxstack_ix)
1619 oldsave = scopestack[scopestack_ix - 1];
1620 LEAVE_SCOPE(oldsave);
1621 return cx->blk_loop.redo_op;
1624 static OP* lastgotoprobe;
1627 dofindlabel(OP *o, char *label, OP **opstack, OP **oplimit)
1631 static char too_deep[] = "Target of goto is too deeply nested";
1635 if (o->op_type == OP_LEAVE ||
1636 o->op_type == OP_SCOPE ||
1637 o->op_type == OP_LEAVELOOP ||
1638 o->op_type == OP_LEAVETRY)
1640 *ops++ = cUNOPo->op_first;
1645 if (o->op_flags & OPf_KIDS) {
1646 /* First try all the kids at this level, since that's likeliest. */
1647 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1648 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1649 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1652 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1653 if (kid == lastgotoprobe)
1655 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1657 (ops[-1]->op_type != OP_NEXTSTATE &&
1658 ops[-1]->op_type != OP_DBSTATE)))
1660 if (o = dofindlabel(kid, label, ops, oplimit))
1670 return pp_goto(ARGS);
1679 register PERL_CONTEXT *cx;
1680 #define GOTO_DEPTH 64
1681 OP *enterops[GOTO_DEPTH];
1683 int do_dump = (op->op_type == OP_DUMP);
1686 if (op->op_flags & OPf_STACKED) {
1689 /* This egregious kludge implements goto &subroutine */
1690 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1692 register PERL_CONTEXT *cx;
1693 CV* cv = (CV*)SvRV(sv);
1698 if (!CvROOT(cv) && !CvXSUB(cv)) {
1700 SV *tmpstr = sv_newmortal();
1701 gv_efullname3(tmpstr, CvGV(cv), Nullch);
1702 DIE("Goto undefined subroutine &%s",SvPVX(tmpstr));
1704 DIE("Goto undefined subroutine");
1707 /* First do some returnish stuff. */
1708 cxix = dopoptosub(cxstack_ix);
1710 DIE("Can't goto subroutine outside a subroutine");
1711 if (cxix < cxstack_ix)
1715 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1716 AV* av = cx->blk_sub.argarray;
1718 items = AvFILL(av) + 1;
1720 EXTEND(stack_sp, items); /* @_ could have been extended. */
1721 Copy(AvARRAY(av), stack_sp, items, SV*);
1724 SvREFCNT_dec(GvAV(defgv));
1725 GvAV(defgv) = cx->blk_sub.savearray;
1726 #endif /* USE_THREADS */
1730 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1731 SvREFCNT_dec(cx->blk_sub.cv);
1732 oldsave = scopestack[scopestack_ix - 1];
1733 LEAVE_SCOPE(oldsave);
1735 /* Now do some callish stuff. */
1738 if (CvOLDSTYLE(cv)) {
1739 I32 (*fp3)_((int,int,int));
1744 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1745 items = (*fp3)(CvXSUBANY(cv).any_i32,
1746 mark - stack_base + 1,
1748 sp = stack_base + items;
1751 stack_sp--; /* There is no cv arg. */
1752 (void)(*CvXSUB(cv))(cv);
1755 return pop_return();
1758 AV* padlist = CvPADLIST(cv);
1759 SV** svp = AvARRAY(padlist);
1760 cx->blk_sub.cv = cv;
1761 cx->blk_sub.olddepth = CvDEPTH(cv);
1763 if (CvDEPTH(cv) < 2)
1764 (void)SvREFCNT_inc(cv);
1765 else { /* save temporaries on recursion? */
1766 if (CvDEPTH(cv) == 100 && dowarn)
1767 sub_crush_depth(cv);
1768 if (CvDEPTH(cv) > AvFILL(padlist)) {
1769 AV *newpad = newAV();
1770 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
1771 I32 ix = AvFILL((AV*)svp[1]);
1772 svp = AvARRAY(svp[0]);
1773 for ( ;ix > 0; ix--) {
1774 if (svp[ix] != &sv_undef) {
1775 char *name = SvPVX(svp[ix]);
1776 if ((SvFLAGS(svp[ix]) & SVf_FAKE)
1779 /* outer lexical or anon code */
1780 av_store(newpad, ix,
1781 SvREFCNT_inc(oldpad[ix]) );
1783 else { /* our own lexical */
1785 av_store(newpad, ix, sv = (SV*)newAV());
1786 else if (*name == '%')
1787 av_store(newpad, ix, sv = (SV*)newHV());
1789 av_store(newpad, ix, sv = NEWSV(0,0));
1794 av_store(newpad, ix, sv = NEWSV(0,0));
1798 if (cx->blk_sub.hasargs) {
1801 av_store(newpad, 0, (SV*)av);
1802 AvFLAGS(av) = AVf_REIFY;
1804 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1805 AvFILL(padlist) = CvDEPTH(cv);
1806 svp = AvARRAY(padlist);
1810 if (!cx->blk_sub.hasargs) {
1811 AV* av = (AV*)curpad[0];
1813 items = AvFILL(av) + 1;
1815 /* Mark is at the end of the stack. */
1817 Copy(AvARRAY(av), sp + 1, items, SV*);
1822 #endif /* USE_THREADS */
1824 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1826 if (cx->blk_sub.hasargs)
1827 #endif /* USE_THREADS */
1829 AV* av = (AV*)curpad[0];
1833 cx->blk_sub.savearray = GvAV(defgv);
1834 GvAV(defgv) = (AV*)SvREFCNT_inc(av);
1835 #endif /* USE_THREADS */
1836 cx->blk_sub.argarray = av;
1839 if (items >= AvMAX(av) + 1) {
1841 if (AvARRAY(av) != ary) {
1842 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1843 SvPVX(av) = (char*)ary;
1845 if (items >= AvMAX(av) + 1) {
1846 AvMAX(av) = items - 1;
1847 Renew(ary,items+1,SV*);
1849 SvPVX(av) = (char*)ary;
1852 Copy(mark,AvARRAY(av),items,SV*);
1853 AvFILL(av) = items - 1;
1861 if (PERLDB_SUB && curstash != debstash) {
1863 * We do not care about using sv to call CV;
1864 * it's for informational purposes only.
1866 SV *sv = GvSV(DBsub);
1868 gv_efullname3(sv, CvGV(cv), Nullch);
1870 RETURNOP(CvSTART(cv));
1874 label = SvPV(sv,na);
1876 else if (op->op_flags & OPf_SPECIAL) {
1878 DIE("goto must have label");
1881 label = cPVOP->op_pv;
1883 if (label && *label) {
1890 for (ix = cxstack_ix; ix >= 0; ix--) {
1892 switch (cx->cx_type) {
1894 gotoprobe = eval_root; /* XXX not good for nested eval */
1897 gotoprobe = cx->blk_oldcop->op_sibling;
1903 gotoprobe = cx->blk_oldcop->op_sibling;
1905 gotoprobe = main_root;
1908 if (CvDEPTH(cx->blk_sub.cv)) {
1909 gotoprobe = CvROOT(cx->blk_sub.cv);
1914 DIE("Can't \"goto\" outside a block");
1918 gotoprobe = main_root;
1921 retop = dofindlabel(gotoprobe, label,
1922 enterops, enterops + GOTO_DEPTH);
1925 lastgotoprobe = gotoprobe;
1928 DIE("Can't find label %s", label);
1930 /* pop unwanted frames */
1932 if (ix < cxstack_ix) {
1939 oldsave = scopestack[scopestack_ix];
1940 LEAVE_SCOPE(oldsave);
1943 /* push wanted frames */
1945 if (*enterops && enterops[1]) {
1947 for (ix = 1; enterops[ix]; ix++) {
1949 /* Eventually we may want to stack the needed arguments
1950 * for each op. For now, we punt on the hard ones. */
1951 if (op->op_type == OP_ENTERITER)
1952 DIE("Can't \"goto\" into the middle of a foreach loop",
1954 (*op->op_ppaddr)(ARGS);
1962 if (!retop) retop = main_start;
1969 restartop = 0; /* hmm, must be GNU unexec().. */
1973 if (curstack == signalstack) {
1991 if (anum == 1 && VMSISH_EXIT)
2004 double value = SvNVx(GvSV(cCOP->cop_gv));
2005 register I32 match = I_32(value);
2008 if (((double)match) > value)
2009 --match; /* was fractional--truncate other way */
2011 match -= cCOP->uop.scop.scop_offset;
2014 else if (match > cCOP->uop.scop.scop_max)
2015 match = cCOP->uop.scop.scop_max;
2016 op = cCOP->uop.scop.scop_next[match];
2026 op = op->op_next; /* can't assume anything */
2028 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
2029 match -= cCOP->uop.scop.scop_offset;
2032 else if (match > cCOP->uop.scop.scop_max)
2033 match = cCOP->uop.scop.scop_max;
2034 op = cCOP->uop.scop.scop_next[match];
2043 save_lines(AV *array, SV *sv)
2045 register char *s = SvPVX(sv);
2046 register char *send = SvPVX(sv) + SvCUR(sv);
2048 register I32 line = 1;
2050 while (s && s < send) {
2051 SV *tmpstr = NEWSV(85,0);
2053 sv_upgrade(tmpstr, SVt_PVMG);
2054 t = strchr(s, '\n');
2060 sv_setpvn(tmpstr, s, t - s);
2061 av_store(array, line++, tmpstr);
2076 assert(CATCH_GET == TRUE);
2077 DEBUG_l(deb("Setting up local jumplevel %p, was %p\n", &cur_env, top_env));
2081 default: /* topmost level handles it */
2088 PerlIO_printf(PerlIO_stderr(), "panic: restartop\n");
2104 sv_compile_2op(SV *sv, OP** startop, char *code, AV** avp)
2105 /* sv Text to convert to OP tree. */
2106 /* startop op_free() this to undo. */
2107 /* code Short string id of the caller. */
2109 dSP; /* Make POPBLOCK work. */
2116 char tmpbuf[TYPE_DIGITS(long) + 12 + 10];
2122 /* switch to eval mode */
2124 SAVESPTR(compiling.cop_filegv);
2125 SAVEI16(compiling.cop_line);
2126 sprintf(tmpbuf, "_<(%.10s_eval %lu)", code, (unsigned long)++evalseq);
2127 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2128 compiling.cop_line = 1;
2129 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2130 deleting the eval's FILEGV from the stash before gv_check() runs
2131 (i.e. before run-time proper). To work around the coredump that
2132 ensues, we always turn GvMULTI_on for any globals that were
2133 introduced within evals. See force_ident(). GSAR 96-10-12 */
2134 safestr = savepv(tmpbuf);
2135 SAVEDELETE(defstash, safestr, strlen(safestr));
2141 op->op_type = 0; /* Avoid uninit warning. */
2142 op->op_flags = 0; /* Avoid uninit warning. */
2143 PUSHBLOCK(cx, CXt_EVAL, SP);
2144 PUSHEVAL(cx, 0, compiling.cop_filegv);
2145 rop = doeval(G_SCALAR, startop);
2149 (*startop)->op_type = OP_NULL;
2150 (*startop)->op_ppaddr = ppaddr[OP_NULL];
2152 *avp = (AV*)SvREFCNT_inc(comppad);
2157 /* With USE_THREADS, eval_owner must be held on entry to doeval */
2159 doeval(int gimme, OP** startop)
2171 /* set up a scratch pad */
2176 SAVESPTR(comppad_name);
2177 SAVEI32(comppad_name_fill);
2178 SAVEI32(min_intro_pending);
2179 SAVEI32(max_intro_pending);
2183 compcv = (CV*)NEWSV(1104,0);
2184 sv_upgrade((SV *)compcv, SVt_PVCV);
2185 CvUNIQUE_on(compcv);
2187 CvOWNER(compcv) = 0;
2188 New(666, CvMUTEXP(compcv), 1, perl_mutex);
2189 MUTEX_INIT(CvMUTEXP(compcv));
2190 #endif /* USE_THREADS */
2193 av_push(comppad, Nullsv);
2194 curpad = AvARRAY(comppad);
2195 comppad_name = newAV();
2196 comppad_name_fill = 0;
2197 min_intro_pending = 0;
2200 av_store(comppad_name, 0, newSVpv("@_", 2));
2201 curpad[0] = (SV*)newAV();
2202 SvPADMY_on(curpad[0]); /* XXX Needed? */
2203 #endif /* USE_THREADS */
2205 comppadlist = newAV();
2206 AvREAL_off(comppadlist);
2207 av_store(comppadlist, 0, (SV*)comppad_name);
2208 av_store(comppadlist, 1, (SV*)comppad);
2209 CvPADLIST(compcv) = comppadlist;
2211 if (!saveop || saveop->op_type != OP_REQUIRE)
2212 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc(caller);
2216 /* make sure we compile in the right package */
2218 newstash = curcop->cop_stash;
2219 if (curstash != newstash) {
2221 curstash = newstash;
2225 SAVEFREESV(beginav);
2227 /* try to compile it */
2231 curcop = &compiling;
2232 curcop->cop_arybase = 0;
2234 rs = newSVpv("\n", 1);
2235 if (saveop && saveop->op_flags & OPf_SPECIAL)
2239 if (yyparse() || error_count || !eval_root) {
2243 I32 optype = 0; /* Might be reset by POPEVAL. */
2250 SP = stack_base + POPMARK; /* pop original mark */
2258 if (optype == OP_REQUIRE) {
2259 char* msg = SvPVx(ERRSV, na);
2260 DIE("%s", *msg ? msg : "Compilation failed in require");
2261 } else if (startop) {
2262 char* msg = SvPVx(ERRSV, na);
2266 croak("%sCompilation failed in regexp", (*msg ? msg : "Unknown error\n"));
2269 rs = SvREFCNT_inc(nrs);
2271 MUTEX_LOCK(&eval_mutex);
2273 COND_SIGNAL(&eval_cond);
2274 MUTEX_UNLOCK(&eval_mutex);
2275 #endif /* USE_THREADS */
2279 rs = SvREFCNT_inc(nrs);
2280 compiling.cop_line = 0;
2282 *startop = eval_root;
2283 SvREFCNT_dec(CvOUTSIDE(compcv));
2284 CvOUTSIDE(compcv) = Nullcv;
2286 SAVEFREEOP(eval_root);
2288 scalarvoid(eval_root);
2289 else if (gimme & G_ARRAY)
2294 DEBUG_x(dump_eval());
2296 /* Register with debugger: */
2297 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2298 CV *cv = perl_get_cv("DB::postponed", FALSE);
2302 XPUSHs((SV*)compiling.cop_filegv);
2304 perl_call_sv((SV*)cv, G_DISCARD);
2308 /* compiled okay, so do it */
2310 CvDEPTH(compcv) = 1;
2311 SP = stack_base + POPMARK; /* pop original mark */
2312 op = saveop; /* The caller may need it. */
2314 MUTEX_LOCK(&eval_mutex);
2316 COND_SIGNAL(&eval_cond);
2317 MUTEX_UNLOCK(&eval_mutex);
2318 #endif /* USE_THREADS */
2320 RETURNOP(eval_start);
2326 register PERL_CONTEXT *cx;
2330 SV *namesv = Nullsv;
2332 I32 gimme = G_SCALAR;
2333 PerlIO *tryrsfp = 0;
2336 if (SvNIOKp(sv) && !SvPOKp(sv)) {
2337 SET_NUMERIC_STANDARD();
2338 if (atof(patchlevel) + 0.00000999 < SvNV(sv))
2339 DIE("Perl %s required--this is only version %s, stopped",
2340 SvPV(sv,na),patchlevel);
2343 name = SvPV(sv, na);
2345 DIE("Null filename used");
2346 TAINT_PROPER("require");
2347 if (op->op_type == OP_REQUIRE &&
2348 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
2352 /* prepare to compile file */
2357 (name[1] == '.' && name[2] == '/')))
2359 || (name[0] && name[1] == ':')
2362 || (name[0] == '\\' && name[1] == '\\') /* UNC path */
2365 || (strchr(name,':') || ((*name == '[' || *name == '<') &&
2366 (isALNUM(name[1]) || strchr("$-_]>",name[1]))))
2371 tryrsfp = PerlIO_open(name,"r");
2374 AV *ar = GvAVn(incgv);
2378 if ((unixname = tounixspec(name, Nullch)) != Nullch)
2381 namesv = NEWSV(806, 0);
2382 for (i = 0; i <= AvFILL(ar); i++) {
2383 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2386 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
2388 sv_setpv(namesv, unixdir);
2389 sv_catpv(namesv, unixname);
2391 sv_setpvf(namesv, "%s/%s", dir, name);
2393 tryname = SvPVX(namesv);
2394 tryrsfp = PerlIO_open(tryname, "r");
2396 if (tryname[0] == '.' && tryname[1] == '/')
2403 SAVESPTR(compiling.cop_filegv);
2404 compiling.cop_filegv = gv_fetchfile(tryrsfp ? tryname : name);
2405 SvREFCNT_dec(namesv);
2407 if (op->op_type == OP_REQUIRE) {
2408 SV *msg = sv_2mortal(newSVpvf("Can't locate %s in @INC", name));
2409 SV *dirmsgsv = NEWSV(0, 0);
2410 AV *ar = GvAVn(incgv);
2412 if (instr(SvPVX(msg), ".h "))
2413 sv_catpv(msg, " (change .h to .ph maybe?)");
2414 if (instr(SvPVX(msg), ".ph "))
2415 sv_catpv(msg, " (did you run h2ph?)");
2416 sv_catpv(msg, " (@INC contains:");
2417 for (i = 0; i <= AvFILL(ar); i++) {
2418 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2419 sv_setpvf(dirmsgsv, " %s", dir);
2420 sv_catsv(msg, dirmsgsv);
2422 sv_catpvn(msg, ")", 1);
2423 SvREFCNT_dec(dirmsgsv);
2430 /* Assume success here to prevent recursive requirement. */
2431 (void)hv_store(GvHVn(incgv), name, strlen(name),
2432 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2436 lex_start(sv_2mortal(newSVpv("",0)));
2438 save_aptr(&rsfp_filters);
2439 rsfp_filters = NULL;
2443 name = savepv(name);
2448 /* switch to eval mode */
2450 push_return(op->op_next);
2451 PUSHBLOCK(cx, CXt_EVAL, SP);
2452 PUSHEVAL(cx, name, compiling.cop_filegv);
2454 compiling.cop_line = 0;
2458 MUTEX_LOCK(&eval_mutex);
2459 if (eval_owner && eval_owner != thr)
2461 COND_WAIT(&eval_cond, &eval_mutex);
2463 MUTEX_UNLOCK(&eval_mutex);
2464 #endif /* USE_THREADS */
2465 return DOCATCH(doeval(G_SCALAR, NULL));
2470 return pp_require(ARGS);
2476 register PERL_CONTEXT *cx;
2478 I32 gimme = GIMME_V, was = sub_generation;
2479 char tmpbuf[TYPE_DIGITS(long) + 12];
2484 if (!SvPV(sv,len) || !len)
2486 TAINT_PROPER("eval");
2492 /* switch to eval mode */
2494 SAVESPTR(compiling.cop_filegv);
2495 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++evalseq);
2496 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2497 compiling.cop_line = 1;
2498 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2499 deleting the eval's FILEGV from the stash before gv_check() runs
2500 (i.e. before run-time proper). To work around the coredump that
2501 ensues, we always turn GvMULTI_on for any globals that were
2502 introduced within evals. See force_ident(). GSAR 96-10-12 */
2503 safestr = savepv(tmpbuf);
2504 SAVEDELETE(defstash, safestr, strlen(safestr));
2506 hints = op->op_targ;
2508 push_return(op->op_next);
2509 PUSHBLOCK(cx, CXt_EVAL, SP);
2510 PUSHEVAL(cx, 0, compiling.cop_filegv);
2512 /* prepare to compile string */
2514 if (PERLDB_LINE && curstash != debstash)
2515 save_lines(GvAV(compiling.cop_filegv), linestr);
2518 MUTEX_LOCK(&eval_mutex);
2519 if (eval_owner && eval_owner != thr)
2521 COND_WAIT(&eval_cond, &eval_mutex);
2523 MUTEX_UNLOCK(&eval_mutex);
2524 #endif /* USE_THREADS */
2525 ret = doeval(gimme, NULL);
2526 if (PERLDB_INTER && was != sub_generation /* Some subs defined here. */
2527 && ret != op->op_next) { /* Successive compilation. */
2528 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
2530 return DOCATCH(ret);
2540 register PERL_CONTEXT *cx;
2542 U8 save_flags = op -> op_flags;
2547 retop = pop_return();
2550 if (gimme == G_VOID)
2552 else if (gimme == G_SCALAR) {
2555 if (SvFLAGS(TOPs) & SVs_TEMP)
2558 *MARK = sv_mortalcopy(TOPs);
2566 /* in case LEAVE wipes old return values */
2567 for (mark = newsp + 1; mark <= SP; mark++) {
2568 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
2569 *mark = sv_mortalcopy(*mark);
2570 TAINT_NOT; /* Each item is independent */
2574 curpm = newpm; /* Don't pop $1 et al till now */
2577 * Closures mentioned at top level of eval cannot be referenced
2578 * again, and their presence indirectly causes a memory leak.
2579 * (Note that the fact that compcv and friends are still set here
2580 * is, AFAIK, an accident.) --Chip
2582 if (AvFILL(comppad_name) >= 0) {
2583 SV **svp = AvARRAY(comppad_name);
2585 for (ix = AvFILL(comppad_name); ix >= 0; ix--) {
2587 if (sv && sv != &sv_undef && *SvPVX(sv) == '&') {
2589 svp[ix] = &sv_undef;
2593 SvREFCNT_dec(CvOUTSIDE(sv));
2594 CvOUTSIDE(sv) = Nullcv;
2607 assert(CvDEPTH(compcv) == 1);
2609 CvDEPTH(compcv) = 0;
2611 if (optype == OP_REQUIRE &&
2612 !(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp))
2614 /* Unassume the success we assumed earlier. */
2615 char *name = cx->blk_eval.old_name;
2616 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2617 retop = die("%s did not return a true value", name);
2623 if (!(save_flags & OPf_SPECIAL))
2632 register PERL_CONTEXT *cx;
2633 I32 gimme = GIMME_V;
2638 push_return(cLOGOP->op_other->op_next);
2639 PUSHBLOCK(cx, CXt_EVAL, SP);
2641 eval_root = op; /* Only needed so that goto works right. */
2646 return DOCATCH(op->op_next);
2656 register PERL_CONTEXT *cx;
2664 if (gimme == G_VOID)
2666 else if (gimme == G_SCALAR) {
2669 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2672 *MARK = sv_mortalcopy(TOPs);
2681 /* in case LEAVE wipes old return values */
2682 for (mark = newsp + 1; mark <= SP; mark++) {
2683 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
2684 *mark = sv_mortalcopy(*mark);
2685 TAINT_NOT; /* Each item is independent */
2689 curpm = newpm; /* Don't pop $1 et al till now */
2700 register char *s = SvPV_force(sv, len);
2701 register char *send = s + len;
2702 register char *base;
2703 register I32 skipspaces = 0;
2706 bool postspace = FALSE;
2714 croak("Null picture in formline");
2716 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
2721 *fpc++ = FF_LINEMARK;
2722 noblank = repeat = FALSE;
2740 case ' ': case '\t':
2751 *fpc++ = FF_LITERAL;
2759 *fpc++ = skipspaces;
2763 *fpc++ = FF_NEWLINE;
2767 arg = fpc - linepc + 1;
2774 *fpc++ = FF_LINEMARK;
2775 noblank = repeat = FALSE;
2784 ischop = s[-1] == '^';
2790 arg = (s - base) - 1;
2792 *fpc++ = FF_LITERAL;
2801 *fpc++ = FF_LINEGLOB;
2803 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2804 arg = ischop ? 512 : 0;
2814 arg |= 256 + (s - f);
2816 *fpc++ = s - base; /* fieldsize for FETCH */
2817 *fpc++ = FF_DECIMAL;
2822 bool ismore = FALSE;
2825 while (*++s == '>') ;
2826 prespace = FF_SPACE;
2828 else if (*s == '|') {
2829 while (*++s == '|') ;
2830 prespace = FF_HALFSPACE;
2835 while (*++s == '<') ;
2838 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2842 *fpc++ = s - base; /* fieldsize for FETCH */
2844 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2862 { /* need to jump to the next word */
2864 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2865 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2866 s = SvPVX(sv) + SvCUR(sv) + z;
2868 Copy(fops, s, arg, U16);
2870 sv_magic(sv, Nullsv, 'f', Nullch, 0);