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 *doeval _((int gimme));
30 static OP *dofindlabel _((OP *o, char *label, OP **opstack, OP **oplimit));
31 static void doparseform _((SV *sv));
32 static I32 dopoptoeval _((I32 startingblock));
33 static I32 dopoptolabel _((char *label));
34 static I32 dopoptoloop _((I32 startingblock));
35 static I32 dopoptosub _((I32 startingblock));
36 static void save_lines _((AV *array, SV *sv));
37 static int sortcv _((const void *, const void *));
38 static int sortcmp _((const void *, const void *));
39 static int sortcmp_locale _((const void *, const void *));
49 cxix = dopoptosub(cxstack_ix);
53 switch (cxstack[cxix].blk_gimme) {
70 register PMOP *pm = (PMOP*)cLOGOP->op_other;
76 t = SvPV(tmpstr, len);
78 /* JMR: Check against the last compiled regexp */
79 if ( ! pm->op_pmregexp || ! pm->op_pmregexp->precomp
80 || strnNE(pm->op_pmregexp->precomp, t, len)
81 || pm->op_pmregexp->precomp[len]) {
82 if (pm->op_pmregexp) {
83 pregfree(pm->op_pmregexp);
84 pm->op_pmregexp = Null(REGEXP*); /* crucial if regcomp aborts */
87 pm->op_pmflags = pm->op_pmpermflags; /* reset case sensitivity */
88 pm->op_pmregexp = pregcomp(t, t + len, pm);
91 if (!pm->op_pmregexp->prelen && curpm)
93 else if (strEQ("\\s+", pm->op_pmregexp->precomp))
94 pm->op_pmflags |= PMf_WHITE;
96 if (pm->op_pmflags & PMf_KEEP) {
97 pm->op_private &= ~OPpRUNTIME; /* no point compiling again */
99 cLOGOP->op_first->op_next = op->op_next;
107 register PMOP *pm = (PMOP*) cLOGOP->op_other;
108 register CONTEXT *cx = &cxstack[cxstack_ix];
109 register SV *dstr = cx->sb_dstr;
110 register char *s = cx->sb_s;
111 register char *m = cx->sb_m;
112 char *orig = cx->sb_orig;
113 register REGEXP *rx = cx->sb_rx;
115 rxres_restore(&cx->sb_rxres, rx);
117 if (cx->sb_iters++) {
118 if (cx->sb_iters > cx->sb_maxiters)
119 DIE("Substitution loop");
121 if (!cx->sb_rxtainted)
122 cx->sb_rxtainted = SvTAINTED(TOPs);
123 sv_catsv(dstr, POPs);
126 if (cx->sb_once || !pregexec(rx, s, cx->sb_strend, orig,
127 s == m, Nullsv, cx->sb_safebase))
129 SV *targ = cx->sb_targ;
130 sv_catpvn(dstr, s, cx->sb_strend - s);
132 TAINT_IF(cx->sb_rxtainted || rx->exec_tainted);
134 (void)SvOOK_off(targ);
135 Safefree(SvPVX(targ));
136 SvPVX(targ) = SvPVX(dstr);
137 SvCUR_set(targ, SvCUR(dstr));
138 SvLEN_set(targ, SvLEN(dstr));
141 (void)SvPOK_only(targ);
145 PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
146 LEAVE_SCOPE(cx->sb_oldsave);
148 RETURNOP(pm->op_next);
151 if (rx->subbase && rx->subbase != orig) {
154 cx->sb_orig = orig = rx->subbase;
156 cx->sb_strend = s + (cx->sb_strend - m);
158 cx->sb_m = m = rx->startp[0];
159 sv_catpvn(dstr, s, m-s);
160 cx->sb_s = rx->endp[0];
161 cx->sb_rxtainted |= rx->exec_tainted;
162 rxres_save(&cx->sb_rxres, rx);
163 RETURNOP(pm->op_pmreplstart);
167 rxres_save(void **rsp, REGEXP *rx)
172 if (!p || p[1] < rx->nparens) {
173 i = 6 + rx->nparens * 2;
181 *p++ = (UV)rx->subbase;
182 rx->subbase = Nullch;
186 *p++ = (UV)rx->subbeg;
187 *p++ = (UV)rx->subend;
188 for (i = 0; i <= rx->nparens; ++i) {
189 *p++ = (UV)rx->startp[i];
190 *p++ = (UV)rx->endp[i];
195 rxres_restore(void **rsp, REGEXP *rx)
200 Safefree(rx->subbase);
201 rx->subbase = (char*)(*p);
206 rx->subbeg = (char*)(*p++);
207 rx->subend = (char*)(*p++);
208 for (i = 0; i <= rx->nparens; ++i) {
209 rx->startp[i] = (char*)(*p++);
210 rx->endp[i] = (char*)(*p++);
215 rxres_free(void **rsp)
220 Safefree((char*)(*p));
228 dSP; dMARK; dORIGMARK;
229 register SV *form = *++MARK;
241 bool chopspace = (strchr(chopset, ' ') != Nullch);
248 if (!SvMAGICAL(form) || !SvCOMPILED(form)) {
249 SvREADONLY_off(form);
253 SvPV_force(formtarget, len);
254 t = SvGROW(formtarget, len + SvCUR(form) + 1); /* XXX SvCUR bad */
257 /* need to jump to the next word */
258 s = f + len + WORD_ALIGN - SvCUR(form) % WORD_ALIGN;
267 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
268 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
269 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
270 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
271 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
273 case FF_CHECKNL: name = "CHECKNL"; break;
274 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
275 case FF_SPACE: name = "SPACE"; break;
276 case FF_HALFSPACE: name = "HALFSPACE"; break;
277 case FF_ITEM: name = "ITEM"; break;
278 case FF_CHOP: name = "CHOP"; break;
279 case FF_LINEGLOB: name = "LINEGLOB"; break;
280 case FF_NEWLINE: name = "NEWLINE"; break;
281 case FF_MORE: name = "MORE"; break;
282 case FF_LINEMARK: name = "LINEMARK"; break;
283 case FF_END: name = "END"; break;
286 PerlIO_printf(PerlIO_stderr(), "%-16s%ld\n", name, (long) arg);
288 PerlIO_printf(PerlIO_stderr(), "%-16s\n", name);
317 warn("Not enough format arguments");
322 item = s = SvPV(sv, len);
324 if (itemsize > fieldsize)
325 itemsize = fieldsize;
326 send = chophere = s + itemsize;
338 item = s = SvPV(sv, len);
340 if (itemsize <= fieldsize) {
341 send = chophere = s + itemsize;
352 itemsize = fieldsize;
353 send = chophere = s + itemsize;
354 while (s < send || (s == send && isSPACE(*s))) {
364 if (strchr(chopset, *s))
369 itemsize = chophere - item;
374 arg = fieldsize - itemsize;
383 arg = fieldsize - itemsize;
397 int ch = *t++ = *s++;
401 if ( !((*t++ = *s++) & ~31) )
411 while (*s && isSPACE(*s))
418 item = s = SvPV(sv, len);
431 SvCUR_set(formtarget, t - SvPVX(formtarget));
432 sv_catpvn(formtarget, item, itemsize);
433 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(form) + 1);
434 t = SvPVX(formtarget) + SvCUR(formtarget);
439 /* If the field is marked with ^ and the value is undefined,
442 if ((arg & 512) && !SvOK(sv)) {
450 /* Formats aren't yet marked for locales, so assume "yes". */
453 sprintf(t, "%#*.*f", (int) fieldsize, (int) arg & 255, value);
455 sprintf(t, "%*.0f", (int) fieldsize, value);
462 while (t-- > linemark && *t == ' ') ;
470 if (arg) { /* repeat until fields exhausted? */
472 SvCUR_set(formtarget, t - SvPVX(formtarget));
473 lines += FmLINES(formtarget);
476 if (strnEQ(linemark, linemark - arg, arg))
477 DIE("Runaway format");
479 FmLINES(formtarget) = lines;
481 RETURNOP(cLISTOP->op_first);
492 arg = fieldsize - itemsize;
499 if (strnEQ(s," ",3)) {
500 while (s > SvPVX(formtarget) && isSPACE(s[-1]))
511 SvCUR_set(formtarget, t - SvPVX(formtarget));
512 FmLINES(formtarget) += lines;
524 if (stack_base + *markstack_ptr == sp) {
526 if (GIMME_V == G_SCALAR)
528 RETURNOP(op->op_next->op_next);
530 stack_sp = stack_base + *markstack_ptr + 1;
531 pp_pushmark(ARGS); /* push dst */
532 pp_pushmark(ARGS); /* push src */
533 ENTER; /* enter outer scope */
536 SAVESPTR(GvSV(defgv));
538 ENTER; /* enter inner scope */
541 src = stack_base[*markstack_ptr];
546 if (op->op_type == OP_MAPSTART)
547 pp_pushmark(ARGS); /* push top */
548 return ((LOGOP*)op->op_next)->op_other;
553 DIE("panic: mapstart"); /* uses grepstart */
559 I32 diff = (sp - stack_base) - *markstack_ptr;
567 if (diff > markstack_ptr[-1] - markstack_ptr[-2]) {
568 shift = diff - (markstack_ptr[-1] - markstack_ptr[-2]);
569 count = (sp - stack_base) - markstack_ptr[-1] + 2;
574 markstack_ptr[-1] += shift;
575 *markstack_ptr += shift;
579 dst = stack_base + (markstack_ptr[-2] += diff) - 1;
582 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
584 LEAVE; /* exit inner scope */
587 if (markstack_ptr[-1] > *markstack_ptr) {
591 (void)POPMARK; /* pop top */
592 LEAVE; /* exit outer scope */
593 (void)POPMARK; /* pop src */
594 items = --*markstack_ptr - markstack_ptr[-1];
595 (void)POPMARK; /* pop dst */
596 SP = stack_base + POPMARK; /* pop original mark */
597 if (gimme == G_SCALAR) {
601 else if (gimme == G_ARRAY)
608 ENTER; /* enter inner scope */
611 src = stack_base[markstack_ptr[-1]];
615 RETURNOP(cLOGOP->op_other);
622 dSP; dMARK; dORIGMARK;
624 SV **myorigmark = ORIGMARK;
630 OP* nextop = op->op_next;
632 if (gimme != G_ARRAY) {
637 if (op->op_flags & OPf_STACKED) {
639 if (op->op_flags & OPf_SPECIAL) {
640 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
641 kid = kUNOP->op_first; /* pass rv2gv */
642 kid = kUNOP->op_first; /* pass leave */
643 sortcop = kid->op_next;
644 stash = curcop->cop_stash;
647 cv = sv_2cv(*++MARK, &stash, &gv, 0);
648 if (!(cv && CvROOT(cv))) {
650 SV *tmpstr = sv_newmortal();
651 gv_efullname3(tmpstr, gv, Nullch);
652 if (cv && CvXSUB(cv))
653 DIE("Xsub \"%s\" called in sort", SvPVX(tmpstr));
654 DIE("Undefined sort subroutine \"%s\" called",
659 DIE("Xsub called in sort");
660 DIE("Undefined subroutine in sort");
662 DIE("Not a CODE reference in sort");
664 sortcop = CvSTART(cv);
665 SAVESPTR(CvROOT(cv)->op_ppaddr);
666 CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
669 curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
674 stash = curcop->cop_stash;
678 while (MARK < SP) { /* This may or may not shift down one here. */
680 if (*up = *++MARK) { /* Weed out nulls. */
682 if (!sortcop && !SvPOK(*up))
683 (void)sv_2pv(*up, &na);
687 max = --up - myorigmark;
693 bool oldcatch = CATCH_GET;
701 AvREAL_off(sortstack);
702 av_extend(sortstack, 32);
705 SWITCHSTACK(curstack, sortstack);
706 if (sortstash != stash) {
707 firstgv = gv_fetchpv("a", TRUE, SVt_PV);
708 secondgv = gv_fetchpv("b", TRUE, SVt_PV);
712 SAVESPTR(GvSV(firstgv));
713 SAVESPTR(GvSV(secondgv));
715 PUSHBLOCK(cx, CXt_NULL, stack_base);
716 if (!(op->op_flags & OPf_SPECIAL)) {
717 bool hasargs = FALSE;
718 cx->cx_type = CXt_SUB;
719 cx->blk_gimme = G_SCALAR;
722 (void)SvREFCNT_inc(cv); /* in preparation for POPSUB */
724 sortcxix = cxstack_ix;
726 qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
729 SWITCHSTACK(sortstack, oldstack);
736 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
737 qsort((char*)(ORIGMARK+1), max, sizeof(SV*),
738 (op->op_private & OPpLOCALE) ? sortcmp_locale : sortcmp);
741 stack_sp = ORIGMARK + max;
749 if (GIMME == G_ARRAY)
750 return cCONDOP->op_true;
751 return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
758 if (GIMME == G_ARRAY) {
759 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
763 SV *targ = PAD_SV(op->op_targ);
765 if ((op->op_private & OPpFLIP_LINENUM)
766 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
768 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
769 if (op->op_flags & OPf_SPECIAL) {
777 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
790 if (GIMME == G_ARRAY) {
796 if (SvNIOKp(left) || !SvPOKp(left) ||
797 (looks_like_number(left) && *SvPVX(left) != '0') )
802 EXTEND_MORTAL(max - i + 1);
803 EXTEND(SP, max - i + 1);
806 sv = sv_2mortal(newSViv(i++));
811 SV *final = sv_mortalcopy(right);
813 char *tmps = SvPV(final, len);
815 sv = sv_mortalcopy(left);
816 while (!SvNIOKp(sv) && SvCUR(sv) <= len &&
817 strNE(SvPVX(sv),tmps) ) {
819 sv = sv_2mortal(newSVsv(sv));
822 if (strEQ(SvPVX(sv),tmps))
828 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
830 if ((op->op_private & OPpFLIP_LINENUM)
831 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
833 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
834 sv_catpv(targ, "E0");
845 dopoptolabel(char *label)
849 register CONTEXT *cx;
851 for (i = cxstack_ix; i >= 0; i--) {
853 switch (cx->cx_type) {
856 warn("Exiting substitution via %s", op_name[op->op_type]);
860 warn("Exiting subroutine via %s", op_name[op->op_type]);
864 warn("Exiting eval via %s", op_name[op->op_type]);
868 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
871 if (!cx->blk_loop.label ||
872 strNE(label, cx->blk_loop.label) ) {
873 DEBUG_l(deb("(Skipping label #%ld %s)\n",
874 (long)i, cx->blk_loop.label));
877 DEBUG_l( deb("(Found label #%ld %s)\n", (long)i, label));
887 I32 gimme = block_gimme();
888 return (gimme == G_VOID) ? G_SCALAR : gimme;
897 cxix = dopoptosub(cxstack_ix);
901 switch (cxstack[cxix].blk_gimme) {
909 croak("panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
914 dopoptosub(I32 startingblock)
918 register CONTEXT *cx;
919 for (i = startingblock; i >= 0; i--) {
921 switch (cx->cx_type) {
926 DEBUG_l( deb("(Found sub #%ld)\n", (long)i));
934 dopoptoeval(I32 startingblock)
938 register CONTEXT *cx;
939 for (i = startingblock; i >= 0; i--) {
941 switch (cx->cx_type) {
945 DEBUG_l( deb("(Found eval #%ld)\n", (long)i));
953 dopoptoloop(I32 startingblock)
957 register CONTEXT *cx;
958 for (i = startingblock; i >= 0; i--) {
960 switch (cx->cx_type) {
963 warn("Exiting substitution via %s", op_name[op->op_type]);
967 warn("Exiting subroutine via %s", op_name[op->op_type]);
971 warn("Exiting eval via %s", op_name[op->op_type]);
975 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
978 DEBUG_l( deb("(Found loop #%ld)\n", (long)i));
989 register CONTEXT *cx;
993 while (cxstack_ix > cxix) {
994 cx = &cxstack[cxstack_ix];
995 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n",
996 (long) cxstack_ix+1, block_type[cx->cx_type]));
997 /* Note: we don't need to restore the base context info till the end. */
998 switch (cx->cx_type) {
1001 continue; /* not break */
1019 die_where(char *message)
1024 register CONTEXT *cx;
1030 STRLEN klen = strlen(message);
1032 svp = hv_fetch(GvHV(errgv), message, klen, TRUE);
1035 static char prefix[] = "\t(in cleanup) ";
1036 sv_upgrade(*svp, SVt_IV);
1037 (void)SvIOK_only(*svp);
1038 SvGROW(GvSV(errgv), SvCUR(GvSV(errgv))+sizeof(prefix)+klen);
1039 sv_catpvn(GvSV(errgv), prefix, sizeof(prefix)-1);
1040 sv_catpvn(GvSV(errgv), message, klen);
1046 sv_setpv(GvSV(errgv), message);
1048 cxix = dopoptoeval(cxstack_ix);
1052 if (cxix < cxstack_ix)
1056 if (cx->cx_type != CXt_EVAL) {
1057 PerlIO_printf(PerlIO_stderr(), "panic: die %s", message);
1062 if (gimme == G_SCALAR)
1063 *++newsp = &sv_undef;
1068 if (optype == OP_REQUIRE) {
1069 char* msg = SvPVx(GvSV(errgv), na);
1070 DIE("%s", *msg ? msg : "Compilation failed in require");
1072 return pop_return();
1075 PerlIO_printf(PerlIO_stderr(), "%s",message);
1076 PerlIO_flush(PerlIO_stderr());
1085 if (SvTRUE(left) != SvTRUE(right))
1097 RETURNOP(cLOGOP->op_other);
1106 RETURNOP(cLOGOP->op_other);
1113 SV** mark = (stack_base + *markstack_ptr + 1);
1115 while (mark < sp) { /* emulate old interface */
1120 return pp_entersub(ARGS);
1127 register I32 cxix = dopoptosub(cxstack_ix);
1128 register CONTEXT *cx;
1139 if (GIMME != G_ARRAY)
1143 if (DBsub && cxix >= 0 &&
1144 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1148 cxix = dopoptosub(cxix - 1);
1150 cx = &cxstack[cxix];
1151 if (cxstack[cxix].cx_type == CXt_SUB) {
1152 dbcxix = dopoptosub(cxix - 1);
1153 /* We expect that cxstack[dbcxix] is CXt_SUB, anyway, the
1154 field below is defined for any cx. */
1155 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1156 cx = &cxstack[dbcxix];
1159 if (GIMME != G_ARRAY) {
1162 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1167 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1168 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1169 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1172 if (cx->cx_type == CXt_SUB) { /* So is cxstack[dbcxix]. */
1174 gv_efullname3(sv, CvGV(cxstack[cxix].blk_sub.cv), Nullch);
1175 PUSHs(sv_2mortal(sv));
1176 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1179 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1180 PUSHs(sv_2mortal(newSViv(0)));
1182 gimme = (I32)cx->blk_gimme;
1183 if (gimme == G_VOID)
1186 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1187 if (cx->cx_type == CXt_EVAL) {
1188 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1189 PUSHs(cx->blk_eval.cur_text);
1192 else if (cx->blk_eval.old_name) { /* Try blocks have old_name == 0. */
1193 /* Require, put the name. */
1194 PUSHs(sv_2mortal(newSVpv(cx->blk_eval.old_name, 0)));
1198 else if (cx->cx_type == CXt_SUB &&
1199 cx->blk_sub.hasargs &&
1200 curcop->cop_stash == debstash)
1202 AV *ary = cx->blk_sub.argarray;
1203 int off = AvARRAY(ary) - AvALLOC(ary);
1207 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1210 AvREAL_off(dbargs); /* XXX Should be REIFY */
1213 if (AvMAX(dbargs) < AvFILL(ary) + off)
1214 av_extend(dbargs, AvFILL(ary) + off);
1215 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1216 AvFILL(dbargs) = AvFILL(ary) + off;
1222 sortcv(const void *a, const void *b)
1225 SV * const *str1 = (SV * const *)a;
1226 SV * const *str2 = (SV * const *)b;
1227 I32 oldsaveix = savestack_ix;
1228 I32 oldscopeix = scopestack_ix;
1230 GvSV(firstgv) = *str1;
1231 GvSV(secondgv) = *str2;
1232 stack_sp = stack_base;
1235 if (stack_sp != stack_base + 1)
1236 croak("Sort subroutine didn't return single value");
1237 if (!SvNIOKp(*stack_sp))
1238 croak("Sort subroutine didn't return a numeric value");
1239 result = SvIV(*stack_sp);
1240 while (scopestack_ix > oldscopeix) {
1243 leave_scope(oldsaveix);
1248 sortcmp(const void *a, const void *b)
1250 return sv_cmp(*(SV * const *)a, *(SV * const *)b);
1254 sortcmp_locale(const void *a, const void *b)
1256 return sv_cmp_locale(*(SV * const *)a, *(SV * const *)b);
1268 sv_reset(tmps, curcop->cop_stash);
1281 TAINT_NOT; /* Each statement is presumed innocent */
1282 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1285 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1289 register CONTEXT *cx;
1290 I32 gimme = G_ARRAY;
1297 DIE("No DB::DB routine defined");
1299 if (CvDEPTH(cv) >= 1 && !(debug & (1<<30))) /* don't do recursive DB::DB call */
1311 push_return(op->op_next);
1312 PUSHBLOCK(cx, CXt_SUB, sp);
1315 (void)SvREFCNT_inc(cv);
1317 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1318 RETURNOP(CvSTART(cv));
1332 register CONTEXT *cx;
1333 I32 gimme = GIMME_V;
1340 svp = &curpad[op->op_targ]; /* "my" variable */
1342 svp = &GvSV((GV*)POPs); /* symbol table variable */
1348 PUSHBLOCK(cx, CXt_LOOP, SP);
1349 PUSHLOOP(cx, svp, MARK);
1350 if (op->op_flags & OPf_STACKED)
1351 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1353 cx->blk_loop.iterary = curstack;
1354 AvFILL(curstack) = sp - stack_base;
1355 cx->blk_loop.iterix = MARK - stack_base;
1364 register CONTEXT *cx;
1365 I32 gimme = GIMME_V;
1371 PUSHBLOCK(cx, CXt_LOOP, SP);
1372 PUSHLOOP(cx, 0, SP);
1380 register CONTEXT *cx;
1381 struct block_loop cxloop;
1389 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1392 if (gimme == G_VOID)
1394 else if (gimme == G_SCALAR) {
1396 *++newsp = sv_mortalcopy(*SP);
1398 *++newsp = &sv_undef;
1402 *++newsp = sv_mortalcopy(*++mark);
1403 TAINT_NOT; /* Each item is independent */
1409 POPLOOP2(); /* Stack values are safe: release loop vars ... */
1410 curpm = newpm; /* ... and pop $1 et al */
1422 register CONTEXT *cx;
1423 struct block_sub cxsub;
1424 bool popsub2 = FALSE;
1430 if (curstack == sortstack) {
1431 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) <= sortcxix) {
1432 if (cxstack_ix > sortcxix)
1434 AvARRAY(curstack)[1] = *SP;
1435 stack_sp = stack_base + 1;
1440 cxix = dopoptosub(cxstack_ix);
1442 DIE("Can't return outside a subroutine");
1443 if (cxix < cxstack_ix)
1447 switch (cx->cx_type) {
1449 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1454 if (optype == OP_REQUIRE &&
1455 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1457 /* Unassume the success we assumed earlier. */
1458 char *name = cx->blk_eval.old_name;
1459 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1460 DIE("%s did not return a true value", name);
1464 DIE("panic: return");
1468 if (gimme == G_SCALAR) {
1470 *++newsp = (popsub2 && SvTEMP(*SP))
1471 ? *SP : sv_mortalcopy(*SP);
1473 *++newsp = &sv_undef;
1475 else if (gimme == G_ARRAY) {
1476 while (++MARK <= SP) {
1477 *++newsp = (popsub2 && SvTEMP(*MARK))
1478 ? *MARK : sv_mortalcopy(*MARK);
1479 TAINT_NOT; /* Each item is independent */
1484 /* Stack values are safe: */
1486 POPSUB2(); /* release CV and @_ ... */
1488 curpm = newpm; /* ... and pop $1 et al */
1491 return pop_return();
1498 register CONTEXT *cx;
1499 struct block_loop cxloop;
1500 struct block_sub cxsub;
1507 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1509 if (op->op_flags & OPf_SPECIAL) {
1510 cxix = dopoptoloop(cxstack_ix);
1512 DIE("Can't \"last\" outside a block");
1515 cxix = dopoptolabel(cPVOP->op_pv);
1517 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1519 if (cxix < cxstack_ix)
1523 switch (cx->cx_type) {
1525 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1527 nextop = cxloop.last_op->op_next;
1530 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1532 nextop = pop_return();
1536 nextop = pop_return();
1543 if (gimme == G_SCALAR) {
1545 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
1546 ? *SP : sv_mortalcopy(*SP);
1548 *++newsp = &sv_undef;
1550 else if (gimme == G_ARRAY) {
1551 while (++MARK <= SP) {
1552 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
1553 ? *MARK : sv_mortalcopy(*MARK);
1554 TAINT_NOT; /* Each item is independent */
1560 /* Stack values are safe: */
1563 POPLOOP2(); /* release loop vars ... */
1567 POPSUB2(); /* release CV and @_ ... */
1570 curpm = newpm; /* ... and pop $1 et al */
1579 register CONTEXT *cx;
1582 if (op->op_flags & OPf_SPECIAL) {
1583 cxix = dopoptoloop(cxstack_ix);
1585 DIE("Can't \"next\" outside a block");
1588 cxix = dopoptolabel(cPVOP->op_pv);
1590 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1592 if (cxix < cxstack_ix)
1596 oldsave = scopestack[scopestack_ix - 1];
1597 LEAVE_SCOPE(oldsave);
1598 return cx->blk_loop.next_op;
1604 register CONTEXT *cx;
1607 if (op->op_flags & OPf_SPECIAL) {
1608 cxix = dopoptoloop(cxstack_ix);
1610 DIE("Can't \"redo\" outside a block");
1613 cxix = dopoptolabel(cPVOP->op_pv);
1615 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1617 if (cxix < cxstack_ix)
1621 oldsave = scopestack[scopestack_ix - 1];
1622 LEAVE_SCOPE(oldsave);
1623 return cx->blk_loop.redo_op;
1626 static OP* lastgotoprobe;
1629 dofindlabel(OP *o, char *label, OP **opstack, OP **oplimit)
1633 static char too_deep[] = "Target of goto is too deeply nested";
1637 if (o->op_type == OP_LEAVE ||
1638 o->op_type == OP_SCOPE ||
1639 o->op_type == OP_LEAVELOOP ||
1640 o->op_type == OP_LEAVETRY)
1642 *ops++ = cUNOPo->op_first;
1647 if (o->op_flags & OPf_KIDS) {
1648 /* First try all the kids at this level, since that's likeliest. */
1649 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1650 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1651 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1654 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1655 if (kid == lastgotoprobe)
1657 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1659 (ops[-1]->op_type != OP_NEXTSTATE &&
1660 ops[-1]->op_type != OP_DBSTATE)))
1662 if (o = dofindlabel(kid, label, ops, oplimit))
1672 return pp_goto(ARGS);
1681 register CONTEXT *cx;
1682 #define GOTO_DEPTH 64
1683 OP *enterops[GOTO_DEPTH];
1685 int do_dump = (op->op_type == OP_DUMP);
1688 if (op->op_flags & OPf_STACKED) {
1691 /* This egregious kludge implements goto &subroutine */
1692 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1694 register CONTEXT *cx;
1695 CV* cv = (CV*)SvRV(sv);
1700 if (!CvROOT(cv) && !CvXSUB(cv)) {
1702 SV *tmpstr = sv_newmortal();
1703 gv_efullname3(tmpstr, CvGV(cv), Nullch);
1704 DIE("Goto undefined subroutine &%s",SvPVX(tmpstr));
1706 DIE("Goto undefined subroutine");
1709 /* First do some returnish stuff. */
1710 cxix = dopoptosub(cxstack_ix);
1712 DIE("Can't goto subroutine outside a subroutine");
1713 if (cxix < cxstack_ix)
1717 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1718 AV* av = cx->blk_sub.argarray;
1720 items = AvFILL(av) + 1;
1722 EXTEND(stack_sp, items); /* @_ could have been extended. */
1723 Copy(AvARRAY(av), stack_sp, items, SV*);
1726 SvREFCNT_dec(GvAV(defgv));
1727 GvAV(defgv) = cx->blk_sub.savearray;
1728 #endif /* USE_THREADS */
1732 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1733 SvREFCNT_dec(cx->blk_sub.cv);
1734 oldsave = scopestack[scopestack_ix - 1];
1735 LEAVE_SCOPE(oldsave);
1737 /* Now do some callish stuff. */
1740 if (CvOLDSTYLE(cv)) {
1741 I32 (*fp3)_((int,int,int));
1746 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1747 items = (*fp3)(CvXSUBANY(cv).any_i32,
1748 mark - stack_base + 1,
1750 sp = stack_base + items;
1753 stack_sp--; /* There is no cv arg. */
1754 (void)(*CvXSUB(cv))(cv);
1757 return pop_return();
1760 AV* padlist = CvPADLIST(cv);
1761 SV** svp = AvARRAY(padlist);
1762 cx->blk_sub.cv = cv;
1763 cx->blk_sub.olddepth = CvDEPTH(cv);
1765 if (CvDEPTH(cv) < 2)
1766 (void)SvREFCNT_inc(cv);
1767 else { /* save temporaries on recursion? */
1768 if (CvDEPTH(cv) == 100 && dowarn)
1769 sub_crush_depth(cv);
1770 if (CvDEPTH(cv) > AvFILL(padlist)) {
1771 AV *newpad = newAV();
1772 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
1773 I32 ix = AvFILL((AV*)svp[1]);
1774 svp = AvARRAY(svp[0]);
1775 for ( ;ix > 0; ix--) {
1776 if (svp[ix] != &sv_undef) {
1777 char *name = SvPVX(svp[ix]);
1778 if ((SvFLAGS(svp[ix]) & SVf_FAKE)
1781 /* outer lexical or anon code */
1782 av_store(newpad, ix,
1783 SvREFCNT_inc(oldpad[ix]) );
1785 else { /* our own lexical */
1787 av_store(newpad, ix, sv = (SV*)newAV());
1788 else if (*name == '%')
1789 av_store(newpad, ix, sv = (SV*)newHV());
1791 av_store(newpad, ix, sv = NEWSV(0,0));
1796 av_store(newpad, ix, sv = NEWSV(0,0));
1800 if (cx->blk_sub.hasargs) {
1803 av_store(newpad, 0, (SV*)av);
1804 AvFLAGS(av) = AVf_REIFY;
1806 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1807 AvFILL(padlist) = CvDEPTH(cv);
1808 svp = AvARRAY(padlist);
1812 if (!cx->blk_sub.hasargs) {
1813 AV* av = (AV*)curpad[0];
1815 items = AvFILL(av) + 1;
1817 /* Mark is at the end of the stack. */
1819 Copy(AvARRAY(av), sp + 1, items, SV*);
1824 #endif /* USE_THREADS */
1826 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1828 if (cx->blk_sub.hasargs)
1829 #endif /* USE_THREADS */
1831 AV* av = (AV*)curpad[0];
1835 cx->blk_sub.savearray = GvAV(defgv);
1836 GvAV(defgv) = (AV*)SvREFCNT_inc(av);
1837 #endif /* USE_THREADS */
1838 cx->blk_sub.argarray = av;
1841 if (items >= AvMAX(av) + 1) {
1843 if (AvARRAY(av) != ary) {
1844 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1845 SvPVX(av) = (char*)ary;
1847 if (items >= AvMAX(av) + 1) {
1848 AvMAX(av) = items - 1;
1849 Renew(ary,items+1,SV*);
1851 SvPVX(av) = (char*)ary;
1854 Copy(mark,AvARRAY(av),items,SV*);
1855 AvFILL(av) = items - 1;
1863 if (PERLDB_SUB && curstash != debstash) {
1865 * We do not care about using sv to call CV;
1866 * it's for informational purposes only.
1868 SV *sv = GvSV(DBsub);
1870 gv_efullname3(sv, CvGV(cv), Nullch);
1872 RETURNOP(CvSTART(cv));
1876 label = SvPV(sv,na);
1878 else if (op->op_flags & OPf_SPECIAL) {
1880 DIE("goto must have label");
1883 label = cPVOP->op_pv;
1885 if (label && *label) {
1892 for (ix = cxstack_ix; ix >= 0; ix--) {
1894 switch (cx->cx_type) {
1896 gotoprobe = eval_root; /* XXX not good for nested eval */
1899 gotoprobe = cx->blk_oldcop->op_sibling;
1905 gotoprobe = cx->blk_oldcop->op_sibling;
1907 gotoprobe = main_root;
1910 if (CvDEPTH(cx->blk_sub.cv)) {
1911 gotoprobe = CvROOT(cx->blk_sub.cv);
1916 DIE("Can't \"goto\" outside a block");
1920 gotoprobe = main_root;
1923 retop = dofindlabel(gotoprobe, label,
1924 enterops, enterops + GOTO_DEPTH);
1927 lastgotoprobe = gotoprobe;
1930 DIE("Can't find label %s", label);
1932 /* pop unwanted frames */
1934 if (ix < cxstack_ix) {
1941 oldsave = scopestack[scopestack_ix];
1942 LEAVE_SCOPE(oldsave);
1945 /* push wanted frames */
1947 if (*enterops && enterops[1]) {
1949 for (ix = 1; enterops[ix]; ix++) {
1951 /* Eventually we may want to stack the needed arguments
1952 * for each op. For now, we punt on the hard ones. */
1953 if (op->op_type == OP_ENTERITER)
1954 DIE("Can't \"goto\" into the middle of a foreach loop",
1956 (*op->op_ppaddr)(ARGS);
1964 if (!retop) retop = main_start;
1971 restartop = 0; /* hmm, must be GNU unexec().. */
1975 if (curstack == signalstack) {
1993 if (anum == 1 && VMSISH_EXIT)
2006 double value = SvNVx(GvSV(cCOP->cop_gv));
2007 register I32 match = I_32(value);
2010 if (((double)match) > value)
2011 --match; /* was fractional--truncate other way */
2013 match -= cCOP->uop.scop.scop_offset;
2016 else if (match > cCOP->uop.scop.scop_max)
2017 match = cCOP->uop.scop.scop_max;
2018 op = cCOP->uop.scop.scop_next[match];
2028 op = op->op_next; /* can't assume anything */
2030 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
2031 match -= cCOP->uop.scop.scop_offset;
2034 else if (match > cCOP->uop.scop.scop_max)
2035 match = cCOP->uop.scop.scop_max;
2036 op = cCOP->uop.scop.scop_next[match];
2045 save_lines(AV *array, SV *sv)
2047 register char *s = SvPVX(sv);
2048 register char *send = SvPVX(sv) + SvCUR(sv);
2050 register I32 line = 1;
2052 while (s && s < send) {
2053 SV *tmpstr = NEWSV(85,0);
2055 sv_upgrade(tmpstr, SVt_PVMG);
2056 t = strchr(s, '\n');
2062 sv_setpvn(tmpstr, s, t - s);
2063 av_store(array, line++, tmpstr);
2073 I32 oldrunlevel = runlevel;
2079 assert(CATCH_GET == TRUE);
2080 DEBUG_l(deb("(Setting up local jumplevel, runlevel = %ld)\n", (long)runlevel+1));
2084 default: /* topmost level handles it */
2086 runlevel = oldrunlevel;
2092 PerlIO_printf(PerlIO_stderr(), "panic: restartop\n");
2103 runlevel = oldrunlevel;
2108 /* With USE_THREADS, eval_owner must be held on entry to doeval */
2123 /* set up a scratch pad */
2128 SAVESPTR(comppad_name);
2129 SAVEI32(comppad_name_fill);
2130 SAVEI32(min_intro_pending);
2131 SAVEI32(max_intro_pending);
2135 compcv = (CV*)NEWSV(1104,0);
2136 sv_upgrade((SV *)compcv, SVt_PVCV);
2137 CvUNIQUE_on(compcv);
2139 CvOWNER(compcv) = 0;
2140 New(666, CvMUTEXP(compcv), 1, perl_mutex);
2141 MUTEX_INIT(CvMUTEXP(compcv));
2142 #endif /* USE_THREADS */
2145 av_push(comppad, Nullsv);
2146 curpad = AvARRAY(comppad);
2147 comppad_name = newAV();
2148 comppad_name_fill = 0;
2149 min_intro_pending = 0;
2152 av_store(comppad_name, 0, newSVpv("@_", 2));
2153 curpad[0] = (SV*)newAV();
2154 SvPADMY_on(curpad[0]); /* XXX Needed? */
2155 #endif /* USE_THREADS */
2157 comppadlist = newAV();
2158 AvREAL_off(comppadlist);
2159 av_store(comppadlist, 0, (SV*)comppad_name);
2160 av_store(comppadlist, 1, (SV*)comppad);
2161 CvPADLIST(compcv) = comppadlist;
2163 if (saveop->op_type != OP_REQUIRE)
2164 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc(caller);
2168 /* make sure we compile in the right package */
2170 newstash = curcop->cop_stash;
2171 if (curstash != newstash) {
2173 curstash = newstash;
2177 SAVEFREESV(beginav);
2179 /* try to compile it */
2183 curcop = &compiling;
2184 curcop->cop_arybase = 0;
2186 rs = newSVpv("\n", 1);
2187 if (saveop->op_flags & OPf_SPECIAL)
2190 sv_setpv(GvSV(errgv),"");
2191 if (yyparse() || error_count || !eval_root) {
2202 SP = stack_base + POPMARK; /* pop original mark */
2208 if (optype == OP_REQUIRE) {
2209 char* msg = SvPVx(GvSV(errgv), na);
2210 DIE("%s", *msg ? msg : "Compilation failed in require");
2213 rs = SvREFCNT_inc(nrs);
2215 MUTEX_LOCK(&eval_mutex);
2217 COND_SIGNAL(&eval_cond);
2218 MUTEX_UNLOCK(&eval_mutex);
2219 #endif /* USE_THREADS */
2223 rs = SvREFCNT_inc(nrs);
2224 compiling.cop_line = 0;
2225 SAVEFREEOP(eval_root);
2227 scalarvoid(eval_root);
2228 else if (gimme & G_ARRAY)
2233 DEBUG_x(dump_eval());
2235 /* Register with debugger: */
2236 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2237 CV *cv = perl_get_cv("DB::postponed", FALSE);
2241 XPUSHs((SV*)compiling.cop_filegv);
2243 perl_call_sv((SV*)cv, G_DISCARD);
2247 /* compiled okay, so do it */
2249 CvDEPTH(compcv) = 1;
2250 SP = stack_base + POPMARK; /* pop original mark */
2251 op = saveop; /* The caller may need it. */
2253 MUTEX_LOCK(&eval_mutex);
2255 COND_SIGNAL(&eval_cond);
2256 MUTEX_UNLOCK(&eval_mutex);
2257 #endif /* USE_THREADS */
2259 RETURNOP(eval_start);
2265 register CONTEXT *cx;
2269 SV *namesv = Nullsv;
2271 I32 gimme = G_SCALAR;
2272 PerlIO *tryrsfp = 0;
2275 if (SvNIOKp(sv) && !SvPOKp(sv)) {
2276 SET_NUMERIC_STANDARD();
2277 if (atof(patchlevel) + 0.00000999 < SvNV(sv))
2278 DIE("Perl %s required--this is only version %s, stopped",
2279 SvPV(sv,na),patchlevel);
2282 name = SvPV(sv, na);
2284 DIE("Null filename used");
2285 TAINT_PROPER("require");
2286 if (op->op_type == OP_REQUIRE &&
2287 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
2291 /* prepare to compile file */
2296 (name[1] == '.' && name[2] == '/')))
2298 || (name[0] && name[1] == ':')
2301 || (name[0] == '\\' && name[1] == '\\') /* UNC path */
2304 || (strchr(name,':') || ((*name == '[' || *name == '<') &&
2305 (isALNUM(name[1]) || strchr("$-_]>",name[1]))))
2310 tryrsfp = PerlIO_open(name,"r");
2313 AV *ar = GvAVn(incgv);
2317 if ((unixname = tounixspec(name, Nullch)) != Nullch)
2320 namesv = NEWSV(806, 0);
2321 for (i = 0; i <= AvFILL(ar); i++) {
2322 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2325 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
2327 sv_setpv(namesv, unixdir);
2328 sv_catpv(namesv, unixname);
2330 sv_setpvf(namesv, "%s/%s", dir, name);
2332 tryname = SvPVX(namesv);
2333 tryrsfp = PerlIO_open(tryname, "r");
2335 if (tryname[0] == '.' && tryname[1] == '/')
2342 SAVESPTR(compiling.cop_filegv);
2343 compiling.cop_filegv = gv_fetchfile(tryrsfp ? tryname : name);
2344 SvREFCNT_dec(namesv);
2346 if (op->op_type == OP_REQUIRE) {
2347 SV *msg = sv_2mortal(newSVpvf("Can't locate %s in @INC", name));
2348 SV *dirmsgsv = NEWSV(0, 0);
2349 AV *ar = GvAVn(incgv);
2351 if (instr(SvPVX(msg), ".h "))
2352 sv_catpv(msg, " (change .h to .ph maybe?)");
2353 if (instr(SvPVX(msg), ".ph "))
2354 sv_catpv(msg, " (did you run h2ph?)");
2355 sv_catpv(msg, " (@INC contains:");
2356 for (i = 0; i <= AvFILL(ar); i++) {
2357 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2358 sv_setpvf(dirmsgsv, " %s", dir);
2359 sv_catsv(msg, dirmsgsv);
2361 sv_catpvn(msg, ")", 1);
2362 SvREFCNT_dec(dirmsgsv);
2369 /* Assume success here to prevent recursive requirement. */
2370 (void)hv_store(GvHVn(incgv), name, strlen(name),
2371 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2375 lex_start(sv_2mortal(newSVpv("",0)));
2377 save_aptr(&rsfp_filters);
2378 rsfp_filters = NULL;
2382 name = savepv(name);
2387 /* switch to eval mode */
2389 push_return(op->op_next);
2390 PUSHBLOCK(cx, CXt_EVAL, SP);
2391 PUSHEVAL(cx, name, compiling.cop_filegv);
2393 compiling.cop_line = 0;
2397 MUTEX_LOCK(&eval_mutex);
2398 if (eval_owner && eval_owner != thr)
2400 COND_WAIT(&eval_cond, &eval_mutex);
2402 MUTEX_UNLOCK(&eval_mutex);
2403 #endif /* USE_THREADS */
2404 return DOCATCH(doeval(G_SCALAR));
2409 return pp_require(ARGS);
2415 register CONTEXT *cx;
2417 I32 gimme = GIMME_V, was = sub_generation;
2418 char tmpbuf[TYPE_DIGITS(long) + 12];
2423 if (!SvPV(sv,len) || !len)
2425 TAINT_PROPER("eval");
2431 /* switch to eval mode */
2433 SAVESPTR(compiling.cop_filegv);
2434 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++evalseq);
2435 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2436 compiling.cop_line = 1;
2437 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2438 deleting the eval's FILEGV from the stash before gv_check() runs
2439 (i.e. before run-time proper). To work around the coredump that
2440 ensues, we always turn GvMULTI_on for any globals that were
2441 introduced within evals. See force_ident(). GSAR 96-10-12 */
2442 safestr = savepv(tmpbuf);
2443 SAVEDELETE(defstash, safestr, strlen(safestr));
2445 hints = op->op_targ;
2447 push_return(op->op_next);
2448 PUSHBLOCK(cx, CXt_EVAL, SP);
2449 PUSHEVAL(cx, 0, compiling.cop_filegv);
2451 /* prepare to compile string */
2453 if (PERLDB_LINE && curstash != debstash)
2454 save_lines(GvAV(compiling.cop_filegv), linestr);
2457 MUTEX_LOCK(&eval_mutex);
2458 if (eval_owner && eval_owner != thr)
2460 COND_WAIT(&eval_cond, &eval_mutex);
2462 MUTEX_UNLOCK(&eval_mutex);
2463 #endif /* USE_THREADS */
2464 ret = doeval(gimme);
2465 if (PERLDB_INTER && was != sub_generation /* Some subs defined here. */
2466 && ret != op->op_next) { /* Successive compilation. */
2467 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
2469 return DOCATCH(ret);
2479 register CONTEXT *cx;
2481 U8 save_flags = op -> op_flags;
2486 retop = pop_return();
2489 if (gimme == G_VOID)
2491 else if (gimme == G_SCALAR) {
2494 if (SvFLAGS(TOPs) & SVs_TEMP)
2497 *MARK = sv_mortalcopy(TOPs);
2505 /* in case LEAVE wipes old return values */
2506 for (mark = newsp + 1; mark <= SP; mark++) {
2507 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
2508 *mark = sv_mortalcopy(*mark);
2509 TAINT_NOT; /* Each item is independent */
2513 curpm = newpm; /* Don't pop $1 et al till now */
2516 * Closures mentioned at top level of eval cannot be referenced
2517 * again, and their presence indirectly causes a memory leak.
2518 * (Note that the fact that compcv and friends are still set here
2519 * is, AFAIK, an accident.) --Chip
2521 if (AvFILL(comppad_name) >= 0) {
2522 SV **svp = AvARRAY(comppad_name);
2524 for (ix = AvFILL(comppad_name); ix >= 0; ix--) {
2526 if (sv && sv != &sv_undef && *SvPVX(sv) == '&') {
2528 svp[ix] = &sv_undef;
2532 SvREFCNT_dec(CvOUTSIDE(sv));
2533 CvOUTSIDE(sv) = Nullcv;
2546 assert(CvDEPTH(compcv) == 1);
2548 CvDEPTH(compcv) = 0;
2550 if (optype == OP_REQUIRE &&
2551 !(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp))
2553 /* Unassume the success we assumed earlier. */
2554 char *name = cx->blk_eval.old_name;
2555 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2556 retop = die("%s did not return a true value", name);
2562 if (!(save_flags & OPf_SPECIAL))
2563 sv_setpv(GvSV(errgv),"");
2571 register CONTEXT *cx;
2572 I32 gimme = GIMME_V;
2577 push_return(cLOGOP->op_other->op_next);
2578 PUSHBLOCK(cx, CXt_EVAL, SP);
2580 eval_root = op; /* Only needed so that goto works right. */
2583 sv_setpv(GvSV(errgv),"");
2585 return DOCATCH(op->op_next);
2595 register CONTEXT *cx;
2603 if (gimme == G_VOID)
2605 else if (gimme == G_SCALAR) {
2608 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2611 *MARK = sv_mortalcopy(TOPs);
2620 /* in case LEAVE wipes old return values */
2621 for (mark = newsp + 1; mark <= SP; mark++) {
2622 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
2623 *mark = sv_mortalcopy(*mark);
2624 TAINT_NOT; /* Each item is independent */
2628 curpm = newpm; /* Don't pop $1 et al till now */
2631 sv_setpv(GvSV(errgv),"");
2639 register char *s = SvPV_force(sv, len);
2640 register char *send = s + len;
2641 register char *base;
2642 register I32 skipspaces = 0;
2645 bool postspace = FALSE;
2653 croak("Null picture in formline");
2655 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
2660 *fpc++ = FF_LINEMARK;
2661 noblank = repeat = FALSE;
2679 case ' ': case '\t':
2690 *fpc++ = FF_LITERAL;
2698 *fpc++ = skipspaces;
2702 *fpc++ = FF_NEWLINE;
2706 arg = fpc - linepc + 1;
2713 *fpc++ = FF_LINEMARK;
2714 noblank = repeat = FALSE;
2723 ischop = s[-1] == '^';
2729 arg = (s - base) - 1;
2731 *fpc++ = FF_LITERAL;
2740 *fpc++ = FF_LINEGLOB;
2742 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2743 arg = ischop ? 512 : 0;
2753 arg |= 256 + (s - f);
2755 *fpc++ = s - base; /* fieldsize for FETCH */
2756 *fpc++ = FF_DECIMAL;
2761 bool ismore = FALSE;
2764 while (*++s == '>') ;
2765 prespace = FF_SPACE;
2767 else if (*s == '|') {
2768 while (*++s == '|') ;
2769 prespace = FF_HALFSPACE;
2774 while (*++s == '<') ;
2777 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2781 *fpc++ = s - base; /* fieldsize for FETCH */
2783 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2801 { /* need to jump to the next word */
2803 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2804 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2805 s = SvPVX(sv) + SvCUR(sv) + z;
2807 Copy(fops, s, arg, U16);
2809 sv_magic(sv, Nullsv, 'f', Nullch, 0);