3 * Copyright (c) 1991-2003, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * Now far ahead the Road has gone,
12 * And I must follow, if I can,
13 * Pursuing it with eager feet,
14 * Until it joins some larger way
15 * Where many paths and errands meet.
16 * And whither then? I cannot say.
20 #define PERL_IN_PP_CTL_C
24 #define WORD_ALIGN sizeof(U16)
27 #define DOCATCH(o) ((CATCH_GET == TRUE) ? docatch(o) : (o))
29 static I32 run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen);
37 cxix = dopoptosub(cxstack_ix);
41 switch (cxstack[cxix].blk_gimme) {
58 /* XXXX Should store the old value to allow for tie/overload - and
59 restore in regcomp, where marked with XXXX. */
67 register PMOP *pm = (PMOP*)cLOGOP->op_other;
71 MAGIC *mg = Null(MAGIC*);
75 /* prevent recompiling under /o and ithreads. */
76 #if defined(USE_ITHREADS) || defined(USE_5005THREADS)
77 if (pm->op_pmflags & PMf_KEEP && PM_GETRE(pm))
82 SV *sv = SvRV(tmpstr);
84 mg = mg_find(sv, PERL_MAGIC_qr);
87 regexp *re = (regexp *)mg->mg_obj;
88 ReREFCNT_dec(PM_GETRE(pm));
89 PM_SETRE(pm, ReREFCNT_inc(re));
92 t = SvPV(tmpstr, len);
94 /* Check against the last compiled regexp. */
95 if (!PM_GETRE(pm) || !PM_GETRE(pm)->precomp ||
96 PM_GETRE(pm)->prelen != (I32)len ||
97 memNE(PM_GETRE(pm)->precomp, t, len))
100 ReREFCNT_dec(PM_GETRE(pm));
101 PM_SETRE(pm, Null(REGEXP*)); /* crucial if regcomp aborts */
103 if (PL_op->op_flags & OPf_SPECIAL)
104 PL_reginterp_cnt = I32_MAX; /* Mark as safe. */
106 pm->op_pmflags = pm->op_pmpermflags; /* reset case sensitivity */
108 pm->op_pmdynflags |= PMdf_DYN_UTF8;
110 pm->op_pmdynflags &= ~PMdf_DYN_UTF8;
111 if (pm->op_pmdynflags & PMdf_UTF8)
112 t = (char*)bytes_to_utf8((U8*)t, &len);
114 PM_SETRE(pm, CALLREGCOMP(aTHX_ t, t + len, pm));
115 if (!DO_UTF8(tmpstr) && (pm->op_pmdynflags & PMdf_UTF8))
117 PL_reginterp_cnt = 0; /* XXXX Be extra paranoid - needed
118 inside tie/overload accessors. */
122 #ifndef INCOMPLETE_TAINTS
125 pm->op_pmdynflags |= PMdf_TAINTED;
127 pm->op_pmdynflags &= ~PMdf_TAINTED;
131 if (!PM_GETRE(pm)->prelen && PL_curpm)
133 else if (strEQ("\\s+", PM_GETRE(pm)->precomp))
134 pm->op_pmflags |= PMf_WHITE;
136 pm->op_pmflags &= ~PMf_WHITE;
138 /* XXX runtime compiled output needs to move to the pad */
139 if (pm->op_pmflags & PMf_KEEP) {
140 pm->op_private &= ~OPpRUNTIME; /* no point compiling again */
141 #if !defined(USE_ITHREADS) && !defined(USE_5005THREADS)
142 /* XXX can't change the optree at runtime either */
143 cLOGOP->op_first->op_next = PL_op->op_next;
152 register PMOP *pm = (PMOP*) cLOGOP->op_other;
153 register PERL_CONTEXT *cx = &cxstack[cxstack_ix];
154 register SV *dstr = cx->sb_dstr;
155 register char *s = cx->sb_s;
156 register char *m = cx->sb_m;
157 char *orig = cx->sb_orig;
158 register REGEXP *rx = cx->sb_rx;
161 rxres_restore(&cx->sb_rxres, rx);
162 RX_MATCH_UTF8_set(rx, SvUTF8(cx->sb_targ));
164 if (cx->sb_iters++) {
165 I32 saviters = cx->sb_iters;
166 if (cx->sb_iters > cx->sb_maxiters)
167 DIE(aTHX_ "Substitution loop");
169 if (!(cx->sb_rxtainted & 2) && SvTAINTED(TOPs))
170 cx->sb_rxtainted |= 2;
171 sv_catsv(dstr, POPs);
174 if (cx->sb_once || !CALLREGEXEC(aTHX_ rx, s, cx->sb_strend, orig,
175 s == m, cx->sb_targ, NULL,
176 ((cx->sb_rflags & REXEC_COPY_STR)
177 ? (REXEC_IGNOREPOS|REXEC_NOT_FIRST)
178 : (REXEC_COPY_STR|REXEC_IGNOREPOS|REXEC_NOT_FIRST))))
180 SV *targ = cx->sb_targ;
182 if (DO_UTF8(dstr) && !SvUTF8(targ))
183 sv_catpvn_utf8_upgrade(dstr, s, cx->sb_strend - s, nsv);
185 sv_catpvn(dstr, s, cx->sb_strend - s);
186 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
188 (void)SvOOK_off(targ);
190 Safefree(SvPVX(targ));
191 SvPVX(targ) = SvPVX(dstr);
192 SvCUR_set(targ, SvCUR(dstr));
193 SvLEN_set(targ, SvLEN(dstr));
199 TAINT_IF(cx->sb_rxtainted & 1);
200 PUSHs(sv_2mortal(newSViv(saviters - 1)));
202 (void)SvPOK_only_UTF8(targ);
203 TAINT_IF(cx->sb_rxtainted);
207 LEAVE_SCOPE(cx->sb_oldsave);
209 RETURNOP(pm->op_next);
211 cx->sb_iters = saviters;
213 if (RX_MATCH_COPIED(rx) && rx->subbeg != orig) {
216 cx->sb_orig = orig = rx->subbeg;
218 cx->sb_strend = s + (cx->sb_strend - m);
220 cx->sb_m = m = rx->startp[0] + orig;
222 if (DO_UTF8(dstr) && !SvUTF8(cx->sb_targ))
223 sv_catpvn_utf8_upgrade(dstr, s, m - s, nsv);
225 sv_catpvn(dstr, s, m-s);
227 cx->sb_s = rx->endp[0] + orig;
228 { /* Update the pos() information. */
229 SV *sv = cx->sb_targ;
232 if (SvTYPE(sv) < SVt_PVMG)
233 (void)SvUPGRADE(sv, SVt_PVMG);
234 if (!(mg = mg_find(sv, PERL_MAGIC_regex_global))) {
235 sv_magic(sv, Nullsv, PERL_MAGIC_regex_global, Nullch, 0);
236 mg = mg_find(sv, PERL_MAGIC_regex_global);
243 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
244 rxres_save(&cx->sb_rxres, rx);
245 RETURNOP(pm->op_pmreplstart);
249 Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx)
254 if (!p || p[1] < rx->nparens) {
255 i = 6 + rx->nparens * 2;
263 *p++ = PTR2UV(RX_MATCH_COPIED(rx) ? rx->subbeg : Nullch);
264 RX_MATCH_COPIED_off(rx);
268 *p++ = PTR2UV(rx->subbeg);
269 *p++ = (UV)rx->sublen;
270 for (i = 0; i <= rx->nparens; ++i) {
271 *p++ = (UV)rx->startp[i];
272 *p++ = (UV)rx->endp[i];
277 Perl_rxres_restore(pTHX_ void **rsp, REGEXP *rx)
282 if (RX_MATCH_COPIED(rx))
283 Safefree(rx->subbeg);
284 RX_MATCH_COPIED_set(rx, *p);
289 rx->subbeg = INT2PTR(char*,*p++);
290 rx->sublen = (I32)(*p++);
291 for (i = 0; i <= rx->nparens; ++i) {
292 rx->startp[i] = (I32)(*p++);
293 rx->endp[i] = (I32)(*p++);
298 Perl_rxres_free(pTHX_ void **rsp)
303 Safefree(INT2PTR(char*,*p));
311 dSP; dMARK; dORIGMARK;
312 register SV *tmpForm = *++MARK;
319 register SV *sv = Nullsv;
324 bool chopspace = (strchr(PL_chopset, ' ') != Nullch);
325 char *chophere = Nullch;
326 char *linemark = Nullch;
328 bool gotsome = FALSE;
330 STRLEN fudge = SvCUR(tmpForm) * (IN_BYTES ? 1 : 3) + 1;
331 bool item_is_utf8 = FALSE;
332 bool targ_is_utf8 = FALSE;
335 if (!SvMAGICAL(tmpForm) || !SvCOMPILED(tmpForm)) {
336 if (SvREADONLY(tmpForm)) {
337 SvREADONLY_off(tmpForm);
338 doparseform(tmpForm);
339 SvREADONLY_on(tmpForm);
342 doparseform(tmpForm);
344 SvPV_force(PL_formtarget, len);
345 if (DO_UTF8(PL_formtarget))
347 t = SvGROW(PL_formtarget, len + fudge + 1); /* XXX SvCUR bad */
349 f = SvPV(tmpForm, len);
350 /* need to jump to the next word */
351 s = f + len + WORD_ALIGN - SvCUR(tmpForm) % WORD_ALIGN;
360 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
361 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
362 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
363 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
364 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
366 case FF_CHECKNL: name = "CHECKNL"; break;
367 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
368 case FF_SPACE: name = "SPACE"; break;
369 case FF_HALFSPACE: name = "HALFSPACE"; break;
370 case FF_ITEM: name = "ITEM"; break;
371 case FF_CHOP: name = "CHOP"; break;
372 case FF_LINEGLOB: name = "LINEGLOB"; break;
373 case FF_NEWLINE: name = "NEWLINE"; break;
374 case FF_MORE: name = "MORE"; break;
375 case FF_LINEMARK: name = "LINEMARK"; break;
376 case FF_END: name = "END"; break;
377 case FF_0DECIMAL: name = "0DECIMAL"; break;
380 PerlIO_printf(Perl_debug_log, "%-16s%ld\n", name, (long) arg);
382 PerlIO_printf(Perl_debug_log, "%-16s\n", name);
393 if (targ_is_utf8 && !SvUTF8(tmpForm)) {
394 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
396 sv_catpvn_utf8_upgrade(PL_formtarget, f, arg, nsv);
397 t = SvEND(PL_formtarget);
400 if (!targ_is_utf8 && DO_UTF8(tmpForm)) {
401 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
403 sv_utf8_upgrade(PL_formtarget);
404 SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
405 t = SvEND(PL_formtarget);
425 if (ckWARN(WARN_SYNTAX))
426 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Not enough format arguments");
431 item = s = SvPV(sv, len);
434 itemsize = sv_len_utf8(sv);
435 if (itemsize != (I32)len) {
437 if (itemsize > fieldsize) {
438 itemsize = fieldsize;
439 itembytes = itemsize;
440 sv_pos_u2b(sv, &itembytes, 0);
444 send = chophere = s + itembytes;
454 sv_pos_b2u(sv, &itemsize);
458 item_is_utf8 = FALSE;
459 if (itemsize > fieldsize)
460 itemsize = fieldsize;
461 send = chophere = s + itemsize;
473 item = s = SvPV(sv, len);
476 itemsize = sv_len_utf8(sv);
477 if (itemsize != (I32)len) {
479 if (itemsize <= fieldsize) {
480 send = chophere = s + itemsize;
491 itemsize = fieldsize;
492 itembytes = itemsize;
493 sv_pos_u2b(sv, &itembytes, 0);
494 send = chophere = s + itembytes;
495 while (s < send || (s == send && isSPACE(*s))) {
505 if (strchr(PL_chopset, *s))
510 itemsize = chophere - item;
511 sv_pos_b2u(sv, &itemsize);
517 item_is_utf8 = FALSE;
518 if (itemsize <= fieldsize) {
519 send = chophere = s + itemsize;
530 itemsize = fieldsize;
531 send = chophere = s + itemsize;
532 while (s < send || (s == send && isSPACE(*s))) {
542 if (strchr(PL_chopset, *s))
547 itemsize = chophere - item;
552 arg = fieldsize - itemsize;
561 arg = fieldsize - itemsize;
575 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
577 sv_utf8_upgrade(PL_formtarget);
578 SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
579 t = SvEND(PL_formtarget);
583 if (UTF8_IS_CONTINUED(*s)) {
584 STRLEN skip = UTF8SKIP(s);
601 if ( !((*t++ = *s++) & ~31) )
607 if (targ_is_utf8 && !item_is_utf8) {
608 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
610 sv_catpvn_utf8_upgrade(PL_formtarget, s, arg, nsv);
611 for (; t < SvEND(PL_formtarget); t++) {
613 int ch = *t++ = *s++;
624 int ch = *t++ = *s++;
627 if ( !((*t++ = *s++) & ~31) )
636 while (*s && isSPACE(*s))
643 item = s = SvPV(sv, len);
645 if ((item_is_utf8 = DO_UTF8(sv)))
646 itemsize = sv_len_utf8(sv);
648 bool chopped = FALSE;
661 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
663 SvUTF8_on(PL_formtarget);
664 sv_catsv(PL_formtarget, sv);
666 SvCUR_set(PL_formtarget, SvCUR(PL_formtarget) - 1);
667 SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
668 t = SvPVX(PL_formtarget) + SvCUR(PL_formtarget);
675 /* If the field is marked with ^ and the value is undefined,
678 if ((arg & 512) && !SvOK(sv)) {
686 /* Formats aren't yet marked for locales, so assume "yes". */
688 STORE_NUMERIC_STANDARD_SET_LOCAL();
689 #if defined(USE_LONG_DOUBLE)
691 sprintf(t, "%#*.*" PERL_PRIfldbl,
692 (int) fieldsize, (int) arg & 255, value);
694 sprintf(t, "%*.0" PERL_PRIfldbl, (int) fieldsize, value);
699 (int) fieldsize, (int) arg & 255, value);
702 (int) fieldsize, value);
705 RESTORE_NUMERIC_STANDARD();
711 /* If the field is marked with ^ and the value is undefined,
714 if ((arg & 512) && !SvOK(sv)) {
722 /* Formats aren't yet marked for locales, so assume "yes". */
724 STORE_NUMERIC_STANDARD_SET_LOCAL();
725 #if defined(USE_LONG_DOUBLE)
727 sprintf(t, "%#0*.*" PERL_PRIfldbl,
728 (int) fieldsize, (int) arg & 255, value);
729 /* is this legal? I don't have long doubles */
731 sprintf(t, "%0*.0" PERL_PRIfldbl, (int) fieldsize, value);
735 sprintf(t, "%#0*.*f",
736 (int) fieldsize, (int) arg & 255, value);
739 (int) fieldsize, value);
742 RESTORE_NUMERIC_STANDARD();
749 while (t-- > linemark && *t == ' ') ;
757 if (arg) { /* repeat until fields exhausted? */
759 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
760 lines += FmLINES(PL_formtarget);
763 if (strnEQ(linemark, linemark - arg, arg))
764 DIE(aTHX_ "Runaway format");
767 SvUTF8_on(PL_formtarget);
768 FmLINES(PL_formtarget) = lines;
770 RETURNOP(cLISTOP->op_first);
783 while (*s && isSPACE(*s) && s < send)
787 arg = fieldsize - itemsize;
794 if (strnEQ(s," ",3)) {
795 while (s > SvPVX(PL_formtarget) && isSPACE(s[-1]))
806 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
808 SvUTF8_on(PL_formtarget);
809 FmLINES(PL_formtarget) += lines;
821 if (PL_stack_base + *PL_markstack_ptr == SP) {
823 if (GIMME_V == G_SCALAR)
824 XPUSHs(sv_2mortal(newSViv(0)));
825 RETURNOP(PL_op->op_next->op_next);
827 PL_stack_sp = PL_stack_base + *PL_markstack_ptr + 1;
828 pp_pushmark(); /* push dst */
829 pp_pushmark(); /* push src */
830 ENTER; /* enter outer scope */
833 /* SAVE_DEFSV does *not* suffice here for USE_5005THREADS */
835 ENTER; /* enter inner scope */
838 src = PL_stack_base[*PL_markstack_ptr];
843 if (PL_op->op_type == OP_MAPSTART)
844 pp_pushmark(); /* push top */
845 return ((LOGOP*)PL_op->op_next)->op_other;
850 DIE(aTHX_ "panic: mapstart"); /* uses grepstart */
856 I32 items = (SP - PL_stack_base) - *PL_markstack_ptr; /* how many new items */
862 /* first, move source pointer to the next item in the source list */
863 ++PL_markstack_ptr[-1];
865 /* if there are new items, push them into the destination list */
867 /* might need to make room back there first */
868 if (items > PL_markstack_ptr[-1] - PL_markstack_ptr[-2]) {
869 /* XXX this implementation is very pessimal because the stack
870 * is repeatedly extended for every set of items. Is possible
871 * to do this without any stack extension or copying at all
872 * by maintaining a separate list over which the map iterates
873 * (like foreach does). --gsar */
875 /* everything in the stack after the destination list moves
876 * towards the end the stack by the amount of room needed */
877 shift = items - (PL_markstack_ptr[-1] - PL_markstack_ptr[-2]);
879 /* items to shift up (accounting for the moved source pointer) */
880 count = (SP - PL_stack_base) - (PL_markstack_ptr[-1] - 1);
882 /* This optimization is by Ben Tilly and it does
883 * things differently from what Sarathy (gsar)
884 * is describing. The downside of this optimization is
885 * that leaves "holes" (uninitialized and hopefully unused areas)
886 * to the Perl stack, but on the other hand this
887 * shouldn't be a problem. If Sarathy's idea gets
888 * implemented, this optimization should become
889 * irrelevant. --jhi */
891 shift = count; /* Avoid shifting too often --Ben Tilly */
896 PL_markstack_ptr[-1] += shift;
897 *PL_markstack_ptr += shift;
901 /* copy the new items down to the destination list */
902 dst = PL_stack_base + (PL_markstack_ptr[-2] += items) - 1;
904 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
906 LEAVE; /* exit inner scope */
909 if (PL_markstack_ptr[-1] > *PL_markstack_ptr) {
912 (void)POPMARK; /* pop top */
913 LEAVE; /* exit outer scope */
914 (void)POPMARK; /* pop src */
915 items = --*PL_markstack_ptr - PL_markstack_ptr[-1];
916 (void)POPMARK; /* pop dst */
917 SP = PL_stack_base + POPMARK; /* pop original mark */
918 if (gimme == G_SCALAR) {
922 else if (gimme == G_ARRAY)
929 ENTER; /* enter inner scope */
932 /* set $_ to the new source item */
933 src = PL_stack_base[PL_markstack_ptr[-1]];
937 RETURNOP(cLOGOP->op_other);
945 if (GIMME == G_ARRAY)
947 if (SvTRUEx(PAD_SV(PL_op->op_targ)))
948 return cLOGOP->op_other;
957 if (GIMME == G_ARRAY) {
958 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
962 SV *targ = PAD_SV(PL_op->op_targ);
965 if (PL_op->op_private & OPpFLIP_LINENUM) {
966 if (GvIO(PL_last_in_gv)) {
967 flip = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
970 GV *gv = gv_fetchpv(".", TRUE, SVt_PV);
971 if (gv && GvSV(gv)) flip = SvIV(sv) == SvIV(GvSV(gv));
977 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
978 if (PL_op->op_flags & OPf_SPECIAL) {
986 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
999 if (GIMME == G_ARRAY) {
1005 if (SvGMAGICAL(left))
1007 if (SvGMAGICAL(right))
1010 /* This code tries to decide if "$left .. $right" should use the
1011 magical string increment, or if the range is numeric (we make
1012 an exception for .."0" [#18165]). AMS 20021031. */
1014 if (SvNIOKp(left) || !SvPOKp(left) ||
1015 SvNIOKp(right) || !SvPOKp(right) ||
1016 (looks_like_number(left) && *SvPVX(left) != '0' &&
1017 looks_like_number(right)))
1019 if (SvNV(left) < IV_MIN || SvNV(right) > IV_MAX)
1020 DIE(aTHX_ "Range iterator outside integer range");
1031 sv = sv_2mortal(newSViv(i++));
1036 SV *final = sv_mortalcopy(right);
1038 char *tmps = SvPV(final, len);
1040 sv = sv_mortalcopy(left);
1042 while (!SvNIOKp(sv) && SvCUR(sv) <= len) {
1044 if (strEQ(SvPVX(sv),tmps))
1046 sv = sv_2mortal(newSVsv(sv));
1053 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
1057 if (PL_op->op_private & OPpFLIP_LINENUM) {
1058 if (GvIO(PL_last_in_gv)) {
1059 flop = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
1062 GV *gv = gv_fetchpv(".", TRUE, SVt_PV);
1063 if (gv && GvSV(gv)) flop = SvIV(sv) == SvIV(GvSV(gv));
1071 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
1072 sv_catpv(targ, "E0");
1082 static char *context_name[] = {
1093 S_dopoptolabel(pTHX_ char *label)
1096 register PERL_CONTEXT *cx;
1098 for (i = cxstack_ix; i >= 0; i--) {
1100 switch (CxTYPE(cx)) {
1106 if (ckWARN(WARN_EXITING))
1107 Perl_warner(aTHX_ packWARN(WARN_EXITING), "Exiting %s via %s",
1108 context_name[CxTYPE(cx)], OP_NAME(PL_op));
1109 if (CxTYPE(cx) == CXt_NULL)
1113 if (!cx->blk_loop.label ||
1114 strNE(label, cx->blk_loop.label) ) {
1115 DEBUG_l(Perl_deb(aTHX_ "(Skipping label #%ld %s)\n",
1116 (long)i, cx->blk_loop.label));
1119 DEBUG_l( Perl_deb(aTHX_ "(Found label #%ld %s)\n", (long)i, label));
1127 Perl_dowantarray(pTHX)
1129 I32 gimme = block_gimme();
1130 return (gimme == G_VOID) ? G_SCALAR : gimme;
1134 Perl_block_gimme(pTHX)
1138 cxix = dopoptosub(cxstack_ix);
1142 switch (cxstack[cxix].blk_gimme) {
1150 Perl_croak(aTHX_ "panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
1157 Perl_is_lvalue_sub(pTHX)
1161 cxix = dopoptosub(cxstack_ix);
1162 assert(cxix >= 0); /* We should only be called from inside subs */
1164 if (cxstack[cxix].blk_sub.lval && CvLVALUE(cxstack[cxix].blk_sub.cv))
1165 return cxstack[cxix].blk_sub.lval;
1171 S_dopoptosub(pTHX_ I32 startingblock)
1173 return dopoptosub_at(cxstack, startingblock);
1177 S_dopoptosub_at(pTHX_ PERL_CONTEXT *cxstk, I32 startingblock)
1180 register PERL_CONTEXT *cx;
1181 for (i = startingblock; i >= 0; i--) {
1183 switch (CxTYPE(cx)) {
1189 DEBUG_l( Perl_deb(aTHX_ "(Found sub #%ld)\n", (long)i));
1197 S_dopoptoeval(pTHX_ I32 startingblock)
1200 register PERL_CONTEXT *cx;
1201 for (i = startingblock; i >= 0; i--) {
1203 switch (CxTYPE(cx)) {
1207 DEBUG_l( Perl_deb(aTHX_ "(Found eval #%ld)\n", (long)i));
1215 S_dopoptoloop(pTHX_ I32 startingblock)
1218 register PERL_CONTEXT *cx;
1219 for (i = startingblock; i >= 0; i--) {
1221 switch (CxTYPE(cx)) {
1227 if (ckWARN(WARN_EXITING))
1228 Perl_warner(aTHX_ packWARN(WARN_EXITING), "Exiting %s via %s",
1229 context_name[CxTYPE(cx)], OP_NAME(PL_op));
1230 if ((CxTYPE(cx)) == CXt_NULL)
1234 DEBUG_l( Perl_deb(aTHX_ "(Found loop #%ld)\n", (long)i));
1242 Perl_dounwind(pTHX_ I32 cxix)
1244 register PERL_CONTEXT *cx;
1247 while (cxstack_ix > cxix) {
1249 cx = &cxstack[cxstack_ix];
1250 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n",
1251 (long) cxstack_ix, PL_block_type[CxTYPE(cx)]));
1252 /* Note: we don't need to restore the base context info till the end. */
1253 switch (CxTYPE(cx)) {
1256 continue; /* not break */
1278 Perl_qerror(pTHX_ SV *err)
1281 sv_catsv(ERRSV, err);
1283 sv_catsv(PL_errors, err);
1285 Perl_warn(aTHX_ "%"SVf, err);
1290 Perl_die_where(pTHX_ char *message, STRLEN msglen)
1298 register PERL_CONTEXT *cx;
1303 if (PL_in_eval & EVAL_KEEPERR) {
1304 static char prefix[] = "\t(in cleanup) ";
1309 else if (SvCUR(err) >= sizeof(prefix)+msglen-1) {
1312 if (*e != *message || strNE(e,message))
1316 SvGROW(err, SvCUR(err)+sizeof(prefix)+msglen);
1317 sv_catpvn(err, prefix, sizeof(prefix)-1);
1318 sv_catpvn(err, message, msglen);
1319 if (ckWARN(WARN_MISC)) {
1320 STRLEN start = SvCUR(err)-msglen-sizeof(prefix)+1;
1321 Perl_warner(aTHX_ packWARN(WARN_MISC), SvPVX(err)+start);
1326 sv_setpvn(ERRSV, message, msglen);
1330 message = SvPVx(ERRSV, msglen);
1332 while ((cxix = dopoptoeval(cxstack_ix)) < 0
1333 && PL_curstackinfo->si_prev)
1342 if (cxix < cxstack_ix)
1345 POPBLOCK(cx,PL_curpm);
1346 if (CxTYPE(cx) != CXt_EVAL) {
1347 PerlIO_write(Perl_error_log, "panic: die ", 11);
1348 PerlIO_write(Perl_error_log, message, msglen);
1353 if (gimme == G_SCALAR)
1354 *++newsp = &PL_sv_undef;
1355 PL_stack_sp = newsp;
1359 /* LEAVE could clobber PL_curcop (see save_re_context())
1360 * XXX it might be better to find a way to avoid messing with
1361 * PL_curcop in save_re_context() instead, but this is a more
1362 * minimal fix --GSAR */
1363 PL_curcop = cx->blk_oldcop;
1365 if (optype == OP_REQUIRE) {
1366 char* msg = SvPVx(ERRSV, n_a);
1367 DIE(aTHX_ "%sCompilation failed in require",
1368 *msg ? msg : "Unknown error\n");
1370 return pop_return();
1374 message = SvPVx(ERRSV, msglen);
1376 /* if STDERR is tied, print to it instead */
1377 if (PL_stderrgv && (io = GvIOp(PL_stderrgv))
1378 && (mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar))) {
1381 XPUSHs(SvTIED_obj((SV*)io, mg));
1382 XPUSHs(sv_2mortal(newSVpvn(message, msglen)));
1384 call_method("PRINT", G_SCALAR);
1389 /* SFIO can really mess with your errno */
1392 PerlIO *serr = Perl_error_log;
1394 PERL_WRITE_MSG_TO_CONSOLE(serr, message, msglen);
1395 (void)PerlIO_flush(serr);
1408 if (SvTRUE(left) != SvTRUE(right))
1420 RETURNOP(cLOGOP->op_other);
1429 RETURNOP(cLOGOP->op_other);
1435 register I32 cxix = dopoptosub(cxstack_ix);
1436 register PERL_CONTEXT *cx;
1437 register PERL_CONTEXT *ccstack = cxstack;
1438 PERL_SI *top_si = PL_curstackinfo;
1449 /* we may be in a higher stacklevel, so dig down deeper */
1450 while (cxix < 0 && top_si->si_type != PERLSI_MAIN) {
1451 top_si = top_si->si_prev;
1452 ccstack = top_si->si_cxstack;
1453 cxix = dopoptosub_at(ccstack, top_si->si_cxix);
1456 if (GIMME != G_ARRAY) {
1462 if (PL_DBsub && cxix >= 0 &&
1463 ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub))
1467 cxix = dopoptosub_at(ccstack, cxix - 1);
1470 cx = &ccstack[cxix];
1471 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1472 dbcxix = dopoptosub_at(ccstack, cxix - 1);
1473 /* We expect that ccstack[dbcxix] is CXt_SUB, anyway, the
1474 field below is defined for any cx. */
1475 if (PL_DBsub && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub))
1476 cx = &ccstack[dbcxix];
1479 stashname = CopSTASHPV(cx->blk_oldcop);
1480 if (GIMME != G_ARRAY) {
1483 PUSHs(&PL_sv_undef);
1486 sv_setpv(TARG, stashname);
1495 PUSHs(&PL_sv_undef);
1497 PUSHs(sv_2mortal(newSVpv(stashname, 0)));
1498 PUSHs(sv_2mortal(newSVpv(OutCopFILE(cx->blk_oldcop), 0)));
1499 PUSHs(sv_2mortal(newSViv((I32)CopLINE(cx->blk_oldcop))));
1502 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1503 GV *cvgv = CvGV(ccstack[cxix].blk_sub.cv);
1504 /* So is ccstack[dbcxix]. */
1507 gv_efullname3(sv, cvgv, Nullch);
1508 PUSHs(sv_2mortal(sv));
1509 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1512 PUSHs(sv_2mortal(newSVpvn("(unknown)",9)));
1513 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1517 PUSHs(sv_2mortal(newSVpvn("(eval)",6)));
1518 PUSHs(sv_2mortal(newSViv(0)));
1520 gimme = (I32)cx->blk_gimme;
1521 if (gimme == G_VOID)
1522 PUSHs(&PL_sv_undef);
1524 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1525 if (CxTYPE(cx) == CXt_EVAL) {
1527 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1528 PUSHs(cx->blk_eval.cur_text);
1532 else if (cx->blk_eval.old_namesv) {
1533 PUSHs(sv_2mortal(newSVsv(cx->blk_eval.old_namesv)));
1536 /* eval BLOCK (try blocks have old_namesv == 0) */
1538 PUSHs(&PL_sv_undef);
1539 PUSHs(&PL_sv_undef);
1543 PUSHs(&PL_sv_undef);
1544 PUSHs(&PL_sv_undef);
1546 if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.hasargs
1547 && CopSTASH_eq(PL_curcop, PL_debstash))
1549 AV *ary = cx->blk_sub.argarray;
1550 int off = AvARRAY(ary) - AvALLOC(ary);
1554 PL_dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1557 AvREAL_off(PL_dbargs); /* XXX should be REIFY (see av.h) */
1560 if (AvMAX(PL_dbargs) < AvFILLp(ary) + off)
1561 av_extend(PL_dbargs, AvFILLp(ary) + off);
1562 Copy(AvALLOC(ary), AvARRAY(PL_dbargs), AvFILLp(ary) + 1 + off, SV*);
1563 AvFILLp(PL_dbargs) = AvFILLp(ary) + off;
1565 /* XXX only hints propagated via op_private are currently
1566 * visible (others are not easily accessible, since they
1567 * use the global PL_hints) */
1568 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->op_private &
1569 HINT_PRIVATE_MASK)));
1572 SV * old_warnings = cx->blk_oldcop->cop_warnings ;
1574 if (old_warnings == pWARN_NONE ||
1575 (old_warnings == pWARN_STD && (PL_dowarn & G_WARN_ON) == 0))
1576 mask = newSVpvn(WARN_NONEstring, WARNsize) ;
1577 else if (old_warnings == pWARN_ALL ||
1578 (old_warnings == pWARN_STD && PL_dowarn & G_WARN_ON))
1579 mask = newSVpvn(WARN_ALLstring, WARNsize) ;
1581 mask = newSVsv(old_warnings);
1582 PUSHs(sv_2mortal(mask));
1597 sv_reset(tmps, CopSTASH(PL_curcop));
1607 /* like pp_nextstate, but used instead when the debugger is active */
1611 PL_curcop = (COP*)PL_op;
1612 TAINT_NOT; /* Each statement is presumed innocent */
1613 PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
1616 if (PL_op->op_flags & OPf_SPECIAL /* breakpoint */
1617 || SvIV(PL_DBsingle) || SvIV(PL_DBsignal) || SvIV(PL_DBtrace))
1621 register PERL_CONTEXT *cx;
1622 I32 gimme = G_ARRAY;
1629 DIE(aTHX_ "No DB::DB routine defined");
1631 if (CvDEPTH(cv) >= 1 && !(PL_debug & DEBUG_DB_RECURSE_FLAG))
1632 /* don't do recursive DB::DB call */
1644 push_return(PL_op->op_next);
1645 PUSHBLOCK(cx, CXt_SUB, SP);
1648 (void)SvREFCNT_inc(cv);
1649 PAD_SET_CUR(CvPADLIST(cv),1);
1650 RETURNOP(CvSTART(cv));
1664 register PERL_CONTEXT *cx;
1665 I32 gimme = GIMME_V;
1667 U32 cxtype = CXt_LOOP;
1675 #ifdef USE_5005THREADS
1676 if (PL_op->op_flags & OPf_SPECIAL) {
1677 svp = &THREADSV(PL_op->op_targ); /* per-thread variable */
1678 SAVEGENERICSV(*svp);
1682 #endif /* USE_5005THREADS */
1683 if (PL_op->op_targ) {
1684 #ifndef USE_ITHREADS
1685 svp = &PAD_SVl(PL_op->op_targ); /* "my" variable */
1688 SAVEPADSV(PL_op->op_targ);
1689 iterdata = INT2PTR(void*, PL_op->op_targ);
1690 cxtype |= CXp_PADVAR;
1695 svp = &GvSV(gv); /* symbol table variable */
1696 SAVEGENERICSV(*svp);
1699 iterdata = (void*)gv;
1705 PUSHBLOCK(cx, cxtype, SP);
1707 PUSHLOOP(cx, iterdata, MARK);
1709 PUSHLOOP(cx, svp, MARK);
1711 if (PL_op->op_flags & OPf_STACKED) {
1712 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1713 if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) {
1715 /* See comment in pp_flop() */
1716 if (SvNIOKp(sv) || !SvPOKp(sv) ||
1717 SvNIOKp(cx->blk_loop.iterary) || !SvPOKp(cx->blk_loop.iterary) ||
1718 (looks_like_number(sv) && *SvPVX(sv) != '0' &&
1719 looks_like_number((SV*)cx->blk_loop.iterary)))
1721 if (SvNV(sv) < IV_MIN ||
1722 SvNV((SV*)cx->blk_loop.iterary) >= IV_MAX)
1723 DIE(aTHX_ "Range iterator outside integer range");
1724 cx->blk_loop.iterix = SvIV(sv);
1725 cx->blk_loop.itermax = SvIV((SV*)cx->blk_loop.iterary);
1728 cx->blk_loop.iterlval = newSVsv(sv);
1732 cx->blk_loop.iterary = PL_curstack;
1733 AvFILLp(PL_curstack) = SP - PL_stack_base;
1734 cx->blk_loop.iterix = MARK - PL_stack_base;
1743 register PERL_CONTEXT *cx;
1744 I32 gimme = GIMME_V;
1750 PUSHBLOCK(cx, CXt_LOOP, SP);
1751 PUSHLOOP(cx, 0, SP);
1759 register PERL_CONTEXT *cx;
1767 newsp = PL_stack_base + cx->blk_loop.resetsp;
1770 if (gimme == G_VOID)
1772 else if (gimme == G_SCALAR) {
1774 *++newsp = sv_mortalcopy(*SP);
1776 *++newsp = &PL_sv_undef;
1780 *++newsp = sv_mortalcopy(*++mark);
1781 TAINT_NOT; /* Each item is independent */
1787 POPLOOP(cx); /* Stack values are safe: release loop vars ... */
1788 PL_curpm = newpm; /* ... and pop $1 et al */
1800 register PERL_CONTEXT *cx;
1801 bool popsub2 = FALSE;
1802 bool clear_errsv = FALSE;
1809 if (PL_curstackinfo->si_type == PERLSI_SORT) {
1810 if (cxstack_ix == PL_sortcxix
1811 || dopoptosub(cxstack_ix) <= PL_sortcxix)
1813 if (cxstack_ix > PL_sortcxix)
1814 dounwind(PL_sortcxix);
1815 AvARRAY(PL_curstack)[1] = *SP;
1816 PL_stack_sp = PL_stack_base + 1;
1821 cxix = dopoptosub(cxstack_ix);
1823 DIE(aTHX_ "Can't return outside a subroutine");
1824 if (cxix < cxstack_ix)
1828 switch (CxTYPE(cx)) {
1833 if (!(PL_in_eval & EVAL_KEEPERR))
1839 if (optype == OP_REQUIRE &&
1840 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1842 /* Unassume the success we assumed earlier. */
1843 SV *nsv = cx->blk_eval.old_namesv;
1844 (void)hv_delete(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), G_DISCARD);
1845 DIE(aTHX_ "%"SVf" did not return a true value", nsv);
1852 DIE(aTHX_ "panic: return");
1856 if (gimme == G_SCALAR) {
1859 if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
1861 *++newsp = SvREFCNT_inc(*SP);
1866 sv = SvREFCNT_inc(*SP); /* FREETMPS could clobber it */
1868 *++newsp = sv_mortalcopy(sv);
1873 *++newsp = (SvTEMP(*SP)) ? *SP : sv_mortalcopy(*SP);
1876 *++newsp = sv_mortalcopy(*SP);
1879 *++newsp = &PL_sv_undef;
1881 else if (gimme == G_ARRAY) {
1882 while (++MARK <= SP) {
1883 *++newsp = (popsub2 && SvTEMP(*MARK))
1884 ? *MARK : sv_mortalcopy(*MARK);
1885 TAINT_NOT; /* Each item is independent */
1888 PL_stack_sp = newsp;
1890 /* Stack values are safe: */
1892 POPSUB(cx,sv); /* release CV and @_ ... */
1896 PL_curpm = newpm; /* ... and pop $1 et al */
1902 return pop_return();
1909 register PERL_CONTEXT *cx;
1919 if (PL_op->op_flags & OPf_SPECIAL) {
1920 cxix = dopoptoloop(cxstack_ix);
1922 DIE(aTHX_ "Can't \"last\" outside a loop block");
1925 cxix = dopoptolabel(cPVOP->op_pv);
1927 DIE(aTHX_ "Label not found for \"last %s\"", cPVOP->op_pv);
1929 if (cxix < cxstack_ix)
1934 switch (CxTYPE(cx)) {
1937 newsp = PL_stack_base + cx->blk_loop.resetsp;
1938 nextop = cx->blk_loop.last_op->op_next;
1942 nextop = pop_return();
1946 nextop = pop_return();
1950 nextop = pop_return();
1953 DIE(aTHX_ "panic: last");
1957 if (gimme == G_SCALAR) {
1959 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
1960 ? *SP : sv_mortalcopy(*SP);
1962 *++newsp = &PL_sv_undef;
1964 else if (gimme == G_ARRAY) {
1965 while (++MARK <= SP) {
1966 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
1967 ? *MARK : sv_mortalcopy(*MARK);
1968 TAINT_NOT; /* Each item is independent */
1974 /* Stack values are safe: */
1977 POPLOOP(cx); /* release loop vars ... */
1981 POPSUB(cx,sv); /* release CV and @_ ... */
1984 PL_curpm = newpm; /* ... and pop $1 et al */
1994 register PERL_CONTEXT *cx;
1997 if (PL_op->op_flags & OPf_SPECIAL) {
1998 cxix = dopoptoloop(cxstack_ix);
2000 DIE(aTHX_ "Can't \"next\" outside a loop block");
2003 cxix = dopoptolabel(cPVOP->op_pv);
2005 DIE(aTHX_ "Label not found for \"next %s\"", cPVOP->op_pv);
2007 if (cxix < cxstack_ix)
2010 /* clear off anything above the scope we're re-entering, but
2011 * save the rest until after a possible continue block */
2012 inner = PL_scopestack_ix;
2014 if (PL_scopestack_ix < inner)
2015 leave_scope(PL_scopestack[PL_scopestack_ix]);
2016 return cx->blk_loop.next_op;
2022 register PERL_CONTEXT *cx;
2025 if (PL_op->op_flags & OPf_SPECIAL) {
2026 cxix = dopoptoloop(cxstack_ix);
2028 DIE(aTHX_ "Can't \"redo\" outside a loop block");
2031 cxix = dopoptolabel(cPVOP->op_pv);
2033 DIE(aTHX_ "Label not found for \"redo %s\"", cPVOP->op_pv);
2035 if (cxix < cxstack_ix)
2039 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2040 LEAVE_SCOPE(oldsave);
2041 return cx->blk_loop.redo_op;
2045 S_dofindlabel(pTHX_ OP *o, char *label, OP **opstack, OP **oplimit)
2049 static char too_deep[] = "Target of goto is too deeply nested";
2052 Perl_croak(aTHX_ too_deep);
2053 if (o->op_type == OP_LEAVE ||
2054 o->op_type == OP_SCOPE ||
2055 o->op_type == OP_LEAVELOOP ||
2056 o->op_type == OP_LEAVESUB ||
2057 o->op_type == OP_LEAVETRY)
2059 *ops++ = cUNOPo->op_first;
2061 Perl_croak(aTHX_ too_deep);
2064 if (o->op_flags & OPf_KIDS) {
2065 /* First try all the kids at this level, since that's likeliest. */
2066 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
2067 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
2068 kCOP->cop_label && strEQ(kCOP->cop_label, label))
2071 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
2072 if (kid == PL_lastgotoprobe)
2074 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
2077 else if (ops[-1]->op_type == OP_NEXTSTATE ||
2078 ops[-1]->op_type == OP_DBSTATE)
2083 if ((o = dofindlabel(kid, label, ops, oplimit)))
2102 register PERL_CONTEXT *cx;
2103 #define GOTO_DEPTH 64
2104 OP *enterops[GOTO_DEPTH];
2106 int do_dump = (PL_op->op_type == OP_DUMP);
2107 static char must_have_label[] = "goto must have label";
2110 if (PL_op->op_flags & OPf_STACKED) {
2114 /* This egregious kludge implements goto &subroutine */
2115 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
2117 register PERL_CONTEXT *cx;
2118 CV* cv = (CV*)SvRV(sv);
2124 if (!CvROOT(cv) && !CvXSUB(cv)) {
2129 /* autoloaded stub? */
2130 if (cv != GvCV(gv) && (cv = GvCV(gv)))
2132 autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv),
2133 GvNAMELEN(gv), FALSE);
2134 if (autogv && (cv = GvCV(autogv)))
2136 tmpstr = sv_newmortal();
2137 gv_efullname3(tmpstr, gv, Nullch);
2138 DIE(aTHX_ "Goto undefined subroutine &%"SVf"",tmpstr);
2140 DIE(aTHX_ "Goto undefined subroutine");
2143 /* First do some returnish stuff. */
2145 cxix = dopoptosub(cxstack_ix);
2147 DIE(aTHX_ "Can't goto subroutine outside a subroutine");
2148 if (cxix < cxstack_ix)
2152 DIE(aTHX_ "Can't goto subroutine from an eval-string");
2154 if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.hasargs) {
2155 /* put @_ back onto stack */
2156 AV* av = cx->blk_sub.argarray;
2158 items = AvFILLp(av) + 1;
2160 EXTEND(PL_stack_sp, items); /* @_ could have been extended. */
2161 Copy(AvARRAY(av), PL_stack_sp, items, SV*);
2162 PL_stack_sp += items;
2163 #ifndef USE_5005THREADS
2164 SvREFCNT_dec(GvAV(PL_defgv));
2165 GvAV(PL_defgv) = cx->blk_sub.savearray;
2166 #endif /* USE_5005THREADS */
2167 /* abandon @_ if it got reified */
2169 (void)sv_2mortal((SV*)av); /* delay until return */
2171 av_extend(av, items-1);
2172 AvFLAGS(av) = AVf_REIFY;
2173 PAD_SVl(0) = (SV*)(cx->blk_sub.argarray = av);
2176 else if (CvXSUB(cv)) { /* put GvAV(defgv) back onto stack */
2178 #ifdef USE_5005THREADS
2179 av = (AV*)PAD_SVl(0);
2181 av = GvAV(PL_defgv);
2183 items = AvFILLp(av) + 1;
2185 EXTEND(PL_stack_sp, items); /* @_ could have been extended. */
2186 Copy(AvARRAY(av), PL_stack_sp, items, SV*);
2187 PL_stack_sp += items;
2189 if (CxTYPE(cx) == CXt_SUB &&
2190 !(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
2191 SvREFCNT_dec(cx->blk_sub.cv);
2192 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2193 LEAVE_SCOPE(oldsave);
2195 /* Now do some callish stuff. */
2198 #ifdef PERL_XSUB_OLDSTYLE
2199 if (CvOLDSTYLE(cv)) {
2200 I32 (*fp3)(int,int,int);
2205 fp3 = (I32(*)(int,int,int))CvXSUB(cv);
2206 items = (*fp3)(CvXSUBANY(cv).any_i32,
2207 mark - PL_stack_base + 1,
2209 SP = PL_stack_base + items;
2212 #endif /* PERL_XSUB_OLDSTYLE */
2217 PL_stack_sp--; /* There is no cv arg. */
2218 /* Push a mark for the start of arglist */
2220 (void)(*CvXSUB(cv))(aTHX_ cv);
2221 /* Pop the current context like a decent sub should */
2222 POPBLOCK(cx, PL_curpm);
2223 /* Do _not_ use PUTBACK, keep the XSUB's return stack! */
2226 return pop_return();
2229 AV* padlist = CvPADLIST(cv);
2230 if (CxTYPE(cx) == CXt_EVAL) {
2231 PL_in_eval = cx->blk_eval.old_in_eval;
2232 PL_eval_root = cx->blk_eval.old_eval_root;
2233 cx->cx_type = CXt_SUB;
2234 cx->blk_sub.hasargs = 0;
2236 cx->blk_sub.cv = cv;
2237 cx->blk_sub.olddepth = (U16)CvDEPTH(cv);
2240 if (CvDEPTH(cv) < 2)
2241 (void)SvREFCNT_inc(cv);
2243 if (CvDEPTH(cv) == 100 && ckWARN(WARN_RECURSION))
2244 sub_crush_depth(cv);
2245 pad_push(padlist, CvDEPTH(cv), cx->blk_sub.hasargs);
2247 #ifdef USE_5005THREADS
2248 if (!cx->blk_sub.hasargs) {
2249 AV* av = (AV*)PAD_SVl(0);
2251 items = AvFILLp(av) + 1;
2253 /* Mark is at the end of the stack. */
2255 Copy(AvARRAY(av), SP + 1, items, SV*);
2260 #endif /* USE_5005THREADS */
2261 PAD_SET_CUR(padlist, CvDEPTH(cv));
2262 #ifndef USE_5005THREADS
2263 if (cx->blk_sub.hasargs)
2264 #endif /* USE_5005THREADS */
2266 AV* av = (AV*)PAD_SVl(0);
2269 #ifndef USE_5005THREADS
2270 cx->blk_sub.savearray = GvAV(PL_defgv);
2271 GvAV(PL_defgv) = (AV*)SvREFCNT_inc(av);
2272 #endif /* USE_5005THREADS */
2273 CX_CURPAD_SAVE(cx->blk_sub);
2274 cx->blk_sub.argarray = av;
2277 if (items >= AvMAX(av) + 1) {
2279 if (AvARRAY(av) != ary) {
2280 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
2281 SvPVX(av) = (char*)ary;
2283 if (items >= AvMAX(av) + 1) {
2284 AvMAX(av) = items - 1;
2285 Renew(ary,items+1,SV*);
2287 SvPVX(av) = (char*)ary;
2290 Copy(mark,AvARRAY(av),items,SV*);
2291 AvFILLp(av) = items - 1;
2292 assert(!AvREAL(av));
2299 if (PERLDB_SUB) { /* Checking curstash breaks DProf. */
2301 * We do not care about using sv to call CV;
2302 * it's for informational purposes only.
2304 SV *sv = GvSV(PL_DBsub);
2307 if (PERLDB_SUB_NN) {
2308 SvIVX(sv) = PTR2IV(cv); /* Already upgraded, saved */
2311 gv_efullname3(sv, CvGV(cv), Nullch);
2314 && (gotocv = get_cv("DB::goto", FALSE)) ) {
2315 PUSHMARK( PL_stack_sp );
2316 call_sv((SV*)gotocv, G_SCALAR | G_NODEBUG);
2320 RETURNOP(CvSTART(cv));
2324 label = SvPV(sv,n_a);
2325 if (!(do_dump || *label))
2326 DIE(aTHX_ must_have_label);
2329 else if (PL_op->op_flags & OPf_SPECIAL) {
2331 DIE(aTHX_ must_have_label);
2334 label = cPVOP->op_pv;
2336 if (label && *label) {
2338 bool leaving_eval = FALSE;
2339 bool in_block = FALSE;
2340 PERL_CONTEXT *last_eval_cx = 0;
2344 PL_lastgotoprobe = 0;
2346 for (ix = cxstack_ix; ix >= 0; ix--) {
2348 switch (CxTYPE(cx)) {
2350 leaving_eval = TRUE;
2351 if (CxREALEVAL(cx)) {
2352 gotoprobe = (last_eval_cx ?
2353 last_eval_cx->blk_eval.old_eval_root :
2358 /* else fall through */
2360 gotoprobe = cx->blk_oldcop->op_sibling;
2366 gotoprobe = cx->blk_oldcop->op_sibling;
2369 gotoprobe = PL_main_root;
2372 if (CvDEPTH(cx->blk_sub.cv)) {
2373 gotoprobe = CvROOT(cx->blk_sub.cv);
2379 DIE(aTHX_ "Can't \"goto\" out of a pseudo block");
2382 DIE(aTHX_ "panic: goto");
2383 gotoprobe = PL_main_root;
2387 retop = dofindlabel(gotoprobe, label,
2388 enterops, enterops + GOTO_DEPTH);
2392 PL_lastgotoprobe = gotoprobe;
2395 DIE(aTHX_ "Can't find label %s", label);
2397 /* if we're leaving an eval, check before we pop any frames
2398 that we're not going to punt, otherwise the error
2401 if (leaving_eval && *enterops && enterops[1]) {
2403 for (i = 1; enterops[i]; i++)
2404 if (enterops[i]->op_type == OP_ENTERITER)
2405 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2408 /* pop unwanted frames */
2410 if (ix < cxstack_ix) {
2417 oldsave = PL_scopestack[PL_scopestack_ix];
2418 LEAVE_SCOPE(oldsave);
2421 /* push wanted frames */
2423 if (*enterops && enterops[1]) {
2425 ix = enterops[1]->op_type == OP_ENTER && in_block ? 2 : 1;
2426 for (; enterops[ix]; ix++) {
2427 PL_op = enterops[ix];
2428 /* Eventually we may want to stack the needed arguments
2429 * for each op. For now, we punt on the hard ones. */
2430 if (PL_op->op_type == OP_ENTERITER)
2431 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2432 CALL_FPTR(PL_op->op_ppaddr)(aTHX);
2440 if (!retop) retop = PL_main_start;
2442 PL_restartop = retop;
2443 PL_do_undump = TRUE;
2447 PL_restartop = 0; /* hmm, must be GNU unexec().. */
2448 PL_do_undump = FALSE;
2464 if (anum == 1 && (PL_op->op_private & OPpEXIT_VMSISH))
2466 VMSISH_HUSHED = VMSISH_HUSHED || (PL_op->op_private & OPpHUSH_VMSISH);
2469 PL_exit_flags |= PERL_EXIT_EXPECTED;
2471 PUSHs(&PL_sv_undef);
2479 NV value = SvNVx(GvSV(cCOP->cop_gv));
2480 register I32 match = I_32(value);
2483 if (((NV)match) > value)
2484 --match; /* was fractional--truncate other way */
2486 match -= cCOP->uop.scop.scop_offset;
2489 else if (match > cCOP->uop.scop.scop_max)
2490 match = cCOP->uop.scop.scop_max;
2491 PL_op = cCOP->uop.scop.scop_next[match];
2501 PL_op = PL_op->op_next; /* can't assume anything */
2504 match = *(SvPVx(GvSV(cCOP->cop_gv), n_a)) & 255;
2505 match -= cCOP->uop.scop.scop_offset;
2508 else if (match > cCOP->uop.scop.scop_max)
2509 match = cCOP->uop.scop.scop_max;
2510 PL_op = cCOP->uop.scop.scop_next[match];
2519 S_save_lines(pTHX_ AV *array, SV *sv)
2521 register char *s = SvPVX(sv);
2522 register char *send = SvPVX(sv) + SvCUR(sv);
2524 register I32 line = 1;
2526 while (s && s < send) {
2527 SV *tmpstr = NEWSV(85,0);
2529 sv_upgrade(tmpstr, SVt_PVMG);
2530 t = strchr(s, '\n');
2536 sv_setpvn(tmpstr, s, t - s);
2537 av_store(array, line++, tmpstr);
2542 #ifdef PERL_FLEXIBLE_EXCEPTIONS
2544 S_docatch_body(pTHX_ va_list args)
2546 return docatch_body();
2551 S_docatch_body(pTHX)
2558 S_docatch(pTHX_ OP *o)
2563 volatile PERL_SI *cursi = PL_curstackinfo;
2567 assert(CATCH_GET == TRUE);
2571 /* Normally, the leavetry at the end of this block of ops will
2572 * pop an op off the return stack and continue there. By setting
2573 * the op to Nullop, we force an exit from the inner runops()
2576 retop = pop_return();
2577 push_return(Nullop);
2579 #ifdef PERL_FLEXIBLE_EXCEPTIONS
2581 CALLPROTECT(aTHX_ pcur_env, &ret, MEMBER_TO_FPTR(S_docatch_body));
2587 #ifndef PERL_FLEXIBLE_EXCEPTIONS
2593 /* die caught by an inner eval - continue inner loop */
2594 if (PL_restartop && cursi == PL_curstackinfo) {
2595 PL_op = PL_restartop;
2599 /* a die in this eval - continue in outer loop */
2615 Perl_sv_compile_2op(pTHX_ SV *sv, OP** startop, char *code, PAD** padp)
2616 /* sv Text to convert to OP tree. */
2617 /* startop op_free() this to undo. */
2618 /* code Short string id of the caller. */
2620 dSP; /* Make POPBLOCK work. */
2623 I32 gimme = 0; /* SUSPECT - INITIALZE TO WHAT? NI-S */
2627 char tbuf[TYPE_DIGITS(long) + 12 + 10];
2628 char *tmpbuf = tbuf;
2631 CV* runcv = Nullcv; /* initialise to avoid compiler warnings */
2636 /* switch to eval mode */
2638 if (PL_curcop == &PL_compiling) {
2639 SAVECOPSTASH_FREE(&PL_compiling);
2640 CopSTASH_set(&PL_compiling, PL_curstash);
2642 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
2643 SV *sv = sv_newmortal();
2644 Perl_sv_setpvf(aTHX_ sv, "_<(%.10seval %lu)[%s:%"IVdf"]",
2645 code, (unsigned long)++PL_evalseq,
2646 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
2650 sprintf(tmpbuf, "_<(%.10s_eval %lu)", code, (unsigned long)++PL_evalseq);
2651 SAVECOPFILE_FREE(&PL_compiling);
2652 CopFILE_set(&PL_compiling, tmpbuf+2);
2653 SAVECOPLINE(&PL_compiling);
2654 CopLINE_set(&PL_compiling, 1);
2655 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2656 deleting the eval's FILEGV from the stash before gv_check() runs
2657 (i.e. before run-time proper). To work around the coredump that
2658 ensues, we always turn GvMULTI_on for any globals that were
2659 introduced within evals. See force_ident(). GSAR 96-10-12 */
2660 safestr = savepv(tmpbuf);
2661 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
2663 #ifdef OP_IN_REGISTER
2668 PL_hints &= HINT_UTF8;
2670 /* we get here either during compilation, or via pp_regcomp at runtime */
2671 runtime = PL_op && (PL_op->op_type == OP_REGCOMP);
2673 runcv = find_runcv(NULL);
2676 PL_op->op_type = OP_ENTEREVAL;
2677 PL_op->op_flags = 0; /* Avoid uninit warning. */
2678 PUSHBLOCK(cx, CXt_EVAL|(PL_curcop == &PL_compiling ? 0 : CXp_REAL), SP);
2679 PUSHEVAL(cx, 0, Nullgv);
2682 rop = doeval(G_SCALAR, startop, runcv, PL_curcop->cop_seq);
2684 rop = doeval(G_SCALAR, startop, PL_compcv, PL_cop_seqmax);
2685 POPBLOCK(cx,PL_curpm);
2688 (*startop)->op_type = OP_NULL;
2689 (*startop)->op_ppaddr = PL_ppaddr[OP_NULL];
2691 /* XXX DAPM do this properly one year */
2692 *padp = (AV*)SvREFCNT_inc(PL_comppad);
2694 if (PL_curcop == &PL_compiling)
2695 PL_compiling.op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);
2696 #ifdef OP_IN_REGISTER
2704 =for apidoc find_runcv
2706 Locate the CV corresponding to the currently executing sub or eval.
2707 If db_seqp is non_null, skip CVs that are in the DB package and populate
2708 *db_seqp with the cop sequence number at the point that the DB:: code was
2709 entered. (allows debuggers to eval in the scope of the breakpoint rather
2710 than in in the scope of the debuger itself).
2716 Perl_find_runcv(pTHX_ U32 *db_seqp)
2723 *db_seqp = PL_curcop->cop_seq;
2724 for (si = PL_curstackinfo; si; si = si->si_prev) {
2725 for (ix = si->si_cxix; ix >= 0; ix--) {
2726 cx = &(si->si_cxstack[ix]);
2727 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
2728 CV *cv = cx->blk_sub.cv;
2729 /* skip DB:: code */
2730 if (db_seqp && PL_debstash && CvSTASH(cv) == PL_debstash) {
2731 *db_seqp = cx->blk_oldcop->cop_seq;
2736 else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx))
2744 /* Compile a require/do, an eval '', or a /(?{...})/.
2745 * In the last case, startop is non-null, and contains the address of
2746 * a pointer that should be set to the just-compiled code.
2747 * outside is the lexically enclosing CV (if any) that invoked us.
2750 /* With USE_5005THREADS, eval_owner must be held on entry to doeval */
2752 S_doeval(pTHX_ int gimme, OP** startop, CV* outside, U32 seq)
2757 PL_in_eval = ((saveop && saveop->op_type == OP_REQUIRE)
2758 ? (EVAL_INREQUIRE | (PL_in_eval & EVAL_INEVAL))
2763 SAVESPTR(PL_compcv);
2764 PL_compcv = (CV*)NEWSV(1104,0);
2765 sv_upgrade((SV *)PL_compcv, SVt_PVCV);
2766 CvEVAL_on(PL_compcv);
2767 assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
2768 cxstack[cxstack_ix].blk_eval.cv = PL_compcv;
2770 #ifdef USE_5005THREADS
2771 CvOWNER(PL_compcv) = 0;
2772 New(666, CvMUTEXP(PL_compcv), 1, perl_mutex);
2773 MUTEX_INIT(CvMUTEXP(PL_compcv));
2774 #endif /* USE_5005THREADS */
2776 CvOUTSIDE_SEQ(PL_compcv) = seq;
2777 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outside);
2779 /* set up a scratch pad */
2781 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE);
2784 SAVEMORTALIZESV(PL_compcv); /* must remain until end of current statement */
2786 /* make sure we compile in the right package */
2788 if (CopSTASH_ne(PL_curcop, PL_curstash)) {
2789 SAVESPTR(PL_curstash);
2790 PL_curstash = CopSTASH(PL_curcop);
2792 SAVESPTR(PL_beginav);
2793 PL_beginav = newAV();
2794 SAVEFREESV(PL_beginav);
2795 SAVEI32(PL_error_count);
2797 /* try to compile it */
2799 PL_eval_root = Nullop;
2801 PL_curcop = &PL_compiling;
2802 PL_curcop->cop_arybase = 0;
2803 if (saveop && saveop->op_flags & OPf_SPECIAL)
2804 PL_in_eval |= EVAL_KEEPERR;
2807 if (yyparse() || PL_error_count || !PL_eval_root) {
2811 I32 optype = 0; /* Might be reset by POPEVAL. */
2816 op_free(PL_eval_root);
2817 PL_eval_root = Nullop;
2819 SP = PL_stack_base + POPMARK; /* pop original mark */
2821 POPBLOCK(cx,PL_curpm);
2827 if (optype == OP_REQUIRE) {
2828 char* msg = SvPVx(ERRSV, n_a);
2829 DIE(aTHX_ "%sCompilation failed in require",
2830 *msg ? msg : "Unknown error\n");
2833 char* msg = SvPVx(ERRSV, n_a);
2835 POPBLOCK(cx,PL_curpm);
2837 Perl_croak(aTHX_ "%sCompilation failed in regexp",
2838 (*msg ? msg : "Unknown error\n"));
2841 char* msg = SvPVx(ERRSV, n_a);
2843 sv_setpv(ERRSV, "Compilation error");
2846 #ifdef USE_5005THREADS
2847 MUTEX_LOCK(&PL_eval_mutex);
2849 COND_SIGNAL(&PL_eval_cond);
2850 MUTEX_UNLOCK(&PL_eval_mutex);
2851 #endif /* USE_5005THREADS */
2854 CopLINE_set(&PL_compiling, 0);
2856 *startop = PL_eval_root;
2858 SAVEFREEOP(PL_eval_root);
2860 scalarvoid(PL_eval_root);
2861 else if (gimme & G_ARRAY)
2864 scalar(PL_eval_root);
2866 DEBUG_x(dump_eval());
2868 /* Register with debugger: */
2869 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2870 CV *cv = get_cv("DB::postponed", FALSE);
2874 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2876 call_sv((SV*)cv, G_DISCARD);
2880 /* compiled okay, so do it */
2882 CvDEPTH(PL_compcv) = 1;
2883 SP = PL_stack_base + POPMARK; /* pop original mark */
2884 PL_op = saveop; /* The caller may need it. */
2885 PL_lex_state = LEX_NOTPARSING; /* $^S needs this. */
2886 #ifdef USE_5005THREADS
2887 MUTEX_LOCK(&PL_eval_mutex);
2889 COND_SIGNAL(&PL_eval_cond);
2890 MUTEX_UNLOCK(&PL_eval_mutex);
2891 #endif /* USE_5005THREADS */
2893 RETURNOP(PL_eval_start);
2897 S_doopen_pmc(pTHX_ const char *name, const char *mode)
2899 STRLEN namelen = strlen(name);
2902 if (namelen > 3 && strEQ(name + namelen - 3, ".pm")) {
2903 SV *pmcsv = Perl_newSVpvf(aTHX_ "%s%c", name, 'c');
2904 char *pmc = SvPV_nolen(pmcsv);
2907 if (PerlLIO_stat(pmc, &pmcstat) < 0) {
2908 fp = PerlIO_open(name, mode);
2911 if (PerlLIO_stat(name, &pmstat) < 0 ||
2912 pmstat.st_mtime < pmcstat.st_mtime)
2914 fp = PerlIO_open(pmc, mode);
2917 fp = PerlIO_open(name, mode);
2920 SvREFCNT_dec(pmcsv);
2923 fp = PerlIO_open(name, mode);
2931 register PERL_CONTEXT *cx;
2935 char *tryname = Nullch;
2936 SV *namesv = Nullsv;
2938 I32 gimme = GIMME_V;
2939 PerlIO *tryrsfp = 0;
2941 int filter_has_file = 0;
2942 GV *filter_child_proc = 0;
2943 SV *filter_state = 0;
2950 if (SvNIOKp(sv) && PL_op->op_type != OP_DOFILE) {
2951 if (SvPOK(sv) && SvNOK(sv) && SvNV(sv)) { /* require v5.6.1 */
2952 UV rev = 0, ver = 0, sver = 0;
2954 U8 *s = (U8*)SvPVX(sv);
2955 U8 *end = (U8*)SvPVX(sv) + SvCUR(sv);
2957 rev = utf8n_to_uvchr(s, end - s, &len, 0);
2960 ver = utf8n_to_uvchr(s, end - s, &len, 0);
2963 sver = utf8n_to_uvchr(s, end - s, &len, 0);
2966 if (PERL_REVISION < rev
2967 || (PERL_REVISION == rev
2968 && (PERL_VERSION < ver
2969 || (PERL_VERSION == ver
2970 && PERL_SUBVERSION < sver))))
2972 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--this is only "
2973 "v%d.%d.%d, stopped", rev, ver, sver, PERL_REVISION,
2974 PERL_VERSION, PERL_SUBVERSION);
2976 if (ckWARN(WARN_PORTABLE))
2977 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
2978 "v-string in use/require non-portable");
2981 else if (!SvPOKp(sv)) { /* require 5.005_03 */
2982 if ((NV)PERL_REVISION + ((NV)PERL_VERSION/(NV)1000)
2983 + ((NV)PERL_SUBVERSION/(NV)1000000)
2984 + 0.00000099 < SvNV(sv))
2988 NV nver = (nrev - rev) * 1000;
2989 UV ver = (UV)(nver + 0.0009);
2990 NV nsver = (nver - ver) * 1000;
2991 UV sver = (UV)(nsver + 0.0009);
2993 /* help out with the "use 5.6" confusion */
2994 if (sver == 0 && (rev > 5 || (rev == 5 && ver >= 100))) {
2995 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required"
2996 " (did you mean v%"UVuf".%03"UVuf"?)--"
2997 "this is only v%d.%d.%d, stopped",
2998 rev, ver, sver, rev, ver/100,
2999 PERL_REVISION, PERL_VERSION, PERL_SUBVERSION);
3002 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--"
3003 "this is only v%d.%d.%d, stopped",
3004 rev, ver, sver, PERL_REVISION, PERL_VERSION,
3011 name = SvPV(sv, len);
3012 if (!(name && len > 0 && *name))
3013 DIE(aTHX_ "Null filename used");
3014 TAINT_PROPER("require");
3015 if (PL_op->op_type == OP_REQUIRE &&
3016 (svp = hv_fetch(GvHVn(PL_incgv), name, len, 0)) &&
3017 *svp != &PL_sv_undef)
3020 /* prepare to compile file */
3022 if (path_is_absolute(name)) {
3024 tryrsfp = doopen_pmc(name,PERL_SCRIPT_MODE);
3026 #ifdef MACOS_TRADITIONAL
3030 MacPerl_CanonDir(name, newname, 1);
3031 if (path_is_absolute(newname)) {
3033 tryrsfp = doopen_pmc(newname,PERL_SCRIPT_MODE);
3038 AV *ar = GvAVn(PL_incgv);
3042 if ((unixname = tounixspec(name, Nullch)) != Nullch)
3045 namesv = NEWSV(806, 0);
3046 for (i = 0; i <= AvFILL(ar); i++) {
3047 SV *dirsv = *av_fetch(ar, i, TRUE);
3053 if (SvTYPE(SvRV(loader)) == SVt_PVAV
3054 && !sv_isobject(loader))
3056 loader = *av_fetch((AV *)SvRV(loader), 0, TRUE);
3059 Perl_sv_setpvf(aTHX_ namesv, "/loader/0x%"UVxf"/%s",
3060 PTR2UV(SvRV(dirsv)), name);
3061 tryname = SvPVX(namesv);
3072 if (sv_isobject(loader))
3073 count = call_method("INC", G_ARRAY);
3075 count = call_sv(loader, G_ARRAY);
3085 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVGV) {
3089 if (SvTYPE(arg) == SVt_PVGV) {
3090 IO *io = GvIO((GV *)arg);
3095 tryrsfp = IoIFP(io);
3096 if (IoTYPE(io) == IoTYPE_PIPE) {
3097 /* reading from a child process doesn't
3098 nest -- when returning from reading
3099 the inner module, the outer one is
3100 unreadable (closed?) I've tried to
3101 save the gv to manage the lifespan of
3102 the pipe, but this didn't help. XXX */
3103 filter_child_proc = (GV *)arg;
3104 (void)SvREFCNT_inc(filter_child_proc);
3107 if (IoOFP(io) && IoOFP(io) != IoIFP(io)) {
3108 PerlIO_close(IoOFP(io));
3120 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVCV) {
3122 (void)SvREFCNT_inc(filter_sub);
3125 filter_state = SP[i];
3126 (void)SvREFCNT_inc(filter_state);
3130 tryrsfp = PerlIO_open("/dev/null",
3145 filter_has_file = 0;
3146 if (filter_child_proc) {
3147 SvREFCNT_dec(filter_child_proc);
3148 filter_child_proc = 0;
3151 SvREFCNT_dec(filter_state);
3155 SvREFCNT_dec(filter_sub);
3160 if (!path_is_absolute(name)
3161 #ifdef MACOS_TRADITIONAL
3162 /* We consider paths of the form :a:b ambiguous and interpret them first
3163 as global then as local
3165 || (*name == ':' && name[1] != ':' && strchr(name+2, ':'))
3168 char *dir = SvPVx(dirsv, n_a);
3169 #ifdef MACOS_TRADITIONAL
3173 MacPerl_CanonDir(name, buf2, 1);
3174 Perl_sv_setpvf(aTHX_ namesv, "%s%s", MacPerl_CanonDir(dir, buf1, 0), buf2+(buf2[0] == ':'));
3178 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
3180 sv_setpv(namesv, unixdir);
3181 sv_catpv(namesv, unixname);
3183 Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name);
3186 TAINT_PROPER("require");
3187 tryname = SvPVX(namesv);
3188 tryrsfp = doopen_pmc(tryname, PERL_SCRIPT_MODE);
3190 if (tryname[0] == '.' && tryname[1] == '/')
3199 SAVECOPFILE_FREE(&PL_compiling);
3200 CopFILE_set(&PL_compiling, tryrsfp ? tryname : name);
3201 SvREFCNT_dec(namesv);
3203 if (PL_op->op_type == OP_REQUIRE) {
3204 char *msgstr = name;
3205 if (namesv) { /* did we lookup @INC? */
3206 SV *msg = sv_2mortal(newSVpv(msgstr,0));
3207 SV *dirmsgsv = NEWSV(0, 0);
3208 AV *ar = GvAVn(PL_incgv);
3210 sv_catpvn(msg, " in @INC", 8);
3211 if (instr(SvPVX(msg), ".h "))
3212 sv_catpv(msg, " (change .h to .ph maybe?)");
3213 if (instr(SvPVX(msg), ".ph "))
3214 sv_catpv(msg, " (did you run h2ph?)");
3215 sv_catpv(msg, " (@INC contains:");
3216 for (i = 0; i <= AvFILL(ar); i++) {
3217 char *dir = SvPVx(*av_fetch(ar, i, TRUE), n_a);
3218 Perl_sv_setpvf(aTHX_ dirmsgsv, " %s", dir);
3219 sv_catsv(msg, dirmsgsv);
3221 sv_catpvn(msg, ")", 1);
3222 SvREFCNT_dec(dirmsgsv);
3223 msgstr = SvPV_nolen(msg);
3225 DIE(aTHX_ "Can't locate %s", msgstr);
3231 SETERRNO(0, SS_NORMAL);
3233 /* Assume success here to prevent recursive requirement. */
3235 /* Check whether a hook in @INC has already filled %INC */
3236 if (!hook_sv || !(svp = hv_fetch(GvHVn(PL_incgv), name, len, 0))) {
3237 (void)hv_store(GvHVn(PL_incgv), name, len,
3238 (hook_sv ? SvREFCNT_inc(hook_sv)
3239 : newSVpv(CopFILE(&PL_compiling), 0)),
3245 lex_start(sv_2mortal(newSVpvn("",0)));
3246 SAVEGENERICSV(PL_rsfp_filters);
3247 PL_rsfp_filters = Nullav;
3252 SAVESPTR(PL_compiling.cop_warnings);
3253 if (PL_dowarn & G_WARN_ALL_ON)
3254 PL_compiling.cop_warnings = pWARN_ALL ;
3255 else if (PL_dowarn & G_WARN_ALL_OFF)
3256 PL_compiling.cop_warnings = pWARN_NONE ;
3257 else if (PL_taint_warn)
3258 PL_compiling.cop_warnings = newSVpvn(WARN_TAINTstring, WARNsize);
3260 PL_compiling.cop_warnings = pWARN_STD ;
3261 SAVESPTR(PL_compiling.cop_io);
3262 PL_compiling.cop_io = Nullsv;
3264 if (filter_sub || filter_child_proc) {
3265 SV *datasv = filter_add(run_user_filter, Nullsv);
3266 IoLINES(datasv) = filter_has_file;
3267 IoFMT_GV(datasv) = (GV *)filter_child_proc;
3268 IoTOP_GV(datasv) = (GV *)filter_state;
3269 IoBOTTOM_GV(datasv) = (GV *)filter_sub;
3272 /* switch to eval mode */
3273 push_return(PL_op->op_next);
3274 PUSHBLOCK(cx, CXt_EVAL, SP);
3275 PUSHEVAL(cx, name, Nullgv);
3277 SAVECOPLINE(&PL_compiling);
3278 CopLINE_set(&PL_compiling, 0);
3281 #ifdef USE_5005THREADS
3282 MUTEX_LOCK(&PL_eval_mutex);
3283 if (PL_eval_owner && PL_eval_owner != thr)
3284 while (PL_eval_owner)
3285 COND_WAIT(&PL_eval_cond, &PL_eval_mutex);
3286 PL_eval_owner = thr;
3287 MUTEX_UNLOCK(&PL_eval_mutex);
3288 #endif /* USE_5005THREADS */
3290 /* Store and reset encoding. */
3291 encoding = PL_encoding;
3292 PL_encoding = Nullsv;
3294 op = DOCATCH(doeval(gimme, NULL, Nullcv, PL_curcop->cop_seq));
3296 /* Restore encoding. */
3297 PL_encoding = encoding;
3304 return pp_require();
3310 register PERL_CONTEXT *cx;
3312 I32 gimme = GIMME_V, was = PL_sub_generation;
3313 char tbuf[TYPE_DIGITS(long) + 12];
3314 char *tmpbuf = tbuf;
3323 TAINT_PROPER("eval");
3329 /* switch to eval mode */
3331 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
3332 SV *sv = sv_newmortal();
3333 Perl_sv_setpvf(aTHX_ sv, "_<(eval %lu)[%s:%"IVdf"]",
3334 (unsigned long)++PL_evalseq,
3335 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
3339 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++PL_evalseq);
3340 SAVECOPFILE_FREE(&PL_compiling);
3341 CopFILE_set(&PL_compiling, tmpbuf+2);
3342 SAVECOPLINE(&PL_compiling);
3343 CopLINE_set(&PL_compiling, 1);
3344 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
3345 deleting the eval's FILEGV from the stash before gv_check() runs
3346 (i.e. before run-time proper). To work around the coredump that
3347 ensues, we always turn GvMULTI_on for any globals that were
3348 introduced within evals. See force_ident(). GSAR 96-10-12 */
3349 safestr = savepv(tmpbuf);
3350 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
3352 PL_hints = PL_op->op_targ;
3353 SAVESPTR(PL_compiling.cop_warnings);
3354 if (specialWARN(PL_curcop->cop_warnings))
3355 PL_compiling.cop_warnings = PL_curcop->cop_warnings;
3357 PL_compiling.cop_warnings = newSVsv(PL_curcop->cop_warnings);
3358 SAVEFREESV(PL_compiling.cop_warnings);
3360 SAVESPTR(PL_compiling.cop_io);
3361 if (specialCopIO(PL_curcop->cop_io))
3362 PL_compiling.cop_io = PL_curcop->cop_io;
3364 PL_compiling.cop_io = newSVsv(PL_curcop->cop_io);
3365 SAVEFREESV(PL_compiling.cop_io);
3367 /* special case: an eval '' executed within the DB package gets lexically
3368 * placed in the first non-DB CV rather than the current CV - this
3369 * allows the debugger to execute code, find lexicals etc, in the
3370 * scope of the code being debugged. Passing &seq gets find_runcv
3371 * to do the dirty work for us */
3372 runcv = find_runcv(&seq);
3374 push_return(PL_op->op_next);
3375 PUSHBLOCK(cx, (CXt_EVAL|CXp_REAL), SP);
3376 PUSHEVAL(cx, 0, Nullgv);
3378 /* prepare to compile string */
3380 if (PERLDB_LINE && PL_curstash != PL_debstash)
3381 save_lines(CopFILEAV(&PL_compiling), PL_linestr);
3383 #ifdef USE_5005THREADS
3384 MUTEX_LOCK(&PL_eval_mutex);
3385 if (PL_eval_owner && PL_eval_owner != thr)
3386 while (PL_eval_owner)
3387 COND_WAIT(&PL_eval_cond, &PL_eval_mutex);
3388 PL_eval_owner = thr;
3389 MUTEX_UNLOCK(&PL_eval_mutex);
3390 #endif /* USE_5005THREADS */
3391 ret = doeval(gimme, NULL, runcv, seq);
3392 if (PERLDB_INTER && was != (I32)PL_sub_generation /* Some subs defined here. */
3393 && ret != PL_op->op_next) { /* Successive compilation. */
3394 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
3396 return DOCATCH(ret);
3406 register PERL_CONTEXT *cx;
3408 U8 save_flags = PL_op -> op_flags;
3413 retop = pop_return();
3416 if (gimme == G_VOID)
3418 else if (gimme == G_SCALAR) {
3421 if (SvFLAGS(TOPs) & SVs_TEMP)
3424 *MARK = sv_mortalcopy(TOPs);
3428 *MARK = &PL_sv_undef;
3433 /* in case LEAVE wipes old return values */
3434 for (mark = newsp + 1; mark <= SP; mark++) {
3435 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
3436 *mark = sv_mortalcopy(*mark);
3437 TAINT_NOT; /* Each item is independent */
3441 PL_curpm = newpm; /* Don't pop $1 et al till now */
3444 assert(CvDEPTH(PL_compcv) == 1);
3446 CvDEPTH(PL_compcv) = 0;
3449 if (optype == OP_REQUIRE &&
3450 !(gimme == G_SCALAR ? SvTRUE(*SP) : SP > newsp))
3452 /* Unassume the success we assumed earlier. */
3453 SV *nsv = cx->blk_eval.old_namesv;
3454 (void)hv_delete(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), G_DISCARD);
3455 retop = Perl_die(aTHX_ "%"SVf" did not return a true value", nsv);
3456 /* die_where() did LEAVE, or we won't be here */
3460 if (!(save_flags & OPf_SPECIAL))
3470 register PERL_CONTEXT *cx;
3471 I32 gimme = GIMME_V;
3476 push_return(cLOGOP->op_other->op_next);
3477 PUSHBLOCK(cx, (CXt_EVAL|CXp_TRYBLOCK), SP);
3480 PL_in_eval = EVAL_INEVAL;
3483 return DOCATCH(PL_op->op_next);
3494 register PERL_CONTEXT *cx;
3499 retop = pop_return();
3502 if (gimme == G_VOID)
3504 else if (gimme == G_SCALAR) {
3507 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
3510 *MARK = sv_mortalcopy(TOPs);
3514 *MARK = &PL_sv_undef;
3519 /* in case LEAVE wipes old return values */
3520 for (mark = newsp + 1; mark <= SP; mark++) {
3521 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
3522 *mark = sv_mortalcopy(*mark);
3523 TAINT_NOT; /* Each item is independent */
3527 PL_curpm = newpm; /* Don't pop $1 et al till now */
3535 S_doparseform(pTHX_ SV *sv)
3538 register char *s = SvPV_force(sv, len);
3539 register char *send = s + len;
3540 register char *base = Nullch;
3541 register I32 skipspaces = 0;
3542 bool noblank = FALSE;
3543 bool repeat = FALSE;
3544 bool postspace = FALSE;
3552 Perl_croak(aTHX_ "Null picture in formline");
3554 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
3559 *fpc++ = FF_LINEMARK;
3560 noblank = repeat = FALSE;
3578 case ' ': case '\t':
3589 *fpc++ = FF_LITERAL;
3597 *fpc++ = (U16)skipspaces;
3601 *fpc++ = FF_NEWLINE;
3605 arg = fpc - linepc + 1;
3612 *fpc++ = FF_LINEMARK;
3613 noblank = repeat = FALSE;
3622 ischop = s[-1] == '^';
3628 arg = (s - base) - 1;
3630 *fpc++ = FF_LITERAL;
3639 *fpc++ = FF_LINEGLOB;
3641 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
3642 arg = ischop ? 512 : 0;
3652 arg |= 256 + (s - f);
3654 *fpc++ = s - base; /* fieldsize for FETCH */
3655 *fpc++ = FF_DECIMAL;
3658 else if (*s == '0' && s[1] == '#') { /* Zero padded decimals */
3659 arg = ischop ? 512 : 0;
3661 s++; /* skip the '0' first */
3670 arg |= 256 + (s - f);
3672 *fpc++ = s - base; /* fieldsize for FETCH */
3673 *fpc++ = FF_0DECIMAL;
3678 bool ismore = FALSE;
3681 while (*++s == '>') ;
3682 prespace = FF_SPACE;
3684 else if (*s == '|') {
3685 while (*++s == '|') ;
3686 prespace = FF_HALFSPACE;
3691 while (*++s == '<') ;
3694 if (*s == '.' && s[1] == '.' && s[2] == '.') {
3698 *fpc++ = s - base; /* fieldsize for FETCH */
3700 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
3703 *fpc++ = (U16)prespace;
3718 { /* need to jump to the next word */
3720 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
3721 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
3722 s = SvPVX(sv) + SvCUR(sv) + z;
3724 Copy(fops, s, arg, U16);
3726 sv_magic(sv, Nullsv, PERL_MAGIC_fm, Nullch, 0);
3731 run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen)
3733 SV *datasv = FILTER_DATA(idx);
3734 int filter_has_file = IoLINES(datasv);
3735 GV *filter_child_proc = (GV *)IoFMT_GV(datasv);
3736 SV *filter_state = (SV *)IoTOP_GV(datasv);
3737 SV *filter_sub = (SV *)IoBOTTOM_GV(datasv);
3740 /* I was having segfault trouble under Linux 2.2.5 after a
3741 parse error occured. (Had to hack around it with a test
3742 for PL_error_count == 0.) Solaris doesn't segfault --
3743 not sure where the trouble is yet. XXX */
3745 if (filter_has_file) {
3746 len = FILTER_READ(idx+1, buf_sv, maxlen);
3749 if (filter_sub && len >= 0) {
3760 PUSHs(sv_2mortal(newSViv(maxlen)));
3762 PUSHs(filter_state);
3765 count = call_sv(filter_sub, G_SCALAR);
3781 IoLINES(datasv) = 0;
3782 if (filter_child_proc) {
3783 SvREFCNT_dec(filter_child_proc);
3784 IoFMT_GV(datasv) = Nullgv;
3787 SvREFCNT_dec(filter_state);
3788 IoTOP_GV(datasv) = Nullgv;
3791 SvREFCNT_dec(filter_sub);
3792 IoBOTTOM_GV(datasv) = Nullgv;
3794 filter_del(run_user_filter);
3800 /* perhaps someone can come up with a better name for
3801 this? it is not really "absolute", per se ... */
3803 S_path_is_absolute(pTHX_ char *name)
3805 if (PERL_FILE_IS_ABSOLUTE(name)
3806 #ifdef MACOS_TRADITIONAL
3809 || (*name == '.' && (name[1] == '/' ||
3810 (name[1] == '.' && name[2] == '/'))))