
nick at ccl4
Nov 28, 2007, 9:10 AM
Post #6 of 9
(222 views)
Permalink
|
On Wed, Nov 28, 2007 at 04:26:02PM +0000, Nicholas Clark wrote: > On Wed, Nov 28, 2007 at 05:23:04PM +0100, Rafael Garcia-Suarez wrote: > > > That comes from sv_bless, this line precisely: > > > > if (SvREADONLY(tmpRef)) > > Perl_croak(aTHX_ PL_no_modify); > > > > It forbids blessing a ref to something which is read only. This code > > is old. I don't know why it isn't exercised in 5.8, but the meaning is > > clear... > > Probably because the core in 5.10 internally copies shared hash key scalars > as shared hash key scalars. 5.8.x doesn't. The appended patch would fix it. Nicholas Clark ==== //depot/perl/sv.c#1442 - /home/nick/p4perl/perl/sv.c ==== --- /tmp/tmp.16261.0 Wed Nov 28 17:06:14 2007 +++ /home/nick/p4perl/perl/sv.c Wed Nov 28 16:45:09 2007 @@ -7979,6 +7979,8 @@ Perl_sv_bless(pTHX_ SV *sv, HV *stash) Perl_croak(aTHX_ "Can't bless non-reference value"); tmpRef = SvRV(sv); if (SvFLAGS(tmpRef) & (SVs_OBJECT|SVf_READONLY)) { + if (SvIsCOW(tmpRef)) + sv_force_normal_flags(tmpRef, 0); if (SvREADONLY(tmpRef)) Perl_croak(aTHX_ PL_no_modify); if (SvOBJECT(tmpRef)) { ==== //depot/perl/t/op/bless.t#8 - /home/nick/p4perl/perl/t/op/bless.t ==== --- /tmp/tmp.16261.1 Wed Nov 28 17:06:14 2007 +++ /home/nick/p4perl/perl/t/op/bless.t Wed Nov 28 16:39:04 2007 @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan (106); +plan (107); sub expected { my($object, $package, $type) = @_; @@ -128,3 +128,11 @@ $h1 = bless {}, "H4"; $c4 = eval { bless \$test, $h1 }; is ($@, '', "class is an overloaded ref"); expected($c4, 'C4', "SCALAR"); + +{ + my %h = 1..2; + my($k) = keys %h; + my $x=\$k; + bless $x, 'pam'; + is(ref $x, 'pam'); +}
|