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 */
550 /* SAVE_DEFSV does *not* suffice here */
551 save_sptr(av_fetch(thr->threadsv, find_threadsv("_"), FALSE));
553 SAVESPTR(GvSV(defgv));
554 #endif /* USE_THREADS */
555 ENTER; /* enter inner scope */
558 src = stack_base[*markstack_ptr];
563 if (op->op_type == OP_MAPSTART)
564 pp_pushmark(ARGS); /* push top */
565 return ((LOGOP*)op->op_next)->op_other;
570 DIE("panic: mapstart"); /* uses grepstart */
576 I32 diff = (sp - stack_base) - *markstack_ptr;
584 if (diff > markstack_ptr[-1] - markstack_ptr[-2]) {
585 shift = diff - (markstack_ptr[-1] - markstack_ptr[-2]);
586 count = (sp - stack_base) - markstack_ptr[-1] + 2;
591 markstack_ptr[-1] += shift;
592 *markstack_ptr += shift;
596 dst = stack_base + (markstack_ptr[-2] += diff) - 1;
599 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
601 LEAVE; /* exit inner scope */
604 if (markstack_ptr[-1] > *markstack_ptr) {
608 (void)POPMARK; /* pop top */
609 LEAVE; /* exit outer scope */
610 (void)POPMARK; /* pop src */
611 items = --*markstack_ptr - markstack_ptr[-1];
612 (void)POPMARK; /* pop dst */
613 SP = stack_base + POPMARK; /* pop original mark */
614 if (gimme == G_SCALAR) {
618 else if (gimme == G_ARRAY)
625 ENTER; /* enter inner scope */
628 src = stack_base[markstack_ptr[-1]];
632 RETURNOP(cLOGOP->op_other);
639 djSP; dMARK; dORIGMARK;
641 SV **myorigmark = ORIGMARK;
647 OP* nextop = op->op_next;
649 if (gimme != G_ARRAY) {
654 if (op->op_flags & OPf_STACKED) {
656 if (op->op_flags & OPf_SPECIAL) {
657 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
658 kid = kUNOP->op_first; /* pass rv2gv */
659 kid = kUNOP->op_first; /* pass leave */
660 sortcop = kid->op_next;
661 stash = curcop->cop_stash;
664 cv = sv_2cv(*++MARK, &stash, &gv, 0);
665 if (!(cv && CvROOT(cv))) {
667 SV *tmpstr = sv_newmortal();
668 gv_efullname3(tmpstr, gv, Nullch);
669 if (cv && CvXSUB(cv))
670 DIE("Xsub \"%s\" called in sort", SvPVX(tmpstr));
671 DIE("Undefined sort subroutine \"%s\" called",
676 DIE("Xsub called in sort");
677 DIE("Undefined subroutine in sort");
679 DIE("Not a CODE reference in sort");
681 sortcop = CvSTART(cv);
682 SAVESPTR(CvROOT(cv)->op_ppaddr);
683 CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
686 curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
691 stash = curcop->cop_stash;
695 while (MARK < SP) { /* This may or may not shift down one here. */
697 if (*up = *++MARK) { /* Weed out nulls. */
699 if (!sortcop && !SvPOK(*up))
700 (void)sv_2pv(*up, &na);
704 max = --up - myorigmark;
710 bool oldcatch = CATCH_GET;
718 AvREAL_off(sortstack);
719 av_extend(sortstack, 32);
722 SWITCHSTACK(curstack, sortstack);
723 if (sortstash != stash) {
724 firstgv = gv_fetchpv("a", TRUE, SVt_PV);
725 secondgv = gv_fetchpv("b", TRUE, SVt_PV);
729 SAVESPTR(GvSV(firstgv));
730 SAVESPTR(GvSV(secondgv));
732 PUSHBLOCK(cx, CXt_NULL, stack_base);
733 if (!(op->op_flags & OPf_SPECIAL)) {
734 bool hasargs = FALSE;
735 cx->cx_type = CXt_SUB;
736 cx->blk_gimme = G_SCALAR;
739 (void)SvREFCNT_inc(cv); /* in preparation for POPSUB */
741 sortcxix = cxstack_ix;
743 qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
746 SWITCHSTACK(sortstack, oldstack);
753 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
754 qsort((char*)(ORIGMARK+1), max, sizeof(SV*),
755 (op->op_private & OPpLOCALE) ? sortcmp_locale : sortcmp);
758 stack_sp = ORIGMARK + max;
766 if (GIMME == G_ARRAY)
767 return cCONDOP->op_true;
768 return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
775 if (GIMME == G_ARRAY) {
776 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
780 SV *targ = PAD_SV(op->op_targ);
782 if ((op->op_private & OPpFLIP_LINENUM)
783 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
785 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
786 if (op->op_flags & OPf_SPECIAL) {
794 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
807 if (GIMME == G_ARRAY) {
813 if (SvNIOKp(left) || !SvPOKp(left) ||
814 (looks_like_number(left) && *SvPVX(left) != '0') )
819 EXTEND_MORTAL(max - i + 1);
820 EXTEND(SP, max - i + 1);
823 sv = sv_2mortal(newSViv(i++));
828 SV *final = sv_mortalcopy(right);
830 char *tmps = SvPV(final, len);
832 sv = sv_mortalcopy(left);
833 while (!SvNIOKp(sv) && SvCUR(sv) <= len &&
834 strNE(SvPVX(sv),tmps) ) {
836 sv = sv_2mortal(newSVsv(sv));
839 if (strEQ(SvPVX(sv),tmps))
845 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
847 if ((op->op_private & OPpFLIP_LINENUM)
848 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
850 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
851 sv_catpv(targ, "E0");
862 dopoptolabel(char *label)
866 register PERL_CONTEXT *cx;
868 for (i = cxstack_ix; i >= 0; i--) {
870 switch (cx->cx_type) {
873 warn("Exiting substitution via %s", op_name[op->op_type]);
877 warn("Exiting subroutine via %s", op_name[op->op_type]);
881 warn("Exiting eval via %s", op_name[op->op_type]);
885 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
888 if (!cx->blk_loop.label ||
889 strNE(label, cx->blk_loop.label) ) {
890 DEBUG_l(deb("(Skipping label #%ld %s)\n",
891 (long)i, cx->blk_loop.label));
894 DEBUG_l( deb("(Found label #%ld %s)\n", (long)i, label));
904 I32 gimme = block_gimme();
905 return (gimme == G_VOID) ? G_SCALAR : gimme;
914 cxix = dopoptosub(cxstack_ix);
918 switch (cxstack[cxix].blk_gimme) {
924 croak("panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
931 dopoptosub(I32 startingblock)
935 register PERL_CONTEXT *cx;
936 for (i = startingblock; i >= 0; i--) {
938 switch (cx->cx_type) {
943 DEBUG_l( deb("(Found sub #%ld)\n", (long)i));
951 dopoptoeval(I32 startingblock)
955 register PERL_CONTEXT *cx;
956 for (i = startingblock; i >= 0; i--) {
958 switch (cx->cx_type) {
962 DEBUG_l( deb("(Found eval #%ld)\n", (long)i));
970 dopoptoloop(I32 startingblock)
974 register PERL_CONTEXT *cx;
975 for (i = startingblock; i >= 0; i--) {
977 switch (cx->cx_type) {
980 warn("Exiting substitution via %s", op_name[op->op_type]);
984 warn("Exiting subroutine via %s", op_name[op->op_type]);
988 warn("Exiting eval via %s", op_name[op->op_type]);
992 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
995 DEBUG_l( deb("(Found loop #%ld)\n", (long)i));
1006 register PERL_CONTEXT *cx;
1010 while (cxstack_ix > cxix) {
1011 cx = &cxstack[cxstack_ix];
1012 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n",
1013 (long) cxstack_ix+1, block_type[cx->cx_type]));
1014 /* Note: we don't need to restore the base context info till the end. */
1015 switch (cx->cx_type) {
1018 continue; /* not break */
1036 die_where(char *message)
1041 register PERL_CONTEXT *cx;
1047 STRLEN klen = strlen(message);
1049 svp = hv_fetch(ERRHV, message, klen, TRUE);
1052 static char prefix[] = "\t(in cleanup) ";
1053 sv_upgrade(*svp, SVt_IV);
1054 (void)SvIOK_only(*svp);
1055 SvGROW(ERRSV, SvCUR(ERRSV)+sizeof(prefix)+klen);
1056 sv_catpvn(ERRSV, prefix, sizeof(prefix)-1);
1057 sv_catpvn(ERRSV, message, klen);
1063 sv_setpv(ERRSV, message);
1065 cxix = dopoptoeval(cxstack_ix);
1069 if (cxix < cxstack_ix)
1073 if (cx->cx_type != CXt_EVAL) {
1074 PerlIO_printf(PerlIO_stderr(), "panic: die %s", message);
1079 if (gimme == G_SCALAR)
1080 *++newsp = &sv_undef;
1085 if (optype == OP_REQUIRE) {
1086 char* msg = SvPVx(ERRSV, na);
1087 DIE("%s", *msg ? msg : "Compilation failed in require");
1089 return pop_return();
1092 PerlIO_printf(PerlIO_stderr(), "%s",message);
1093 PerlIO_flush(PerlIO_stderr());
1102 if (SvTRUE(left) != SvTRUE(right))
1114 RETURNOP(cLOGOP->op_other);
1123 RETURNOP(cLOGOP->op_other);
1129 register I32 cxix = dopoptosub(cxstack_ix);
1130 register PERL_CONTEXT *cx;
1141 if (GIMME != G_ARRAY)
1145 if (DBsub && cxix >= 0 &&
1146 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1150 cxix = dopoptosub(cxix - 1);
1152 cx = &cxstack[cxix];
1153 if (cxstack[cxix].cx_type == CXt_SUB) {
1154 dbcxix = dopoptosub(cxix - 1);
1155 /* We expect that cxstack[dbcxix] is CXt_SUB, anyway, the
1156 field below is defined for any cx. */
1157 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1158 cx = &cxstack[dbcxix];
1161 if (GIMME != G_ARRAY) {
1164 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1169 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1170 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1171 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1174 if (cx->cx_type == CXt_SUB) { /* So is cxstack[dbcxix]. */
1176 gv_efullname3(sv, CvGV(cxstack[cxix].blk_sub.cv), Nullch);
1177 PUSHs(sv_2mortal(sv));
1178 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1181 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1182 PUSHs(sv_2mortal(newSViv(0)));
1184 gimme = (I32)cx->blk_gimme;
1185 if (gimme == G_VOID)
1188 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1189 if (cx->cx_type == CXt_EVAL) {
1190 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1191 PUSHs(cx->blk_eval.cur_text);
1194 else if (cx->blk_eval.old_name) { /* Try blocks have old_name == 0. */
1195 /* Require, put the name. */
1196 PUSHs(sv_2mortal(newSVpv(cx->blk_eval.old_name, 0)));
1200 else if (cx->cx_type == CXt_SUB &&
1201 cx->blk_sub.hasargs &&
1202 curcop->cop_stash == debstash)
1204 AV *ary = cx->blk_sub.argarray;
1205 int off = AvARRAY(ary) - AvALLOC(ary);
1209 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1212 AvREAL_off(dbargs); /* XXX Should be REIFY */
1215 if (AvMAX(dbargs) < AvFILL(ary) + off)
1216 av_extend(dbargs, AvFILL(ary) + off);
1217 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1218 AvFILL(dbargs) = AvFILL(ary) + off;
1224 sortcv(const void *a, const void *b)
1227 SV * const *str1 = (SV * const *)a;
1228 SV * const *str2 = (SV * const *)b;
1229 I32 oldsaveix = savestack_ix;
1230 I32 oldscopeix = scopestack_ix;
1232 GvSV(firstgv) = *str1;
1233 GvSV(secondgv) = *str2;
1234 stack_sp = stack_base;
1237 if (stack_sp != stack_base + 1)
1238 croak("Sort subroutine didn't return single value");
1239 if (!SvNIOKp(*stack_sp))
1240 croak("Sort subroutine didn't return a numeric value");
1241 result = SvIV(*stack_sp);
1242 while (scopestack_ix > oldscopeix) {
1245 leave_scope(oldsaveix);
1250 sortcmp(const void *a, const void *b)
1252 return sv_cmp(*(SV * const *)a, *(SV * const *)b);
1256 sortcmp_locale(const void *a, const void *b)
1258 return sv_cmp_locale(*(SV * const *)a, *(SV * const *)b);
1270 sv_reset(tmps, curcop->cop_stash);
1283 TAINT_NOT; /* Each statement is presumed innocent */
1284 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1287 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1291 register PERL_CONTEXT *cx;
1292 I32 gimme = G_ARRAY;
1299 DIE("No DB::DB routine defined");
1301 if (CvDEPTH(cv) >= 1 && !(debug & (1<<30))) /* don't do recursive DB::DB call */
1313 push_return(op->op_next);
1314 PUSHBLOCK(cx, CXt_SUB, sp);
1317 (void)SvREFCNT_inc(cv);
1319 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1320 RETURNOP(CvSTART(cv));
1334 register PERL_CONTEXT *cx;
1335 I32 gimme = GIMME_V;
1342 if (op->op_flags & OPf_SPECIAL)
1343 svp = save_threadsv(op->op_targ); /* per-thread variable */
1345 #endif /* USE_THREADS */
1347 svp = &curpad[op->op_targ]; /* "my" variable */
1351 svp = &GvSV((GV*)POPs); /* symbol table variable */
1357 PUSHBLOCK(cx, CXt_LOOP, SP);
1358 PUSHLOOP(cx, svp, MARK);
1359 if (op->op_flags & OPf_STACKED)
1360 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1362 cx->blk_loop.iterary = curstack;
1363 AvFILL(curstack) = sp - stack_base;
1364 cx->blk_loop.iterix = MARK - stack_base;
1373 register PERL_CONTEXT *cx;
1374 I32 gimme = GIMME_V;
1380 PUSHBLOCK(cx, CXt_LOOP, SP);
1381 PUSHLOOP(cx, 0, SP);
1389 register PERL_CONTEXT *cx;
1390 struct block_loop cxloop;
1398 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1401 if (gimme == G_VOID)
1403 else if (gimme == G_SCALAR) {
1405 *++newsp = sv_mortalcopy(*SP);
1407 *++newsp = &sv_undef;
1411 *++newsp = sv_mortalcopy(*++mark);
1412 TAINT_NOT; /* Each item is independent */
1418 POPLOOP2(); /* Stack values are safe: release loop vars ... */
1419 curpm = newpm; /* ... and pop $1 et al */
1431 register PERL_CONTEXT *cx;
1432 struct block_sub cxsub;
1433 bool popsub2 = FALSE;
1439 if (curstack == sortstack) {
1440 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) <= sortcxix) {
1441 if (cxstack_ix > sortcxix)
1443 AvARRAY(curstack)[1] = *SP;
1444 stack_sp = stack_base + 1;
1449 cxix = dopoptosub(cxstack_ix);
1451 DIE("Can't return outside a subroutine");
1452 if (cxix < cxstack_ix)
1456 switch (cx->cx_type) {
1458 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1463 if (optype == OP_REQUIRE &&
1464 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1466 /* Unassume the success we assumed earlier. */
1467 char *name = cx->blk_eval.old_name;
1468 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1469 DIE("%s did not return a true value", name);
1473 DIE("panic: return");
1477 if (gimme == G_SCALAR) {
1479 *++newsp = (popsub2 && SvTEMP(*SP))
1480 ? *SP : sv_mortalcopy(*SP);
1482 *++newsp = &sv_undef;
1484 else if (gimme == G_ARRAY) {
1485 while (++MARK <= SP) {
1486 *++newsp = (popsub2 && SvTEMP(*MARK))
1487 ? *MARK : sv_mortalcopy(*MARK);
1488 TAINT_NOT; /* Each item is independent */
1493 /* Stack values are safe: */
1495 POPSUB2(); /* release CV and @_ ... */
1497 curpm = newpm; /* ... and pop $1 et al */
1500 return pop_return();
1507 register PERL_CONTEXT *cx;
1508 struct block_loop cxloop;
1509 struct block_sub cxsub;
1516 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1518 if (op->op_flags & OPf_SPECIAL) {
1519 cxix = dopoptoloop(cxstack_ix);
1521 DIE("Can't \"last\" outside a block");
1524 cxix = dopoptolabel(cPVOP->op_pv);
1526 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1528 if (cxix < cxstack_ix)
1532 switch (cx->cx_type) {
1534 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1536 nextop = cxloop.last_op->op_next;
1539 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1541 nextop = pop_return();
1545 nextop = pop_return();
1552 if (gimme == G_SCALAR) {
1554 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
1555 ? *SP : sv_mortalcopy(*SP);
1557 *++newsp = &sv_undef;
1559 else if (gimme == G_ARRAY) {
1560 while (++MARK <= SP) {
1561 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
1562 ? *MARK : sv_mortalcopy(*MARK);
1563 TAINT_NOT; /* Each item is independent */
1569 /* Stack values are safe: */
1572 POPLOOP2(); /* release loop vars ... */
1576 POPSUB2(); /* release CV and @_ ... */
1579 curpm = newpm; /* ... and pop $1 et al */
1588 register PERL_CONTEXT *cx;
1591 if (op->op_flags & OPf_SPECIAL) {
1592 cxix = dopoptoloop(cxstack_ix);
1594 DIE("Can't \"next\" outside a block");
1597 cxix = dopoptolabel(cPVOP->op_pv);
1599 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1601 if (cxix < cxstack_ix)
1605 oldsave = scopestack[scopestack_ix - 1];
1606 LEAVE_SCOPE(oldsave);
1607 return cx->blk_loop.next_op;
1613 register PERL_CONTEXT *cx;
1616 if (op->op_flags & OPf_SPECIAL) {
1617 cxix = dopoptoloop(cxstack_ix);
1619 DIE("Can't \"redo\" outside a block");
1622 cxix = dopoptolabel(cPVOP->op_pv);
1624 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1626 if (cxix < cxstack_ix)
1630 oldsave = scopestack[scopestack_ix - 1];
1631 LEAVE_SCOPE(oldsave);
1632 return cx->blk_loop.redo_op;
1635 static OP* lastgotoprobe;
1638 dofindlabel(OP *o, char *label, OP **opstack, OP **oplimit)
1642 static char too_deep[] = "Target of goto is too deeply nested";
1646 if (o->op_type == OP_LEAVE ||
1647 o->op_type == OP_SCOPE ||
1648 o->op_type == OP_LEAVELOOP ||
1649 o->op_type == OP_LEAVETRY)
1651 *ops++ = cUNOPo->op_first;
1656 if (o->op_flags & OPf_KIDS) {
1657 /* First try all the kids at this level, since that's likeliest. */
1658 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1659 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1660 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1663 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1664 if (kid == lastgotoprobe)
1666 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1668 (ops[-1]->op_type != OP_NEXTSTATE &&
1669 ops[-1]->op_type != OP_DBSTATE)))
1671 if (o = dofindlabel(kid, label, ops, oplimit))
1681 return pp_goto(ARGS);
1690 register PERL_CONTEXT *cx;
1691 #define GOTO_DEPTH 64
1692 OP *enterops[GOTO_DEPTH];
1694 int do_dump = (op->op_type == OP_DUMP);
1697 if (op->op_flags & OPf_STACKED) {
1700 /* This egregious kludge implements goto &subroutine */
1701 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1703 register PERL_CONTEXT *cx;
1704 CV* cv = (CV*)SvRV(sv);
1709 if (!CvROOT(cv) && !CvXSUB(cv)) {
1711 SV *tmpstr = sv_newmortal();
1712 gv_efullname3(tmpstr, CvGV(cv), Nullch);
1713 DIE("Goto undefined subroutine &%s",SvPVX(tmpstr));
1715 DIE("Goto undefined subroutine");
1718 /* First do some returnish stuff. */
1719 cxix = dopoptosub(cxstack_ix);
1721 DIE("Can't goto subroutine outside a subroutine");
1722 if (cxix < cxstack_ix)
1726 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1727 AV* av = cx->blk_sub.argarray;
1729 items = AvFILL(av) + 1;
1731 EXTEND(stack_sp, items); /* @_ could have been extended. */
1732 Copy(AvARRAY(av), stack_sp, items, SV*);
1735 SvREFCNT_dec(GvAV(defgv));
1736 GvAV(defgv) = cx->blk_sub.savearray;
1737 #endif /* USE_THREADS */
1741 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1742 SvREFCNT_dec(cx->blk_sub.cv);
1743 oldsave = scopestack[scopestack_ix - 1];
1744 LEAVE_SCOPE(oldsave);
1746 /* Now do some callish stuff. */
1749 if (CvOLDSTYLE(cv)) {
1750 I32 (*fp3)_((int,int,int));
1755 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1756 items = (*fp3)(CvXSUBANY(cv).any_i32,
1757 mark - stack_base + 1,
1759 sp = stack_base + items;
1762 stack_sp--; /* There is no cv arg. */
1763 (void)(*CvXSUB(cv))(cv);
1766 return pop_return();
1769 AV* padlist = CvPADLIST(cv);
1770 SV** svp = AvARRAY(padlist);
1771 cx->blk_sub.cv = cv;
1772 cx->blk_sub.olddepth = CvDEPTH(cv);
1774 if (CvDEPTH(cv) < 2)
1775 (void)SvREFCNT_inc(cv);
1776 else { /* save temporaries on recursion? */
1777 if (CvDEPTH(cv) == 100 && dowarn)
1778 sub_crush_depth(cv);
1779 if (CvDEPTH(cv) > AvFILL(padlist)) {
1780 AV *newpad = newAV();
1781 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
1782 I32 ix = AvFILL((AV*)svp[1]);
1783 svp = AvARRAY(svp[0]);
1784 for ( ;ix > 0; ix--) {
1785 if (svp[ix] != &sv_undef) {
1786 char *name = SvPVX(svp[ix]);
1787 if ((SvFLAGS(svp[ix]) & SVf_FAKE)
1790 /* outer lexical or anon code */
1791 av_store(newpad, ix,
1792 SvREFCNT_inc(oldpad[ix]) );
1794 else { /* our own lexical */
1796 av_store(newpad, ix, sv = (SV*)newAV());
1797 else if (*name == '%')
1798 av_store(newpad, ix, sv = (SV*)newHV());
1800 av_store(newpad, ix, sv = NEWSV(0,0));
1805 av_store(newpad, ix, sv = NEWSV(0,0));
1809 if (cx->blk_sub.hasargs) {
1812 av_store(newpad, 0, (SV*)av);
1813 AvFLAGS(av) = AVf_REIFY;
1815 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1816 AvFILL(padlist) = CvDEPTH(cv);
1817 svp = AvARRAY(padlist);
1821 if (!cx->blk_sub.hasargs) {
1822 AV* av = (AV*)curpad[0];
1824 items = AvFILL(av) + 1;
1826 /* Mark is at the end of the stack. */
1828 Copy(AvARRAY(av), sp + 1, items, SV*);
1833 #endif /* USE_THREADS */
1835 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1837 if (cx->blk_sub.hasargs)
1838 #endif /* USE_THREADS */
1840 AV* av = (AV*)curpad[0];
1844 cx->blk_sub.savearray = GvAV(defgv);
1845 GvAV(defgv) = (AV*)SvREFCNT_inc(av);
1846 #endif /* USE_THREADS */
1847 cx->blk_sub.argarray = av;
1850 if (items >= AvMAX(av) + 1) {
1852 if (AvARRAY(av) != ary) {
1853 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1854 SvPVX(av) = (char*)ary;
1856 if (items >= AvMAX(av) + 1) {
1857 AvMAX(av) = items - 1;
1858 Renew(ary,items+1,SV*);
1860 SvPVX(av) = (char*)ary;
1863 Copy(mark,AvARRAY(av),items,SV*);
1864 AvFILL(av) = items - 1;
1872 if (PERLDB_SUB && curstash != debstash) {
1874 * We do not care about using sv to call CV;
1875 * it's for informational purposes only.
1877 SV *sv = GvSV(DBsub);
1879 gv_efullname3(sv, CvGV(cv), Nullch);
1881 RETURNOP(CvSTART(cv));
1885 label = SvPV(sv,na);
1887 else if (op->op_flags & OPf_SPECIAL) {
1889 DIE("goto must have label");
1892 label = cPVOP->op_pv;
1894 if (label && *label) {
1901 for (ix = cxstack_ix; ix >= 0; ix--) {
1903 switch (cx->cx_type) {
1905 gotoprobe = eval_root; /* XXX not good for nested eval */
1908 gotoprobe = cx->blk_oldcop->op_sibling;
1914 gotoprobe = cx->blk_oldcop->op_sibling;
1916 gotoprobe = main_root;
1919 if (CvDEPTH(cx->blk_sub.cv)) {
1920 gotoprobe = CvROOT(cx->blk_sub.cv);
1925 DIE("Can't \"goto\" outside a block");
1929 gotoprobe = main_root;
1932 retop = dofindlabel(gotoprobe, label,
1933 enterops, enterops + GOTO_DEPTH);
1936 lastgotoprobe = gotoprobe;
1939 DIE("Can't find label %s", label);
1941 /* pop unwanted frames */
1943 if (ix < cxstack_ix) {
1950 oldsave = scopestack[scopestack_ix];
1951 LEAVE_SCOPE(oldsave);
1954 /* push wanted frames */
1956 if (*enterops && enterops[1]) {
1958 for (ix = 1; enterops[ix]; ix++) {
1960 /* Eventually we may want to stack the needed arguments
1961 * for each op. For now, we punt on the hard ones. */
1962 if (op->op_type == OP_ENTERITER)
1963 DIE("Can't \"goto\" into the middle of a foreach loop",
1965 (*op->op_ppaddr)(ARGS);
1973 if (!retop) retop = main_start;
1980 restartop = 0; /* hmm, must be GNU unexec().. */
1984 if (curstack == signalstack) {
2002 if (anum == 1 && VMSISH_EXIT)
2015 double value = SvNVx(GvSV(cCOP->cop_gv));
2016 register I32 match = I_32(value);
2019 if (((double)match) > value)
2020 --match; /* was fractional--truncate other way */
2022 match -= cCOP->uop.scop.scop_offset;
2025 else if (match > cCOP->uop.scop.scop_max)
2026 match = cCOP->uop.scop.scop_max;
2027 op = cCOP->uop.scop.scop_next[match];
2037 op = op->op_next; /* can't assume anything */
2039 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
2040 match -= cCOP->uop.scop.scop_offset;
2043 else if (match > cCOP->uop.scop.scop_max)
2044 match = cCOP->uop.scop.scop_max;
2045 op = cCOP->uop.scop.scop_next[match];
2054 save_lines(AV *array, SV *sv)
2056 register char *s = SvPVX(sv);
2057 register char *send = SvPVX(sv) + SvCUR(sv);
2059 register I32 line = 1;
2061 while (s && s < send) {
2062 SV *tmpstr = NEWSV(85,0);
2064 sv_upgrade(tmpstr, SVt_PVMG);
2065 t = strchr(s, '\n');
2071 sv_setpvn(tmpstr, s, t - s);
2072 av_store(array, line++, tmpstr);
2087 assert(CATCH_GET == TRUE);
2088 DEBUG_l(deb("Setting up local jumplevel %p, was %p\n", &cur_env, top_env));
2092 default: /* topmost level handles it */
2099 PerlIO_printf(PerlIO_stderr(), "panic: restartop\n");
2115 sv_compile_2op(SV *sv, OP** startop, char *code, AV** avp)
2116 /* sv Text to convert to OP tree. */
2117 /* startop op_free() this to undo. */
2118 /* code Short string id of the caller. */
2120 dSP; /* Make POPBLOCK work. */
2123 I32 gimme = 0; /* SUSPECT - INITIALZE TO WHAT? NI-S */
2127 char tmpbuf[TYPE_DIGITS(long) + 12 + 10];
2133 /* switch to eval mode */
2135 SAVESPTR(compiling.cop_filegv);
2136 SAVEI16(compiling.cop_line);
2137 sprintf(tmpbuf, "_<(%.10s_eval %lu)", code, (unsigned long)++evalseq);
2138 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2139 compiling.cop_line = 1;
2140 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2141 deleting the eval's FILEGV from the stash before gv_check() runs
2142 (i.e. before run-time proper). To work around the coredump that
2143 ensues, we always turn GvMULTI_on for any globals that were
2144 introduced within evals. See force_ident(). GSAR 96-10-12 */
2145 safestr = savepv(tmpbuf);
2146 SAVEDELETE(defstash, safestr, strlen(safestr));
2152 op->op_type = 0; /* Avoid uninit warning. */
2153 op->op_flags = 0; /* Avoid uninit warning. */
2154 PUSHBLOCK(cx, CXt_EVAL, SP);
2155 PUSHEVAL(cx, 0, compiling.cop_filegv);
2156 rop = doeval(G_SCALAR, startop);
2160 (*startop)->op_type = OP_NULL;
2161 (*startop)->op_ppaddr = ppaddr[OP_NULL];
2163 *avp = (AV*)SvREFCNT_inc(comppad);
2168 /* With USE_THREADS, eval_owner must be held on entry to doeval */
2170 doeval(int gimme, OP** startop)
2182 /* set up a scratch pad */
2187 SAVESPTR(comppad_name);
2188 SAVEI32(comppad_name_fill);
2189 SAVEI32(min_intro_pending);
2190 SAVEI32(max_intro_pending);
2194 compcv = (CV*)NEWSV(1104,0);
2195 sv_upgrade((SV *)compcv, SVt_PVCV);
2196 CvUNIQUE_on(compcv);
2198 CvOWNER(compcv) = 0;
2199 New(666, CvMUTEXP(compcv), 1, perl_mutex);
2200 MUTEX_INIT(CvMUTEXP(compcv));
2201 #endif /* USE_THREADS */
2204 av_push(comppad, Nullsv);
2205 curpad = AvARRAY(comppad);
2206 comppad_name = newAV();
2207 comppad_name_fill = 0;
2208 min_intro_pending = 0;
2211 av_store(comppad_name, 0, newSVpv("@_", 2));
2212 curpad[0] = (SV*)newAV();
2213 SvPADMY_on(curpad[0]); /* XXX Needed? */
2214 #endif /* USE_THREADS */
2216 comppadlist = newAV();
2217 AvREAL_off(comppadlist);
2218 av_store(comppadlist, 0, (SV*)comppad_name);
2219 av_store(comppadlist, 1, (SV*)comppad);
2220 CvPADLIST(compcv) = comppadlist;
2222 if (!saveop || saveop->op_type != OP_REQUIRE)
2223 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc(caller);
2227 /* make sure we compile in the right package */
2229 newstash = curcop->cop_stash;
2230 if (curstash != newstash) {
2232 curstash = newstash;
2236 SAVEFREESV(beginav);
2238 /* try to compile it */
2242 curcop = &compiling;
2243 curcop->cop_arybase = 0;
2245 rs = newSVpv("\n", 1);
2246 if (saveop && saveop->op_flags & OPf_SPECIAL)
2250 if (yyparse() || error_count || !eval_root) {
2254 I32 optype = 0; /* Might be reset by POPEVAL. */
2261 SP = stack_base + POPMARK; /* pop original mark */
2269 if (optype == OP_REQUIRE) {
2270 char* msg = SvPVx(ERRSV, na);
2271 DIE("%s", *msg ? msg : "Compilation failed in require");
2272 } else if (startop) {
2273 char* msg = SvPVx(ERRSV, na);
2277 croak("%sCompilation failed in regexp", (*msg ? msg : "Unknown error\n"));
2280 rs = SvREFCNT_inc(nrs);
2282 MUTEX_LOCK(&eval_mutex);
2284 COND_SIGNAL(&eval_cond);
2285 MUTEX_UNLOCK(&eval_mutex);
2286 #endif /* USE_THREADS */
2290 rs = SvREFCNT_inc(nrs);
2291 compiling.cop_line = 0;
2293 *startop = eval_root;
2294 SvREFCNT_dec(CvOUTSIDE(compcv));
2295 CvOUTSIDE(compcv) = Nullcv;
2297 SAVEFREEOP(eval_root);
2299 scalarvoid(eval_root);
2300 else if (gimme & G_ARRAY)
2305 DEBUG_x(dump_eval());
2307 /* Register with debugger: */
2308 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2309 CV *cv = perl_get_cv("DB::postponed", FALSE);
2313 XPUSHs((SV*)compiling.cop_filegv);
2315 perl_call_sv((SV*)cv, G_DISCARD);
2319 /* compiled okay, so do it */
2321 CvDEPTH(compcv) = 1;
2322 SP = stack_base + POPMARK; /* pop original mark */
2323 op = saveop; /* The caller may need it. */
2325 MUTEX_LOCK(&eval_mutex);
2327 COND_SIGNAL(&eval_cond);
2328 MUTEX_UNLOCK(&eval_mutex);
2329 #endif /* USE_THREADS */
2331 RETURNOP(eval_start);
2337 register PERL_CONTEXT *cx;
2341 SV *namesv = Nullsv;
2343 I32 gimme = G_SCALAR;
2344 PerlIO *tryrsfp = 0;
2347 if (SvNIOKp(sv) && !SvPOKp(sv)) {
2348 SET_NUMERIC_STANDARD();
2349 if (atof(patchlevel) + 0.00000999 < SvNV(sv))
2350 DIE("Perl %s required--this is only version %s, stopped",
2351 SvPV(sv,na),patchlevel);
2354 name = SvPV(sv, na);
2356 DIE("Null filename used");
2357 TAINT_PROPER("require");
2358 if (op->op_type == OP_REQUIRE &&
2359 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
2363 /* prepare to compile file */
2368 (name[1] == '.' && name[2] == '/')))
2370 || (name[0] && name[1] == ':')
2373 || (name[0] == '\\' && name[1] == '\\') /* UNC path */
2376 || (strchr(name,':') || ((*name == '[' || *name == '<') &&
2377 (isALNUM(name[1]) || strchr("$-_]>",name[1]))))
2382 tryrsfp = PerlIO_open(name,PERL_SCRIPT_MODE);
2385 AV *ar = GvAVn(incgv);
2389 if ((unixname = tounixspec(name, Nullch)) != Nullch)
2392 namesv = NEWSV(806, 0);
2393 for (i = 0; i <= AvFILL(ar); i++) {
2394 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2397 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
2399 sv_setpv(namesv, unixdir);
2400 sv_catpv(namesv, unixname);
2402 sv_setpvf(namesv, "%s/%s", dir, name);
2404 tryname = SvPVX(namesv);
2405 tryrsfp = PerlIO_open(tryname, PERL_SCRIPT_MODE);
2407 if (tryname[0] == '.' && tryname[1] == '/')
2414 SAVESPTR(compiling.cop_filegv);
2415 compiling.cop_filegv = gv_fetchfile(tryrsfp ? tryname : name);
2416 SvREFCNT_dec(namesv);
2418 if (op->op_type == OP_REQUIRE) {
2419 SV *msg = sv_2mortal(newSVpvf("Can't locate %s in @INC", name));
2420 SV *dirmsgsv = NEWSV(0, 0);
2421 AV *ar = GvAVn(incgv);
2423 if (instr(SvPVX(msg), ".h "))
2424 sv_catpv(msg, " (change .h to .ph maybe?)");
2425 if (instr(SvPVX(msg), ".ph "))
2426 sv_catpv(msg, " (did you run h2ph?)");
2427 sv_catpv(msg, " (@INC contains:");
2428 for (i = 0; i <= AvFILL(ar); i++) {
2429 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2430 sv_setpvf(dirmsgsv, " %s", dir);
2431 sv_catsv(msg, dirmsgsv);
2433 sv_catpvn(msg, ")", 1);
2434 SvREFCNT_dec(dirmsgsv);
2441 /* Assume success here to prevent recursive requirement. */
2442 (void)hv_store(GvHVn(incgv), name, strlen(name),
2443 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2447 lex_start(sv_2mortal(newSVpv("",0)));
2449 save_aptr(&rsfp_filters);
2450 rsfp_filters = NULL;
2454 name = savepv(name);
2459 /* switch to eval mode */
2461 push_return(op->op_next);
2462 PUSHBLOCK(cx, CXt_EVAL, SP);
2463 PUSHEVAL(cx, name, compiling.cop_filegv);
2465 compiling.cop_line = 0;
2469 MUTEX_LOCK(&eval_mutex);
2470 if (eval_owner && eval_owner != thr)
2472 COND_WAIT(&eval_cond, &eval_mutex);
2474 MUTEX_UNLOCK(&eval_mutex);
2475 #endif /* USE_THREADS */
2476 return DOCATCH(doeval(G_SCALAR, NULL));
2481 return pp_require(ARGS);
2487 register PERL_CONTEXT *cx;
2489 I32 gimme = GIMME_V, was = sub_generation;
2490 char tmpbuf[TYPE_DIGITS(long) + 12];
2495 if (!SvPV(sv,len) || !len)
2497 TAINT_PROPER("eval");
2503 /* switch to eval mode */
2505 SAVESPTR(compiling.cop_filegv);
2506 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++evalseq);
2507 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2508 compiling.cop_line = 1;
2509 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2510 deleting the eval's FILEGV from the stash before gv_check() runs
2511 (i.e. before run-time proper). To work around the coredump that
2512 ensues, we always turn GvMULTI_on for any globals that were
2513 introduced within evals. See force_ident(). GSAR 96-10-12 */
2514 safestr = savepv(tmpbuf);
2515 SAVEDELETE(defstash, safestr, strlen(safestr));
2517 hints = op->op_targ;
2519 push_return(op->op_next);
2520 PUSHBLOCK(cx, CXt_EVAL, SP);
2521 PUSHEVAL(cx, 0, compiling.cop_filegv);
2523 /* prepare to compile string */
2525 if (PERLDB_LINE && curstash != debstash)
2526 save_lines(GvAV(compiling.cop_filegv), linestr);
2529 MUTEX_LOCK(&eval_mutex);
2530 if (eval_owner && eval_owner != thr)
2532 COND_WAIT(&eval_cond, &eval_mutex);
2534 MUTEX_UNLOCK(&eval_mutex);
2535 #endif /* USE_THREADS */
2536 ret = doeval(gimme, NULL);
2537 if (PERLDB_INTER && was != sub_generation /* Some subs defined here. */
2538 && ret != op->op_next) { /* Successive compilation. */
2539 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
2541 return DOCATCH(ret);
2551 register PERL_CONTEXT *cx;
2553 U8 save_flags = op -> op_flags;
2558 retop = pop_return();
2561 if (gimme == G_VOID)
2563 else if (gimme == G_SCALAR) {
2566 if (SvFLAGS(TOPs) & SVs_TEMP)
2569 *MARK = sv_mortalcopy(TOPs);
2577 /* in case LEAVE wipes old return values */
2578 for (mark = newsp + 1; mark <= SP; mark++) {
2579 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
2580 *mark = sv_mortalcopy(*mark);
2581 TAINT_NOT; /* Each item is independent */
2585 curpm = newpm; /* Don't pop $1 et al till now */
2588 * Closures mentioned at top level of eval cannot be referenced
2589 * again, and their presence indirectly causes a memory leak.
2590 * (Note that the fact that compcv and friends are still set here
2591 * is, AFAIK, an accident.) --Chip
2593 if (AvFILL(comppad_name) >= 0) {
2594 SV **svp = AvARRAY(comppad_name);
2596 for (ix = AvFILL(comppad_name); ix >= 0; ix--) {
2598 if (sv && sv != &sv_undef && *SvPVX(sv) == '&') {
2600 svp[ix] = &sv_undef;
2604 SvREFCNT_dec(CvOUTSIDE(sv));
2605 CvOUTSIDE(sv) = Nullcv;
2618 assert(CvDEPTH(compcv) == 1);
2620 CvDEPTH(compcv) = 0;
2622 if (optype == OP_REQUIRE &&
2623 !(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp))
2625 /* Unassume the success we assumed earlier. */
2626 char *name = cx->blk_eval.old_name;
2627 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2628 retop = die("%s did not return a true value", name);
2634 if (!(save_flags & OPf_SPECIAL))
2643 register PERL_CONTEXT *cx;
2644 I32 gimme = GIMME_V;
2649 push_return(cLOGOP->op_other->op_next);
2650 PUSHBLOCK(cx, CXt_EVAL, SP);
2652 eval_root = op; /* Only needed so that goto works right. */
2657 return DOCATCH(op->op_next);
2667 register PERL_CONTEXT *cx;
2675 if (gimme == G_VOID)
2677 else if (gimme == G_SCALAR) {
2680 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2683 *MARK = sv_mortalcopy(TOPs);
2692 /* in case LEAVE wipes old return values */
2693 for (mark = newsp + 1; mark <= SP; mark++) {
2694 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
2695 *mark = sv_mortalcopy(*mark);
2696 TAINT_NOT; /* Each item is independent */
2700 curpm = newpm; /* Don't pop $1 et al till now */
2711 register char *s = SvPV_force(sv, len);
2712 register char *send = s + len;
2713 register char *base;
2714 register I32 skipspaces = 0;
2717 bool postspace = FALSE;
2725 croak("Null picture in formline");
2727 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
2732 *fpc++ = FF_LINEMARK;
2733 noblank = repeat = FALSE;
2751 case ' ': case '\t':
2762 *fpc++ = FF_LITERAL;
2770 *fpc++ = skipspaces;
2774 *fpc++ = FF_NEWLINE;
2778 arg = fpc - linepc + 1;
2785 *fpc++ = FF_LINEMARK;
2786 noblank = repeat = FALSE;
2795 ischop = s[-1] == '^';
2801 arg = (s - base) - 1;
2803 *fpc++ = FF_LITERAL;
2812 *fpc++ = FF_LINEGLOB;
2814 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2815 arg = ischop ? 512 : 0;
2825 arg |= 256 + (s - f);
2827 *fpc++ = s - base; /* fieldsize for FETCH */
2828 *fpc++ = FF_DECIMAL;
2833 bool ismore = FALSE;
2836 while (*++s == '>') ;
2837 prespace = FF_SPACE;
2839 else if (*s == '|') {
2840 while (*++s == '|') ;
2841 prespace = FF_HALFSPACE;
2846 while (*++s == '<') ;
2849 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2853 *fpc++ = s - base; /* fieldsize for FETCH */
2855 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2873 { /* need to jump to the next word */
2875 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2876 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2877 s = SvPVX(sv) + SvCUR(sv) + z;
2879 Copy(fops, s, arg, U16);
2881 sv_magic(sv, Nullsv, 'f', Nullch, 0);