Skip to content
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

[PATCH] Tie::StdHandle::BINMODE does not handle LAYER argument #16262

Closed
p5pRT opened this issue Nov 20, 2017 · 10 comments · Fixed by #17231
Closed

[PATCH] Tie::StdHandle::BINMODE does not handle LAYER argument #16262

p5pRT opened this issue Nov 20, 2017 · 10 comments · Fixed by #17231

Comments

@p5pRT
Copy link

p5pRT commented Nov 20, 2017

Migrated from rt.perl.org#132475 (status was 'open')

Searchable as RT132475$

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2017

From @haukex

Dear Perl 5 Porters,

The final test in the attached script always fails (tested on Linux,
Perl 5.8.1 thru blead, and Windows on several Perl versions). The reason
is that Tie​::StdHandle​::BINMODE is implemented like this​:

  sub BINMODE { binmode($_[0]) }

meaning that the layer argument is not passed through. The attached
patch fixes this (tests included) by changing the implementation to​:

  sub BINMODE { &CORE​::binmode(shift, @​_) }

This is based on the first of the patches that I wrote about a while ago
here (this time submitted as a bug for tracking)​:
https://www.nntp.perl.org/group/perl.perl5.porters/2017/09/msg246402.html

Thanks, Best Regards,
-- Hauke D

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2017

From @haukex

tie_stdhandle_binmode_2.pl

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2017

From @haukex

0001-Tie-StdHandle-BINMODE-handle-layer-argument.patch
From 6d372dc31841cd31461dc3f5d86e0f80fc2ebd0a Mon Sep 17 00:00:00 2001
From: Hauke D <haukex@zero-g.net>
Date: Mon, 20 Nov 2017 15:31:57 +0100
Subject: [PATCH] Tie::StdHandle::BINMODE: handle layer argument

BINMODE was not handling the LAYER argument.
Also bump the version number.
---
 lib/Tie/Handle/stdhandle.t | 13 ++++++++++++-
 lib/Tie/StdHandle.pm       |  4 ++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/lib/Tie/Handle/stdhandle.t b/lib/Tie/Handle/stdhandle.t
index d2f04bcc5c..6c20d90f2b 100644
--- a/lib/Tie/Handle/stdhandle.t
+++ b/lib/Tie/Handle/stdhandle.t
@@ -5,7 +5,7 @@ BEGIN {
     @INC = '../lib';
 }
 
-use Test::More tests => 27;
+use Test::More tests => 29;
 
 use_ok('Tie::StdHandle');
 
@@ -72,6 +72,17 @@ is($b, "rhubarbX\n", "b eq rhubarbX");
 $b = <$f>;
 is($b, "89\n", "b eq 89");
 
+# binmode should pass through layer argument
+
+binmode $f, ':raw';
+ok !grep( $_ eq 'utf8', PerlIO::get_layers(tied(*$f)) ),
+    'no utf8 in layers after binmode :raw';
+binmode $f, ':utf8';
+ok grep( $_ eq 'utf8', PerlIO::get_layers(tied(*$f)) ),
+    'utf8 is in layers after binmode :utf8';
+
+# finish up
+
 ok(eof($f), "eof");
 ok(close($f), "close");
 
diff --git a/lib/Tie/StdHandle.pm b/lib/Tie/StdHandle.pm
index dfb86634f0..fb79a986c6 100644
--- a/lib/Tie/StdHandle.pm
+++ b/lib/Tie/StdHandle.pm
@@ -4,7 +4,7 @@ use strict;
 
 use Tie::Handle;
 our @ISA = 'Tie::Handle';
-our $VERSION = '4.5';
+our $VERSION = '4.6';
 
 =head1 NAME
 
@@ -48,7 +48,7 @@ sub TELL    { tell($_[0]) }
 sub FILENO  { fileno($_[0]) }
 sub SEEK    { seek($_[0],$_[1],$_[2]) }
 sub CLOSE   { close($_[0]) }
-sub BINMODE { binmode($_[0]) }
+sub BINMODE { &CORE::binmode(shift, @_) }
 
 sub OPEN
 {
-- 
2.15.0

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2017

From @atoomic

Thanks for the patch, I've kicked a smoker run with it
p5h/perl5demo#32

nicolas

On Mon, 20 Nov 2017 07​:31​:23 -0800, haukex@​zero-g.net wrote​:

Dear Perl 5 Porters,

The final test in the attached script always fails (tested on Linux,
Perl 5.8.1 thru blead, and Windows on several Perl versions). The reason
is that Tie​::StdHandle​::BINMODE is implemented like this​:

sub BINMODE { binmode($_[0]) }

meaning that the layer argument is not passed through. The attached
patch fixes this (tests included) by changing the implementation to​:

sub BINMODE { &CORE​::binmode(shift, @​_) }

This is based on the first of the patches that I wrote about a while ago
here (this time submitted as a bug for tracking)​:
https://www.nntp.perl.org/group/perl.perl5.porters/2017/09/msg246402.html

Thanks, Best Regards,
-- Hauke D

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2017

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2017

From @jkeenan

On Mon, 20 Nov 2017 15​:58​:42 GMT, atoomic@​cpan.org wrote​:

Thanks for the patch, I've kicked a smoker run with it
p5h/perl5demo#32

nicolas

On Mon, 20 Nov 2017 07​:31​:23 -0800, haukex@​zero-g.net wrote​:

Dear Perl 5 Porters,

The final test in the attached script always fails (tested on Linux,
Perl 5.8.1 thru blead, and Windows on several Perl versions). The reason
is that Tie​::StdHandle​::BINMODE is implemented like this​:

sub BINMODE { binmode($_[0]) }

meaning that the layer argument is not passed through. The attached
patch fixes this (tests included) by changing the implementation to​:

sub BINMODE { &CORE​::binmode(shift, @​_) }

This is based on the first of the patches that I wrote about a while ago
here (this time submitted as a bug for tracking)​:
https://www.nntp.perl.org/group/perl.perl5.porters/2017/09/msg246402.html

Thanks, Best Regards,
-- Hauke D

Also available in this branch​:

smoke-me/jkeenan/haukex/132475-binmode
--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Aug 13, 2019

From @haukex

Hi,

Bump! Thanks for the smokers, how are things looking there?

Best,
-- Hauke D

On Mon, 20 Nov 2017 14​:43​:13 -0800, jkeenan wrote​:

On Mon, 20 Nov 2017 15​:58​:42 GMT, atoomic@​cpan.org wrote​:

Thanks for the patch, I've kicked a smoker run with it
p5h/perl5demo#32

nicolas

Also available in this branch​:

smoke-me/jkeenan/haukex/132475-binmode

@toddr
Copy link
Member

toddr commented Oct 19, 2019

@xsawyerx
Copy link
Member

Can we merge, then?

atoomic pushed a commit to atoomic/perl5 that referenced this issue Oct 29, 2019
Fixes Perl#16262

BINMODE was not handling the LAYER argument.
Also bump the version number.

(cherry picked from commit 479d04b98e5b747e5c9ead7368d3e132f524a2b7)
Signed-off-by: Nicolas R <atoomic@cpan.org>
toddr pushed a commit that referenced this issue Oct 29, 2019
Fixes #16262

BINMODE was not handling the LAYER argument.
Also bump the version number.

(cherry picked from commit 479d04b98e5b747e5c9ead7368d3e132f524a2b7)
Signed-off-by: Nicolas R <atoomic@cpan.org>
@haukex
Copy link
Contributor

haukex commented Oct 29, 2019

Thanks all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants