logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0001-libsupport-remove-unused-sort_r-definition.patch (4536B)


  1. From 24a0e8d916019160c1fe186ccfb9843d00a5ddde Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Tue, 2 Mar 2021 15:47:20 -0800
  4. Subject: [PATCH] libsupport: remove unused sort_r definition
  5. e2fsprogs uses sort_r_simple directly, so sort_r is not needed.
  6. On any linux (including linux-musl), sort_r is defined in terms of
  7. qsort_r, so a compiler that does not support inlining may still
  8. emit a reference to qsort_r.
  9. ---
  10. lib/support/sort_r.h | 119 +------------------------------------------
  11. 1 file changed, 2 insertions(+), 117 deletions(-)
  12. diff --git a/lib/support/sort_r.h b/lib/support/sort_r.h
  13. index 3292a26a..08f496d4 100644
  14. --- a/lib/support/sort_r.h
  15. +++ b/lib/support/sort_r.h
  16. @@ -22,20 +22,10 @@ void sort_r(void *base, size_t nel, size_t width,
  17. */
  18. -#define _SORT_R_INLINE inline
  19. -
  20. -#if (defined __gnu_hurd__ || defined __GNU__ || \
  21. - defined __linux__ || defined __MINGW32__ || defined __GLIBC__)
  22. -# define _SORT_R_LINUX
  23. -#elif (defined __APPLE__ || defined __MACH__ || defined __DARWIN__ || \
  24. - defined __FreeBSD__ || defined __DragonFly__)
  25. -# define _SORT_R_BSD
  26. -#elif (defined _WIN32 || defined _WIN64 || defined __WINDOWS__)
  27. -# define _SORT_R_WINDOWS
  28. -# undef _SORT_R_INLINE
  29. +#if (defined _WIN32 || defined _WIN64 || defined __WINDOWS__)
  30. # define _SORT_R_INLINE __inline
  31. #else
  32. - /* Using our own recursive quicksort sort_r_simple() */
  33. +# define _SORT_R_INLINE inline
  34. #endif
  35. #if (defined NESTED_QSORT && NESTED_QSORT == 0)
  36. @@ -211,111 +201,6 @@ static _SORT_R_INLINE void sort_r_simple(void *base, size_t nel, size_t w,
  37. }
  38. }
  39. -
  40. -#if defined NESTED_QSORT
  41. -
  42. - static _SORT_R_INLINE void sort_r(void *base, size_t nel, size_t width,
  43. - int (*compar)(const void *_a,
  44. - const void *_b,
  45. - void *aarg),
  46. - void *arg)
  47. - {
  48. - int nested_cmp(const void *a, const void *b)
  49. - {
  50. - return compar(a, b, arg);
  51. - }
  52. -
  53. - qsort(base, nel, width, nested_cmp);
  54. - }
  55. -
  56. -#else /* !NESTED_QSORT */
  57. -
  58. - /* Declare structs and functions */
  59. -
  60. - #if defined _SORT_R_BSD
  61. -
  62. - /* Ensure qsort_r is defined */
  63. - extern void qsort_r(void *base, size_t nel, size_t width, void *thunk,
  64. - int (*compar)(void *_thunk,
  65. - const void *_a, const void *_b));
  66. -
  67. - #endif
  68. -
  69. - #if defined _SORT_R_BSD || defined _SORT_R_WINDOWS
  70. -
  71. - /* BSD (qsort_r), Windows (qsort_s) require argument swap */
  72. -
  73. - struct sort_r_data
  74. - {
  75. - void *arg;
  76. - int (*compar)(const void *_a, const void *_b, void *_arg);
  77. - };
  78. -
  79. - static _SORT_R_INLINE int sort_r_arg_swap(void *s,
  80. - const void *a, const void *b)
  81. - {
  82. - struct sort_r_data *ss = (struct sort_r_data*)s;
  83. - return (ss->compar)(a, b, ss->arg);
  84. - }
  85. -
  86. - #endif
  87. -
  88. - #if defined _SORT_R_LINUX
  89. -
  90. - typedef int(* __compar_d_fn_t)(const void *, const void *, void *);
  91. - extern void qsort_r(void *base, size_t nel, size_t width,
  92. - __compar_d_fn_t __compar, void *arg)
  93. - __attribute__((nonnull (1, 4)));
  94. -
  95. - #endif
  96. -
  97. - /* implementation */
  98. -
  99. - static _SORT_R_INLINE void sort_r(void *base, size_t nel, size_t width,
  100. - int (*compar)(const void *_a,
  101. - const void *_b, void *_arg),
  102. - void *arg)
  103. - {
  104. - #if defined _SORT_R_LINUX
  105. -
  106. - #if defined __GLIBC__ && ((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8))
  107. -
  108. - /* no qsort_r in glibc before 2.8, need to use nested qsort */
  109. - sort_r_simple(base, nel, width, compar, arg);
  110. -
  111. - #else
  112. -
  113. - qsort_r(base, nel, width, compar, arg);
  114. -
  115. - #endif
  116. -
  117. - #elif defined _SORT_R_BSD
  118. -
  119. - struct sort_r_data tmp;
  120. - tmp.arg = arg;
  121. - tmp.compar = compar;
  122. - qsort_r(base, nel, width, &tmp, sort_r_arg_swap);
  123. -
  124. - #elif defined _SORT_R_WINDOWS
  125. -
  126. - struct sort_r_data tmp;
  127. - tmp.arg = arg;
  128. - tmp.compar = compar;
  129. - qsort_s(base, nel, width, sort_r_arg_swap, &tmp);
  130. -
  131. - #else
  132. -
  133. - /* Fall back to our own quicksort implementation */
  134. - sort_r_simple(base, nel, width, compar, arg);
  135. -
  136. - #endif
  137. - }
  138. -
  139. -#endif /* !NESTED_QSORT */
  140. -
  141. #undef _SORT_R_INLINE
  142. -#undef _SORT_R_WINDOWS
  143. -#undef _SORT_R_LINUX
  144. -#undef _SORT_R_BSD
  145. #endif /* SORT_R_H_ */
  146. --
  147. 2.32.0