#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
}
}
-/* 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,
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