This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate win32 into ansiperl
[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;
3049007d 298 if (SvRMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) {
68dc0745 299 if (MARK == ORIGMARK) {
4352c267 300 MEXTEND(SP, 1);
68dc0745
PP
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
3049007d 986 if (SvRMAGICAL(last_in_gv) && (mg = mg_find((SV*)last_in_gv, 'q'))) {
e79b0511
PP
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
39e571d4
ML
1109#ifdef DJGPP
1110 sv_setpv(tmpcmd, "/dev/dosglob/"); /* File System Extension */
1111 sv_catsv(tmpcmd, tmpglob);
1112#else
a0d0e21e
LW
1113 sv_setpv(tmpcmd, "perlglob ");
1114 sv_catsv(tmpcmd, tmpglob);
1115 sv_catpv(tmpcmd, " |");
39e571d4 1116#endif /* !DJGPP */
67955e0c
PP
1117#endif /* !OS2 */
1118#else /* !DOSISH */
1119#if defined(CSH)
a0d0e21e
LW
1120 sv_setpvn(tmpcmd, cshname, cshlen);
1121 sv_catpv(tmpcmd, " -cf 'set nonomatch; glob ");
1122 sv_catsv(tmpcmd, tmpglob);
16d20bd9 1123 sv_catpv(tmpcmd, "' 2>/dev/null |");
a0d0e21e
LW
1124#else
1125 sv_setpv(tmpcmd, "echo ");
1126 sv_catsv(tmpcmd, tmpglob);
1127#if 'z' - 'a' == 25
1128 sv_catpv(tmpcmd, "|tr -s ' \t\f\r' '\\012\\012\\012\\012'|");
1129#else
1130 sv_catpv(tmpcmd, "|tr -s ' \t\f\r' '\\n\\n\\n\\n'|");
1131#endif
1132#endif /* !CSH */
67955e0c 1133#endif /* !DOSISH */
c07a80fd
PP
1134 (void)do_open(last_in_gv, SvPVX(tmpcmd), SvCUR(tmpcmd),
1135 FALSE, 0, 0, Nullfp);
a0d0e21e
LW
1136 fp = IoIFP(io);
1137#endif /* !VMS */
1138 LEAVE;
1139 }
1140 }
1141 else if (type == OP_GLOB)
1142 SP--;
1143 }
1144 if (!fp) {
4633a7c4 1145 if (dowarn && io && !(IoFLAGS(io) & IOf_START))
a0d0e21e 1146 warn("Read on closed filehandle <%s>", GvENAME(last_in_gv));
54310121 1147 if (gimme == G_SCALAR) {
a0d0e21e
LW
1148 (void)SvOK_off(TARG);
1149 PUSHTARG;
1150 }
1151 RETURN;
1152 }
54310121 1153 if (gimme == G_SCALAR) {
a0d0e21e 1154 sv = TARG;
9607fc9c
PP
1155 if (SvROK(sv))
1156 sv_unref(sv);
a0d0e21e
LW
1157 (void)SvUPGRADE(sv, SVt_PV);
1158 tmplen = SvLEN(sv); /* remember if already alloced */
1159 if (!tmplen)
1160 Sv_Grow(sv, 80); /* try short-buffering it */
1161 if (type == OP_RCATLINE)
1162 offset = SvCUR(sv);
1163 else
1164 offset = 0;
1165 }
54310121
PP
1166 else {
1167 sv = sv_2mortal(NEWSV(57, 80));
1168 offset = 0;
1169 }
a0d0e21e
LW
1170 for (;;) {
1171 if (!sv_gets(sv, fp, offset)) {
760ac839 1172 PerlIO_clearerr(fp);
a0d0e21e
LW
1173 if (IoFLAGS(io) & IOf_ARGV) {
1174 fp = nextargv(last_in_gv);
1175 if (fp)
1176 continue;
1177 (void)do_close(last_in_gv, FALSE);
1178 IoFLAGS(io) |= IOf_START;
1179 }
1180 else if (type == OP_GLOB) {
5cd24f17
PP
1181 if (do_close(last_in_gv, FALSE) & ~0xFF)
1182 warn("internal error: glob failed");
a0d0e21e 1183 }
54310121 1184 if (gimme == G_SCALAR) {
a0d0e21e
LW
1185 (void)SvOK_off(TARG);
1186 PUSHTARG;
1187 }
1188 RETURN;
1189 }
bbce6d69
PP
1190 /* This should not be marked tainted if the fp is marked clean */
1191 if (!(IoFLAGS(io) & IOf_UNTAINT)) {
1192 TAINT;
1193 SvTAINTED_on(sv);
1194 }
a0d0e21e 1195 IoLINES(io)++;
71be2cbc 1196 SvSETMAGIC(sv);
a0d0e21e 1197 XPUSHs(sv);
a0d0e21e
LW
1198 if (type == OP_GLOB) {
1199 char *tmps;
1200
c07a80fd
PP
1201 if (SvCUR(sv) > 0 && SvCUR(rs) > 0) {
1202 tmps = SvEND(sv) - 1;
1203 if (*tmps == *SvPVX(rs)) {
1204 *tmps = '\0';
1205 SvCUR(sv)--;
1206 }
1207 }
a0d0e21e
LW
1208 for (tmps = SvPVX(sv); *tmps; tmps++)
1209 if (!isALPHA(*tmps) && !isDIGIT(*tmps) &&
1210 strchr("$&*(){}[]'\";\\|?<>~`", *tmps))
1211 break;
1212 if (*tmps && Stat(SvPVX(sv), &statbuf) < 0) {
1213 (void)POPs; /* Unmatched wildcard? Chuck it... */
1214 continue;
1215 }
1216 }
54310121 1217 if (gimme == G_ARRAY) {
a0d0e21e
LW
1218 if (SvLEN(sv) - SvCUR(sv) > 20) {
1219 SvLEN_set(sv, SvCUR(sv)+1);
1220 Renew(SvPVX(sv), SvLEN(sv), char);
1221 }
1222 sv = sv_2mortal(NEWSV(58, 80));
1223 continue;
1224 }
54310121 1225 else if (gimme == G_SCALAR && !tmplen && SvLEN(sv) - SvCUR(sv) > 80) {
a0d0e21e
LW
1226 /* try to reclaim a bit of scalar space (only on 1st alloc) */
1227 if (SvCUR(sv) < 60)
1228 SvLEN_set(sv, 80);
1229 else
1230 SvLEN_set(sv, SvCUR(sv)+40); /* allow some slop */
1231 Renew(SvPVX(sv), SvLEN(sv), char);
1232 }
1233 RETURN;
1234 }
1235}
1236
1237PP(pp_enter)
1238{
4e35701f 1239 djSP;
c09156bb 1240 register PERL_CONTEXT *cx;
54310121 1241 I32 gimme = OP_GIMME(op, -1);
a0d0e21e 1242
54310121
PP
1243 if (gimme == -1) {
1244 if (cxstack_ix >= 0)
1245 gimme = cxstack[cxstack_ix].blk_gimme;
1246 else
1247 gimme = G_SCALAR;
1248 }
a0d0e21e
LW
1249
1250 ENTER;
1251
1252 SAVETMPS;
1253 PUSHBLOCK(cx, CXt_BLOCK, sp);
1254
1255 RETURN;
1256}
1257
1258PP(pp_helem)
1259{
4e35701f 1260 djSP;
760ac839 1261 HE* he;
ae77835f 1262 SV **svp;
a0d0e21e 1263 SV *keysv = POPs;
a0d0e21e 1264 HV *hv = (HV*)POPs;
68dc0745
PP
1265 U32 lval = op->op_flags & OPf_MOD;
1266 U32 defer = op->op_private & OPpLVAL_DEFER;
a0d0e21e 1267
ae77835f
MB
1268 if (SvTYPE(hv) == SVt_PVHV) {
1269 he = hv_fetch_ent(hv, keysv, lval && !defer, 0);
97fcbf96 1270 svp = he ? &HeVAL(he) : 0;
ae77835f
MB
1271 }
1272 else if (SvTYPE(hv) == SVt_PVAV) {
97fcbf96 1273 svp = avhv_fetch_ent((AV*)hv, keysv, lval && !defer, 0);
ae77835f 1274 }
c750a3ec 1275 else {
a0d0e21e 1276 RETPUSHUNDEF;
c750a3ec 1277 }
a0d0e21e 1278 if (lval) {
97fcbf96 1279 if (!svp || *svp == &sv_undef) {
68dc0745
PP
1280 SV* lv;
1281 SV* key2;
1282 if (!defer)
1283 DIE(no_helem, SvPV(keysv, na));
1284 lv = sv_newmortal();
1285 sv_upgrade(lv, SVt_PVLV);
1286 LvTYPE(lv) = 'y';
1287 sv_magic(lv, key2 = newSVsv(keysv), 'y', Nullch, 0);
1288 SvREFCNT_dec(key2); /* sv_magic() increments refcount */
1289 LvTARG(lv) = SvREFCNT_inc(hv);
1290 LvTARGLEN(lv) = 1;
1291 PUSHs(lv);
1292 RETURN;
1293 }
5f05dabc 1294 if (op->op_private & OPpLVAL_INTRO) {
ae77835f
MB
1295 if (HvNAME(hv) && isGV(*svp))
1296 save_gp((GV*)*svp, !(op->op_flags & OPf_SPECIAL));
5f05dabc 1297 else
ae77835f 1298 save_svref(svp);
5f05dabc
PP
1299 }
1300 else if (op->op_private & OPpDEREF)
ae77835f 1301 vivify_ref(*svp, op->op_private & OPpDEREF);
a0d0e21e
LW
1302 }
1303 PUSHs(svp ? *svp : &sv_undef);
1304 RETURN;
1305}
1306
1307PP(pp_leave)
1308{
4e35701f 1309 djSP;
c09156bb 1310 register PERL_CONTEXT *cx;
a0d0e21e
LW
1311 register SV **mark;
1312 SV **newsp;
1313 PMOP *newpm;
1314 I32 gimme;
1315
1316 if (op->op_flags & OPf_SPECIAL) {
1317 cx = &cxstack[cxstack_ix];
1318 cx->blk_oldpm = curpm; /* fake block should preserve $1 et al */
1319 }
1320
1321 POPBLOCK(cx,newpm);
1322
54310121
PP
1323 gimme = OP_GIMME(op, -1);
1324 if (gimme == -1) {
1325 if (cxstack_ix >= 0)
1326 gimme = cxstack[cxstack_ix].blk_gimme;
1327 else
1328 gimme = G_SCALAR;
1329 }
a0d0e21e 1330
a1f49e72 1331 TAINT_NOT;
54310121
PP
1332 if (gimme == G_VOID)
1333 SP = newsp;
1334 else if (gimme == G_SCALAR) {
1335 MARK = newsp + 1;
1336 if (MARK <= SP)
1337 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
1338 *MARK = TOPs;
1339 else
1340 *MARK = sv_mortalcopy(TOPs);
a0d0e21e 1341 else {
54310121
PP
1342 MEXTEND(mark,0);
1343 *MARK = &sv_undef;
a0d0e21e 1344 }
54310121 1345 SP = MARK;
a0d0e21e 1346 }
54310121 1347 else if (gimme == G_ARRAY) {
a1f49e72
CS
1348 /* in case LEAVE wipes old return values */
1349 for (mark = newsp + 1; mark <= SP; mark++) {
1350 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
a0d0e21e 1351 *mark = sv_mortalcopy(*mark);
a1f49e72
CS
1352 TAINT_NOT; /* Each item is independent */
1353 }
1354 }
a0d0e21e
LW
1355 }
1356 curpm = newpm; /* Don't pop $1 et al till now */
1357
1358 LEAVE;
1359
1360 RETURN;
1361}
1362
1363PP(pp_iter)
1364{
4e35701f 1365 djSP;
c09156bb 1366 register PERL_CONTEXT *cx;
5f05dabc 1367 SV* sv;
4633a7c4 1368 AV* av;
a0d0e21e
LW
1369
1370 EXTEND(sp, 1);
1371 cx = &cxstack[cxstack_ix];
1372 if (cx->cx_type != CXt_LOOP)
1373 DIE("panic: pp_iter");
1374
4633a7c4 1375 av = cx->blk_loop.iterary;
71be2cbc 1376 if (cx->blk_loop.iterix >= (av == curstack ? cx->blk_oldsp : AvFILL(av)))
4633a7c4 1377 RETPUSHNO;
a0d0e21e 1378
7a4c00b4 1379 SvREFCNT_dec(*cx->blk_loop.itervar);
a0d0e21e 1380
5f05dabc 1381 if (sv = AvARRAY(av)[++cx->blk_loop.iterix])
a0d0e21e 1382 SvTEMP_off(sv);
a0d0e21e 1383 else
5f05dabc
PP
1384 sv = &sv_undef;
1385 if (av != curstack && SvIMMORTAL(sv)) {
1386 SV *lv = cx->blk_loop.iterlval;
71be2cbc
PP
1387 if (lv && SvREFCNT(lv) > 1) {
1388 SvREFCNT_dec(lv);
1389 lv = Nullsv;
1390 }
5f05dabc
PP
1391 if (lv)
1392 SvREFCNT_dec(LvTARG(lv));
1393 else {
68dc0745 1394 lv = cx->blk_loop.iterlval = NEWSV(26, 0);
5f05dabc 1395 sv_upgrade(lv, SVt_PVLV);
5f05dabc 1396 LvTYPE(lv) = 'y';
68dc0745 1397 sv_magic(lv, Nullsv, 'y', Nullch, 0);
5f05dabc
PP
1398 }
1399 LvTARG(lv) = SvREFCNT_inc(av);
1400 LvTARGOFF(lv) = cx->blk_loop.iterix;
8ac85365 1401 LvTARGLEN(lv) = (UV) -1;
5f05dabc
PP
1402 sv = (SV*)lv;
1403 }
a0d0e21e 1404
7a4c00b4 1405 *cx->blk_loop.itervar = SvREFCNT_inc(sv);
a0d0e21e
LW
1406 RETPUSHYES;
1407}
1408
1409PP(pp_subst)
1410{
4e35701f 1411 djSP; dTARG;
a0d0e21e
LW
1412 register PMOP *pm = cPMOP;
1413 PMOP *rpm = pm;
1414 register SV *dstr;
1415 register char *s;
1416 char *strend;
1417 register char *m;
1418 char *c;
1419 register char *d;
1420 STRLEN clen;
1421 I32 iters = 0;
1422 I32 maxiters;
1423 register I32 i;
1424 bool once;
71be2cbc 1425 bool rxtainted;
a0d0e21e
LW
1426 char *orig;
1427 I32 safebase;
1428 register REGEXP *rx = pm->op_pmregexp;
1429 STRLEN len;
1430 int force_on_match = 0;
4633a7c4 1431 I32 oldsave = savestack_ix;
c277df42
IZ
1432 I32 update_minmatch = 1;
1433 SV *screamer;
a0d0e21e 1434
5cd24f17
PP
1435 /* known replacement string? */
1436 dstr = (pm->op_pmflags & PMf_CONST) ? POPs : Nullsv;
a0d0e21e
LW
1437 if (op->op_flags & OPf_STACKED)
1438 TARG = POPs;
1439 else {
54b9620d 1440 TARG = DEFSV;
a0d0e21e
LW
1441 EXTEND(SP,1);
1442 }
68dc0745
PP
1443 if (SvREADONLY(TARG)
1444 || (SvTYPE(TARG) > SVt_PVLV
1445 && !(SvTYPE(TARG) == SVt_PVGV && SvFAKE(TARG))))
1446 croak(no_modify);
a0d0e21e 1447 s = SvPV(TARG, len);
68dc0745 1448 if (!SvPOKp(TARG) || SvTYPE(TARG) == SVt_PVGV)
a0d0e21e 1449 force_on_match = 1;
9212bbba 1450 TAINT_NOT;
a0d0e21e
LW
1451
1452 force_it:
1453 if (!pm || !s)
1454 DIE("panic: do_subst");
1455
1456 strend = s + len;
1457 maxiters = (strend - s) + 10;
1458
1459 if (!rx->prelen && curpm) {
1460 pm = curpm;
1461 rx = pm->op_pmregexp;
1462 }
c277df42
IZ
1463 screamer = ( (SvSCREAM(TARG) && rx->check_substr
1464 && SvTYPE(rx->check_substr) == SVt_PVBM
1465 && SvVALID(rx->check_substr))
1466 ? TARG : Nullsv);
1467 safebase = (!rx->nparens && !sawampersand) ? 0 : REXEC_COPY_STR;
a0d0e21e
LW
1468 if (pm->op_pmflags & (PMf_MULTILINE|PMf_SINGLELINE)) {
1469 SAVEINT(multiline);
1470 multiline = pm->op_pmflags & PMf_MULTILINE;
1471 }
1472 orig = m = s;
c277df42
IZ
1473 if (rx->check_substr) {
1474 if (!(rx->reganch & ROPT_NOSCAN)) { /* It floats. */
1475 if (screamer) {
1476 I32 p = -1;
1477
1478 if (screamfirst[BmRARE(rx->check_substr)] < 0)
a0d0e21e 1479 goto nope;
c277df42 1480 else if (!(s = screaminstr(TARG, rx->check_substr, rx->check_offset_min, 0, &p, 0)))
a0d0e21e
LW
1481 goto nope;
1482 }
c277df42
IZ
1483 else if (!(s = fbm_instr((unsigned char*)s + rx->check_offset_min,
1484 (unsigned char*)strend,
1485 rx->check_substr)))
a0d0e21e 1486 goto nope;
c277df42
IZ
1487 if (s && rx->check_offset_max < s - m) {
1488 ++BmUSEFUL(rx->check_substr);
1489 s -= rx->check_offset_max;
a0d0e21e
LW
1490 }
1491 else
1492 s = m;
1493 }
c277df42
IZ
1494 /* Now checkstring is fixed, i.e. at fixed offset from the
1495 beginning of match, and the match is anchored at s. */
1496 else if (!multiline) { /* Anchored at beginning of string. */
1497 I32 slen;
1498 if (*SvPVX(rx->check_substr) != s[rx->check_offset_min]
1499 || ((slen = SvCUR(rx->check_substr)) > 1
1500 && memNE(SvPVX(rx->check_substr),
1501 s + rx->check_offset_min, slen)))
bbce6d69 1502 goto nope;
a0d0e21e 1503 }
c277df42
IZ
1504 if (!rx->naughty && --BmUSEFUL(rx->check_substr) < 0
1505 && rx->check_substr == rx->float_substr) {
1506 SvREFCNT_dec(rx->check_substr);
1507 rx->check_substr = Nullsv; /* opt is being useless */
1508 rx->float_substr = Nullsv;
a0d0e21e
LW
1509 }
1510 }
71be2cbc
PP
1511
1512 /* only replace once? */
a0d0e21e 1513 once = !(rpm->op_pmflags & PMf_GLOBAL);
71be2cbc
PP
1514
1515 /* known replacement string? */
5cd24f17 1516 c = dstr ? SvPV(dstr, clen) : Nullch;
71be2cbc
PP
1517
1518 /* can do inplace substitution? */
c277df42
IZ
1519 if (c && clen <= rx->minlen && (once || !(safebase & REXEC_COPY_STR))
1520 && !(rx->reganch & ROPT_LOOKBEHIND_SEEN)) {
1521 if (!regexec_flags(rx, s, strend, orig, 0, screamer, NULL, safebase)) {
71be2cbc
PP
1522 PUSHs(&sv_no);
1523 LEAVE_SCOPE(oldsave);
1524 RETURN;
1525 }
1526 if (force_on_match) {
1527 force_on_match = 0;
1528 s = SvPV_force(TARG, len);
1529 goto force_it;
1530 }
71be2cbc
PP
1531 d = s;
1532 curpm = pm;
1533 SvSCREAM_off(TARG); /* disable possible screamer */
1534 if (once) {
c277df42
IZ
1535 rxtainted = RX_MATCH_TAINTED(rx);
1536 if (rx->subbase) {
1537 m = orig + (rx->startp[0] - rx->subbase);
1538 d = orig + (rx->endp[0] - rx->subbase);
1539 } else {
1540 m = rx->startp[0];
1541 d = rx->endp[0];
1542 }
71be2cbc
PP
1543 s = orig;
1544 if (m - s > strend - d) { /* faster to shorten from end */
1545 if (clen) {
1546 Copy(c, m, clen, char);
1547 m += clen;
a0d0e21e 1548 }
71be2cbc
PP
1549 i = strend - d;
1550 if (i > 0) {
1551 Move(d, m, i, char);
1552 m += i;
a0d0e21e 1553 }
71be2cbc
PP
1554 *m = '\0';
1555 SvCUR_set(TARG, m - s);
1556 }
1557 /*SUPPRESS 560*/
1558 else if (i = m - s) { /* faster from front */
1559 d -= clen;
1560 m = d;
1561 sv_chop(TARG, d-i);
1562 s += i;
1563 while (i--)
1564 *--d = *--s;
1565 if (clen)
1566 Copy(c, m, clen, char);
1567 }
1568 else if (clen) {
1569 d -= clen;
1570 sv_chop(TARG, d);
1571 Copy(c, d, clen, char);
1572 }
1573 else {
1574 sv_chop(TARG, d);
1575 }
9212bbba 1576 TAINT_IF(rxtainted);
71be2cbc
PP
1577 PUSHs(&sv_yes);
1578 }
1579 else {
1580 rxtainted = 0;
1581 do {
1582 if (iters++ > maxiters)
1583 DIE("Substitution loop");
c277df42 1584 rxtainted |= RX_MATCH_TAINTED(rx);
71be2cbc
PP
1585 m = rx->startp[0];
1586 /*SUPPRESS 560*/
1587 if (i = m - s) {
1588 if (s != d)
1589 Move(s, d, i, char);
1590 d += i;
a0d0e21e 1591 }
71be2cbc
PP
1592 if (clen) {
1593 Copy(c, d, clen, char);
1594 d += clen;
1595 }
1596 s = rx->endp[0];
c277df42
IZ
1597 } while (regexec_flags(rx, s, strend, orig, s == m,
1598 Nullsv, NULL, 0)); /* don't match same null twice */
71be2cbc
PP
1599 if (s != d) {
1600 i = strend - s;
1601 SvCUR_set(TARG, d - SvPVX(TARG) + i);
1602 Move(s, d, i+1, char); /* include the NUL */
a0d0e21e 1603 }
9212bbba 1604 TAINT_IF(rxtainted);
71be2cbc 1605 PUSHs(sv_2mortal(newSViv((I32)iters)));
a0d0e21e 1606 }
71be2cbc
PP
1607 (void)SvPOK_only(TARG);
1608 SvSETMAGIC(TARG);
9212bbba 1609 SvTAINT(TARG);
71be2cbc
PP
1610 LEAVE_SCOPE(oldsave);
1611 RETURN;
a0d0e21e 1612 }
71be2cbc 1613
c277df42 1614 if (regexec_flags(rx, s, strend, orig, 0, screamer, NULL, safebase)) {
a0d0e21e
LW
1615 if (force_on_match) {
1616 force_on_match = 0;
1617 s = SvPV_force(TARG, len);
1618 goto force_it;
1619 }
c277df42 1620 rxtainted = RX_MATCH_TAINTED(rx);
a0d0e21e
LW
1621 dstr = NEWSV(25, sv_len(TARG));
1622 sv_setpvn(dstr, m, s-m);
1623 curpm = pm;
1624 if (!c) {
c09156bb 1625 register PERL_CONTEXT *cx;
a0d0e21e
LW
1626 PUSHSUBST(cx);
1627 RETURNOP(cPMOP->op_pmreplroot);
1628 }
1629 do {
1630 if (iters++ > maxiters)
1631 DIE("Substitution loop");
c277df42 1632 rxtainted |= RX_MATCH_TAINTED(rx);
a0d0e21e
LW
1633 if (rx->subbase && rx->subbase != orig) {
1634 m = s;
1635 s = orig;
1636 orig = rx->subbase;
1637 s = orig + (m - s);
1638 strend = s + (strend - m);
1639 }
1640 m = rx->startp[0];
1641 sv_catpvn(dstr, s, m-s);
1642 s = rx->endp[0];
1643 if (clen)
1644 sv_catpvn(dstr, c, clen);
1645 if (once)
1646 break;
c277df42 1647 } while (regexec_flags(rx, s, strend, orig, s == m, Nullsv, NULL, safebase));
a0d0e21e 1648 sv_catpvn(dstr, s, strend - s);
748a9306 1649
9212bbba
CS
1650 TAINT_IF(rxtainted);
1651
4633a7c4 1652 (void)SvOOK_off(TARG);
cb0b1708 1653 Safefree(SvPVX(TARG));
748a9306
LW
1654 SvPVX(TARG) = SvPVX(dstr);
1655 SvCUR_set(TARG, SvCUR(dstr));
1656 SvLEN_set(TARG, SvLEN(dstr));
1657 SvPVX(dstr) = 0;
1658 sv_free(dstr);
1659
a0d0e21e
LW
1660 (void)SvPOK_only(TARG);
1661 SvSETMAGIC(TARG);
9212bbba 1662 SvTAINT(TARG);
a0d0e21e 1663 PUSHs(sv_2mortal(newSViv((I32)iters)));
4633a7c4 1664 LEAVE_SCOPE(oldsave);
a0d0e21e
LW
1665 RETURN;
1666 }
5cd24f17 1667 goto ret_no;
a0d0e21e
LW
1668
1669nope:
c277df42 1670 ++BmUSEFUL(rx->check_substr);
5cd24f17
PP
1671
1672ret_no:
a0d0e21e 1673 PUSHs(&sv_no);
4633a7c4 1674 LEAVE_SCOPE(oldsave);
a0d0e21e
LW
1675 RETURN;
1676}
1677
1678PP(pp_grepwhile)
1679{
4e35701f 1680 djSP;
a0d0e21e
LW
1681
1682 if (SvTRUEx(POPs))
1683 stack_base[markstack_ptr[-1]++] = stack_base[*markstack_ptr];
1684 ++*markstack_ptr;
1685 LEAVE; /* exit inner scope */
1686
1687 /* All done yet? */
1688 if (stack_base + *markstack_ptr > sp) {
1689 I32 items;
54310121 1690 I32 gimme = GIMME_V;
a0d0e21e
LW
1691
1692 LEAVE; /* exit outer scope */
1693 (void)POPMARK; /* pop src */
1694 items = --*markstack_ptr - markstack_ptr[-1];
1695 (void)POPMARK; /* pop dst */
1696 SP = stack_base + POPMARK; /* pop original mark */
54310121 1697 if (gimme == G_SCALAR) {
a0d0e21e
LW
1698 dTARGET;
1699 XPUSHi(items);
a0d0e21e 1700 }
54310121
PP
1701 else if (gimme == G_ARRAY)
1702 SP += items;
a0d0e21e
LW
1703 RETURN;
1704 }
1705 else {
1706 SV *src;
1707
1708 ENTER; /* enter inner scope */
1709 SAVESPTR(curpm);
1710
1711 src = stack_base[*markstack_ptr];
1712 SvTEMP_off(src);
54b9620d 1713 DEFSV = src;
a0d0e21e
LW
1714
1715 RETURNOP(cLOGOP->op_other);
1716 }
1717}
1718
1719PP(pp_leavesub)
1720{
4e35701f 1721 djSP;
a0d0e21e
LW
1722 SV **mark;
1723 SV **newsp;
1724 PMOP *newpm;
1725 I32 gimme;
c09156bb 1726 register PERL_CONTEXT *cx;
f86702cc 1727 struct block_sub cxsub;
a0d0e21e
LW
1728
1729 POPBLOCK(cx,newpm);
f86702cc
PP
1730 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1731
a1f49e72 1732 TAINT_NOT;
a0d0e21e
LW
1733 if (gimme == G_SCALAR) {
1734 MARK = newsp + 1;
1735 if (MARK <= SP)
f86702cc 1736 *MARK = SvTEMP(TOPs) ? TOPs : sv_mortalcopy(TOPs);
a0d0e21e 1737 else {
f86702cc 1738 MEXTEND(MARK, 0);
a0d0e21e
LW
1739 *MARK = &sv_undef;
1740 }
1741 SP = MARK;
1742 }
54310121 1743 else if (gimme == G_ARRAY) {
f86702cc 1744 for (MARK = newsp + 1; MARK <= SP; MARK++) {
a1f49e72 1745 if (!SvTEMP(*MARK)) {
f86702cc 1746 *MARK = sv_mortalcopy(*MARK);
a1f49e72
CS
1747 TAINT_NOT; /* Each item is independent */
1748 }
f86702cc 1749 }
a0d0e21e 1750 }
f86702cc
PP
1751 PUTBACK;
1752
1753 POPSUB2(); /* Stack values are safe: release CV and @_ ... */
1754 curpm = newpm; /* ... and pop $1 et al */
a0d0e21e
LW
1755
1756 LEAVE;
a0d0e21e
LW
1757 return pop_return();
1758}
1759
3de9ffa1 1760static CV *
8ac85365 1761get_db_sub(SV **svp, CV *cv)
3de9ffa1
MB
1762{
1763 dTHR;
4f01c5a5 1764 SV *oldsv = *svp;
3de9ffa1 1765 GV *gv;
3de9ffa1 1766
4f01c5a5
MB
1767 *svp = GvSV(DBsub);
1768 save_item(*svp);
3de9ffa1
MB
1769 gv = CvGV(cv);
1770 if ( (CvFLAGS(cv) & (CVf_ANON | CVf_CLONED))
1771 || strEQ(GvNAME(gv), "END")
1772 || ((GvCV(gv) != cv) && /* Could be imported, and old sub redefined. */
1773 !( (SvTYPE(oldsv) == SVt_PVGV) && (GvCV((GV*)oldsv) == cv)
1774 && (gv = (GV*)oldsv) ))) {
1775 /* Use GV from the stack as a fallback. */
1776 /* GV is potentially non-unique, or contain different CV. */
4f01c5a5 1777 sv_setsv(*svp, newRV((SV*)cv));
3de9ffa1
MB
1778 }
1779 else {
4f01c5a5 1780 gv_efullname3(*svp, gv, Nullch);
3de9ffa1
MB
1781 }
1782 cv = GvCV(DBsub);
1783 if (CvXSUB(cv))
1784 curcopdb = curcop;
1785 return cv;
1786}
1787
a0d0e21e
LW
1788PP(pp_entersub)
1789{
4e35701f 1790 djSP; dPOPss;
a0d0e21e
LW
1791 GV *gv;
1792 HV *stash;
1793 register CV *cv;
c09156bb 1794 register PERL_CONTEXT *cx;
5d94fbed 1795 I32 gimme;
07055b4c 1796 bool hasargs = (op->op_flags & OPf_STACKED) != 0;
a0d0e21e
LW
1797
1798 if (!sv)
1799 DIE("Not a CODE reference");
1800 switch (SvTYPE(sv)) {
1801 default:
1802 if (!SvROK(sv)) {
748a9306
LW
1803 char *sym;
1804
fb73857a
PP
1805 if (sv == &sv_yes) { /* unfound import, ignore */
1806 if (hasargs)
1807 SP = stack_base + POPMARK;
a0d0e21e 1808 RETURN;
fb73857a 1809 }
15ff848f
CS
1810 if (SvGMAGICAL(sv)) {
1811 mg_get(sv);
1812 sym = SvPOKp(sv) ? SvPVX(sv) : Nullch;
1813 }
1814 else
1815 sym = SvPV(sv, na);
1816 if (!sym)
a0d0e21e
LW
1817 DIE(no_usym, "a subroutine");
1818 if (op->op_private & HINT_STRICT_REFS)
748a9306
LW
1819 DIE(no_symref, sym, "a subroutine");
1820 cv = perl_get_cv(sym, TRUE);
a0d0e21e
LW
1821 break;
1822 }
1823 cv = (CV*)SvRV(sv);
1824 if (SvTYPE(cv) == SVt_PVCV)
1825 break;
1826 /* FALL THROUGH */
1827 case SVt_PVHV:
1828 case SVt_PVAV:
1829 DIE("Not a CODE reference");
1830 case SVt_PVCV:
1831 cv = (CV*)sv;
1832 break;
1833 case SVt_PVGV:
8ebc5c01 1834 if (!(cv = GvCVu((GV*)sv)))
a0d0e21e
LW
1835 cv = sv_2cv(sv, &stash, &gv, TRUE);
1836 break;
1837 }
1838
1839 ENTER;
1840 SAVETMPS;
1841
1842 retry:
1843 if (!cv)
1844 DIE("Not a CODE reference");
1845
1846 if (!CvROOT(cv) && !CvXSUB(cv)) {
44a8e56a 1847 GV* autogv;
22239a37 1848 SV* sub_name;
44a8e56a
PP
1849
1850 /* anonymous or undef'd function leaves us no recourse */
1851 if (CvANON(cv) || !(gv = CvGV(cv)))
1852 DIE("Undefined subroutine called");
1853 /* autoloaded stub? */
1854 if (cv != GvCV(gv)) {
1855 cv = GvCV(gv);
1856 goto retry;
a0d0e21e 1857 }
44a8e56a 1858 /* should call AUTOLOAD now? */
54310121
PP
1859 if ((autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv), GvNAMELEN(gv),
1860 FALSE)))
1861 {
44a8e56a
PP
1862 cv = GvCV(autogv);
1863 goto retry;
a0d0e21e 1864 }
44a8e56a 1865 /* sorry */
22239a37
NIS
1866 sub_name = sv_newmortal();
1867 gv_efullname3(sub_name, gv, Nullch);
1868 DIE("Undefined subroutine &%s called", SvPVX(sub_name));
a0d0e21e
LW
1869 }
1870
54310121 1871 gimme = GIMME_V;
3de9ffa1 1872 if ((op->op_private & OPpENTERSUB_DB) && GvCV(DBsub) && !CvNODEBUG(cv))
4f01c5a5 1873 cv = get_db_sub(&sv, cv);
3de9ffa1
MB
1874 if (!cv)
1875 DIE("No DBsub routine");
a0d0e21e 1876
11343788 1877#ifdef USE_THREADS
3de9ffa1
MB
1878 /*
1879 * First we need to check if the sub or method requires locking.
458fb581
MB
1880 * If so, we gain a lock on the CV, the first argument or the
1881 * stash (for static methods), as appropriate. This has to be
1882 * inline because for FAKE_THREADS, COND_WAIT inlines code to
1883 * reschedule by returning a new op.
3de9ffa1 1884 */
11343788 1885 MUTEX_LOCK(CvMUTEXP(cv));
77a005ab
MB
1886 if (CvFLAGS(cv) & CVf_LOCKED) {
1887 MAGIC *mg;
1888 if (CvFLAGS(cv) & CVf_METHOD) {
1889 if (SP > stack_base + TOPMARK)
1890 sv = *(stack_base + TOPMARK + 1);
1891 else {
1892 MUTEX_UNLOCK(CvMUTEXP(cv));
1893 croak("no argument for locked method call");
1894 }
1895 if (SvROK(sv))
1896 sv = SvRV(sv);
458fb581
MB
1897 else {
1898 STRLEN len;
1899 char *stashname = SvPV(sv, len);
1900 sv = (SV*)gv_stashpvn(stashname, len, TRUE);
1901 }
77a005ab
MB
1902 }
1903 else {
1904 sv = (SV*)cv;
1905 }
1906 MUTEX_UNLOCK(CvMUTEXP(cv));
1907 mg = condpair_magic(sv);
1908 MUTEX_LOCK(MgMUTEXP(mg));
1909 if (MgOWNER(mg) == thr)
1910 MUTEX_UNLOCK(MgMUTEXP(mg));
1911 else {
1912 while (MgOWNER(mg))
1913 COND_WAIT(MgOWNERCONDP(mg), MgMUTEXP(mg));
1914 MgOWNER(mg) = thr;
1fd28e87
MB
1915 DEBUG_L(PerlIO_printf(PerlIO_stderr(), "%p: pp_entersub lock %p\n",
1916 thr, sv);)
77a005ab 1917 MUTEX_UNLOCK(MgMUTEXP(mg));
e55aaa0e 1918 SvREFCNT_inc(sv); /* Keep alive until magic_mutexfree */
77a005ab 1919 save_destructor(unlock_condpair, sv);
11343788 1920 }
77a005ab 1921 MUTEX_LOCK(CvMUTEXP(cv));
11343788 1922 }
3de9ffa1
MB
1923 /*
1924 * Now we have permission to enter the sub, we must distinguish
1925 * four cases. (0) It's an XSUB (in which case we don't care
1926 * about ownership); (1) it's ours already (and we're recursing);
1927 * (2) it's free (but we may already be using a cached clone);
1928 * (3) another thread owns it. Case (1) is easy: we just use it.
1929 * Case (2) means we look for a clone--if we have one, use it
1930 * otherwise grab ownership of cv. Case (3) means we look for a
1931 * clone (for non-XSUBs) and have to create one if we don't
1932 * already have one.
1933 * Why look for a clone in case (2) when we could just grab
1934 * ownership of cv straight away? Well, we could be recursing,
1935 * i.e. we originally tried to enter cv while another thread
1936 * owned it (hence we used a clone) but it has been freed up
1937 * and we're now recursing into it. It may or may not be "better"
1938 * to use the clone but at least CvDEPTH can be trusted.
1939 */
1940 if (CvOWNER(cv) == thr || CvXSUB(cv))
1941 MUTEX_UNLOCK(CvMUTEXP(cv));
11343788 1942 else {
3de9ffa1
MB
1943 /* Case (2) or (3) */
1944 SV **svp;
1945
11343788 1946 /*
3de9ffa1
MB
1947 * XXX Might it be better to release CvMUTEXP(cv) while we
1948 * do the hv_fetch? We might find someone has pinched it
1949 * when we look again, in which case we would be in case
1950 * (3) instead of (2) so we'd have to clone. Would the fact
1951 * that we released the mutex more quickly make up for this?
1952 */
199100c8 1953 svp = hv_fetch(thr->cvcache, (char *)cv, sizeof(cv), FALSE);
3de9ffa1
MB
1954 if (svp) {
1955 /* We already have a clone to use */
11343788 1956 MUTEX_UNLOCK(CvMUTEXP(cv));
3de9ffa1
MB
1957 cv = *(CV**)svp;
1958 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
1fd28e87
MB
1959 "entersub: %p already has clone %p:%s\n",
1960 thr, cv, SvPEEK((SV*)cv)));
3de9ffa1
MB
1961 CvOWNER(cv) = thr;
1962 SvREFCNT_inc(cv);
1963 if (CvDEPTH(cv) == 0)
1964 SAVEDESTRUCTOR(unset_cvowner, (void*) cv);
1965 }
11343788 1966 else {
3de9ffa1
MB
1967 /* (2) => grab ownership of cv. (3) => make clone */
1968 if (!CvOWNER(cv)) {
1969 CvOWNER(cv) = thr;
1970 SvREFCNT_inc(cv);
11343788 1971 MUTEX_UNLOCK(CvMUTEXP(cv));
d9f997d7 1972 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
1fd28e87
MB
1973 "entersub: %p grabbing %p:%s in stash %s\n",
1974 thr, cv, SvPEEK((SV*)cv), CvSTASH(cv) ?
3de9ffa1
MB
1975 HvNAME(CvSTASH(cv)) : "(none)"));
1976 } else {
1977 /* Make a new clone. */
1978 CV *clonecv;
1979 SvREFCNT_inc(cv); /* don't let it vanish from under us */
1980 MUTEX_UNLOCK(CvMUTEXP(cv));
1981 DEBUG_L((PerlIO_printf(PerlIO_stderr(),
1fd28e87
MB
1982 "entersub: %p cloning %p:%s\n",
1983 thr, cv, SvPEEK((SV*)cv))));
3de9ffa1
MB
1984 /*
1985 * We're creating a new clone so there's no race
1986 * between the original MUTEX_UNLOCK and the
1987 * SvREFCNT_inc since no one will be trying to undef
1988 * it out from underneath us. At least, I don't think
1989 * there's a race...
1990 */
1991 clonecv = cv_clone(cv);
1992 SvREFCNT_dec(cv); /* finished with this */
199100c8 1993 hv_store(thr->cvcache, (char*)cv, sizeof(cv), (SV*)clonecv,0);
3de9ffa1
MB
1994 CvOWNER(clonecv) = thr;
1995 cv = clonecv;
11343788 1996 SvREFCNT_inc(cv);
11343788 1997 }
3de9ffa1
MB
1998 DEBUG_L(if (CvDEPTH(cv) != 0)
1999 PerlIO_printf(PerlIO_stderr(), "depth %ld != 0\n",
2000 CvDEPTH(cv)););
2001 SAVEDESTRUCTOR(unset_cvowner, (void*) cv);
11343788 2002 }
3de9ffa1 2003 }
11343788
MB
2004#endif /* USE_THREADS */
2005
2006 gimme = GIMME;
2007
a0d0e21e
LW
2008 if (CvXSUB(cv)) {
2009 if (CvOLDSTYLE(cv)) {
ecfc5424 2010 I32 (*fp3)_((int,int,int));
a0d0e21e
LW
2011 dMARK;
2012 register I32 items = SP - MARK;
67955e0c 2013 /* We dont worry to copy from @_. */
a0d0e21e
LW
2014 while (sp > mark) {
2015 sp[1] = sp[0];
2016 sp--;
2017 }
2018 stack_sp = mark + 1;
ecfc5424
AD
2019 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
2020 items = (*fp3)(CvXSUBANY(cv).any_i32,
2021 MARK - stack_base + 1,
2022 items);
a0d0e21e
LW
2023 stack_sp = stack_base + items;
2024 }
2025 else {
748a9306
LW
2026 I32 markix = TOPMARK;
2027
a0d0e21e 2028 PUTBACK;
67955e0c
PP
2029
2030 if (!hasargs) {
2031 /* Need to copy @_ to stack. Alternative may be to
2032 * switch stack to @_, and copy return values
2033 * back. This would allow popping @_ in XSUB, e.g.. XXXX */
6d4ff0d2
MB
2034 AV* av;
2035 I32 items;
2036#ifdef USE_THREADS
2037 av = (AV*)curpad[0];
2038#else
2039 av = GvAV(defgv);
2040#endif /* USE_THREADS */
2041 items = AvFILL(av) + 1;
67955e0c
PP
2042
2043 if (items) {
2044 /* Mark is at the end of the stack. */
2045 EXTEND(sp, items);
2046 Copy(AvARRAY(av), sp + 1, items, SV*);
2047 sp += items;
2048 PUTBACK ;
2049 }
2050 }
2051 if (curcopdb) { /* We assume that the first
2052 XSUB in &DB::sub is the
2053 called one. */
2054 SAVESPTR(curcop);
2055 curcop = curcopdb;
2056 curcopdb = NULL;
2057 }
2058 /* Do we need to open block here? XXXX */
a0d0e21e 2059 (void)(*CvXSUB(cv))(cv);
748a9306
LW
2060
2061 /* Enforce some sanity in scalar context. */
5d94fbed 2062 if (gimme == G_SCALAR && ++markix != stack_sp - stack_base ) {
748a9306
LW
2063 if (markix > stack_sp - stack_base)
2064 *(stack_base + markix) = &sv_undef;
2065 else
2066 *(stack_base + markix) = *stack_sp;
2067 stack_sp = stack_base + markix;
2068 }
a0d0e21e
LW
2069 }
2070 LEAVE;
2071 return NORMAL;
2072 }
2073 else {
2074 dMARK;
2075 register I32 items = SP - MARK;
a0d0e21e
LW
2076 AV* padlist = CvPADLIST(cv);
2077 SV** svp = AvARRAY(padlist);
2078 push_return(op->op_next);
2079 PUSHBLOCK(cx, CXt_SUB, MARK);
2080 PUSHSUB(cx);
2081 CvDEPTH(cv)++;
2082 if (CvDEPTH(cv) < 2)
2083 (void)SvREFCNT_inc(cv);
2084 else { /* save temporaries on recursion? */
5f05dabc 2085 if (CvDEPTH(cv) == 100 && dowarn
84902520 2086 && !(PERLDB_SUB && cv == GvCV(DBsub)))
44a8e56a 2087 sub_crush_depth(cv);
a0d0e21e
LW
2088 if (CvDEPTH(cv) > AvFILL(padlist)) {
2089 AV *av;
2090 AV *newpad = newAV();
4aa0a1f7 2091 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
a0d0e21e
LW
2092 I32 ix = AvFILL((AV*)svp[1]);
2093 svp = AvARRAY(svp[0]);
748a9306 2094 for ( ;ix > 0; ix--) {
a0d0e21e 2095 if (svp[ix] != &sv_undef) {
748a9306 2096 char *name = SvPVX(svp[ix]);
5f05dabc
PP
2097 if ((SvFLAGS(svp[ix]) & SVf_FAKE) /* outer lexical? */
2098 || *name == '&') /* anonymous code? */
2099 {
2100 av_store(newpad, ix, SvREFCNT_inc(oldpad[ix]));
748a9306
LW
2101 }
2102 else { /* our own lexical */
2103 if (*name == '@')
2104 av_store(newpad, ix, sv = (SV*)newAV());
2105 else if (*name == '%')
2106 av_store(newpad, ix, sv = (SV*)newHV());
2107 else
2108 av_store(newpad, ix, sv = NEWSV(0,0));
2109 SvPADMY_on(sv);
2110 }
a0d0e21e
LW
2111 }
2112 else {
748a9306 2113 av_store(newpad, ix, sv = NEWSV(0,0));
a0d0e21e
LW
2114 SvPADTMP_on(sv);
2115 }
2116 }
2117 av = newAV(); /* will be @_ */
2118 av_extend(av, 0);
2119 av_store(newpad, 0, (SV*)av);
2120 AvFLAGS(av) = AVf_REIFY;
2121 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
2122 AvFILL(padlist) = CvDEPTH(cv);
2123 svp = AvARRAY(padlist);
2124 }
2125 }
6d4ff0d2
MB
2126#ifdef USE_THREADS
2127 if (!hasargs) {
a0d0e21e 2128 AV* av = (AV*)curpad[0];
6d4ff0d2
MB
2129
2130 items = AvFILL(av) + 1;
2131 if (items) {
2132 /* Mark is at the end of the stack. */
2133 EXTEND(sp, items);
2134 Copy(AvARRAY(av), sp + 1, items, SV*);
2135 sp += items;
2136 PUTBACK ;
2137 }
2138 }
2139#endif /* USE_THREADS */
2140 SAVESPTR(curpad);
2141 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
2142#ifndef USE_THREADS
2143 if (hasargs)
2144#endif /* USE_THREADS */
2145 {
2146 AV* av;
a0d0e21e
LW
2147 SV** ary;
2148
77a005ab 2149#if 0
0f15f207
MB
2150 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
2151 "%p entersub preparing @_\n", thr));
77a005ab 2152#endif
6d4ff0d2 2153 av = (AV*)curpad[0];
a0d0e21e
LW
2154 if (AvREAL(av)) {
2155 av_clear(av);
2156 AvREAL_off(av);
2157 }
6d4ff0d2 2158#ifndef USE_THREADS
a0d0e21e 2159 cx->blk_sub.savearray = GvAV(defgv);
0c8c7a05 2160 GvAV(defgv) = (AV*)SvREFCNT_inc(av);
6d4ff0d2
MB
2161#endif /* USE_THREADS */
2162 cx->blk_sub.argarray = av;
a0d0e21e
LW
2163 ++MARK;
2164
2165 if (items > AvMAX(av) + 1) {
2166 ary = AvALLOC(av);
2167 if (AvARRAY(av) != ary) {
2168 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
2169 SvPVX(av) = (char*)ary;
2170 }
2171 if (items > AvMAX(av) + 1) {
2172 AvMAX(av) = items - 1;
2173 Renew(ary,items,SV*);
2174 AvALLOC(av) = ary;
2175 SvPVX(av) = (char*)ary;
2176 }
2177 }
2178 Copy(MARK,AvARRAY(av),items,SV*);
2179 AvFILL(av) = items - 1;
2180
2181 while (items--) {
2182 if (*MARK)
2183 SvTEMP_off(*MARK);
2184 MARK++;
2185 }
2186 }
77a005ab 2187#if 0
0f15f207
MB
2188 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
2189 "%p entersub returning %p\n", thr, CvSTART(cv)));
77a005ab 2190#endif
a0d0e21e
LW
2191 RETURNOP(CvSTART(cv));
2192 }
2193}
2194
44a8e56a 2195void
8ac85365 2196sub_crush_depth(CV *cv)
44a8e56a
PP
2197{
2198 if (CvANON(cv))
2199 warn("Deep recursion on anonymous subroutine");
2200 else {
2201 SV* tmpstr = sv_newmortal();
2202 gv_efullname3(tmpstr, CvGV(cv), Nullch);
2203 warn("Deep recursion on subroutine \"%s\"", SvPVX(tmpstr));
2204 }
2205}
2206
a0d0e21e
LW
2207PP(pp_aelem)
2208{
4e35701f 2209 djSP;
a0d0e21e 2210 SV** svp;
748a9306 2211 I32 elem = POPi;
68dc0745
PP
2212 AV* av = (AV*)POPs;
2213 U32 lval = op->op_flags & OPf_MOD;
2214 U32 defer = (op->op_private & OPpLVAL_DEFER) && (elem > AvFILL(av));
a0d0e21e 2215
748a9306
LW
2216 if (elem > 0)
2217 elem -= curcop->cop_arybase;
a0d0e21e
LW
2218 if (SvTYPE(av) != SVt_PVAV)
2219 RETPUSHUNDEF;
68dc0745 2220 svp = av_fetch(av, elem, lval && !defer);
a0d0e21e 2221 if (lval) {
68dc0745
PP
2222 if (!svp || *svp == &sv_undef) {
2223 SV* lv;
2224 if (!defer)
2225 DIE(no_aelem, elem);
2226 lv = sv_newmortal();
2227 sv_upgrade(lv, SVt_PVLV);
2228 LvTYPE(lv) = 'y';
2229 sv_magic(lv, Nullsv, 'y', Nullch, 0);
2230 LvTARG(lv) = SvREFCNT_inc(av);
2231 LvTARGOFF(lv) = elem;
2232 LvTARGLEN(lv) = 1;
2233 PUSHs(lv);
2234 RETURN;
2235 }
a0d0e21e
LW
2236 if (op->op_private & OPpLVAL_INTRO)
2237 save_svref(svp);
5f05dabc 2238 else if (op->op_private & OPpDEREF)
68dc0745 2239 vivify_ref(*svp, op->op_private & OPpDEREF);
a0d0e21e
LW
2240 }
2241 PUSHs(svp ? *svp : &sv_undef);
2242 RETURN;
2243}
2244
02a9e968 2245void
8ac85365 2246vivify_ref(SV *sv, U32 to_what)
02a9e968
CS
2247{
2248 if (SvGMAGICAL(sv))
2249 mg_get(sv);
2250 if (!SvOK(sv)) {
2251 if (SvREADONLY(sv))
2252 croak(no_modify);
5f05dabc
PP
2253 if (SvTYPE(sv) < SVt_RV)
2254 sv_upgrade(sv, SVt_RV);
2255 else if (SvTYPE(sv) >= SVt_PV) {
2256 (void)SvOOK_off(sv);
2257 Safefree(SvPVX(sv));
2258 SvLEN(sv) = SvCUR(sv) = 0;
2259 }
68dc0745 2260 switch (to_what) {
5f05dabc
PP
2261 case OPpDEREF_SV:
2262 SvRV(sv) = newSV(0);
2263 break;
2264 case OPpDEREF_AV:
2265 SvRV(sv) = (SV*)newAV();
2266 break;
2267 case OPpDEREF_HV:
2268 SvRV(sv) = (SV*)newHV();
2269 break;
2270 }
02a9e968
CS
2271 SvROK_on(sv);
2272 SvSETMAGIC(sv);
2273 }
2274}
2275
a0d0e21e
LW
2276PP(pp_method)
2277{
4e35701f 2278 djSP;
a0d0e21e
LW
2279 SV* sv;
2280 SV* ob;
2281 GV* gv;
56304f61
CS
2282 HV* stash;
2283 char* name;
ac91690f
CS
2284 char* packname;
2285 STRLEN packlen;
a0d0e21e 2286
fb73857a
PP
2287 if (SvROK(TOPs)) {
2288 sv = SvRV(TOPs);
2289 if (SvTYPE(sv) == SVt_PVCV) {
2290 SETs(sv);
2291 RETURN;
2292 }
2293 }
2294
56304f61 2295 name = SvPV(TOPs, na);
a0d0e21e
LW
2296 sv = *(stack_base + TOPMARK + 1);
2297
16d20bd9
AD
2298 if (SvGMAGICAL(sv))
2299 mg_get(sv);
a0d0e21e 2300 if (SvROK(sv))
16d20bd9 2301 ob = (SV*)SvRV(sv);
a0d0e21e
LW
2302 else {
2303 GV* iogv;
a0d0e21e 2304
56304f61 2305 packname = Nullch;
a0d0e21e 2306 if (!SvOK(sv) ||
56304f61 2307 !(packname = SvPV(sv, packlen)) ||
a0d0e21e
LW
2308 !(iogv = gv_fetchpv(packname, FALSE, SVt_PVIO)) ||
2309 !(ob=(SV*)GvIO(iogv)))
2310 {
56304f61 2311 if (!packname || !isIDFIRST(*packname))
ac91690f 2312 DIE("Can't call method \"%s\" without a package or object reference", name);
56304f61 2313 stash = gv_stashpvn(packname, packlen, TRUE);
ac91690f 2314 goto fetch;
a0d0e21e 2315 }
ac91690f 2316 *(stack_base + TOPMARK + 1) = sv_2mortal(newRV((SV*)iogv));
a0d0e21e
LW
2317 }
2318
ac91690f 2319 if (!ob || !SvOBJECT(ob))
a0d0e21e 2320 DIE("Can't call method \"%s\" on unblessed reference", name);
a0d0e21e 2321
56304f61 2322 stash = SvSTASH(ob);
a0d0e21e 2323
ac91690f 2324 fetch:
ac91690f 2325 gv = gv_fetchmethod(stash, name);
56304f61
CS
2326 if (!gv) {
2327 char* leaf = name;
2328 char* sep = Nullch;
2329 char* p;
2330
2331 for (p = name; *p; p++) {
2332 if (*p == '\'')
2333 sep = p, leaf = p + 1;
2334 else if (*p == ':' && *(p + 1) == ':')
2335 sep = p, leaf = p + 2;
2336 }
2337 if (!sep || ((sep - name) == 5 && strnEQ(name, "SUPER", 5))) {
2338 packname = HvNAME(sep ? curcop->cop_stash : stash);
2339 packlen = strlen(packname);
2340 }
2341 else {
2342 packname = name;
2343 packlen = sep - name;
2344 }
2345 DIE("Can't locate object method \"%s\" via package \"%.*s\"",
2346 leaf, (int)packlen, packname);
2347 }
8ebc5c01 2348 SETs(isGV(gv) ? (SV*)GvCV(gv) : (SV*)gv);
a0d0e21e
LW
2349 RETURN;
2350}
22239a37 2351