3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * Then he heard Merry change the note, and up went the Horn-cry of Buckland,
15 * Awake! Awake! Fear, Fire, Foes! Awake!
20 #define PERL_IN_PP_HOT_C
34 PL_curcop = (COP*)PL_op;
35 TAINT_NOT; /* Each statement is presumed innocent */
36 PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
45 if (PL_op->op_private & OPpLVAL_INTRO)
46 PUSHs(save_scalar(cGVOP_gv));
48 PUSHs(GvSV(cGVOP_gv));
59 PL_curcop = (COP*)PL_op;
65 PUSHMARK(PL_stack_sp);
80 XPUSHs((SV*)cGVOP_gv);
91 RETURNOP(cLOGOP->op_other);
99 if (PL_op->op_private & OPpASSIGN_BACKWARDS) {
101 temp = left; left = right; right = temp;
103 if (PL_tainting && PL_tainted && !SvTAINTED(left))
105 SvSetMagicSV(right, left);
114 RETURNOP(cLOGOP->op_other);
116 RETURNOP(cLOGOP->op_next);
122 TAINT_NOT; /* Each statement is presumed innocent */
123 PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
125 oldsave = PL_scopestack[PL_scopestack_ix - 1];
126 LEAVE_SCOPE(oldsave);
132 dSP; dATARGET; tryAMAGICbin(concat,opASSIGN);
139 char* rpv = SvPV(right, rlen); /* mg_get(right) happens here */
140 bool rbyte = !SvUTF8(right), rcopied = FALSE;
142 if (TARG == right && right != left) {
143 right = sv_2mortal(newSVpvn(rpv, rlen));
144 rpv = SvPV(right, rlen); /* no point setting UTF-8 here */
149 lpv = SvPV(left, llen); /* mg_get(left) may happen here */
150 lbyte = !SvUTF8(left);
151 sv_setpvn(TARG, lpv, llen);
157 else { /* TARG == left */
158 if (SvGMAGICAL(left))
159 mg_get(left); /* or mg_get(left) may happen here */
162 lpv = SvPV_nomg(left, llen);
163 lbyte = !SvUTF8(left);
166 #if defined(PERL_Y2KWARN)
167 if ((SvIOK(right) || SvNOK(right)) && ckWARN(WARN_Y2K) && SvOK(TARG)) {
168 if (llen >= 2 && lpv[llen - 2] == '1' && lpv[llen - 1] == '9'
169 && (llen == 2 || !isDIGIT(lpv[llen - 3])))
171 Perl_warner(aTHX_ packWARN(WARN_Y2K), "Possible Y2K bug: %s",
172 "about to append an integer to '19'");
177 if (lbyte != rbyte) {
179 sv_utf8_upgrade_nomg(TARG);
182 right = sv_2mortal(newSVpvn(rpv, rlen));
183 sv_utf8_upgrade_nomg(right);
184 rpv = SvPV(right, rlen);
187 sv_catpvn_nomg(TARG, rpv, rlen);
198 if (PL_op->op_flags & OPf_MOD) {
199 if (PL_op->op_private & OPpLVAL_INTRO)
200 SAVECLEARSV(PAD_SVl(PL_op->op_targ));
201 else if (PL_op->op_private & OPpDEREF) {
203 vivify_ref(PAD_SVl(PL_op->op_targ), PL_op->op_private & OPpDEREF);
212 tryAMAGICunTARGET(iter, 0);
213 PL_last_in_gv = (GV*)(*PL_stack_sp--);
214 if (SvTYPE(PL_last_in_gv) != SVt_PVGV) {
215 if (SvROK(PL_last_in_gv) && SvTYPE(SvRV(PL_last_in_gv)) == SVt_PVGV)
216 PL_last_in_gv = (GV*)SvRV(PL_last_in_gv);
219 XPUSHs((SV*)PL_last_in_gv);
222 PL_last_in_gv = (GV*)(*PL_stack_sp--);
225 return do_readline();
230 dSP; tryAMAGICbinSET(eq,0);
231 #ifndef NV_PRESERVES_UV
232 if (SvROK(TOPs) && SvROK(TOPm1s)) {
234 SETs(boolSV(SvRV(TOPs) == SvRV(TOPp1s)));
238 #ifdef PERL_PRESERVE_IVUV
241 /* Unless the left argument is integer in range we are going
242 to have to use NV maths. Hence only attempt to coerce the
243 right argument if we know the left is integer. */
246 bool auvok = SvUOK(TOPm1s);
247 bool buvok = SvUOK(TOPs);
249 if (auvok == buvok) { /* ## IV == IV or UV == UV ## */
250 /* Casting IV to UV before comparison isn't going to matter
251 on 2s complement. On 1s complement or sign&magnitude
252 (if we have any of them) it could to make negative zero
253 differ from normal zero. As I understand it. (Need to
254 check - is negative zero implementation defined behaviour
256 UV buv = SvUVX(POPs);
257 UV auv = SvUVX(TOPs);
259 SETs(boolSV(auv == buv));
262 { /* ## Mixed IV,UV ## */
266 /* == is commutative so doesn't matter which is left or right */
268 /* top of stack (b) is the iv */
277 /* As uv is a UV, it's >0, so it cannot be == */
281 /* we know iv is >= 0 */
282 SETs(boolSV((UV)iv == SvUVX(uvp)));
290 SETs(boolSV(TOPn == value));
298 if (SvTYPE(TOPs) > SVt_PVLV)
299 DIE(aTHX_ PL_no_modify);
300 if (!SvREADONLY(TOPs) && SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs)
301 && SvIVX(TOPs) != IV_MAX)
304 SvFLAGS(TOPs) &= ~(SVp_NOK|SVp_POK);
306 else /* Do all the PERL_PRESERVE_IVUV conditionals in sv_inc */
319 RETURNOP(cLOGOP->op_other);
325 /* Most of this is lifted straight from pp_defined */
330 if (!sv || !SvANY(sv)) {
332 RETURNOP(cLOGOP->op_other);
335 switch (SvTYPE(sv)) {
337 if (AvMAX(sv) >= 0 || SvGMAGICAL(sv) || (SvRMAGICAL(sv) && mg_find(sv, PERL_MAGIC_tied)))
341 if (HvARRAY(sv) || SvGMAGICAL(sv) || (SvRMAGICAL(sv) && mg_find(sv, PERL_MAGIC_tied)))
345 if (CvROOT(sv) || CvXSUB(sv))
356 RETURNOP(cLOGOP->op_other);
361 dSP; dATARGET; bool useleft; tryAMAGICbin(add,opASSIGN);
362 useleft = USE_LEFT(TOPm1s);
363 #ifdef PERL_PRESERVE_IVUV
364 /* We must see if we can perform the addition with integers if possible,
365 as the integer code detects overflow while the NV code doesn't.
366 If either argument hasn't had a numeric conversion yet attempt to get
367 the IV. It's important to do this now, rather than just assuming that
368 it's not IOK as a PV of "9223372036854775806" may not take well to NV
369 addition, and an SV which is NOK, NV=6.0 ought to be coerced to
370 integer in case the second argument is IV=9223372036854775806
371 We can (now) rely on sv_2iv to do the right thing, only setting the
372 public IOK flag if the value in the NV (or PV) slot is truly integer.
374 A side effect is that this also aggressively prefers integer maths over
375 fp maths for integer values.
377 How to detect overflow?
379 C 99 section 6.2.6.1 says
381 The range of nonnegative values of a signed integer type is a subrange
382 of the corresponding unsigned integer type, and the representation of
383 the same value in each type is the same. A computation involving
384 unsigned operands can never overflow, because a result that cannot be
385 represented by the resulting unsigned integer type is reduced modulo
386 the number that is one greater than the largest value that can be
387 represented by the resulting type.
391 which I read as "unsigned ints wrap."
393 signed integer overflow seems to be classed as "exception condition"
395 If an exceptional condition occurs during the evaluation of an
396 expression (that is, if the result is not mathematically defined or not
397 in the range of representable values for its type), the behavior is
400 (6.5, the 5th paragraph)
402 I had assumed that on 2s complement machines signed arithmetic would
403 wrap, hence coded pp_add and pp_subtract on the assumption that
404 everything perl builds on would be happy. After much wailing and
405 gnashing of teeth it would seem that irix64 knows its ANSI spec well,
406 knows that it doesn't need to, and doesn't. Bah. Anyway, the all-
407 unsigned code below is actually shorter than the old code. :-)
412 /* Unless the left argument is integer in range we are going to have to
413 use NV maths. Hence only attempt to coerce the right argument if
414 we know the left is integer. */
422 /* left operand is undef, treat as zero. + 0 is identity,
423 Could SETi or SETu right now, but space optimise by not adding
424 lots of code to speed up what is probably a rarish case. */
426 /* Left operand is defined, so is it IV? */
429 if ((auvok = SvUOK(TOPm1s)))
432 register IV aiv = SvIVX(TOPm1s);
435 auvok = 1; /* Now acting as a sign flag. */
436 } else { /* 2s complement assumption for IV_MIN */
444 bool result_good = 0;
447 bool buvok = SvUOK(TOPs);
452 register IV biv = SvIVX(TOPs);
459 /* ?uvok if value is >= 0. basically, flagged as UV if it's +ve,
460 else "IV" now, independent of how it came in.
461 if a, b represents positive, A, B negative, a maps to -A etc
466 all UV maths. negate result if A negative.
467 add if signs same, subtract if signs differ. */
473 /* Must get smaller */
479 /* result really should be -(auv-buv). as its negation
480 of true value, need to swap our result flag */
497 if (result <= (UV)IV_MIN)
500 /* result valid, but out of range for IV. */
505 } /* Overflow, drop through to NVs. */
512 /* left operand is undef, treat as zero. + 0.0 is identity. */
516 SETn( value + TOPn );
524 AV *av = GvAV(cGVOP_gv);
525 U32 lval = PL_op->op_flags & OPf_MOD;
526 SV** svp = av_fetch(av, PL_op->op_private, lval);
527 SV *sv = (svp ? *svp : &PL_sv_undef);
529 if (!lval && SvGMAGICAL(sv)) /* see note in pp_helem() */
530 sv = sv_mortalcopy(sv);
539 do_join(TARG, *MARK, MARK, SP);
550 * We ass_u_me that LvTARGOFF() comes first, and that two STRLENs
551 * will be enough to hold an OP*.
553 SV* sv = sv_newmortal();
554 sv_upgrade(sv, SVt_PVLV);
556 Copy(&PL_op, &LvTARGOFF(sv), 1, OP*);
564 /* Oversized hot code. */
568 dSP; dMARK; dORIGMARK;
574 if (PL_op->op_flags & OPf_STACKED)
579 if (gv && (io = GvIO(gv))
580 && (mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar)))
583 if (MARK == ORIGMARK) {
584 /* If using default handle then we need to make space to
585 * pass object as 1st arg, so move other args up ...
589 Move(MARK, MARK + 1, (SP - MARK) + 1, SV*);
593 *MARK = SvTIED_obj((SV*)io, mg);
596 call_method("PRINT", G_SCALAR);
604 if (!(io = GvIO(gv))) {
605 if ((GvEGV(gv)) && (io = GvIO(GvEGV(gv)))
606 && (mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar)))
608 if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
609 report_evil_fh(gv, io, PL_op->op_type);
610 SETERRNO(EBADF,RMS_IFI);
613 else if (!(fp = IoOFP(io))) {
614 if (ckWARN2(WARN_CLOSED, WARN_IO)) {
616 report_evil_fh(gv, io, OP_phoney_INPUT_ONLY);
617 else if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
618 report_evil_fh(gv, io, PL_op->op_type);
620 SETERRNO(EBADF,IoIFP(io)?RMS_FAC:RMS_IFI);
625 if (PL_ofs_sv && SvOK(PL_ofs_sv)) {
627 if (!do_print(*MARK, fp))
631 if (!do_print(PL_ofs_sv, fp)) { /* $, */
640 if (!do_print(*MARK, fp))
648 if (PL_ors_sv && SvOK(PL_ors_sv))
649 if (!do_print(PL_ors_sv, fp)) /* $\ */
652 if (IoFLAGS(io) & IOf_FLUSH)
653 if (PerlIO_flush(fp) == EOF)
674 tryAMAGICunDEREF(to_av);
677 if (SvTYPE(av) != SVt_PVAV)
678 DIE(aTHX_ "Not an ARRAY reference");
679 if (PL_op->op_flags & OPf_REF) {
684 if (GIMME == G_SCALAR)
685 Perl_croak(aTHX_ "Can't return array to lvalue scalar context");
689 else if (PL_op->op_flags & OPf_MOD
690 && PL_op->op_private & OPpLVAL_INTRO)
691 Perl_croak(aTHX_ PL_no_localize_ref);
694 if (SvTYPE(sv) == SVt_PVAV) {
696 if (PL_op->op_flags & OPf_REF) {
701 if (GIMME == G_SCALAR)
702 Perl_croak(aTHX_ "Can't return array to lvalue"
711 if (SvTYPE(sv) != SVt_PVGV) {
715 if (SvGMAGICAL(sv)) {
721 if (PL_op->op_flags & OPf_REF ||
722 PL_op->op_private & HINT_STRICT_REFS)
723 DIE(aTHX_ PL_no_usym, "an ARRAY");
724 if (ckWARN(WARN_UNINITIALIZED))
726 if (GIMME == G_ARRAY) {
733 if ((PL_op->op_flags & OPf_SPECIAL) &&
734 !(PL_op->op_flags & OPf_MOD))
736 gv = (GV*)gv_fetchpv(sym, FALSE, SVt_PVAV);
738 && (!is_gv_magical(sym,len,0)
739 || !(gv = (GV*)gv_fetchpv(sym, TRUE, SVt_PVAV))))
745 if (PL_op->op_private & HINT_STRICT_REFS)
746 DIE(aTHX_ PL_no_symref, sym, "an ARRAY");
747 gv = (GV*)gv_fetchpv(sym, TRUE, SVt_PVAV);
754 if (PL_op->op_private & OPpLVAL_INTRO)
756 if (PL_op->op_flags & OPf_REF) {
761 if (GIMME == G_SCALAR)
762 Perl_croak(aTHX_ "Can't return array to lvalue"
770 if (GIMME == G_ARRAY) {
771 I32 maxarg = AvFILL(av) + 1;
772 (void)POPs; /* XXXX May be optimized away? */
774 if (SvRMAGICAL(av)) {
776 for (i=0; i < (U32)maxarg; i++) {
777 SV **svp = av_fetch(av, i, FALSE);
778 SP[i+1] = (svp) ? *svp : &PL_sv_undef;
782 Copy(AvARRAY(av), SP+1, maxarg, SV*);
786 else if (GIMME_V == G_SCALAR) {
788 I32 maxarg = AvFILL(av) + 1;
802 tryAMAGICunDEREF(to_hv);
805 if (SvTYPE(hv) != SVt_PVHV)
806 DIE(aTHX_ "Not a HASH reference");
807 if (PL_op->op_flags & OPf_REF) {
812 if (gimme != G_ARRAY)
813 Perl_croak(aTHX_ "Can't return hash to lvalue scalar context");
817 else if (PL_op->op_flags & OPf_MOD
818 && PL_op->op_private & OPpLVAL_INTRO)
819 Perl_croak(aTHX_ PL_no_localize_ref);
822 if (SvTYPE(sv) == SVt_PVHV) {
824 if (PL_op->op_flags & OPf_REF) {
829 if (gimme != G_ARRAY)
830 Perl_croak(aTHX_ "Can't return hash to lvalue"
839 if (SvTYPE(sv) != SVt_PVGV) {
843 if (SvGMAGICAL(sv)) {
849 if (PL_op->op_flags & OPf_REF ||
850 PL_op->op_private & HINT_STRICT_REFS)
851 DIE(aTHX_ PL_no_usym, "a HASH");
852 if (ckWARN(WARN_UNINITIALIZED))
854 if (gimme == G_ARRAY) {
861 if ((PL_op->op_flags & OPf_SPECIAL) &&
862 !(PL_op->op_flags & OPf_MOD))
864 gv = (GV*)gv_fetchpv(sym, FALSE, SVt_PVHV);
866 && (!is_gv_magical(sym,len,0)
867 || !(gv = (GV*)gv_fetchpv(sym, TRUE, SVt_PVHV))))
873 if (PL_op->op_private & HINT_STRICT_REFS)
874 DIE(aTHX_ PL_no_symref, sym, "a HASH");
875 gv = (GV*)gv_fetchpv(sym, TRUE, SVt_PVHV);
882 if (PL_op->op_private & OPpLVAL_INTRO)
884 if (PL_op->op_flags & OPf_REF) {
889 if (gimme != G_ARRAY)
890 Perl_croak(aTHX_ "Can't return hash to lvalue"
898 if (gimme == G_ARRAY) { /* array wanted */
899 *PL_stack_sp = (SV*)hv;
902 else if (gimme == G_SCALAR) {
904 if (SvRMAGICAL(hv) && mg_find((SV *)hv, PERL_MAGIC_tied))
905 Perl_croak(aTHX_ "Can't provide tied hash usage; "
906 "use keys(%%hash) to test if empty");
908 Perl_sv_setpvf(aTHX_ TARG, "%"IVdf"/%"IVdf,
909 (IV)HvFILL(hv), (IV)HvMAX(hv) + 1);
919 S_do_oddball(pTHX_ HV *hash, SV **relem, SV **firstrelem)
925 if (ckWARN(WARN_MISC)) {
926 if (relem == firstrelem &&
928 (SvTYPE(SvRV(*relem)) == SVt_PVAV ||
929 SvTYPE(SvRV(*relem)) == SVt_PVHV))
931 Perl_warner(aTHX_ packWARN(WARN_MISC),
932 "Reference found where even-sized list expected");
935 Perl_warner(aTHX_ packWARN(WARN_MISC),
936 "Odd number of elements in hash assignment");
939 tmpstr = NEWSV(29,0);
940 didstore = hv_store_ent(hash,*relem,tmpstr,0);
941 if (SvMAGICAL(hash)) {
942 if (SvSMAGICAL(tmpstr))
954 SV **lastlelem = PL_stack_sp;
955 SV **lastrelem = PL_stack_base + POPMARK;
956 SV **firstrelem = PL_stack_base + POPMARK + 1;
957 SV **firstlelem = lastrelem + 1;
970 SV **firsthashrelem = 0; /* "= 0" keeps gcc 2.95 quiet */
973 PL_delaymagic = DM_DELAY; /* catch simultaneous items */
976 /* If there's a common identifier on both sides we have to take
977 * special care that assigning the identifier on the left doesn't
978 * clobber a value on the right that's used later in the list.
980 if (PL_op->op_private & (OPpASSIGN_COMMON)) {
981 EXTEND_MORTAL(lastrelem - firstrelem + 1);
982 for (relem = firstrelem; relem <= lastrelem; relem++) {
985 TAINT_NOT; /* Each item is independent */
986 *relem = sv_mortalcopy(sv);
996 while (lelem <= lastlelem) {
997 TAINT_NOT; /* Each item stands on its own, taintwise. */
999 switch (SvTYPE(sv)) {
1002 magic = SvMAGICAL(ary) != 0;
1004 av_extend(ary, lastrelem - relem);
1006 while (relem <= lastrelem) { /* gobble up all the rest */
1010 sv_setsv(sv,*relem);
1012 didstore = av_store(ary,i++,sv);
1022 case SVt_PVHV: { /* normal hash */
1026 magic = SvMAGICAL(hash) != 0;
1028 firsthashrelem = relem;
1030 while (relem < lastrelem) { /* gobble up all the rest */
1035 sv = &PL_sv_no, relem++;
1036 tmpstr = NEWSV(29,0);
1038 sv_setsv(tmpstr,*relem); /* value */
1039 *(relem++) = tmpstr;
1040 if (gimme != G_VOID && hv_exists_ent(hash, sv, 0))
1041 /* key overwrites an existing entry */
1043 didstore = hv_store_ent(hash,sv,tmpstr,0);
1045 if (SvSMAGICAL(tmpstr))
1052 if (relem == lastrelem) {
1053 do_oddball(hash, relem, firstrelem);
1059 if (SvIMMORTAL(sv)) {
1060 if (relem <= lastrelem)
1064 if (relem <= lastrelem) {
1065 sv_setsv(sv, *relem);
1069 sv_setsv(sv, &PL_sv_undef);
1074 if (PL_delaymagic & ~DM_DELAY) {
1075 if (PL_delaymagic & DM_UID) {
1076 #ifdef HAS_SETRESUID
1077 (void)setresuid((PL_delaymagic & DM_RUID) ? PL_uid : (Uid_t)-1,
1078 (PL_delaymagic & DM_EUID) ? PL_euid : (Uid_t)-1,
1081 # ifdef HAS_SETREUID
1082 (void)setreuid((PL_delaymagic & DM_RUID) ? PL_uid : (Uid_t)-1,
1083 (PL_delaymagic & DM_EUID) ? PL_euid : (Uid_t)-1);
1086 if ((PL_delaymagic & DM_UID) == DM_RUID) {
1087 (void)setruid(PL_uid);
1088 PL_delaymagic &= ~DM_RUID;
1090 # endif /* HAS_SETRUID */
1092 if ((PL_delaymagic & DM_UID) == DM_EUID) {
1093 (void)seteuid(PL_euid);
1094 PL_delaymagic &= ~DM_EUID;
1096 # endif /* HAS_SETEUID */
1097 if (PL_delaymagic & DM_UID) {
1098 if (PL_uid != PL_euid)
1099 DIE(aTHX_ "No setreuid available");
1100 (void)PerlProc_setuid(PL_uid);
1102 # endif /* HAS_SETREUID */
1103 #endif /* HAS_SETRESUID */
1104 PL_uid = PerlProc_getuid();
1105 PL_euid = PerlProc_geteuid();
1107 if (PL_delaymagic & DM_GID) {
1108 #ifdef HAS_SETRESGID
1109 (void)setresgid((PL_delaymagic & DM_RGID) ? PL_gid : (Gid_t)-1,
1110 (PL_delaymagic & DM_EGID) ? PL_egid : (Gid_t)-1,
1113 # ifdef HAS_SETREGID
1114 (void)setregid((PL_delaymagic & DM_RGID) ? PL_gid : (Gid_t)-1,
1115 (PL_delaymagic & DM_EGID) ? PL_egid : (Gid_t)-1);
1118 if ((PL_delaymagic & DM_GID) == DM_RGID) {
1119 (void)setrgid(PL_gid);
1120 PL_delaymagic &= ~DM_RGID;
1122 # endif /* HAS_SETRGID */
1124 if ((PL_delaymagic & DM_GID) == DM_EGID) {
1125 (void)setegid(PL_egid);
1126 PL_delaymagic &= ~DM_EGID;
1128 # endif /* HAS_SETEGID */
1129 if (PL_delaymagic & DM_GID) {
1130 if (PL_gid != PL_egid)
1131 DIE(aTHX_ "No setregid available");
1132 (void)PerlProc_setgid(PL_gid);
1134 # endif /* HAS_SETREGID */
1135 #endif /* HAS_SETRESGID */
1136 PL_gid = PerlProc_getgid();
1137 PL_egid = PerlProc_getegid();
1139 PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
1143 if (gimme == G_VOID)
1144 SP = firstrelem - 1;
1145 else if (gimme == G_SCALAR) {
1148 SETi(lastrelem - firstrelem + 1 - duplicates);
1155 /* Removes from the stack the entries which ended up as
1156 * duplicated keys in the hash (fix for [perl #24380]) */
1157 Move(firsthashrelem + duplicates,
1158 firsthashrelem, duplicates, SV**);
1159 lastrelem -= duplicates;
1164 SP = firstrelem + (lastlelem - firstlelem);
1165 lelem = firstlelem + (relem - firstrelem);
1167 *relem++ = (lelem <= lastlelem) ? *lelem++ : &PL_sv_undef;
1175 register PMOP *pm = cPMOP;
1176 SV *rv = sv_newmortal();
1177 SV *sv = newSVrv(rv, "Regexp");
1178 if (pm->op_pmdynflags & PMdf_TAINTED)
1180 sv_magic(sv,(SV*)ReREFCNT_inc(PM_GETRE(pm)), PERL_MAGIC_qr,0,0);
1187 register PMOP *pm = cPMOP;
1193 I32 r_flags = REXEC_CHECKED;
1194 char *truebase; /* Start of string */
1195 register REGEXP *rx = PM_GETRE(pm);
1200 I32 oldsave = PL_savestack_ix;
1201 I32 update_minmatch = 1;
1202 I32 had_zerolen = 0;
1204 if (PL_op->op_flags & OPf_STACKED)
1211 PUTBACK; /* EVAL blocks need stack_sp. */
1212 s = SvPV(TARG, len);
1215 DIE(aTHX_ "panic: pp_match");
1216 rxtainted = ((pm->op_pmdynflags & PMdf_TAINTED) ||
1217 (PL_tainted && (pm->op_pmflags & PMf_RETAINT)));
1220 RX_MATCH_UTF8_set(rx, DO_UTF8(TARG));
1222 /* PMdf_USED is set after a ?? matches once */
1223 if (pm->op_pmdynflags & PMdf_USED) {
1225 if (gimme == G_ARRAY)
1230 /* empty pattern special-cased to use last successful pattern if possible */
1231 if (!rx->prelen && PL_curpm) {
1236 if (rx->minlen > (I32)len)
1241 /* XXXX What part of this is needed with true \G-support? */
1242 if ((global = dynpm->op_pmflags & PMf_GLOBAL)) {
1244 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) {
1245 MAGIC* mg = mg_find(TARG, PERL_MAGIC_regex_global);
1246 if (mg && mg->mg_len >= 0) {
1247 if (!(rx->reganch & ROPT_GPOS_SEEN))
1248 rx->endp[0] = rx->startp[0] = mg->mg_len;
1249 else if (rx->reganch & ROPT_ANCH_GPOS) {
1250 r_flags |= REXEC_IGNOREPOS;
1251 rx->endp[0] = rx->startp[0] = mg->mg_len;
1253 minmatch = (mg->mg_flags & MGf_MINMATCH);
1254 update_minmatch = 0;
1258 if ((!global && rx->nparens)
1259 || SvTEMP(TARG) || PL_sawampersand)
1260 r_flags |= REXEC_COPY_STR;
1262 r_flags |= REXEC_SCREAM;
1264 if ((int)(pm->op_pmflags & PMf_MULTILINE) != PL_multiline) {
1265 SAVEINT(PL_multiline);
1266 PL_multiline = pm->op_pmflags & PMf_MULTILINE;
1270 if (global && rx->startp[0] != -1) {
1271 t = s = rx->endp[0] + truebase;
1272 if ((s + rx->minlen) > strend)
1274 if (update_minmatch++)
1275 minmatch = had_zerolen;
1277 if (rx->reganch & RE_USE_INTUIT &&
1278 DO_UTF8(TARG) == ((rx->reganch & ROPT_UTF8) != 0)) {
1279 PL_bostr = truebase;
1280 s = CALLREG_INTUIT_START(aTHX_ rx, TARG, s, strend, r_flags, NULL);
1284 if ( (rx->reganch & ROPT_CHECK_ALL)
1286 && ((rx->reganch & ROPT_NOSCAN)
1287 || !((rx->reganch & RE_INTUIT_TAIL)
1288 && (r_flags & REXEC_SCREAM)))
1289 && !SvROK(TARG)) /* Cannot trust since INTUIT cannot guess ^ */
1292 if (CALLREGEXEC(aTHX_ rx, s, strend, truebase, minmatch, TARG, NULL, r_flags))
1295 if (dynpm->op_pmflags & PMf_ONCE)
1296 dynpm->op_pmdynflags |= PMdf_USED;
1305 RX_MATCH_TAINTED_on(rx);
1306 TAINT_IF(RX_MATCH_TAINTED(rx));
1307 if (gimme == G_ARRAY) {
1308 I32 nparens, i, len;
1310 nparens = rx->nparens;
1311 if (global && !nparens)
1315 SPAGAIN; /* EVAL blocks could move the stack. */
1316 EXTEND(SP, nparens + i);
1317 EXTEND_MORTAL(nparens + i);
1318 for (i = !i; i <= nparens; i++) {
1319 PUSHs(sv_newmortal());
1321 if ((rx->startp[i] != -1) && rx->endp[i] != -1 ) {
1322 len = rx->endp[i] - rx->startp[i];
1323 if (rx->endp[i] < 0 || rx->startp[i] < 0 ||
1324 len < 0 || len > strend - s)
1325 DIE(aTHX_ "panic: pp_match start/end pointers");
1326 s = rx->startp[i] + truebase;
1327 sv_setpvn(*SP, s, len);
1328 if (DO_UTF8(TARG) && is_utf8_string((U8*)s, len))
1333 if (dynpm->op_pmflags & PMf_CONTINUE) {
1335 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG))
1336 mg = mg_find(TARG, PERL_MAGIC_regex_global);
1338 sv_magic(TARG, (SV*)0, PERL_MAGIC_regex_global, Nullch, 0);
1339 mg = mg_find(TARG, PERL_MAGIC_regex_global);
1341 if (rx->startp[0] != -1) {
1342 mg->mg_len = rx->endp[0];
1343 if (rx->startp[0] == rx->endp[0])
1344 mg->mg_flags |= MGf_MINMATCH;
1346 mg->mg_flags &= ~MGf_MINMATCH;
1349 had_zerolen = (rx->startp[0] != -1
1350 && rx->startp[0] == rx->endp[0]);
1351 PUTBACK; /* EVAL blocks may use stack */
1352 r_flags |= REXEC_IGNOREPOS | REXEC_NOT_FIRST;
1357 LEAVE_SCOPE(oldsave);
1363 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG))
1364 mg = mg_find(TARG, PERL_MAGIC_regex_global);
1366 sv_magic(TARG, (SV*)0, PERL_MAGIC_regex_global, Nullch, 0);
1367 mg = mg_find(TARG, PERL_MAGIC_regex_global);
1369 if (rx->startp[0] != -1) {
1370 mg->mg_len = rx->endp[0];
1371 if (rx->startp[0] == rx->endp[0])
1372 mg->mg_flags |= MGf_MINMATCH;
1374 mg->mg_flags &= ~MGf_MINMATCH;
1377 LEAVE_SCOPE(oldsave);
1381 yup: /* Confirmed by INTUIT */
1383 RX_MATCH_TAINTED_on(rx);
1384 TAINT_IF(RX_MATCH_TAINTED(rx));
1386 if (dynpm->op_pmflags & PMf_ONCE)
1387 dynpm->op_pmdynflags |= PMdf_USED;
1388 if (RX_MATCH_COPIED(rx))
1389 Safefree(rx->subbeg);
1390 RX_MATCH_COPIED_off(rx);
1391 rx->subbeg = Nullch;
1393 rx->subbeg = truebase;
1394 rx->startp[0] = s - truebase;
1395 if (RX_MATCH_UTF8(rx)) {
1396 char *t = (char*)utf8_hop((U8*)s, rx->minlen);
1397 rx->endp[0] = t - truebase;
1400 rx->endp[0] = s - truebase + rx->minlen;
1402 rx->sublen = strend - truebase;
1405 if (PL_sawampersand) {
1407 #ifdef PERL_COPY_ON_WRITE
1408 if (SvIsCOW(TARG) || (SvFLAGS(TARG) & CAN_COW_MASK) == CAN_COW_FLAGS) {
1410 PerlIO_printf(Perl_debug_log,
1411 "Copy on write: pp_match $& capture, type %d, truebase=%p, t=%p, difference %d\n",
1412 (int) SvTYPE(TARG), truebase, t,
1415 rx->saved_copy = sv_setsv_cow(rx->saved_copy, TARG);
1416 rx->subbeg = SvPVX(rx->saved_copy) + (t - truebase);
1417 assert (SvPOKp(rx->saved_copy));
1422 rx->subbeg = savepvn(t, strend - t);
1423 #ifdef PERL_COPY_ON_WRITE
1424 rx->saved_copy = Nullsv;
1427 rx->sublen = strend - t;
1428 RX_MATCH_COPIED_on(rx);
1429 off = rx->startp[0] = s - t;
1430 rx->endp[0] = off + rx->minlen;
1432 else { /* startp/endp are used by @- @+. */
1433 rx->startp[0] = s - truebase;
1434 rx->endp[0] = s - truebase + rx->minlen;
1436 rx->nparens = rx->lastparen = rx->lastcloseparen = 0; /* used by @-, @+, and $^N */
1437 LEAVE_SCOPE(oldsave);
1442 if (global && !(dynpm->op_pmflags & PMf_CONTINUE)) {
1443 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) {
1444 MAGIC* mg = mg_find(TARG, PERL_MAGIC_regex_global);
1449 LEAVE_SCOPE(oldsave);
1450 if (gimme == G_ARRAY)
1456 Perl_do_readline(pTHX)
1458 dSP; dTARGETSTACKED;
1463 register IO *io = GvIO(PL_last_in_gv);
1464 register I32 type = PL_op->op_type;
1465 I32 gimme = GIMME_V;
1468 if (io && (mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar))) {
1470 XPUSHs(SvTIED_obj((SV*)io, mg));
1473 call_method("READLINE", gimme);
1476 if (gimme == G_SCALAR) {
1478 SvSetSV_nosteal(TARG, result);
1487 if (IoFLAGS(io) & IOf_ARGV) {
1488 if (IoFLAGS(io) & IOf_START) {
1490 if (av_len(GvAVn(PL_last_in_gv)) < 0) {
1491 IoFLAGS(io) &= ~IOf_START;
1492 do_open(PL_last_in_gv,"-",1,FALSE,O_RDONLY,0,Nullfp);
1493 sv_setpvn(GvSV(PL_last_in_gv), "-", 1);
1494 SvSETMAGIC(GvSV(PL_last_in_gv));
1499 fp = nextargv(PL_last_in_gv);
1500 if (!fp) { /* Note: fp != IoIFP(io) */
1501 (void)do_close(PL_last_in_gv, FALSE); /* now it does*/
1504 else if (type == OP_GLOB)
1505 fp = Perl_start_glob(aTHX_ POPs, io);
1507 else if (type == OP_GLOB)
1509 else if (ckWARN(WARN_IO) && IoTYPE(io) == IoTYPE_WRONLY) {
1510 report_evil_fh(PL_last_in_gv, io, OP_phoney_OUTPUT_ONLY);
1514 if (ckWARN2(WARN_GLOB, WARN_CLOSED)
1515 && (!io || !(IoFLAGS(io) & IOf_START))) {
1516 if (type == OP_GLOB)
1517 Perl_warner(aTHX_ packWARN(WARN_GLOB),
1518 "glob failed (can't start child: %s)",
1521 report_evil_fh(PL_last_in_gv, io, PL_op->op_type);
1523 if (gimme == G_SCALAR) {
1524 /* undef TARG, and push that undefined value */
1525 if (type != OP_RCATLINE) {
1526 SV_CHECK_THINKFIRST_COW_DROP(TARG);
1527 (void)SvOK_off(TARG);
1534 if (gimme == G_SCALAR) {
1538 (void)SvUPGRADE(sv, SVt_PV);
1539 tmplen = SvLEN(sv); /* remember if already alloced */
1540 if (!tmplen && !SvREADONLY(sv))
1541 Sv_Grow(sv, 80); /* try short-buffering it */
1543 if (type == OP_RCATLINE && SvOK(sv)) {
1546 (void)SvPV_force(sv, n_a);
1552 sv = sv_2mortal(NEWSV(57, 80));
1556 /* This should not be marked tainted if the fp is marked clean */
1557 #define MAYBE_TAINT_LINE(io, sv) \
1558 if (!(IoFLAGS(io) & IOf_UNTAINT)) { \
1563 /* delay EOF state for a snarfed empty file */
1564 #define SNARF_EOF(gimme,rs,io,sv) \
1565 (gimme != G_SCALAR || SvCUR(sv) \
1566 || (IoFLAGS(io) & IOf_NOLINE) || !RsSNARF(rs))
1570 if (!sv_gets(sv, fp, offset)
1572 || SNARF_EOF(gimme, PL_rs, io, sv)
1573 || PerlIO_error(fp)))
1575 PerlIO_clearerr(fp);
1576 if (IoFLAGS(io) & IOf_ARGV) {
1577 fp = nextargv(PL_last_in_gv);
1580 (void)do_close(PL_last_in_gv, FALSE);
1582 else if (type == OP_GLOB) {
1583 if (!do_close(PL_last_in_gv, FALSE) && ckWARN(WARN_GLOB)) {
1584 Perl_warner(aTHX_ packWARN(WARN_GLOB),
1585 "glob failed (child exited with status %d%s)",
1586 (int)(STATUS_CURRENT >> 8),
1587 (STATUS_CURRENT & 0x80) ? ", core dumped" : "");
1590 if (gimme == G_SCALAR) {
1591 if (type != OP_RCATLINE) {
1592 SV_CHECK_THINKFIRST_COW_DROP(TARG);
1593 (void)SvOK_off(TARG);
1598 MAYBE_TAINT_LINE(io, sv);
1601 MAYBE_TAINT_LINE(io, sv);
1603 IoFLAGS(io) |= IOf_NOLINE;
1607 if (type == OP_GLOB) {
1610 if (SvCUR(sv) > 0 && SvCUR(PL_rs) > 0) {
1611 tmps = SvEND(sv) - 1;
1612 if (*tmps == *SvPVX(PL_rs)) {
1617 for (tmps = SvPVX(sv); *tmps; tmps++)
1618 if (!isALPHA(*tmps) && !isDIGIT(*tmps) &&
1619 strchr("$&*(){}[]'\";\\|?<>~`", *tmps))
1621 if (*tmps && PerlLIO_lstat(SvPVX(sv), &PL_statbuf) < 0) {
1622 (void)POPs; /* Unmatched wildcard? Chuck it... */
1625 } else if (SvUTF8(sv)) { /* OP_READLINE, OP_RCATLINE */
1626 U8 *s = (U8*)SvPVX(sv) + offset;
1627 STRLEN len = SvCUR(sv) - offset;
1630 if (ckWARN(WARN_UTF8) &&
1631 !Perl_is_utf8_string_loc(aTHX_ s, len, &f))
1632 /* Emulate :encoding(utf8) warning in the same case. */
1633 Perl_warner(aTHX_ packWARN(WARN_UTF8),
1634 "utf8 \"\\x%02X\" does not map to Unicode",
1635 f < (U8*)SvEND(sv) ? *f : 0);
1637 if (gimme == G_ARRAY) {
1638 if (SvLEN(sv) - SvCUR(sv) > 20) {
1639 SvLEN_set(sv, SvCUR(sv)+1);
1640 Renew(SvPVX(sv), SvLEN(sv), char);
1642 sv = sv_2mortal(NEWSV(58, 80));
1645 else if (gimme == G_SCALAR && !tmplen && SvLEN(sv) - SvCUR(sv) > 80) {
1646 /* try to reclaim a bit of scalar space (only on 1st alloc) */
1650 SvLEN_set(sv, SvCUR(sv)+40); /* allow some slop */
1651 Renew(SvPVX(sv), SvLEN(sv), char);
1660 register PERL_CONTEXT *cx;
1661 I32 gimme = OP_GIMME(PL_op, -1);
1664 if (cxstack_ix >= 0)
1665 gimme = cxstack[cxstack_ix].blk_gimme;
1673 PUSHBLOCK(cx, CXt_BLOCK, SP);
1685 U32 lval = PL_op->op_flags & OPf_MOD || LVRET;
1686 U32 defer = PL_op->op_private & OPpLVAL_DEFER;
1688 #ifdef PERL_COPY_ON_WRITE
1689 U32 hash = (SvIsCOW_shared_hash(keysv)) ? SvUVX(keysv) : 0;
1691 U32 hash = (SvFAKE(keysv) && SvREADONLY(keysv)) ? SvUVX(keysv) : 0;
1695 if (SvTYPE(hv) == SVt_PVHV) {
1696 if (PL_op->op_private & OPpLVAL_INTRO) {
1699 /* does the element we're localizing already exist? */
1701 /* can we determine whether it exists? */
1703 || mg_find((SV*)hv, PERL_MAGIC_env)
1704 || ( (mg = mg_find((SV*)hv, PERL_MAGIC_tied))
1705 /* Try to preserve the existenceness of a tied hash
1706 * element by using EXISTS and DELETE if possible.
1707 * Fallback to FETCH and STORE otherwise */
1708 && (stash = SvSTASH(SvRV(SvTIED_obj((SV*)hv, mg))))
1709 && gv_fetchmethod_autoload(stash, "EXISTS", TRUE)
1710 && gv_fetchmethod_autoload(stash, "DELETE", TRUE)
1712 ) ? hv_exists_ent(hv, keysv, 0) : 1;
1715 he = hv_fetch_ent(hv, keysv, lval && !defer, hash);
1716 svp = he ? &HeVAL(he) : 0;
1722 if (!svp || *svp == &PL_sv_undef) {
1727 DIE(aTHX_ PL_no_helem, SvPV(keysv, n_a));
1729 lv = sv_newmortal();
1730 sv_upgrade(lv, SVt_PVLV);
1732 sv_magic(lv, key2 = newSVsv(keysv), PERL_MAGIC_defelem, Nullch, 0);
1733 SvREFCNT_dec(key2); /* sv_magic() increments refcount */
1734 LvTARG(lv) = SvREFCNT_inc(hv);
1739 if (PL_op->op_private & OPpLVAL_INTRO) {
1740 if (HvNAME(hv) && isGV(*svp))
1741 save_gp((GV*)*svp, !(PL_op->op_flags & OPf_SPECIAL));
1745 char *key = SvPV(keysv, keylen);
1746 SAVEDELETE(hv, savepvn(key,keylen), keylen);
1748 save_helem(hv, keysv, svp);
1751 else if (PL_op->op_private & OPpDEREF)
1752 vivify_ref(*svp, PL_op->op_private & OPpDEREF);
1754 sv = (svp ? *svp : &PL_sv_undef);
1755 /* This makes C<local $tied{foo} = $tied{foo}> possible.
1756 * Pushing the magical RHS on to the stack is useless, since
1757 * that magic is soon destined to be misled by the local(),
1758 * and thus the later pp_sassign() will fail to mg_get() the
1759 * old value. This should also cure problems with delayed
1760 * mg_get()s. GSAR 98-07-03 */
1761 if (!lval && SvGMAGICAL(sv))
1762 sv = sv_mortalcopy(sv);
1770 register PERL_CONTEXT *cx;
1776 if (PL_op->op_flags & OPf_SPECIAL) {
1777 cx = &cxstack[cxstack_ix];
1778 cx->blk_oldpm = PL_curpm; /* fake block should preserve $1 et al */
1783 gimme = OP_GIMME(PL_op, -1);
1785 if (cxstack_ix >= 0)
1786 gimme = cxstack[cxstack_ix].blk_gimme;
1792 if (gimme == G_VOID)
1794 else if (gimme == G_SCALAR) {
1797 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
1800 *MARK = sv_mortalcopy(TOPs);
1803 *MARK = &PL_sv_undef;
1807 else if (gimme == G_ARRAY) {
1808 /* in case LEAVE wipes old return values */
1809 for (mark = newsp + 1; mark <= SP; mark++) {
1810 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
1811 *mark = sv_mortalcopy(*mark);
1812 TAINT_NOT; /* Each item is independent */
1816 PL_curpm = newpm; /* Don't pop $1 et al till now */
1826 register PERL_CONTEXT *cx;
1832 cx = &cxstack[cxstack_ix];
1833 if (CxTYPE(cx) != CXt_LOOP)
1834 DIE(aTHX_ "panic: pp_iter");
1836 itersvp = CxITERVAR(cx);
1837 av = cx->blk_loop.iterary;
1838 if (SvTYPE(av) != SVt_PVAV) {
1839 /* iterate ($min .. $max) */
1840 if (cx->blk_loop.iterlval) {
1841 /* string increment */
1842 register SV* cur = cx->blk_loop.iterlval;
1844 char *max = SvPV((SV*)av, maxlen);
1845 if (!SvNIOK(cur) && SvCUR(cur) <= maxlen) {
1846 if (SvREFCNT(*itersvp) == 1 && !SvMAGICAL(*itersvp)) {
1847 /* safe to reuse old SV */
1848 sv_setsv(*itersvp, cur);
1852 /* we need a fresh SV every time so that loop body sees a
1853 * completely new SV for closures/references to work as
1855 SvREFCNT_dec(*itersvp);
1856 *itersvp = newSVsv(cur);
1858 if (strEQ(SvPVX(cur), max))
1859 sv_setiv(cur, 0); /* terminate next time */
1866 /* integer increment */
1867 if (cx->blk_loop.iterix > cx->blk_loop.itermax)
1870 /* don't risk potential race */
1871 if (SvREFCNT(*itersvp) == 1 && !SvMAGICAL(*itersvp)) {
1872 /* safe to reuse old SV */
1873 sv_setiv(*itersvp, cx->blk_loop.iterix++);
1877 /* we need a fresh SV every time so that loop body sees a
1878 * completely new SV for closures/references to work as they
1880 SvREFCNT_dec(*itersvp);
1881 *itersvp = newSViv(cx->blk_loop.iterix++);
1887 if (cx->blk_loop.iterix >= (av == PL_curstack ? cx->blk_oldsp : AvFILL(av)))
1890 SvREFCNT_dec(*itersvp);
1892 if (SvMAGICAL(av) || AvREIFY(av)) {
1893 SV **svp = av_fetch(av, ++cx->blk_loop.iterix, FALSE);
1900 sv = AvARRAY(av)[++cx->blk_loop.iterix];
1902 if (sv && SvREFCNT(sv) == 0) {
1904 Perl_croak(aTHX_ "Use of freed value in iteration");
1911 if (av != PL_curstack && sv == &PL_sv_undef) {
1912 SV *lv = cx->blk_loop.iterlval;
1913 if (lv && SvREFCNT(lv) > 1) {
1918 SvREFCNT_dec(LvTARG(lv));
1920 lv = cx->blk_loop.iterlval = NEWSV(26, 0);
1921 sv_upgrade(lv, SVt_PVLV);
1923 sv_magic(lv, Nullsv, PERL_MAGIC_defelem, Nullch, 0);
1925 LvTARG(lv) = SvREFCNT_inc(av);
1926 LvTARGOFF(lv) = cx->blk_loop.iterix;
1927 LvTARGLEN(lv) = (STRLEN)UV_MAX;
1931 *itersvp = SvREFCNT_inc(sv);
1938 register PMOP *pm = cPMOP;
1954 register REGEXP *rx = PM_GETRE(pm);
1956 int force_on_match = 0;
1957 I32 oldsave = PL_savestack_ix;
1959 bool doutf8 = FALSE;
1960 #ifdef PERL_COPY_ON_WRITE
1965 /* known replacement string? */
1966 dstr = (pm->op_pmflags & PMf_CONST) ? POPs : Nullsv;
1967 if (PL_op->op_flags & OPf_STACKED)
1974 #ifdef PERL_COPY_ON_WRITE
1975 /* Awooga. Awooga. "bool" types that are actually char are dangerous,
1976 because they make integers such as 256 "false". */
1977 is_cow = SvIsCOW(TARG) ? TRUE : FALSE;
1980 sv_force_normal_flags(TARG,0);
1983 #ifdef PERL_COPY_ON_WRITE
1987 || (SvTYPE(TARG) > SVt_PVLV
1988 && !(SvTYPE(TARG) == SVt_PVGV && SvFAKE(TARG)))))
1989 DIE(aTHX_ PL_no_modify);
1992 s = SvPV(TARG, len);
1993 if (!SvPOKp(TARG) || SvTYPE(TARG) == SVt_PVGV)
1995 rxtainted = ((pm->op_pmdynflags & PMdf_TAINTED) ||
1996 (PL_tainted && (pm->op_pmflags & PMf_RETAINT)));
2001 RX_MATCH_UTF8_set(rx, DO_UTF8(TARG));
2005 DIE(aTHX_ "panic: pp_subst");
2008 slen = RX_MATCH_UTF8(rx) ? utf8_length((U8*)s, (U8*)strend) : len;
2009 maxiters = 2 * slen + 10; /* We can match twice at each
2010 position, once with zero-length,
2011 second time with non-zero. */
2013 if (!rx->prelen && PL_curpm) {
2017 r_flags = (rx->nparens || SvTEMP(TARG) || PL_sawampersand)
2018 ? REXEC_COPY_STR : 0;
2020 r_flags |= REXEC_SCREAM;
2021 if ((int)(pm->op_pmflags & PMf_MULTILINE) != PL_multiline) {
2022 SAVEINT(PL_multiline);
2023 PL_multiline = pm->op_pmflags & PMf_MULTILINE;
2026 if (rx->reganch & RE_USE_INTUIT) {
2028 s = CALLREG_INTUIT_START(aTHX_ rx, TARG, s, strend, r_flags, NULL);
2032 /* How to do it in subst? */
2033 /* if ( (rx->reganch & ROPT_CHECK_ALL)
2035 && ((rx->reganch & ROPT_NOSCAN)
2036 || !((rx->reganch & RE_INTUIT_TAIL)
2037 && (r_flags & REXEC_SCREAM))))
2042 /* only replace once? */
2043 once = !(rpm->op_pmflags & PMf_GLOBAL);
2045 /* known replacement string? */
2047 /* replacement needing upgrading? */
2048 if (DO_UTF8(TARG) && !doutf8) {
2049 nsv = sv_newmortal();
2052 sv_recode_to_utf8(nsv, PL_encoding);
2054 sv_utf8_upgrade(nsv);
2055 c = SvPV(nsv, clen);
2059 c = SvPV(dstr, clen);
2060 doutf8 = DO_UTF8(dstr);
2068 /* can do inplace substitution? */
2070 #ifdef PERL_COPY_ON_WRITE
2073 && (I32)clen <= rx->minlen && (once || !(r_flags & REXEC_COPY_STR))
2074 && !(rx->reganch & ROPT_LOOKBEHIND_SEEN)
2075 && (!doutf8 || SvUTF8(TARG))) {
2076 if (!CALLREGEXEC(aTHX_ rx, s, strend, orig, 0, TARG, NULL,
2077 r_flags | REXEC_CHECKED))
2081 LEAVE_SCOPE(oldsave);
2084 #ifdef PERL_COPY_ON_WRITE
2085 if (SvIsCOW(TARG)) {
2086 assert (!force_on_match);
2090 if (force_on_match) {
2092 s = SvPV_force(TARG, len);
2097 SvSCREAM_off(TARG); /* disable possible screamer */
2099 rxtainted |= RX_MATCH_TAINTED(rx);
2100 m = orig + rx->startp[0];
2101 d = orig + rx->endp[0];
2103 if (m - s > strend - d) { /* faster to shorten from end */
2105 Copy(c, m, clen, char);
2110 Move(d, m, i, char);
2114 SvCUR_set(TARG, m - s);
2117 else if ((i = m - s)) { /* faster from front */
2125 Copy(c, m, clen, char);
2130 Copy(c, d, clen, char);
2135 TAINT_IF(rxtainted & 1);
2141 if (iters++ > maxiters)
2142 DIE(aTHX_ "Substitution loop");
2143 rxtainted |= RX_MATCH_TAINTED(rx);
2144 m = rx->startp[0] + orig;
2148 Move(s, d, i, char);
2152 Copy(c, d, clen, char);
2155 s = rx->endp[0] + orig;
2156 } while (CALLREGEXEC(aTHX_ rx, s, strend, orig, s == m,
2158 /* don't match same null twice */
2159 REXEC_NOT_FIRST|REXEC_IGNOREPOS));
2162 SvCUR_set(TARG, d - SvPVX(TARG) + i);
2163 Move(s, d, i+1, char); /* include the NUL */
2165 TAINT_IF(rxtainted & 1);
2167 PUSHs(sv_2mortal(newSViv((I32)iters)));
2169 (void)SvPOK_only_UTF8(TARG);
2170 TAINT_IF(rxtainted);
2171 if (SvSMAGICAL(TARG)) {
2179 LEAVE_SCOPE(oldsave);
2183 if (CALLREGEXEC(aTHX_ rx, s, strend, orig, 0, TARG, NULL,
2184 r_flags | REXEC_CHECKED))
2186 if (force_on_match) {
2188 s = SvPV_force(TARG, len);
2191 #ifdef PERL_COPY_ON_WRITE
2194 rxtainted |= RX_MATCH_TAINTED(rx);
2195 dstr = NEWSV(25, len);
2196 sv_setpvn(dstr, m, s-m);
2201 register PERL_CONTEXT *cx;
2205 RETURNOP(cPMOP->op_pmreplroot);
2207 r_flags |= REXEC_IGNOREPOS | REXEC_NOT_FIRST;
2209 if (iters++ > maxiters)
2210 DIE(aTHX_ "Substitution loop");
2211 rxtainted |= RX_MATCH_TAINTED(rx);
2212 if (RX_MATCH_COPIED(rx) && rx->subbeg != orig) {
2217 strend = s + (strend - m);
2219 m = rx->startp[0] + orig;
2220 if (doutf8 && !SvUTF8(dstr))
2221 sv_catpvn_utf8_upgrade(dstr, s, m - s, nsv);
2223 sv_catpvn(dstr, s, m-s);
2224 s = rx->endp[0] + orig;
2226 sv_catpvn(dstr, c, clen);
2229 } while (CALLREGEXEC(aTHX_ rx, s, strend, orig, s == m,
2230 TARG, NULL, r_flags));
2231 if (doutf8 && !DO_UTF8(TARG))
2232 sv_catpvn_utf8_upgrade(dstr, s, strend - s, nsv);
2234 sv_catpvn(dstr, s, strend - s);
2236 #ifdef PERL_COPY_ON_WRITE
2237 /* The match may make the string COW. If so, brilliant, because that's
2238 just saved us one malloc, copy and free - the regexp has donated
2239 the old buffer, and we malloc an entirely new one, rather than the
2240 regexp malloc()ing a buffer and copying our original, only for
2241 us to throw it away here during the substitution. */
2242 if (SvIsCOW(TARG)) {
2243 sv_force_normal_flags(TARG, SV_COW_DROP_PV);
2247 (void)SvOOK_off(TARG);
2249 Safefree(SvPVX(TARG));
2251 SvPVX(TARG) = SvPVX(dstr);
2252 SvCUR_set(TARG, SvCUR(dstr));
2253 SvLEN_set(TARG, SvLEN(dstr));
2254 doutf8 |= DO_UTF8(dstr);
2258 TAINT_IF(rxtainted & 1);
2260 PUSHs(sv_2mortal(newSViv((I32)iters)));
2262 (void)SvPOK_only(TARG);
2265 TAINT_IF(rxtainted);
2268 LEAVE_SCOPE(oldsave);
2277 LEAVE_SCOPE(oldsave);
2286 PL_stack_base[PL_markstack_ptr[-1]++] = PL_stack_base[*PL_markstack_ptr];
2287 ++*PL_markstack_ptr;
2288 LEAVE; /* exit inner scope */
2291 if (PL_stack_base + *PL_markstack_ptr > SP) {
2293 I32 gimme = GIMME_V;
2295 LEAVE; /* exit outer scope */
2296 (void)POPMARK; /* pop src */
2297 items = --*PL_markstack_ptr - PL_markstack_ptr[-1];
2298 (void)POPMARK; /* pop dst */
2299 SP = PL_stack_base + POPMARK; /* pop original mark */
2300 if (gimme == G_SCALAR) {
2304 else if (gimme == G_ARRAY)
2311 ENTER; /* enter inner scope */
2314 src = PL_stack_base[*PL_markstack_ptr];
2318 RETURNOP(cLOGOP->op_other);
2329 register PERL_CONTEXT *cx;
2333 cxstack_ix++; /* temporarily protect top context */
2336 if (gimme == G_SCALAR) {
2339 if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
2341 *MARK = SvREFCNT_inc(TOPs);
2346 sv = SvREFCNT_inc(TOPs); /* FREETMPS could clobber it */
2348 *MARK = sv_mortalcopy(sv);
2353 *MARK = SvTEMP(TOPs) ? TOPs : sv_mortalcopy(TOPs);
2357 *MARK = &PL_sv_undef;
2361 else if (gimme == G_ARRAY) {
2362 for (MARK = newsp + 1; MARK <= SP; MARK++) {
2363 if (!SvTEMP(*MARK)) {
2364 *MARK = sv_mortalcopy(*MARK);
2365 TAINT_NOT; /* Each item is independent */
2373 POPSUB(cx,sv); /* Stack values are safe: release CV and @_ ... */
2374 PL_curpm = newpm; /* ... and pop $1 et al */
2377 return pop_return();
2380 /* This duplicates the above code because the above code must not
2381 * get any slower by more conditions */
2389 register PERL_CONTEXT *cx;
2393 cxstack_ix++; /* temporarily protect top context */
2397 if (cx->blk_sub.lval & OPpENTERSUB_INARGS) {
2398 /* We are an argument to a function or grep().
2399 * This kind of lvalueness was legal before lvalue
2400 * subroutines too, so be backward compatible:
2401 * cannot report errors. */
2403 /* Scalar context *is* possible, on the LHS of -> only,
2404 * as in f()->meth(). But this is not an lvalue. */
2405 if (gimme == G_SCALAR)
2407 if (gimme == G_ARRAY) {
2408 if (!CvLVALUE(cx->blk_sub.cv))
2409 goto temporise_array;
2410 EXTEND_MORTAL(SP - newsp);
2411 for (mark = newsp + 1; mark <= SP; mark++) {
2414 else if (SvFLAGS(*mark) & (SVs_PADTMP | SVf_READONLY))
2415 *mark = sv_mortalcopy(*mark);
2417 /* Can be a localized value subject to deletion. */
2418 PL_tmps_stack[++PL_tmps_ix] = *mark;
2419 (void)SvREFCNT_inc(*mark);
2424 else if (cx->blk_sub.lval) { /* Leave it as it is if we can. */
2425 /* Here we go for robustness, not for speed, so we change all
2426 * the refcounts so the caller gets a live guy. Cannot set
2427 * TEMP, so sv_2mortal is out of question. */
2428 if (!CvLVALUE(cx->blk_sub.cv)) {
2434 DIE(aTHX_ "Can't modify non-lvalue subroutine call");
2436 if (gimme == G_SCALAR) {
2440 if (SvFLAGS(TOPs) & (SVs_TEMP | SVs_PADTMP | SVf_READONLY)) {
2446 DIE(aTHX_ "Can't return %s from lvalue subroutine",
2447 SvREADONLY(TOPs) ? (TOPs == &PL_sv_undef) ? "undef"
2448 : "a readonly value" : "a temporary");
2450 else { /* Can be a localized value
2451 * subject to deletion. */
2452 PL_tmps_stack[++PL_tmps_ix] = *mark;
2453 (void)SvREFCNT_inc(*mark);
2456 else { /* Should not happen? */
2462 DIE(aTHX_ "%s returned from lvalue subroutine in scalar context",
2463 (MARK > SP ? "Empty array" : "Array"));
2467 else if (gimme == G_ARRAY) {
2468 EXTEND_MORTAL(SP - newsp);
2469 for (mark = newsp + 1; mark <= SP; mark++) {
2470 if (*mark != &PL_sv_undef
2471 && SvFLAGS(*mark) & (SVs_TEMP | SVs_PADTMP | SVf_READONLY)) {
2472 /* Might be flattened array after $#array = */
2479 DIE(aTHX_ "Can't return a %s from lvalue subroutine",
2480 SvREADONLY(TOPs) ? "readonly value" : "temporary");
2483 /* Can be a localized value subject to deletion. */
2484 PL_tmps_stack[++PL_tmps_ix] = *mark;
2485 (void)SvREFCNT_inc(*mark);
2491 if (gimme == G_SCALAR) {
2495 if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
2497 *MARK = SvREFCNT_inc(TOPs);
2502 sv = SvREFCNT_inc(TOPs); /* FREETMPS could clobber it */
2504 *MARK = sv_mortalcopy(sv);
2509 *MARK = SvTEMP(TOPs) ? TOPs : sv_mortalcopy(TOPs);
2513 *MARK = &PL_sv_undef;
2517 else if (gimme == G_ARRAY) {
2519 for (MARK = newsp + 1; MARK <= SP; MARK++) {
2520 if (!SvTEMP(*MARK)) {
2521 *MARK = sv_mortalcopy(*MARK);
2522 TAINT_NOT; /* Each item is independent */
2531 POPSUB(cx,sv); /* Stack values are safe: release CV and @_ ... */
2532 PL_curpm = newpm; /* ... and pop $1 et al */
2535 return pop_return();
2540 S_get_db_sub(pTHX_ SV **svp, CV *cv)
2542 SV *dbsv = GvSV(PL_DBsub);
2544 if (!PERLDB_SUB_NN) {
2548 if ( (CvFLAGS(cv) & (CVf_ANON | CVf_CLONED))
2549 || strEQ(GvNAME(gv), "END")
2550 || ((GvCV(gv) != cv) && /* Could be imported, and old sub redefined. */
2551 !( (SvTYPE(*svp) == SVt_PVGV) && (GvCV((GV*)*svp) == cv)
2552 && (gv = (GV*)*svp) ))) {
2553 /* Use GV from the stack as a fallback. */
2554 /* GV is potentially non-unique, or contain different CV. */
2555 SV *tmp = newRV((SV*)cv);
2556 sv_setsv(dbsv, tmp);
2560 gv_efullname3(dbsv, gv, Nullch);
2564 (void)SvUPGRADE(dbsv, SVt_PVIV);
2565 (void)SvIOK_on(dbsv);
2566 SAVEIV(SvIVX(dbsv));
2567 SvIVX(dbsv) = PTR2IV(cv); /* Do it the quickest way */
2571 PL_curcopdb = PL_curcop;
2572 cv = GvCV(PL_DBsub);
2582 register PERL_CONTEXT *cx;
2584 bool hasargs = (PL_op->op_flags & OPf_STACKED) != 0;
2587 DIE(aTHX_ "Not a CODE reference");
2588 switch (SvTYPE(sv)) {
2589 /* This is overwhelming the most common case: */
2591 if (!(cv = GvCVu((GV*)sv)))
2592 cv = sv_2cv(sv, &stash, &gv, FALSE);
2604 if (sv == &PL_sv_yes) { /* unfound import, ignore */
2606 SP = PL_stack_base + POPMARK;
2609 if (SvGMAGICAL(sv)) {
2613 sym = SvPOKp(sv) ? SvPVX(sv) : Nullch;
2616 sym = SvPV(sv, n_a);
2618 DIE(aTHX_ PL_no_usym, "a subroutine");
2619 if (PL_op->op_private & HINT_STRICT_REFS)
2620 DIE(aTHX_ PL_no_symref, sym, "a subroutine");
2621 cv = get_cv(sym, TRUE);
2626 SV **sp = &sv; /* Used in tryAMAGICunDEREF macro. */
2627 tryAMAGICunDEREF(to_cv);
2630 if (SvTYPE(cv) == SVt_PVCV)
2635 DIE(aTHX_ "Not a CODE reference");
2636 /* This is the second most common case: */
2646 if (!CvROOT(cv) && !CvXSUB(cv)) {
2651 if ((PL_op->op_private & OPpENTERSUB_DB) && GvCV(PL_DBsub) && !CvNODEBUG(cv)) {
2652 if (CvASSERTION(cv) && PL_DBassertion)
2653 sv_setiv(PL_DBassertion, 1);
2655 cv = get_db_sub(&sv, cv);
2657 DIE(aTHX_ "No DBsub routine");
2660 if (!(CvXSUB(cv))) {
2661 /* This path taken at least 75% of the time */
2663 register I32 items = SP - MARK;
2664 AV* padlist = CvPADLIST(cv);
2665 push_return(PL_op->op_next);
2666 PUSHBLOCK(cx, CXt_SUB, MARK);
2669 /* XXX This would be a natural place to set C<PL_compcv = cv> so
2670 * that eval'' ops within this sub know the correct lexical space.
2671 * Owing the speed considerations, we choose instead to search for
2672 * the cv using find_runcv() when calling doeval().
2674 if (CvDEPTH(cv) < 2)
2675 (void)SvREFCNT_inc(cv);
2677 PERL_STACK_OVERFLOW_CHECK();
2678 pad_push(padlist, CvDEPTH(cv), 1);
2680 PAD_SET_CUR(padlist, CvDEPTH(cv));
2687 DEBUG_S(PerlIO_printf(Perl_debug_log,
2688 "%p entersub preparing @_\n", thr));
2690 av = (AV*)PAD_SVl(0);
2692 /* @_ is normally not REAL--this should only ever
2693 * happen when DB::sub() calls things that modify @_ */
2698 cx->blk_sub.savearray = GvAV(PL_defgv);
2699 GvAV(PL_defgv) = (AV*)SvREFCNT_inc(av);
2700 CX_CURPAD_SAVE(cx->blk_sub);
2701 cx->blk_sub.argarray = av;
2704 if (items > AvMAX(av) + 1) {
2706 if (AvARRAY(av) != ary) {
2707 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
2708 SvPVX(av) = (char*)ary;
2710 if (items > AvMAX(av) + 1) {
2711 AvMAX(av) = items - 1;
2712 Renew(ary,items,SV*);
2714 SvPVX(av) = (char*)ary;
2717 Copy(MARK,AvARRAY(av),items,SV*);
2718 AvFILLp(av) = items - 1;
2726 /* warning must come *after* we fully set up the context
2727 * stuff so that __WARN__ handlers can safely dounwind()
2730 if (CvDEPTH(cv) == 100 && ckWARN(WARN_RECURSION)
2731 && !(PERLDB_SUB && cv == GvCV(PL_DBsub)))
2732 sub_crush_depth(cv);
2734 DEBUG_S(PerlIO_printf(Perl_debug_log,
2735 "%p entersub returning %p\n", thr, CvSTART(cv)));
2737 RETURNOP(CvSTART(cv));
2740 #ifdef PERL_XSUB_OLDSTYLE
2741 if (CvOLDSTYLE(cv)) {
2742 I32 (*fp3)(int,int,int);
2744 register I32 items = SP - MARK;
2745 /* We dont worry to copy from @_. */
2750 PL_stack_sp = mark + 1;
2751 fp3 = (I32(*)(int,int,int))CvXSUB(cv);
2752 items = (*fp3)(CvXSUBANY(cv).any_i32,
2753 MARK - PL_stack_base + 1,
2755 PL_stack_sp = PL_stack_base + items;
2758 #endif /* PERL_XSUB_OLDSTYLE */
2760 I32 markix = TOPMARK;
2765 /* Need to copy @_ to stack. Alternative may be to
2766 * switch stack to @_, and copy return values
2767 * back. This would allow popping @_ in XSUB, e.g.. XXXX */
2770 av = GvAV(PL_defgv);
2771 items = AvFILLp(av) + 1; /* @_ is not tieable */
2774 /* Mark is at the end of the stack. */
2776 Copy(AvARRAY(av), SP + 1, items, SV*);
2781 /* We assume first XSUB in &DB::sub is the called one. */
2783 SAVEVPTR(PL_curcop);
2784 PL_curcop = PL_curcopdb;
2787 /* Do we need to open block here? XXXX */
2788 (void)(*CvXSUB(cv))(aTHX_ cv);
2790 /* Enforce some sanity in scalar context. */
2791 if (gimme == G_SCALAR && ++markix != PL_stack_sp - PL_stack_base ) {
2792 if (markix > PL_stack_sp - PL_stack_base)
2793 *(PL_stack_base + markix) = &PL_sv_undef;
2795 *(PL_stack_base + markix) = *PL_stack_sp;
2796 PL_stack_sp = PL_stack_base + markix;
2803 assert (0); /* Cannot get here. */
2804 /* This is deliberately moved here as spaghetti code to keep it out of the
2811 /* anonymous or undef'd function leaves us no recourse */
2812 if (CvANON(cv) || !(gv = CvGV(cv)))
2813 DIE(aTHX_ "Undefined subroutine called");
2815 /* autoloaded stub? */
2816 if (cv != GvCV(gv)) {
2819 /* should call AUTOLOAD now? */
2822 if ((autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv), GvNAMELEN(gv),
2829 sub_name = sv_newmortal();
2830 gv_efullname3(sub_name, gv, Nullch);
2831 DIE(aTHX_ "Undefined subroutine &%"SVf" called", sub_name);
2835 DIE(aTHX_ "Not a CODE reference");
2841 Perl_sub_crush_depth(pTHX_ CV *cv)
2844 Perl_warner(aTHX_ packWARN(WARN_RECURSION), "Deep recursion on anonymous subroutine");
2846 SV* tmpstr = sv_newmortal();
2847 gv_efullname3(tmpstr, CvGV(cv), Nullch);
2848 Perl_warner(aTHX_ packWARN(WARN_RECURSION), "Deep recursion on subroutine \"%"SVf"\"",
2858 IV elem = SvIV(elemsv);
2860 U32 lval = PL_op->op_flags & OPf_MOD || LVRET;
2861 U32 defer = (PL_op->op_private & OPpLVAL_DEFER) && (elem > AvFILL(av));
2864 if (SvROK(elemsv) && !SvGAMAGIC(elemsv) && ckWARN(WARN_MISC))
2865 Perl_warner(aTHX_ packWARN(WARN_MISC), "Use of reference \"%"SVf"\" as array index", elemsv);
2867 elem -= PL_curcop->cop_arybase;
2868 if (SvTYPE(av) != SVt_PVAV)
2870 svp = av_fetch(av, elem, lval && !defer);
2872 if (!svp || *svp == &PL_sv_undef) {
2875 DIE(aTHX_ PL_no_aelem, elem);
2876 lv = sv_newmortal();
2877 sv_upgrade(lv, SVt_PVLV);
2879 sv_magic(lv, Nullsv, PERL_MAGIC_defelem, Nullch, 0);
2880 LvTARG(lv) = SvREFCNT_inc(av);
2881 LvTARGOFF(lv) = elem;
2886 if (PL_op->op_private & OPpLVAL_INTRO)
2887 save_aelem(av, elem, svp);
2888 else if (PL_op->op_private & OPpDEREF)
2889 vivify_ref(*svp, PL_op->op_private & OPpDEREF);
2891 sv = (svp ? *svp : &PL_sv_undef);
2892 if (!lval && SvGMAGICAL(sv)) /* see note in pp_helem() */
2893 sv = sv_mortalcopy(sv);
2899 Perl_vivify_ref(pTHX_ SV *sv, U32 to_what)
2905 Perl_croak(aTHX_ PL_no_modify);
2906 if (SvTYPE(sv) < SVt_RV)
2907 sv_upgrade(sv, SVt_RV);
2908 else if (SvTYPE(sv) >= SVt_PV) {
2909 (void)SvOOK_off(sv);
2910 Safefree(SvPVX(sv));
2911 SvLEN(sv) = SvCUR(sv) = 0;
2915 SvRV(sv) = NEWSV(355,0);
2918 SvRV(sv) = (SV*)newAV();
2921 SvRV(sv) = (SV*)newHV();
2936 if (SvTYPE(rsv) == SVt_PVCV) {
2942 SETs(method_common(sv, Null(U32*)));
2950 U32 hash = SvUVX(sv);
2952 XPUSHs(method_common(sv, &hash));
2957 S_method_common(pTHX_ SV* meth, U32* hashp)
2966 SV *packsv = Nullsv;
2969 name = SvPV(meth, namelen);
2970 sv = *(PL_stack_base + TOPMARK + 1);
2973 Perl_croak(aTHX_ "Can't call method \"%s\" on an undefined value", name);
2982 /* this isn't a reference */
2985 if(SvOK(sv) && (packname = SvPV(sv, packlen))) {
2987 he = hv_fetch_ent(PL_stashcache, sv, 0, 0);
2989 stash = INT2PTR(HV*,SvIV(HeVAL(he)));
2996 !(iogv = gv_fetchpv(packname, FALSE, SVt_PVIO)) ||
2997 !(ob=(SV*)GvIO(iogv)))
2999 /* this isn't the name of a filehandle either */
3001 ((UTF8_IS_START(*packname) && DO_UTF8(sv))
3002 ? !isIDFIRST_utf8((U8*)packname)
3003 : !isIDFIRST(*packname)
3006 Perl_croak(aTHX_ "Can't call method \"%s\" %s", name,
3007 SvOK(sv) ? "without a package or object reference"
3008 : "on an undefined value");
3010 /* assume it's a package name */
3011 stash = gv_stashpvn(packname, packlen, FALSE);
3015 SV* ref = newSViv(PTR2IV(stash));
3016 hv_store(PL_stashcache, packname, packlen, ref, 0);
3020 /* it _is_ a filehandle name -- replace with a reference */
3021 *(PL_stack_base + TOPMARK + 1) = sv_2mortal(newRV((SV*)iogv));
3024 /* if we got here, ob should be a reference or a glob */
3025 if (!ob || !(SvOBJECT(ob)
3026 || (SvTYPE(ob) == SVt_PVGV && (ob = (SV*)GvIO((GV*)ob))
3029 Perl_croak(aTHX_ "Can't call method \"%s\" on unblessed reference",
3033 stash = SvSTASH(ob);
3036 /* NOTE: stash may be null, hope hv_fetch_ent and
3037 gv_fetchmethod can cope (it seems they can) */
3039 /* shortcut for simple names */
3041 HE* he = hv_fetch_ent(stash, meth, 0, *hashp);
3043 gv = (GV*)HeVAL(he);
3044 if (isGV(gv) && GvCV(gv) &&
3045 (!GvCVGEN(gv) || GvCVGEN(gv) == PL_sub_generation))
3046 return (SV*)GvCV(gv);
3050 gv = gv_fetchmethod(stash ? stash : (HV*)packsv, name);
3053 /* This code tries to figure out just what went wrong with
3054 gv_fetchmethod. It therefore needs to duplicate a lot of
3055 the internals of that function. We can't move it inside
3056 Perl_gv_fetchmethod_autoload(), however, since that would
3057 cause UNIVERSAL->can("NoSuchPackage::foo") to croak, and we
3064 for (p = name; *p; p++) {
3066 sep = p, leaf = p + 1;
3067 else if (*p == ':' && *(p + 1) == ':')
3068 sep = p, leaf = p + 2;
3070 if (!sep || ((sep - name) == 5 && strnEQ(name, "SUPER", 5))) {
3071 /* the method name is unqualified or starts with SUPER:: */
3072 packname = sep ? CopSTASHPV(PL_curcop) :
3073 stash ? HvNAME(stash) : packname;
3076 "Can't use anonymous symbol table for method lookup");
3078 packlen = strlen(packname);
3081 /* the method name is qualified */
3083 packlen = sep - name;
3086 /* we're relying on gv_fetchmethod not autovivifying the stash */
3087 if (gv_stashpvn(packname, packlen, FALSE)) {
3089 "Can't locate object method \"%s\" via package \"%.*s\"",
3090 leaf, (int)packlen, packname);
3094 "Can't locate object method \"%s\" via package \"%.*s\""
3095 " (perhaps you forgot to load \"%.*s\"?)",
3096 leaf, (int)packlen, packname, (int)packlen, packname);
3099 return isGV(gv) ? (SV*)GvCV(gv) : (SV*)gv;