Skip Menu |
Report information
Id: 132588
Status: open
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: sprout <sprout [at] cpan.org>
Cc:
AdminCc:

Operating System: (no value)
PatchStatus: (no value)
Severity: low
Type: unknown
Perl Version: (no value)
Fixed In: (no value)



Date: Fri, 15 Dec 2017 12:29:30 -0800
To: "perlbug [...] perl.org" <perlbug [...] perl.org>
Subject: In-place sort does not kill weak refs
From: Father Chrysostomos <sprout [...] cpan.org>
Download (untitled) / with headers
text/plain 2.8k
Oops. I sent this to perlbug-follow the first time. $ perl5.27.7 -le 'use Scalar::Util "weaken"; weaken ($a = \$_[0]); @_ = sort @_; print $a; print \$_[0]' SCALAR(0x7f8ad0805480) SCALAR(0x7f8ad0805480) The first line of output should be blank ($a should be undefined.) $ perl5.27.7 -V Summary of my perl5 (revision 5 version 27 subversion 7) configuration: Snapshot of: 2cb35ee012cfe486aa75a422e7bb3cb18ff51336 Platform: osname=darwin osvers=12.5.0 archname=darwin-2level uname='darwin pint.local 12.5.0 darwin kernel version 12.5.0: sun sep 29 13:33:47 pdt 2013; root:xnu-2050.48.12~1release_x86_64 x86_64 ' config_args='-de -Dusedevel' hint=recommended useposix=true d_sigaction=define useithreads=undef usemultiplicity=undef use64bitint=define use64bitall=define uselongdouble=undef usemymalloc=n default_inc_excludes_dot=define bincompat5005=undef Compiler: cc='cc' ccflags ='-fno-common -DPERL_DARWIN -mmacosx-version-min=10.8 -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -I/opt/local/include -DPERL_USE_SAFE_PUTENV' optimize='-O3' cppflags='-fno-common -DPERL_DARWIN -mmacosx-version-min=10.8 -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -I/opt/local/include' ccversion='' gccversion='4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.27)' gccosandvers='' intsize=4 longsize=8 ptrsize=8 doublesize=8 byteorder=12345678 doublekind=3 d_longlong=define longlongsize=8 d_longdbl=define longdblsize=16 longdblkind=3 ivtype='long' ivsize=8 nvtype='double' nvsize=8 Off_t='off_t' lseeksize=8 alignbytes=8 prototype=define Linker and Libraries: ld='cc' ldflags =' -mmacosx-version-min=10.8 -fstack-protector -L/usr/local/lib -L/opt/local/lib' libpth=/usr/local/lib /usr/bin/../lib/clang/4.2/lib /usr/lib /opt/local/lib libs=-lpthread -ldbm -ldl -lm -lutil -lc perllibs=-lpthread -ldl -lm -lutil -lc libc= so=dylib useshrplib=false libperl=libperl.a gnulibc_version='' Dynamic Linking: dlsrc=dl_dlopen.xs dlext=bundle d_dlsymun=undef ccdlflags=' ' cccdlflags=' ' lddlflags=' -mmacosx-version-min=10.8 -bundle -undefined dynamic_lookup -L/usr/local/lib -L/opt/local/lib -fstack-protector' Characteristics of this binary (from libperl): Compile-time options: HAS_TIMES PERLIO_LAYERS PERL_COPY_ON_WRITE PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP PERL_OP_PARENT PERL_PRESERVE_IVUV PERL_USE_DEVEL PERL_USE_SAFE_PUTENV USE_64_BIT_ALL USE_64_BIT_INT USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_LOCALE_TIME USE_PERLIO USE_PERL_ATOF Built under darwin Compiled at Nov 26 2017 13:47:48 @INC: /usr/local/lib/perl5/site_perl/5.27.7/darwin-2level /usr/local/lib/perl5/site_perl/5.27.7 /usr/local/lib/perl5/5.27.7/darwin-2level /usr/local/lib/perl5/5.27.7 /usr/local/lib/perl5/site_perl
Subject: Re: [perl #132588] In-place sort does not kill weak refs
From: Zefram <zefram [...] fysh.org>
To: perl5-porters [...] perl.org
Date: Fri, 15 Dec 2017 22:41:31 +0000
Download (untitled) / with headers
text/plain 585b
Father Chrysostomos wrote: Show quoted text
>$ perl5.27.7 -le 'use Scalar::Util "weaken"; weaken ($a = \$_[0]); @_ = sort @_; print $a; print \$_[0]'
After coming up with blessedness and then tiedness, I was wondering what other kinds of magic might be applied to an array element, and how sort would need to treat them. This one confirms that in general sort needs to take the slow path for any kind of magic. We don't distinguish between magic that's part of the container and magic that's part of the value, but we have little of the latter, so wouldn't lose much by not catering to it. -zefram
From: Dave Mitchell <davem [...] iabyn.com>
Subject: Re: [perl #132588] In-place sort does not kill weak refs
Date: Mon, 18 Dec 2017 09:58:00 +0000
CC: perl5-porters [...] perl.org
To: Zefram <zefram [...] fysh.org>
Download (untitled) / with headers
text/plain 953b
On Fri, Dec 15, 2017 at 10:41:31PM +0000, Zefram wrote: Show quoted text
> Father Chrysostomos wrote:
> >$ perl5.27.7 -le 'use Scalar::Util "weaken"; weaken ($a = \$_[0]); @_ = sort @_; print $a; print \$_[0]'
> > After coming up with blessedness and then tiedness, I was wondering what > other kinds of magic might be applied to an array element, and how sort > would need to treat them. This one confirms that in general sort needs > to take the slow path for any kind of magic. We don't distinguish between > magic that's part of the container and magic that's part of the value, but > we have little of the latter, so wouldn't lose much by not catering to it.
I think that by default, in-place sort should make a copy of every SV (thus emulating the action of pp_aassign) *except* for special cases of SV such as SvREFCNT == 1, no magic etc. -- I don't want to achieve immortality through my work... I want to achieve it through not dying. -- Woody Allen


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org