Front page | perl.perl5.porters |
Postings from July 2008
[perl #57012] Result of FETCH not checked for overload?
From:
Steve Fink
Date:
July 16, 2008 14:40
Subject:
[perl #57012] Result of FETCH not checked for overload?
# New Ticket Created by "Steve Fink"
# Please include the string: [perl #57012]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=57012 >
This is a bug report for perl from sphink@gmail.com,
generated with the help of perlbug 1.35 running under perl v5.8.8.
-----------------------------------------------------------------
[Please enter your report here]
I have a tie'd variable %h that returns values from its FETCH()
routine that are blessed into a package that uses overloads.
When I use the += operator on the return value from that FETCH,
the overloading is ignored.
If I use the + operator, it works fine.
Example (uncomment the two commented-out lines to prove that
the overloading is ignored):
package Over;
use overload '+' => \&add;
#use overload '+=' => \&add2;
use overload '""' => \&toString;
sub add {
my ($a, $b, $swapped) = @_;
return bless [ $a->[0] + $b->[0], $a->[1] + $b->[1] ], 'Over';
}
#sub add2 { die "add2 called" }
sub toString {
my ($self) = @_;
return "<$self->[0],$self->[1]>";
}
package Tied;
sub TIEHASH {
my ($selfpkg, $data) = @_;
return bless \$data, $selfpkg;
}
sub FETCH {
my ($self, $key) = @_;
return bless [ $key, $key ], 'Over';
}
sub STORE {
my ($self, $key, $value) = @_;
print "STORE($key,$value) called\n";
}
package main;
my $v = bless [ 1, 2 ], 'Over';
my %h;
tie %h, 'Tied';
print "v = $v\n";
print "h{1} = $h{1}\n";
print "h{1} + [10,10] = ", ($h{1} + [10,10]), "\n";
print "h{1} += [10,10] = ", ($h{1} += [10,10]), "\n";
# The overloading was ignored on the previous line. It correctly
# fetched key '1' and converted it into a blessed ref, but then
# when it applied the += operator to the result, it didn't respect
# the overloading.
[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=core
severity=medium
---
This perlbug was built using Perl v5.8.8 in the Red Hat build system.
It is being executed now by Perl v5.8.8 - Thu Jan 3 23:26:16 PST 2008.
Site configuration information for perl v5.8.8:
Configured by Red Hat, Inc. at Thu Jan 3 23:26:16 PST 2008.
Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
Platform:
osname=linux, osvers=2.6.18-8.el5, archname=i386-linux-thread-multi
uname='linux bias.corp.reactrix.com 2.6.18-8.el5 #1 smp thu mar 15
19:57:35 edt 2007 i686 i686 i386 gnulinux '
config_args='-des -Doptimize=-O2 -g -march=i386 -mcpu=i686
-Dversion=5.8.8 -Dmyhostname=localhost -Dperladmin=root@localhost
-Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr
-Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr
-Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_mymalloc
-Dusemymalloc -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm
-Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl=n
-Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr
-Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_r_proto
-Ud_endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endservent_r_proto
-Ud_setservent_r_proto -Dinc_version_list=5.8.7 5.8.6 5.8.5
-Dscriptdir=/usr/bin'
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=undef use64bitall=undef uselongdouble=undef
usemymalloc=y, bincompat5005=undef
Compiler:
cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING
-fno-strict-aliasing -pipe -Wdeclaration-after-statement
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
-I/usr/include/gdbm',
optimize='-O2 -g -march=i386 -mcpu=i686',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING
-fno-strict-aliasing -pipe -Wdeclaration-after-statement
-I/usr/local/include -I/usr/include/gdbm'
ccversion='', gccversion='4.1.1 20070105 (Red Hat 4.1.1-52)',
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 =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=/lib/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/i386-linux-thread-multi/CORE'
cccdlflags='-fPIC', lddlflags='-shared -O2 -g -march=i386
-mcpu=i686 -L/usr/local/lib'
Locally applied patches:
---
@INC for perl v5.8.8:
/dummy/first_is_skipped
/home/tools/lib/CentOS-5
/home/tools/lib
/dummy/first_is_skipped
/home/tools/lib/CentOS-5
/home/tools/lib
/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.8
/usr/lib/perl5/site_perl/5.8.7
/usr/lib/perl5/site_perl/5.8.6
/usr/lib/perl5/site_perl/5.8.5
/usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.8
/usr/lib/perl5/vendor_perl/5.8.7
/usr/lib/perl5/vendor_perl/5.8.6
/usr/lib/perl5/vendor_perl/5.8.5
/usr/lib/perl5/vendor_perl
/usr/lib/perl5/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/5.8.8
.
---
Environment for perl v5.8.8:
HOME=/home/sfink
LANG=en_US
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/home/tools/bin:/usr/lib/ccache/bin:/home/sfink/bin:/sbin:/usr/sbin:/home/sfink/Rx/scripts/bin:/bin:/usr/bin:/usr/local/reactrix/rms_client/bin:/usr/local/reactrix/bin:/usr/X11R6/bin:/home/tools/Ops/bin:/home/tools/bin-CentOS-5:/home/sfink/Rx-pilot/bin/linux-pentium4-2.5-debug
PERL5LIB=/dummy/first_is_skipped:/home/tools/lib/CentOS-5:/home/tools/lib:/dummy/first_is_skipped:/home/tools/lib/CentOS-5:/home/tools/lib:
PERL_BADLANG (unset)
SHELL=/bin/zsh
-
[perl #57012] Result of FETCH not checked for overload?
by Steve Fink