]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
prioq: make prioq_ensure_put() type safe 37379/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 7 May 2025 16:59:40 +0000 (01:59 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 7 May 2025 20:58:33 +0000 (05:58 +0900)
src/basic/prioq.c
src/basic/prioq.h
src/libsystemd-network/lldp-neighbor.c
src/libsystemd-network/lldp-neighbor.h

index 97e3fd936faf55846e7a84aa269633c7663ac1fe..ed9b33e59de05efc062c30f03056fd7035d0ced4 100644 (file)
@@ -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);
index da06dcd8192261e89da09b35dc48787550c914d9..204ba54faeeed03ddb9d1fe6372e062940a9bb87 100644 (file)
@@ -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);
 
index 67500895f8b80c990eeec693c0ddc90c2c517553..dd2a221403fbd2c94866dd3b5ad11abf95aed0a0 100644 (file)
@@ -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);
 
index 57ac3a3f209103f1589a54704a9c88b9f4c24dd0..f7945c2edfe3b2313781b95c028f5b84d86516bf 100644 (file)
@@ -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);