summaryrefslogtreecommitdiff
path: root/pp_hot.c
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2003-02-24 18:44:41 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2003-02-24 18:44:41 +0000
commitdb79b45b3c913399aef4d2f3647453e63c4772a8 (patch)
tree8f017949a97d258ab9bf69382ed306017ae5d7f4 /pp_hot.c
parent8fde6460a7cb90e344d87e1652b5fa8d61c68699 (diff)
downloadperl-db79b45b3c913399aef4d2f3647453e63c4772a8.tar.gz
Patching magic from Inaba-san's keyboard: fix for [perl #8769]:
"scalar upgraded to UTF-8 as a side effect of quote-interpolation when 'use encoding' is engaged"-- wasn't actually encoding's fault. p4raw-id: //depot/perl@18764
Diffstat (limited to 'pp_hot.c')
-rw-r--r--pp_hot.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/pp_hot.c b/pp_hot.c
index 62b5c5c5c7..299190046c 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -136,11 +136,12 @@ PP(pp_concat)
bool lbyte;
STRLEN rlen;
char* rpv = SvPV(right, rlen); /* mg_get(right) happens here */
- bool rbyte = !SvUTF8(right);
+ bool rbyte = !SvUTF8(right), rcopied = FALSE;
if (TARG == right && right != left) {
right = sv_2mortal(newSVpvn(rpv, rlen));
rpv = SvPV(right, rlen); /* no point setting UTF8 here */
+ rcopied = TRUE;
}
if (TARG != left) {
@@ -176,6 +177,8 @@ PP(pp_concat)
if (lbyte)
sv_utf8_upgrade_nomg(TARG);
else {
+ if (!rcopied)
+ right = sv_2mortal(newSVpvn(rpv, rlen));
sv_utf8_upgrade_nomg(right);
rpv = SvPV(right, rlen);
}
@@ -1901,6 +1904,7 @@ PP(pp_subst)
#ifdef PERL_COPY_ON_WRITE
bool is_cow;
#endif
+ SV *nsv = Nullsv;
/* known replacement string? */
dstr = (pm->op_pmflags & PMf_CONST) ? POPs : Nullsv;
@@ -1986,7 +1990,7 @@ PP(pp_subst)
if (dstr) {
/* replacement needing upgrading? */
if (DO_UTF8(TARG) && !doutf8) {
- SV *nsv = sv_newmortal();
+ nsv = sv_newmortal();
SvSetSV(nsv, dstr);
if (PL_encoding)
sv_recode_to_utf8(nsv, PL_encoding);
@@ -2011,7 +2015,8 @@ PP(pp_subst)
&& !is_cow
#endif
&& (I32)clen <= rx->minlen && (once || !(r_flags & REXEC_COPY_STR))
- && !(rx->reganch & ROPT_LOOKBEHIND_SEEN)) {
+ && !(rx->reganch & ROPT_LOOKBEHIND_SEEN)
+ && (!doutf8 || SvUTF8(TARG))) {
if (!CALLREGEXEC(aTHX_ rx, s, strend, orig, 0, TARG, NULL,
r_flags | REXEC_CHECKED))
{
@@ -2155,7 +2160,10 @@ PP(pp_subst)
strend = s + (strend - m);
}
m = rx->startp[0] + orig;
- sv_catpvn(dstr, s, m-s);
+ if (doutf8 && !SvUTF8(dstr))
+ sv_catpvn_utf8_upgrade(dstr, s, m - s, nsv);
+ else
+ sv_catpvn(dstr, s, m-s);
s = rx->endp[0] + orig;
if (clen)
sv_catpvn(dstr, c, clen);
@@ -2163,12 +2171,8 @@ PP(pp_subst)
break;
} while (CALLREGEXEC(aTHX_ rx, s, strend, orig, s == m,
TARG, NULL, r_flags));
- if (doutf8 && !DO_UTF8(dstr)) {
- SV* nsv = sv_2mortal(newSVpvn(s, strend - s));
-
- sv_utf8_upgrade(nsv);
- sv_catpvn(dstr, SvPVX(nsv), SvCUR(nsv));
- }
+ if (doutf8 && !DO_UTF8(TARG))
+ sv_catpvn_utf8_upgrade(dstr, s, strend - s, nsv);
else
sv_catpvn(dstr, s, strend - s);