develooper Front page | perl.perl5.porters | Postings from July 2013

[perl #109744] referenced constant loses readonlyness

Thread Next
From:
Father Chrysostomos via RT
Date:
July 26, 2013 07:28
Subject:
[perl #109744] referenced constant loses readonlyness
Message ID:
rt-3.6.HEAD-2552-1374823684-630.109744-15-0@perl.org
On Fri Feb 03 08:03:52 2012, zefram@fysh.org wrote:
> On a threading Perl, a list-mode refgen applied to a constant will
> copy the constant rather than reference it.  An srefgen, however, will
> reference it, and either will work correctly on a non-threading Perl:

That has been fixed in commit 82b84d0.

On Sat Oct 06 22:10:52 2012, sprout wrote:
> Interestingly, copy-on-write can affect whether a ‘constant’ is constant:
> 
> use overload;
> BEGIN { overload'constant"integer" =>=> sub { __PACKAGE__ } }
> eval { ${\5} = "whatever" };
> print $@ || "no error\n";
> BEGIN { overload'constant"integer" =>=> sub { "main" } }
> eval { ${\5} = "whatever" };
> print $@ || "no error\n";
> __END__
> 
> Ouput:
> 
> no error
> Modification of a read-only value attempted at - line 6.

This was fixed in 19130678.

On Tue Jun 11 14:53:37 2013, sprout wrote:
> I feel strongly that sub(){42} and sub(){return 42} should behave the
> same way.

They do, as of d2440203227.

On Fri Jun 14 06:09:56 2013, nicholas wrote:
> IIRC Dave has said that the logic in pad.c needed to
> cause the closure cloning routine to see that
> 
>     sub foo() { $a; }
> 
> isn't to be treated as a closure is an utter hack.

137da2b removed that hack.

On Fri Jun 14 08:39:07 2013, sprout wrote:
> For a long time now, it has bothered me that list constants are not
> inlined.  I see no reason why they couldn’t be.  The default storage
> could be $::{foo} = [], and then we may need a separate constlist op.

We don’t need a constlist op.  I implemented this in commits 6f1b3ab,
15635cbfa and f815dc14d.

> 
> The way it is currently implemented, there is nothing constant about
> these, according to your definition of constant, whether under threads
> or no.

15635cbfa fixed that, too.

On Sun Jun 16 06:48:26 2013, sprout wrote:
> $ ./perl -Ilib -le 'sub foo(){42} for(foo) { print \$_; print \$_; }'
> SCALAR(0x7f99a1806100)
> SCALAR(0x7f99a18062c8)
> 
> This is under ithreads.  Why am I getting two different memory addresses?

This particular cased is fixed by 8e079c2a6.  The surrounding commits
fix similar bugs.  I’ll attach the list to #78194.

> I suggest we apply this patch:
> 
> diff --git a/pod/perlsub.pod b/pod/perlsub.pod
> index 027d7be..7fff252 100644
> --- a/pod/perlsub.pod
> +++ b/pod/perlsub.pod
> @@ -1365,7 +1365,7 @@ starts scribbling on your C<@_> parameter list.
 Ouch!
>  This is all very powerful, of course, and should be used only in
moderation
>  to make the world a better place.
>  
> -=head2 Constant Functions
> +=head2 Inlinable Functions
>  X<constant>
etc.

This is the one unresolved issue left in this ticket.  If I apply the
patch, I break the link in constant.pm’s documentation.  If I change
constant.pm at the same time, I break its link when the next CPAN
release is installed in 5.18 or earlier.

POD is too limiting.  Can we revive #95784 perhaps?

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=109744

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About