This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add missing patch to op.c that didn't come across with win32 merge.
[perl5.git] / pp_hot.c
CommitLineData
a0d0e21e
LW
1/* pp_hot.c
2 *
9607fc9c 3 * Copyright (c) 1991-1997, Larry Wall
a0d0e21e
LW
4 *
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
7 *
8 */
9
10/*
11 * Then he heard Merry change the note, and up went the Horn-cry of Buckland,
12 * shaking the air.
13 *
14 * Awake! Awake! Fear, Fire, Foes! Awake!
15 * Fire, Foes! Awake!
16 */
17
18#include "EXTERN.h"
19#include "perl.h"
20
8ac85365
NIS
21#ifdef I_UNISTD
22#include <unistd.h>
23#endif
24
a0d0e21e
LW
25/* Hot code. */
26
11343788
MB
27#ifdef USE_THREADS
28static void
8ac85365 29unset_cvowner(void *cvarg)
11343788
MB
30{
31 register CV* cv = (CV *) cvarg;
32#ifdef DEBUGGING
33 dTHR;
34#endif /* DEBUGGING */
35
1fd28e87
MB
36 DEBUG_L((PerlIO_printf(PerlIO_stderr(), "%p unsetting CvOWNER of %p:%s\n",
37 thr, cv, SvPEEK((SV*)cv))));
11343788 38 MUTEX_LOCK(CvMUTEXP(cv));
77a005ab
MB
39 DEBUG_L(if (CvDEPTH(cv) != 0)
40 PerlIO_printf(PerlIO_stderr(), "depth %ld != 0\n",
41 CvDEPTH(cv)););
11343788
MB
42 assert(thr == CvOWNER(cv));
43 CvOWNER(cv) = 0;
11343788
MB
44 MUTEX_UNLOCK(CvMUTEXP(cv));
45 SvREFCNT_dec(cv);
46}
11343788
MB
47#endif /* USE_THREADS */
48
a0d0e21e
LW
49PP(pp_const)
50{
4e35701f 51 djSP;
a0d0e21e
LW
52 XPUSHs(cSVOP->op_sv);
53 RETURN;
54}
55
56PP(pp_nextstate)
57{
58 curcop = (COP*)op;
59 TAINT_NOT; /* Each statement is presumed innocent */
60 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
61 FREETMPS;
62 return NORMAL;
63}
64
65PP(pp_gvsv)
66{
4e35701f 67 djSP;
a0d0e21e
LW
68 EXTEND(sp,1);
69 if (op->op_private & OPpLVAL_INTRO)
70 PUSHs(save_scalar(cGVOP->op_gv));
71 else
72 PUSHs(GvSV(cGVOP->op_gv));
73 RETURN;
74}
75
76PP(pp_null)
77{
78 return NORMAL;
79}
80
81PP(pp_pushmark)
82{
83 PUSHMARK(stack_sp);
84 return NORMAL;
85}
86
87PP(pp_stringify)
88{
4e35701f 89 djSP; dTARGET;
a0d0e21e
LW
90 STRLEN len;
91 char *s;
92 s = SvPV(TOPs,len);
93 sv_setpvn(TARG,s,len);
94 SETTARG;
95 RETURN;
96}
97
98PP(pp_gv)
99{
4e35701f 100 djSP;
a0d0e21e
LW
101 XPUSHs((SV*)cGVOP->op_gv);
102 RETURN;
103}
104
105PP(pp_and)
106{
4e35701f 107 djSP;
a0d0e21e
LW
108 if (!SvTRUE(TOPs))
109 RETURN;
110 else {
111 --SP;
112 RETURNOP(cLOGOP->op_other);
113 }
114}
115
116PP(pp_sassign)
117{
4e35701f 118 djSP; dPOPTOPssrl;
748a9306
LW
119 MAGIC *mg;
120
a0d0e21e
LW
121 if (op->op_private & OPpASSIGN_BACKWARDS) {
122 SV *temp;
123 temp = left; left = right; right = temp;
124 }
bbce6d69 125 if (tainting && tainted && !SvTAINTED(left))
a0d0e21e 126 TAINT_NOT;
54310121 127 SvSetMagicSV(right, left);
a0d0e21e
LW
128 SETs(right);
129 RETURN;
130}
131
132PP(pp_cond_expr)
133{
4e35701f 134 djSP;
a0d0e21e
LW
135 if (SvTRUEx(POPs))
136 RETURNOP(cCONDOP->op_true);
137 else
138 RETURNOP(cCONDOP->op_false);
139}
140
141PP(pp_unstack)
142{
143 I32 oldsave;
144 TAINT_NOT; /* Each statement is presumed innocent */
145 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
146 FREETMPS;
147 oldsave = scopestack[scopestack_ix - 1];
148 LEAVE_SCOPE(oldsave);
149 return NORMAL;
150}
151
a0d0e21e
LW
152PP(pp_concat)
153{
4e35701f 154 djSP; dATARGET; tryAMAGICbin(concat,opASSIGN);
748a9306
LW
155 {
156 dPOPTOPssrl;
a0d0e21e
LW
157 STRLEN len;
158 char *s;
159 if (TARG != left) {
160 s = SvPV(left,len);
161 sv_setpvn(TARG,s,len);
162 }
c07a80fd
PP
163 else if (SvGMAGICAL(TARG))
164 mg_get(TARG);
7a4c00b4 165 else if (!SvOK(TARG) && SvTYPE(TARG) <= SVt_PVMG) {
748a9306 166 sv_setpv(TARG, ""); /* Suppress warning. */
7a4c00b4 167 s = SvPV_force(TARG, len);
4633a7c4 168 }
a0d0e21e 169 s = SvPV(right,len);
68dc0745
PP
170 if (SvOK(TARG))
171 sv_catpvn(TARG,s,len);
172 else
173 sv_setpvn(TARG,s,len); /* suppress warning */
a0d0e21e
LW
174 SETTARG;
175 RETURN;
748a9306 176 }
a0d0e21e
LW
177}
178
179PP(pp_padsv)
180{
4e35701f 181 djSP; dTARGET;
a0d0e21e 182 XPUSHs(TARG);
4633a7c4
LW
183 if (op->op_flags & OPf_MOD) {
184 if (op->op_private & OPpLVAL_INTRO)
185 SAVECLEARSV(curpad[op->op_targ]);
5f05dabc 186 else if (op->op_private & OPpDEREF)
54310121 187 vivify_ref(curpad[op->op_targ], op->op_private & OPpDEREF);
4633a7c4 188 }
a0d0e21e
LW
189 RETURN;
190}
191
192PP(pp_readline)
193{
194 last_in_gv = (GV*)(*stack_sp--);
195 return do_readline();
196}
197
198PP(pp_eq)
199{
4e35701f 200 djSP; tryAMAGICbinSET(eq,0);
a0d0e21e
LW
201 {
202 dPOPnv;
54310121 203 SETs(boolSV(TOPn == value));
a0d0e21e
LW
204 RETURN;
205 }
206}
207
208PP(pp_preinc)
209{
4e35701f 210 djSP;
68dc0745 211 if (SvREADONLY(TOPs) || SvTYPE(TOPs) > SVt_PVLV)
44a8e56a 212 croak(no_modify);
55497cff
PP
213 if (SvIOK(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs) &&
214 SvIVX(TOPs) != IV_MAX)
215 {
748a9306 216 ++SvIVX(TOPs);
55497cff 217 SvFLAGS(TOPs) &= ~(SVp_NOK|SVp_POK);
748a9306
LW
218 }
219 else
220 sv_inc(TOPs);
a0d0e21e
LW
221 SvSETMAGIC(TOPs);
222 return NORMAL;
223}
224
225PP(pp_or)
226{
4e35701f 227 djSP;
a0d0e21e
LW
228 if (SvTRUE(TOPs))
229 RETURN;
230 else {
231 --SP;
232 RETURNOP(cLOGOP->op_other);
233 }
234}
235
236PP(pp_add)
237{
4e35701f 238 djSP; dATARGET; tryAMAGICbin(add,opASSIGN);
a0d0e21e 239 {
7a4c00b4 240 dPOPTOPnnrl_ul;
a0d0e21e
LW
241 SETn( left + right );
242 RETURN;
243 }
244}
245
246PP(pp_aelemfast)
247{
4e35701f 248 djSP;
a0d0e21e
LW
249 AV *av = GvAV((GV*)cSVOP->op_sv);
250 SV** svp = av_fetch(av, op->op_private, op->op_flags & OPf_MOD);
251 PUSHs(svp ? *svp : &sv_undef);
252 RETURN;
253}
254
255PP(pp_join)
256{
4e35701f 257 djSP; dMARK; dTARGET;
a0d0e21e
LW
258 MARK++;
259 do_join(TARG, *MARK, MARK, SP);
260 SP = MARK;
261 SETs(TARG);
262 RETURN;
263}
264
265PP(pp_pushre)
266{
4e35701f 267 djSP;
44a8e56a
PP
268#ifdef DEBUGGING
269 /*
270 * We ass_u_me that LvTARGOFF() comes first, and that two STRLENs
271 * will be enough to hold an OP*.
272 */
273 SV* sv = sv_newmortal();
274 sv_upgrade(sv, SVt_PVLV);
275 LvTYPE(sv) = '/';
276 Copy(&op, &LvTARGOFF(sv), 1, OP*);
277 XPUSHs(sv);
278#else
a0d0e21e 279 XPUSHs((SV*)op);
44a8e56a 280#endif
a0d0e21e
LW
281 RETURN;
282}
283
284/* Oversized hot code. */
285
286PP(pp_print)
287{
4e35701f 288 djSP; dMARK; dORIGMARK;
a0d0e21e
LW
289 GV *gv;
290 IO *io;
760ac839 291 register PerlIO *fp;
236988e4 292 MAGIC *mg;
a0d0e21e
LW
293
294 if (op->op_flags & OPf_STACKED)
295 gv = (GV*)*++MARK;
296 else
297 gv = defoutgv;
236988e4 298 if (SvMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) {
68dc0745
PP
299 if (MARK == ORIGMARK) {
300 EXTEND(SP, 1);
301 ++MARK;
302 Move(MARK, MARK + 1, (SP - MARK) + 1, SV*);
303 ++SP;
304 }
305 PUSHMARK(MARK - 1);
236988e4 306 *MARK = mg->mg_obj;
68dc0745 307 PUTBACK;
236988e4
PP
308 ENTER;
309 perl_call_method("PRINT", G_SCALAR);
310 LEAVE;
311 SPAGAIN;
68dc0745
PP
312 MARK = ORIGMARK + 1;
313 *MARK = *SP;
314 SP = MARK;
236988e4
PP
315 RETURN;
316 }
a0d0e21e 317 if (!(io = GvIO(gv))) {
748a9306
LW
318 if (dowarn) {
319 SV* sv = sv_newmortal();
4f732624 320 gv_fullname3(sv, gv, Nullch);
748a9306
LW
321 warn("Filehandle %s never opened", SvPV(sv,na));
322 }
323
324 SETERRNO(EBADF,RMS$_IFI);
a0d0e21e
LW
325 goto just_say_no;
326 }
327 else if (!(fp = IoOFP(io))) {
328 if (dowarn) {
748a9306 329 SV* sv = sv_newmortal();
4f732624 330 gv_fullname3(sv, gv, Nullch);
a0d0e21e 331 if (IoIFP(io))
748a9306 332 warn("Filehandle %s opened only for input", SvPV(sv,na));
a0d0e21e 333 else
748a9306 334 warn("print on closed filehandle %s", SvPV(sv,na));
a0d0e21e 335 }
748a9306 336 SETERRNO(EBADF,IoIFP(io)?RMS$_FAC:RMS$_IFI);
a0d0e21e
LW
337 goto just_say_no;
338 }
339 else {
340 MARK++;
341 if (ofslen) {
342 while (MARK <= SP) {
343 if (!do_print(*MARK, fp))
344 break;
345 MARK++;
346 if (MARK <= SP) {
760ac839 347 if (PerlIO_write(fp, ofs, ofslen) == 0 || PerlIO_error(fp)) {
a0d0e21e
LW
348 MARK--;
349 break;
350 }
351 }
352 }
353 }
354 else {
355 while (MARK <= SP) {
356 if (!do_print(*MARK, fp))
357 break;
358 MARK++;
359 }
360 }
361 if (MARK <= SP)
362 goto just_say_no;
363 else {
364 if (orslen)
760ac839 365 if (PerlIO_write(fp, ors, orslen) == 0 || PerlIO_error(fp))
a0d0e21e
LW
366 goto just_say_no;
367
368 if (IoFLAGS(io) & IOf_FLUSH)
760ac839 369 if (PerlIO_flush(fp) == EOF)
a0d0e21e
LW
370 goto just_say_no;
371 }
372 }
373 SP = ORIGMARK;
374 PUSHs(&sv_yes);
375 RETURN;
376
377 just_say_no:
378 SP = ORIGMARK;
379 PUSHs(&sv_undef);
380 RETURN;
381}
382
383PP(pp_rv2av)
384{
4e35701f 385 djSP; dPOPss;
a0d0e21e
LW
386 AV *av;
387
388 if (SvROK(sv)) {
389 wasref:
390 av = (AV*)SvRV(sv);
391 if (SvTYPE(av) != SVt_PVAV)
392 DIE("Not an ARRAY reference");
a0d0e21e
LW
393 if (op->op_flags & OPf_REF) {
394 PUSHs((SV*)av);
395 RETURN;
396 }
397 }
398 else {
399 if (SvTYPE(sv) == SVt_PVAV) {
400 av = (AV*)sv;
401 if (op->op_flags & OPf_REF) {
402 PUSHs((SV*)av);
403 RETURN;
404 }
405 }
406 else {
67955e0c
PP
407 GV *gv;
408
a0d0e21e 409 if (SvTYPE(sv) != SVt_PVGV) {
748a9306
LW
410 char *sym;
411
a0d0e21e
LW
412 if (SvGMAGICAL(sv)) {
413 mg_get(sv);
414 if (SvROK(sv))
415 goto wasref;
416 }
417 if (!SvOK(sv)) {
418 if (op->op_flags & OPf_REF ||
419 op->op_private & HINT_STRICT_REFS)
420 DIE(no_usym, "an ARRAY");
d83e6520
CS
421 if (dowarn)
422 warn(warn_uninit);
4633a7c4
LW
423 if (GIMME == G_ARRAY)
424 RETURN;
a0d0e21e
LW
425 RETPUSHUNDEF;
426 }
748a9306 427 sym = SvPV(sv,na);
a0d0e21e 428 if (op->op_private & HINT_STRICT_REFS)
748a9306 429 DIE(no_symref, sym, "an ARRAY");
67955e0c
PP
430 gv = (GV*)gv_fetchpv(sym, TRUE, SVt_PVAV);
431 } else {
432 gv = (GV*)sv;
a0d0e21e 433 }
67955e0c 434 av = GvAVn(gv);
a0d0e21e 435 if (op->op_private & OPpLVAL_INTRO)
67955e0c 436 av = save_ary(gv);
a0d0e21e
LW
437 if (op->op_flags & OPf_REF) {
438 PUSHs((SV*)av);
439 RETURN;
440 }
441 }
442 }
443
444 if (GIMME == G_ARRAY) {
445 I32 maxarg = AvFILL(av) + 1;
446 EXTEND(SP, maxarg);
447 Copy(AvARRAY(av), SP+1, maxarg, SV*);
448 SP += maxarg;
449 }
450 else {
451 dTARGET;
452 I32 maxarg = AvFILL(av) + 1;
453 PUSHi(maxarg);
454 }
455 RETURN;
456}
457
458PP(pp_rv2hv)
459{
4e35701f 460 djSP; dTOPss;
a0d0e21e
LW
461 HV *hv;
462
463 if (SvROK(sv)) {
464 wasref:
465 hv = (HV*)SvRV(sv);
c750a3ec 466 if (SvTYPE(hv) != SVt_PVHV && SvTYPE(hv) != SVt_PVAV)
a0d0e21e 467 DIE("Not a HASH reference");
a0d0e21e
LW
468 if (op->op_flags & OPf_REF) {
469 SETs((SV*)hv);
470 RETURN;
471 }
472 }
473 else {
c750a3ec 474 if (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV) {
a0d0e21e
LW
475 hv = (HV*)sv;
476 if (op->op_flags & OPf_REF) {
477 SETs((SV*)hv);
478 RETURN;
479 }
480 }
481 else {
67955e0c
PP
482 GV *gv;
483
a0d0e21e 484 if (SvTYPE(sv) != SVt_PVGV) {
748a9306
LW
485 char *sym;
486
a0d0e21e
LW
487 if (SvGMAGICAL(sv)) {
488 mg_get(sv);
489 if (SvROK(sv))
490 goto wasref;
491 }
492 if (!SvOK(sv)) {
493 if (op->op_flags & OPf_REF ||
494 op->op_private & HINT_STRICT_REFS)
495 DIE(no_usym, "a HASH");
d83e6520
CS
496 if (dowarn)
497 warn(warn_uninit);
4633a7c4
LW
498 if (GIMME == G_ARRAY) {
499 SP--;
500 RETURN;
501 }
a0d0e21e
LW
502 RETSETUNDEF;
503 }
748a9306 504 sym = SvPV(sv,na);
a0d0e21e 505 if (op->op_private & HINT_STRICT_REFS)
748a9306 506 DIE(no_symref, sym, "a HASH");
67955e0c
PP
507 gv = (GV*)gv_fetchpv(sym, TRUE, SVt_PVHV);
508 } else {
509 gv = (GV*)sv;
a0d0e21e 510 }
67955e0c 511 hv = GvHVn(gv);
a0d0e21e 512 if (op->op_private & OPpLVAL_INTRO)
67955e0c 513 hv = save_hash(gv);
a0d0e21e
LW
514 if (op->op_flags & OPf_REF) {
515 SETs((SV*)hv);
516 RETURN;
517 }
518 }
519 }
520
521 if (GIMME == G_ARRAY) { /* array wanted */
522 *stack_sp = (SV*)hv;
523 return do_kv(ARGS);
524 }
525 else {
526 dTARGET;
c750a3ec 527 /* This bit is OK even when hv is really an AV */
46fc3d4c
PP
528 if (HvFILL(hv))
529 sv_setpvf(TARG, "%ld/%ld",
530 (long)HvFILL(hv), (long)HvMAX(hv) + 1);
a0d0e21e
LW
531 else
532 sv_setiv(TARG, 0);
c750a3ec 533
a0d0e21e
LW
534 SETTARG;
535 RETURN;
536 }
537}
538
539PP(pp_aassign)
540{
4e35701f 541 djSP;
a0d0e21e
LW
542 SV **lastlelem = stack_sp;
543 SV **lastrelem = stack_base + POPMARK;
544 SV **firstrelem = stack_base + POPMARK + 1;
545 SV **firstlelem = lastrelem + 1;
546
547 register SV **relem;
548 register SV **lelem;
549
550 register SV *sv;
551 register AV *ary;
552
54310121 553 I32 gimme;
a0d0e21e
LW
554 HV *hash;
555 I32 i;
556 int magic;
557
558 delaymagic = DM_DELAY; /* catch simultaneous items */
559
560 /* If there's a common identifier on both sides we have to take
561 * special care that assigning the identifier on the left doesn't
562 * clobber a value on the right that's used later in the list.
563 */
564 if (op->op_private & OPpASSIGN_COMMON) {
565 for (relem = firstrelem; relem <= lastrelem; relem++) {
566 /*SUPPRESS 560*/
a1f49e72
CS
567 if (sv = *relem) {
568 TAINT_NOT; /* Each item is independent */
a0d0e21e 569 *relem = sv_mortalcopy(sv);
a1f49e72 570 }
a0d0e21e
LW
571 }
572 }
573
574 relem = firstrelem;
575 lelem = firstlelem;
576 ary = Null(AV*);
577 hash = Null(HV*);
578 while (lelem <= lastlelem) {
bbce6d69 579 TAINT_NOT; /* Each item stands on its own, taintwise. */
a0d0e21e
LW
580 sv = *lelem++;
581 switch (SvTYPE(sv)) {
582 case SVt_PVAV:
583 ary = (AV*)sv;
748a9306 584 magic = SvMAGICAL(ary) != 0;
a0d0e21e
LW
585
586 av_clear(ary);
7e42bd57 587 av_extend(ary, lastrelem - relem);
a0d0e21e
LW
588 i = 0;
589 while (relem <= lastrelem) { /* gobble up all the rest */
5117ca91 590 SV **didstore;
a0d0e21e
LW
591 sv = NEWSV(28,0);
592 assert(*relem);
593 sv_setsv(sv,*relem);
594 *(relem++) = sv;
5117ca91
GS
595 didstore = av_store(ary,i++,sv);
596 if (magic) {
fb73857a
PP
597 if (SvSMAGICAL(sv))
598 mg_set(sv);
5117ca91
GS
599 if (!didstore)
600 SvREFCNT_dec(sv);
601 }
bbce6d69 602 TAINT_NOT;
a0d0e21e
LW
603 }
604 break;
605 case SVt_PVHV: {
a0d0e21e
LW
606 SV *tmpstr;
607
608 hash = (HV*)sv;
748a9306 609 magic = SvMAGICAL(hash) != 0;
a0d0e21e
LW
610 hv_clear(hash);
611
612 while (relem < lastrelem) { /* gobble up all the rest */
613 STRLEN len;
5117ca91 614 HE *didstore;
4633a7c4 615 if (*relem)
a0d0e21e 616 sv = *(relem++);
4633a7c4 617 else
a0d0e21e 618 sv = &sv_no, relem++;
a0d0e21e
LW
619 tmpstr = NEWSV(29,0);
620 if (*relem)
621 sv_setsv(tmpstr,*relem); /* value */
622 *(relem++) = tmpstr;
5117ca91
GS
623 didstore = hv_store_ent(hash,sv,tmpstr,0);
624 if (magic) {
fb73857a
PP
625 if (SvSMAGICAL(tmpstr))
626 mg_set(tmpstr);
5117ca91
GS
627 if (!didstore)
628 SvREFCNT_dec(tmpstr);
629 }
bbce6d69 630 TAINT_NOT;
8e07c86e 631 }
fb73857a 632 if (relem == lastrelem && dowarn)
760ac839 633 warn("Odd number of elements in hash list");
a0d0e21e
LW
634 }
635 break;
636 default:
637 if (SvTHINKFIRST(sv)) {
638 if (SvREADONLY(sv) && curcop != &compiling) {
639 if (sv != &sv_undef && sv != &sv_yes && sv != &sv_no)
640 DIE(no_modify);
641 if (relem <= lastrelem)
642 relem++;
643 break;
644 }
645 if (SvROK(sv))
646 sv_unref(sv);
647 }
648 if (relem <= lastrelem) {
649 sv_setsv(sv, *relem);
650 *(relem++) = sv;
651 }
652 else
653 sv_setsv(sv, &sv_undef);
654 SvSETMAGIC(sv);
655 break;
656 }
657 }
658 if (delaymagic & ~DM_DELAY) {
659 if (delaymagic & DM_UID) {
660#ifdef HAS_SETRESUID
661 (void)setresuid(uid,euid,(Uid_t)-1);
56febc5e
AD
662#else
663# ifdef HAS_SETREUID
a0d0e21e 664 (void)setreuid(uid,euid);
56febc5e
AD
665# else
666# ifdef HAS_SETRUID
a0d0e21e
LW
667 if ((delaymagic & DM_UID) == DM_RUID) {
668 (void)setruid(uid);
748a9306 669 delaymagic &= ~DM_RUID;
a0d0e21e 670 }
56febc5e
AD
671# endif /* HAS_SETRUID */
672# ifdef HAS_SETEUID
a0d0e21e
LW
673 if ((delaymagic & DM_UID) == DM_EUID) {
674 (void)seteuid(uid);
748a9306 675 delaymagic &= ~DM_EUID;
a0d0e21e 676 }
56febc5e 677# endif /* HAS_SETEUID */
a0d0e21e
LW
678 if (delaymagic & DM_UID) {
679 if (uid != euid)
680 DIE("No setreuid available");
681 (void)setuid(uid);
682 }
56febc5e
AD
683# endif /* HAS_SETREUID */
684#endif /* HAS_SETRESUID */
a0d0e21e
LW
685 uid = (int)getuid();
686 euid = (int)geteuid();
687 }
688 if (delaymagic & DM_GID) {
689#ifdef HAS_SETRESGID
690 (void)setresgid(gid,egid,(Gid_t)-1);
56febc5e
AD
691#else
692# ifdef HAS_SETREGID
a0d0e21e 693 (void)setregid(gid,egid);
56febc5e
AD
694# else
695# ifdef HAS_SETRGID
a0d0e21e
LW
696 if ((delaymagic & DM_GID) == DM_RGID) {
697 (void)setrgid(gid);
748a9306 698 delaymagic &= ~DM_RGID;
a0d0e21e 699 }
56febc5e
AD
700# endif /* HAS_SETRGID */
701# ifdef HAS_SETEGID
a0d0e21e
LW
702 if ((delaymagic & DM_GID) == DM_EGID) {
703 (void)setegid(gid);
748a9306 704 delaymagic &= ~DM_EGID;
a0d0e21e 705 }
56febc5e 706# endif /* HAS_SETEGID */
a0d0e21e
LW
707 if (delaymagic & DM_GID) {
708 if (gid != egid)
709 DIE("No setregid available");
710 (void)setgid(gid);
711 }
56febc5e
AD
712# endif /* HAS_SETREGID */
713#endif /* HAS_SETRESGID */
a0d0e21e
LW
714 gid = (int)getgid();
715 egid = (int)getegid();
716 }
4633a7c4 717 tainting |= (uid && (euid != uid || egid != gid));
a0d0e21e
LW
718 }
719 delaymagic = 0;
54310121
PP
720
721 gimme = GIMME_V;
722 if (gimme == G_VOID)
723 SP = firstrelem - 1;
724 else if (gimme == G_SCALAR) {
725 dTARGET;
726 SP = firstrelem;
727 SETi(lastrelem - firstrelem + 1);
728 }
729 else {
a0d0e21e
LW
730 if (ary || hash)
731 SP = lastrelem;
732 else
733 SP = firstrelem + (lastlelem - firstlelem);
0c8c7a05 734 lelem = firstlelem + (relem - firstrelem);
5f05dabc 735 while (relem <= SP)
0c8c7a05 736 *relem++ = (lelem <= lastlelem) ? *lelem++ : &sv_undef;
a0d0e21e 737 }
54310121 738 RETURN;
a0d0e21e
LW
739}
740
741PP(pp_match)
742{
4e35701f 743 djSP; dTARG;
a0d0e21e
LW
744 register PMOP *pm = cPMOP;
745 register char *t;
746 register char *s;
747 char *strend;
748 I32 global;
749 I32 safebase;
750 char *truebase;
751 register REGEXP *rx = pm->op_pmregexp;
752 I32 gimme = GIMME;
753 STRLEN len;
748a9306 754 I32 minmatch = 0;
4633a7c4 755 I32 oldsave = savestack_ix;
f86702cc 756 I32 update_minmatch = 1;
c277df42 757 SV *screamer;
a0d0e21e
LW
758
759 if (op->op_flags & OPf_STACKED)
760 TARG = POPs;
761 else {
54b9620d 762 TARG = DEFSV;
a0d0e21e
LW
763 EXTEND(SP,1);
764 }
c277df42 765 PUTBACK; /* EVAL blocks need stack_sp. */
a0d0e21e
LW
766 s = SvPV(TARG, len);
767 strend = s + len;
768 if (!s)
769 DIE("panic: do_match");
9212bbba 770 TAINT_NOT;
a0d0e21e
LW
771
772 if (pm->op_pmflags & PMf_USED) {
c277df42 773 failure:
a0d0e21e
LW
774 if (gimme == G_ARRAY)
775 RETURN;
776 RETPUSHNO;
777 }
778
779 if (!rx->prelen && curpm) {
780 pm = curpm;
781 rx = pm->op_pmregexp;
782 }
c277df42
IZ
783 if (rx->minlen > len) goto failure;
784
785 screamer = ( (SvSCREAM(TARG) && rx->check_substr
786 && SvTYPE(rx->check_substr) == SVt_PVBM
787 && SvVALID(rx->check_substr))
788 ? TARG : Nullsv);
a0d0e21e
LW
789 truebase = t = s;
790 if (global = pm->op_pmflags & PMf_GLOBAL) {
791 rx->startp[0] = 0;
792 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) {
793 MAGIC* mg = mg_find(TARG, 'g');
748a9306 794 if (mg && mg->mg_len >= 0) {
a0d0e21e 795 rx->endp[0] = rx->startp[0] = s + mg->mg_len;
748a9306 796 minmatch = (mg->mg_flags & MGf_MINMATCH);
f86702cc 797 update_minmatch = 0;
748a9306 798 }
a0d0e21e
LW
799 }
800 }
748a9306
LW
801 if (!rx->nparens && !global)
802 gimme = G_SCALAR; /* accidental array context? */
137443ea
PP
803 safebase = (((gimme == G_ARRAY) || global || !rx->nparens)
804 && !sawampersand);
c277df42 805 safebase = safebase ? 0 : REXEC_COPY_STR ;
a0d0e21e
LW
806 if (pm->op_pmflags & (PMf_MULTILINE|PMf_SINGLELINE)) {
807 SAVEINT(multiline);
808 multiline = pm->op_pmflags & PMf_MULTILINE;
809 }
810
811play_it_again:
812 if (global && rx->startp[0]) {
813 t = s = rx->endp[0];
51aa1f50 814 if ((s + rx->minlen) > strend)
a0d0e21e 815 goto nope;
f86702cc
PP
816 if (update_minmatch++)
817 minmatch = (s == rx->startp[0]);
a0d0e21e 818 }
c277df42
IZ
819 if (rx->check_substr) {
820 if (!(rx->reganch & ROPT_NOSCAN)) { /* Floating checkstring. */
821 if ( screamer ) {
822 I32 p = -1;
823
824 if (screamfirst[BmRARE(rx->check_substr)] < 0)
a0d0e21e 825 goto nope;
c277df42
IZ
826 else if (!(s = screaminstr(TARG, rx->check_substr,
827 rx->check_offset_min, 0, &p, 0)))
a0d0e21e 828 goto nope;
c277df42
IZ
829 else if ((rx->reganch & ROPT_CHECK_ALL)
830 && !sawampersand && !SvTAIL(rx->check_substr))
a0d0e21e
LW
831 goto yup;
832 }
c277df42
IZ
833 else if (!(s = fbm_instr((unsigned char*)s + rx->check_offset_min,
834 (unsigned char*)strend,
835 rx->check_substr)))
a0d0e21e 836 goto nope;
c277df42 837 else if ((rx->reganch & ROPT_CHECK_ALL) && !sawampersand)
a0d0e21e 838 goto yup;
c277df42
IZ
839 if (s && rx->check_offset_max < t - s) {
840 ++BmUSEFUL(rx->check_substr);
841 s -= rx->check_offset_max;
a0d0e21e
LW
842 }
843 else
844 s = t;
845 }
c277df42
IZ
846 /* Now checkstring is fixed, i.e. at fixed offset from the
847 beginning of match, and the match is anchored at s. */
848 else if (!multiline) { /* Anchored near beginning of string. */
849 I32 slen;
850 if (*SvPVX(rx->check_substr) != s[rx->check_offset_min]
851 || ((slen = SvCUR(rx->check_substr)) > 1
852 && memNE(SvPVX(rx->check_substr),
853 s + rx->check_offset_min, slen)))
bbce6d69 854 goto nope;
a0d0e21e 855 }
c277df42
IZ
856 if (!rx->naughty && --BmUSEFUL(rx->check_substr) < 0
857 && rx->check_substr == rx->float_substr) {
858 SvREFCNT_dec(rx->check_substr);
859 rx->check_substr = Nullsv; /* opt is being useless */
860 rx->float_substr = Nullsv;
a0d0e21e
LW
861 }
862 }
c277df42
IZ
863 if (regexec_flags(rx, s, strend, truebase, minmatch,
864 screamer, NULL, safebase))
bbce6d69 865 {
a0d0e21e
LW
866 curpm = pm;
867 if (pm->op_pmflags & PMf_ONCE)
868 pm->op_pmflags |= PMf_USED;
869 goto gotcha;
870 }
871 else
872 goto ret_no;
873 /*NOTREACHED*/
874
875 gotcha:
c277df42 876 TAINT_IF(RX_MATCH_TAINTED(rx));
a0d0e21e
LW
877 if (gimme == G_ARRAY) {
878 I32 iters, i, len;
879
880 iters = rx->nparens;
881 if (global && !iters)
882 i = 1;
883 else
884 i = 0;
c277df42 885 SPAGAIN; /* EVAL blocks could move the stack. */
a0d0e21e 886 EXTEND(SP, iters + i);
bbce6d69 887 EXTEND_MORTAL(iters + i);
a0d0e21e
LW
888 for (i = !i; i <= iters; i++) {
889 PUSHs(sv_newmortal());
890 /*SUPPRESS 560*/
891 if ((s = rx->startp[i]) && rx->endp[i] ) {
892 len = rx->endp[i] - s;
893 sv_setpvn(*SP, s, len);
894 }
895 }
896 if (global) {
897 truebase = rx->subbeg;
5f05dabc 898 strend = rx->subend;
a0d0e21e
LW
899 if (rx->startp[0] && rx->startp[0] == rx->endp[0])
900 ++rx->endp[0];
c277df42 901 PUTBACK; /* EVAL blocks may use stack */
a0d0e21e
LW
902 goto play_it_again;
903 }
4633a7c4 904 LEAVE_SCOPE(oldsave);
a0d0e21e
LW
905 RETURN;
906 }
907 else {
908 if (global) {
909 MAGIC* mg = 0;
910 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG))
911 mg = mg_find(TARG, 'g');
912 if (!mg) {
913 sv_magic(TARG, (SV*)0, 'g', Nullch, 0);
914 mg = mg_find(TARG, 'g');
915 }
748a9306 916 if (rx->startp[0]) {
5f05dabc 917 mg->mg_len = rx->endp[0] - rx->subbeg;
748a9306
LW
918 if (rx->startp[0] == rx->endp[0])
919 mg->mg_flags |= MGf_MINMATCH;
920 else
921 mg->mg_flags &= ~MGf_MINMATCH;
922 }
a0d0e21e 923 }
4633a7c4 924 LEAVE_SCOPE(oldsave);
a0d0e21e
LW
925 RETPUSHYES;
926 }
927
c277df42
IZ
928yup: /* Confirmed by check_substr */
929 TAINT_IF(RX_MATCH_TAINTED(rx));
930 ++BmUSEFUL(rx->check_substr);
a0d0e21e
LW
931 curpm = pm;
932 if (pm->op_pmflags & PMf_ONCE)
933 pm->op_pmflags |= PMf_USED;
5f05dabc
PP
934 Safefree(rx->subbase);
935 rx->subbase = Nullch;
a0d0e21e
LW
936 if (global) {
937 rx->subbeg = truebase;
938 rx->subend = strend;
939 rx->startp[0] = s;
c277df42 940 rx->endp[0] = s + SvCUR(rx->check_substr);
a0d0e21e
LW
941 goto gotcha;
942 }
943 if (sawampersand) {
944 char *tmps;
945
a0d0e21e
LW
946 tmps = rx->subbase = savepvn(t, strend-t);
947 rx->subbeg = tmps;
948 rx->subend = tmps + (strend-t);
949 tmps = rx->startp[0] = tmps + (s - t);
c277df42 950 rx->endp[0] = tmps + SvCUR(rx->check_substr);
a0d0e21e 951 }
4633a7c4 952 LEAVE_SCOPE(oldsave);
a0d0e21e
LW
953 RETPUSHYES;
954
955nope:
c277df42
IZ
956 if (rx->check_substr)
957 ++BmUSEFUL(rx->check_substr);
a0d0e21e
LW
958
959ret_no:
c90c0ff4 960 if (global && !(pm->op_pmflags & PMf_CONTINUE)) {
a0d0e21e
LW
961 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) {
962 MAGIC* mg = mg_find(TARG, 'g');
963 if (mg)
964 mg->mg_len = -1;
965 }
966 }
4633a7c4 967 LEAVE_SCOPE(oldsave);
a0d0e21e
LW
968 if (gimme == G_ARRAY)
969 RETURN;
970 RETPUSHNO;
971}
972
973OP *
8ac85365 974do_readline(void)
a0d0e21e
LW
975{
976 dSP; dTARGETSTACKED;
977 register SV *sv;
978 STRLEN tmplen = 0;
979 STRLEN offset;
760ac839 980 PerlIO *fp;
a0d0e21e
LW
981 register IO *io = GvIO(last_in_gv);
982 register I32 type = op->op_type;
54310121 983 I32 gimme = GIMME_V;
e79b0511 984 MAGIC *mg;
a0d0e21e 985
e79b0511
PP
986 if (SvMAGICAL(last_in_gv) && (mg = mg_find((SV*)last_in_gv, 'q'))) {
987 PUSHMARK(SP);
988 XPUSHs(mg->mg_obj);
989 PUTBACK;
990 ENTER;
54310121 991 perl_call_method("READLINE", gimme);
e79b0511
PP
992 LEAVE;
993 SPAGAIN;
54310121
PP
994 if (gimme == G_SCALAR)
995 SvSetMagicSV_nosteal(TARG, TOPs);
e79b0511
PP
996 RETURN;
997 }
a0d0e21e
LW
998 fp = Nullfp;
999 if (io) {
1000 fp = IoIFP(io);
1001 if (!fp) {
1002 if (IoFLAGS(io) & IOf_ARGV) {
1003 if (IoFLAGS(io) & IOf_START) {
1004 IoFLAGS(io) &= ~IOf_START;
1005 IoLINES(io) = 0;
1006 if (av_len(GvAVn(last_in_gv)) < 0) {
1007 SV *tmpstr = newSVpv("-", 1); /* assume stdin */
1008 av_push(GvAVn(last_in_gv), tmpstr);
1009 }
1010 }
1011 fp = nextargv(last_in_gv);
1012 if (!fp) { /* Note: fp != IoIFP(io) */
1013 (void)do_close(last_in_gv, FALSE); /* now it does*/
1014 IoFLAGS(io) |= IOf_START;
1015 }
1016 }
1017 else if (type == OP_GLOB) {
1018 SV *tmpcmd = NEWSV(55, 0);
1019 SV *tmpglob = POPs;
1020 ENTER;
1021 SAVEFREESV(tmpcmd);
1022#ifdef VMS /* expand the wildcards right here, rather than opening a pipe, */
1023 /* since spawning off a process is a real performance hit */
1024 {
1025#include <descrip.h>
1026#include <lib$routines.h>
1027#include <nam.h>
1028#include <rmsdef.h>
1029 char rslt[NAM$C_MAXRSS+1+sizeof(unsigned short int)] = {'\0','\0'};
1030 char vmsspec[NAM$C_MAXRSS+1];
1031 char *rstr = rslt + sizeof(unsigned short int), *begin, *end, *cp;
1032 char tmpfnam[L_tmpnam] = "SYS$SCRATCH:";
1033 $DESCRIPTOR(dfltdsc,"SYS$DISK:[]*.*;");
760ac839 1034 PerlIO *tmpfp;
a0d0e21e
LW
1035 STRLEN i;
1036 struct dsc$descriptor_s wilddsc
1037 = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};
1038 struct dsc$descriptor_vs rsdsc
1039 = {sizeof rslt, DSC$K_DTYPE_VT, DSC$K_CLASS_VS, rslt};
1040 unsigned long int cxt = 0, sts = 0, ok = 1, hasdir = 0, hasver = 0, isunix = 0;
1041
1042 /* We could find out if there's an explicit dev/dir or version
1043 by peeking into lib$find_file's internal context at
1044 ((struct NAM *)((struct FAB *)cxt)->fab$l_nam)->nam$l_fnb
1045 but that's unsupported, so I don't want to do it now and
1046 have it bite someone in the future. */
1047 strcat(tmpfnam,tmpnam(NULL));
1048 cp = SvPV(tmpglob,i);
1049 for (; i; i--) {
1050 if (cp[i] == ';') hasver = 1;
1051 if (cp[i] == '.') {
1052 if (sts) hasver = 1;
1053 else sts = 1;
1054 }
1055 if (cp[i] == '/') {
1056 hasdir = isunix = 1;
1057 break;
748a9306 1058 }
a0d0e21e
LW
1059 if (cp[i] == ']' || cp[i] == '>' || cp[i] == ':') {
1060 hasdir = 1;
1061 break;
1062 }
1063 }
760ac839 1064 if ((tmpfp = PerlIO_open(tmpfnam,"w+","fop=dlt")) != NULL) {
a0d0e21e
LW
1065 ok = ((wilddsc.dsc$a_pointer = tovmsspec(SvPVX(tmpglob),vmsspec)) != NULL);
1066 if (ok) wilddsc.dsc$w_length = (unsigned short int) strlen(wilddsc.dsc$a_pointer);
1067 while (ok && ((sts = lib$find_file(&wilddsc,&rsdsc,&cxt,
1068 &dfltdsc,NULL,NULL,NULL))&1)) {
1069 end = rstr + (unsigned long int) *rslt;
1070 if (!hasver) while (*end != ';') end--;
1071 *(end++) = '\n'; *end = '\0';
1072 for (cp = rstr; *cp; cp++) *cp = _tolower(*cp);
1073 if (hasdir) {
f86702cc 1074 if (isunix) trim_unixpath(rstr,SvPVX(tmpglob),1);
a0d0e21e
LW
1075 begin = rstr;
1076 }
1077 else {
1078 begin = end;
1079 while (*(--begin) != ']' && *begin != '>') ;
1080 ++begin;
1081 }
760ac839 1082 ok = (PerlIO_puts(tmpfp,begin) != EOF);
a0d0e21e
LW
1083 }
1084 if (cxt) (void)lib$find_file_end(&cxt);
748a9306
LW
1085 if (ok && sts != RMS$_NMF &&
1086 sts != RMS$_DNF && sts != RMS$_FNF) ok = 0;
a0d0e21e 1087 if (!ok) {
c07a80fd
PP
1088 if (!(sts & 1)) {
1089 SETERRNO((sts == RMS$_SYN ? EINVAL : EVMSERR),sts);
1090 }
760ac839 1091 PerlIO_close(tmpfp);
a0d0e21e
LW
1092 fp = NULL;
1093 }
1094 else {
760ac839 1095 PerlIO_rewind(tmpfp);
a0d0e21e
LW
1096 IoTYPE(io) = '<';
1097 IoIFP(io) = fp = tmpfp;
1e422769 1098 IoFLAGS(io) &= ~IOf_UNTAINT; /* maybe redundant */
a0d0e21e
LW
1099 }
1100 }
1101 }
1102#else /* !VMS */
1103#ifdef DOSISH
67955e0c
PP
1104#ifdef OS2
1105 sv_setpv(tmpcmd, "for a in ");
1106 sv_catsv(tmpcmd, tmpglob);
1107 sv_catpv(tmpcmd, "; do echo \"$a\\0\\c\"; done |");
1108#else
a0d0e21e
LW
1109 sv_setpv(tmpcmd, "perlglob ");
1110 sv_catsv(tmpcmd, tmpglob);
1111 sv_catpv(tmpcmd, " |");
67955e0c
PP
1112#endif /* !OS2 */
1113#else /* !DOSISH */
1114#if defined(CSH)
a0d0e21e
LW
1115 sv_setpvn(tmpcmd, cshname, cshlen);
1116 sv_catpv(tmpcmd, " -cf 'set nonomatch; glob ");
1117 sv_catsv(tmpcmd, tmpglob);
16d20bd9 1118 sv_catpv(tmpcmd, "' 2>/dev/null |");
a0d0e21e
LW
1119#else
1120 sv_setpv(tmpcmd, "echo ");
1121 sv_catsv(tmpcmd, tmpglob);
1122#if 'z' - 'a' == 25
1123 sv_catpv(tmpcmd, "|tr -s ' \t\f\r' '\\012\\012\\012\\012'|");
1124#else
1125 sv_catpv(tmpcmd, "|tr -s ' \t\f\r' '\\n\\n\\n\\n'|");
1126#endif
1127#endif /* !CSH */
67955e0c 1128#endif /* !DOSISH */
c07a80fd
PP
1129 (void)do_open(last_in_gv, SvPVX(tmpcmd), SvCUR(tmpcmd),
1130 FALSE, 0, 0, Nullfp);
a0d0e21e
LW
1131 fp = IoIFP(io);
1132#endif /* !VMS */
1133 LEAVE;
1134 }
1135 }
1136 else if (type == OP_GLOB)
1137 SP--;
1138 }
1139 if (!fp) {
4633a7c4 1140 if (dowarn && io && !(IoFLAGS(io) & IOf_START))
a0d0e21e 1141 warn("Read on closed filehandle <%s>", GvENAME(last_in_gv));
54310121 1142 if (gimme == G_SCALAR) {
a0d0e21e
LW
1143 (void)SvOK_off(TARG);
1144 PUSHTARG;
1145 }
1146 RETURN;
1147 }
54310121 1148 if (gimme == G_SCALAR) {
a0d0e21e 1149 sv = TARG;
9607fc9c
PP
1150 if (SvROK(sv))
1151 sv_unref(sv);
a0d0e21e
LW
1152 (void)SvUPGRADE(sv, SVt_PV);
1153 tmplen = SvLEN(sv); /* remember if already alloced */
1154 if (!tmplen)
1155 Sv_Grow(sv, 80); /* try short-buffering it */
1156 if (type == OP_RCATLINE)
1157 offset = SvCUR(sv);
1158 else
1159 offset = 0;
1160 }
54310121
PP
1161 else {
1162 sv = sv_2mortal(NEWSV(57, 80));
1163 offset = 0;
1164 }
a0d0e21e
LW
1165 for (;;) {
1166 if (!sv_gets(sv, fp, offset)) {
760ac839 1167 PerlIO_clearerr(fp);
a0d0e21e
LW
1168 if (IoFLAGS(io) & IOf_ARGV) {
1169 fp = nextargv(last_in_gv);
1170 if (fp)
1171 continue;
1172 (void)do_close(last_in_gv, FALSE);
1173 IoFLAGS(io) |= IOf_START;
1174 }
1175 else if (type == OP_GLOB) {
5cd24f17
PP
1176 if (do_close(last_in_gv, FALSE) & ~0xFF)
1177 warn("internal error: glob failed");
a0d0e21e 1178 }
54310121 1179 if (gimme == G_SCALAR) {
a0d0e21e
LW
1180 (void)SvOK_off(TARG);
1181 PUSHTARG;
1182 }
1183 RETURN;
1184 }
bbce6d69
PP
1185 /* This should not be marked tainted if the fp is marked clean */
1186 if (!(IoFLAGS(io) & IOf_UNTAINT)) {
1187 TAINT;
1188 SvTAINTED_on(sv);
1189 }
a0d0e21e 1190 IoLINES(io)++;
71be2cbc 1191 SvSETMAGIC(sv);
a0d0e21e 1192 XPUSHs(sv);
a0d0e21e
LW
1193 if (type == OP_GLOB) {
1194 char *tmps;
1195
c07a80fd
PP
1196 if (SvCUR(sv) > 0 && SvCUR(rs) > 0) {
1197 tmps = SvEND(sv) - 1;
1198 if (*tmps == *SvPVX(rs)) {
1199 *tmps = '\0';
1200 SvCUR(sv)--;
1201 }
1202 }
a0d0e21e
LW
1203 for (tmps = SvPVX(sv); *tmps; tmps++)
1204 if (!isALPHA(*tmps) && !isDIGIT(*tmps) &&
1205 strchr("$&*(){}[]'\";\\|?<>~`", *tmps))
1206 break;
1207 if (*tmps && Stat(SvPVX(sv), &statbuf) < 0) {
1208 (void)POPs; /* Unmatched wildcard? Chuck it... */
1209 continue;
1210 }
1211 }
54310121 1212 if (gimme == G_ARRAY) {
a0d0e21e
LW
1213 if (SvLEN(sv) - SvCUR(sv) > 20) {
1214 SvLEN_set(sv, SvCUR(sv)+1);
1215 Renew(SvPVX(sv), SvLEN(sv), char);
1216 }
1217 sv = sv_2mortal(NEWSV(58, 80));
1218 continue;
1219 }
54310121 1220 else if (gimme == G_SCALAR && !tmplen && SvLEN(sv) - SvCUR(sv) > 80) {
a0d0e21e
LW
1221 /* try to reclaim a bit of scalar space (only on 1st alloc) */
1222 if (SvCUR(sv) < 60)
1223 SvLEN_set(sv, 80);
1224 else
1225 SvLEN_set(sv, SvCUR(sv)+40); /* allow some slop */
1226 Renew(SvPVX(sv), SvLEN(sv), char);
1227 }
1228 RETURN;
1229 }
1230}
1231
1232PP(pp_enter)
1233{
4e35701f 1234 djSP;
c09156bb 1235 register PERL_CONTEXT *cx;
54310121 1236 I32 gimme = OP_GIMME(op, -1);
a0d0e21e 1237
54310121
PP
1238 if (gimme == -1) {
1239 if (cxstack_ix >= 0)
1240 gimme = cxstack[cxstack_ix].blk_gimme;
1241 else
1242 gimme = G_SCALAR;
1243 }
a0d0e21e
LW
1244
1245 ENTER;
1246
1247 SAVETMPS;
1248 PUSHBLOCK(cx, CXt_BLOCK, sp);
1249
1250 RETURN;
1251}
1252
1253PP(pp_helem)
1254{
4e35701f 1255 djSP;
760ac839 1256 HE* he;
ae77835f 1257 SV **svp;
a0d0e21e 1258 SV *keysv = POPs;
a0d0e21e 1259 HV *hv = (HV*)POPs;
68dc0745
PP
1260 U32 lval = op->op_flags & OPf_MOD;
1261 U32 defer = op->op_private & OPpLVAL_DEFER;
a0d0e21e 1262
ae77835f
MB
1263 if (SvTYPE(hv) == SVt_PVHV) {
1264 he = hv_fetch_ent(hv, keysv, lval && !defer, 0);
97fcbf96 1265 svp = he ? &HeVAL(he) : 0;
ae77835f
MB
1266 }
1267 else if (SvTYPE(hv) == SVt_PVAV) {
97fcbf96 1268 svp = avhv_fetch_ent((AV*)hv, keysv, lval && !defer, 0);
ae77835f 1269 }
c750a3ec 1270 else {
a0d0e21e 1271 RETPUSHUNDEF;
c750a3ec 1272 }
a0d0e21e 1273 if (lval) {
97fcbf96 1274 if (!svp || *svp == &sv_undef) {
68dc0745
PP
1275 SV* lv;
1276 SV* key2;
1277 if (!defer)
1278 DIE(no_helem, SvPV(keysv, na));
1279 lv = sv_newmortal();
1280 sv_upgrade(lv, SVt_PVLV);
1281 LvTYPE(lv) = 'y';
1282 sv_magic(lv, key2 = newSVsv(keysv), 'y', Nullch, 0);
1283 SvREFCNT_dec(key2); /* sv_magic() increments refcount */
1284 LvTARG(lv) = SvREFCNT_inc(hv);
1285 LvTARGLEN(lv) = 1;
1286 PUSHs(lv);
1287 RETURN;
1288 }
5f05dabc 1289 if (op->op_private & OPpLVAL_INTRO) {
ae77835f
MB
1290 if (HvNAME(hv) && isGV(*svp))
1291 save_gp((GV*)*svp, !(op->op_flags & OPf_SPECIAL));
5f05dabc 1292 else
ae77835f 1293 save_svref(svp);
5f05dabc
PP
1294 }
1295 else if (op->op_private & OPpDEREF)
ae77835f 1296 vivify_ref(*svp, op->op_private & OPpDEREF);
a0d0e21e
LW
1297 }
1298 PUSHs(svp ? *svp : &sv_undef);
1299 RETURN;
1300}
1301
1302PP(pp_leave)
1303{
4e35701f 1304 djSP;
c09156bb 1305 register PERL_CONTEXT *cx;
a0d0e21e
LW
1306 register SV **mark;
1307 SV **newsp;
1308 PMOP *newpm;
1309 I32 gimme;
1310
1311 if (op->op_flags & OPf_SPECIAL) {
1312 cx = &cxstack[cxstack_ix];
1313 cx->blk_oldpm = curpm; /* fake block should preserve $1 et al */
1314 }
1315
1316 POPBLOCK(cx,newpm);
1317
54310121
PP
1318 gimme = OP_GIMME(op, -1);
1319 if (gimme == -1) {
1320 if (cxstack_ix >= 0)
1321 gimme = cxstack[cxstack_ix].blk_gimme;
1322 else
1323 gimme = G_SCALAR;
1324 }
a0d0e21e 1325
a1f49e72 1326 TAINT_NOT;
54310121
PP
1327 if (gimme == G_VOID)
1328 SP = newsp;
1329 else if (gimme == G_SCALAR) {
1330 MARK = newsp + 1;
1331 if (MARK <= SP)
1332 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
1333 *MARK = TOPs;
1334 else
1335 *MARK = sv_mortalcopy(TOPs);
a0d0e21e 1336 else {
54310121
PP
1337 MEXTEND(mark,0);
1338 *MARK = &sv_undef;
a0d0e21e 1339 }
54310121 1340 SP = MARK;
a0d0e21e 1341 }
54310121 1342 else if (gimme == G_ARRAY) {
a1f49e72
CS
1343 /* in case LEAVE wipes old return values */
1344 for (mark = newsp + 1; mark <= SP; mark++) {
1345 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
a0d0e21e 1346 *mark = sv_mortalcopy(*mark);
a1f49e72
CS
1347 TAINT_NOT; /* Each item is independent */
1348 }
1349 }
a0d0e21e
LW
1350 }
1351 curpm = newpm; /* Don't pop $1 et al till now */
1352
1353 LEAVE;
1354
1355 RETURN;
1356}
1357
1358PP(pp_iter)
1359{
4e35701f 1360 djSP;
c09156bb 1361 register PERL_CONTEXT *cx;
5f05dabc 1362 SV* sv;
4633a7c4 1363 AV* av;
a0d0e21e
LW
1364
1365 EXTEND(sp, 1);
1366 cx = &cxstack[cxstack_ix];
1367 if (cx->cx_type != CXt_LOOP)
1368 DIE("panic: pp_iter");
1369
4633a7c4 1370 av = cx->blk_loop.iterary;
71be2cbc 1371 if (cx->blk_loop.iterix >= (av == curstack ? cx->blk_oldsp : AvFILL(av)))
4633a7c4 1372 RETPUSHNO;
a0d0e21e 1373
7a4c00b4 1374 SvREFCNT_dec(*cx->blk_loop.itervar);
a0d0e21e 1375
5f05dabc 1376 if (sv = AvARRAY(av)[++cx->blk_loop.iterix])
a0d0e21e 1377 SvTEMP_off(sv);
a0d0e21e 1378 else
5f05dabc
PP
1379 sv = &sv_undef;
1380 if (av != curstack && SvIMMORTAL(sv)) {
1381 SV *lv = cx->blk_loop.iterlval;
71be2cbc
PP
1382 if (lv && SvREFCNT(lv) > 1) {
1383 SvREFCNT_dec(lv);
1384 lv = Nullsv;
1385 }
5f05dabc
PP
1386 if (lv)
1387 SvREFCNT_dec(LvTARG(lv));
1388 else {
68dc0745 1389 lv = cx->blk_loop.iterlval = NEWSV(26, 0);
5f05dabc 1390 sv_upgrade(lv, SVt_PVLV);
5f05dabc 1391 LvTYPE(lv) = 'y';
68dc0745 1392 sv_magic(lv, Nullsv, 'y', Nullch, 0);
5f05dabc
PP
1393 }
1394 LvTARG(lv) = SvREFCNT_inc(av);
1395 LvTARGOFF(lv) = cx->blk_loop.iterix;
8ac85365 1396 LvTARGLEN(lv) = (UV) -1;
5f05dabc
PP
1397 sv = (SV*)lv;
1398 }
a0d0e21e 1399
7a4c00b4 1400 *cx->blk_loop.itervar = SvREFCNT_inc(sv);
a0d0e21e
LW
1401 RETPUSHYES;
1402}
1403
1404PP(pp_subst)
1405{
4e35701f 1406 djSP; dTARG;
a0d0e21e
LW
1407 register PMOP *pm = cPMOP;
1408 PMOP *rpm = pm;
1409 register SV *dstr;
1410 register char *s;
1411 char *strend;
1412 register char *m;
1413 char *c;
1414 register char *d;
1415 STRLEN clen;
1416 I32 iters = 0;
1417 I32 maxiters;
1418 register I32 i;
1419 bool once;
71be2cbc 1420 bool rxtainted;
a0d0e21e
LW
1421 char *orig;
1422 I32 safebase;
1423 register REGEXP *rx = pm->op_pmregexp;
1424 STRLEN len;
1425 int force_on_match = 0;
4633a7c4 1426 I32 oldsave = savestack_ix;
c277df42
IZ
1427 I32 update_minmatch = 1;
1428 SV *screamer;
a0d0e21e 1429
5cd24f17
PP
1430 /* known replacement string? */
1431 dstr = (pm->op_pmflags & PMf_CONST) ? POPs : Nullsv;
a0d0e21e
LW
1432 if (op->op_flags & OPf_STACKED)
1433 TARG = POPs;
1434 else {
54b9620d 1435 TARG = DEFSV;
a0d0e21e
LW
1436 EXTEND(SP,1);
1437 }
68dc0745
PP
1438 if (SvREADONLY(TARG)
1439 || (SvTYPE(TARG) > SVt_PVLV
1440 && !(SvTYPE(TARG) == SVt_PVGV && SvFAKE(TARG))))
1441 croak(no_modify);
a0d0e21e 1442 s = SvPV(TARG, len);
68dc0745 1443 if (!SvPOKp(TARG) || SvTYPE(TARG) == SVt_PVGV)
a0d0e21e 1444 force_on_match = 1;
9212bbba 1445 TAINT_NOT;
a0d0e21e
LW
1446
1447 force_it:
1448 if (!pm || !s)
1449 DIE("panic: do_subst");
1450
1451 strend = s + len;
1452 maxiters = (strend - s) + 10;
1453
1454 if (!rx->prelen && curpm) {
1455 pm = curpm;
1456 rx = pm->op_pmregexp;
1457 }
c277df42
IZ
1458 screamer = ( (SvSCREAM(TARG) && rx->check_substr
1459 && SvTYPE(rx->check_substr) == SVt_PVBM
1460 && SvVALID(rx->check_substr))
1461 ? TARG : Nullsv);
1462 safebase = (!rx->nparens && !sawampersand) ? 0 : REXEC_COPY_STR;
a0d0e21e
LW
1463 if (pm->op_pmflags & (PMf_MULTILINE|PMf_SINGLELINE)) {
1464 SAVEINT(multiline);
1465 multiline = pm->op_pmflags & PMf_MULTILINE;
1466 }
1467 orig = m = s;
c277df42
IZ
1468 if (rx->check_substr) {
1469 if (!(rx->reganch & ROPT_NOSCAN)) { /* It floats. */
1470 if (screamer) {
1471 I32 p = -1;
1472
1473 if (screamfirst[BmRARE(rx->check_substr)] < 0)
a0d0e21e 1474 goto nope;
c277df42 1475 else if (!(s = screaminstr(TARG, rx->check_substr, rx->check_offset_min, 0, &p, 0)))
a0d0e21e
LW
1476 goto nope;
1477 }
c277df42
IZ
1478 else if (!(s = fbm_instr((unsigned char*)s + rx->check_offset_min,
1479 (unsigned char*)strend,
1480 rx->check_substr)))
a0d0e21e 1481 goto nope;
c277df42
IZ
1482 if (s && rx->check_offset_max < s - m) {
1483 ++BmUSEFUL(rx->check_substr);
1484 s -= rx->check_offset_max;
a0d0e21e
LW
1485 }
1486 else
1487 s = m;
1488 }
c277df42
IZ
1489 /* Now checkstring is fixed, i.e. at fixed offset from the
1490 beginning of match, and the match is anchored at s. */
1491 else if (!multiline) { /* Anchored at beginning of string. */
1492 I32 slen;
1493 if (*SvPVX(rx->check_substr) != s[rx->check_offset_min]
1494 || ((slen = SvCUR(rx->check_substr)) > 1
1495 && memNE(SvPVX(rx->check_substr),
1496 s + rx->check_offset_min, slen)))
bbce6d69 1497 goto nope;
a0d0e21e 1498 }
c277df42
IZ
1499 if (!rx->naughty && --BmUSEFUL(rx->check_substr) < 0
1500 && rx->check_substr == rx->float_substr) {
1501 SvREFCNT_dec(rx->check_substr);
1502 rx->check_substr = Nullsv; /* opt is being useless */
1503 rx->float_substr = Nullsv;
a0d0e21e
LW
1504 }
1505 }
71be2cbc
PP
1506
1507 /* only replace once? */
a0d0e21e 1508 once = !(rpm->op_pmflags & PMf_GLOBAL);
71be2cbc
PP
1509
1510 /* known replacement string? */
5cd24f17 1511 c = dstr ? SvPV(dstr, clen) : Nullch;
71be2cbc
PP
1512
1513 /* can do inplace substitution? */
c277df42
IZ
1514 if (c && clen <= rx->minlen && (once || !(safebase & REXEC_COPY_STR))
1515 && !(rx->reganch & ROPT_LOOKBEHIND_SEEN)) {
1516 if (!regexec_flags(rx, s, strend, orig, 0, screamer, NULL, safebase)) {
71be2cbc
PP
1517 PUSHs(&sv_no);
1518 LEAVE_SCOPE(oldsave);
1519 RETURN;
1520 }
1521 if (force_on_match) {
1522 force_on_match = 0;
1523 s = SvPV_force(TARG, len);
1524 goto force_it;
1525 }
71be2cbc
PP
1526 d = s;
1527 curpm = pm;
1528 SvSCREAM_off(TARG); /* disable possible screamer */
1529 if (once) {
c277df42
IZ
1530 rxtainted = RX_MATCH_TAINTED(rx);
1531 if (rx->subbase) {
1532 m = orig + (rx->startp[0] - rx->subbase);
1533 d = orig + (rx->endp[0] - rx->subbase);
1534 } else {
1535 m = rx->startp[0];
1536 d = rx->endp[0];
1537 }
71be2cbc
PP
1538 s = orig;
1539 if (m - s > strend - d) { /* faster to shorten from end */
1540 if (clen) {
1541 Copy(c, m, clen, char);
1542 m += clen;
a0d0e21e 1543 }
71be2cbc
PP
1544 i = strend - d;
1545 if (i > 0) {
1546 Move(d, m, i, char);
1547 m += i;
a0d0e21e 1548 }
71be2cbc
PP
1549 *m = '\0';
1550 SvCUR_set(TARG, m - s);
1551 }
1552 /*SUPPRESS 560*/
1553 else if (i = m - s) { /* faster from front */
1554 d -= clen;
1555 m = d;
1556 sv_chop(TARG, d-i);
1557 s += i;
1558 while (i--)
1559 *--d = *--s;
1560 if (clen)
1561 Copy(c, m, clen, char);
1562 }
1563 else if (clen) {
1564 d -= clen;
1565 sv_chop(TARG, d);
1566 Copy(c, d, clen, char);
1567 }
1568 else {
1569 sv_chop(TARG, d);
1570 }
9212bbba 1571 TAINT_IF(rxtainted);
71be2cbc
PP
1572 PUSHs(&sv_yes);
1573 }
1574 else {
1575 rxtainted = 0;
1576 do {
1577 if (iters++ > maxiters)
1578 DIE("Substitution loop");
c277df42 1579 rxtainted |= RX_MATCH_TAINTED(rx);
71be2cbc
PP
1580 m = rx->startp[0];
1581 /*SUPPRESS 560*/
1582 if (i = m - s) {
1583 if (s != d)
1584 Move(s, d, i, char);
1585 d += i;
a0d0e21e 1586 }
71be2cbc
PP
1587 if (clen) {
1588 Copy(c, d, clen, char);
1589 d += clen;
1590 }
1591 s = rx->endp[0];
c277df42
IZ
1592 } while (regexec_flags(rx, s, strend, orig, s == m,
1593 Nullsv, NULL, 0)); /* don't match same null twice */
71be2cbc
PP
1594 if (s != d) {
1595 i = strend - s;
1596 SvCUR_set(TARG, d - SvPVX(TARG) + i);
1597 Move(s, d, i+1, char); /* include the NUL */
a0d0e21e 1598 }
9212bbba 1599 TAINT_IF(rxtainted);
71be2cbc 1600 PUSHs(sv_2mortal(newSViv((I32)iters)));
a0d0e21e 1601 }
71be2cbc
PP
1602 (void)SvPOK_only(TARG);
1603 SvSETMAGIC(TARG);
9212bbba 1604 SvTAINT(TARG);
71be2cbc
PP
1605 LEAVE_SCOPE(oldsave);
1606 RETURN;
a0d0e21e 1607 }
71be2cbc 1608
c277df42 1609 if (regexec_flags(rx, s, strend, orig, 0, screamer, NULL, safebase)) {
a0d0e21e
LW
1610 if (force_on_match) {
1611 force_on_match = 0;
1612 s = SvPV_force(TARG, len);
1613 goto force_it;
1614 }
c277df42 1615 rxtainted = RX_MATCH_TAINTED(rx);
a0d0e21e
LW
1616 dstr = NEWSV(25, sv_len(TARG));
1617 sv_setpvn(dstr, m, s-m);
1618 curpm = pm;
1619 if (!c) {
c09156bb 1620 register PERL_CONTEXT *cx;
a0d0e21e
LW
1621 PUSHSUBST(cx);
1622 RETURNOP(cPMOP->op_pmreplroot);
1623 }
1624 do {
1625 if (iters++ > maxiters)
1626 DIE("Substitution loop");
c277df42 1627 rxtainted |= RX_MATCH_TAINTED(rx);
a0d0e21e
LW
1628 if (rx->subbase && rx->subbase != orig) {
1629 m = s;
1630 s = orig;
1631 orig = rx->subbase;
1632 s = orig + (m - s);
1633 strend = s + (strend - m);
1634 }
1635 m = rx->startp[0];
1636 sv_catpvn(dstr, s, m-s);
1637 s = rx->endp[0];
1638 if (clen)
1639 sv_catpvn(dstr, c, clen);
1640 if (once)
1641 break;
c277df42 1642 } while (regexec_flags(rx, s, strend, orig, s == m, Nullsv, NULL, safebase));
a0d0e21e 1643 sv_catpvn(dstr, s, strend - s);
748a9306 1644
9212bbba
CS
1645 TAINT_IF(rxtainted);
1646
4633a7c4 1647 (void)SvOOK_off(TARG);
cb0b1708 1648 Safefree(SvPVX(TARG));
748a9306
LW
1649 SvPVX(TARG) = SvPVX(dstr);
1650 SvCUR_set(TARG, SvCUR(dstr));
1651 SvLEN_set(TARG, SvLEN(dstr));
1652 SvPVX(dstr) = 0;
1653 sv_free(dstr);
1654
a0d0e21e
LW
1655 (void)SvPOK_only(TARG);
1656 SvSETMAGIC(TARG);
9212bbba 1657 SvTAINT(TARG);
a0d0e21e 1658 PUSHs(sv_2mortal(newSViv((I32)iters)));
4633a7c4 1659 LEAVE_SCOPE(oldsave);
a0d0e21e
LW
1660 RETURN;
1661 }
5cd24f17 1662 goto ret_no;
a0d0e21e
LW
1663
1664nope:
c277df42 1665 ++BmUSEFUL(rx->check_substr);
5cd24f17
PP
1666
1667ret_no:
a0d0e21e 1668 PUSHs(&sv_no);
4633a7c4 1669 LEAVE_SCOPE(oldsave);
a0d0e21e
LW
1670 RETURN;
1671}
1672
1673PP(pp_grepwhile)
1674{
4e35701f 1675 djSP;
a0d0e21e
LW
1676
1677 if (SvTRUEx(POPs))
1678 stack_base[markstack_ptr[-1]++] = stack_base[*markstack_ptr];
1679 ++*markstack_ptr;
1680 LEAVE; /* exit inner scope */
1681
1682 /* All done yet? */
1683 if (stack_base + *markstack_ptr > sp) {
1684 I32 items;
54310121 1685 I32 gimme = GIMME_V;
a0d0e21e
LW
1686
1687 LEAVE; /* exit outer scope */
1688 (void)POPMARK; /* pop src */
1689 items = --*markstack_ptr - markstack_ptr[-1];
1690 (void)POPMARK; /* pop dst */
1691 SP = stack_base + POPMARK; /* pop original mark */
54310121 1692 if (gimme == G_SCALAR) {
a0d0e21e
LW
1693 dTARGET;
1694 XPUSHi(items);
a0d0e21e 1695 }
54310121
PP
1696 else if (gimme == G_ARRAY)
1697 SP += items;
a0d0e21e
LW
1698 RETURN;
1699 }
1700 else {
1701 SV *src;
1702
1703 ENTER; /* enter inner scope */
1704 SAVESPTR(curpm);
1705
1706 src = stack_base[*markstack_ptr];
1707 SvTEMP_off(src);
54b9620d 1708 DEFSV = src;
a0d0e21e
LW
1709
1710 RETURNOP(cLOGOP->op_other);
1711 }
1712}
1713
1714PP(pp_leavesub)
1715{
4e35701f 1716 djSP;
a0d0e21e
LW
1717 SV **mark;
1718 SV **newsp;
1719 PMOP *newpm;
1720 I32 gimme;
c09156bb 1721 register PERL_CONTEXT *cx;
f86702cc 1722 struct block_sub cxsub;
a0d0e21e
LW
1723
1724 POPBLOCK(cx,newpm);
f86702cc
PP
1725 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1726
a1f49e72 1727 TAINT_NOT;
a0d0e21e
LW
1728 if (gimme == G_SCALAR) {
1729 MARK = newsp + 1;
1730 if (MARK <= SP)
f86702cc 1731 *MARK = SvTEMP(TOPs) ? TOPs : sv_mortalcopy(TOPs);
a0d0e21e 1732 else {
f86702cc 1733 MEXTEND(MARK, 0);
a0d0e21e
LW
1734 *MARK = &sv_undef;
1735 }
1736 SP = MARK;
1737 }
54310121 1738 else if (gimme == G_ARRAY) {
f86702cc 1739 for (MARK = newsp + 1; MARK <= SP; MARK++) {
a1f49e72 1740 if (!SvTEMP(*MARK)) {
f86702cc 1741 *MARK = sv_mortalcopy(*MARK);
a1f49e72
CS
1742 TAINT_NOT; /* Each item is independent */
1743 }
f86702cc 1744 }
a0d0e21e 1745 }
f86702cc
PP
1746 PUTBACK;
1747
1748 POPSUB2(); /* Stack values are safe: release CV and @_ ... */
1749 curpm = newpm; /* ... and pop $1 et al */
a0d0e21e
LW
1750
1751 LEAVE;
a0d0e21e
LW
1752 return pop_return();
1753}
1754
3de9ffa1 1755static CV *
8ac85365 1756get_db_sub(SV **svp, CV *cv)
3de9ffa1
MB
1757{
1758 dTHR;
4f01c5a5 1759 SV *oldsv = *svp;
3de9ffa1 1760 GV *gv;
3de9ffa1 1761
4f01c5a5
MB
1762 *svp = GvSV(DBsub);
1763 save_item(*svp);
3de9ffa1
MB
1764 gv = CvGV(cv);
1765 if ( (CvFLAGS(cv) & (CVf_ANON | CVf_CLONED))
1766 || strEQ(GvNAME(gv), "END")
1767 || ((GvCV(gv) != cv) && /* Could be imported, and old sub redefined. */
1768 !( (SvTYPE(oldsv) == SVt_PVGV) && (GvCV((GV*)oldsv) == cv)
1769 && (gv = (GV*)oldsv) ))) {
1770 /* Use GV from the stack as a fallback. */
1771 /* GV is potentially non-unique, or contain different CV. */
4f01c5a5 1772 sv_setsv(*svp, newRV((SV*)cv));
3de9ffa1
MB
1773 }
1774 else {
4f01c5a5 1775 gv_efullname3(*svp, gv, Nullch);
3de9ffa1
MB
1776 }
1777 cv = GvCV(DBsub);
1778 if (CvXSUB(cv))
1779 curcopdb = curcop;
1780 return cv;
1781}
1782
a0d0e21e
LW
1783PP(pp_entersub)
1784{
4e35701f 1785 djSP; dPOPss;
a0d0e21e
LW
1786 GV *gv;
1787 HV *stash;
1788 register CV *cv;
c09156bb 1789 register PERL_CONTEXT *cx;
5d94fbed 1790 I32 gimme;
07055b4c 1791 bool hasargs = (op->op_flags & OPf_STACKED) != 0;
a0d0e21e
LW
1792
1793 if (!sv)
1794 DIE("Not a CODE reference");
1795 switch (SvTYPE(sv)) {
1796 default:
1797 if (!SvROK(sv)) {
748a9306
LW
1798 char *sym;
1799
fb73857a
PP
1800 if (sv == &sv_yes) { /* unfound import, ignore */
1801 if (hasargs)
1802 SP = stack_base + POPMARK;
a0d0e21e 1803 RETURN;
fb73857a 1804 }
15ff848f
CS
1805 if (SvGMAGICAL(sv)) {
1806 mg_get(sv);
1807 sym = SvPOKp(sv) ? SvPVX(sv) : Nullch;
1808 }
1809 else
1810 sym = SvPV(sv, na);
1811 if (!sym)
a0d0e21e
LW
1812 DIE(no_usym, "a subroutine");
1813 if (op->op_private & HINT_STRICT_REFS)
748a9306
LW
1814 DIE(no_symref, sym, "a subroutine");
1815 cv = perl_get_cv(sym, TRUE);
a0d0e21e
LW
1816 break;
1817 }
1818 cv = (CV*)SvRV(sv);
1819 if (SvTYPE(cv) == SVt_PVCV)
1820 break;
1821 /* FALL THROUGH */
1822 case SVt_PVHV:
1823 case SVt_PVAV:
1824 DIE("Not a CODE reference");
1825 case SVt_PVCV:
1826 cv = (CV*)sv;
1827 break;
1828 case SVt_PVGV:
8ebc5c01 1829 if (!(cv = GvCVu((GV*)sv)))
a0d0e21e
LW
1830 cv = sv_2cv(sv, &stash, &gv, TRUE);
1831 break;
1832 }
1833
1834 ENTER;
1835 SAVETMPS;
1836
1837 retry:
1838 if (!cv)
1839 DIE("Not a CODE reference");
1840
1841 if (!CvROOT(cv) && !CvXSUB(cv)) {
44a8e56a 1842 GV* autogv;
22239a37 1843 SV* sub_name;
44a8e56a
PP
1844
1845 /* anonymous or undef'd function leaves us no recourse */
1846 if (CvANON(cv) || !(gv = CvGV(cv)))
1847 DIE("Undefined subroutine called");
1848 /* autoloaded stub? */
1849 if (cv != GvCV(gv)) {
1850 cv = GvCV(gv);
1851 goto retry;
a0d0e21e 1852 }
44a8e56a 1853 /* should call AUTOLOAD now? */
54310121
PP
1854 if ((autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv), GvNAMELEN(gv),
1855 FALSE)))
1856 {
44a8e56a
PP
1857 cv = GvCV(autogv);
1858 goto retry;
a0d0e21e 1859 }
44a8e56a 1860 /* sorry */
22239a37
NIS
1861 sub_name = sv_newmortal();
1862 gv_efullname3(sub_name, gv, Nullch);
1863 DIE("Undefined subroutine &%s called", SvPVX(sub_name));
a0d0e21e
LW
1864 }
1865
54310121 1866 gimme = GIMME_V;
3de9ffa1 1867 if ((op->op_private & OPpENTERSUB_DB) && GvCV(DBsub) && !CvNODEBUG(cv))
4f01c5a5 1868 cv = get_db_sub(&sv, cv);
3de9ffa1
MB
1869 if (!cv)
1870 DIE("No DBsub routine");
a0d0e21e 1871
11343788 1872#ifdef USE_THREADS
3de9ffa1
MB
1873 /*
1874 * First we need to check if the sub or method requires locking.
458fb581
MB
1875 * If so, we gain a lock on the CV, the first argument or the
1876 * stash (for static methods), as appropriate. This has to be
1877 * inline because for FAKE_THREADS, COND_WAIT inlines code to
1878 * reschedule by returning a new op.
3de9ffa1 1879 */
11343788 1880 MUTEX_LOCK(CvMUTEXP(cv));
77a005ab
MB
1881 if (CvFLAGS(cv) & CVf_LOCKED) {
1882 MAGIC *mg;
1883 if (CvFLAGS(cv) & CVf_METHOD) {
1884 if (SP > stack_base + TOPMARK)
1885 sv = *(stack_base + TOPMARK + 1);
1886 else {
1887 MUTEX_UNLOCK(CvMUTEXP(cv));
1888 croak("no argument for locked method call");
1889 }
1890 if (SvROK(sv))
1891 sv = SvRV(sv);
458fb581
MB
1892 else {
1893 STRLEN len;
1894 char *stashname = SvPV(sv, len);
1895 sv = (SV*)gv_stashpvn(stashname, len, TRUE);
1896 }
77a005ab
MB
1897 }
1898 else {
1899 sv = (SV*)cv;
1900 }
1901 MUTEX_UNLOCK(CvMUTEXP(cv));
1902 mg = condpair_magic(sv);
1903 MUTEX_LOCK(MgMUTEXP(mg));
1904 if (MgOWNER(mg) == thr)
1905 MUTEX_UNLOCK(MgMUTEXP(mg));
1906 else {
1907 while (MgOWNER(mg))
1908 COND_WAIT(MgOWNERCONDP(mg), MgMUTEXP(mg));
1909 MgOWNER(mg) = thr;
1fd28e87
MB
1910 DEBUG_L(PerlIO_printf(PerlIO_stderr(), "%p: pp_entersub lock %p\n",
1911 thr, sv);)
77a005ab 1912 MUTEX_UNLOCK(MgMUTEXP(mg));
e55aaa0e 1913 SvREFCNT_inc(sv); /* Keep alive until magic_mutexfree */
77a005ab 1914 save_destructor(unlock_condpair, sv);
11343788 1915 }
77a005ab 1916 MUTEX_LOCK(CvMUTEXP(cv));
11343788 1917 }
3de9ffa1
MB
1918 /*
1919 * Now we have permission to enter the sub, we must distinguish
1920 * four cases. (0) It's an XSUB (in which case we don't care
1921 * about ownership); (1) it's ours already (and we're recursing);
1922 * (2) it's free (but we may already be using a cached clone);
1923 * (3) another thread owns it. Case (1) is easy: we just use it.
1924 * Case (2) means we look for a clone--if we have one, use it
1925 * otherwise grab ownership of cv. Case (3) means we look for a
1926 * clone (for non-XSUBs) and have to create one if we don't
1927 * already have one.
1928 * Why look for a clone in case (2) when we could just grab
1929 * ownership of cv straight away? Well, we could be recursing,
1930 * i.e. we originally tried to enter cv while another thread
1931 * owned it (hence we used a clone) but it has been freed up
1932 * and we're now recursing into it. It may or may not be "better"
1933 * to use the clone but at least CvDEPTH can be trusted.
1934 */
1935 if (CvOWNER(cv) == thr || CvXSUB(cv))
1936 MUTEX_UNLOCK(CvMUTEXP(cv));
11343788 1937 else {
3de9ffa1
MB
1938 /* Case (2) or (3) */
1939 SV **svp;
1940
11343788 1941 /*
3de9ffa1
MB
1942 * XXX Might it be better to release CvMUTEXP(cv) while we
1943 * do the hv_fetch? We might find someone has pinched it
1944 * when we look again, in which case we would be in case
1945 * (3) instead of (2) so we'd have to clone. Would the fact
1946 * that we released the mutex more quickly make up for this?
1947 */
199100c8 1948 svp = hv_fetch(thr->cvcache, (char *)cv, sizeof(cv), FALSE);
3de9ffa1
MB
1949 if (svp) {
1950 /* We already have a clone to use */
11343788 1951 MUTEX_UNLOCK(CvMUTEXP(cv));
3de9ffa1
MB
1952 cv = *(CV**)svp;
1953 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
1fd28e87
MB
1954 "entersub: %p already has clone %p:%s\n",
1955 thr, cv, SvPEEK((SV*)cv)));
3de9ffa1
MB
1956 CvOWNER(cv) = thr;
1957 SvREFCNT_inc(cv);
1958 if (CvDEPTH(cv) == 0)
1959 SAVEDESTRUCTOR(unset_cvowner, (void*) cv);
1960 }
11343788 1961 else {
3de9ffa1
MB
1962 /* (2) => grab ownership of cv. (3) => make clone */
1963 if (!CvOWNER(cv)) {
1964 CvOWNER(cv) = thr;
1965 SvREFCNT_inc(cv);
11343788 1966 MUTEX_UNLOCK(CvMUTEXP(cv));
d9f997d7 1967 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
1fd28e87
MB
1968 "entersub: %p grabbing %p:%s in stash %s\n",
1969 thr, cv, SvPEEK((SV*)cv), CvSTASH(cv) ?
3de9ffa1
MB
1970 HvNAME(CvSTASH(cv)) : "(none)"));
1971 } else {
1972 /* Make a new clone. */
1973 CV *clonecv;
1974 SvREFCNT_inc(cv); /* don't let it vanish from under us */
1975 MUTEX_UNLOCK(CvMUTEXP(cv));
1976 DEBUG_L((PerlIO_printf(PerlIO_stderr(),
1fd28e87
MB
1977 "entersub: %p cloning %p:%s\n",
1978 thr, cv, SvPEEK((SV*)cv))));
3de9ffa1
MB
1979 /*
1980 * We're creating a new clone so there's no race
1981 * between the original MUTEX_UNLOCK and the
1982 * SvREFCNT_inc since no one will be trying to undef
1983 * it out from underneath us. At least, I don't think
1984 * there's a race...
1985 */
1986 clonecv = cv_clone(cv);
1987 SvREFCNT_dec(cv); /* finished with this */
199100c8 1988 hv_store(thr->cvcache, (char*)cv, sizeof(cv), (SV*)clonecv,0);
3de9ffa1
MB
1989 CvOWNER(clonecv) = thr;
1990 cv = clonecv;
11343788 1991 SvREFCNT_inc(cv);
11343788 1992 }
3de9ffa1
MB
1993 DEBUG_L(if (CvDEPTH(cv) != 0)
1994 PerlIO_printf(PerlIO_stderr(), "depth %ld != 0\n",
1995 CvDEPTH(cv)););
1996 SAVEDESTRUCTOR(unset_cvowner, (void*) cv);
11343788 1997 }
3de9ffa1 1998 }
11343788
MB
1999#endif /* USE_THREADS */
2000
2001 gimme = GIMME;
2002
a0d0e21e
LW
2003 if (CvXSUB(cv)) {
2004 if (CvOLDSTYLE(cv)) {
ecfc5424 2005 I32 (*fp3)_((int,int,int));
a0d0e21e
LW
2006 dMARK;
2007 register I32 items = SP - MARK;
67955e0c 2008 /* We dont worry to copy from @_. */
a0d0e21e
LW
2009 while (sp > mark) {
2010 sp[1] = sp[0];
2011 sp--;
2012 }
2013 stack_sp = mark + 1;
ecfc5424
AD
2014 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
2015 items = (*fp3)(CvXSUBANY(cv).any_i32,
2016 MARK - stack_base + 1,
2017 items);
a0d0e21e
LW
2018 stack_sp = stack_base + items;
2019 }
2020 else {
748a9306
LW
2021 I32 markix = TOPMARK;
2022
a0d0e21e 2023 PUTBACK;
67955e0c
PP
2024
2025 if (!hasargs) {
2026 /* Need to copy @_ to stack. Alternative may be to
2027 * switch stack to @_, and copy return values
2028 * back. This would allow popping @_ in XSUB, e.g.. XXXX */
6d4ff0d2
MB
2029 AV* av;
2030 I32 items;
2031#ifdef USE_THREADS
2032 av = (AV*)curpad[0];
2033#else
2034 av = GvAV(defgv);
2035#endif /* USE_THREADS */
2036 items = AvFILL(av) + 1;
67955e0c
PP
2037
2038 if (items) {
2039 /* Mark is at the end of the stack. */
2040 EXTEND(sp, items);
2041 Copy(AvARRAY(av), sp + 1, items, SV*);
2042 sp += items;
2043 PUTBACK ;
2044 }
2045 }
2046 if (curcopdb) { /* We assume that the first
2047 XSUB in &DB::sub is the
2048 called one. */
2049 SAVESPTR(curcop);
2050 curcop = curcopdb;
2051 curcopdb = NULL;
2052 }
2053 /* Do we need to open block here? XXXX */
a0d0e21e 2054 (void)(*CvXSUB(cv))(cv);
748a9306
LW
2055
2056 /* Enforce some sanity in scalar context. */
5d94fbed 2057 if (gimme == G_SCALAR && ++markix != stack_sp - stack_base ) {
748a9306
LW
2058 if (markix > stack_sp - stack_base)
2059 *(stack_base + markix) = &sv_undef;
2060 else
2061 *(stack_base + markix) = *stack_sp;
2062 stack_sp = stack_base + markix;
2063 }
a0d0e21e
LW
2064 }
2065 LEAVE;
2066 return NORMAL;
2067 }
2068 else {
2069 dMARK;
2070 register I32 items = SP - MARK;
a0d0e21e
LW
2071 AV* padlist = CvPADLIST(cv);
2072 SV** svp = AvARRAY(padlist);
2073 push_return(op->op_next);
2074 PUSHBLOCK(cx, CXt_SUB, MARK);
2075 PUSHSUB(cx);
2076 CvDEPTH(cv)++;
2077 if (CvDEPTH(cv) < 2)
2078 (void)SvREFCNT_inc(cv);
2079 else { /* save temporaries on recursion? */
5f05dabc 2080 if (CvDEPTH(cv) == 100 && dowarn
84902520 2081 && !(PERLDB_SUB && cv == GvCV(DBsub)))
44a8e56a 2082 sub_crush_depth(cv);
a0d0e21e
LW
2083 if (CvDEPTH(cv) > AvFILL(padlist)) {
2084 AV *av;
2085 AV *newpad = newAV();
4aa0a1f7 2086 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
a0d0e21e
LW
2087 I32 ix = AvFILL((AV*)svp[1]);
2088 svp = AvARRAY(svp[0]);
748a9306 2089 for ( ;ix > 0; ix--) {
a0d0e21e 2090 if (svp[ix] != &sv_undef) {
748a9306 2091 char *name = SvPVX(svp[ix]);
5f05dabc
PP
2092 if ((SvFLAGS(svp[ix]) & SVf_FAKE) /* outer lexical? */
2093 || *name == '&') /* anonymous code? */
2094 {
2095 av_store(newpad, ix, SvREFCNT_inc(oldpad[ix]));
748a9306
LW
2096 }
2097 else { /* our own lexical */
2098 if (*name == '@')
2099 av_store(newpad, ix, sv = (SV*)newAV());
2100 else if (*name == '%')
2101 av_store(newpad, ix, sv = (SV*)newHV());
2102 else
2103 av_store(newpad, ix, sv = NEWSV(0,0));
2104 SvPADMY_on(sv);
2105 }
a0d0e21e
LW
2106 }
2107 else {
748a9306 2108 av_store(newpad, ix, sv = NEWSV(0,0));
a0d0e21e
LW
2109 SvPADTMP_on(sv);
2110 }
2111 }
2112 av = newAV(); /* will be @_ */
2113 av_extend(av, 0);
2114 av_store(newpad, 0, (SV*)av);
2115 AvFLAGS(av) = AVf_REIFY;
2116 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
2117 AvFILL(padlist) = CvDEPTH(cv);
2118 svp = AvARRAY(padlist);
2119 }
2120 }
6d4ff0d2
MB
2121#ifdef USE_THREADS
2122 if (!hasargs) {
a0d0e21e 2123 AV* av = (AV*)curpad[0];
6d4ff0d2
MB
2124
2125 items = AvFILL(av) + 1;
2126 if (items) {
2127 /* Mark is at the end of the stack. */
2128 EXTEND(sp, items);
2129 Copy(AvARRAY(av), sp + 1, items, SV*);
2130 sp += items;
2131 PUTBACK ;
2132 }
2133 }
2134#endif /* USE_THREADS */
2135 SAVESPTR(curpad);
2136 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
2137#ifndef USE_THREADS
2138 if (hasargs)
2139#endif /* USE_THREADS */
2140 {
2141 AV* av;
a0d0e21e
LW
2142 SV** ary;
2143
77a005ab 2144#if 0
0f15f207
MB
2145 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
2146 "%p entersub preparing @_\n", thr));
77a005ab 2147#endif
6d4ff0d2 2148 av = (AV*)curpad[0];
a0d0e21e
LW
2149 if (AvREAL(av)) {
2150 av_clear(av);
2151 AvREAL_off(av);
2152 }
6d4ff0d2 2153#ifndef USE_THREADS
a0d0e21e 2154 cx->blk_sub.savearray = GvAV(defgv);
0c8c7a05 2155 GvAV(defgv) = (AV*)SvREFCNT_inc(av);
6d4ff0d2
MB
2156#endif /* USE_THREADS */
2157 cx->blk_sub.argarray = av;
a0d0e21e
LW
2158 ++MARK;
2159
2160 if (items > AvMAX(av) + 1) {
2161 ary = AvALLOC(av);
2162 if (AvARRAY(av) != ary) {
2163 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
2164 SvPVX(av) = (char*)ary;
2165 }
2166 if (items > AvMAX(av) + 1) {
2167 AvMAX(av) = items - 1;
2168 Renew(ary,items,SV*);
2169 AvALLOC(av) = ary;
2170 SvPVX(av) = (char*)ary;
2171 }
2172 }
2173 Copy(MARK,AvARRAY(av),items,SV*);
2174 AvFILL(av) = items - 1;
2175
2176 while (items--) {
2177 if (*MARK)
2178 SvTEMP_off(*MARK);
2179 MARK++;
2180 }
2181 }
77a005ab 2182#if 0
0f15f207
MB
2183 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
2184 "%p entersub returning %p\n", thr, CvSTART(cv)));
77a005ab 2185#endif
a0d0e21e
LW
2186 RETURNOP(CvSTART(cv));
2187 }
2188}
2189
44a8e56a 2190void
8ac85365 2191sub_crush_depth(CV *cv)
44a8e56a
PP
2192{
2193 if (CvANON(cv))
2194 warn("Deep recursion on anonymous subroutine");
2195 else {
2196 SV* tmpstr = sv_newmortal();
2197 gv_efullname3(tmpstr, CvGV(cv), Nullch);
2198 warn("Deep recursion on subroutine \"%s\"", SvPVX(tmpstr));
2199 }
2200}
2201
a0d0e21e
LW
2202PP(pp_aelem)
2203{
4e35701f 2204 djSP;
a0d0e21e 2205 SV** svp;
748a9306 2206 I32 elem = POPi;
68dc0745
PP
2207 AV* av = (AV*)POPs;
2208 U32 lval = op->op_flags & OPf_MOD;
2209 U32 defer = (op->op_private & OPpLVAL_DEFER) && (elem > AvFILL(av));
a0d0e21e 2210
748a9306
LW
2211 if (elem > 0)
2212 elem -= curcop->cop_arybase;
a0d0e21e
LW
2213 if (SvTYPE(av) != SVt_PVAV)
2214 RETPUSHUNDEF;
68dc0745 2215 svp = av_fetch(av, elem, lval && !defer);
a0d0e21e 2216 if (lval) {
68dc0745
PP
2217 if (!svp || *svp == &sv_undef) {
2218 SV* lv;
2219 if (!defer)
2220 DIE(no_aelem, elem);
2221 lv = sv_newmortal();
2222 sv_upgrade(lv, SVt_PVLV);
2223 LvTYPE(lv) = 'y';
2224 sv_magic(lv, Nullsv, 'y', Nullch, 0);
2225 LvTARG(lv) = SvREFCNT_inc(av);
2226 LvTARGOFF(lv) = elem;
2227 LvTARGLEN(lv) = 1;
2228 PUSHs(lv);
2229 RETURN;
2230 }
a0d0e21e
LW
2231 if (op->op_private & OPpLVAL_INTRO)
2232 save_svref(svp);
5f05dabc 2233 else if (op->op_private & OPpDEREF)
68dc0745 2234 vivify_ref(*svp, op->op_private & OPpDEREF);
a0d0e21e
LW
2235 }
2236 PUSHs(svp ? *svp : &sv_undef);
2237 RETURN;
2238}
2239
02a9e968 2240void
8ac85365 2241vivify_ref(SV *sv, U32 to_what)
02a9e968
CS
2242{
2243 if (SvGMAGICAL(sv))
2244 mg_get(sv);
2245 if (!SvOK(sv)) {
2246 if (SvREADONLY(sv))
2247 croak(no_modify);
5f05dabc
PP
2248 if (SvTYPE(sv) < SVt_RV)
2249 sv_upgrade(sv, SVt_RV);
2250 else if (SvTYPE(sv) >= SVt_PV) {
2251 (void)SvOOK_off(sv);
2252 Safefree(SvPVX(sv));
2253 SvLEN(sv) = SvCUR(sv) = 0;
2254 }
68dc0745 2255 switch (to_what) {
5f05dabc
PP
2256 case OPpDEREF_SV:
2257 SvRV(sv) = newSV(0);
2258 break;
2259 case OPpDEREF_AV:
2260 SvRV(sv) = (SV*)newAV();
2261 break;
2262 case OPpDEREF_HV:
2263 SvRV(sv) = (SV*)newHV();
2264 break;
2265 }
02a9e968
CS
2266 SvROK_on(sv);
2267 SvSETMAGIC(sv);
2268 }
2269}
2270
a0d0e21e
LW
2271PP(pp_method)
2272{
4e35701f 2273 djSP;
a0d0e21e
LW
2274 SV* sv;
2275 SV* ob;
2276 GV* gv;
56304f61
CS
2277 HV* stash;
2278 char* name;
ac91690f
CS
2279 char* packname;
2280 STRLEN packlen;
a0d0e21e 2281
fb73857a
PP
2282 if (SvROK(TOPs)) {
2283 sv = SvRV(TOPs);
2284 if (SvTYPE(sv) == SVt_PVCV) {
2285 SETs(sv);
2286 RETURN;
2287 }
2288 }
2289
56304f61 2290 name = SvPV(TOPs, na);
a0d0e21e
LW
2291 sv = *(stack_base + TOPMARK + 1);
2292
16d20bd9
AD
2293 if (SvGMAGICAL(sv))
2294 mg_get(sv);
a0d0e21e 2295 if (SvROK(sv))
16d20bd9 2296 ob = (SV*)SvRV(sv);
a0d0e21e
LW
2297 else {
2298 GV* iogv;
a0d0e21e 2299
56304f61 2300 packname = Nullch;
a0d0e21e 2301 if (!SvOK(sv) ||
56304f61 2302 !(packname = SvPV(sv, packlen)) ||
a0d0e21e
LW
2303 !(iogv = gv_fetchpv(packname, FALSE, SVt_PVIO)) ||
2304 !(ob=(SV*)GvIO(iogv)))
2305 {
56304f61 2306 if (!packname || !isIDFIRST(*packname))
ac91690f 2307 DIE("Can't call method \"%s\" without a package or object reference", name);
56304f61 2308 stash = gv_stashpvn(packname, packlen, TRUE);
ac91690f 2309 goto fetch;
a0d0e21e 2310 }
ac91690f 2311 *(stack_base + TOPMARK + 1) = sv_2mortal(newRV((SV*)iogv));
a0d0e21e
LW
2312 }
2313
ac91690f 2314 if (!ob || !SvOBJECT(ob))
a0d0e21e 2315 DIE("Can't call method \"%s\" on unblessed reference", name);
a0d0e21e 2316
56304f61 2317 stash = SvSTASH(ob);
a0d0e21e 2318
ac91690f 2319 fetch:
ac91690f 2320 gv = gv_fetchmethod(stash, name);
56304f61
CS
2321 if (!gv) {
2322 char* leaf = name;
2323 char* sep = Nullch;
2324 char* p;
2325
2326 for (p = name; *p; p++) {
2327 if (*p == '\'')
2328 sep = p, leaf = p + 1;
2329 else if (*p == ':' && *(p + 1) == ':')
2330 sep = p, leaf = p + 2;
2331 }
2332 if (!sep || ((sep - name) == 5 && strnEQ(name, "SUPER", 5))) {
2333 packname = HvNAME(sep ? curcop->cop_stash : stash);
2334 packlen = strlen(packname);
2335 }
2336 else {
2337 packname = name;
2338 packlen = sep - name;
2339 }
2340 DIE("Can't locate object method \"%s\" via package \"%.*s\"",
2341 leaf, (int)packlen, packname);
2342 }
8ebc5c01 2343 SETs(isGV(gv) ? (SV*)GvCV(gv) : (SV*)gv);
a0d0e21e
LW
2344 RETURN;
2345}
22239a37 2346