Front page | perl.perl5.porters |
Postings from June 2009
[perl #66970] Incorrect coderef in MODIFY_CODE_ATTRIBUTES
From:
perlbug-followup
Date:
June 26, 2009 07:59
Subject:
[perl #66970] Incorrect coderef in MODIFY_CODE_ATTRIBUTES
Message ID:
rt-3.6.HEAD-7634-1245963475-543.66970-75-0@perl.org
# New Ticket Created by alan@pit27.pair.com
# Please include the string: [perl #66970]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=66970 >
This is a bug report for perl from alan@pit27.pair.com,
generated with the help of perlbug 1.39 running under perl v5.8.9.
-----------------------------------------------------------------
[Please describe your issue here]
If you use an attribute on a sub definition which has already had a
reference made to it previously in the current compilation, or which
has already had another attribute applied to it in a separate sub
declaration, any attributes added at sub definition time cause
MODIFY_CODE_ATTRIBUTES to receive a bogus coderef for the sub.
I can reproduce this bug in perl 5.8.9 and perl 5.10.0, on freebsd 6.
* Sample code:
#!/usr/local/bin/perl
use strict;
sub MODIFY_CODE_ATTRIBUTES {
my ($pkg, $code, @att) = @_;
warn "MODIFY_CODE_ATTRIBUTE for $code\n";
return;
}
BEGIN { print "* sub foo has a reference constructed at compile time\n" }
BEGIN { warn " BEGIN before: ". \&foo. "\n" }
sub foo : declaration {}
BEGIN { warn " BEGIN after: ". \&foo. "\n" }
BEGIN { print "\n* sub bar has multiple attribute declarations\n" }
sub bar : before;
sub bar : declaration {}
sub bar : after;
BEGIN { print "\n* sub baz is free from interference\n" }
sub baz : declaration {}
print "\n* foo is: ", \&foo, "\n";
print "* bar is: ", \&bar, "\n";
print "* baz is: ", \&baz, "\n";
__END__
* Sample buggy output:
* sub foo has a reference constructed at compile time
BEGIN before: CODE(0x806b130)
MODIFY_CODE_ATTRIBUTE for CODE(0x806b124)
BEGIN after: CODE(0x806b130)
* sub bar has multiple attribute declarations
MODIFY_CODE_ATTRIBUTE for CODE(0x806b178)
MODIFY_CODE_ATTRIBUTE for CODE(0x806b0a0)
MODIFY_CODE_ATTRIBUTE for CODE(0x806b178)
* sub baz is free from interference
MODIFY_CODE_ATTRIBUTE for CODE(0x806b1b4)
* foo is: CODE(0x806b130)
* bar is: CODE(0x806b178)
* baz is: CODE(0x806b1b4)
In the output above, sub foo's MODIFY_CODE_ATTRIBUTES $code ref does not
match the reference taken before the sub definition. bar's $code in
MODIFY_CODE_ATTRIBUTES is different in the case where the attribute is
directly added to the sub as it is being defined. baz's $code matches,
and no reference to sub baz existed prior to adding the attribute at
sub definition time.
This bug prevents the use of MODIFY_CODE_ATTRIBUTES to consistently store
metadata about a coderef if an attribute is added at sub definition time.
Instead, it requires that all attributes be added in separate attribute
declarations.
I haven't looked at the code, but my guess is that the attribute system is
constructing a random coderef at sub definition time, and passing it to
MODIFY_CODE_ATTRIBUTES, but then the coderef is not installed into the
symbol table because there is already another code ref there.
Thank you for your help,
Alan Ferrency
[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=core
severity=low
---
Site configuration information for perl v5.8.9:
Configured by alan at Tue Jun 16 16:19:31 EDT 2009.
Summary of my perl5 (revision 5 version 8 subversion 9) configuration:
Platform:
osname=freebsd, osvers=6.1-stable, archname=i386-freebsd-64int
uname='freebsd pit27.pair.com 6.1-stable freebsd 6.1-stable #3: tue may 16 12:04:45 edt 2006 cap@pit54.pair.com:usrsrcsysi386compilepair_ws i386 '
config_args='-sde -Dprefix=/usr/local -Darchlib=/usr/local/lib/perl5/5.8.9/mach -Dprivlib=/usr/local/lib/perl5/5.8.9 -Dman3dir=/usr/local/lib/perl5/5.8.9/perl/man/man3 -Dman1dir=/usr/local/man/man1 -Dsitearch=/usr/local/lib/perl5/site_perl/5.8.9/mach -Dsitelib=/usr/local/lib/perl5/site_perl/5.8.9 -Dscriptdir=/usr/local/bin -Dsiteman3dir=/usr/local/lib/perl5/5.8.9/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Ui_malloc -Ui_iconv -Uinstallusrbinperl -Dcc=cc -Duseshrplib -Dinc_version_list=none -Dccflags=-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.9/BSDPAN" -Doptimize=-O2 -fno-strict-aliasing -pipe -Ud_dosuid -Ui_gdbm -Dusethreads=n -Dusemymalloc=y -Duse64bitint'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=define use64bitall=undef uselongdouble=undef
usemymalloc=y, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.9/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe -I/usr/local/include',
optimize='-O2 -fno-strict-aliasing -pipe',
cppflags='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.9/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe -I/usr/local/include'
ccversion='', gccversion='3.4.4 [FreeBSD] 20050518', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -Wl,-E -L/usr/local/lib'
libpth=/usr/lib /usr/local/lib
libs=-lgdbm -lm -lcrypt -lutil
perllibs=-lm -lcrypt -lutil
libc=, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' -Wl,-R/usr/local/lib/perl5/5.8.9/mach/CORE'
cccdlflags='-DPIC -fPIC', lddlflags='-shared -L/usr/local/lib'
Locally applied patches:
defined-or
---
@INC for perl v5.8.9:
/usr/local/lib/perl5/5.8.9/BSDPAN
/usr/local/lib/perl5/site_perl/5.8.9/mach
/usr/local/lib/perl5/site_perl/5.8.9
/usr/local/lib/perl5/5.8.9/mach
/usr/local/lib/perl5/5.8.9
.
---
Environment for perl v5.8.9:
HOME=/usr/home/staff/alan
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/X11R6/bin:/usr/home/staff/alan/bin
PERL_BADLANG (unset)
SHELL=/usr/local/bin/zsh
-
[perl #66970] Incorrect coderef in MODIFY_CODE_ATTRIBUTES
by perlbug-followup