3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 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 * "It's a big house this, and very peculiar. Always a bit more to discover,
13 * and no knowing what you'll find around a corner. And Elves, sir!" --Samwise
16 /* This file contains general pp ("push/pop") functions that execute the
17 * opcodes that make up a perl program. A typical pp function expects to
18 * find its arguments on the stack, and usually pushes its results onto
19 * the stack, hence the 'pp' terminology. Each OP structure contains
20 * a pointer to the relevant pp_foo() function.
30 /* XXX I can't imagine anyone who doesn't have this actually _needs_
31 it, since pid_t is an integral type.
34 #ifdef NEED_GETPID_PROTO
35 extern Pid_t getpid (void);
39 * Some BSDs and Cygwin default to POSIX math instead of IEEE.
40 * This switches them over to IEEE.
42 #if defined(LIBM_LIB_VERSION)
43 _LIB_VERSION_TYPE _LIB_VERSION = _IEEE_;
46 /* variations on pp_null */
52 if (GIMME_V == G_SCALAR)
63 if (PL_op->op_private & OPpLVAL_INTRO)
64 if (!(PL_op->op_private & OPpPAD_STATE))
65 SAVECLEARSV(PAD_SVl(PL_op->op_targ));
67 if (PL_op->op_flags & OPf_REF) {
71 if (GIMME == G_SCALAR)
72 Perl_croak(aTHX_ "Can't return array to lvalue scalar context");
77 if (gimme == G_ARRAY) {
78 const I32 maxarg = AvFILL((AV*)TARG) + 1;
80 if (SvMAGICAL(TARG)) {
82 for (i=0; i < (U32)maxarg; i++) {
83 SV * const * const svp = av_fetch((AV*)TARG, i, FALSE);
84 SP[i+1] = (svp) ? *svp : &PL_sv_undef;
88 Copy(AvARRAY((AV*)TARG), SP+1, maxarg, SV*);
92 else if (gimme == G_SCALAR) {
93 SV* const sv = sv_newmortal();
94 const I32 maxarg = AvFILL((AV*)TARG) + 1;
107 if (PL_op->op_private & OPpLVAL_INTRO)
108 if (!(PL_op->op_private & OPpPAD_STATE))
109 SAVECLEARSV(PAD_SVl(PL_op->op_targ));
110 if (PL_op->op_flags & OPf_REF)
113 if (GIMME == G_SCALAR)
114 Perl_croak(aTHX_ "Can't return hash to lvalue scalar context");
118 if (gimme == G_ARRAY) {
121 else if (gimme == G_SCALAR) {
122 SV* const sv = Perl_hv_scalar(aTHX_ (HV*)TARG);
136 tryAMAGICunDEREF(to_gv);
139 if (SvTYPE(sv) == SVt_PVIO) {
140 GV * const gv = (GV*) sv_newmortal();
141 gv_init(gv, 0, "", 0, 0);
142 GvIOp(gv) = (IO *)sv;
143 SvREFCNT_inc_void_NN(sv);
146 else if (SvTYPE(sv) != SVt_PVGV)
147 DIE(aTHX_ "Not a GLOB reference");
150 if (SvTYPE(sv) != SVt_PVGV) {
151 if (SvGMAGICAL(sv)) {
156 if (!SvOK(sv) && sv != &PL_sv_undef) {
157 /* If this is a 'my' scalar and flag is set then vivify
161 Perl_croak(aTHX_ PL_no_modify);
162 if (PL_op->op_private & OPpDEREF) {
164 if (cUNOP->op_targ) {
166 SV * const namesv = PAD_SV(cUNOP->op_targ);
167 const char * const name = SvPV(namesv, len);
169 gv_init(gv, CopSTASH(PL_curcop), name, len, 0);
172 const char * const name = CopSTASHPV(PL_curcop);
175 if (SvTYPE(sv) < SVt_RV)
176 sv_upgrade(sv, SVt_RV);
177 else if (SvPVX_const(sv)) {
182 SvRV_set(sv, (SV*)gv);
187 if (PL_op->op_flags & OPf_REF ||
188 PL_op->op_private & HINT_STRICT_REFS)
189 DIE(aTHX_ PL_no_usym, "a symbol");
190 if (ckWARN(WARN_UNINITIALIZED))
194 if ((PL_op->op_flags & OPf_SPECIAL) &&
195 !(PL_op->op_flags & OPf_MOD))
197 SV * const temp = (SV*)gv_fetchsv(sv, 0, SVt_PVGV);
199 && (!is_gv_magical_sv(sv,0)
200 || !(sv = (SV*)gv_fetchsv(sv, GV_ADD, SVt_PVGV)))) {
206 if (PL_op->op_private & HINT_STRICT_REFS)
207 DIE(aTHX_ PL_no_symref_sv, sv, "a symbol");
208 if ((PL_op->op_private & (OPpLVAL_INTRO|OPpDONT_INIT_GV))
209 == OPpDONT_INIT_GV) {
210 /* We are the target of a coderef assignment. Return
211 the scalar unchanged, and let pp_sasssign deal with
215 sv = (SV*)gv_fetchsv(sv, GV_ADD, SVt_PVGV);
219 if (PL_op->op_private & OPpLVAL_INTRO)
220 save_gp((GV*)sv, !(PL_op->op_flags & OPf_SPECIAL));
225 /* Helper function for pp_rv2sv and pp_rv2av */
227 Perl_softref2xv(pTHX_ SV *const sv, const char *const what, const U32 type,
233 if (PL_op->op_private & HINT_STRICT_REFS) {
235 Perl_die(aTHX_ PL_no_symref_sv, sv, what);
237 Perl_die(aTHX_ PL_no_usym, what);
240 if (PL_op->op_flags & OPf_REF)
241 Perl_die(aTHX_ PL_no_usym, what);
242 if (ckWARN(WARN_UNINITIALIZED))
244 if (type != SVt_PV && GIMME_V == G_ARRAY) {
248 **spp = &PL_sv_undef;
251 if ((PL_op->op_flags & OPf_SPECIAL) &&
252 !(PL_op->op_flags & OPf_MOD))
254 gv = gv_fetchsv(sv, 0, type);
256 && (!is_gv_magical_sv(sv,0)
257 || !(gv = gv_fetchsv(sv, GV_ADD, type))))
259 **spp = &PL_sv_undef;
264 gv = gv_fetchsv(sv, GV_ADD, type);
276 tryAMAGICunDEREF(to_sv);
279 switch (SvTYPE(sv)) {
285 DIE(aTHX_ "Not a SCALAR reference");
292 if (SvTYPE(gv) != SVt_PVGV) {
293 if (SvGMAGICAL(sv)) {
298 gv = Perl_softref2xv(aTHX_ sv, "a SCALAR", SVt_PV, &sp);
304 if (PL_op->op_flags & OPf_MOD) {
305 if (PL_op->op_private & OPpLVAL_INTRO) {
306 if (cUNOP->op_first->op_type == OP_NULL)
307 sv = save_scalar((GV*)TOPs);
309 sv = save_scalar(gv);
311 Perl_croak(aTHX_ PL_no_localize_ref);
313 else if (PL_op->op_private & OPpDEREF)
314 vivify_ref(sv, PL_op->op_private & OPpDEREF);
323 AV * const av = (AV*)TOPs;
324 SV ** const sv = Perl_av_arylen_p(aTHX_ (AV*)av);
326 *sv = newSV_type(SVt_PVMG);
327 sv_magic(*sv, (SV*)av, PERL_MAGIC_arylen, NULL, 0);
335 dVAR; dSP; dTARGET; dPOPss;
337 if (PL_op->op_flags & OPf_MOD || LVRET) {
338 if (SvTYPE(TARG) < SVt_PVLV) {
339 sv_upgrade(TARG, SVt_PVLV);
340 sv_magic(TARG, NULL, PERL_MAGIC_pos, NULL, 0);
344 if (LvTARG(TARG) != sv) {
346 SvREFCNT_dec(LvTARG(TARG));
347 LvTARG(TARG) = SvREFCNT_inc_simple(sv);
349 PUSHs(TARG); /* no SvSETMAGIC */
353 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
354 const MAGIC * const mg = mg_find(sv, PERL_MAGIC_regex_global);
355 if (mg && mg->mg_len >= 0) {
359 PUSHi(i + CopARYBASE_get(PL_curcop));
372 const I32 flags = (PL_op->op_flags & OPf_SPECIAL)
374 : ((PL_op->op_private & (OPpLVAL_INTRO|OPpMAY_RETURN_CONSTANT)) == OPpMAY_RETURN_CONSTANT)
377 /* We usually try to add a non-existent subroutine in case of AUTOLOAD. */
378 /* (But not in defined().) */
380 CV *cv = sv_2cv(TOPs, &stash_unused, &gv, flags);
383 cv = (CV*)sv_2mortal((SV*)cv_clone(cv));
384 if ((PL_op->op_private & OPpLVAL_INTRO)) {
385 if (gv && GvCV(gv) == cv && (gv = gv_autoload4(GvSTASH(gv), GvNAME(gv), GvNAMELEN(gv), FALSE)))
388 DIE(aTHX_ "Can't modify non-lvalue subroutine call");
391 else if ((flags == (GV_ADD|GV_NOEXPAND)) && gv && SvROK(gv)) {
395 cv = (CV*)&PL_sv_undef;
406 SV *ret = &PL_sv_undef;
408 if (SvPOK(TOPs) && SvCUR(TOPs) >= 7) {
409 const char * s = SvPVX_const(TOPs);
410 if (strnEQ(s, "CORE::", 6)) {
411 const int code = keyword(s + 6, SvCUR(TOPs) - 6, 1);
412 if (code < 0) { /* Overridable. */
413 #define MAX_ARGS_OP ((sizeof(I32) - 1) * 2)
414 int i = 0, n = 0, seen_question = 0, defgv = 0;
416 char str[ MAX_ARGS_OP * 2 + 2 ]; /* One ';', one '\0' */
418 if (code == -KEY_chop || code == -KEY_chomp
419 || code == -KEY_exec || code == -KEY_system || code == -KEY_err)
421 if (code == -KEY_mkdir) {
422 ret = sv_2mortal(newSVpvs("_;$"));
425 if (code == -KEY_readpipe) {
426 s = "CORE::backtick";
428 while (i < MAXO) { /* The slow way. */
429 if (strEQ(s + 6, PL_op_name[i])
430 || strEQ(s + 6, PL_op_desc[i]))
436 goto nonesuch; /* Should not happen... */
438 defgv = PL_opargs[i] & OA_DEFGV;
439 oa = PL_opargs[i] >> OASHIFT;
441 if (oa & OA_OPTIONAL && !seen_question && !defgv) {
445 if ((oa & (OA_OPTIONAL - 1)) >= OA_AVREF
446 && (oa & (OA_OPTIONAL - 1)) <= OA_SCALARREF
447 /* But globs are already references (kinda) */
448 && (oa & (OA_OPTIONAL - 1)) != OA_FILEREF
452 str[n++] = ("?$@@%&*$")[oa & (OA_OPTIONAL - 1)];
455 if (defgv && str[n - 1] == '$')
458 ret = sv_2mortal(newSVpvn(str, n - 1));
460 else if (code) /* Non-Overridable */
462 else { /* None such */
464 DIE(aTHX_ "Can't find an opnumber for \"%s\"", s+6);
468 cv = sv_2cv(TOPs, &stash, &gv, 0);
470 ret = sv_2mortal(newSVpvn(SvPVX_const(cv), SvCUR(cv)));
479 CV* cv = (CV*)PAD_SV(PL_op->op_targ);
481 cv = (CV*)sv_2mortal((SV*)cv_clone(cv));
497 if (GIMME != G_ARRAY) {
501 *MARK = &PL_sv_undef;
502 *MARK = refto(*MARK);
506 EXTEND_MORTAL(SP - MARK);
508 *MARK = refto(*MARK);
513 S_refto(pTHX_ SV *sv)
518 if (SvTYPE(sv) == SVt_PVLV && LvTYPE(sv) == 'y') {
521 if (!(sv = LvTARG(sv)))
524 SvREFCNT_inc_void_NN(sv);
526 else if (SvTYPE(sv) == SVt_PVAV) {
527 if (!AvREAL((AV*)sv) && AvREIFY((AV*)sv))
530 SvREFCNT_inc_void_NN(sv);
532 else if (SvPADTMP(sv) && !IS_PADGV(sv))
536 SvREFCNT_inc_void_NN(sv);
539 sv_upgrade(rv, SVt_RV);
549 SV * const sv = POPs;
554 if (!sv || !SvROK(sv))
557 pv = sv_reftype(SvRV(sv),TRUE);
558 PUSHp(pv, strlen(pv));
568 stash = CopSTASH(PL_curcop);
570 SV * const ssv = POPs;
574 if (ssv && !SvGMAGICAL(ssv) && !SvAMAGIC(ssv) && SvROK(ssv))
575 Perl_croak(aTHX_ "Attempt to bless into a reference");
576 ptr = SvPV_const(ssv,len);
577 if (len == 0 && ckWARN(WARN_MISC))
578 Perl_warner(aTHX_ packWARN(WARN_MISC),
579 "Explicit blessing to '' (assuming package main)");
580 stash = gv_stashpvn(ptr, len, GV_ADD);
583 (void)sv_bless(TOPs, stash);
592 const char * const elem = SvPV_nolen_const(sv);
593 GV * const gv = (GV*)POPs;
598 /* elem will always be NUL terminated. */
599 const char * const second_letter = elem + 1;
602 if (strEQ(second_letter, "RRAY"))
603 tmpRef = (SV*)GvAV(gv);
606 if (strEQ(second_letter, "ODE"))
607 tmpRef = (SV*)GvCVu(gv);
610 if (strEQ(second_letter, "ILEHANDLE")) {
611 /* finally deprecated in 5.8.0 */
612 deprecate("*glob{FILEHANDLE}");
613 tmpRef = (SV*)GvIOp(gv);
616 if (strEQ(second_letter, "ORMAT"))
617 tmpRef = (SV*)GvFORM(gv);
620 if (strEQ(second_letter, "LOB"))
624 if (strEQ(second_letter, "ASH"))
625 tmpRef = (SV*)GvHV(gv);
628 if (*second_letter == 'O' && !elem[2])
629 tmpRef = (SV*)GvIOp(gv);
632 if (strEQ(second_letter, "AME"))
633 sv = newSVpvn(GvNAME(gv), GvNAMELEN(gv));
636 if (strEQ(second_letter, "ACKAGE")) {
637 const HV * const stash = GvSTASH(gv);
638 const HEK * const hek = stash ? HvNAME_HEK(stash) : NULL;
639 sv = hek ? newSVhek(hek) : newSVpvs("__ANON__");
643 if (strEQ(second_letter, "CALAR"))
658 /* Pattern matching */
663 register unsigned char *s;
666 register I32 *sfirst;
670 if (sv == PL_lastscream) {
674 s = (unsigned char*)(SvPV(sv, len));
676 if (pos <= 0 || !SvPOK(sv) || SvUTF8(sv)) {
677 /* No point in studying a zero length string, and not safe to study
678 anything that doesn't appear to be a simple scalar (and hence might
679 change between now and when the regexp engine runs without our set
680 magic ever running) such as a reference to an object with overloaded
686 SvSCREAM_off(PL_lastscream);
687 SvREFCNT_dec(PL_lastscream);
689 PL_lastscream = SvREFCNT_inc_simple(sv);
691 s = (unsigned char*)(SvPV(sv, len));
695 if (pos > PL_maxscream) {
696 if (PL_maxscream < 0) {
697 PL_maxscream = pos + 80;
698 Newx(PL_screamfirst, 256, I32);
699 Newx(PL_screamnext, PL_maxscream, I32);
702 PL_maxscream = pos + pos / 4;
703 Renew(PL_screamnext, PL_maxscream, I32);
707 sfirst = PL_screamfirst;
708 snext = PL_screamnext;
710 if (!sfirst || !snext)
711 DIE(aTHX_ "do_study: out of memory");
713 for (ch = 256; ch; --ch)
718 register const I32 ch = s[pos];
720 snext[pos] = sfirst[ch] - pos;
727 /* piggyback on m//g magic */
728 sv_magic(sv, NULL, PERL_MAGIC_regex_global, NULL, 0);
737 if (PL_op->op_flags & OPf_STACKED)
739 else if (PL_op->op_private & OPpTARGET_MY)
745 TARG = sv_newmortal();
750 /* Lvalue operators. */
762 dVAR; dSP; dMARK; dTARGET; dORIGMARK;
764 do_chop(TARG, *++MARK);
773 SETi(do_chomp(TOPs));
779 dVAR; dSP; dMARK; dTARGET;
780 register I32 count = 0;
783 count += do_chomp(POPs);
793 if (!PL_op->op_private) {
802 SV_CHECK_THINKFIRST_COW_DROP(sv);
804 switch (SvTYPE(sv)) {
814 if (cv_const_sv((CV*)sv) && ckWARN(WARN_MISC))
815 Perl_warner(aTHX_ packWARN(WARN_MISC), "Constant subroutine %s undefined",
816 CvANON((CV*)sv) ? "(anonymous)" : GvENAME(CvGV((CV*)sv)));
820 /* let user-undef'd sub keep its identity */
821 GV* const gv = CvGV((CV*)sv);
828 SvSetMagicSV(sv, &PL_sv_undef);
834 if((stash = GvHV((GV*)sv)) && HvNAME_get(stash))
835 mro_isa_changed_in(stash);
836 /* undef *Pkg::meth_name ... */
837 else if(GvCVu((GV*)sv) && (stash = GvSTASH((GV*)sv)) && HvNAME_get(stash))
838 mro_method_changed_in(stash);
842 GvGP(sv) = gp_ref(gp);
844 GvLINE(sv) = CopLINE(PL_curcop);
850 if (SvTYPE(sv) >= SVt_PV && SvPVX_const(sv) && SvLEN(sv)) {
865 if (SvTYPE(TOPs) >= SVt_PVGV && SvTYPE(TOPs) != SVt_PVLV)
866 DIE(aTHX_ PL_no_modify);
867 if (!SvREADONLY(TOPs) && SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs)
868 && SvIVX(TOPs) != IV_MIN)
870 SvIV_set(TOPs, SvIVX(TOPs) - 1);
871 SvFLAGS(TOPs) &= ~(SVp_NOK|SVp_POK);
882 if (SvTYPE(TOPs) >= SVt_PVGV && SvTYPE(TOPs) != SVt_PVLV)
883 DIE(aTHX_ PL_no_modify);
884 sv_setsv(TARG, TOPs);
885 if (!SvREADONLY(TOPs) && SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs)
886 && SvIVX(TOPs) != IV_MAX)
888 SvIV_set(TOPs, SvIVX(TOPs) + 1);
889 SvFLAGS(TOPs) &= ~(SVp_NOK|SVp_POK);
894 /* special case for undef: see thread at 2003-03/msg00536.html in archive */
904 if (SvTYPE(TOPs) >= SVt_PVGV && SvTYPE(TOPs) != SVt_PVLV)
905 DIE(aTHX_ PL_no_modify);
906 sv_setsv(TARG, TOPs);
907 if (!SvREADONLY(TOPs) && SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs)
908 && SvIVX(TOPs) != IV_MIN)
910 SvIV_set(TOPs, SvIVX(TOPs) - 1);
911 SvFLAGS(TOPs) &= ~(SVp_NOK|SVp_POK);
920 /* Ordinary operators. */
925 #ifdef PERL_PRESERVE_IVUV
928 tryAMAGICbin(pow,opASSIGN);
929 #ifdef PERL_PRESERVE_IVUV
930 /* For integer to integer power, we do the calculation by hand wherever
931 we're sure it is safe; otherwise we call pow() and try to convert to
932 integer afterwards. */
945 const IV iv = SvIVX(TOPs);
949 goto float_it; /* Can't do negative powers this way. */
953 baseuok = SvUOK(TOPm1s);
955 baseuv = SvUVX(TOPm1s);
957 const IV iv = SvIVX(TOPm1s);
960 baseuok = TRUE; /* effectively it's a UV now */
962 baseuv = -iv; /* abs, baseuok == false records sign */
965 /* now we have integer ** positive integer. */
968 /* foo & (foo - 1) is zero only for a power of 2. */
969 if (!(baseuv & (baseuv - 1))) {
970 /* We are raising power-of-2 to a positive integer.
971 The logic here will work for any base (even non-integer
972 bases) but it can be less accurate than
973 pow (base,power) or exp (power * log (base)) when the
974 intermediate values start to spill out of the mantissa.
975 With powers of 2 we know this can't happen.
976 And powers of 2 are the favourite thing for perl
977 programmers to notice ** not doing what they mean. */
979 NV base = baseuok ? baseuv : -(NV)baseuv;
984 while (power >>= 1) {
995 register unsigned int highbit = 8 * sizeof(UV);
996 register unsigned int diff = 8 * sizeof(UV);
999 if (baseuv >> highbit) {
1003 /* we now have baseuv < 2 ** highbit */
1004 if (power * highbit <= 8 * sizeof(UV)) {
1005 /* result will definitely fit in UV, so use UV math
1006 on same algorithm as above */
1007 register UV result = 1;
1008 register UV base = baseuv;
1009 const bool odd_power = (bool)(power & 1);
1013 while (power >>= 1) {
1020 if (baseuok || !odd_power)
1021 /* answer is positive */
1023 else if (result <= (UV)IV_MAX)
1024 /* answer negative, fits in IV */
1025 SETi( -(IV)result );
1026 else if (result == (UV)IV_MIN)
1027 /* 2's complement assumption: special case IV_MIN */
1030 /* answer negative, doesn't fit */
1031 SETn( -(NV)result );
1043 #if defined(USE_LONG_DOUBLE) && defined(HAS_AIX_POWL_NEG_BASE_BUG)
1045 We are building perl with long double support and are on an AIX OS
1046 afflicted with a powl() function that wrongly returns NaNQ for any
1047 negative base. This was reported to IBM as PMR #23047-379 on
1048 03/06/2006. The problem exists in at least the following versions
1049 of AIX and the libm fileset, and no doubt others as well:
1051 AIX 4.3.3-ML10 bos.adt.libm 4.3.3.50
1052 AIX 5.1.0-ML04 bos.adt.libm 5.1.0.29
1053 AIX 5.2.0 bos.adt.libm 5.2.0.85
1055 So, until IBM fixes powl(), we provide the following workaround to
1056 handle the problem ourselves. Our logic is as follows: for
1057 negative bases (left), we use fmod(right, 2) to check if the
1058 exponent is an odd or even integer:
1060 - if odd, powl(left, right) == -powl(-left, right)
1061 - if even, powl(left, right) == powl(-left, right)
1063 If the exponent is not an integer, the result is rightly NaNQ, so
1064 we just return that (as NV_NAN).
1068 NV mod2 = Perl_fmod( right, 2.0 );
1069 if (mod2 == 1.0 || mod2 == -1.0) { /* odd integer */
1070 SETn( -Perl_pow( -left, right) );
1071 } else if (mod2 == 0.0) { /* even integer */
1072 SETn( Perl_pow( -left, right) );
1073 } else { /* fractional power */
1077 SETn( Perl_pow( left, right) );
1080 SETn( Perl_pow( left, right) );
1081 #endif /* HAS_AIX_POWL_NEG_BASE_BUG */
1083 #ifdef PERL_PRESERVE_IVUV
1093 dVAR; dSP; dATARGET; tryAMAGICbin(mult,opASSIGN);
1094 #ifdef PERL_PRESERVE_IVUV
1097 /* Unless the left argument is integer in range we are going to have to
1098 use NV maths. Hence only attempt to coerce the right argument if
1099 we know the left is integer. */
1100 /* Left operand is defined, so is it IV? */
1101 SvIV_please(TOPm1s);
1102 if (SvIOK(TOPm1s)) {
1103 bool auvok = SvUOK(TOPm1s);
1104 bool buvok = SvUOK(TOPs);
1105 const UV topmask = (~ (UV)0) << (4 * sizeof (UV));
1106 const UV botmask = ~((~ (UV)0) << (4 * sizeof (UV)));
1113 alow = SvUVX(TOPm1s);
1115 const IV aiv = SvIVX(TOPm1s);
1118 auvok = TRUE; /* effectively it's a UV now */
1120 alow = -aiv; /* abs, auvok == false records sign */
1126 const IV biv = SvIVX(TOPs);
1129 buvok = TRUE; /* effectively it's a UV now */
1131 blow = -biv; /* abs, buvok == false records sign */
1135 /* If this does sign extension on unsigned it's time for plan B */
1136 ahigh = alow >> (4 * sizeof (UV));
1138 bhigh = blow >> (4 * sizeof (UV));
1140 if (ahigh && bhigh) {
1142 /* eg 32 bit is at least 0x10000 * 0x10000 == 0x100000000
1143 which is overflow. Drop to NVs below. */
1144 } else if (!ahigh && !bhigh) {
1145 /* eg 32 bit is at most 0xFFFF * 0xFFFF == 0xFFFE0001
1146 so the unsigned multiply cannot overflow. */
1147 const UV product = alow * blow;
1148 if (auvok == buvok) {
1149 /* -ve * -ve or +ve * +ve gives a +ve result. */
1153 } else if (product <= (UV)IV_MIN) {
1154 /* 2s complement assumption that (UV)-IV_MIN is correct. */
1155 /* -ve result, which could overflow an IV */
1157 SETi( -(IV)product );
1159 } /* else drop to NVs below. */
1161 /* One operand is large, 1 small */
1164 /* swap the operands */
1166 bhigh = blow; /* bhigh now the temp var for the swap */
1170 /* now, ((ahigh * blow) << half_UV_len) + (alow * blow)
1171 multiplies can't overflow. shift can, add can, -ve can. */
1172 product_middle = ahigh * blow;
1173 if (!(product_middle & topmask)) {
1174 /* OK, (ahigh * blow) won't lose bits when we shift it. */
1176 product_middle <<= (4 * sizeof (UV));
1177 product_low = alow * blow;
1179 /* as for pp_add, UV + something mustn't get smaller.
1180 IIRC ANSI mandates this wrapping *behaviour* for
1181 unsigned whatever the actual representation*/
1182 product_low += product_middle;
1183 if (product_low >= product_middle) {
1184 /* didn't overflow */
1185 if (auvok == buvok) {
1186 /* -ve * -ve or +ve * +ve gives a +ve result. */
1188 SETu( product_low );
1190 } else if (product_low <= (UV)IV_MIN) {
1191 /* 2s complement assumption again */
1192 /* -ve result, which could overflow an IV */
1194 SETi( -(IV)product_low );
1196 } /* else drop to NVs below. */
1198 } /* product_middle too large */
1199 } /* ahigh && bhigh */
1200 } /* SvIOK(TOPm1s) */
1205 SETn( left * right );
1212 dVAR; dSP; dATARGET; tryAMAGICbin(div,opASSIGN);
1213 /* Only try to do UV divide first
1214 if ((SLOPPYDIVIDE is true) or
1215 (PERL_PRESERVE_IVUV is true and one or both SV is a UV too large
1217 The assumption is that it is better to use floating point divide
1218 whenever possible, only doing integer divide first if we can't be sure.
1219 If NV_PRESERVES_UV is true then we know at compile time that no UV
1220 can be too large to preserve, so don't need to compile the code to
1221 test the size of UVs. */
1224 # define PERL_TRY_UV_DIVIDE
1225 /* ensure that 20./5. == 4. */
1227 # ifdef PERL_PRESERVE_IVUV
1228 # ifndef NV_PRESERVES_UV
1229 # define PERL_TRY_UV_DIVIDE
1234 #ifdef PERL_TRY_UV_DIVIDE
1237 SvIV_please(TOPm1s);
1238 if (SvIOK(TOPm1s)) {
1239 bool left_non_neg = SvUOK(TOPm1s);
1240 bool right_non_neg = SvUOK(TOPs);
1244 if (right_non_neg) {
1245 right = SvUVX(TOPs);
1248 const IV biv = SvIVX(TOPs);
1251 right_non_neg = TRUE; /* effectively it's a UV now */
1257 /* historically undef()/0 gives a "Use of uninitialized value"
1258 warning before dieing, hence this test goes here.
1259 If it were immediately before the second SvIV_please, then
1260 DIE() would be invoked before left was even inspected, so
1261 no inpsection would give no warning. */
1263 DIE(aTHX_ "Illegal division by zero");
1266 left = SvUVX(TOPm1s);
1269 const IV aiv = SvIVX(TOPm1s);
1272 left_non_neg = TRUE; /* effectively it's a UV now */
1281 /* For sloppy divide we always attempt integer division. */
1283 /* Otherwise we only attempt it if either or both operands
1284 would not be preserved by an NV. If both fit in NVs
1285 we fall through to the NV divide code below. However,
1286 as left >= right to ensure integer result here, we know that
1287 we can skip the test on the right operand - right big
1288 enough not to be preserved can't get here unless left is
1291 && (left > ((UV)1 << NV_PRESERVES_UV_BITS))
1294 /* Integer division can't overflow, but it can be imprecise. */
1295 const UV result = left / right;
1296 if (result * right == left) {
1297 SP--; /* result is valid */
1298 if (left_non_neg == right_non_neg) {
1299 /* signs identical, result is positive. */
1303 /* 2s complement assumption */
1304 if (result <= (UV)IV_MIN)
1305 SETi( -(IV)result );
1307 /* It's exact but too negative for IV. */
1308 SETn( -(NV)result );
1311 } /* tried integer divide but it was not an integer result */
1312 } /* else (PERL_ABS(result) < 1.0) or (both UVs in range for NV) */
1313 } /* left wasn't SvIOK */
1314 } /* right wasn't SvIOK */
1315 #endif /* PERL_TRY_UV_DIVIDE */
1318 #if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan)
1319 if (! Perl_isnan(right) && right == 0.0)
1323 DIE(aTHX_ "Illegal division by zero");
1324 PUSHn( left / right );
1331 dVAR; dSP; dATARGET; tryAMAGICbin(modulo,opASSIGN);
1335 bool left_neg = FALSE;
1336 bool right_neg = FALSE;
1337 bool use_double = FALSE;
1338 bool dright_valid = FALSE;
1344 right_neg = !SvUOK(TOPs);
1346 right = SvUVX(POPs);
1348 const IV biv = SvIVX(POPs);
1351 right_neg = FALSE; /* effectively it's a UV now */
1359 right_neg = dright < 0;
1362 if (dright < UV_MAX_P1) {
1363 right = U_V(dright);
1364 dright_valid = TRUE; /* In case we need to use double below. */
1370 /* At this point use_double is only true if right is out of range for
1371 a UV. In range NV has been rounded down to nearest UV and
1372 use_double false. */
1374 if (!use_double && SvIOK(TOPs)) {
1376 left_neg = !SvUOK(TOPs);
1380 const IV aiv = SvIVX(POPs);
1383 left_neg = FALSE; /* effectively it's a UV now */
1392 left_neg = dleft < 0;
1396 /* This should be exactly the 5.6 behaviour - if left and right are
1397 both in range for UV then use U_V() rather than floor. */
1399 if (dleft < UV_MAX_P1) {
1400 /* right was in range, so is dleft, so use UVs not double.
1404 /* left is out of range for UV, right was in range, so promote
1405 right (back) to double. */
1407 /* The +0.5 is used in 5.6 even though it is not strictly
1408 consistent with the implicit +0 floor in the U_V()
1409 inside the #if 1. */
1410 dleft = Perl_floor(dleft + 0.5);
1413 dright = Perl_floor(dright + 0.5);
1423 DIE(aTHX_ "Illegal modulus zero");
1425 dans = Perl_fmod(dleft, dright);
1426 if ((left_neg != right_neg) && dans)
1427 dans = dright - dans;
1430 sv_setnv(TARG, dans);
1436 DIE(aTHX_ "Illegal modulus zero");
1439 if ((left_neg != right_neg) && ans)
1442 /* XXX may warn: unary minus operator applied to unsigned type */
1443 /* could change -foo to be (~foo)+1 instead */
1444 if (ans <= ~((UV)IV_MAX)+1)
1445 sv_setiv(TARG, ~ans+1);
1447 sv_setnv(TARG, -(NV)ans);
1450 sv_setuv(TARG, ans);
1459 dVAR; dSP; dATARGET; tryAMAGICbin(repeat,opASSIGN);
1466 const UV uv = SvUV(sv);
1468 count = IV_MAX; /* The best we can do? */
1472 const IV iv = SvIV(sv);
1479 else if (SvNOKp(sv)) {
1480 const NV nv = SvNV(sv);
1488 if (GIMME == G_ARRAY && PL_op->op_private & OPpREPEAT_DOLIST) {
1490 static const char oom_list_extend[] = "Out of memory during list extend";
1491 const I32 items = SP - MARK;
1492 const I32 max = items * count;
1494 MEM_WRAP_CHECK_1(max, SV*, oom_list_extend);
1495 /* Did the max computation overflow? */
1496 if (items > 0 && max > 0 && (max < items || max < count))
1497 Perl_croak(aTHX_ oom_list_extend);
1502 /* This code was intended to fix 20010809.028:
1505 for (($x =~ /./g) x 2) {
1506 print chop; # "abcdabcd" expected as output.
1509 * but that change (#11635) broke this code:
1511 $x = [("foo")x2]; # only one "foo" ended up in the anonlist.
1513 * I can't think of a better fix that doesn't introduce
1514 * an efficiency hit by copying the SVs. The stack isn't
1515 * refcounted, and mortalisation obviously doesn't
1516 * Do The Right Thing when the stack has more than
1517 * one pointer to the same mortal value.
1521 *SP = sv_2mortal(newSVsv(*SP));
1531 repeatcpy((char*)(MARK + items), (char*)MARK,
1532 items * sizeof(SV*), count - 1);
1535 else if (count <= 0)
1538 else { /* Note: mark already snarfed by pp_list */
1539 SV * const tmpstr = POPs;
1542 static const char oom_string_extend[] =
1543 "Out of memory during string extend";
1545 SvSetSV(TARG, tmpstr);
1546 SvPV_force(TARG, len);
1547 isutf = DO_UTF8(TARG);
1552 const STRLEN max = (UV)count * len;
1553 if (len > MEM_SIZE_MAX / count)
1554 Perl_croak(aTHX_ oom_string_extend);
1555 MEM_WRAP_CHECK_1(max, char, oom_string_extend);
1556 SvGROW(TARG, max + 1);
1557 repeatcpy(SvPVX(TARG) + len, SvPVX(TARG), len, count - 1);
1558 SvCUR_set(TARG, SvCUR(TARG) * count);
1560 *SvEND(TARG) = '\0';
1563 (void)SvPOK_only_UTF8(TARG);
1565 (void)SvPOK_only(TARG);
1567 if (PL_op->op_private & OPpREPEAT_DOLIST) {
1568 /* The parser saw this as a list repeat, and there
1569 are probably several items on the stack. But we're
1570 in scalar context, and there's no pp_list to save us
1571 now. So drop the rest of the items -- robin@kitsite.com
1584 dVAR; dSP; dATARGET; bool useleft; tryAMAGICbin(subtr,opASSIGN);
1585 useleft = USE_LEFT(TOPm1s);
1586 #ifdef PERL_PRESERVE_IVUV
1587 /* See comments in pp_add (in pp_hot.c) about Overflow, and how
1588 "bad things" happen if you rely on signed integers wrapping. */
1591 /* Unless the left argument is integer in range we are going to have to
1592 use NV maths. Hence only attempt to coerce the right argument if
1593 we know the left is integer. */
1594 register UV auv = 0;
1600 a_valid = auvok = 1;
1601 /* left operand is undef, treat as zero. */
1603 /* Left operand is defined, so is it IV? */
1604 SvIV_please(TOPm1s);
1605 if (SvIOK(TOPm1s)) {
1606 if ((auvok = SvUOK(TOPm1s)))
1607 auv = SvUVX(TOPm1s);
1609 register const IV aiv = SvIVX(TOPm1s);
1612 auvok = 1; /* Now acting as a sign flag. */
1613 } else { /* 2s complement assumption for IV_MIN */
1621 bool result_good = 0;
1624 bool buvok = SvUOK(TOPs);
1629 register const IV biv = SvIVX(TOPs);
1636 /* ?uvok if value is >= 0. basically, flagged as UV if it's +ve,
1637 else "IV" now, independent of how it came in.
1638 if a, b represents positive, A, B negative, a maps to -A etc
1643 all UV maths. negate result if A negative.
1644 subtract if signs same, add if signs differ. */
1646 if (auvok ^ buvok) {
1655 /* Must get smaller */
1660 if (result <= buv) {
1661 /* result really should be -(auv-buv). as its negation
1662 of true value, need to swap our result flag */
1674 if (result <= (UV)IV_MIN)
1675 SETi( -(IV)result );
1677 /* result valid, but out of range for IV. */
1678 SETn( -(NV)result );
1682 } /* Overflow, drop through to NVs. */
1686 useleft = USE_LEFT(TOPm1s);
1690 /* left operand is undef, treat as zero - value */
1694 SETn( TOPn - value );
1701 dVAR; dSP; dATARGET; tryAMAGICbin(lshift,opASSIGN);
1703 const IV shift = POPi;
1704 if (PL_op->op_private & HINT_INTEGER) {
1718 dVAR; dSP; dATARGET; tryAMAGICbin(rshift,opASSIGN);
1720 const IV shift = POPi;
1721 if (PL_op->op_private & HINT_INTEGER) {
1735 dVAR; dSP; tryAMAGICbinSET(lt,0);
1736 #ifdef PERL_PRESERVE_IVUV
1739 SvIV_please(TOPm1s);
1740 if (SvIOK(TOPm1s)) {
1741 bool auvok = SvUOK(TOPm1s);
1742 bool buvok = SvUOK(TOPs);
1744 if (!auvok && !buvok) { /* ## IV < IV ## */
1745 const IV aiv = SvIVX(TOPm1s);
1746 const IV biv = SvIVX(TOPs);
1749 SETs(boolSV(aiv < biv));
1752 if (auvok && buvok) { /* ## UV < UV ## */
1753 const UV auv = SvUVX(TOPm1s);
1754 const UV buv = SvUVX(TOPs);
1757 SETs(boolSV(auv < buv));
1760 if (auvok) { /* ## UV < IV ## */
1762 const IV biv = SvIVX(TOPs);
1765 /* As (a) is a UV, it's >=0, so it cannot be < */
1770 SETs(boolSV(auv < (UV)biv));
1773 { /* ## IV < UV ## */
1774 const IV aiv = SvIVX(TOPm1s);
1778 /* As (b) is a UV, it's >=0, so it must be < */
1785 SETs(boolSV((UV)aiv < buv));
1791 #ifndef NV_PRESERVES_UV
1792 #ifdef PERL_PRESERVE_IVUV
1795 if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) {
1797 SETs(boolSV(SvRV(TOPs) < SvRV(TOPp1s)));
1802 #if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan)
1804 if (Perl_isnan(left) || Perl_isnan(right))
1806 SETs(boolSV(left < right));
1809 SETs(boolSV(TOPn < value));
1817 dVAR; dSP; tryAMAGICbinSET(gt,0);
1818 #ifdef PERL_PRESERVE_IVUV
1821 SvIV_please(TOPm1s);
1822 if (SvIOK(TOPm1s)) {
1823 bool auvok = SvUOK(TOPm1s);
1824 bool buvok = SvUOK(TOPs);
1826 if (!auvok && !buvok) { /* ## IV > IV ## */
1827 const IV aiv = SvIVX(TOPm1s);
1828 const IV biv = SvIVX(TOPs);
1831 SETs(boolSV(aiv > biv));
1834 if (auvok && buvok) { /* ## UV > UV ## */
1835 const UV auv = SvUVX(TOPm1s);
1836 const UV buv = SvUVX(TOPs);
1839 SETs(boolSV(auv > buv));
1842 if (auvok) { /* ## UV > IV ## */
1844 const IV biv = SvIVX(TOPs);
1848 /* As (a) is a UV, it's >=0, so it must be > */
1853 SETs(boolSV(auv > (UV)biv));
1856 { /* ## IV > UV ## */
1857 const IV aiv = SvIVX(TOPm1s);
1861 /* As (b) is a UV, it's >=0, so it cannot be > */
1868 SETs(boolSV((UV)aiv > buv));
1874 #ifndef NV_PRESERVES_UV
1875 #ifdef PERL_PRESERVE_IVUV
1878 if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) {
1880 SETs(boolSV(SvRV(TOPs) > SvRV(TOPp1s)));
1885 #if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan)
1887 if (Perl_isnan(left) || Perl_isnan(right))
1889 SETs(boolSV(left > right));
1892 SETs(boolSV(TOPn > value));
1900 dVAR; dSP; tryAMAGICbinSET(le,0);
1901 #ifdef PERL_PRESERVE_IVUV
1904 SvIV_please(TOPm1s);
1905 if (SvIOK(TOPm1s)) {
1906 bool auvok = SvUOK(TOPm1s);
1907 bool buvok = SvUOK(TOPs);
1909 if (!auvok && !buvok) { /* ## IV <= IV ## */
1910 const IV aiv = SvIVX(TOPm1s);
1911 const IV biv = SvIVX(TOPs);
1914 SETs(boolSV(aiv <= biv));
1917 if (auvok && buvok) { /* ## UV <= UV ## */
1918 UV auv = SvUVX(TOPm1s);
1919 UV buv = SvUVX(TOPs);
1922 SETs(boolSV(auv <= buv));
1925 if (auvok) { /* ## UV <= IV ## */
1927 const IV biv = SvIVX(TOPs);
1931 /* As (a) is a UV, it's >=0, so a cannot be <= */
1936 SETs(boolSV(auv <= (UV)biv));
1939 { /* ## IV <= UV ## */
1940 const IV aiv = SvIVX(TOPm1s);
1944 /* As (b) is a UV, it's >=0, so a must be <= */
1951 SETs(boolSV((UV)aiv <= buv));
1957 #ifndef NV_PRESERVES_UV
1958 #ifdef PERL_PRESERVE_IVUV
1961 if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) {
1963 SETs(boolSV(SvRV(TOPs) <= SvRV(TOPp1s)));
1968 #if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan)
1970 if (Perl_isnan(left) || Perl_isnan(right))
1972 SETs(boolSV(left <= right));
1975 SETs(boolSV(TOPn <= value));
1983 dVAR; dSP; tryAMAGICbinSET(ge,0);
1984 #ifdef PERL_PRESERVE_IVUV
1987 SvIV_please(TOPm1s);
1988 if (SvIOK(TOPm1s)) {
1989 bool auvok = SvUOK(TOPm1s);
1990 bool buvok = SvUOK(TOPs);
1992 if (!auvok && !buvok) { /* ## IV >= IV ## */
1993 const IV aiv = SvIVX(TOPm1s);
1994 const IV biv = SvIVX(TOPs);
1997 SETs(boolSV(aiv >= biv));
2000 if (auvok && buvok) { /* ## UV >= UV ## */
2001 const UV auv = SvUVX(TOPm1s);
2002 const UV buv = SvUVX(TOPs);
2005 SETs(boolSV(auv >= buv));
2008 if (auvok) { /* ## UV >= IV ## */
2010 const IV biv = SvIVX(TOPs);
2014 /* As (a) is a UV, it's >=0, so it must be >= */
2019 SETs(boolSV(auv >= (UV)biv));
2022 { /* ## IV >= UV ## */
2023 const IV aiv = SvIVX(TOPm1s);
2027 /* As (b) is a UV, it's >=0, so a cannot be >= */
2034 SETs(boolSV((UV)aiv >= buv));
2040 #ifndef NV_PRESERVES_UV
2041 #ifdef PERL_PRESERVE_IVUV
2044 if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) {
2046 SETs(boolSV(SvRV(TOPs) >= SvRV(TOPp1s)));
2051 #if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan)
2053 if (Perl_isnan(left) || Perl_isnan(right))
2055 SETs(boolSV(left >= right));
2058 SETs(boolSV(TOPn >= value));
2066 dVAR; dSP; tryAMAGICbinSET(ne,0);
2067 #ifndef NV_PRESERVES_UV
2068 if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) {
2070 SETs(boolSV(SvRV(TOPs) != SvRV(TOPp1s)));
2074 #ifdef PERL_PRESERVE_IVUV
2077 SvIV_please(TOPm1s);
2078 if (SvIOK(TOPm1s)) {
2079 const bool auvok = SvUOK(TOPm1s);
2080 const bool buvok = SvUOK(TOPs);
2082 if (auvok == buvok) { /* ## IV == IV or UV == UV ## */
2083 /* Casting IV to UV before comparison isn't going to matter
2084 on 2s complement. On 1s complement or sign&magnitude
2085 (if we have any of them) it could make negative zero
2086 differ from normal zero. As I understand it. (Need to
2087 check - is negative zero implementation defined behaviour
2089 const UV buv = SvUVX(POPs);
2090 const UV auv = SvUVX(TOPs);
2092 SETs(boolSV(auv != buv));
2095 { /* ## Mixed IV,UV ## */
2099 /* != is commutative so swap if needed (save code) */
2101 /* swap. top of stack (b) is the iv */
2105 /* As (a) is a UV, it's >0, so it cannot be == */
2114 /* As (b) is a UV, it's >0, so it cannot be == */
2118 uv = SvUVX(*(SP+1)); /* Do I want TOPp1s() ? */
2120 SETs(boolSV((UV)iv != uv));
2127 #if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan)
2129 if (Perl_isnan(left) || Perl_isnan(right))
2131 SETs(boolSV(left != right));
2134 SETs(boolSV(TOPn != value));
2142 dVAR; dSP; dTARGET; tryAMAGICbin(ncmp,0);
2143 #ifndef NV_PRESERVES_UV
2144 if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) {
2145 const UV right = PTR2UV(SvRV(POPs));
2146 const UV left = PTR2UV(SvRV(TOPs));
2147 SETi((left > right) - (left < right));
2151 #ifdef PERL_PRESERVE_IVUV
2152 /* Fortunately it seems NaN isn't IOK */
2155 SvIV_please(TOPm1s);
2156 if (SvIOK(TOPm1s)) {
2157 const bool leftuvok = SvUOK(TOPm1s);
2158 const bool rightuvok = SvUOK(TOPs);
2160 if (!leftuvok && !rightuvok) { /* ## IV <=> IV ## */
2161 const IV leftiv = SvIVX(TOPm1s);
2162 const IV rightiv = SvIVX(TOPs);
2164 if (leftiv > rightiv)
2166 else if (leftiv < rightiv)
2170 } else if (leftuvok && rightuvok) { /* ## UV <=> UV ## */
2171 const UV leftuv = SvUVX(TOPm1s);
2172 const UV rightuv = SvUVX(TOPs);
2174 if (leftuv > rightuv)
2176 else if (leftuv < rightuv)
2180 } else if (leftuvok) { /* ## UV <=> IV ## */
2181 const IV rightiv = SvIVX(TOPs);
2183 /* As (a) is a UV, it's >=0, so it cannot be < */
2186 const UV leftuv = SvUVX(TOPm1s);
2187 if (leftuv > (UV)rightiv) {
2189 } else if (leftuv < (UV)rightiv) {
2195 } else { /* ## IV <=> UV ## */
2196 const IV leftiv = SvIVX(TOPm1s);
2198 /* As (b) is a UV, it's >=0, so it must be < */
2201 const UV rightuv = SvUVX(TOPs);
2202 if ((UV)leftiv > rightuv) {
2204 } else if ((UV)leftiv < rightuv) {
2222 if (Perl_isnan(left) || Perl_isnan(right)) {
2226 value = (left > right) - (left < right);
2230 else if (left < right)
2232 else if (left > right)
2248 int amg_type = sle_amg;
2252 switch (PL_op->op_type) {
2271 tryAMAGICbinSET_var(amg_type,0);
2274 const int cmp = (IN_LOCALE_RUNTIME
2275 ? sv_cmp_locale(left, right)
2276 : sv_cmp(left, right));
2277 SETs(boolSV(cmp * multiplier < rhs));
2284 dVAR; dSP; tryAMAGICbinSET(seq,0);
2287 SETs(boolSV(sv_eq(left, right)));
2294 dVAR; dSP; tryAMAGICbinSET(sne,0);
2297 SETs(boolSV(!sv_eq(left, right)));
2304 dVAR; dSP; dTARGET; tryAMAGICbin(scmp,0);
2307 const int cmp = (IN_LOCALE_RUNTIME
2308 ? sv_cmp_locale(left, right)
2309 : sv_cmp(left, right));
2317 dVAR; dSP; dATARGET; tryAMAGICbin(band,opASSIGN);
2322 if (SvNIOKp(left) || SvNIOKp(right)) {
2323 if (PL_op->op_private & HINT_INTEGER) {
2324 const IV i = SvIV_nomg(left) & SvIV_nomg(right);
2328 const UV u = SvUV_nomg(left) & SvUV_nomg(right);
2333 do_vop(PL_op->op_type, TARG, left, right);
2342 dVAR; dSP; dATARGET;
2343 const int op_type = PL_op->op_type;
2345 tryAMAGICbin_var((op_type == OP_BIT_OR ? bor_amg : bxor_amg), opASSIGN);
2350 if (SvNIOKp(left) || SvNIOKp(right)) {
2351 if (PL_op->op_private & HINT_INTEGER) {
2352 const IV l = (USE_LEFT(left) ? SvIV_nomg(left) : 0);
2353 const IV r = SvIV_nomg(right);
2354 const IV result = op_type == OP_BIT_OR ? (l | r) : (l ^ r);
2358 const UV l = (USE_LEFT(left) ? SvUV_nomg(left) : 0);
2359 const UV r = SvUV_nomg(right);
2360 const UV result = op_type == OP_BIT_OR ? (l | r) : (l ^ r);
2365 do_vop(op_type, TARG, left, right);
2374 dVAR; dSP; dTARGET; tryAMAGICun(neg);
2377 const int flags = SvFLAGS(sv);
2379 if ((flags & SVf_IOK) || ((flags & (SVp_IOK | SVp_NOK)) == SVp_IOK)) {
2380 /* It's publicly an integer, or privately an integer-not-float */
2383 if (SvIVX(sv) == IV_MIN) {
2384 /* 2s complement assumption. */
2385 SETi(SvIVX(sv)); /* special case: -((UV)IV_MAX+1) == IV_MIN */
2388 else if (SvUVX(sv) <= IV_MAX) {
2393 else if (SvIVX(sv) != IV_MIN) {
2397 #ifdef PERL_PRESERVE_IVUV
2406 else if (SvPOKp(sv)) {
2408 const char * const s = SvPV_const(sv, len);
2409 if (isIDFIRST(*s)) {
2410 sv_setpvn(TARG, "-", 1);
2413 else if (*s == '+' || *s == '-') {
2415 *SvPV_force(TARG, len) = *s == '-' ? '+' : '-';
2417 else if (DO_UTF8(sv)) {
2420 goto oops_its_an_int;
2422 sv_setnv(TARG, -SvNV(sv));
2424 sv_setpvn(TARG, "-", 1);
2431 goto oops_its_an_int;
2432 sv_setnv(TARG, -SvNV(sv));
2444 dVAR; dSP; tryAMAGICunSET(not);
2445 *PL_stack_sp = boolSV(!SvTRUE(*PL_stack_sp));
2451 dVAR; dSP; dTARGET; tryAMAGICun(compl);
2456 if (PL_op->op_private & HINT_INTEGER) {
2457 const IV i = ~SvIV_nomg(sv);
2461 const UV u = ~SvUV_nomg(sv);
2470 (void)SvPV_nomg_const(sv,len); /* force check for uninit var */
2471 sv_setsv_nomg(TARG, sv);
2472 tmps = (U8*)SvPV_force(TARG, len);
2475 /* Calculate exact length, let's not estimate. */
2480 U8 * const send = tmps + len;
2481 U8 * const origtmps = tmps;
2482 const UV utf8flags = UTF8_ALLOW_ANYUV;
2484 while (tmps < send) {
2485 const UV c = utf8n_to_uvchr(tmps, send-tmps, &l, utf8flags);
2487 targlen += UNISKIP(~c);
2493 /* Now rewind strings and write them. */
2500 Newx(result, targlen + 1, U8);
2502 while (tmps < send) {
2503 const UV c = utf8n_to_uvchr(tmps, send-tmps, &l, utf8flags);
2505 p = uvchr_to_utf8_flags(p, ~c, UNICODE_ALLOW_ANY);
2508 sv_usepvn_flags(TARG, (char*)result, targlen,
2509 SV_HAS_TRAILING_NUL);
2516 Newx(result, nchar + 1, U8);
2518 while (tmps < send) {
2519 const U8 c = (U8)utf8n_to_uvchr(tmps, send-tmps, &l, utf8flags);
2524 sv_usepvn_flags(TARG, (char*)result, nchar, SV_HAS_TRAILING_NUL);
2532 register long *tmpl;
2533 for ( ; anum && (unsigned long)tmps % sizeof(long); anum--, tmps++)
2536 for ( ; anum >= (I32)sizeof(long); anum -= (I32)sizeof(long), tmpl++)
2541 for ( ; anum > 0; anum--, tmps++)
2550 /* integer versions of some of the above */
2554 dVAR; dSP; dATARGET; tryAMAGICbin(mult,opASSIGN);
2557 SETi( left * right );
2565 dVAR; dSP; dATARGET; tryAMAGICbin(div,opASSIGN);
2569 DIE(aTHX_ "Illegal division by zero");
2572 /* avoid FPE_INTOVF on some platforms when num is IV_MIN */
2576 value = num / value;
2582 #if defined(__GLIBC__) && IVSIZE == 8
2589 /* This is the vanilla old i_modulo. */
2590 dVAR; dSP; dATARGET; tryAMAGICbin(modulo,opASSIGN);
2594 DIE(aTHX_ "Illegal modulus zero");
2595 /* avoid FPE_INTOVF on some platforms when left is IV_MIN */
2599 SETi( left % right );
2604 #if defined(__GLIBC__) && IVSIZE == 8
2609 /* This is the i_modulo with the workaround for the _moddi3 bug
2610 * in (at least) glibc 2.2.5 (the PERL_ABS() the workaround).
2611 * See below for pp_i_modulo. */
2612 dVAR; dVAR; dSP; dATARGET; tryAMAGICbin(modulo,opASSIGN);
2616 DIE(aTHX_ "Illegal modulus zero");
2617 /* avoid FPE_INTOVF on some platforms when left is IV_MIN */
2621 SETi( left % PERL_ABS(right) );
2628 dVAR; dSP; dATARGET; tryAMAGICbin(modulo,opASSIGN);
2632 DIE(aTHX_ "Illegal modulus zero");
2633 /* The assumption is to use hereafter the old vanilla version... */
2635 PL_ppaddr[OP_I_MODULO] =
2637 /* .. but if we have glibc, we might have a buggy _moddi3
2638 * (at least glicb 2.2.5 is known to have this bug), in other
2639 * words our integer modulus with negative quad as the second
2640 * argument might be broken. Test for this and re-patch the
2641 * opcode dispatch table if that is the case, remembering to
2642 * also apply the workaround so that this first round works
2643 * right, too. See [perl #9402] for more information. */
2647 /* Cannot do this check with inlined IV constants since
2648 * that seems to work correctly even with the buggy glibc. */
2650 /* Yikes, we have the bug.
2651 * Patch in the workaround version. */
2653 PL_ppaddr[OP_I_MODULO] =
2654 &Perl_pp_i_modulo_1;
2655 /* Make certain we work right this time, too. */
2656 right = PERL_ABS(right);
2659 /* avoid FPE_INTOVF on some platforms when left is IV_MIN */
2663 SETi( left % right );
2671 dVAR; dSP; dATARGET; tryAMAGICbin(add,opASSIGN);
2674 SETi( left + right );
2681 dVAR; dSP; dATARGET; tryAMAGICbin(subtr,opASSIGN);
2684 SETi( left - right );
2691 dVAR; dSP; tryAMAGICbinSET(lt,0);
2694 SETs(boolSV(left < right));
2701 dVAR; dSP; tryAMAGICbinSET(gt,0);
2704 SETs(boolSV(left > right));
2711 dVAR; dSP; tryAMAGICbinSET(le,0);
2714 SETs(boolSV(left <= right));
2721 dVAR; dSP; tryAMAGICbinSET(ge,0);
2724 SETs(boolSV(left >= right));
2731 dVAR; dSP; tryAMAGICbinSET(eq,0);
2734 SETs(boolSV(left == right));
2741 dVAR; dSP; tryAMAGICbinSET(ne,0);
2744 SETs(boolSV(left != right));
2751 dVAR; dSP; dTARGET; tryAMAGICbin(ncmp,0);
2758 else if (left < right)
2769 dVAR; dSP; dTARGET; tryAMAGICun(neg);
2774 /* High falutin' math. */
2778 dVAR; dSP; dTARGET; tryAMAGICbin(atan2,0);
2781 SETn(Perl_atan2(left, right));
2789 int amg_type = sin_amg;
2790 const char *neg_report = NULL;
2791 NV (*func)(NV) = Perl_sin;
2792 const int op_type = PL_op->op_type;
2809 amg_type = sqrt_amg;
2811 neg_report = "sqrt";
2815 tryAMAGICun_var(amg_type);
2817 const NV value = POPn;
2819 if (op_type == OP_LOG ? (value <= 0.0) : (value < 0.0)) {
2820 SET_NUMERIC_STANDARD();
2821 DIE(aTHX_ "Can't take %s of %"NVgf, neg_report, value);
2824 XPUSHn(func(value));
2829 /* Support Configure command-line overrides for rand() functions.
2830 After 5.005, perhaps we should replace this by Configure support
2831 for drand48(), random(), or rand(). For 5.005, though, maintain
2832 compatibility by calling rand() but allow the user to override it.
2833 See INSTALL for details. --Andy Dougherty 15 July 1998
2835 /* Now it's after 5.005, and Configure supports drand48() and random(),
2836 in addition to rand(). So the overrides should not be needed any more.
2837 --Jarkko Hietaniemi 27 September 1998
2840 #ifndef HAS_DRAND48_PROTO
2841 extern double drand48 (void);
2854 if (!PL_srand_called) {
2855 (void)seedDrand01((Rand_seed_t)seed());
2856 PL_srand_called = TRUE;
2866 const UV anum = (MAXARG < 1) ? seed() : POPu;
2867 (void)seedDrand01((Rand_seed_t)anum);
2868 PL_srand_called = TRUE;
2875 dVAR; dSP; dTARGET; tryAMAGICun(int);
2877 const IV iv = TOPi; /* attempt to convert to IV if possible. */
2878 /* XXX it's arguable that compiler casting to IV might be subtly
2879 different from modf (for numbers inside (IV_MIN,UV_MAX)) in which
2880 else preferring IV has introduced a subtle behaviour change bug. OTOH
2881 relying on floating point to be accurate is a bug. */
2885 else if (SvIOK(TOPs)) {
2892 const NV value = TOPn;
2894 if (value < (NV)UV_MAX + 0.5) {
2897 SETn(Perl_floor(value));
2901 if (value > (NV)IV_MIN - 0.5) {
2904 SETn(Perl_ceil(value));
2914 dVAR; dSP; dTARGET; tryAMAGICun(abs);
2916 /* This will cache the NV value if string isn't actually integer */
2921 else if (SvIOK(TOPs)) {
2922 /* IVX is precise */
2924 SETu(TOPu); /* force it to be numeric only */
2932 /* 2s complement assumption. Also, not really needed as
2933 IV_MIN and -IV_MIN should both be %100...00 and NV-able */
2939 const NV value = TOPn;
2953 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES;
2957 SV* const sv = POPs;
2959 tmps = (SvPV_const(sv, len));
2961 /* If Unicode, try to downgrade
2962 * If not possible, croak. */
2963 SV* const tsv = sv_2mortal(newSVsv(sv));
2966 sv_utf8_downgrade(tsv, FALSE);
2967 tmps = SvPV_const(tsv, len);
2969 if (PL_op->op_type == OP_HEX)
2972 while (*tmps && len && isSPACE(*tmps))
2978 result_uv = grok_hex (tmps, &len, &flags, &result_nv);
2980 else if (*tmps == 'b')
2981 result_uv = grok_bin (tmps, &len, &flags, &result_nv);
2983 result_uv = grok_oct (tmps, &len, &flags, &result_nv);
2985 if (flags & PERL_SCAN_GREATER_THAN_UV_MAX) {
2999 SV * const sv = TOPs;
3002 /* For an overloaded scalar, we can't know in advance if it's going to
3003 be UTF-8 or not. Also, we can't call sv_len_utf8 as it likes to
3004 cache the length. Maybe that should be a documented feature of it.
3007 const char *const p = SvPV_const(sv, len);
3010 SETi(utf8_length((U8*)p, (U8*)p + len));
3016 else if (DO_UTF8(sv))
3017 SETi(sv_len_utf8(sv));
3033 const I32 lvalue = PL_op->op_flags & OPf_MOD || LVRET;
3035 const I32 arybase = CopARYBASE_get(PL_curcop);
3037 const char *repl = NULL;
3039 const int num_args = PL_op->op_private & 7;
3040 bool repl_need_utf8_upgrade = FALSE;
3041 bool repl_is_utf8 = FALSE;
3043 SvTAINTED_off(TARG); /* decontaminate */
3044 SvUTF8_off(TARG); /* decontaminate */
3048 repl = SvPV_const(repl_sv, repl_len);
3049 repl_is_utf8 = DO_UTF8(repl_sv) && SvCUR(repl_sv);
3059 sv_utf8_upgrade(sv);
3061 else if (DO_UTF8(sv))
3062 repl_need_utf8_upgrade = TRUE;
3064 tmps = SvPV_const(sv, curlen);
3066 utf8_curlen = sv_len_utf8(sv);
3067 if (utf8_curlen == curlen)
3070 curlen = utf8_curlen;
3075 if (pos >= arybase) {
3093 else if (len >= 0) {
3095 if (rem > (I32)curlen)
3110 Perl_croak(aTHX_ "substr outside of string");
3111 if (ckWARN(WARN_SUBSTR))
3112 Perl_warner(aTHX_ packWARN(WARN_SUBSTR), "substr outside of string");
3116 const I32 upos = pos;
3117 const I32 urem = rem;
3119 sv_pos_u2b(sv, &pos, &rem);
3121 /* we either return a PV or an LV. If the TARG hasn't been used
3122 * before, or is of that type, reuse it; otherwise use a mortal
3123 * instead. Note that LVs can have an extended lifetime, so also
3124 * dont reuse if refcount > 1 (bug #20933) */
3125 if (SvTYPE(TARG) > SVt_NULL) {
3126 if ( (SvTYPE(TARG) == SVt_PVLV)
3127 ? (!lvalue || SvREFCNT(TARG) > 1)
3130 TARG = sv_newmortal();
3134 sv_setpvn(TARG, tmps, rem);
3135 #ifdef USE_LOCALE_COLLATE
3136 sv_unmagic(TARG, PERL_MAGIC_collxfrm);
3141 SV* repl_sv_copy = NULL;
3143 if (repl_need_utf8_upgrade) {
3144 repl_sv_copy = newSVsv(repl_sv);
3145 sv_utf8_upgrade(repl_sv_copy);
3146 repl = SvPV_const(repl_sv_copy, repl_len);
3147 repl_is_utf8 = DO_UTF8(repl_sv_copy) && SvCUR(sv);
3149 sv_insert(sv, pos, rem, repl, repl_len);
3153 SvREFCNT_dec(repl_sv_copy);
3155 else if (lvalue) { /* it's an lvalue! */
3156 if (!SvGMAGICAL(sv)) {
3158 SvPV_force_nolen(sv);
3159 if (ckWARN(WARN_SUBSTR))
3160 Perl_warner(aTHX_ packWARN(WARN_SUBSTR),
3161 "Attempt to use reference as lvalue in substr");
3163 if (isGV_with_GP(sv))
3164 SvPV_force_nolen(sv);
3165 else if (SvOK(sv)) /* is it defined ? */
3166 (void)SvPOK_only_UTF8(sv);
3168 sv_setpvn(sv,"",0); /* avoid lexical reincarnation */
3171 if (SvTYPE(TARG) < SVt_PVLV) {
3172 sv_upgrade(TARG, SVt_PVLV);
3173 sv_magic(TARG, NULL, PERL_MAGIC_substr, NULL, 0);
3177 if (LvTARG(TARG) != sv) {
3179 SvREFCNT_dec(LvTARG(TARG));
3180 LvTARG(TARG) = SvREFCNT_inc_simple(sv);
3182 LvTARGOFF(TARG) = upos;
3183 LvTARGLEN(TARG) = urem;
3187 PUSHs(TARG); /* avoid SvSETMAGIC here */
3194 register const IV size = POPi;
3195 register const IV offset = POPi;
3196 register SV * const src = POPs;
3197 const I32 lvalue = PL_op->op_flags & OPf_MOD || LVRET;
3199 SvTAINTED_off(TARG); /* decontaminate */
3200 if (lvalue) { /* it's an lvalue! */
3201 if (SvREFCNT(TARG) > 1) /* don't share the TARG (#20933) */
3202 TARG = sv_newmortal();
3203 if (SvTYPE(TARG) < SVt_PVLV) {
3204 sv_upgrade(TARG, SVt_PVLV);
3205 sv_magic(TARG, NULL, PERL_MAGIC_vec, NULL, 0);
3208 if (LvTARG(TARG) != src) {
3210 SvREFCNT_dec(LvTARG(TARG));
3211 LvTARG(TARG) = SvREFCNT_inc_simple(src);
3213 LvTARGOFF(TARG) = offset;
3214 LvTARGLEN(TARG) = size;
3217 sv_setuv(TARG, do_vecget(src, offset, size));
3233 const char *little_p;
3234 const I32 arybase = CopARYBASE_get(PL_curcop);
3237 const bool is_index = PL_op->op_type == OP_INDEX;
3240 /* arybase is in characters, like offset, so combine prior to the
3241 UTF-8 to bytes calculation. */
3242 offset = POPi - arybase;
3246 big_p = SvPV_const(big, biglen);
3247 little_p = SvPV_const(little, llen);
3249 big_utf8 = DO_UTF8(big);
3250 little_utf8 = DO_UTF8(little);
3251 if (big_utf8 ^ little_utf8) {
3252 /* One needs to be upgraded. */
3253 if (little_utf8 && !PL_encoding) {
3254 /* Well, maybe instead we might be able to downgrade the small
3256 char * const pv = (char*)bytes_from_utf8((U8 *)little_p, &llen,
3259 /* If the large string is ISO-8859-1, and it's not possible to
3260 convert the small string to ISO-8859-1, then there is no
3261 way that it could be found anywhere by index. */
3266 /* At this point, pv is a malloc()ed string. So donate it to temp
3267 to ensure it will get free()d */
3268 little = temp = newSV(0);
3269 sv_usepvn(temp, pv, llen);
3270 little_p = SvPVX(little);
3273 ? newSVpvn(big_p, biglen) : newSVpvn(little_p, llen);
3276 sv_recode_to_utf8(temp, PL_encoding);
3278 sv_utf8_upgrade(temp);
3283 big_p = SvPV_const(big, biglen);
3286 little_p = SvPV_const(little, llen);
3290 if (SvGAMAGIC(big)) {
3291 /* Life just becomes a lot easier if I use a temporary here.
3292 Otherwise I need to avoid calls to sv_pos_u2b(), which (dangerously)
3293 will trigger magic and overloading again, as will fbm_instr()
3295 big = sv_2mortal(newSVpvn(big_p, biglen));
3300 if (SvGAMAGIC(little) || (is_index && !SvOK(little))) {
3301 /* index && SvOK() is a hack. fbm_instr() calls SvPV_const, which will
3302 warn on undef, and we've already triggered a warning with the
3303 SvPV_const some lines above. We can't remove that, as we need to
3304 call some SvPV to trigger overloading early and find out if the
3306 This is all getting to messy. The API isn't quite clean enough,
3307 because data access has side effects.
3309 little = sv_2mortal(newSVpvn(little_p, llen));
3312 little_p = SvPVX(little);
3316 offset = is_index ? 0 : biglen;
3318 if (big_utf8 && offset > 0)
3319 sv_pos_u2b(big, &offset, 0);
3325 else if (offset > (I32)biglen)
3327 if (!(little_p = is_index
3328 ? fbm_instr((unsigned char*)big_p + offset,
3329 (unsigned char*)big_p + biglen, little, 0)
3330 : rninstr(big_p, big_p + offset,
3331 little_p, little_p + llen)))
3334 retval = little_p - big_p;
3335 if (retval > 0 && big_utf8)
3336 sv_pos_b2u(big, &retval);
3341 PUSHi(retval + arybase);
3347 dVAR; dSP; dMARK; dORIGMARK; dTARGET;
3348 if (SvTAINTED(MARK[1]))
3349 TAINT_PROPER("sprintf");
3350 do_sprintf(TARG, SP-MARK, MARK+1);
3351 TAINT_IF(SvTAINTED(TARG));
3363 const U8 *s = (U8*)SvPV_const(argsv, len);
3365 if (PL_encoding && SvPOK(argsv) && !DO_UTF8(argsv)) {
3366 SV * const tmpsv = sv_2mortal(newSVsv(argsv));
3367 s = (U8*)sv_recode_to_utf8(tmpsv, PL_encoding);
3371 XPUSHu(DO_UTF8(argsv) ?
3372 utf8n_to_uvchr(s, UTF8_MAXBYTES, 0, UTF8_ALLOW_ANYUV) :
3384 if (((SvIOK_notUV(TOPs) && SvIV(TOPs) < 0)
3386 (SvNOK(TOPs) && SvNV(TOPs) < 0.0))) {
3388 value = POPu; /* chr(-1) eq chr(0xff), etc. */
3390 (void) POPs; /* Ignore the argument value. */
3391 value = UNICODE_REPLACEMENT;
3397 SvUPGRADE(TARG,SVt_PV);
3399 if (value > 255 && !IN_BYTES) {
3400 SvGROW(TARG, (STRLEN)UNISKIP(value)+1);
3401 tmps = (char*)uvchr_to_utf8_flags((U8*)SvPVX(TARG), value, 0);
3402 SvCUR_set(TARG, tmps - SvPVX_const(TARG));
3404 (void)SvPOK_only(TARG);
3413 *tmps++ = (char)value;
3415 (void)SvPOK_only(TARG);
3417 if (PL_encoding && !IN_BYTES) {
3418 sv_recode_to_utf8(TARG, PL_encoding);
3420 if (SvCUR(TARG) == 0 || !is_utf8_string((U8*)tmps, SvCUR(TARG)) ||
3421 UNICODE_IS_REPLACEMENT(utf8_to_uvchr((U8*)tmps, NULL))) {
3425 *tmps++ = (char)value;
3441 const char *tmps = SvPV_const(left, len);
3443 if (DO_UTF8(left)) {
3444 /* If Unicode, try to downgrade.
3445 * If not possible, croak.
3446 * Yes, we made this up. */
3447 SV* const tsv = sv_2mortal(newSVsv(left));
3450 sv_utf8_downgrade(tsv, FALSE);
3451 tmps = SvPV_const(tsv, len);
3453 # ifdef USE_ITHREADS
3455 if (!PL_reentrant_buffer->_crypt_struct_buffer) {
3456 /* This should be threadsafe because in ithreads there is only
3457 * one thread per interpreter. If this would not be true,
3458 * we would need a mutex to protect this malloc. */
3459 PL_reentrant_buffer->_crypt_struct_buffer =
3460 (struct crypt_data *)safemalloc(sizeof(struct crypt_data));
3461 #if defined(__GLIBC__) || defined(__EMX__)
3462 if (PL_reentrant_buffer->_crypt_struct_buffer) {
3463 PL_reentrant_buffer->_crypt_struct_buffer->initialized = 0;
3464 /* work around glibc-2.2.5 bug */
3465 PL_reentrant_buffer->_crypt_struct_buffer->current_saltbits = 0;
3469 # endif /* HAS_CRYPT_R */
3470 # endif /* USE_ITHREADS */
3472 sv_setpv(TARG, fcrypt(tmps, SvPV_nolen_const(right)));
3474 sv_setpv(TARG, PerlProc_crypt(tmps, SvPV_nolen_const(right)));
3480 "The crypt() function is unimplemented due to excessive paranoia.");
3492 bool inplace = TRUE;
3494 const int op_type = PL_op->op_type;
3497 U8 tmpbuf[UTF8_MAXBYTES_CASE+1];
3503 s = (const U8*)SvPV_nomg_const(source, slen);
3509 if (slen && DO_UTF8(source) && UTF8_IS_START(*s)) {
3511 utf8_to_uvchr(s, &ulen);
3512 if (op_type == OP_UCFIRST) {
3513 toTITLE_utf8(s, tmpbuf, &tculen);
3515 toLOWER_utf8(s, tmpbuf, &tculen);
3517 /* If the two differ, we definately cannot do inplace. */
3518 inplace = (ulen == tculen);
3519 need = slen + 1 - ulen + tculen;
3525 if (SvPADTMP(source) && !SvREADONLY(source) && inplace && SvTEMP(source)) {
3526 /* We can convert in place. */
3529 s = d = (U8*)SvPV_force_nomg(source, slen);
3535 SvUPGRADE(dest, SVt_PV);
3536 d = (U8*)SvGROW(dest, need);
3537 (void)SvPOK_only(dest);
3546 /* slen is the byte length of the whole SV.
3547 * ulen is the byte length of the original Unicode character
3548 * stored as UTF-8 at s.
3549 * tculen is the byte length of the freshly titlecased (or
3550 * lowercased) Unicode character stored as UTF-8 at tmpbuf.
3551 * We first set the result to be the titlecased (/lowercased)
3552 * character, and then append the rest of the SV data. */
3553 sv_setpvn(dest, (char*)tmpbuf, tculen);
3555 sv_catpvn(dest, (char*)(s + ulen), slen - ulen);
3559 Copy(tmpbuf, d, tculen, U8);
3560 SvCUR_set(dest, need - 1);
3565 if (IN_LOCALE_RUNTIME) {
3568 *d = (op_type == OP_UCFIRST)
3569 ? toUPPER_LC(*s) : toLOWER_LC(*s);
3572 *d = (op_type == OP_UCFIRST) ? toUPPER(*s) : toLOWER(*s);
3574 /* See bug #39028 */
3582 /* This will copy the trailing NUL */
3583 Copy(s + 1, d + 1, slen, U8);
3584 SvCUR_set(dest, need - 1);
3591 /* There's so much setup/teardown code common between uc and lc, I wonder if
3592 it would be worth merging the two, and just having a switch outside each
3593 of the three tight loops. */
3607 if (SvPADTMP(source) && !SvREADONLY(source) && !SvAMAGIC(source)
3608 && SvTEMP(source) && !DO_UTF8(source)) {
3609 /* We can convert in place. */
3612 s = d = (U8*)SvPV_force_nomg(source, len);
3619 /* The old implementation would copy source into TARG at this point.
3620 This had the side effect that if source was undef, TARG was now
3621 an undefined SV with PADTMP set, and they don't warn inside
3622 sv_2pv_flags(). However, we're now getting the PV direct from
3623 source, which doesn't have PADTMP set, so it would warn. Hence the
3627 s = (const U8*)SvPV_nomg_const(source, len);
3634 SvUPGRADE(dest, SVt_PV);
3635 d = (U8*)SvGROW(dest, min);
3636 (void)SvPOK_only(dest);
3641 /* Overloaded values may have toggled the UTF-8 flag on source, so we need
3642 to check DO_UTF8 again here. */
3644 if (DO_UTF8(source)) {
3645 const U8 *const send = s + len;
3646 U8 tmpbuf[UTF8_MAXBYTES+1];
3649 const STRLEN u = UTF8SKIP(s);
3652 toUPPER_utf8(s, tmpbuf, &ulen);
3653 if (ulen > u && (SvLEN(dest) < (min += ulen - u))) {
3654 /* If the eventually required minimum size outgrows
3655 * the available space, we need to grow. */
3656 const UV o = d - (U8*)SvPVX_const(dest);
3658 /* If someone uppercases one million U+03B0s we SvGROW() one
3659 * million times. Or we could try guessing how much to
3660 allocate without allocating too much. Such is life. */
3662 d = (U8*)SvPVX(dest) + o;
3664 Copy(tmpbuf, d, ulen, U8);
3670 SvCUR_set(dest, d - (U8*)SvPVX_const(dest));
3673 const U8 *const send = s + len;
3674 if (IN_LOCALE_RUNTIME) {
3677 for (; s < send; d++, s++)
3678 *d = toUPPER_LC(*s);
3681 for (; s < send; d++, s++)
3685 if (source != dest) {
3687 SvCUR_set(dest, d - (U8*)SvPVX_const(dest));
3707 if (SvPADTMP(source) && !SvREADONLY(source) && !SvAMAGIC(source)
3708 && SvTEMP(source) && !DO_UTF8(source)) {
3709 /* We can convert in place. */
3712 s = d = (U8*)SvPV_force_nomg(source, len);
3719 /* The old implementation would copy source into TARG at this point.
3720 This had the side effect that if source was undef, TARG was now
3721 an undefined SV with PADTMP set, and they don't warn inside
3722 sv_2pv_flags(). However, we're now getting the PV direct from
3723 source, which doesn't have PADTMP set, so it would warn. Hence the
3727 s = (const U8*)SvPV_nomg_const(source, len);
3734 SvUPGRADE(dest, SVt_PV);
3735 d = (U8*)SvGROW(dest, min);
3736 (void)SvPOK_only(dest);
3741 /* Overloaded values may have toggled the UTF-8 flag on source, so we need
3742 to check DO_UTF8 again here. */
3744 if (DO_UTF8(source)) {
3745 const U8 *const send = s + len;
3746 U8 tmpbuf[UTF8_MAXBYTES_CASE+1];
3749 const STRLEN u = UTF8SKIP(s);
3751 const UV uv = toLOWER_utf8(s, tmpbuf, &ulen);
3753 #define GREEK_CAPITAL_LETTER_SIGMA 0x03A3 /* Unicode U+03A3 */
3754 if (uv == GREEK_CAPITAL_LETTER_SIGMA) {
3757 * Now if the sigma is NOT followed by
3758 * /$ignorable_sequence$cased_letter/;
3759 * and it IS preceded by /$cased_letter$ignorable_sequence/;
3760 * where $ignorable_sequence is [\x{2010}\x{AD}\p{Mn}]*
3761 * and $cased_letter is [\p{Ll}\p{Lo}\p{Lt}]
3762 * then it should be mapped to 0x03C2,
3763 * (GREEK SMALL LETTER FINAL SIGMA),
3764 * instead of staying 0x03A3.
3765 * "should be": in other words, this is not implemented yet.
3766 * See lib/unicore/SpecialCasing.txt.
3769 if (ulen > u && (SvLEN(dest) < (min += ulen - u))) {
3770 /* If the eventually required minimum size outgrows
3771 * the available space, we need to grow. */
3772 const UV o = d - (U8*)SvPVX_const(dest);
3774 /* If someone lowercases one million U+0130s we SvGROW() one
3775 * million times. Or we could try guessing how much to
3776 allocate without allocating too much. Such is life. */
3778 d = (U8*)SvPVX(dest) + o;
3780 Copy(tmpbuf, d, ulen, U8);
3786 SvCUR_set(dest, d - (U8*)SvPVX_const(dest));
3789 const U8 *const send = s + len;
3790 if (IN_LOCALE_RUNTIME) {
3793 for (; s < send; d++, s++)
3794 *d = toLOWER_LC(*s);
3797 for (; s < send; d++, s++)
3801 if (source != dest) {
3803 SvCUR_set(dest, d - (U8*)SvPVX_const(dest));
3813 SV * const sv = TOPs;
3815 register const char *s = SvPV_const(sv,len);
3817 SvUTF8_off(TARG); /* decontaminate */
3820 SvUPGRADE(TARG, SVt_PV);
3821 SvGROW(TARG, (len * 2) + 1);
3825 if (UTF8_IS_CONTINUED(*s)) {
3826 STRLEN ulen = UTF8SKIP(s);
3850 SvCUR_set(TARG, d - SvPVX_const(TARG));
3851 (void)SvPOK_only_UTF8(TARG);
3854 sv_setpvn(TARG, s, len);
3856 if (SvSMAGICAL(TARG))
3865 dVAR; dSP; dMARK; dORIGMARK;
3866 register AV* const av = (AV*)POPs;
3867 register const I32 lval = (PL_op->op_flags & OPf_MOD || LVRET);
3869 if (SvTYPE(av) == SVt_PVAV) {
3870 const I32 arybase = CopARYBASE_get(PL_curcop);
3871 if (lval && PL_op->op_private & OPpLVAL_INTRO) {
3874 for (svp = MARK + 1; svp <= SP; svp++) {
3875 const I32 elem = SvIV(*svp);
3879 if (max > AvMAX(av))
3882 while (++MARK <= SP) {
3884 I32 elem = SvIV(*MARK);
3888 svp = av_fetch(av, elem, lval);
3890 if (!svp || *svp == &PL_sv_undef)
3891 DIE(aTHX_ PL_no_aelem, elem);
3892 if (PL_op->op_private & OPpLVAL_INTRO)
3893 save_aelem(av, elem, svp);
3895 *MARK = svp ? *svp : &PL_sv_undef;
3898 if (GIMME != G_ARRAY) {
3900 *++MARK = SP > ORIGMARK ? *SP : &PL_sv_undef;
3906 /* Associative arrays. */
3912 HV * hash = (HV*)POPs;
3914 const I32 gimme = GIMME_V;
3917 /* might clobber stack_sp */
3918 entry = hv_iternext(hash);
3923 SV* const sv = hv_iterkeysv(entry);
3924 PUSHs(sv); /* won't clobber stack_sp */
3925 if (gimme == G_ARRAY) {
3928 /* might clobber stack_sp */
3929 val = hv_iterval(hash, entry);
3934 else if (gimme == G_SCALAR)
3944 const I32 gimme = GIMME_V;
3945 const I32 discard = (gimme == G_VOID) ? G_DISCARD : 0;
3947 if (PL_op->op_private & OPpSLICE) {
3949 HV * const hv = (HV*)POPs;
3950 const U32 hvtype = SvTYPE(hv);
3951 if (hvtype == SVt_PVHV) { /* hash element */
3952 while (++MARK <= SP) {
3953 SV * const sv = hv_delete_ent(hv, *MARK, discard, 0);
3954 *MARK = sv ? sv : &PL_sv_undef;
3957 else if (hvtype == SVt_PVAV) { /* array element */
3958 if (PL_op->op_flags & OPf_SPECIAL) {
3959 while (++MARK <= SP) {
3960 SV * const sv = av_delete((AV*)hv, SvIV(*MARK), discard);
3961 *MARK = sv ? sv : &PL_sv_undef;
3966 DIE(aTHX_ "Not a HASH reference");
3969 else if (gimme == G_SCALAR) {
3974 *++MARK = &PL_sv_undef;
3980 HV * const hv = (HV*)POPs;
3982 if (SvTYPE(hv) == SVt_PVHV)
3983 sv = hv_delete_ent(hv, keysv, discard, 0);
3984 else if (SvTYPE(hv) == SVt_PVAV) {
3985 if (PL_op->op_flags & OPf_SPECIAL)
3986 sv = av_delete((AV*)hv, SvIV(keysv), discard);
3988 DIE(aTHX_ "panic: avhv_delete no longer supported");
3991 DIE(aTHX_ "Not a HASH reference");
4007 if (PL_op->op_private & OPpEXISTS_SUB) {
4009 SV * const sv = POPs;
4010 CV * const cv = sv_2cv(sv, &hv, &gv, 0);
4013 if (gv && isGV(gv) && GvCV(gv) && !GvCVGEN(gv))
4019 if (SvTYPE(hv) == SVt_PVHV) {
4020 if (hv_exists_ent(hv, tmpsv, 0))
4023 else if (SvTYPE(hv) == SVt_PVAV) {
4024 if (PL_op->op_flags & OPf_SPECIAL) { /* array element */
4025 if (av_exists((AV*)hv, SvIV(tmpsv)))
4030 DIE(aTHX_ "Not a HASH reference");
4037 dVAR; dSP; dMARK; dORIGMARK;
4038 register HV * const hv = (HV*)POPs;
4039 register const I32 lval = (PL_op->op_flags & OPf_MOD || LVRET);
4040 const bool localizing = PL_op->op_private & OPpLVAL_INTRO;
4041 bool other_magic = FALSE;
4047 other_magic = mg_find((SV*)hv, PERL_MAGIC_env) ||
4048 ((mg = mg_find((SV*)hv, PERL_MAGIC_tied))
4049 /* Try to preserve the existenceness of a tied hash
4050 * element by using EXISTS and DELETE if possible.
4051 * Fallback to FETCH and STORE otherwise */
4052 && (stash = SvSTASH(SvRV(SvTIED_obj((SV*)hv, mg))))
4053 && gv_fetchmethod_autoload(stash, "EXISTS", TRUE)
4054 && gv_fetchmethod_autoload(stash, "DELETE", TRUE));
4057 while (++MARK <= SP) {
4058 SV * const keysv = *MARK;
4061 bool preeminent = FALSE;
4064 preeminent = SvRMAGICAL(hv) && !other_magic ? 1 :
4065 hv_exists_ent(hv, keysv, 0);
4068 he = hv_fetch_ent(hv, keysv, lval, 0);
4069 svp = he ? &HeVAL(he) : 0;
4072 if (!svp || *svp == &PL_sv_undef) {
4073 DIE(aTHX_ PL_no_helem_sv, SVfARG(keysv));
4076 if (HvNAME_get(hv) && isGV(*svp))
4077 save_gp((GV*)*svp, !(PL_op->op_flags & OPf_SPECIAL));
4080 save_helem(hv, keysv, svp);
4083 const char * const key = SvPV_const(keysv, keylen);
4084 SAVEDELETE(hv, savepvn(key,keylen),
4085 SvUTF8(keysv) ? -(I32)keylen : (I32)keylen);
4090 *MARK = svp ? *svp : &PL_sv_undef;
4092 if (GIMME != G_ARRAY) {
4094 *++MARK = SP > ORIGMARK ? *SP : &PL_sv_undef;
4100 /* List operators. */
4105 if (GIMME != G_ARRAY) {
4107 *MARK = *SP; /* unwanted list, return last item */
4109 *MARK = &PL_sv_undef;
4119 SV ** const lastrelem = PL_stack_sp;
4120 SV ** const lastlelem = PL_stack_base + POPMARK;
4121 SV ** const firstlelem = PL_stack_base + POPMARK + 1;
4122 register SV ** const firstrelem = lastlelem + 1;
4123 const I32 arybase = CopARYBASE_get(PL_curcop);
4124 I32 is_something_there = FALSE;
4126 register const I32 max = lastrelem - lastlelem;
4127 register SV **lelem;
4129 if (GIMME != G_ARRAY) {
4130 I32 ix = SvIV(*lastlelem);
4135 if (ix < 0 || ix >= max)
4136 *firstlelem = &PL_sv_undef;
4138 *firstlelem = firstrelem[ix];
4144 SP = firstlelem - 1;
4148 for (lelem = firstlelem; lelem <= lastlelem; lelem++) {
4149 I32 ix = SvIV(*lelem);
4154 if (ix < 0 || ix >= max)
4155 *lelem = &PL_sv_undef;
4157 is_something_there = TRUE;
4158 if (!(*lelem = firstrelem[ix]))
4159 *lelem = &PL_sv_undef;
4162 if (is_something_there)
4165 SP = firstlelem - 1;
4171 dVAR; dSP; dMARK; dORIGMARK;
4172 const I32 items = SP - MARK;
4173 SV * const av = (SV *) av_make(items, MARK+1);
4174 SP = ORIGMARK; /* av_make() might realloc stack_sp */
4175 XPUSHs(sv_2mortal((PL_op->op_flags & OPf_SPECIAL)
4176 ? newRV_noinc(av) : av));
4182 dVAR; dSP; dMARK; dORIGMARK;
4183 HV* const hv = newHV();
4186 SV * const key = *++MARK;
4187 SV * const val = newSV(0);
4189 sv_setsv(val, *++MARK);
4190 else if (ckWARN(WARN_MISC))
4191 Perl_warner(aTHX_ packWARN(WARN_MISC), "Odd number of elements in anonymous hash");
4192 (void)hv_store_ent(hv,key,val,0);
4195 XPUSHs(sv_2mortal((PL_op->op_flags & OPf_SPECIAL)
4196 ? newRV_noinc((SV*) hv) : (SV*)hv));
4202 dVAR; dSP; dMARK; dORIGMARK;
4203 register AV *ary = (AV*)*++MARK;
4207 register I32 offset;
4208 register I32 length;
4212 const MAGIC * const mg = SvTIED_mg((SV*)ary, PERL_MAGIC_tied);
4215 *MARK-- = SvTIED_obj((SV*)ary, mg);
4219 call_method("SPLICE",GIMME_V);
4228 offset = i = SvIV(*MARK);
4230 offset += AvFILLp(ary) + 1;
4232 offset -= CopARYBASE_get(PL_curcop);
4234 DIE(aTHX_ PL_no_aelem, i);
4236 length = SvIVx(*MARK++);
4238 length += AvFILLp(ary) - offset + 1;
4244 length = AvMAX(ary) + 1; /* close enough to infinity */
4248 length = AvMAX(ary) + 1;
4250 if (offset > AvFILLp(ary) + 1) {
4251 if (ckWARN(WARN_MISC))
4252 Perl_warner(aTHX_ packWARN(WARN_MISC), "splice() offset past end of array" );
4253 offset = AvFILLp(ary) + 1;
4255 after = AvFILLp(ary) + 1 - (offset + length);
4256 if (after < 0) { /* not that much array */
4257 length += after; /* offset+length now in array */
4263 /* At this point, MARK .. SP-1 is our new LIST */
4266 diff = newlen - length;
4267 if (newlen && !AvREAL(ary) && AvREIFY(ary))
4270 /* make new elements SVs now: avoid problems if they're from the array */
4271 for (dst = MARK, i = newlen; i; i--) {
4272 SV * const h = *dst;
4273 *dst++ = newSVsv(h);
4276 if (diff < 0) { /* shrinking the area */
4277 SV **tmparyval = NULL;
4279 Newx(tmparyval, newlen, SV*); /* so remember insertion */
4280 Copy(MARK, tmparyval, newlen, SV*);
4283 MARK = ORIGMARK + 1;
4284 if (GIMME == G_ARRAY) { /* copy return vals to stack */
4285 MEXTEND(MARK, length);
4286 Copy(AvARRAY(ary)+offset, MARK, length, SV*);
4288 EXTEND_MORTAL(length);
4289 for (i = length, dst = MARK; i; i--) {
4290 sv_2mortal(*dst); /* free them eventualy */
4297 *MARK = AvARRAY(ary)[offset+length-1];
4300 for (i = length - 1, dst = &AvARRAY(ary)[offset]; i > 0; i--)
4301 SvREFCNT_dec(*dst++); /* free them now */
4304 AvFILLp(ary) += diff;
4306 /* pull up or down? */
4308 if (offset < after) { /* easier to pull up */
4309 if (offset) { /* esp. if nothing to pull */
4310 src = &AvARRAY(ary)[offset-1];
4311 dst = src - diff; /* diff is negative */
4312 for (i = offset; i > 0; i--) /* can't trust Copy */
4316 AvARRAY(ary) = AvARRAY(ary) - diff; /* diff is negative */
4320 if (after) { /* anything to pull down? */
4321 src = AvARRAY(ary) + offset + length;
4322 dst = src + diff; /* diff is negative */
4323 Move(src, dst, after, SV*);
4325 dst = &AvARRAY(ary)[AvFILLp(ary)+1];
4326 /* avoid later double free */
4330 dst[--i] = &PL_sv_undef;
4333 Copy( tmparyval, AvARRAY(ary) + offset, newlen, SV* );
4334 Safefree(tmparyval);
4337 else { /* no, expanding (or same) */
4338 SV** tmparyval = NULL;
4340 Newx(tmparyval, length, SV*); /* so remember deletion */
4341 Copy(AvARRAY(ary)+offset, tmparyval, length, SV*);
4344 if (diff > 0) { /* expanding */
4345 /* push up or down? */
4346 if (offset < after && diff <= AvARRAY(ary) - AvALLOC(ary)) {
4350 Move(src, dst, offset, SV*);
4352 AvARRAY(ary) = AvARRAY(ary) - diff;/* diff is positive */
4354 AvFILLp(ary) += diff;
4357 if (AvFILLp(ary) + diff >= AvMAX(ary)) /* oh, well */
4358 av_extend(ary, AvFILLp(ary) + diff);
4359 AvFILLp(ary) += diff;
4362 dst = AvARRAY(ary) + AvFILLp(ary);
4364 for (i = after; i; i--) {
4372 Copy( MARK, AvARRAY(ary) + offset, newlen, SV* );
4375 MARK = ORIGMARK + 1;
4376 if (GIMME == G_ARRAY) { /* copy return vals to stack */
4378 Copy(tmparyval, MARK, length, SV*);
4380 EXTEND_MORTAL(length);
4381 for (i = length, dst = MARK; i; i--) {
4382 sv_2mortal(*dst); /* free them eventualy */
4389 else if (length--) {
4390 *MARK = tmparyval[length];
4393 while (length-- > 0)
4394 SvREFCNT_dec(tmparyval[length]);
4398 *MARK = &PL_sv_undef;
4399 Safefree(tmparyval);
4407 dVAR; dSP; dMARK; dORIGMARK; dTARGET;
4408 register AV * const ary = (AV*)*++MARK;
4409 const MAGIC * const mg = SvTIED_mg((SV*)ary, PERL_MAGIC_tied);
4412 *MARK-- = SvTIED_obj((SV*)ary, mg);
4416 call_method("PUSH",G_SCALAR|G_DISCARD);
4420 PUSHi( AvFILL(ary) + 1 );
4423 for (++MARK; MARK <= SP; MARK++) {
4424 SV * const sv = newSV(0);
4426 sv_setsv(sv, *MARK);
4427 av_store(ary, AvFILLp(ary)+1, sv);
4430 PUSHi( AvFILLp(ary) + 1 );
4439 AV * const av = (AV*)POPs;
4440 SV * const sv = PL_op->op_type == OP_SHIFT ? av_shift(av) : av_pop(av);
4444 (void)sv_2mortal(sv);
4451 dVAR; dSP; dMARK; dORIGMARK; dTARGET;
4452 register AV *ary = (AV*)*++MARK;
4453 const MAGIC * const mg = SvTIED_mg((SV*)ary, PERL_MAGIC_tied);
4456 *MARK-- = SvTIED_obj((SV*)ary, mg);
4460 call_method("UNSHIFT",G_SCALAR|G_DISCARD);
4466 av_unshift(ary, SP - MARK);
4468 SV * const sv = newSVsv(*++MARK);
4469 (void)av_store(ary, i++, sv);
4473 PUSHi( AvFILL(ary) + 1 );
4480 SV ** const oldsp = SP;
4482 if (GIMME == G_ARRAY) {
4485 register SV * const tmp = *MARK;
4489 /* safe as long as stack cannot get extended in the above */
4494 register char *down;
4498 PADOFFSET padoff_du;
4500 SvUTF8_off(TARG); /* decontaminate */
4502 do_join(TARG, &PL_sv_no, MARK, SP);
4504 sv_setsv(TARG, (SP > MARK)
4506 : (padoff_du = find_rundefsvoffset(),
4507 (padoff_du == NOT_IN_PAD
4508 || PAD_COMPNAME_FLAGS_isOUR(padoff_du))
4509 ? DEFSV : PAD_SVl(padoff_du)));
4510 up = SvPV_force(TARG, len);
4512 if (DO_UTF8(TARG)) { /* first reverse each character */
4513 U8* s = (U8*)SvPVX(TARG);
4514 const U8* send = (U8*)(s + len);
4516 if (UTF8_IS_INVARIANT(*s)) {
4521 if (!utf8_to_uvchr(s, 0))
4525 down = (char*)(s - 1);
4526 /* reverse this character */
4530 *down-- = (char)tmp;
4536 down = SvPVX(TARG) + len - 1;
4540 *down-- = (char)tmp;
4542 (void)SvPOK_only_UTF8(TARG);
4554 register IV limit = POPi; /* note, negative is forever */
4555 SV * const sv = POPs;
4557 register const char *s = SvPV_const(sv, len);
4558 const bool do_utf8 = DO_UTF8(sv);
4559 const char *strend = s + len;
4561 register REGEXP *rx;
4563 register const char *m;
4565 const STRLEN slen = do_utf8 ? utf8_length((U8*)s, (U8*)strend) : (STRLEN)(strend - s);
4566 I32 maxiters = slen + 10;
4568 const I32 origlimit = limit;
4571 const I32 gimme = GIMME_V;
4572 const I32 oldsave = PL_savestack_ix;
4573 I32 make_mortal = 1;
4578 Copy(&LvTARGOFF(POPs), &pm, 1, PMOP*);
4583 DIE(aTHX_ "panic: pp_split");
4586 TAINT_IF((rx->extflags & RXf_PMf_LOCALE) &&
4587 (rx->extflags & (RXf_WHITE | RXf_SKIPWHITE)));
4589 RX_MATCH_UTF8_set(rx, do_utf8);
4592 if (pm->op_pmreplrootu.op_pmtargetoff) {
4593 ary = GvAVn((GV*)PAD_SVl(pm->op_pmreplrootu.op_pmtargetoff));
4596 if (pm->op_pmreplrootu.op_pmtargetgv) {
4597 ary = GvAVn(pm->op_pmreplrootu.op_pmtargetgv);
4600 else if (gimme != G_ARRAY)
4601 ary = GvAVn(PL_defgv);
4604 if (ary && (gimme != G_ARRAY || (pm->op_pmflags & PMf_ONCE))) {
4610 if ((mg = SvTIED_mg((SV*)ary, PERL_MAGIC_tied))) {
4612 XPUSHs(SvTIED_obj((SV*)ary, mg));
4619 for (i = AvFILLp(ary); i >= 0; i--)
4620 AvARRAY(ary)[i] = &PL_sv_undef; /* don't free mere refs */
4622 /* temporarily switch stacks */
4623 SAVESWITCHSTACK(PL_curstack, ary);
4627 base = SP - PL_stack_base;
4629 if (rx->extflags & RXf_SKIPWHITE) {
4631 while (*s == ' ' || is_utf8_space((U8*)s))
4634 else if (rx->extflags & RXf_PMf_LOCALE) {
4635 while (isSPACE_LC(*s))
4643 if (rx->extflags & PMf_MULTILINE) {
4648 limit = maxiters + 2;
4649 if (rx->extflags & RXf_WHITE) {
4652 /* this one uses 'm' and is a negative test */
4654 while (m < strend && !( *m == ' ' || is_utf8_space((U8*)m) )) {
4655 const int t = UTF8SKIP(m);
4656 /* is_utf8_space returns FALSE for malform utf8 */
4662 } else if (rx->extflags & RXf_PMf_LOCALE) {
4663 while (m < strend && !isSPACE_LC(*m))
4666 while (m < strend && !isSPACE(*m))
4672 dstr = newSVpvn(s, m-s);
4676 (void)SvUTF8_on(dstr);
4679 /* skip the whitespace found last */
4681 s = m + UTF8SKIP(m);
4685 /* this one uses 's' and is a positive test */
4687 while (s < strend && ( *s == ' ' || is_utf8_space((U8*)s) ))
4689 } else if (rx->extflags & RXf_PMf_LOCALE) {
4690 while (s < strend && isSPACE_LC(*s))
4693 while (s < strend && isSPACE(*s))
4698 else if (rx->extflags & RXf_START_ONLY) {
4700 for (m = s; m < strend && *m != '\n'; m++)
4705 dstr = newSVpvn(s, m-s);
4709 (void)SvUTF8_on(dstr);
4714 else if (do_utf8 == ((rx->extflags & RXf_UTF8) != 0) &&
4715 (rx->extflags & RXf_USE_INTUIT) && !rx->nparens
4716 && (rx->extflags & RXf_CHECK_ALL)
4717 && !(rx->extflags & RXf_ANCH)) {
4718 const int tail = (rx->extflags & RXf_INTUIT_TAIL);
4719 SV * const csv = CALLREG_INTUIT_STRING(rx);
4721 len = rx->minlenret;
4722 if (len == 1 && !(rx->extflags & RXf_UTF8) && !tail) {
4723 const char c = *SvPV_nolen_const(csv);
4725 for (m = s; m < strend && *m != c; m++)
4729 dstr = newSVpvn(s, m-s);
4733 (void)SvUTF8_on(dstr);
4735 /* The rx->minlen is in characters but we want to step
4736 * s ahead by bytes. */
4738 s = (char*)utf8_hop((U8*)m, len);
4740 s = m + len; /* Fake \n at the end */
4744 while (s < strend && --limit &&
4745 (m = fbm_instr((unsigned char*)s, (unsigned char*)strend,
4746 csv, multiline ? FBMrf_MULTILINE : 0)) )
4748 dstr = newSVpvn(s, m-s);
4752 (void)SvUTF8_on(dstr);
4754 /* The rx->minlen is in characters but we want to step
4755 * s ahead by bytes. */
4757 s = (char*)utf8_hop((U8*)m, len);
4759 s = m + len; /* Fake \n at the end */
4764 maxiters += slen * rx->nparens;
4765 while (s < strend && --limit)
4769 rex_return = CALLREGEXEC(rx, (char*)s, (char*)strend, (char*)orig, 1 ,
4772 if (rex_return == 0)
4774 TAINT_IF(RX_MATCH_TAINTED(rx));
4775 if (RX_MATCH_COPIED(rx) && rx->subbeg != orig) {
4780 strend = s + (strend - m);
4782 m = rx->offs[0].start + orig;
4783 dstr = newSVpvn(s, m-s);
4787 (void)SvUTF8_on(dstr);
4791 for (i = 1; i <= (I32)rx->nparens; i++) {
4792 s = rx->offs[i].start + orig;
4793 m = rx->offs[i].end + orig;
4795 /* japhy (07/27/01) -- the (m && s) test doesn't catch
4796 parens that didn't match -- they should be set to
4797 undef, not the empty string */
4798 if (m >= orig && s >= orig) {
4799 dstr = newSVpvn(s, m-s);
4802 dstr = &PL_sv_undef; /* undef, not "" */
4806 (void)SvUTF8_on(dstr);
4810 s = rx->offs[0].end + orig;
4814 iters = (SP - PL_stack_base) - base;
4815 if (iters > maxiters)
4816 DIE(aTHX_ "Split loop");
4818 /* keep field after final delim? */
4819 if (s < strend || (iters && origlimit)) {
4820 const STRLEN l = strend - s;
4821 dstr = newSVpvn(s, l);
4825 (void)SvUTF8_on(dstr);
4829 else if (!origlimit) {
4830 while (iters > 0 && (!TOPs || !SvANY(TOPs) || SvCUR(TOPs) == 0)) {
4831 if (TOPs && !make_mortal)
4834 *SP-- = &PL_sv_undef;
4839 LEAVE_SCOPE(oldsave); /* may undo an earlier SWITCHSTACK */
4843 if (SvSMAGICAL(ary)) {
4848 if (gimme == G_ARRAY) {
4850 Copy(AvARRAY(ary), SP + 1, iters, SV*);
4858 call_method("PUSH",G_SCALAR|G_DISCARD);
4861 if (gimme == G_ARRAY) {
4863 /* EXTEND should not be needed - we just popped them */
4865 for (i=0; i < iters; i++) {
4866 SV **svp = av_fetch(ary, i, FALSE);
4867 PUSHs((svp) ? *svp : &PL_sv_undef);
4874 if (gimme == G_ARRAY)
4890 if (SvTYPE(retsv) == SVt_PVAV || SvTYPE(retsv) == SVt_PVHV
4891 || SvTYPE(retsv) == SVt_PVCV) {
4892 retsv = refto(retsv);
4899 PP(unimplemented_op)
4902 DIE(aTHX_ "panic: unimplemented op %s (#%d) called", OP_NAME(PL_op),
4908 * c-indentation-style: bsd
4910 * indent-tabs-mode: t
4913 * ex: set ts=8 sts=4 sw=4 noet: