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
*FH{IO} and $. scoping ickiness #1420
Comments
From @simoncozens
Perl Info
|
From @schwernThis appears to have gotten worse.
|
@simoncozens, thank you for reporting Perl RT 2566. Your ticket has been moved to #1420 |
This appears to still be an issue on perl 5.30. |
This can also be formulated as «$^LAST_FH is not set if you do <$f> where $f was an |
It's not so much that it's not set, it's that it's set and then immediately cleared. Each of the I/O ops either has a rv2gv generated for it (most) or calls rv2gv itself (readline), which for an IO ref create a mortal GV which is then assigned to PL_last_in_gv, on the next FREETMPS that's released and PL_last_in_gv is cleared (in Perl_sv_clear()). |
It's always been possible to extract a reference to the IO SV from a glob, and use that for I/O, but such use would set PL_last_in_gv to a temporary GV which would almost immediately be released, clearing PL_last_in_gv. This would result in reads from $. returning its most recently read value (even from another handle) and modification being ignored, while ${^LAST_FH} would return undef, even though the file handle is still open. To fix this, store the underlying IO object as well as the GV. Retaining the GV lets errors continue to report the GV name where possible, while the IO object means $. and ${^LAST_FH} can still work if the IO object still exists. This does not try to fix the problem where localization can leave PL_last_in_gv (and now PL_last_in_io) pointing at a SV that has been destroyed, the original changes that introduced PL_last_in_gv didn't keep a reference count for the GV, since this would prevent the file being close automatically when the reference to to the glob went out of scope. Fixes Perl#1420
It's always been possible to extract a reference to the IO SV from a glob, and use that for I/O, but such use would set PL_last_in_gv to a temporary GV which would almost immediately be released, clearing PL_last_in_gv. This would result in reads from $. returning its most recently read value (even from another handle) and modification being ignored, while ${^LAST_FH} would return undef, even though the file handle is still open. To fix this, store the underlying IO object as well as the GV. Retaining the GV lets errors continue to report the GV name where possible, while the IO object means $. and ${^LAST_FH} can still work if the IO object still exists. This does not try to fix the problem where localization can leave PL_last_in_gv (and now PL_last_in_io) pointing at a SV that has been destroyed, the original changes that introduced PL_last_in_gv didn't keep a reference count for the GV, since this would prevent the file being close automatically when the reference to to the glob went out of scope. Fixes Perl#1420
Migrated from rt.perl.org#2566 (status was 'open')
Searchable as RT2566$
The text was updated successfully, but these errors were encountered: