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 reopened STDOUT #8998

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

Layers not applied to reopened STDOUT #8998

p5pRT opened this issue Aug 16, 2007 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 16, 2007

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

Searchable as RT44703$

@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.

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

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
Copy link
Author

p5pRT commented Jan 7, 2017

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<STDOUT> or C<STDERR> 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
Copy link
Author

p5pRT commented Jan 7, 2017

@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2017

@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