From: Arran Cudbard-Bell Date: Mon, 8 Mar 2021 21:51:08 +0000 (+0000) Subject: Remove duplicate comparison macros X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=546cd86dc194a7f0421ced99656aa74a4e4531fb;p=thirdparty%2Ffreeradius-server.git Remove duplicate comparison macros --- diff --git a/src/include/build.h b/src/include/build.h index 84a65034360..04bce840ed3 100644 --- a/src/include/build.h +++ b/src/include/build.h @@ -75,17 +75,24 @@ extern "C" { */ #define L(_str) { _str, sizeof(_str) - 1 } -/** Comparison macro for integers - * +/** Evaluates to +1 for a > b, and -1 for a < b + */ +#define CMP_PREFER_SMALLER(_a,_b) (((_a) > (_b)) - ((_a) < (_b))) + +/** Evaluates to -1 for a > b, and +1 for a < b + */ +#define CMP_PREFER_LARGER(_a,_b) (((_a) < (_b)) - ((_a) > (_b))) + +/** Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want _an_ ordering. */ -#define CMP(_a, _b) (((_a) > (_b)) - ((_a) < (_b))) +#define CMP(_a, _b) CMP_PREFER_SMALLER(_a, _b) /** Remove const qualification from a pointer * * @param[in] _type The non-const version of the type. * @param[in] _ptr to de-const. */ -#define UNCONST(_type, _ptr) ((_type)((uintptr_t)(_ptr))) +#define UNCONST(_type, _ptr) ((_type)((uintptr_t)(_ptr))) /* * HEX concatenation macros diff --git a/src/lib/io/master.c b/src/lib/io/master.c index 2b8250883b4..876edc9d614 100644 --- a/src/lib/io/master.c +++ b/src/lib/io/master.c @@ -182,7 +182,7 @@ static int8_t pending_packet_cmp(void const *one, void const *two) * priority elements. So if "a" is larger than "b", we * wish to prefer "a". */ - ret = COMPARE_PREFER_LARGER(a->priority, b->priority); + ret = CMP_PREFER_LARGER(a->priority, b->priority); if (ret != 0) return ret; /* @@ -194,7 +194,7 @@ static int8_t pending_packet_cmp(void const *one, void const *two) * packets go in. Since we'll never have two identical * "recv_time" values, the code should never get here. */ - return COMPARE_PREFER_SMALLER(a->recv_time, b->recv_time); + return CMP_PREFER_SMALLER(a->recv_time, b->recv_time); } /* @@ -225,13 +225,13 @@ static int8_t address_cmp(void const *one, void const *two) fr_io_address_t const *a = talloc_get_type_abort_const(one, fr_io_address_t); fr_io_address_t const *b = talloc_get_type_abort_const(two, fr_io_address_t);; - ret = STABLE_COMPARE(a->socket.inet.src_port, b->socket.inet.src_port); + ret = CMP(a->socket.inet.src_port, b->socket.inet.src_port); if (ret != 0) return ret; - ret = STABLE_COMPARE(a->socket.inet.dst_port, b->socket.inet.dst_port); + ret = CMP(a->socket.inet.dst_port, b->socket.inet.dst_port); if (ret != 0) return ret; - ret = STABLE_COMPARE(a->socket.inet.ifindex, b->socket.inet.ifindex); + ret = CMP(a->socket.inet.ifindex, b->socket.inet.ifindex); if (ret != 0) return ret; ret = fr_ipaddr_cmp(&a->socket.inet.src_ipaddr, &b->socket.inet.src_ipaddr); diff --git a/src/lib/server/method.c b/src/lib/server/method.c index 10a43f0627f..52275e6fa18 100644 --- a/src/lib/server/method.c +++ b/src/lib/server/method.c @@ -128,7 +128,7 @@ static int module_method_cmp(void const *one, void const *two) { module_method_entry_t const *a = one, *b = two; - return STABLE_COMPARE(a, b); + return CMP(a, b); } /** Allocate a new module method set diff --git a/src/lib/util/dict.h b/src/lib/util/dict.h index 1d2eaa28119..7e604b38716 100644 --- a/src/lib/util/dict.h +++ b/src/lib/util/dict.h @@ -367,10 +367,10 @@ static inline CC_HINT(nonnull) int8_t fr_dict_attr_cmp(fr_dict_attr_t const *a, * because we need to check the lineage. */ if (a->flags.is_unknown | a->flags.is_raw | b->flags.is_unknown | b->flags.is_raw) { - ret = STABLE_COMPARE(a->depth, b->depth); + ret = CMP(a->depth, b->depth); if (ret != 0) return ret; - ret = STABLE_COMPARE(a->attr, b->attr); + ret = CMP(a->attr, b->attr); if (ret != 0) return ret; ret = (a->parent == NULL) - (b->parent == NULL); @@ -383,7 +383,7 @@ static inline CC_HINT(nonnull) int8_t fr_dict_attr_cmp(fr_dict_attr_t const *a, * Comparing knowns is cheap because the * DAs are unique. */ - return STABLE_COMPARE(a, b); + return CMP(a, b); } /** @} */ diff --git a/src/lib/util/event.c b/src/lib/util/event.c index c557eea4f79..97757227000 100644 --- a/src/lib/util/event.c +++ b/src/lib/util/event.c @@ -423,7 +423,7 @@ static int8_t fr_event_pid_cmp(void const *a, void const *b) { fr_event_pid_t const *ev_a = a, *ev_b = b; - return STABLE_COMPARE(ev_a->pid, ev_b->pid); + return CMP(ev_a->pid, ev_b->pid); } #endif diff --git a/src/lib/util/heap.h b/src/lib/util/heap.h index 1bd3d713f67..ccd5a9504e1 100644 --- a/src/lib/util/heap.h +++ b/src/lib/util/heap.h @@ -36,19 +36,6 @@ extern "C" { typedef int32_t fr_heap_iter_t; -#ifndef STABLE_COMPARE -/* - * The first comparison returns +1 for a>b, and -1 for ab, and +1 for a (_b)) - ((_a) < (_b))) -#define COMPARE_PREFER_LARGER(_a,_b) (((_a) < (_b)) - ((_a) > (_b))) -#define STABLE_COMPARE COMPARE_PREFER_SMALLER -#endif - /* * Return negative numbers to put 'a' at the top of the heap. * Return positive numbers to put 'b' at the top of the heap. diff --git a/src/lib/util/rbtree.h b/src/lib/util/rbtree.h index 857318fe70a..27536403de1 100644 --- a/src/lib/util/rbtree.h +++ b/src/lib/util/rbtree.h @@ -61,19 +61,6 @@ struct fr_rb_node_s { typedef int (*fr_rb_cmp_t)(void const *one, void const *two); typedef void (*fr_rb_free_t)(void *data); -#ifndef STABLE_COMPARE -/* - * The first comparison returns +1 for a>b, and -1 for ab, and +1 for a (_b)) - ((_a) < (_b))) -#define COMPARE_PREFER_LARGER(_a,_b) (((_a) < (_b)) - ((_a) > (_b))) -#define STABLE_COMPARE COMPARE_PREFER_SMALLER -#endif - /** Creates a red black that verifies elements are of a specific talloc type * * @param[in] _ctx to tie tree lifetime to.