Open p5pRT opened 12 years ago
When Capture::Tiny saves\, redirects and restores filehandles to capture output\, it also duplicates the original filehandle layers on the capturing filehandle. Something in this process appears to confuse PerlIO. In the example file below\, PerlIO::get_layers shows the same layers before and after\, yet afterwards a wide character in print warning is issued. I have confirmed this issue in Perl 5.14.2\, Perl 5.10.1 and Perl 5.8.9. (Originally reported against Perl 5.16.0 in Capture::Tiny bug rt.cpan.org #78819)
use Encode; use Capture::Tiny qw(capture);
sub say { print @_\, "\n" }
my $foo = Encode::decode_utf8("\xC5\x82");
binmode( STDOUT\, ":utf8" );
out('PRE'); capture { say "hello world" }; out('POST');
sub out { say STDOUT "$_[0]:"; say STDOUT "fd " . fileno(STDOUT) . " has " . join '\, '\, PerlIO::get_layers( \*STDOUT ); say STDOUT $foo; say STDOUT ''; }
##### OUTPUT ##### #PRE: #fd 1 has unix\, perlio\, utf8 #ł # #POST: #fd 1 has unix\, perlio\, utf8 #Wide character in print at /home/david/perl5/perlbrew/perls/perl-5.14.2/lib/5.14.2/x86_64-linux/IO/Handle.pm line 430. #ł
Note -- triggering this behavior requires Capture::Tiny 0.18 or earlier\, as later versions force a relayering back on top of restored filehandles as a workaround to this bug.
Just because Capture::Tiny has a workaround does not resolve this issue. There is still no reason why PerlIO::get_layers should be reporting layers that aren't actually in effect on a handle.
-- David
@xdg - Status changed from 'new' to 'open'
On Monday August 6 2012 5:18:48 PM David Golden wrote:
When Capture::Tiny saves\, redirects and restores filehandles to capture output\, it also duplicates the original filehandle layers on the capturing filehandle. Something in this process appears to confuse PerlIO. In the example file below\, PerlIO::get_layers shows the same layers before and after\, yet afterwards a wide character in print warning is issued. I have confirmed this issue in Perl 5.14.2\, Perl 5.10.1 and Perl 5.8.9. (Originally reported against Perl 5.16.0 in Capture::Tiny bug rt.cpan.org #78819)
This is a duplicate of https://rt-archive.perl.org/perl5/Ticket/Display.html?id=113982
use Encode; use Capture::Tiny qw(capture);
sub say { print @_\, "\n" }
my $foo = Encode::decode_utf8("\xC5\x82");
binmode( STDOUT\, ":utf8" );
out('PRE'); capture { say "hello world" }; out('POST');
sub out { say STDOUT "$_[0]:"; say STDOUT "fd " . fileno(STDOUT) . " has " . join '\, '\, PerlIO::get_layers( \*STDOUT ); say STDOUT $foo;
You need to add "\, output => 1" here:
say "fd " . fileno(STDOUT) . " has " . join '\, '\, PerlIO::get_layers( \*STDOUT\, output => 1 );
Then you see the difference. Yes\, I faced the same quandary with the previous bug report.
(This may also mean that the fix/workaround to Capture::Tiny might be off in that it's only checking the input layers\, not the output layers\, though I'm assured that most of the time they're the same.)
say STDOUT '';
}
##### OUTPUT ##### #PRE: #fd 1 has unix\, perlio\, utf8 #ł # #POST: #fd 1 has unix\, perlio\, utf8 #Wide character in print at
On Mon\, Aug 6\, 2012 at 11:11 PM\, Darin McBride \dmcbride@​cpan\.org wrote:
This is a duplicate of https://rt-archive.perl.org/perl5/Ticket/Display.html?id=113982
I don't think it's quite the same\, as this bug also points out that get_layers is reporting it incorrectly.
I've marked them as referring to each other\, so whoever fixes it can close them both.
-- David
On Tue\, Aug 7\, 2012 at 6:11 AM\, Darin McBride \dmcbride@​cpan\.org wrote:
(This may also mean that the fix/workaround to Capture::Tiny might be off in that it's only checking the input layers\, not the output layers\, though I'm assured that most of the time they're the same.)
The layers shouldn't be different. binmode explicitly tries to make sure of that if the handles are different. The reason why have this duality is that on for example sockets input and output need separate buffers.
Leon
On Tue\, Aug 7\, 2012 at 6:15 AM\, David Golden \xdaveg@​gmail\.com wrote:
I don't think it's quite the same\, as this bug also points out that get_layers is reporting it incorrectly.
I don't see how it's incorrect\, it's just very confusing.
Leon
Migrated from rt.perl.org#114404 (status was 'open')
Searchable as RT114404$