Fix for redefined sort subs nastiness
authorGurusamy Sarathy <gsar@engin.umich.edu>
Fri, 9 May 1997 00:04:18 +0000 (20:04 -0400)
committerChip Salzenberg <chip@atlantic.net>
Wed, 7 May 1997 12:00:00 +0000 (00:00 +1200)
commite9e069932a0db06904b29e2b09a435afd40ed35c
tree72860dd0a183947dbf98cc8d6508993ae34d89aa
parenteb447b8692d1c89cd24ab421497dcff667570be4
Fix for redefined sort subs nastiness

>sub sortfunc { &once }
>sub once {
>    eval q{
> print "Eval from ", join(':', caller(0)), "\n";
> sub rest {
>     print "REST: $a <=> $b\n";
>     $a <=> $b
> }
>    };
>    *sortfunc = *rest;
>    &sortfunc;
>}
>@x = sort sortfunc 10, 5, 2.5, 1.25;

That misbehaves due to the redefinition of the sort sub
while the sort is active.  That's a big no-no, because
the sortcop was pointing to the CvSTART of the original,
and it will now point to freed memory (if the sub really
got undefined).

Here's a tested patch that does nothing but die under
that circumstance.

p5p-msgid: 199705090004.UAA15032@aatma.engin.umich.edu
op.c
pod/perldelta.pod
pod/perldiag.pod
sv.c
t/op/sort.t