3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * Now far ahead the Road has gone,
13 * And I must follow, if I can,
14 * Pursuing it with eager feet,
15 * Until it joins some larger way
16 * Where many paths and errands meet.
17 * And whither then? I cannot say.
21 #define PERL_IN_PP_CTL_C
25 #define WORD_ALIGN sizeof(U32)
28 #define DOCATCH(o) ((CATCH_GET == TRUE) ? docatch(o) : (o))
30 static I32 run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen);
38 cxix = dopoptosub(cxstack_ix);
42 switch (cxstack[cxix].blk_gimme) {
59 /* XXXX Should store the old value to allow for tie/overload - and
60 restore in regcomp, where marked with XXXX. */
69 register PMOP *pm = (PMOP*)cLOGOP->op_other;
73 MAGIC *mg = Null(MAGIC*);
77 /* prevent recompiling under /o and ithreads. */
78 #if defined(USE_ITHREADS)
79 if (pm->op_pmflags & PMf_KEEP && PM_GETRE(pm))
84 SV *sv = SvRV(tmpstr);
86 mg = mg_find(sv, PERL_MAGIC_qr);
89 regexp *re = (regexp *)mg->mg_obj;
90 ReREFCNT_dec(PM_GETRE(pm));
91 PM_SETRE(pm, ReREFCNT_inc(re));
94 t = SvPV(tmpstr, len);
96 /* Check against the last compiled regexp. */
97 if (!PM_GETRE(pm) || !PM_GETRE(pm)->precomp ||
98 PM_GETRE(pm)->prelen != (I32)len ||
99 memNE(PM_GETRE(pm)->precomp, t, len))
102 ReREFCNT_dec(PM_GETRE(pm));
103 PM_SETRE(pm, Null(REGEXP*)); /* crucial if regcomp aborts */
105 if (PL_op->op_flags & OPf_SPECIAL)
106 PL_reginterp_cnt = I32_MAX; /* Mark as safe. */
108 pm->op_pmflags = pm->op_pmpermflags; /* reset case sensitivity */
110 pm->op_pmdynflags |= PMdf_DYN_UTF8;
112 pm->op_pmdynflags &= ~PMdf_DYN_UTF8;
113 if (pm->op_pmdynflags & PMdf_UTF8)
114 t = (char*)bytes_to_utf8((U8*)t, &len);
116 PM_SETRE(pm, CALLREGCOMP(aTHX_ t, t + len, pm));
117 if (!DO_UTF8(tmpstr) && (pm->op_pmdynflags & PMdf_UTF8))
119 PL_reginterp_cnt = 0; /* XXXX Be extra paranoid - needed
120 inside tie/overload accessors. */
124 #ifndef INCOMPLETE_TAINTS
127 pm->op_pmdynflags |= PMdf_TAINTED;
129 pm->op_pmdynflags &= ~PMdf_TAINTED;
133 if (!PM_GETRE(pm)->prelen && PL_curpm)
135 else if (strEQ("\\s+", PM_GETRE(pm)->precomp))
136 pm->op_pmflags |= PMf_WHITE;
138 pm->op_pmflags &= ~PMf_WHITE;
140 /* XXX runtime compiled output needs to move to the pad */
141 if (pm->op_pmflags & PMf_KEEP) {
142 pm->op_private &= ~OPpRUNTIME; /* no point compiling again */
143 #if !defined(USE_ITHREADS)
144 /* XXX can't change the optree at runtime either */
145 cLOGOP->op_first->op_next = PL_op->op_next;
154 register PMOP *pm = (PMOP*) cLOGOP->op_other;
155 register PERL_CONTEXT *cx = &cxstack[cxstack_ix];
156 register SV *dstr = cx->sb_dstr;
157 register char *s = cx->sb_s;
158 register char *m = cx->sb_m;
159 char *orig = cx->sb_orig;
160 register REGEXP *rx = cx->sb_rx;
164 REGEXP *old = PM_GETRE(pm);
172 rxres_restore(&cx->sb_rxres, rx);
173 RX_MATCH_UTF8_set(rx, SvUTF8(cx->sb_targ));
175 if (cx->sb_iters++) {
176 I32 saviters = cx->sb_iters;
177 if (cx->sb_iters > cx->sb_maxiters)
178 DIE(aTHX_ "Substitution loop");
180 if (!(cx->sb_rxtainted & 2) && SvTAINTED(TOPs))
181 cx->sb_rxtainted |= 2;
182 sv_catsv(dstr, POPs);
185 if (cx->sb_once || !CALLREGEXEC(aTHX_ rx, s, cx->sb_strend, orig,
186 s == m, cx->sb_targ, NULL,
187 ((cx->sb_rflags & REXEC_COPY_STR)
188 ? (REXEC_IGNOREPOS|REXEC_NOT_FIRST)
189 : (REXEC_COPY_STR|REXEC_IGNOREPOS|REXEC_NOT_FIRST))))
191 SV *targ = cx->sb_targ;
193 if (DO_UTF8(dstr) && !SvUTF8(targ))
194 sv_catpvn_utf8_upgrade(dstr, s, cx->sb_strend - s, nsv);
196 sv_catpvn(dstr, s, cx->sb_strend - s);
197 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
199 #ifdef PERL_COPY_ON_WRITE
201 sv_force_normal_flags(targ, SV_COW_DROP_PV);
205 (void)SvOOK_off(targ);
207 Safefree(SvPVX(targ));
209 SvPVX(targ) = SvPVX(dstr);
210 SvCUR_set(targ, SvCUR(dstr));
211 SvLEN_set(targ, SvLEN(dstr));
217 TAINT_IF(cx->sb_rxtainted & 1);
218 PUSHs(sv_2mortal(newSViv(saviters - 1)));
220 (void)SvPOK_only_UTF8(targ);
221 TAINT_IF(cx->sb_rxtainted);
225 LEAVE_SCOPE(cx->sb_oldsave);
228 RETURNOP(pm->op_next);
230 cx->sb_iters = saviters;
232 if (RX_MATCH_COPIED(rx) && rx->subbeg != orig) {
235 cx->sb_orig = orig = rx->subbeg;
237 cx->sb_strend = s + (cx->sb_strend - m);
239 cx->sb_m = m = rx->startp[0] + orig;
241 if (DO_UTF8(dstr) && !SvUTF8(cx->sb_targ))
242 sv_catpvn_utf8_upgrade(dstr, s, m - s, nsv);
244 sv_catpvn(dstr, s, m-s);
246 cx->sb_s = rx->endp[0] + orig;
247 { /* Update the pos() information. */
248 SV *sv = cx->sb_targ;
251 if (SvTYPE(sv) < SVt_PVMG)
252 (void)SvUPGRADE(sv, SVt_PVMG);
253 if (!(mg = mg_find(sv, PERL_MAGIC_regex_global))) {
254 sv_magic(sv, Nullsv, PERL_MAGIC_regex_global, Nullch, 0);
255 mg = mg_find(sv, PERL_MAGIC_regex_global);
263 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
264 rxres_save(&cx->sb_rxres, rx);
265 RETURNOP(pm->op_pmreplstart);
269 Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx)
274 if (!p || p[1] < rx->nparens) {
275 #ifdef PERL_COPY_ON_WRITE
276 i = 7 + rx->nparens * 2;
278 i = 6 + rx->nparens * 2;
287 *p++ = PTR2UV(RX_MATCH_COPIED(rx) ? rx->subbeg : Nullch);
288 RX_MATCH_COPIED_off(rx);
290 #ifdef PERL_COPY_ON_WRITE
291 *p++ = PTR2UV(rx->saved_copy);
292 rx->saved_copy = Nullsv;
297 *p++ = PTR2UV(rx->subbeg);
298 *p++ = (UV)rx->sublen;
299 for (i = 0; i <= rx->nparens; ++i) {
300 *p++ = (UV)rx->startp[i];
301 *p++ = (UV)rx->endp[i];
306 Perl_rxres_restore(pTHX_ void **rsp, REGEXP *rx)
311 RX_MATCH_COPY_FREE(rx);
312 RX_MATCH_COPIED_set(rx, *p);
315 #ifdef PERL_COPY_ON_WRITE
317 SvREFCNT_dec (rx->saved_copy);
318 rx->saved_copy = INT2PTR(SV*,*p);
324 rx->subbeg = INT2PTR(char*,*p++);
325 rx->sublen = (I32)(*p++);
326 for (i = 0; i <= rx->nparens; ++i) {
327 rx->startp[i] = (I32)(*p++);
328 rx->endp[i] = (I32)(*p++);
333 Perl_rxres_free(pTHX_ void **rsp)
338 Safefree(INT2PTR(char*,*p));
339 #ifdef PERL_COPY_ON_WRITE
341 SvREFCNT_dec (INT2PTR(SV*,p[1]));
351 dSP; dMARK; dORIGMARK;
352 register SV *tmpForm = *++MARK;
359 register SV *sv = Nullsv;
364 bool chopspace = (strchr(PL_chopset, ' ') != Nullch);
365 char *chophere = Nullch;
366 char *linemark = Nullch;
368 bool gotsome = FALSE;
370 STRLEN fudge = SvCUR(tmpForm) * (IN_BYTES ? 1 : 3) + 1;
371 bool item_is_utf8 = FALSE;
372 bool targ_is_utf8 = FALSE;
375 if (!SvMAGICAL(tmpForm) || !SvCOMPILED(tmpForm)) {
376 if (SvREADONLY(tmpForm)) {
377 SvREADONLY_off(tmpForm);
378 doparseform(tmpForm);
379 SvREADONLY_on(tmpForm);
382 doparseform(tmpForm);
384 SvPV_force(PL_formtarget, len);
385 if (DO_UTF8(PL_formtarget))
387 t = SvGROW(PL_formtarget, len + fudge + 1); /* XXX SvCUR bad */
389 f = SvPV(tmpForm, len);
390 /* need to jump to the next word */
391 s = f + len + WORD_ALIGN - SvCUR(tmpForm) % WORD_ALIGN;
400 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
401 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
402 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
403 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
404 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
406 case FF_CHECKNL: name = "CHECKNL"; break;
407 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
408 case FF_SPACE: name = "SPACE"; break;
409 case FF_HALFSPACE: name = "HALFSPACE"; break;
410 case FF_ITEM: name = "ITEM"; break;
411 case FF_CHOP: name = "CHOP"; break;
412 case FF_LINEGLOB: name = "LINEGLOB"; break;
413 case FF_NEWLINE: name = "NEWLINE"; break;
414 case FF_MORE: name = "MORE"; break;
415 case FF_LINEMARK: name = "LINEMARK"; break;
416 case FF_END: name = "END"; break;
417 case FF_0DECIMAL: name = "0DECIMAL"; break;
420 PerlIO_printf(Perl_debug_log, "%-16s%ld\n", name, (long) arg);
422 PerlIO_printf(Perl_debug_log, "%-16s\n", name);
433 if (targ_is_utf8 && !SvUTF8(tmpForm)) {
434 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
436 sv_catpvn_utf8_upgrade(PL_formtarget, f, arg, nsv);
437 t = SvEND(PL_formtarget);
440 if (!targ_is_utf8 && DO_UTF8(tmpForm)) {
441 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
443 sv_utf8_upgrade(PL_formtarget);
444 SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
445 t = SvEND(PL_formtarget);
465 if (ckWARN(WARN_SYNTAX))
466 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Not enough format arguments");
471 item = s = SvPV(sv, len);
474 itemsize = sv_len_utf8(sv);
475 if (itemsize != (I32)len) {
477 if (itemsize > fieldsize) {
478 itemsize = fieldsize;
479 itembytes = itemsize;
480 sv_pos_u2b(sv, &itembytes, 0);
484 send = chophere = s + itembytes;
494 sv_pos_b2u(sv, &itemsize);
498 item_is_utf8 = FALSE;
499 if (itemsize > fieldsize)
500 itemsize = fieldsize;
501 send = chophere = s + itemsize;
513 item = s = SvPV(sv, len);
516 itemsize = sv_len_utf8(sv);
517 if (itemsize != (I32)len) {
519 if (itemsize <= fieldsize) {
520 send = chophere = s + itemsize;
531 itemsize = fieldsize;
532 itembytes = itemsize;
533 sv_pos_u2b(sv, &itembytes, 0);
534 send = chophere = s + itembytes;
535 while (s < send || (s == send && isSPACE(*s))) {
545 if (strchr(PL_chopset, *s))
550 itemsize = chophere - item;
551 sv_pos_b2u(sv, &itemsize);
557 item_is_utf8 = FALSE;
558 if (itemsize <= fieldsize) {
559 send = chophere = s + itemsize;
570 itemsize = fieldsize;
571 send = chophere = s + itemsize;
572 while (s < send || (s == send && isSPACE(*s))) {
582 if (strchr(PL_chopset, *s))
587 itemsize = chophere - item;
592 arg = fieldsize - itemsize;
601 arg = fieldsize - itemsize;
615 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
617 sv_utf8_upgrade(PL_formtarget);
618 SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
619 t = SvEND(PL_formtarget);
623 if (UTF8_IS_CONTINUED(*s)) {
624 STRLEN skip = UTF8SKIP(s);
641 if ( !((*t++ = *s++) & ~31) )
647 if (targ_is_utf8 && !item_is_utf8) {
648 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
650 sv_catpvn_utf8_upgrade(PL_formtarget, s, arg, nsv);
651 for (; t < SvEND(PL_formtarget); t++) {
653 int ch = *t++ = *s++;
664 int ch = *t++ = *s++;
667 if ( !((*t++ = *s++) & ~31) )
676 while (*s && isSPACE(*s))
684 item = s = SvPV(sv, len);
686 if ((item_is_utf8 = DO_UTF8(sv)))
687 itemsize = sv_len_utf8(sv);
689 bool chopped = FALSE;
702 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
704 SvUTF8_on(PL_formtarget);
705 sv_catsv(PL_formtarget, sv);
707 SvCUR_set(PL_formtarget, SvCUR(PL_formtarget) - 1);
708 SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
709 t = SvPVX(PL_formtarget) + SvCUR(PL_formtarget);
716 /* If the field is marked with ^ and the value is undefined,
719 if ((arg & 512) && !SvOK(sv)) {
727 /* Formats aren't yet marked for locales, so assume "yes". */
729 STORE_NUMERIC_STANDARD_SET_LOCAL();
730 #if defined(USE_LONG_DOUBLE)
732 sprintf(t, "%#*.*" PERL_PRIfldbl,
733 (int) fieldsize, (int) arg & 255, value);
735 sprintf(t, "%*.0" PERL_PRIfldbl, (int) fieldsize, value);
740 (int) fieldsize, (int) arg & 255, value);
743 (int) fieldsize, value);
746 RESTORE_NUMERIC_STANDARD();
752 /* If the field is marked with ^ and the value is undefined,
755 if ((arg & 512) && !SvOK(sv)) {
763 /* Formats aren't yet marked for locales, so assume "yes". */
765 STORE_NUMERIC_STANDARD_SET_LOCAL();
766 #if defined(USE_LONG_DOUBLE)
768 sprintf(t, "%#0*.*" PERL_PRIfldbl,
769 (int) fieldsize, (int) arg & 255, value);
770 /* is this legal? I don't have long doubles */
772 sprintf(t, "%0*.0" PERL_PRIfldbl, (int) fieldsize, value);
776 sprintf(t, "%#0*.*f",
777 (int) fieldsize, (int) arg & 255, value);
780 (int) fieldsize, value);
783 RESTORE_NUMERIC_STANDARD();
790 while (t-- > linemark && *t == ' ') ;
798 if (arg) { /* repeat until fields exhausted? */
800 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
801 lines += FmLINES(PL_formtarget);
804 if (strnEQ(linemark, linemark - arg, arg))
805 DIE(aTHX_ "Runaway format");
808 SvUTF8_on(PL_formtarget);
809 FmLINES(PL_formtarget) = lines;
811 RETURNOP(cLISTOP->op_first);
824 while (*s && isSPACE(*s) && s < send)
828 arg = fieldsize - itemsize;
835 if (strnEQ(s," ",3)) {
836 while (s > SvPVX(PL_formtarget) && isSPACE(s[-1]))
847 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
849 SvUTF8_on(PL_formtarget);
850 FmLINES(PL_formtarget) += lines;
862 if (PL_stack_base + *PL_markstack_ptr == SP) {
864 if (GIMME_V == G_SCALAR)
865 XPUSHs(sv_2mortal(newSViv(0)));
866 RETURNOP(PL_op->op_next->op_next);
868 PL_stack_sp = PL_stack_base + *PL_markstack_ptr + 1;
869 pp_pushmark(); /* push dst */
870 pp_pushmark(); /* push src */
871 ENTER; /* enter outer scope */
874 /* SAVE_DEFSV does *not* suffice here for USE_5005THREADS */
876 ENTER; /* enter inner scope */
879 src = PL_stack_base[*PL_markstack_ptr];
884 if (PL_op->op_type == OP_MAPSTART)
885 pp_pushmark(); /* push top */
886 return ((LOGOP*)PL_op->op_next)->op_other;
891 DIE(aTHX_ "panic: mapstart"); /* uses grepstart */
898 I32 items = (SP - PL_stack_base) - *PL_markstack_ptr; /* how many new items */
904 /* first, move source pointer to the next item in the source list */
905 ++PL_markstack_ptr[-1];
907 /* if there are new items, push them into the destination list */
908 if (items && gimme != G_VOID) {
909 /* might need to make room back there first */
910 if (items > PL_markstack_ptr[-1] - PL_markstack_ptr[-2]) {
911 /* XXX this implementation is very pessimal because the stack
912 * is repeatedly extended for every set of items. Is possible
913 * to do this without any stack extension or copying at all
914 * by maintaining a separate list over which the map iterates
915 * (like foreach does). --gsar */
917 /* everything in the stack after the destination list moves
918 * towards the end the stack by the amount of room needed */
919 shift = items - (PL_markstack_ptr[-1] - PL_markstack_ptr[-2]);
921 /* items to shift up (accounting for the moved source pointer) */
922 count = (SP - PL_stack_base) - (PL_markstack_ptr[-1] - 1);
924 /* This optimization is by Ben Tilly and it does
925 * things differently from what Sarathy (gsar)
926 * is describing. The downside of this optimization is
927 * that leaves "holes" (uninitialized and hopefully unused areas)
928 * to the Perl stack, but on the other hand this
929 * shouldn't be a problem. If Sarathy's idea gets
930 * implemented, this optimization should become
931 * irrelevant. --jhi */
933 shift = count; /* Avoid shifting too often --Ben Tilly */
938 PL_markstack_ptr[-1] += shift;
939 *PL_markstack_ptr += shift;
943 /* copy the new items down to the destination list */
944 dst = PL_stack_base + (PL_markstack_ptr[-2] += items) - 1;
946 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
948 LEAVE; /* exit inner scope */
951 if (PL_markstack_ptr[-1] > *PL_markstack_ptr) {
953 (void)POPMARK; /* pop top */
954 LEAVE; /* exit outer scope */
955 (void)POPMARK; /* pop src */
956 items = --*PL_markstack_ptr - PL_markstack_ptr[-1];
957 (void)POPMARK; /* pop dst */
958 SP = PL_stack_base + POPMARK; /* pop original mark */
959 if (gimme == G_SCALAR) {
963 else if (gimme == G_ARRAY)
970 ENTER; /* enter inner scope */
973 /* set $_ to the new source item */
974 src = PL_stack_base[PL_markstack_ptr[-1]];
978 RETURNOP(cLOGOP->op_other);
986 if (GIMME == G_ARRAY)
988 if (SvTRUEx(PAD_SV(PL_op->op_targ)))
989 return cLOGOP->op_other;
998 if (GIMME == G_ARRAY) {
999 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
1003 SV *targ = PAD_SV(PL_op->op_targ);
1006 if (PL_op->op_private & OPpFLIP_LINENUM) {
1007 if (GvIO(PL_last_in_gv)) {
1008 flip = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
1011 GV *gv = gv_fetchpv(".", TRUE, SVt_PV);
1012 if (gv && GvSV(gv)) flip = SvIV(sv) == SvIV(GvSV(gv));
1018 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
1019 if (PL_op->op_flags & OPf_SPECIAL) {
1027 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
1040 if (GIMME == G_ARRAY) {
1046 if (SvGMAGICAL(left))
1048 if (SvGMAGICAL(right))
1051 /* This code tries to decide if "$left .. $right" should use the
1052 magical string increment, or if the range is numeric (we make
1053 an exception for .."0" [#18165]). AMS 20021031. */
1055 if (SvNIOKp(left) || !SvPOKp(left) ||
1056 SvNIOKp(right) || !SvPOKp(right) ||
1057 (looks_like_number(left) && *SvPVX(left) != '0' &&
1058 looks_like_number(right)))
1060 if (SvNV(left) < IV_MIN || SvNV(right) > IV_MAX)
1061 DIE(aTHX_ "Range iterator outside integer range");
1072 sv = sv_2mortal(newSViv(i++));
1077 SV *final = sv_mortalcopy(right);
1079 char *tmps = SvPV(final, len);
1081 sv = sv_mortalcopy(left);
1083 while (!SvNIOKp(sv) && SvCUR(sv) <= len) {
1085 if (strEQ(SvPVX(sv),tmps))
1087 sv = sv_2mortal(newSVsv(sv));
1094 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
1098 if (PL_op->op_private & OPpFLIP_LINENUM) {
1099 if (GvIO(PL_last_in_gv)) {
1100 flop = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
1103 GV *gv = gv_fetchpv(".", TRUE, SVt_PV);
1104 if (gv && GvSV(gv)) flop = SvIV(sv) == SvIV(GvSV(gv));
1112 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
1113 sv_catpv(targ, "E0");
1123 static char *context_name[] = {
1134 S_dopoptolabel(pTHX_ char *label)
1137 register PERL_CONTEXT *cx;
1139 for (i = cxstack_ix; i >= 0; i--) {
1141 switch (CxTYPE(cx)) {
1147 if (ckWARN(WARN_EXITING))
1148 Perl_warner(aTHX_ packWARN(WARN_EXITING), "Exiting %s via %s",
1149 context_name[CxTYPE(cx)], OP_NAME(PL_op));
1150 if (CxTYPE(cx) == CXt_NULL)
1154 if (!cx->blk_loop.label ||
1155 strNE(label, cx->blk_loop.label) ) {
1156 DEBUG_l(Perl_deb(aTHX_ "(Skipping label #%ld %s)\n",
1157 (long)i, cx->blk_loop.label));
1160 DEBUG_l( Perl_deb(aTHX_ "(Found label #%ld %s)\n", (long)i, label));
1168 Perl_dowantarray(pTHX)
1170 I32 gimme = block_gimme();
1171 return (gimme == G_VOID) ? G_SCALAR : gimme;
1175 Perl_block_gimme(pTHX)
1179 cxix = dopoptosub(cxstack_ix);
1183 switch (cxstack[cxix].blk_gimme) {
1191 Perl_croak(aTHX_ "panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
1198 Perl_is_lvalue_sub(pTHX)
1202 cxix = dopoptosub(cxstack_ix);
1203 assert(cxix >= 0); /* We should only be called from inside subs */
1205 if (cxstack[cxix].blk_sub.lval && CvLVALUE(cxstack[cxix].blk_sub.cv))
1206 return cxstack[cxix].blk_sub.lval;
1212 S_dopoptosub(pTHX_ I32 startingblock)
1214 return dopoptosub_at(cxstack, startingblock);
1218 S_dopoptosub_at(pTHX_ PERL_CONTEXT *cxstk, I32 startingblock)
1221 register PERL_CONTEXT *cx;
1222 for (i = startingblock; i >= 0; i--) {
1224 switch (CxTYPE(cx)) {
1230 DEBUG_l( Perl_deb(aTHX_ "(Found sub #%ld)\n", (long)i));
1238 S_dopoptoeval(pTHX_ I32 startingblock)
1241 register PERL_CONTEXT *cx;
1242 for (i = startingblock; i >= 0; i--) {
1244 switch (CxTYPE(cx)) {
1248 DEBUG_l( Perl_deb(aTHX_ "(Found eval #%ld)\n", (long)i));
1256 S_dopoptoloop(pTHX_ I32 startingblock)
1259 register PERL_CONTEXT *cx;
1260 for (i = startingblock; i >= 0; i--) {
1262 switch (CxTYPE(cx)) {
1268 if (ckWARN(WARN_EXITING))
1269 Perl_warner(aTHX_ packWARN(WARN_EXITING), "Exiting %s via %s",
1270 context_name[CxTYPE(cx)], OP_NAME(PL_op));
1271 if ((CxTYPE(cx)) == CXt_NULL)
1275 DEBUG_l( Perl_deb(aTHX_ "(Found loop #%ld)\n", (long)i));
1283 Perl_dounwind(pTHX_ I32 cxix)
1285 register PERL_CONTEXT *cx;
1288 while (cxstack_ix > cxix) {
1290 cx = &cxstack[cxstack_ix];
1291 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n",
1292 (long) cxstack_ix, PL_block_type[CxTYPE(cx)]));
1293 /* Note: we don't need to restore the base context info till the end. */
1294 switch (CxTYPE(cx)) {
1297 continue; /* not break */
1319 Perl_qerror(pTHX_ SV *err)
1322 sv_catsv(ERRSV, err);
1324 sv_catsv(PL_errors, err);
1326 Perl_warn(aTHX_ "%"SVf, err);
1331 Perl_die_where(pTHX_ char *message, STRLEN msglen)
1337 register PERL_CONTEXT *cx;
1342 if (PL_in_eval & EVAL_KEEPERR) {
1343 static char prefix[] = "\t(in cleanup) ";
1348 else if (SvCUR(err) >= sizeof(prefix)+msglen-1) {
1351 if (*e != *message || strNE(e,message))
1355 SvGROW(err, SvCUR(err)+sizeof(prefix)+msglen);
1356 sv_catpvn(err, prefix, sizeof(prefix)-1);
1357 sv_catpvn(err, message, msglen);
1358 if (ckWARN(WARN_MISC)) {
1359 STRLEN start = SvCUR(err)-msglen-sizeof(prefix)+1;
1360 Perl_warner(aTHX_ packWARN(WARN_MISC), SvPVX(err)+start);
1365 sv_setpvn(ERRSV, message, msglen);
1369 while ((cxix = dopoptoeval(cxstack_ix)) < 0
1370 && PL_curstackinfo->si_prev)
1379 if (cxix < cxstack_ix)
1382 POPBLOCK(cx,PL_curpm);
1383 if (CxTYPE(cx) != CXt_EVAL) {
1385 message = SvPVx(ERRSV, msglen);
1386 PerlIO_write(Perl_error_log, "panic: die ", 11);
1387 PerlIO_write(Perl_error_log, message, msglen);
1392 if (gimme == G_SCALAR)
1393 *++newsp = &PL_sv_undef;
1394 PL_stack_sp = newsp;
1398 /* LEAVE could clobber PL_curcop (see save_re_context())
1399 * XXX it might be better to find a way to avoid messing with
1400 * PL_curcop in save_re_context() instead, but this is a more
1401 * minimal fix --GSAR */
1402 PL_curcop = cx->blk_oldcop;
1404 if (optype == OP_REQUIRE) {
1405 char* msg = SvPVx(ERRSV, n_a);
1406 SV *nsv = cx->blk_eval.old_namesv;
1407 (void)hv_store(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv),
1409 DIE(aTHX_ "%sCompilation failed in require",
1410 *msg ? msg : "Unknown error\n");
1412 return pop_return();
1416 message = SvPVx(ERRSV, msglen);
1418 write_to_stderr(message, msglen);
1427 if (SvTRUE(left) != SvTRUE(right))
1439 RETURNOP(cLOGOP->op_other);
1448 RETURNOP(cLOGOP->op_other);
1457 if (!sv || !SvANY(sv)) {
1458 RETURNOP(cLOGOP->op_other);
1461 switch (SvTYPE(sv)) {
1463 if (AvMAX(sv) >= 0 || SvGMAGICAL(sv) || (SvRMAGICAL(sv) && mg_find(sv, PERL_MAGIC_tied)))
1467 if (HvARRAY(sv) || SvGMAGICAL(sv) || (SvRMAGICAL(sv) && mg_find(sv, PERL_MAGIC_tied)))
1471 if (CvROOT(sv) || CvXSUB(sv))
1481 RETURNOP(cLOGOP->op_other);
1487 register I32 cxix = dopoptosub(cxstack_ix);
1488 register PERL_CONTEXT *cx;
1489 register PERL_CONTEXT *ccstack = cxstack;
1490 PERL_SI *top_si = PL_curstackinfo;
1501 /* we may be in a higher stacklevel, so dig down deeper */
1502 while (cxix < 0 && top_si->si_type != PERLSI_MAIN) {
1503 top_si = top_si->si_prev;
1504 ccstack = top_si->si_cxstack;
1505 cxix = dopoptosub_at(ccstack, top_si->si_cxix);
1508 if (GIMME != G_ARRAY) {
1514 if (PL_DBsub && cxix >= 0 &&
1515 ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub))
1519 cxix = dopoptosub_at(ccstack, cxix - 1);
1522 cx = &ccstack[cxix];
1523 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1524 dbcxix = dopoptosub_at(ccstack, cxix - 1);
1525 /* We expect that ccstack[dbcxix] is CXt_SUB, anyway, the
1526 field below is defined for any cx. */
1527 if (PL_DBsub && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub))
1528 cx = &ccstack[dbcxix];
1531 stashname = CopSTASHPV(cx->blk_oldcop);
1532 if (GIMME != G_ARRAY) {
1535 PUSHs(&PL_sv_undef);
1538 sv_setpv(TARG, stashname);
1547 PUSHs(&PL_sv_undef);
1549 PUSHs(sv_2mortal(newSVpv(stashname, 0)));
1550 PUSHs(sv_2mortal(newSVpv(OutCopFILE(cx->blk_oldcop), 0)));
1551 PUSHs(sv_2mortal(newSViv((I32)CopLINE(cx->blk_oldcop))));
1554 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1555 GV *cvgv = CvGV(ccstack[cxix].blk_sub.cv);
1556 /* So is ccstack[dbcxix]. */
1559 gv_efullname3(sv, cvgv, Nullch);
1560 PUSHs(sv_2mortal(sv));
1561 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1564 PUSHs(sv_2mortal(newSVpvn("(unknown)",9)));
1565 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1569 PUSHs(sv_2mortal(newSVpvn("(eval)",6)));
1570 PUSHs(sv_2mortal(newSViv(0)));
1572 gimme = (I32)cx->blk_gimme;
1573 if (gimme == G_VOID)
1574 PUSHs(&PL_sv_undef);
1576 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1577 if (CxTYPE(cx) == CXt_EVAL) {
1579 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1580 PUSHs(cx->blk_eval.cur_text);
1584 else if (cx->blk_eval.old_namesv) {
1585 PUSHs(sv_2mortal(newSVsv(cx->blk_eval.old_namesv)));
1588 /* eval BLOCK (try blocks have old_namesv == 0) */
1590 PUSHs(&PL_sv_undef);
1591 PUSHs(&PL_sv_undef);
1595 PUSHs(&PL_sv_undef);
1596 PUSHs(&PL_sv_undef);
1598 if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.hasargs
1599 && CopSTASH_eq(PL_curcop, PL_debstash))
1601 AV *ary = cx->blk_sub.argarray;
1602 int off = AvARRAY(ary) - AvALLOC(ary);
1606 PL_dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1609 AvREAL_off(PL_dbargs); /* XXX should be REIFY (see av.h) */
1612 if (AvMAX(PL_dbargs) < AvFILLp(ary) + off)
1613 av_extend(PL_dbargs, AvFILLp(ary) + off);
1614 Copy(AvALLOC(ary), AvARRAY(PL_dbargs), AvFILLp(ary) + 1 + off, SV*);
1615 AvFILLp(PL_dbargs) = AvFILLp(ary) + off;
1617 /* XXX only hints propagated via op_private are currently
1618 * visible (others are not easily accessible, since they
1619 * use the global PL_hints) */
1620 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->op_private &
1621 HINT_PRIVATE_MASK)));
1624 SV * old_warnings = cx->blk_oldcop->cop_warnings ;
1626 if (old_warnings == pWARN_NONE ||
1627 (old_warnings == pWARN_STD && (PL_dowarn & G_WARN_ON) == 0))
1628 mask = newSVpvn(WARN_NONEstring, WARNsize) ;
1629 else if (old_warnings == pWARN_ALL ||
1630 (old_warnings == pWARN_STD && PL_dowarn & G_WARN_ON)) {
1631 /* Get the bit mask for $warnings::Bits{all}, because
1632 * it could have been extended by warnings::register */
1634 HV *bits = get_hv("warnings::Bits", FALSE);
1635 if (bits && (bits_all=hv_fetch(bits, "all", 3, FALSE))) {
1636 mask = newSVsv(*bits_all);
1639 mask = newSVpvn(WARN_ALLstring, WARNsize) ;
1643 mask = newSVsv(old_warnings);
1644 PUSHs(sv_2mortal(mask));
1659 sv_reset(tmps, CopSTASH(PL_curcop));
1669 /* like pp_nextstate, but used instead when the debugger is active */
1673 PL_curcop = (COP*)PL_op;
1674 TAINT_NOT; /* Each statement is presumed innocent */
1675 PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
1678 if (PL_op->op_flags & OPf_SPECIAL /* breakpoint */
1679 || SvIV(PL_DBsingle) || SvIV(PL_DBsignal) || SvIV(PL_DBtrace))
1683 register PERL_CONTEXT *cx;
1684 I32 gimme = G_ARRAY;
1691 DIE(aTHX_ "No DB::DB routine defined");
1693 if (CvDEPTH(cv) >= 1 && !(PL_debug & DEBUG_DB_RECURSE_FLAG))
1694 /* don't do recursive DB::DB call */
1706 push_return(PL_op->op_next);
1707 PUSHBLOCK(cx, CXt_SUB, SP);
1710 (void)SvREFCNT_inc(cv);
1711 PAD_SET_CUR(CvPADLIST(cv),1);
1712 RETURNOP(CvSTART(cv));
1726 register PERL_CONTEXT *cx;
1727 I32 gimme = GIMME_V;
1729 U32 cxtype = CXt_LOOP;
1737 if (PL_op->op_targ) {
1738 if (PL_op->op_private & OPpLVAL_INTRO) { /* for my $x (...) */
1739 SvPADSTALE_off(PAD_SVl(PL_op->op_targ));
1740 SAVESETSVFLAGS(PAD_SVl(PL_op->op_targ),
1741 SVs_PADSTALE, SVs_PADSTALE);
1743 #ifndef USE_ITHREADS
1744 svp = &PAD_SVl(PL_op->op_targ); /* "my" variable */
1747 SAVEPADSV(PL_op->op_targ);
1748 iterdata = INT2PTR(void*, PL_op->op_targ);
1749 cxtype |= CXp_PADVAR;
1754 svp = &GvSV(gv); /* symbol table variable */
1755 SAVEGENERICSV(*svp);
1758 iterdata = (void*)gv;
1764 PUSHBLOCK(cx, cxtype, SP);
1766 PUSHLOOP(cx, iterdata, MARK);
1768 PUSHLOOP(cx, svp, MARK);
1770 if (PL_op->op_flags & OPf_STACKED) {
1771 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1772 if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) {
1774 /* See comment in pp_flop() */
1775 if (SvNIOKp(sv) || !SvPOKp(sv) ||
1776 SvNIOKp(cx->blk_loop.iterary) || !SvPOKp(cx->blk_loop.iterary) ||
1777 (looks_like_number(sv) && *SvPVX(sv) != '0' &&
1778 looks_like_number((SV*)cx->blk_loop.iterary)))
1780 if (SvNV(sv) < IV_MIN ||
1781 SvNV((SV*)cx->blk_loop.iterary) >= IV_MAX)
1782 DIE(aTHX_ "Range iterator outside integer range");
1783 cx->blk_loop.iterix = SvIV(sv);
1784 cx->blk_loop.itermax = SvIV((SV*)cx->blk_loop.iterary);
1787 cx->blk_loop.iterlval = newSVsv(sv);
1791 cx->blk_loop.iterary = PL_curstack;
1792 AvFILLp(PL_curstack) = SP - PL_stack_base;
1793 cx->blk_loop.iterix = MARK - PL_stack_base;
1802 register PERL_CONTEXT *cx;
1803 I32 gimme = GIMME_V;
1809 PUSHBLOCK(cx, CXt_LOOP, SP);
1810 PUSHLOOP(cx, 0, SP);
1818 register PERL_CONTEXT *cx;
1826 newsp = PL_stack_base + cx->blk_loop.resetsp;
1829 if (gimme == G_VOID)
1831 else if (gimme == G_SCALAR) {
1833 *++newsp = sv_mortalcopy(*SP);
1835 *++newsp = &PL_sv_undef;
1839 *++newsp = sv_mortalcopy(*++mark);
1840 TAINT_NOT; /* Each item is independent */
1846 POPLOOP(cx); /* Stack values are safe: release loop vars ... */
1847 PL_curpm = newpm; /* ... and pop $1 et al */
1859 register PERL_CONTEXT *cx;
1860 bool popsub2 = FALSE;
1861 bool clear_errsv = FALSE;
1868 if (PL_curstackinfo->si_type == PERLSI_SORT) {
1869 if (cxstack_ix == PL_sortcxix
1870 || dopoptosub(cxstack_ix) <= PL_sortcxix)
1872 if (cxstack_ix > PL_sortcxix)
1873 dounwind(PL_sortcxix);
1874 AvARRAY(PL_curstack)[1] = *SP;
1875 PL_stack_sp = PL_stack_base + 1;
1880 cxix = dopoptosub(cxstack_ix);
1882 DIE(aTHX_ "Can't return outside a subroutine");
1883 if (cxix < cxstack_ix)
1887 switch (CxTYPE(cx)) {
1890 cxstack_ix++; /* preserve cx entry on stack for use by POPSUB */
1893 if (!(PL_in_eval & EVAL_KEEPERR))
1899 if (optype == OP_REQUIRE &&
1900 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1902 /* Unassume the success we assumed earlier. */
1903 SV *nsv = cx->blk_eval.old_namesv;
1904 (void)hv_delete(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), G_DISCARD);
1905 DIE(aTHX_ "%"SVf" did not return a true value", nsv);
1912 DIE(aTHX_ "panic: return");
1916 if (gimme == G_SCALAR) {
1919 if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
1921 *++newsp = SvREFCNT_inc(*SP);
1926 sv = SvREFCNT_inc(*SP); /* FREETMPS could clobber it */
1928 *++newsp = sv_mortalcopy(sv);
1933 *++newsp = (SvTEMP(*SP)) ? *SP : sv_mortalcopy(*SP);
1936 *++newsp = sv_mortalcopy(*SP);
1939 *++newsp = &PL_sv_undef;
1941 else if (gimme == G_ARRAY) {
1942 while (++MARK <= SP) {
1943 *++newsp = (popsub2 && SvTEMP(*MARK))
1944 ? *MARK : sv_mortalcopy(*MARK);
1945 TAINT_NOT; /* Each item is independent */
1948 PL_stack_sp = newsp;
1951 /* Stack values are safe: */
1954 POPSUB(cx,sv); /* release CV and @_ ... */
1958 PL_curpm = newpm; /* ... and pop $1 et al */
1963 return pop_return();
1970 register PERL_CONTEXT *cx;
1980 if (PL_op->op_flags & OPf_SPECIAL) {
1981 cxix = dopoptoloop(cxstack_ix);
1983 DIE(aTHX_ "Can't \"last\" outside a loop block");
1986 cxix = dopoptolabel(cPVOP->op_pv);
1988 DIE(aTHX_ "Label not found for \"last %s\"", cPVOP->op_pv);
1990 if (cxix < cxstack_ix)
1994 cxstack_ix++; /* temporarily protect top context */
1996 switch (CxTYPE(cx)) {
1999 newsp = PL_stack_base + cx->blk_loop.resetsp;
2000 nextop = cx->blk_loop.last_op->op_next;
2004 nextop = pop_return();
2008 nextop = pop_return();
2012 nextop = pop_return();
2015 DIE(aTHX_ "panic: last");
2019 if (gimme == G_SCALAR) {
2021 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
2022 ? *SP : sv_mortalcopy(*SP);
2024 *++newsp = &PL_sv_undef;
2026 else if (gimme == G_ARRAY) {
2027 while (++MARK <= SP) {
2028 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
2029 ? *MARK : sv_mortalcopy(*MARK);
2030 TAINT_NOT; /* Each item is independent */
2038 /* Stack values are safe: */
2041 POPLOOP(cx); /* release loop vars ... */
2045 POPSUB(cx,sv); /* release CV and @_ ... */
2048 PL_curpm = newpm; /* ... and pop $1 et al */
2057 register PERL_CONTEXT *cx;
2060 if (PL_op->op_flags & OPf_SPECIAL) {
2061 cxix = dopoptoloop(cxstack_ix);
2063 DIE(aTHX_ "Can't \"next\" outside a loop block");
2066 cxix = dopoptolabel(cPVOP->op_pv);
2068 DIE(aTHX_ "Label not found for \"next %s\"", cPVOP->op_pv);
2070 if (cxix < cxstack_ix)
2073 /* clear off anything above the scope we're re-entering, but
2074 * save the rest until after a possible continue block */
2075 inner = PL_scopestack_ix;
2077 if (PL_scopestack_ix < inner)
2078 leave_scope(PL_scopestack[PL_scopestack_ix]);
2079 return cx->blk_loop.next_op;
2085 register PERL_CONTEXT *cx;
2088 if (PL_op->op_flags & OPf_SPECIAL) {
2089 cxix = dopoptoloop(cxstack_ix);
2091 DIE(aTHX_ "Can't \"redo\" outside a loop block");
2094 cxix = dopoptolabel(cPVOP->op_pv);
2096 DIE(aTHX_ "Label not found for \"redo %s\"", cPVOP->op_pv);
2098 if (cxix < cxstack_ix)
2102 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2103 LEAVE_SCOPE(oldsave);
2104 return cx->blk_loop.redo_op;
2108 S_dofindlabel(pTHX_ OP *o, char *label, OP **opstack, OP **oplimit)
2112 static char too_deep[] = "Target of goto is too deeply nested";
2115 Perl_croak(aTHX_ too_deep);
2116 if (o->op_type == OP_LEAVE ||
2117 o->op_type == OP_SCOPE ||
2118 o->op_type == OP_LEAVELOOP ||
2119 o->op_type == OP_LEAVESUB ||
2120 o->op_type == OP_LEAVETRY)
2122 *ops++ = cUNOPo->op_first;
2124 Perl_croak(aTHX_ too_deep);
2127 if (o->op_flags & OPf_KIDS) {
2128 /* First try all the kids at this level, since that's likeliest. */
2129 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
2130 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
2131 kCOP->cop_label && strEQ(kCOP->cop_label, label))
2134 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
2135 if (kid == PL_lastgotoprobe)
2137 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
2140 else if (ops[-1]->op_type == OP_NEXTSTATE ||
2141 ops[-1]->op_type == OP_DBSTATE)
2146 if ((o = dofindlabel(kid, label, ops, oplimit)))
2165 register PERL_CONTEXT *cx;
2166 #define GOTO_DEPTH 64
2167 OP *enterops[GOTO_DEPTH];
2169 int do_dump = (PL_op->op_type == OP_DUMP);
2170 static char must_have_label[] = "goto must have label";
2173 if (PL_op->op_flags & OPf_STACKED) {
2177 /* This egregious kludge implements goto &subroutine */
2178 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
2180 register PERL_CONTEXT *cx;
2181 CV* cv = (CV*)SvRV(sv);
2187 if (!CvROOT(cv) && !CvXSUB(cv)) {
2192 /* autoloaded stub? */
2193 if (cv != GvCV(gv) && (cv = GvCV(gv)))
2195 autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv),
2196 GvNAMELEN(gv), FALSE);
2197 if (autogv && (cv = GvCV(autogv)))
2199 tmpstr = sv_newmortal();
2200 gv_efullname3(tmpstr, gv, Nullch);
2201 DIE(aTHX_ "Goto undefined subroutine &%"SVf"",tmpstr);
2203 DIE(aTHX_ "Goto undefined subroutine");
2206 /* First do some returnish stuff. */
2207 SvREFCNT_inc(cv); /* avoid premature free during unwind */
2209 cxix = dopoptosub(cxstack_ix);
2211 DIE(aTHX_ "Can't goto subroutine outside a subroutine");
2212 if (cxix < cxstack_ix)
2216 DIE(aTHX_ "Can't goto subroutine from an eval-string");
2218 if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.hasargs) {
2219 /* put @_ back onto stack */
2220 AV* av = cx->blk_sub.argarray;
2222 items = AvFILLp(av) + 1;
2224 EXTEND(PL_stack_sp, items); /* @_ could have been extended. */
2225 Copy(AvARRAY(av), PL_stack_sp, items, SV*);
2226 PL_stack_sp += items;
2227 SvREFCNT_dec(GvAV(PL_defgv));
2228 GvAV(PL_defgv) = cx->blk_sub.savearray;
2229 /* abandon @_ if it got reified */
2231 (void)sv_2mortal((SV*)av); /* delay until return */
2233 av_extend(av, items-1);
2234 AvFLAGS(av) = AVf_REIFY;
2235 PAD_SVl(0) = (SV*)(cx->blk_sub.argarray = av);
2240 else if (CvXSUB(cv)) { /* put GvAV(defgv) back onto stack */
2242 av = GvAV(PL_defgv);
2243 items = AvFILLp(av) + 1;
2245 EXTEND(PL_stack_sp, items); /* @_ could have been extended. */
2246 Copy(AvARRAY(av), PL_stack_sp, items, SV*);
2247 PL_stack_sp += items;
2249 if (CxTYPE(cx) == CXt_SUB &&
2250 !(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
2251 SvREFCNT_dec(cx->blk_sub.cv);
2252 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2253 LEAVE_SCOPE(oldsave);
2255 /* Now do some callish stuff. */
2257 SAVEFREESV(cv); /* later, undo the 'avoid premature free' hack */
2259 #ifdef PERL_XSUB_OLDSTYLE
2260 if (CvOLDSTYLE(cv)) {
2261 I32 (*fp3)(int,int,int);
2266 fp3 = (I32(*)(int,int,int))CvXSUB(cv);
2267 items = (*fp3)(CvXSUBANY(cv).any_i32,
2268 mark - PL_stack_base + 1,
2270 SP = PL_stack_base + items;
2273 #endif /* PERL_XSUB_OLDSTYLE */
2278 PL_stack_sp--; /* There is no cv arg. */
2279 /* Push a mark for the start of arglist */
2281 (void)(*CvXSUB(cv))(aTHX_ cv);
2282 /* Pop the current context like a decent sub should */
2283 POPBLOCK(cx, PL_curpm);
2284 /* Do _not_ use PUTBACK, keep the XSUB's return stack! */
2287 return pop_return();
2290 AV* padlist = CvPADLIST(cv);
2291 if (CxTYPE(cx) == CXt_EVAL) {
2292 PL_in_eval = cx->blk_eval.old_in_eval;
2293 PL_eval_root = cx->blk_eval.old_eval_root;
2294 cx->cx_type = CXt_SUB;
2295 cx->blk_sub.hasargs = 0;
2297 cx->blk_sub.cv = cv;
2298 cx->blk_sub.olddepth = (U16)CvDEPTH(cv);
2301 if (CvDEPTH(cv) < 2)
2302 (void)SvREFCNT_inc(cv);
2304 if (CvDEPTH(cv) == 100 && ckWARN(WARN_RECURSION))
2305 sub_crush_depth(cv);
2306 pad_push(padlist, CvDEPTH(cv), cx->blk_sub.hasargs);
2308 PAD_SET_CUR(padlist, CvDEPTH(cv));
2309 if (cx->blk_sub.hasargs)
2311 AV* av = (AV*)PAD_SVl(0);
2314 cx->blk_sub.savearray = GvAV(PL_defgv);
2315 GvAV(PL_defgv) = (AV*)SvREFCNT_inc(av);
2316 CX_CURPAD_SAVE(cx->blk_sub);
2317 cx->blk_sub.argarray = av;
2320 if (items >= AvMAX(av) + 1) {
2322 if (AvARRAY(av) != ary) {
2323 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
2324 SvPVX(av) = (char*)ary;
2326 if (items >= AvMAX(av) + 1) {
2327 AvMAX(av) = items - 1;
2328 Renew(ary,items+1,SV*);
2330 SvPVX(av) = (char*)ary;
2333 Copy(mark,AvARRAY(av),items,SV*);
2334 AvFILLp(av) = items - 1;
2335 assert(!AvREAL(av));
2342 if (PERLDB_SUB) { /* Checking curstash breaks DProf. */
2344 * We do not care about using sv to call CV;
2345 * it's for informational purposes only.
2347 SV *sv = GvSV(PL_DBsub);
2350 if (PERLDB_SUB_NN) {
2351 (void)SvUPGRADE(sv, SVt_PVIV);
2354 SvIVX(sv) = PTR2IV(cv); /* Do it the quickest way */
2357 gv_efullname3(sv, CvGV(cv), Nullch);
2360 && (gotocv = get_cv("DB::goto", FALSE)) ) {
2361 PUSHMARK( PL_stack_sp );
2362 call_sv((SV*)gotocv, G_SCALAR | G_NODEBUG);
2366 RETURNOP(CvSTART(cv));
2370 label = SvPV(sv,n_a);
2371 if (!(do_dump || *label))
2372 DIE(aTHX_ must_have_label);
2375 else if (PL_op->op_flags & OPf_SPECIAL) {
2377 DIE(aTHX_ must_have_label);
2380 label = cPVOP->op_pv;
2382 if (label && *label) {
2384 bool leaving_eval = FALSE;
2385 bool in_block = FALSE;
2386 PERL_CONTEXT *last_eval_cx = 0;
2390 PL_lastgotoprobe = 0;
2392 for (ix = cxstack_ix; ix >= 0; ix--) {
2394 switch (CxTYPE(cx)) {
2396 leaving_eval = TRUE;
2397 if (!CxTRYBLOCK(cx)) {
2398 gotoprobe = (last_eval_cx ?
2399 last_eval_cx->blk_eval.old_eval_root :
2404 /* else fall through */
2406 gotoprobe = cx->blk_oldcop->op_sibling;
2412 gotoprobe = cx->blk_oldcop->op_sibling;
2415 gotoprobe = PL_main_root;
2418 if (CvDEPTH(cx->blk_sub.cv)) {
2419 gotoprobe = CvROOT(cx->blk_sub.cv);
2425 DIE(aTHX_ "Can't \"goto\" out of a pseudo block");
2428 DIE(aTHX_ "panic: goto");
2429 gotoprobe = PL_main_root;
2433 retop = dofindlabel(gotoprobe, label,
2434 enterops, enterops + GOTO_DEPTH);
2438 PL_lastgotoprobe = gotoprobe;
2441 DIE(aTHX_ "Can't find label %s", label);
2443 /* if we're leaving an eval, check before we pop any frames
2444 that we're not going to punt, otherwise the error
2447 if (leaving_eval && *enterops && enterops[1]) {
2449 for (i = 1; enterops[i]; i++)
2450 if (enterops[i]->op_type == OP_ENTERITER)
2451 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2454 /* pop unwanted frames */
2456 if (ix < cxstack_ix) {
2463 oldsave = PL_scopestack[PL_scopestack_ix];
2464 LEAVE_SCOPE(oldsave);
2467 /* push wanted frames */
2469 if (*enterops && enterops[1]) {
2471 ix = enterops[1]->op_type == OP_ENTER && in_block ? 2 : 1;
2472 for (; enterops[ix]; ix++) {
2473 PL_op = enterops[ix];
2474 /* Eventually we may want to stack the needed arguments
2475 * for each op. For now, we punt on the hard ones. */
2476 if (PL_op->op_type == OP_ENTERITER)
2477 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2478 CALL_FPTR(PL_op->op_ppaddr)(aTHX);
2486 if (!retop) retop = PL_main_start;
2488 PL_restartop = retop;
2489 PL_do_undump = TRUE;
2493 PL_restartop = 0; /* hmm, must be GNU unexec().. */
2494 PL_do_undump = FALSE;
2510 if (anum == 1 && (PL_op->op_private & OPpEXIT_VMSISH))
2512 VMSISH_HUSHED = VMSISH_HUSHED || (PL_op->op_private & OPpHUSH_VMSISH);
2515 PL_exit_flags |= PERL_EXIT_EXPECTED;
2517 PUSHs(&PL_sv_undef);
2525 NV value = SvNVx(GvSV(cCOP->cop_gv));
2526 register I32 match = I_32(value);
2529 if (((NV)match) > value)
2530 --match; /* was fractional--truncate other way */
2532 match -= cCOP->uop.scop.scop_offset;
2535 else if (match > cCOP->uop.scop.scop_max)
2536 match = cCOP->uop.scop.scop_max;
2537 PL_op = cCOP->uop.scop.scop_next[match];
2547 PL_op = PL_op->op_next; /* can't assume anything */
2550 match = *(SvPVx(GvSV(cCOP->cop_gv), n_a)) & 255;
2551 match -= cCOP->uop.scop.scop_offset;
2554 else if (match > cCOP->uop.scop.scop_max)
2555 match = cCOP->uop.scop.scop_max;
2556 PL_op = cCOP->uop.scop.scop_next[match];
2565 S_save_lines(pTHX_ AV *array, SV *sv)
2567 register char *s = SvPVX(sv);
2568 register char *send = SvPVX(sv) + SvCUR(sv);
2570 register I32 line = 1;
2572 while (s && s < send) {
2573 SV *tmpstr = NEWSV(85,0);
2575 sv_upgrade(tmpstr, SVt_PVMG);
2576 t = strchr(s, '\n');
2582 sv_setpvn(tmpstr, s, t - s);
2583 av_store(array, line++, tmpstr);
2588 #ifdef PERL_FLEXIBLE_EXCEPTIONS
2590 S_docatch_body(pTHX_ va_list args)
2592 return docatch_body();
2597 S_docatch_body(pTHX)
2604 S_docatch(pTHX_ OP *o)
2609 volatile PERL_SI *cursi = PL_curstackinfo;
2613 assert(CATCH_GET == TRUE);
2617 /* Normally, the leavetry at the end of this block of ops will
2618 * pop an op off the return stack and continue there. By setting
2619 * the op to Nullop, we force an exit from the inner runops()
2622 retop = pop_return();
2623 push_return(Nullop);
2625 #ifdef PERL_FLEXIBLE_EXCEPTIONS
2627 CALLPROTECT(aTHX_ pcur_env, &ret, MEMBER_TO_FPTR(S_docatch_body));
2633 #ifndef PERL_FLEXIBLE_EXCEPTIONS
2639 /* die caught by an inner eval - continue inner loop */
2640 if (PL_restartop && cursi == PL_curstackinfo) {
2641 PL_op = PL_restartop;
2645 /* a die in this eval - continue in outer loop */
2661 Perl_sv_compile_2op(pTHX_ SV *sv, OP** startop, char *code, PAD** padp)
2662 /* sv Text to convert to OP tree. */
2663 /* startop op_free() this to undo. */
2664 /* code Short string id of the caller. */
2666 dSP; /* Make POPBLOCK work. */
2669 I32 gimme = 0; /* SUSPECT - INITIALZE TO WHAT? NI-S */
2673 char tbuf[TYPE_DIGITS(long) + 12 + 10];
2674 char *tmpbuf = tbuf;
2677 CV* runcv = Nullcv; /* initialise to avoid compiler warnings */
2682 /* switch to eval mode */
2684 if (IN_PERL_COMPILETIME) {
2685 SAVECOPSTASH_FREE(&PL_compiling);
2686 CopSTASH_set(&PL_compiling, PL_curstash);
2688 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
2689 SV *sv = sv_newmortal();
2690 Perl_sv_setpvf(aTHX_ sv, "_<(%.10seval %lu)[%s:%"IVdf"]",
2691 code, (unsigned long)++PL_evalseq,
2692 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
2696 sprintf(tmpbuf, "_<(%.10s_eval %lu)", code, (unsigned long)++PL_evalseq);
2697 SAVECOPFILE_FREE(&PL_compiling);
2698 CopFILE_set(&PL_compiling, tmpbuf+2);
2699 SAVECOPLINE(&PL_compiling);
2700 CopLINE_set(&PL_compiling, 1);
2701 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2702 deleting the eval's FILEGV from the stash before gv_check() runs
2703 (i.e. before run-time proper). To work around the coredump that
2704 ensues, we always turn GvMULTI_on for any globals that were
2705 introduced within evals. See force_ident(). GSAR 96-10-12 */
2706 safestr = savepv(tmpbuf);
2707 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
2709 #ifdef OP_IN_REGISTER
2714 PL_hints &= HINT_UTF8;
2716 /* we get here either during compilation, or via pp_regcomp at runtime */
2717 runtime = IN_PERL_RUNTIME;
2719 runcv = find_runcv(NULL);
2722 PL_op->op_type = OP_ENTEREVAL;
2723 PL_op->op_flags = 0; /* Avoid uninit warning. */
2724 PUSHBLOCK(cx, CXt_EVAL|(IN_PERL_COMPILETIME ? 0 : CXp_REAL), SP);
2725 PUSHEVAL(cx, 0, Nullgv);
2728 rop = doeval(G_SCALAR, startop, runcv, PL_curcop->cop_seq);
2730 rop = doeval(G_SCALAR, startop, PL_compcv, PL_cop_seqmax);
2731 POPBLOCK(cx,PL_curpm);
2734 (*startop)->op_type = OP_NULL;
2735 (*startop)->op_ppaddr = PL_ppaddr[OP_NULL];
2737 /* XXX DAPM do this properly one year */
2738 *padp = (AV*)SvREFCNT_inc(PL_comppad);
2740 if (IN_PERL_COMPILETIME)
2741 PL_compiling.op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);
2742 #ifdef OP_IN_REGISTER
2750 =for apidoc find_runcv
2752 Locate the CV corresponding to the currently executing sub or eval.
2753 If db_seqp is non_null, skip CVs that are in the DB package and populate
2754 *db_seqp with the cop sequence number at the point that the DB:: code was
2755 entered. (allows debuggers to eval in the scope of the breakpoint rather
2756 than in in the scope of the debuger itself).
2762 Perl_find_runcv(pTHX_ U32 *db_seqp)
2769 *db_seqp = PL_curcop->cop_seq;
2770 for (si = PL_curstackinfo; si; si = si->si_prev) {
2771 for (ix = si->si_cxix; ix >= 0; ix--) {
2772 cx = &(si->si_cxstack[ix]);
2773 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
2774 CV *cv = cx->blk_sub.cv;
2775 /* skip DB:: code */
2776 if (db_seqp && PL_debstash && CvSTASH(cv) == PL_debstash) {
2777 *db_seqp = cx->blk_oldcop->cop_seq;
2782 else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx))
2790 /* Compile a require/do, an eval '', or a /(?{...})/.
2791 * In the last case, startop is non-null, and contains the address of
2792 * a pointer that should be set to the just-compiled code.
2793 * outside is the lexically enclosing CV (if any) that invoked us.
2796 /* With USE_5005THREADS, eval_owner must be held on entry to doeval */
2798 S_doeval(pTHX_ int gimme, OP** startop, CV* outside, U32 seq)
2803 PL_in_eval = ((saveop && saveop->op_type == OP_REQUIRE)
2804 ? (EVAL_INREQUIRE | (PL_in_eval & EVAL_INEVAL))
2809 SAVESPTR(PL_compcv);
2810 PL_compcv = (CV*)NEWSV(1104,0);
2811 sv_upgrade((SV *)PL_compcv, SVt_PVCV);
2812 CvEVAL_on(PL_compcv);
2813 assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
2814 cxstack[cxstack_ix].blk_eval.cv = PL_compcv;
2816 CvOUTSIDE_SEQ(PL_compcv) = seq;
2817 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outside);
2819 /* set up a scratch pad */
2821 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE);
2824 SAVEMORTALIZESV(PL_compcv); /* must remain until end of current statement */
2826 /* make sure we compile in the right package */
2828 if (CopSTASH_ne(PL_curcop, PL_curstash)) {
2829 SAVESPTR(PL_curstash);
2830 PL_curstash = CopSTASH(PL_curcop);
2832 SAVESPTR(PL_beginav);
2833 PL_beginav = newAV();
2834 SAVEFREESV(PL_beginav);
2835 SAVEI32(PL_error_count);
2837 /* try to compile it */
2839 PL_eval_root = Nullop;
2841 PL_curcop = &PL_compiling;
2842 PL_curcop->cop_arybase = 0;
2843 if (saveop && saveop->op_flags & OPf_SPECIAL)
2844 PL_in_eval |= EVAL_KEEPERR;
2847 if (yyparse() || PL_error_count || !PL_eval_root) {
2848 SV **newsp; /* Used by POPBLOCK. */
2849 PERL_CONTEXT *cx = &cxstack[cxstack_ix];
2850 I32 optype = 0; /* Might be reset by POPEVAL. */
2855 op_free(PL_eval_root);
2856 PL_eval_root = Nullop;
2858 SP = PL_stack_base + POPMARK; /* pop original mark */
2860 POPBLOCK(cx,PL_curpm);
2866 if (optype == OP_REQUIRE) {
2867 char* msg = SvPVx(ERRSV, n_a);
2868 SV *nsv = cx->blk_eval.old_namesv;
2869 (void)hv_store(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv),
2871 DIE(aTHX_ "%sCompilation failed in require",
2872 *msg ? msg : "Unknown error\n");
2875 char* msg = SvPVx(ERRSV, n_a);
2877 POPBLOCK(cx,PL_curpm);
2879 Perl_croak(aTHX_ "%sCompilation failed in regexp",
2880 (*msg ? msg : "Unknown error\n"));
2883 char* msg = SvPVx(ERRSV, n_a);
2885 sv_setpv(ERRSV, "Compilation error");
2890 CopLINE_set(&PL_compiling, 0);
2892 *startop = PL_eval_root;
2894 SAVEFREEOP(PL_eval_root);
2896 /* Set the context for this new optree.
2897 * If the last op is an OP_REQUIRE, force scalar context.
2898 * Otherwise, propagate the context from the eval(). */
2899 if (PL_eval_root->op_type == OP_LEAVEEVAL
2900 && cUNOPx(PL_eval_root)->op_first->op_type == OP_LINESEQ
2901 && cLISTOPx(cUNOPx(PL_eval_root)->op_first)->op_last->op_type
2903 scalar(PL_eval_root);
2904 else if (gimme & G_VOID)
2905 scalarvoid(PL_eval_root);
2906 else if (gimme & G_ARRAY)
2909 scalar(PL_eval_root);
2911 DEBUG_x(dump_eval());
2913 /* Register with debugger: */
2914 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2915 CV *cv = get_cv("DB::postponed", FALSE);
2919 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2921 call_sv((SV*)cv, G_DISCARD);
2925 /* compiled okay, so do it */
2927 CvDEPTH(PL_compcv) = 1;
2928 SP = PL_stack_base + POPMARK; /* pop original mark */
2929 PL_op = saveop; /* The caller may need it. */
2930 PL_lex_state = LEX_NOTPARSING; /* $^S needs this. */
2932 RETURNOP(PL_eval_start);
2936 S_doopen_pm(pTHX_ const char *name, const char *mode)
2938 #ifndef PERL_DISABLE_PMC
2939 STRLEN namelen = strlen(name);
2942 if (namelen > 3 && strEQ(name + namelen - 3, ".pm")) {
2943 SV *pmcsv = Perl_newSVpvf(aTHX_ "%s%c", name, 'c');
2944 char *pmc = SvPV_nolen(pmcsv);
2947 if (PerlLIO_stat(pmc, &pmcstat) < 0) {
2948 fp = PerlIO_open(name, mode);
2951 if (PerlLIO_stat(name, &pmstat) < 0 ||
2952 pmstat.st_mtime < pmcstat.st_mtime)
2954 fp = PerlIO_open(pmc, mode);
2957 fp = PerlIO_open(name, mode);
2960 SvREFCNT_dec(pmcsv);
2963 fp = PerlIO_open(name, mode);
2967 return PerlIO_open(name, mode);
2968 #endif /* !PERL_DISABLE_PMC */
2974 register PERL_CONTEXT *cx;
2978 char *tryname = Nullch;
2979 SV *namesv = Nullsv;
2981 I32 gimme = GIMME_V;
2982 PerlIO *tryrsfp = 0;
2984 int filter_has_file = 0;
2985 GV *filter_child_proc = 0;
2986 SV *filter_state = 0;
2993 if (SvNIOKp(sv) && PL_op->op_type != OP_DOFILE) {
2994 if (SvPOK(sv) && SvNOK(sv) && SvNV(sv)) { /* require v5.6.1 */
2995 UV rev = 0, ver = 0, sver = 0;
2997 U8 *s = (U8*)SvPVX(sv);
2998 U8 *end = (U8*)SvPVX(sv) + SvCUR(sv);
3000 rev = utf8n_to_uvchr(s, end - s, &len, 0);
3003 ver = utf8n_to_uvchr(s, end - s, &len, 0);
3006 sver = utf8n_to_uvchr(s, end - s, &len, 0);
3009 if (PERL_REVISION < rev
3010 || (PERL_REVISION == rev
3011 && (PERL_VERSION < ver
3012 || (PERL_VERSION == ver
3013 && PERL_SUBVERSION < sver))))
3015 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--this is only "
3016 "v%d.%d.%d, stopped", rev, ver, sver, PERL_REVISION,
3017 PERL_VERSION, PERL_SUBVERSION);
3019 if (ckWARN(WARN_PORTABLE))
3020 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
3021 "v-string in use/require non-portable");
3024 else if (!SvPOKp(sv)) { /* require 5.005_03 */
3025 if ((NV)PERL_REVISION + ((NV)PERL_VERSION/(NV)1000)
3026 + ((NV)PERL_SUBVERSION/(NV)1000000)
3027 + 0.00000099 < SvNV(sv))
3031 NV nver = (nrev - rev) * 1000;
3032 UV ver = (UV)(nver + 0.0009);
3033 NV nsver = (nver - ver) * 1000;
3034 UV sver = (UV)(nsver + 0.0009);
3036 /* help out with the "use 5.6" confusion */
3037 if (sver == 0 && (rev > 5 || (rev == 5 && ver >= 100))) {
3038 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required"
3039 " (did you mean v%"UVuf".%03"UVuf"?)--"
3040 "this is only v%d.%d.%d, stopped",
3041 rev, ver, sver, rev, ver/100,
3042 PERL_REVISION, PERL_VERSION, PERL_SUBVERSION);
3045 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--"
3046 "this is only v%d.%d.%d, stopped",
3047 rev, ver, sver, PERL_REVISION, PERL_VERSION,
3054 name = SvPV(sv, len);
3055 if (!(name && len > 0 && *name))
3056 DIE(aTHX_ "Null filename used");
3057 TAINT_PROPER("require");
3058 if (PL_op->op_type == OP_REQUIRE &&
3059 (svp = hv_fetch(GvHVn(PL_incgv), name, len, 0))) {
3060 if (*svp != &PL_sv_undef)
3063 DIE(aTHX_ "Compilation failed in require");
3066 /* prepare to compile file */
3068 if (path_is_absolute(name)) {
3070 tryrsfp = doopen_pm(name,PERL_SCRIPT_MODE);
3072 #ifdef MACOS_TRADITIONAL
3076 MacPerl_CanonDir(name, newname, 1);
3077 if (path_is_absolute(newname)) {
3079 tryrsfp = doopen_pm(newname,PERL_SCRIPT_MODE);
3084 AV *ar = GvAVn(PL_incgv);
3088 if ((unixname = tounixspec(name, Nullch)) != Nullch)
3091 namesv = NEWSV(806, 0);
3092 for (i = 0; i <= AvFILL(ar); i++) {
3093 SV *dirsv = *av_fetch(ar, i, TRUE);
3099 if (SvTYPE(SvRV(loader)) == SVt_PVAV
3100 && !sv_isobject(loader))
3102 loader = *av_fetch((AV *)SvRV(loader), 0, TRUE);
3105 Perl_sv_setpvf(aTHX_ namesv, "/loader/0x%"UVxf"/%s",
3106 PTR2UV(SvRV(dirsv)), name);
3107 tryname = SvPVX(namesv);
3118 if (sv_isobject(loader))
3119 count = call_method("INC", G_ARRAY);
3121 count = call_sv(loader, G_ARRAY);
3131 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVGV) {
3135 if (SvTYPE(arg) == SVt_PVGV) {
3136 IO *io = GvIO((GV *)arg);
3141 tryrsfp = IoIFP(io);
3142 if (IoTYPE(io) == IoTYPE_PIPE) {
3143 /* reading from a child process doesn't
3144 nest -- when returning from reading
3145 the inner module, the outer one is
3146 unreadable (closed?) I've tried to
3147 save the gv to manage the lifespan of
3148 the pipe, but this didn't help. XXX */
3149 filter_child_proc = (GV *)arg;
3150 (void)SvREFCNT_inc(filter_child_proc);
3153 if (IoOFP(io) && IoOFP(io) != IoIFP(io)) {
3154 PerlIO_close(IoOFP(io));
3166 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVCV) {
3168 (void)SvREFCNT_inc(filter_sub);
3171 filter_state = SP[i];
3172 (void)SvREFCNT_inc(filter_state);
3176 tryrsfp = PerlIO_open("/dev/null",
3192 filter_has_file = 0;
3193 if (filter_child_proc) {
3194 SvREFCNT_dec(filter_child_proc);
3195 filter_child_proc = 0;
3198 SvREFCNT_dec(filter_state);
3202 SvREFCNT_dec(filter_sub);
3207 if (!path_is_absolute(name)
3208 #ifdef MACOS_TRADITIONAL
3209 /* We consider paths of the form :a:b ambiguous and interpret them first
3210 as global then as local
3212 || (*name == ':' && name[1] != ':' && strchr(name+2, ':'))
3215 char *dir = SvPVx(dirsv, n_a);
3216 #ifdef MACOS_TRADITIONAL
3220 MacPerl_CanonDir(name, buf2, 1);
3221 Perl_sv_setpvf(aTHX_ namesv, "%s%s", MacPerl_CanonDir(dir, buf1, 0), buf2+(buf2[0] == ':'));
3225 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
3227 sv_setpv(namesv, unixdir);
3228 sv_catpv(namesv, unixname);
3230 Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name);
3233 TAINT_PROPER("require");
3234 tryname = SvPVX(namesv);
3235 tryrsfp = doopen_pm(tryname, PERL_SCRIPT_MODE);
3237 if (tryname[0] == '.' && tryname[1] == '/')
3246 SAVECOPFILE_FREE(&PL_compiling);
3247 CopFILE_set(&PL_compiling, tryrsfp ? tryname : name);
3248 SvREFCNT_dec(namesv);
3250 if (PL_op->op_type == OP_REQUIRE) {
3251 char *msgstr = name;
3252 if (namesv) { /* did we lookup @INC? */
3253 SV *msg = sv_2mortal(newSVpv(msgstr,0));
3254 SV *dirmsgsv = NEWSV(0, 0);
3255 AV *ar = GvAVn(PL_incgv);
3257 sv_catpvn(msg, " in @INC", 8);
3258 if (instr(SvPVX(msg), ".h "))
3259 sv_catpv(msg, " (change .h to .ph maybe?)");
3260 if (instr(SvPVX(msg), ".ph "))
3261 sv_catpv(msg, " (did you run h2ph?)");
3262 sv_catpv(msg, " (@INC contains:");
3263 for (i = 0; i <= AvFILL(ar); i++) {
3264 char *dir = SvPVx(*av_fetch(ar, i, TRUE), n_a);
3265 Perl_sv_setpvf(aTHX_ dirmsgsv, " %s", dir);
3266 sv_catsv(msg, dirmsgsv);
3268 sv_catpvn(msg, ")", 1);
3269 SvREFCNT_dec(dirmsgsv);
3270 msgstr = SvPV_nolen(msg);
3272 DIE(aTHX_ "Can't locate %s", msgstr);
3278 SETERRNO(0, SS_NORMAL);
3280 /* Assume success here to prevent recursive requirement. */
3282 /* Check whether a hook in @INC has already filled %INC */
3283 if (!hook_sv || !(svp = hv_fetch(GvHVn(PL_incgv), name, len, 0))) {
3284 (void)hv_store(GvHVn(PL_incgv), name, len,
3285 (hook_sv ? SvREFCNT_inc(hook_sv)
3286 : newSVpv(CopFILE(&PL_compiling), 0)),
3292 lex_start(sv_2mortal(newSVpvn("",0)));
3293 SAVEGENERICSV(PL_rsfp_filters);
3294 PL_rsfp_filters = Nullav;
3299 SAVESPTR(PL_compiling.cop_warnings);
3300 if (PL_dowarn & G_WARN_ALL_ON)
3301 PL_compiling.cop_warnings = pWARN_ALL ;
3302 else if (PL_dowarn & G_WARN_ALL_OFF)
3303 PL_compiling.cop_warnings = pWARN_NONE ;
3304 else if (PL_taint_warn)
3305 PL_compiling.cop_warnings = newSVpvn(WARN_TAINTstring, WARNsize);
3307 PL_compiling.cop_warnings = pWARN_STD ;
3308 SAVESPTR(PL_compiling.cop_io);
3309 PL_compiling.cop_io = Nullsv;
3311 if (filter_sub || filter_child_proc) {
3312 SV *datasv = filter_add(run_user_filter, Nullsv);
3313 IoLINES(datasv) = filter_has_file;
3314 IoFMT_GV(datasv) = (GV *)filter_child_proc;
3315 IoTOP_GV(datasv) = (GV *)filter_state;
3316 IoBOTTOM_GV(datasv) = (GV *)filter_sub;
3319 /* switch to eval mode */
3320 push_return(PL_op->op_next);
3321 PUSHBLOCK(cx, CXt_EVAL, SP);
3322 PUSHEVAL(cx, name, Nullgv);
3324 SAVECOPLINE(&PL_compiling);
3325 CopLINE_set(&PL_compiling, 0);
3329 /* Store and reset encoding. */
3330 encoding = PL_encoding;
3331 PL_encoding = Nullsv;
3333 op = DOCATCH(doeval(gimme, NULL, Nullcv, PL_curcop->cop_seq));
3335 /* Restore encoding. */
3336 PL_encoding = encoding;
3343 return pp_require();
3349 register PERL_CONTEXT *cx;
3351 I32 gimme = GIMME_V, was = PL_sub_generation;
3352 char tbuf[TYPE_DIGITS(long) + 12];
3353 char *tmpbuf = tbuf;
3362 TAINT_PROPER("eval");
3368 /* switch to eval mode */
3370 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
3371 SV *sv = sv_newmortal();
3372 Perl_sv_setpvf(aTHX_ sv, "_<(eval %lu)[%s:%"IVdf"]",
3373 (unsigned long)++PL_evalseq,
3374 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
3378 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++PL_evalseq);
3379 SAVECOPFILE_FREE(&PL_compiling);
3380 CopFILE_set(&PL_compiling, tmpbuf+2);
3381 SAVECOPLINE(&PL_compiling);
3382 CopLINE_set(&PL_compiling, 1);
3383 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
3384 deleting the eval's FILEGV from the stash before gv_check() runs
3385 (i.e. before run-time proper). To work around the coredump that
3386 ensues, we always turn GvMULTI_on for any globals that were
3387 introduced within evals. See force_ident(). GSAR 96-10-12 */
3388 safestr = savepv(tmpbuf);
3389 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
3391 PL_hints = PL_op->op_targ;
3392 SAVESPTR(PL_compiling.cop_warnings);
3393 if (specialWARN(PL_curcop->cop_warnings))
3394 PL_compiling.cop_warnings = PL_curcop->cop_warnings;
3396 PL_compiling.cop_warnings = newSVsv(PL_curcop->cop_warnings);
3397 SAVEFREESV(PL_compiling.cop_warnings);
3399 SAVESPTR(PL_compiling.cop_io);
3400 if (specialCopIO(PL_curcop->cop_io))
3401 PL_compiling.cop_io = PL_curcop->cop_io;
3403 PL_compiling.cop_io = newSVsv(PL_curcop->cop_io);
3404 SAVEFREESV(PL_compiling.cop_io);
3406 /* special case: an eval '' executed within the DB package gets lexically
3407 * placed in the first non-DB CV rather than the current CV - this
3408 * allows the debugger to execute code, find lexicals etc, in the
3409 * scope of the code being debugged. Passing &seq gets find_runcv
3410 * to do the dirty work for us */
3411 runcv = find_runcv(&seq);
3413 push_return(PL_op->op_next);
3414 PUSHBLOCK(cx, (CXt_EVAL|CXp_REAL), SP);
3415 PUSHEVAL(cx, 0, Nullgv);
3417 /* prepare to compile string */
3419 if (PERLDB_LINE && PL_curstash != PL_debstash)
3420 save_lines(CopFILEAV(&PL_compiling), PL_linestr);
3422 ret = doeval(gimme, NULL, runcv, seq);
3423 if (PERLDB_INTER && was != (I32)PL_sub_generation /* Some subs defined here. */
3424 && ret != PL_op->op_next) { /* Successive compilation. */
3425 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
3427 return DOCATCH(ret);
3437 register PERL_CONTEXT *cx;
3439 U8 save_flags = PL_op -> op_flags;
3444 retop = pop_return();
3447 if (gimme == G_VOID)
3449 else if (gimme == G_SCALAR) {
3452 if (SvFLAGS(TOPs) & SVs_TEMP)
3455 *MARK = sv_mortalcopy(TOPs);
3459 *MARK = &PL_sv_undef;
3464 /* in case LEAVE wipes old return values */
3465 for (mark = newsp + 1; mark <= SP; mark++) {
3466 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
3467 *mark = sv_mortalcopy(*mark);
3468 TAINT_NOT; /* Each item is independent */
3472 PL_curpm = newpm; /* Don't pop $1 et al till now */
3475 assert(CvDEPTH(PL_compcv) == 1);
3477 CvDEPTH(PL_compcv) = 0;
3480 if (optype == OP_REQUIRE &&
3481 !(gimme == G_SCALAR ? SvTRUE(*SP) : SP > newsp))
3483 /* Unassume the success we assumed earlier. */
3484 SV *nsv = cx->blk_eval.old_namesv;
3485 (void)hv_delete(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), G_DISCARD);
3486 retop = Perl_die(aTHX_ "%"SVf" did not return a true value", nsv);
3487 /* die_where() did LEAVE, or we won't be here */
3491 if (!(save_flags & OPf_SPECIAL))
3501 register PERL_CONTEXT *cx;
3502 I32 gimme = GIMME_V;
3507 push_return(cLOGOP->op_other->op_next);
3508 PUSHBLOCK(cx, (CXt_EVAL|CXp_TRYBLOCK), SP);
3511 PL_in_eval = EVAL_INEVAL;
3514 return DOCATCH(PL_op->op_next);
3525 register PERL_CONTEXT *cx;
3530 retop = pop_return();
3533 if (gimme == G_VOID)
3535 else if (gimme == G_SCALAR) {
3538 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
3541 *MARK = sv_mortalcopy(TOPs);
3545 *MARK = &PL_sv_undef;
3550 /* in case LEAVE wipes old return values */
3551 for (mark = newsp + 1; mark <= SP; mark++) {
3552 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
3553 *mark = sv_mortalcopy(*mark);
3554 TAINT_NOT; /* Each item is independent */
3558 PL_curpm = newpm; /* Don't pop $1 et al till now */
3566 S_doparseform(pTHX_ SV *sv)
3569 register char *s = SvPV_force(sv, len);
3570 register char *send = s + len;
3571 register char *base = Nullch;
3572 register I32 skipspaces = 0;
3573 bool noblank = FALSE;
3574 bool repeat = FALSE;
3575 bool postspace = FALSE;
3581 int maxops = 2; /* FF_LINEMARK + FF_END) */
3584 Perl_croak(aTHX_ "Null picture in formline");
3586 /* estimate the buffer size needed */
3587 for (base = s; s <= send; s++) {
3588 if (*s == '\n' || *s == '@' || *s == '^')
3594 New(804, fops, maxops, U32);
3599 *fpc++ = FF_LINEMARK;
3600 noblank = repeat = FALSE;
3618 case ' ': case '\t':
3629 *fpc++ = FF_LITERAL;
3637 *fpc++ = (U16)skipspaces;
3641 *fpc++ = FF_NEWLINE;
3645 arg = fpc - linepc + 1;
3652 *fpc++ = FF_LINEMARK;
3653 noblank = repeat = FALSE;
3662 ischop = s[-1] == '^';
3668 arg = (s - base) - 1;
3670 *fpc++ = FF_LITERAL;
3679 *fpc++ = FF_LINEGLOB;
3681 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
3682 arg = ischop ? 512 : 0;
3692 arg |= 256 + (s - f);
3694 *fpc++ = s - base; /* fieldsize for FETCH */
3695 *fpc++ = FF_DECIMAL;
3698 else if (*s == '0' && s[1] == '#') { /* Zero padded decimals */
3699 arg = ischop ? 512 : 0;
3701 s++; /* skip the '0' first */
3710 arg |= 256 + (s - f);
3712 *fpc++ = s - base; /* fieldsize for FETCH */
3713 *fpc++ = FF_0DECIMAL;
3718 bool ismore = FALSE;
3721 while (*++s == '>') ;
3722 prespace = FF_SPACE;
3724 else if (*s == '|') {
3725 while (*++s == '|') ;
3726 prespace = FF_HALFSPACE;
3731 while (*++s == '<') ;
3734 if (*s == '.' && s[1] == '.' && s[2] == '.') {
3738 *fpc++ = s - base; /* fieldsize for FETCH */
3740 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
3743 *fpc++ = (U16)prespace;
3757 assert (fpc <= fops + maxops); /* ensure our buffer estimate was valid */
3759 { /* need to jump to the next word */
3761 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
3762 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U32) + 4);
3763 s = SvPVX(sv) + SvCUR(sv) + z;
3765 Copy(fops, s, arg, U32);
3767 sv_magic(sv, Nullsv, PERL_MAGIC_fm, Nullch, 0);
3772 run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen)
3774 SV *datasv = FILTER_DATA(idx);
3775 int filter_has_file = IoLINES(datasv);
3776 GV *filter_child_proc = (GV *)IoFMT_GV(datasv);
3777 SV *filter_state = (SV *)IoTOP_GV(datasv);
3778 SV *filter_sub = (SV *)IoBOTTOM_GV(datasv);
3781 /* I was having segfault trouble under Linux 2.2.5 after a
3782 parse error occured. (Had to hack around it with a test
3783 for PL_error_count == 0.) Solaris doesn't segfault --
3784 not sure where the trouble is yet. XXX */
3786 if (filter_has_file) {
3787 len = FILTER_READ(idx+1, buf_sv, maxlen);
3790 if (filter_sub && len >= 0) {
3801 PUSHs(sv_2mortal(newSViv(maxlen)));
3803 PUSHs(filter_state);
3806 count = call_sv(filter_sub, G_SCALAR);
3822 IoLINES(datasv) = 0;
3823 if (filter_child_proc) {
3824 SvREFCNT_dec(filter_child_proc);
3825 IoFMT_GV(datasv) = Nullgv;
3828 SvREFCNT_dec(filter_state);
3829 IoTOP_GV(datasv) = Nullgv;
3832 SvREFCNT_dec(filter_sub);
3833 IoBOTTOM_GV(datasv) = Nullgv;
3835 filter_del(run_user_filter);
3841 /* perhaps someone can come up with a better name for
3842 this? it is not really "absolute", per se ... */
3844 S_path_is_absolute(pTHX_ char *name)
3846 if (PERL_FILE_IS_ABSOLUTE(name)
3847 #ifdef MACOS_TRADITIONAL
3850 || (*name == '.' && (name[1] == '/' ||
3851 (name[1] == '.' && name[2] == '/'))))