This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix typos in comments
[perl5.git] / pp_ctl.c
... / ...
CommitLineData
1/* pp_ctl.c
2 *
3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 * 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by Larry Wall and others
5 *
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.
8 *
9 */
10
11/*
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.
18 *
19 * [Bilbo on p.35 of _The Lord of the Rings_, I/i: "A Long-Expected Party"]
20 */
21
22/* This file contains control-oriented pp ("push/pop") functions that
23 * execute the opcodes that make up a perl program. A typical pp function
24 * expects to find its arguments on the stack, and usually pushes its
25 * results onto the stack, hence the 'pp' terminology. Each OP structure
26 * contains a pointer to the relevant pp_foo() function.
27 *
28 * Control-oriented means things like pp_enteriter() and pp_next(), which
29 * alter the flow of control of the program.
30 */
31
32
33#include "EXTERN.h"
34#define PERL_IN_PP_CTL_C
35#include "perl.h"
36
37#ifndef WORD_ALIGN
38#define WORD_ALIGN sizeof(U32)
39#endif
40
41#define DOCATCH(o) ((CATCH_GET == TRUE) ? docatch(o) : (o))
42
43#define dopoptosub(plop) dopoptosub_at(cxstack, (plop))
44
45PP(pp_wantarray)
46{
47 dVAR;
48 dSP;
49 I32 cxix;
50 EXTEND(SP, 1);
51
52 cxix = dopoptosub(cxstack_ix);
53 if (cxix < 0)
54 RETPUSHUNDEF;
55
56 switch (cxstack[cxix].blk_gimme) {
57 case G_ARRAY:
58 RETPUSHYES;
59 case G_SCALAR:
60 RETPUSHNO;
61 default:
62 RETPUSHUNDEF;
63 }
64}
65
66PP(pp_regcreset)
67{
68 dVAR;
69 /* XXXX Should store the old value to allow for tie/overload - and
70 restore in regcomp, where marked with XXXX. */
71 PL_reginterp_cnt = 0;
72 TAINT_NOT;
73 return NORMAL;
74}
75
76PP(pp_regcomp)
77{
78 dVAR;
79 dSP;
80 register PMOP *pm = (PMOP*)cLOGOP->op_other;
81 SV *tmpstr;
82 REGEXP *re = NULL;
83
84 /* prevent recompiling under /o and ithreads. */
85#if defined(USE_ITHREADS)
86 if (pm->op_pmflags & PMf_KEEP && PM_GETRE(pm)) {
87 if (PL_op->op_flags & OPf_STACKED) {
88 dMARK;
89 SP = MARK;
90 }
91 else
92 (void)POPs;
93 RETURN;
94 }
95#endif
96
97#define tryAMAGICregexp(rx) \
98 STMT_START { \
99 SvGETMAGIC(rx); \
100 if (SvROK(rx) && SvAMAGIC(rx)) { \
101 SV *sv = AMG_CALLun(rx, regexp); \
102 if (sv) { \
103 if (SvROK(sv)) \
104 sv = SvRV(sv); \
105 if (SvTYPE(sv) != SVt_REGEXP) \
106 Perl_croak(aTHX_ "Overloaded qr did not return a REGEXP"); \
107 rx = sv; \
108 } \
109 } \
110 } STMT_END
111
112
113 if (PL_op->op_flags & OPf_STACKED) {
114 /* multiple args; concatentate them */
115 dMARK; dORIGMARK;
116 tmpstr = PAD_SV(ARGTARG);
117 sv_setpvs(tmpstr, "");
118 while (++MARK <= SP) {
119 SV *msv = *MARK;
120 SV *sv;
121
122 tryAMAGICregexp(msv);
123
124 if ((SvAMAGIC(tmpstr) || SvAMAGIC(msv)) &&
125 (sv = amagic_call(tmpstr, msv, concat_amg, AMGf_assign)))
126 {
127 sv_setsv(tmpstr, sv);
128 continue;
129 }
130 sv_catsv_nomg(tmpstr, msv);
131 }
132 SvSETMAGIC(tmpstr);
133 SP = ORIGMARK;
134 }
135 else {
136 tmpstr = POPs;
137 tryAMAGICregexp(tmpstr);
138 }
139
140#undef tryAMAGICregexp
141
142 if (SvROK(tmpstr)) {
143 SV * const sv = SvRV(tmpstr);
144 if (SvTYPE(sv) == SVt_REGEXP)
145 re = (REGEXP*) sv;
146 }
147 else if (SvTYPE(tmpstr) == SVt_REGEXP)
148 re = (REGEXP*) tmpstr;
149
150 if (re) {
151 /* The match's LHS's get-magic might need to access this op's reg-
152 exp (as is sometimes the case with $'; see bug 70764). So we
153 must call get-magic now before we replace the regexp. Hopeful-
154 ly this hack can be replaced with the approach described at
155 http://www.nntp.perl.org/group/perl.perl5.porters/2007/03
156 /msg122415.html some day. */
157 if(pm->op_type == OP_MATCH) {
158 SV *lhs;
159 const bool was_tainted = PL_tainted;
160 if (pm->op_flags & OPf_STACKED)
161 lhs = TOPs;
162 else if (pm->op_private & OPpTARGET_MY)
163 lhs = PAD_SV(pm->op_targ);
164 else lhs = DEFSV;
165 SvGETMAGIC(lhs);
166 /* Restore the previous value of PL_tainted (which may have been
167 modified by get-magic), to avoid incorrectly setting the
168 RXf_TAINTED flag further down. */
169 PL_tainted = was_tainted;
170 }
171
172 re = reg_temp_copy(NULL, re);
173 ReREFCNT_dec(PM_GETRE(pm));
174 PM_SETRE(pm, re);
175 }
176 else {
177 STRLEN len = 0;
178 const char *t = SvOK(tmpstr) ? SvPV_nomg_const(tmpstr, len) : "";
179
180 re = PM_GETRE(pm);
181 assert (re != (REGEXP*) &PL_sv_undef);
182
183 /* Check against the last compiled regexp. */
184 if (!re || !RX_PRECOMP(re) || RX_PRELEN(re) != len ||
185 memNE(RX_PRECOMP(re), t, len))
186 {
187 const regexp_engine *eng = re ? RX_ENGINE(re) : NULL;
188 U32 pm_flags = pm->op_pmflags & PMf_COMPILETIME;
189 if (re) {
190 ReREFCNT_dec(re);
191#ifdef USE_ITHREADS
192 PM_SETRE(pm, (REGEXP*) &PL_sv_undef);
193#else
194 PM_SETRE(pm, NULL); /* crucial if regcomp aborts */
195#endif
196 } else if (PL_curcop->cop_hints_hash) {
197 SV *ptr = Perl_refcounted_he_fetch(aTHX_ PL_curcop->cop_hints_hash, 0,
198 "regcomp", 7, 0, 0);
199 if (ptr && SvIOK(ptr) && SvIV(ptr))
200 eng = INT2PTR(regexp_engine*,SvIV(ptr));
201 }
202
203 if (PL_op->op_flags & OPf_SPECIAL)
204 PL_reginterp_cnt = I32_MAX; /* Mark as safe. */
205
206 if (DO_UTF8(tmpstr)) {
207 assert (SvUTF8(tmpstr));
208 } else if (SvUTF8(tmpstr)) {
209 /* Not doing UTF-8, despite what the SV says. Is this only if
210 we're trapped in use 'bytes'? */
211 /* Make a copy of the octet sequence, but without the flag on,
212 as the compiler now honours the SvUTF8 flag on tmpstr. */
213 STRLEN len;
214 const char *const p = SvPV(tmpstr, len);
215 tmpstr = newSVpvn_flags(p, len, SVs_TEMP);
216 }
217 else if (SvAMAGIC(tmpstr)) {
218 /* make a copy to avoid extra stringifies */
219 tmpstr = newSVpvn_flags(t, len, SVs_TEMP | SvUTF8(tmpstr));
220 }
221
222 /* If it is gmagical, create a mortal copy, but without calling
223 get-magic, as we have already done that. */
224 if(SvGMAGICAL(tmpstr)) {
225 SV *mortalcopy = sv_newmortal();
226 sv_setsv_flags(mortalcopy, tmpstr, 0);
227 tmpstr = mortalcopy;
228 }
229
230 if (eng)
231 PM_SETRE(pm, CALLREGCOMP_ENG(eng, tmpstr, pm_flags));
232 else
233 PM_SETRE(pm, CALLREGCOMP(tmpstr, pm_flags));
234
235 PL_reginterp_cnt = 0; /* XXXX Be extra paranoid - needed
236 inside tie/overload accessors. */
237 }
238 }
239
240 re = PM_GETRE(pm);
241
242#ifndef INCOMPLETE_TAINTS
243 if (PL_tainting) {
244 if (PL_tainted)
245 RX_EXTFLAGS(re) |= RXf_TAINTED;
246 else
247 RX_EXTFLAGS(re) &= ~RXf_TAINTED;
248 }
249#endif
250
251 if (!RX_PRELEN(PM_GETRE(pm)) && PL_curpm)
252 pm = PL_curpm;
253
254
255#if !defined(USE_ITHREADS)
256 /* can't change the optree at runtime either */
257 /* PMf_KEEP is handled differently under threads to avoid these problems */
258 if (pm->op_pmflags & PMf_KEEP) {
259 pm->op_private &= ~OPpRUNTIME; /* no point compiling again */
260 cLOGOP->op_first->op_next = PL_op->op_next;
261 }
262#endif
263 RETURN;
264}
265
266PP(pp_substcont)
267{
268 dVAR;
269 dSP;
270 register PERL_CONTEXT *cx = &cxstack[cxstack_ix];
271 register PMOP * const pm = (PMOP*) cLOGOP->op_other;
272 register SV * const dstr = cx->sb_dstr;
273 register char *s = cx->sb_s;
274 register char *m = cx->sb_m;
275 char *orig = cx->sb_orig;
276 register REGEXP * const rx = cx->sb_rx;
277 SV *nsv = NULL;
278 REGEXP *old = PM_GETRE(pm);
279
280 PERL_ASYNC_CHECK();
281
282 if(old != rx) {
283 if(old)
284 ReREFCNT_dec(old);
285 PM_SETRE(pm,ReREFCNT_inc(rx));
286 }
287
288 rxres_restore(&cx->sb_rxres, rx);
289 RX_MATCH_UTF8_set(rx, DO_UTF8(cx->sb_targ));
290
291 if (cx->sb_iters++) {
292 const I32 saviters = cx->sb_iters;
293 if (cx->sb_iters > cx->sb_maxiters)
294 DIE(aTHX_ "Substitution loop");
295
296 SvGETMAGIC(TOPs); /* possibly clear taint on $1 etc: #67962 */
297
298 if (!(cx->sb_rxtainted & 2) && SvTAINTED(TOPs))
299 cx->sb_rxtainted |= 2;
300 sv_catsv_nomg(dstr, POPs);
301 /* XXX: adjust for positive offsets of \G for instance s/(.)\G//g with positive pos() */
302 s -= RX_GOFS(rx);
303
304 /* Are we done */
305 if (CxONCE(cx) || s < orig ||
306 !CALLREGEXEC(rx, s, cx->sb_strend, orig,
307 (s == m) + RX_GOFS(rx), cx->sb_targ, NULL,
308 ((cx->sb_rflags & REXEC_COPY_STR)
309 ? (REXEC_IGNOREPOS|REXEC_NOT_FIRST)
310 : (REXEC_COPY_STR|REXEC_IGNOREPOS|REXEC_NOT_FIRST))))
311 {
312 SV * const targ = cx->sb_targ;
313
314 assert(cx->sb_strend >= s);
315 if(cx->sb_strend > s) {
316 if (DO_UTF8(dstr) && !SvUTF8(targ))
317 sv_catpvn_utf8_upgrade(dstr, s, cx->sb_strend - s, nsv);
318 else
319 sv_catpvn(dstr, s, cx->sb_strend - s);
320 }
321 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
322
323#ifdef PERL_OLD_COPY_ON_WRITE
324 if (SvIsCOW(targ)) {
325 sv_force_normal_flags(targ, SV_COW_DROP_PV);
326 } else
327#endif
328 {
329 SvPV_free(targ);
330 }
331 SvPV_set(targ, SvPVX(dstr));
332 SvCUR_set(targ, SvCUR(dstr));
333 SvLEN_set(targ, SvLEN(dstr));
334 if (DO_UTF8(dstr))
335 SvUTF8_on(targ);
336 SvPV_set(dstr, NULL);
337
338 TAINT_IF(cx->sb_rxtainted & 1);
339 if (pm->op_pmflags & PMf_NONDESTRUCT)
340 PUSHs(targ);
341 else
342 mPUSHi(saviters - 1);
343
344 (void)SvPOK_only_UTF8(targ);
345 TAINT_IF(cx->sb_rxtainted);
346 SvSETMAGIC(targ);
347 SvTAINT(targ);
348
349 LEAVE_SCOPE(cx->sb_oldsave);
350 POPSUBST(cx);
351 RETURNOP(pm->op_next);
352 }
353 cx->sb_iters = saviters;
354 }
355 if (RX_MATCH_COPIED(rx) && RX_SUBBEG(rx) != orig) {
356 m = s;
357 s = orig;
358 cx->sb_orig = orig = RX_SUBBEG(rx);
359 s = orig + (m - s);
360 cx->sb_strend = s + (cx->sb_strend - m);
361 }
362 cx->sb_m = m = RX_OFFS(rx)[0].start + orig;
363 if (m > s) {
364 if (DO_UTF8(dstr) && !SvUTF8(cx->sb_targ))
365 sv_catpvn_utf8_upgrade(dstr, s, m - s, nsv);
366 else
367 sv_catpvn(dstr, s, m-s);
368 }
369 cx->sb_s = RX_OFFS(rx)[0].end + orig;
370 { /* Update the pos() information. */
371 SV * const sv = cx->sb_targ;
372 MAGIC *mg;
373 SvUPGRADE(sv, SVt_PVMG);
374 if (!(mg = mg_find(sv, PERL_MAGIC_regex_global))) {
375#ifdef PERL_OLD_COPY_ON_WRITE
376 if (SvIsCOW(sv))
377 sv_force_normal_flags(sv, 0);
378#endif
379 mg = sv_magicext(sv, NULL, PERL_MAGIC_regex_global, &PL_vtbl_mglob,
380 NULL, 0);
381 }
382 mg->mg_len = m - orig;
383 }
384 if (old != rx)
385 (void)ReREFCNT_inc(rx);
386 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
387 rxres_save(&cx->sb_rxres, rx);
388 PL_curpm = pm;
389 RETURNOP(pm->op_pmstashstartu.op_pmreplstart);
390}
391
392void
393Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx)
394{
395 UV *p = (UV*)*rsp;
396 U32 i;
397
398 PERL_ARGS_ASSERT_RXRES_SAVE;
399 PERL_UNUSED_CONTEXT;
400
401 if (!p || p[1] < RX_NPARENS(rx)) {
402#ifdef PERL_OLD_COPY_ON_WRITE
403 i = 7 + RX_NPARENS(rx) * 2;
404#else
405 i = 6 + RX_NPARENS(rx) * 2;
406#endif
407 if (!p)
408 Newx(p, i, UV);
409 else
410 Renew(p, i, UV);
411 *rsp = (void*)p;
412 }
413
414 *p++ = PTR2UV(RX_MATCH_COPIED(rx) ? RX_SUBBEG(rx) : NULL);
415 RX_MATCH_COPIED_off(rx);
416
417#ifdef PERL_OLD_COPY_ON_WRITE
418 *p++ = PTR2UV(RX_SAVED_COPY(rx));
419 RX_SAVED_COPY(rx) = NULL;
420#endif
421
422 *p++ = RX_NPARENS(rx);
423
424 *p++ = PTR2UV(RX_SUBBEG(rx));
425 *p++ = (UV)RX_SUBLEN(rx);
426 for (i = 0; i <= RX_NPARENS(rx); ++i) {
427 *p++ = (UV)RX_OFFS(rx)[i].start;
428 *p++ = (UV)RX_OFFS(rx)[i].end;
429 }
430}
431
432static void
433S_rxres_restore(pTHX_ void **rsp, REGEXP *rx)
434{
435 UV *p = (UV*)*rsp;
436 U32 i;
437
438 PERL_ARGS_ASSERT_RXRES_RESTORE;
439 PERL_UNUSED_CONTEXT;
440
441 RX_MATCH_COPY_FREE(rx);
442 RX_MATCH_COPIED_set(rx, *p);
443 *p++ = 0;
444
445#ifdef PERL_OLD_COPY_ON_WRITE
446 if (RX_SAVED_COPY(rx))
447 SvREFCNT_dec (RX_SAVED_COPY(rx));
448 RX_SAVED_COPY(rx) = INT2PTR(SV*,*p);
449 *p++ = 0;
450#endif
451
452 RX_NPARENS(rx) = *p++;
453
454 RX_SUBBEG(rx) = INT2PTR(char*,*p++);
455 RX_SUBLEN(rx) = (I32)(*p++);
456 for (i = 0; i <= RX_NPARENS(rx); ++i) {
457 RX_OFFS(rx)[i].start = (I32)(*p++);
458 RX_OFFS(rx)[i].end = (I32)(*p++);
459 }
460}
461
462static void
463S_rxres_free(pTHX_ void **rsp)
464{
465 UV * const p = (UV*)*rsp;
466
467 PERL_ARGS_ASSERT_RXRES_FREE;
468 PERL_UNUSED_CONTEXT;
469
470 if (p) {
471#ifdef PERL_POISON
472 void *tmp = INT2PTR(char*,*p);
473 Safefree(tmp);
474 if (*p)
475 PoisonFree(*p, 1, sizeof(*p));
476#else
477 Safefree(INT2PTR(char*,*p));
478#endif
479#ifdef PERL_OLD_COPY_ON_WRITE
480 if (p[1]) {
481 SvREFCNT_dec (INT2PTR(SV*,p[1]));
482 }
483#endif
484 Safefree(p);
485 *rsp = NULL;
486 }
487}
488
489PP(pp_formline)
490{
491 dVAR; dSP; dMARK; dORIGMARK;
492 register SV * const tmpForm = *++MARK;
493 register U32 *fpc;
494 register char *t;
495 const char *f;
496 register I32 arg;
497 register SV *sv = NULL;
498 const char *item = NULL;
499 I32 itemsize = 0;
500 I32 fieldsize = 0;
501 I32 lines = 0;
502 bool chopspace = (strchr(PL_chopset, ' ') != NULL);
503 const char *chophere = NULL;
504 char *linemark = NULL;
505 NV value;
506 bool gotsome = FALSE;
507 STRLEN len;
508 const STRLEN fudge = SvPOK(tmpForm)
509 ? (SvCUR(tmpForm) * (IN_BYTES ? 1 : 3) + 1) : 0;
510 bool item_is_utf8 = FALSE;
511 bool targ_is_utf8 = FALSE;
512 SV * nsv = NULL;
513 OP * parseres = NULL;
514 const char *fmt;
515
516 if (!SvMAGICAL(tmpForm) || !SvCOMPILED(tmpForm)) {
517 if (SvREADONLY(tmpForm)) {
518 SvREADONLY_off(tmpForm);
519 parseres = doparseform(tmpForm);
520 SvREADONLY_on(tmpForm);
521 }
522 else
523 parseres = doparseform(tmpForm);
524 if (parseres)
525 return parseres;
526 }
527 SvPV_force(PL_formtarget, len);
528 if (DO_UTF8(PL_formtarget))
529 targ_is_utf8 = TRUE;
530 t = SvGROW(PL_formtarget, len + fudge + 1); /* XXX SvCUR bad */
531 t += len;
532 f = SvPV_const(tmpForm, len);
533 /* need to jump to the next word */
534 fpc = (U32*)(f + len + WORD_ALIGN - SvCUR(tmpForm) % WORD_ALIGN);
535
536 for (;;) {
537 DEBUG_f( {
538 const char *name = "???";
539 arg = -1;
540 switch (*fpc) {
541 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
542 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
543 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
544 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
545 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
546
547 case FF_CHECKNL: name = "CHECKNL"; break;
548 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
549 case FF_SPACE: name = "SPACE"; break;
550 case FF_HALFSPACE: name = "HALFSPACE"; break;
551 case FF_ITEM: name = "ITEM"; break;
552 case FF_CHOP: name = "CHOP"; break;
553 case FF_LINEGLOB: name = "LINEGLOB"; break;
554 case FF_NEWLINE: name = "NEWLINE"; break;
555 case FF_MORE: name = "MORE"; break;
556 case FF_LINEMARK: name = "LINEMARK"; break;
557 case FF_END: name = "END"; break;
558 case FF_0DECIMAL: name = "0DECIMAL"; break;
559 case FF_LINESNGL: name = "LINESNGL"; break;
560 }
561 if (arg >= 0)
562 PerlIO_printf(Perl_debug_log, "%-16s%ld\n", name, (long) arg);
563 else
564 PerlIO_printf(Perl_debug_log, "%-16s\n", name);
565 } );
566 switch (*fpc++) {
567 case FF_LINEMARK:
568 linemark = t;
569 lines++;
570 gotsome = FALSE;
571 break;
572
573 case FF_LITERAL:
574 arg = *fpc++;
575 if (targ_is_utf8 && !SvUTF8(tmpForm)) {
576 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
577 *t = '\0';
578 sv_catpvn_utf8_upgrade(PL_formtarget, f, arg, nsv);
579 t = SvEND(PL_formtarget);
580 f += arg;
581 break;
582 }
583 if (!targ_is_utf8 && DO_UTF8(tmpForm)) {
584 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
585 *t = '\0';
586 sv_utf8_upgrade_flags_grow(PL_formtarget, SV_GMAGIC, fudge + 1);
587 t = SvEND(PL_formtarget);
588 targ_is_utf8 = TRUE;
589 }
590 while (arg--)
591 *t++ = *f++;
592 break;
593
594 case FF_SKIP:
595 f += *fpc++;
596 break;
597
598 case FF_FETCH:
599 arg = *fpc++;
600 f += arg;
601 fieldsize = arg;
602
603 if (MARK < SP)
604 sv = *++MARK;
605 else {
606 sv = &PL_sv_no;
607 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Not enough format arguments");
608 }
609 break;
610
611 case FF_CHECKNL:
612 {
613 const char *send;
614 const char *s = item = SvPV_const(sv, len);
615 itemsize = len;
616 if (DO_UTF8(sv)) {
617 itemsize = sv_len_utf8(sv);
618 if (itemsize != (I32)len) {
619 I32 itembytes;
620 if (itemsize > fieldsize) {
621 itemsize = fieldsize;
622 itembytes = itemsize;
623 sv_pos_u2b(sv, &itembytes, 0);
624 }
625 else
626 itembytes = len;
627 send = chophere = s + itembytes;
628 while (s < send) {
629 if (*s & ~31)
630 gotsome = TRUE;
631 else if (*s == '\n')
632 break;
633 s++;
634 }
635 item_is_utf8 = TRUE;
636 itemsize = s - item;
637 sv_pos_b2u(sv, &itemsize);
638 break;
639 }
640 }
641 item_is_utf8 = FALSE;
642 if (itemsize > fieldsize)
643 itemsize = fieldsize;
644 send = chophere = s + itemsize;
645 while (s < send) {
646 if (*s & ~31)
647 gotsome = TRUE;
648 else if (*s == '\n')
649 break;
650 s++;
651 }
652 itemsize = s - item;
653 break;
654 }
655
656 case FF_CHECKCHOP:
657 {
658 const char *s = item = SvPV_const(sv, len);
659 itemsize = len;
660 if (DO_UTF8(sv)) {
661 itemsize = sv_len_utf8(sv);
662 if (itemsize != (I32)len) {
663 I32 itembytes;
664 if (itemsize <= fieldsize) {
665 const char *send = chophere = s + itemsize;
666 while (s < send) {
667 if (*s == '\r') {
668 itemsize = s - item;
669 chophere = s;
670 break;
671 }
672 if (*s++ & ~31)
673 gotsome = TRUE;
674 }
675 }
676 else {
677 const char *send;
678 itemsize = fieldsize;
679 itembytes = itemsize;
680 sv_pos_u2b(sv, &itembytes, 0);
681 send = chophere = s + itembytes;
682 while (s < send || (s == send && isSPACE(*s))) {
683 if (isSPACE(*s)) {
684 if (chopspace)
685 chophere = s;
686 if (*s == '\r')
687 break;
688 }
689 else {
690 if (*s & ~31)
691 gotsome = TRUE;
692 if (strchr(PL_chopset, *s))
693 chophere = s + 1;
694 }
695 s++;
696 }
697 itemsize = chophere - item;
698 sv_pos_b2u(sv, &itemsize);
699 }
700 item_is_utf8 = TRUE;
701 break;
702 }
703 }
704 item_is_utf8 = FALSE;
705 if (itemsize <= fieldsize) {
706 const char *const send = chophere = s + itemsize;
707 while (s < send) {
708 if (*s == '\r') {
709 itemsize = s - item;
710 chophere = s;
711 break;
712 }
713 if (*s++ & ~31)
714 gotsome = TRUE;
715 }
716 }
717 else {
718 const char *send;
719 itemsize = fieldsize;
720 send = chophere = s + itemsize;
721 while (s < send || (s == send && isSPACE(*s))) {
722 if (isSPACE(*s)) {
723 if (chopspace)
724 chophere = s;
725 if (*s == '\r')
726 break;
727 }
728 else {
729 if (*s & ~31)
730 gotsome = TRUE;
731 if (strchr(PL_chopset, *s))
732 chophere = s + 1;
733 }
734 s++;
735 }
736 itemsize = chophere - item;
737 }
738 break;
739 }
740
741 case FF_SPACE:
742 arg = fieldsize - itemsize;
743 if (arg) {
744 fieldsize -= arg;
745 while (arg-- > 0)
746 *t++ = ' ';
747 }
748 break;
749
750 case FF_HALFSPACE:
751 arg = fieldsize - itemsize;
752 if (arg) {
753 arg /= 2;
754 fieldsize -= arg;
755 while (arg-- > 0)
756 *t++ = ' ';
757 }
758 break;
759
760 case FF_ITEM:
761 {
762 const char *s = item;
763 arg = itemsize;
764 if (item_is_utf8) {
765 if (!targ_is_utf8) {
766 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
767 *t = '\0';
768 sv_utf8_upgrade_flags_grow(PL_formtarget, SV_GMAGIC,
769 fudge + 1);
770 t = SvEND(PL_formtarget);
771 targ_is_utf8 = TRUE;
772 }
773 while (arg--) {
774 if (UTF8_IS_CONTINUED(*s)) {
775 STRLEN skip = UTF8SKIP(s);
776 switch (skip) {
777 default:
778 Move(s,t,skip,char);
779 s += skip;
780 t += skip;
781 break;
782 case 7: *t++ = *s++;
783 case 6: *t++ = *s++;
784 case 5: *t++ = *s++;
785 case 4: *t++ = *s++;
786 case 3: *t++ = *s++;
787 case 2: *t++ = *s++;
788 case 1: *t++ = *s++;
789 }
790 }
791 else {
792 if ( !((*t++ = *s++) & ~31) )
793 t[-1] = ' ';
794 }
795 }
796 break;
797 }
798 if (targ_is_utf8 && !item_is_utf8) {
799 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
800 *t = '\0';
801 sv_catpvn_utf8_upgrade(PL_formtarget, s, arg, nsv);
802 for (; t < SvEND(PL_formtarget); t++) {
803#ifdef EBCDIC
804 const int ch = *t;
805 if (iscntrl(ch))
806#else
807 if (!(*t & ~31))
808#endif
809 *t = ' ';
810 }
811 break;
812 }
813 while (arg--) {
814#ifdef EBCDIC
815 const int ch = *t++ = *s++;
816 if (iscntrl(ch))
817#else
818 if ( !((*t++ = *s++) & ~31) )
819#endif
820 t[-1] = ' ';
821 }
822 break;
823 }
824
825 case FF_CHOP:
826 {
827 const char *s = chophere;
828 if (chopspace) {
829 while (isSPACE(*s))
830 s++;
831 }
832 sv_chop(sv,s);
833 SvSETMAGIC(sv);
834 break;
835 }
836
837 case FF_LINESNGL:
838 chopspace = 0;
839 case FF_LINEGLOB:
840 {
841 const bool oneline = fpc[-1] == FF_LINESNGL;
842 const char *s = item = SvPV_const(sv, len);
843 item_is_utf8 = DO_UTF8(sv);
844 itemsize = len;
845 if (itemsize) {
846 STRLEN to_copy = itemsize;
847 const char *const send = s + len;
848 const U8 *source = (const U8 *) s;
849 U8 *tmp = NULL;
850
851 gotsome = TRUE;
852 chophere = s + itemsize;
853 while (s < send) {
854 if (*s++ == '\n') {
855 if (oneline) {
856 to_copy = s - SvPVX_const(sv) - 1;
857 chophere = s;
858 break;
859 } else {
860 if (s == send) {
861 itemsize--;
862 to_copy--;
863 } else
864 lines++;
865 }
866 }
867 }
868 if (targ_is_utf8 && !item_is_utf8) {
869 source = tmp = bytes_to_utf8(source, &to_copy);
870 SvCUR_set(PL_formtarget,
871 t - SvPVX_const(PL_formtarget));
872 } else {
873 if (item_is_utf8 && !targ_is_utf8) {
874 /* Upgrade targ to UTF8, and then we reduce it to
875 a problem we have a simple solution for. */
876 SvCUR_set(PL_formtarget,
877 t - SvPVX_const(PL_formtarget));
878 targ_is_utf8 = TRUE;
879 /* Don't need get magic. */
880 sv_utf8_upgrade_nomg(PL_formtarget);
881 } else {
882 SvCUR_set(PL_formtarget,
883 t - SvPVX_const(PL_formtarget));
884 }
885
886 /* Easy. They agree. */
887 assert (item_is_utf8 == targ_is_utf8);
888 }
889 SvGROW(PL_formtarget,
890 SvCUR(PL_formtarget) + to_copy + fudge + 1);
891 t = SvPVX(PL_formtarget) + SvCUR(PL_formtarget);
892
893 Copy(source, t, to_copy, char);
894 t += to_copy;
895 SvCUR_set(PL_formtarget, SvCUR(PL_formtarget) + to_copy);
896 if (item_is_utf8) {
897 if (SvGMAGICAL(sv)) {
898 /* Mustn't call sv_pos_b2u() as it does a second
899 mg_get(). Is this a bug? Do we need a _flags()
900 variant? */
901 itemsize = utf8_length(source, source + itemsize);
902 } else {
903 sv_pos_b2u(sv, &itemsize);
904 }
905 assert(!tmp);
906 } else if (tmp) {
907 Safefree(tmp);
908 }
909 }
910 break;
911 }
912
913 case FF_0DECIMAL:
914 arg = *fpc++;
915#if defined(USE_LONG_DOUBLE)
916 fmt = (const char *)
917 ((arg & 256) ?
918 "%#0*.*" PERL_PRIfldbl : "%0*.*" PERL_PRIfldbl);
919#else
920 fmt = (const char *)
921 ((arg & 256) ?
922 "%#0*.*f" : "%0*.*f");
923#endif
924 goto ff_dec;
925 case FF_DECIMAL:
926 arg = *fpc++;
927#if defined(USE_LONG_DOUBLE)
928 fmt = (const char *)
929 ((arg & 256) ? "%#*.*" PERL_PRIfldbl : "%*.*" PERL_PRIfldbl);
930#else
931 fmt = (const char *)
932 ((arg & 256) ? "%#*.*f" : "%*.*f");
933#endif
934 ff_dec:
935 /* If the field is marked with ^ and the value is undefined,
936 blank it out. */
937 if ((arg & 512) && !SvOK(sv)) {
938 arg = fieldsize;
939 while (arg--)
940 *t++ = ' ';
941 break;
942 }
943 gotsome = TRUE;
944 value = SvNV(sv);
945 /* overflow evidence */
946 if (num_overflow(value, fieldsize, arg)) {
947 arg = fieldsize;
948 while (arg--)
949 *t++ = '#';
950 break;
951 }
952 /* Formats aren't yet marked for locales, so assume "yes". */
953 {
954 STORE_NUMERIC_STANDARD_SET_LOCAL();
955 my_snprintf(t, SvLEN(PL_formtarget) - (t - SvPVX(PL_formtarget)), fmt, (int) fieldsize, (int) arg & 255, value);
956 RESTORE_NUMERIC_STANDARD();
957 }
958 t += fieldsize;
959 break;
960
961 case FF_NEWLINE:
962 f++;
963 while (t-- > linemark && *t == ' ') ;
964 t++;
965 *t++ = '\n';
966 break;
967
968 case FF_BLANK:
969 arg = *fpc++;
970 if (gotsome) {
971 if (arg) { /* repeat until fields exhausted? */
972 *t = '\0';
973 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
974 lines += FmLINES(PL_formtarget);
975 if (targ_is_utf8)
976 SvUTF8_on(PL_formtarget);
977 FmLINES(PL_formtarget) = lines;
978 SP = ORIGMARK;
979 RETURNOP(cLISTOP->op_first);
980 }
981 }
982 else {
983 t = linemark;
984 lines--;
985 }
986 break;
987
988 case FF_MORE:
989 {
990 const char *s = chophere;
991 const char *send = item + len;
992 if (chopspace) {
993 while (isSPACE(*s) && (s < send))
994 s++;
995 }
996 if (s < send) {
997 char *s1;
998 arg = fieldsize - itemsize;
999 if (arg) {
1000 fieldsize -= arg;
1001 while (arg-- > 0)
1002 *t++ = ' ';
1003 }
1004 s1 = t - 3;
1005 if (strnEQ(s1," ",3)) {
1006 while (s1 > SvPVX_const(PL_formtarget) && isSPACE(s1[-1]))
1007 s1--;
1008 }
1009 *s1++ = '.';
1010 *s1++ = '.';
1011 *s1++ = '.';
1012 }
1013 break;
1014 }
1015 case FF_END:
1016 *t = '\0';
1017 SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
1018 if (targ_is_utf8)
1019 SvUTF8_on(PL_formtarget);
1020 FmLINES(PL_formtarget) += lines;
1021 SP = ORIGMARK;
1022 RETPUSHYES;
1023 }
1024 }
1025}
1026
1027PP(pp_grepstart)
1028{
1029 dVAR; dSP;
1030 SV *src;
1031
1032 if (PL_stack_base + *PL_markstack_ptr == SP) {
1033 (void)POPMARK;
1034 if (GIMME_V == G_SCALAR)
1035 mXPUSHi(0);
1036 RETURNOP(PL_op->op_next->op_next);
1037 }
1038 PL_stack_sp = PL_stack_base + *PL_markstack_ptr + 1;
1039 pp_pushmark(); /* push dst */
1040 pp_pushmark(); /* push src */
1041 ENTER_with_name("grep"); /* enter outer scope */
1042
1043 SAVETMPS;
1044 if (PL_op->op_private & OPpGREP_LEX)
1045 SAVESPTR(PAD_SVl(PL_op->op_targ));
1046 else
1047 SAVE_DEFSV;
1048 ENTER_with_name("grep_item"); /* enter inner scope */
1049 SAVEVPTR(PL_curpm);
1050
1051 src = PL_stack_base[*PL_markstack_ptr];
1052 SvTEMP_off(src);
1053 if (PL_op->op_private & OPpGREP_LEX)
1054 PAD_SVl(PL_op->op_targ) = src;
1055 else
1056 DEFSV_set(src);
1057
1058 PUTBACK;
1059 if (PL_op->op_type == OP_MAPSTART)
1060 pp_pushmark(); /* push top */
1061 return ((LOGOP*)PL_op->op_next)->op_other;
1062}
1063
1064PP(pp_mapwhile)
1065{
1066 dVAR; dSP;
1067 const I32 gimme = GIMME_V;
1068 I32 items = (SP - PL_stack_base) - *PL_markstack_ptr; /* how many new items */
1069 I32 count;
1070 I32 shift;
1071 SV** src;
1072 SV** dst;
1073
1074 /* first, move source pointer to the next item in the source list */
1075 ++PL_markstack_ptr[-1];
1076
1077 /* if there are new items, push them into the destination list */
1078 if (items && gimme != G_VOID) {
1079 /* might need to make room back there first */
1080 if (items > PL_markstack_ptr[-1] - PL_markstack_ptr[-2]) {
1081 /* XXX this implementation is very pessimal because the stack
1082 * is repeatedly extended for every set of items. Is possible
1083 * to do this without any stack extension or copying at all
1084 * by maintaining a separate list over which the map iterates
1085 * (like foreach does). --gsar */
1086
1087 /* everything in the stack after the destination list moves
1088 * towards the end the stack by the amount of room needed */
1089 shift = items - (PL_markstack_ptr[-1] - PL_markstack_ptr[-2]);
1090
1091 /* items to shift up (accounting for the moved source pointer) */
1092 count = (SP - PL_stack_base) - (PL_markstack_ptr[-1] - 1);
1093
1094 /* This optimization is by Ben Tilly and it does
1095 * things differently from what Sarathy (gsar)
1096 * is describing. The downside of this optimization is
1097 * that leaves "holes" (uninitialized and hopefully unused areas)
1098 * to the Perl stack, but on the other hand this
1099 * shouldn't be a problem. If Sarathy's idea gets
1100 * implemented, this optimization should become
1101 * irrelevant. --jhi */
1102 if (shift < count)
1103 shift = count; /* Avoid shifting too often --Ben Tilly */
1104
1105 EXTEND(SP,shift);
1106 src = SP;
1107 dst = (SP += shift);
1108 PL_markstack_ptr[-1] += shift;
1109 *PL_markstack_ptr += shift;
1110 while (count--)
1111 *dst-- = *src--;
1112 }
1113 /* copy the new items down to the destination list */
1114 dst = PL_stack_base + (PL_markstack_ptr[-2] += items) - 1;
1115 if (gimme == G_ARRAY) {
1116 /* add returned items to the collection (making mortal copies
1117 * if necessary), then clear the current temps stack frame
1118 * *except* for those items. We do this splicing the items
1119 * into the start of the tmps frame (so some items may be on
1120 * the tmps stack twice), then moving PL_stack_floor above
1121 * them, then freeing the frame. That way, the only tmps that
1122 * accumulate over iterations are the return values for map.
1123 * We have to do to this way so that everything gets correctly
1124 * freed if we die during the map.
1125 */
1126 I32 tmpsbase;
1127 I32 i = items;
1128 /* make space for the slice */
1129 EXTEND_MORTAL(items);
1130 tmpsbase = PL_tmps_floor + 1;
1131 Move(PL_tmps_stack + tmpsbase,
1132 PL_tmps_stack + tmpsbase + items,
1133 PL_tmps_ix - PL_tmps_floor,
1134 SV*);
1135 PL_tmps_ix += items;
1136
1137 while (i-- > 0) {
1138 SV *sv = POPs;
1139 if (!SvTEMP(sv))
1140 sv = sv_mortalcopy(sv);
1141 *dst-- = sv;
1142 PL_tmps_stack[tmpsbase++] = SvREFCNT_inc_simple(sv);
1143 }
1144 /* clear the stack frame except for the items */
1145 PL_tmps_floor += items;
1146 FREETMPS;
1147 /* FREETMPS may have cleared the TEMP flag on some of the items */
1148 i = items;
1149 while (i-- > 0)
1150 SvTEMP_on(PL_tmps_stack[--tmpsbase]);
1151 }
1152 else {
1153 /* scalar context: we don't care about which values map returns
1154 * (we use undef here). And so we certainly don't want to do mortal
1155 * copies of meaningless values. */
1156 while (items-- > 0) {
1157 (void)POPs;
1158 *dst-- = &PL_sv_undef;
1159 }
1160 FREETMPS;
1161 }
1162 }
1163 else {
1164 FREETMPS;
1165 }
1166 LEAVE_with_name("grep_item"); /* exit inner scope */
1167
1168 /* All done yet? */
1169 if (PL_markstack_ptr[-1] > *PL_markstack_ptr) {
1170
1171 (void)POPMARK; /* pop top */
1172 LEAVE_with_name("grep"); /* exit outer scope */
1173 (void)POPMARK; /* pop src */
1174 items = --*PL_markstack_ptr - PL_markstack_ptr[-1];
1175 (void)POPMARK; /* pop dst */
1176 SP = PL_stack_base + POPMARK; /* pop original mark */
1177 if (gimme == G_SCALAR) {
1178 if (PL_op->op_private & OPpGREP_LEX) {
1179 SV* sv = sv_newmortal();
1180 sv_setiv(sv, items);
1181 PUSHs(sv);
1182 }
1183 else {
1184 dTARGET;
1185 XPUSHi(items);
1186 }
1187 }
1188 else if (gimme == G_ARRAY)
1189 SP += items;
1190 RETURN;
1191 }
1192 else {
1193 SV *src;
1194
1195 ENTER_with_name("grep_item"); /* enter inner scope */
1196 SAVEVPTR(PL_curpm);
1197
1198 /* set $_ to the new source item */
1199 src = PL_stack_base[PL_markstack_ptr[-1]];
1200 SvTEMP_off(src);
1201 if (PL_op->op_private & OPpGREP_LEX)
1202 PAD_SVl(PL_op->op_targ) = src;
1203 else
1204 DEFSV_set(src);
1205
1206 RETURNOP(cLOGOP->op_other);
1207 }
1208}
1209
1210/* Range stuff. */
1211
1212PP(pp_range)
1213{
1214 dVAR;
1215 if (GIMME == G_ARRAY)
1216 return NORMAL;
1217 if (SvTRUEx(PAD_SV(PL_op->op_targ)))
1218 return cLOGOP->op_other;
1219 else
1220 return NORMAL;
1221}
1222
1223PP(pp_flip)
1224{
1225 dVAR;
1226 dSP;
1227
1228 if (GIMME == G_ARRAY) {
1229 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
1230 }
1231 else {
1232 dTOPss;
1233 SV * const targ = PAD_SV(PL_op->op_targ);
1234 int flip = 0;
1235
1236 if (PL_op->op_private & OPpFLIP_LINENUM) {
1237 if (GvIO(PL_last_in_gv)) {
1238 flip = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
1239 }
1240 else {
1241 GV * const gv = gv_fetchpvs(".", GV_ADD|GV_NOTQUAL, SVt_PV);
1242 if (gv && GvSV(gv))
1243 flip = SvIV(sv) == SvIV(GvSV(gv));
1244 }
1245 } else {
1246 flip = SvTRUE(sv);
1247 }
1248 if (flip) {
1249 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
1250 if (PL_op->op_flags & OPf_SPECIAL) {
1251 sv_setiv(targ, 1);
1252 SETs(targ);
1253 RETURN;
1254 }
1255 else {
1256 sv_setiv(targ, 0);
1257 SP--;
1258 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
1259 }
1260 }
1261 sv_setpvs(TARG, "");
1262 SETs(targ);
1263 RETURN;
1264 }
1265}
1266
1267/* This code tries to decide if "$left .. $right" should use the
1268 magical string increment, or if the range is numeric (we make
1269 an exception for .."0" [#18165]). AMS 20021031. */
1270
1271#define RANGE_IS_NUMERIC(left,right) ( \
1272 SvNIOKp(left) || (SvOK(left) && !SvPOKp(left)) || \
1273 SvNIOKp(right) || (SvOK(right) && !SvPOKp(right)) || \
1274 (((!SvOK(left) && SvOK(right)) || ((!SvOK(left) || \
1275 looks_like_number(left)) && SvPOKp(left) && *SvPVX_const(left) != '0')) \
1276 && (!SvOK(right) || looks_like_number(right))))
1277
1278PP(pp_flop)
1279{
1280 dVAR; dSP;
1281
1282 if (GIMME == G_ARRAY) {
1283 dPOPPOPssrl;
1284
1285 SvGETMAGIC(left);
1286 SvGETMAGIC(right);
1287
1288 if (RANGE_IS_NUMERIC(left,right)) {
1289 register IV i, j;
1290 IV max;
1291 if ((SvOK(left) && SvNV(left) < IV_MIN) ||
1292 (SvOK(right) && SvNV(right) > IV_MAX))
1293 DIE(aTHX_ "Range iterator outside integer range");
1294 i = SvIV(left);
1295 max = SvIV(right);
1296 if (max >= i) {
1297 j = max - i + 1;
1298 EXTEND_MORTAL(j);
1299 EXTEND(SP, j);
1300 }
1301 else
1302 j = 0;
1303 while (j--) {
1304 SV * const sv = sv_2mortal(newSViv(i++));
1305 PUSHs(sv);
1306 }
1307 }
1308 else {
1309 SV * const final = sv_mortalcopy(right);
1310 STRLEN len;
1311 const char * const tmps = SvPV_const(final, len);
1312
1313 SV *sv = sv_mortalcopy(left);
1314 SvPV_force_nolen(sv);
1315 while (!SvNIOKp(sv) && SvCUR(sv) <= len) {
1316 XPUSHs(sv);
1317 if (strEQ(SvPVX_const(sv),tmps))
1318 break;
1319 sv = sv_2mortal(newSVsv(sv));
1320 sv_inc(sv);
1321 }
1322 }
1323 }
1324 else {
1325 dTOPss;
1326 SV * const targ = PAD_SV(cUNOP->op_first->op_targ);
1327 int flop = 0;
1328 sv_inc(targ);
1329
1330 if (PL_op->op_private & OPpFLIP_LINENUM) {
1331 if (GvIO(PL_last_in_gv)) {
1332 flop = SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv));
1333 }
1334 else {
1335 GV * const gv = gv_fetchpvs(".", GV_ADD|GV_NOTQUAL, SVt_PV);
1336 if (gv && GvSV(gv)) flop = SvIV(sv) == SvIV(GvSV(gv));
1337 }
1338 }
1339 else {
1340 flop = SvTRUE(sv);
1341 }
1342
1343 if (flop) {
1344 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
1345 sv_catpvs(targ, "E0");
1346 }
1347 SETs(targ);
1348 }
1349
1350 RETURN;
1351}
1352
1353/* Control. */
1354
1355static const char * const context_name[] = {
1356 "pseudo-block",
1357 NULL, /* CXt_WHEN never actually needs "block" */
1358 NULL, /* CXt_BLOCK never actually needs "block" */
1359 NULL, /* CXt_GIVEN never actually needs "block" */
1360 NULL, /* CXt_LOOP_FOR never actually needs "loop" */
1361 NULL, /* CXt_LOOP_PLAIN never actually needs "loop" */
1362 NULL, /* CXt_LOOP_LAZYSV never actually needs "loop" */
1363 NULL, /* CXt_LOOP_LAZYIV never actually needs "loop" */
1364 "subroutine",
1365 "format",
1366 "eval",
1367 "substitution",
1368};
1369
1370STATIC I32
1371S_dopoptolabel(pTHX_ const char *label)
1372{
1373 dVAR;
1374 register I32 i;
1375
1376 PERL_ARGS_ASSERT_DOPOPTOLABEL;
1377
1378 for (i = cxstack_ix; i >= 0; i--) {
1379 register const PERL_CONTEXT * const cx = &cxstack[i];
1380 switch (CxTYPE(cx)) {
1381 case CXt_SUBST:
1382 case CXt_SUB:
1383 case CXt_FORMAT:
1384 case CXt_EVAL:
1385 case CXt_NULL:
1386 Perl_ck_warner(aTHX_ packWARN(WARN_EXITING), "Exiting %s via %s",
1387 context_name[CxTYPE(cx)], OP_NAME(PL_op));
1388 if (CxTYPE(cx) == CXt_NULL)
1389 return -1;
1390 break;
1391 case CXt_LOOP_LAZYIV:
1392 case CXt_LOOP_LAZYSV:
1393 case CXt_LOOP_FOR:
1394 case CXt_LOOP_PLAIN:
1395 {
1396 const char *cx_label = CxLABEL(cx);
1397 if (!cx_label || strNE(label, cx_label) ) {
1398 DEBUG_l(Perl_deb(aTHX_ "(poptolabel(): skipping label at cx=%ld %s)\n",
1399 (long)i, cx_label));
1400 continue;
1401 }
1402 DEBUG_l( Perl_deb(aTHX_ "(poptolabel(): found label at cx=%ld %s)\n", (long)i, label));
1403 return i;
1404 }
1405 }
1406 }
1407 return i;
1408}
1409
1410
1411
1412I32
1413Perl_dowantarray(pTHX)
1414{
1415 dVAR;
1416 const I32 gimme = block_gimme();
1417 return (gimme == G_VOID) ? G_SCALAR : gimme;
1418}
1419
1420I32
1421Perl_block_gimme(pTHX)
1422{
1423 dVAR;
1424 const I32 cxix = dopoptosub(cxstack_ix);
1425 if (cxix < 0)
1426 return G_VOID;
1427
1428 switch (cxstack[cxix].blk_gimme) {
1429 case G_VOID:
1430 return G_VOID;
1431 case G_SCALAR:
1432 return G_SCALAR;
1433 case G_ARRAY:
1434 return G_ARRAY;
1435 default:
1436 Perl_croak(aTHX_ "panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
1437 /* NOTREACHED */
1438 return 0;
1439 }
1440}
1441
1442I32
1443Perl_is_lvalue_sub(pTHX)
1444{
1445 dVAR;
1446 const I32 cxix = dopoptosub(cxstack_ix);
1447 assert(cxix >= 0); /* We should only be called from inside subs */
1448
1449 if (CxLVAL(cxstack + cxix) && CvLVALUE(cxstack[cxix].blk_sub.cv))
1450 return CxLVAL(cxstack + cxix);
1451 else
1452 return 0;
1453}
1454
1455STATIC I32
1456S_dopoptosub_at(pTHX_ const PERL_CONTEXT *cxstk, I32 startingblock)
1457{
1458 dVAR;
1459 I32 i;
1460
1461 PERL_ARGS_ASSERT_DOPOPTOSUB_AT;
1462
1463 for (i = startingblock; i >= 0; i--) {
1464 register const PERL_CONTEXT * const cx = &cxstk[i];
1465 switch (CxTYPE(cx)) {
1466 default:
1467 continue;
1468 case CXt_EVAL:
1469 case CXt_SUB:
1470 case CXt_FORMAT:
1471 DEBUG_l( Perl_deb(aTHX_ "(dopoptosub_at(): found sub at cx=%ld)\n", (long)i));
1472 return i;
1473 }
1474 }
1475 return i;
1476}
1477
1478STATIC I32
1479S_dopoptoeval(pTHX_ I32 startingblock)
1480{
1481 dVAR;
1482 I32 i;
1483 for (i = startingblock; i >= 0; i--) {
1484 register const PERL_CONTEXT *cx = &cxstack[i];
1485 switch (CxTYPE(cx)) {
1486 default:
1487 continue;
1488 case CXt_EVAL:
1489 DEBUG_l( Perl_deb(aTHX_ "(dopoptoeval(): found eval at cx=%ld)\n", (long)i));
1490 return i;
1491 }
1492 }
1493 return i;
1494}
1495
1496STATIC I32
1497S_dopoptoloop(pTHX_ I32 startingblock)
1498{
1499 dVAR;
1500 I32 i;
1501 for (i = startingblock; i >= 0; i--) {
1502 register const PERL_CONTEXT * const cx = &cxstack[i];
1503 switch (CxTYPE(cx)) {
1504 case CXt_SUBST:
1505 case CXt_SUB:
1506 case CXt_FORMAT:
1507 case CXt_EVAL:
1508 case CXt_NULL:
1509 Perl_ck_warner(aTHX_ packWARN(WARN_EXITING), "Exiting %s via %s",
1510 context_name[CxTYPE(cx)], OP_NAME(PL_op));
1511 if ((CxTYPE(cx)) == CXt_NULL)
1512 return -1;
1513 break;
1514 case CXt_LOOP_LAZYIV:
1515 case CXt_LOOP_LAZYSV:
1516 case CXt_LOOP_FOR:
1517 case CXt_LOOP_PLAIN:
1518 DEBUG_l( Perl_deb(aTHX_ "(dopoptoloop(): found loop at cx=%ld)\n", (long)i));
1519 return i;
1520 }
1521 }
1522 return i;
1523}
1524
1525STATIC I32
1526S_dopoptogiven(pTHX_ I32 startingblock)
1527{
1528 dVAR;
1529 I32 i;
1530 for (i = startingblock; i >= 0; i--) {
1531 register const PERL_CONTEXT *cx = &cxstack[i];
1532 switch (CxTYPE(cx)) {
1533 default:
1534 continue;
1535 case CXt_GIVEN:
1536 DEBUG_l( Perl_deb(aTHX_ "(dopoptogiven(): found given at cx=%ld)\n", (long)i));
1537 return i;
1538 case CXt_LOOP_PLAIN:
1539 assert(!CxFOREACHDEF(cx));
1540 break;
1541 case CXt_LOOP_LAZYIV:
1542 case CXt_LOOP_LAZYSV:
1543 case CXt_LOOP_FOR:
1544 if (CxFOREACHDEF(cx)) {
1545 DEBUG_l( Perl_deb(aTHX_ "(dopoptogiven(): found foreach at cx=%ld)\n", (long)i));
1546 return i;
1547 }
1548 }
1549 }
1550 return i;
1551}
1552
1553STATIC I32
1554S_dopoptowhen(pTHX_ I32 startingblock)
1555{
1556 dVAR;
1557 I32 i;
1558 for (i = startingblock; i >= 0; i--) {
1559 register const PERL_CONTEXT *cx = &cxstack[i];
1560 switch (CxTYPE(cx)) {
1561 default:
1562 continue;
1563 case CXt_WHEN:
1564 DEBUG_l( Perl_deb(aTHX_ "(dopoptowhen(): found when at cx=%ld)\n", (long)i));
1565 return i;
1566 }
1567 }
1568 return i;
1569}
1570
1571void
1572Perl_dounwind(pTHX_ I32 cxix)
1573{
1574 dVAR;
1575 I32 optype;
1576
1577 while (cxstack_ix > cxix) {
1578 SV *sv;
1579 register PERL_CONTEXT *cx = &cxstack[cxstack_ix];
1580 DEBUG_CX("UNWIND"); \
1581 /* Note: we don't need to restore the base context info till the end. */
1582 switch (CxTYPE(cx)) {
1583 case CXt_SUBST:
1584 POPSUBST(cx);
1585 continue; /* not break */
1586 case CXt_SUB:
1587 POPSUB(cx,sv);
1588 LEAVESUB(sv);
1589 break;
1590 case CXt_EVAL:
1591 POPEVAL(cx);
1592 break;
1593 case CXt_LOOP_LAZYIV:
1594 case CXt_LOOP_LAZYSV:
1595 case CXt_LOOP_FOR:
1596 case CXt_LOOP_PLAIN:
1597 POPLOOP(cx);
1598 break;
1599 case CXt_NULL:
1600 break;
1601 case CXt_FORMAT:
1602 POPFORMAT(cx);
1603 break;
1604 }
1605 cxstack_ix--;
1606 }
1607 PERL_UNUSED_VAR(optype);
1608}
1609
1610void
1611Perl_qerror(pTHX_ SV *err)
1612{
1613 dVAR;
1614
1615 PERL_ARGS_ASSERT_QERROR;
1616
1617 if (PL_in_eval) {
1618 if (PL_in_eval & EVAL_KEEPERR) {
1619 Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "\t(in cleanup) %s",
1620 SvPV_nolen_const(err));
1621 }
1622 else
1623 sv_catsv(ERRSV, err);
1624 }
1625 else if (PL_errors)
1626 sv_catsv(PL_errors, err);
1627 else
1628 Perl_warn(aTHX_ "%"SVf, SVfARG(err));
1629 if (PL_parser)
1630 ++PL_parser->error_count;
1631}
1632
1633void
1634Perl_die_unwind(pTHX_ SV *msv)
1635{
1636 dVAR;
1637 SV *exceptsv = sv_mortalcopy(msv);
1638 U8 in_eval = PL_in_eval;
1639 PERL_ARGS_ASSERT_DIE_UNWIND;
1640
1641 if (in_eval) {
1642 I32 cxix;
1643 I32 gimme;
1644
1645 while ((cxix = dopoptoeval(cxstack_ix)) < 0
1646 && PL_curstackinfo->si_prev)
1647 {
1648 dounwind(-1);
1649 POPSTACK;
1650 }
1651
1652 if (cxix >= 0) {
1653 I32 optype;
1654 SV *namesv;
1655 register PERL_CONTEXT *cx;
1656 SV **newsp;
1657
1658 if (cxix < cxstack_ix)
1659 dounwind(cxix);
1660
1661 POPBLOCK(cx,PL_curpm);
1662 if (CxTYPE(cx) != CXt_EVAL) {
1663 STRLEN msglen;
1664 const char* message = SvPVx_const(exceptsv, msglen);
1665 PerlIO_write(Perl_error_log, (const char *)"panic: die ", 11);
1666 PerlIO_write(Perl_error_log, message, msglen);
1667 my_exit(1);
1668 }
1669 POPEVAL(cx);
1670 namesv = cx->blk_eval.old_namesv;
1671
1672 if (gimme == G_SCALAR)
1673 *++newsp = &PL_sv_undef;
1674 PL_stack_sp = newsp;
1675
1676 LEAVE;
1677
1678 /* LEAVE could clobber PL_curcop (see save_re_context())
1679 * XXX it might be better to find a way to avoid messing with
1680 * PL_curcop in save_re_context() instead, but this is a more
1681 * minimal fix --GSAR */
1682 PL_curcop = cx->blk_oldcop;
1683
1684 if (optype == OP_REQUIRE) {
1685 const char* const msg = SvPVx_nolen_const(exceptsv);
1686 (void)hv_store(GvHVn(PL_incgv),
1687 SvPVX_const(namesv), SvCUR(namesv),
1688 &PL_sv_undef, 0);
1689 /* note that unlike pp_entereval, pp_require isn't
1690 * supposed to trap errors. So now that we've popped the
1691 * EVAL that pp_require pushed, and processed the error
1692 * message, rethrow the error */
1693 Perl_croak(aTHX_ "%sCompilation failed in require",
1694 *msg ? msg : "Unknown error\n");
1695 }
1696 if (in_eval & EVAL_KEEPERR) {
1697 Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "\t(in cleanup) %s",
1698 SvPV_nolen_const(exceptsv));
1699 }
1700 else {
1701 sv_setsv(ERRSV, exceptsv);
1702 }
1703 assert(CxTYPE(cx) == CXt_EVAL);
1704 PL_restartjmpenv = cx->blk_eval.cur_top_env;
1705 PL_restartop = cx->blk_eval.retop;
1706 JMPENV_JUMP(3);
1707 /* NOTREACHED */
1708 }
1709 }
1710
1711 write_to_stderr(exceptsv);
1712 my_failure_exit();
1713 /* NOTREACHED */
1714}
1715
1716PP(pp_xor)
1717{
1718 dVAR; dSP; dPOPTOPssrl;
1719 if (SvTRUE(left) != SvTRUE(right))
1720 RETSETYES;
1721 else
1722 RETSETNO;
1723}
1724
1725/*
1726=for apidoc caller_cx
1727
1728The XSUB-writer's equivalent of L<caller()|perlfunc/caller>. The
1729returned C<PERL_CONTEXT> structure can be interrogated to find all the
1730information returned to Perl by C<caller>. Note that XSUBs don't get a
1731stack frame, so C<caller_cx(0, NULL)> will return information for the
1732immediately-surrounding Perl code.
1733
1734This function skips over the automatic calls to C<&DB::sub> made on the
1735behalf of the debugger. If the stack frame requested was a sub called by
1736C<DB::sub>, the return value will be the frame for the call to
1737C<DB::sub>, since that has the correct line number/etc. for the call
1738site. If I<dbcxp> is non-C<NULL>, it will be set to a pointer to the
1739frame for the sub call itself.
1740
1741=cut
1742*/
1743
1744const PERL_CONTEXT *
1745Perl_caller_cx(pTHX_ I32 count, const PERL_CONTEXT **dbcxp)
1746{
1747 register I32 cxix = dopoptosub(cxstack_ix);
1748 register const PERL_CONTEXT *cx;
1749 register const PERL_CONTEXT *ccstack = cxstack;
1750 const PERL_SI *top_si = PL_curstackinfo;
1751
1752 for (;;) {
1753 /* we may be in a higher stacklevel, so dig down deeper */
1754 while (cxix < 0 && top_si->si_type != PERLSI_MAIN) {
1755 top_si = top_si->si_prev;
1756 ccstack = top_si->si_cxstack;
1757 cxix = dopoptosub_at(ccstack, top_si->si_cxix);
1758 }
1759 if (cxix < 0)
1760 return NULL;
1761 /* caller() should not report the automatic calls to &DB::sub */
1762 if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 &&
1763 ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub))
1764 count++;
1765 if (!count--)
1766 break;
1767 cxix = dopoptosub_at(ccstack, cxix - 1);
1768 }
1769
1770 cx = &ccstack[cxix];
1771 if (dbcxp) *dbcxp = cx;
1772
1773 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1774 const I32 dbcxix = dopoptosub_at(ccstack, cxix - 1);
1775 /* We expect that ccstack[dbcxix] is CXt_SUB, anyway, the
1776 field below is defined for any cx. */
1777 /* caller() should not report the automatic calls to &DB::sub */
1778 if (PL_DBsub && GvCV(PL_DBsub) && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub))
1779 cx = &ccstack[dbcxix];
1780 }
1781
1782 return cx;
1783}
1784
1785PP(pp_caller)
1786{
1787 dVAR;
1788 dSP;
1789 register const PERL_CONTEXT *cx;
1790 const PERL_CONTEXT *dbcx;
1791 I32 gimme;
1792 const char *stashname;
1793 I32 count = 0;
1794
1795 if (MAXARG)
1796 count = POPi;
1797
1798 cx = caller_cx(count, &dbcx);
1799 if (!cx) {
1800 if (GIMME != G_ARRAY) {
1801 EXTEND(SP, 1);
1802 RETPUSHUNDEF;
1803 }
1804 RETURN;
1805 }
1806
1807 stashname = CopSTASHPV(cx->blk_oldcop);
1808 if (GIMME != G_ARRAY) {
1809 EXTEND(SP, 1);
1810 if (!stashname)
1811 PUSHs(&PL_sv_undef);
1812 else {
1813 dTARGET;
1814 sv_setpv(TARG, stashname);
1815 PUSHs(TARG);
1816 }
1817 RETURN;
1818 }
1819
1820 EXTEND(SP, 11);
1821
1822 if (!stashname)
1823 PUSHs(&PL_sv_undef);
1824 else
1825 mPUSHs(newSVpv(stashname, 0));
1826 mPUSHs(newSVpv(OutCopFILE(cx->blk_oldcop), 0));
1827 mPUSHi((I32)CopLINE(cx->blk_oldcop));
1828 if (!MAXARG)
1829 RETURN;
1830 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
1831 GV * const cvgv = CvGV(dbcx->blk_sub.cv);
1832 /* So is ccstack[dbcxix]. */
1833 if (isGV(cvgv)) {
1834 SV * const sv = newSV(0);
1835 gv_efullname3(sv, cvgv, NULL);
1836 mPUSHs(sv);
1837 PUSHs(boolSV(CxHASARGS(cx)));
1838 }
1839 else {
1840 PUSHs(newSVpvs_flags("(unknown)", SVs_TEMP));
1841 PUSHs(boolSV(CxHASARGS(cx)));
1842 }
1843 }
1844 else {
1845 PUSHs(newSVpvs_flags("(eval)", SVs_TEMP));
1846 mPUSHi(0);
1847 }
1848 gimme = (I32)cx->blk_gimme;
1849 if (gimme == G_VOID)
1850 PUSHs(&PL_sv_undef);
1851 else
1852 PUSHs(boolSV((gimme & G_WANT) == G_ARRAY));
1853 if (CxTYPE(cx) == CXt_EVAL) {
1854 /* eval STRING */
1855 if (CxOLD_OP_TYPE(cx) == OP_ENTEREVAL) {
1856 PUSHs(cx->blk_eval.cur_text);
1857 PUSHs(&PL_sv_no);
1858 }
1859 /* require */
1860 else if (cx->blk_eval.old_namesv) {
1861 mPUSHs(newSVsv(cx->blk_eval.old_namesv));
1862 PUSHs(&PL_sv_yes);
1863 }
1864 /* eval BLOCK (try blocks have old_namesv == 0) */
1865 else {
1866 PUSHs(&PL_sv_undef);
1867 PUSHs(&PL_sv_undef);
1868 }
1869 }
1870 else {
1871 PUSHs(&PL_sv_undef);
1872 PUSHs(&PL_sv_undef);
1873 }
1874 if (CxTYPE(cx) == CXt_SUB && CxHASARGS(cx)
1875 && CopSTASH_eq(PL_curcop, PL_debstash))
1876 {
1877 AV * const ary = cx->blk_sub.argarray;
1878 const int off = AvARRAY(ary) - AvALLOC(ary);
1879
1880 if (!PL_dbargs)
1881 Perl_init_dbargs(aTHX);
1882
1883 if (AvMAX(PL_dbargs) < AvFILLp(ary) + off)
1884 av_extend(PL_dbargs, AvFILLp(ary) + off);
1885 Copy(AvALLOC(ary), AvARRAY(PL_dbargs), AvFILLp(ary) + 1 + off, SV*);
1886 AvFILLp(PL_dbargs) = AvFILLp(ary) + off;
1887 }
1888 /* XXX only hints propagated via op_private are currently
1889 * visible (others are not easily accessible, since they
1890 * use the global PL_hints) */
1891 mPUSHi(CopHINTS_get(cx->blk_oldcop));
1892 {
1893 SV * mask ;
1894 STRLEN * const old_warnings = cx->blk_oldcop->cop_warnings ;
1895
1896 if (old_warnings == pWARN_NONE ||
1897 (old_warnings == pWARN_STD && (PL_dowarn & G_WARN_ON) == 0))
1898 mask = newSVpvn(WARN_NONEstring, WARNsize) ;
1899 else if (old_warnings == pWARN_ALL ||
1900 (old_warnings == pWARN_STD && PL_dowarn & G_WARN_ON)) {
1901 /* Get the bit mask for $warnings::Bits{all}, because
1902 * it could have been extended by warnings::register */
1903 SV **bits_all;
1904 HV * const bits = get_hv("warnings::Bits", 0);
1905 if (bits && (bits_all=hv_fetchs(bits, "all", FALSE))) {
1906 mask = newSVsv(*bits_all);
1907 }
1908 else {
1909 mask = newSVpvn(WARN_ALLstring, WARNsize) ;
1910 }
1911 }
1912 else
1913 mask = newSVpvn((char *) (old_warnings + 1), old_warnings[0]);
1914 mPUSHs(mask);
1915 }
1916
1917 PUSHs(cx->blk_oldcop->cop_hints_hash ?
1918 sv_2mortal(newRV_noinc(
1919 MUTABLE_SV(Perl_refcounted_he_chain_2hv(aTHX_
1920 cx->blk_oldcop->cop_hints_hash))))
1921 : &PL_sv_undef);
1922 RETURN;
1923}
1924
1925PP(pp_reset)
1926{
1927 dVAR;
1928 dSP;
1929 const char * const tmps = (MAXARG < 1) ? (const char *)"" : POPpconstx;
1930 sv_reset(tmps, CopSTASH(PL_curcop));
1931 PUSHs(&PL_sv_yes);
1932 RETURN;
1933}
1934
1935/* like pp_nextstate, but used instead when the debugger is active */
1936
1937PP(pp_dbstate)
1938{
1939 dVAR;
1940 PL_curcop = (COP*)PL_op;
1941 TAINT_NOT; /* Each statement is presumed innocent */
1942 PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
1943 FREETMPS;
1944
1945 PERL_ASYNC_CHECK();
1946
1947 if (PL_op->op_flags & OPf_SPECIAL /* breakpoint */
1948 || SvIV(PL_DBsingle) || SvIV(PL_DBsignal) || SvIV(PL_DBtrace))
1949 {
1950 dSP;
1951 register PERL_CONTEXT *cx;
1952 const I32 gimme = G_ARRAY;
1953 U8 hasargs;
1954 GV * const gv = PL_DBgv;
1955 register CV * const cv = GvCV(gv);
1956
1957 if (!cv)
1958 DIE(aTHX_ "No DB::DB routine defined");
1959
1960 if (CvDEPTH(cv) >= 1 && !(PL_debug & DEBUG_DB_RECURSE_FLAG))
1961 /* don't do recursive DB::DB call */
1962 return NORMAL;
1963
1964 ENTER;
1965 SAVETMPS;
1966
1967 SAVEI32(PL_debug);
1968 SAVESTACK_POS();
1969 PL_debug = 0;
1970 hasargs = 0;
1971 SPAGAIN;
1972
1973 if (CvISXSUB(cv)) {
1974 CvDEPTH(cv)++;
1975 PUSHMARK(SP);
1976 (void)(*CvXSUB(cv))(aTHX_ cv);
1977 CvDEPTH(cv)--;
1978 FREETMPS;
1979 LEAVE;
1980 return NORMAL;
1981 }
1982 else {
1983 PUSHBLOCK(cx, CXt_SUB, SP);
1984 PUSHSUB_DB(cx);
1985 cx->blk_sub.retop = PL_op->op_next;
1986 CvDEPTH(cv)++;
1987 SAVECOMPPAD();
1988 PAD_SET_CUR_NOSAVE(CvPADLIST(cv), 1);
1989 RETURNOP(CvSTART(cv));
1990 }
1991 }
1992 else
1993 return NORMAL;
1994}
1995
1996PP(pp_enteriter)
1997{
1998 dVAR; dSP; dMARK;
1999 register PERL_CONTEXT *cx;
2000 const I32 gimme = GIMME_V;
2001 void *itervar; /* location of the iteration variable */
2002 U8 cxtype = CXt_LOOP_FOR;
2003
2004 ENTER_with_name("loop1");
2005 SAVETMPS;
2006
2007 if (PL_op->op_targ) { /* "my" variable */
2008 if (PL_op->op_private & OPpLVAL_INTRO) { /* for my $x (...) */
2009 SvPADSTALE_off(PAD_SVl(PL_op->op_targ));
2010 SAVESETSVFLAGS(PAD_SVl(PL_op->op_targ),
2011 SVs_PADSTALE, SVs_PADSTALE);
2012 }
2013 SAVEPADSVANDMORTALIZE(PL_op->op_targ);
2014#ifdef USE_ITHREADS
2015 itervar = PL_comppad;
2016#else
2017 itervar = &PAD_SVl(PL_op->op_targ);
2018#endif
2019 }
2020 else { /* symbol table variable */
2021 GV * const gv = MUTABLE_GV(POPs);
2022 SV** svp = &GvSV(gv);
2023 save_pushptrptr(gv, SvREFCNT_inc(*svp), SAVEt_GVSV);
2024 *svp = newSV(0);
2025 itervar = (void *)gv;
2026 }
2027
2028 if (PL_op->op_private & OPpITER_DEF)
2029 cxtype |= CXp_FOR_DEF;
2030
2031 ENTER_with_name("loop2");
2032
2033 PUSHBLOCK(cx, cxtype, SP);
2034 PUSHLOOP_FOR(cx, itervar, MARK);
2035 if (PL_op->op_flags & OPf_STACKED) {
2036 SV *maybe_ary = POPs;
2037 if (SvTYPE(maybe_ary) != SVt_PVAV) {
2038 dPOPss;
2039 SV * const right = maybe_ary;
2040 SvGETMAGIC(sv);
2041 SvGETMAGIC(right);
2042 if (RANGE_IS_NUMERIC(sv,right)) {
2043 cx->cx_type &= ~CXTYPEMASK;
2044 cx->cx_type |= CXt_LOOP_LAZYIV;
2045 /* Make sure that no-one re-orders cop.h and breaks our
2046 assumptions */
2047 assert(CxTYPE(cx) == CXt_LOOP_LAZYIV);
2048#ifdef NV_PRESERVES_UV
2049 if ((SvOK(sv) && ((SvNV(sv) < (NV)IV_MIN) ||
2050 (SvNV(sv) > (NV)IV_MAX)))
2051 ||
2052 (SvOK(right) && ((SvNV(right) > (NV)IV_MAX) ||
2053 (SvNV(right) < (NV)IV_MIN))))
2054#else
2055 if ((SvOK(sv) && ((SvNV(sv) <= (NV)IV_MIN)
2056 ||
2057 ((SvNV(sv) > 0) &&
2058 ((SvUV(sv) > (UV)IV_MAX) ||
2059 (SvNV(sv) > (NV)UV_MAX)))))
2060 ||
2061 (SvOK(right) && ((SvNV(right) <= (NV)IV_MIN)
2062 ||
2063 ((SvNV(right) > 0) &&
2064 ((SvUV(right) > (UV)IV_MAX) ||
2065 (SvNV(right) > (NV)UV_MAX))))))
2066#endif
2067 DIE(aTHX_ "Range iterator outside integer range");
2068 cx->blk_loop.state_u.lazyiv.cur = SvIV(sv);
2069 cx->blk_loop.state_u.lazyiv.end = SvIV(right);
2070#ifdef DEBUGGING
2071 /* for correct -Dstv display */
2072 cx->blk_oldsp = sp - PL_stack_base;
2073#endif
2074 }
2075 else {
2076 cx->cx_type &= ~CXTYPEMASK;
2077 cx->cx_type |= CXt_LOOP_LAZYSV;
2078 /* Make sure that no-one re-orders cop.h and breaks our
2079 assumptions */
2080 assert(CxTYPE(cx) == CXt_LOOP_LAZYSV);
2081 cx->blk_loop.state_u.lazysv.cur = newSVsv(sv);
2082 cx->blk_loop.state_u.lazysv.end = right;
2083 SvREFCNT_inc(right);
2084 (void) SvPV_force_nolen(cx->blk_loop.state_u.lazysv.cur);
2085 /* This will do the upgrade to SVt_PV, and warn if the value
2086 is uninitialised. */
2087 (void) SvPV_nolen_const(right);
2088 /* Doing this avoids a check every time in pp_iter in pp_hot.c
2089 to replace !SvOK() with a pointer to "". */
2090 if (!SvOK(right)) {
2091 SvREFCNT_dec(right);
2092 cx->blk_loop.state_u.lazysv.end = &PL_sv_no;
2093 }
2094 }
2095 }
2096 else /* SvTYPE(maybe_ary) == SVt_PVAV */ {
2097 cx->blk_loop.state_u.ary.ary = MUTABLE_AV(maybe_ary);
2098 SvREFCNT_inc(maybe_ary);
2099 cx->blk_loop.state_u.ary.ix =
2100 (PL_op->op_private & OPpITER_REVERSED) ?
2101 AvFILL(cx->blk_loop.state_u.ary.ary) + 1 :
2102 -1;
2103 }
2104 }
2105 else { /* iterating over items on the stack */
2106 cx->blk_loop.state_u.ary.ary = NULL; /* means to use the stack */
2107 if (PL_op->op_private & OPpITER_REVERSED) {
2108 cx->blk_loop.state_u.ary.ix = cx->blk_oldsp + 1;
2109 }
2110 else {
2111 cx->blk_loop.state_u.ary.ix = MARK - PL_stack_base;
2112 }
2113 }
2114
2115 RETURN;
2116}
2117
2118PP(pp_enterloop)
2119{
2120 dVAR; dSP;
2121 register PERL_CONTEXT *cx;
2122 const I32 gimme = GIMME_V;
2123
2124 ENTER_with_name("loop1");
2125 SAVETMPS;
2126 ENTER_with_name("loop2");
2127
2128 PUSHBLOCK(cx, CXt_LOOP_PLAIN, SP);
2129 PUSHLOOP_PLAIN(cx, SP);
2130
2131 RETURN;
2132}
2133
2134PP(pp_leaveloop)
2135{
2136 dVAR; dSP;
2137 register PERL_CONTEXT *cx;
2138 I32 gimme;
2139 SV **newsp;
2140 PMOP *newpm;
2141 SV **mark;
2142
2143 POPBLOCK(cx,newpm);
2144 assert(CxTYPE_is_LOOP(cx));
2145 mark = newsp;
2146 newsp = PL_stack_base + cx->blk_loop.resetsp;
2147
2148 TAINT_NOT;
2149 if (gimme == G_VOID)
2150 NOOP;
2151 else if (gimme == G_SCALAR) {
2152 if (mark < SP)
2153 *++newsp = sv_mortalcopy(*SP);
2154 else
2155 *++newsp = &PL_sv_undef;
2156 }
2157 else {
2158 while (mark < SP) {
2159 *++newsp = sv_mortalcopy(*++mark);
2160 TAINT_NOT; /* Each item is independent */
2161 }
2162 }
2163 SP = newsp;
2164 PUTBACK;
2165
2166 POPLOOP(cx); /* Stack values are safe: release loop vars ... */
2167 PL_curpm = newpm; /* ... and pop $1 et al */
2168
2169 LEAVE_with_name("loop2");
2170 LEAVE_with_name("loop1");
2171
2172 return NORMAL;
2173}
2174
2175PP(pp_return)
2176{
2177 dVAR; dSP; dMARK;
2178 register PERL_CONTEXT *cx;
2179 bool popsub2 = FALSE;
2180 bool clear_errsv = FALSE;
2181 I32 gimme;
2182 SV **newsp;
2183 PMOP *newpm;
2184 I32 optype = 0;
2185 SV *namesv;
2186 SV *sv;
2187 OP *retop = NULL;
2188
2189 const I32 cxix = dopoptosub(cxstack_ix);
2190
2191 if (cxix < 0) {
2192 if (CxMULTICALL(cxstack)) { /* In this case we must be in a
2193 * sort block, which is a CXt_NULL
2194 * not a CXt_SUB */
2195 dounwind(0);
2196 PL_stack_base[1] = *PL_stack_sp;
2197 PL_stack_sp = PL_stack_base + 1;
2198 return 0;
2199 }
2200 else
2201 DIE(aTHX_ "Can't return outside a subroutine");
2202 }
2203 if (cxix < cxstack_ix)
2204 dounwind(cxix);
2205
2206 if (CxMULTICALL(&cxstack[cxix])) {
2207 gimme = cxstack[cxix].blk_gimme;
2208 if (gimme == G_VOID)
2209 PL_stack_sp = PL_stack_base;
2210 else if (gimme == G_SCALAR) {
2211 PL_stack_base[1] = *PL_stack_sp;
2212 PL_stack_sp = PL_stack_base + 1;
2213 }
2214 return 0;
2215 }
2216
2217 POPBLOCK(cx,newpm);
2218 switch (CxTYPE(cx)) {
2219 case CXt_SUB:
2220 popsub2 = TRUE;
2221 retop = cx->blk_sub.retop;
2222 cxstack_ix++; /* preserve cx entry on stack for use by POPSUB */
2223 break;
2224 case CXt_EVAL:
2225 if (!(PL_in_eval & EVAL_KEEPERR))
2226 clear_errsv = TRUE;
2227 POPEVAL(cx);
2228 namesv = cx->blk_eval.old_namesv;
2229 retop = cx->blk_eval.retop;
2230 if (CxTRYBLOCK(cx))
2231 break;
2232 lex_end();
2233 if (optype == OP_REQUIRE &&
2234 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
2235 {
2236 /* Unassume the success we assumed earlier. */
2237 (void)hv_delete(GvHVn(PL_incgv),
2238 SvPVX_const(namesv), SvCUR(namesv),
2239 G_DISCARD);
2240 DIE(aTHX_ "%"SVf" did not return a true value", SVfARG(namesv));
2241 }
2242 break;
2243 case CXt_FORMAT:
2244 POPFORMAT(cx);
2245 retop = cx->blk_sub.retop;
2246 break;
2247 default:
2248 DIE(aTHX_ "panic: return");
2249 }
2250
2251 TAINT_NOT;
2252 if (gimme == G_SCALAR) {
2253 if (MARK < SP) {
2254 if (popsub2) {
2255 if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
2256 if (SvTEMP(TOPs)) {
2257 *++newsp = SvREFCNT_inc(*SP);
2258 FREETMPS;
2259 sv_2mortal(*newsp);
2260 }
2261 else {
2262 sv = SvREFCNT_inc(*SP); /* FREETMPS could clobber it */
2263 FREETMPS;
2264 *++newsp = sv_mortalcopy(sv);
2265 SvREFCNT_dec(sv);
2266 }
2267 }
2268 else
2269 *++newsp = (SvTEMP(*SP)) ? *SP : sv_mortalcopy(*SP);
2270 }
2271 else
2272 *++newsp = sv_mortalcopy(*SP);
2273 }
2274 else
2275 *++newsp = &PL_sv_undef;
2276 }
2277 else if (gimme == G_ARRAY) {
2278 while (++MARK <= SP) {
2279 *++newsp = (popsub2 && SvTEMP(*MARK))
2280 ? *MARK : sv_mortalcopy(*MARK);
2281 TAINT_NOT; /* Each item is independent */
2282 }
2283 }
2284 PL_stack_sp = newsp;
2285
2286 LEAVE;
2287 /* Stack values are safe: */
2288 if (popsub2) {
2289 cxstack_ix--;
2290 POPSUB(cx,sv); /* release CV and @_ ... */
2291 }
2292 else
2293 sv = NULL;
2294 PL_curpm = newpm; /* ... and pop $1 et al */
2295
2296 LEAVESUB(sv);
2297 if (clear_errsv) {
2298 CLEAR_ERRSV();
2299 }
2300 return retop;
2301}
2302
2303PP(pp_last)
2304{
2305 dVAR; dSP;
2306 I32 cxix;
2307 register PERL_CONTEXT *cx;
2308 I32 pop2 = 0;
2309 I32 gimme;
2310 I32 optype;
2311 OP *nextop = NULL;
2312 SV **newsp;
2313 PMOP *newpm;
2314 SV **mark;
2315 SV *sv = NULL;
2316
2317
2318 if (PL_op->op_flags & OPf_SPECIAL) {
2319 cxix = dopoptoloop(cxstack_ix);
2320 if (cxix < 0)
2321 DIE(aTHX_ "Can't \"last\" outside a loop block");
2322 }
2323 else {
2324 cxix = dopoptolabel(cPVOP->op_pv);
2325 if (cxix < 0)
2326 DIE(aTHX_ "Label not found for \"last %s\"", cPVOP->op_pv);
2327 }
2328 if (cxix < cxstack_ix)
2329 dounwind(cxix);
2330
2331 POPBLOCK(cx,newpm);
2332 cxstack_ix++; /* temporarily protect top context */
2333 mark = newsp;
2334 switch (CxTYPE(cx)) {
2335 case CXt_LOOP_LAZYIV:
2336 case CXt_LOOP_LAZYSV:
2337 case CXt_LOOP_FOR:
2338 case CXt_LOOP_PLAIN:
2339 pop2 = CxTYPE(cx);
2340 newsp = PL_stack_base + cx->blk_loop.resetsp;
2341 nextop = cx->blk_loop.my_op->op_lastop->op_next;
2342 break;
2343 case CXt_SUB:
2344 pop2 = CXt_SUB;
2345 nextop = cx->blk_sub.retop;
2346 break;
2347 case CXt_EVAL:
2348 POPEVAL(cx);
2349 nextop = cx->blk_eval.retop;
2350 break;
2351 case CXt_FORMAT:
2352 POPFORMAT(cx);
2353 nextop = cx->blk_sub.retop;
2354 break;
2355 default:
2356 DIE(aTHX_ "panic: last");
2357 }
2358
2359 TAINT_NOT;
2360 if (gimme == G_SCALAR) {
2361 if (MARK < SP)
2362 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
2363 ? *SP : sv_mortalcopy(*SP);
2364 else
2365 *++newsp = &PL_sv_undef;
2366 }
2367 else if (gimme == G_ARRAY) {
2368 while (++MARK <= SP) {
2369 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
2370 ? *MARK : sv_mortalcopy(*MARK);
2371 TAINT_NOT; /* Each item is independent */
2372 }
2373 }
2374 SP = newsp;
2375 PUTBACK;
2376
2377 LEAVE;
2378 cxstack_ix--;
2379 /* Stack values are safe: */
2380 switch (pop2) {
2381 case CXt_LOOP_LAZYIV:
2382 case CXt_LOOP_PLAIN:
2383 case CXt_LOOP_LAZYSV:
2384 case CXt_LOOP_FOR:
2385 POPLOOP(cx); /* release loop vars ... */
2386 LEAVE;
2387 break;
2388 case CXt_SUB:
2389 POPSUB(cx,sv); /* release CV and @_ ... */
2390 break;
2391 }
2392 PL_curpm = newpm; /* ... and pop $1 et al */
2393
2394 LEAVESUB(sv);
2395 PERL_UNUSED_VAR(optype);
2396 PERL_UNUSED_VAR(gimme);
2397 return nextop;
2398}
2399
2400PP(pp_next)
2401{
2402 dVAR;
2403 I32 cxix;
2404 register PERL_CONTEXT *cx;
2405 I32 inner;
2406
2407 if (PL_op->op_flags & OPf_SPECIAL) {
2408 cxix = dopoptoloop(cxstack_ix);
2409 if (cxix < 0)
2410 DIE(aTHX_ "Can't \"next\" outside a loop block");
2411 }
2412 else {
2413 cxix = dopoptolabel(cPVOP->op_pv);
2414 if (cxix < 0)
2415 DIE(aTHX_ "Label not found for \"next %s\"", cPVOP->op_pv);
2416 }
2417 if (cxix < cxstack_ix)
2418 dounwind(cxix);
2419
2420 /* clear off anything above the scope we're re-entering, but
2421 * save the rest until after a possible continue block */
2422 inner = PL_scopestack_ix;
2423 TOPBLOCK(cx);
2424 if (PL_scopestack_ix < inner)
2425 leave_scope(PL_scopestack[PL_scopestack_ix]);
2426 PL_curcop = cx->blk_oldcop;
2427 return (cx)->blk_loop.my_op->op_nextop;
2428}
2429
2430PP(pp_redo)
2431{
2432 dVAR;
2433 I32 cxix;
2434 register PERL_CONTEXT *cx;
2435 I32 oldsave;
2436 OP* redo_op;
2437
2438 if (PL_op->op_flags & OPf_SPECIAL) {
2439 cxix = dopoptoloop(cxstack_ix);
2440 if (cxix < 0)
2441 DIE(aTHX_ "Can't \"redo\" outside a loop block");
2442 }
2443 else {
2444 cxix = dopoptolabel(cPVOP->op_pv);
2445 if (cxix < 0)
2446 DIE(aTHX_ "Label not found for \"redo %s\"", cPVOP->op_pv);
2447 }
2448 if (cxix < cxstack_ix)
2449 dounwind(cxix);
2450
2451 redo_op = cxstack[cxix].blk_loop.my_op->op_redoop;
2452 if (redo_op->op_type == OP_ENTER) {
2453 /* pop one less context to avoid $x being freed in while (my $x..) */
2454 cxstack_ix++;
2455 assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_BLOCK);
2456 redo_op = redo_op->op_next;
2457 }
2458
2459 TOPBLOCK(cx);
2460 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2461 LEAVE_SCOPE(oldsave);
2462 FREETMPS;
2463 PL_curcop = cx->blk_oldcop;
2464 return redo_op;
2465}
2466
2467STATIC OP *
2468S_dofindlabel(pTHX_ OP *o, const char *label, OP **opstack, OP **oplimit)
2469{
2470 dVAR;
2471 OP **ops = opstack;
2472 static const char too_deep[] = "Target of goto is too deeply nested";
2473
2474 PERL_ARGS_ASSERT_DOFINDLABEL;
2475
2476 if (ops >= oplimit)
2477 Perl_croak(aTHX_ too_deep);
2478 if (o->op_type == OP_LEAVE ||
2479 o->op_type == OP_SCOPE ||
2480 o->op_type == OP_LEAVELOOP ||
2481 o->op_type == OP_LEAVESUB ||
2482 o->op_type == OP_LEAVETRY)
2483 {
2484 *ops++ = cUNOPo->op_first;
2485 if (ops >= oplimit)
2486 Perl_croak(aTHX_ too_deep);
2487 }
2488 *ops = 0;
2489 if (o->op_flags & OPf_KIDS) {
2490 OP *kid;
2491 /* First try all the kids at this level, since that's likeliest. */
2492 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
2493 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
2494 const char *kid_label = CopLABEL(kCOP);
2495 if (kid_label && strEQ(kid_label, label))
2496 return kid;
2497 }
2498 }
2499 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
2500 if (kid == PL_lastgotoprobe)
2501 continue;
2502 if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) {
2503 if (ops == opstack)
2504 *ops++ = kid;
2505 else if (ops[-1]->op_type == OP_NEXTSTATE ||
2506 ops[-1]->op_type == OP_DBSTATE)
2507 ops[-1] = kid;
2508 else
2509 *ops++ = kid;
2510 }
2511 if ((o = dofindlabel(kid, label, ops, oplimit)))
2512 return o;
2513 }
2514 }
2515 *ops = 0;
2516 return 0;
2517}
2518
2519PP(pp_goto)
2520{
2521 dVAR; dSP;
2522 OP *retop = NULL;
2523 I32 ix;
2524 register PERL_CONTEXT *cx;
2525#define GOTO_DEPTH 64
2526 OP *enterops[GOTO_DEPTH];
2527 const char *label = NULL;
2528 const bool do_dump = (PL_op->op_type == OP_DUMP);
2529 static const char must_have_label[] = "goto must have label";
2530
2531 if (PL_op->op_flags & OPf_STACKED) {
2532 SV * const sv = POPs;
2533
2534 /* This egregious kludge implements goto &subroutine */
2535 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
2536 I32 cxix;
2537 register PERL_CONTEXT *cx;
2538 CV *cv = MUTABLE_CV(SvRV(sv));
2539 SV** mark;
2540 I32 items = 0;
2541 I32 oldsave;
2542 bool reified = 0;
2543
2544 retry:
2545 if (!CvROOT(cv) && !CvXSUB(cv)) {
2546 const GV * const gv = CvGV(cv);
2547 if (gv) {
2548 GV *autogv;
2549 SV *tmpstr;
2550 /* autoloaded stub? */
2551 if (cv != GvCV(gv) && (cv = GvCV(gv)))
2552 goto retry;
2553 autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv),
2554 GvNAMELEN(gv), FALSE);
2555 if (autogv && (cv = GvCV(autogv)))
2556 goto retry;
2557 tmpstr = sv_newmortal();
2558 gv_efullname3(tmpstr, gv, NULL);
2559 DIE(aTHX_ "Goto undefined subroutine &%"SVf"", SVfARG(tmpstr));
2560 }
2561 DIE(aTHX_ "Goto undefined subroutine");
2562 }
2563
2564 /* First do some returnish stuff. */
2565 SvREFCNT_inc_simple_void(cv); /* avoid premature free during unwind */
2566 FREETMPS;
2567 cxix = dopoptosub(cxstack_ix);
2568 if (cxix < 0)
2569 DIE(aTHX_ "Can't goto subroutine outside a subroutine");
2570 if (cxix < cxstack_ix)
2571 dounwind(cxix);
2572 TOPBLOCK(cx);
2573 SPAGAIN;
2574 /* ban goto in eval: see <20050521150056.GC20213@iabyn.com> */
2575 if (CxTYPE(cx) == CXt_EVAL) {
2576 if (CxREALEVAL(cx))
2577 DIE(aTHX_ "Can't goto subroutine from an eval-string");
2578 else
2579 DIE(aTHX_ "Can't goto subroutine from an eval-block");
2580 }
2581 else if (CxMULTICALL(cx))
2582 DIE(aTHX_ "Can't goto subroutine from a sort sub (or similar callback)");
2583 if (CxTYPE(cx) == CXt_SUB && CxHASARGS(cx)) {
2584 /* put @_ back onto stack */
2585 AV* av = cx->blk_sub.argarray;
2586
2587 items = AvFILLp(av) + 1;
2588 EXTEND(SP, items+1); /* @_ could have been extended. */
2589 Copy(AvARRAY(av), SP + 1, items, SV*);
2590 SvREFCNT_dec(GvAV(PL_defgv));
2591 GvAV(PL_defgv) = cx->blk_sub.savearray;
2592 CLEAR_ARGARRAY(av);
2593 /* abandon @_ if it got reified */
2594 if (AvREAL(av)) {
2595 reified = 1;
2596 SvREFCNT_dec(av);
2597 av = newAV();
2598 av_extend(av, items-1);
2599 AvREIFY_only(av);
2600 PAD_SVl(0) = MUTABLE_SV(cx->blk_sub.argarray = av);
2601 }
2602 }
2603 else if (CvISXSUB(cv)) { /* put GvAV(defgv) back onto stack */
2604 AV* const av = GvAV(PL_defgv);
2605 items = AvFILLp(av) + 1;
2606 EXTEND(SP, items+1); /* @_ could have been extended. */
2607 Copy(AvARRAY(av), SP + 1, items, SV*);
2608 }
2609 mark = SP;
2610 SP += items;
2611 if (CxTYPE(cx) == CXt_SUB &&
2612 !(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
2613 SvREFCNT_dec(cx->blk_sub.cv);
2614 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2615 LEAVE_SCOPE(oldsave);
2616
2617 /* Now do some callish stuff. */
2618 SAVETMPS;
2619 SAVEFREESV(cv); /* later, undo the 'avoid premature free' hack */
2620 if (CvISXSUB(cv)) {
2621 OP* const retop = cx->blk_sub.retop;
2622 SV **newsp;
2623 I32 gimme;
2624 if (reified) {
2625 I32 index;
2626 for (index=0; index<items; index++)
2627 sv_2mortal(SP[-index]);
2628 }
2629
2630 /* XS subs don't have a CxSUB, so pop it */
2631 POPBLOCK(cx, PL_curpm);
2632 /* Push a mark for the start of arglist */
2633 PUSHMARK(mark);
2634 PUTBACK;
2635 (void)(*CvXSUB(cv))(aTHX_ cv);
2636 LEAVE;
2637 return retop;
2638 }
2639 else {
2640 AV* const padlist = CvPADLIST(cv);
2641 if (CxTYPE(cx) == CXt_EVAL) {
2642 PL_in_eval = CxOLD_IN_EVAL(cx);
2643 PL_eval_root = cx->blk_eval.old_eval_root;
2644 cx->cx_type = CXt_SUB;
2645 }
2646 cx->blk_sub.cv = cv;
2647 cx->blk_sub.olddepth = CvDEPTH(cv);
2648
2649 CvDEPTH(cv)++;
2650 if (CvDEPTH(cv) < 2)
2651 SvREFCNT_inc_simple_void_NN(cv);
2652 else {
2653 if (CvDEPTH(cv) == PERL_SUB_DEPTH_WARN && ckWARN(WARN_RECURSION))
2654 sub_crush_depth(cv);
2655 pad_push(padlist, CvDEPTH(cv));
2656 }
2657 SAVECOMPPAD();
2658 PAD_SET_CUR_NOSAVE(padlist, CvDEPTH(cv));
2659 if (CxHASARGS(cx))
2660 {
2661 AV *const av = MUTABLE_AV(PAD_SVl(0));
2662
2663 cx->blk_sub.savearray = GvAV(PL_defgv);
2664 GvAV(PL_defgv) = MUTABLE_AV(SvREFCNT_inc_simple(av));
2665 CX_CURPAD_SAVE(cx->blk_sub);
2666 cx->blk_sub.argarray = av;
2667
2668 if (items >= AvMAX(av) + 1) {
2669 SV **ary = AvALLOC(av);
2670 if (AvARRAY(av) != ary) {
2671 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
2672 AvARRAY(av) = ary;
2673 }
2674 if (items >= AvMAX(av) + 1) {
2675 AvMAX(av) = items - 1;
2676 Renew(ary,items+1,SV*);
2677 AvALLOC(av) = ary;
2678 AvARRAY(av) = ary;
2679 }
2680 }
2681 ++mark;
2682 Copy(mark,AvARRAY(av),items,SV*);
2683 AvFILLp(av) = items - 1;
2684 assert(!AvREAL(av));
2685 if (reified) {
2686 /* transfer 'ownership' of refcnts to new @_ */
2687 AvREAL_on(av);
2688 AvREIFY_off(av);
2689 }
2690 while (items--) {
2691 if (*mark)
2692 SvTEMP_off(*mark);
2693 mark++;
2694 }
2695 }
2696 if (PERLDB_SUB) { /* Checking curstash breaks DProf. */
2697 Perl_get_db_sub(aTHX_ NULL, cv);
2698 if (PERLDB_GOTO) {
2699 CV * const gotocv = get_cvs("DB::goto", 0);
2700 if (gotocv) {
2701 PUSHMARK( PL_stack_sp );
2702 call_sv(MUTABLE_SV(gotocv), G_SCALAR | G_NODEBUG);
2703 PL_stack_sp--;
2704 }
2705 }
2706 }
2707 RETURNOP(CvSTART(cv));
2708 }
2709 }
2710 else {
2711 label = SvPV_nolen_const(sv);
2712 if (!(do_dump || *label))
2713 DIE(aTHX_ must_have_label);
2714 }
2715 }
2716 else if (PL_op->op_flags & OPf_SPECIAL) {
2717 if (! do_dump)
2718 DIE(aTHX_ must_have_label);
2719 }
2720 else
2721 label = cPVOP->op_pv;
2722
2723 PERL_ASYNC_CHECK();
2724
2725 if (label && *label) {
2726 OP *gotoprobe = NULL;
2727 bool leaving_eval = FALSE;
2728 bool in_block = FALSE;
2729 PERL_CONTEXT *last_eval_cx = NULL;
2730
2731 /* find label */
2732
2733 PL_lastgotoprobe = NULL;
2734 *enterops = 0;
2735 for (ix = cxstack_ix; ix >= 0; ix--) {
2736 cx = &cxstack[ix];
2737 switch (CxTYPE(cx)) {
2738 case CXt_EVAL:
2739 leaving_eval = TRUE;
2740 if (!CxTRYBLOCK(cx)) {
2741 gotoprobe = (last_eval_cx ?
2742 last_eval_cx->blk_eval.old_eval_root :
2743 PL_eval_root);
2744 last_eval_cx = cx;
2745 break;
2746 }
2747 /* else fall through */
2748 case CXt_LOOP_LAZYIV:
2749 case CXt_LOOP_LAZYSV:
2750 case CXt_LOOP_FOR:
2751 case CXt_LOOP_PLAIN:
2752 case CXt_GIVEN:
2753 case CXt_WHEN:
2754 gotoprobe = cx->blk_oldcop->op_sibling;
2755 break;
2756 case CXt_SUBST:
2757 continue;
2758 case CXt_BLOCK:
2759 if (ix) {
2760 gotoprobe = cx->blk_oldcop->op_sibling;
2761 in_block = TRUE;
2762 } else
2763 gotoprobe = PL_main_root;
2764 break;
2765 case CXt_SUB:
2766 if (CvDEPTH(cx->blk_sub.cv) && !CxMULTICALL(cx)) {
2767 gotoprobe = CvROOT(cx->blk_sub.cv);
2768 break;
2769 }
2770 /* FALL THROUGH */
2771 case CXt_FORMAT:
2772 case CXt_NULL:
2773 DIE(aTHX_ "Can't \"goto\" out of a pseudo block");
2774 default:
2775 if (ix)
2776 DIE(aTHX_ "panic: goto");
2777 gotoprobe = PL_main_root;
2778 break;
2779 }
2780 if (gotoprobe) {
2781 retop = dofindlabel(gotoprobe, label,
2782 enterops, enterops + GOTO_DEPTH);
2783 if (retop)
2784 break;
2785 }
2786 PL_lastgotoprobe = gotoprobe;
2787 }
2788 if (!retop)
2789 DIE(aTHX_ "Can't find label %s", label);
2790
2791 /* if we're leaving an eval, check before we pop any frames
2792 that we're not going to punt, otherwise the error
2793 won't be caught */
2794
2795 if (leaving_eval && *enterops && enterops[1]) {
2796 I32 i;
2797 for (i = 1; enterops[i]; i++)
2798 if (enterops[i]->op_type == OP_ENTERITER)
2799 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2800 }
2801
2802 if (*enterops && enterops[1]) {
2803 I32 i = enterops[1]->op_type == OP_ENTER && in_block ? 2 : 1;
2804 if (enterops[i])
2805 deprecate("\"goto\" to jump into a construct");
2806 }
2807
2808 /* pop unwanted frames */
2809
2810 if (ix < cxstack_ix) {
2811 I32 oldsave;
2812
2813 if (ix < 0)
2814 ix = 0;
2815 dounwind(ix);
2816 TOPBLOCK(cx);
2817 oldsave = PL_scopestack[PL_scopestack_ix];
2818 LEAVE_SCOPE(oldsave);
2819 }
2820
2821 /* push wanted frames */
2822
2823 if (*enterops && enterops[1]) {
2824 OP * const oldop = PL_op;
2825 ix = enterops[1]->op_type == OP_ENTER && in_block ? 2 : 1;
2826 for (; enterops[ix]; ix++) {
2827 PL_op = enterops[ix];
2828 /* Eventually we may want to stack the needed arguments
2829 * for each op. For now, we punt on the hard ones. */
2830 if (PL_op->op_type == OP_ENTERITER)
2831 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
2832 PL_op->op_ppaddr(aTHX);
2833 }
2834 PL_op = oldop;
2835 }
2836 }
2837
2838 if (do_dump) {
2839#ifdef VMS
2840 if (!retop) retop = PL_main_start;
2841#endif
2842 PL_restartop = retop;
2843 PL_do_undump = TRUE;
2844
2845 my_unexec();
2846
2847 PL_restartop = 0; /* hmm, must be GNU unexec().. */
2848 PL_do_undump = FALSE;
2849 }
2850
2851 RETURNOP(retop);
2852}
2853
2854PP(pp_exit)
2855{
2856 dVAR;
2857 dSP;
2858 I32 anum;
2859
2860 if (MAXARG < 1)
2861 anum = 0;
2862 else {
2863 anum = SvIVx(POPs);
2864#ifdef VMS
2865 if (anum == 1 && (PL_op->op_private & OPpEXIT_VMSISH))
2866 anum = 0;
2867 VMSISH_HUSHED = VMSISH_HUSHED || (PL_op->op_private & OPpHUSH_VMSISH);
2868#endif
2869 }
2870 PL_exit_flags |= PERL_EXIT_EXPECTED;
2871#ifdef PERL_MAD
2872 /* KLUDGE: disable exit 0 in BEGIN blocks when we're just compiling */
2873 if (anum || !(PL_minus_c && PL_madskills))
2874 my_exit(anum);
2875#else
2876 my_exit(anum);
2877#endif
2878 PUSHs(&PL_sv_undef);
2879 RETURN;
2880}
2881
2882/* Eval. */
2883
2884STATIC void
2885S_save_lines(pTHX_ AV *array, SV *sv)
2886{
2887 const char *s = SvPVX_const(sv);
2888 const char * const send = SvPVX_const(sv) + SvCUR(sv);
2889 I32 line = 1;
2890
2891 PERL_ARGS_ASSERT_SAVE_LINES;
2892
2893 while (s && s < send) {
2894 const char *t;
2895 SV * const tmpstr = newSV_type(SVt_PVMG);
2896
2897 t = (const char *)memchr(s, '\n', send - s);
2898 if (t)
2899 t++;
2900 else
2901 t = send;
2902
2903 sv_setpvn(tmpstr, s, t - s);
2904 av_store(array, line++, tmpstr);
2905 s = t;
2906 }
2907}
2908
2909/*
2910=for apidoc docatch
2911
2912Check for the cases 0 or 3 of cur_env.je_ret, only used inside an eval context.
2913
29140 is used as continue inside eval,
2915
29163 is used for a die caught by an inner eval - continue inner loop
2917
2918See cop.h: je_mustcatch, when set at any runlevel to TRUE, means eval ops must
2919establish a local jmpenv to handle exception traps.
2920
2921=cut
2922*/
2923STATIC OP *
2924S_docatch(pTHX_ OP *o)
2925{
2926 dVAR;
2927 int ret;
2928 OP * const oldop = PL_op;
2929 dJMPENV;
2930
2931#ifdef DEBUGGING
2932 assert(CATCH_GET == TRUE);
2933#endif
2934 PL_op = o;
2935
2936 JMPENV_PUSH(ret);
2937 switch (ret) {
2938 case 0:
2939 assert(cxstack_ix >= 0);
2940 assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
2941 cxstack[cxstack_ix].blk_eval.cur_top_env = PL_top_env;
2942 redo_body:
2943 CALLRUNOPS(aTHX);
2944 break;
2945 case 3:
2946 /* die caught by an inner eval - continue inner loop */
2947 if (PL_restartop && PL_restartjmpenv == PL_top_env) {
2948 PL_restartjmpenv = NULL;
2949 PL_op = PL_restartop;
2950 PL_restartop = 0;
2951 goto redo_body;
2952 }
2953 /* FALL THROUGH */
2954 default:
2955 JMPENV_POP;
2956 PL_op = oldop;
2957 JMPENV_JUMP(ret);
2958 /* NOTREACHED */
2959 }
2960 JMPENV_POP;
2961 PL_op = oldop;
2962 return NULL;
2963}
2964
2965/* James Bond: Do you expect me to talk?
2966 Auric Goldfinger: No, Mr. Bond. I expect you to die.
2967
2968 This code is an ugly hack, doesn't work with lexicals in subroutines that are
2969 called more than once, and is only used by regcomp.c, for (?{}) blocks.
2970
2971 Currently it is not used outside the core code. Best if it stays that way.
2972*/
2973OP *
2974Perl_sv_compile_2op(pTHX_ SV *sv, OP** startop, const char *code, PAD** padp)
2975/* sv Text to convert to OP tree. */
2976/* startop op_free() this to undo. */
2977/* code Short string id of the caller. */
2978{
2979 dVAR; dSP; /* Make POPBLOCK work. */
2980 PERL_CONTEXT *cx;
2981 SV **newsp;
2982 I32 gimme = G_VOID;
2983 I32 optype;
2984 OP dummy;
2985 char tbuf[TYPE_DIGITS(long) + 12 + 10];
2986 char *tmpbuf = tbuf;
2987 char *safestr;
2988 int runtime;
2989 CV* runcv = NULL; /* initialise to avoid compiler warnings */
2990 STRLEN len;
2991 bool need_catch;
2992
2993 PERL_ARGS_ASSERT_SV_COMPILE_2OP;
2994
2995 ENTER_with_name("eval");
2996 lex_start(sv, NULL, FALSE);
2997 SAVETMPS;
2998 /* switch to eval mode */
2999
3000 if (IN_PERL_COMPILETIME) {
3001 SAVECOPSTASH_FREE(&PL_compiling);
3002 CopSTASH_set(&PL_compiling, PL_curstash);
3003 }
3004 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
3005 SV * const sv = sv_newmortal();
3006 Perl_sv_setpvf(aTHX_ sv, "_<(%.10seval %lu)[%s:%"IVdf"]",
3007 code, (unsigned long)++PL_evalseq,
3008 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
3009 tmpbuf = SvPVX(sv);
3010 len = SvCUR(sv);
3011 }
3012 else
3013 len = my_snprintf(tmpbuf, sizeof(tbuf), "_<(%.10s_eval %lu)", code,
3014 (unsigned long)++PL_evalseq);
3015 SAVECOPFILE_FREE(&PL_compiling);
3016 CopFILE_set(&PL_compiling, tmpbuf+2);
3017 SAVECOPLINE(&PL_compiling);
3018 CopLINE_set(&PL_compiling, 1);
3019 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
3020 deleting the eval's FILEGV from the stash before gv_check() runs
3021 (i.e. before run-time proper). To work around the coredump that
3022 ensues, we always turn GvMULTI_on for any globals that were
3023 introduced within evals. See force_ident(). GSAR 96-10-12 */
3024 safestr = savepvn(tmpbuf, len);
3025 SAVEDELETE(PL_defstash, safestr, len);
3026 SAVEHINTS();
3027#ifdef OP_IN_REGISTER
3028 PL_opsave = op;
3029#else
3030 SAVEVPTR(PL_op);
3031#endif
3032
3033 /* we get here either during compilation, or via pp_regcomp at runtime */
3034 runtime = IN_PERL_RUNTIME;
3035 if (runtime)
3036 runcv = find_runcv(NULL);
3037
3038 PL_op = &dummy;
3039 PL_op->op_type = OP_ENTEREVAL;
3040 PL_op->op_flags = 0; /* Avoid uninit warning. */
3041 PUSHBLOCK(cx, CXt_EVAL|(IN_PERL_COMPILETIME ? 0 : CXp_REAL), SP);
3042 PUSHEVAL(cx, 0);
3043 need_catch = CATCH_GET;
3044 CATCH_SET(TRUE);
3045
3046 if (runtime)
3047 (void) doeval(G_SCALAR, startop, runcv, PL_curcop->cop_seq);
3048 else
3049 (void) doeval(G_SCALAR, startop, PL_compcv, PL_cop_seqmax);
3050 CATCH_SET(need_catch);
3051 POPBLOCK(cx,PL_curpm);
3052 POPEVAL(cx);
3053
3054 (*startop)->op_type = OP_NULL;
3055 (*startop)->op_ppaddr = PL_ppaddr[OP_NULL];
3056 lex_end();
3057 /* XXX DAPM do this properly one year */
3058 *padp = MUTABLE_AV(SvREFCNT_inc_simple(PL_comppad));
3059 LEAVE_with_name("eval");
3060 if (IN_PERL_COMPILETIME)
3061 CopHINTS_set(&PL_compiling, PL_hints);
3062#ifdef OP_IN_REGISTER
3063 op = PL_opsave;
3064#endif
3065 PERL_UNUSED_VAR(newsp);
3066 PERL_UNUSED_VAR(optype);
3067
3068 return PL_eval_start;
3069}
3070
3071
3072/*
3073=for apidoc find_runcv
3074
3075Locate the CV corresponding to the currently executing sub or eval.
3076If db_seqp is non_null, skip CVs that are in the DB package and populate
3077*db_seqp with the cop sequence number at the point that the DB:: code was
3078entered. (allows debuggers to eval in the scope of the breakpoint rather
3079than in the scope of the debugger itself).
3080
3081=cut
3082*/
3083
3084CV*
3085Perl_find_runcv(pTHX_ U32 *db_seqp)
3086{
3087 dVAR;
3088 PERL_SI *si;
3089
3090 if (db_seqp)
3091 *db_seqp = PL_curcop->cop_seq;
3092 for (si = PL_curstackinfo; si; si = si->si_prev) {
3093 I32 ix;
3094 for (ix = si->si_cxix; ix >= 0; ix--) {
3095 const PERL_CONTEXT *cx = &(si->si_cxstack[ix]);
3096 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) {
3097 CV * const cv = cx->blk_sub.cv;
3098 /* skip DB:: code */
3099 if (db_seqp && PL_debstash && CvSTASH(cv) == PL_debstash) {
3100 *db_seqp = cx->blk_oldcop->cop_seq;
3101 continue;
3102 }
3103 return cv;
3104 }
3105 else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx))
3106 return PL_compcv;
3107 }
3108 }
3109 return PL_main_cv;
3110}
3111
3112
3113/* Run yyparse() in a setjmp wrapper. Returns:
3114 * 0: yyparse() successful
3115 * 1: yyparse() failed
3116 * 3: yyparse() died
3117 */
3118STATIC int
3119S_try_yyparse(pTHX_ int gramtype)
3120{
3121 int ret;
3122 dJMPENV;
3123
3124 assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
3125 JMPENV_PUSH(ret);
3126 switch (ret) {
3127 case 0:
3128 ret = yyparse(gramtype) ? 1 : 0;
3129 break;
3130 case 3:
3131 break;
3132 default:
3133 JMPENV_POP;
3134 JMPENV_JUMP(ret);
3135 /* NOTREACHED */
3136 }
3137 JMPENV_POP;
3138 return ret;
3139}
3140
3141
3142/* Compile a require/do, an eval '', or a /(?{...})/.
3143 * In the last case, startop is non-null, and contains the address of
3144 * a pointer that should be set to the just-compiled code.
3145 * outside is the lexically enclosing CV (if any) that invoked us.
3146 * Returns a bool indicating whether the compile was successful; if so,
3147 * PL_eval_start contains the first op of the compiled ocde; otherwise,
3148 * pushes undef (also croaks if startop != NULL).
3149 */
3150
3151STATIC bool
3152S_doeval(pTHX_ int gimme, OP** startop, CV* outside, U32 seq)
3153{
3154 dVAR; dSP;
3155 OP * const saveop = PL_op;
3156 bool in_require = (saveop && saveop->op_type == OP_REQUIRE);
3157 int yystatus;
3158
3159 PL_in_eval = (in_require
3160 ? (EVAL_INREQUIRE | (PL_in_eval & EVAL_INEVAL))
3161 : EVAL_INEVAL);
3162
3163 PUSHMARK(SP);
3164
3165 SAVESPTR(PL_compcv);
3166 PL_compcv = MUTABLE_CV(newSV_type(SVt_PVCV));
3167 CvEVAL_on(PL_compcv);
3168 assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
3169 cxstack[cxstack_ix].blk_eval.cv = PL_compcv;
3170
3171 CvOUTSIDE_SEQ(PL_compcv) = seq;
3172 CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outside));
3173
3174 /* set up a scratch pad */
3175
3176 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE);
3177 PL_op = NULL; /* avoid PL_op and PL_curpad referring to different CVs */
3178
3179
3180 if (!PL_madskills)
3181 SAVEMORTALIZESV(PL_compcv); /* must remain until end of current statement */
3182
3183 /* make sure we compile in the right package */
3184
3185 if (CopSTASH_ne(PL_curcop, PL_curstash)) {
3186 SAVESPTR(PL_curstash);
3187 PL_curstash = CopSTASH(PL_curcop);
3188 }
3189 /* XXX:ajgo do we really need to alloc an AV for begin/checkunit */
3190 SAVESPTR(PL_beginav);
3191 PL_beginav = newAV();
3192 SAVEFREESV(PL_beginav);
3193 SAVESPTR(PL_unitcheckav);
3194 PL_unitcheckav = newAV();
3195 SAVEFREESV(PL_unitcheckav);
3196
3197#ifdef PERL_MAD
3198 SAVEBOOL(PL_madskills);
3199 PL_madskills = 0;
3200#endif
3201
3202 /* try to compile it */
3203
3204 PL_eval_root = NULL;
3205 PL_curcop = &PL_compiling;
3206 CopARYBASE_set(PL_curcop, 0);
3207 if (saveop && (saveop->op_type != OP_REQUIRE) && (saveop->op_flags & OPf_SPECIAL))
3208 PL_in_eval |= EVAL_KEEPERR;
3209 else
3210 CLEAR_ERRSV();
3211
3212 CALL_BLOCK_HOOKS(bhk_eval, saveop);
3213
3214 /* note that yyparse() may raise an exception, e.g. C<BEGIN{die}>,
3215 * so honour CATCH_GET and trap it here if necessary */
3216
3217 yystatus = (!in_require && CATCH_GET) ? S_try_yyparse(aTHX_ GRAMPROG) : yyparse(GRAMPROG);
3218
3219 if (yystatus || PL_parser->error_count || !PL_eval_root) {
3220 SV **newsp; /* Used by POPBLOCK. */
3221 PERL_CONTEXT *cx = NULL;
3222 I32 optype; /* Used by POPEVAL. */
3223 SV *namesv = NULL;
3224 const char *msg;
3225
3226 PERL_UNUSED_VAR(newsp);
3227 PERL_UNUSED_VAR(optype);
3228
3229 /* note that if yystatus == 3, then the EVAL CX block has already
3230 * been popped, and various vars restored */
3231 PL_op = saveop;
3232 if (yystatus != 3) {
3233 if (PL_eval_root) {
3234 op_free(PL_eval_root);
3235 PL_eval_root = NULL;
3236 }
3237 SP = PL_stack_base + POPMARK; /* pop original mark */
3238 if (!startop) {
3239 POPBLOCK(cx,PL_curpm);
3240 POPEVAL(cx);
3241 namesv = cx->blk_eval.old_namesv;
3242 }
3243 }
3244 lex_end();
3245 if (yystatus != 3)
3246 LEAVE_with_name("eval"); /* pp_entereval knows about this LEAVE. */
3247
3248 msg = SvPVx_nolen_const(ERRSV);
3249 if (in_require) {
3250 if (!cx) {
3251 /* If cx is still NULL, it means that we didn't go in the
3252 * POPEVAL branch. */
3253 cx = &cxstack[cxstack_ix];
3254 assert(CxTYPE(cx) == CXt_EVAL);
3255 namesv = cx->blk_eval.old_namesv;
3256 }
3257 (void)hv_store(GvHVn(PL_incgv),
3258 SvPVX_const(namesv), SvCUR(namesv),
3259 &PL_sv_undef, 0);
3260 Perl_croak(aTHX_ "%sCompilation failed in require",
3261 *msg ? msg : "Unknown error\n");
3262 }
3263 else if (startop) {
3264 if (yystatus != 3) {
3265 POPBLOCK(cx,PL_curpm);
3266 POPEVAL(cx);
3267 }
3268 Perl_croak(aTHX_ "%sCompilation failed in regexp",
3269 (*msg ? msg : "Unknown error\n"));
3270 }
3271 else {
3272 if (!*msg) {
3273 sv_setpvs(ERRSV, "Compilation error");
3274 }
3275 }
3276 PUSHs(&PL_sv_undef);
3277 PUTBACK;
3278 return FALSE;
3279 }
3280 CopLINE_set(&PL_compiling, 0);
3281 if (startop) {
3282 *startop = PL_eval_root;
3283 } else
3284 SAVEFREEOP(PL_eval_root);
3285
3286 /* Set the context for this new optree.
3287 * Propagate the context from the eval(). */
3288 if ((gimme & G_WANT) == G_VOID)
3289 scalarvoid(PL_eval_root);
3290 else if ((gimme & G_WANT) == G_ARRAY)
3291 list(PL_eval_root);
3292 else
3293 scalar(PL_eval_root);
3294
3295 DEBUG_x(dump_eval());
3296
3297 /* Register with debugger: */
3298 if (PERLDB_INTER && saveop && saveop->op_type == OP_REQUIRE) {
3299 CV * const cv = get_cvs("DB::postponed", 0);
3300 if (cv) {
3301 dSP;
3302 PUSHMARK(SP);
3303 XPUSHs(MUTABLE_SV(CopFILEGV(&PL_compiling)));
3304 PUTBACK;
3305 call_sv(MUTABLE_SV(cv), G_DISCARD);
3306 }
3307 }
3308
3309 if (PL_unitcheckav) {
3310 OP *es = PL_eval_start;
3311 call_list(PL_scopestack_ix, PL_unitcheckav);
3312 PL_eval_start = es;
3313 }
3314
3315 /* compiled okay, so do it */
3316
3317 CvDEPTH(PL_compcv) = 1;
3318 SP = PL_stack_base + POPMARK; /* pop original mark */
3319 PL_op = saveop; /* The caller may need it. */
3320 PL_parser->lex_state = LEX_NOTPARSING; /* $^S needs this. */
3321
3322 PUTBACK;
3323 return TRUE;
3324}
3325
3326STATIC PerlIO *
3327S_check_type_and_open(pTHX_ const char *name)
3328{
3329 Stat_t st;
3330 const int st_rc = PerlLIO_stat(name, &st);
3331
3332 PERL_ARGS_ASSERT_CHECK_TYPE_AND_OPEN;
3333
3334 if (st_rc < 0 || S_ISDIR(st.st_mode) || S_ISBLK(st.st_mode)) {
3335 return NULL;
3336 }
3337
3338 return PerlIO_open(name, PERL_SCRIPT_MODE);
3339}
3340
3341#ifndef PERL_DISABLE_PMC
3342STATIC PerlIO *
3343S_doopen_pm(pTHX_ const char *name, const STRLEN namelen)
3344{
3345 PerlIO *fp;
3346
3347 PERL_ARGS_ASSERT_DOOPEN_PM;
3348
3349 if (namelen > 3 && memEQs(name + namelen - 3, 3, ".pm")) {
3350 SV *const pmcsv = newSV(namelen + 2);
3351 char *const pmc = SvPVX(pmcsv);
3352 Stat_t pmcstat;
3353
3354 memcpy(pmc, name, namelen);
3355 pmc[namelen] = 'c';
3356 pmc[namelen + 1] = '\0';
3357
3358 if (PerlLIO_stat(pmc, &pmcstat) < 0) {
3359 fp = check_type_and_open(name);
3360 }
3361 else {
3362 fp = check_type_and_open(pmc);
3363 }
3364 SvREFCNT_dec(pmcsv);
3365 }
3366 else {
3367 fp = check_type_and_open(name);
3368 }
3369 return fp;
3370}
3371#else
3372# define doopen_pm(name, namelen) check_type_and_open(name)
3373#endif /* !PERL_DISABLE_PMC */
3374
3375PP(pp_require)
3376{
3377 dVAR; dSP;
3378 register PERL_CONTEXT *cx;
3379 SV *sv;
3380 const char *name;
3381 STRLEN len;
3382 char * unixname;
3383 STRLEN unixlen;
3384#ifdef VMS
3385 int vms_unixname = 0;
3386#endif
3387 const char *tryname = NULL;
3388 SV *namesv = NULL;
3389 const I32 gimme = GIMME_V;
3390 int filter_has_file = 0;
3391 PerlIO *tryrsfp = NULL;
3392 SV *filter_cache = NULL;
3393 SV *filter_state = NULL;
3394 SV *filter_sub = NULL;
3395 SV *hook_sv = NULL;
3396 SV *encoding;
3397 OP *op;
3398
3399 sv = POPs;
3400 if ( (SvNIOKp(sv) || SvVOK(sv)) && PL_op->op_type != OP_DOFILE) {
3401 sv = new_version(sv);
3402 if (!sv_derived_from(PL_patchlevel, "version"))
3403 upg_version(PL_patchlevel, TRUE);
3404 if (cUNOP->op_first->op_type == OP_CONST && cUNOP->op_first->op_private & OPpCONST_NOVER) {
3405 if ( vcmp(sv,PL_patchlevel) <= 0 )
3406 DIE(aTHX_ "Perls since %"SVf" too modern--this is %"SVf", stopped",
3407 SVfARG(vnormal(sv)), SVfARG(vnormal(PL_patchlevel)));
3408 }
3409 else {
3410 if ( vcmp(sv,PL_patchlevel) > 0 ) {
3411 I32 first = 0;
3412 AV *lav;
3413 SV * const req = SvRV(sv);
3414 SV * const pv = *hv_fetchs(MUTABLE_HV(req), "original", FALSE);
3415
3416 /* get the left hand term */
3417 lav = MUTABLE_AV(SvRV(*hv_fetchs(MUTABLE_HV(req), "version", FALSE)));
3418
3419 first = SvIV(*av_fetch(lav,0,0));
3420 if ( first > (int)PERL_REVISION /* probably 'use 6.0' */
3421 || hv_exists(MUTABLE_HV(req), "qv", 2 ) /* qv style */
3422 || av_len(lav) > 1 /* FP with > 3 digits */
3423 || strstr(SvPVX(pv),".0") /* FP with leading 0 */
3424 ) {
3425 DIE(aTHX_ "Perl %"SVf" required--this is only "
3426 "%"SVf", stopped", SVfARG(vnormal(req)),
3427 SVfARG(vnormal(PL_patchlevel)));
3428 }
3429 else { /* probably 'use 5.10' or 'use 5.8' */
3430 SV *hintsv;
3431 I32 second = 0;
3432
3433 if (av_len(lav)>=1)
3434 second = SvIV(*av_fetch(lav,1,0));
3435
3436 second /= second >= 600 ? 100 : 10;
3437 hintsv = Perl_newSVpvf(aTHX_ "v%d.%d.0",
3438 (int)first, (int)second);
3439 upg_version(hintsv, TRUE);
3440
3441 DIE(aTHX_ "Perl %"SVf" required (did you mean %"SVf"?)"
3442 "--this is only %"SVf", stopped",
3443 SVfARG(vnormal(req)),
3444 SVfARG(vnormal(sv_2mortal(hintsv))),
3445 SVfARG(vnormal(PL_patchlevel)));
3446 }
3447 }
3448 }
3449
3450 /* We do this only with "use", not "require" or "no". */
3451 if (PL_compcv && !(cUNOP->op_first->op_private & OPpCONST_NOVER)) {
3452 /* If we request a version >= 5.9.5, load feature.pm with the
3453 * feature bundle that corresponds to the required version. */
3454 if (vcmp(sv, sv_2mortal(upg_version(newSVnv(5.009005), FALSE))) >= 0) {
3455 SV *const importsv = vnormal(sv);
3456 *SvPVX_mutable(importsv) = ':';
3457 ENTER_with_name("load_feature");
3458 Perl_load_module(aTHX_ 0, newSVpvs("feature"), NULL, importsv, NULL);
3459 LEAVE_with_name("load_feature");
3460 }
3461 /* If a version >= 5.11.0 is requested, strictures are on by default! */
3462 if (vcmp(sv, sv_2mortal(upg_version(newSVnv(5.011000), FALSE))) >= 0) {
3463 PL_hints |= (HINT_STRICT_REFS | HINT_STRICT_SUBS | HINT_STRICT_VARS);
3464 }
3465 }
3466
3467 RETPUSHYES;
3468 }
3469 name = SvPV_const(sv, len);
3470 if (!(name && len > 0 && *name))
3471 DIE(aTHX_ "Null filename used");
3472 TAINT_PROPER("require");
3473
3474
3475#ifdef VMS
3476 /* The key in the %ENV hash is in the syntax of file passed as the argument
3477 * usually this is in UNIX format, but sometimes in VMS format, which
3478 * can result in a module being pulled in more than once.
3479 * To prevent this, the key must be stored in UNIX format if the VMS
3480 * name can be translated to UNIX.
3481 */
3482 if ((unixname = tounixspec(name, NULL)) != NULL) {
3483 unixlen = strlen(unixname);
3484 vms_unixname = 1;
3485 }
3486 else
3487#endif
3488 {
3489 /* if not VMS or VMS name can not be translated to UNIX, pass it
3490 * through.
3491 */
3492 unixname = (char *) name;
3493 unixlen = len;
3494 }
3495 if (PL_op->op_type == OP_REQUIRE) {
3496 SV * const * const svp = hv_fetch(GvHVn(PL_incgv),
3497 unixname, unixlen, 0);
3498 if ( svp ) {
3499 if (*svp != &PL_sv_undef)
3500 RETPUSHYES;
3501 else
3502 DIE(aTHX_ "Attempt to reload %s aborted.\n"
3503 "Compilation failed in require", unixname);
3504 }
3505 }
3506
3507 /* prepare to compile file */
3508
3509 if (path_is_absolute(name)) {
3510 tryname = name;
3511 tryrsfp = doopen_pm(name, len);
3512 }
3513 if (!tryrsfp) {
3514 AV * const ar = GvAVn(PL_incgv);
3515 I32 i;
3516#ifdef VMS
3517 if (vms_unixname)
3518#endif
3519 {
3520 namesv = newSV_type(SVt_PV);
3521 for (i = 0; i <= AvFILL(ar); i++) {
3522 SV * const dirsv = *av_fetch(ar, i, TRUE);
3523
3524 if (SvTIED_mg((const SV *)ar, PERL_MAGIC_tied))
3525 mg_get(dirsv);
3526 if (SvROK(dirsv)) {
3527 int count;
3528 SV **svp;
3529 SV *loader = dirsv;
3530
3531 if (SvTYPE(SvRV(loader)) == SVt_PVAV
3532 && !sv_isobject(loader))
3533 {
3534 loader = *av_fetch(MUTABLE_AV(SvRV(loader)), 0, TRUE);
3535 }
3536
3537 Perl_sv_setpvf(aTHX_ namesv, "/loader/0x%"UVxf"/%s",
3538 PTR2UV(SvRV(dirsv)), name);
3539 tryname = SvPVX_const(namesv);
3540 tryrsfp = NULL;
3541
3542 ENTER_with_name("call_INC");
3543 SAVETMPS;
3544 EXTEND(SP, 2);
3545
3546 PUSHMARK(SP);
3547 PUSHs(dirsv);
3548 PUSHs(sv);
3549 PUTBACK;
3550 if (sv_isobject(loader))
3551 count = call_method("INC", G_ARRAY);
3552 else
3553 count = call_sv(loader, G_ARRAY);
3554 SPAGAIN;
3555
3556 if (count > 0) {
3557 int i = 0;
3558 SV *arg;
3559
3560 SP -= count - 1;
3561 arg = SP[i++];
3562
3563 if (SvROK(arg) && (SvTYPE(SvRV(arg)) <= SVt_PVLV)
3564 && !isGV_with_GP(SvRV(arg))) {
3565 filter_cache = SvRV(arg);
3566 SvREFCNT_inc_simple_void_NN(filter_cache);
3567
3568 if (i < count) {
3569 arg = SP[i++];
3570 }
3571 }
3572
3573 if (SvROK(arg) && isGV_with_GP(SvRV(arg))) {
3574 arg = SvRV(arg);
3575 }
3576
3577 if (isGV_with_GP(arg)) {
3578 IO * const io = GvIO((const GV *)arg);
3579
3580 ++filter_has_file;
3581
3582 if (io) {
3583 tryrsfp = IoIFP(io);
3584 if (IoOFP(io) && IoOFP(io) != IoIFP(io)) {
3585 PerlIO_close(IoOFP(io));
3586 }
3587 IoIFP(io) = NULL;
3588 IoOFP(io) = NULL;
3589 }
3590
3591 if (i < count) {
3592 arg = SP[i++];
3593 }
3594 }
3595
3596 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVCV) {
3597 filter_sub = arg;
3598 SvREFCNT_inc_simple_void_NN(filter_sub);
3599
3600 if (i < count) {
3601 filter_state = SP[i];
3602 SvREFCNT_inc_simple_void(filter_state);
3603 }
3604 }
3605
3606 if (!tryrsfp && (filter_cache || filter_sub)) {
3607 tryrsfp = PerlIO_open(BIT_BUCKET,
3608 PERL_SCRIPT_MODE);
3609 }
3610 SP--;
3611 }
3612
3613 PUTBACK;
3614 FREETMPS;
3615 LEAVE_with_name("call_INC");
3616
3617 /* Adjust file name if the hook has set an %INC entry.
3618 This needs to happen after the FREETMPS above. */
3619 svp = hv_fetch(GvHVn(PL_incgv), name, len, 0);
3620 if (svp)
3621 tryname = SvPV_nolen_const(*svp);
3622
3623 if (tryrsfp) {
3624 hook_sv = dirsv;
3625 break;
3626 }
3627
3628 filter_has_file = 0;
3629 if (filter_cache) {
3630 SvREFCNT_dec(filter_cache);
3631 filter_cache = NULL;
3632 }
3633 if (filter_state) {
3634 SvREFCNT_dec(filter_state);
3635 filter_state = NULL;
3636 }
3637 if (filter_sub) {
3638 SvREFCNT_dec(filter_sub);
3639 filter_sub = NULL;
3640 }
3641 }
3642 else {
3643 if (!path_is_absolute(name)
3644 ) {
3645 const char *dir;
3646 STRLEN dirlen;
3647
3648 if (SvOK(dirsv)) {
3649 dir = SvPV_const(dirsv, dirlen);
3650 } else {
3651 dir = "";
3652 dirlen = 0;
3653 }
3654
3655#ifdef VMS
3656 char *unixdir;
3657 if ((unixdir = tounixpath(dir, NULL)) == NULL)
3658 continue;
3659 sv_setpv(namesv, unixdir);
3660 sv_catpv(namesv, unixname);
3661#else
3662# ifdef __SYMBIAN32__
3663 if (PL_origfilename[0] &&
3664 PL_origfilename[1] == ':' &&
3665 !(dir[0] && dir[1] == ':'))
3666 Perl_sv_setpvf(aTHX_ namesv,
3667 "%c:%s\\%s",
3668 PL_origfilename[0],
3669 dir, name);
3670 else
3671 Perl_sv_setpvf(aTHX_ namesv,
3672 "%s\\%s",
3673 dir, name);
3674# else
3675 /* The equivalent of
3676 Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name);
3677 but without the need to parse the format string, or
3678 call strlen on either pointer, and with the correct
3679 allocation up front. */
3680 {
3681 char *tmp = SvGROW(namesv, dirlen + len + 2);
3682
3683 memcpy(tmp, dir, dirlen);
3684 tmp +=dirlen;
3685 *tmp++ = '/';
3686 /* name came from an SV, so it will have a '\0' at the
3687 end that we can copy as part of this memcpy(). */
3688 memcpy(tmp, name, len + 1);
3689
3690 SvCUR_set(namesv, dirlen + len + 1);
3691
3692 /* Don't even actually have to turn SvPOK_on() as we
3693 access it directly with SvPVX() below. */
3694 }
3695# endif
3696#endif
3697 TAINT_PROPER("require");
3698 tryname = SvPVX_const(namesv);
3699 tryrsfp = doopen_pm(tryname, SvCUR(namesv));
3700 if (tryrsfp) {
3701 if (tryname[0] == '.' && tryname[1] == '/') {
3702 ++tryname;
3703 while (*++tryname == '/');
3704 }
3705 break;
3706 }
3707 else if (errno == EMFILE)
3708 /* no point in trying other paths if out of handles */
3709 break;
3710 }
3711 }
3712 }
3713 }
3714 }
3715 if (tryrsfp) {
3716 SAVECOPFILE_FREE(&PL_compiling);
3717 CopFILE_set(&PL_compiling, tryname);
3718 }
3719 SvREFCNT_dec(namesv);
3720 if (!tryrsfp) {
3721 if (PL_op->op_type == OP_REQUIRE) {
3722 if(errno == EMFILE) {
3723 /* diag_listed_as: Can't locate %s */
3724 DIE(aTHX_ "Can't locate %s: %s", name, Strerror(errno));
3725 } else {
3726 if (namesv) { /* did we lookup @INC? */
3727 AV * const ar = GvAVn(PL_incgv);
3728 I32 i;
3729 SV *const inc = newSVpvs_flags("", SVs_TEMP);
3730 for (i = 0; i <= AvFILL(ar); i++) {
3731 sv_catpvs(inc, " ");
3732 sv_catsv(inc, *av_fetch(ar, i, TRUE));
3733 }
3734
3735 /* diag_listed_as: Can't locate %s */
3736 DIE(aTHX_
3737 "Can't locate %s in @INC%s%s (@INC contains:%" SVf ")",
3738 name,
3739 (memEQ(name + len - 2, ".h", 3)
3740 ? " (change .h to .ph maybe?) (did you run h2ph?)" : ""),
3741 (memEQ(name + len - 3, ".ph", 4)
3742 ? " (did you run h2ph?)" : ""),
3743 inc
3744 );
3745 }
3746 }
3747 DIE(aTHX_ "Can't locate %s", name);
3748 }
3749
3750 RETPUSHUNDEF;
3751 }
3752 else
3753 SETERRNO(0, SS_NORMAL);
3754
3755 /* Assume success here to prevent recursive requirement. */
3756 /* name is never assigned to again, so len is still strlen(name) */
3757 /* Check whether a hook in @INC has already filled %INC */
3758 if (!hook_sv) {
3759 (void)hv_store(GvHVn(PL_incgv),
3760 unixname, unixlen, newSVpv(CopFILE(&PL_compiling),0),0);
3761 } else {
3762 SV** const svp = hv_fetch(GvHVn(PL_incgv), unixname, unixlen, 0);
3763 if (!svp)
3764 (void)hv_store(GvHVn(PL_incgv),
3765 unixname, unixlen, SvREFCNT_inc_simple(hook_sv), 0 );
3766 }
3767
3768 ENTER_with_name("eval");
3769 SAVETMPS;
3770 lex_start(NULL, tryrsfp, TRUE);
3771
3772 SAVEHINTS();
3773 PL_hints = 0;
3774 hv_clear(GvHV(PL_hintgv));
3775
3776 SAVECOMPILEWARNINGS();
3777 if (PL_dowarn & G_WARN_ALL_ON)
3778 PL_compiling.cop_warnings = pWARN_ALL ;
3779 else if (PL_dowarn & G_WARN_ALL_OFF)
3780 PL_compiling.cop_warnings = pWARN_NONE ;
3781 else
3782 PL_compiling.cop_warnings = pWARN_STD ;
3783
3784 if (filter_sub || filter_cache) {
3785 /* We can use the SvPV of the filter PVIO itself as our cache, rather
3786 than hanging another SV from it. In turn, filter_add() optionally
3787 takes the SV to use as the filter (or creates a new SV if passed
3788 NULL), so simply pass in whatever value filter_cache has. */
3789 SV * const datasv = filter_add(S_run_user_filter, filter_cache);
3790 IoLINES(datasv) = filter_has_file;
3791 IoTOP_GV(datasv) = MUTABLE_GV(filter_state);
3792 IoBOTTOM_GV(datasv) = MUTABLE_GV(filter_sub);
3793 }
3794
3795 /* switch to eval mode */
3796 PUSHBLOCK(cx, CXt_EVAL, SP);
3797 PUSHEVAL(cx, name);
3798 cx->blk_eval.retop = PL_op->op_next;
3799
3800 SAVECOPLINE(&PL_compiling);
3801 CopLINE_set(&PL_compiling, 0);
3802
3803 PUTBACK;
3804
3805 /* Store and reset encoding. */
3806 encoding = PL_encoding;
3807 PL_encoding = NULL;
3808
3809 if (doeval(gimme, NULL, NULL, PL_curcop->cop_seq))
3810 op = DOCATCH(PL_eval_start);
3811 else
3812 op = PL_op->op_next;
3813
3814 /* Restore encoding. */
3815 PL_encoding = encoding;
3816
3817 return op;
3818}
3819
3820/* This is a op added to hold the hints hash for
3821 pp_entereval. The hash can be modified by the code
3822 being eval'ed, so we return a copy instead. */
3823
3824PP(pp_hintseval)
3825{
3826 dVAR;
3827 dSP;
3828 mXPUSHs(MUTABLE_SV(hv_copy_hints_hv(MUTABLE_HV(cSVOP_sv))));
3829 RETURN;
3830}
3831
3832
3833PP(pp_entereval)
3834{
3835 dVAR; dSP;
3836 register PERL_CONTEXT *cx;
3837 SV *sv;
3838 const I32 gimme = GIMME_V;
3839 const U32 was = PL_breakable_sub_gen;
3840 char tbuf[TYPE_DIGITS(long) + 12];
3841 char *tmpbuf = tbuf;
3842 STRLEN len;
3843 CV* runcv;
3844 U32 seq;
3845 HV *saved_hh = NULL;
3846
3847 if (PL_op->op_private & OPpEVAL_HAS_HH) {
3848 saved_hh = MUTABLE_HV(SvREFCNT_inc(POPs));
3849 }
3850 sv = POPs;
3851 if (!SvPOK(sv)) {
3852 /* make sure we've got a plain PV (no overload etc) before testing
3853 * for taint. Making a copy here is probably overkill, but better
3854 * safe than sorry */
3855 STRLEN len;
3856 const char * const p = SvPV_const(sv, len);
3857
3858 sv = newSVpvn_flags(p, len, SVs_TEMP | SvUTF8(sv));
3859 }
3860
3861 TAINT_IF(SvTAINTED(sv));
3862 TAINT_PROPER("eval");
3863
3864 ENTER_with_name("eval");
3865 lex_start(sv, NULL, FALSE);
3866 SAVETMPS;
3867
3868 /* switch to eval mode */
3869
3870 if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) {
3871 SV * const temp_sv = sv_newmortal();
3872 Perl_sv_setpvf(aTHX_ temp_sv, "_<(eval %lu)[%s:%"IVdf"]",
3873 (unsigned long)++PL_evalseq,
3874 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
3875 tmpbuf = SvPVX(temp_sv);
3876 len = SvCUR(temp_sv);
3877 }
3878 else
3879 len = my_snprintf(tmpbuf, sizeof(tbuf), "_<(eval %lu)", (unsigned long)++PL_evalseq);
3880 SAVECOPFILE_FREE(&PL_compiling);
3881 CopFILE_set(&PL_compiling, tmpbuf+2);
3882 SAVECOPLINE(&PL_compiling);
3883 CopLINE_set(&PL_compiling, 1);
3884 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
3885 deleting the eval's FILEGV from the stash before gv_check() runs
3886 (i.e. before run-time proper). To work around the coredump that
3887 ensues, we always turn GvMULTI_on for any globals that were
3888 introduced within evals. See force_ident(). GSAR 96-10-12 */
3889 SAVEHINTS();
3890 PL_hints = PL_op->op_targ;
3891 if (saved_hh) {
3892 /* SAVEHINTS created a new HV in PL_hintgv, which we need to GC */
3893 SvREFCNT_dec(GvHV(PL_hintgv));
3894 GvHV(PL_hintgv) = saved_hh;
3895 }
3896 SAVECOMPILEWARNINGS();
3897 PL_compiling.cop_warnings = DUP_WARNINGS(PL_curcop->cop_warnings);
3898 if (PL_compiling.cop_hints_hash) {
3899 Perl_refcounted_he_free(aTHX_ PL_compiling.cop_hints_hash);
3900 }
3901 if (Perl_fetch_cop_label(aTHX_ PL_curcop, NULL, NULL)) {
3902 /* The label, if present, is the first entry on the chain. So rather
3903 than writing a blank label in front of it (which involves an
3904 allocation), just use the next entry in the chain. */
3905 PL_compiling.cop_hints_hash
3906 = PL_curcop->cop_hints_hash->refcounted_he_next;
3907 /* Check the assumption that this removed the label. */
3908 assert(Perl_fetch_cop_label(aTHX_ &PL_compiling, NULL, NULL) == NULL);
3909 }
3910 else
3911 PL_compiling.cop_hints_hash = PL_curcop->cop_hints_hash;
3912 if (PL_compiling.cop_hints_hash) {
3913 HINTS_REFCNT_LOCK;
3914 PL_compiling.cop_hints_hash->refcounted_he_refcnt++;
3915 HINTS_REFCNT_UNLOCK;
3916 }
3917 /* special case: an eval '' executed within the DB package gets lexically
3918 * placed in the first non-DB CV rather than the current CV - this
3919 * allows the debugger to execute code, find lexicals etc, in the
3920 * scope of the code being debugged. Passing &seq gets find_runcv
3921 * to do the dirty work for us */
3922 runcv = find_runcv(&seq);
3923
3924 PUSHBLOCK(cx, (CXt_EVAL|CXp_REAL), SP);
3925 PUSHEVAL(cx, 0);
3926 cx->blk_eval.retop = PL_op->op_next;
3927
3928 /* prepare to compile string */
3929
3930 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
3931 save_lines(CopFILEAV(&PL_compiling), PL_parser->linestr);
3932 PUTBACK;
3933
3934 if (doeval(gimme, NULL, runcv, seq)) {
3935 if (was != PL_breakable_sub_gen /* Some subs defined here. */
3936 ? (PERLDB_LINE || PERLDB_SAVESRC)
3937 : PERLDB_SAVESRC_NOSUBS) {
3938 /* Retain the filegv we created. */
3939 } else {
3940 char *const safestr = savepvn(tmpbuf, len);
3941 SAVEDELETE(PL_defstash, safestr, len);
3942 }
3943 return DOCATCH(PL_eval_start);
3944 } else {
3945 /* We have already left the scope set up earler thanks to the LEAVE
3946 in doeval(). */
3947 if (was != PL_breakable_sub_gen /* Some subs defined here. */
3948 ? (PERLDB_LINE || PERLDB_SAVESRC)
3949 : PERLDB_SAVESRC_INVALID) {
3950 /* Retain the filegv we created. */
3951 } else {
3952 (void)hv_delete(PL_defstash, tmpbuf, len, G_DISCARD);
3953 }
3954 return PL_op->op_next;
3955 }
3956}
3957
3958PP(pp_leaveeval)
3959{
3960 dVAR; dSP;
3961 register SV **mark;
3962 SV **newsp;
3963 PMOP *newpm;
3964 I32 gimme;
3965 register PERL_CONTEXT *cx;
3966 OP *retop;
3967 const U8 save_flags = PL_op -> op_flags;
3968 I32 optype;
3969 SV *namesv;
3970
3971 POPBLOCK(cx,newpm);
3972 POPEVAL(cx);
3973 namesv = cx->blk_eval.old_namesv;
3974 retop = cx->blk_eval.retop;
3975
3976 TAINT_NOT;
3977 if (gimme == G_VOID)
3978 MARK = newsp;
3979 else if (gimme == G_SCALAR) {
3980 MARK = newsp + 1;
3981 if (MARK <= SP) {
3982 if (SvFLAGS(TOPs) & SVs_TEMP)
3983 *MARK = TOPs;
3984 else
3985 *MARK = sv_mortalcopy(TOPs);
3986 }
3987 else {
3988 MEXTEND(mark,0);
3989 *MARK = &PL_sv_undef;
3990 }
3991 SP = MARK;
3992 }
3993 else {
3994 /* in case LEAVE wipes old return values */
3995 for (mark = newsp + 1; mark <= SP; mark++) {
3996 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
3997 *mark = sv_mortalcopy(*mark);
3998 TAINT_NOT; /* Each item is independent */
3999 }
4000 }
4001 }
4002 PL_curpm = newpm; /* Don't pop $1 et al till now */
4003
4004#ifdef DEBUGGING
4005 assert(CvDEPTH(PL_compcv) == 1);
4006#endif
4007 CvDEPTH(PL_compcv) = 0;
4008 lex_end();
4009
4010 if (optype == OP_REQUIRE &&
4011 !(gimme == G_SCALAR ? SvTRUE(*SP) : SP > newsp))
4012 {
4013 /* Unassume the success we assumed earlier. */
4014 (void)hv_delete(GvHVn(PL_incgv),
4015 SvPVX_const(namesv), SvCUR(namesv),
4016 G_DISCARD);
4017 retop = Perl_die(aTHX_ "%"SVf" did not return a true value",
4018 SVfARG(namesv));
4019 /* die_unwind() did LEAVE, or we won't be here */
4020 }
4021 else {
4022 LEAVE_with_name("eval");
4023 if (!(save_flags & OPf_SPECIAL)) {
4024 CLEAR_ERRSV();
4025 }
4026 }
4027
4028 RETURNOP(retop);
4029}
4030
4031/* Common code for Perl_call_sv and Perl_fold_constants, put here to keep it
4032 close to the related Perl_create_eval_scope. */
4033void
4034Perl_delete_eval_scope(pTHX)
4035{
4036 SV **newsp;
4037 PMOP *newpm;
4038 I32 gimme;
4039 register PERL_CONTEXT *cx;
4040 I32 optype;
4041
4042 POPBLOCK(cx,newpm);
4043 POPEVAL(cx);
4044 PL_curpm = newpm;
4045 LEAVE_with_name("eval_scope");
4046 PERL_UNUSED_VAR(newsp);
4047 PERL_UNUSED_VAR(gimme);
4048 PERL_UNUSED_VAR(optype);
4049}
4050
4051/* Common-ish code salvaged from Perl_call_sv and pp_entertry, because it was
4052 also needed by Perl_fold_constants. */
4053PERL_CONTEXT *
4054Perl_create_eval_scope(pTHX_ U32 flags)
4055{
4056 PERL_CONTEXT *cx;
4057 const I32 gimme = GIMME_V;
4058
4059 ENTER_with_name("eval_scope");
4060 SAVETMPS;
4061
4062 PUSHBLOCK(cx, (CXt_EVAL|CXp_TRYBLOCK), PL_stack_sp);
4063 PUSHEVAL(cx, 0);
4064
4065 PL_in_eval = EVAL_INEVAL;
4066 if (flags & G_KEEPERR)
4067 PL_in_eval |= EVAL_KEEPERR;
4068 else
4069 CLEAR_ERRSV();
4070 if (flags & G_FAKINGEVAL) {
4071 PL_eval_root = PL_op; /* Only needed so that goto works right. */
4072 }
4073 return cx;
4074}
4075
4076PP(pp_entertry)
4077{
4078 dVAR;
4079 PERL_CONTEXT * const cx = create_eval_scope(0);
4080 cx->blk_eval.retop = cLOGOP->op_other->op_next;
4081 return DOCATCH(PL_op->op_next);
4082}
4083
4084PP(pp_leavetry)
4085{
4086 dVAR; dSP;
4087 SV **newsp;
4088 PMOP *newpm;
4089 I32 gimme;
4090 register PERL_CONTEXT *cx;
4091 I32 optype;
4092
4093 POPBLOCK(cx,newpm);
4094 POPEVAL(cx);
4095 PERL_UNUSED_VAR(optype);
4096
4097 TAINT_NOT;
4098 if (gimme == G_VOID)
4099 SP = newsp;
4100 else if (gimme == G_SCALAR) {
4101 register SV **mark;
4102 MARK = newsp + 1;
4103 if (MARK <= SP) {
4104 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
4105 *MARK = TOPs;
4106 else
4107 *MARK = sv_mortalcopy(TOPs);
4108 }
4109 else {
4110 MEXTEND(mark,0);
4111 *MARK = &PL_sv_undef;
4112 }
4113 SP = MARK;
4114 }
4115 else {
4116 /* in case LEAVE wipes old return values */
4117 register SV **mark;
4118 for (mark = newsp + 1; mark <= SP; mark++) {
4119 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
4120 *mark = sv_mortalcopy(*mark);
4121 TAINT_NOT; /* Each item is independent */
4122 }
4123 }
4124 }
4125 PL_curpm = newpm; /* Don't pop $1 et al till now */
4126
4127 LEAVE_with_name("eval_scope");
4128 CLEAR_ERRSV();
4129 RETURN;
4130}
4131
4132PP(pp_entergiven)
4133{
4134 dVAR; dSP;
4135 register PERL_CONTEXT *cx;
4136 const I32 gimme = GIMME_V;
4137
4138 ENTER_with_name("given");
4139 SAVETMPS;
4140
4141 sv_setsv(PAD_SV(PL_op->op_targ), POPs);
4142
4143 PUSHBLOCK(cx, CXt_GIVEN, SP);
4144 PUSHGIVEN(cx);
4145
4146 RETURN;
4147}
4148
4149PP(pp_leavegiven)
4150{
4151 dVAR; dSP;
4152 register PERL_CONTEXT *cx;
4153 I32 gimme;
4154 SV **newsp;
4155 PMOP *newpm;
4156 PERL_UNUSED_CONTEXT;
4157
4158 POPBLOCK(cx,newpm);
4159 assert(CxTYPE(cx) == CXt_GIVEN);
4160
4161 TAINT_NOT;
4162 if (gimme == G_VOID)
4163 SP = newsp;
4164 else if (gimme == G_SCALAR) {
4165 register SV **mark;
4166 MARK = newsp + 1;
4167 if (MARK <= SP) {
4168 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
4169 *MARK = TOPs;
4170 else
4171 *MARK = sv_mortalcopy(TOPs);
4172 }
4173 else {
4174 MEXTEND(mark,0);
4175 *MARK = &PL_sv_undef;
4176 }
4177 SP = MARK;
4178 }
4179 else {
4180 /* in case LEAVE wipes old return values */
4181 register SV **mark;
4182 for (mark = newsp + 1; mark <= SP; mark++) {
4183 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
4184 *mark = sv_mortalcopy(*mark);
4185 TAINT_NOT; /* Each item is independent */
4186 }
4187 }
4188 }
4189 PL_curpm = newpm; /* Don't pop $1 et al till now */
4190
4191 LEAVE_with_name("given");
4192 RETURN;
4193}
4194
4195/* Helper routines used by pp_smartmatch */
4196STATIC PMOP *
4197S_make_matcher(pTHX_ REGEXP *re)
4198{
4199 dVAR;
4200 PMOP *matcher = (PMOP *) newPMOP(OP_MATCH, OPf_WANT_SCALAR | OPf_STACKED);
4201
4202 PERL_ARGS_ASSERT_MAKE_MATCHER;
4203
4204 PM_SETRE(matcher, ReREFCNT_inc(re));
4205
4206 SAVEFREEOP((OP *) matcher);
4207 ENTER_with_name("matcher"); SAVETMPS;
4208 SAVEOP();
4209 return matcher;
4210}
4211
4212STATIC bool
4213S_matcher_matches_sv(pTHX_ PMOP *matcher, SV *sv)
4214{
4215 dVAR;
4216 dSP;
4217
4218 PERL_ARGS_ASSERT_MATCHER_MATCHES_SV;
4219
4220 PL_op = (OP *) matcher;
4221 XPUSHs(sv);
4222 PUTBACK;
4223 (void) pp_match();
4224 SPAGAIN;
4225 return (SvTRUEx(POPs));
4226}
4227
4228STATIC void
4229S_destroy_matcher(pTHX_ PMOP *matcher)
4230{
4231 dVAR;
4232
4233 PERL_ARGS_ASSERT_DESTROY_MATCHER;
4234 PERL_UNUSED_ARG(matcher);
4235
4236 FREETMPS;
4237 LEAVE_with_name("matcher");
4238}
4239
4240/* Do a smart match */
4241PP(pp_smartmatch)
4242{
4243 DEBUG_M(Perl_deb(aTHX_ "Starting smart match resolution\n"));
4244 return do_smartmatch(NULL, NULL);
4245}
4246
4247/* This version of do_smartmatch() implements the
4248 * table of smart matches that is found in perlsyn.
4249 */
4250STATIC OP *
4251S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other)
4252{
4253 dVAR;
4254 dSP;
4255
4256 bool object_on_left = FALSE;
4257 SV *e = TOPs; /* e is for 'expression' */
4258 SV *d = TOPm1s; /* d is for 'default', as in PL_defgv */
4259
4260 /* Take care only to invoke mg_get() once for each argument.
4261 * Currently we do this by copying the SV if it's magical. */
4262 if (d) {
4263 if (SvGMAGICAL(d))
4264 d = sv_mortalcopy(d);
4265 }
4266 else
4267 d = &PL_sv_undef;
4268
4269 assert(e);
4270 if (SvGMAGICAL(e))
4271 e = sv_mortalcopy(e);
4272
4273 /* First of all, handle overload magic of the rightmost argument */
4274 if (SvAMAGIC(e)) {
4275 SV * tmpsv;
4276 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Object\n"));
4277 DEBUG_M(Perl_deb(aTHX_ " attempting overload\n"));
4278
4279 tmpsv = amagic_call(d, e, smart_amg, 0);
4280 if (tmpsv) {
4281 SPAGAIN;
4282 (void)POPs;
4283 SETs(tmpsv);
4284 RETURN;
4285 }
4286 DEBUG_M(Perl_deb(aTHX_ " failed to run overload method; continuing...\n"));
4287 }
4288
4289 SP -= 2; /* Pop the values */
4290
4291
4292 /* ~~ undef */
4293 if (!SvOK(e)) {
4294 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-undef\n"));
4295 if (SvOK(d))
4296 RETPUSHNO;
4297 else
4298 RETPUSHYES;
4299 }
4300
4301 if (sv_isobject(e) && (SvTYPE(SvRV(e)) != SVt_REGEXP)) {
4302 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Object\n"));
4303 Perl_croak(aTHX_ "Smart matching a non-overloaded object breaks encapsulation");
4304 }
4305 if (sv_isobject(d) && (SvTYPE(SvRV(d)) != SVt_REGEXP))
4306 object_on_left = TRUE;
4307
4308 /* ~~ sub */
4309 if (SvROK(e) && SvTYPE(SvRV(e)) == SVt_PVCV) {
4310 I32 c;
4311 if (object_on_left) {
4312 goto sm_any_sub; /* Treat objects like scalars */
4313 }
4314 else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVHV) {
4315 /* Test sub truth for each key */
4316 HE *he;
4317 bool andedresults = TRUE;
4318 HV *hv = (HV*) SvRV(d);
4319 I32 numkeys = hv_iterinit(hv);
4320 DEBUG_M(Perl_deb(aTHX_ " applying rule Hash-CodeRef\n"));
4321 if (numkeys == 0)
4322 RETPUSHYES;
4323 while ( (he = hv_iternext(hv)) ) {
4324 DEBUG_M(Perl_deb(aTHX_ " testing hash key...\n"));
4325 ENTER_with_name("smartmatch_hash_key_test");
4326 SAVETMPS;
4327 PUSHMARK(SP);
4328 PUSHs(hv_iterkeysv(he));
4329 PUTBACK;
4330 c = call_sv(e, G_SCALAR);
4331 SPAGAIN;
4332 if (c == 0)
4333 andedresults = FALSE;
4334 else
4335 andedresults = SvTRUEx(POPs) && andedresults;
4336 FREETMPS;
4337 LEAVE_with_name("smartmatch_hash_key_test");
4338 }
4339 if (andedresults)
4340 RETPUSHYES;
4341 else
4342 RETPUSHNO;
4343 }
4344 else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVAV) {
4345 /* Test sub truth for each element */
4346 I32 i;
4347 bool andedresults = TRUE;
4348 AV *av = (AV*) SvRV(d);
4349 const I32 len = av_len(av);
4350 DEBUG_M(Perl_deb(aTHX_ " applying rule Array-CodeRef\n"));
4351 if (len == -1)
4352 RETPUSHYES;
4353 for (i = 0; i <= len; ++i) {
4354 SV * const * const svp = av_fetch(av, i, FALSE);
4355 DEBUG_M(Perl_deb(aTHX_ " testing array element...\n"));
4356 ENTER_with_name("smartmatch_array_elem_test");
4357 SAVETMPS;
4358 PUSHMARK(SP);
4359 if (svp)
4360 PUSHs(*svp);
4361 PUTBACK;
4362 c = call_sv(e, G_SCALAR);
4363 SPAGAIN;
4364 if (c == 0)
4365 andedresults = FALSE;
4366 else
4367 andedresults = SvTRUEx(POPs) && andedresults;
4368 FREETMPS;
4369 LEAVE_with_name("smartmatch_array_elem_test");
4370 }
4371 if (andedresults)
4372 RETPUSHYES;
4373 else
4374 RETPUSHNO;
4375 }
4376 else {
4377 sm_any_sub:
4378 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-CodeRef\n"));
4379 ENTER_with_name("smartmatch_coderef");
4380 SAVETMPS;
4381 PUSHMARK(SP);
4382 PUSHs(d);
4383 PUTBACK;
4384 c = call_sv(e, G_SCALAR);
4385 SPAGAIN;
4386 if (c == 0)
4387 PUSHs(&PL_sv_no);
4388 else if (SvTEMP(TOPs))
4389 SvREFCNT_inc_void(TOPs);
4390 FREETMPS;
4391 LEAVE_with_name("smartmatch_coderef");
4392 RETURN;
4393 }
4394 }
4395 /* ~~ %hash */
4396 else if (SvROK(e) && SvTYPE(SvRV(e)) == SVt_PVHV) {
4397 if (object_on_left) {
4398 goto sm_any_hash; /* Treat objects like scalars */
4399 }
4400 else if (!SvOK(d)) {
4401 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Hash ($a undef)\n"));
4402 RETPUSHNO;
4403 }
4404 else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVHV) {
4405 /* Check that the key-sets are identical */
4406 HE *he;
4407 HV *other_hv = MUTABLE_HV(SvRV(d));
4408 bool tied = FALSE;
4409 bool other_tied = FALSE;
4410 U32 this_key_count = 0,
4411 other_key_count = 0;
4412 HV *hv = MUTABLE_HV(SvRV(e));
4413
4414 DEBUG_M(Perl_deb(aTHX_ " applying rule Hash-Hash\n"));
4415 /* Tied hashes don't know how many keys they have. */
4416 if (SvTIED_mg((SV*)hv, PERL_MAGIC_tied)) {
4417 tied = TRUE;
4418 }
4419 else if (SvTIED_mg((const SV *)other_hv, PERL_MAGIC_tied)) {
4420 HV * const temp = other_hv;
4421 other_hv = hv;
4422 hv = temp;
4423 tied = TRUE;
4424 }
4425 if (SvTIED_mg((const SV *)other_hv, PERL_MAGIC_tied))
4426 other_tied = TRUE;
4427
4428 if (!tied && HvUSEDKEYS((const HV *) hv) != HvUSEDKEYS(other_hv))
4429 RETPUSHNO;
4430
4431 /* The hashes have the same number of keys, so it suffices
4432 to check that one is a subset of the other. */
4433 (void) hv_iterinit(hv);
4434 while ( (he = hv_iternext(hv)) ) {
4435 SV *key = hv_iterkeysv(he);
4436
4437 DEBUG_M(Perl_deb(aTHX_ " comparing hash key...\n"));
4438 ++ this_key_count;
4439
4440 if(!hv_exists_ent(other_hv, key, 0)) {
4441 (void) hv_iterinit(hv); /* reset iterator */
4442 RETPUSHNO;
4443 }
4444 }
4445
4446 if (other_tied) {
4447 (void) hv_iterinit(other_hv);
4448 while ( hv_iternext(other_hv) )
4449 ++other_key_count;
4450 }
4451 else
4452 other_key_count = HvUSEDKEYS(other_hv);
4453
4454 if (this_key_count != other_key_count)
4455 RETPUSHNO;
4456 else
4457 RETPUSHYES;
4458 }
4459 else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVAV) {
4460 AV * const other_av = MUTABLE_AV(SvRV(d));
4461 const I32 other_len = av_len(other_av) + 1;
4462 I32 i;
4463 HV *hv = MUTABLE_HV(SvRV(e));
4464
4465 DEBUG_M(Perl_deb(aTHX_ " applying rule Array-Hash\n"));
4466 for (i = 0; i < other_len; ++i) {
4467 SV ** const svp = av_fetch(other_av, i, FALSE);
4468 DEBUG_M(Perl_deb(aTHX_ " checking for key existence...\n"));
4469 if (svp) { /* ??? When can this not happen? */
4470 if (hv_exists_ent(hv, *svp, 0))
4471 RETPUSHYES;
4472 }
4473 }
4474 RETPUSHNO;
4475 }
4476 else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_REGEXP) {
4477 DEBUG_M(Perl_deb(aTHX_ " applying rule Regex-Hash\n"));
4478 sm_regex_hash:
4479 {
4480 PMOP * const matcher = make_matcher((REGEXP*) SvRV(d));
4481 HE *he;
4482 HV *hv = MUTABLE_HV(SvRV(e));
4483
4484 (void) hv_iterinit(hv);
4485 while ( (he = hv_iternext(hv)) ) {
4486 DEBUG_M(Perl_deb(aTHX_ " testing key against pattern...\n"));
4487 if (matcher_matches_sv(matcher, hv_iterkeysv(he))) {
4488 (void) hv_iterinit(hv);
4489 destroy_matcher(matcher);
4490 RETPUSHYES;
4491 }
4492 }
4493 destroy_matcher(matcher);
4494 RETPUSHNO;
4495 }
4496 }
4497 else {
4498 sm_any_hash:
4499 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Hash\n"));
4500 if (hv_exists_ent(MUTABLE_HV(SvRV(e)), d, 0))
4501 RETPUSHYES;
4502 else
4503 RETPUSHNO;
4504 }
4505 }
4506 /* ~~ @array */
4507 else if (SvROK(e) && SvTYPE(SvRV(e)) == SVt_PVAV) {
4508 if (object_on_left) {
4509 goto sm_any_array; /* Treat objects like scalars */
4510 }
4511 else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVHV) {
4512 AV * const other_av = MUTABLE_AV(SvRV(e));
4513 const I32 other_len = av_len(other_av) + 1;
4514 I32 i;
4515
4516 DEBUG_M(Perl_deb(aTHX_ " applying rule Hash-Array\n"));
4517 for (i = 0; i < other_len; ++i) {
4518 SV ** const svp = av_fetch(other_av, i, FALSE);
4519
4520 DEBUG_M(Perl_deb(aTHX_ " testing for key existence...\n"));
4521 if (svp) { /* ??? When can this not happen? */
4522 if (hv_exists_ent(MUTABLE_HV(SvRV(d)), *svp, 0))
4523 RETPUSHYES;
4524 }
4525 }
4526 RETPUSHNO;
4527 }
4528 if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVAV) {
4529 AV *other_av = MUTABLE_AV(SvRV(d));
4530 DEBUG_M(Perl_deb(aTHX_ " applying rule Array-Array\n"));
4531 if (av_len(MUTABLE_AV(SvRV(e))) != av_len(other_av))
4532 RETPUSHNO;
4533 else {
4534 I32 i;
4535 const I32 other_len = av_len(other_av);
4536
4537 if (NULL == seen_this) {
4538 seen_this = newHV();
4539 (void) sv_2mortal(MUTABLE_SV(seen_this));
4540 }
4541 if (NULL == seen_other) {
4542 seen_other = newHV();
4543 (void) sv_2mortal(MUTABLE_SV(seen_other));
4544 }
4545 for(i = 0; i <= other_len; ++i) {
4546 SV * const * const this_elem = av_fetch(MUTABLE_AV(SvRV(e)), i, FALSE);
4547 SV * const * const other_elem = av_fetch(other_av, i, FALSE);
4548
4549 if (!this_elem || !other_elem) {
4550 if ((this_elem && SvOK(*this_elem))
4551 || (other_elem && SvOK(*other_elem)))
4552 RETPUSHNO;
4553 }
4554 else if (hv_exists_ent(seen_this,
4555 sv_2mortal(newSViv(PTR2IV(*this_elem))), 0) ||
4556 hv_exists_ent(seen_other,
4557 sv_2mortal(newSViv(PTR2IV(*other_elem))), 0))
4558 {
4559 if (*this_elem != *other_elem)
4560 RETPUSHNO;
4561 }
4562 else {
4563 (void)hv_store_ent(seen_this,
4564 sv_2mortal(newSViv(PTR2IV(*this_elem))),
4565 &PL_sv_undef, 0);
4566 (void)hv_store_ent(seen_other,
4567 sv_2mortal(newSViv(PTR2IV(*other_elem))),
4568 &PL_sv_undef, 0);
4569 PUSHs(*other_elem);
4570 PUSHs(*this_elem);
4571
4572 PUTBACK;
4573 DEBUG_M(Perl_deb(aTHX_ " recursively comparing array element...\n"));
4574 (void) do_smartmatch(seen_this, seen_other);
4575 SPAGAIN;
4576 DEBUG_M(Perl_deb(aTHX_ " recursion finished\n"));
4577
4578 if (!SvTRUEx(POPs))
4579 RETPUSHNO;
4580 }
4581 }
4582 RETPUSHYES;
4583 }
4584 }
4585 else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_REGEXP) {
4586 DEBUG_M(Perl_deb(aTHX_ " applying rule Regex-Array\n"));
4587 sm_regex_array:
4588 {
4589 PMOP * const matcher = make_matcher((REGEXP*) SvRV(d));
4590 const I32 this_len = av_len(MUTABLE_AV(SvRV(e)));
4591 I32 i;
4592
4593 for(i = 0; i <= this_len; ++i) {
4594 SV * const * const svp = av_fetch(MUTABLE_AV(SvRV(e)), i, FALSE);
4595 DEBUG_M(Perl_deb(aTHX_ " testing element against pattern...\n"));
4596 if (svp && matcher_matches_sv(matcher, *svp)) {
4597 destroy_matcher(matcher);
4598 RETPUSHYES;
4599 }
4600 }
4601 destroy_matcher(matcher);
4602 RETPUSHNO;
4603 }
4604 }
4605 else if (!SvOK(d)) {
4606 /* undef ~~ array */
4607 const I32 this_len = av_len(MUTABLE_AV(SvRV(e)));
4608 I32 i;
4609
4610 DEBUG_M(Perl_deb(aTHX_ " applying rule Undef-Array\n"));
4611 for (i = 0; i <= this_len; ++i) {
4612 SV * const * const svp = av_fetch(MUTABLE_AV(SvRV(e)), i, FALSE);
4613 DEBUG_M(Perl_deb(aTHX_ " testing for undef element...\n"));
4614 if (!svp || !SvOK(*svp))
4615 RETPUSHYES;
4616 }
4617 RETPUSHNO;
4618 }
4619 else {
4620 sm_any_array:
4621 {
4622 I32 i;
4623 const I32 this_len = av_len(MUTABLE_AV(SvRV(e)));
4624
4625 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Array\n"));
4626 for (i = 0; i <= this_len; ++i) {
4627 SV * const * const svp = av_fetch(MUTABLE_AV(SvRV(e)), i, FALSE);
4628 if (!svp)
4629 continue;
4630
4631 PUSHs(d);
4632 PUSHs(*svp);
4633 PUTBACK;
4634 /* infinite recursion isn't supposed to happen here */
4635 DEBUG_M(Perl_deb(aTHX_ " recursively testing array element...\n"));
4636 (void) do_smartmatch(NULL, NULL);
4637 SPAGAIN;
4638 DEBUG_M(Perl_deb(aTHX_ " recursion finished\n"));
4639 if (SvTRUEx(POPs))
4640 RETPUSHYES;
4641 }
4642 RETPUSHNO;
4643 }
4644 }
4645 }
4646 /* ~~ qr// */
4647 else if (SvROK(e) && SvTYPE(SvRV(e)) == SVt_REGEXP) {
4648 if (!object_on_left && SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVHV) {
4649 SV *t = d; d = e; e = t;
4650 DEBUG_M(Perl_deb(aTHX_ " applying rule Hash-Regex\n"));
4651 goto sm_regex_hash;
4652 }
4653 else if (!object_on_left && SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVAV) {
4654 SV *t = d; d = e; e = t;
4655 DEBUG_M(Perl_deb(aTHX_ " applying rule Array-Regex\n"));
4656 goto sm_regex_array;
4657 }
4658 else {
4659 PMOP * const matcher = make_matcher((REGEXP*) SvRV(e));
4660
4661 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Regex\n"));
4662 PUTBACK;
4663 PUSHs(matcher_matches_sv(matcher, d)
4664 ? &PL_sv_yes
4665 : &PL_sv_no);
4666 destroy_matcher(matcher);
4667 RETURN;
4668 }
4669 }
4670 /* ~~ scalar */
4671 /* See if there is overload magic on left */
4672 else if (object_on_left && SvAMAGIC(d)) {
4673 SV *tmpsv;
4674 DEBUG_M(Perl_deb(aTHX_ " applying rule Object-Any\n"));
4675 DEBUG_M(Perl_deb(aTHX_ " attempting overload\n"));
4676 PUSHs(d); PUSHs(e);
4677 PUTBACK;
4678 tmpsv = amagic_call(d, e, smart_amg, AMGf_noright);
4679 if (tmpsv) {
4680 SPAGAIN;
4681 (void)POPs;
4682 SETs(tmpsv);
4683 RETURN;
4684 }
4685 SP -= 2;
4686 DEBUG_M(Perl_deb(aTHX_ " failed to run overload method; falling back...\n"));
4687 goto sm_any_scalar;
4688 }
4689 else if (!SvOK(d)) {
4690 /* undef ~~ scalar ; we already know that the scalar is SvOK */
4691 DEBUG_M(Perl_deb(aTHX_ " applying rule undef-Any\n"));
4692 RETPUSHNO;
4693 }
4694 else
4695 sm_any_scalar:
4696 if (SvNIOK(e) || (SvPOK(e) && looks_like_number(e) && SvNIOK(d))) {
4697 DEBUG_M(if (SvNIOK(e))
4698 Perl_deb(aTHX_ " applying rule Any-Num\n");
4699 else
4700 Perl_deb(aTHX_ " applying rule Num-numish\n");
4701 );
4702 /* numeric comparison */
4703 PUSHs(d); PUSHs(e);
4704 PUTBACK;
4705 if (CopHINTS_get(PL_curcop) & HINT_INTEGER)
4706 (void) pp_i_eq();
4707 else
4708 (void) pp_eq();
4709 SPAGAIN;
4710 if (SvTRUEx(POPs))
4711 RETPUSHYES;
4712 else
4713 RETPUSHNO;
4714 }
4715
4716 /* As a last resort, use string comparison */
4717 DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Any\n"));
4718 PUSHs(d); PUSHs(e);
4719 PUTBACK;
4720 return pp_seq();
4721}
4722
4723PP(pp_enterwhen)
4724{
4725 dVAR; dSP;
4726 register PERL_CONTEXT *cx;
4727 const I32 gimme = GIMME_V;
4728
4729 /* This is essentially an optimization: if the match
4730 fails, we don't want to push a context and then
4731 pop it again right away, so we skip straight
4732 to the op that follows the leavewhen.
4733 RETURNOP calls PUTBACK which restores the stack pointer after the POPs.
4734 */
4735 if ((0 == (PL_op->op_flags & OPf_SPECIAL)) && !SvTRUEx(POPs))
4736 RETURNOP(cLOGOP->op_other->op_next);
4737
4738 ENTER_with_name("eval");
4739 SAVETMPS;
4740
4741 PUSHBLOCK(cx, CXt_WHEN, SP);
4742 PUSHWHEN(cx);
4743
4744 RETURN;
4745}
4746
4747PP(pp_leavewhen)
4748{
4749 dVAR; dSP;
4750 register PERL_CONTEXT *cx;
4751 I32 gimme;
4752 SV **newsp;
4753 PMOP *newpm;
4754
4755 POPBLOCK(cx,newpm);
4756 assert(CxTYPE(cx) == CXt_WHEN);
4757
4758 SP = newsp;
4759 PUTBACK;
4760
4761 PL_curpm = newpm; /* pop $1 et al */
4762
4763 LEAVE_with_name("eval");
4764 return NORMAL;
4765}
4766
4767PP(pp_continue)
4768{
4769 dVAR;
4770 I32 cxix;
4771 register PERL_CONTEXT *cx;
4772 I32 inner;
4773
4774 cxix = dopoptowhen(cxstack_ix);
4775 if (cxix < 0)
4776 DIE(aTHX_ "Can't \"continue\" outside a when block");
4777 if (cxix < cxstack_ix)
4778 dounwind(cxix);
4779
4780 /* clear off anything above the scope we're re-entering */
4781 inner = PL_scopestack_ix;
4782 TOPBLOCK(cx);
4783 if (PL_scopestack_ix < inner)
4784 leave_scope(PL_scopestack[PL_scopestack_ix]);
4785 PL_curcop = cx->blk_oldcop;
4786 return cx->blk_givwhen.leave_op;
4787}
4788
4789PP(pp_break)
4790{
4791 dVAR;
4792 I32 cxix;
4793 register PERL_CONTEXT *cx;
4794 I32 inner;
4795 dSP;
4796
4797 cxix = dopoptogiven(cxstack_ix);
4798 if (cxix < 0) {
4799 if (PL_op->op_flags & OPf_SPECIAL)
4800 DIE(aTHX_ "Can't use when() outside a topicalizer");
4801 else
4802 DIE(aTHX_ "Can't \"break\" outside a given block");
4803 }
4804 if (CxFOREACH(&cxstack[cxix]) && (0 == (PL_op->op_flags & OPf_SPECIAL)))
4805 DIE(aTHX_ "Can't \"break\" in a loop topicalizer");
4806
4807 if (cxix < cxstack_ix)
4808 dounwind(cxix);
4809
4810 /* clear off anything above the scope we're re-entering */
4811 inner = PL_scopestack_ix;
4812 TOPBLOCK(cx);
4813 if (PL_scopestack_ix < inner)
4814 leave_scope(PL_scopestack[PL_scopestack_ix]);
4815 PL_curcop = cx->blk_oldcop;
4816
4817 if (CxFOREACH(cx))
4818 return (cx)->blk_loop.my_op->op_nextop;
4819 else
4820 /* RETURNOP calls PUTBACK which restores the old old sp */
4821 RETURNOP(cx->blk_givwhen.leave_op);
4822}
4823
4824STATIC OP *
4825S_doparseform(pTHX_ SV *sv)
4826{
4827 STRLEN len;
4828 register char *s = SvPV_force(sv, len);
4829 register char * const send = s + len;
4830 register char *base = NULL;
4831 register I32 skipspaces = 0;
4832 bool noblank = FALSE;
4833 bool repeat = FALSE;
4834 bool postspace = FALSE;
4835 U32 *fops;
4836 register U32 *fpc;
4837 U32 *linepc = NULL;
4838 register I32 arg;
4839 bool ischop;
4840 bool unchopnum = FALSE;
4841 int maxops = 12; /* FF_LINEMARK + FF_END + 10 (\0 without preceding \n) */
4842
4843 PERL_ARGS_ASSERT_DOPARSEFORM;
4844
4845 if (len == 0)
4846 Perl_croak(aTHX_ "Null picture in formline");
4847
4848 /* estimate the buffer size needed */
4849 for (base = s; s <= send; s++) {
4850 if (*s == '\n' || *s == '@' || *s == '^')
4851 maxops += 10;
4852 }
4853 s = base;
4854 base = NULL;
4855
4856 Newx(fops, maxops, U32);
4857 fpc = fops;
4858
4859 if (s < send) {
4860 linepc = fpc;
4861 *fpc++ = FF_LINEMARK;
4862 noblank = repeat = FALSE;
4863 base = s;
4864 }
4865
4866 while (s <= send) {
4867 switch (*s++) {
4868 default:
4869 skipspaces = 0;
4870 continue;
4871
4872 case '~':
4873 if (*s == '~') {
4874 repeat = TRUE;
4875 *s = ' ';
4876 }
4877 noblank = TRUE;
4878 s[-1] = ' ';
4879 /* FALL THROUGH */
4880 case ' ': case '\t':
4881 skipspaces++;
4882 continue;
4883 case 0:
4884 if (s < send) {
4885 skipspaces = 0;
4886 continue;
4887 } /* else FALL THROUGH */
4888 case '\n':
4889 arg = s - base;
4890 skipspaces++;
4891 arg -= skipspaces;
4892 if (arg) {
4893 if (postspace)
4894 *fpc++ = FF_SPACE;
4895 *fpc++ = FF_LITERAL;
4896 *fpc++ = (U16)arg;
4897 }
4898 postspace = FALSE;
4899 if (s <= send)
4900 skipspaces--;
4901 if (skipspaces) {
4902 *fpc++ = FF_SKIP;
4903 *fpc++ = (U16)skipspaces;
4904 }
4905 skipspaces = 0;
4906 if (s <= send)
4907 *fpc++ = FF_NEWLINE;
4908 if (noblank) {
4909 *fpc++ = FF_BLANK;
4910 if (repeat)
4911 arg = fpc - linepc + 1;
4912 else
4913 arg = 0;
4914 *fpc++ = (U16)arg;
4915 }
4916 if (s < send) {
4917 linepc = fpc;
4918 *fpc++ = FF_LINEMARK;
4919 noblank = repeat = FALSE;
4920 base = s;
4921 }
4922 else
4923 s++;
4924 continue;
4925
4926 case '@':
4927 case '^':
4928 ischop = s[-1] == '^';
4929
4930 if (postspace) {
4931 *fpc++ = FF_SPACE;
4932 postspace = FALSE;
4933 }
4934 arg = (s - base) - 1;
4935 if (arg) {
4936 *fpc++ = FF_LITERAL;
4937 *fpc++ = (U16)arg;
4938 }
4939
4940 base = s - 1;
4941 *fpc++ = FF_FETCH;
4942 if (*s == '*') {
4943 s++;
4944 *fpc++ = 2; /* skip the @* or ^* */
4945 if (ischop) {
4946 *fpc++ = FF_LINESNGL;
4947 *fpc++ = FF_CHOP;
4948 } else
4949 *fpc++ = FF_LINEGLOB;
4950 }
4951 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
4952 arg = ischop ? 512 : 0;
4953 base = s - 1;
4954 while (*s == '#')
4955 s++;
4956 if (*s == '.') {
4957 const char * const f = ++s;
4958 while (*s == '#')
4959 s++;
4960 arg |= 256 + (s - f);
4961 }
4962 *fpc++ = s - base; /* fieldsize for FETCH */
4963 *fpc++ = FF_DECIMAL;
4964 *fpc++ = (U16)arg;
4965 unchopnum |= ! ischop;
4966 }
4967 else if (*s == '0' && s[1] == '#') { /* Zero padded decimals */
4968 arg = ischop ? 512 : 0;
4969 base = s - 1;
4970 s++; /* skip the '0' first */
4971 while (*s == '#')
4972 s++;
4973 if (*s == '.') {
4974 const char * const f = ++s;
4975 while (*s == '#')
4976 s++;
4977 arg |= 256 + (s - f);
4978 }
4979 *fpc++ = s - base; /* fieldsize for FETCH */
4980 *fpc++ = FF_0DECIMAL;
4981 *fpc++ = (U16)arg;
4982 unchopnum |= ! ischop;
4983 }
4984 else {
4985 I32 prespace = 0;
4986 bool ismore = FALSE;
4987
4988 if (*s == '>') {
4989 while (*++s == '>') ;
4990 prespace = FF_SPACE;
4991 }
4992 else if (*s == '|') {
4993 while (*++s == '|') ;
4994 prespace = FF_HALFSPACE;
4995 postspace = TRUE;
4996 }
4997 else {
4998 if (*s == '<')
4999 while (*++s == '<') ;
5000 postspace = TRUE;
5001 }
5002 if (*s == '.' && s[1] == '.' && s[2] == '.') {
5003 s += 3;
5004 ismore = TRUE;
5005 }
5006 *fpc++ = s - base; /* fieldsize for FETCH */
5007
5008 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
5009
5010 if (prespace)
5011 *fpc++ = (U16)prespace;
5012 *fpc++ = FF_ITEM;
5013 if (ismore)
5014 *fpc++ = FF_MORE;
5015 if (ischop)
5016 *fpc++ = FF_CHOP;
5017 }
5018 base = s;
5019 skipspaces = 0;
5020 continue;
5021 }
5022 }
5023 *fpc++ = FF_END;
5024
5025 assert (fpc <= fops + maxops); /* ensure our buffer estimate was valid */
5026 arg = fpc - fops;
5027 { /* need to jump to the next word */
5028 int z;
5029 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
5030 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U32) + 4);
5031 s = SvPVX(sv) + SvCUR(sv) + z;
5032 }
5033 Copy(fops, s, arg, U32);
5034 Safefree(fops);
5035 sv_magic(sv, NULL, PERL_MAGIC_fm, NULL, 0);
5036 SvCOMPILED_on(sv);
5037
5038 if (unchopnum && repeat)
5039 DIE(aTHX_ "Repeated format line will never terminate (~~ and @#)");
5040 return 0;
5041}
5042
5043
5044STATIC bool
5045S_num_overflow(NV value, I32 fldsize, I32 frcsize)
5046{
5047 /* Can value be printed in fldsize chars, using %*.*f ? */
5048 NV pwr = 1;
5049 NV eps = 0.5;
5050 bool res = FALSE;
5051 int intsize = fldsize - (value < 0 ? 1 : 0);
5052
5053 if (frcsize & 256)
5054 intsize--;
5055 frcsize &= 255;
5056 intsize -= frcsize;
5057
5058 while (intsize--) pwr *= 10.0;
5059 while (frcsize--) eps /= 10.0;
5060
5061 if( value >= 0 ){
5062 if (value + eps >= pwr)
5063 res = TRUE;
5064 } else {
5065 if (value - eps <= -pwr)
5066 res = TRUE;
5067 }
5068 return res;
5069}
5070
5071static I32
5072S_run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen)
5073{
5074 dVAR;
5075 SV * const datasv = FILTER_DATA(idx);
5076 const int filter_has_file = IoLINES(datasv);
5077 SV * const filter_state = MUTABLE_SV(IoTOP_GV(datasv));
5078 SV * const filter_sub = MUTABLE_SV(IoBOTTOM_GV(datasv));
5079 int status = 0;
5080 SV *upstream;
5081 STRLEN got_len;
5082 char *got_p = NULL;
5083 char *prune_from = NULL;
5084 bool read_from_cache = FALSE;
5085 STRLEN umaxlen;
5086
5087 PERL_ARGS_ASSERT_RUN_USER_FILTER;
5088
5089 assert(maxlen >= 0);
5090 umaxlen = maxlen;
5091
5092 /* I was having segfault trouble under Linux 2.2.5 after a
5093 parse error occured. (Had to hack around it with a test
5094 for PL_parser->error_count == 0.) Solaris doesn't segfault --
5095 not sure where the trouble is yet. XXX */
5096
5097 {
5098 SV *const cache = datasv;
5099 if (SvOK(cache)) {
5100 STRLEN cache_len;
5101 const char *cache_p = SvPV(cache, cache_len);
5102 STRLEN take = 0;
5103
5104 if (umaxlen) {
5105 /* Running in block mode and we have some cached data already.
5106 */
5107 if (cache_len >= umaxlen) {
5108 /* In fact, so much data we don't even need to call
5109 filter_read. */
5110 take = umaxlen;
5111 }
5112 } else {
5113 const char *const first_nl =
5114 (const char *)memchr(cache_p, '\n', cache_len);
5115 if (first_nl) {
5116 take = first_nl + 1 - cache_p;
5117 }
5118 }
5119 if (take) {
5120 sv_catpvn(buf_sv, cache_p, take);
5121 sv_chop(cache, cache_p + take);
5122 /* Definately not EOF */
5123 return 1;
5124 }
5125
5126 sv_catsv(buf_sv, cache);
5127 if (umaxlen) {
5128 umaxlen -= cache_len;
5129 }
5130 SvOK_off(cache);
5131 read_from_cache = TRUE;
5132 }
5133 }
5134
5135 /* Filter API says that the filter appends to the contents of the buffer.
5136 Usually the buffer is "", so the details don't matter. But if it's not,
5137 then clearly what it contains is already filtered by this filter, so we
5138 don't want to pass it in a second time.
5139 I'm going to use a mortal in case the upstream filter croaks. */
5140 upstream = ((SvOK(buf_sv) && sv_len(buf_sv)) || SvGMAGICAL(buf_sv))
5141 ? sv_newmortal() : buf_sv;
5142 SvUPGRADE(upstream, SVt_PV);
5143
5144 if (filter_has_file) {
5145 status = FILTER_READ(idx+1, upstream, 0);
5146 }
5147
5148 if (filter_sub && status >= 0) {
5149 dSP;
5150 int count;
5151
5152 ENTER_with_name("call_filter_sub");
5153 SAVE_DEFSV;
5154 SAVETMPS;
5155 EXTEND(SP, 2);
5156
5157 DEFSV_set(upstream);
5158 PUSHMARK(SP);
5159 mPUSHi(0);
5160 if (filter_state) {
5161 PUSHs(filter_state);
5162 }
5163 PUTBACK;
5164 count = call_sv(filter_sub, G_SCALAR);
5165 SPAGAIN;
5166
5167 if (count > 0) {
5168 SV *out = POPs;
5169 if (SvOK(out)) {
5170 status = SvIV(out);
5171 }
5172 }
5173
5174 PUTBACK;
5175 FREETMPS;
5176 LEAVE_with_name("call_filter_sub");
5177 }
5178
5179 if(SvOK(upstream)) {
5180 got_p = SvPV(upstream, got_len);
5181 if (umaxlen) {
5182 if (got_len > umaxlen) {
5183 prune_from = got_p + umaxlen;
5184 }
5185 } else {
5186 char *const first_nl = (char *)memchr(got_p, '\n', got_len);
5187 if (first_nl && first_nl + 1 < got_p + got_len) {
5188 /* There's a second line here... */
5189 prune_from = first_nl + 1;
5190 }
5191 }
5192 }
5193 if (prune_from) {
5194 /* Oh. Too long. Stuff some in our cache. */
5195 STRLEN cached_len = got_p + got_len - prune_from;
5196 SV *const cache = datasv;
5197
5198 if (SvOK(cache)) {
5199 /* Cache should be empty. */
5200 assert(!SvCUR(cache));
5201 }
5202
5203 sv_setpvn(cache, prune_from, cached_len);
5204 /* If you ask for block mode, you may well split UTF-8 characters.
5205 "If it breaks, you get to keep both parts"
5206 (Your code is broken if you don't put them back together again
5207 before something notices.) */
5208 if (SvUTF8(upstream)) {
5209 SvUTF8_on(cache);
5210 }
5211 SvCUR_set(upstream, got_len - cached_len);
5212 *prune_from = 0;
5213 /* Can't yet be EOF */
5214 if (status == 0)
5215 status = 1;
5216 }
5217
5218 /* If they are at EOF but buf_sv has something in it, then they may never
5219 have touched the SV upstream, so it may be undefined. If we naively
5220 concatenate it then we get a warning about use of uninitialised value.
5221 */
5222 if (upstream != buf_sv && (SvOK(upstream) || SvGMAGICAL(upstream))) {
5223 sv_catsv(buf_sv, upstream);
5224 }
5225
5226 if (status <= 0) {
5227 IoLINES(datasv) = 0;
5228 if (filter_state) {
5229 SvREFCNT_dec(filter_state);
5230 IoTOP_GV(datasv) = NULL;
5231 }
5232 if (filter_sub) {
5233 SvREFCNT_dec(filter_sub);
5234 IoBOTTOM_GV(datasv) = NULL;
5235 }
5236 filter_del(S_run_user_filter);
5237 }
5238 if (status == 0 && read_from_cache) {
5239 /* If we read some data from the cache (and by getting here it implies
5240 that we emptied the cache) then we aren't yet at EOF, and mustn't
5241 report that to our caller. */
5242 return 1;
5243 }
5244 return status;
5245}
5246
5247/* perhaps someone can come up with a better name for
5248 this? it is not really "absolute", per se ... */
5249static bool
5250S_path_is_absolute(const char *name)
5251{
5252 PERL_ARGS_ASSERT_PATH_IS_ABSOLUTE;
5253
5254 if (PERL_FILE_IS_ABSOLUTE(name)
5255#ifdef WIN32
5256 || (*name == '.' && ((name[1] == '/' ||
5257 (name[1] == '.' && name[2] == '/'))
5258 || (name[1] == '\\' ||
5259 ( name[1] == '.' && name[2] == '\\')))
5260 )
5261#else
5262 || (*name == '.' && (name[1] == '/' ||
5263 (name[1] == '.' && name[2] == '/')))
5264#endif
5265 )
5266 {
5267 return TRUE;
5268 }
5269 else
5270 return FALSE;
5271}
5272
5273/*
5274 * Local variables:
5275 * c-indentation-style: bsd
5276 * c-basic-offset: 4
5277 * indent-tabs-mode: t
5278 * End:
5279 *
5280 * ex: set ts=8 sts=4 sw=4 noet:
5281 */