Perl / perl5

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

I believe I found a bug with Readonly::XS that might actually be a guts bug. #9307

Closed p5pRT closed 16 years ago

p5pRT commented 16 years ago

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

Searchable as RT53482$

p5pRT commented 16 years ago

From manchicken@manchicken.com

Created by manchicken@manchicken.com

### In the file "Bill/Constants.pm"\, I have the following​:

package Bill​::Constants;

Readonly our $RETACT_DO_RETURN => 1; Readonly our $RETACT_DO_CANCEL => 2; Readonly our $RETACT_DO_MARK_FRAUD => 4; Readonly our $RETACT_DO_EMAIL_CONFIRM => 8; Readonly our $RETACT_EVERYTHING => $RETACT_DO_RETURN| $RETACT_DO_CANCEL|$RETACT_DO_MARK_FRAUD|$RETACT_DO_EMAIL_CONFIRM;

1;

### Then on the command line I do...

manchicken@​thepea​:\~/projects/billing$ perl -e 'use Devel​::Peek;use Bill​::Constants; print STDERR "$RETACT_EVERYTHING\n \n";Dump($RETACT_EVERYTHING);' && echo

### And here's my output ?

SV = PVMG(0x71ede0) at 0x620c30   REFCNT = 2   FLAGS = (GMG\,SMG\,RMG\,pPOK)   IV = 0   NV = 0   PV = 0x621d80 "?"\0   CUR = 1   LEN = 8   MAGIC = 0x7207d0   MG_VIRTUAL = &PL_vtbl_packelem   MG_TYPE = PERL_MAGIC_tiedscalar(q)   MG_FLAGS = 0x02   REFCOUNTED   MG_OBJ = 0x71f590   SV = RV(0x63fdd8) at 0x71f590   REFCNT = 1   FLAGS = (ROK)   RV = 0x71f580   SV = PVMG(0x71eda8) at 0x71f580   REFCNT = 1   FLAGS = (PADBUSY\,PADMY\,OBJECT\,POK\,pPOK)   IV = 0   NV = 0   PV = 0x7207b0 "?"\0   CUR = 1   LEN = 8   STASH = 0x681c60 "Readonly​::Scalar"

### I have the following versions​: $Readonly​::XS​::VERSION == 1.04 $Readonly​::VERSION == 1.03

Perl Info ``` Flags: category=core severity=medium Site configuration information for perl v5.8.8: Configured by Debian Project at Tue Nov 27 10:55:30 GMT 2007. Summary of my perl5 (revision 5 version 8 subversion 8) configuration: Platform: osname=linux, osvers=2.6.15.7, archname=x86_64-linux-gnu-thread-multi uname='linux yellow 2.6.15.7 #1 smp sun sep 23 13:51:52 utc 2007 x86_64 gnulinux ' config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=x86_64-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.8 -Dsitearch=/usr/local/lib/perl/5.8.8 -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 -Duseshrplib -Dlibperl=libperl.so.5.8.8 -Dd_dosuid -des' 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 -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include' ccversion='', gccversion='4.2.3 20071123 (prerelease) (Ubuntu 4.2.2-3ubuntu4)', 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/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt perllibs=-ldl -lm -lpthread -lc -lcrypt libc=/lib/libc-2.6.1.so, so=so, useshrplib=true, libperl=libperl.so.5.8.8 gnulibc_version='2.6.1' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib' Locally applied patches: @INC for perl v5.8.8: /home/manchicken/projects/billing/lib /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/Bundle /home/manchicken/projects/notsosoft/lib /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl . Environment for perl v5.8.8: HOME=/home/manchicken LANG=en_US.UTF-8 LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/manchicken/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/manchicken/bin:/home/manchicken/projects/billing/misc/examples PERL5LIB=/home/manchicken/projects/billing/lib:/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi:/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/Bundle:/home/manchicken/projects/notsosoft/lib PERL_BADLANG (unset) SHELL=/bin/bash -- Michael D. Stemle, Jr. manchicken.com ```
p5pRT commented 16 years ago

From manchicken@manchicken.com

Attached is a copy of a simple script that also fails in the same manner (using much the same code)

On Mon\, 2008-04-28 at 18​:01 -0700\, perlbug-followup@​perl.org wrote​:

#53482 -- Michael D. Stemle\, Jr. \manchicken@​manchicken\.com manchicken.com

p5pRT commented 16 years ago

From manchicken@manchicken.com

readonly_bug.pl

p5pRT commented 16 years ago

From p5p@perl.wizbit.be

First let's get this out of the way​:

? = "1" | "2" | "4" | "8"\, \< = "4" | "8"\,

Meaning​: if you see ? then it used strings and not the numbers.

First observation​:

perl -wle 'my $x=4 ;my $y=8 ;print $x | $y;' # prints 12 perl -wle 'my $x="4";my $y="8";print $x | $y;' # prints \< perl -wle 'my $x="4";my $y="8";print 0 | $x | $y;' # prints 12

(which is ok/expected)

Second observation​:

#!/usr/bin/perl -l

use Readonly;

