Make qsort_r usage "portable". Why does a function which seems so simple

have to be so complicated?

llvm-svn: 105797
This commit is contained in:
Eli Friedman 2010-06-10 23:36:31 +00:00
parent c27ee0fd29
commit a92e332b09
2 changed files with 10 additions and 0 deletions

View File

@ -60,6 +60,7 @@ protected:
typedef collection::const_iterator const_iterator;
static int CompareSymbolValueByIndex (void *thunk, const void *a, const void *b);
static int CompareSymbolValueByIndexLinux (const void *a, const void *b, void *thunk);
void InitNameIndexes ();
void InitAddressIndexes ();

View File

@ -251,6 +251,10 @@ Symtab::CompareSymbolValueByIndex (void *thunk, const void *a, const void *b)
return 1;
}
int Symtab::CompareSymbolValueByIndexLinux(const void* a, const void* b, void* thunk) {
CompareSymbolValueByIndex(thunk, a, b);
}
void
Symtab::SortSymbolIndexesByValue (std::vector<uint32_t>& indexes, bool remove_duplicates) const
{
@ -259,7 +263,12 @@ Symtab::SortSymbolIndexesByValue (std::vector<uint32_t>& indexes, bool remove_du
return;
// Sort the indexes in place using qsort
// FIXME: (WRONGDEFINE) Need a better define for this!
#ifdef __APPLE__
::qsort_r (&indexes[0], indexes.size(), sizeof(uint32_t), (void *)&m_symbols[0], Symtab::CompareSymbolValueByIndex);
#else
::qsort_r (&indexes[0], indexes.size(), sizeof(uint32_t), CompareSymbolValueByIndexLinux, (void *)&m_symbols[0]);
#endif
// Remove any duplicates if requested
if (remove_duplicates)