diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2014-08-30 15:59:39 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2014-08-30 15:59:39 -0700 |
commit | f9caea823350640fb03195c73c301f08ce932bd0 (patch) | |
tree | be0e02155cf2f218c61379dde8ac98f100553392 /lib/vla.h | |
parent | 88366fcf88e5bccc4d0bcff798beb3ef27aaa496 (diff) | |
download | emacs-f9caea823350640fb03195c73c301f08ce932bd0.tar.gz emacs-f9caea823350640fb03195c73c301f08ce932bd0.tar.bz2 emacs-f9caea823350640fb03195c73c301f08ce932bd0.zip |
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
Diffstat (limited to 'lib/vla.h')
-rw-r--r-- | lib/vla.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/vla.h b/lib/vla.h new file mode 100644 index 00000000000..05125a7978e --- /dev/null +++ b/lib/vla.h @@ -0,0 +1,27 @@ +/* vla.h - variable length arrays + + Copyright 2014 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + Written by Paul Eggert. */ + +/* A function's argument must point to an array with at least N elements. + Example: 'int main (int argc, char *argv[VLA_ELEMS (argc)]);'. */ + +#ifdef __STDC_NO_VLA__ +# define VLA_ELEMS(n) +#else +# define VLA_ELEMS(n) static n +#endif |