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