From: Arran Cudbard-Bell Date: Tue, 16 Aug 2022 09:14:18 +0000 (+0800) Subject: Remove horrible macro hacks in pair.c and replace them with a different set of horrib... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c74d6ee2f10cf7ac61df9c1094d544eb03c6c42;p=thirdparty%2Ffreeradius-server.git Remove horrible macro hacks in pair.c and replace them with a different set of horrible hacks --- diff --git a/src/lib/util/dlist.h b/src/lib/util/dlist.h index 01f825ad50e..b9e20914ab0 100644 --- a/src/lib/util/dlist.h +++ b/src/lib/util/dlist.h @@ -1204,7 +1204,6 @@ DIAG_OFF(unused-function) \ { fr_dlist_sort(&list->head, cmp); } \ DIAG_ON(unused-function) - #ifdef __cplusplus } #endif diff --git a/src/lib/util/libfreeradius-util.mk b/src/lib/util/libfreeradius-util.mk index 6a30967a3c2..1b0af87db1d 100644 --- a/src/lib/util/libfreeradius-util.mk +++ b/src/lib/util/libfreeradius-util.mk @@ -58,6 +58,7 @@ SOURCES := \ net.c \ packet.c \ pair.c \ + pair_inline.c \ pair_legacy.c \ pair_print.c \ pair_tokenize.c \ diff --git a/src/lib/util/pair.c b/src/lib/util/pair.c index c747a920868..fc16a23f251 100644 --- a/src/lib/util/pair.c +++ b/src/lib/util/pair.c @@ -24,6 +24,7 @@ RCSID("$Id$") #define _PAIR_PRIVATE 1 +#define _PAIR_INLINE 1 #include #include @@ -34,6 +35,8 @@ RCSID("$Id$") FR_TLIST_FUNCS(fr_pair_order_list, fr_pair_t, order_entry) +#include + /** Initialise a pair list header * * @param[in,out] list to initialise @@ -574,187 +577,6 @@ int fr_pair_to_unknown(fr_pair_t *vp) return 0; } -/* - * Start of magic macros / functions. - * - * We want to hide the implementation details of the pairs and - * pair lists from the caller. So we need to have public - * wrappers around the internal functions which do the actual - * work. - * - * However... in many cases those wrappers are only one line. - * When that happens, we define a public function, and then use a - * macro to re-define the public function to use the internal API. - * - * This lets us use the "public" functions in this file, while - * avoiding a function call bounce through the public functions. - * - * It also lets us avoid what would otherwise be random uses of - * public versus internal functions in this file, based on who - * edited what when, and what they remembered to do. In most - * cases, the public functions can be used, and there will be no - * extra cost to using them. - */ - -/** Get the head of a valuepair list - * - * @param[in] list to return the head of - * - * @return - * - NULL if the list is empty - * - pointer to the first item in the list. - * @hidecallergraph - */ -fr_pair_t *fr_pair_list_head(fr_pair_list_t const *list) -{ - return fr_pair_order_list_head(&list->order); -} -#define fr_pair_list_head(_x) fr_pair_order_list_head(&(_x)->order) - -/** Get the tail of a valuepair list - * - * @param[in] list to return the tail of - * - * @return - * - NULL if the list is empty - * - pointer to the last item in the list. - */ -fr_pair_t *fr_pair_list_tail(fr_pair_list_t const *list) -{ - return fr_pair_order_list_tail(&list->order); -} -//#define fr_pair_list_tail(_x) fr_pair_order_list_tail(&(_x)->order) - -/** Get the next item in a valuepair list after a specific entry - * - * @param[in] list to walk - * @param[in] item whose "next" item to return - * @return - * - NULL if the end of the list has been reached - * - pointer to the next item - * @hidecallergraph - */ -fr_pair_t *fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item) -{ - return fr_pair_order_list_next(&list->order, item); -} -#define fr_pair_list_next(_x, _item) fr_pair_order_list_next(&(_x)->order, _item) - -/** Get the previous item in a valuepair list before a specific entry - * - * @param[in] list to walk - * @param[in] item whose "prev" item to return - * @return - * - NULL if the head of the list has been reached - * - pointer to the previous item - */ -fr_pair_t *fr_pair_list_prev(fr_pair_list_t const *list, fr_pair_t const *item) -{ - return fr_pair_order_list_prev(&list->order, item); -} -//#define fr_pair_list_prev(_x, _item) fr_pair_order_list_prev(&(_x)->order, )item) - -/** Remove fr_pair_t from a list without freeing - * - * @param[in] list of value pairs to remove VP from. - * @param[in] vp to remove - * @return previous item in the list to the one being removed. - */ -fr_pair_t *fr_pair_remove(fr_pair_list_t *list, fr_pair_t *vp) -{ - return fr_pair_order_list_remove(&list->order, vp); -} -#define fr_pair_remove(_x, _item) fr_pair_order_list_remove(&(_x)->order, _item) - -/** Free memory used by a valuepair list. - * - * @hidecallergraph - */ -void fr_pair_list_free(fr_pair_list_t *list) -{ - fr_pair_order_list_talloc_free(&list->order); -} -//#define fr_pair_list_free(_x) fr_pair_order_list_talloc_free(&(_x)->order) - -/** Is a valuepair list empty - * - * @param[in] list to check - * @return true if empty - * - * @hidecallergraph - */ -bool fr_pair_list_empty(fr_pair_list_t const *list) -{ - return fr_pair_order_list_empty(&list->order); -} -#define fr_pair_list_empty(_x) fr_pair_order_list_empty(&(_x)->order) - -/** Sort a doubly linked list of fr_pair_ts using merge sort - * - * @note We use a merge sort (which is a stable sort), making this - * suitable for use on lists with things like EAP-Message - * fragments where the order of EAP-Message attributes needs to - * be maintained. - * - * @param[in,out] list head of dlinked fr_pair_ts to sort. - * @param[in] cmp to sort with - */ -void fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp) -{ - fr_pair_order_list_sort(&list->order, cmp); -} -//#define fr_pair_list_sort(_x, _cmp) fr_pair_order_list_sort(&(_x)->order, _cmp) - -/** Get the length of a list of fr_pair_t - * - * @param[in] list to return the length of - * - * @return number of entries in the list - */ -size_t fr_pair_list_num_elements(fr_pair_list_t const *list) -{ - return fr_pair_order_list_num_elements(&list->order); -} -//#define fr_pair_list_num_elements(_x) fr_pair_order_list_num_elements(&(_x)->order) - -/** Get the dlist head from a pair list - * - * @param[in] list to get the head from - * - * @return number of entries in the list - */ -fr_dlist_head_t *fr_pair_list_dlist_head(fr_pair_list_t const *list) -{ - return fr_pair_order_list_dlist_head(&list->order); -} -//#define fr_pair_list_dlist_head(_x) fr_pair_order_list_dlist_head(&(_x)->order) - -/** Appends a list of fr_pair_t from a temporary list to a destination list - * - * @param dst list to move pairs into - * @param src list from which to take pairs - */ -void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src) -{ - fr_pair_order_list_move(&dst->order, &src->order); -} -//#define fr_pair_list_append(_dst, _src) fr_pair_order_list_move(&(_dst)->order, &(_src)->order) - -/** Move a list of fr_pair_t from a temporary list to the head of a destination list - * - * @param dst list to move pairs into - * @param src from which to take pairs - */ -void fr_pair_list_prepend(fr_pair_list_t *dst, fr_pair_list_t *src) -{ - fr_pair_order_list_move_head(&dst->order, &src->order); -} -//#define fr_pair_list_prepend(_dst, _src) fr_pair_order_list_move_head(&(_dst)->order, &(_src)->order) - -/* - * End of magic macros. - */ - /** Iterate over pairs with a specified da * * @param[in] list to iterate over. diff --git a/src/lib/util/pair.h b/src/lib/util/pair.h index 03749e2fe59..194c519a72b 100644 --- a/src/lib/util/pair.h +++ b/src/lib/util/pair.h @@ -393,16 +393,6 @@ int fr_pair_steal_append(TALLOC_CTX *nctx, fr_pair_list_t *list, fr_pair_t *vp) int fr_pair_steal_prepend(TALLOC_CTX *nctx, fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull); -/** @hidecallergraph */ -void fr_pair_list_free(fr_pair_list_t *list) CC_HINT(nonnull); - -/** @hidecallergraph */ -bool fr_pair_list_empty(fr_pair_list_t const *list) CC_HINT(nonnull); - -size_t fr_pair_list_num_elements(fr_pair_list_t const *list) CC_HINT(nonnull); - -fr_dlist_head_t *fr_pair_list_dlist_head(fr_pair_list_t const *list) CC_HINT(nonnull); - /* Searching and list modification */ int fr_pair_to_unknown(fr_pair_t *vp) CC_HINT(nonnull); @@ -455,8 +445,6 @@ int fr_pair_update_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list int fr_pair_delete_by_da(fr_pair_list_t *head, fr_dict_attr_t const *da) CC_HINT(nonnull); -fr_pair_t *fr_pair_remove(fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull); - fr_pair_t *fr_pair_delete(fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull); /* functions for FR_TYPE_STRUCTURAL */ @@ -566,8 +554,6 @@ int fr_pair_cmp(fr_pair_t const *a, fr_pair_t const *b); int fr_pair_list_cmp(fr_pair_list_t const *a, fr_pair_list_t const *b) CC_HINT(nonnull); -void fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp) CC_HINT(nonnull); - /* Filtering */ void fr_pair_validate_debug(TALLOC_CTX *ctx, fr_pair_t const *failed[2]) CC_HINT(nonnull(2)); @@ -595,6 +581,22 @@ int fr_pair_sublist_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from, fr_pair_t const *start, unsigned int count) CC_HINT(nonnull(2,3)); +#ifndef _PAIR_INLINE +/** @hidecallergraph */ +void fr_pair_list_free(fr_pair_list_t *list) CC_HINT(nonnull); + +fr_pair_t *fr_pair_remove(fr_pair_list_t *list, fr_pair_t *vp) CC_HINT(nonnull); + + +/** @hidecallergraph */ +bool fr_pair_list_empty(fr_pair_list_t const *list) CC_HINT(nonnull); + +size_t fr_pair_list_num_elements(fr_pair_list_t const *list) CC_HINT(nonnull); + +fr_dlist_head_t *fr_pair_list_dlist_head(fr_pair_list_t const *list) CC_HINT(nonnull); + +void fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp) CC_HINT(nonnull); + void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src) CC_HINT(nonnull); void fr_pair_list_prepend(fr_pair_list_t *dst, fr_pair_list_t *src) CC_HINT(nonnull); @@ -608,6 +610,7 @@ fr_pair_t *fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const * fr_pair_t *fr_pair_list_prev(fr_pair_list_t const *list, fr_pair_t const *item) CC_HINT(nonnull(1)); fr_pair_t *fr_pair_list_tail(fr_pair_list_t const *list) CC_HINT(nonnull); +#endif /** @name Pair to pair copying *