From: Yu Watanabe Date: Wed, 7 May 2025 16:59:40 +0000 (+0900) Subject: prioq: make prioq_ensure_put() type safe X-Git-Tag: v258-rc1~663^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F37379%2Fhead;p=thirdparty%2Fsystemd.git prioq: make prioq_ensure_put() type safe --- diff --git a/src/basic/prioq.c b/src/basic/prioq.c index 97e3fd936fa..ed9b33e59de 100644 --- a/src/basic/prioq.c +++ b/src/basic/prioq.c @@ -169,7 +169,7 @@ int prioq_put(Prioq *q, void *data, unsigned *idx) { return 0; } -int prioq_ensure_put(Prioq **q, compare_func_t compare_func, void *data, unsigned *idx) { +int _prioq_ensure_put(Prioq **q, compare_func_t compare_func, void *data, unsigned *idx) { int r; r = prioq_ensure_allocated(q, compare_func); diff --git a/src/basic/prioq.h b/src/basic/prioq.h index da06dcd8192..204ba54faee 100644 --- a/src/basic/prioq.h +++ b/src/basic/prioq.h @@ -16,7 +16,13 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Prioq*, prioq_free); int prioq_ensure_allocated(Prioq **q, compare_func_t compare_func); int prioq_put(Prioq *q, void *data, unsigned *idx); -int prioq_ensure_put(Prioq **q, compare_func_t compare_func, void *data, unsigned *idx); +int _prioq_ensure_put(Prioq **q, compare_func_t compare_func, void *data, unsigned *idx); +#define prioq_ensure_put(q, compare_func, data, idx) \ + ({ \ + int (*_func_)(const typeof((data)[0])*, const typeof((data)[0])*) = compare_func; \ + _prioq_ensure_put(q, (compare_func_t) _func_, data, idx); \ + }) + int prioq_remove(Prioq *q, void *data, unsigned *idx); void prioq_reshuffle(Prioq *q, void *data, unsigned *idx); diff --git a/src/libsystemd-network/lldp-neighbor.c b/src/libsystemd-network/lldp-neighbor.c index 67500895f8b..dd2a221403f 100644 --- a/src/libsystemd-network/lldp-neighbor.c +++ b/src/libsystemd-network/lldp-neighbor.c @@ -37,9 +37,7 @@ DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR( sd_lldp_neighbor, lldp_neighbor_unlink); -int lldp_neighbor_prioq_compare_func(const void *a, const void *b) { - const sd_lldp_neighbor *x = a, *y = b; - +int lldp_neighbor_prioq_compare_func(const sd_lldp_neighbor *x, const sd_lldp_neighbor *y) { assert(x); assert(y); diff --git a/src/libsystemd-network/lldp-neighbor.h b/src/libsystemd-network/lldp-neighbor.h index 57ac3a3f209..f7945c2edfe 100644 --- a/src/libsystemd-network/lldp-neighbor.h +++ b/src/libsystemd-network/lldp-neighbor.h @@ -84,7 +84,7 @@ static inline void* LLDP_NEIGHBOR_TLV_DATA(const sd_lldp_neighbor *n) { extern const struct hash_ops lldp_neighbor_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); +int lldp_neighbor_prioq_compare_func(const sd_lldp_neighbor *x, const sd_lldp_neighbor *y); sd_lldp_neighbor *lldp_neighbor_unlink(sd_lldp_neighbor *n); sd_lldp_neighbor *lldp_neighbor_new(size_t raw_size);