-
Notifications
You must be signed in to change notification settings - Fork 558
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
temporary objects created in returning statements are DESTROYed too late #14637
Comments
From kazuhooku@gmail.comCreated by kazuhooku@gmail.comuse Scope::Guard; sub bar { !! new Scope::Guard(sub { warn "destroyed" }); } sub baz { warn "baz"; } baz(bar()); In the code above, "baz" is printed before "destroyed". In other words, the temporary object that is created and evaluated while executing the last statement of subroutine `bar` is not DESTROYed until the execution of the calling statement (in the caller) completes. I believe that this is a bug. The guard object created in `bar` should be DESTROYed before `baz` gets called. The issue caused degradations in one of the Perl modules I maintain, which was reported as and was worked around as Perl Info
|
From @jkeenanOn Mon Apr 06 12:44:44 2015, kazuhooku@gmail.com wrote:
1. Would it be possible for you to try this with perl-5.20 (or, better still, with blead)? You reported with perl-5.16.2, which is no longer a supported version of perl. 2. Have you excluded the possibility that this is a bug in Scope::Guard? (I see that that distribution has not had a new release in nearly 5 years.) Thank you very much.
-- |
The RT System itself - Status changed from 'new' to 'open' |
From @iabynOn Mon, Apr 06, 2015 at 04:39:04PM -0700, James E Keenan via RT wrote:
It can be reproduced in blead with this simple core-only code: sub DESTROY { warn "destroyed" }; The issue is that that we free temporaries at the end of each statement but I don't see that this is fixable. -- |
From @ap* Dave Mitchell <davem@iabyn.com> [2015-04-07 12:45]:
But the value returned has nothing to do with the value expected to be Is this another instance of the “stack isn’t refcounted” issue (or maybe -- |
From @LeontOn Tue, Apr 7, 2015 at 1:02 PM, Aristotle Pagaltzis <pagaltzis@gmx.de>
Possible? Probably, but not without doing more work on every leavesub. And
Was it that predictable? Leon |
From @iabynOn Tue, Apr 07, 2015 at 01:02:04PM +0200, Aristotle Pagaltzis wrote:
Well its more an issue that we use the temps stack ("mortalised")to keep Consider the following. (-DR causes items which have a refcount other than $ ./perl -DstR -e'$x = bless []; $y = $x' ... anonlist creates a ref to an anonymous AV. That RV has an initial At this point the first RV is only accessible from the tmps stack. Not that all this has nothing to do with what we do with the return value This is useful as otherwise something like [] in void context (or more -- |
From kazuhooku@gmail.comThank you for the quick response! 2015-04-07 8:39 GMT+09:00 James E Keenan via RT <perlbug-followup@perl.org>:
The problem still persists on perl 5.20.2, output of perl -V is
I believe that the cause of the issue is not Scope::Guard. The issue was A simple test script using IO::Socket::INET to reproduce the issue can be
-- |
From kazuhooku@gmail.comHi, Thank you all for your help. 2015-04-07 19:41 GMT+09:00 Dave Mitchell via RT <perlbug-followup@perl.org>:
As Aristotle pointed out, the object is evaluated and converted to boolean I do not believe that this issue should necessarily be fixed, however, it
In case of `$x` in your example, I suspect that for a novice user it would Would it be possible to document how and when objects are pushed/popped -- |
From @iabynOn Thu, Apr 09, 2015 at 04:38:17PM +0900, Kazuho Oku wrote:
And as I pointed out, an extra ref to the anon array is created and added The difficulty is in ensuring that 1) in something like this for example $x = ([], {})[$i]; that the unused an array or hash doesn't leak; 2) in something like return []; that the anon array isn't prematurely freed before it gets a chance to These two goals are more or less in conflict with each other. The temps Many bugs are theoretically fixable. That doesn't necessarily make thm
Not really. At a quick grep, there are at least 500 places in the core code -- |
From kazuhooku@gmail.comDave, Thank you for the response. 2015-04-09 22:45 GMT+09:00 Dave Mitchell <davem@iabyn.com>:
I agree.
Thank you for the explanation. If it is hard to describe how it The reason why I ask is the fact that people tend to use DESTORY for However the truth in case of Perl seems to be that there are Consider the following example, foo() tries to lock a file, and does sub trylockfn { sub foo { sub bar { bar(foo(), foo()); The example is indeed artificial and may seem unrealistic, but please
-- |
From @iabynOn Fri, Apr 10, 2015 at 01:04:34PM +0900, Kazuho Oku wrote:
Ok, how about something like the following added to the end of the =head2 Destructors section in perlobj? Note that perl often creates temporary references to newly created This becomes significant where there isn't a statement boundary, such -- |
From @iabynOn Thu, Apr 09, 2015 at 02:45:02PM +0100, Dave Mitchell wrote:
But I've fixed it anyway :-) Commit f7a874b, part of my work on revamping the context system. -- |
@iabyn - Status changed from 'open' to 'pending release' |
From @khwilliamsonThank you for submitting this report. You have helped make Perl better. Perl 5.24.0 may be downloaded via https://metacpan.org/release/RJBS/perl-5.24.0 |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#124248 (status was 'resolved')
Searchable as RT124248$
The text was updated successfully, but these errors were encountered: