3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 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 * "'So that was the job I felt I had to do when I started,' thought Sam."
16 #define PERL_IN_DOOP_C
20 #if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX)
26 S_do_trans_simple(pTHX_ SV *sv)
33 I32 grows = PL_op->op_private & OPpTRANS_GROWS;
38 tbl = (short*)cPVOP->op_pv;
40 Perl_croak(aTHX_ "panic: do_trans_simple line %d",__LINE__);
42 s = (U8*)SvPV(sv, len);
45 /* First, take care of non-UTF8 input strings, because they're easy */
48 if ((ch = tbl[*s]) >= 0) {
59 /* Allow for expansion: $_="a".chr(400); tr/a/\xFE/, FE needs encoding */
61 New(0, d, len*2+1, U8);
69 /* Need to check this, otherwise 128..255 won't match */
70 c = utf8n_to_uvchr(s, send - s, &ulen, 0);
71 if (c < 0x100 && (ch = tbl[c]) >= 0) {
73 d = uvchr_to_utf8(d, ch);
76 else { /* No match -> copy */
83 sv_setpvn(sv, (char*)dstart, d - dstart);
88 SvCUR_set(sv, d - dstart);
96 S_do_trans_count(pTHX_ SV *sv)
103 I32 complement = PL_op->op_private & OPpTRANS_COMPLEMENT;
105 tbl = (short*)cPVOP->op_pv;
107 Perl_croak(aTHX_ "panic: do_trans_count line %d",__LINE__);
109 s = (U8*)SvPV(sv, len);
121 c = utf8n_to_uvchr(s, send - s, &ulen, 0);
125 } else if (complement)
134 S_do_trans_complex(pTHX_ SV *sv)
142 I32 grows = PL_op->op_private & OPpTRANS_GROWS;
143 I32 complement = PL_op->op_private & OPpTRANS_COMPLEMENT;
144 I32 del = PL_op->op_private & OPpTRANS_DELETE;
145 STRLEN len, rlen = 0;
149 tbl = (short*)cPVOP->op_pv;
151 Perl_croak(aTHX_ "panic: do_trans_complex line %d",__LINE__);
153 s = (U8*)SvPV(sv, len);
159 if (PL_op->op_private & OPpTRANS_SQUASH) {
162 if ((ch = tbl[*s]) >= 0) {
165 if (p != d - 1 || *p != *d)
168 else if (ch == -1) /* -1 is unmapped character */
170 else if (ch == -2) /* -2 is delete character */
177 if ((ch = tbl[*s]) >= 0) {
181 else if (ch == -1) /* -1 is unmapped character */
183 else if (ch == -2) /* -2 is delete character */
189 SvCUR_set(sv, d - dstart);
193 New(0, d, len*2+1, U8);
197 if (complement && !del)
200 #ifdef MACOS_TRADITIONAL
201 #define comp CoMP /* "comp" is a keyword in some compilers ... */
204 if (PL_op->op_private & OPpTRANS_SQUASH) {
208 UV comp = utf8_to_uvchr(s, &len);
218 ch = (rlen == 0) ? comp :
219 (comp - 0x100 < rlen) ?
220 tbl[comp+1] : tbl[0x100+rlen];
222 d = uvchr_to_utf8(d, ch);
230 else if ((ch = tbl[comp]) >= 0) {
233 d = uvchr_to_utf8(d, ch);
239 else if (ch == -1) { /* -1 is unmapped character */
243 else if (ch == -2) /* -2 is delete character */
252 UV comp = utf8_to_uvchr(s, &len);
261 if (comp - 0x100 < rlen)
262 d = uvchr_to_utf8(d, tbl[comp+1]);
264 d = uvchr_to_utf8(d, tbl[0x100+rlen]);
268 else if ((ch = tbl[comp]) >= 0) {
269 d = uvchr_to_utf8(d, ch);
272 else if (ch == -1) { /* -1 is unmapped character */
276 else if (ch == -2) /* -2 is delete character */
282 sv_setpvn(sv, (char*)dstart, d - dstart);
287 SvCUR_set(sv, d - dstart);
296 S_do_trans_simple_utf8(pTHX_ SV *sv)
304 I32 grows = PL_op->op_private & OPpTRANS_GROWS;
307 SV* rv = (SV*)cSVOP->op_sv;
308 HV* hv = (HV*)SvRV(rv);
309 SV** svp = hv_fetch(hv, "NONE", 4, FALSE);
310 UV none = svp ? SvUV(*svp) : 0x7fffffff;
317 s = (U8*)SvPV(sv, len);
320 U8 *t = s, *e = s + len;
323 if ((hibit = !NATIVE_IS_INVARIANT(ch)))
327 s = bytes_to_utf8(s, &len);
332 svp = hv_fetch(hv, "FINAL", 5, FALSE);
337 /* d needs to be bigger than s, in case e.g. upgrading is required */
338 New(0, d, len*3+UTF8_MAXLEN, U8);
348 if ((uv = swash_fetch(rv, s, TRUE)) < none) {
351 d = uvuni_to_utf8(d, uv);
353 else if (uv == none) {
359 else if (uv == extra) {
363 d = uvuni_to_utf8(d, final);
369 STRLEN clen = d - dstart;
370 STRLEN nlen = dend - dstart + len + UTF8_MAXLEN;
372 Perl_croak(aTHX_ "panic: do_trans_simple_utf8 line %d",__LINE__);
373 Renew(dstart, nlen+UTF8_MAXLEN, U8);
375 dend = dstart + nlen;
378 if (grows || hibit) {
379 sv_setpvn(sv, (char*)dstart, d - dstart);
386 SvCUR_set(sv, d - dstart);
395 S_do_trans_count_utf8(pTHX_ SV *sv)
398 U8 *start = 0, *send;
402 SV* rv = (SV*)cSVOP->op_sv;
403 HV* hv = (HV*)SvRV(rv);
404 SV** svp = hv_fetch(hv, "NONE", 4, FALSE);
405 UV none = svp ? SvUV(*svp) : 0x7fffffff;
410 s = (U8*)SvPV(sv, len);
412 U8 *t = s, *e = s + len;
415 if ((hibit = !NATIVE_IS_INVARIANT(ch)))
419 start = s = bytes_to_utf8(s, &len);
424 if ((uv = swash_fetch(rv, s, TRUE)) < none || uv == extra)
435 S_do_trans_complex_utf8(pTHX_ SV *sv)
441 I32 squash = PL_op->op_private & OPpTRANS_SQUASH;
442 I32 del = PL_op->op_private & OPpTRANS_DELETE;
443 I32 grows = PL_op->op_private & OPpTRANS_GROWS;
444 SV* rv = (SV*)cSVOP->op_sv;
445 HV* hv = (HV*)SvRV(rv);
446 SV** svp = hv_fetch(hv, "NONE", 4, FALSE);
447 UV none = svp ? SvUV(*svp) : 0x7fffffff;
450 bool havefinal = FALSE;
457 s = (U8*)SvPV(sv, len);
460 U8 *t = s, *e = s + len;
463 if ((hibit = !NATIVE_IS_INVARIANT(ch)))
467 s = bytes_to_utf8(s, &len);
472 svp = hv_fetch(hv, "FINAL", 5, FALSE);
479 /* d needs to be bigger than s, in case e.g. upgrading is required */
480 New(0, d, len*3+UTF8_MAXLEN, U8);
492 uv = swash_fetch(rv, s, TRUE);
495 STRLEN clen = d - dstart;
496 STRLEN nlen = dend - dstart + len + UTF8_MAXLEN;
498 Perl_croak(aTHX_ "panic: do_trans_complex_utf8 line %d",__LINE__);
499 Renew(dstart, nlen+UTF8_MAXLEN, U8);
501 dend = dstart + nlen;
507 d = uvuni_to_utf8(d, uv);
512 else if (uv == none) { /* "none" is unmapped character */
520 else if (uv == extra && !del) {
525 d = uvuni_to_utf8(d, final);
531 uv = utf8_to_uvuni(s, &len);
541 matches++; /* "none+1" is delete character */
547 uv = swash_fetch(rv, s, TRUE);
549 STRLEN clen = d - dstart;
550 STRLEN nlen = dend - dstart + len + UTF8_MAXLEN;
552 Perl_croak(aTHX_ "panic: do_trans_complex_utf8 line %d",__LINE__);
553 Renew(dstart, nlen+UTF8_MAXLEN, U8);
555 dend = dstart + nlen;
560 d = uvuni_to_utf8(d, uv);
563 else if (uv == none) { /* "none" is unmapped character */
570 else if (uv == extra && !del) {
573 d = uvuni_to_utf8(d, final);
576 matches++; /* "none+1" is delete character */
580 if (grows || hibit) {
581 sv_setpvn(sv, (char*)dstart, d - dstart);
588 SvCUR_set(sv, d - dstart);
597 Perl_do_trans(pTHX_ SV *sv)
600 I32 hasutf = (PL_op->op_private &
601 (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF));
603 if (SvREADONLY(sv)) {
605 sv_force_normal_flags(sv, 0);
606 if (SvREADONLY(sv) && !(PL_op->op_private & OPpTRANS_IDENTICAL))
607 Perl_croak(aTHX_ PL_no_modify);
612 if (!(PL_op->op_private & OPpTRANS_IDENTICAL)) {
614 (void)SvPV_force(sv, len);
615 (void)SvPOK_only_UTF8(sv);
618 DEBUG_t( Perl_deb(aTHX_ "2.TBL\n"));
620 switch (PL_op->op_private & ~hasutf & 63) {
623 return do_trans_simple_utf8(sv);
625 return do_trans_simple(sv);
627 case OPpTRANS_IDENTICAL:
628 case OPpTRANS_IDENTICAL|OPpTRANS_COMPLEMENT:
630 return do_trans_count_utf8(sv);
632 return do_trans_count(sv);
636 return do_trans_complex_utf8(sv);
638 return do_trans_complex(sv);
643 Perl_do_join(pTHX_ register SV *sv, SV *del, register SV **mark, register SV **sp)
646 register I32 items = sp - mark;
651 (void) SvPV(del, delimlen); /* stringify and get the delimlen */
652 /* SvCUR assumes it's SvPOK() and woe betide you if it's not. */
655 len = (items > 0 ? (delimlen * (items - 1) ) : 0);
656 (void)SvUPGRADE(sv, SVt_PV);
657 if (SvLEN(sv) < len + items) { /* current length is way too short */
658 while (items-- > 0) {
659 if (*mark && !SvGAMAGIC(*mark) && SvOK(*mark)) {
665 SvGROW(sv, len + 1); /* so try to pre-extend */
673 if (PL_tainting && SvMAGICAL(sv))
683 for (; items > 0; items--,mark++) {
689 for (; items > 0; items--,mark++)
696 Perl_do_sprintf(pTHX_ SV *sv, I32 len, SV **sarg)
699 char *pat = SvPV(*sarg, patlen);
700 bool do_taint = FALSE;
705 sv_vsetpvfn(sv, pat, patlen, Null(va_list*), sarg + 1, len - 1, &do_taint);
711 /* currently converts input to bytes if possible, but doesn't sweat failure */
713 Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size)
716 unsigned char *s = (unsigned char *) SvPV(sv, srclen);
721 if (size < 1 || (size & (size-1))) /* size < 1 or not a power of two */
722 Perl_croak(aTHX_ "Illegal number of bits in vec");
725 (void) Perl_sv_utf8_downgrade(aTHX_ sv, TRUE);
727 offset *= size; /* turn into bit offset */
728 len = (offset + size + 7) / 8; /* required number of bytes */
733 offset >>= 3; /* turn into byte offset */
735 if ((STRLEN)offset >= srclen)
738 retnum = (UV) s[offset] << 8;
740 else if (size == 32) {
741 if ((STRLEN)offset >= srclen)
743 else if ((STRLEN)(offset + 1) >= srclen)
745 ((UV) s[offset ] << 24);
746 else if ((STRLEN)(offset + 2) >= srclen)
748 ((UV) s[offset ] << 24) +
749 ((UV) s[offset + 1] << 16);
752 ((UV) s[offset ] << 24) +
753 ((UV) s[offset + 1] << 16) +
754 ( s[offset + 2] << 8);
757 else if (size == 64) {
758 if (ckWARN(WARN_PORTABLE))
759 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
760 "Bit vector size > 32 non-portable");
761 if (offset >= srclen)
763 else if (offset + 1 >= srclen)
765 (UV) s[offset ] << 56;
766 else if (offset + 2 >= srclen)
768 ((UV) s[offset ] << 56) +
769 ((UV) s[offset + 1] << 48);
770 else if (offset + 3 >= srclen)
772 ((UV) s[offset ] << 56) +
773 ((UV) s[offset + 1] << 48) +
774 ((UV) s[offset + 2] << 40);
775 else if (offset + 4 >= srclen)
777 ((UV) s[offset ] << 56) +
778 ((UV) s[offset + 1] << 48) +
779 ((UV) s[offset + 2] << 40) +
780 ((UV) s[offset + 3] << 32);
781 else if (offset + 5 >= srclen)
783 ((UV) s[offset ] << 56) +
784 ((UV) s[offset + 1] << 48) +
785 ((UV) s[offset + 2] << 40) +
786 ((UV) s[offset + 3] << 32) +
787 ( s[offset + 4] << 24);
788 else if (offset + 6 >= srclen)
790 ((UV) s[offset ] << 56) +
791 ((UV) s[offset + 1] << 48) +
792 ((UV) s[offset + 2] << 40) +
793 ((UV) s[offset + 3] << 32) +
794 ((UV) s[offset + 4] << 24) +
795 ((UV) s[offset + 5] << 16);
798 ((UV) s[offset ] << 56) +
799 ((UV) s[offset + 1] << 48) +
800 ((UV) s[offset + 2] << 40) +
801 ((UV) s[offset + 3] << 32) +
802 ((UV) s[offset + 4] << 24) +
803 ((UV) s[offset + 5] << 16) +
804 ( s[offset + 6] << 8);
810 retnum = (s[offset >> 3] >> (offset & 7)) & ((1 << size) - 1);
812 offset >>= 3; /* turn into byte offset */
817 ((UV) s[offset] << 8) +
821 ((UV) s[offset ] << 24) +
822 ((UV) s[offset + 1] << 16) +
823 ( s[offset + 2] << 8) +
826 else if (size == 64) {
827 if (ckWARN(WARN_PORTABLE))
828 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
829 "Bit vector size > 32 non-portable");
831 ((UV) s[offset ] << 56) +
832 ((UV) s[offset + 1] << 48) +
833 ((UV) s[offset + 2] << 40) +
834 ((UV) s[offset + 3] << 32) +
835 ((UV) s[offset + 4] << 24) +
836 ((UV) s[offset + 5] << 16) +
837 ( s[offset + 6] << 8) +
846 /* currently converts input to bytes if possible but doesn't sweat failures,
847 * although it does ensure that the string it clobbers is not marked as
848 * utf8-valid any more
851 Perl_do_vecset(pTHX_ SV *sv)
853 SV *targ = LvTARG(sv);
856 register unsigned char *s;
864 s = (unsigned char*)SvPV_force(targ, targlen);
866 /* This is handled by the SvPOK_only below...
867 if (!Perl_sv_utf8_downgrade(aTHX_ targ, TRUE))
870 (void) Perl_sv_utf8_downgrade(aTHX_ targ, TRUE);
873 (void)SvPOK_only(targ);
875 offset = LvTARGOFF(sv);
877 Perl_croak(aTHX_ "Negative offset to vec in lvalue context");
878 size = LvTARGLEN(sv);
879 if (size < 1 || (size & (size-1))) /* size < 1 or not a power of two */
880 Perl_croak(aTHX_ "Illegal number of bits in vec");
882 offset *= size; /* turn into bit offset */
883 len = (offset + size + 7) / 8; /* required number of bytes */
885 s = (unsigned char*)SvGROW(targ, len + 1);
886 (void)memzero((char *)(s + targlen), len - targlen + 1);
887 SvCUR_set(targ, len);
891 mask = (1 << size) - 1;
894 offset >>= 3; /* turn into byte offset */
895 s[offset] &= ~(mask << size);
896 s[offset] |= lval << size;
899 offset >>= 3; /* turn into byte offset */
901 s[offset ] = (U8)( lval & 0xff);
902 else if (size == 16) {
903 s[offset ] = (U8)((lval >> 8) & 0xff);
904 s[offset+1] = (U8)( lval & 0xff);
906 else if (size == 32) {
907 s[offset ] = (U8)((lval >> 24) & 0xff);
908 s[offset+1] = (U8)((lval >> 16) & 0xff);
909 s[offset+2] = (U8)((lval >> 8) & 0xff);
910 s[offset+3] = (U8)( lval & 0xff);
913 else if (size == 64) {
914 if (ckWARN(WARN_PORTABLE))
915 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
916 "Bit vector size > 32 non-portable");
917 s[offset ] = (U8)((lval >> 56) & 0xff);
918 s[offset+1] = (U8)((lval >> 48) & 0xff);
919 s[offset+2] = (U8)((lval >> 40) & 0xff);
920 s[offset+3] = (U8)((lval >> 32) & 0xff);
921 s[offset+4] = (U8)((lval >> 24) & 0xff);
922 s[offset+5] = (U8)((lval >> 16) & 0xff);
923 s[offset+6] = (U8)((lval >> 8) & 0xff);
924 s[offset+7] = (U8)( lval & 0xff);
932 Perl_do_chop(pTHX_ register SV *astr, register SV *sv)
937 if (SvTYPE(sv) == SVt_PVAV) {
942 for (i = 0; i <= max; i++) {
943 sv = (SV*)av_fetch(av, i, FALSE);
944 if (sv && ((sv = *(SV**)sv), sv != &PL_sv_undef))
949 else if (SvTYPE(sv) == SVt_PVHV) {
952 (void)hv_iterinit(hv);
954 while ((entry = hv_iternext(hv)))
955 do_chop(astr,hv_iterval(hv,entry));
958 else if (SvREADONLY(sv)) {
960 /* SV is copy-on-write */
961 sv_force_normal_flags(sv, 0);
964 Perl_croak(aTHX_ PL_no_modify);
967 if (len && !SvPOK(sv))
968 s = SvPV_force(sv, len);
971 char *send = s + len;
974 while (s > start && UTF8_IS_CONTINUATION(*s))
976 if (utf8_to_uvchr((U8*)s, 0)) {
977 sv_setpvn(astr, s, send - s);
979 SvCUR_set(sv, s - start);
985 sv_setpvn(astr, "", 0);
989 sv_setpvn(astr, s, 1);
996 sv_setpvn(astr, "", 0);
1001 Perl_do_chomp(pTHX_ register SV *sv)
1010 if (RsRECORD(PL_rs))
1013 if (SvTYPE(sv) == SVt_PVAV) {
1018 for (i = 0; i <= max; i++) {
1019 sv = (SV*)av_fetch(av, i, FALSE);
1020 if (sv && ((sv = *(SV**)sv), sv != &PL_sv_undef))
1021 count += do_chomp(sv);
1025 else if (SvTYPE(sv) == SVt_PVHV) {
1028 (void)hv_iterinit(hv);
1030 while ((entry = hv_iternext(hv)))
1031 count += do_chomp(hv_iterval(hv,entry));
1034 else if (SvREADONLY(sv)) {
1036 /* SV is copy-on-write */
1037 sv_force_normal_flags(sv, 0);
1040 Perl_croak(aTHX_ PL_no_modify);
1045 if (RsPARA(PL_rs)) {
1049 while (len && s[-1] == '\n') {
1057 char *rsptr = SvPV(PL_rs, rslen);
1064 if (len < rslen - 1)
1068 if (memNE(s, rsptr, rslen))
1073 s = SvPV_force(sv, n_a);
1084 Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
1100 bool left_utf = DO_UTF8(left);
1101 bool right_utf = DO_UTF8(right);
1104 if (left_utf && !right_utf)
1105 sv_utf8_upgrade(right);
1106 else if (!left_utf && right_utf)
1107 sv_utf8_upgrade(left);
1109 if (sv != left || (optype != OP_BIT_AND && !SvOK(sv) && !SvGMAGICAL(sv)))
1110 sv_setpvn(sv, "", 0); /* avoid undef warning on |= and ^= */
1111 lsave = lc = SvPV(left, leftlen);
1112 rsave = rc = SvPV(right, rightlen);
1113 len = leftlen < rightlen ? leftlen : rightlen;
1115 if ((left_utf || right_utf) && (sv == left || sv == right)) {
1116 needlen = optype == OP_BIT_AND ? len : leftlen + rightlen;
1117 Newz(801, dc, needlen + 1, char);
1119 else if (SvOK(sv) || SvTYPE(sv) > SVt_PVMG) {
1121 dc = SvPV_force(sv, n_a);
1122 if (SvCUR(sv) < (STRLEN)len) {
1123 dc = SvGROW(sv, (STRLEN)(len + 1));
1124 (void)memzero(dc + SvCUR(sv), len - SvCUR(sv) + 1);
1126 if (optype != OP_BIT_AND && (left_utf || right_utf))
1127 dc = SvGROW(sv, leftlen + rightlen + 1);
1130 needlen = ((optype == OP_BIT_AND)
1131 ? len : (leftlen > rightlen ? leftlen : rightlen));
1132 Newz(801, dc, needlen + 1, char);
1133 (void)sv_usepvn(sv, dc, needlen);
1134 dc = SvPVX(sv); /* sv_usepvn() calls Renew() */
1137 (void)SvPOK_only(sv);
1138 if (left_utf || right_utf) {
1141 STRLEN lulen = leftlen;
1142 STRLEN rulen = rightlen;
1147 while (lulen && rulen) {
1148 luc = utf8n_to_uvchr((U8*)lc, lulen, &ulen, UTF8_ALLOW_ANYUV);
1151 ruc = utf8n_to_uvchr((U8*)rc, rulen, &ulen, UTF8_ALLOW_ANYUV);
1155 dc = (char*)uvchr_to_utf8((U8*)dc, duc);
1157 if (sv == left || sv == right)
1158 (void)sv_usepvn(sv, dcsave, needlen);
1159 SvCUR_set(sv, dc - dcsave);
1162 while (lulen && rulen) {
1163 luc = utf8n_to_uvchr((U8*)lc, lulen, &ulen, UTF8_ALLOW_ANYUV);
1166 ruc = utf8n_to_uvchr((U8*)rc, rulen, &ulen, UTF8_ALLOW_ANYUV);
1170 dc = (char*)uvchr_to_utf8((U8*)dc, duc);
1174 while (lulen && rulen) {
1175 luc = utf8n_to_uvchr((U8*)lc, lulen, &ulen, UTF8_ALLOW_ANYUV);
1178 ruc = utf8n_to_uvchr((U8*)rc, rulen, &ulen, UTF8_ALLOW_ANYUV);
1182 dc = (char*)uvchr_to_utf8((U8*)dc, duc);
1185 if (sv == left || sv == right)
1186 (void)sv_usepvn(sv, dcsave, needlen);
1187 SvCUR_set(sv, dc - dcsave);
1189 sv_catpvn(sv, rc, rulen);
1191 sv_catpvn(sv, lc, lulen);
1201 if (len >= sizeof(long)*4 &&
1202 !((long)dc % sizeof(long)) &&
1203 !((long)lc % sizeof(long)) &&
1204 !((long)rc % sizeof(long))) /* It's almost always aligned... */
1206 I32 remainder = len % (sizeof(long)*4);
1207 len /= (sizeof(long)*4);
1216 *dl++ = *ll++ & *rl++;
1217 *dl++ = *ll++ & *rl++;
1218 *dl++ = *ll++ & *rl++;
1219 *dl++ = *ll++ & *rl++;
1224 *dl++ = *ll++ ^ *rl++;
1225 *dl++ = *ll++ ^ *rl++;
1226 *dl++ = *ll++ ^ *rl++;
1227 *dl++ = *ll++ ^ *rl++;
1232 *dl++ = *ll++ | *rl++;
1233 *dl++ = *ll++ | *rl++;
1234 *dl++ = *ll++ | *rl++;
1235 *dl++ = *ll++ | *rl++;
1250 *dc++ = *lc++ & *rc++;
1254 *dc++ = *lc++ ^ *rc++;
1258 *dc++ = *lc++ | *rc++;
1261 if (rightlen > (STRLEN)len)
1262 sv_catpvn(sv, rsave + len, rightlen - len);
1263 else if (leftlen > (STRLEN)len)
1264 sv_catpvn(sv, lsave + len, leftlen - len);
1282 I32 gimme = GIMME_V;
1283 I32 dokeys = (PL_op->op_type == OP_KEYS);
1284 I32 dovalues = (PL_op->op_type == OP_VALUES);
1286 if (PL_op->op_type == OP_RV2HV || PL_op->op_type == OP_PADHV)
1287 dokeys = dovalues = TRUE;
1290 if (PL_op->op_flags & OPf_MOD || LVRET) { /* lvalue */
1291 dTARGET; /* make sure to clear its target here */
1292 if (SvTYPE(TARG) == SVt_PVLV)
1293 LvTARG(TARG) = Nullsv;
1300 (void)hv_iterinit(keys); /* always reset iterator regardless */
1302 if (gimme == G_VOID)
1305 if (gimme == G_SCALAR) {
1309 if (PL_op->op_flags & OPf_MOD || LVRET) { /* lvalue */
1310 if (SvTYPE(TARG) < SVt_PVLV) {
1311 sv_upgrade(TARG, SVt_PVLV);
1312 sv_magic(TARG, Nullsv, PERL_MAGIC_nkeys, Nullch, 0);
1315 if (LvTARG(TARG) != (SV*)keys) {
1317 SvREFCNT_dec(LvTARG(TARG));
1318 LvTARG(TARG) = SvREFCNT_inc(keys);
1324 if (! SvTIED_mg((SV*)keys, PERL_MAGIC_tied))
1329 while (hv_iternext(keys)) i++;
1335 EXTEND(SP, HvKEYS(keys) * (dokeys + dovalues));
1337 PUTBACK; /* hv_iternext and hv_iterval might clobber stack_sp */
1338 while ((entry = hv_iternext(keys))) {
1341 SV* sv = hv_iterkeysv(entry);
1342 XPUSHs(sv); /* won't clobber stack_sp */
1346 tmpstr = hv_iterval(hv,entry);
1347 DEBUG_H(Perl_sv_setpvf(aTHX_ tmpstr, "%lu%%%d=%lu",
1348 (unsigned long)HeHASH(entry),
1350 (unsigned long)(HeHASH(entry) & HvMAX(keys))));