diff options
author | Tom Tromey <tom@tromey.com> | 2017-10-12 15:46:42 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-10-16 16:10:19 -0600 |
commit | b05628f0a878cdd64492bbc49d60003d699763ad (patch) | |
tree | 05aa5dc663a74684958a62003cec8af989d4c993 /gdb/buildsym.c | |
parent | 739b3f1d8ff7072dcc66240c25b026c6433bda1a (diff) | |
download | gdb-b05628f0a878cdd64492bbc49d60003d699763ad.zip gdb-b05628f0a878cdd64492bbc49d60003d699763ad.tar.gz gdb-b05628f0a878cdd64492bbc49d60003d699763ad.tar.bz2 |
Use std::vector in end_symtab_get_static_block
Change end_symtab_get_static_block to use std::vector. This removes a
cleanup.
ChangeLog
2017-10-16 Tom Tromey <tom@tromey.com>
* buildsym.c (block_compar): Remove.
(end_symtab_get_static_block): Use std::vector.
Diffstat (limited to 'gdb/buildsym.c')
-rw-r--r-- | gdb/buildsym.c | 39 |
1 files changed, 11 insertions, 28 deletions
diff --git a/gdb/buildsym.c b/gdb/buildsym.c index cbad027..c556ac1 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -86,6 +86,7 @@ #include "cp-support.h" #include "dictionary.h" #include "addrmap.h" +#include <algorithm> /* Ask buildsym.h to define the vars it normally declares `extern'. */ #define EXTERN @@ -1165,19 +1166,6 @@ watch_main_source_file_lossage (void) } } -/* Helper function for qsort. Parameters are `struct block *' pointers, - function sorts them in descending order by their BLOCK_START. */ - -static int -block_compar (const void *ap, const void *bp) -{ - const struct block *a = *(const struct block **) ap; - const struct block *b = *(const struct block **) bp; - - return ((BLOCK_START (b) > BLOCK_START (a)) - - (BLOCK_START (b) < BLOCK_START (a))); -} - /* Reset state after a successful building of a symtab. This exists because dbxread.c and xcoffread.c can call start_symtab+end_symtab multiple times after one call to buildsym_init, @@ -1254,28 +1242,23 @@ end_symtab_get_static_block (CORE_ADDR end_addr, int expandable, int required) if ((objfile->flags & OBJF_REORDERED) && pending_blocks) { - unsigned count = 0; struct pending_block *pb; - struct block **barray, **bp; - struct cleanup *back_to; - - for (pb = pending_blocks; pb != NULL; pb = pb->next) - count++; - barray = XNEWVEC (struct block *, count); - back_to = make_cleanup (xfree, barray); + std::vector<block *> barray; - bp = barray; for (pb = pending_blocks; pb != NULL; pb = pb->next) - *bp++ = pb->block; + barray.push_back (pb->block); - qsort (barray, count, sizeof (*barray), block_compar); + std::sort (barray.begin (), barray.end (), + [] (const block *a, const block *b) + { + /* Sort blocks in descending order. */ + return BLOCK_START (a) > BLOCK_START (b); + }); - bp = barray; + int i = 0; for (pb = pending_blocks; pb != NULL; pb = pb->next) - pb->block = *bp++; - - do_cleanups (back_to); + pb->block = barray[i++]; } /* Cleanup any undefined types that have been left hanging around |