develooper Front page | perl.perl5.porters | Postings from April 2002

Re: [ID 20010821.007] sort stupidness caused segfault

Thread Previous
From:
John P. Linderman
Date:
April 15, 2002 07:49
Subject:
Re: [ID 20010821.007] sort stupidness caused segfault
Message ID:
200204151449.KAA93538@raptor.research.att.com
Hugo noted:
> A while back, "Abigail" <abigail@foad.org> wrote:
> :On Wed, Aug 22, 2001 at 07:17:07AM -0400, John P. Linderman wrote:
>
> This still dumps with latest bleadperl. Here's a shorter test case:
>   ./perl -wle '@a=(1..8); @a = sort { @a = (0) } @a'
> ... and each occurrence of @a appears to be required for the coredump.
> 
> Hugo

I'm woefully ignorant of the setup prior to the sorting itself.
(So I can't offer any insight into the
 sub s1 { goto &s2 } sub s2 { $a cmp $b } print sort s1 (3, 2, 1)
problem, either).

I know that mergesort makes yet another copy of all the references
to the original list passed to sort, as does the stabilized qsort.
If the array is changed as part of the comparison routine, these
references are going who-knows-where.  Even if it is possible to
check on the validity of the reference, it's not obvious (to me)
that the overhead *all* users would have to pay is worth the
protection provided to way-out users.

Should a warning against modifying the array as a side-effect
of the comparison routine be added to the documentation?  -- jpl


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About