From: Nicholas Clark Date: Sun, 2 Dec 2001 20:52:32 +0000 (+0000) Subject: Shared hash keys X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2233f375aa37a706e02f773eded0886e392aa503;p=p5sagit%2Fp5-mst-13.2.git Shared hash keys Message-ID: <20011202205232.U21702@plum.flirble.org> p4raw-id: //depot/perl@13430 --- diff --git a/doop.c b/doop.c index 8600b7c..bc77201 100644 --- a/doop.c +++ b/doop.c @@ -599,9 +599,12 @@ Perl_do_trans(pTHX_ SV *sv) I32 hasutf = (PL_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)); - if (SvREADONLY(sv) && !(PL_op->op_private & OPpTRANS_IDENTICAL)) - Perl_croak(aTHX_ PL_no_modify); - + if (SvREADONLY(sv)) { + if (SvFAKE(sv)) + sv_force_normal(sv); + if (SvREADONLY(sv) && !(PL_op->op_private & OPpTRANS_IDENTICAL)) + Perl_croak(aTHX_ PL_no_modify); + } (void)SvPV(sv, len); if (!len) return 0; diff --git a/t/op/tr.t b/t/op/tr.t index 124c08a..5cd800f 100755 --- a/t/op/tr.t +++ b/t/op/tr.t @@ -5,7 +5,7 @@ BEGIN { @INC = '../lib'; } -print "1..70\n"; +print "1..71\n"; $_ = "abcdefghijklmnopqrstuvwxyz"; @@ -390,4 +390,10 @@ print "ok 69\n"; print "not " unless $a eq "XZY"; print "ok 70\n"; - +# pp_trans needs to unshare shared hash keys +# Used to fail with "Modification of a read-only value attempted" +%a = (N=>1); +foreach (keys %a) { + tr/N/n/; + print +($_ eq 'n' ? '' : "not ") . "ok 71\n"; +}