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

local $/ = <STDIN> broken #13205

Open
p5pRT opened this issue Aug 27, 2013 · 4 comments
Open

local $/ = <STDIN> broken #13205

p5pRT opened this issue Aug 27, 2013 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 27, 2013

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

Searchable as RT119487$

@p5pRT
Copy link
Author

p5pRT commented Aug 27, 2013

From @mauke

Created by @mauke

The following programs should all produce the same output​:

% perl -e 'print "a\nb\nc\n"' | perl -we 'print "[$_]\n" for do { local $/ = <STDIN> }'
[a
b
c
]

% perl -e 'print "a\nb\nc\n"' | perl -we 'print "[$_]\n" for do { local $/ = do { <STDIN> } }'
[a
]

% perl -e 'print "a\nb\nc\n"' | perl -we 'print "[$_]\n" for do { local $/ = (0, <STDIN>) }'
[a
]

I think the first one is broken.

Perl Info

Flags:
    category=core
    severity=low

This perlbug was built using Perl 5.12.1 - Thu Jun  3 20:09:15 CEST 2010
It is being executed now by  Perl 5.18.1 - Tue Aug 13 07:08:47 CEST 2013.

Site configuration information for perl 5.18.1:

Configured by mauke at Tue Aug 13 07:08:47 CEST 2013.

Summary of my perl5 (revision 5 version 18 subversion 1) configuration:
   
  Platform:
    osname=linux, osvers=3.5.7-gentoo, archname=i686-linux
    uname='linux nora 3.5.7-gentoo #5 preempt sat jan 26 16:46:10 cet 2013 i686 amd athlon(tm) 64 processor 3200+ authenticamd gnulinux '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -flto',
    cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.8.1', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags ='-O2 -flto -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib/../lib /usr/lib/../lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.15.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.15'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -flto -L/usr/local/lib -fstack-protector'

Locally applied patches:
    SAVEARGV0 - disable magic open in <ARGV>


@INC for perl 5.18.1:
    /home/mauke/usr/local/lib/perl5/site_perl/5.18.1/i686-linux
    /home/mauke/usr/local/lib/perl5/site_perl/5.18.1
    /home/mauke/usr/local/lib/perl5/5.18.1/i686-linux
    /home/mauke/usr/local/lib/perl5/5.18.1
    .


Environment for perl 5.18.1:
    HOME=/home/mauke
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LC_COLLATE=POSIX
    LD_LIBRARY_PATH=/home/mauke/usr/local/lib
    LOGDIR (unset)
    PATH=/home/mauke/usr/perlbrew/bin:/home/mauke/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.6.3:/opt/sun-jdk-1.4.2.13/bin:/opt/sun-jdk-1.4.2.13/jre/bin:/opt/sun-jdk-1.4.2.13/jre/javaws:/opt/dmd/bin:/usr/games/bin
    PERLBREW_BASHRC_VERSION=0.43
    PERLBREW_HOME=/home/mauke/.perlbrew
    PERLBREW_PATH=/home/mauke/usr/perlbrew/bin
    PERLBREW_ROOT=/home/mauke/usr/perlbrew
    PERLBREW_VERSION=0.27
    PERL_BADLANG (unset)
    PERL_UNICODE=SAL
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Aug 27, 2013

From @cpansprout

On Tue Aug 27 13​:12​:01 2013, mauke- wrote​:

The following programs should all produce the same output​:

% perl -e 'print "a\nb\nc\n"' | perl -we 'print "[$_]\n" for do {
local $/ = <STDIN> }'
[a
b
c
]

% perl -e 'print "a\nb\nc\n"' | perl -we 'print "[$_]\n" for do {
local $/ = do { <STDIN> } }'
[a
]

% perl -e 'print "a\nb\nc\n"' | perl -we 'print "[$_]\n" for do {
local $/ = (0, <STDIN>) }'
[a
]

I think the first one is broken.

A readline optimisation is causing the order of evaluation to change,
making the ‘local $/’ get executed too soon​:

Notice how the LVINTRO line is number 3 while readline is number 5​:

$ ./perl -Ilib -MO=Concise -e ' local $/ = <foo> '
6 <@​> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e​:1) v​:{ ->3
- <1> null vKS/2 ->6
- <1> ex-rv2sv sKRM*/129 ->4
3 <#> gvsv[*/] s/LVINTRO ->4
5 <1> readline[t3] sKS/1 ->6
4 <#> gv[*foo] s ->5
-e syntax OK

Here the numbers are 5 and 4, so the execution order is different​:

$ ./perl -Ilib -MO=Concise -e ' local $/ = do { <foo> } '
7 <@​> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 2 -e​:1) v​:{ ->3
6 <2> sassign vKS/2 ->7
- <1> null sK*/1 ->5
- <@​> scope sK ->-
- <0> ex-nextstate v ->3
4 <1> readline[t3] sK/1 ->5
3 <#> gv[*foo] s ->4
- <1> ex-rv2sv sKRM*/129 ->6
5 <#> gvsv[*/] s/LVINTRO ->6
-e syntax OK

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Aug 27, 2013

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

@p5pRT
Copy link
Author

p5pRT commented Aug 29, 2013

From @mauke

On Di. 27. Aug. 2013, 14​:39​:39, sprout wrote​:

A readline optimisation is causing the order of evaluation to change,
making the ‘local $/’ get executed too soon​:

Notice how the LVINTRO line is number 3 while readline is number 5​:

$ ./perl -Ilib -MO=Concise -e ' local $/ = <foo> '
6 <@​> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e​:1) v​:{ ->3
- <1> null vKS/2 ->6
- <1> ex-rv2sv sKRM*/129 ->4
3 <#> gvsv[*/] s/LVINTRO ->4
5 <1> readline[t3] sKS/1 ->6
4 <#> gv[*foo] s ->5
-e syntax OK

Here the numbers are 5 and 4, so the execution order is different​:

$ ./perl -Ilib -MO=Concise -e ' local $/ = do { <foo> } '
7 <@​> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 2 -e​:1) v​:{ ->3
6 <2> sassign vKS/2 ->7
- <1> null sK*/1 ->5
- <@​> scope sK ->-
- <0> ex-nextstate v ->3
4 <1> readline[t3] sK/1 ->5
3 <#> gv[*foo] s ->4
- <1> ex-rv2sv sKRM*/129 ->6
5 <#> gvsv[*/] s/LVINTRO ->6
-e syntax OK

That optimization seems to be blatantly invalid. :-)

% cat try.pl
#!/usr/bin/perl
use strict;
use warnings;

{
  package Ohai;

  sub TIEHANDLE {
  my $class = shift;
  bless {@​_}, $class
  }

  sub READLINE {
  my $self = shift;
  $self->{readline}()
  }
}

our $xy = 42;

tie *HDL, 'Ohai', (
  readline => sub {
  print "the value of \$xy is [$xy]\n";
  qw(a b c)
  },
);

{ local $xy = do { <HDL> }; }
{ local $xy = <HDL>; }
__END__

% perl try.pl
the value of $xy is [42]
Use of uninitialized value $xy in concatenation (.) or string at try.pl
line 23.
the value of $xy is []

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