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 */
552 save_sptr(av_fetch(thr->threadsv, find_threadsv("_"), FALSE));
554 ENTER; /* enter inner scope */
557 src = stack_base[*markstack_ptr];
562 if (op->op_type == OP_MAPSTART)
563 pp_pushmark(ARGS); /* push top */
564 return ((LOGOP*)op->op_next)->op_other;
569 DIE("panic: mapstart"); /* uses grepstart */
575 I32 diff = (sp - stack_base) - *markstack_ptr;
583 if (diff > markstack_ptr[-1] - markstack_ptr[-2]) {
584 shift = diff - (markstack_ptr[-1] - markstack_ptr[-2]);
585 count = (sp - stack_base) - markstack_ptr[-1] + 2;
590 markstack_ptr[-1] += shift;
591 *markstack_ptr += shift;
595 dst = stack_base + (markstack_ptr[-2] += diff) - 1;
598 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
600 LEAVE; /* exit inner scope */
603 if (markstack_ptr[-1] > *markstack_ptr) {
607 (void)POPMARK; /* pop top */
608 LEAVE; /* exit outer scope */
609 (void)POPMARK; /* pop src */
610 items = --*markstack_ptr - markstack_ptr[-1];
611 (void)POPMARK; /* pop dst */
612 SP = stack_base + POPMARK; /* pop original mark */
613 if (gimme == G_SCALAR) {
617 else if (gimme == G_ARRAY)
624 ENTER; /* enter inner scope */
627 src = stack_base[markstack_ptr[-1]];
631 RETURNOP(cLOGOP->op_other);
638 djSP; dMARK; dORIGMARK;
640 SV **myorigmark = ORIGMARK;
646 OP* nextop = op->op_next;
648 if (gimme != G_ARRAY) {
653 if (op->op_flags & OPf_STACKED) {
655 if (op->op_flags & OPf_SPECIAL) {
656 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
657 kid = kUNOP->op_first; /* pass rv2gv */
658 kid = kUNOP->op_first; /* pass leave */
659 sortcop = kid->op_next;
660 stash = curcop->cop_stash;
663 cv = sv_2cv(*++MARK, &stash, &gv, 0);
664 if (!(cv && CvROOT(cv))) {
666 SV *tmpstr = sv_newmortal();
667 gv_efullname3(tmpstr, gv, Nullch);
668 if (cv && CvXSUB(cv))
669 DIE("Xsub \"%s\" called in sort", SvPVX(tmpstr));
670 DIE("Undefined sort subroutine \"%s\" called",
675 DIE("Xsub called in sort");
676 DIE("Undefined subroutine in sort");
678 DIE("Not a CODE reference in sort");
680 sortcop = CvSTART(cv);
681 SAVESPTR(CvROOT(cv)->op_ppaddr);
682 CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
685 curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
690 stash = curcop->cop_stash;
694 while (MARK < SP) { /* This may or may not shift down one here. */
696 if (*up = *++MARK) { /* Weed out nulls. */
698 if (!sortcop && !SvPOK(*up))
699 (void)sv_2pv(*up, &na);
703 max = --up - myorigmark;
709 bool oldcatch = CATCH_GET;
717 AvREAL_off(sortstack);
718 av_extend(sortstack, 32);
721 SWITCHSTACK(curstack, sortstack);
722 if (sortstash != stash) {
723 firstgv = gv_fetchpv("a", TRUE, SVt_PV);
724 secondgv = gv_fetchpv("b", TRUE, SVt_PV);
728 SAVESPTR(GvSV(firstgv));
729 SAVESPTR(GvSV(secondgv));
731 PUSHBLOCK(cx, CXt_NULL, stack_base);
732 if (!(op->op_flags & OPf_SPECIAL)) {
733 bool hasargs = FALSE;
734 cx->cx_type = CXt_SUB;
735 cx->blk_gimme = G_SCALAR;
738 (void)SvREFCNT_inc(cv); /* in preparation for POPSUB */
740 sortcxix = cxstack_ix;
742 qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
745 SWITCHSTACK(sortstack, oldstack);
752 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
753 qsort((char*)(ORIGMARK+1), max, sizeof(SV*),
754 (op->op_private & OPpLOCALE) ? sortcmp_locale : sortcmp);
757 stack_sp = ORIGMARK + max;
765 if (GIMME == G_ARRAY)
766 return cCONDOP->op_true;
767 return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
774 if (GIMME == G_ARRAY) {
775 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
779 SV *targ = PAD_SV(op->op_targ);
781 if ((op->op_private & OPpFLIP_LINENUM)
782 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
784 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
785 if (op->op_flags & OPf_SPECIAL) {
793 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
806 if (GIMME == G_ARRAY) {
812 if (SvNIOKp(left) || !SvPOKp(left) ||
813 (looks_like_number(left) && *SvPVX(left) != '0') )
818 EXTEND_MORTAL(max - i + 1);
819 EXTEND(SP, max - i + 1);
822 sv = sv_2mortal(newSViv(i++));
827 SV *final = sv_mortalcopy(right);
829 char *tmps = SvPV(final, len);
831 sv = sv_mortalcopy(left);
832 while (!SvNIOKp(sv) && SvCUR(sv) <= len &&
833 strNE(SvPVX(sv),tmps) ) {
835 sv = sv_2mortal(newSVsv(sv));
838 if (strEQ(SvPVX(sv),tmps))
844 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
846 if ((op->op_private & OPpFLIP_LINENUM)
847 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
849 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
850 sv_catpv(targ, "E0");
861 dopoptolabel(char *label)
865 register PERL_CONTEXT *cx;
867 for (i = cxstack_ix; i >= 0; i--) {
869 switch (cx->cx_type) {
872 warn("Exiting substitution via %s", op_name[op->op_type]);
876 warn("Exiting subroutine via %s", op_name[op->op_type]);
880 warn("Exiting eval via %s", op_name[op->op_type]);
884 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
887 if (!cx->blk_loop.label ||
888 strNE(label, cx->blk_loop.label) ) {
889 DEBUG_l(deb("(Skipping label #%ld %s)\n",
890 (long)i, cx->blk_loop.label));
893 DEBUG_l( deb("(Found label #%ld %s)\n", (long)i, label));
903 I32 gimme = block_gimme();
904 return (gimme == G_VOID) ? G_SCALAR : gimme;
913 cxix = dopoptosub(cxstack_ix);
917 switch (cxstack[cxix].blk_gimme) {
923 croak("panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
930 dopoptosub(I32 startingblock)
934 register PERL_CONTEXT *cx;
935 for (i = startingblock; i >= 0; i--) {
937 switch (cx->cx_type) {
942 DEBUG_l( deb("(Found sub #%ld)\n", (long)i));
950 dopoptoeval(I32 startingblock)
954 register PERL_CONTEXT *cx;
955 for (i = startingblock; i >= 0; i--) {
957 switch (cx->cx_type) {
961 DEBUG_l( deb("(Found eval #%ld)\n", (long)i));
969 dopoptoloop(I32 startingblock)
973 register PERL_CONTEXT *cx;
974 for (i = startingblock; i >= 0; i--) {
976 switch (cx->cx_type) {
979 warn("Exiting substitution via %s", op_name[op->op_type]);
983 warn("Exiting subroutine via %s", op_name[op->op_type]);
987 warn("Exiting eval via %s", op_name[op->op_type]);
991 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
994 DEBUG_l( deb("(Found loop #%ld)\n", (long)i));
1005 register PERL_CONTEXT *cx;
1009 while (cxstack_ix > cxix) {
1010 cx = &cxstack[cxstack_ix];
1011 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n",
1012 (long) cxstack_ix+1, block_type[cx->cx_type]));
1013 /* Note: we don't need to restore the base context info till the end. */
1014 switch (cx->cx_type) {
1017 continue; /* not break */
1035 die_where(char *message)
1040 register PERL_CONTEXT *cx;
1046 STRLEN klen = strlen(message);
1048 svp = hv_fetch(ERRHV, message, klen, TRUE);
1051 static char prefix[] = "\t(in cleanup) ";
1052 sv_upgrade(*svp, SVt_IV);
1053 (void)SvIOK_only(*svp);
1054 SvGROW(ERRSV, SvCUR(ERRSV)+sizeof(prefix)+klen);
1055 sv_catpvn(ERRSV, prefix, sizeof(prefix)-1);
1056 sv_catpvn(ERRSV, message, klen);
1062 sv_setpv(ERRSV, message);
1064 cxix = dopoptoeval(cxstack_ix);
1068 if (cxix < cxstack_ix)
1072 if (cx->cx_type != CXt_EVAL) {
1073 PerlIO_printf(PerlIO_stderr(), "panic: die %s", message);
1078 if (gimme == G_SCALAR)
1079 *++newsp = &sv_undef;
1084 if (optype == OP_REQUIRE) {
1085 char* msg = SvPVx(ERRSV, na);
1086 DIE("%s", *msg ? msg : "Compilation failed in require");
1088 return pop_return();
1091 PerlIO_printf(PerlIO_stderr(), "%s",message);
1092 PerlIO_flush(PerlIO_stderr());
1101 if (SvTRUE(left) != SvTRUE(right))
1113 RETURNOP(cLOGOP->op_other);
1122 RETURNOP(cLOGOP->op_other);
1128 register I32 cxix = dopoptosub(cxstack_ix);
1129 register PERL_CONTEXT *cx;
1140 if (GIMME != G_ARRAY)
1144 if (DBsub && cxix >= 0 &&
1145 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1149 cxix = dopoptosub(cxix - 1);
1151 cx = &cxstack[cxix];
1152 if (cxstack[cxix].cx_type == CXt_SUB) {
1153 dbcxix = dopoptosub(cxix - 1);
1154 /* We expect that cxstack[dbcxix] is CXt_SUB, anyway, the
1155 field below is defined for any cx. */
1156 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1157 cx = &cxstack[dbcxix];
1160 if (GIMME != G_ARRAY) {
1163 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1168 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1169 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1170 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1173 if (cx->cx_type == CXt_SUB) { /* So is cxstack[dbcxix]. */
1175 gv_efullname3(sv, CvGV(cxstack[cxix].blk_sub.cv), Nullch);
1176 PUSHs(sv_2mortal(sv));
1177 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1180 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1181 PUSHs(sv_2mortal(newSViv(0)));
1183 gimme = (I32)cx->blk_gimme;
1184 if (gimme == G_VOID)
1187 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1188 if (cx->cx_type == CXt_EVAL) {
1189 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1190 PUSHs(cx->blk_eval.cur_text);
1193 else if (cx->blk_eval.old_name) { /* Try blocks have old_name == 0. */
1194 /* Require, put the name. */
1195 PUSHs(sv_2mortal(newSVpv(cx->blk_eval.old_name, 0)));
1199 else if (cx->cx_type == CXt_SUB &&
1200 cx->blk_sub.hasargs &&
1201 curcop->cop_stash == debstash)
1203 AV *ary = cx->blk_sub.argarray;
1204 int off = AvARRAY(ary) - AvALLOC(ary);
1208 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1211 AvREAL_off(dbargs); /* XXX Should be REIFY */
1214 if (AvMAX(dbargs) < AvFILL(ary) + off)
1215 av_extend(dbargs, AvFILL(ary) + off);
1216 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1217 AvFILL(dbargs) = AvFILL(ary) + off;
1223 sortcv(const void *a, const void *b)
1226 SV * const *str1 = (SV * const *)a;
1227 SV * const *str2 = (SV * const *)b;
1228 I32 oldsaveix = savestack_ix;
1229 I32 oldscopeix = scopestack_ix;
1231 GvSV(firstgv) = *str1;
1232 GvSV(secondgv) = *str2;
1233 stack_sp = stack_base;
1236 if (stack_sp != stack_base + 1)
1237 croak("Sort subroutine didn't return single value");
1238 if (!SvNIOKp(*stack_sp))
1239 croak("Sort subroutine didn't return a numeric value");
1240 result = SvIV(*stack_sp);
1241 while (scopestack_ix > oldscopeix) {
1244 leave_scope(oldsaveix);
1249 sortcmp(const void *a, const void *b)
1251 return sv_cmp(*(SV * const *)a, *(SV * const *)b);
1255 sortcmp_locale(const void *a, const void *b)
1257 return sv_cmp_locale(*(SV * const *)a, *(SV * const *)b);
1269 sv_reset(tmps, curcop->cop_stash);
1282 TAINT_NOT; /* Each statement is presumed innocent */
1283 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1286 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1290 register PERL_CONTEXT *cx;
1291 I32 gimme = G_ARRAY;
1298 DIE("No DB::DB routine defined");
1300 if (CvDEPTH(cv) >= 1 && !(debug & (1<<30))) /* don't do recursive DB::DB call */
1312 push_return(op->op_next);
1313 PUSHBLOCK(cx, CXt_SUB, sp);
1316 (void)SvREFCNT_inc(cv);
1318 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1319 RETURNOP(CvSTART(cv));
1333 register PERL_CONTEXT *cx;
1334 I32 gimme = GIMME_V;
1341 if (op->op_flags & OPf_SPECIAL)
1342 svp = save_threadsv(op->op_targ); /* per-thread variable */
1344 #endif /* USE_THREADS */
1346 svp = &curpad[op->op_targ]; /* "my" variable */
1350 svp = &GvSV((GV*)POPs); /* symbol table variable */
1356 PUSHBLOCK(cx, CXt_LOOP, SP);
1357 PUSHLOOP(cx, svp, MARK);
1358 if (op->op_flags & OPf_STACKED)
1359 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1361 cx->blk_loop.iterary = curstack;
1362 AvFILL(curstack) = sp - stack_base;
1363 cx->blk_loop.iterix = MARK - stack_base;
1372 register PERL_CONTEXT *cx;
1373 I32 gimme = GIMME_V;
1379 PUSHBLOCK(cx, CXt_LOOP, SP);
1380 PUSHLOOP(cx, 0, SP);
1388 register PERL_CONTEXT *cx;
1389 struct block_loop cxloop;
1397 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1400 if (gimme == G_VOID)
1402 else if (gimme == G_SCALAR) {
1404 *++newsp = sv_mortalcopy(*SP);
1406 *++newsp = &sv_undef;
1410 *++newsp = sv_mortalcopy(*++mark);
1411 TAINT_NOT; /* Each item is independent */
1417 POPLOOP2(); /* Stack values are safe: release loop vars ... */
1418 curpm = newpm; /* ... and pop $1 et al */
1430 register PERL_CONTEXT *cx;
1431 struct block_sub cxsub;
1432 bool popsub2 = FALSE;
1438 if (curstack == sortstack) {
1439 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) <= sortcxix) {
1440 if (cxstack_ix > sortcxix)
1442 AvARRAY(curstack)[1] = *SP;
1443 stack_sp = stack_base + 1;
1448 cxix = dopoptosub(cxstack_ix);
1450 DIE("Can't return outside a subroutine");
1451 if (cxix < cxstack_ix)
1455 switch (cx->cx_type) {
1457 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1462 if (optype == OP_REQUIRE &&
1463 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1465 /* Unassume the success we assumed earlier. */
1466 char *name = cx->blk_eval.old_name;
1467 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1468 DIE("%s did not return a true value", name);
1472 DIE("panic: return");
1476 if (gimme == G_SCALAR) {
1478 *++newsp = (popsub2 && SvTEMP(*SP))
1479 ? *SP : sv_mortalcopy(*SP);
1481 *++newsp = &sv_undef;
1483 else if (gimme == G_ARRAY) {
1484 while (++MARK <= SP) {
1485 *++newsp = (popsub2 && SvTEMP(*MARK))
1486 ? *MARK : sv_mortalcopy(*MARK);
1487 TAINT_NOT; /* Each item is independent */
1492 /* Stack values are safe: */
1494 POPSUB2(); /* release CV and @_ ... */
1496 curpm = newpm; /* ... and pop $1 et al */
1499 return pop_return();
1506 register PERL_CONTEXT *cx;
1507 struct block_loop cxloop;
1508 struct block_sub cxsub;
1515 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1517 if (op->op_flags & OPf_SPECIAL) {
1518 cxix = dopoptoloop(cxstack_ix);
1520 DIE("Can't \"last\" outside a block");
1523 cxix = dopoptolabel(cPVOP->op_pv);
1525 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1527 if (cxix < cxstack_ix)
1531 switch (cx->cx_type) {
1533 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1535 nextop = cxloop.last_op->op_next;
1538 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1540 nextop = pop_return();
1544 nextop = pop_return();
1551 if (gimme == G_SCALAR) {
1553 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
1554 ? *SP : sv_mortalcopy(*SP);
1556 *++newsp = &sv_undef;
1558 else if (gimme == G_ARRAY) {
1559 while (++MARK <= SP) {
1560 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
1561 ? *MARK : sv_mortalcopy(*MARK);
1562 TAINT_NOT; /* Each item is independent */
1568 /* Stack values are safe: */
1571 POPLOOP2(); /* release loop vars ... */
1575 POPSUB2(); /* release CV and @_ ... */
1578 curpm = newpm; /* ... and pop $1 et al */
1587 register PERL_CONTEXT *cx;
1590 if (op->op_flags & OPf_SPECIAL) {
1591 cxix = dopoptoloop(cxstack_ix);
1593 DIE("Can't \"next\" outside a block");
1596 cxix = dopoptolabel(cPVOP->op_pv);
1598 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1600 if (cxix < cxstack_ix)
1604 oldsave = scopestack[scopestack_ix - 1];
1605 LEAVE_SCOPE(oldsave);
1606 return cx->blk_loop.next_op;
1612 register PERL_CONTEXT *cx;
1615 if (op->op_flags & OPf_SPECIAL) {
1616 cxix = dopoptoloop(cxstack_ix);
1618 DIE("Can't \"redo\" outside a block");
1621 cxix = dopoptolabel(cPVOP->op_pv);
1623 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1625 if (cxix < cxstack_ix)
1629 oldsave = scopestack[scopestack_ix - 1];
1630 LEAVE_SCOPE(oldsave);
1631 return cx->blk_loop.redo_op;
1634 static OP* lastgotoprobe;
1637 dofindlabel(OP *o, char *label, OP **opstack, OP **oplimit)
1641 static char too_deep[] = "Target of goto is too deeply nested";
1645 if (o->op_type == OP_LEAVE ||
1646 o->op_type == OP_SCOPE ||
1647 o->op_type == OP_LEAVELOOP ||
1648 o->op_type == OP_LEAVETRY)
1650 *ops++ = cUNOPo->op_first;
1655 if (o->op_flags & OPf_KIDS) {
1656 /* First try all the kids at this level, since that's likeliest. */
1657 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1658 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1659 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1662 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1663 if (kid == lastgotoprobe)
1665 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1667 (ops[-1]->op_type != OP_NEXTSTATE &&
1668 ops[-1]->op_type != OP_DBSTATE)))
1670 if (o = dofindlabel(kid, label, ops, oplimit))
1680 return pp_goto(ARGS);
1689 register PERL_CONTEXT *cx;
1690 #define GOTO_DEPTH 64
1691 OP *enterops[GOTO_DEPTH];
1693 int do_dump = (op->op_type == OP_DUMP);
1696 if (op->op_flags & OPf_STACKED) {
1699 /* This egregious kludge implements goto &subroutine */
1700 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1702 register PERL_CONTEXT *cx;
1703 CV* cv = (CV*)SvRV(sv);
1708 if (!CvROOT(cv) && !CvXSUB(cv)) {
1710 SV *tmpstr = sv_newmortal();
1711 gv_efullname3(tmpstr, CvGV(cv), Nullch);
1712 DIE("Goto undefined subroutine &%s",SvPVX(tmpstr));
1714 DIE("Goto undefined subroutine");
1717 /* First do some returnish stuff. */
1718 cxix = dopoptosub(cxstack_ix);
1720 DIE("Can't goto subroutine outside a subroutine");
1721 if (cxix < cxstack_ix)
1725 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1726 AV* av = cx->blk_sub.argarray;
1728 items = AvFILL(av) + 1;
1730 EXTEND(stack_sp, items); /* @_ could have been extended. */
1731 Copy(AvARRAY(av), stack_sp, items, SV*);
1734 SvREFCNT_dec(GvAV(defgv));
1735 GvAV(defgv) = cx->blk_sub.savearray;
1736 #endif /* USE_THREADS */
1740 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1741 SvREFCNT_dec(cx->blk_sub.cv);
1742 oldsave = scopestack[scopestack_ix - 1];
1743 LEAVE_SCOPE(oldsave);
1745 /* Now do some callish stuff. */
1748 if (CvOLDSTYLE(cv)) {
1749 I32 (*fp3)_((int,int,int));
1754 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1755 items = (*fp3)(CvXSUBANY(cv).any_i32,
1756 mark - stack_base + 1,
1758 sp = stack_base + items;
1761 stack_sp--; /* There is no cv arg. */
1762 (void)(*CvXSUB(cv))(cv);
1765 return pop_return();
1768 AV* padlist = CvPADLIST(cv);
1769 SV** svp = AvARRAY(padlist);
1770 cx->blk_sub.cv = cv;
1771 cx->blk_sub.olddepth = CvDEPTH(cv);
1773 if (CvDEPTH(cv) < 2)
1774 (void)SvREFCNT_inc(cv);
1775 else { /* save temporaries on recursion? */
1776 if (CvDEPTH(cv) == 100 && dowarn)
1777 sub_crush_depth(cv);
1778 if (CvDEPTH(cv) > AvFILL(padlist)) {
1779 AV *newpad = newAV();
1780 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
1781 I32 ix = AvFILL((AV*)svp[1]);
1782 svp = AvARRAY(svp[0]);
1783 for ( ;ix > 0; ix--) {
1784 if (svp[ix] != &sv_undef) {
1785 char *name = SvPVX(svp[ix]);
1786 if ((SvFLAGS(svp[ix]) & SVf_FAKE)
1789 /* outer lexical or anon code */
1790 av_store(newpad, ix,
1791 SvREFCNT_inc(oldpad[ix]) );
1793 else { /* our own lexical */
1795 av_store(newpad, ix, sv = (SV*)newAV());
1796 else if (*name == '%')
1797 av_store(newpad, ix, sv = (SV*)newHV());
1799 av_store(newpad, ix, sv = NEWSV(0,0));
1804 av_store(newpad, ix, sv = NEWSV(0,0));
1808 if (cx->blk_sub.hasargs) {
1811 av_store(newpad, 0, (SV*)av);
1812 AvFLAGS(av) = AVf_REIFY;
1814 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1815 AvFILL(padlist) = CvDEPTH(cv);
1816 svp = AvARRAY(padlist);
1820 if (!cx->blk_sub.hasargs) {
1821 AV* av = (AV*)curpad[0];
1823 items = AvFILL(av) + 1;
1825 /* Mark is at the end of the stack. */
1827 Copy(AvARRAY(av), sp + 1, items, SV*);
1832 #endif /* USE_THREADS */
1834 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1836 if (cx->blk_sub.hasargs)
1837 #endif /* USE_THREADS */
1839 AV* av = (AV*)curpad[0];
1843 cx->blk_sub.savearray = GvAV(defgv);
1844 GvAV(defgv) = (AV*)SvREFCNT_inc(av);
1845 #endif /* USE_THREADS */
1846 cx->blk_sub.argarray = av;
1849 if (items >= AvMAX(av) + 1) {
1851 if (AvARRAY(av) != ary) {
1852 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1853 SvPVX(av) = (char*)ary;
1855 if (items >= AvMAX(av) + 1) {
1856 AvMAX(av) = items - 1;
1857 Renew(ary,items+1,SV*);
1859 SvPVX(av) = (char*)ary;
1862 Copy(mark,AvARRAY(av),items,SV*);
1863 AvFILL(av) = items - 1;
1871 if (PERLDB_SUB && curstash != debstash) {
1873 * We do not care about using sv to call CV;
1874 * it's for informational purposes only.
1876 SV *sv = GvSV(DBsub);
1878 gv_efullname3(sv, CvGV(cv), Nullch);
1880 RETURNOP(CvSTART(cv));
1884 label = SvPV(sv,na);
1886 else if (op->op_flags & OPf_SPECIAL) {
1888 DIE("goto must have label");
1891 label = cPVOP->op_pv;
1893 if (label && *label) {
1900 for (ix = cxstack_ix; ix >= 0; ix--) {
1902 switch (cx->cx_type) {
1904 gotoprobe = eval_root; /* XXX not good for nested eval */
1907 gotoprobe = cx->blk_oldcop->op_sibling;
1913 gotoprobe = cx->blk_oldcop->op_sibling;
1915 gotoprobe = main_root;
1918 if (CvDEPTH(cx->blk_sub.cv)) {
1919 gotoprobe = CvROOT(cx->blk_sub.cv);
1924 DIE("Can't \"goto\" outside a block");
1928 gotoprobe = main_root;
1931 retop = dofindlabel(gotoprobe, label,
1932 enterops, enterops + GOTO_DEPTH);
1935 lastgotoprobe = gotoprobe;
1938 DIE("Can't find label %s", label);
1940 /* pop unwanted frames */
1942 if (ix < cxstack_ix) {
1949 oldsave = scopestack[scopestack_ix];
1950 LEAVE_SCOPE(oldsave);
1953 /* push wanted frames */
1955 if (*enterops && enterops[1]) {
1957 for (ix = 1; enterops[ix]; ix++) {
1959 /* Eventually we may want to stack the needed arguments
1960 * for each op. For now, we punt on the hard ones. */
1961 if (op->op_type == OP_ENTERITER)
1962 DIE("Can't \"goto\" into the middle of a foreach loop",
1964 (*op->op_ppaddr)(ARGS);
1972 if (!retop) retop = main_start;
1979 restartop = 0; /* hmm, must be GNU unexec().. */
1983 if (curstack == signalstack) {
2001 if (anum == 1 && VMSISH_EXIT)
2014 double value = SvNVx(GvSV(cCOP->cop_gv));
2015 register I32 match = I_32(value);
2018 if (((double)match) > value)
2019 --match; /* was fractional--truncate other way */
2021 match -= cCOP->uop.scop.scop_offset;
2024 else if (match > cCOP->uop.scop.scop_max)
2025 match = cCOP->uop.scop.scop_max;
2026 op = cCOP->uop.scop.scop_next[match];
2036 op = op->op_next; /* can't assume anything */
2038 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
2039 match -= cCOP->uop.scop.scop_offset;
2042 else if (match > cCOP->uop.scop.scop_max)
2043 match = cCOP->uop.scop.scop_max;
2044 op = cCOP->uop.scop.scop_next[match];
2053 save_lines(AV *array, SV *sv)
2055 register char *s = SvPVX(sv);
2056 register char *send = SvPVX(sv) + SvCUR(sv);
2058 register I32 line = 1;
2060 while (s && s < send) {
2061 SV *tmpstr = NEWSV(85,0);
2063 sv_upgrade(tmpstr, SVt_PVMG);
2064 t = strchr(s, '\n');
2070 sv_setpvn(tmpstr, s, t - s);
2071 av_store(array, line++, tmpstr);
2086 assert(CATCH_GET == TRUE);
2087 DEBUG_l(deb("Setting up local jumplevel %p, was %p\n", &cur_env, top_env));
2091 default: /* topmost level handles it */
2098 PerlIO_printf(PerlIO_stderr(), "panic: restartop\n");
2114 sv_compile_2op(SV *sv, OP** startop, char *code, AV** avp)
2115 /* sv Text to convert to OP tree. */
2116 /* startop op_free() this to undo. */
2117 /* code Short string id of the caller. */
2119 dSP; /* Make POPBLOCK work. */
2122 I32 gimme = 0; /* SUSPECT - INITIALZE TO WHAT? NI-S */
2126 char tmpbuf[TYPE_DIGITS(long) + 12 + 10];
2132 /* switch to eval mode */
2134 SAVESPTR(compiling.cop_filegv);
2135 SAVEI16(compiling.cop_line);
2136 sprintf(tmpbuf, "_<(%.10s_eval %lu)", code, (unsigned long)++evalseq);
2137 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2138 compiling.cop_line = 1;
2139 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2140 deleting the eval's FILEGV from the stash before gv_check() runs
2141 (i.e. before run-time proper). To work around the coredump that
2142 ensues, we always turn GvMULTI_on for any globals that were
2143 introduced within evals. See force_ident(). GSAR 96-10-12 */
2144 safestr = savepv(tmpbuf);
2145 SAVEDELETE(defstash, safestr, strlen(safestr));
2151 op->op_type = 0; /* Avoid uninit warning. */
2152 op->op_flags = 0; /* Avoid uninit warning. */
2153 PUSHBLOCK(cx, CXt_EVAL, SP);
2154 PUSHEVAL(cx, 0, compiling.cop_filegv);
2155 rop = doeval(G_SCALAR, startop);
2159 (*startop)->op_type = OP_NULL;
2160 (*startop)->op_ppaddr = ppaddr[OP_NULL];
2162 *avp = (AV*)SvREFCNT_inc(comppad);
2167 /* With USE_THREADS, eval_owner must be held on entry to doeval */
2169 doeval(int gimme, OP** startop)
2181 /* set up a scratch pad */
2186 SAVESPTR(comppad_name);
2187 SAVEI32(comppad_name_fill);
2188 SAVEI32(min_intro_pending);
2189 SAVEI32(max_intro_pending);
2193 compcv = (CV*)NEWSV(1104,0);
2194 sv_upgrade((SV *)compcv, SVt_PVCV);
2195 CvUNIQUE_on(compcv);
2197 CvOWNER(compcv) = 0;
2198 New(666, CvMUTEXP(compcv), 1, perl_mutex);
2199 MUTEX_INIT(CvMUTEXP(compcv));
2200 #endif /* USE_THREADS */
2203 av_push(comppad, Nullsv);
2204 curpad = AvARRAY(comppad);
2205 comppad_name = newAV();
2206 comppad_name_fill = 0;
2207 min_intro_pending = 0;
2210 av_store(comppad_name, 0, newSVpv("@_", 2));
2211 curpad[0] = (SV*)newAV();
2212 SvPADMY_on(curpad[0]); /* XXX Needed? */
2213 #endif /* USE_THREADS */
2215 comppadlist = newAV();
2216 AvREAL_off(comppadlist);
2217 av_store(comppadlist, 0, (SV*)comppad_name);
2218 av_store(comppadlist, 1, (SV*)comppad);
2219 CvPADLIST(compcv) = comppadlist;
2221 if (!saveop || saveop->op_type != OP_REQUIRE)
2222 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc(caller);
2226 /* make sure we compile in the right package */
2228 newstash = curcop->cop_stash;
2229 if (curstash != newstash) {
2231 curstash = newstash;
2235 SAVEFREESV(beginav);
2237 /* try to compile it */
2241 curcop = &compiling;
2242 curcop->cop_arybase = 0;
2244 rs = newSVpv("\n", 1);
2245 if (saveop && saveop->op_flags & OPf_SPECIAL)
2249 if (yyparse() || error_count || !eval_root) {
2253 I32 optype = 0; /* Might be reset by POPEVAL. */
2260 SP = stack_base + POPMARK; /* pop original mark */
2268 if (optype == OP_REQUIRE) {
2269 char* msg = SvPVx(ERRSV, na);
2270 DIE("%s", *msg ? msg : "Compilation failed in require");
2271 } else if (startop) {
2272 char* msg = SvPVx(ERRSV, na);
2276 croak("%sCompilation failed in regexp", (*msg ? msg : "Unknown error\n"));
2279 rs = SvREFCNT_inc(nrs);
2281 MUTEX_LOCK(&eval_mutex);
2283 COND_SIGNAL(&eval_cond);
2284 MUTEX_UNLOCK(&eval_mutex);
2285 #endif /* USE_THREADS */
2289 rs = SvREFCNT_inc(nrs);
2290 compiling.cop_line = 0;
2292 *startop = eval_root;
2293 SvREFCNT_dec(CvOUTSIDE(compcv));
2294 CvOUTSIDE(compcv) = Nullcv;
2296 SAVEFREEOP(eval_root);
2298 scalarvoid(eval_root);
2299 else if (gimme & G_ARRAY)
2304 DEBUG_x(dump_eval());
2306 /* Register with debugger: */
2307 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2308 CV *cv = perl_get_cv("DB::postponed", FALSE);
2312 XPUSHs((SV*)compiling.cop_filegv);
2314 perl_call_sv((SV*)cv, G_DISCARD);
2318 /* compiled okay, so do it */
2320 CvDEPTH(compcv) = 1;
2321 SP = stack_base + POPMARK; /* pop original mark */
2322 op = saveop; /* The caller may need it. */
2324 MUTEX_LOCK(&eval_mutex);
2326 COND_SIGNAL(&eval_cond);
2327 MUTEX_UNLOCK(&eval_mutex);
2328 #endif /* USE_THREADS */
2330 RETURNOP(eval_start);
2336 register PERL_CONTEXT *cx;
2340 SV *namesv = Nullsv;
2342 I32 gimme = G_SCALAR;
2343 PerlIO *tryrsfp = 0;
2346 if (SvNIOKp(sv) && !SvPOKp(sv)) {
2347 SET_NUMERIC_STANDARD();
2348 if (atof(patchlevel) + 0.00000999 < SvNV(sv))
2349 DIE("Perl %s required--this is only version %s, stopped",
2350 SvPV(sv,na),patchlevel);
2353 name = SvPV(sv, na);
2355 DIE("Null filename used");
2356 TAINT_PROPER("require");
2357 if (op->op_type == OP_REQUIRE &&
2358 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
2362 /* prepare to compile file */
2367 (name[1] == '.' && name[2] == '/')))
2369 || (name[0] && name[1] == ':')
2372 || (name[0] == '\\' && name[1] == '\\') /* UNC path */
2375 || (strchr(name,':') || ((*name == '[' || *name == '<') &&
2376 (isALNUM(name[1]) || strchr("$-_]>",name[1]))))
2381 tryrsfp = PerlIO_open(name,PERL_SCRIPT_MODE);
2384 AV *ar = GvAVn(incgv);
2388 if ((unixname = tounixspec(name, Nullch)) != Nullch)
2391 namesv = NEWSV(806, 0);
2392 for (i = 0; i <= AvFILL(ar); i++) {
2393 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2396 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
2398 sv_setpv(namesv, unixdir);
2399 sv_catpv(namesv, unixname);
2401 sv_setpvf(namesv, "%s/%s", dir, name);
2403 tryname = SvPVX(namesv);
2404 tryrsfp = PerlIO_open(tryname, PERL_SCRIPT_MODE);
2406 if (tryname[0] == '.' && tryname[1] == '/')
2413 SAVESPTR(compiling.cop_filegv);
2414 compiling.cop_filegv = gv_fetchfile(tryrsfp ? tryname : name);
2415 SvREFCNT_dec(namesv);
2417 if (op->op_type == OP_REQUIRE) {
2418 SV *msg = sv_2mortal(newSVpvf("Can't locate %s in @INC", name));
2419 SV *dirmsgsv = NEWSV(0, 0);
2420 AV *ar = GvAVn(incgv);
2422 if (instr(SvPVX(msg), ".h "))
2423 sv_catpv(msg, " (change .h to .ph maybe?)");
2424 if (instr(SvPVX(msg), ".ph "))
2425 sv_catpv(msg, " (did you run h2ph?)");
2426 sv_catpv(msg, " (@INC contains:");
2427 for (i = 0; i <= AvFILL(ar); i++) {
2428 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2429 sv_setpvf(dirmsgsv, " %s", dir);
2430 sv_catsv(msg, dirmsgsv);
2432 sv_catpvn(msg, ")", 1);
2433 SvREFCNT_dec(dirmsgsv);
2440 /* Assume success here to prevent recursive requirement. */
2441 (void)hv_store(GvHVn(incgv), name, strlen(name),
2442 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2446 lex_start(sv_2mortal(newSVpv("",0)));
2448 save_aptr(&rsfp_filters);
2449 rsfp_filters = NULL;
2453 name = savepv(name);
2458 /* switch to eval mode */
2460 push_return(op->op_next);
2461 PUSHBLOCK(cx, CXt_EVAL, SP);
2462 PUSHEVAL(cx, name, compiling.cop_filegv);
2464 compiling.cop_line = 0;
2468 MUTEX_LOCK(&eval_mutex);
2469 if (eval_owner && eval_owner != thr)
2471 COND_WAIT(&eval_cond, &eval_mutex);
2473 MUTEX_UNLOCK(&eval_mutex);
2474 #endif /* USE_THREADS */
2475 return DOCATCH(doeval(G_SCALAR, NULL));
2480 return pp_require(ARGS);
2486 register PERL_CONTEXT *cx;
2488 I32 gimme = GIMME_V, was = sub_generation;
2489 char tmpbuf[TYPE_DIGITS(long) + 12];
2494 if (!SvPV(sv,len) || !len)
2496 TAINT_PROPER("eval");
2502 /* switch to eval mode */
2504 SAVESPTR(compiling.cop_filegv);
2505 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++evalseq);
2506 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2507 compiling.cop_line = 1;
2508 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2509 deleting the eval's FILEGV from the stash before gv_check() runs
2510 (i.e. before run-time proper). To work around the coredump that
2511 ensues, we always turn GvMULTI_on for any globals that were
2512 introduced within evals. See force_ident(). GSAR 96-10-12 */
2513 safestr = savepv(tmpbuf);
2514 SAVEDELETE(defstash, safestr, strlen(safestr));
2516 hints = op->op_targ;
2518 push_return(op->op_next);
2519 PUSHBLOCK(cx, CXt_EVAL, SP);
2520 PUSHEVAL(cx, 0, compiling.cop_filegv);
2522 /* prepare to compile string */
2524 if (PERLDB_LINE && curstash != debstash)
2525 save_lines(GvAV(compiling.cop_filegv), linestr);
2528 MUTEX_LOCK(&eval_mutex);
2529 if (eval_owner && eval_owner != thr)
2531 COND_WAIT(&eval_cond, &eval_mutex);
2533 MUTEX_UNLOCK(&eval_mutex);
2534 #endif /* USE_THREADS */
2535 ret = doeval(gimme, NULL);
2536 if (PERLDB_INTER && was != sub_generation /* Some subs defined here. */
2537 && ret != op->op_next) { /* Successive compilation. */
2538 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
2540 return DOCATCH(ret);
2550 register PERL_CONTEXT *cx;
2552 U8 save_flags = op -> op_flags;
2557 retop = pop_return();
2560 if (gimme == G_VOID)
2562 else if (gimme == G_SCALAR) {
2565 if (SvFLAGS(TOPs) & SVs_TEMP)
2568 *MARK = sv_mortalcopy(TOPs);
2576 /* in case LEAVE wipes old return values */
2577 for (mark = newsp + 1; mark <= SP; mark++) {
2578 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
2579 *mark = sv_mortalcopy(*mark);
2580 TAINT_NOT; /* Each item is independent */
2584 curpm = newpm; /* Don't pop $1 et al till now */
2587 * Closures mentioned at top level of eval cannot be referenced
2588 * again, and their presence indirectly causes a memory leak.
2589 * (Note that the fact that compcv and friends are still set here
2590 * is, AFAIK, an accident.) --Chip
2592 if (AvFILL(comppad_name) >= 0) {
2593 SV **svp = AvARRAY(comppad_name);
2595 for (ix = AvFILL(comppad_name); ix >= 0; ix--) {
2597 if (sv && sv != &sv_undef && *SvPVX(sv) == '&') {
2599 svp[ix] = &sv_undef;
2603 SvREFCNT_dec(CvOUTSIDE(sv));
2604 CvOUTSIDE(sv) = Nullcv;
2617 assert(CvDEPTH(compcv) == 1);
2619 CvDEPTH(compcv) = 0;
2621 if (optype == OP_REQUIRE &&
2622 !(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp))
2624 /* Unassume the success we assumed earlier. */
2625 char *name = cx->blk_eval.old_name;
2626 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2627 retop = die("%s did not return a true value", name);
2633 if (!(save_flags & OPf_SPECIAL))
2642 register PERL_CONTEXT *cx;
2643 I32 gimme = GIMME_V;
2648 push_return(cLOGOP->op_other->op_next);
2649 PUSHBLOCK(cx, CXt_EVAL, SP);
2651 eval_root = op; /* Only needed so that goto works right. */
2656 return DOCATCH(op->op_next);
2666 register PERL_CONTEXT *cx;
2674 if (gimme == G_VOID)
2676 else if (gimme == G_SCALAR) {
2679 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2682 *MARK = sv_mortalcopy(TOPs);
2691 /* in case LEAVE wipes old return values */
2692 for (mark = newsp + 1; mark <= SP; mark++) {
2693 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
2694 *mark = sv_mortalcopy(*mark);
2695 TAINT_NOT; /* Each item is independent */
2699 curpm = newpm; /* Don't pop $1 et al till now */
2710 register char *s = SvPV_force(sv, len);
2711 register char *send = s + len;
2712 register char *base;
2713 register I32 skipspaces = 0;
2716 bool postspace = FALSE;
2724 croak("Null picture in formline");
2726 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
2731 *fpc++ = FF_LINEMARK;
2732 noblank = repeat = FALSE;
2750 case ' ': case '\t':
2761 *fpc++ = FF_LITERAL;
2769 *fpc++ = skipspaces;
2773 *fpc++ = FF_NEWLINE;
2777 arg = fpc - linepc + 1;
2784 *fpc++ = FF_LINEMARK;
2785 noblank = repeat = FALSE;
2794 ischop = s[-1] == '^';
2800 arg = (s - base) - 1;
2802 *fpc++ = FF_LITERAL;
2811 *fpc++ = FF_LINEGLOB;
2813 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2814 arg = ischop ? 512 : 0;
2824 arg |= 256 + (s - f);
2826 *fpc++ = s - base; /* fieldsize for FETCH */
2827 *fpc++ = FF_DECIMAL;
2832 bool ismore = FALSE;
2835 while (*++s == '>') ;
2836 prespace = FF_SPACE;
2838 else if (*s == '|') {
2839 while (*++s == '|') ;
2840 prespace = FF_HALFSPACE;
2845 while (*++s == '<') ;
2848 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2852 *fpc++ = s - base; /* fieldsize for FETCH */
2854 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2872 { /* need to jump to the next word */
2874 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2875 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2876 s = SvPVX(sv) + SvCUR(sv) + z;
2878 Copy(fops, s, arg, U16);
2880 sv_magic(sv, Nullsv, 'f', Nullch, 0);