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

Document "perl -Cio" scoping #10798

Closed
p5pRT opened this issue Nov 5, 2010 · 5 comments
Closed

Document "perl -Cio" scoping #10798

p5pRT opened this issue Nov 5, 2010 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 5, 2010

Migrated from rt.perl.org#78828 (status was 'resolved')

Searchable as RT78828$

@p5pRT
Copy link
Author

p5pRT commented Nov 5, 2010

From @ntyni

This is a bug report for perl from Niko Tyni <ntyni@​debian.org>,
generated with the help of perlbug 1.39 running under perl 5.13.6.


While the other -C settings are global, "i" and "o" only affect subsequent
open() calls in the current file. This seems to be working as designed,
judging by the names HINT_LEXICAL_IO_IN and HINT_LEXICAL_IO_OUT in
the code, but it's not currently documented and may cause surprising
behaviour.

The attached suggested patch documents the scoping and adds two tests
to make sure the documented behaviour doesn't change accidentally.

Reported by Joey Hess in http​://bugs.debian.org/373698

Also reported by Frank Krout as [perl #23199], which was closed because
"the -C option on the shebang line is no longer supported." However,
I don't think the new shebang restrictions are relevant here, as shown
by the tests.



Flags​:
  category=docs
  severity=low


Site configuration information for perl 5.13.6​:

Configured by niko at Fri Nov 5 14​:02​:26 EET 2010.

Summary of my perl5 (revision 5 version 13 subversion 6) configuration​:
  Local Commit​: d0e436546e64a3300dcdf33c89ba0ac7ae994521
  Ancestor​: 512ba29
  Platform​:
  osname=linux, osvers=2.6.32-5-amd64, archname=x86_64-linux-gnu-thread-multi
  uname='linux madeleine 2.6.32-5-amd64 #1 smp sat oct 30 14​:18​:21 utc 2010 x86_64 gnulinux '
  config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=x86_64-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.13 -Darchlib=/usr/lib/perl/5.13 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.13.6 -Dsitearch=/usr/local/lib/perl/5.13.6 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -DDEBUGGING=both -Doptimize=-O0 -Dusedevel -Uuseshrplib -des'
  hint=recommended, useposix=true, d_sigaction=define
  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 -DDEBIAN -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-O0 -g',
  cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
  ccversion='', gccversion='4.4.5', 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 =' -fstack-protector -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64
  libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc -lgdbm_compat
  perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
  libc=/lib/libc-2.11.2.so, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version='2.11.2'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
  cccdlflags='-fPIC', lddlflags='-shared -O0 -g -L/usr/local/lib -fstack-protector'

Locally applied patches​:
 


@​INC for perl 5.13.6​:
  lib
  /usr/local/lib/perl/5.13.6
  /usr/local/share/perl/5.13.6
  /usr/lib/perl5
  /usr/share/perl5
  /usr/lib/perl/5.13
  /usr/share/perl/5.13
  /usr/local/share/perl
  /usr/share/perl5
  .


Environment for perl 5.13.6​:
  HOME=/home/niko
  LANG=en_US.UTF-8
  LANGUAGE (unset)
  LC_CTYPE=fi_FI.UTF-8
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/home/niko/bin​:/home/niko/bin​:/home/niko/bin​:/usr/local/bin​:/usr/bin​:/bin​:/usr/local/games​:/usr/games​:/sbin​:/usr/sbin​:/sbin​:/usr/sbin
  PERL_BADLANG (unset)
  SHELL=/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented Nov 5, 2010

From @ntyni

0001-Document-that-the-Ci-Co-and-CD-options-have-file-sco.patch
From 7db0e78765d807d179a563e20d73e4e9f2dbb135 Mon Sep 17 00:00:00 2001
From: Niko Tyni <ntyni@debian.org>
Date: Fri, 5 Nov 2010 13:59:14 +0200
Subject: [PATCH] Document that the -Ci, -Co, and -CD options have file scope

While the other -C settings are global, "i" and "o" only affect subsequent
open() calls in the current file. Document this and add two tests to
make sure the documented behaviour doesn't change accidentally.
---
 pod/perlrun.pod |   10 +++++-----
 t/run/switchC.t |   17 ++++++++++++++++-
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/pod/perlrun.pod b/pod/perlrun.pod
index f3db450..5f93336 100644
--- a/pod/perlrun.pod
+++ b/pod/perlrun.pod
@@ -301,11 +301,11 @@ STDOUT and STDERR.  Repeating letters is just redundant, not cumulative
 nor toggling.
 
 The C<io> options mean that any subsequent open() (or similar I/O
-operations) will have the C<:utf8> PerlIO layer implicitly applied
-to them, in other words, UTF-8 is expected from any input stream,
-and UTF-8 is produced to any output stream.  This is just the default,
-with explicit layers in open() and with binmode() one can manipulate
-streams as usual.
+operations) in the current file scope will have the C<:utf8> PerlIO layer
+implicitly applied to them, in other words, UTF-8 is expected from any
+input stream, and UTF-8 is produced to any output stream.  This is just
+the default, with explicit layers in open() and with binmode() one can
+manipulate streams as usual.
 
 C<-C> on its own (not followed by any number or option list), or the
 empty string C<""> for the C<PERL_UNICODE> environment variable, has the
diff --git a/t/run/switchC.t b/t/run/switchC.t
index 65b5eab..b6231ca 100644
--- a/t/run/switchC.t
+++ b/t/run/switchC.t
@@ -18,11 +18,12 @@ BEGIN {
 
 BEGIN { require "./test.pl"; }
 
-plan(tests => 11);
+plan(tests => 13);
 
 my $r;
 
 my $tmpfile = tempfile();
+my $scriptfile = tempfile();
 
 my $b = pack("C*", unpack("U0C*", pack("U",256)));
 
@@ -58,6 +59,20 @@ $r = runperl( switches => [ '-Ci', '-w' ],
               stderr   => 1 );
 like( $r, qr/^256(?:\r?\n)?$/s, '-Ci: auto-UTF-8 open for input' );
 
+open(S, ">$scriptfile") or die("open $scriptfile: $!");
+print S "open(F, q(<$tmpfile)); print ord(<F>); close F";
+close S;
+
+$r = runperl( switches => [ '-Ci', '-w' ],
+	      progfile => $scriptfile,
+              stderr   => 1 );
+like( $r, qr/^256(?:\r?\n)?$/s, '-Ci: auto-UTF-8 open for input affects the current file' );
+
+$r = runperl( switches => [ '-Ci', '-w' ],
+	      prog     => "do q($scriptfile)",
+              stderr   => 1 );
+unlike( $r, qr/^256(?:\r?\n)?$/s, '-Ci: auto-UTF-8 open for input has file scope' );
+
 $r = runperl( switches => [ '-CA', '-w' ],
 	      prog     => 'print ord shift',
               stderr   => 1,
-- 
1.7.2.3

@p5pRT
Copy link
Author

p5pRT commented Nov 5, 2010

From @cpansprout

On Fri Nov 05 05​:20​:09 2010, ntyni@​debian.org wrote​:

While the other -C settings are global, "i" and "o" only affect
subsequent
open() calls in the current file. This seems to be working as
designed,
judging by the names HINT_LEXICAL_IO_IN and HINT_LEXICAL_IO_OUT in
the code, but it's not currently documented and may cause surprising
behaviour.

The attached suggested patch documents the scoping and adds two tests
to make sure the documented behaviour doesn't change accidentally.

Thank you. Applied as 88770b4.

Reported by Joey Hess in http​://bugs.debian.org/373698

Also reported by Frank Krout as [perl #23199], which was closed
because
"the -C option on the shebang line is no longer supported."

See also [perl #67880].

@p5pRT
Copy link
Author

p5pRT commented Nov 5, 2010

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

@p5pRT
Copy link
Author

p5pRT commented Nov 5, 2010

@cpansprout - Status changed from 'open' to 'resolved'

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

No branches or pull requests

1 participant