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))
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 *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)
1339 if (PL_in_eval & EVAL_KEEPERR) {
1340 static const char prefix[] = "\t(in cleanup) ";
1342 const char *e = Nullch;
1344 sv_setpvn(err,"",0);
1345 else if (SvCUR(err) >= sizeof(prefix)+msglen-1) {
1347 e = SvPV_const(err, len);
1349 if (*e != *message || strNE(e,message))
1353 SvGROW(err, SvCUR(err)+sizeof(prefix)+msglen);
1354 sv_catpvn(err, prefix, sizeof(prefix)-1);
1355 sv_catpvn(err, message, msglen);
1356 if (ckWARN(WARN_MISC)) {
1357 const STRLEN start = SvCUR(err)-msglen-sizeof(prefix)+1;
1358 Perl_warner(aTHX_ packWARN(WARN_MISC), SvPVX_const(err)+start);
1363 sv_setpvn(ERRSV, message, msglen);
1367 while ((cxix = dopoptoeval(cxstack_ix)) < 0
1368 && PL_curstackinfo->si_prev)
1376 register PERL_CONTEXT *cx;
1379 if (cxix < cxstack_ix)
1382 POPBLOCK(cx,PL_curpm);
1383 if (CxTYPE(cx) != CXt_EVAL) {
1385 message = SvPVx_const(ERRSV, msglen);
1386 PerlIO_write(Perl_error_log, "panic: die ", 11);
1387 PerlIO_write(Perl_error_log, message, msglen);
1392 if (gimme == G_SCALAR)
1393 *++newsp = &PL_sv_undef;
1394 PL_stack_sp = newsp;
1398 /* LEAVE could clobber PL_curcop (see save_re_context())
1399 * XXX it might be better to find a way to avoid messing with
1400 * PL_curcop in save_re_context() instead, but this is a more
1401 * minimal fix --GSAR */
1402 PL_curcop = cx->blk_oldcop;
1404 if (optype == OP_REQUIRE) {
1405 const char* msg = SvPVx_nolen_const(ERRSV);
1406 DIE(aTHX_ "%sCompilation failed in require",
1407 *msg ? msg : "Unknown error\n");
1409 return pop_return();
1413 message = SvPVx_const(ERRSV, msglen);
1415 write_to_stderr(message, msglen);
1424 if (SvTRUE(left) != SvTRUE(right))
1436 RETURNOP(cLOGOP->op_other);
1445 RETURNOP(cLOGOP->op_other);
1451 register I32 cxix = dopoptosub(cxstack_ix);
1452 register const PERL_CONTEXT *cx;
1453 register const PERL_CONTEXT *ccstack = cxstack;
1454 const PERL_SI *top_si = PL_curstackinfo;
1456 const char *stashname;
1463 /* we may be in a higher stacklevel, so dig down deeper */
1464 while (cxix < 0 && top_si->si_type != PERLSI_MAIN) {
1465 top_si = top_si->si_prev;
1466 ccstack = top_si->si_cxstack;
1467 cxix = dopoptosub_at(ccstack, top_si->si_cxix);
1470 if (GIMME != G_ARRAY) {
1476 /* caller() should not report the automatic calls to &DB::sub */
1477 if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 &&
1478 ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub))
1482 cxix = dopoptosub_at(ccstack, cxix - 1);
1485 cx = &ccstack[cxix];
1486 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1487 const I32 dbcxix = dopoptosub_at(ccstack, cxix - 1);
1488 /* We expect that ccstack[dbcxix] is CXt_SUB, anyway, the
1489 field below is defined for any cx. */
1490 /* caller() should not report the automatic calls to &DB::sub */
1491 if (PL_DBsub && GvCV(PL_DBsub) && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub))
1492 cx = &ccstack[dbcxix];
1495 stashname = CopSTASHPV(cx->blk_oldcop);
1496 if (GIMME != G_ARRAY) {
1499 PUSHs(&PL_sv_undef);
1502 sv_setpv(TARG, stashname);
1511 PUSHs(&PL_sv_undef);
1513 PUSHs(sv_2mortal(newSVpv(stashname, 0)));
1514 PUSHs(sv_2mortal(newSVpv(OutCopFILE(cx->blk_oldcop), 0)));
1515 PUSHs(sv_2mortal(newSViv((I32)CopLINE(cx->blk_oldcop))));
1518 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1519 GV *cvgv = CvGV(ccstack[cxix].blk_sub.cv);
1520 /* So is ccstack[dbcxix]. */
1522 SV * const sv = NEWSV(49, 0);
1523 gv_efullname3(sv, cvgv, Nullch);
1524 PUSHs(sv_2mortal(sv));
1525 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1528 PUSHs(sv_2mortal(newSVpvn("(unknown)",9)));
1529 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1533 PUSHs(sv_2mortal(newSVpvn("(eval)",6)));
1534 PUSHs(sv_2mortal(newSViv(0)));
1536 gimme = (I32)cx->blk_gimme;
1537 if (gimme == G_VOID)
1538 PUSHs(&PL_sv_undef);
1540 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1541 if (CxTYPE(cx) == CXt_EVAL) {
1543 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1544 PUSHs(cx->blk_eval.cur_text);
1548 else if (cx->blk_eval.old_namesv) {
1549 PUSHs(sv_2mortal(newSVsv(cx->blk_eval.old_namesv)));
1552 /* eval BLOCK (try blocks have old_namesv == 0) */
1554 PUSHs(&PL_sv_undef);
1555 PUSHs(&PL_sv_undef);
1559 PUSHs(&PL_sv_undef);
1560 PUSHs(&PL_sv_undef);
1562 if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.hasargs
1563 && CopSTASH_eq(PL_curcop, PL_debstash))
1565 AV * const ary = cx->blk_sub.argarray;
1566 const int off = AvARRAY(ary) - AvALLOC(ary);
1570 PL_dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1573 AvREAL_off(PL_dbargs); /* XXX should be REIFY (see av.h) */
1576 if (AvMAX(PL_dbargs) < AvFILLp(ary) + off)
1577 av_extend(PL_dbargs, AvFILLp(ary) + off);
1578 Copy(AvALLOC(ary), AvARRAY(PL_dbargs), AvFILLp(ary) + 1 + off, SV*);
1579 AvFILLp(PL_dbargs) = AvFILLp(ary) + off;
1581 /* XXX only hints propagated via op_private are currently
1582 * visible (others are not easily accessible, since they
1583 * use the global PL_hints) */
1584 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->op_private &
1585 HINT_PRIVATE_MASK)));
1588 SV * old_warnings = cx->blk_oldcop->cop_warnings ;
1590 if (old_warnings == pWARN_NONE ||
1591 (old_warnings == pWARN_STD && (PL_dowarn & G_WARN_ON) == 0))
1592 mask = newSVpvn(WARN_NONEstring, WARNsize) ;
1593 else if (old_warnings == pWARN_ALL ||
1594 (old_warnings == pWARN_STD && PL_dowarn & G_WARN_ON)) {
1595 /* Get the bit mask for $warnings::Bits{all}, because
1596 * it could have been extended by warnings::register */
1598 HV *bits = get_hv("warnings::Bits", FALSE);
1599 if (bits && (bits_all=hv_fetch(bits, "all", 3, FALSE))) {
1600 mask = newSVsv(*bits_all);
1603 mask = newSVpvn(WARN_ALLstring, WARNsize) ;
1607 mask = newSVsv(old_warnings);
1608 PUSHs(sv_2mortal(mask));
1622 sv_reset(tmps, CopSTASH(PL_curcop));
1632 /* like pp_nextstate, but used instead when the debugger is active */
1636 PL_curcop = (COP*)PL_op;
1637 TAINT_NOT; /* Each statement is presumed innocent */
1638 PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
1641 if (PL_op->op_flags & OPf_SPECIAL /* breakpoint */
1642 || SvIV(PL_DBsingle) || SvIV(PL_DBsignal) || SvIV(PL_DBtrace))
1646 register PERL_CONTEXT *cx;
1647 const I32 gimme = G_ARRAY;
1654 DIE(aTHX_ "No DB::DB routine defined");
1656 if (CvDEPTH(cv) >= 1 && !(PL_debug & DEBUG_DB_RECURSE_FLAG))
1657 /* don't do recursive DB::DB call */
1669 push_return(PL_op->op_next);
1670 PUSHBLOCK(cx, CXt_SUB, SP);
1674 PAD_SET_CUR_NOSAVE(CvPADLIST(cv), 1);
1675 RETURNOP(CvSTART(cv));
1689 register PERL_CONTEXT *cx;
1690 const I32 gimme = GIMME_V;
1692 U32 cxtype = CXt_LOOP;
1700 #ifdef USE_5005THREADS
1701 if (PL_op->op_flags & OPf_SPECIAL) {
1702 svp = &THREADSV(PL_op->op_targ); /* per-thread variable */
1703 SAVEGENERICSV(*svp);
1707 #endif /* USE_5005THREADS */
1708 if (PL_op->op_targ) {
1709 #ifndef USE_ITHREADS
1710 svp = &PAD_SVl(PL_op->op_targ); /* "my" variable */
1713 SAVEPADSV(PL_op->op_targ);
1714 iterdata = INT2PTR(void*, PL_op->op_targ);
1715 cxtype |= CXp_PADVAR;
1720 svp = &GvSV(gv); /* symbol table variable */
1721 SAVEGENERICSV(*svp);
1724 iterdata = (void*)gv;
1730 PUSHBLOCK(cx, cxtype, SP);
1732 PUSHLOOP(cx, iterdata, MARK);
1734 PUSHLOOP(cx, svp, MARK);
1736 if (PL_op->op_flags & OPf_STACKED) {
1737 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1738 if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) {
1740 SV *right = (SV*)cx->blk_loop.iterary;
1741 if (RANGE_IS_NUMERIC(sv,right)) {
1742 if ((SvOK(sv) && SvNV(sv) < IV_MIN) ||
1743 (SvOK(right) && SvNV(right) >= IV_MAX))
1744 DIE(aTHX_ "Range iterator outside integer range");
1745 cx->blk_loop.iterix = SvIV(sv);
1746 cx->blk_loop.itermax = SvIV(right);
1748 /* for correct -Dstv display */
1749 cx->blk_oldsp = sp - PL_stack_base;
1753 cx->blk_loop.iterlval = newSVsv(sv);
1754 (void) SvPV_force_nolen(cx->blk_loop.iterlval);
1755 (void) SvPV_nolen_const(right);
1758 else if (PL_op->op_private & OPpITER_REVERSED) {
1759 cx->blk_loop.itermax = -1;
1760 cx->blk_loop.iterix = AvFILL(cx->blk_loop.iterary);
1765 cx->blk_loop.iterary = PL_curstack;
1766 AvFILLp(PL_curstack) = SP - PL_stack_base;
1767 if (PL_op->op_private & OPpITER_REVERSED) {
1768 cx->blk_loop.itermax = MARK - PL_stack_base;
1769 cx->blk_loop.iterix = cx->blk_oldsp;
1772 cx->blk_loop.iterix = MARK - PL_stack_base;
1782 register PERL_CONTEXT *cx;
1783 const I32 gimme = GIMME_V;
1789 PUSHBLOCK(cx, CXt_LOOP, SP);
1790 PUSHLOOP(cx, 0, SP);
1798 register PERL_CONTEXT *cx;
1805 assert(CxTYPE(cx) == CXt_LOOP);
1807 newsp = PL_stack_base + cx->blk_loop.resetsp;
1810 if (gimme == G_VOID)
1812 else if (gimme == G_SCALAR) {
1814 *++newsp = sv_mortalcopy(*SP);
1816 *++newsp = &PL_sv_undef;
1820 *++newsp = sv_mortalcopy(*++mark);
1821 TAINT_NOT; /* Each item is independent */
1827 POPLOOP(cx); /* Stack values are safe: release loop vars ... */
1828 PL_curpm = newpm; /* ... and pop $1 et al */
1840 register PERL_CONTEXT *cx;
1841 bool popsub2 = FALSE;
1842 bool clear_errsv = FALSE;
1849 if (PL_curstackinfo->si_type == PERLSI_SORT) {
1850 if (cxstack_ix == PL_sortcxix
1851 || dopoptosub(cxstack_ix) <= PL_sortcxix)
1853 if (cxstack_ix > PL_sortcxix)
1854 dounwind(PL_sortcxix);
1855 AvARRAY(PL_curstack)[1] = *SP;
1856 PL_stack_sp = PL_stack_base + 1;
1861 cxix = dopoptosub(cxstack_ix);
1863 DIE(aTHX_ "Can't return outside a subroutine");
1864 if (cxix < cxstack_ix)
1868 switch (CxTYPE(cx)) {
1871 cxstack_ix++; /* preserve cx entry on stack for use by POPSUB */
1874 if (!(PL_in_eval & EVAL_KEEPERR))
1880 if (optype == OP_REQUIRE &&
1881 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1883 /* Unassume the success we assumed earlier. */
1884 SV * const nsv = cx->blk_eval.old_namesv;
1885 (void)hv_delete(GvHVn(PL_incgv), SvPVX_const(nsv), SvCUR(nsv), G_DISCARD);
1886 DIE(aTHX_ "%"SVf" did not return a true value", nsv);
1893 DIE(aTHX_ "panic: return");
1897 if (gimme == G_SCALAR) {
1900 if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
1902 *++newsp = SvREFCNT_inc(*SP);
1907 sv = SvREFCNT_inc(*SP); /* FREETMPS could clobber it */
1909 *++newsp = sv_mortalcopy(sv);
1914 *++newsp = (SvTEMP(*SP)) ? *SP : sv_mortalcopy(*SP);
1917 *++newsp = sv_mortalcopy(*SP);
1920 *++newsp = &PL_sv_undef;
1922 else if (gimme == G_ARRAY) {
1923 while (++MARK <= SP) {
1924 *++newsp = (popsub2 && SvTEMP(*MARK))
1925 ? *MARK : sv_mortalcopy(*MARK);
1926 TAINT_NOT; /* Each item is independent */
1929 PL_stack_sp = newsp;
1932 /* Stack values are safe: */
1935 POPSUB(cx,sv); /* release CV and @_ ... */
1939 PL_curpm = newpm; /* ... and pop $1 et al */
1943 sv_setpvn(ERRSV,"",0);
1944 return pop_return();
1951 register PERL_CONTEXT *cx;
1962 if (PL_op->op_flags & OPf_SPECIAL) {
1963 cxix = dopoptoloop(cxstack_ix);
1965 DIE(aTHX_ "Can't \"last\" outside a loop block");
1968 cxix = dopoptolabel(cPVOP->op_pv);
1970 DIE(aTHX_ "Label not found for \"last %s\"", cPVOP->op_pv);
1972 if (cxix < cxstack_ix)
1976 cxstack_ix++; /* temporarily protect top context */
1978 switch (CxTYPE(cx)) {
1981 newsp = PL_stack_base + cx->blk_loop.resetsp;
1982 nextop = cx->blk_loop.last_op->op_next;
1986 nextop = pop_return();
1990 nextop = pop_return();
1994 nextop = pop_return();
1997 DIE(aTHX_ "panic: last");
2001 if (gimme == G_SCALAR) {
2003 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
2004 ? *SP : sv_mortalcopy(*SP);
2006 *++newsp = &PL_sv_undef;
2008 else if (gimme == G_ARRAY) {
2009 while (++MARK <= SP) {
2010 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
2011 ? *MARK : sv_mortalcopy(*MARK);
2012 TAINT_NOT; /* Each item is independent */
2020 /* Stack values are safe: */
2023 POPLOOP(cx); /* release loop vars ... */
2027 POPSUB(cx,sv); /* release CV and @_ ... */
2030 PL_curpm = newpm; /* ... and pop $1 et al */
2033 PERL_UNUSED_VAR(optype);
2034 PERL_UNUSED_VAR(gimme);
2041 register PERL_CONTEXT *cx;
2044 if (PL_op->op_flags & OPf_SPECIAL) {
2045 cxix = dopoptoloop(cxstack_ix);
2047 DIE(aTHX_ "Can't \"next\" outside a loop block");
2050 cxix = dopoptolabel(cPVOP->op_pv);
2052 DIE(aTHX_ "Label not found for \"next %s\"", cPVOP->op_pv);
2054 if (cxix < cxstack_ix)
2057 /* clear off anything above the scope we're re-entering, but
2058 * save the rest until after a possible continue block */
2059 inner = PL_scopestack_ix;
2061 if (PL_scopestack_ix < inner)
2062 leave_scope(PL_scopestack[PL_scopestack_ix]);
2063 PL_curcop = cx->blk_oldcop;
2064 return cx->blk_loop.next_op;
2070 register PERL_CONTEXT *cx;
2073 if (PL_op->op_flags & OPf_SPECIAL) {
2074 cxix = dopoptoloop(cxstack_ix);
2076 DIE(aTHX_ "Can't \"redo\" outside a loop block");
2079 cxix = dopoptolabel(cPVOP->op_pv);
2081 DIE(aTHX_ "Label not found for \"redo %s\"", cPVOP->op_pv);
2083 if (cxix < cxstack_ix)
2087 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2088 LEAVE_SCOPE(oldsave);
2090 PL_curcop = cx->blk_oldcop;
2091 return cx->blk_loop.redo_op;
2095 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) {
2115 /* First try all the kids at this level, since that's likeliest. */
2116 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
2117 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
2118 kCOP->cop_label && strEQ(kCOP->cop_label, label))
2121 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
2122 if (kid == PL_lastgotoprobe)
2124 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
2127 else if (ops[-1]->op_type == OP_NEXTSTATE ||
2128 ops[-1]->op_type == OP_DBSTATE)
2133 if ((o = dofindlabel(kid, label, ops, oplimit)))
2152 register PERL_CONTEXT *cx;
2153 #define GOTO_DEPTH 64
2154 OP *enterops[GOTO_DEPTH];
2155 const char *label = 0;
2156 const bool do_dump = (PL_op->op_type == OP_DUMP);
2157 static const char must_have_label[] = "goto must have label";
2159 if (PL_op->op_flags & OPf_STACKED) {
2160 SV * const sv = POPs;
2162 /* This egregious kludge implements goto &subroutine */
2163 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
2165 register PERL_CONTEXT *cx;
2166 CV* cv = (CV*)SvRV(sv);
2173 if (!CvROOT(cv) && !CvXSUB(cv)) {
2174 const GV * const gv = CvGV(cv);
2178 /* autoloaded stub? */
2179 if (cv != GvCV(gv) && (cv = GvCV(gv)))
2181 autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv),
2182 GvNAMELEN(gv), FALSE);
2183 if (autogv && (cv = GvCV(autogv)))
2185 tmpstr = sv_newmortal();
2186 gv_efullname3(tmpstr, (GV *) gv, Nullch);
2187 DIE(aTHX_ "Goto undefined subroutine &%"SVf"",tmpstr);
2189 DIE(aTHX_ "Goto undefined subroutine");
2192 /* First do some returnish stuff. */
2193 (void)SvREFCNT_inc(cv); /* avoid premature free during unwind */
2195 cxix = dopoptosub(cxstack_ix);
2197 DIE(aTHX_ "Can't goto subroutine outside a subroutine");
2198 if (cxix < cxstack_ix)
2202 if (CxTYPE(cx) == CXt_EVAL) {
2204 DIE(aTHX_ "Can't goto subroutine from an eval-string");
2206 DIE(aTHX_ "Can't goto subroutine from an eval-block");
2208 if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.hasargs) {
2209 /* put @_ back onto stack */
2210 AV* av = cx->blk_sub.argarray;
2212 items = AvFILLp(av) + 1;
2213 EXTEND(SP, items+1); /* @_ could have been extended. */
2214 Copy(AvARRAY(av), SP + 1, items, SV*);
2215 #ifndef USE_5005THREADS
2216 SvREFCNT_dec(GvAV(PL_defgv));
2217 GvAV(PL_defgv) = cx->blk_sub.savearray;
2218 #endif /* USE_5005THREADS */
2220 /* abandon @_ if it got reified */
2225 av_extend(av, items-1);
2226 AvFLAGS(av) = AVf_REIFY;
2227 PAD_SVl(0) = (SV*)(cx->blk_sub.argarray = av);
2230 else if (CvXSUB(cv)) { /* put GvAV(defgv) back onto stack */
2231 #ifdef USE_5005THREADS
2232 AV* const av = (AV*)PAD_SVl(0);
2234 AV* const av = GvAV(PL_defgv);
2236 items = AvFILLp(av) + 1;
2237 EXTEND(SP, items+1); /* @_ could have been extended. */
2238 Copy(AvARRAY(av), SP + 1, items, SV*);
2242 if (CxTYPE(cx) == CXt_SUB &&
2243 !(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
2244 SvREFCNT_dec(cx->blk_sub.cv);
2245 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2246 LEAVE_SCOPE(oldsave);
2248 /* Now do some callish stuff. */
2250 SAVEFREESV(cv); /* later, undo the 'avoid premature free' hack */
2254 for (index=0; index<items; index++)
2255 sv_2mortal(SP[-index]);
2257 #ifdef PERL_XSUB_OLDSTYLE
2258 if (CvOLDSTYLE(cv)) {
2259 I32 (*fp3)(int,int,int);
2264 fp3 = (I32(*)(int,int,int))CvXSUB(cv);
2265 items = (*fp3)(CvXSUBANY(cv).any_i32,
2266 mark - PL_stack_base + 1,
2268 SP = PL_stack_base + items;
2271 #endif /* PERL_XSUB_OLDSTYLE */
2276 /* Push a mark for the start of arglist */
2279 (void)(*CvXSUB(cv))(aTHX_ cv);
2281 /* Pop the current context like a decent sub should */
2282 POPBLOCK(cx, PL_curpm);
2283 /* Do _not_ use PUTBACK, keep the XSUB's return stack! */
2285 /* Put these at the bottom since the vars are set but not used */
2286 PERL_UNUSED_VAR(newsp);
2287 PERL_UNUSED_VAR(gimme);
2290 return pop_return();
2293 AV* padlist = CvPADLIST(cv);
2294 if (CxTYPE(cx) == CXt_EVAL) {
2295 PL_in_eval = cx->blk_eval.old_in_eval;
2296 PL_eval_root = cx->blk_eval.old_eval_root;
2297 cx->cx_type = CXt_SUB;
2298 cx->blk_sub.hasargs = 0;
2300 cx->blk_sub.cv = cv;
2301 cx->blk_sub.olddepth = (U16)CvDEPTH(cv);
2304 if (CvDEPTH(cv) < 2)
2305 (void)SvREFCNT_inc(cv);
2307 if (CvDEPTH(cv) == 100 && ckWARN(WARN_RECURSION))
2308 sub_crush_depth(cv);
2309 pad_push(padlist, CvDEPTH(cv), 1);
2311 #ifdef USE_5005THREADS
2312 if (!cx->blk_sub.hasargs) {
2313 AV* av = (AV*)PAD_SVl(0);
2315 items = AvFILLp(av) + 1;
2317 /* Mark is at the end of the stack. */
2319 Copy(AvARRAY(av), SP + 1, items, SV*);
2324 #endif /* USE_5005THREADS */
2326 PAD_SET_CUR_NOSAVE(padlist, CvDEPTH(cv));
2327 #ifndef USE_5005THREADS
2328 if (cx->blk_sub.hasargs)
2329 #endif /* USE_5005THREADS */
2331 AV* av = (AV*)PAD_SVl(0);
2334 #ifndef USE_5005THREADS
2335 cx->blk_sub.savearray = GvAV(PL_defgv);
2336 GvAV(PL_defgv) = (AV*)SvREFCNT_inc(av);
2337 #endif /* USE_5005THREADS */
2338 CX_CURPAD_SAVE(cx->blk_sub);
2339 cx->blk_sub.argarray = av;
2341 if (items >= AvMAX(av) + 1) {
2343 if (AvARRAY(av) != ary) {
2344 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
2345 SvPV_set(av, (char*)ary);
2347 if (items >= AvMAX(av) + 1) {
2348 AvMAX(av) = items - 1;
2349 Renew(ary,items+1,SV*);
2351 SvPV_set(av, (char*)ary);
2355 Copy(mark,AvARRAY(av),items,SV*);
2356 AvFILLp(av) = items - 1;
2357 assert(!AvREAL(av));
2359 /* transfer 'ownership' of refcnts to new @_ */
2369 if (PERLDB_SUB) { /* Checking curstash breaks DProf. */
2371 * We do not care about using sv to call CV;
2372 * it's for informational purposes only.
2374 SV * const sv = GvSV(PL_DBsub);
2378 if (PERLDB_SUB_NN) {
2379 const int type = SvTYPE(sv);
2380 if (type < SVt_PVIV && type != SVt_IV)
2381 sv_upgrade(sv, SVt_PVIV);
2383 SvIV_set(sv, PTR2IV(cv)); /* Do it the quickest way */
2385 gv_efullname3(sv, CvGV(cv), Nullch);
2388 && (gotocv = get_cv("DB::goto", FALSE)) ) {
2389 PUSHMARK( PL_stack_sp );
2390 call_sv((SV*)gotocv, G_SCALAR | G_NODEBUG);
2394 RETURNOP(CvSTART(cv));
2398 label = SvPV_nolen_const(sv);
2399 if (!(do_dump || *label))
2400 DIE(aTHX_ must_have_label);
2403 else if (PL_op->op_flags & OPf_SPECIAL) {
2405 DIE(aTHX_ must_have_label);
2408 label = cPVOP->op_pv;
2410 if (label && *label) {
2412 bool leaving_eval = FALSE;
2413 bool in_block = FALSE;
2414 PERL_CONTEXT *last_eval_cx = 0;
2418 PL_lastgotoprobe = 0;
2420 for (ix = cxstack_ix; ix >= 0; ix--) {
2422 switch (CxTYPE(cx)) {
2424 leaving_eval = TRUE;
2425 if (!CxTRYBLOCK(cx)) {
2426 gotoprobe = (last_eval_cx ?
2427 last_eval_cx->blk_eval.old_eval_root :
2432 /* else fall through */
2434 gotoprobe = cx->blk_oldcop->op_sibling;
2440 gotoprobe = cx->blk_oldcop->op_sibling;
2443 gotoprobe = PL_main_root;
2446 if (CvDEPTH(cx->blk_sub.cv)) {
2447 gotoprobe = CvROOT(cx->blk_sub.cv);
2453 DIE(aTHX_ "Can't \"goto\" out of a pseudo block");
2456 DIE(aTHX_ "panic: goto");
2457 gotoprobe = PL_main_root;
2461 retop = dofindlabel(gotoprobe, label,
2462 enterops, enterops + GOTO_DEPTH);
2466 PL_lastgotoprobe = gotoprobe;
2469 DIE(aTHX_ "Can't find label %s", label);
2471 /* if we're leaving an eval, check before we pop any frames
2472 that we're not going to punt, otherwise the error
2475 if (leaving_eval && *enterops && enterops[1]) {
2477 for (i = 1; enterops[i]; i++)
2478 if (enterops[i]->op_type == OP_ENTERITER)
2479 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2482 /* pop unwanted frames */
2484 if (ix < cxstack_ix) {
2491 oldsave = PL_scopestack[PL_scopestack_ix];
2492 LEAVE_SCOPE(oldsave);
2495 /* push wanted frames */
2497 if (*enterops && enterops[1]) {
2499 ix = enterops[1]->op_type == OP_ENTER && in_block ? 2 : 1;
2500 for (; enterops[ix]; ix++) {
2501 PL_op = enterops[ix];
2502 /* Eventually we may want to stack the needed arguments
2503 * for each op. For now, we punt on the hard ones. */
2504 if (PL_op->op_type == OP_ENTERITER)
2505 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2506 CALL_FPTR(PL_op->op_ppaddr)(aTHX);
2514 if (!retop) retop = PL_main_start;
2516 PL_restartop = retop;
2517 PL_do_undump = TRUE;
2521 PL_restartop = 0; /* hmm, must be GNU unexec().. */
2522 PL_do_undump = FALSE;
2538 if (anum == 1 && (PL_op->op_private & OPpEXIT_VMSISH))
2540 VMSISH_HUSHED = VMSISH_HUSHED || (PL_op->op_private & OPpHUSH_VMSISH);
2543 PL_exit_flags |= PERL_EXIT_EXPECTED;
2545 PUSHs(&PL_sv_undef);
2553 const NV value = SvNVx(GvSV(cCOP->cop_gv));
2554 register I32 match = I_32(value);
2557 if (((NV)match) > value)
2558 --match; /* was fractional--truncate other way */
2560 match -= cCOP->uop.scop.scop_offset;
2563 else if (match > cCOP->uop.scop.scop_max)
2564 match = cCOP->uop.scop.scop_max;
2565 PL_op = cCOP->uop.scop.scop_next[match];
2575 PL_op = PL_op->op_next; /* can't assume anything */
2577 match = *(SvPVx_nolen_const(GvSV(cCOP->cop_gv))) & 255;
2578 match -= cCOP->uop.scop.scop_offset;
2581 else if (match > cCOP->uop.scop.scop_max)
2582 match = cCOP->uop.scop.scop_max;
2583 PL_op = cCOP->uop.scop.scop_next[match];
2592 S_save_lines(pTHX_ AV *array, SV *sv)
2594 const char *s = SvPVX_const(sv);
2595 const char * const send = SvPVX_const(sv) + SvCUR(sv);
2598 while (s && s < send) {
2600 SV * const tmpstr = NEWSV(85,0);
2602 sv_upgrade(tmpstr, SVt_PVMG);
2603 t = strchr(s, '\n');
2609 sv_setpvn(tmpstr, s, t - s);
2610 av_store(array, line++, tmpstr);
2615 #ifdef PERL_FLEXIBLE_EXCEPTIONS
2617 S_docatch_body(pTHX_ va_list args)
2619 return docatch_body();
2624 S_docatch_body(pTHX)
2631 S_docatch(pTHX_ OP *o)
2634 OP * const oldop = PL_op;
2636 volatile PERL_SI *cursi = PL_curstackinfo;
2640 assert(CATCH_GET == TRUE);
2644 /* Normally, the leavetry at the end of this block of ops will
2645 * pop an op off the return stack and continue there. By setting
2646 * the op to Nullop, we force an exit from the inner runops()
2649 retop = pop_return();
2650 push_return(Nullop);
2652 #ifdef PERL_FLEXIBLE_EXCEPTIONS
2654 CALLPROTECT(aTHX_ pcur_env, &ret, MEMBER_TO_FPTR(S_docatch_body));
2660 #ifndef PERL_FLEXIBLE_EXCEPTIONS
2666 /* die caught by an inner eval - continue inner loop */
2667 if (PL_restartop && cursi == PL_curstackinfo) {
2668 PL_op = PL_restartop;
2672 /* a die in this eval - continue in outer loop */
2688 Perl_sv_compile_2op(pTHX_ SV *sv, OP** startop, char *code, PAD** padp)
2689 /* sv Text to convert to OP tree. */
2690 /* startop op_free() this to undo. */
2691 /* code Short string id of the caller. */
2693 dSP; /* Make POPBLOCK work. */
2700 char tbuf[TYPE_DIGITS(long) + 12 + 10];
2701 char *tmpbuf = tbuf;
2704 CV* runcv = Nullcv; /* initialise to avoid compiler warnings */
2709 /* switch to eval mode */
2711 if (IN_PERL_COMPILETIME) {
2712 SAVECOPSTASH_FREE(&PL_compiling);
2713 CopSTASH_set(&PL_compiling, PL_curstash);
2715 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
2716 SV * const sv = sv_newmortal();
2717 Perl_sv_setpvf(aTHX_ sv, "_<(%.10seval %lu)[%s:%"IVdf"]",
2718 code, (unsigned long)++PL_evalseq,
2719 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
2723 sprintf(tmpbuf, "_<(%.10s_eval %lu)", code, (unsigned long)++PL_evalseq);
2724 SAVECOPFILE_FREE(&PL_compiling);
2725 CopFILE_set(&PL_compiling, tmpbuf+2);
2726 SAVECOPLINE(&PL_compiling);
2727 CopLINE_set(&PL_compiling, 1);
2728 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2729 deleting the eval's FILEGV from the stash before gv_check() runs
2730 (i.e. before run-time proper). To work around the coredump that
2731 ensues, we always turn GvMULTI_on for any globals that were
2732 introduced within evals. See force_ident(). GSAR 96-10-12 */
2733 safestr = savepv(tmpbuf);
2734 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
2736 #ifdef OP_IN_REGISTER
2742 /* we get here either during compilation, or via pp_regcomp at runtime */
2743 runtime = IN_PERL_RUNTIME;
2745 runcv = find_runcv(NULL);
2748 PL_op->op_type = OP_ENTEREVAL;
2749 PL_op->op_flags = 0; /* Avoid uninit warning. */
2750 PUSHBLOCK(cx, CXt_EVAL|(IN_PERL_COMPILETIME ? 0 : CXp_REAL), SP);
2751 PUSHEVAL(cx, 0, Nullgv);
2754 rop = doeval(G_SCALAR, startop, runcv, PL_curcop->cop_seq);
2756 rop = doeval(G_SCALAR, startop, PL_compcv, PL_cop_seqmax);
2757 POPBLOCK(cx,PL_curpm);
2760 (*startop)->op_type = OP_NULL;
2761 (*startop)->op_ppaddr = PL_ppaddr[OP_NULL];
2763 /* XXX DAPM do this properly one year */
2764 *padp = (AV*)SvREFCNT_inc(PL_comppad);
2766 if (IN_PERL_COMPILETIME)
2767 PL_compiling.op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);
2768 #ifdef OP_IN_REGISTER
2771 PERL_UNUSED_VAR(newsp);
2772 PERL_UNUSED_VAR(optype);
2779 =for apidoc find_runcv
2781 Locate the CV corresponding to the currently executing sub or eval.
2782 If db_seqp is non_null, skip CVs that are in the DB package and populate
2783 *db_seqp with the cop sequence number at the point that the DB:: code was
2784 entered. (allows debuggers to eval in the scope of the breakpoint rather
2785 than in the scope of the debugger itself).
2791 Perl_find_runcv(pTHX_ U32 *db_seqp)
2796 *db_seqp = PL_curcop->cop_seq;
2797 for (si = PL_curstackinfo; si; si = si->si_prev) {
2799 for (ix = si->si_cxix; ix >= 0; ix--) {
2800 const PERL_CONTEXT *cx = &(si->si_cxstack[ix]);
2801 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
2802 CV * const cv = cx->blk_sub.cv;
2803 /* skip DB:: code */
2804 if (db_seqp && PL_debstash && CvSTASH(cv) == PL_debstash) {
2805 *db_seqp = cx->blk_oldcop->cop_seq;
2810 else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx))
2818 /* Compile a require/do, an eval '', or a /(?{...})/.
2819 * In the last case, startop is non-null, and contains the address of
2820 * a pointer that should be set to the just-compiled code.
2821 * outside is the lexically enclosing CV (if any) that invoked us.
2824 /* With USE_5005THREADS, eval_owner must be held on entry to doeval */
2826 S_doeval(pTHX_ int gimme, OP** startop, CV* outside, U32 seq)
2831 PL_in_eval = ((saveop && saveop->op_type == OP_REQUIRE)
2832 ? (EVAL_INREQUIRE | (PL_in_eval & EVAL_INEVAL))
2837 SAVESPTR(PL_compcv);
2838 PL_compcv = (CV*)NEWSV(1104,0);
2839 sv_upgrade((SV *)PL_compcv, SVt_PVCV);
2840 CvEVAL_on(PL_compcv);
2841 assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
2842 cxstack[cxstack_ix].blk_eval.cv = PL_compcv;
2844 #ifdef USE_5005THREADS
2845 CvOWNER(PL_compcv) = 0;
2846 New(666, CvMUTEXP(PL_compcv), 1, perl_mutex);
2847 MUTEX_INIT(CvMUTEXP(PL_compcv));
2848 #endif /* USE_5005THREADS */
2850 CvOUTSIDE_SEQ(PL_compcv) = seq;
2851 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outside);
2853 /* set up a scratch pad */
2855 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE);
2858 SAVEMORTALIZESV(PL_compcv); /* must remain until end of current statement */
2860 /* make sure we compile in the right package */
2862 if (CopSTASH_ne(PL_curcop, PL_curstash)) {
2863 SAVESPTR(PL_curstash);
2864 PL_curstash = CopSTASH(PL_curcop);
2866 SAVESPTR(PL_beginav);
2867 PL_beginav = newAV();
2868 SAVEFREESV(PL_beginav);
2869 SAVEI32(PL_error_count);
2871 /* try to compile it */
2873 PL_eval_root = Nullop;
2875 PL_curcop = &PL_compiling;
2876 PL_curcop->cop_arybase = 0;
2877 if (saveop && saveop->op_flags & OPf_SPECIAL)
2878 PL_in_eval |= EVAL_KEEPERR;
2880 sv_setpvn(ERRSV,"",0);
2881 if (yyparse() || PL_error_count || !PL_eval_root) {
2882 SV **newsp; /* Used by POPBLOCK. */
2884 I32 optype = 0; /* Might be reset by POPEVAL. */
2889 op_free(PL_eval_root);
2890 PL_eval_root = Nullop;
2892 SP = PL_stack_base + POPMARK; /* pop original mark */
2894 POPBLOCK(cx,PL_curpm);
2901 msg = SvPVx_nolen_const(ERRSV);
2902 if (optype == OP_REQUIRE) {
2903 const char* const msg = SvPVx_nolen_const(ERRSV);
2904 DIE(aTHX_ "%sCompilation failed in require",
2905 *msg ? msg : "Unknown error\n");
2908 POPBLOCK(cx,PL_curpm);
2910 Perl_croak(aTHX_ "%sCompilation failed in regexp",
2911 (*msg ? msg : "Unknown error\n"));
2915 sv_setpv(ERRSV, "Compilation error");
2918 #ifdef USE_5005THREADS
2919 MUTEX_LOCK(&PL_eval_mutex);
2921 COND_SIGNAL(&PL_eval_cond);
2922 MUTEX_UNLOCK(&PL_eval_mutex);
2923 #endif /* USE_5005THREADS */
2924 PERL_UNUSED_VAR(newsp);
2927 CopLINE_set(&PL_compiling, 0);
2929 *startop = PL_eval_root;
2931 SAVEFREEOP(PL_eval_root);
2933 /* Set the context for this new optree.
2934 * If the last op is an OP_REQUIRE, force scalar context.
2935 * Otherwise, propagate the context from the eval(). */
2936 if (PL_eval_root->op_type == OP_LEAVEEVAL
2937 && cUNOPx(PL_eval_root)->op_first->op_type == OP_LINESEQ
2938 && cLISTOPx(cUNOPx(PL_eval_root)->op_first)->op_last->op_type
2940 scalar(PL_eval_root);
2941 else if (gimme & G_VOID)
2942 scalarvoid(PL_eval_root);
2943 else if (gimme & G_ARRAY)
2946 scalar(PL_eval_root);
2948 DEBUG_x(dump_eval());
2950 /* Register with debugger: */
2951 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2952 CV * const cv = get_cv("DB::postponed", FALSE);
2956 XPUSHs((SV*)CopFILEGV(&PL_compiling));
2958 call_sv((SV*)cv, G_DISCARD);
2962 /* compiled okay, so do it */
2964 CvDEPTH(PL_compcv) = 1;
2965 SP = PL_stack_base + POPMARK; /* pop original mark */
2966 PL_op = saveop; /* The caller may need it. */
2967 PL_lex_state = LEX_NOTPARSING; /* $^S needs this. */
2968 #ifdef USE_5005THREADS
2969 MUTEX_LOCK(&PL_eval_mutex);
2971 COND_SIGNAL(&PL_eval_cond);
2972 MUTEX_UNLOCK(&PL_eval_mutex);
2973 #endif /* USE_5005THREADS */
2975 RETURNOP(PL_eval_start);
2979 S_doopen_pm(pTHX_ const char *name, const char *mode)
2981 #ifndef PERL_DISABLE_PMC
2982 const STRLEN namelen = strlen(name);
2985 if (namelen > 3 && strEQ(name + namelen - 3, ".pm")) {
2986 SV * const pmcsv = Perl_newSVpvf(aTHX_ "%s%c", name, 'c');
2987 const char * const pmc = SvPV_nolen_const(pmcsv);
2989 if (PerlLIO_stat(pmc, &pmcstat) < 0) {
2990 fp = PerlIO_open(name, mode);
2994 if (PerlLIO_stat(name, &pmstat) < 0 ||
2995 pmstat.st_mtime < pmcstat.st_mtime)
2997 fp = PerlIO_open(pmc, mode);
3000 fp = PerlIO_open(name, mode);
3003 SvREFCNT_dec(pmcsv);
3006 fp = PerlIO_open(name, mode);
3010 return PerlIO_open(name, mode);
3011 #endif /* !PERL_DISABLE_PMC */
3017 register PERL_CONTEXT *cx;
3021 const char *tryname = Nullch;
3022 SV *namesv = Nullsv;
3024 const I32 gimme = GIMME_V;
3025 PerlIO *tryrsfp = 0;
3026 int filter_has_file = 0;
3027 GV *filter_child_proc = 0;
3028 SV *filter_state = 0;
3035 if (SvNIOKp(sv) && PL_op->op_type != OP_DOFILE) {
3036 if (SvPOK(sv) && SvNOK(sv) && SvNV(sv)) { /* require v5.6.1 */
3037 UV rev = 0, ver = 0, sver = 0;
3039 U8 *s = (U8*)SvPVX(sv);
3040 U8 *end = (U8*)SvPVX(sv) + SvCUR(sv);
3042 rev = utf8n_to_uvchr(s, end - s, &len, 0);
3045 ver = utf8n_to_uvchr(s, end - s, &len, 0);
3048 sver = utf8n_to_uvchr(s, end - s, &len, 0);
3051 if (PERL_REVISION < rev
3052 || (PERL_REVISION == rev
3053 && (PERL_VERSION < ver
3054 || (PERL_VERSION == ver
3055 && PERL_SUBVERSION < sver))))
3057 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--this is only "
3058 "v%d.%d.%d, stopped", rev, ver, sver, PERL_REVISION,
3059 PERL_VERSION, PERL_SUBVERSION);
3063 else if (!SvPOKp(sv)) { /* require 5.005_03 */
3064 if ((NV)PERL_REVISION + ((NV)PERL_VERSION/(NV)1000)
3065 + ((NV)PERL_SUBVERSION/(NV)1000000)
3066 + 0.00000099 < SvNV(sv))
3070 NV nver = (nrev - rev) * 1000;
3071 UV ver = (UV)(nver + 0.0009);
3072 NV nsver = (nver - ver) * 1000;
3073 UV sver = (UV)(nsver + 0.0009);
3075 /* help out with the "use 5.6" confusion */
3076 if (sver == 0 && (rev > 5 || (rev == 5 && ver >= 100))) {
3077 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required"
3078 " (did you mean v%"UVuf".%03"UVuf"?)--"
3079 "this is only v%d.%d.%d, stopped",
3080 rev, ver, sver, rev, ver/100,
3081 PERL_REVISION, PERL_VERSION, PERL_SUBVERSION);
3084 DIE(aTHX_ "Perl v%"UVuf".%"UVuf".%"UVuf" required--"
3085 "this is only v%d.%d.%d, stopped",
3086 rev, ver, sver, PERL_REVISION, PERL_VERSION,
3093 name = SvPV_const(sv, len);
3094 if (!(name && len > 0 && *name))
3095 DIE(aTHX_ "Null filename used");
3096 TAINT_PROPER("require");
3097 if (PL_op->op_type == OP_REQUIRE &&
3098 (svp = hv_fetch(GvHVn(PL_incgv), name, len, 0)) &&
3099 *svp != &PL_sv_undef)
3102 /* prepare to compile file */
3104 if (path_is_absolute(name)) {
3106 tryrsfp = doopen_pm(name,PERL_SCRIPT_MODE);
3108 #ifdef MACOS_TRADITIONAL
3112 MacPerl_CanonDir(name, newname, 1);
3113 if (path_is_absolute(newname)) {
3115 tryrsfp = doopen_pm(newname,PERL_SCRIPT_MODE);
3120 AV *ar = GvAVn(PL_incgv);
3124 if ((unixname = tounixspec(name, Nullch)) != Nullch)
3127 namesv = NEWSV(806, 0);
3128 for (i = 0; i <= AvFILL(ar); i++) {
3129 SV *dirsv = *av_fetch(ar, i, TRUE);
3135 if (SvTYPE(SvRV(loader)) == SVt_PVAV
3136 && !sv_isobject(loader))
3138 loader = *av_fetch((AV *)SvRV(loader), 0, TRUE);
3141 Perl_sv_setpvf(aTHX_ namesv, "/loader/0x%"UVxf"/%s",
3142 PTR2UV(SvRV(dirsv)), name);
3143 tryname = SvPVX_const(namesv);
3154 if (sv_isobject(loader))
3155 count = call_method("INC", G_ARRAY);
3157 count = call_sv(loader, G_ARRAY);
3167 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVGV) {
3171 if (SvTYPE(arg) == SVt_PVGV) {
3172 IO *io = GvIO((GV *)arg);
3177 tryrsfp = IoIFP(io);
3178 if (IoTYPE(io) == IoTYPE_PIPE) {
3179 /* reading from a child process doesn't
3180 nest -- when returning from reading
3181 the inner module, the outer one is
3182 unreadable (closed?) I've tried to
3183 save the gv to manage the lifespan of
3184 the pipe, but this didn't help. XXX */
3185 filter_child_proc = (GV *)arg;
3186 (void)SvREFCNT_inc(filter_child_proc);
3189 if (IoOFP(io) && IoOFP(io) != IoIFP(io)) {
3190 PerlIO_close(IoOFP(io));
3202 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVCV) {
3204 (void)SvREFCNT_inc(filter_sub);
3207 filter_state = SP[i];
3208 (void)SvREFCNT_inc(filter_state);
3212 tryrsfp = PerlIO_open("/dev/null",
3228 filter_has_file = 0;
3229 if (filter_child_proc) {
3230 SvREFCNT_dec(filter_child_proc);
3231 filter_child_proc = 0;
3234 SvREFCNT_dec(filter_state);
3238 SvREFCNT_dec(filter_sub);
3243 if (!path_is_absolute(name)
3244 #ifdef MACOS_TRADITIONAL
3245 /* We consider paths of the form :a:b ambiguous and interpret them first
3246 as global then as local
3248 || (*name == ':' && name[1] != ':' && strchr(name+2, ':'))
3251 const char *dir = SvPVx_nolen_const(dirsv);
3252 #ifdef MACOS_TRADITIONAL
3256 MacPerl_CanonDir(name, buf2, 1);
3257 Perl_sv_setpvf(aTHX_ namesv, "%s%s", MacPerl_CanonDir(dir, buf1, 0), buf2+(buf2[0] == ':'));
3261 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
3263 sv_setpv(namesv, unixdir);
3264 sv_catpv(namesv, unixname);
3266 Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name);
3269 TAINT_PROPER("require");
3270 tryname = SvPVX_const(namesv);
3271 tryrsfp = doopen_pm(tryname, PERL_SCRIPT_MODE);
3273 if (tryname[0] == '.' && tryname[1] == '/')
3282 SAVECOPFILE_FREE(&PL_compiling);
3283 CopFILE_set(&PL_compiling, tryrsfp ? tryname : name);
3284 SvREFCNT_dec(namesv);
3286 if (PL_op->op_type == OP_REQUIRE) {
3287 const char *msgstr = name;
3288 if (namesv) { /* did we lookup @INC? */
3289 SV *msg = sv_2mortal(newSVpv(msgstr,0));
3290 SV *dirmsgsv = NEWSV(0, 0);
3291 AV *ar = GvAVn(PL_incgv);
3293 sv_catpvn(msg, " in @INC", 8);
3294 if (instr(SvPVX_const(msg), ".h "))
3295 sv_catpv(msg, " (change .h to .ph maybe?)");
3296 if (instr(SvPVX_const(msg), ".ph "))
3297 sv_catpv(msg, " (did you run h2ph?)");
3298 sv_catpv(msg, " (@INC contains:");
3299 for (i = 0; i <= AvFILL(ar); i++) {
3300 const char *dir = SvPVx_nolen_const(*av_fetch(ar, i, TRUE));
3301 Perl_sv_setpvf(aTHX_ dirmsgsv, " %s", dir);
3302 sv_catsv(msg, dirmsgsv);
3304 sv_catpvn(msg, ")", 1);
3305 SvREFCNT_dec(dirmsgsv);
3306 msgstr = SvPV_nolen_const(msg);
3308 DIE(aTHX_ "Can't locate %s", msgstr);
3314 SETERRNO(0, SS_NORMAL);
3316 /* Assume success here to prevent recursive requirement. */
3318 /* Check whether a hook in @INC has already filled %INC */
3319 if (!hook_sv || !(svp = hv_fetch(GvHVn(PL_incgv), name, len, 0))) {
3320 (void)hv_store(GvHVn(PL_incgv), name, len,
3321 (hook_sv ? SvREFCNT_inc(hook_sv)
3322 : newSVpv(CopFILE(&PL_compiling), 0)),
3328 lex_start(sv_2mortal(newSVpvn("",0)));
3329 SAVEGENERICSV(PL_rsfp_filters);
3330 PL_rsfp_filters = Nullav;
3335 SAVESPTR(PL_compiling.cop_warnings);
3336 if (PL_dowarn & G_WARN_ALL_ON)
3337 PL_compiling.cop_warnings = pWARN_ALL ;
3338 else if (PL_dowarn & G_WARN_ALL_OFF)
3339 PL_compiling.cop_warnings = pWARN_NONE ;
3340 else if (PL_taint_warn)
3341 PL_compiling.cop_warnings = newSVpvn(WARN_TAINTstring, WARNsize);
3343 PL_compiling.cop_warnings = pWARN_STD ;
3344 SAVESPTR(PL_compiling.cop_io);
3345 PL_compiling.cop_io = Nullsv;
3347 if (filter_sub || filter_child_proc) {
3348 SV * const datasv = filter_add(run_user_filter, Nullsv);
3349 IoLINES(datasv) = filter_has_file;
3350 IoFMT_GV(datasv) = (GV *)filter_child_proc;
3351 IoTOP_GV(datasv) = (GV *)filter_state;
3352 IoBOTTOM_GV(datasv) = (GV *)filter_sub;
3355 /* switch to eval mode */
3356 push_return(PL_op->op_next);
3357 PUSHBLOCK(cx, CXt_EVAL, SP);
3358 PUSHEVAL(cx, name, Nullgv);
3360 SAVECOPLINE(&PL_compiling);
3361 CopLINE_set(&PL_compiling, 0);
3364 #ifdef USE_5005THREADS
3365 MUTEX_LOCK(&PL_eval_mutex);
3366 if (PL_eval_owner && PL_eval_owner != thr)
3367 while (PL_eval_owner)
3368 COND_WAIT(&PL_eval_cond, &PL_eval_mutex);
3369 PL_eval_owner = thr;
3370 MUTEX_UNLOCK(&PL_eval_mutex);
3371 #endif /* USE_5005THREADS */
3373 /* Store and reset encoding. */
3374 encoding = PL_encoding;
3375 PL_encoding = Nullsv;
3377 op = DOCATCH(doeval(gimme, NULL, Nullcv, PL_curcop->cop_seq));
3379 /* Restore encoding. */
3380 PL_encoding = encoding;
3387 return pp_require();
3393 register PERL_CONTEXT *cx;
3395 const I32 gimme = GIMME_V;
3396 const I32 was = PL_sub_generation;
3397 char tbuf[TYPE_DIGITS(long) + 12];
3398 char *tmpbuf = tbuf;
3405 if (!SvPV_const(sv,len))
3407 TAINT_PROPER("eval");
3413 /* switch to eval mode */
3415 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
3416 SV * const sv = sv_newmortal();
3417 Perl_sv_setpvf(aTHX_ sv, "_<(eval %lu)[%s:%"IVdf"]",
3418 (unsigned long)++PL_evalseq,
3419 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
3423 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++PL_evalseq);
3424 SAVECOPFILE_FREE(&PL_compiling);
3425 CopFILE_set(&PL_compiling, tmpbuf+2);
3426 SAVECOPLINE(&PL_compiling);
3427 CopLINE_set(&PL_compiling, 1);
3428 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
3429 deleting the eval's FILEGV from the stash before gv_check() runs
3430 (i.e. before run-time proper). To work around the coredump that
3431 ensues, we always turn GvMULTI_on for any globals that were
3432 introduced within evals. See force_ident(). GSAR 96-10-12 */
3433 safestr = savepv(tmpbuf);
3434 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
3436 PL_hints = PL_op->op_targ;
3437 SAVESPTR(PL_compiling.cop_warnings);
3438 if (specialWARN(PL_curcop->cop_warnings))
3439 PL_compiling.cop_warnings = PL_curcop->cop_warnings;
3441 PL_compiling.cop_warnings = newSVsv(PL_curcop->cop_warnings);
3442 SAVEFREESV(PL_compiling.cop_warnings);
3444 SAVESPTR(PL_compiling.cop_io);
3445 if (specialCopIO(PL_curcop->cop_io))
3446 PL_compiling.cop_io = PL_curcop->cop_io;
3448 PL_compiling.cop_io = newSVsv(PL_curcop->cop_io);
3449 SAVEFREESV(PL_compiling.cop_io);
3451 /* special case: an eval '' executed within the DB package gets lexically
3452 * placed in the first non-DB CV rather than the current CV - this
3453 * allows the debugger to execute code, find lexicals etc, in the
3454 * scope of the code being debugged. Passing &seq gets find_runcv
3455 * to do the dirty work for us */
3456 runcv = find_runcv(&seq);
3458 push_return(PL_op->op_next);
3459 PUSHBLOCK(cx, (CXt_EVAL|CXp_REAL), SP);
3460 PUSHEVAL(cx, 0, Nullgv);
3462 /* prepare to compile string */
3464 if (PERLDB_LINE && PL_curstash != PL_debstash)
3465 save_lines(CopFILEAV(&PL_compiling), PL_linestr);
3467 #ifdef USE_5005THREADS
3468 MUTEX_LOCK(&PL_eval_mutex);
3469 if (PL_eval_owner && PL_eval_owner != thr)
3470 while (PL_eval_owner)
3471 COND_WAIT(&PL_eval_cond, &PL_eval_mutex);
3472 PL_eval_owner = thr;
3473 MUTEX_UNLOCK(&PL_eval_mutex);
3474 #endif /* USE_5005THREADS */
3475 ret = doeval(gimme, NULL, runcv, seq);
3476 if (PERLDB_INTER && was != (I32)PL_sub_generation /* Some subs defined here. */
3477 && ret != PL_op->op_next) { /* Successive compilation. */
3478 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
3480 return DOCATCH(ret);
3490 register PERL_CONTEXT *cx;
3492 const U8 save_flags = PL_op -> op_flags;
3497 retop = pop_return();
3500 if (gimme == G_VOID)
3502 else if (gimme == G_SCALAR) {
3505 if (SvFLAGS(TOPs) & SVs_TEMP)
3508 *MARK = sv_mortalcopy(TOPs);
3512 *MARK = &PL_sv_undef;
3517 /* in case LEAVE wipes old return values */
3518 for (mark = newsp + 1; mark <= SP; mark++) {
3519 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
3520 *mark = sv_mortalcopy(*mark);
3521 TAINT_NOT; /* Each item is independent */
3525 PL_curpm = newpm; /* Don't pop $1 et al till now */
3528 assert(CvDEPTH(PL_compcv) == 1);
3530 CvDEPTH(PL_compcv) = 0;
3533 if (optype == OP_REQUIRE &&
3534 !(gimme == G_SCALAR ? SvTRUE(*SP) : SP > newsp))
3536 /* Unassume the success we assumed earlier. */
3537 SV * const nsv = cx->blk_eval.old_namesv;
3538 (void)hv_delete(GvHVn(PL_incgv), SvPVX_const(nsv), SvCUR(nsv), G_DISCARD);
3539 retop = Perl_die(aTHX_ "%"SVf" did not return a true value", nsv);
3540 /* die_where() did LEAVE, or we won't be here */
3544 if (!(save_flags & OPf_SPECIAL))
3545 sv_setpvn(ERRSV,"",0);
3554 register PERL_CONTEXT *cx;
3555 const I32 gimme = GIMME_V;
3560 push_return(cLOGOP->op_other->op_next);
3561 PUSHBLOCK(cx, (CXt_EVAL|CXp_TRYBLOCK), SP);
3564 PL_in_eval = EVAL_INEVAL;
3565 sv_setpvn(ERRSV,"",0);
3567 return DOCATCH(PL_op->op_next);
3578 register PERL_CONTEXT *cx;
3583 retop = pop_return();
3584 PERL_UNUSED_VAR(optype);
3587 if (gimme == G_VOID)
3589 else if (gimme == G_SCALAR) {
3592 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
3595 *MARK = sv_mortalcopy(TOPs);
3599 *MARK = &PL_sv_undef;
3604 /* in case LEAVE wipes old return values */
3605 for (mark = newsp + 1; mark <= SP; mark++) {
3606 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
3607 *mark = sv_mortalcopy(*mark);
3608 TAINT_NOT; /* Each item is independent */
3612 PL_curpm = newpm; /* Don't pop $1 et al till now */
3615 sv_setpvn(ERRSV,"",0);
3620 S_doparseform(pTHX_ SV *sv)
3623 register char *s = SvPV_force(sv, len);
3624 register char *send = s + len;
3625 register char *base = Nullch;
3626 register I32 skipspaces = 0;
3627 bool noblank = FALSE;
3628 bool repeat = FALSE;
3629 bool postspace = FALSE;
3635 bool unchopnum = FALSE;
3636 int maxops = 12; /* FF_LINEMARK + FF_END + 10 (\0 without preceding \n) */
3639 Perl_croak(aTHX_ "Null picture in formline");
3641 /* estimate the buffer size needed */
3642 for (base = s; s <= send; s++) {
3643 if (*s == '\n' || *s == '@' || *s == '^')
3649 Newx(fops, maxops, U32);
3654 *fpc++ = FF_LINEMARK;
3655 noblank = repeat = FALSE;
3673 case ' ': case '\t':
3680 } /* else FALL THROUGH */
3688 *fpc++ = FF_LITERAL;
3696 *fpc++ = (U16)skipspaces;
3700 *fpc++ = FF_NEWLINE;
3704 arg = fpc - linepc + 1;
3711 *fpc++ = FF_LINEMARK;
3712 noblank = repeat = FALSE;
3721 ischop = s[-1] == '^';
3727 arg = (s - base) - 1;
3729 *fpc++ = FF_LITERAL;
3737 *fpc++ = 2; /* skip the @* or ^* */
3739 *fpc++ = FF_LINESNGL;
3742 *fpc++ = FF_LINEGLOB;
3744 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
3745 arg = ischop ? 512 : 0;
3750 const char * const f = ++s;
3753 arg |= 256 + (s - f);
3755 *fpc++ = s - base; /* fieldsize for FETCH */
3756 *fpc++ = FF_DECIMAL;
3758 unchopnum |= ! ischop;
3760 else if (*s == '0' && s[1] == '#') { /* Zero padded decimals */
3761 arg = ischop ? 512 : 0;
3763 s++; /* skip the '0' first */
3767 const char * const f = ++s;
3770 arg |= 256 + (s - f);
3772 *fpc++ = s - base; /* fieldsize for FETCH */
3773 *fpc++ = FF_0DECIMAL;
3775 unchopnum |= ! ischop;
3779 bool ismore = FALSE;
3782 while (*++s == '>') ;
3783 prespace = FF_SPACE;
3785 else if (*s == '|') {
3786 while (*++s == '|') ;
3787 prespace = FF_HALFSPACE;
3792 while (*++s == '<') ;
3795 if (*s == '.' && s[1] == '.' && s[2] == '.') {
3799 *fpc++ = s - base; /* fieldsize for FETCH */
3801 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
3804 *fpc++ = (U16)prespace;
3818 assert (fpc <= fops + maxops); /* ensure our buffer estimate was valid */
3820 { /* need to jump to the next word */
3822 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
3823 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U32) + 4);
3824 s = SvPVX(sv) + SvCUR(sv) + z;
3826 Copy(fops, s, arg, U32);
3828 sv_magic(sv, Nullsv, PERL_MAGIC_fm, Nullch, 0);
3831 if (unchopnum && repeat)
3832 DIE(aTHX_ "Repeated format line will never terminate (~~ and @#)");
3838 S_num_overflow(NV value, I32 fldsize, I32 frcsize)
3840 /* Can value be printed in fldsize chars, using %*.*f ? */
3844 int intsize = fldsize - (value < 0 ? 1 : 0);
3851 while (intsize--) pwr *= 10.0;
3852 while (frcsize--) eps /= 10.0;
3855 if (value + eps >= pwr)
3858 if (value - eps <= -pwr)
3865 run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen)
3867 SV *datasv = FILTER_DATA(idx);
3868 const int filter_has_file = IoLINES(datasv);
3869 GV *filter_child_proc = (GV *)IoFMT_GV(datasv);
3870 SV *filter_state = (SV *)IoTOP_GV(datasv);
3871 SV *filter_sub = (SV *)IoBOTTOM_GV(datasv);
3874 /* I was having segfault trouble under Linux 2.2.5 after a
3875 parse error occured. (Had to hack around it with a test
3876 for PL_error_count == 0.) Solaris doesn't segfault --
3877 not sure where the trouble is yet. XXX */
3879 if (filter_has_file) {
3880 len = FILTER_READ(idx+1, buf_sv, maxlen);
3883 if (filter_sub && len >= 0) {
3894 PUSHs(sv_2mortal(newSViv(maxlen)));
3896 PUSHs(filter_state);
3899 count = call_sv(filter_sub, G_SCALAR);
3915 IoLINES(datasv) = 0;
3916 if (filter_child_proc) {
3917 SvREFCNT_dec(filter_child_proc);
3918 IoFMT_GV(datasv) = Nullgv;
3921 SvREFCNT_dec(filter_state);
3922 IoTOP_GV(datasv) = Nullgv;
3925 SvREFCNT_dec(filter_sub);
3926 IoBOTTOM_GV(datasv) = Nullgv;
3928 filter_del(run_user_filter);
3934 /* perhaps someone can come up with a better name for
3935 this? it is not really "absolute", per se ... */
3937 S_path_is_absolute(pTHX_ const char *name)
3939 if (PERL_FILE_IS_ABSOLUTE(name)
3940 #ifdef MACOS_TRADITIONAL
3943 || (*name == '.' && (name[1] == '/' ||
3944 (name[1] == '.' && name[2] == '/'))))
3955 * c-indentation-style: bsd
3957 * indent-tabs-mode: t
3960 * ex: set ts=8 sts=4 sw=4 noet: