Vector-sorting fixes.
commitf9caea823350640fb03195c73c301f08ce932bd0
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 30 Aug 2014 22:59:39 +0000 (30 15:59 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 30 Aug 2014 22:59:39 +0000 (30 15:59 -0700)
treebe0e02155cf2f218c61379dde8ac98f100553392
parent88366fcf88e5bccc4d0bcff798beb3ef27aaa496
Vector-sorting fixes.

It's not safe to call qsort or qsort_r, since they have undefined
behavior if the user-specified predicate is not a total order.
Also, watch out for garbage-collection while sorting vectors.
* admin/merge-gnulib (GNULIB_MODULES): Add vla.
* configure.ac (qsort_r): Remove, as we no longer use qsort-like
functions.
* lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
* lib/vla.h, m4/vararrays.m4: New files, copied from gnulib.
* lib/stdlib.in.h, m4/stdlib_h.m4: Sync from gnulib, incorporating:
2014-08-29 qsort_r: new module, for GNU-style qsort_r
The previous two files' changes are boilerplate generated by
admin/merge-gnulib, and should not affect Emacs.
* src/fns.c: Include <vla.h>.
(sort_vector_predicate) [!HAVE_QSORT_R]: Remove.
(sort_vector_compare): Remove, replacing with ....
(inorder, merge_vectors, sort_vector_inplace, sort_vector_copy):
... these new functions.
(sort_vector): Rewrite to use the new functions.
GCPRO locals, since the predicate can invoke the GC.
Since it's in-place return void; caller changed.
(merge): Use 'inorder', for clarity.

Fixes: debbugs:18361
12 files changed:
ChangeLog
admin/ChangeLog
admin/merge-gnulib
configure.ac
lib/gnulib.mk
lib/stdlib.in.h
lib/vla.h [new file with mode: 0644]
m4/gnulib-comp.m4
m4/stdlib_h.m4
m4/vararrays.m4 [new file with mode: 0644]
src/ChangeLog
src/fns.c