Skip to content

Commit cc67069

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Fix build break on glibc hosts."
2 parents 21cc2c1 + 46fc395 commit cc67069

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tools/aapt/StringPool.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ status_t StringPool::addStyleSpan(size_t idx, const entry_style_span& span)
213213
return NO_ERROR;
214214
}
215215

216+
#ifdef __GLIBC__
217+
int StringPool::config_sort(const void* lhs, const void* rhs, void* state)
218+
#else
216219
int StringPool::config_sort(void* state, const void* lhs, const void* rhs)
220+
#endif
217221
{
218222
StringPool* pool = (StringPool*)state;
219223
const entry& lhe = pool->mEntries[pool->mEntryArray[*static_cast<const size_t*>(lhs)]];
@@ -241,7 +245,13 @@ void StringPool::sortByConfig()
241245
NOISY(printf("SORTING STRINGS BY CONFIGURATION...\n"));
242246
// Vector::sort uses insertion sort, which is very slow for this data set.
243247
// Use quicksort instead because we don't need a stable sort here.
248+
// For more fun, GLibC took qsort_r from BSD but then decided to swap the
249+
// order the last two parameters.
250+
#ifdef __GLIBC__
251+
qsort_r(newPosToOriginalPos.editArray(), N, sizeof(size_t), config_sort, this);
252+
#else
244253
qsort_r(newPosToOriginalPos.editArray(), N, sizeof(size_t), this, config_sort);
254+
#endif
245255
//newPosToOriginalPos.sort(config_sort, this);
246256
NOISY(printf("DONE SORTING STRINGS BY CONFIGURATION.\n"));
247257

0 commit comments

Comments
 (0)