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

Layers not applied to redirected filehandles #8997

Open
p5pRT opened this issue Aug 16, 2007 · 5 comments
Open

Layers not applied to redirected filehandles #8997

p5pRT opened this issue Aug 16, 2007 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 16, 2007

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

Searchable as RT44701$

@p5pRT
Copy link
Author

p5pRT commented Aug 16, 2007

From @clintongormley

Created by @clintongormley

This is a bug report for perl from clint@​traveljury.com,
generated with the help of perlbug 1.35 running under perl v5.8.8.

-----------------------------------------------------------------

When duplicating a filehandle, layers applied to that filehandle
need to be reapplied to the duplicated handle, and this cannot (I think)
be done with the 3 arg form. It has to be done with binmode().

------------------------------------
  #!/usr/bin/perl
  use strict;
  use warnings;

  my $utf8="\xe9";

  close (STDOUT);
  open( STDOUT, ">>​:utf8", 'test.txt' ) or die $!;
  close STDERR;
  open( STDERR, ">>&STDOUT" ) or die $!;

  print ("STDOUT​: ",$utf8,"\n");
  print STDERR ("STDERR​: ",$utf8,"\n");

  binmode (STDERR,'​:utf8');
  print STDERR ("STDERR with binmode​: ",$utf8,"\n");
 
 
PRINTS​:

  STDOUT​: é
  STDERR​: \xe9 (not literally - prints character \xe9, not UTF-8 encoded)
  STDERR with binmode​: é
-----------------------------------

I would consider this a bug - I would have expected the existing layers to be taken
into account. In the meantime, I've suggested a doc patch to perlfunc to make
this issue clear​:

Inline Patch
--- Desktop/perlfunc.pod.orig   2007-08-16 13:56:42.000000000 +0200
+++ Desktop/perlfunc.pod        2007-08-16 14:04:05.000000000 +0200
@@ -3198,6 +3198,18 @@
     print STDOUT "stdout 2\n";
     print STDERR "stderr 2\n";
 
+Note: Currently, when duplicating file handles, layers applied to
+the destination file handle need to be reapplied to the duplicated handle. 
+This can only be done with L<binmode>.
+
+For example:
+
+    open STDOUT, '>:utf8', 'foo.out' or die "Can't redirect STDOUT: $!";
+    open STDERR, '>&STDOUT'          or die "Can't dup STDOUT: $!";
+
+    # apply :utf8 layer to STDERR
+    binmode (STDERR,':utf8');        
+
 If you specify C<< '<&=X' >>, where C<X> is a file descriptor number
 or a filehandle, then Perl will do an equivalent of C's C<fdopen> of
 that file descriptor (and not call L<dup(2)>); this is more
Perl Info

Flags:
    category=docs
    severity=medium

This perlbug was built using Perl v5.8.8 - Sat Nov 25 11:01:17 UTC 2006
It is being executed now by  Perl v5.8.8 - Sat Nov 25 10:57:22 UTC 2006.

Site configuration information for perl v5.8.8:

Configured by abuild at Sat Nov 25 10:57:22 UTC 2006.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=linux, osvers=2.6.18, archname=x86_64-linux-thread-multi
    uname='linux eisler 2.6.18 #1 smp tue nov 21 12:59:21 utc 2006 x86_64 x86_64 x86_64 gnulinux '
    config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr -Dinstallusrbinperl -Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm -Duseshrplib=true -Doptimize=-O2 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -Wall -pipe'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=define uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -Wall -pipe',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement'
    ccversion='', gccversion='4.1.2 20061115 (prerelease) (SUSE Linux)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib64'
    libpth=/lib64 /usr/lib64 /usr/local/lib64
    libs=-lm -ldl -lcrypt -lpthread
    perllibs=-lm -ldl -lcrypt -lpthread
    libc=/lib64/libc-2.5.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.5'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.8.8/x86_64-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib64'

Locally applied patches:
    


@INC for perl v5.8.8:
    /usr/lib/perl5/5.8.8/x86_64-linux-thread-multi
    /usr/lib/perl5/5.8.8
    /usr/lib/perl5/site_perl/5.8.8/x86_64-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.8
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.8
    /usr/lib/perl5/vendor_perl
    .


Environment for perl v5.8.8:
    HOME=/home/clinton
    LANG=en_GB.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH=:/usr/lib64/seamonkey:/usr/lib64/seamonkey:/usr/lib64/seamonkey
    LOGDIR (unset)
    PATH=/usr/lib/mozart/bin:/home/clinton/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/usr/lib/qt3/bin:/usr/sbin:/usr/sbin:/usr/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2017

From @jkeenan

On Thu, 16 Aug 2007 12​:49​:00 GMT, DrTech wrote​:

This is a bug report for perl from clint@​traveljury.com,
generated with the help of perlbug 1.35 running under perl v5.8.8.

-----------------------------------------------------------------

When duplicating a filehandle, layers applied to that filehandle
need to be reapplied to the duplicated handle, and this cannot (I
think)
be done with the 3 arg form. It has to be done with binmode().

------------------------------------
#!/usr/bin/perl
use strict;
use warnings;

my $utf8="\xe9";

close (STDOUT);
open( STDOUT, ">>​:utf8", 'test.txt' ) or die $!;
close STDERR;
open( STDERR, ">>&STDOUT" ) or die $!;

print ("STDOUT​: ",$utf8,"\n");
print STDERR ("STDERR​: ",$utf8,"\n");

binmode (STDERR,'​:utf8');
print STDERR ("STDERR with binmode​: ",$utf8,"\n");

PRINTS​:

STDOUT​: é
STDERR​: \xe9 (not literally - prints character \xe9, not
UTF-8 encoded)
STDERR with binmode​: é
-----------------------------------

I would consider this a bug - I would have expected the existing
layers to be taken
into account. In the meantime, I've suggested a doc patch to perlfunc
to make
this issue clear​:

--- Desktop/perlfunc.pod.orig 2007-08-16 13​:56​:42.000000000 +0200
+++ Desktop/perlfunc.pod 2007-08-16 14​:04​:05.000000000 +0200
@​@​ -3198,6 +3198,18 @​@​
print STDOUT "stdout 2\n";
print STDERR "stderr 2\n";

+Note​: Currently, when duplicating file handles, layers applied to
+the destination file handle need to be reapplied to the duplicated
handle.
+This can only be done with L<binmode>.
+
+For example​:
+
+ open STDOUT, '>​:utf8', 'foo.out' or die "Can't redirect STDOUT​:
$!";
+ open STDERR, '>&STDOUT' or die "Can't dup STDOUT​: $!";
+
+ # apply :utf8 layer to STDERR
+ binmode (STDERR,'​:utf8');
+
If you specify C<< '<&=X' >>, where C<X> is a file descriptor number
or a filehandle, then Perl will do an equivalent of C's C<fdopen> of
that file descriptor (and not call L<dup(2)>); this is more

Assuming I understand the problem correctly, I cannot reproduce the problem in any perl from 5.8.9 forward.

I'm attaching two programs, one with binmode in effect and one with binmode commented out. I get the same results from each.

#####
$ perl -v | head -2 | tail -1
This is perl, v5.8.9 built for x86_64-linux

$ cat ftest.txt
STDOUT​: é
STDERR​: é
STDERR with binmode​: é

$cat gtest.txt
STDOUT​: é
STDERR​: é
STDERR with binmode​: é
#####

If the results are the same, then there's no need to patch the documentation.

Thank you very much.
--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2017

From @jkeenan

44701-g-layers.pl

@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2017

From @jkeenan

44701-layers.pl

@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2017

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

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

No branches or pull requests

2 participants