Re: Sorting lists of integers doesn't always work
authorGurusamy Sarathy <gsar@engin.umich.edu>
Wed, 9 Oct 1996 03:54:47 +0000 (23:54 -0400)
committerAndy Dougherty <doughera@lafcol.lafayette.edu>
Wed, 9 Oct 1996 03:54:47 +0000 (23:54 -0400)
>> >       print sort (4,1,2,3);
>> >
>> > actually prints "4123", i.e. doesn't actually sort.   Bug?  Feature?

This broke between 5.001n and 5.002.  There was a long winded thread
about sorting undefs in some order (rather than coredumping) around
the 5.002beta times (search for "bogorefs" in the subject-line on
p5p archive for details). Larry added in some code that presumes that
the private flags are set by the time qsort() is called:

Unfortunately, sv_2pv() does not set the POKp flag, so the above
code breaks!  Here's a patch against 5.00306.

sv.c

diff --git a/sv.c b/sv.c
index b155eee..0af82f7 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -1517,7 +1517,7 @@ STRLEN *lp;
        s = SvGROW(sv, len + 1);
        SvCUR_set(sv, len);
        (void)strcpy(s, tokenbuf);
-       /* NO SvPOK_on(sv) here! */
+       SvPOKp_on(sv);
        return s;
     }
 }