Perl / perl5

šŸŖ The Perl programming language
https://dev.perl.org/perl5/
Other
1.94k stars 554 forks source link

bizarre empty string is true and both defined/undef #11556

Closed p5pRT closed 12 years ago

p5pRT commented 13 years ago

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

Searchable as RT96326$

p5pRT commented 13 years ago

From @mauke

Created by @mauke

% perl -wle 'my $x = *{*STDIN{IO}}; defined $x && $x eq "" or die 1; $x and die 2;' 2 at -e line 1.

=> $x is the empty string\, yet true

% perl -wle 'my $x = *{*STDIN{IO}}; defined $x && $x eq "" or die 1; print "[$x]"' []

=> $x is an ordinary (defined) empty string

% perl -wle 'my $x = *{*STDIN{IO}}; defined $x && $x eq "" or die 1; $x .= ""' Use of uninitialized value $x in concatenation (.) or string at -e line 1.

=> $x is defined() and undef at the same time

Even better\, .= normally doesn't warn about an uninitialized LHS!

I don't know what the intended behavior of *{*STDIN{IO}} is but this is probably not it.

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.14.1 - Wed Jun 22 01:57:37 CEST 2011. Site configuration information for perl 5.14.1: Configured by mauke at Wed Jun 22 01:57:37 CEST 2011. Summary of my perl5 (revision 5 version 14 subversion 1) configuration: Platform: osname=linux, osvers=2.6.37-gentoo-r4, archname=i686-linux uname='linux nora 2.6.37-gentoo-r4 #3 preempt thu may 5 20:36:24 cest 2011 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='gcc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include' ccversion='', gccversion='4.6.0', 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='gcc', ldflags =' -fstack-protector -L/usr/local/lib' libpth=/usr/local/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.12.2.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.12.2' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector' Locally applied patches: SAVEARGV0 - disable magic open in @INC for perl 5.14.1: /home/mauke/usr/local/lib/perl5/site_perl/5.14.1/i686-linux /home/mauke/usr/local/lib/perl5/site_perl/5.14.1 /home/mauke/usr/local/lib/perl5/5.14.1/i686-linux /home/mauke/usr/local/lib/perl5/5.14.1 /home/mauke/usr/local/lib/perl5/site_perl/5.14.0/i686-linux /home/mauke/usr/local/lib/perl5/site_perl/5.14.0 /home/mauke/usr/local/lib/perl5/site_perl . Environment for perl 5.14.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/local/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.4.5:/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 PERL_BADLANG (unset) PERL_UNICODE=SAL SHELL=/bin/bash ```
p5pRT commented 13 years ago

From perl@profvince.com

% perl -wle 'my $x = *{*STDIN{IO}}; defined $x&& $x eq "" or die 1; $x and die 2;' 2 at -e line 1.

This behaves correctly on 5.8.x. On 5.10\, it segfaults - a debugging 5.10.1 gives the following assertion failure :

  Assertion ((buffer)->sv_flags & 0x00000400) failed​: file "sv.c"\, line 1859 at -e line 1.

It starts failing on perl 5.12.

Vincent.

p5pRT commented 13 years ago

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

p5pRT commented 13 years ago

From @cpansprout

On Fri Aug 05 02​:42​:13 2011\, perl@​profvince.com wrote​:

% perl -wle 'my $x = *{*STDIN{IO}}; defined $x&& $x eq "" or die 1; $x and die 2;' 2 at -e line 1.

This behaves correctly on 5.8.x.

In 5.8.x\, defined(*$io} returns false. For defined to return false on a typeglob seems wrong to me.

On 5.10\, it segfaults - a debugging 5.10.1 gives the following assertion failure :

 Assertion \(\(buffer\)\->sv\_flags & 0x00000400\) failed​: file "sv\.c"\,

line 1859 at -e line 1.

It starts failing on perl 5.12.

I donā€™t know the history\, but I suspect stringification was never taken into account\, hence a string was never provided.

So this special glob stringifies as undef\, which is a contradiction in terms; hence all the bugs.

I would suggest stringifying it as *__ANON__ or *__ANONIO__. (Thereā€™s precedent for the latter in op.c​:ck_fun\, but I donā€™t know how to trigger it.)

p5pRT commented 13 years ago

From @Hugmeir

On Mon\, Aug 22\, 2011 at 6​:38 PM\, Father Chrysostomos via RT \< perlbug-followup@​perl.org> wrote​:

I would suggest stringifying it as *__ANON__ or *__ANONIO__. (Thereā€™s precedent for the latter in op.c​:ck_fun\, but I donā€™t know how to trigger it.)

perl -we 'my $t = {}; open $t->{fh}\, ">"\, "some_file.txt"; lstat $t->{fh}'

That behavior needs some tests\, I think.

p5pRT commented 12 years ago

From @cpansprout

Now fixed with commit 52a6327.

p5pRT commented 12 years ago

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