Readonly my $RETACT_DO_MARK_FRAUD => 4; Readonly my $RETACT_DO_EMAIL_CONFIRM => 8; print $RETACT_DO_MARK_FRAUD|$RETACT_DO_EMAIL_CONFIRM; print $RETACT_DO_MARK_FRAUD|$RETACT_DO_EMAIL_CONFIRM; __END__

Output​: \< 12

This shows that it first used the string "4" and the string "8" and
after that the number 4 and the number 8.

But I find this somewhat confusing...

perl -wle 'my $x="4";my $y="8";print $x | $y;print $x | $y' # prints
\< \< and not \< 12.

Looking deeper​:

perl -wle 'use Tie​::Scalar;use base qw/Tie​::StdScalar/;tie my $x\,
"main"\, 4;tie my $y\, "main"\, 8;for (1 .. 2) { print $x | $y }'

Also prints \< and 12.

Taking Tie​::Scalar out of the picture​:

perl -wle 'sub TIESCALAR { my $foo = $_[1]; bless \$foo\, "main"; };sub
FETCH { ${ $_[0]} } ;tie my $x\, "main"\, 4;tie my $y\, "main"\, 8;for (1
.. 2) { print $x | $y }'

Also prints \< and 12.

So could this be a problem with how tie works?

Kind regards\,

Bram

p5pRT commented 16 years ago

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

p5pRT commented 16 years ago

From p5p@perl.wizbit.be

$cat foo.pl

#!/usr/bin/perl -l

sub TIESCALAR {   my $foo = $_[1];   bless \$foo\, "main"; };

sub FETCH { ${ $_[0]} }; tie my $x\, "main"\, 4; tie my $y\, "main"\, 8; for (1 .. 2) { print $x | $y }

perl588 foo.pl # \< and 12 perl5100 foo.pl # 12 and 12 perl-blead foo.pl # 12 and 12

So this was resolved in perl 5.10.

A workarround is to use Readonly our $RETACT_EVERYTHING => 0|$RETACT_DO_RETURN| $RETACT_DO_CANCEL|$RETACT_DO_MARK_FRAUD|$RETACT_DO_EMAIL_CONFIRM;

Kind regards\,

Bram

p5pRT commented 16 years ago

From @nwc10

On Tue\, Apr 29\, 2008 at 01​:29​:24PM +0200\, Bram wrote​:

$cat foo.pl

#!/usr/bin/perl -l

sub TIESCALAR { my $foo = $_[1]; bless \$foo\, "main"; };

sub FETCH { ${ $_[0]} }; tie my $x\, "main"\, 4; tie my $y\, "main"\, 8; for (1 .. 2) { print $x | $y }

perl588 foo.pl # \< and 12 perl5100 foo.pl # 12 and 12 perl-blead foo.pl # 12 and 12

So this was resolved in perl 5.10.

The upcoming 5.8.9 will have the same behaviour as 5.10. I don't know which source code change changed this behaviour.

Nicholas Clark

p5pRT commented 16 years ago

p5p@spam.wizbit.be - Status changed from 'open' to 'resolved'

p5pRT commented 16 years ago

From p5p@perl.wizbit.be

I don't know which source code change changed this behaviour.

See patch 27633 which introduced a test marking that the READONLY
bug had been fixed\, but I counted tell which source code change had
fixed it.

Attached patch adds 3 tests to make sure the output stays the same.

Kind regards\,

Bram

p5pRT commented 16 years ago

From p5p@perl.wizbit.be

Inline Patch ```diff --- old/t/op/tie.t 2008-04-29 14:41:38.000000000 +0200 +++ new/t/op/tie.t 2008-04-29 14:53:41.000000000 +0200 @@ -586,13 +586,19 @@ EXPECT 01 ######## +# Bug 53482 (and maybe others) sub TIESCALAR { my $foo = $_[1]; bless \$foo, $_[0] } sub FETCH { ${$_[0]} } -tie my $x, "main", 2; -tie my $y, "main", 8; -print $x | $y; +tie my $x1, "main", 2; +tie my $y1, "main", 8; +print $x1 | $y1; +print $x1 | $y1; +tie my $x2, "main", "2"; +tie my $y2, "main", "8"; +print $x2 | $y2; +print $x2 | $y2; EXPECT -10 +1010:: ######## # Bug 36267 sub TIEHASH { bless {}, $_[0] } ```
p5pRT commented 16 years ago

From Robin.Barker@npl.co.uk

From​: Nicholas Clark [mailto​:nick@​flirble.org]On

The upcoming 5.8.9 will have the same behaviour as 5.10. I don't know which source code change changed this behaviour.

See patch 27633 which introduced a test marking that the READONLY bug had been fixed\, but I counted tell which source code change had fixed it.

Robin


This e-mail and any attachments may contain confidential and/or privileged material; it is for the intended addressee(s) only. If you are not a named addressee\, you must not use\, retain or disclose such information.

NPL Management Ltd cannot guarantee that the e-mail or any attachments are free from viruses.

NPL Management Ltd. Registered in England and Wales. No​: 2937881 Registered Office​: Serco House\, 16 Bartley Wood Business Park\,   Hook\, Hampshire\, United Kingdom RG27 9UY


