-
Notifications
You must be signed in to change notification settings - Fork 581
refcount for anonymous sub is 2 instead of 1 #11818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
From @dolmenThis is a bug report for perl from dolmen@cpan.org, With the following expression: my $x = sub { }; the refcount of $x is 2 instead of 1. Here is a testcase. Tests 1,2,3 fail at least on perl 5.10.1 and 5.14.2. use Test::More; # Simple sub # Closure done_testing; Flags: Site configuration information for perl 5.10.1: Configured by Debian Project at Tue Apr 26 15:53:22 UTC 2011. Summary of my perl5 (revision 5 version 10 subversion 1) configuration: Platform: Locally applied patches: |
From @ikegami2011/12/22 Olivier Mengué <perlbug-followup@perl.org>
There is no such problem if the sub, instead of behind a simple sub,
What problem? - Eric |
The RT System itself - Status changed from 'new' to 'open' |
From @ikegami2011/12/22 Olivier Mengué <perlbug-followup@perl.org>
4, one for each element in @a, and one to the sub alive until sub {} needs With closures, there would be 4 CVs with one reference each instead of 1 CV |
@ikegami - Status changed from 'open' to 'rejected' |
From @cpansproutOn Sat Dec 24 15:55:23 2011, ikegami@adaelis.com wrote:
I think this is a bug, in that mentioning a variable in a sub shouldn’t It also causes the blessing bug in ticket #3306. -- Father Chrysostomos |
@cpansprout - Status changed from 'rejected' to 'open' |
From @doyOn Sat, Dec 24, 2011 at 06:55:03PM -0800, Father Chrysostomos via RT wrote:
Oh good, that's already reported - I just ran into that a couple months -doy |
From @leonerdOn Thu, Dec 22, 2011 at 11:59:15AM -0800, Olivier Mengué wrote:
One reference in the RV, one in the optree of the program. Since the anonymous function is not a closure it does not need to be I run into similar problems in the unit tests for Test::Refcount. To create a trivial coderef with refcount 1 you need to make it a my $x = do { my $dummy; sub { undef $dummy; } }; HTH -- leonerd@leonerd.org.uk |
From @dolmenLe Sam. Déc. 24 18:55:03 2011, sprout a écrit :
Well, it does. In my use case, I use weaken on closures to break circular references The bug I had in my code was that I did use weaken "as usual" on the To avoid such mistakes in the future, would it be possible to detect and
Thanks for that reference. I submitted an idea on how to fix that one too. -- |
From [Unknown Contact. See original ticket]Le Sam. Déc. 24 18:55:03 2011, sprout a écrit :
Well, it does. In my use case, I use weaken on closures to break circular references The bug I had in my code was that I did use weaken "as usual" on the To avoid such mistakes in the future, would it be possible to detect and
Thanks for that reference. I submitted an idea on how to fix that one too. -- |
From @cpansproutOn Fri Dec 30 06:31:34 2011, dolmen wrote:
But holding a weak reference to a non-closure sub is not necessarily a
-- Father Chrysostomos |
From [email protected]Olivier Mengu?? via RT wrote:
You might want to make your weakening conditional on the sub being use Scalar::Util qw(weaken); sub weaken_closure($) { Use weaken_closure() everywhere that you currently use weaken() for -zefram |
From @cpansproutOn Fri Dec 30 06:31:34 2011, dolmen wrote:
One way to fix this, which would make sub{} do what most people think I don’t fully understand, though, how CvCLONE and CvCLONED work. Do -- Father Chrysostomos |
From @iabynOn Tue, Jan 03, 2012 at 11:16:54PM -0800, Father Chrysostomos via RT wrote:
I don't understand how that helps. Can you elaborate?
The logic is like this. In an idealised world, a prototype anon sub is In the real world, as an optimisation, if the anon sub doesn't close over -- |
From @nwc10On Sun, Jan 08, 2012 at 03:41:20PM +0000, Dave Mitchell wrote:
I note the above represents the idea, and that this is the optimisation:
and that I don't understand the implications enough to know if something What I've been wondering for a while is, what happens if PVCV is split PVCV would be a light(er)weight head, pointing to the heavy weight stuff I sort of wondered about copying PVCV directly for the "optimised" case Nicholas Clark |
From @iabynOn Wed, Jan 11, 2012 at 11:30:04AM +0000, Nicholas Clark wrote:
Interesting. I suppose the con side is how much will it slow down normal
But the cloning (and its optimised skipping thereof) should only apply to One possible approach would be to initially just copy the whole CV -- |
Migrated from rt.perl.org#106864 (status was 'open')
Searchable as RT106864$
The text was updated successfully, but these errors were encountered: