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) ";
1054 sv_upgrade(*svp, SVt_IV);
1055 (void)SvIOK_only(*svp);
1058 SvGROW(err, SvCUR(err)+sizeof(prefix)+klen);
1059 sv_catpvn(err, prefix, sizeof(prefix)-1);
1060 sv_catpvn(err, message, klen);
1066 sv_setpv(ERRSV, message);
1068 cxix = dopoptoeval(cxstack_ix);
1072 if (cxix < cxstack_ix)
1076 if (cx->cx_type != CXt_EVAL) {
1077 PerlIO_printf(PerlIO_stderr(), "panic: die %s", message);
1082 if (gimme == G_SCALAR)
1083 *++newsp = &sv_undef;
1088 if (optype == OP_REQUIRE) {
1089 char* msg = SvPVx(ERRSV, na);
1090 DIE("%s", *msg ? msg : "Compilation failed in require");
1092 return pop_return();
1095 PerlIO_printf(PerlIO_stderr(), "%s",message);
1096 PerlIO_flush(PerlIO_stderr());
1105 if (SvTRUE(left) != SvTRUE(right))
1117 RETURNOP(cLOGOP->op_other);
1126 RETURNOP(cLOGOP->op_other);
1132 register I32 cxix = dopoptosub(cxstack_ix);
1133 register PERL_CONTEXT *cx;
1144 if (GIMME != G_ARRAY)
1148 if (DBsub && cxix >= 0 &&
1149 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1153 cxix = dopoptosub(cxix - 1);
1155 cx = &cxstack[cxix];
1156 if (cxstack[cxix].cx_type == CXt_SUB) {
1157 dbcxix = dopoptosub(cxix - 1);
1158 /* We expect that cxstack[dbcxix] is CXt_SUB, anyway, the
1159 field below is defined for any cx. */
1160 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1161 cx = &cxstack[dbcxix];
1164 if (GIMME != G_ARRAY) {
1167 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1172 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1173 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1174 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1177 if (cx->cx_type == CXt_SUB) { /* So is cxstack[dbcxix]. */
1179 gv_efullname3(sv, CvGV(cxstack[cxix].blk_sub.cv), Nullch);
1180 PUSHs(sv_2mortal(sv));
1181 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1184 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1185 PUSHs(sv_2mortal(newSViv(0)));
1187 gimme = (I32)cx->blk_gimme;
1188 if (gimme == G_VOID)
1191 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1192 if (cx->cx_type == CXt_EVAL) {
1193 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1194 PUSHs(cx->blk_eval.cur_text);
1197 else if (cx->blk_eval.old_name) { /* Try blocks have old_name == 0. */
1198 /* Require, put the name. */
1199 PUSHs(sv_2mortal(newSVpv(cx->blk_eval.old_name, 0)));
1203 else if (cx->cx_type == CXt_SUB &&
1204 cx->blk_sub.hasargs &&
1205 curcop->cop_stash == debstash)
1207 AV *ary = cx->blk_sub.argarray;
1208 int off = AvARRAY(ary) - AvALLOC(ary);
1212 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1215 AvREAL_off(dbargs); /* XXX Should be REIFY */
1218 if (AvMAX(dbargs) < AvFILL(ary) + off)
1219 av_extend(dbargs, AvFILL(ary) + off);
1220 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1221 AvFILL(dbargs) = AvFILL(ary) + off;
1227 sortcv(const void *a, const void *b)
1230 SV * const *str1 = (SV * const *)a;
1231 SV * const *str2 = (SV * const *)b;
1232 I32 oldsaveix = savestack_ix;
1233 I32 oldscopeix = scopestack_ix;
1235 GvSV(firstgv) = *str1;
1236 GvSV(secondgv) = *str2;
1237 stack_sp = stack_base;
1240 if (stack_sp != stack_base + 1)
1241 croak("Sort subroutine didn't return single value");
1242 if (!SvNIOKp(*stack_sp))
1243 croak("Sort subroutine didn't return a numeric value");
1244 result = SvIV(*stack_sp);
1245 while (scopestack_ix > oldscopeix) {
1248 leave_scope(oldsaveix);
1253 sortcmp(const void *a, const void *b)
1255 return sv_cmp(*(SV * const *)a, *(SV * const *)b);
1259 sortcmp_locale(const void *a, const void *b)
1261 return sv_cmp_locale(*(SV * const *)a, *(SV * const *)b);
1273 sv_reset(tmps, curcop->cop_stash);
1286 TAINT_NOT; /* Each statement is presumed innocent */
1287 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1290 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1294 register PERL_CONTEXT *cx;
1295 I32 gimme = G_ARRAY;
1302 DIE("No DB::DB routine defined");
1304 if (CvDEPTH(cv) >= 1 && !(debug & (1<<30))) /* don't do recursive DB::DB call */
1316 push_return(op->op_next);
1317 PUSHBLOCK(cx, CXt_SUB, sp);
1320 (void)SvREFCNT_inc(cv);
1322 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1323 RETURNOP(CvSTART(cv));
1337 register PERL_CONTEXT *cx;
1338 I32 gimme = GIMME_V;
1345 if (op->op_flags & OPf_SPECIAL)
1346 svp = save_threadsv(op->op_targ); /* per-thread variable */
1348 #endif /* USE_THREADS */
1350 svp = &curpad[op->op_targ]; /* "my" variable */
1354 svp = &GvSV((GV*)POPs); /* symbol table variable */
1360 PUSHBLOCK(cx, CXt_LOOP, SP);
1361 PUSHLOOP(cx, svp, MARK);
1362 if (op->op_flags & OPf_STACKED)
1363 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1365 cx->blk_loop.iterary = curstack;
1366 AvFILL(curstack) = sp - stack_base;
1367 cx->blk_loop.iterix = MARK - stack_base;
1376 register PERL_CONTEXT *cx;
1377 I32 gimme = GIMME_V;
1383 PUSHBLOCK(cx, CXt_LOOP, SP);
1384 PUSHLOOP(cx, 0, SP);
1392 register PERL_CONTEXT *cx;
1393 struct block_loop cxloop;
1401 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1404 if (gimme == G_VOID)
1406 else if (gimme == G_SCALAR) {
1408 *++newsp = sv_mortalcopy(*SP);
1410 *++newsp = &sv_undef;
1414 *++newsp = sv_mortalcopy(*++mark);
1415 TAINT_NOT; /* Each item is independent */
1421 POPLOOP2(); /* Stack values are safe: release loop vars ... */
1422 curpm = newpm; /* ... and pop $1 et al */
1434 register PERL_CONTEXT *cx;
1435 struct block_sub cxsub;
1436 bool popsub2 = FALSE;
1442 if (curstack == sortstack) {
1443 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) <= sortcxix) {
1444 if (cxstack_ix > sortcxix)
1446 AvARRAY(curstack)[1] = *SP;
1447 stack_sp = stack_base + 1;
1452 cxix = dopoptosub(cxstack_ix);
1454 DIE("Can't return outside a subroutine");
1455 if (cxix < cxstack_ix)
1459 switch (cx->cx_type) {
1461 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1466 if (optype == OP_REQUIRE &&
1467 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1469 /* Unassume the success we assumed earlier. */
1470 char *name = cx->blk_eval.old_name;
1471 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1472 DIE("%s did not return a true value", name);
1476 DIE("panic: return");
1480 if (gimme == G_SCALAR) {
1482 *++newsp = (popsub2 && SvTEMP(*SP))
1483 ? *SP : sv_mortalcopy(*SP);
1485 *++newsp = &sv_undef;
1487 else if (gimme == G_ARRAY) {
1488 while (++MARK <= SP) {
1489 *++newsp = (popsub2 && SvTEMP(*MARK))
1490 ? *MARK : sv_mortalcopy(*MARK);
1491 TAINT_NOT; /* Each item is independent */
1496 /* Stack values are safe: */
1498 POPSUB2(); /* release CV and @_ ... */
1500 curpm = newpm; /* ... and pop $1 et al */
1503 return pop_return();
1510 register PERL_CONTEXT *cx;
1511 struct block_loop cxloop;
1512 struct block_sub cxsub;
1519 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1521 if (op->op_flags & OPf_SPECIAL) {
1522 cxix = dopoptoloop(cxstack_ix);
1524 DIE("Can't \"last\" outside a block");
1527 cxix = dopoptolabel(cPVOP->op_pv);
1529 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1531 if (cxix < cxstack_ix)
1535 switch (cx->cx_type) {
1537 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1539 nextop = cxloop.last_op->op_next;
1542 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1544 nextop = pop_return();
1548 nextop = pop_return();
1555 if (gimme == G_SCALAR) {
1557 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
1558 ? *SP : sv_mortalcopy(*SP);
1560 *++newsp = &sv_undef;
1562 else if (gimme == G_ARRAY) {
1563 while (++MARK <= SP) {
1564 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
1565 ? *MARK : sv_mortalcopy(*MARK);
1566 TAINT_NOT; /* Each item is independent */
1572 /* Stack values are safe: */
1575 POPLOOP2(); /* release loop vars ... */
1579 POPSUB2(); /* release CV and @_ ... */
1582 curpm = newpm; /* ... and pop $1 et al */
1591 register PERL_CONTEXT *cx;
1594 if (op->op_flags & OPf_SPECIAL) {
1595 cxix = dopoptoloop(cxstack_ix);
1597 DIE("Can't \"next\" outside a block");
1600 cxix = dopoptolabel(cPVOP->op_pv);
1602 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1604 if (cxix < cxstack_ix)
1608 oldsave = scopestack[scopestack_ix - 1];
1609 LEAVE_SCOPE(oldsave);
1610 return cx->blk_loop.next_op;
1616 register PERL_CONTEXT *cx;
1619 if (op->op_flags & OPf_SPECIAL) {
1620 cxix = dopoptoloop(cxstack_ix);
1622 DIE("Can't \"redo\" outside a block");
1625 cxix = dopoptolabel(cPVOP->op_pv);
1627 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1629 if (cxix < cxstack_ix)
1633 oldsave = scopestack[scopestack_ix - 1];
1634 LEAVE_SCOPE(oldsave);
1635 return cx->blk_loop.redo_op;
1638 static OP* lastgotoprobe;
1641 dofindlabel(OP *o, char *label, OP **opstack, OP **oplimit)
1645 static char too_deep[] = "Target of goto is too deeply nested";
1649 if (o->op_type == OP_LEAVE ||
1650 o->op_type == OP_SCOPE ||
1651 o->op_type == OP_LEAVELOOP ||
1652 o->op_type == OP_LEAVETRY)
1654 *ops++ = cUNOPo->op_first;
1659 if (o->op_flags & OPf_KIDS) {
1660 /* First try all the kids at this level, since that's likeliest. */
1661 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1662 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1663 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1666 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1667 if (kid == lastgotoprobe)
1669 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1671 (ops[-1]->op_type != OP_NEXTSTATE &&
1672 ops[-1]->op_type != OP_DBSTATE)))
1674 if (o = dofindlabel(kid, label, ops, oplimit))
1684 return pp_goto(ARGS);
1693 register PERL_CONTEXT *cx;
1694 #define GOTO_DEPTH 64
1695 OP *enterops[GOTO_DEPTH];
1697 int do_dump = (op->op_type == OP_DUMP);
1700 if (op->op_flags & OPf_STACKED) {
1703 /* This egregious kludge implements goto &subroutine */
1704 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1706 register PERL_CONTEXT *cx;
1707 CV* cv = (CV*)SvRV(sv);
1712 if (!CvROOT(cv) && !CvXSUB(cv)) {
1714 SV *tmpstr = sv_newmortal();
1715 gv_efullname3(tmpstr, CvGV(cv), Nullch);
1716 DIE("Goto undefined subroutine &%s",SvPVX(tmpstr));
1718 DIE("Goto undefined subroutine");
1721 /* First do some returnish stuff. */
1722 cxix = dopoptosub(cxstack_ix);
1724 DIE("Can't goto subroutine outside a subroutine");
1725 if (cxix < cxstack_ix)
1729 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1730 AV* av = cx->blk_sub.argarray;
1732 items = AvFILL(av) + 1;
1734 EXTEND(stack_sp, items); /* @_ could have been extended. */
1735 Copy(AvARRAY(av), stack_sp, items, SV*);
1738 SvREFCNT_dec(GvAV(defgv));
1739 GvAV(defgv) = cx->blk_sub.savearray;
1740 #endif /* USE_THREADS */
1744 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1745 SvREFCNT_dec(cx->blk_sub.cv);
1746 oldsave = scopestack[scopestack_ix - 1];
1747 LEAVE_SCOPE(oldsave);
1749 /* Now do some callish stuff. */
1752 if (CvOLDSTYLE(cv)) {
1753 I32 (*fp3)_((int,int,int));
1758 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1759 items = (*fp3)(CvXSUBANY(cv).any_i32,
1760 mark - stack_base + 1,
1762 sp = stack_base + items;
1765 stack_sp--; /* There is no cv arg. */
1766 (void)(*CvXSUB(cv))(cv);
1769 return pop_return();
1772 AV* padlist = CvPADLIST(cv);
1773 SV** svp = AvARRAY(padlist);
1774 cx->blk_sub.cv = cv;
1775 cx->blk_sub.olddepth = CvDEPTH(cv);
1777 if (CvDEPTH(cv) < 2)
1778 (void)SvREFCNT_inc(cv);
1779 else { /* save temporaries on recursion? */
1780 if (CvDEPTH(cv) == 100 && dowarn)
1781 sub_crush_depth(cv);
1782 if (CvDEPTH(cv) > AvFILL(padlist)) {
1783 AV *newpad = newAV();
1784 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
1785 I32 ix = AvFILL((AV*)svp[1]);
1786 svp = AvARRAY(svp[0]);
1787 for ( ;ix > 0; ix--) {
1788 if (svp[ix] != &sv_undef) {
1789 char *name = SvPVX(svp[ix]);
1790 if ((SvFLAGS(svp[ix]) & SVf_FAKE)
1793 /* outer lexical or anon code */
1794 av_store(newpad, ix,
1795 SvREFCNT_inc(oldpad[ix]) );
1797 else { /* our own lexical */
1799 av_store(newpad, ix, sv = (SV*)newAV());
1800 else if (*name == '%')
1801 av_store(newpad, ix, sv = (SV*)newHV());
1803 av_store(newpad, ix, sv = NEWSV(0,0));
1808 av_store(newpad, ix, sv = NEWSV(0,0));
1812 if (cx->blk_sub.hasargs) {
1815 av_store(newpad, 0, (SV*)av);
1816 AvFLAGS(av) = AVf_REIFY;
1818 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1819 AvFILL(padlist) = CvDEPTH(cv);
1820 svp = AvARRAY(padlist);
1824 if (!cx->blk_sub.hasargs) {
1825 AV* av = (AV*)curpad[0];
1827 items = AvFILL(av) + 1;
1829 /* Mark is at the end of the stack. */
1831 Copy(AvARRAY(av), sp + 1, items, SV*);
1836 #endif /* USE_THREADS */
1838 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1840 if (cx->blk_sub.hasargs)
1841 #endif /* USE_THREADS */
1843 AV* av = (AV*)curpad[0];
1847 cx->blk_sub.savearray = GvAV(defgv);
1848 GvAV(defgv) = (AV*)SvREFCNT_inc(av);
1849 #endif /* USE_THREADS */
1850 cx->blk_sub.argarray = av;
1853 if (items >= AvMAX(av) + 1) {
1855 if (AvARRAY(av) != ary) {
1856 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1857 SvPVX(av) = (char*)ary;
1859 if (items >= AvMAX(av) + 1) {
1860 AvMAX(av) = items - 1;
1861 Renew(ary,items+1,SV*);
1863 SvPVX(av) = (char*)ary;
1866 Copy(mark,AvARRAY(av),items,SV*);
1867 AvFILL(av) = items - 1;
1875 if (PERLDB_SUB && curstash != debstash) {
1877 * We do not care about using sv to call CV;
1878 * it's for informational purposes only.
1880 SV *sv = GvSV(DBsub);
1882 gv_efullname3(sv, CvGV(cv), Nullch);
1884 RETURNOP(CvSTART(cv));
1888 label = SvPV(sv,na);
1890 else if (op->op_flags & OPf_SPECIAL) {
1892 DIE("goto must have label");
1895 label = cPVOP->op_pv;
1897 if (label && *label) {
1904 for (ix = cxstack_ix; ix >= 0; ix--) {
1906 switch (cx->cx_type) {
1908 gotoprobe = eval_root; /* XXX not good for nested eval */
1911 gotoprobe = cx->blk_oldcop->op_sibling;
1917 gotoprobe = cx->blk_oldcop->op_sibling;
1919 gotoprobe = main_root;
1922 if (CvDEPTH(cx->blk_sub.cv)) {
1923 gotoprobe = CvROOT(cx->blk_sub.cv);
1928 DIE("Can't \"goto\" outside a block");
1932 gotoprobe = main_root;
1935 retop = dofindlabel(gotoprobe, label,
1936 enterops, enterops + GOTO_DEPTH);
1939 lastgotoprobe = gotoprobe;
1942 DIE("Can't find label %s", label);
1944 /* pop unwanted frames */
1946 if (ix < cxstack_ix) {
1953 oldsave = scopestack[scopestack_ix];
1954 LEAVE_SCOPE(oldsave);
1957 /* push wanted frames */
1959 if (*enterops && enterops[1]) {
1961 for (ix = 1; enterops[ix]; ix++) {
1963 /* Eventually we may want to stack the needed arguments
1964 * for each op. For now, we punt on the hard ones. */
1965 if (op->op_type == OP_ENTERITER)
1966 DIE("Can't \"goto\" into the middle of a foreach loop",
1968 (*op->op_ppaddr)(ARGS);
1976 if (!retop) retop = main_start;
1983 restartop = 0; /* hmm, must be GNU unexec().. */
1987 if (curstack == signalstack) {
2005 if (anum == 1 && VMSISH_EXIT)
2018 double value = SvNVx(GvSV(cCOP->cop_gv));
2019 register I32 match = I_32(value);
2022 if (((double)match) > value)
2023 --match; /* was fractional--truncate other way */
2025 match -= cCOP->uop.scop.scop_offset;
2028 else if (match > cCOP->uop.scop.scop_max)
2029 match = cCOP->uop.scop.scop_max;
2030 op = cCOP->uop.scop.scop_next[match];
2040 op = op->op_next; /* can't assume anything */
2042 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
2043 match -= cCOP->uop.scop.scop_offset;
2046 else if (match > cCOP->uop.scop.scop_max)
2047 match = cCOP->uop.scop.scop_max;
2048 op = cCOP->uop.scop.scop_next[match];
2057 save_lines(AV *array, SV *sv)
2059 register char *s = SvPVX(sv);
2060 register char *send = SvPVX(sv) + SvCUR(sv);
2062 register I32 line = 1;
2064 while (s && s < send) {
2065 SV *tmpstr = NEWSV(85,0);
2067 sv_upgrade(tmpstr, SVt_PVMG);
2068 t = strchr(s, '\n');
2074 sv_setpvn(tmpstr, s, t - s);
2075 av_store(array, line++, tmpstr);
2090 assert(CATCH_GET == TRUE);
2091 DEBUG_l(deb("Setting up local jumplevel %p, was %p\n", &cur_env, top_env));
2095 default: /* topmost level handles it */
2102 PerlIO_printf(PerlIO_stderr(), "panic: restartop\n");
2118 sv_compile_2op(SV *sv, OP** startop, char *code, AV** avp)
2119 /* sv Text to convert to OP tree. */
2120 /* startop op_free() this to undo. */
2121 /* code Short string id of the caller. */
2123 dSP; /* Make POPBLOCK work. */
2126 I32 gimme = 0; /* SUSPECT - INITIALZE TO WHAT? NI-S */
2130 char tmpbuf[TYPE_DIGITS(long) + 12 + 10];
2136 /* switch to eval mode */
2138 SAVESPTR(compiling.cop_filegv);
2139 SAVEI16(compiling.cop_line);
2140 sprintf(tmpbuf, "_<(%.10s_eval %lu)", code, (unsigned long)++evalseq);
2141 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2142 compiling.cop_line = 1;
2143 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2144 deleting the eval's FILEGV from the stash before gv_check() runs
2145 (i.e. before run-time proper). To work around the coredump that
2146 ensues, we always turn GvMULTI_on for any globals that were
2147 introduced within evals. See force_ident(). GSAR 96-10-12 */
2148 safestr = savepv(tmpbuf);
2149 SAVEDELETE(defstash, safestr, strlen(safestr));
2155 op->op_type = 0; /* Avoid uninit warning. */
2156 op->op_flags = 0; /* Avoid uninit warning. */
2157 PUSHBLOCK(cx, CXt_EVAL, SP);
2158 PUSHEVAL(cx, 0, compiling.cop_filegv);
2159 rop = doeval(G_SCALAR, startop);
2163 (*startop)->op_type = OP_NULL;
2164 (*startop)->op_ppaddr = ppaddr[OP_NULL];
2166 *avp = (AV*)SvREFCNT_inc(comppad);
2171 /* With USE_THREADS, eval_owner must be held on entry to doeval */
2173 doeval(int gimme, OP** startop)
2185 /* set up a scratch pad */
2190 SAVESPTR(comppad_name);
2191 SAVEI32(comppad_name_fill);
2192 SAVEI32(min_intro_pending);
2193 SAVEI32(max_intro_pending);
2197 compcv = (CV*)NEWSV(1104,0);
2198 sv_upgrade((SV *)compcv, SVt_PVCV);
2199 CvUNIQUE_on(compcv);
2201 CvOWNER(compcv) = 0;
2202 New(666, CvMUTEXP(compcv), 1, perl_mutex);
2203 MUTEX_INIT(CvMUTEXP(compcv));
2204 #endif /* USE_THREADS */
2207 av_push(comppad, Nullsv);
2208 curpad = AvARRAY(comppad);
2209 comppad_name = newAV();
2210 comppad_name_fill = 0;
2211 min_intro_pending = 0;
2214 av_store(comppad_name, 0, newSVpv("@_", 2));
2215 curpad[0] = (SV*)newAV();
2216 SvPADMY_on(curpad[0]); /* XXX Needed? */
2217 #endif /* USE_THREADS */
2219 comppadlist = newAV();
2220 AvREAL_off(comppadlist);
2221 av_store(comppadlist, 0, (SV*)comppad_name);
2222 av_store(comppadlist, 1, (SV*)comppad);
2223 CvPADLIST(compcv) = comppadlist;
2225 if (!saveop || saveop->op_type != OP_REQUIRE)
2226 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc(caller);
2230 /* make sure we compile in the right package */
2232 newstash = curcop->cop_stash;
2233 if (curstash != newstash) {
2235 curstash = newstash;
2239 SAVEFREESV(beginav);
2241 /* try to compile it */
2245 curcop = &compiling;
2246 curcop->cop_arybase = 0;
2248 rs = newSVpv("\n", 1);
2249 if (saveop && saveop->op_flags & OPf_SPECIAL)
2253 if (yyparse() || error_count || !eval_root) {
2257 I32 optype = 0; /* Might be reset by POPEVAL. */
2264 SP = stack_base + POPMARK; /* pop original mark */
2272 if (optype == OP_REQUIRE) {
2273 char* msg = SvPVx(ERRSV, na);
2274 DIE("%s", *msg ? msg : "Compilation failed in require");
2275 } else if (startop) {
2276 char* msg = SvPVx(ERRSV, na);
2280 croak("%sCompilation failed in regexp", (*msg ? msg : "Unknown error\n"));
2283 rs = SvREFCNT_inc(nrs);
2285 MUTEX_LOCK(&eval_mutex);
2287 COND_SIGNAL(&eval_cond);
2288 MUTEX_UNLOCK(&eval_mutex);
2289 #endif /* USE_THREADS */
2293 rs = SvREFCNT_inc(nrs);
2294 compiling.cop_line = 0;
2296 *startop = eval_root;
2297 SvREFCNT_dec(CvOUTSIDE(compcv));
2298 CvOUTSIDE(compcv) = Nullcv;
2300 SAVEFREEOP(eval_root);
2302 scalarvoid(eval_root);
2303 else if (gimme & G_ARRAY)
2308 DEBUG_x(dump_eval());
2310 /* Register with debugger: */
2311 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2312 CV *cv = perl_get_cv("DB::postponed", FALSE);
2316 XPUSHs((SV*)compiling.cop_filegv);
2318 perl_call_sv((SV*)cv, G_DISCARD);
2322 /* compiled okay, so do it */
2324 CvDEPTH(compcv) = 1;
2325 SP = stack_base + POPMARK; /* pop original mark */
2326 op = saveop; /* The caller may need it. */
2328 MUTEX_LOCK(&eval_mutex);
2330 COND_SIGNAL(&eval_cond);
2331 MUTEX_UNLOCK(&eval_mutex);
2332 #endif /* USE_THREADS */
2334 RETURNOP(eval_start);
2340 register PERL_CONTEXT *cx;
2344 SV *namesv = Nullsv;
2346 I32 gimme = G_SCALAR;
2347 PerlIO *tryrsfp = 0;
2350 if (SvNIOKp(sv) && !SvPOKp(sv)) {
2351 SET_NUMERIC_STANDARD();
2352 if (atof(patchlevel) + 0.00000999 < SvNV(sv))
2353 DIE("Perl %s required--this is only version %s, stopped",
2354 SvPV(sv,na),patchlevel);
2357 name = SvPV(sv, na);
2359 DIE("Null filename used");
2360 TAINT_PROPER("require");
2361 if (op->op_type == OP_REQUIRE &&
2362 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
2366 /* prepare to compile file */
2371 (name[1] == '.' && name[2] == '/')))
2373 || (name[0] && name[1] == ':')
2376 || (name[0] == '\\' && name[1] == '\\') /* UNC path */
2379 || (strchr(name,':') || ((*name == '[' || *name == '<') &&
2380 (isALNUM(name[1]) || strchr("$-_]>",name[1]))))
2385 tryrsfp = PerlIO_open(name,PERL_SCRIPT_MODE);
2388 AV *ar = GvAVn(incgv);
2392 if ((unixname = tounixspec(name, Nullch)) != Nullch)
2395 namesv = NEWSV(806, 0);
2396 for (i = 0; i <= AvFILL(ar); i++) {
2397 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2400 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
2402 sv_setpv(namesv, unixdir);
2403 sv_catpv(namesv, unixname);
2405 sv_setpvf(namesv, "%s/%s", dir, name);
2407 tryname = SvPVX(namesv);
2408 tryrsfp = PerlIO_open(tryname, PERL_SCRIPT_MODE);
2410 if (tryname[0] == '.' && tryname[1] == '/')
2417 SAVESPTR(compiling.cop_filegv);
2418 compiling.cop_filegv = gv_fetchfile(tryrsfp ? tryname : name);
2419 SvREFCNT_dec(namesv);
2421 if (op->op_type == OP_REQUIRE) {
2422 SV *msg = sv_2mortal(newSVpvf("Can't locate %s in @INC", name));
2423 SV *dirmsgsv = NEWSV(0, 0);
2424 AV *ar = GvAVn(incgv);
2426 if (instr(SvPVX(msg), ".h "))
2427 sv_catpv(msg, " (change .h to .ph maybe?)");
2428 if (instr(SvPVX(msg), ".ph "))
2429 sv_catpv(msg, " (did you run h2ph?)");
2430 sv_catpv(msg, " (@INC contains:");
2431 for (i = 0; i <= AvFILL(ar); i++) {
2432 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2433 sv_setpvf(dirmsgsv, " %s", dir);
2434 sv_catsv(msg, dirmsgsv);
2436 sv_catpvn(msg, ")", 1);
2437 SvREFCNT_dec(dirmsgsv);
2444 /* Assume success here to prevent recursive requirement. */
2445 (void)hv_store(GvHVn(incgv), name, strlen(name),
2446 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2450 lex_start(sv_2mortal(newSVpv("",0)));
2452 save_aptr(&rsfp_filters);
2453 rsfp_filters = NULL;
2457 name = savepv(name);
2462 /* switch to eval mode */
2464 push_return(op->op_next);
2465 PUSHBLOCK(cx, CXt_EVAL, SP);
2466 PUSHEVAL(cx, name, compiling.cop_filegv);
2468 compiling.cop_line = 0;
2472 MUTEX_LOCK(&eval_mutex);
2473 if (eval_owner && eval_owner != thr)
2475 COND_WAIT(&eval_cond, &eval_mutex);
2477 MUTEX_UNLOCK(&eval_mutex);
2478 #endif /* USE_THREADS */
2479 return DOCATCH(doeval(G_SCALAR, NULL));
2484 return pp_require(ARGS);
2490 register PERL_CONTEXT *cx;
2492 I32 gimme = GIMME_V, was = sub_generation;
2493 char tmpbuf[TYPE_DIGITS(long) + 12];
2498 if (!SvPV(sv,len) || !len)
2500 TAINT_PROPER("eval");
2506 /* switch to eval mode */
2508 SAVESPTR(compiling.cop_filegv);
2509 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++evalseq);
2510 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2511 compiling.cop_line = 1;
2512 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2513 deleting the eval's FILEGV from the stash before gv_check() runs
2514 (i.e. before run-time proper). To work around the coredump that
2515 ensues, we always turn GvMULTI_on for any globals that were
2516 introduced within evals. See force_ident(). GSAR 96-10-12 */
2517 safestr = savepv(tmpbuf);
2518 SAVEDELETE(defstash, safestr, strlen(safestr));
2520 hints = op->op_targ;
2522 push_return(op->op_next);
2523 PUSHBLOCK(cx, CXt_EVAL, SP);
2524 PUSHEVAL(cx, 0, compiling.cop_filegv);
2526 /* prepare to compile string */
2528 if (PERLDB_LINE && curstash != debstash)
2529 save_lines(GvAV(compiling.cop_filegv), linestr);
2532 MUTEX_LOCK(&eval_mutex);
2533 if (eval_owner && eval_owner != thr)
2535 COND_WAIT(&eval_cond, &eval_mutex);
2537 MUTEX_UNLOCK(&eval_mutex);
2538 #endif /* USE_THREADS */
2539 ret = doeval(gimme, NULL);
2540 if (PERLDB_INTER && was != sub_generation /* Some subs defined here. */
2541 && ret != op->op_next) { /* Successive compilation. */
2542 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
2544 return DOCATCH(ret);
2554 register PERL_CONTEXT *cx;
2556 U8 save_flags = op -> op_flags;
2561 retop = pop_return();
2564 if (gimme == G_VOID)
2566 else if (gimme == G_SCALAR) {
2569 if (SvFLAGS(TOPs) & SVs_TEMP)
2572 *MARK = sv_mortalcopy(TOPs);
2580 /* in case LEAVE wipes old return values */
2581 for (mark = newsp + 1; mark <= SP; mark++) {
2582 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
2583 *mark = sv_mortalcopy(*mark);
2584 TAINT_NOT; /* Each item is independent */
2588 curpm = newpm; /* Don't pop $1 et al till now */
2591 * Closures mentioned at top level of eval cannot be referenced
2592 * again, and their presence indirectly causes a memory leak.
2593 * (Note that the fact that compcv and friends are still set here
2594 * is, AFAIK, an accident.) --Chip
2596 if (AvFILL(comppad_name) >= 0) {
2597 SV **svp = AvARRAY(comppad_name);
2599 for (ix = AvFILL(comppad_name); ix >= 0; ix--) {
2601 if (sv && sv != &sv_undef && *SvPVX(sv) == '&') {
2603 svp[ix] = &sv_undef;
2607 SvREFCNT_dec(CvOUTSIDE(sv));
2608 CvOUTSIDE(sv) = Nullcv;
2621 assert(CvDEPTH(compcv) == 1);
2623 CvDEPTH(compcv) = 0;
2625 if (optype == OP_REQUIRE &&
2626 !(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp))
2628 /* Unassume the success we assumed earlier. */
2629 char *name = cx->blk_eval.old_name;
2630 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2631 retop = die("%s did not return a true value", name);
2637 if (!(save_flags & OPf_SPECIAL))
2646 register PERL_CONTEXT *cx;
2647 I32 gimme = GIMME_V;
2652 push_return(cLOGOP->op_other->op_next);
2653 PUSHBLOCK(cx, CXt_EVAL, SP);
2655 eval_root = op; /* Only needed so that goto works right. */
2660 return DOCATCH(op->op_next);
2670 register PERL_CONTEXT *cx;
2678 if (gimme == G_VOID)
2680 else if (gimme == G_SCALAR) {
2683 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2686 *MARK = sv_mortalcopy(TOPs);
2695 /* in case LEAVE wipes old return values */
2696 for (mark = newsp + 1; mark <= SP; mark++) {
2697 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
2698 *mark = sv_mortalcopy(*mark);
2699 TAINT_NOT; /* Each item is independent */
2703 curpm = newpm; /* Don't pop $1 et al till now */
2714 register char *s = SvPV_force(sv, len);
2715 register char *send = s + len;
2716 register char *base;
2717 register I32 skipspaces = 0;
2720 bool postspace = FALSE;
2728 croak("Null picture in formline");
2730 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
2735 *fpc++ = FF_LINEMARK;
2736 noblank = repeat = FALSE;
2754 case ' ': case '\t':
2765 *fpc++ = FF_LITERAL;
2773 *fpc++ = skipspaces;
2777 *fpc++ = FF_NEWLINE;
2781 arg = fpc - linepc + 1;
2788 *fpc++ = FF_LINEMARK;
2789 noblank = repeat = FALSE;
2798 ischop = s[-1] == '^';
2804 arg = (s - base) - 1;
2806 *fpc++ = FF_LITERAL;
2815 *fpc++ = FF_LINEGLOB;
2817 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2818 arg = ischop ? 512 : 0;
2828 arg |= 256 + (s - f);
2830 *fpc++ = s - base; /* fieldsize for FETCH */
2831 *fpc++ = FF_DECIMAL;
2836 bool ismore = FALSE;
2839 while (*++s == '>') ;
2840 prespace = FF_SPACE;
2842 else if (*s == '|') {
2843 while (*++s == '|') ;
2844 prespace = FF_HALFSPACE;
2849 while (*++s == '<') ;
2852 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2856 *fpc++ = s - base; /* fieldsize for FETCH */
2858 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2876 { /* need to jump to the next word */
2878 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2879 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2880 s = SvPVX(sv) + SvCUR(sv) + z;
2882 Copy(fops, s, arg, U16);
2884 sv_magic(sv, Nullsv, 'f', Nullch, 0);