busctl,sd-lldp: explicitly specify type of argument in compare function
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 18 Sep 2018 23:28:50 +0000 (08:28 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 18 Sep 2018 23:28:54 +0000 (08:28 +0900)
Several functions are shared by qsort and hash_ops or Prioq.
This makes these functions explicitly specify argument type,
and cast to __compar_fn_t where necessary.

src/busctl/busctl.c
src/libsystemd-network/lldp-neighbor.c
src/libsystemd-network/lldp-neighbor.h
src/libsystemd-network/sd-lldp.c

index 1fe6500..7b651cf 100644 (file)
@@ -719,8 +719,7 @@ static void member_hash_func(const void *p, struct siphash *state) {
                 string_hash_func(m->interface, state);
 }
 
-static int member_compare_func(const void *a, const void *b) {
-        const Member *x = a, *y = b;
+static int member_compare_func(const Member *x, const Member *y) {
         int d;
 
         assert(x);
@@ -911,7 +910,7 @@ static int on_property(const char *interface, const char *name, const char *sign
 static int introspect(int argc, char **argv, void *userdata) {
         static const struct hash_ops member_hash_ops = {
                 .hash = member_hash_func,
-                .compare = member_compare_func,
+                .compare = (__compar_fn_t) member_compare_func,
         };
 
         static const XMLIntrospectOps ops = {
index 8295d4d..f3c4e0a 100644 (file)
@@ -18,8 +18,7 @@ static void lldp_neighbor_id_hash_func(const void *p, struct siphash *state) {
         siphash24_compress(&id->port_id_size, sizeof(id->port_id_size), state);
 }
 
-static int lldp_neighbor_id_compare_func(const void *a, const void *b) {
-        const LLDPNeighborID *x = a, *y = b;
+int lldp_neighbor_id_compare_func(const LLDPNeighborID *x, const LLDPNeighborID *y) {
         int r;
 
         r = memcmp(x->chassis_id, y->chassis_id, MIN(x->chassis_id_size, y->chassis_id_size));
@@ -39,7 +38,7 @@ static int lldp_neighbor_id_compare_func(const void *a, const void *b) {
 
 const struct hash_ops lldp_neighbor_id_hash_ops = {
         .hash = lldp_neighbor_id_hash_func,
-        .compare = lldp_neighbor_id_compare_func
+        .compare = (__compar_fn_t) lldp_neighbor_id_compare_func,
 };
 
 int lldp_neighbor_prioq_compare_func(const void *a, const void *b) {
index 494bc51..2241c3b 100644 (file)
@@ -81,6 +81,7 @@ static inline void* LLDP_NEIGHBOR_TLV_DATA(const sd_lldp_neighbor *n) {
 }
 
 extern const struct hash_ops lldp_neighbor_id_hash_ops;
+int lldp_neighbor_id_compare_func(const LLDPNeighborID *x, const LLDPNeighborID *y);
 int lldp_neighbor_prioq_compare_func(const void *a, const void *b);
 
 sd_lldp_neighbor *lldp_neighbor_unlink(sd_lldp_neighbor *n);
index 4edcc6d..e60aebc 100644 (file)
@@ -372,7 +372,7 @@ _public_ int sd_lldp_new(sd_lldp **ret) {
 }
 
 static int neighbor_compare_func(sd_lldp_neighbor * const *a, sd_lldp_neighbor * const *b) {
-        return lldp_neighbor_id_hash_ops.compare(&(*a)->id, &(*b)->id);
+        return lldp_neighbor_id_compare_func(&(*a)->id, &(*b)->id);
 }
 
 static int on_timer_event(sd_event_source *s, uint64_t usec, void *userdata) {