Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.93k stars 549 forks source link

Layers not applied to reopened STDOUT #8998

Open p5pRT opened 17 years ago

p5pRT commented 17 years ago

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

Searchable as RT44703$

p5pRT commented 17 years ago

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.

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

According to perlfunc\, if you try to re-open STDOUT or STDERR as an "in memory" file\, you have to close it first\, implying that if you want to re-open it to a file\, you DON'T need to close it first.

However\, if you don't close it first\, then the '​:utf8' layer won't be applied​:

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

  my $utf8="\xe9";

  open STDOUT\, ">>​:utf8"\, 'test.txt' or die $!;   print "No close​: "\,$utf8\,"\n";

  close STDOUT;   open STDOUT\, ">>​:utf8"\, 'test.txt' or die $!;   print "Close​: "\,$utf8\,"\n";

PRINTS​:   No close​: \xe9 (not literally - prints character \xe9\, not UTF-8 encoded)   Close​: é

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 commented 7 years ago

From @jkeenan

On Thu\, 16 Aug 2007 13​:15​:15 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.

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

According to perlfunc\, if you try to re-open STDOUT or STDERR as an "in memory" file\, you have to close it first\, implying that if you want to re-open it to a file\, you DON'T need to close it first.

However\, if you don't close it first\, then the '​:utf8' layer won't be applied​:

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

my $utf8="\xe9";

open STDOUT\, ">>​:utf8"\, 'test.txt' or die $!; print "No close​: "\,$utf8\,"\n";

close STDOUT; open STDOUT\, ">>​:utf8"\, 'test.txt' or die $!; print "Close​: "\,$utf8\,"\n";

PRINTS​: No close​: \xe9 (not literally - prints character \xe9\, not UTF- 8 encoded) Close​: é

I'm confused by this report. You cite pod/perlfunc.pod with respect to opening in-memory files. The relevant documentation in perl-5.24.0 is this​:

##### ... you can open filehandles directly to Perl scalars via​:

  open(my $fh\, ">"\, \$variable) || ..

To (re)open C\ or C\ as an in-memory file\, close it first​:

  close STDOUT;   open(STDOUT\, ">"\, \$variable)   or die "Can't open STDOUT​: $!"; #####

So far\, so good. The example you provide\, however\, entails opening handles to regular files\, not in-memory files. If I rewrite your the first part of your example to print to a scalar reference (attached​: print_to_scalar_no_close_first.pl)\, then I get an exception.

##### $ perl print_to_scalar_no_close_first.pl unable to open​: Bad file descriptor at print_to_scalar_no_close_first.pl line 7. #####

If I close the filehandle first (attached as print_to_scalar_close_first.pl)\, I get reasonable results.

##### $ perl print_to_scalar_close_first.pl $VAR1 = 'Close​: é '; #####

So I'm not sure if there is really a bug here. Thank you very much.

-- James E Keenan (jkeenan@​cpan.org)

p5pRT commented 7 years ago

From @jkeenan

print_to_scalar_close_first.pl

p5pRT commented 7 years ago

From @jkeenan

print_to_scalar_no_close_first.pl

p5pRT commented 7 years ago

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