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