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);
174 if (!p || p[1] < rx->nparens) {
175 i = 6 + rx->nparens * 2;
183 *p++ = (UV)rx->subbase;
184 rx->subbase = Nullch;
188 *p++ = (UV)rx->subbeg;
189 *p++ = (UV)rx->subend;
190 for (i = 0; i <= rx->nparens; ++i) {
191 *p++ = (UV)rx->startp[i];
192 *p++ = (UV)rx->endp[i];
197 rxres_restore(rsp, rx)
204 Safefree(rx->subbase);
205 rx->subbase = (char*)(*p);
210 rx->subbeg = (char*)(*p++);
211 rx->subend = (char*)(*p++);
212 for (i = 0; i <= rx->nparens; ++i) {
213 rx->startp[i] = (char*)(*p++);
214 rx->endp[i] = (char*)(*p++);
225 Safefree((char*)(*p));
233 dSP; dMARK; dORIGMARK;
234 register SV *form = *++MARK;
246 bool chopspace = (strchr(chopset, ' ') != Nullch);
253 if (!SvMAGICAL(form) || !SvCOMPILED(form)) {
254 SvREADONLY_off(form);
258 SvPV_force(formtarget, len);
259 t = SvGROW(formtarget, len + SvCUR(form) + 1); /* XXX SvCUR bad */
262 /* need to jump to the next word */
263 s = f + len + WORD_ALIGN - SvCUR(form) % WORD_ALIGN;
272 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
273 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
274 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
275 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
276 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
278 case FF_CHECKNL: name = "CHECKNL"; break;
279 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
280 case FF_SPACE: name = "SPACE"; break;
281 case FF_HALFSPACE: name = "HALFSPACE"; break;
282 case FF_ITEM: name = "ITEM"; break;
283 case FF_CHOP: name = "CHOP"; break;
284 case FF_LINEGLOB: name = "LINEGLOB"; break;
285 case FF_NEWLINE: name = "NEWLINE"; break;
286 case FF_MORE: name = "MORE"; break;
287 case FF_LINEMARK: name = "LINEMARK"; break;
288 case FF_END: name = "END"; break;
291 PerlIO_printf(PerlIO_stderr(), "%-16s%ld\n", name, (long) arg);
293 PerlIO_printf(PerlIO_stderr(), "%-16s\n", name);
322 warn("Not enough format arguments");
327 item = s = SvPV(sv, len);
329 if (itemsize > fieldsize)
330 itemsize = fieldsize;
331 send = chophere = s + itemsize;
343 item = s = SvPV(sv, len);
345 if (itemsize <= fieldsize) {
346 send = chophere = s + itemsize;
357 itemsize = fieldsize;
358 send = chophere = s + itemsize;
359 while (s < send || (s == send && isSPACE(*s))) {
369 if (strchr(chopset, *s))
374 itemsize = chophere - item;
379 arg = fieldsize - itemsize;
388 arg = fieldsize - itemsize;
402 int ch = *t++ = *s++;
406 if ( !((*t++ = *s++) & ~31) )
416 while (*s && isSPACE(*s))
423 item = s = SvPV(sv, len);
436 SvCUR_set(formtarget, t - SvPVX(formtarget));
437 sv_catpvn(formtarget, item, itemsize);
438 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(form) + 1);
439 t = SvPVX(formtarget) + SvCUR(formtarget);
444 /* If the field is marked with ^ and the value is undefined,
447 if ((arg & 512) && !SvOK(sv)) {
455 /* Formats aren't yet marked for locales, so assume "yes". */
458 sprintf(t, "%#*.*f", (int) fieldsize, (int) arg & 255, value);
460 sprintf(t, "%*.0f", (int) fieldsize, value);
467 while (t-- > linemark && *t == ' ') ;
475 if (arg) { /* repeat until fields exhausted? */
477 SvCUR_set(formtarget, t - SvPVX(formtarget));
478 lines += FmLINES(formtarget);
481 if (strnEQ(linemark, linemark - arg, arg))
482 DIE("Runaway format");
484 FmLINES(formtarget) = lines;
486 RETURNOP(cLISTOP->op_first);
497 arg = fieldsize - itemsize;
504 if (strnEQ(s," ",3)) {
505 while (s > SvPVX(formtarget) && isSPACE(s[-1]))
516 SvCUR_set(formtarget, t - SvPVX(formtarget));
517 FmLINES(formtarget) += lines;
529 if (stack_base + *markstack_ptr == sp) {
531 if (GIMME_V == G_SCALAR)
533 RETURNOP(op->op_next->op_next);
535 stack_sp = stack_base + *markstack_ptr + 1;
536 pp_pushmark(ARGS); /* push dst */
537 pp_pushmark(ARGS); /* push src */
538 ENTER; /* enter outer scope */
541 SAVESPTR(GvSV(defgv));
543 ENTER; /* enter inner scope */
546 src = stack_base[*markstack_ptr];
551 if (op->op_type == OP_MAPSTART)
552 pp_pushmark(ARGS); /* push top */
553 return ((LOGOP*)op->op_next)->op_other;
558 DIE("panic: mapstart"); /* uses grepstart */
564 I32 diff = (sp - stack_base) - *markstack_ptr;
572 if (diff > markstack_ptr[-1] - markstack_ptr[-2]) {
573 shift = diff - (markstack_ptr[-1] - markstack_ptr[-2]);
574 count = (sp - stack_base) - markstack_ptr[-1] + 2;
579 markstack_ptr[-1] += shift;
580 *markstack_ptr += shift;
584 dst = stack_base + (markstack_ptr[-2] += diff) - 1;
587 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
589 LEAVE; /* exit inner scope */
592 if (markstack_ptr[-1] > *markstack_ptr) {
596 (void)POPMARK; /* pop top */
597 LEAVE; /* exit outer scope */
598 (void)POPMARK; /* pop src */
599 items = --*markstack_ptr - markstack_ptr[-1];
600 (void)POPMARK; /* pop dst */
601 SP = stack_base + POPMARK; /* pop original mark */
602 if (gimme == G_SCALAR) {
606 else if (gimme == G_ARRAY)
613 ENTER; /* enter inner scope */
616 src = stack_base[markstack_ptr[-1]];
620 RETURNOP(cLOGOP->op_other);
627 dSP; dMARK; dORIGMARK;
629 SV **myorigmark = ORIGMARK;
635 OP* nextop = op->op_next;
637 if (gimme != G_ARRAY) {
642 if (op->op_flags & OPf_STACKED) {
644 if (op->op_flags & OPf_SPECIAL) {
645 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
646 kid = kUNOP->op_first; /* pass rv2gv */
647 kid = kUNOP->op_first; /* pass leave */
648 sortcop = kid->op_next;
649 stash = curcop->cop_stash;
652 cv = sv_2cv(*++MARK, &stash, &gv, 0);
653 if (!(cv && CvROOT(cv))) {
655 SV *tmpstr = sv_newmortal();
656 gv_efullname3(tmpstr, gv, Nullch);
657 if (cv && CvXSUB(cv))
658 DIE("Xsub \"%s\" called in sort", SvPVX(tmpstr));
659 DIE("Undefined sort subroutine \"%s\" called",
664 DIE("Xsub called in sort");
665 DIE("Undefined subroutine in sort");
667 DIE("Not a CODE reference in sort");
669 sortcop = CvSTART(cv);
670 SAVESPTR(CvROOT(cv)->op_ppaddr);
671 CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
674 curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
679 stash = curcop->cop_stash;
683 while (MARK < SP) { /* This may or may not shift down one here. */
685 if (*up = *++MARK) { /* Weed out nulls. */
687 if (!sortcop && !SvPOK(*up))
688 (void)sv_2pv(*up, &na);
692 max = --up - myorigmark;
698 bool oldcatch = CATCH_GET;
706 AvREAL_off(sortstack);
707 av_extend(sortstack, 32);
710 SWITCHSTACK(curstack, sortstack);
711 if (sortstash != stash) {
712 firstgv = gv_fetchpv("a", TRUE, SVt_PV);
713 secondgv = gv_fetchpv("b", TRUE, SVt_PV);
717 SAVESPTR(GvSV(firstgv));
718 SAVESPTR(GvSV(secondgv));
720 PUSHBLOCK(cx, CXt_NULL, stack_base);
721 if (!(op->op_flags & OPf_SPECIAL)) {
722 bool hasargs = FALSE;
723 cx->cx_type = CXt_SUB;
724 cx->blk_gimme = G_SCALAR;
727 (void)SvREFCNT_inc(cv); /* in preparation for POPSUB */
729 sortcxix = cxstack_ix;
731 qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
734 SWITCHSTACK(sortstack, oldstack);
741 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
742 qsort((char*)(ORIGMARK+1), max, sizeof(SV*),
743 (op->op_private & OPpLOCALE) ? sortcmp_locale : sortcmp);
746 stack_sp = ORIGMARK + max;
754 if (GIMME == G_ARRAY)
755 return cCONDOP->op_true;
756 return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
763 if (GIMME == G_ARRAY) {
764 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
768 SV *targ = PAD_SV(op->op_targ);
770 if ((op->op_private & OPpFLIP_LINENUM)
771 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
773 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
774 if (op->op_flags & OPf_SPECIAL) {
782 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
795 if (GIMME == G_ARRAY) {
801 if (SvNIOKp(left) || !SvPOKp(left) ||
802 (looks_like_number(left) && *SvPVX(left) != '0') )
807 EXTEND_MORTAL(max - i + 1);
808 EXTEND(SP, max - i + 1);
811 sv = sv_2mortal(newSViv(i++));
816 SV *final = sv_mortalcopy(right);
818 char *tmps = SvPV(final, len);
820 sv = sv_mortalcopy(left);
821 while (!SvNIOKp(sv) && SvCUR(sv) <= len &&
822 strNE(SvPVX(sv),tmps) ) {
824 sv = sv_2mortal(newSVsv(sv));
827 if (strEQ(SvPVX(sv),tmps))
833 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
835 if ((op->op_private & OPpFLIP_LINENUM)
836 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
838 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
839 sv_catpv(targ, "E0");
855 register CONTEXT *cx;
857 for (i = cxstack_ix; i >= 0; i--) {
859 switch (cx->cx_type) {
862 warn("Exiting substitution via %s", op_name[op->op_type]);
866 warn("Exiting subroutine via %s", op_name[op->op_type]);
870 warn("Exiting eval via %s", op_name[op->op_type]);
874 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
877 if (!cx->blk_loop.label ||
878 strNE(label, cx->blk_loop.label) ) {
879 DEBUG_l(deb("(Skipping label #%ld %s)\n",
880 (long)i, cx->blk_loop.label));
883 DEBUG_l( deb("(Found label #%ld %s)\n", (long)i, label));
893 I32 gimme = block_gimme();
894 return (gimme == G_VOID) ? G_SCALAR : gimme;
903 cxix = dopoptosub(cxstack_ix);
907 switch (cxstack[cxix].blk_gimme) {
915 croak("panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
920 dopoptosub(startingblock)
925 register CONTEXT *cx;
926 for (i = startingblock; i >= 0; i--) {
928 switch (cx->cx_type) {
933 DEBUG_l( deb("(Found sub #%ld)\n", (long)i));
941 dopoptoeval(startingblock)
946 register CONTEXT *cx;
947 for (i = startingblock; i >= 0; i--) {
949 switch (cx->cx_type) {
953 DEBUG_l( deb("(Found eval #%ld)\n", (long)i));
961 dopoptoloop(startingblock)
966 register CONTEXT *cx;
967 for (i = startingblock; i >= 0; i--) {
969 switch (cx->cx_type) {
972 warn("Exiting substitution via %s", op_name[op->op_type]);
976 warn("Exiting subroutine via %s", op_name[op->op_type]);
980 warn("Exiting eval via %s", op_name[op->op_type]);
984 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
987 DEBUG_l( deb("(Found loop #%ld)\n", (long)i));
999 register CONTEXT *cx;
1003 while (cxstack_ix > cxix) {
1004 cx = &cxstack[cxstack_ix];
1005 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n",
1006 (long) cxstack_ix+1, block_type[cx->cx_type]));
1007 /* Note: we don't need to restore the base context info till the end. */
1008 switch (cx->cx_type) {
1011 continue; /* not break */
1035 register CONTEXT *cx;
1041 STRLEN klen = strlen(message);
1043 svp = hv_fetch(errhv, message, klen, TRUE);
1046 static char prefix[] = "\t(in cleanup) ";
1047 sv_upgrade(*svp, SVt_IV);
1048 (void)SvIOK_only(*svp);
1049 SvGROW(errsv, SvCUR(errsv)+sizeof(prefix)+klen);
1050 sv_catpvn(errsv, prefix, sizeof(prefix)-1);
1051 sv_catpvn(errsv, message, klen);
1057 sv_setpv(errsv, message);
1059 cxix = dopoptoeval(cxstack_ix);
1063 if (cxix < cxstack_ix)
1067 if (cx->cx_type != CXt_EVAL) {
1068 PerlIO_printf(PerlIO_stderr(), "panic: die %s", message);
1073 if (gimme == G_SCALAR)
1074 *++newsp = &sv_undef;
1079 if (optype == OP_REQUIRE) {
1080 char* msg = SvPV(errsv, na);
1081 DIE("%s", *msg ? msg : "Compilation failed in require");
1083 return pop_return();
1086 PerlIO_printf(PerlIO_stderr(), "%s",message);
1087 PerlIO_flush(PerlIO_stderr());
1096 if (SvTRUE(left) != SvTRUE(right))
1108 RETURNOP(cLOGOP->op_other);
1117 RETURNOP(cLOGOP->op_other);
1124 SV** mark = (stack_base + *markstack_ptr + 1);
1126 while (mark < sp) { /* emulate old interface */
1131 return pp_entersub(ARGS);
1138 register I32 cxix = dopoptosub(cxstack_ix);
1139 register CONTEXT *cx;
1150 if (GIMME != G_ARRAY)
1154 if (DBsub && cxix >= 0 &&
1155 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1159 cxix = dopoptosub(cxix - 1);
1161 cx = &cxstack[cxix];
1162 if (cxstack[cxix].cx_type == CXt_SUB) {
1163 dbcxix = dopoptosub(cxix - 1);
1164 /* We expect that cxstack[dbcxix] is CXt_SUB, anyway, the
1165 field below is defined for any cx. */
1166 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1167 cx = &cxstack[dbcxix];
1170 if (GIMME != G_ARRAY) {
1173 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1178 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1179 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1180 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1183 if (cx->cx_type == CXt_SUB) { /* So is cxstack[dbcxix]. */
1185 gv_efullname3(sv, CvGV(cxstack[cxix].blk_sub.cv), Nullch);
1186 PUSHs(sv_2mortal(sv));
1187 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1190 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1191 PUSHs(sv_2mortal(newSViv(0)));
1193 gimme = (I32)cx->blk_gimme;
1194 if (gimme == G_VOID)
1197 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1198 if (cx->cx_type == CXt_EVAL) {
1199 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1200 PUSHs(cx->blk_eval.cur_text);
1203 else if (cx->blk_eval.old_name) { /* Try blocks have old_name == 0. */
1204 /* Require, put the name. */
1205 PUSHs(sv_2mortal(newSVpv(cx->blk_eval.old_name, 0)));
1209 else if (cx->cx_type == CXt_SUB &&
1210 cx->blk_sub.hasargs &&
1211 curcop->cop_stash == debstash)
1213 AV *ary = cx->blk_sub.argarray;
1214 int off = AvARRAY(ary) - AvALLOC(ary);
1218 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1221 AvREAL_off(dbargs); /* XXX Should be REIFY */
1224 if (AvMAX(dbargs) < AvFILL(ary) + off)
1225 av_extend(dbargs, AvFILL(ary) + off);
1226 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1227 AvFILL(dbargs) = AvFILL(ary) + off;
1238 SV * const *str1 = (SV * const *)a;
1239 SV * const *str2 = (SV * const *)b;
1240 I32 oldsaveix = savestack_ix;
1241 I32 oldscopeix = scopestack_ix;
1243 GvSV(firstgv) = *str1;
1244 GvSV(secondgv) = *str2;
1245 stack_sp = stack_base;
1248 if (stack_sp != stack_base + 1)
1249 croak("Sort subroutine didn't return single value");
1250 if (!SvNIOKp(*stack_sp))
1251 croak("Sort subroutine didn't return a numeric value");
1252 result = SvIV(*stack_sp);
1253 while (scopestack_ix > oldscopeix) {
1256 leave_scope(oldsaveix);
1265 return sv_cmp(*(SV * const *)a, *(SV * const *)b);
1269 sortcmp_locale(a, b)
1273 return sv_cmp_locale(*(SV * const *)a, *(SV * const *)b);
1285 sv_reset(tmps, curcop->cop_stash);
1298 TAINT_NOT; /* Each statement is presumed innocent */
1299 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1302 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1306 register CONTEXT *cx;
1307 I32 gimme = G_ARRAY;
1314 DIE("No DB::DB routine defined");
1316 if (CvDEPTH(cv) >= 1 && !(debug & (1<<30))) /* don't do recursive DB::DB call */
1328 push_return(op->op_next);
1329 PUSHBLOCK(cx, CXt_SUB, sp);
1332 (void)SvREFCNT_inc(cv);
1334 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1335 RETURNOP(CvSTART(cv));
1349 register CONTEXT *cx;
1350 I32 gimme = GIMME_V;
1357 svp = &curpad[op->op_targ]; /* "my" variable */
1359 svp = &GvSV((GV*)POPs); /* symbol table variable */
1365 PUSHBLOCK(cx, CXt_LOOP, SP);
1366 PUSHLOOP(cx, svp, MARK);
1367 if (op->op_flags & OPf_STACKED)
1368 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1370 cx->blk_loop.iterary = curstack;
1371 AvFILL(curstack) = sp - stack_base;
1372 cx->blk_loop.iterix = MARK - stack_base;
1381 register CONTEXT *cx;
1382 I32 gimme = GIMME_V;
1388 PUSHBLOCK(cx, CXt_LOOP, SP);
1389 PUSHLOOP(cx, 0, SP);
1397 register CONTEXT *cx;
1398 struct block_loop cxloop;
1406 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1409 if (gimme == G_VOID)
1411 else if (gimme == G_SCALAR) {
1413 *++newsp = sv_mortalcopy(*SP);
1415 *++newsp = &sv_undef;
1419 *++newsp = sv_mortalcopy(*++mark);
1420 TAINT_NOT; /* Each item is independent */
1426 POPLOOP2(); /* Stack values are safe: release loop vars ... */
1427 curpm = newpm; /* ... and pop $1 et al */
1439 register CONTEXT *cx;
1440 struct block_sub cxsub;
1441 bool popsub2 = FALSE;
1447 if (curstack == sortstack) {
1448 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) <= sortcxix) {
1449 if (cxstack_ix > sortcxix)
1451 AvARRAY(curstack)[1] = *SP;
1452 stack_sp = stack_base + 1;
1457 cxix = dopoptosub(cxstack_ix);
1459 DIE("Can't return outside a subroutine");
1460 if (cxix < cxstack_ix)
1464 switch (cx->cx_type) {
1466 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1471 if (optype == OP_REQUIRE &&
1472 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1474 /* Unassume the success we assumed earlier. */
1475 char *name = cx->blk_eval.old_name;
1476 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1477 DIE("%s did not return a true value", name);
1481 DIE("panic: return");
1485 if (gimme == G_SCALAR) {
1487 *++newsp = (popsub2 && SvTEMP(*SP))
1488 ? *SP : sv_mortalcopy(*SP);
1490 *++newsp = &sv_undef;
1492 else if (gimme == G_ARRAY) {
1493 while (++MARK <= SP) {
1494 *++newsp = (popsub2 && SvTEMP(*MARK))
1495 ? *MARK : sv_mortalcopy(*MARK);
1496 TAINT_NOT; /* Each item is independent */
1501 /* Stack values are safe: */
1503 POPSUB2(); /* release CV and @_ ... */
1505 curpm = newpm; /* ... and pop $1 et al */
1508 return pop_return();
1515 register CONTEXT *cx;
1516 struct block_loop cxloop;
1517 struct block_sub cxsub;
1524 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1526 if (op->op_flags & OPf_SPECIAL) {
1527 cxix = dopoptoloop(cxstack_ix);
1529 DIE("Can't \"last\" outside a block");
1532 cxix = dopoptolabel(cPVOP->op_pv);
1534 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1536 if (cxix < cxstack_ix)
1540 switch (cx->cx_type) {
1542 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1544 nextop = cxloop.last_op->op_next;
1547 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1549 nextop = pop_return();
1553 nextop = pop_return();
1560 if (gimme == G_SCALAR) {
1562 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
1563 ? *SP : sv_mortalcopy(*SP);
1565 *++newsp = &sv_undef;
1567 else if (gimme == G_ARRAY) {
1568 while (++MARK <= SP) {
1569 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
1570 ? *MARK : sv_mortalcopy(*MARK);
1571 TAINT_NOT; /* Each item is independent */
1577 /* Stack values are safe: */
1580 POPLOOP2(); /* release loop vars ... */
1584 POPSUB2(); /* release CV and @_ ... */
1587 curpm = newpm; /* ... and pop $1 et al */
1596 register CONTEXT *cx;
1599 if (op->op_flags & OPf_SPECIAL) {
1600 cxix = dopoptoloop(cxstack_ix);
1602 DIE("Can't \"next\" outside a block");
1605 cxix = dopoptolabel(cPVOP->op_pv);
1607 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1609 if (cxix < cxstack_ix)
1613 oldsave = scopestack[scopestack_ix - 1];
1614 LEAVE_SCOPE(oldsave);
1615 return cx->blk_loop.next_op;
1621 register CONTEXT *cx;
1624 if (op->op_flags & OPf_SPECIAL) {
1625 cxix = dopoptoloop(cxstack_ix);
1627 DIE("Can't \"redo\" outside a block");
1630 cxix = dopoptolabel(cPVOP->op_pv);
1632 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1634 if (cxix < cxstack_ix)
1638 oldsave = scopestack[scopestack_ix - 1];
1639 LEAVE_SCOPE(oldsave);
1640 return cx->blk_loop.redo_op;
1643 static OP* lastgotoprobe;
1646 dofindlabel(o,label,opstack,oplimit)
1654 static char too_deep[] = "Target of goto is too deeply nested";
1658 if (o->op_type == OP_LEAVE ||
1659 o->op_type == OP_SCOPE ||
1660 o->op_type == OP_LEAVELOOP ||
1661 o->op_type == OP_LEAVETRY)
1663 *ops++ = cUNOPo->op_first;
1668 if (o->op_flags & OPf_KIDS) {
1669 /* First try all the kids at this level, since that's likeliest. */
1670 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1671 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1672 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1675 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1676 if (kid == lastgotoprobe)
1678 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1680 (ops[-1]->op_type != OP_NEXTSTATE &&
1681 ops[-1]->op_type != OP_DBSTATE)))
1683 if (o = dofindlabel(kid, label, ops, oplimit))
1693 return pp_goto(ARGS);
1702 register CONTEXT *cx;
1703 #define GOTO_DEPTH 64
1704 OP *enterops[GOTO_DEPTH];
1706 int do_dump = (op->op_type == OP_DUMP);
1709 if (op->op_flags & OPf_STACKED) {
1712 /* This egregious kludge implements goto &subroutine */
1713 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1715 register CONTEXT *cx;
1716 CV* cv = (CV*)SvRV(sv);
1721 if (!CvROOT(cv) && !CvXSUB(cv)) {
1723 SV *tmpstr = sv_newmortal();
1724 gv_efullname3(tmpstr, CvGV(cv), Nullch);
1725 DIE("Goto undefined subroutine &%s",SvPVX(tmpstr));
1727 DIE("Goto undefined subroutine");
1730 /* First do some returnish stuff. */
1731 cxix = dopoptosub(cxstack_ix);
1733 DIE("Can't goto subroutine outside a subroutine");
1734 if (cxix < cxstack_ix)
1738 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1739 AV* av = cx->blk_sub.argarray;
1741 items = AvFILL(av) + 1;
1743 EXTEND(stack_sp, items); /* @_ could have been extended. */
1744 Copy(AvARRAY(av), stack_sp, items, SV*);
1747 SvREFCNT_dec(GvAV(defgv));
1748 GvAV(defgv) = cx->blk_sub.savearray;
1749 #endif /* USE_THREADS */
1753 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1754 SvREFCNT_dec(cx->blk_sub.cv);
1755 oldsave = scopestack[scopestack_ix - 1];
1756 LEAVE_SCOPE(oldsave);
1758 /* Now do some callish stuff. */
1761 if (CvOLDSTYLE(cv)) {
1762 I32 (*fp3)_((int,int,int));
1767 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1768 items = (*fp3)(CvXSUBANY(cv).any_i32,
1769 mark - stack_base + 1,
1771 sp = stack_base + items;
1774 stack_sp--; /* There is no cv arg. */
1775 (void)(*CvXSUB(cv))(cv);
1778 return pop_return();
1781 AV* padlist = CvPADLIST(cv);
1782 SV** svp = AvARRAY(padlist);
1783 cx->blk_sub.cv = cv;
1784 cx->blk_sub.olddepth = CvDEPTH(cv);
1786 if (CvDEPTH(cv) < 2)
1787 (void)SvREFCNT_inc(cv);
1788 else { /* save temporaries on recursion? */
1789 if (CvDEPTH(cv) == 100 && dowarn)
1790 sub_crush_depth(cv);
1791 if (CvDEPTH(cv) > AvFILL(padlist)) {
1792 AV *newpad = newAV();
1793 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
1794 I32 ix = AvFILL((AV*)svp[1]);
1795 svp = AvARRAY(svp[0]);
1796 for ( ;ix > 0; ix--) {
1797 if (svp[ix] != &sv_undef) {
1798 char *name = SvPVX(svp[ix]);
1799 if ((SvFLAGS(svp[ix]) & SVf_FAKE)
1802 /* outer lexical or anon code */
1803 av_store(newpad, ix,
1804 SvREFCNT_inc(oldpad[ix]) );
1806 else { /* our own lexical */
1808 av_store(newpad, ix, sv = (SV*)newAV());
1809 else if (*name == '%')
1810 av_store(newpad, ix, sv = (SV*)newHV());
1812 av_store(newpad, ix, sv = NEWSV(0,0));
1817 av_store(newpad, ix, sv = NEWSV(0,0));
1821 if (cx->blk_sub.hasargs) {
1824 av_store(newpad, 0, (SV*)av);
1825 AvFLAGS(av) = AVf_REIFY;
1827 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1828 AvFILL(padlist) = CvDEPTH(cv);
1829 svp = AvARRAY(padlist);
1833 if (!cx->blk_sub.hasargs) {
1834 AV* av = (AV*)curpad[0];
1836 items = AvFILL(av) + 1;
1838 /* Mark is at the end of the stack. */
1840 Copy(AvARRAY(av), sp + 1, items, SV*);
1845 #endif /* USE_THREADS */
1847 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1849 if (cx->blk_sub.hasargs)
1850 #endif /* USE_THREADS */
1852 AV* av = (AV*)curpad[0];
1856 cx->blk_sub.savearray = GvAV(defgv);
1857 GvAV(defgv) = (AV*)SvREFCNT_inc(av);
1858 #endif /* USE_THREADS */
1859 cx->blk_sub.argarray = av;
1862 if (items >= AvMAX(av) + 1) {
1864 if (AvARRAY(av) != ary) {
1865 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1866 SvPVX(av) = (char*)ary;
1868 if (items >= AvMAX(av) + 1) {
1869 AvMAX(av) = items - 1;
1870 Renew(ary,items+1,SV*);
1872 SvPVX(av) = (char*)ary;
1875 Copy(mark,AvARRAY(av),items,SV*);
1876 AvFILL(av) = items - 1;
1884 if (PERLDB_SUB && curstash != debstash) {
1886 * We do not care about using sv to call CV;
1887 * it's for informational purposes only.
1889 SV *sv = GvSV(DBsub);
1891 gv_efullname3(sv, CvGV(cv), Nullch);
1893 RETURNOP(CvSTART(cv));
1897 label = SvPV(sv,na);
1899 else if (op->op_flags & OPf_SPECIAL) {
1901 DIE("goto must have label");
1904 label = cPVOP->op_pv;
1906 if (label && *label) {
1913 for (ix = cxstack_ix; ix >= 0; ix--) {
1915 switch (cx->cx_type) {
1917 gotoprobe = eval_root; /* XXX not good for nested eval */
1920 gotoprobe = cx->blk_oldcop->op_sibling;
1926 gotoprobe = cx->blk_oldcop->op_sibling;
1928 gotoprobe = main_root;
1931 if (CvDEPTH(cx->blk_sub.cv)) {
1932 gotoprobe = CvROOT(cx->blk_sub.cv);
1937 DIE("Can't \"goto\" outside a block");
1941 gotoprobe = main_root;
1944 retop = dofindlabel(gotoprobe, label,
1945 enterops, enterops + GOTO_DEPTH);
1948 lastgotoprobe = gotoprobe;
1951 DIE("Can't find label %s", label);
1953 /* pop unwanted frames */
1955 if (ix < cxstack_ix) {
1962 oldsave = scopestack[scopestack_ix];
1963 LEAVE_SCOPE(oldsave);
1966 /* push wanted frames */
1968 if (*enterops && enterops[1]) {
1970 for (ix = 1; enterops[ix]; ix++) {
1972 /* Eventually we may want to stack the needed arguments
1973 * for each op. For now, we punt on the hard ones. */
1974 if (op->op_type == OP_ENTERITER)
1975 DIE("Can't \"goto\" into the middle of a foreach loop",
1977 (*op->op_ppaddr)(ARGS);
1985 if (!retop) retop = main_start;
1992 restartop = 0; /* hmm, must be GNU unexec().. */
1996 if (curstack == signalstack) {
2014 if (anum == 1 && VMSISH_EXIT)
2027 double value = SvNVx(GvSV(cCOP->cop_gv));
2028 register I32 match = I_32(value);
2031 if (((double)match) > value)
2032 --match; /* was fractional--truncate other way */
2034 match -= cCOP->uop.scop.scop_offset;
2037 else if (match > cCOP->uop.scop.scop_max)
2038 match = cCOP->uop.scop.scop_max;
2039 op = cCOP->uop.scop.scop_next[match];
2049 op = op->op_next; /* can't assume anything */
2051 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
2052 match -= cCOP->uop.scop.scop_offset;
2055 else if (match > cCOP->uop.scop.scop_max)
2056 match = cCOP->uop.scop.scop_max;
2057 op = cCOP->uop.scop.scop_next[match];
2066 save_lines(array, sv)
2070 register char *s = SvPVX(sv);
2071 register char *send = SvPVX(sv) + SvCUR(sv);
2073 register I32 line = 1;
2075 while (s && s < send) {
2076 SV *tmpstr = NEWSV(85,0);
2078 sv_upgrade(tmpstr, SVt_PVMG);
2079 t = strchr(s, '\n');
2085 sv_setpvn(tmpstr, s, t - s);
2086 av_store(array, line++, tmpstr);
2097 I32 oldrunlevel = runlevel;
2103 assert(CATCH_GET == TRUE);
2104 DEBUG_l(deb("(Setting up local jumplevel, runlevel = %ld)\n", (long)runlevel+1));
2108 default: /* topmost level handles it */
2110 runlevel = oldrunlevel;
2116 PerlIO_printf(PerlIO_stderr(), "panic: restartop\n");
2127 runlevel = oldrunlevel;
2132 /* With USE_THREADS, eval_owner must be held on entry to doeval */
2148 /* set up a scratch pad */
2153 SAVESPTR(comppad_name);
2154 SAVEI32(comppad_name_fill);
2155 SAVEI32(min_intro_pending);
2156 SAVEI32(max_intro_pending);
2160 compcv = (CV*)NEWSV(1104,0);
2161 sv_upgrade((SV *)compcv, SVt_PVCV);
2162 CvUNIQUE_on(compcv);
2164 CvOWNER(compcv) = 0;
2165 New(666, CvMUTEXP(compcv), 1, perl_mutex);
2166 MUTEX_INIT(CvMUTEXP(compcv));
2167 #endif /* USE_THREADS */
2170 av_push(comppad, Nullsv);
2171 curpad = AvARRAY(comppad);
2172 comppad_name = newAV();
2173 comppad_name_fill = 0;
2174 min_intro_pending = 0;
2177 av_store(comppad_name, 0, newSVpv("@_", 2));
2178 curpad[0] = (SV*)newAV();
2179 SvPADMY_on(curpad[0]); /* XXX Needed? */
2180 #endif /* USE_THREADS */
2182 comppadlist = newAV();
2183 AvREAL_off(comppadlist);
2184 av_store(comppadlist, 0, (SV*)comppad_name);
2185 av_store(comppadlist, 1, (SV*)comppad);
2186 CvPADLIST(compcv) = comppadlist;
2188 if (saveop->op_type != OP_REQUIRE)
2189 CvOUTSIDE(compcv) = caller ? (CV*)SvREFCNT_inc(caller) : 0;
2193 /* make sure we compile in the right package */
2195 newstash = curcop->cop_stash;
2196 if (curstash != newstash) {
2198 curstash = newstash;
2202 SAVEFREESV(beginav);
2204 /* try to compile it */
2208 curcop = &compiling;
2209 curcop->cop_arybase = 0;
2211 rs = newSVpv("\n", 1);
2212 if (saveop->op_flags & OPf_SPECIAL)
2216 if (yyparse() || error_count || !eval_root) {
2227 SP = stack_base + POPMARK; /* pop original mark */
2233 if (optype == OP_REQUIRE) {
2234 char* msg = SvPV(errsv, na);
2235 DIE("%s", *msg ? msg : "Compilation failed in require");
2238 rs = SvREFCNT_inc(nrs);
2240 MUTEX_LOCK(&eval_mutex);
2242 COND_SIGNAL(&eval_cond);
2243 MUTEX_UNLOCK(&eval_mutex);
2244 #endif /* USE_THREADS */
2248 rs = SvREFCNT_inc(nrs);
2249 compiling.cop_line = 0;
2250 SAVEFREEOP(eval_root);
2252 scalarvoid(eval_root);
2253 else if (gimme & G_ARRAY)
2258 DEBUG_x(dump_eval());
2260 /* Register with debugger: */
2261 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2262 CV *cv = perl_get_cv("DB::postponed", FALSE);
2266 XPUSHs((SV*)compiling.cop_filegv);
2268 perl_call_sv((SV*)cv, G_DISCARD);
2272 /* compiled okay, so do it */
2274 CvDEPTH(compcv) = 1;
2275 SP = stack_base + POPMARK; /* pop original mark */
2276 op = saveop; /* The caller may need it. */
2278 MUTEX_LOCK(&eval_mutex);
2280 COND_SIGNAL(&eval_cond);
2281 MUTEX_UNLOCK(&eval_mutex);
2282 #endif /* USE_THREADS */
2284 RETURNOP(eval_start);
2290 register CONTEXT *cx;
2294 SV *namesv = Nullsv;
2296 I32 gimme = G_SCALAR;
2297 PerlIO *tryrsfp = 0;
2300 if (SvNIOKp(sv) && !SvPOKp(sv)) {
2301 SET_NUMERIC_STANDARD();
2302 if (atof(patchlevel) + 0.00000999 < SvNV(sv))
2303 DIE("Perl %s required--this is only version %s, stopped",
2304 SvPV(sv,na),patchlevel);
2307 name = SvPV(sv, na);
2309 DIE("Null filename used");
2310 TAINT_PROPER("require");
2311 if (op->op_type == OP_REQUIRE &&
2312 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
2316 /* prepare to compile file */
2321 (name[1] == '.' && name[2] == '/')))
2323 || (name[0] && name[1] == ':')
2326 || (name[0] == '\\' && name[1] == '\\') /* UNC path */
2329 || (strchr(name,':') || ((*name == '[' || *name == '<') &&
2330 (isALNUM(name[1]) || strchr("$-_]>",name[1]))))
2335 tryrsfp = PerlIO_open(name,"r");
2338 AV *ar = GvAVn(incgv);
2342 if ((unixname = tounixspec(name, Nullch)) != Nullch)
2345 namesv = NEWSV(806, 0);
2346 for (i = 0; i <= AvFILL(ar); i++) {
2347 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2350 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
2352 sv_setpv(namesv, unixdir);
2353 sv_catpv(namesv, unixname);
2355 sv_setpvf(namesv, "%s/%s", dir, name);
2357 tryname = SvPVX(namesv);
2358 tryrsfp = PerlIO_open(tryname, "r");
2360 if (tryname[0] == '.' && tryname[1] == '/')
2367 SAVESPTR(compiling.cop_filegv);
2368 compiling.cop_filegv = gv_fetchfile(tryrsfp ? tryname : name);
2369 SvREFCNT_dec(namesv);
2371 if (op->op_type == OP_REQUIRE) {
2372 SV *msg = sv_2mortal(newSVpvf("Can't locate %s in @INC", name));
2373 SV *dirmsgsv = NEWSV(0, 0);
2374 AV *ar = GvAVn(incgv);
2376 if (instr(SvPVX(msg), ".h "))
2377 sv_catpv(msg, " (change .h to .ph maybe?)");
2378 if (instr(SvPVX(msg), ".ph "))
2379 sv_catpv(msg, " (did you run h2ph?)");
2380 sv_catpv(msg, " (@INC contains:");
2381 for (i = 0; i <= AvFILL(ar); i++) {
2382 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2383 sv_setpvf(dirmsgsv, " %s", dir);
2384 sv_catsv(msg, dirmsgsv);
2386 sv_catpvn(msg, ")", 1);
2387 SvREFCNT_dec(dirmsgsv);
2394 /* Assume success here to prevent recursive requirement. */
2395 (void)hv_store(GvHVn(incgv), name, strlen(name),
2396 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2400 lex_start(sv_2mortal(newSVpv("",0)));
2402 save_aptr(&rsfp_filters);
2403 rsfp_filters = NULL;
2407 name = savepv(name);
2412 /* switch to eval mode */
2414 push_return(op->op_next);
2415 PUSHBLOCK(cx, CXt_EVAL, SP);
2416 PUSHEVAL(cx, name, compiling.cop_filegv);
2418 compiling.cop_line = 0;
2422 MUTEX_LOCK(&eval_mutex);
2423 if (eval_owner && eval_owner != thr)
2425 COND_WAIT(&eval_cond, &eval_mutex);
2427 MUTEX_UNLOCK(&eval_mutex);
2428 #endif /* USE_THREADS */
2429 return DOCATCH(doeval(G_SCALAR));
2434 return pp_require(ARGS);
2440 register CONTEXT *cx;
2442 I32 gimme = GIMME_V, was = sub_generation;
2443 char tmpbuf[TYPE_DIGITS(long) + 12];
2448 if (!SvPV(sv,len) || !len)
2450 TAINT_PROPER("eval");
2456 /* switch to eval mode */
2458 SAVESPTR(compiling.cop_filegv);
2459 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++evalseq);
2460 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2461 compiling.cop_line = 1;
2462 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2463 deleting the eval's FILEGV from the stash before gv_check() runs
2464 (i.e. before run-time proper). To work around the coredump that
2465 ensues, we always turn GvMULTI_on for any globals that were
2466 introduced within evals. See force_ident(). GSAR 96-10-12 */
2467 safestr = savepv(tmpbuf);
2468 SAVEDELETE(defstash, safestr, strlen(safestr));
2470 hints = op->op_targ;
2472 push_return(op->op_next);
2473 PUSHBLOCK(cx, CXt_EVAL, SP);
2474 PUSHEVAL(cx, 0, compiling.cop_filegv);
2476 /* prepare to compile string */
2478 if (PERLDB_LINE && curstash != debstash)
2479 save_lines(GvAV(compiling.cop_filegv), linestr);
2482 MUTEX_LOCK(&eval_mutex);
2483 if (eval_owner && eval_owner != thr)
2485 COND_WAIT(&eval_cond, &eval_mutex);
2487 MUTEX_UNLOCK(&eval_mutex);
2488 #endif /* USE_THREADS */
2489 ret = doeval(gimme);
2490 if (PERLDB_INTER && was != sub_generation /* Some subs defined here. */
2491 && ret != op->op_next) { /* Successive compilation. */
2492 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
2494 return DOCATCH(ret);
2504 register CONTEXT *cx;
2506 U8 save_flags = op -> op_flags;
2511 retop = pop_return();
2514 if (gimme == G_VOID)
2516 else if (gimme == G_SCALAR) {
2519 if (SvFLAGS(TOPs) & SVs_TEMP)
2522 *MARK = sv_mortalcopy(TOPs);
2530 /* in case LEAVE wipes old return values */
2531 for (mark = newsp + 1; mark <= SP; mark++) {
2532 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
2533 *mark = sv_mortalcopy(*mark);
2534 TAINT_NOT; /* Each item is independent */
2538 curpm = newpm; /* Don't pop $1 et al till now */
2541 * Closures mentioned at top level of eval cannot be referenced
2542 * again, and their presence indirectly causes a memory leak.
2543 * (Note that the fact that compcv and friends are still set here
2544 * is, AFAIK, an accident.) --Chip
2546 if (AvFILL(comppad_name) >= 0) {
2547 SV **svp = AvARRAY(comppad_name);
2549 for (ix = AvFILL(comppad_name); ix >= 0; ix--) {
2551 if (sv && sv != &sv_undef && *SvPVX(sv) == '&') {
2553 svp[ix] = &sv_undef;
2557 SvREFCNT_dec(CvOUTSIDE(sv));
2558 CvOUTSIDE(sv) = Nullcv;
2571 assert(CvDEPTH(compcv) == 1);
2573 CvDEPTH(compcv) = 0;
2575 if (optype == OP_REQUIRE &&
2576 !(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp))
2578 /* Unassume the success we assumed earlier. */
2579 char *name = cx->blk_eval.old_name;
2580 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2581 retop = die("%s did not return a true value", name);
2587 if (!(save_flags & OPf_SPECIAL))
2596 register CONTEXT *cx;
2597 I32 gimme = GIMME_V;
2602 push_return(cLOGOP->op_other->op_next);
2603 PUSHBLOCK(cx, CXt_EVAL, SP);
2605 eval_root = op; /* Only needed so that goto works right. */
2610 return DOCATCH(op->op_next);
2620 register CONTEXT *cx;
2628 if (gimme == G_VOID)
2630 else if (gimme == G_SCALAR) {
2633 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2636 *MARK = sv_mortalcopy(TOPs);
2645 /* in case LEAVE wipes old return values */
2646 for (mark = newsp + 1; mark <= SP; mark++) {
2647 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
2648 *mark = sv_mortalcopy(*mark);
2649 TAINT_NOT; /* Each item is independent */
2653 curpm = newpm; /* Don't pop $1 et al till now */
2665 register char *s = SvPV_force(sv, len);
2666 register char *send = s + len;
2667 register char *base;
2668 register I32 skipspaces = 0;
2671 bool postspace = FALSE;
2679 croak("Null picture in formline");
2681 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
2686 *fpc++ = FF_LINEMARK;
2687 noblank = repeat = FALSE;
2705 case ' ': case '\t':
2716 *fpc++ = FF_LITERAL;
2724 *fpc++ = skipspaces;
2728 *fpc++ = FF_NEWLINE;
2732 arg = fpc - linepc + 1;
2739 *fpc++ = FF_LINEMARK;
2740 noblank = repeat = FALSE;
2749 ischop = s[-1] == '^';
2755 arg = (s - base) - 1;
2757 *fpc++ = FF_LITERAL;
2766 *fpc++ = FF_LINEGLOB;
2768 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2769 arg = ischop ? 512 : 0;
2779 arg |= 256 + (s - f);
2781 *fpc++ = s - base; /* fieldsize for FETCH */
2782 *fpc++ = FF_DECIMAL;
2787 bool ismore = FALSE;
2790 while (*++s == '>') ;
2791 prespace = FF_SPACE;
2793 else if (*s == '|') {
2794 while (*++s == '|') ;
2795 prespace = FF_HALFSPACE;
2800 while (*++s == '<') ;
2803 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2807 *fpc++ = s - base; /* fieldsize for FETCH */
2809 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2827 { /* need to jump to the next word */
2829 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2830 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2831 s = SvPVX(sv) + SvCUR(sv) + z;
2833 Copy(fops, s, arg, U16);
2835 sv_magic(sv, Nullsv, 'f', Nullch, 0);