]> granicus.if.org Git - procps-ng/commitdiff
library: adjust 'noop' callback definition, <PIDS> api
authorJim Warner <james.warner@comcast.net>
Thu, 9 Jun 2016 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Sat, 11 Jun 2016 01:50:37 +0000 (11:50 +1000)
Though all those callback's parameters are ignored and
qsort treats them as pointers to void, it's wrong when
3rd parm is 'enum pids_item', not 'struct sort_parms'.

So we will fix it in a way that lessens the likelihood
of another such a mistake when some new type is added.

Signed-off-by: Jim Warner <james.warner@comcast.net>
proc/pids.c

index a542cf6b2a5a06be8fe5b4a860e1ada9eec3e77a..c575dbb0311a7c8edc1cad1e6174dbb5b3c729d7 100644 (file)
@@ -285,16 +285,16 @@ struct sort_parms {
     enum pids_sort_order order;
 };
 
-#define srtNAME(e) sort_results_ ## e
+#define srtNAME(t) sort_results_ ## t
+#define srtDECL(t) static int srtNAME(t) \
+    (const struct pids_stack **A, const struct pids_stack **B, struct sort_parms *P)
 
-#define NUM_srt(T) static int srtNAME(T) ( \
-  const struct pids_stack **A, const struct pids_stack **B, struct sort_parms *P) { \
+#define NUM_srt(T) srtDECL(T) { \
     const struct pids_result *a = (*A)->head + P->offset; \
     const struct pids_result *b = (*B)->head + P->offset; \
     return P->order * (a->result. T - b->result. T); }
 
-#define REG_srt(T) static int srtNAME(T) ( \
-  const struct pids_stack **A, const struct pids_stack **B, struct sort_parms *P) { \
+#define REG_srt(T) srtDECL(T) { \
     const struct pids_result *a = (*A)->head + P->offset; \
     const struct pids_result *b = (*B)->head + P->offset; \
     if ( a->result. T > b->result. T ) return P->order > 0 ?  1 : -1; \
@@ -309,34 +309,31 @@ REG_srt(u_int)
 REG_srt(ul_int)
 REG_srt(ull_int)
 
-static int srtNAME(str) (
-  const struct pids_stack **A, const struct pids_stack **B, struct sort_parms *P) {
+srtDECL(str) {
     const struct pids_result *a = (*A)->head + P->offset;
     const struct pids_result *b = (*B)->head + P->offset;
     return P->order * strcoll(a->result.str, b->result.str);
 }
 
-static int srtNAME(strv) (
-  const struct pids_stack **A, const struct pids_stack **B, struct sort_parms *P) {
+srtDECL(strv) {
     const struct pids_result *a = (*A)->head + P->offset;
     const struct pids_result *b = (*B)->head + P->offset;
     if (!a->result.strv || !b->result.strv) return 0;
     return P->order * strcoll((*a->result.strv), (*b->result.strv));
 }
 
-static int srtNAME(strvers) (
-  const struct pids_stack **A, const struct pids_stack **B, struct sort_parms *P) {
+srtDECL(strvers) {
     const struct pids_result *a = (*A)->head + P->offset;
     const struct pids_result *b = (*B)->head + P->offset;
     return P->order * strverscmp(a->result.str, b->result.str);
 }
 
-static int srtNAME(noop) (
-  const struct pids_stack **A, const struct pids_stack **B, enum pids_item *O) {
-    (void)A; (void)B; (void)O;
+srtDECL(noop) {
+    (void)A; (void)B; (void)P;
     return 0;
 }
 
+#undef srtDECL
 #undef NUM_srt
 #undef REG_srt
 
@@ -515,12 +512,6 @@ static struct {
 enum pids_item PROCPS_PIDS_logical_end  = PROCPS_PIDS_WCHAN_NAME + 1;
 
 #undef setNAME
-#undef setDECL
-#undef CVT_set
-#undef DUP_set
-#undef REG_set
-#undef STR_set
-#undef VEC_set
 #undef freNAME
 #undef srtNAME
 #undef RS