Front page | perl.perl5.porters |
Postings from February 2012
[perl #109744] referenced constant loses readonlyness
Thread Previous
From:
Zefram
Date:
February 3, 2012 08:09
Subject:
[perl #109744] referenced constant loses readonlyness
Message ID:
rt-3.6.HEAD-14510-1328285032-1371.109744-75-0@perl.org
# New Ticket Created by Zefram
# Please include the string: [perl #109744]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=109744 >
This is a bug report for perl from zefram@fysh.org,
generated with the help of perlbug 1.39 running under perl 5.15.7.
-----------------------------------------------------------------
[Please describe your issue here]
On a threading Perl, a list-mode refgen applied to a constant will
copy the constant rather than reference it. An srefgen, however, will
reference it, and either will work correctly on a non-threading Perl:
$ perl-single -MDevel::Peek -lwe '$sref = \123; Dump $sref; ($lref,undef) = \(123,2); Dump $lref;'
SV = IV(0x80969a4) at 0x80969a8
REFCNT = 1
FLAGS = (ROK)
RV = 0x8096988
SV = IV(0x8096984) at 0x8096988
REFCNT = 2
FLAGS = (IOK,READONLY,pIOK)
IV = 123
SV = IV(0x80969c4) at 0x80969c8
REFCNT = 1
FLAGS = (ROK)
RV = 0x80969e8
SV = IV(0x80969e4) at 0x80969e8
REFCNT = 2
FLAGS = (IOK,READONLY,pIOK)
IV = 123
$ perl-threads -MDevel::Peek -lwe '$sref = \123; Dump $sref; ($lref,undef) = \(123,2); Dump $lref;'
SV = IV(0x8617e50) at 0x8617e54
REFCNT = 1
FLAGS = (ROK)
RV = 0x8617e34
SV = IV(0x8617e30) at 0x8617e34
REFCNT = 2
FLAGS = (IOK,READONLY,pIOK)
IV = 123
SV = IV(0x8617e70) at 0x8617e74
REFCNT = 1
FLAGS = (ROK)
RV = 0x85fd7b4
SV = IV(0x85fd7b0) at 0x85fd7b4
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 123
I presume that this copy is being performed by S_refto() in pp.c, in
the SvPADTMP(sv) branch. This would occur because the constant goes
into the pad, and gets marked PADTMP, on a threading Perl:
$ perl-single -MDevel::Peek -lwe 'Dump 123'
SV = IV(0x97ae934) at 0x97ae938
REFCNT = 1
FLAGS = (IOK,READONLY,pIOK)
IV = 123
$ perl-threads -MDevel::Peek -lwe 'Dump 123'
SV = IV(0x831dde8) at 0x831ddec
REFCNT = 1
FLAGS = (PADTMP,IOK,READONLY,pIOK)
IV = 123
The srefgen case behaves itself because it's constant-folded before the
constant moves to the pad. An srefgen that can't constant-fold will go
wrong in the same way as the list-mode refgen:
$ perl-single -MDevel::Peek -lwe 'sub dumpref($) { Dump \$_[0]; } dumpref 123'
SV = IV(0x9628074) at 0x9628078
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x9637990
SV = IV(0x963798c) at 0x9637990
REFCNT = 2
FLAGS = (IOK,READONLY,pIOK)
IV = 123
$ perl-threads -MDevel::Peek -lwe 'sub dumpref($) { Dump \$_[0]; } dumpref 123'
SV = IV(0x873f8f0) at 0x873f8f4
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x873f7b4
SV = IV(0x873f7b0) at 0x873f7b4
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 123
It seems awfully wrong for S_refto() to ever copy the referent. I don't
know enough about the pad to see how it should be changed, though.
[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=core
severity=low
---
Site configuration information for perl 5.15.7:
Configured by zefram at Sat Jan 21 18:33:38 GMT 2012.
Summary of my perl5 (revision 5 version 15 subversion 7) configuration:
Platform:
osname=linux, osvers=2.6.32-5-686, archname=i386-linux-thread-multi
uname='linux vigo.rous.org 2.6.32-5-686 #1 smp thu nov 3 04:23:54 utc 2011 i686 gnulinux '
config_args='-des -Darchname=i386-linux -Dcccdlflags=-fPIC -Dccdlflags=-rdynamic -Dprefix=/home/zefram/usr/perl/perl_install/perl-5.15.7-i32-f52 -Dman1ext=1 -Dman3ext=3perl -Duselargefiles -Dusethreads -Uafs -Ud_csh -Uusesfio -Uusenm -Duseshrplib -Dusedevel -Uversiononly -Ui_db'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
ccversion='', gccversion='4.4.5', 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 =' -fstack-protector -L/usr/local/lib'
libpth=/usr/local/lib /lib/../lib /usr/lib/../lib /lib /usr/lib /usr/lib64
libs=-lnsl -lgdbm -ldl -lm -lcrypt -lutil -lpthread -lc -lgdbm_compat
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=/lib/libc-2.11.2.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.11.2'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/home/zefram/usr/perl/perl_install/perl-5.15.7-i32-f52/lib/5.15.7/i386-linux-thread-multi/CORE'
cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'
Locally applied patches:
---
@INC for perl 5.15.7:
/home/zefram/usr/perl/perl_install/perl-5.15.7-i32-f52/lib/site_perl/5.15.7/i386-linux-thread-multi
/home/zefram/usr/perl/perl_install/perl-5.15.7-i32-f52/lib/site_perl/5.15.7
/home/zefram/usr/perl/perl_install/perl-5.15.7-i32-f52/lib/5.15.7/i386-linux-thread-multi
/home/zefram/usr/perl/perl_install/perl-5.15.7-i32-f52/lib/5.15.7
.
---
Environment for perl 5.15.7:
HOME=/home/zefram
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/home/zefram/usr/perl/perl_install/perl-5.15.7-i32-f52/bin:/home/zefram/usr/perl/util:/home/zefram/pub/i686-pc-linux-gnu/bin:/home/zefram/pub/common/bin:/usr/bin:/bin:/usr/local/bin:/usr/games
PERL_BADLANG (unset)
SHELL=/usr/bin/zsh
Thread Previous