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))
29 #define CALLOP this->*op
32 static OP *docatch _((OP *o));
33 static OP *dofindlabel _((OP *o, char *label, OP **opstack, OP **oplimit));
34 static void doparseform _((SV *sv));
35 static I32 dopoptoeval _((I32 startingblock));
36 static I32 dopoptolabel _((char *label));
37 static I32 dopoptoloop _((I32 startingblock));
38 static I32 dopoptosub _((I32 startingblock));
39 static void save_lines _((AV *array, SV *sv));
40 static int sortcv _((const void *, const void *));
41 static int sortcmp _((const void *, const void *));
42 static int sortcmp_locale _((const void *, const void *));
43 static OP *doeval _((int gimme, OP** startop));
54 cxix = dopoptosub(cxstack_ix);
58 switch (cxstack[cxix].blk_gimme) {
75 register PMOP *pm = (PMOP*)cLOGOP->op_other;
79 MAGIC *mg = Null(MAGIC*);
83 SV *sv = SvRV(tmpstr);
85 mg = mg_find(sv, 'r');
88 regexp *re = (regexp *)mg->mg_obj;
89 ReREFCNT_dec(pm->op_pmregexp);
90 pm->op_pmregexp = ReREFCNT_inc(re);
93 t = SvPV(tmpstr, len);
95 /* JMR: Check against the last compiled regexp */
96 if ( ! pm->op_pmregexp || ! pm->op_pmregexp->precomp
97 || strnNE(pm->op_pmregexp->precomp, t, len)
98 || pm->op_pmregexp->precomp[len]) {
99 if (pm->op_pmregexp) {
100 ReREFCNT_dec(pm->op_pmregexp);
101 pm->op_pmregexp = Null(REGEXP*); /* crucial if regcomp aborts */
104 pm->op_pmflags = pm->op_pmpermflags; /* reset case sensitivity */
105 pm->op_pmregexp = pregcomp(t, t + len, pm);
109 if (!pm->op_pmregexp->prelen && curpm)
111 else if (strEQ("\\s+", pm->op_pmregexp->precomp))
112 pm->op_pmflags |= PMf_WHITE;
114 if (pm->op_pmflags & PMf_KEEP) {
115 pm->op_private &= ~OPpRUNTIME; /* no point compiling again */
116 cLOGOP->op_first->op_next = op->op_next;
124 register PMOP *pm = (PMOP*) cLOGOP->op_other;
125 register PERL_CONTEXT *cx = &cxstack[cxstack_ix];
126 register SV *dstr = cx->sb_dstr;
127 register char *s = cx->sb_s;
128 register char *m = cx->sb_m;
129 char *orig = cx->sb_orig;
130 register REGEXP *rx = cx->sb_rx;
132 rxres_restore(&cx->sb_rxres, rx);
134 if (cx->sb_iters++) {
135 if (cx->sb_iters > cx->sb_maxiters)
136 DIE("Substitution loop");
138 if (!cx->sb_rxtainted)
139 cx->sb_rxtainted = SvTAINTED(TOPs);
140 sv_catsv(dstr, POPs);
143 if (cx->sb_once || !regexec_flags(rx, s, cx->sb_strend, orig,
144 s == m, Nullsv, NULL,
145 cx->sb_safebase ? 0 : REXEC_COPY_STR))
147 SV *targ = cx->sb_targ;
148 sv_catpvn(dstr, s, cx->sb_strend - s);
150 TAINT_IF(cx->sb_rxtainted || RX_MATCH_TAINTED(rx));
152 (void)SvOOK_off(targ);
153 Safefree(SvPVX(targ));
154 SvPVX(targ) = SvPVX(dstr);
155 SvCUR_set(targ, SvCUR(dstr));
156 SvLEN_set(targ, SvLEN(dstr));
159 (void)SvPOK_only(targ);
163 PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
164 LEAVE_SCOPE(cx->sb_oldsave);
166 RETURNOP(pm->op_next);
169 if (rx->subbase && rx->subbase != orig) {
172 cx->sb_orig = orig = rx->subbase;
174 cx->sb_strend = s + (cx->sb_strend - m);
176 cx->sb_m = m = rx->startp[0];
177 sv_catpvn(dstr, s, m-s);
178 cx->sb_s = rx->endp[0];
179 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
180 rxres_save(&cx->sb_rxres, rx);
181 RETURNOP(pm->op_pmreplstart);
185 rxres_save(void **rsp, REGEXP *rx)
190 if (!p || p[1] < rx->nparens) {
191 i = 6 + rx->nparens * 2;
199 *p++ = (UV)rx->subbase;
200 rx->subbase = Nullch;
204 *p++ = (UV)rx->subbeg;
205 *p++ = (UV)rx->subend;
206 for (i = 0; i <= rx->nparens; ++i) {
207 *p++ = (UV)rx->startp[i];
208 *p++ = (UV)rx->endp[i];
213 rxres_restore(void **rsp, REGEXP *rx)
218 Safefree(rx->subbase);
219 rx->subbase = (char*)(*p);
224 rx->subbeg = (char*)(*p++);
225 rx->subend = (char*)(*p++);
226 for (i = 0; i <= rx->nparens; ++i) {
227 rx->startp[i] = (char*)(*p++);
228 rx->endp[i] = (char*)(*p++);
233 rxres_free(void **rsp)
238 Safefree((char*)(*p));
246 djSP; dMARK; dORIGMARK;
247 register SV *tmpForm = *++MARK;
259 bool chopspace = (strchr(chopset, ' ') != Nullch);
266 if (!SvMAGICAL(tmpForm) || !SvCOMPILED(tmpForm)) {
267 SvREADONLY_off(tmpForm);
268 doparseform(tmpForm);
271 SvPV_force(formtarget, len);
272 t = SvGROW(formtarget, len + SvCUR(tmpForm) + 1); /* XXX SvCUR bad */
274 f = SvPV(tmpForm, len);
275 /* need to jump to the next word */
276 s = f + len + WORD_ALIGN - SvCUR(tmpForm) % WORD_ALIGN;
285 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
286 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
287 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
288 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
289 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
291 case FF_CHECKNL: name = "CHECKNL"; break;
292 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
293 case FF_SPACE: name = "SPACE"; break;
294 case FF_HALFSPACE: name = "HALFSPACE"; break;
295 case FF_ITEM: name = "ITEM"; break;
296 case FF_CHOP: name = "CHOP"; break;
297 case FF_LINEGLOB: name = "LINEGLOB"; break;
298 case FF_NEWLINE: name = "NEWLINE"; break;
299 case FF_MORE: name = "MORE"; break;
300 case FF_LINEMARK: name = "LINEMARK"; break;
301 case FF_END: name = "END"; break;
304 PerlIO_printf(PerlIO_stderr(), "%-16s%ld\n", name, (long) arg);
306 PerlIO_printf(PerlIO_stderr(), "%-16s\n", name);
335 warn("Not enough format arguments");
340 item = s = SvPV(sv, len);
342 if (itemsize > fieldsize)
343 itemsize = fieldsize;
344 send = chophere = s + itemsize;
356 item = s = SvPV(sv, len);
358 if (itemsize <= fieldsize) {
359 send = chophere = s + itemsize;
370 itemsize = fieldsize;
371 send = chophere = s + itemsize;
372 while (s < send || (s == send && isSPACE(*s))) {
382 if (strchr(chopset, *s))
387 itemsize = chophere - item;
392 arg = fieldsize - itemsize;
401 arg = fieldsize - itemsize;
415 int ch = *t++ = *s++;
419 if ( !((*t++ = *s++) & ~31) )
429 while (*s && isSPACE(*s))
436 item = s = SvPV(sv, len);
449 SvCUR_set(formtarget, t - SvPVX(formtarget));
450 sv_catpvn(formtarget, item, itemsize);
451 SvGROW(formtarget, SvCUR(formtarget) + SvCUR(tmpForm) + 1);
452 t = SvPVX(formtarget) + SvCUR(formtarget);
457 /* If the field is marked with ^ and the value is undefined,
460 if ((arg & 512) && !SvOK(sv)) {
468 /* Formats aren't yet marked for locales, so assume "yes". */
471 sprintf(t, "%#*.*f", (int) fieldsize, (int) arg & 255, value);
473 sprintf(t, "%*.0f", (int) fieldsize, value);
480 while (t-- > linemark && *t == ' ') ;
488 if (arg) { /* repeat until fields exhausted? */
490 SvCUR_set(formtarget, t - SvPVX(formtarget));
491 lines += FmLINES(formtarget);
494 if (strnEQ(linemark, linemark - arg, arg))
495 DIE("Runaway format");
497 FmLINES(formtarget) = lines;
499 RETURNOP(cLISTOP->op_first);
510 arg = fieldsize - itemsize;
517 if (strnEQ(s," ",3)) {
518 while (s > SvPVX(formtarget) && isSPACE(s[-1]))
529 SvCUR_set(formtarget, t - SvPVX(formtarget));
530 FmLINES(formtarget) += lines;
542 if (stack_base + *markstack_ptr == sp) {
544 if (GIMME_V == G_SCALAR)
546 RETURNOP(op->op_next->op_next);
548 stack_sp = stack_base + *markstack_ptr + 1;
549 pp_pushmark(ARGS); /* push dst */
550 pp_pushmark(ARGS); /* push src */
551 ENTER; /* enter outer scope */
555 /* SAVE_DEFSV does *not* suffice here */
556 save_sptr(av_fetch(thr->threadsv, find_threadsv("_"), FALSE));
558 SAVESPTR(GvSV(defgv));
559 #endif /* USE_THREADS */
560 ENTER; /* enter inner scope */
563 src = stack_base[*markstack_ptr];
568 if (op->op_type == OP_MAPSTART)
569 pp_pushmark(ARGS); /* push top */
570 return ((LOGOP*)op->op_next)->op_other;
575 DIE("panic: mapstart"); /* uses grepstart */
581 I32 diff = (sp - stack_base) - *markstack_ptr;
589 if (diff > markstack_ptr[-1] - markstack_ptr[-2]) {
590 shift = diff - (markstack_ptr[-1] - markstack_ptr[-2]);
591 count = (sp - stack_base) - markstack_ptr[-1] + 2;
596 markstack_ptr[-1] += shift;
597 *markstack_ptr += shift;
601 dst = stack_base + (markstack_ptr[-2] += diff) - 1;
604 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
606 LEAVE; /* exit inner scope */
609 if (markstack_ptr[-1] > *markstack_ptr) {
613 (void)POPMARK; /* pop top */
614 LEAVE; /* exit outer scope */
615 (void)POPMARK; /* pop src */
616 items = --*markstack_ptr - markstack_ptr[-1];
617 (void)POPMARK; /* pop dst */
618 SP = stack_base + POPMARK; /* pop original mark */
619 if (gimme == G_SCALAR) {
623 else if (gimme == G_ARRAY)
630 ENTER; /* enter inner scope */
633 src = stack_base[markstack_ptr[-1]];
637 RETURNOP(cLOGOP->op_other);
643 static CPerlObj *pSortPerl;
644 static int SortCv(const void *a, const void *b)
646 return pSortPerl->sortcv(a, b);
648 static int SortCmp(const void *a, const void *b)
650 return pSortPerl->sortcmp(a, b);
652 static int SortCmpLocale(const void *a, const void *b)
654 return pSortPerl->sortcmp_locale(a, b);
660 djSP; dMARK; dORIGMARK;
662 SV **myorigmark = ORIGMARK;
668 OP* nextop = op->op_next;
670 if (gimme != G_ARRAY) {
675 if (op->op_flags & OPf_STACKED) {
677 if (op->op_flags & OPf_SPECIAL) {
678 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
679 kid = kUNOP->op_first; /* pass rv2gv */
680 kid = kUNOP->op_first; /* pass leave */
681 sortcop = kid->op_next;
682 stash = curcop->cop_stash;
685 cv = sv_2cv(*++MARK, &stash, &gv, 0);
686 if (!(cv && CvROOT(cv))) {
688 SV *tmpstr = sv_newmortal();
689 gv_efullname3(tmpstr, gv, Nullch);
690 if (cv && CvXSUB(cv))
691 DIE("Xsub \"%s\" called in sort", SvPVX(tmpstr));
692 DIE("Undefined sort subroutine \"%s\" called",
697 DIE("Xsub called in sort");
698 DIE("Undefined subroutine in sort");
700 DIE("Not a CODE reference in sort");
702 sortcop = CvSTART(cv);
703 SAVESPTR(CvROOT(cv)->op_ppaddr);
704 CvROOT(cv)->op_ppaddr = ppaddr[OP_NULL];
707 curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
712 stash = curcop->cop_stash;
716 while (MARK < SP) { /* This may or may not shift down one here. */
718 if (*up = *++MARK) { /* Weed out nulls. */
720 if (!sortcop && !SvPOK(*up))
721 (void)sv_2pv(*up, &na);
725 max = --up - myorigmark;
731 bool oldcatch = CATCH_GET;
739 AvREAL_off(sortstack);
740 av_extend(sortstack, 32);
743 SWITCHSTACK(curstack, sortstack);
744 if (sortstash != stash) {
745 firstgv = gv_fetchpv("a", TRUE, SVt_PV);
746 secondgv = gv_fetchpv("b", TRUE, SVt_PV);
750 SAVESPTR(GvSV(firstgv));
751 SAVESPTR(GvSV(secondgv));
753 PUSHBLOCK(cx, CXt_NULL, stack_base);
754 if (!(op->op_flags & OPf_SPECIAL)) {
755 bool hasargs = FALSE;
756 cx->cx_type = CXt_SUB;
757 cx->blk_gimme = G_SCALAR;
760 (void)SvREFCNT_inc(cv); /* in preparation for POPSUB */
762 sortcxix = cxstack_ix;
765 MUTEX_LOCK(&sort_mutex);
767 qsort((char*)(myorigmark+1), max, sizeof(SV*), SortCv);
768 MUTEX_UNLOCK(&sort_mutex);
770 qsort((char*)(myorigmark+1), max, sizeof(SV*), sortcv);
774 SWITCHSTACK(sortstack, oldstack);
781 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
783 MUTEX_LOCK(&sort_mutex);
785 qsort((char*)(ORIGMARK+1), max, sizeof(SV*),
786 (op->op_private & OPpLOCALE) ? SortCmpLocale : SortCmp);
787 MUTEX_UNLOCK(&sort_mutex);
789 qsort((char*)(ORIGMARK+1), max, sizeof(SV*),
790 (op->op_private & OPpLOCALE) ? sortcmp_locale : sortcmp);
794 stack_sp = ORIGMARK + max;
802 if (GIMME == G_ARRAY)
803 return cCONDOP->op_true;
804 return SvTRUEx(PAD_SV(op->op_targ)) ? cCONDOP->op_false : cCONDOP->op_true;
811 if (GIMME == G_ARRAY) {
812 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
816 SV *targ = PAD_SV(op->op_targ);
818 if ((op->op_private & OPpFLIP_LINENUM)
819 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
821 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
822 if (op->op_flags & OPf_SPECIAL) {
830 RETURNOP(((CONDOP*)cUNOP->op_first)->op_false);
843 if (GIMME == G_ARRAY) {
849 if (SvNIOKp(left) || !SvPOKp(left) ||
850 (looks_like_number(left) && *SvPVX(left) != '0') )
855 EXTEND_MORTAL(max - i + 1);
856 EXTEND(SP, max - i + 1);
859 sv = sv_2mortal(newSViv(i++));
864 SV *final = sv_mortalcopy(right);
866 char *tmps = SvPV(final, len);
868 sv = sv_mortalcopy(left);
869 while (!SvNIOKp(sv) && SvCUR(sv) <= len &&
870 strNE(SvPVX(sv),tmps) ) {
872 sv = sv_2mortal(newSVsv(sv));
875 if (strEQ(SvPVX(sv),tmps))
881 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
883 if ((op->op_private & OPpFLIP_LINENUM)
884 ? last_in_gv && SvIV(sv) == IoLINES(GvIOp(last_in_gv))
886 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
887 sv_catpv(targ, "E0");
898 dopoptolabel(char *label)
902 register PERL_CONTEXT *cx;
904 for (i = cxstack_ix; i >= 0; i--) {
906 switch (cx->cx_type) {
909 warn("Exiting substitution via %s", op_name[op->op_type]);
913 warn("Exiting subroutine via %s", op_name[op->op_type]);
917 warn("Exiting eval via %s", op_name[op->op_type]);
921 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
924 if (!cx->blk_loop.label ||
925 strNE(label, cx->blk_loop.label) ) {
926 DEBUG_l(deb("(Skipping label #%ld %s)\n",
927 (long)i, cx->blk_loop.label));
930 DEBUG_l( deb("(Found label #%ld %s)\n", (long)i, label));
940 I32 gimme = block_gimme();
941 return (gimme == G_VOID) ? G_SCALAR : gimme;
950 cxix = dopoptosub(cxstack_ix);
954 switch (cxstack[cxix].blk_gimme) {
960 croak("panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
967 dopoptosub(I32 startingblock)
971 register PERL_CONTEXT *cx;
972 for (i = startingblock; i >= 0; i--) {
974 switch (cx->cx_type) {
979 DEBUG_l( deb("(Found sub #%ld)\n", (long)i));
987 dopoptoeval(I32 startingblock)
991 register PERL_CONTEXT *cx;
992 for (i = startingblock; i >= 0; i--) {
994 switch (cx->cx_type) {
998 DEBUG_l( deb("(Found eval #%ld)\n", (long)i));
1006 dopoptoloop(I32 startingblock)
1010 register PERL_CONTEXT *cx;
1011 for (i = startingblock; i >= 0; i--) {
1013 switch (cx->cx_type) {
1016 warn("Exiting substitution via %s", op_name[op->op_type]);
1020 warn("Exiting subroutine via %s", op_name[op->op_type]);
1024 warn("Exiting eval via %s", op_name[op->op_type]);
1028 warn("Exiting pseudo-block via %s", op_name[op->op_type]);
1031 DEBUG_l( deb("(Found loop #%ld)\n", (long)i));
1042 register PERL_CONTEXT *cx;
1046 while (cxstack_ix > cxix) {
1047 cx = &cxstack[cxstack_ix];
1048 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n",
1049 (long) cxstack_ix+1, block_type[cx->cx_type]));
1050 /* Note: we don't need to restore the base context info till the end. */
1051 switch (cx->cx_type) {
1054 continue; /* not break */
1072 die_where(char *message)
1077 register PERL_CONTEXT *cx;
1083 STRLEN klen = strlen(message);
1085 svp = hv_fetch(ERRHV, message, klen, TRUE);
1088 static char prefix[] = "\t(in cleanup) ";
1090 sv_upgrade(*svp, SVt_IV);
1091 (void)SvIOK_only(*svp);
1094 SvGROW(err, SvCUR(err)+sizeof(prefix)+klen);
1095 sv_catpvn(err, prefix, sizeof(prefix)-1);
1096 sv_catpvn(err, message, klen);
1102 sv_setpv(ERRSV, message);
1104 cxix = dopoptoeval(cxstack_ix);
1108 if (cxix < cxstack_ix)
1112 if (cx->cx_type != CXt_EVAL) {
1113 PerlIO_printf(PerlIO_stderr(), "panic: die %s", message);
1118 if (gimme == G_SCALAR)
1119 *++newsp = &sv_undef;
1124 if (optype == OP_REQUIRE) {
1125 char* msg = SvPVx(ERRSV, na);
1126 DIE("%s", *msg ? msg : "Compilation failed in require");
1128 return pop_return();
1131 PerlIO_printf(PerlIO_stderr(), "%s",message);
1132 PerlIO_flush(PerlIO_stderr());
1141 if (SvTRUE(left) != SvTRUE(right))
1153 RETURNOP(cLOGOP->op_other);
1162 RETURNOP(cLOGOP->op_other);
1168 register I32 cxix = dopoptosub(cxstack_ix);
1169 register PERL_CONTEXT *cx;
1180 if (GIMME != G_ARRAY)
1184 if (DBsub && cxix >= 0 &&
1185 cxstack[cxix].blk_sub.cv == GvCV(DBsub))
1189 cxix = dopoptosub(cxix - 1);
1191 cx = &cxstack[cxix];
1192 if (cxstack[cxix].cx_type == CXt_SUB) {
1193 dbcxix = dopoptosub(cxix - 1);
1194 /* We expect that cxstack[dbcxix] is CXt_SUB, anyway, the
1195 field below is defined for any cx. */
1196 if (DBsub && dbcxix >= 0 && cxstack[dbcxix].blk_sub.cv == GvCV(DBsub))
1197 cx = &cxstack[dbcxix];
1200 if (GIMME != G_ARRAY) {
1203 sv_setpv(TARG, HvNAME(cx->blk_oldcop->cop_stash));
1208 PUSHs(sv_2mortal(newSVpv(HvNAME(cx->blk_oldcop->cop_stash), 0)));
1209 PUSHs(sv_2mortal(newSVpv(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)), 0)));
1210 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1213 if (cx->cx_type == CXt_SUB) { /* So is cxstack[dbcxix]. */
1215 gv_efullname3(sv, CvGV(cxstack[cxix].blk_sub.cv), Nullch);
1216 PUSHs(sv_2mortal(sv));
1217 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1220 PUSHs(sv_2mortal(newSVpv("(eval)",0)));
1221 PUSHs(sv_2mortal(newSViv(0)));
1223 gimme = (I32)cx->blk_gimme;
1224 if (gimme == G_VOID)
1227 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1228 if (cx->cx_type == CXt_EVAL) {
1229 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1230 PUSHs(cx->blk_eval.cur_text);
1233 else if (cx->blk_eval.old_name) { /* Try blocks have old_name == 0. */
1234 /* Require, put the name. */
1235 PUSHs(sv_2mortal(newSVpv(cx->blk_eval.old_name, 0)));
1239 else if (cx->cx_type == CXt_SUB &&
1240 cx->blk_sub.hasargs &&
1241 curcop->cop_stash == debstash)
1243 AV *ary = cx->blk_sub.argarray;
1244 int off = AvARRAY(ary) - AvALLOC(ary);
1248 dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1251 AvREAL_off(dbargs); /* XXX Should be REIFY */
1254 if (AvMAX(dbargs) < AvFILL(ary) + off)
1255 av_extend(dbargs, AvFILL(ary) + off);
1256 Copy(AvALLOC(ary), AvARRAY(dbargs), AvFILL(ary) + 1 + off, SV*);
1257 AvFILL(dbargs) = AvFILL(ary) + off;
1263 sortcv(const void *a, const void *b)
1266 SV * const *str1 = (SV * const *)a;
1267 SV * const *str2 = (SV * const *)b;
1268 I32 oldsaveix = savestack_ix;
1269 I32 oldscopeix = scopestack_ix;
1271 GvSV(firstgv) = *str1;
1272 GvSV(secondgv) = *str2;
1273 stack_sp = stack_base;
1276 if (stack_sp != stack_base + 1)
1277 croak("Sort subroutine didn't return single value");
1278 if (!SvNIOKp(*stack_sp))
1279 croak("Sort subroutine didn't return a numeric value");
1280 result = SvIV(*stack_sp);
1281 while (scopestack_ix > oldscopeix) {
1284 leave_scope(oldsaveix);
1289 sortcmp(const void *a, const void *b)
1291 return sv_cmp(*(SV * const *)a, *(SV * const *)b);
1295 sortcmp_locale(const void *a, const void *b)
1297 return sv_cmp_locale(*(SV * const *)a, *(SV * const *)b);
1309 sv_reset(tmps, curcop->cop_stash);
1322 TAINT_NOT; /* Each statement is presumed innocent */
1323 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
1326 if (op->op_private || SvIV(DBsingle) || SvIV(DBsignal) || SvIV(DBtrace))
1330 register PERL_CONTEXT *cx;
1331 I32 gimme = G_ARRAY;
1338 DIE("No DB::DB routine defined");
1340 if (CvDEPTH(cv) >= 1 && !(debug & (1<<30))) /* don't do recursive DB::DB call */
1352 push_return(op->op_next);
1353 PUSHBLOCK(cx, CXt_SUB, sp);
1356 (void)SvREFCNT_inc(cv);
1358 curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1359 RETURNOP(CvSTART(cv));
1373 register PERL_CONTEXT *cx;
1374 I32 gimme = GIMME_V;
1381 if (op->op_flags & OPf_SPECIAL)
1382 svp = save_threadsv(op->op_targ); /* per-thread variable */
1384 #endif /* USE_THREADS */
1386 svp = &curpad[op->op_targ]; /* "my" variable */
1390 svp = &GvSV((GV*)POPs); /* symbol table variable */
1396 PUSHBLOCK(cx, CXt_LOOP, SP);
1397 PUSHLOOP(cx, svp, MARK);
1398 if (op->op_flags & OPf_STACKED)
1399 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1401 cx->blk_loop.iterary = curstack;
1402 AvFILL(curstack) = sp - stack_base;
1403 cx->blk_loop.iterix = MARK - stack_base;
1412 register PERL_CONTEXT *cx;
1413 I32 gimme = GIMME_V;
1419 PUSHBLOCK(cx, CXt_LOOP, SP);
1420 PUSHLOOP(cx, 0, SP);
1428 register PERL_CONTEXT *cx;
1429 struct block_loop cxloop;
1437 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1440 if (gimme == G_VOID)
1442 else if (gimme == G_SCALAR) {
1444 *++newsp = sv_mortalcopy(*SP);
1446 *++newsp = &sv_undef;
1450 *++newsp = sv_mortalcopy(*++mark);
1451 TAINT_NOT; /* Each item is independent */
1457 POPLOOP2(); /* Stack values are safe: release loop vars ... */
1458 curpm = newpm; /* ... and pop $1 et al */
1470 register PERL_CONTEXT *cx;
1471 struct block_sub cxsub;
1472 bool popsub2 = FALSE;
1478 if (curstack == sortstack) {
1479 if (cxstack_ix == sortcxix || dopoptosub(cxstack_ix) <= sortcxix) {
1480 if (cxstack_ix > sortcxix)
1482 AvARRAY(curstack)[1] = *SP;
1483 stack_sp = stack_base + 1;
1488 cxix = dopoptosub(cxstack_ix);
1490 DIE("Can't return outside a subroutine");
1491 if (cxix < cxstack_ix)
1495 switch (cx->cx_type) {
1497 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1502 if (optype == OP_REQUIRE &&
1503 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1505 /* Unassume the success we assumed earlier. */
1506 char *name = cx->blk_eval.old_name;
1507 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
1508 DIE("%s did not return a true value", name);
1512 DIE("panic: return");
1516 if (gimme == G_SCALAR) {
1518 *++newsp = (popsub2 && SvTEMP(*SP))
1519 ? *SP : sv_mortalcopy(*SP);
1521 *++newsp = &sv_undef;
1523 else if (gimme == G_ARRAY) {
1524 while (++MARK <= SP) {
1525 *++newsp = (popsub2 && SvTEMP(*MARK))
1526 ? *MARK : sv_mortalcopy(*MARK);
1527 TAINT_NOT; /* Each item is independent */
1532 /* Stack values are safe: */
1534 POPSUB2(); /* release CV and @_ ... */
1536 curpm = newpm; /* ... and pop $1 et al */
1539 return pop_return();
1546 register PERL_CONTEXT *cx;
1547 struct block_loop cxloop;
1548 struct block_sub cxsub;
1555 SV **mark = stack_base + cxstack[cxstack_ix].blk_oldsp;
1557 if (op->op_flags & OPf_SPECIAL) {
1558 cxix = dopoptoloop(cxstack_ix);
1560 DIE("Can't \"last\" outside a block");
1563 cxix = dopoptolabel(cPVOP->op_pv);
1565 DIE("Label not found for \"last %s\"", cPVOP->op_pv);
1567 if (cxix < cxstack_ix)
1571 switch (cx->cx_type) {
1573 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1575 nextop = cxloop.last_op->op_next;
1578 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1580 nextop = pop_return();
1584 nextop = pop_return();
1591 if (gimme == G_SCALAR) {
1593 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
1594 ? *SP : sv_mortalcopy(*SP);
1596 *++newsp = &sv_undef;
1598 else if (gimme == G_ARRAY) {
1599 while (++MARK <= SP) {
1600 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
1601 ? *MARK : sv_mortalcopy(*MARK);
1602 TAINT_NOT; /* Each item is independent */
1608 /* Stack values are safe: */
1611 POPLOOP2(); /* release loop vars ... */
1615 POPSUB2(); /* release CV and @_ ... */
1618 curpm = newpm; /* ... and pop $1 et al */
1627 register PERL_CONTEXT *cx;
1630 if (op->op_flags & OPf_SPECIAL) {
1631 cxix = dopoptoloop(cxstack_ix);
1633 DIE("Can't \"next\" outside a block");
1636 cxix = dopoptolabel(cPVOP->op_pv);
1638 DIE("Label not found for \"next %s\"", cPVOP->op_pv);
1640 if (cxix < cxstack_ix)
1644 oldsave = scopestack[scopestack_ix - 1];
1645 LEAVE_SCOPE(oldsave);
1646 return cx->blk_loop.next_op;
1652 register PERL_CONTEXT *cx;
1655 if (op->op_flags & OPf_SPECIAL) {
1656 cxix = dopoptoloop(cxstack_ix);
1658 DIE("Can't \"redo\" outside a block");
1661 cxix = dopoptolabel(cPVOP->op_pv);
1663 DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
1665 if (cxix < cxstack_ix)
1669 oldsave = scopestack[scopestack_ix - 1];
1670 LEAVE_SCOPE(oldsave);
1671 return cx->blk_loop.redo_op;
1674 static OP* lastgotoprobe;
1677 dofindlabel(OP *o, char *label, OP **opstack, OP **oplimit)
1681 static char too_deep[] = "Target of goto is too deeply nested";
1685 if (o->op_type == OP_LEAVE ||
1686 o->op_type == OP_SCOPE ||
1687 o->op_type == OP_LEAVELOOP ||
1688 o->op_type == OP_LEAVETRY)
1690 *ops++ = cUNOPo->op_first;
1695 if (o->op_flags & OPf_KIDS) {
1696 /* First try all the kids at this level, since that's likeliest. */
1697 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1698 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1699 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1702 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1703 if (kid == lastgotoprobe)
1705 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1707 (ops[-1]->op_type != OP_NEXTSTATE &&
1708 ops[-1]->op_type != OP_DBSTATE)))
1710 if (o = dofindlabel(kid, label, ops, oplimit))
1720 return pp_goto(ARGS);
1729 register PERL_CONTEXT *cx;
1730 #define GOTO_DEPTH 64
1731 OP *enterops[GOTO_DEPTH];
1733 int do_dump = (op->op_type == OP_DUMP);
1736 if (op->op_flags & OPf_STACKED) {
1739 /* This egregious kludge implements goto &subroutine */
1740 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1742 register PERL_CONTEXT *cx;
1743 CV* cv = (CV*)SvRV(sv);
1748 if (!CvROOT(cv) && !CvXSUB(cv)) {
1750 SV *tmpstr = sv_newmortal();
1751 gv_efullname3(tmpstr, CvGV(cv), Nullch);
1752 DIE("Goto undefined subroutine &%s",SvPVX(tmpstr));
1754 DIE("Goto undefined subroutine");
1757 /* First do some returnish stuff. */
1758 cxix = dopoptosub(cxstack_ix);
1760 DIE("Can't goto subroutine outside a subroutine");
1761 if (cxix < cxstack_ix)
1765 if (cx->blk_sub.hasargs) { /* put @_ back onto stack */
1766 AV* av = cx->blk_sub.argarray;
1768 items = AvFILL(av) + 1;
1770 EXTEND(stack_sp, items); /* @_ could have been extended. */
1771 Copy(AvARRAY(av), stack_sp, items, SV*);
1774 SvREFCNT_dec(GvAV(defgv));
1775 GvAV(defgv) = cx->blk_sub.savearray;
1776 #endif /* USE_THREADS */
1780 if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
1781 SvREFCNT_dec(cx->blk_sub.cv);
1782 oldsave = scopestack[scopestack_ix - 1];
1783 LEAVE_SCOPE(oldsave);
1785 /* Now do some callish stuff. */
1788 if (CvOLDSTYLE(cv)) {
1789 I32 (*fp3)_((int,int,int));
1794 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1795 items = (*fp3)(CvXSUBANY(cv).any_i32,
1796 mark - stack_base + 1,
1798 sp = stack_base + items;
1801 stack_sp--; /* There is no cv arg. */
1802 (void)(*CvXSUB(cv))(THIS_ cv);
1805 return pop_return();
1808 AV* padlist = CvPADLIST(cv);
1809 SV** svp = AvARRAY(padlist);
1810 cx->blk_sub.cv = cv;
1811 cx->blk_sub.olddepth = CvDEPTH(cv);
1813 if (CvDEPTH(cv) < 2)
1814 (void)SvREFCNT_inc(cv);
1815 else { /* save temporaries on recursion? */
1816 if (CvDEPTH(cv) == 100 && dowarn)
1817 sub_crush_depth(cv);
1818 if (CvDEPTH(cv) > AvFILL(padlist)) {
1819 AV *newpad = newAV();
1820 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
1821 I32 ix = AvFILL((AV*)svp[1]);
1822 svp = AvARRAY(svp[0]);
1823 for ( ;ix > 0; ix--) {
1824 if (svp[ix] != &sv_undef) {
1825 char *name = SvPVX(svp[ix]);
1826 if ((SvFLAGS(svp[ix]) & SVf_FAKE)
1829 /* outer lexical or anon code */
1830 av_store(newpad, ix,
1831 SvREFCNT_inc(oldpad[ix]) );
1833 else { /* our own lexical */
1835 av_store(newpad, ix, sv = (SV*)newAV());
1836 else if (*name == '%')
1837 av_store(newpad, ix, sv = (SV*)newHV());
1839 av_store(newpad, ix, sv = NEWSV(0,0));
1844 av_store(newpad, ix, sv = NEWSV(0,0));
1848 if (cx->blk_sub.hasargs) {
1851 av_store(newpad, 0, (SV*)av);
1852 AvFLAGS(av) = AVf_REIFY;
1854 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1855 AvFILL(padlist) = CvDEPTH(cv);
1856 svp = AvARRAY(padlist);
1860 if (!cx->blk_sub.hasargs) {
1861 AV* av = (AV*)curpad[0];
1863 items = AvFILL(av) + 1;
1865 /* Mark is at the end of the stack. */
1867 Copy(AvARRAY(av), sp + 1, items, SV*);
1872 #endif /* USE_THREADS */
1874 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1876 if (cx->blk_sub.hasargs)
1877 #endif /* USE_THREADS */
1879 AV* av = (AV*)curpad[0];
1883 cx->blk_sub.savearray = GvAV(defgv);
1884 GvAV(defgv) = (AV*)SvREFCNT_inc(av);
1885 #endif /* USE_THREADS */
1886 cx->blk_sub.argarray = av;
1889 if (items >= AvMAX(av) + 1) {
1891 if (AvARRAY(av) != ary) {
1892 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1893 SvPVX(av) = (char*)ary;
1895 if (items >= AvMAX(av) + 1) {
1896 AvMAX(av) = items - 1;
1897 Renew(ary,items+1,SV*);
1899 SvPVX(av) = (char*)ary;
1902 Copy(mark,AvARRAY(av),items,SV*);
1903 AvFILL(av) = items - 1;
1911 if (PERLDB_SUB && curstash != debstash) {
1913 * We do not care about using sv to call CV;
1914 * it's for informational purposes only.
1916 SV *sv = GvSV(DBsub);
1918 gv_efullname3(sv, CvGV(cv), Nullch);
1920 RETURNOP(CvSTART(cv));
1924 label = SvPV(sv,na);
1926 else if (op->op_flags & OPf_SPECIAL) {
1928 DIE("goto must have label");
1931 label = cPVOP->op_pv;
1933 if (label && *label) {
1940 for (ix = cxstack_ix; ix >= 0; ix--) {
1942 switch (cx->cx_type) {
1944 gotoprobe = eval_root; /* XXX not good for nested eval */
1947 gotoprobe = cx->blk_oldcop->op_sibling;
1953 gotoprobe = cx->blk_oldcop->op_sibling;
1955 gotoprobe = main_root;
1958 if (CvDEPTH(cx->blk_sub.cv)) {
1959 gotoprobe = CvROOT(cx->blk_sub.cv);
1964 DIE("Can't \"goto\" outside a block");
1968 gotoprobe = main_root;
1971 retop = dofindlabel(gotoprobe, label,
1972 enterops, enterops + GOTO_DEPTH);
1975 lastgotoprobe = gotoprobe;
1978 DIE("Can't find label %s", label);
1980 /* pop unwanted frames */
1982 if (ix < cxstack_ix) {
1989 oldsave = scopestack[scopestack_ix];
1990 LEAVE_SCOPE(oldsave);
1993 /* push wanted frames */
1995 if (*enterops && enterops[1]) {
1997 for (ix = 1; enterops[ix]; ix++) {
1999 /* Eventually we may want to stack the needed arguments
2000 * for each op. For now, we punt on the hard ones. */
2001 if (op->op_type == OP_ENTERITER)
2002 DIE("Can't \"goto\" into the middle of a foreach loop",
2004 (CALLOP->op_ppaddr)(ARGS);
2012 if (!retop) retop = main_start;
2019 restartop = 0; /* hmm, must be GNU unexec().. */
2023 if (curstack == signalstack) {
2041 if (anum == 1 && VMSISH_EXIT)
2054 double value = SvNVx(GvSV(cCOP->cop_gv));
2055 register I32 match = I_32(value);
2058 if (((double)match) > value)
2059 --match; /* was fractional--truncate other way */
2061 match -= cCOP->uop.scop.scop_offset;
2064 else if (match > cCOP->uop.scop.scop_max)
2065 match = cCOP->uop.scop.scop_max;
2066 op = cCOP->uop.scop.scop_next[match];
2076 op = op->op_next; /* can't assume anything */
2078 match = *(SvPVx(GvSV(cCOP->cop_gv), na)) & 255;
2079 match -= cCOP->uop.scop.scop_offset;
2082 else if (match > cCOP->uop.scop.scop_max)
2083 match = cCOP->uop.scop.scop_max;
2084 op = cCOP->uop.scop.scop_next[match];
2093 save_lines(AV *array, SV *sv)
2095 register char *s = SvPVX(sv);
2096 register char *send = SvPVX(sv) + SvCUR(sv);
2098 register I32 line = 1;
2100 while (s && s < send) {
2101 SV *tmpstr = NEWSV(85,0);
2103 sv_upgrade(tmpstr, SVt_PVMG);
2104 t = strchr(s, '\n');
2110 sv_setpvn(tmpstr, s, t - s);
2111 av_store(array, line++, tmpstr);
2126 assert(CATCH_GET == TRUE);
2127 DEBUG_l(deb("Setting up local jumplevel %p, was %p\n", &cur_env, top_env));
2131 default: /* topmost level handles it */
2138 PerlIO_printf(PerlIO_stderr(), "panic: restartop\n");
2154 sv_compile_2op(SV *sv, OP** startop, char *code, AV** avp)
2155 /* sv Text to convert to OP tree. */
2156 /* startop op_free() this to undo. */
2157 /* code Short string id of the caller. */
2159 dSP; /* Make POPBLOCK work. */
2162 I32 gimme = 0; /* SUSPECT - INITIALZE TO WHAT? NI-S */
2166 char tmpbuf[TYPE_DIGITS(long) + 12 + 10];
2172 /* switch to eval mode */
2174 SAVESPTR(compiling.cop_filegv);
2175 SAVEI16(compiling.cop_line);
2176 sprintf(tmpbuf, "_<(%.10s_eval %lu)", code, (unsigned long)++evalseq);
2177 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2178 compiling.cop_line = 1;
2179 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2180 deleting the eval's FILEGV from the stash before gv_check() runs
2181 (i.e. before run-time proper). To work around the coredump that
2182 ensues, we always turn GvMULTI_on for any globals that were
2183 introduced within evals. See force_ident(). GSAR 96-10-12 */
2184 safestr = savepv(tmpbuf);
2185 SAVEDELETE(defstash, safestr, strlen(safestr));
2191 op->op_type = 0; /* Avoid uninit warning. */
2192 op->op_flags = 0; /* Avoid uninit warning. */
2193 PUSHBLOCK(cx, CXt_EVAL, SP);
2194 PUSHEVAL(cx, 0, compiling.cop_filegv);
2195 rop = doeval(G_SCALAR, startop);
2199 (*startop)->op_type = OP_NULL;
2200 (*startop)->op_ppaddr = ppaddr[OP_NULL];
2202 *avp = (AV*)SvREFCNT_inc(comppad);
2207 /* With USE_THREADS, eval_owner must be held on entry to doeval */
2209 doeval(int gimme, OP** startop)
2221 /* set up a scratch pad */
2226 SAVESPTR(comppad_name);
2227 SAVEI32(comppad_name_fill);
2228 SAVEI32(min_intro_pending);
2229 SAVEI32(max_intro_pending);
2233 compcv = (CV*)NEWSV(1104,0);
2234 sv_upgrade((SV *)compcv, SVt_PVCV);
2235 CvUNIQUE_on(compcv);
2237 CvOWNER(compcv) = 0;
2238 New(666, CvMUTEXP(compcv), 1, perl_mutex);
2239 MUTEX_INIT(CvMUTEXP(compcv));
2240 #endif /* USE_THREADS */
2243 av_push(comppad, Nullsv);
2244 curpad = AvARRAY(comppad);
2245 comppad_name = newAV();
2246 comppad_name_fill = 0;
2247 min_intro_pending = 0;
2250 av_store(comppad_name, 0, newSVpv("@_", 2));
2251 curpad[0] = (SV*)newAV();
2252 SvPADMY_on(curpad[0]); /* XXX Needed? */
2253 #endif /* USE_THREADS */
2255 comppadlist = newAV();
2256 AvREAL_off(comppadlist);
2257 av_store(comppadlist, 0, (SV*)comppad_name);
2258 av_store(comppadlist, 1, (SV*)comppad);
2259 CvPADLIST(compcv) = comppadlist;
2261 if (!saveop || saveop->op_type != OP_REQUIRE)
2262 CvOUTSIDE(compcv) = (CV*)SvREFCNT_inc(caller);
2266 /* make sure we compile in the right package */
2268 newstash = curcop->cop_stash;
2269 if (curstash != newstash) {
2271 curstash = newstash;
2275 SAVEFREESV(beginav);
2277 /* try to compile it */
2281 curcop = &compiling;
2282 curcop->cop_arybase = 0;
2284 rs = newSVpv("\n", 1);
2285 if (saveop && saveop->op_flags & OPf_SPECIAL)
2289 if (yyparse() || error_count || !eval_root) {
2293 I32 optype = 0; /* Might be reset by POPEVAL. */
2300 SP = stack_base + POPMARK; /* pop original mark */
2308 if (optype == OP_REQUIRE) {
2309 char* msg = SvPVx(ERRSV, na);
2310 DIE("%s", *msg ? msg : "Compilation failed in require");
2311 } else if (startop) {
2312 char* msg = SvPVx(ERRSV, na);
2316 croak("%sCompilation failed in regexp", (*msg ? msg : "Unknown error\n"));
2319 rs = SvREFCNT_inc(nrs);
2321 MUTEX_LOCK(&eval_mutex);
2323 COND_SIGNAL(&eval_cond);
2324 MUTEX_UNLOCK(&eval_mutex);
2325 #endif /* USE_THREADS */
2329 rs = SvREFCNT_inc(nrs);
2330 compiling.cop_line = 0;
2332 *startop = eval_root;
2333 SvREFCNT_dec(CvOUTSIDE(compcv));
2334 CvOUTSIDE(compcv) = Nullcv;
2336 SAVEFREEOP(eval_root);
2338 scalarvoid(eval_root);
2339 else if (gimme & G_ARRAY)
2344 DEBUG_x(dump_eval());
2346 /* Register with debugger: */
2347 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2348 CV *cv = perl_get_cv("DB::postponed", FALSE);
2352 XPUSHs((SV*)compiling.cop_filegv);
2354 perl_call_sv((SV*)cv, G_DISCARD);
2358 /* compiled okay, so do it */
2360 CvDEPTH(compcv) = 1;
2361 SP = stack_base + POPMARK; /* pop original mark */
2362 op = saveop; /* The caller may need it. */
2364 MUTEX_LOCK(&eval_mutex);
2366 COND_SIGNAL(&eval_cond);
2367 MUTEX_UNLOCK(&eval_mutex);
2368 #endif /* USE_THREADS */
2370 RETURNOP(eval_start);
2376 register PERL_CONTEXT *cx;
2380 SV *namesv = Nullsv;
2382 I32 gimme = G_SCALAR;
2383 PerlIO *tryrsfp = 0;
2386 if (SvNIOKp(sv) && !SvPOKp(sv)) {
2387 SET_NUMERIC_STANDARD();
2388 if (atof(patchlevel) + 0.00000999 < SvNV(sv))
2389 DIE("Perl %s required--this is only version %s, stopped",
2390 SvPV(sv,na),patchlevel);
2393 name = SvPV(sv, na);
2395 DIE("Null filename used");
2396 TAINT_PROPER("require");
2397 if (op->op_type == OP_REQUIRE &&
2398 (svp = hv_fetch(GvHVn(incgv), name, SvCUR(sv), 0)) &&
2402 /* prepare to compile file */
2407 (name[1] == '.' && name[2] == '/')))
2409 || (name[0] && name[1] == ':')
2412 || (name[0] == '\\' && name[1] == '\\') /* UNC path */
2415 || (strchr(name,':') || ((*name == '[' || *name == '<') &&
2416 (isALNUM(name[1]) || strchr("$-_]>",name[1]))))
2421 tryrsfp = PerlIO_open(name,PERL_SCRIPT_MODE);
2424 AV *ar = GvAVn(incgv);
2428 if ((unixname = tounixspec(name, Nullch)) != Nullch)
2431 namesv = NEWSV(806, 0);
2432 for (i = 0; i <= AvFILL(ar); i++) {
2433 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2436 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
2438 sv_setpv(namesv, unixdir);
2439 sv_catpv(namesv, unixname);
2441 sv_setpvf(namesv, "%s/%s", dir, name);
2443 tryname = SvPVX(namesv);
2444 tryrsfp = PerlIO_open(tryname, PERL_SCRIPT_MODE);
2446 if (tryname[0] == '.' && tryname[1] == '/')
2453 SAVESPTR(compiling.cop_filegv);
2454 compiling.cop_filegv = gv_fetchfile(tryrsfp ? tryname : name);
2455 SvREFCNT_dec(namesv);
2457 if (op->op_type == OP_REQUIRE) {
2458 SV *msg = sv_2mortal(newSVpvf("Can't locate %s in @INC", name));
2459 SV *dirmsgsv = NEWSV(0, 0);
2460 AV *ar = GvAVn(incgv);
2462 if (instr(SvPVX(msg), ".h "))
2463 sv_catpv(msg, " (change .h to .ph maybe?)");
2464 if (instr(SvPVX(msg), ".ph "))
2465 sv_catpv(msg, " (did you run h2ph?)");
2466 sv_catpv(msg, " (@INC contains:");
2467 for (i = 0; i <= AvFILL(ar); i++) {
2468 char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
2469 sv_setpvf(dirmsgsv, " %s", dir);
2470 sv_catsv(msg, dirmsgsv);
2472 sv_catpvn(msg, ")", 1);
2473 SvREFCNT_dec(dirmsgsv);
2480 /* Assume success here to prevent recursive requirement. */
2481 (void)hv_store(GvHVn(incgv), name, strlen(name),
2482 newSVsv(GvSV(compiling.cop_filegv)), 0 );
2486 lex_start(sv_2mortal(newSVpv("",0)));
2488 save_aptr(&rsfp_filters);
2489 rsfp_filters = NULL;
2493 name = savepv(name);
2498 /* switch to eval mode */
2500 push_return(op->op_next);
2501 PUSHBLOCK(cx, CXt_EVAL, SP);
2502 PUSHEVAL(cx, name, compiling.cop_filegv);
2504 compiling.cop_line = 0;
2508 MUTEX_LOCK(&eval_mutex);
2509 if (eval_owner && eval_owner != thr)
2511 COND_WAIT(&eval_cond, &eval_mutex);
2513 MUTEX_UNLOCK(&eval_mutex);
2514 #endif /* USE_THREADS */
2515 return DOCATCH(doeval(G_SCALAR, NULL));
2520 return pp_require(ARGS);
2526 register PERL_CONTEXT *cx;
2528 I32 gimme = GIMME_V, was = sub_generation;
2529 char tmpbuf[TYPE_DIGITS(long) + 12];
2534 if (!SvPV(sv,len) || !len)
2536 TAINT_PROPER("eval");
2542 /* switch to eval mode */
2544 SAVESPTR(compiling.cop_filegv);
2545 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++evalseq);
2546 compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2547 compiling.cop_line = 1;
2548 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2549 deleting the eval's FILEGV from the stash before gv_check() runs
2550 (i.e. before run-time proper). To work around the coredump that
2551 ensues, we always turn GvMULTI_on for any globals that were
2552 introduced within evals. See force_ident(). GSAR 96-10-12 */
2553 safestr = savepv(tmpbuf);
2554 SAVEDELETE(defstash, safestr, strlen(safestr));
2556 hints = op->op_targ;
2558 push_return(op->op_next);
2559 PUSHBLOCK(cx, CXt_EVAL, SP);
2560 PUSHEVAL(cx, 0, compiling.cop_filegv);
2562 /* prepare to compile string */
2564 if (PERLDB_LINE && curstash != debstash)
2565 save_lines(GvAV(compiling.cop_filegv), linestr);
2568 MUTEX_LOCK(&eval_mutex);
2569 if (eval_owner && eval_owner != thr)
2571 COND_WAIT(&eval_cond, &eval_mutex);
2573 MUTEX_UNLOCK(&eval_mutex);
2574 #endif /* USE_THREADS */
2575 ret = doeval(gimme, NULL);
2576 if (PERLDB_INTER && was != sub_generation /* Some subs defined here. */
2577 && ret != op->op_next) { /* Successive compilation. */
2578 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
2580 return DOCATCH(ret);
2590 register PERL_CONTEXT *cx;
2592 U8 save_flags = op -> op_flags;
2597 retop = pop_return();
2600 if (gimme == G_VOID)
2602 else if (gimme == G_SCALAR) {
2605 if (SvFLAGS(TOPs) & SVs_TEMP)
2608 *MARK = sv_mortalcopy(TOPs);
2616 /* in case LEAVE wipes old return values */
2617 for (mark = newsp + 1; mark <= SP; mark++) {
2618 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
2619 *mark = sv_mortalcopy(*mark);
2620 TAINT_NOT; /* Each item is independent */
2624 curpm = newpm; /* Don't pop $1 et al till now */
2627 * Closures mentioned at top level of eval cannot be referenced
2628 * again, and their presence indirectly causes a memory leak.
2629 * (Note that the fact that compcv and friends are still set here
2630 * is, AFAIK, an accident.) --Chip
2632 if (AvFILL(comppad_name) >= 0) {
2633 SV **svp = AvARRAY(comppad_name);
2635 for (ix = AvFILL(comppad_name); ix >= 0; ix--) {
2637 if (sv && sv != &sv_undef && *SvPVX(sv) == '&') {
2639 svp[ix] = &sv_undef;
2643 SvREFCNT_dec(CvOUTSIDE(sv));
2644 CvOUTSIDE(sv) = Nullcv;
2657 assert(CvDEPTH(compcv) == 1);
2659 CvDEPTH(compcv) = 0;
2661 if (optype == OP_REQUIRE &&
2662 !(gimme == G_SCALAR ? SvTRUE(*sp) : sp > newsp))
2664 /* Unassume the success we assumed earlier. */
2665 char *name = cx->blk_eval.old_name;
2666 (void)hv_delete(GvHVn(incgv), name, strlen(name), G_DISCARD);
2667 retop = die("%s did not return a true value", name);
2673 if (!(save_flags & OPf_SPECIAL))
2682 register PERL_CONTEXT *cx;
2683 I32 gimme = GIMME_V;
2688 push_return(cLOGOP->op_other->op_next);
2689 PUSHBLOCK(cx, CXt_EVAL, SP);
2691 eval_root = op; /* Only needed so that goto works right. */
2696 return DOCATCH(op->op_next);
2706 register PERL_CONTEXT *cx;
2714 if (gimme == G_VOID)
2716 else if (gimme == G_SCALAR) {
2719 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
2722 *MARK = sv_mortalcopy(TOPs);
2731 /* in case LEAVE wipes old return values */
2732 for (mark = newsp + 1; mark <= SP; mark++) {
2733 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
2734 *mark = sv_mortalcopy(*mark);
2735 TAINT_NOT; /* Each item is independent */
2739 curpm = newpm; /* Don't pop $1 et al till now */
2750 register char *s = SvPV_force(sv, len);
2751 register char *send = s + len;
2752 register char *base;
2753 register I32 skipspaces = 0;
2756 bool postspace = FALSE;
2764 croak("Null picture in formline");
2766 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
2771 *fpc++ = FF_LINEMARK;
2772 noblank = repeat = FALSE;
2790 case ' ': case '\t':
2801 *fpc++ = FF_LITERAL;
2809 *fpc++ = skipspaces;
2813 *fpc++ = FF_NEWLINE;
2817 arg = fpc - linepc + 1;
2824 *fpc++ = FF_LINEMARK;
2825 noblank = repeat = FALSE;
2834 ischop = s[-1] == '^';
2840 arg = (s - base) - 1;
2842 *fpc++ = FF_LITERAL;
2851 *fpc++ = FF_LINEGLOB;
2853 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
2854 arg = ischop ? 512 : 0;
2864 arg |= 256 + (s - f);
2866 *fpc++ = s - base; /* fieldsize for FETCH */
2867 *fpc++ = FF_DECIMAL;
2872 bool ismore = FALSE;
2875 while (*++s == '>') ;
2876 prespace = FF_SPACE;
2878 else if (*s == '|') {
2879 while (*++s == '|') ;
2880 prespace = FF_HALFSPACE;
2885 while (*++s == '<') ;
2888 if (*s == '.' && s[1] == '.' && s[2] == '.') {
2892 *fpc++ = s - base; /* fieldsize for FETCH */
2894 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
2912 { /* need to jump to the next word */
2914 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
2915 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
2916 s = SvPVX(sv) + SvCUR(sv) + z;
2918 Copy(fops, s, arg, U16);
2920 sv_magic(sv, Nullsv, 'f', Nullch, 0);