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;
162 REGEXP *old = PM_GETRE(pm);
169 rxres_restore(&cx->sb_rxres, rx);
170 RX_MATCH_UTF8_set(rx, SvUTF8(cx->sb_targ));
172 if (cx->sb_iters++) {
173 I32 saviters = cx->sb_iters;
174 if (cx->sb_iters > cx->sb_maxiters)
175 DIE(aTHX_ "Substitution loop");
177 if (!(cx->sb_rxtainted & 2) && SvTAINTED(TOPs))
178 cx->sb_rxtainted |= 2;
179 sv_catsv(dstr, POPs);
182 if (cx->sb_once || !CALLREGEXEC(aTHX_ rx, s, cx->sb_strend, orig,
183 s == m, cx->sb_targ, NULL,
184 ((cx->sb_rflags & REXEC_COPY_STR)
185 ? (REXEC_IGNOREPOS|REXEC_NOT_FIRST)
186 : (REXEC_COPY_STR|REXEC_IGNOREPOS|REXEC_NOT_FIRST))))
188 SV *targ = cx->sb_targ;
190 if (DO_UTF8(dstr) && !SvUTF8(targ))
191 sv_catpvn_utf8_upgrade(dstr, s, cx->sb_strend - s, nsv);
193 sv_catpvn(dstr, s, cx->sb_strend - s);
194 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
196 #ifdef PERL_COPY_ON_WRITE
198 sv_force_normal_flags(targ, SV_COW_DROP_PV);
202 (void)SvOOK_off(targ);
204 Safefree(SvPVX(targ));
206 SvPVX(targ) = SvPVX(dstr);
207 SvCUR_set(targ, SvCUR(dstr));
208 SvLEN_set(targ, SvLEN(dstr));
214 TAINT_IF(cx->sb_rxtainted & 1);
215 PUSHs(sv_2mortal(newSViv(saviters - 1)));
217 (void)SvPOK_only_UTF8(targ);
218 TAINT_IF(cx->sb_rxtainted);
222 LEAVE_SCOPE(cx->sb_oldsave);
225 RETURNOP(pm->op_next);
227 cx->sb_iters = saviters;
229 if (RX_MATCH_COPIED(rx) && rx->subbeg != orig) {
232 cx->sb_orig = orig = rx->subbeg;
234 cx->sb_strend = s + (cx->sb_strend - m);
236 cx->sb_m = m = rx->startp[0] + orig;
238 if (DO_UTF8(dstr) && !SvUTF8(cx->sb_targ))
239 sv_catpvn_utf8_upgrade(dstr, s, m - s, nsv);
241 sv_catpvn(dstr, s, m-s);
243 cx->sb_s = rx->endp[0] + orig;
244 { /* Update the pos() information. */
245 SV *sv = cx->sb_targ;
248 if (SvTYPE(sv) < SVt_PVMG)
249 (void)SvUPGRADE(sv, SVt_PVMG);
250 if (!(mg = mg_find(sv, PERL_MAGIC_regex_global))) {
251 sv_magic(sv, Nullsv, PERL_MAGIC_regex_global, Nullch, 0);
252 mg = mg_find(sv, PERL_MAGIC_regex_global);
261 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
262 rxres_save(&cx->sb_rxres, rx);
263 RETURNOP(pm->op_pmreplstart);
267 Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx)
272 if (!p || p[1] < rx->nparens) {
273 #ifdef PERL_COPY_ON_WRITE
274 i = 7 + rx->nparens * 2;
276 i = 6 + rx->nparens * 2;
285 *p++ = PTR2UV(RX_MATCH_COPIED(rx) ? rx->subbeg : Nullch);
286 RX_MATCH_COPIED_off(rx);
288 #ifdef PERL_COPY_ON_WRITE
289 *p++ = PTR2UV(rx->saved_copy);
290 rx->saved_copy = Nullsv;
295 *p++ = PTR2UV(rx->subbeg);
296 *p++ = (UV)rx->sublen;
297 for (i = 0; i <= rx->nparens; ++i) {
298 *p++ = (UV)rx->startp[i];
299 *p++ = (UV)rx->endp[i];
304 Perl_rxres_restore(pTHX_ void **rsp, REGEXP *rx)
309 RX_MATCH_COPY_FREE(rx);
310 RX_MATCH_COPIED_set(rx, *p);
313 #ifdef PERL_COPY_ON_WRITE
315 SvREFCNT_dec (rx->saved_copy);
316 rx->saved_copy = INT2PTR(SV*,*p);
322 rx->subbeg = INT2PTR(char*,*p++);
323 rx->sublen = (I32)(*p++);
324 for (i = 0; i <= rx->nparens; ++i) {
325 rx->startp[i] = (I32)(*p++);
326 rx->endp[i] = (I32)(*p++);
331 Perl_rxres_free(pTHX_ void **rsp)
336 Safefree(INT2PTR(char*,*p));
337 #ifdef PERL_COPY_ON_WRITE
339 SvREFCNT_dec (INT2PTR(SV*,p[1]));
349 dSP; dMARK; dORIGMARK;
350 register SV *tmpForm = *++MARK;
357 register SV *sv = Nullsv;
362 bool chopspace = (strchr(PL_chopset, ' ') != Nullch);
363 char *chophere = Nullch;
364 char *linemark = Nullch;
366 bool gotsome = FALSE;
368 STRLEN fudge = SvCUR(tmpForm) * (IN_BYTES ? 1 : 3) + 1;
369 bool item_is_utf8 = FALSE;
370 bool targ_is_utf8 = FALSE;
373 if (!SvMAGICAL(tmpForm) || !SvCOMPILED(tmpForm)) {
374 if (SvREADONLY(tmpForm)) {
375 SvREADONLY_off(tmpForm);
376 doparseform(tmpForm);
377 SvREADONLY_on(tmpForm);
380 doparseform(tmpForm);
382 SvPV_force(PL_formtarget, len);
383 if (DO_UTF8(PL_formtarget))
385 t = SvGROW(PL_formtarget, len + fudge + 1); /* XXX SvCUR bad */
387 f = SvPV(tmpForm, len);
388 /* need to jump to the next word */
389 s = f + len + WORD_ALIGN - SvCUR(tmpForm) % WORD_ALIGN;
398 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
399 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
400 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
401 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
402 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
404 case FF_CHECKNL: name = "CHECKNL"; break;
405 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
406 case FF_SPACE: name = "SPACE"; break;
407 case FF_HALFSPACE: name = "HALFSPACE"; break;
408 case FF_ITEM: name = "ITEM"; break;
409 case FF_CHOP: name = "CHOP"; break;
410 case FF_LINEGLOB: name = "LINEGLOB"; break;
411 case FF_NEWLINE: name = "NEWLINE"; break;
412 case FF_MORE: name = "MORE"; break;
413 case FF_LINEMARK: name = "LINEMARK"; break;
414 case FF_END: name = "END"; break;
415 case FF_0DECIMAL: name = "0DECIMAL"; break;
418 PerlIO_printf(Perl_debug_log, "%-16s%ld\n", name, (long) arg);
420 PerlIO_printf(Perl_debug_log, "%-16s\n", name);
431 if (targ_is_utf8 && !SvUTF8(tmpForm)) {
432 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
434 sv_catpvn_utf8_upgrade(PL_formtarget, f, arg, nsv);
435 t = SvEND(PL_formtarget);
438 if (!targ_is_utf8 && DO_UTF8(tmpForm)) {
439 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
441 sv_utf8_upgrade(PL_formtarget);
442 SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
443 t = SvEND(PL_formtarget);
463 if (ckWARN(WARN_SYNTAX))
464 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Not enough format arguments");
469 item = s = SvPV(sv, len);
472 itemsize = sv_len_utf8(sv);
473 if (itemsize != (I32)len) {
475 if (itemsize > fieldsize) {
476 itemsize = fieldsize;
477 itembytes = itemsize;
478 sv_pos_u2b(sv, &itembytes, 0);
482 send = chophere = s + itembytes;
492 sv_pos_b2u(sv, &itemsize);
496 item_is_utf8 = FALSE;
497 if (itemsize > fieldsize)
498 itemsize = fieldsize;
499 send = chophere = s + itemsize;
511 item = s = SvPV(sv, len);
514 itemsize = sv_len_utf8(sv);
515 if (itemsize != (I32)len) {
517 if (itemsize <= fieldsize) {
518 send = chophere = s + itemsize;
529 itemsize = fieldsize;
530 itembytes = itemsize;
531 sv_pos_u2b(sv, &itembytes, 0);
532 send = chophere = s + itembytes;
533 while (s < send || (s == send && isSPACE(*s))) {
543 if (strchr(PL_chopset, *s))
548 itemsize = chophere - item;
549 sv_pos_b2u(sv, &itemsize);
555 item_is_utf8 = FALSE;
556 if (itemsize <= fieldsize) {
557 send = chophere = s + itemsize;
568 itemsize = fieldsize;
569 send = chophere = s + itemsize;
570 while (s < send || (s == send && isSPACE(*s))) {
580 if (strchr(PL_chopset, *s))
585 itemsize = chophere - item;
590 arg = fieldsize - itemsize;
599 arg = fieldsize - itemsize;
613 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
615 sv_utf8_upgrade(PL_formtarget);
616 SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
617 t = SvEND(PL_formtarget);
621 if (UTF8_IS_CONTINUED(*s)) {
622 STRLEN skip = UTF8SKIP(s);
639 if ( !((*t++ = *s++) & ~31) )
645 if (targ_is_utf8 && !item_is_utf8) {
646 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
648 sv_catpvn_utf8_upgrade(PL_formtarget, s, arg, nsv);
649 for (; t < SvEND(PL_formtarget); t++) {
651 int ch = *t++ = *s++;
662 int ch = *t++ = *s++;
665 if ( !((*t++ = *s++) & ~31) )
674 while (*s && isSPACE(*s))
682 item = s = SvPV(sv, len);
684 if ((item_is_utf8 = DO_UTF8(sv)))
685 itemsize = sv_len_utf8(sv);
687 bool chopped = FALSE;
700 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
702 SvUTF8_on(PL_formtarget);
703 sv_catsv(PL_formtarget, sv);
705 SvCUR_set(PL_formtarget, SvCUR(PL_formtarget) - 1);
706 SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
707 t = SvPVX(PL_formtarget) + SvCUR(PL_formtarget);
714 /* If the field is marked with ^ and the value is undefined,
717 if ((arg & 512) && !SvOK(sv)) {
725 /* Formats aren't yet marked for locales, so assume "yes". */
727 STORE_NUMERIC_STANDARD_SET_LOCAL();
728 #if defined(USE_LONG_DOUBLE)
730 sprintf(t, "%#*.*" PERL_PRIfldbl,
731 (int) fieldsize, (int) arg & 255, value);
733 sprintf(t, "%*.0" PERL_PRIfldbl, (int) fieldsize, value);
738 (int) fieldsize, (int) arg & 255, value);
741 (int) fieldsize, value);
744 RESTORE_NUMERIC_STANDARD();
750 /* If the field is marked with ^ and the value is undefined,
753 if ((arg & 512) && !SvOK(sv)) {
761 /* Formats aren't yet marked for locales, so assume "yes". */
763 STORE_NUMERIC_STANDARD_SET_LOCAL();
764 #if defined(USE_LONG_DOUBLE)
766 sprintf(t, "%#0*.*" PERL_PRIfldbl,
767 (int) fieldsize, (int) arg & 255, value);
768 /* is this legal? I don't have long doubles */
770 sprintf(t, "%0*.0" PERL_PRIfldbl, (int) fieldsize, value);
774 sprintf(t, "%#0*.*f",
775 (int) fieldsize, (int) arg & 255, value);
778 (int) fieldsize, value);
781 RESTORE_NUMERIC_STANDARD();
788 while (t-- > linemark && *t == ' ') ;
796 if (arg) { /* repeat until fields exhausted? */
798 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
799 lines += FmLINES(PL_formtarget);
802 if (strnEQ(linemark, linemark - arg, arg))
803 DIE(aTHX_ "Runaway format");
806 SvUTF8_on(PL_formtarget);
807 FmLINES(PL_formtarget) = lines;
809 RETURNOP(cLISTOP->op_first);
822 while (*s && isSPACE(*s) && s < send)
826 arg = fieldsize - itemsize;
833 if (strnEQ(s," ",3)) {
834 while (s > SvPVX(PL_formtarget) && isSPACE(s[-1]))
845 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
847 SvUTF8_on(PL_formtarget);
848 FmLINES(PL_formtarget) += lines;
860 if (PL_stack_base + *PL_markstack_ptr == SP) {
862 if (GIMME_V == G_SCALAR)
863 XPUSHs(sv_2mortal(newSViv(0)));
864 RETURNOP(PL_op->op_next->op_next);
866 PL_stack_sp = PL_stack_base + *PL_markstack_ptr + 1;
867 pp_pushmark(); /* push dst */
868 pp_pushmark(); /* push src */
869 ENTER; /* enter outer scope */
872 /* SAVE_DEFSV does *not* suffice here for USE_5005THREADS */
874 ENTER; /* enter inner scope */
877 src = PL_stack_base[*PL_markstack_ptr];
882 if (PL_op->op_type == OP_MAPSTART)
883 pp_pushmark(); /* push top */
884 return ((LOGOP*)PL_op->op_next)->op_other;
889 DIE(aTHX_ "panic: mapstart"); /* uses grepstart */
896 I32 items = (SP - PL_stack_base) - *PL_markstack_ptr; /* how many new items */
902 /* first, move source pointer to the next item in the source list */
903 ++PL_markstack_ptr[-1];
905 /* if there are new items, push them into the destination list */
906 if (items && gimme != G_VOID) {
907 /* might need to make room back there first */
908 if (items > PL_markstack_ptr[-1] - PL_markstack_ptr[-2]) {
909 /* XXX this implementation is very pessimal because the stack
910 * is repeatedly extended for every set of items. Is possible
911 * to do this without any stack extension or copying at all
912 * by maintaining a separate list over which the map iterates
913 * (like foreach does). --gsar */
915 /* everything in the stack after the destination list moves
916 * towards the end the stack by the amount of room needed */
917 shift = items - (PL_markstack_ptr[-1] - PL_markstack_ptr[-2]);
919 /* items to shift up (accounting for the moved source pointer) */
920 count = (SP - PL_stack_base) - (PL_markstack_ptr[-1] - 1);
922 /* This optimization is by Ben Tilly and it does
923 * things differently from what Sarathy (gsar)
924 * is describing. The downside of this optimization is
925 * that leaves "holes" (uninitialized and hopefully unused areas)
926 * to the Perl stack, but on the other hand this
927 * shouldn't be a problem. If Sarathy's idea gets
928 * implemented, this optimization should become
929 * irrelevant. --jhi */
931 shift = count; /* Avoid shifting too often --Ben Tilly */
936 PL_markstack_ptr[-1] += shift;
937 *PL_markstack_ptr += shift;
941 /* copy the new items down to the destination list */
942 dst = PL_stack_base + (PL_markstack_ptr[-2] += items) - 1;
944 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
946 LEAVE; /* exit inner scope */
949 if (PL_markstack_ptr[-1] > *PL_markstack_ptr) {
951 (void)POPMARK; /* pop top */
952 LEAVE; /* exit outer scope */
953 (void)POPMARK; /* pop src */
954 items = --*PL_markstack_ptr - PL_markstack_ptr[-1];
955 (void)POPMARK; /* pop dst */
956 SP = PL_stack_base + POPMARK; /* pop original mark */
957 if (gimme == G_SCALAR) {
961 else if (gimme == G_ARRAY)
968 ENTER; /* enter inner scope */
971 /* set $_ to the new source item */
972 src = PL_stack_base[PL_markstack_ptr[-1]];
976 RETURNOP(cLOGOP->op_other);
984 if (GIMME == G_ARRAY)
986 if (SvTRUEx(PAD_SV(PL_op->op_targ)))
987 return cLOGOP->op_other;
996 if (GIMME == G_ARRAY) {
997 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
1001 SV *targ = PAD_SV(PL_op->op_targ);
1004 if (PL_op->op_private & OPpFLIP_LINENUM) {
1005 if (GvIO(PL_last_in_gv)) {
1006 flip = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
1009 GV *gv = gv_fetchpv(".", TRUE, SVt_PV);
1010 if (gv && GvSV(gv)) flip = SvIV(sv) == SvIV(GvSV(gv));
1016 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
1017 if (PL_op->op_flags & OPf_SPECIAL) {
1025 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
1034 /* This code tries to decide if "$left .. $right" should use the
1035 magical string increment, or if the range is numeric (we make
1036 an exception for .."0" [#18165]). AMS 20021031. */
1038 #define RANGE_IS_NUMERIC(left,right) ( \
1039 SvNIOKp(left) || !SvPOKp(left) || \
1040 SvNIOKp(right) || !SvPOKp(right) || \
1041 (looks_like_number(left) && *SvPVX(left) != '0' && \
1042 looks_like_number(right)))
1048 if (GIMME == G_ARRAY) {
1054 if (SvGMAGICAL(left))
1056 if (SvGMAGICAL(right))
1059 if (RANGE_IS_NUMERIC(left,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 if (RANGE_IS_NUMERIC(sv,(SV*)cx->blk_loop.iterary)) {
1775 if (SvNV(sv) < IV_MIN ||
1776 SvNV((SV*)cx->blk_loop.iterary) >= IV_MAX)
1777 DIE(aTHX_ "Range iterator outside integer range");
1778 cx->blk_loop.iterix = SvIV(sv);
1779 cx->blk_loop.itermax = SvIV((SV*)cx->blk_loop.iterary);
1782 cx->blk_loop.iterlval = newSVsv(sv);
1786 cx->blk_loop.iterary = PL_curstack;
1787 AvFILLp(PL_curstack) = SP - PL_stack_base;
1788 cx->blk_loop.iterix = MARK - PL_stack_base;
1797 register PERL_CONTEXT *cx;
1798 I32 gimme = GIMME_V;
1804 PUSHBLOCK(cx, CXt_LOOP, SP);
1805 PUSHLOOP(cx, 0, SP);
1813 register PERL_CONTEXT *cx;
1821 newsp = PL_stack_base + cx->blk_loop.resetsp;
1824 if (gimme == G_VOID)
1826 else if (gimme == G_SCALAR) {
1828 *++newsp = sv_mortalcopy(*SP);
1830 *++newsp = &PL_sv_undef;
1834 *++newsp = sv_mortalcopy(*++mark);
1835 TAINT_NOT; /* Each item is independent */
1841 POPLOOP(cx); /* Stack values are safe: release loop vars ... */
1842 PL_curpm = newpm; /* ... and pop $1 et al */
1854 register PERL_CONTEXT *cx;
1855 bool popsub2 = FALSE;
1856 bool clear_errsv = FALSE;
1863 if (PL_curstackinfo->si_type == PERLSI_SORT) {
1864 if (cxstack_ix == PL_sortcxix
1865 || dopoptosub(cxstack_ix) <= PL_sortcxix)
1867 if (cxstack_ix > PL_sortcxix)
1868 dounwind(PL_sortcxix);
1869 AvARRAY(PL_curstack)[1] = *SP;
1870 PL_stack_sp = PL_stack_base + 1;
1875 cxix = dopoptosub(cxstack_ix);
1877 DIE(aTHX_ "Can't return outside a subroutine");
1878 if (cxix < cxstack_ix)
1882 switch (CxTYPE(cx)) {
1885 cxstack_ix++; /* preserve cx entry on stack for use by POPSUB */
1888 if (!(PL_in_eval & EVAL_KEEPERR))
1894 if (optype == OP_REQUIRE &&
1895 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1897 /* Unassume the success we assumed earlier. */
1898 SV *nsv = cx->blk_eval.old_namesv;
1899 (void)hv_delete(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), G_DISCARD);
1900 DIE(aTHX_ "%"SVf" did not return a true value", nsv);
1907 DIE(aTHX_ "panic: return");
1911 if (gimme == G_SCALAR) {
1914 if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
1916 *++newsp = SvREFCNT_inc(*SP);
1921 sv = SvREFCNT_inc(*SP); /* FREETMPS could clobber it */
1923 *++newsp = sv_mortalcopy(sv);
1928 *++newsp = (SvTEMP(*SP)) ? *SP : sv_mortalcopy(*SP);
1931 *++newsp = sv_mortalcopy(*SP);
1934 *++newsp = &PL_sv_undef;
1936 else if (gimme == G_ARRAY) {
1937 while (++MARK <= SP) {
1938 *++newsp = (popsub2 && SvTEMP(*MARK))
1939 ? *MARK : sv_mortalcopy(*MARK);
1940 TAINT_NOT; /* Each item is independent */
1943 PL_stack_sp = newsp;
1946 /* Stack values are safe: */
1949 POPSUB(cx,sv); /* release CV and @_ ... */
1953 PL_curpm = newpm; /* ... and pop $1 et al */
1958 return pop_return();
1965 register PERL_CONTEXT *cx;
1975 if (PL_op->op_flags & OPf_SPECIAL) {
1976 cxix = dopoptoloop(cxstack_ix);
1978 DIE(aTHX_ "Can't \"last\" outside a loop block");
1981 cxix = dopoptolabel(cPVOP->op_pv);
1983 DIE(aTHX_ "Label not found for \"last %s\"", cPVOP->op_pv);
1985 if (cxix < cxstack_ix)
1989 cxstack_ix++; /* temporarily protect top context */
1991 switch (CxTYPE(cx)) {
1994 newsp = PL_stack_base + cx->blk_loop.resetsp;
1995 nextop = cx->blk_loop.last_op->op_next;
1999 nextop = pop_return();
2003 nextop = pop_return();
2007 nextop = pop_return();
2010 DIE(aTHX_ "panic: last");
2014 if (gimme == G_SCALAR) {
2016 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
2017 ? *SP : sv_mortalcopy(*SP);
2019 *++newsp = &PL_sv_undef;
2021 else if (gimme == G_ARRAY) {
2022 while (++MARK <= SP) {
2023 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
2024 ? *MARK : sv_mortalcopy(*MARK);
2025 TAINT_NOT; /* Each item is independent */
2033 /* Stack values are safe: */
2036 POPLOOP(cx); /* release loop vars ... */
2040 POPSUB(cx,sv); /* release CV and @_ ... */
2043 PL_curpm = newpm; /* ... and pop $1 et al */
2052 register PERL_CONTEXT *cx;
2055 if (PL_op->op_flags & OPf_SPECIAL) {
2056 cxix = dopoptoloop(cxstack_ix);
2058 DIE(aTHX_ "Can't \"next\" outside a loop block");
2061 cxix = dopoptolabel(cPVOP->op_pv);
2063 DIE(aTHX_ "Label not found for \"next %s\"", cPVOP->op_pv);
2065 if (cxix < cxstack_ix)
2068 /* clear off anything above the scope we're re-entering, but
2069 * save the rest until after a possible continue block */
2070 inner = PL_scopestack_ix;
2072 if (PL_scopestack_ix < inner)
2073 leave_scope(PL_scopestack[PL_scopestack_ix]);
2074 return cx->blk_loop.next_op;
2080 register PERL_CONTEXT *cx;
2083 if (PL_op->op_flags & OPf_SPECIAL) {
2084 cxix = dopoptoloop(cxstack_ix);
2086 DIE(aTHX_ "Can't \"redo\" outside a loop block");
2089 cxix = dopoptolabel(cPVOP->op_pv);
2091 DIE(aTHX_ "Label not found for \"redo %s\"", cPVOP->op_pv);
2093 if (cxix < cxstack_ix)
2097 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2098 LEAVE_SCOPE(oldsave);
2099 return cx->blk_loop.redo_op;
2103 S_dofindlabel(pTHX_ OP *o, char *label, OP **opstack, OP **oplimit)
2107 static char too_deep[] = "Target of goto is too deeply nested";
2110 Perl_croak(aTHX_ too_deep);
2111 if (o->op_type == OP_LEAVE ||
2112 o->op_type == OP_SCOPE ||
2113 o->op_type == OP_LEAVELOOP ||
2114 o->op_type == OP_LEAVESUB ||
2115 o->op_type == OP_LEAVETRY)
2117 *ops++ = cUNOPo->op_first;
2119 Perl_croak(aTHX_ too_deep);
2122 if (o->op_flags & OPf_KIDS) {
2123 /* First try all the kids at this level, since that's likeliest. */
2124 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
2125 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
2126 kCOP->cop_label && strEQ(kCOP->cop_label, label))
2129 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
2130 if (kid == PL_lastgotoprobe)
2132 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
2135 else if (ops[-1]->op_type == OP_NEXTSTATE ||
2136 ops[-1]->op_type == OP_DBSTATE)
2141 if ((o = dofindlabel(kid, label, ops, oplimit)))
2160 register PERL_CONTEXT *cx;
2161 #define GOTO_DEPTH 64
2162 OP *enterops[GOTO_DEPTH];
2164 int do_dump = (PL_op->op_type == OP_DUMP);
2165 static char must_have_label[] = "goto must have label";
2168 if (PL_op->op_flags & OPf_STACKED) {
2172 /* This egregious kludge implements goto &subroutine */
2173 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
2175 register PERL_CONTEXT *cx;
2176 CV* cv = (CV*)SvRV(sv);
2182 if (!CvROOT(cv) && !CvXSUB(cv)) {
2187 /* autoloaded stub? */
2188 if (cv != GvCV(gv) && (cv = GvCV(gv)))
2190 autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv),
2191 GvNAMELEN(gv), FALSE);
2192 if (autogv && (cv = GvCV(autogv)))
2194 tmpstr = sv_newmortal();
2195 gv_efullname3(tmpstr, gv, Nullch);
2196 DIE(aTHX_ "Goto undefined subroutine &%"SVf"",tmpstr);
2198 DIE(aTHX_ "Goto undefined subroutine");
2201 /* First do some returnish stuff. */
2202 SvREFCNT_inc(cv); /* avoid premature free during unwind */
2204 cxix = dopoptosub(cxstack_ix);
2206 DIE(aTHX_ "Can't goto subroutine outside a subroutine");
2207 if (cxix < cxstack_ix)
2211 DIE(aTHX_ "Can't goto subroutine from an eval-string");
2213 if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.hasargs) {
2214 /* put @_ back onto stack */
2215 AV* av = cx->blk_sub.argarray;
2217 items = AvFILLp(av) + 1;
2219 EXTEND(PL_stack_sp, items); /* @_ could have been extended. */
2220 Copy(AvARRAY(av), PL_stack_sp, items, SV*);
2221 PL_stack_sp += items;
2222 SvREFCNT_dec(GvAV(PL_defgv));
2223 GvAV(PL_defgv) = cx->blk_sub.savearray;
2224 /* abandon @_ if it got reified */
2226 (void)sv_2mortal((SV*)av); /* delay until return */
2228 av_extend(av, items-1);
2229 AvFLAGS(av) = AVf_REIFY;
2230 PAD_SVl(0) = (SV*)(cx->blk_sub.argarray = av);
2235 else if (CvXSUB(cv)) { /* put GvAV(defgv) back onto stack */
2237 av = GvAV(PL_defgv);
2238 items = AvFILLp(av) + 1;
2240 EXTEND(PL_stack_sp, items); /* @_ could have been extended. */
2241 Copy(AvARRAY(av), PL_stack_sp, items, SV*);
2242 PL_stack_sp += items;
2244 if (CxTYPE(cx) == CXt_SUB &&
2245 !(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
2246 SvREFCNT_dec(cx->blk_sub.cv);
2247 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2248 LEAVE_SCOPE(oldsave);
2250 /* Now do some callish stuff. */
2252 SAVEFREESV(cv); /* later, undo the 'avoid premature free' hack */
2254 #ifdef PERL_XSUB_OLDSTYLE
2255 if (CvOLDSTYLE(cv)) {
2256 I32 (*fp3)(int,int,int);
2261 fp3 = (I32(*)(int,int,int))CvXSUB(cv);
2262 items = (*fp3)(CvXSUBANY(cv).any_i32,
2263 mark - PL_stack_base + 1,
2265 SP = PL_stack_base + items;
2268 #endif /* PERL_XSUB_OLDSTYLE */
2273 PL_stack_sp--; /* There is no cv arg. */
2274 /* Push a mark for the start of arglist */
2276 (void)(*CvXSUB(cv))(aTHX_ cv);
2277 /* Pop the current context like a decent sub should */
2278 POPBLOCK(cx, PL_curpm);
2279 /* Do _not_ use PUTBACK, keep the XSUB's return stack! */
2282 return pop_return();
2285 AV* padlist = CvPADLIST(cv);
2286 if (CxTYPE(cx) == CXt_EVAL) {
2287 PL_in_eval = cx->blk_eval.old_in_eval;
2288 PL_eval_root = cx->blk_eval.old_eval_root;
2289 cx->cx_type = CXt_SUB;
2290 cx->blk_sub.hasargs = 0;
2292 cx->blk_sub.cv = cv;
2293 cx->blk_sub.olddepth = (U16)CvDEPTH(cv);
2296 if (CvDEPTH(cv) < 2)
2297 (void)SvREFCNT_inc(cv);
2299 if (CvDEPTH(cv) == 100 && ckWARN(WARN_RECURSION))
2300 sub_crush_depth(cv);
2301 pad_push(padlist, CvDEPTH(cv), cx->blk_sub.hasargs);
2303 PAD_SET_CUR(padlist, CvDEPTH(cv));
2304 if (cx->blk_sub.hasargs)
2306 AV* av = (AV*)PAD_SVl(0);
2309 cx->blk_sub.savearray = GvAV(PL_defgv);
2310 GvAV(PL_defgv) = (AV*)SvREFCNT_inc(av);
2311 CX_CURPAD_SAVE(cx->blk_sub);
2312 cx->blk_sub.argarray = av;
2315 if (items >= AvMAX(av) + 1) {
2317 if (AvARRAY(av) != ary) {
2318 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
2319 SvPVX(av) = (char*)ary;
2321 if (items >= AvMAX(av) + 1) {
2322 AvMAX(av) = items - 1;
2323 Renew(ary,items+1,SV*);
2325 SvPVX(av) = (char*)ary;
2328 Copy(mark,AvARRAY(av),items,SV*);
2329 AvFILLp(av) = items - 1;
2330 assert(!AvREAL(av));
2337 if (PERLDB_SUB) { /* Checking curstash breaks DProf. */
2339 * We do not care about using sv to call CV;
2340 * it's for informational purposes only.
2342 SV *sv = GvSV(PL_DBsub);
2345 if (PERLDB_SUB_NN) {
2346 (void)SvUPGRADE(sv, SVt_PVIV);
2349 SvIVX(sv) = PTR2IV(cv); /* Do it the quickest way */
2352 gv_efullname3(sv, CvGV(cv), Nullch);
2355 && (gotocv = get_cv("DB::goto", FALSE)) ) {
2356 PUSHMARK( PL_stack_sp );
2357 call_sv((SV*)gotocv, G_SCALAR | G_NODEBUG);
2361 RETURNOP(CvSTART(cv));
2365 label = SvPV(sv,n_a);
2366 if (!(do_dump || *label))
2367 DIE(aTHX_ must_have_label);
2370 else if (PL_op->op_flags & OPf_SPECIAL) {
2372 DIE(aTHX_ must_have_label);
2375 label = cPVOP->op_pv;
2377 if (label && *label) {
2379 bool leaving_eval = FALSE;
2380 bool in_block = FALSE;
2381 PERL_CONTEXT *last_eval_cx = 0;
2385 PL_lastgotoprobe = 0;
2387 for (ix = cxstack_ix; ix >= 0; ix--) {
2389 switch (CxTYPE(cx)) {
2391 leaving_eval = TRUE;
2392 if (!CxTRYBLOCK(cx)) {
2393 gotoprobe = (last_eval_cx ?
2394 last_eval_cx->blk_eval.old_eval_root :
2399 /* else fall through */
2401 gotoprobe = cx->blk_oldcop->op_sibling;
2407 gotoprobe = cx->blk_oldcop->op_sibling;
2410 gotoprobe = PL_main_root;
2413 if (CvDEPTH(cx->blk_sub.cv)) {
2414 gotoprobe = CvROOT(cx->blk_sub.cv);
2420 DIE(aTHX_ "Can't \"goto\" out of a pseudo block");
2423 DIE(aTHX_ "panic: goto");
2424 gotoprobe = PL_main_root;
2428 retop = dofindlabel(gotoprobe, label,
2429 enterops, enterops + GOTO_DEPTH);
2433 PL_lastgotoprobe = gotoprobe;
2436 DIE(aTHX_ "Can't find label %s", label);
2438 /* if we're leaving an eval, check before we pop any frames
2439 that we're not going to punt, otherwise the error
2442 if (leaving_eval && *enterops && enterops[1]) {
2444 for (i = 1; enterops[i]; i++)
2445 if (enterops[i]->op_type == OP_ENTERITER)
2446 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2449 /* pop unwanted frames */
2451 if (ix < cxstack_ix) {
2458 oldsave = PL_scopestack[PL_scopestack_ix];
2459 LEAVE_SCOPE(oldsave);
2462 /* push wanted frames */
2464 if (*enterops && enterops[1]) {
2466 ix = enterops[1]->op_type == OP_ENTER && in_block ? 2 : 1;
2467 for (; enterops[ix]; ix++) {
2468 PL_op = enterops[ix];
2469 /* Eventually we may want to stack the needed arguments
2470 * for each op. For now, we punt on the hard ones. */
2471 if (PL_op->op_type == OP_ENTERITER)
2472 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2473 CALL_FPTR(PL_op->op_ppaddr)(aTHX);
2481 if (!retop) retop = PL_main_start;
2483 PL_restartop = retop;
2484 PL_do_undump = TRUE;
2488 PL_restartop = 0; /* hmm, must be GNU unexec().. */
2489 PL_do_undump = FALSE;
2505 if (anum == 1 && (PL_op->op_private & OPpEXIT_VMSISH))
2507 VMSISH_HUSHED = VMSISH_HUSHED || (PL_op->op_private & OPpHUSH_VMSISH);
2510 PL_exit_flags |= PERL_EXIT_EXPECTED;
2512 PUSHs(&PL_sv_undef);
2520 NV value = SvNVx(GvSV(cCOP->cop_gv));
2521 register I32 match = I_32(value);
2524 if (((NV)match) > value)
2525 --match; /* was fractional--truncate other way */
2527 match -= cCOP->uop.scop.scop_offset;
2530 else if (match > cCOP->uop.scop.scop_max)
2531 match = cCOP->uop.scop.scop_max;
2532 PL_op = cCOP->uop.scop.scop_next[match];
2542 PL_op = PL_op->op_next; /* can't assume anything */
2545 match = *(SvPVx(GvSV(cCOP->cop_gv), n_a)) & 255;
2546 match -= cCOP->uop.scop.scop_offset;
2549 else if (match > cCOP->uop.scop.scop_max)
2550 match = cCOP->uop.scop.scop_max;
2551 PL_op = cCOP->uop.scop.scop_next[match];
2560 S_save_lines(pTHX_ AV *array, SV *sv)
2562 register char *s = SvPVX(sv);
2563 register char *send = SvPVX(sv) + SvCUR(sv);
2565 register I32 line = 1;
2567 while (s && s < send) {
2568 SV *tmpstr = NEWSV(85,0);
2570 sv_upgrade(tmpstr, SVt_PVMG);
2571 t = strchr(s, '\n');
2577 sv_setpvn(tmpstr, s, t - s);
2578 av_store(array, line++, tmpstr);
2583 #ifdef PERL_FLEXIBLE_EXCEPTIONS
2585 S_docatch_body(pTHX_ va_list args)
2587 return docatch_body();
2592 S_docatch_body(pTHX)
2599 S_docatch(pTHX_ OP *o)
2604 volatile PERL_SI *cursi = PL_curstackinfo;
2608 assert(CATCH_GET == TRUE);
2612 /* Normally, the leavetry at the end of this block of ops will
2613 * pop an op off the return stack and continue there. By setting
2614 * the op to Nullop, we force an exit from the inner runops()
2617 retop = pop_return();
2618 push_return(Nullop);
2620 #ifdef PERL_FLEXIBLE_EXCEPTIONS
2622 CALLPROTECT(aTHX_ pcur_env, &ret, MEMBER_TO_FPTR(S_docatch_body));
2628 #ifndef PERL_FLEXIBLE_EXCEPTIONS
2634 /* die caught by an inner eval - continue inner loop */
2635 if (PL_restartop && cursi == PL_curstackinfo) {
2636 PL_op = PL_restartop;
2640 /* a die in this eval - continue in outer loop */
2656 Perl_sv_compile_2op(pTHX_ SV *sv, OP** startop, char *code, PAD** padp)
2657 /* sv Text to convert to OP tree. */
2658 /* startop op_free() this to undo. */
2659 /* code Short string id of the caller. */
2661 dSP; /* Make POPBLOCK work. */
2664 I32 gimme = 0; /* SUSPECT - INITIALZE TO WHAT? NI-S */
2668 char tbuf[TYPE_DIGITS(long) + 12 + 10];
2669 char *tmpbuf = tbuf;
2672 CV* runcv = Nullcv; /* initialise to avoid compiler warnings */
2677 /* switch to eval mode */
2679 if (IN_PERL_COMPILETIME) {
2680 SAVECOPSTASH_FREE(&PL_compiling);
2681 CopSTASH_set(&PL_compiling, PL_curstash);
2683 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
2684 SV *sv = sv_newmortal();
2685 Perl_sv_setpvf(aTHX_ sv, "_<(%.10seval %lu)[%s:%"IVdf"]",
2686 code, (unsigned long)++PL_evalseq,
2687 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
2691 sprintf(tmpbuf, "_<(%.10s_eval %lu)", code, (unsigned long)++PL_evalseq);
2692 SAVECOPFILE_FREE(&PL_compiling);
2693 CopFILE_set(&PL_compiling, tmpbuf+2);
2694 SAVECOPLINE(&PL_compiling);
2695 CopLINE_set(&PL_compiling, 1);
2696 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2697 deleting the eval's FILEGV from the stash before gv_check() runs
2698 (i.e. before run-time proper). To work around the coredump that
2699 ensues, we always turn GvMULTI_on for any globals that were
2700 introduced within evals. See force_ident(). GSAR 96-10-12 */
2701 safestr = savepv(tmpbuf);
2702 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
2704 #ifdef OP_IN_REGISTER
2709 PL_hints &= HINT_UTF8;
2711 /* we get here either during compilation, or via pp_regcomp at runtime */
2712 runtime = IN_PERL_RUNTIME;
2714 runcv = find_runcv(NULL);
2717 PL_op->op_type = OP_ENTEREVAL;
2718 PL_op->op_flags = 0; /* Avoid uninit warning. */
2719 PUSHBLOCK(cx, CXt_EVAL|(IN_PERL_COMPILETIME ? 0 : CXp_REAL), SP);
2720 PUSHEVAL(cx, 0, Nullgv);
2723 rop = doeval(G_SCALAR, startop, runcv, PL_curcop->cop_seq);
2725 rop = doeval(G_SCALAR, startop, PL_compcv, PL_cop_seqmax);
2726 POPBLOCK(cx,PL_curpm);
2729 (*startop)->op_type = OP_NULL;
2730 (*startop)->op_ppaddr = PL_ppaddr[OP_NULL];
2732 /* XXX DAPM do this properly one year */
2733 *padp = (AV*)SvREFCNT_inc(PL_comppad);
2735 if (IN_PERL_COMPILETIME)
2736 PL_compiling.op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);
2737 #ifdef OP_IN_REGISTER
2745 =for apidoc find_runcv
2747 Locate the CV corresponding to the currently executing sub or eval.
2748 If db_seqp is non_null, skip CVs that are in the DB package and populate
2749 *db_seqp with the cop sequence number at the point that the DB:: code was
2750 entered. (allows debuggers to eval in the scope of the breakpoint rather
2751 than in in the scope of the debuger itself).
2757 Perl_find_runcv(pTHX_ U32 *db_seqp)
2764 *db_seqp = PL_curcop->cop_seq;
2765 for (si = PL_curstackinfo; si; si = si->si_prev) {
2766 for (ix = si->si_cxix; ix >= 0; ix--) {
2767 cx = &(si->si_cxstack[ix]);
2768 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
2769 CV *cv = cx->blk_sub.cv;
2770 /* skip DB:: code */
2771 if (db_seqp && PL_debstash && CvSTASH(cv) == PL_debstash) {
2772 *db_seqp = cx->blk_oldcop->cop_seq;
2777 else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx))
2785 /* Compile a require/do, an eval '', or a /(?{...})/.
2786 * In the last case, startop is non-null, and contains the address of
2787 * a pointer that should be set to the just-compiled code.
2788 * outside is the lexically enclosing CV (if any) that invoked us.
2791 /* With USE_5005THREADS, eval_owner must be held on entry to doeval */
2793 S_doeval(pTHX_ int gimme, OP** startop, CV* outside, U32 seq)
2798 PL_in_eval = ((saveop && saveop->op_type == OP_REQUIRE)
2799 ? (EVAL_INREQUIRE | (PL_in_eval & EVAL_INEVAL))
2804 SAVESPTR(PL_compcv);
2805 PL_compcv = (CV*)NEWSV(1104,0);
2806 sv_upgrade((SV *)PL_compcv, SVt_PVCV);
2807 CvEVAL_on(PL_compcv);
2808 assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
2809 cxstack[cxstack_ix].blk_eval.cv = PL_compcv;
2811 CvOUTSIDE_SEQ(PL_compcv) = seq;
2812 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outside);
2814 /* set up a scratch pad */
2816 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE);
2819 SAVEMORTALIZESV(PL_compcv); /* must remain until end of current statement */
2821 /* make sure we compile in the right package */
2823 if (CopSTASH_ne(PL_curcop, PL_curstash)) {
2824 SAVESPTR(PL_curstash);
2825 PL_curstash = CopSTASH(PL_curcop);
2827 SAVESPTR(PL_beginav);
2828 PL_beginav = newAV();
2829 SAVEFREESV(PL_beginav);
2830 SAVEI32(PL_error_count);
2832 /* try to compile it */
2834 PL_eval_root = Nullop;
2836 PL_curcop = &PL_compiling;
2837 PL_curcop->cop_arybase = 0;
2838 if (saveop && saveop->op_flags & OPf_SPECIAL)
2839 PL_in_eval |= EVAL_KEEPERR;
2842 if (yyparse() || PL_error_count || !PL_eval_root) {
2843 SV **newsp; /* Used by POPBLOCK. */
2844 PERL_CONTEXT *cx = &cxstack[cxstack_ix];
2845 I32 optype = 0; /* Might be reset by POPEVAL. */
2850 op_free(PL_eval_root);
2851 PL_eval_root = Nullop;
2853 SP = PL_stack_base + POPMARK; /* pop original mark */
2855 POPBLOCK(cx,PL_curpm);
2861 if (optype == OP_REQUIRE) {
2862 char* msg = SvPVx(ERRSV, n_a);
2863 SV *nsv = cx->blk_eval.old_namesv;
2864 (void)hv_store(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv),
2866 DIE(aTHX_ "%sCompilation failed in require",
2867 *msg ? msg : "Unknown error\n");
2870 char* msg = SvPVx(ERRSV, n_a);
2872 POPBLOCK(cx,PL_curpm);
2874 Perl_croak(aTHX_ "%sCompilation failed in regexp",
2875 (*msg ? msg : "Unknown error\n"));
2878 char* msg = SvPVx(ERRSV, n_a);
2880 sv_setpv(ERRSV, "Compilation error");
2885 CopLINE_set(&PL_compiling, 0);
2887 *startop = PL_eval_root;
2889 SAVEFREEOP(PL_eval_root);
2891 /* Set the context for this new optree.
2892 * If the last op is an OP_REQUIRE, force scalar context.
2893 * Otherwise, propagate the context from the eval(). */
2894 if (PL_eval_root->op_type == OP_LEAVEEVAL
2895 && cUNOPx(PL_eval_root)->op_first->op_type == OP_LINESEQ
2896 && cLISTOPx(cUNOPx(PL_eval_root)->op_first)->op_last->op_type
2898 scalar(PL_eval_root);
2899 else if (gimme & G_VOID)
2900 scalarvoid(PL_eval_root);
2901 else if (gimme & G_ARRAY)
2904 scalar(PL_eval_root);
2906 DEBUG_x(dump_eval());
2908 /* Register with debugger: */
2909 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2910 CV *cv = get_cv("DB::postponed", FALSE);
2914 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2916 call_sv((SV*)cv, G_DISCARD);
2920 /* compiled okay, so do it */
2922 CvDEPTH(PL_compcv) = 1;
2923 SP = PL_stack_base + POPMARK; /* pop original mark */
2924 PL_op = saveop; /* The caller may need it. */
2925 PL_lex_state = LEX_NOTPARSING; /* $^S needs this. */
2927 RETURNOP(PL_eval_start);
2931 S_doopen_pm(pTHX_ const char *name, const char *mode)
2933 #ifndef PERL_DISABLE_PMC
2934 STRLEN namelen = strlen(name);
2937 if (namelen > 3 && strEQ(name + namelen - 3, ".pm")) {
2938 SV *pmcsv = Perl_newSVpvf(aTHX_ "%s%c", name, 'c');
2939 char *pmc = SvPV_nolen(pmcsv);
2942 if (PerlLIO_stat(pmc, &pmcstat) < 0) {
2943 fp = PerlIO_open(name, mode);
2946 if (PerlLIO_stat(name, &pmstat) < 0 ||
2947 pmstat.st_mtime < pmcstat.st_mtime)
2949 fp = PerlIO_open(pmc, mode);
2952 fp = PerlIO_open(name, mode);
2955 SvREFCNT_dec(pmcsv);
2958 fp = PerlIO_open(name, mode);
2962 return PerlIO_open(name, mode);
2963 #endif /* !PERL_DISABLE_PMC */
2969 register PERL_CONTEXT *cx;
2973 char *tryname = Nullch;
2974 SV *namesv = Nullsv;
2976 I32 gimme = GIMME_V;
2977 PerlIO *tryrsfp = 0;
2979 int filter_has_file = 0;
2980 GV *filter_child_proc = 0;
2981 SV *filter_state = 0;
2988 if (SvNIOKp(sv) && PL_op->op_type != OP_DOFILE) {
2989 if (SvPOK(sv) && SvNOK(sv) && SvNV(sv)) { /* require v5.6.1 */
2990 UV rev = 0, ver = 0, sver = 0;
2992 U8 *s = (U8*)SvPVX(sv);
2993 U8 *end = (U8*)SvPVX(sv) + SvCUR(sv);
2995 rev = utf8n_to_uvchr(s, end - s, &len, 0);
2998 ver = utf8n_to_uvchr(s, end - s, &len, 0);
3001 sver = utf8n_to_uvchr(s, end - s, &len, 0);
3004 if (PERL_REVISION < rev
3005 || (PERL_REVISION == rev
3006 && (PERL_VERSION < ver
3007 || (PERL_VERSION == ver
3008 && PERL_SUBVERSION < sver))))
3010 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--this is only "
3011 "v%d.%d.%d, stopped", rev, ver, sver, PERL_REVISION,
3012 PERL_VERSION, PERL_SUBVERSION);
3014 if (ckWARN(WARN_PORTABLE))
3015 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
3016 "v-string in use/require non-portable");
3019 else if (!SvPOKp(sv)) { /* require 5.005_03 */
3020 if ((NV)PERL_REVISION + ((NV)PERL_VERSION/(NV)1000)
3021 + ((NV)PERL_SUBVERSION/(NV)1000000)
3022 + 0.00000099 < SvNV(sv))
3026 NV nver = (nrev - rev) * 1000;
3027 UV ver = (UV)(nver + 0.0009);
3028 NV nsver = (nver - ver) * 1000;
3029 UV sver = (UV)(nsver + 0.0009);
3031 /* help out with the "use 5.6" confusion */
3032 if (sver == 0 && (rev > 5 || (rev == 5 && ver >= 100))) {
3033 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required"
3034 " (did you mean v%"UVuf".%03"UVuf"?)--"
3035 "this is only v%d.%d.%d, stopped",
3036 rev, ver, sver, rev, ver/100,
3037 PERL_REVISION, PERL_VERSION, PERL_SUBVERSION);
3040 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--"
3041 "this is only v%d.%d.%d, stopped",
3042 rev, ver, sver, PERL_REVISION, PERL_VERSION,
3049 name = SvPV(sv, len);
3050 if (!(name && len > 0 && *name))
3051 DIE(aTHX_ "Null filename used");
3052 TAINT_PROPER("require");
3053 if (PL_op->op_type == OP_REQUIRE &&
3054 (svp = hv_fetch(GvHVn(PL_incgv), name, len, 0))) {
3055 if (*svp != &PL_sv_undef)
3058 DIE(aTHX_ "Compilation failed in require");
3061 /* prepare to compile file */
3063 if (path_is_absolute(name)) {
3065 tryrsfp = doopen_pm(name,PERL_SCRIPT_MODE);
3067 #ifdef MACOS_TRADITIONAL
3071 MacPerl_CanonDir(name, newname, 1);
3072 if (path_is_absolute(newname)) {
3074 tryrsfp = doopen_pm(newname,PERL_SCRIPT_MODE);
3079 AV *ar = GvAVn(PL_incgv);
3083 if ((unixname = tounixspec(name, Nullch)) != Nullch)
3086 namesv = NEWSV(806, 0);
3087 for (i = 0; i <= AvFILL(ar); i++) {
3088 SV *dirsv = *av_fetch(ar, i, TRUE);
3094 if (SvTYPE(SvRV(loader)) == SVt_PVAV
3095 && !sv_isobject(loader))
3097 loader = *av_fetch((AV *)SvRV(loader), 0, TRUE);
3100 Perl_sv_setpvf(aTHX_ namesv, "/loader/0x%"UVxf"/%s",
3101 PTR2UV(SvRV(dirsv)), name);
3102 tryname = SvPVX(namesv);
3113 if (sv_isobject(loader))
3114 count = call_method("INC", G_ARRAY);
3116 count = call_sv(loader, G_ARRAY);
3126 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVGV) {
3130 if (SvTYPE(arg) == SVt_PVGV) {
3131 IO *io = GvIO((GV *)arg);
3136 tryrsfp = IoIFP(io);
3137 if (IoTYPE(io) == IoTYPE_PIPE) {
3138 /* reading from a child process doesn't
3139 nest -- when returning from reading
3140 the inner module, the outer one is
3141 unreadable (closed?) I've tried to
3142 save the gv to manage the lifespan of
3143 the pipe, but this didn't help. XXX */
3144 filter_child_proc = (GV *)arg;
3145 (void)SvREFCNT_inc(filter_child_proc);
3148 if (IoOFP(io) && IoOFP(io) != IoIFP(io)) {
3149 PerlIO_close(IoOFP(io));
3161 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVCV) {
3163 (void)SvREFCNT_inc(filter_sub);
3166 filter_state = SP[i];
3167 (void)SvREFCNT_inc(filter_state);
3171 tryrsfp = PerlIO_open("/dev/null",
3187 filter_has_file = 0;
3188 if (filter_child_proc) {
3189 SvREFCNT_dec(filter_child_proc);
3190 filter_child_proc = 0;
3193 SvREFCNT_dec(filter_state);
3197 SvREFCNT_dec(filter_sub);
3202 if (!path_is_absolute(name)
3203 #ifdef MACOS_TRADITIONAL
3204 /* We consider paths of the form :a:b ambiguous and interpret them first
3205 as global then as local
3207 || (*name == ':' && name[1] != ':' && strchr(name+2, ':'))
3210 char *dir = SvPVx(dirsv, n_a);
3211 #ifdef MACOS_TRADITIONAL
3215 MacPerl_CanonDir(name, buf2, 1);
3216 Perl_sv_setpvf(aTHX_ namesv, "%s%s", MacPerl_CanonDir(dir, buf1, 0), buf2+(buf2[0] == ':'));
3220 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
3222 sv_setpv(namesv, unixdir);
3223 sv_catpv(namesv, unixname);
3225 Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name);
3228 TAINT_PROPER("require");
3229 tryname = SvPVX(namesv);
3230 tryrsfp = doopen_pm(tryname, PERL_SCRIPT_MODE);
3232 if (tryname[0] == '.' && tryname[1] == '/')
3241 SAVECOPFILE_FREE(&PL_compiling);
3242 CopFILE_set(&PL_compiling, tryrsfp ? tryname : name);
3243 SvREFCNT_dec(namesv);
3245 if (PL_op->op_type == OP_REQUIRE) {
3246 char *msgstr = name;
3247 if (namesv) { /* did we lookup @INC? */
3248 SV *msg = sv_2mortal(newSVpv(msgstr,0));
3249 SV *dirmsgsv = NEWSV(0, 0);
3250 AV *ar = GvAVn(PL_incgv);
3252 sv_catpvn(msg, " in @INC", 8);
3253 if (instr(SvPVX(msg), ".h "))
3254 sv_catpv(msg, " (change .h to .ph maybe?)");
3255 if (instr(SvPVX(msg), ".ph "))
3256 sv_catpv(msg, " (did you run h2ph?)");
3257 sv_catpv(msg, " (@INC contains:");
3258 for (i = 0; i <= AvFILL(ar); i++) {
3259 char *dir = SvPVx(*av_fetch(ar, i, TRUE), n_a);
3260 Perl_sv_setpvf(aTHX_ dirmsgsv, " %s", dir);
3261 sv_catsv(msg, dirmsgsv);
3263 sv_catpvn(msg, ")", 1);
3264 SvREFCNT_dec(dirmsgsv);
3265 msgstr = SvPV_nolen(msg);
3267 DIE(aTHX_ "Can't locate %s", msgstr);
3273 SETERRNO(0, SS_NORMAL);
3275 /* Assume success here to prevent recursive requirement. */
3277 /* Check whether a hook in @INC has already filled %INC */
3278 if (!hook_sv || !(svp = hv_fetch(GvHVn(PL_incgv), name, len, 0))) {
3279 (void)hv_store(GvHVn(PL_incgv), name, len,
3280 (hook_sv ? SvREFCNT_inc(hook_sv)
3281 : newSVpv(CopFILE(&PL_compiling), 0)),
3287 lex_start(sv_2mortal(newSVpvn("",0)));
3288 SAVEGENERICSV(PL_rsfp_filters);
3289 PL_rsfp_filters = Nullav;
3294 SAVESPTR(PL_compiling.cop_warnings);
3295 if (PL_dowarn & G_WARN_ALL_ON)
3296 PL_compiling.cop_warnings = pWARN_ALL ;
3297 else if (PL_dowarn & G_WARN_ALL_OFF)
3298 PL_compiling.cop_warnings = pWARN_NONE ;
3299 else if (PL_taint_warn)
3300 PL_compiling.cop_warnings = newSVpvn(WARN_TAINTstring, WARNsize);
3302 PL_compiling.cop_warnings = pWARN_STD ;
3303 SAVESPTR(PL_compiling.cop_io);
3304 PL_compiling.cop_io = Nullsv;
3306 if (filter_sub || filter_child_proc) {
3307 SV *datasv = filter_add(run_user_filter, Nullsv);
3308 IoLINES(datasv) = filter_has_file;
3309 IoFMT_GV(datasv) = (GV *)filter_child_proc;
3310 IoTOP_GV(datasv) = (GV *)filter_state;
3311 IoBOTTOM_GV(datasv) = (GV *)filter_sub;
3314 /* switch to eval mode */
3315 push_return(PL_op->op_next);
3316 PUSHBLOCK(cx, CXt_EVAL, SP);
3317 PUSHEVAL(cx, name, Nullgv);
3319 SAVECOPLINE(&PL_compiling);
3320 CopLINE_set(&PL_compiling, 0);
3324 /* Store and reset encoding. */
3325 encoding = PL_encoding;
3326 PL_encoding = Nullsv;
3328 op = DOCATCH(doeval(gimme, NULL, Nullcv, PL_curcop->cop_seq));
3330 /* Restore encoding. */
3331 PL_encoding = encoding;
3338 return pp_require();
3344 register PERL_CONTEXT *cx;
3346 I32 gimme = GIMME_V, was = PL_sub_generation;
3347 char tbuf[TYPE_DIGITS(long) + 12];
3348 char *tmpbuf = tbuf;
3357 TAINT_PROPER("eval");
3363 /* switch to eval mode */
3365 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
3366 SV *sv = sv_newmortal();
3367 Perl_sv_setpvf(aTHX_ sv, "_<(eval %lu)[%s:%"IVdf"]",
3368 (unsigned long)++PL_evalseq,
3369 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
3373 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++PL_evalseq);
3374 SAVECOPFILE_FREE(&PL_compiling);
3375 CopFILE_set(&PL_compiling, tmpbuf+2);
3376 SAVECOPLINE(&PL_compiling);
3377 CopLINE_set(&PL_compiling, 1);
3378 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
3379 deleting the eval's FILEGV from the stash before gv_check() runs
3380 (i.e. before run-time proper). To work around the coredump that
3381 ensues, we always turn GvMULTI_on for any globals that were
3382 introduced within evals. See force_ident(). GSAR 96-10-12 */
3383 safestr = savepv(tmpbuf);
3384 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
3386 PL_hints = PL_op->op_targ;
3387 SAVESPTR(PL_compiling.cop_warnings);
3388 if (specialWARN(PL_curcop->cop_warnings))
3389 PL_compiling.cop_warnings = PL_curcop->cop_warnings;
3391 PL_compiling.cop_warnings = newSVsv(PL_curcop->cop_warnings);
3392 SAVEFREESV(PL_compiling.cop_warnings);
3394 SAVESPTR(PL_compiling.cop_io);
3395 if (specialCopIO(PL_curcop->cop_io))
3396 PL_compiling.cop_io = PL_curcop->cop_io;
3398 PL_compiling.cop_io = newSVsv(PL_curcop->cop_io);
3399 SAVEFREESV(PL_compiling.cop_io);
3401 /* special case: an eval '' executed within the DB package gets lexically
3402 * placed in the first non-DB CV rather than the current CV - this
3403 * allows the debugger to execute code, find lexicals etc, in the
3404 * scope of the code being debugged. Passing &seq gets find_runcv
3405 * to do the dirty work for us */
3406 runcv = find_runcv(&seq);
3408 push_return(PL_op->op_next);
3409 PUSHBLOCK(cx, (CXt_EVAL|CXp_REAL), SP);
3410 PUSHEVAL(cx, 0, Nullgv);
3412 /* prepare to compile string */
3414 if (PERLDB_LINE && PL_curstash != PL_debstash)
3415 save_lines(CopFILEAV(&PL_compiling), PL_linestr);
3417 ret = doeval(gimme, NULL, runcv, seq);
3418 if (PERLDB_INTER && was != (I32)PL_sub_generation /* Some subs defined here. */
3419 && ret != PL_op->op_next) { /* Successive compilation. */
3420 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
3422 return DOCATCH(ret);
3432 register PERL_CONTEXT *cx;
3434 U8 save_flags = PL_op -> op_flags;
3439 retop = pop_return();
3442 if (gimme == G_VOID)
3444 else if (gimme == G_SCALAR) {
3447 if (SvFLAGS(TOPs) & SVs_TEMP)
3450 *MARK = sv_mortalcopy(TOPs);
3454 *MARK = &PL_sv_undef;
3459 /* in case LEAVE wipes old return values */
3460 for (mark = newsp + 1; mark <= SP; mark++) {
3461 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
3462 *mark = sv_mortalcopy(*mark);
3463 TAINT_NOT; /* Each item is independent */
3467 PL_curpm = newpm; /* Don't pop $1 et al till now */
3470 assert(CvDEPTH(PL_compcv) == 1);
3472 CvDEPTH(PL_compcv) = 0;
3475 if (optype == OP_REQUIRE &&
3476 !(gimme == G_SCALAR ? SvTRUE(*SP) : SP > newsp))
3478 /* Unassume the success we assumed earlier. */
3479 SV *nsv = cx->blk_eval.old_namesv;
3480 (void)hv_delete(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), G_DISCARD);
3481 retop = Perl_die(aTHX_ "%"SVf" did not return a true value", nsv);
3482 /* die_where() did LEAVE, or we won't be here */
3486 if (!(save_flags & OPf_SPECIAL))
3496 register PERL_CONTEXT *cx;
3497 I32 gimme = GIMME_V;
3502 push_return(cLOGOP->op_other->op_next);
3503 PUSHBLOCK(cx, (CXt_EVAL|CXp_TRYBLOCK), SP);
3506 PL_in_eval = EVAL_INEVAL;
3509 return DOCATCH(PL_op->op_next);
3520 register PERL_CONTEXT *cx;
3525 retop = pop_return();
3528 if (gimme == G_VOID)
3530 else if (gimme == G_SCALAR) {
3533 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
3536 *MARK = sv_mortalcopy(TOPs);
3540 *MARK = &PL_sv_undef;
3545 /* in case LEAVE wipes old return values */
3546 for (mark = newsp + 1; mark <= SP; mark++) {
3547 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
3548 *mark = sv_mortalcopy(*mark);
3549 TAINT_NOT; /* Each item is independent */
3553 PL_curpm = newpm; /* Don't pop $1 et al till now */
3561 S_doparseform(pTHX_ SV *sv)
3564 register char *s = SvPV_force(sv, len);
3565 register char *send = s + len;
3566 register char *base = Nullch;
3567 register I32 skipspaces = 0;
3568 bool noblank = FALSE;
3569 bool repeat = FALSE;
3570 bool postspace = FALSE;
3576 int maxops = 2; /* FF_LINEMARK + FF_END) */
3579 Perl_croak(aTHX_ "Null picture in formline");
3581 /* estimate the buffer size needed */
3582 for (base = s; s <= send; s++) {
3583 if (*s == '\n' || *s == '@' || *s == '^')
3589 New(804, fops, maxops, U32);
3594 *fpc++ = FF_LINEMARK;
3595 noblank = repeat = FALSE;
3613 case ' ': case '\t':
3624 *fpc++ = FF_LITERAL;
3632 *fpc++ = (U16)skipspaces;
3636 *fpc++ = FF_NEWLINE;
3640 arg = fpc - linepc + 1;
3647 *fpc++ = FF_LINEMARK;
3648 noblank = repeat = FALSE;
3657 ischop = s[-1] == '^';
3663 arg = (s - base) - 1;
3665 *fpc++ = FF_LITERAL;
3674 *fpc++ = FF_LINEGLOB;
3676 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
3677 arg = ischop ? 512 : 0;
3687 arg |= 256 + (s - f);
3689 *fpc++ = s - base; /* fieldsize for FETCH */
3690 *fpc++ = FF_DECIMAL;
3693 else if (*s == '0' && s[1] == '#') { /* Zero padded decimals */
3694 arg = ischop ? 512 : 0;
3696 s++; /* skip the '0' first */
3705 arg |= 256 + (s - f);
3707 *fpc++ = s - base; /* fieldsize for FETCH */
3708 *fpc++ = FF_0DECIMAL;
3713 bool ismore = FALSE;
3716 while (*++s == '>') ;
3717 prespace = FF_SPACE;
3719 else if (*s == '|') {
3720 while (*++s == '|') ;
3721 prespace = FF_HALFSPACE;
3726 while (*++s == '<') ;
3729 if (*s == '.' && s[1] == '.' && s[2] == '.') {
3733 *fpc++ = s - base; /* fieldsize for FETCH */
3735 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
3738 *fpc++ = (U16)prespace;
3752 assert (fpc <= fops + maxops); /* ensure our buffer estimate was valid */
3754 { /* need to jump to the next word */
3756 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
3757 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U32) + 4);
3758 s = SvPVX(sv) + SvCUR(sv) + z;
3760 Copy(fops, s, arg, U32);
3762 sv_magic(sv, Nullsv, PERL_MAGIC_fm, Nullch, 0);
3767 run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen)
3769 SV *datasv = FILTER_DATA(idx);
3770 int filter_has_file = IoLINES(datasv);
3771 GV *filter_child_proc = (GV *)IoFMT_GV(datasv);
3772 SV *filter_state = (SV *)IoTOP_GV(datasv);
3773 SV *filter_sub = (SV *)IoBOTTOM_GV(datasv);
3776 /* I was having segfault trouble under Linux 2.2.5 after a
3777 parse error occured. (Had to hack around it with a test
3778 for PL_error_count == 0.) Solaris doesn't segfault --
3779 not sure where the trouble is yet. XXX */
3781 if (filter_has_file) {
3782 len = FILTER_READ(idx+1, buf_sv, maxlen);
3785 if (filter_sub && len >= 0) {
3796 PUSHs(sv_2mortal(newSViv(maxlen)));
3798 PUSHs(filter_state);
3801 count = call_sv(filter_sub, G_SCALAR);
3817 IoLINES(datasv) = 0;
3818 if (filter_child_proc) {
3819 SvREFCNT_dec(filter_child_proc);
3820 IoFMT_GV(datasv) = Nullgv;
3823 SvREFCNT_dec(filter_state);
3824 IoTOP_GV(datasv) = Nullgv;
3827 SvREFCNT_dec(filter_sub);
3828 IoBOTTOM_GV(datasv) = Nullgv;
3830 filter_del(run_user_filter);
3836 /* perhaps someone can come up with a better name for
3837 this? it is not really "absolute", per se ... */
3839 S_path_is_absolute(pTHX_ char *name)
3841 if (PERL_FILE_IS_ABSOLUTE(name)
3842 #ifdef MACOS_TRADITIONAL
3845 || (*name == '.' && (name[1] == '/' ||
3846 (name[1] == '.' && name[2] == '/'))))