p5pRT commented 16 years ago

From Robin.Barker@npl.co.uk

From​: Robin Barker [mailto​:Robin.Barker@​npl.co.uk]

See patch 27633 which introduced a test marking that the READONLY bug had been fixed\, but I counted tell which source code change had fixed it. =====> couldn't

Robin


This e-mail and any attachments may contain confidential and/or privileged material; it is for the intended addressee(s) only. If you are not a named addressee\, you must not use\, retain or disclose such information.

NPL Management Ltd cannot guarantee that the e-mail or any attachments are free from viruses.

NPL Management Ltd. Registered in England and Wales. No​: 2937881 Registered Office​: Serco House\, 16 Bartley Wood Business Park\,   Hook\, Hampshire\, United Kingdom RG27 9UY


p5pRT commented 16 years ago

From Robin.Barker@npl.co.uk

From​: Nicholas Clark [mailto​:nick@​flirble.org]On

The upcoming 5.8.9 will have the same behaviour as 5.10. I don't know which source code change changed this behaviour.

Perhaps change 26192. That was my guess when I submitted change 27633.

Robin


This e-mail and any attachments may contain confidential and/or privileged material; it is for the intended addressee(s) only. If you are not a named addressee\, you must not use\, retain or disclose such information.

NPL Management Ltd cannot guarantee that the e-mail or any attachments are free from viruses.

NPL Management Ltd. Registered in England and Wales. No​: 2937881 Registered Office​: Serco House\, 16 Bartley Wood Business Park\,   Hook\, Hampshire\, United Kingdom RG27 9UY


p5pRT commented 16 years ago

From @andk

On Tue\, 29 Apr 2008 16​:54​:24 +0100\, "Robin Barker" \Robin\.Barker@&#8203;npl\.co\.uk said​:

  > From​: Nicholas Clark [mailto​:nick@​flirble.org]On

The upcoming 5.8.9 will have the same behaviour as 5.10. I don't know which source code change changed this behaviour.

  > Perhaps change 26192. That was my guess when I submitted change 27633.

My binary search says 22074​:

  ----Program----   #!/usr/bin/perl -l

  sub TIESCALAR {   my $foo = $_[1];   bless \$foo\, "main";   };

  sub FETCH { ${ $_[0]} };   tie my $x\, "main"\, 4;   tie my $y\, "main"\, 8;   for (1 .. 2) { print $x | $y }

  ----Output of .../p7dcK3N/perl-5.9.0@​22071/bin/perl----   \<   12

  ----EOF ($?='0')----   ----Output of .../pvpF9Iw/perl-5.9.0@​22074/bin/perl----   12   12

  ----EOF ($?='0')----

-- andreas

p5pRT commented 16 years ago

From Robin.Barker@npl.co.uk

From​: Andreas J. Koenig

My binary search says 22074

Looks like their are two bugs and two fixes

When does the following program give "​:" not 10.

Thanks

Robin

  ----Program----   #!/usr/bin/perl -l

  sub TIESCALAR {   my $foo = $_[1];   bless \$foo\, "main";   };

  sub FETCH { ${ $_[0]} };   tie my $x\, "main"\, 2;   tie my $y\, "main"\, 8;   print $x | $y;


This e-mail and any attachments may contain confidential and/or privileged material; it is for the intended addressee(s) only. If you are not a named addressee\, you must not use\, retain or disclose such information.

NPL Management Ltd cannot guarantee that the e-mail or any attachments are free from viruses.

NPL Management Ltd. Registered in England and Wales. No​: 2937881 Registered Office​: Serco House\, 16 Bartley Wood Business Park\,   Hook\, Hampshire\, United Kingdom RG27 9UY


p5pRT commented 16 years ago

From @andk

On Wed\, 30 Apr 2008 08​:39​:10 +0100\, "Robin Barker" \Robin\.Barker@&#8203;npl\.co\.uk said​:

  > From​: Andreas J. Koenig

My binary search says 22074

  > Looks like their are two bugs and two fixes

  > When does the following program give "​:" not 10.

Same thing.

----Program---- #!/usr/bin/perl -l

  sub TIESCALAR {   my $foo = $_[1];   bless \$foo\, "main";   };

  sub FETCH { ${ $_[0]} };   tie my $x\, "main"\, 2;   tie my $y\, "main"\, 8;   print $x | $y;

----Output of .../p7dcK3N/perl-5.9.0@​22071/bin/perl---- :

----EOF ($?='0')---- ----Output of .../pvpF9Iw/perl-5.9.0@​22074/bin/perl---- 10

----EOF ($?='0')----

-- andreas

p5pRT commented 14 years ago

From @smpeters

Thanks! This has been applied as change 7de9d14.

Steve Peters steve@​fisharerojo.org

On Tue\, Apr 29\, 2008 at 8​:00 AM\, Bram \p5p@&#8203;perl\.wizbit\.be wrote​:

I don't know which source code change changed this behaviour.

See patch 27633 which introduced a test marking that the READONLY  bug had been fixed\, but I counted tell which source code change had  fixed it.

Attached patch adds 3 tests to make sure the output stays the same.

Kind regards\,

Bram