3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, 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.
20 /* This file contains control-oriented pp ("push/pop") functions that
21 * execute the opcodes that make up a perl program. A typical pp function
22 * expects to find its arguments on the stack, and usually pushes its
23 * results onto the stack, hence the 'pp' terminology. Each OP structure
24 * contains a pointer to the relevant pp_foo() function.
26 * Control-oriented means things like pp_enteriter() and pp_next(), which
27 * alter the flow of control of the program.
32 #define PERL_IN_PP_CTL_C
36 #define WORD_ALIGN sizeof(U32)
39 #define DOCATCH(o) ((CATCH_GET == TRUE) ? docatch(o) : (o))
41 static I32 run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen);
49 cxix = dopoptosub(cxstack_ix);
53 switch (cxstack[cxix].blk_gimme) {
70 /* XXXX Should store the old value to allow for tie/overload - and
71 restore in regcomp, where marked with XXXX. */
80 register PMOP *pm = (PMOP*)cLOGOP->op_other;
82 MAGIC *mg = Null(MAGIC*);
86 /* prevent recompiling under /o and ithreads. */
87 #if defined(USE_ITHREADS) || defined(USE_5005THREADS)
88 if (pm->op_pmflags & PMf_KEEP && PM_GETRE(pm))
93 SV *sv = SvRV(tmpstr);
95 mg = mg_find(sv, PERL_MAGIC_qr);
98 regexp *re = (regexp *)mg->mg_obj;
99 ReREFCNT_dec(PM_GETRE(pm));
100 PM_SETRE(pm, ReREFCNT_inc(re));
104 const char *t = SvPV_const(tmpstr, len);
106 /* Check against the last compiled regexp. */
107 if (!PM_GETRE(pm) || !PM_GETRE(pm)->precomp ||
108 PM_GETRE(pm)->prelen != (I32)len ||
109 memNE(PM_GETRE(pm)->precomp, t, len))
112 ReREFCNT_dec(PM_GETRE(pm));
113 PM_SETRE(pm, Null(REGEXP*)); /* crucial if regcomp aborts */
115 if (PL_op->op_flags & OPf_SPECIAL)
116 PL_reginterp_cnt = I32_MAX; /* Mark as safe. */
118 pm->op_pmflags = pm->op_pmpermflags; /* reset case sensitivity */
120 pm->op_pmdynflags |= PMdf_DYN_UTF8;
122 pm->op_pmdynflags &= ~PMdf_DYN_UTF8;
123 if (pm->op_pmdynflags & PMdf_UTF8)
124 t = (char*)bytes_to_utf8((U8*)t, &len);
126 PM_SETRE(pm, CALLREGCOMP(aTHX_ (char *)t, (char *)t + len, pm));
127 if (!DO_UTF8(tmpstr) && (pm->op_pmdynflags & PMdf_UTF8))
129 PL_reginterp_cnt = 0; /* XXXX Be extra paranoid - needed
130 inside tie/overload accessors. */
134 #ifndef INCOMPLETE_TAINTS
137 pm->op_pmdynflags |= PMdf_TAINTED;
139 pm->op_pmdynflags &= ~PMdf_TAINTED;
143 if (!PM_GETRE(pm)->prelen && PL_curpm)
145 else if (strEQ("\\s+", PM_GETRE(pm)->precomp))
146 pm->op_pmflags |= PMf_WHITE;
148 pm->op_pmflags &= ~PMf_WHITE;
150 /* XXX runtime compiled output needs to move to the pad */
151 if (pm->op_pmflags & PMf_KEEP) {
152 pm->op_private &= ~OPpRUNTIME; /* no point compiling again */
153 #if !defined(USE_ITHREADS) && !defined(USE_5005THREADS)
154 /* XXX can't change the optree at runtime either */
155 cLOGOP->op_first->op_next = PL_op->op_next;
164 register PERL_CONTEXT *cx = &cxstack[cxstack_ix];
165 register PMOP * const pm = (PMOP*) cLOGOP->op_other;
166 register SV * const dstr = cx->sb_dstr;
167 register char *s = cx->sb_s;
168 register char *m = cx->sb_m;
169 char *orig = cx->sb_orig;
170 register REGEXP * const rx = cx->sb_rx;
172 REGEXP *old = PM_GETRE(pm);
179 rxres_restore(&cx->sb_rxres, rx);
180 RX_MATCH_UTF8_set(rx, DO_UTF8(cx->sb_targ));
182 if (cx->sb_iters++) {
183 const I32 saviters = cx->sb_iters;
184 if (cx->sb_iters > cx->sb_maxiters)
185 DIE(aTHX_ "Substitution loop");
187 if (!(cx->sb_rxtainted & 2) && SvTAINTED(TOPs))
188 cx->sb_rxtainted |= 2;
189 sv_catsv(dstr, POPs);
192 if (cx->sb_once || !CALLREGEXEC(aTHX_ rx, s, cx->sb_strend, orig,
193 s == m, cx->sb_targ, NULL,
194 ((cx->sb_rflags & REXEC_COPY_STR)
195 ? (REXEC_IGNOREPOS|REXEC_NOT_FIRST)
196 : (REXEC_COPY_STR|REXEC_IGNOREPOS|REXEC_NOT_FIRST))))
198 SV *targ = cx->sb_targ;
200 assert(cx->sb_strend >= s);
201 if(cx->sb_strend > s) {
202 if (DO_UTF8(dstr) && !SvUTF8(targ))
203 sv_catpvn_utf8_upgrade(dstr, s, cx->sb_strend - s, nsv);
205 sv_catpvn(dstr, s, cx->sb_strend - s);
207 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
210 SvPV_set(targ, SvPVX(dstr));
211 SvCUR_set(targ, SvCUR(dstr));
212 SvLEN_set(targ, SvLEN(dstr));
215 SvPV_set(dstr, (char*)0);
218 TAINT_IF(cx->sb_rxtainted & 1);
219 PUSHs(sv_2mortal(newSViv(saviters - 1)));
221 (void)SvPOK_only_UTF8(targ);
222 TAINT_IF(cx->sb_rxtainted);
226 LEAVE_SCOPE(cx->sb_oldsave);
229 RETURNOP(pm->op_next);
231 cx->sb_iters = saviters;
233 if (RX_MATCH_COPIED(rx) && rx->subbeg != orig) {
236 cx->sb_orig = orig = rx->subbeg;
238 cx->sb_strend = s + (cx->sb_strend - m);
240 cx->sb_m = m = rx->startp[0] + orig;
242 if (DO_UTF8(dstr) && !SvUTF8(cx->sb_targ))
243 sv_catpvn_utf8_upgrade(dstr, s, m - s, nsv);
245 sv_catpvn(dstr, s, m-s);
247 cx->sb_s = rx->endp[0] + orig;
248 { /* Update the pos() information. */
249 SV *sv = cx->sb_targ;
252 if (SvTYPE(sv) < SVt_PVMG)
253 (void)SvUPGRADE(sv, SVt_PVMG);
254 if (!(mg = mg_find(sv, PERL_MAGIC_regex_global))) {
255 sv_magic(sv, Nullsv, PERL_MAGIC_regex_global, Nullch, 0);
256 mg = mg_find(sv, PERL_MAGIC_regex_global);
264 (void)ReREFCNT_inc(rx);
265 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
266 rxres_save(&cx->sb_rxres, rx);
267 RETURNOP(pm->op_pmreplstart);
271 Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx)
276 if (!p || p[1] < rx->nparens) {
277 i = 6 + rx->nparens * 2;
285 *p++ = PTR2UV(RX_MATCH_COPIED(rx) ? rx->subbeg : Nullch);
286 RX_MATCH_COPIED_off(rx);
290 *p++ = PTR2UV(rx->subbeg);
291 *p++ = (UV)rx->sublen;
292 for (i = 0; i <= rx->nparens; ++i) {
293 *p++ = (UV)rx->startp[i];
294 *p++ = (UV)rx->endp[i];
299 Perl_rxres_restore(pTHX_ void **rsp, REGEXP *rx)
304 if (RX_MATCH_COPIED(rx))
305 Safefree(rx->subbeg);
306 RX_MATCH_COPIED_set(rx, *p);
311 rx->subbeg = INT2PTR(char*,*p++);
312 rx->sublen = (I32)(*p++);
313 for (i = 0; i <= rx->nparens; ++i) {
314 rx->startp[i] = (I32)(*p++);
315 rx->endp[i] = (I32)(*p++);
320 Perl_rxres_free(pTHX_ void **rsp)
326 void *tmp = INT2PTR(char*,*p);
329 Poison(*p, 1, sizeof(*p));
331 Safefree(INT2PTR(char*,*p));
340 dSP; dMARK; dORIGMARK;
341 register SV *tmpForm = *++MARK;
346 register SV *sv = Nullsv;
347 const char *item = Nullch;
351 bool chopspace = (strchr(PL_chopset, ' ') != Nullch);
352 const char *chophere = Nullch;
353 char *linemark = Nullch;
355 bool gotsome = FALSE;
357 STRLEN fudge = SvPOK(tmpForm)
358 ? (SvCUR(tmpForm) * (IN_BYTES ? 1 : 3) + 1) : 0;
359 bool item_is_utf8 = FALSE;
360 bool targ_is_utf8 = FALSE;
366 if (!SvMAGICAL(tmpForm) || !SvCOMPILED(tmpForm)) {
367 if (SvREADONLY(tmpForm)) {
368 SvREADONLY_off(tmpForm);
369 parseres = doparseform(tmpForm);
370 SvREADONLY_on(tmpForm);
373 parseres = doparseform(tmpForm);
377 SvPV_force(PL_formtarget, len);
378 if (DO_UTF8(PL_formtarget))
380 t = SvGROW(PL_formtarget, len + fudge + 1); /* XXX SvCUR bad */
382 f = SvPV_const(tmpForm, len);
383 /* need to jump to the next word */
384 fpc = (U32*)(f + len + WORD_ALIGN - SvCUR(tmpForm) % WORD_ALIGN);
388 const char *name = "???";
391 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
392 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
393 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
394 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
395 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
397 case FF_CHECKNL: name = "CHECKNL"; break;
398 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
399 case FF_SPACE: name = "SPACE"; break;
400 case FF_HALFSPACE: name = "HALFSPACE"; break;
401 case FF_ITEM: name = "ITEM"; break;
402 case FF_CHOP: name = "CHOP"; break;
403 case FF_LINEGLOB: name = "LINEGLOB"; break;
404 case FF_NEWLINE: name = "NEWLINE"; break;
405 case FF_MORE: name = "MORE"; break;
406 case FF_LINEMARK: name = "LINEMARK"; break;
407 case FF_END: name = "END"; break;
408 case FF_0DECIMAL: name = "0DECIMAL"; break;
409 case FF_LINESNGL: name = "LINESNGL"; break;
412 PerlIO_printf(Perl_debug_log, "%-16s%ld\n", name, (long) arg);
414 PerlIO_printf(Perl_debug_log, "%-16s\n", name);
425 if (targ_is_utf8 && !SvUTF8(tmpForm)) {
426 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
428 sv_catpvn_utf8_upgrade(PL_formtarget, f, arg, nsv);
429 t = SvEND(PL_formtarget);
432 if (!targ_is_utf8 && DO_UTF8(tmpForm)) {
433 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
435 sv_utf8_upgrade(PL_formtarget);
436 SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
437 t = SvEND(PL_formtarget);
457 if (ckWARN(WARN_SYNTAX))
458 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Not enough format arguments");
465 const char *s = item = SvPV_const(sv, len);
468 itemsize = sv_len_utf8(sv);
469 if (itemsize != (I32)len) {
471 if (itemsize > fieldsize) {
472 itemsize = fieldsize;
473 itembytes = itemsize;
474 sv_pos_u2b(sv, &itembytes, 0);
478 send = chophere = s + itembytes;
488 sv_pos_b2u(sv, &itemsize);
492 item_is_utf8 = FALSE;
493 if (itemsize > fieldsize)
494 itemsize = fieldsize;
495 send = chophere = s + itemsize;
509 const char *s = item = SvPV_const(sv, len);
512 itemsize = sv_len_utf8(sv);
513 if (itemsize != (I32)len) {
515 if (itemsize <= fieldsize) {
516 const char *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 const char *const send = chophere = s + itemsize;
570 itemsize = fieldsize;
571 send = chophere = s + itemsize;
572 while (s < send || (s == send && isSPACE(*s))) {
582 if (strchr(PL_chopset, *s))
587 itemsize = chophere - item;
593 arg = fieldsize - itemsize;
602 arg = fieldsize - itemsize;
613 const char *s = item;
617 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
619 sv_utf8_upgrade(PL_formtarget);
620 SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
621 t = SvEND(PL_formtarget);
625 if (UTF8_IS_CONTINUED(*s)) {
626 STRLEN skip = UTF8SKIP(s);
643 if ( !((*t++ = *s++) & ~31) )
649 if (targ_is_utf8 && !item_is_utf8) {
650 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
652 sv_catpvn_utf8_upgrade(PL_formtarget, s, arg, nsv);
653 for (; t < SvEND(PL_formtarget); t++) {
666 const int ch = *t++ = *s++;
669 if ( !((*t++ = *s++) & ~31) )
678 const char *s = chophere;
680 while (*s && isSPACE(*s))
683 sv_chop(sv,(char *)s);
696 const char *s = item = SvPV_const(sv, len);
698 if ((item_is_utf8 = DO_UTF8(sv)))
699 itemsize = sv_len_utf8(sv);
701 bool chopped = FALSE;
702 const char *const send = s + len;
704 chophere = s + itemsize;
720 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
722 SvUTF8_on(PL_formtarget);
724 SvCUR_set(sv, chophere - item);
725 sv_catsv(PL_formtarget, sv);
726 SvCUR_set(sv, itemsize);
728 sv_catsv(PL_formtarget, sv);
730 SvCUR_set(PL_formtarget, SvCUR(PL_formtarget) - 1);
731 SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
732 t = SvPVX(PL_formtarget) + SvCUR(PL_formtarget);
741 #if defined(USE_LONG_DOUBLE)
742 fmt = (arg & 256) ? "%#0*.*" PERL_PRIfldbl : "%0*.*" PERL_PRIfldbl;
744 fmt = (arg & 256) ? "%#0*.*f" : "%0*.*f";
749 #if defined(USE_LONG_DOUBLE)
750 fmt = (arg & 256) ? "%#*.*" PERL_PRIfldbl : "%*.*" PERL_PRIfldbl;
752 fmt = (arg & 256) ? "%#*.*f" : "%*.*f";
755 /* If the field is marked with ^ and the value is undefined,
757 if ((arg & 512) && !SvOK(sv)) {
765 /* overflow evidence */
766 if (num_overflow(value, fieldsize, arg)) {
772 /* Formats aren't yet marked for locales, so assume "yes". */
774 STORE_NUMERIC_STANDARD_SET_LOCAL();
775 sprintf(t, fmt, (int) fieldsize, (int) arg & 255, value);
776 RESTORE_NUMERIC_STANDARD();
783 while (t-- > linemark && *t == ' ') ;
791 if (arg) { /* repeat until fields exhausted? */
793 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
794 lines += FmLINES(PL_formtarget);
797 if (strnEQ(linemark, linemark - arg, arg))
798 DIE(aTHX_ "Runaway format");
801 SvUTF8_on(PL_formtarget);
802 FmLINES(PL_formtarget) = lines;
804 RETURNOP(cLISTOP->op_first);
815 const char *s = chophere;
816 const char *send = item + len;
818 while (*s && isSPACE(*s) && s < send)
823 arg = fieldsize - itemsize;
830 if (strnEQ(s1," ",3)) {
831 while (s1 > SvPVX_const(PL_formtarget) && isSPACE(s1[-1]))
842 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
844 SvUTF8_on(PL_formtarget);
845 FmLINES(PL_formtarget) += lines;
857 if (PL_stack_base + *PL_markstack_ptr == SP) {
859 if (GIMME_V == G_SCALAR)
860 XPUSHs(sv_2mortal(newSViv(0)));
861 RETURNOP(PL_op->op_next->op_next);
863 PL_stack_sp = PL_stack_base + *PL_markstack_ptr + 1;
864 pp_pushmark(); /* push dst */
865 pp_pushmark(); /* push src */
866 ENTER; /* enter outer scope */
869 /* SAVE_DEFSV does *not* suffice here for USE_5005THREADS */
871 ENTER; /* enter inner scope */
874 src = PL_stack_base[*PL_markstack_ptr];
879 if (PL_op->op_type == OP_MAPSTART)
880 pp_pushmark(); /* push top */
881 return ((LOGOP*)PL_op->op_next)->op_other;
886 DIE(aTHX_ "panic: mapstart"); /* uses grepstart */
892 const I32 gimme = GIMME_V;
893 I32 items = (SP - PL_stack_base) - *PL_markstack_ptr; /* how many new items */
899 /* first, move source pointer to the next item in the source list */
900 ++PL_markstack_ptr[-1];
902 /* if there are new items, push them into the destination list */
903 if (items && gimme != G_VOID) {
904 /* might need to make room back there first */
905 if (items > PL_markstack_ptr[-1] - PL_markstack_ptr[-2]) {
906 /* XXX this implementation is very pessimal because the stack
907 * is repeatedly extended for every set of items. Is possible
908 * to do this without any stack extension or copying at all
909 * by maintaining a separate list over which the map iterates
910 * (like foreach does). --gsar */
912 /* everything in the stack after the destination list moves
913 * towards the end the stack by the amount of room needed */
914 shift = items - (PL_markstack_ptr[-1] - PL_markstack_ptr[-2]);
916 /* items to shift up (accounting for the moved source pointer) */
917 count = (SP - PL_stack_base) - (PL_markstack_ptr[-1] - 1);
919 /* This optimization is by Ben Tilly and it does
920 * things differently from what Sarathy (gsar)
921 * is describing. The downside of this optimization is
922 * that leaves "holes" (uninitialized and hopefully unused areas)
923 * to the Perl stack, but on the other hand this
924 * shouldn't be a problem. If Sarathy's idea gets
925 * implemented, this optimization should become
926 * irrelevant. --jhi */
928 shift = count; /* Avoid shifting too often --Ben Tilly */
933 PL_markstack_ptr[-1] += shift;
934 *PL_markstack_ptr += shift;
938 /* copy the new items down to the destination list */
939 dst = PL_stack_base + (PL_markstack_ptr[-2] += items) - 1;
940 if (gimme == G_ARRAY) {
942 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
945 /* scalar context: we don't care about which values map returns
946 * (we use undef here). And so we certainly don't want to do mortal
947 * copies of meaningless values. */
948 while (items-- > 0) {
950 *dst-- = &PL_sv_undef;
954 LEAVE; /* exit inner scope */
957 if (PL_markstack_ptr[-1] > *PL_markstack_ptr) {
959 (void)POPMARK; /* pop top */
960 LEAVE; /* exit outer scope */
961 (void)POPMARK; /* pop src */
962 items = --*PL_markstack_ptr - PL_markstack_ptr[-1];
963 (void)POPMARK; /* pop dst */
964 SP = PL_stack_base + POPMARK; /* pop original mark */
965 if (gimme == G_SCALAR) {
969 else if (gimme == G_ARRAY)
976 ENTER; /* enter inner scope */
979 /* set $_ to the new source item */
980 src = PL_stack_base[PL_markstack_ptr[-1]];
984 RETURNOP(cLOGOP->op_other);
992 if (GIMME == G_ARRAY)
994 if (SvTRUEx(PAD_SV(PL_op->op_targ)))
995 return cLOGOP->op_other;
1004 if (GIMME == G_ARRAY) {
1005 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
1009 SV *targ = PAD_SV(PL_op->op_targ);
1012 if (PL_op->op_private & OPpFLIP_LINENUM) {
1013 if (GvIO(PL_last_in_gv)) {
1014 flip = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
1017 GV *gv = gv_fetchpv(".", TRUE, SVt_PV);
1018 if (gv && GvSV(gv)) flip = SvIV(sv) == SvIV(GvSV(gv));
1024 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
1025 if (PL_op->op_flags & OPf_SPECIAL) {
1033 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
1036 sv_setpvn(TARG, "", 0);
1042 /* This code tries to decide if "$left .. $right" should use the
1043 magical string increment, or if the range is numeric (we make
1044 an exception for .."0" [#18165]). AMS 20021031. */
1046 #define RANGE_IS_NUMERIC(left,right) ( \
1047 SvNIOKp(left) || (SvOK(left) && !SvPOKp(left)) || \
1048 SvNIOKp(right) || (SvOK(right) && !SvPOKp(right)) || \
1049 (((!SvOK(left) && SvOK(right)) || ((!SvOK(left) || \
1050 looks_like_number(left)) && SvPOKp(left) && *SvPVX_const(left) != '0')) \
1051 && (!SvOK(right) || looks_like_number(right))))
1057 if (GIMME == G_ARRAY) {
1060 if (SvGMAGICAL(left))
1062 if (SvGMAGICAL(right))
1065 if (RANGE_IS_NUMERIC(left,right)) {
1068 if ((SvOK(left) && SvNV(left) < IV_MIN) ||
1069 (SvOK(right) && SvNV(right) > IV_MAX))
1070 DIE(aTHX_ "Range iterator outside integer range");
1081 SV * const sv = sv_2mortal(newSViv(i++));
1086 SV *final = sv_mortalcopy(right);
1088 const char *tmps = SvPV_const(final, len);
1090 SV *sv = sv_mortalcopy(left);
1091 SvPV_force_nolen(sv);
1092 while (!SvNIOKp(sv) && SvCUR(sv) <= len) {
1094 if (strEQ(SvPVX_const(sv),tmps))
1096 sv = sv_2mortal(newSVsv(sv));
1103 SV * const targ = PAD_SV(cUNOP->op_first->op_targ);
1107 if (PL_op->op_private & OPpFLIP_LINENUM) {
1108 if (GvIO(PL_last_in_gv)) {
1109 flop = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
1112 GV * const gv = gv_fetchpv(".", TRUE, SVt_PV);
1113 if (gv && GvSV(gv)) flop = SvIV(sv) == SvIV(GvSV(gv));
1121 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
1122 sv_catpvn(targ, "E0", 2);
1132 static const char * const context_name[] = {
1143 S_dopoptolabel(pTHX_ const char *label)
1147 for (i = cxstack_ix; i >= 0; i--) {
1148 register const PERL_CONTEXT * const cx = &cxstack[i];
1149 switch (CxTYPE(cx)) {
1155 if (ckWARN(WARN_EXITING))
1156 Perl_warner(aTHX_ packWARN(WARN_EXITING), "Exiting %s via %s",
1157 context_name[CxTYPE(cx)], OP_NAME(PL_op));
1158 if (CxTYPE(cx) == CXt_NULL)
1162 if ( !cx->blk_loop.label || strNE(label, cx->blk_loop.label) ) {
1163 DEBUG_l(Perl_deb(aTHX_ "(Skipping label #%ld %s)\n",
1164 (long)i, cx->blk_loop.label));
1167 DEBUG_l( Perl_deb(aTHX_ "(Found label #%ld %s)\n", (long)i, label));
1175 Perl_dowantarray(pTHX)
1177 const I32 gimme = block_gimme();
1178 return (gimme == G_VOID) ? G_SCALAR : gimme;
1182 Perl_block_gimme(pTHX)
1184 const I32 cxix = dopoptosub(cxstack_ix);
1188 switch (cxstack[cxix].blk_gimme) {
1196 Perl_croak(aTHX_ "panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
1203 Perl_is_lvalue_sub(pTHX)
1205 const I32 cxix = dopoptosub(cxstack_ix);
1206 assert(cxix >= 0); /* We should only be called from inside subs */
1208 if (cxstack[cxix].blk_sub.lval && CvLVALUE(cxstack[cxix].blk_sub.cv))
1209 return cxstack[cxix].blk_sub.lval;
1215 S_dopoptosub(pTHX_ I32 startingblock)
1217 return dopoptosub_at(cxstack, startingblock);
1221 S_dopoptosub_at(pTHX_ const PERL_CONTEXT *cxstk, I32 startingblock)
1224 for (i = startingblock; i >= 0; i--) {
1225 register const PERL_CONTEXT * const cx = &cxstk[i];
1226 switch (CxTYPE(cx)) {
1232 DEBUG_l( Perl_deb(aTHX_ "(Found sub #%ld)\n", (long)i));
1240 S_dopoptoeval(pTHX_ I32 startingblock)
1243 for (i = startingblock; i >= 0; i--) {
1244 register const PERL_CONTEXT *cx = &cxstack[i];
1245 switch (CxTYPE(cx)) {
1249 DEBUG_l( Perl_deb(aTHX_ "(Found eval #%ld)\n", (long)i));
1257 S_dopoptoloop(pTHX_ I32 startingblock)
1260 for (i = startingblock; i >= 0; i--) {
1261 register const PERL_CONTEXT * const cx = &cxstack[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)
1287 while (cxstack_ix > cxix) {
1289 register PERL_CONTEXT *cx = &cxstack[cxstack_ix];
1290 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n",
1291 (long) cxstack_ix, PL_block_type[CxTYPE(cx)]));
1292 /* Note: we don't need to restore the base context info till the end. */
1293 switch (CxTYPE(cx)) {
1296 continue; /* not break */
1315 PERL_UNUSED_VAR(optype);
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)
1338 if (PL_in_eval & EVAL_KEEPERR) {
1339 static const char prefix[] = "\t(in cleanup) ";
1340 SV * const err = ERRSV;
1341 const char *e = Nullch;
1343 sv_setpvn(err,"",0);
1344 else if (SvCUR(err) >= sizeof(prefix)+msglen-1) {
1346 e = SvPV_const(err, len);
1348 if (*e != *message || strNE(e,message))
1352 SvGROW(err, SvCUR(err)+sizeof(prefix)+msglen);
1353 sv_catpvn(err, prefix, sizeof(prefix)-1);
1354 sv_catpvn(err, message, msglen);
1355 if (ckWARN(WARN_MISC)) {
1356 const STRLEN start = SvCUR(err)-msglen-sizeof(prefix)+1;
1357 Perl_warner(aTHX_ packWARN(WARN_MISC), SvPVX_const(err)+start);
1362 sv_setpvn(ERRSV, message, msglen);
1366 while ((cxix = dopoptoeval(cxstack_ix)) < 0
1367 && PL_curstackinfo->si_prev)
1375 register PERL_CONTEXT *cx;
1378 if (cxix < cxstack_ix)
1381 POPBLOCK(cx,PL_curpm);
1382 if (CxTYPE(cx) != CXt_EVAL) {
1384 message = (char *)SvPVx_const(ERRSV, msglen);
1385 PerlIO_write(Perl_error_log, "panic: die ", 11);
1386 PerlIO_write(Perl_error_log, message, msglen);
1391 if (gimme == G_SCALAR)
1392 *++newsp = &PL_sv_undef;
1393 PL_stack_sp = newsp;
1397 /* LEAVE could clobber PL_curcop (see save_re_context())
1398 * XXX it might be better to find a way to avoid messing with
1399 * PL_curcop in save_re_context() instead, but this is a more
1400 * minimal fix --GSAR */
1401 PL_curcop = cx->blk_oldcop;
1403 if (optype == OP_REQUIRE) {
1404 const char* msg = SvPVx_nolen_const(ERRSV);
1405 DIE(aTHX_ "%sCompilation failed in require",
1406 *msg ? msg : "Unknown error\n");
1408 return pop_return();
1412 message = (char *)SvPVx_const(ERRSV, msglen);
1414 write_to_stderr(message, msglen);
1423 if (SvTRUE(left) != SvTRUE(right))
1435 RETURNOP(cLOGOP->op_other);
1444 RETURNOP(cLOGOP->op_other);
1450 register I32 cxix = dopoptosub(cxstack_ix);
1451 register const PERL_CONTEXT *cx;
1452 register const PERL_CONTEXT *ccstack = cxstack;
1453 const PERL_SI *top_si = PL_curstackinfo;
1455 const char *stashname;
1462 /* we may be in a higher stacklevel, so dig down deeper */
1463 while (cxix < 0 && top_si->si_type != PERLSI_MAIN) {
1464 top_si = top_si->si_prev;
1465 ccstack = top_si->si_cxstack;
1466 cxix = dopoptosub_at(ccstack, top_si->si_cxix);
1469 if (GIMME != G_ARRAY) {
1475 /* caller() should not report the automatic calls to &DB::sub */
1476 if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 &&
1477 ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub))
1481 cxix = dopoptosub_at(ccstack, cxix - 1);
1484 cx = &ccstack[cxix];
1485 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1486 const I32 dbcxix = dopoptosub_at(ccstack, cxix - 1);
1487 /* We expect that ccstack[dbcxix] is CXt_SUB, anyway, the
1488 field below is defined for any cx. */
1489 /* caller() should not report the automatic calls to &DB::sub */
1490 if (PL_DBsub && GvCV(PL_DBsub) && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub))
1491 cx = &ccstack[dbcxix];
1494 stashname = CopSTASHPV(cx->blk_oldcop);
1495 if (GIMME != G_ARRAY) {
1498 PUSHs(&PL_sv_undef);
1501 sv_setpv(TARG, stashname);
1510 PUSHs(&PL_sv_undef);
1512 PUSHs(sv_2mortal(newSVpv(stashname, 0)));
1513 PUSHs(sv_2mortal(newSVpv(OutCopFILE(cx->blk_oldcop), 0)));
1514 PUSHs(sv_2mortal(newSViv((I32)CopLINE(cx->blk_oldcop))));
1517 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1518 GV *cvgv = CvGV(ccstack[cxix].blk_sub.cv);
1519 /* So is ccstack[dbcxix]. */
1521 SV * const sv = NEWSV(49, 0);
1522 gv_efullname3(sv, cvgv, Nullch);
1523 PUSHs(sv_2mortal(sv));
1524 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1527 PUSHs(sv_2mortal(newSVpvn("(unknown)",9)));
1528 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1532 PUSHs(sv_2mortal(newSVpvn("(eval)",6)));
1533 PUSHs(sv_2mortal(newSViv(0)));
1535 gimme = (I32)cx->blk_gimme;
1536 if (gimme == G_VOID)
1537 PUSHs(&PL_sv_undef);
1539 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1540 if (CxTYPE(cx) == CXt_EVAL) {
1542 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1543 PUSHs(cx->blk_eval.cur_text);
1547 else if (cx->blk_eval.old_namesv) {
1548 PUSHs(sv_2mortal(newSVsv(cx->blk_eval.old_namesv)));
1551 /* eval BLOCK (try blocks have old_namesv == 0) */
1553 PUSHs(&PL_sv_undef);
1554 PUSHs(&PL_sv_undef);
1558 PUSHs(&PL_sv_undef);
1559 PUSHs(&PL_sv_undef);
1561 if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.hasargs
1562 && CopSTASH_eq(PL_curcop, PL_debstash))
1564 AV * const ary = cx->blk_sub.argarray;
1565 const int off = AvARRAY(ary) - AvALLOC(ary);
1569 PL_dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1572 AvREAL_off(PL_dbargs); /* XXX should be REIFY (see av.h) */
1575 if (AvMAX(PL_dbargs) < AvFILLp(ary) + off)
1576 av_extend(PL_dbargs, AvFILLp(ary) + off);
1577 Copy(AvALLOC(ary), AvARRAY(PL_dbargs), AvFILLp(ary) + 1 + off, SV*);
1578 AvFILLp(PL_dbargs) = AvFILLp(ary) + off;
1580 /* XXX only hints propagated via op_private are currently
1581 * visible (others are not easily accessible, since they
1582 * use the global PL_hints) */
1583 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->op_private &
1584 HINT_PRIVATE_MASK)));
1587 SV * old_warnings = cx->blk_oldcop->cop_warnings ;
1589 if (old_warnings == pWARN_NONE ||
1590 (old_warnings == pWARN_STD && (PL_dowarn & G_WARN_ON) == 0))
1591 mask = newSVpvn(WARN_NONEstring, WARNsize) ;
1592 else if (old_warnings == pWARN_ALL ||
1593 (old_warnings == pWARN_STD && PL_dowarn & G_WARN_ON)) {
1594 /* Get the bit mask for $warnings::Bits{all}, because
1595 * it could have been extended by warnings::register */
1597 HV *bits = get_hv("warnings::Bits", FALSE);
1598 if (bits && (bits_all=hv_fetch(bits, "all", 3, FALSE))) {
1599 mask = newSVsv(*bits_all);
1602 mask = newSVpvn(WARN_ALLstring, WARNsize) ;
1606 mask = newSVsv(old_warnings);
1607 PUSHs(sv_2mortal(mask));
1621 sv_reset((char *)tmps, CopSTASH(PL_curcop));
1631 /* like pp_nextstate, but used instead when the debugger is active */
1635 PL_curcop = (COP*)PL_op;
1636 TAINT_NOT; /* Each statement is presumed innocent */
1637 PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
1640 if (PL_op->op_flags & OPf_SPECIAL /* breakpoint */
1641 || SvIV(PL_DBsingle) || SvIV(PL_DBsignal) || SvIV(PL_DBtrace))
1645 register PERL_CONTEXT *cx;
1646 const I32 gimme = G_ARRAY;
1653 DIE(aTHX_ "No DB::DB routine defined");
1655 if (CvDEPTH(cv) >= 1 && !(PL_debug & DEBUG_DB_RECURSE_FLAG))
1656 /* don't do recursive DB::DB call */
1668 push_return(PL_op->op_next);
1669 PUSHBLOCK(cx, CXt_SUB, SP);
1673 PAD_SET_CUR_NOSAVE(CvPADLIST(cv), 1);
1674 RETURNOP(CvSTART(cv));
1688 register PERL_CONTEXT *cx;
1689 const I32 gimme = GIMME_V;
1691 U32 cxtype = CXt_LOOP;
1699 #ifdef USE_5005THREADS
1700 if (PL_op->op_flags & OPf_SPECIAL) {
1701 svp = &THREADSV(PL_op->op_targ); /* per-thread variable */
1702 SAVEGENERICSV(*svp);
1706 #endif /* USE_5005THREADS */
1707 if (PL_op->op_targ) {
1708 #ifndef USE_ITHREADS
1709 svp = &PAD_SVl(PL_op->op_targ); /* "my" variable */
1712 SAVEPADSV(PL_op->op_targ);
1713 iterdata = INT2PTR(void*, PL_op->op_targ);
1714 cxtype |= CXp_PADVAR;
1719 svp = &GvSV(gv); /* symbol table variable */
1720 SAVEGENERICSV(*svp);
1723 iterdata = (void*)gv;
1729 PUSHBLOCK(cx, cxtype, SP);
1731 PUSHLOOP(cx, iterdata, MARK);
1733 PUSHLOOP(cx, svp, MARK);
1735 if (PL_op->op_flags & OPf_STACKED) {
1736 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1737 if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) {
1739 SV *right = (SV*)cx->blk_loop.iterary;
1742 if (RANGE_IS_NUMERIC(sv,right)) {
1743 if ((SvOK(sv) && SvNV(sv) < IV_MIN) ||
1744 (SvOK(right) && SvNV(right) >= IV_MAX))
1745 DIE(aTHX_ "Range iterator outside integer range");
1746 cx->blk_loop.iterix = SvIV(sv);
1747 cx->blk_loop.itermax = SvIV(right);
1749 /* for correct -Dstv display */
1750 cx->blk_oldsp = sp - PL_stack_base;
1754 cx->blk_loop.iterlval = newSVsv(sv);
1755 (void) SvPV_force_nolen(cx->blk_loop.iterlval);
1756 (void) SvPV_nolen_const(right);
1759 else if (PL_op->op_private & OPpITER_REVERSED) {
1760 cx->blk_loop.itermax = -1;
1761 cx->blk_loop.iterix = AvFILL(cx->blk_loop.iterary);
1766 cx->blk_loop.iterary = PL_curstack;
1767 AvFILLp(PL_curstack) = SP - PL_stack_base;
1768 if (PL_op->op_private & OPpITER_REVERSED) {
1769 cx->blk_loop.itermax = MARK - PL_stack_base;
1770 cx->blk_loop.iterix = cx->blk_oldsp;
1773 cx->blk_loop.iterix = MARK - PL_stack_base;
1783 register PERL_CONTEXT *cx;
1784 const I32 gimme = GIMME_V;
1790 PUSHBLOCK(cx, CXt_LOOP, SP);
1791 PUSHLOOP(cx, 0, SP);
1799 register PERL_CONTEXT *cx;
1806 assert(CxTYPE(cx) == CXt_LOOP);
1808 newsp = PL_stack_base + cx->blk_loop.resetsp;
1811 if (gimme == G_VOID)
1813 else if (gimme == G_SCALAR) {
1815 *++newsp = sv_mortalcopy(*SP);
1817 *++newsp = &PL_sv_undef;
1821 *++newsp = sv_mortalcopy(*++mark);
1822 TAINT_NOT; /* Each item is independent */
1828 POPLOOP(cx); /* Stack values are safe: release loop vars ... */
1829 PL_curpm = newpm; /* ... and pop $1 et al */
1841 register PERL_CONTEXT *cx;
1842 bool popsub2 = FALSE;
1843 bool clear_errsv = FALSE;
1850 if (PL_curstackinfo->si_type == PERLSI_SORT) {
1851 if (cxstack_ix == PL_sortcxix
1852 || dopoptosub(cxstack_ix) <= PL_sortcxix)
1854 if (cxstack_ix > PL_sortcxix)
1855 dounwind(PL_sortcxix);
1856 AvARRAY(PL_curstack)[1] = *SP;
1857 PL_stack_sp = PL_stack_base + 1;
1862 cxix = dopoptosub(cxstack_ix);
1864 DIE(aTHX_ "Can't return outside a subroutine");
1865 if (cxix < cxstack_ix)
1869 switch (CxTYPE(cx)) {
1872 cxstack_ix++; /* preserve cx entry on stack for use by POPSUB */
1875 if (!(PL_in_eval & EVAL_KEEPERR))
1881 if (optype == OP_REQUIRE &&
1882 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1884 /* Unassume the success we assumed earlier. */
1885 SV * const nsv = cx->blk_eval.old_namesv;
1886 (void)hv_delete(GvHVn(PL_incgv), SvPVX_const(nsv), SvCUR(nsv), G_DISCARD);
1887 DIE(aTHX_ "%"SVf" did not return a true value", nsv);
1894 DIE(aTHX_ "panic: return");
1898 if (gimme == G_SCALAR) {
1901 if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
1903 *++newsp = SvREFCNT_inc(*SP);
1908 sv = SvREFCNT_inc(*SP); /* FREETMPS could clobber it */
1910 *++newsp = sv_mortalcopy(sv);
1915 *++newsp = (SvTEMP(*SP)) ? *SP : sv_mortalcopy(*SP);
1918 *++newsp = sv_mortalcopy(*SP);
1921 *++newsp = &PL_sv_undef;
1923 else if (gimme == G_ARRAY) {
1924 while (++MARK <= SP) {
1925 *++newsp = (popsub2 && SvTEMP(*MARK))
1926 ? *MARK : sv_mortalcopy(*MARK);
1927 TAINT_NOT; /* Each item is independent */
1930 PL_stack_sp = newsp;
1933 /* Stack values are safe: */
1936 POPSUB(cx,sv); /* release CV and @_ ... */
1940 PL_curpm = newpm; /* ... and pop $1 et al */
1944 sv_setpvn(ERRSV,"",0);
1945 return pop_return();
1952 register PERL_CONTEXT *cx;
1963 if (PL_op->op_flags & OPf_SPECIAL) {
1964 cxix = dopoptoloop(cxstack_ix);
1966 DIE(aTHX_ "Can't \"last\" outside a loop block");
1969 cxix = dopoptolabel(cPVOP->op_pv);
1971 DIE(aTHX_ "Label not found for \"last %s\"", cPVOP->op_pv);
1973 if (cxix < cxstack_ix)
1977 cxstack_ix++; /* temporarily protect top context */
1979 switch (CxTYPE(cx)) {
1982 newsp = PL_stack_base + cx->blk_loop.resetsp;
1983 nextop = cx->blk_loop.last_op->op_next;
1987 nextop = pop_return();
1991 nextop = pop_return();
1995 nextop = pop_return();
1998 DIE(aTHX_ "panic: last");
2002 if (gimme == G_SCALAR) {
2004 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
2005 ? *SP : sv_mortalcopy(*SP);
2007 *++newsp = &PL_sv_undef;
2009 else if (gimme == G_ARRAY) {
2010 while (++MARK <= SP) {
2011 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
2012 ? *MARK : sv_mortalcopy(*MARK);
2013 TAINT_NOT; /* Each item is independent */
2021 /* Stack values are safe: */
2024 POPLOOP(cx); /* release loop vars ... */
2028 POPSUB(cx,sv); /* release CV and @_ ... */
2031 PL_curpm = newpm; /* ... and pop $1 et al */
2034 PERL_UNUSED_VAR(optype);
2035 PERL_UNUSED_VAR(gimme);
2042 register PERL_CONTEXT *cx;
2045 if (PL_op->op_flags & OPf_SPECIAL) {
2046 cxix = dopoptoloop(cxstack_ix);
2048 DIE(aTHX_ "Can't \"next\" outside a loop block");
2051 cxix = dopoptolabel(cPVOP->op_pv);
2053 DIE(aTHX_ "Label not found for \"next %s\"", cPVOP->op_pv);
2055 if (cxix < cxstack_ix)
2058 /* clear off anything above the scope we're re-entering, but
2059 * save the rest until after a possible continue block */
2060 inner = PL_scopestack_ix;
2062 if (PL_scopestack_ix < inner)
2063 leave_scope(PL_scopestack[PL_scopestack_ix]);
2064 PL_curcop = cx->blk_oldcop;
2065 return cx->blk_loop.next_op;
2071 register PERL_CONTEXT *cx;
2074 if (PL_op->op_flags & OPf_SPECIAL) {
2075 cxix = dopoptoloop(cxstack_ix);
2077 DIE(aTHX_ "Can't \"redo\" outside a loop block");
2080 cxix = dopoptolabel(cPVOP->op_pv);
2082 DIE(aTHX_ "Label not found for \"redo %s\"", cPVOP->op_pv);
2084 if (cxix < cxstack_ix)
2088 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2089 LEAVE_SCOPE(oldsave);
2091 PL_curcop = cx->blk_oldcop;
2092 return cx->blk_loop.redo_op;
2096 S_dofindlabel(pTHX_ OP *o, const char *label, OP **opstack, OP **oplimit)
2099 static const char too_deep[] = "Target of goto is too deeply nested";
2102 Perl_croak(aTHX_ too_deep);
2103 if (o->op_type == OP_LEAVE ||
2104 o->op_type == OP_SCOPE ||
2105 o->op_type == OP_LEAVELOOP ||
2106 o->op_type == OP_LEAVESUB ||
2107 o->op_type == OP_LEAVETRY)
2109 *ops++ = cUNOPo->op_first;
2111 Perl_croak(aTHX_ too_deep);
2114 if (o->op_flags & OPf_KIDS) {
2116 /* First try all the kids at this level, since that's likeliest. */
2117 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
2118 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
2119 kCOP->cop_label && strEQ(kCOP->cop_label, label))
2122 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
2123 if (kid == PL_lastgotoprobe)
2125 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
2128 else if (ops[-1]->op_type == OP_NEXTSTATE ||
2129 ops[-1]->op_type == OP_DBSTATE)
2134 if ((o = dofindlabel(kid, label, ops, oplimit)))
2153 register PERL_CONTEXT *cx;
2154 #define GOTO_DEPTH 64
2155 OP *enterops[GOTO_DEPTH];
2156 const char *label = 0;
2157 const bool do_dump = (PL_op->op_type == OP_DUMP);
2158 static const char must_have_label[] = "goto must have label";
2160 if (PL_op->op_flags & OPf_STACKED) {
2161 SV * const sv = POPs;
2163 /* This egregious kludge implements goto &subroutine */
2164 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
2166 register PERL_CONTEXT *cx;
2167 CV* cv = (CV*)SvRV(sv);
2174 if (!CvROOT(cv) && !CvXSUB(cv)) {
2175 const GV * const gv = CvGV(cv);
2179 /* autoloaded stub? */
2180 if (cv != GvCV(gv) && (cv = GvCV(gv)))
2182 autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv),
2183 GvNAMELEN(gv), FALSE);
2184 if (autogv && (cv = GvCV(autogv)))
2186 tmpstr = sv_newmortal();
2187 gv_efullname3(tmpstr, (GV *) gv, Nullch);
2188 DIE(aTHX_ "Goto undefined subroutine &%"SVf"",tmpstr);
2190 DIE(aTHX_ "Goto undefined subroutine");
2193 /* First do some returnish stuff. */
2194 (void)SvREFCNT_inc(cv); /* avoid premature free during unwind */
2196 cxix = dopoptosub(cxstack_ix);
2198 DIE(aTHX_ "Can't goto subroutine outside a subroutine");
2199 if (cxix < cxstack_ix)
2203 if (CxTYPE(cx) == CXt_EVAL) {
2205 DIE(aTHX_ "Can't goto subroutine from an eval-string");
2207 DIE(aTHX_ "Can't goto subroutine from an eval-block");
2209 if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.hasargs) {
2210 /* put @_ back onto stack */
2211 AV* av = cx->blk_sub.argarray;
2213 items = AvFILLp(av) + 1;
2214 EXTEND(SP, items+1); /* @_ could have been extended. */
2215 Copy(AvARRAY(av), SP + 1, items, SV*);
2216 #ifndef USE_5005THREADS
2217 SvREFCNT_dec(GvAV(PL_defgv));
2218 GvAV(PL_defgv) = cx->blk_sub.savearray;
2219 #endif /* USE_5005THREADS */
2221 /* abandon @_ if it got reified */
2226 av_extend(av, items-1);
2227 AvFLAGS(av) = AVf_REIFY;
2228 PAD_SVl(0) = (SV*)(cx->blk_sub.argarray = av);
2231 else if (CvXSUB(cv)) { /* put GvAV(defgv) back onto stack */
2232 #ifdef USE_5005THREADS
2233 AV* const av = (AV*)PAD_SVl(0);
2235 AV* const av = GvAV(PL_defgv);
2237 items = AvFILLp(av) + 1;
2238 EXTEND(SP, items+1); /* @_ could have been extended. */
2239 Copy(AvARRAY(av), SP + 1, items, SV*);
2243 if (CxTYPE(cx) == CXt_SUB &&
2244 !(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
2245 SvREFCNT_dec(cx->blk_sub.cv);
2246 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2247 LEAVE_SCOPE(oldsave);
2249 /* Now do some callish stuff. */
2251 SAVEFREESV(cv); /* later, undo the 'avoid premature free' hack */
2255 for (index=0; index<items; index++)
2256 sv_2mortal(SP[-index]);
2258 #ifdef PERL_XSUB_OLDSTYLE
2259 if (CvOLDSTYLE(cv)) {
2260 I32 (*fp3)(int,int,int);
2265 fp3 = (I32(*)(int,int,int))CvXSUB(cv);
2266 items = (*fp3)(CvXSUBANY(cv).any_i32,
2267 mark - PL_stack_base + 1,
2269 SP = PL_stack_base + items;
2272 #endif /* PERL_XSUB_OLDSTYLE */
2277 /* Push a mark for the start of arglist */
2280 (void)(*CvXSUB(cv))(aTHX_ cv);
2282 /* Pop the current context like a decent sub should */
2283 POPBLOCK(cx, PL_curpm);
2284 /* Do _not_ use PUTBACK, keep the XSUB's return stack! */
2286 /* Put these at the bottom since the vars are set but not used */
2287 PERL_UNUSED_VAR(newsp);
2288 PERL_UNUSED_VAR(gimme);
2291 return pop_return();
2294 AV* padlist = CvPADLIST(cv);
2295 if (CxTYPE(cx) == CXt_EVAL) {
2296 PL_in_eval = cx->blk_eval.old_in_eval;
2297 PL_eval_root = cx->blk_eval.old_eval_root;
2298 cx->cx_type = CXt_SUB;
2299 cx->blk_sub.hasargs = 0;
2301 cx->blk_sub.cv = cv;
2302 cx->blk_sub.olddepth = (U16)CvDEPTH(cv);
2305 if (CvDEPTH(cv) < 2)
2306 (void)SvREFCNT_inc(cv);
2308 if (CvDEPTH(cv) == 100 && ckWARN(WARN_RECURSION))
2309 sub_crush_depth(cv);
2310 pad_push(padlist, CvDEPTH(cv), 1);
2312 #ifdef USE_5005THREADS
2313 if (!cx->blk_sub.hasargs) {
2314 AV* av = (AV*)PAD_SVl(0);
2316 items = AvFILLp(av) + 1;
2318 /* Mark is at the end of the stack. */
2320 Copy(AvARRAY(av), SP + 1, items, SV*);
2325 #endif /* USE_5005THREADS */
2327 PAD_SET_CUR_NOSAVE(padlist, CvDEPTH(cv));
2328 #ifndef USE_5005THREADS
2329 if (cx->blk_sub.hasargs)
2330 #endif /* USE_5005THREADS */
2332 AV* av = (AV*)PAD_SVl(0);
2335 #ifndef USE_5005THREADS
2336 cx->blk_sub.savearray = GvAV(PL_defgv);
2337 GvAV(PL_defgv) = (AV*)SvREFCNT_inc(av);
2338 #endif /* USE_5005THREADS */
2339 CX_CURPAD_SAVE(cx->blk_sub);
2340 cx->blk_sub.argarray = av;
2342 if (items >= AvMAX(av) + 1) {
2344 if (AvARRAY(av) != ary) {
2345 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
2346 SvPV_set(av, (char*)ary);
2348 if (items >= AvMAX(av) + 1) {
2349 AvMAX(av) = items - 1;
2350 Renew(ary,items+1,SV*);
2352 SvPV_set(av, (char*)ary);
2356 Copy(mark,AvARRAY(av),items,SV*);
2357 AvFILLp(av) = items - 1;
2358 assert(!AvREAL(av));
2360 /* transfer 'ownership' of refcnts to new @_ */
2370 if (PERLDB_SUB) { /* Checking curstash breaks DProf. */
2372 * We do not care about using sv to call CV;
2373 * it's for informational purposes only.
2375 SV * const sv = GvSV(PL_DBsub);
2379 if (PERLDB_SUB_NN) {
2380 const int type = SvTYPE(sv);
2381 if (type < SVt_PVIV && type != SVt_IV)
2382 sv_upgrade(sv, SVt_PVIV);
2384 SvIV_set(sv, PTR2IV(cv)); /* Do it the quickest way */
2386 gv_efullname3(sv, CvGV(cv), Nullch);
2389 && (gotocv = get_cv("DB::goto", FALSE)) ) {
2390 PUSHMARK( PL_stack_sp );
2391 call_sv((SV*)gotocv, G_SCALAR | G_NODEBUG);
2395 RETURNOP(CvSTART(cv));
2399 label = SvPV_nolen_const(sv);
2400 if (!(do_dump || *label))
2401 DIE(aTHX_ must_have_label);
2404 else if (PL_op->op_flags & OPf_SPECIAL) {
2406 DIE(aTHX_ must_have_label);
2409 label = cPVOP->op_pv;
2411 if (label && *label) {
2413 bool leaving_eval = FALSE;
2414 bool in_block = FALSE;
2415 PERL_CONTEXT *last_eval_cx = 0;
2419 PL_lastgotoprobe = 0;
2421 for (ix = cxstack_ix; ix >= 0; ix--) {
2423 switch (CxTYPE(cx)) {
2425 leaving_eval = TRUE;
2426 if (!CxTRYBLOCK(cx)) {
2427 gotoprobe = (last_eval_cx ?
2428 last_eval_cx->blk_eval.old_eval_root :
2433 /* else fall through */
2435 gotoprobe = cx->blk_oldcop->op_sibling;
2441 gotoprobe = cx->blk_oldcop->op_sibling;
2444 gotoprobe = PL_main_root;
2447 if (CvDEPTH(cx->blk_sub.cv)) {
2448 gotoprobe = CvROOT(cx->blk_sub.cv);
2454 DIE(aTHX_ "Can't \"goto\" out of a pseudo block");
2457 DIE(aTHX_ "panic: goto");
2458 gotoprobe = PL_main_root;
2462 retop = dofindlabel(gotoprobe, label,
2463 enterops, enterops + GOTO_DEPTH);
2467 PL_lastgotoprobe = gotoprobe;
2470 DIE(aTHX_ "Can't find label %s", label);
2472 /* if we're leaving an eval, check before we pop any frames
2473 that we're not going to punt, otherwise the error
2476 if (leaving_eval && *enterops && enterops[1]) {
2478 for (i = 1; enterops[i]; i++)
2479 if (enterops[i]->op_type == OP_ENTERITER)
2480 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2483 /* pop unwanted frames */
2485 if (ix < cxstack_ix) {
2492 oldsave = PL_scopestack[PL_scopestack_ix];
2493 LEAVE_SCOPE(oldsave);
2496 /* push wanted frames */
2498 if (*enterops && enterops[1]) {
2500 ix = enterops[1]->op_type == OP_ENTER && in_block ? 2 : 1;
2501 for (; enterops[ix]; ix++) {
2502 PL_op = enterops[ix];
2503 /* Eventually we may want to stack the needed arguments
2504 * for each op. For now, we punt on the hard ones. */
2505 if (PL_op->op_type == OP_ENTERITER)
2506 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2507 CALL_FPTR(PL_op->op_ppaddr)(aTHX);
2515 if (!retop) retop = PL_main_start;
2517 PL_restartop = retop;
2518 PL_do_undump = TRUE;
2522 PL_restartop = 0; /* hmm, must be GNU unexec().. */
2523 PL_do_undump = FALSE;
2539 if (anum == 1 && (PL_op->op_private & OPpEXIT_VMSISH))
2541 VMSISH_HUSHED = VMSISH_HUSHED || (PL_op->op_private & OPpHUSH_VMSISH);
2544 PL_exit_flags |= PERL_EXIT_EXPECTED;
2546 PUSHs(&PL_sv_undef);
2554 const NV value = SvNVx(GvSV(cCOP->cop_gv));
2555 register I32 match = I_32(value);
2558 if (((NV)match) > value)
2559 --match; /* was fractional--truncate other way */
2561 match -= cCOP->uop.scop.scop_offset;
2564 else if (match > cCOP->uop.scop.scop_max)
2565 match = cCOP->uop.scop.scop_max;
2566 PL_op = cCOP->uop.scop.scop_next[match];
2576 PL_op = PL_op->op_next; /* can't assume anything */
2578 match = *(SvPVx_nolen_const(GvSV(cCOP->cop_gv))) & 255;
2579 match -= cCOP->uop.scop.scop_offset;
2582 else if (match > cCOP->uop.scop.scop_max)
2583 match = cCOP->uop.scop.scop_max;
2584 PL_op = cCOP->uop.scop.scop_next[match];
2593 S_save_lines(pTHX_ AV *array, SV *sv)
2595 const char *s = SvPVX_const(sv);
2596 const char * const send = SvPVX_const(sv) + SvCUR(sv);
2599 while (s && s < send) {
2601 SV * const tmpstr = NEWSV(85,0);
2603 sv_upgrade(tmpstr, SVt_PVMG);
2604 t = strchr(s, '\n');
2610 sv_setpvn(tmpstr, s, t - s);
2611 av_store(array, line++, tmpstr);
2616 #ifdef PERL_FLEXIBLE_EXCEPTIONS
2618 S_docatch_body(pTHX_ va_list args)
2620 return docatch_body();
2625 S_docatch_body(pTHX)
2632 S_docatch(pTHX_ OP *o)
2635 OP * const oldop = PL_op;
2637 volatile PERL_SI *cursi = PL_curstackinfo;
2641 assert(CATCH_GET == TRUE);
2645 /* Normally, the leavetry at the end of this block of ops will
2646 * pop an op off the return stack and continue there. By setting
2647 * the op to Nullop, we force an exit from the inner runops()
2650 retop = pop_return();
2651 push_return(Nullop);
2653 #ifdef PERL_FLEXIBLE_EXCEPTIONS
2655 CALLPROTECT(aTHX_ pcur_env, &ret, MEMBER_TO_FPTR(S_docatch_body));
2661 #ifndef PERL_FLEXIBLE_EXCEPTIONS
2667 /* die caught by an inner eval - continue inner loop */
2668 if (PL_restartop && cursi == PL_curstackinfo) {
2669 PL_op = PL_restartop;
2673 /* a die in this eval - continue in outer loop */
2689 Perl_sv_compile_2op(pTHX_ SV *sv, OP** startop, char *code, PAD** padp)
2690 /* sv Text to convert to OP tree. */
2691 /* startop op_free() this to undo. */
2692 /* code Short string id of the caller. */
2694 dSP; /* Make POPBLOCK work. */
2701 char tbuf[TYPE_DIGITS(long) + 12 + 10];
2702 char *tmpbuf = tbuf;
2705 CV* runcv = Nullcv; /* initialise to avoid compiler warnings */
2710 /* switch to eval mode */
2712 if (IN_PERL_COMPILETIME) {
2713 SAVECOPSTASH_FREE(&PL_compiling);
2714 CopSTASH_set(&PL_compiling, PL_curstash);
2716 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
2717 SV * const sv = sv_newmortal();
2718 Perl_sv_setpvf(aTHX_ sv, "_<(%.10seval %lu)[%s:%"IVdf"]",
2719 code, (unsigned long)++PL_evalseq,
2720 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
2724 sprintf(tmpbuf, "_<(%.10s_eval %lu)", code, (unsigned long)++PL_evalseq);
2725 SAVECOPFILE_FREE(&PL_compiling);
2726 CopFILE_set(&PL_compiling, tmpbuf+2);
2727 SAVECOPLINE(&PL_compiling);
2728 CopLINE_set(&PL_compiling, 1);
2729 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2730 deleting the eval's FILEGV from the stash before gv_check() runs
2731 (i.e. before run-time proper). To work around the coredump that
2732 ensues, we always turn GvMULTI_on for any globals that were
2733 introduced within evals. See force_ident(). GSAR 96-10-12 */
2734 safestr = savepv(tmpbuf);
2735 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
2737 #ifdef OP_IN_REGISTER
2743 /* we get here either during compilation, or via pp_regcomp at runtime */
2744 runtime = IN_PERL_RUNTIME;
2746 runcv = find_runcv(NULL);
2749 PL_op->op_type = OP_ENTEREVAL;
2750 PL_op->op_flags = 0; /* Avoid uninit warning. */
2751 PUSHBLOCK(cx, CXt_EVAL|(IN_PERL_COMPILETIME ? 0 : CXp_REAL), SP);
2752 PUSHEVAL(cx, 0, Nullgv);
2755 rop = doeval(G_SCALAR, startop, runcv, PL_curcop->cop_seq);
2757 rop = doeval(G_SCALAR, startop, PL_compcv, PL_cop_seqmax);
2758 POPBLOCK(cx,PL_curpm);
2761 (*startop)->op_type = OP_NULL;
2762 (*startop)->op_ppaddr = PL_ppaddr[OP_NULL];
2764 /* XXX DAPM do this properly one year */
2765 *padp = (AV*)SvREFCNT_inc(PL_comppad);
2767 if (IN_PERL_COMPILETIME)
2768 PL_compiling.op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);
2769 #ifdef OP_IN_REGISTER
2772 PERL_UNUSED_VAR(newsp);
2773 PERL_UNUSED_VAR(optype);
2780 =for apidoc find_runcv
2782 Locate the CV corresponding to the currently executing sub or eval.
2783 If db_seqp is non_null, skip CVs that are in the DB package and populate
2784 *db_seqp with the cop sequence number at the point that the DB:: code was
2785 entered. (allows debuggers to eval in the scope of the breakpoint rather
2786 than in the scope of the debugger itself).
2792 Perl_find_runcv(pTHX_ U32 *db_seqp)
2797 *db_seqp = PL_curcop->cop_seq;
2798 for (si = PL_curstackinfo; si; si = si->si_prev) {
2800 for (ix = si->si_cxix; ix >= 0; ix--) {
2801 const PERL_CONTEXT *cx = &(si->si_cxstack[ix]);
2802 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
2803 CV * const cv = cx->blk_sub.cv;
2804 /* skip DB:: code */
2805 if (db_seqp && PL_debstash && CvSTASH(cv) == PL_debstash) {
2806 *db_seqp = cx->blk_oldcop->cop_seq;
2811 else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx))
2819 /* Compile a require/do, an eval '', or a /(?{...})/.
2820 * In the last case, startop is non-null, and contains the address of
2821 * a pointer that should be set to the just-compiled code.
2822 * outside is the lexically enclosing CV (if any) that invoked us.
2825 /* With USE_5005THREADS, eval_owner must be held on entry to doeval */
2827 S_doeval(pTHX_ int gimme, OP** startop, CV* outside, U32 seq)
2830 OP * const saveop = PL_op;
2832 PL_in_eval = ((saveop && saveop->op_type == OP_REQUIRE)
2833 ? (EVAL_INREQUIRE | (PL_in_eval & EVAL_INEVAL))
2838 SAVESPTR(PL_compcv);
2839 PL_compcv = (CV*)NEWSV(1104,0);
2840 sv_upgrade((SV *)PL_compcv, SVt_PVCV);
2841 CvEVAL_on(PL_compcv);
2842 assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
2843 cxstack[cxstack_ix].blk_eval.cv = PL_compcv;
2845 #ifdef USE_5005THREADS
2846 CvOWNER(PL_compcv) = 0;
2847 New(666, CvMUTEXP(PL_compcv), 1, perl_mutex);
2848 MUTEX_INIT(CvMUTEXP(PL_compcv));
2849 #endif /* USE_5005THREADS */
2851 CvOUTSIDE_SEQ(PL_compcv) = seq;
2852 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outside);
2854 /* set up a scratch pad */
2856 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE);
2859 SAVEMORTALIZESV(PL_compcv); /* must remain until end of current statement */
2861 /* make sure we compile in the right package */
2863 if (CopSTASH_ne(PL_curcop, PL_curstash)) {
2864 SAVESPTR(PL_curstash);
2865 PL_curstash = CopSTASH(PL_curcop);
2867 SAVESPTR(PL_beginav);
2868 PL_beginav = newAV();
2869 SAVEFREESV(PL_beginav);
2870 SAVEI32(PL_error_count);
2872 /* try to compile it */
2874 PL_eval_root = Nullop;
2876 PL_curcop = &PL_compiling;
2877 PL_curcop->cop_arybase = 0;
2878 if (saveop && saveop->op_flags & OPf_SPECIAL)
2879 PL_in_eval |= EVAL_KEEPERR;
2881 sv_setpvn(ERRSV,"",0);
2882 if (yyparse() || PL_error_count || !PL_eval_root) {
2883 SV **newsp; /* Used by POPBLOCK. */
2885 I32 optype = 0; /* Might be reset by POPEVAL. */
2890 op_free(PL_eval_root);
2891 PL_eval_root = Nullop;
2893 SP = PL_stack_base + POPMARK; /* pop original mark */
2895 POPBLOCK(cx,PL_curpm);
2902 msg = SvPVx_nolen_const(ERRSV);
2903 if (optype == OP_REQUIRE) {
2904 const char* const msg = SvPVx_nolen_const(ERRSV);
2905 DIE(aTHX_ "%sCompilation failed in require",
2906 *msg ? msg : "Unknown error\n");
2909 POPBLOCK(cx,PL_curpm);
2911 Perl_croak(aTHX_ "%sCompilation failed in regexp",
2912 (*msg ? msg : "Unknown error\n"));
2916 sv_setpv(ERRSV, "Compilation error");
2919 #ifdef USE_5005THREADS
2920 MUTEX_LOCK(&PL_eval_mutex);
2922 COND_SIGNAL(&PL_eval_cond);
2923 MUTEX_UNLOCK(&PL_eval_mutex);
2924 #endif /* USE_5005THREADS */
2925 PERL_UNUSED_VAR(newsp);
2928 CopLINE_set(&PL_compiling, 0);
2930 *startop = PL_eval_root;
2932 SAVEFREEOP(PL_eval_root);
2934 /* Set the context for this new optree.
2935 * If the last op is an OP_REQUIRE, force scalar context.
2936 * Otherwise, propagate the context from the eval(). */
2937 if (PL_eval_root->op_type == OP_LEAVEEVAL
2938 && cUNOPx(PL_eval_root)->op_first->op_type == OP_LINESEQ
2939 && cLISTOPx(cUNOPx(PL_eval_root)->op_first)->op_last->op_type
2941 scalar(PL_eval_root);
2942 else if (gimme & G_VOID)
2943 scalarvoid(PL_eval_root);
2944 else if (gimme & G_ARRAY)
2947 scalar(PL_eval_root);
2949 DEBUG_x(dump_eval());
2951 /* Register with debugger: */
2952 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2953 CV * const cv = get_cv("DB::postponed", FALSE);
2957 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2959 call_sv((SV*)cv, G_DISCARD);
2963 /* compiled okay, so do it */
2965 CvDEPTH(PL_compcv) = 1;
2966 SP = PL_stack_base + POPMARK; /* pop original mark */
2967 PL_op = saveop; /* The caller may need it. */
2968 PL_lex_state = LEX_NOTPARSING; /* $^S needs this. */
2969 #ifdef USE_5005THREADS
2970 MUTEX_LOCK(&PL_eval_mutex);
2972 COND_SIGNAL(&PL_eval_cond);
2973 MUTEX_UNLOCK(&PL_eval_mutex);
2974 #endif /* USE_5005THREADS */
2976 RETURNOP(PL_eval_start);
2980 S_doopen_pm(pTHX_ const char *name, const char *mode)
2982 #ifndef PERL_DISABLE_PMC
2983 const STRLEN namelen = strlen(name);
2986 if (namelen > 3 && strEQ(name + namelen - 3, ".pm")) {
2987 SV * const pmcsv = Perl_newSVpvf(aTHX_ "%s%c", name, 'c');
2988 const char * const pmc = SvPV_nolen_const(pmcsv);
2990 if (PerlLIO_stat(pmc, &pmcstat) < 0) {
2991 fp = PerlIO_open(name, mode);
2995 if (PerlLIO_stat(name, &pmstat) < 0 ||
2996 pmstat.st_mtime < pmcstat.st_mtime)
2998 fp = PerlIO_open(pmc, mode);
3001 fp = PerlIO_open(name, mode);
3004 SvREFCNT_dec(pmcsv);
3007 fp = PerlIO_open(name, mode);
3011 return PerlIO_open(name, mode);
3012 #endif /* !PERL_DISABLE_PMC */
3018 register PERL_CONTEXT *cx;
3022 const char *tryname = Nullch;
3023 SV *namesv = Nullsv;
3025 const I32 gimme = GIMME_V;
3026 PerlIO *tryrsfp = 0;
3027 int filter_has_file = 0;
3028 GV *filter_child_proc = 0;
3029 SV *filter_state = 0;
3036 if (SvNIOKp(sv) && PL_op->op_type != OP_DOFILE) {
3037 if (SvPOK(sv) && SvNOK(sv) && SvNV(sv)) { /* require v5.6.1 */
3038 UV rev = 0, ver = 0, sver = 0;
3040 U8 *s = (U8*)SvPVX(sv);
3041 U8 *end = (U8*)SvPVX(sv) + SvCUR(sv);
3043 rev = utf8n_to_uvchr(s, end - s, &len, 0);
3046 ver = utf8n_to_uvchr(s, end - s, &len, 0);
3049 sver = utf8n_to_uvchr(s, end - s, &len, 0);
3052 if (PERL_REVISION < rev
3053 || (PERL_REVISION == rev
3054 && (PERL_VERSION < ver
3055 || (PERL_VERSION == ver
3056 && PERL_SUBVERSION < sver))))
3058 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--this is only "
3059 "v%d.%d.%d, stopped", rev, ver, sver, PERL_REVISION,
3060 PERL_VERSION, PERL_SUBVERSION);
3064 else if (!SvPOKp(sv)) { /* require 5.005_03 */
3065 if ((NV)PERL_REVISION + ((NV)PERL_VERSION/(NV)1000)
3066 + ((NV)PERL_SUBVERSION/(NV)1000000)
3067 + 0.00000099 < SvNV(sv))
3071 NV nver = (nrev - rev) * 1000;
3072 UV ver = (UV)(nver + 0.0009);
3073 NV nsver = (nver - ver) * 1000;
3074 UV sver = (UV)(nsver + 0.0009);
3076 /* help out with the "use 5.6" confusion */
3077 if (sver == 0 && (rev > 5 || (rev == 5 && ver >= 100))) {
3078 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required"
3079 " (did you mean v%"UVuf".%03"UVuf"?)--"
3080 "this is only v%d.%d.%d, stopped",
3081 rev, ver, sver, rev, ver/100,
3082 PERL_REVISION, PERL_VERSION, PERL_SUBVERSION);
3085 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--"
3086 "this is only v%d.%d.%d, stopped",
3087 rev, ver, sver, PERL_REVISION, PERL_VERSION,
3094 name = SvPV_const(sv, len);
3095 if (!(name && len > 0 && *name))
3096 DIE(aTHX_ "Null filename used");
3097 TAINT_PROPER("require");
3098 if (PL_op->op_type == OP_REQUIRE &&
3099 (svp = hv_fetch(GvHVn(PL_incgv), name, len, 0)) &&
3100 *svp != &PL_sv_undef)
3103 /* prepare to compile file */
3105 if (path_is_absolute(name)) {
3107 tryrsfp = doopen_pm(name,PERL_SCRIPT_MODE);
3109 #ifdef MACOS_TRADITIONAL
3113 MacPerl_CanonDir(name, newname, 1);
3114 if (path_is_absolute(newname)) {
3116 tryrsfp = doopen_pm(newname,PERL_SCRIPT_MODE);
3121 AV *ar = GvAVn(PL_incgv);
3125 if ((unixname = tounixspec((char *)name, Nullch)) != Nullch)
3128 namesv = NEWSV(806, 0);
3129 for (i = 0; i <= AvFILL(ar); i++) {
3130 SV *dirsv = *av_fetch(ar, i, TRUE);
3136 if (SvTYPE(SvRV(loader)) == SVt_PVAV
3137 && !sv_isobject(loader))
3139 loader = *av_fetch((AV *)SvRV(loader), 0, TRUE);
3142 Perl_sv_setpvf(aTHX_ namesv, "/loader/0x%"UVxf"/%s",
3143 PTR2UV(SvRV(dirsv)), name);
3144 tryname = SvPVX_const(namesv);
3155 if (sv_isobject(loader))
3156 count = call_method("INC", G_ARRAY);
3158 count = call_sv(loader, G_ARRAY);
3168 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVGV) {
3172 if (SvTYPE(arg) == SVt_PVGV) {
3173 IO *io = GvIO((GV *)arg);
3178 tryrsfp = IoIFP(io);
3179 if (IoTYPE(io) == IoTYPE_PIPE) {
3180 /* reading from a child process doesn't
3181 nest -- when returning from reading
3182 the inner module, the outer one is
3183 unreadable (closed?) I've tried to
3184 save the gv to manage the lifespan of
3185 the pipe, but this didn't help. XXX */
3186 filter_child_proc = (GV *)arg;
3187 (void)SvREFCNT_inc(filter_child_proc);
3190 if (IoOFP(io) && IoOFP(io) != IoIFP(io)) {
3191 PerlIO_close(IoOFP(io));
3203 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVCV) {
3205 (void)SvREFCNT_inc(filter_sub);
3208 filter_state = SP[i];
3209 (void)SvREFCNT_inc(filter_state);
3213 tryrsfp = PerlIO_open("/dev/null",
3229 filter_has_file = 0;
3230 if (filter_child_proc) {
3231 SvREFCNT_dec(filter_child_proc);
3232 filter_child_proc = 0;
3235 SvREFCNT_dec(filter_state);
3239 SvREFCNT_dec(filter_sub);
3244 if (!path_is_absolute(name)
3245 #ifdef MACOS_TRADITIONAL
3246 /* We consider paths of the form :a:b ambiguous and interpret them first
3247 as global then as local
3249 || (*name == ':' && name[1] != ':' && strchr(name+2, ':'))
3252 const char *dir = SvPVx_nolen_const(dirsv);
3253 #ifdef MACOS_TRADITIONAL
3257 MacPerl_CanonDir(name, buf2, 1);
3258 Perl_sv_setpvf(aTHX_ namesv, "%s%s", MacPerl_CanonDir(dir, buf1, 0), buf2+(buf2[0] == ':'));
3262 if ((unixdir = tounixpath((char *)dir, Nullch)) == Nullch)
3264 sv_setpv(namesv, unixdir);
3265 sv_catpv(namesv, unixname);
3268 if (PL_origfilename[0] &&
3269 PL_origfilename[1] == ':' &&
3270 !(dir[0] && dir[1] == ':'))
3271 Perl_sv_setpvf(aTHX_ namesv,
3276 Perl_sv_setpvf(aTHX_ namesv,
3280 Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name);
3284 TAINT_PROPER("require");
3285 tryname = SvPVX_const(namesv);
3286 tryrsfp = doopen_pm(tryname, PERL_SCRIPT_MODE);
3288 if (tryname[0] == '.' && tryname[1] == '/')
3297 SAVECOPFILE_FREE(&PL_compiling);
3298 CopFILE_set(&PL_compiling, tryrsfp ? tryname : name);
3299 SvREFCNT_dec(namesv);
3301 if (PL_op->op_type == OP_REQUIRE) {
3302 const char *msgstr = name;
3303 if (namesv) { /* did we lookup @INC? */
3304 SV *msg = sv_2mortal(newSVpv(msgstr,0));
3305 SV *dirmsgsv = NEWSV(0, 0);
3306 AV *ar = GvAVn(PL_incgv);
3308 sv_catpvn(msg, " in @INC", 8);
3309 if (instr(SvPVX_const(msg), ".h "))
3310 sv_catpv(msg, " (change .h to .ph maybe?)");
3311 if (instr(SvPVX_const(msg), ".ph "))
3312 sv_catpv(msg, " (did you run h2ph?)");
3313 sv_catpv(msg, " (@INC contains:");
3314 for (i = 0; i <= AvFILL(ar); i++) {
3315 const char *dir = SvPVx_nolen_const(*av_fetch(ar, i, TRUE));
3316 Perl_sv_setpvf(aTHX_ dirmsgsv, " %s", dir);
3317 sv_catsv(msg, dirmsgsv);
3319 sv_catpvn(msg, ")", 1);
3320 SvREFCNT_dec(dirmsgsv);
3321 msgstr = SvPV_nolen_const(msg);
3323 DIE(aTHX_ "Can't locate %s", msgstr);
3329 SETERRNO(0, SS_NORMAL);
3331 /* Assume success here to prevent recursive requirement. */
3333 /* Check whether a hook in @INC has already filled %INC */
3334 if (!hook_sv || !(svp = hv_fetch(GvHVn(PL_incgv), name, len, 0))) {
3335 (void)hv_store(GvHVn(PL_incgv), name, len,
3336 (hook_sv ? SvREFCNT_inc(hook_sv)
3337 : newSVpv(CopFILE(&PL_compiling), 0)),
3343 lex_start(sv_2mortal(newSVpvn("",0)));
3344 SAVEGENERICSV(PL_rsfp_filters);
3345 PL_rsfp_filters = Nullav;
3350 SAVESPTR(PL_compiling.cop_warnings);
3351 if (PL_dowarn & G_WARN_ALL_ON)
3352 PL_compiling.cop_warnings = pWARN_ALL ;
3353 else if (PL_dowarn & G_WARN_ALL_OFF)
3354 PL_compiling.cop_warnings = pWARN_NONE ;
3355 else if (PL_taint_warn)
3356 PL_compiling.cop_warnings = newSVpvn(WARN_TAINTstring, WARNsize);
3358 PL_compiling.cop_warnings = pWARN_STD ;
3359 SAVESPTR(PL_compiling.cop_io);
3360 PL_compiling.cop_io = Nullsv;
3362 if (filter_sub || filter_child_proc) {
3363 SV * const datasv = filter_add(run_user_filter, Nullsv);
3364 IoLINES(datasv) = filter_has_file;
3365 IoFMT_GV(datasv) = (GV *)filter_child_proc;
3366 IoTOP_GV(datasv) = (GV *)filter_state;
3367 IoBOTTOM_GV(datasv) = (GV *)filter_sub;
3370 /* switch to eval mode */
3371 push_return(PL_op->op_next);
3372 PUSHBLOCK(cx, CXt_EVAL, SP);
3373 PUSHEVAL(cx, name, Nullgv);
3375 SAVECOPLINE(&PL_compiling);
3376 CopLINE_set(&PL_compiling, 0);
3379 #ifdef USE_5005THREADS
3380 MUTEX_LOCK(&PL_eval_mutex);
3381 if (PL_eval_owner && PL_eval_owner != thr)
3382 while (PL_eval_owner)
3383 COND_WAIT(&PL_eval_cond, &PL_eval_mutex);
3384 PL_eval_owner = thr;
3385 MUTEX_UNLOCK(&PL_eval_mutex);
3386 #endif /* USE_5005THREADS */
3388 /* Store and reset encoding. */
3389 encoding = PL_encoding;
3390 PL_encoding = Nullsv;
3392 op = DOCATCH(doeval(gimme, NULL, Nullcv, PL_curcop->cop_seq));
3394 /* Restore encoding. */
3395 PL_encoding = encoding;
3402 return pp_require();
3408 register PERL_CONTEXT *cx;
3410 const I32 gimme = GIMME_V;
3411 const I32 was = PL_sub_generation;
3412 char tbuf[TYPE_DIGITS(long) + 12];
3413 char *tmpbuf = tbuf;
3420 if (!SvPV_const(sv,len))
3422 TAINT_PROPER("eval");
3428 /* switch to eval mode */
3430 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
3431 SV * const sv = sv_newmortal();
3432 Perl_sv_setpvf(aTHX_ sv, "_<(eval %lu)[%s:%"IVdf"]",
3433 (unsigned long)++PL_evalseq,
3434 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
3438 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++PL_evalseq);
3439 SAVECOPFILE_FREE(&PL_compiling);
3440 CopFILE_set(&PL_compiling, tmpbuf+2);
3441 SAVECOPLINE(&PL_compiling);
3442 CopLINE_set(&PL_compiling, 1);
3443 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
3444 deleting the eval's FILEGV from the stash before gv_check() runs
3445 (i.e. before run-time proper). To work around the coredump that
3446 ensues, we always turn GvMULTI_on for any globals that were
3447 introduced within evals. See force_ident(). GSAR 96-10-12 */
3448 safestr = savepv(tmpbuf);
3449 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
3451 PL_hints = PL_op->op_targ;
3452 SAVESPTR(PL_compiling.cop_warnings);
3453 if (specialWARN(PL_curcop->cop_warnings))
3454 PL_compiling.cop_warnings = PL_curcop->cop_warnings;
3456 PL_compiling.cop_warnings = newSVsv(PL_curcop->cop_warnings);
3457 SAVEFREESV(PL_compiling.cop_warnings);
3459 SAVESPTR(PL_compiling.cop_io);
3460 if (specialCopIO(PL_curcop->cop_io))
3461 PL_compiling.cop_io = PL_curcop->cop_io;
3463 PL_compiling.cop_io = newSVsv(PL_curcop->cop_io);
3464 SAVEFREESV(PL_compiling.cop_io);
3466 /* special case: an eval '' executed within the DB package gets lexically
3467 * placed in the first non-DB CV rather than the current CV - this
3468 * allows the debugger to execute code, find lexicals etc, in the
3469 * scope of the code being debugged. Passing &seq gets find_runcv
3470 * to do the dirty work for us */
3471 runcv = find_runcv(&seq);
3473 push_return(PL_op->op_next);
3474 PUSHBLOCK(cx, (CXt_EVAL|CXp_REAL), SP);
3475 PUSHEVAL(cx, 0, Nullgv);
3477 /* prepare to compile string */
3479 if (PERLDB_LINE && PL_curstash != PL_debstash)
3480 save_lines(CopFILEAV(&PL_compiling), PL_linestr);
3482 #ifdef USE_5005THREADS
3483 MUTEX_LOCK(&PL_eval_mutex);
3484 if (PL_eval_owner && PL_eval_owner != thr)
3485 while (PL_eval_owner)
3486 COND_WAIT(&PL_eval_cond, &PL_eval_mutex);
3487 PL_eval_owner = thr;
3488 MUTEX_UNLOCK(&PL_eval_mutex);
3489 #endif /* USE_5005THREADS */
3490 ret = doeval(gimme, NULL, runcv, seq);
3491 if (PERLDB_INTER && was != (I32)PL_sub_generation /* Some subs defined here. */
3492 && ret != PL_op->op_next) { /* Successive compilation. */
3493 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
3495 return DOCATCH(ret);
3505 register PERL_CONTEXT *cx;
3507 const U8 save_flags = PL_op -> op_flags;
3512 retop = pop_return();
3515 if (gimme == G_VOID)
3517 else if (gimme == G_SCALAR) {
3520 if (SvFLAGS(TOPs) & SVs_TEMP)
3523 *MARK = sv_mortalcopy(TOPs);
3527 *MARK = &PL_sv_undef;
3532 /* in case LEAVE wipes old return values */
3533 for (mark = newsp + 1; mark <= SP; mark++) {
3534 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
3535 *mark = sv_mortalcopy(*mark);
3536 TAINT_NOT; /* Each item is independent */
3540 PL_curpm = newpm; /* Don't pop $1 et al till now */
3543 assert(CvDEPTH(PL_compcv) == 1);
3545 CvDEPTH(PL_compcv) = 0;
3548 if (optype == OP_REQUIRE &&
3549 !(gimme == G_SCALAR ? SvTRUE(*SP) : SP > newsp))
3551 /* Unassume the success we assumed earlier. */
3552 SV * const nsv = cx->blk_eval.old_namesv;
3553 (void)hv_delete(GvHVn(PL_incgv), SvPVX_const(nsv), SvCUR(nsv), G_DISCARD);
3554 retop = Perl_die(aTHX_ "%"SVf" did not return a true value", nsv);
3555 /* die_where() did LEAVE, or we won't be here */
3559 if (!(save_flags & OPf_SPECIAL))
3560 sv_setpvn(ERRSV,"",0);
3569 register PERL_CONTEXT *cx;
3570 const I32 gimme = GIMME_V;
3575 push_return(cLOGOP->op_other->op_next);
3576 PUSHBLOCK(cx, (CXt_EVAL|CXp_TRYBLOCK), SP);
3579 PL_in_eval = EVAL_INEVAL;
3580 sv_setpvn(ERRSV,"",0);
3582 return DOCATCH(PL_op->op_next);
3593 register PERL_CONTEXT *cx;
3598 retop = pop_return();
3599 PERL_UNUSED_VAR(optype);
3602 if (gimme == G_VOID)
3604 else if (gimme == G_SCALAR) {
3607 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
3610 *MARK = sv_mortalcopy(TOPs);
3614 *MARK = &PL_sv_undef;
3619 /* in case LEAVE wipes old return values */
3620 for (mark = newsp + 1; mark <= SP; mark++) {
3621 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
3622 *mark = sv_mortalcopy(*mark);
3623 TAINT_NOT; /* Each item is independent */
3627 PL_curpm = newpm; /* Don't pop $1 et al till now */
3630 sv_setpvn(ERRSV,"",0);
3635 S_doparseform(pTHX_ SV *sv)
3638 register char *s = SvPV_force(sv, len);
3639 register char *send = s + len;
3640 register char *base = Nullch;
3641 register I32 skipspaces = 0;
3642 bool noblank = FALSE;
3643 bool repeat = FALSE;
3644 bool postspace = FALSE;
3650 bool unchopnum = FALSE;
3651 int maxops = 12; /* FF_LINEMARK + FF_END + 10 (\0 without preceding \n) */
3654 Perl_croak(aTHX_ "Null picture in formline");
3656 /* estimate the buffer size needed */
3657 for (base = s; s <= send; s++) {
3658 if (*s == '\n' || *s == '@' || *s == '^')
3664 Newx(fops, maxops, U32);
3669 *fpc++ = FF_LINEMARK;
3670 noblank = repeat = FALSE;
3688 case ' ': case '\t':
3695 } /* else FALL THROUGH */
3703 *fpc++ = FF_LITERAL;
3711 *fpc++ = (U16)skipspaces;
3715 *fpc++ = FF_NEWLINE;
3719 arg = fpc - linepc + 1;
3726 *fpc++ = FF_LINEMARK;
3727 noblank = repeat = FALSE;
3736 ischop = s[-1] == '^';
3742 arg = (s - base) - 1;
3744 *fpc++ = FF_LITERAL;
3752 *fpc++ = 2; /* skip the @* or ^* */
3754 *fpc++ = FF_LINESNGL;
3757 *fpc++ = FF_LINEGLOB;
3759 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
3760 arg = ischop ? 512 : 0;
3765 const char * const f = ++s;
3768 arg |= 256 + (s - f);
3770 *fpc++ = s - base; /* fieldsize for FETCH */
3771 *fpc++ = FF_DECIMAL;
3773 unchopnum |= ! ischop;
3775 else if (*s == '0' && s[1] == '#') { /* Zero padded decimals */
3776 arg = ischop ? 512 : 0;
3778 s++; /* skip the '0' first */
3782 const char * const f = ++s;
3785 arg |= 256 + (s - f);
3787 *fpc++ = s - base; /* fieldsize for FETCH */
3788 *fpc++ = FF_0DECIMAL;
3790 unchopnum |= ! ischop;
3794 bool ismore = FALSE;
3797 while (*++s == '>') ;
3798 prespace = FF_SPACE;
3800 else if (*s == '|') {
3801 while (*++s == '|') ;
3802 prespace = FF_HALFSPACE;
3807 while (*++s == '<') ;
3810 if (*s == '.' && s[1] == '.' && s[2] == '.') {
3814 *fpc++ = s - base; /* fieldsize for FETCH */
3816 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
3819 *fpc++ = (U16)prespace;
3833 assert (fpc <= fops + maxops); /* ensure our buffer estimate was valid */
3835 { /* need to jump to the next word */
3837 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
3838 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U32) + 4);
3839 s = SvPVX(sv) + SvCUR(sv) + z;
3841 Copy(fops, s, arg, U32);
3843 sv_magic(sv, Nullsv, PERL_MAGIC_fm, Nullch, 0);
3846 if (unchopnum && repeat)
3847 DIE(aTHX_ "Repeated format line will never terminate (~~ and @#)");
3853 S_num_overflow(NV value, I32 fldsize, I32 frcsize)
3855 /* Can value be printed in fldsize chars, using %*.*f ? */
3859 int intsize = fldsize - (value < 0 ? 1 : 0);
3866 while (intsize--) pwr *= 10.0;
3867 while (frcsize--) eps /= 10.0;
3870 if (value + eps >= pwr)
3873 if (value - eps <= -pwr)
3880 run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen)
3882 SV *datasv = FILTER_DATA(idx);
3883 const int filter_has_file = IoLINES(datasv);
3884 GV *filter_child_proc = (GV *)IoFMT_GV(datasv);
3885 SV *filter_state = (SV *)IoTOP_GV(datasv);
3886 SV *filter_sub = (SV *)IoBOTTOM_GV(datasv);
3889 /* I was having segfault trouble under Linux 2.2.5 after a
3890 parse error occured. (Had to hack around it with a test
3891 for PL_error_count == 0.) Solaris doesn't segfault --
3892 not sure where the trouble is yet. XXX */
3894 if (filter_has_file) {
3895 len = FILTER_READ(idx+1, buf_sv, maxlen);
3898 if (filter_sub && len >= 0) {
3909 PUSHs(sv_2mortal(newSViv(maxlen)));
3911 PUSHs(filter_state);
3914 count = call_sv(filter_sub, G_SCALAR);
3930 IoLINES(datasv) = 0;
3931 if (filter_child_proc) {
3932 SvREFCNT_dec(filter_child_proc);
3933 IoFMT_GV(datasv) = Nullgv;
3936 SvREFCNT_dec(filter_state);
3937 IoTOP_GV(datasv) = Nullgv;
3940 SvREFCNT_dec(filter_sub);
3941 IoBOTTOM_GV(datasv) = Nullgv;
3943 filter_del(run_user_filter);
3949 /* perhaps someone can come up with a better name for
3950 this? it is not really "absolute", per se ... */
3952 S_path_is_absolute(pTHX_ const char *name)
3954 if (PERL_FILE_IS_ABSOLUTE(name)
3955 #ifdef MACOS_TRADITIONAL
3958 || (*name == '.' && (name[1] == '/' ||
3959 (name[1] == '.' && name[2] == '/'))))
3970 * c-indentation-style: bsd
3972 * indent-tabs-mode: t
3975 * ex: set ts=8 sts=4 sw=4 noet: