]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Remove duplicate comparison macros
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 8 Mar 2021 21:51:08 +0000 (21:51 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 8 Mar 2021 21:51:08 +0000 (21:51 +0000)
src/include/build.h
src/lib/io/master.c
src/lib/server/method.c
src/lib/util/dict.h
src/lib/util/event.c
src/lib/util/heap.h
src/lib/util/rbtree.h

index 84a65034360cdaa36b0524ea58cae97bf78286cd..04bce840ed323b34949a120e4b9fd94087764c04 100644 (file)
@@ -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
index 2b8250883b4087e2a5dfdb57e5c43d42e19a450f..876edc9d6149b91461c683e39899cd54868c7637 100644 (file)
@@ -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);
index 10a43f0627fcdb4f6a9f50b5d4caa7fb7b394816..52275e6fa181034b8748899678b80769d52f8759 100644 (file)
@@ -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
index 1d2eaa281191228ee8247bf59ca0eed9e23cf5a2..7e604b387162693b237fc5edd182bd8469f26e7a 100644 (file)
@@ -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);
 }
 /** @} */
 
index c557eea4f7977322ec05aaedab5b8eb5cbc39d22..97757227000febe63976176e2d99b597b130ca8a 100644 (file)
@@ -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
 
index 1bd3d713f673b036c41d269bf9ec9e7ca69f0307..ccd5a9504e104472fddfa72c39b87a2cc7812e3f 100644 (file)
@@ -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 a<b
- *     The second comparison returns -1 for a>b, and +1 for a<b
- *
- *     Use STABLE_COMPARE when you don't really care about ordering,
- *     you just want _an_ ordering.
- */
-#define COMPARE_PREFER_SMALLER(_a,_b) (((_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.
index 857318fe70a7d4ebdd079b607ab5b59f946579ba..27536403de13124c2944b20d77e7bf1cf3960c0a 100644 (file)
@@ -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 a<b
- *     The second comparison returns -1 for a>b, and +1 for a<b
- *
- *     Use STABLE_COMPARE when you don't really care about ordering,
- *     you just want _an_ ordering.
- */
-#define COMPARE_PREFER_SMALLER(_a,_b) (((_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.