From 4b252650e3cba3c04c665d57f92a0253a01eec4a Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Tue, 17 Aug 2021 09:50:24 -0500 Subject: [PATCH] Index heaps at 1 instead of 0 Allows us to have more elements in the heap, and fixes an issue where the element inserted at index 0 may have been counted as not inserted. --- src/lib/io/channel.h | 3 +- src/lib/io/network.c | 6 +- src/lib/io/worker.c | 6 +- src/lib/server/cf_file.c | 6 +- src/lib/server/pool.c | 2 +- src/lib/server/request.c | 7 +- src/lib/server/request.h | 4 +- src/lib/server/trunk.c | 5 +- src/lib/util/event.c | 8 +- src/lib/util/heap.c | 145 +++++++++--------- src/lib/util/heap.h | 17 +- src/lib/util/heap_tests.c | 29 ++-- src/lib/util/trie.c | 2 +- src/lib/util/trie.h | 2 +- .../rlm_cache_rbtree/rlm_cache_rbtree.c | 3 +- 15 files changed, 123 insertions(+), 122 deletions(-) diff --git a/src/lib/io/channel.h b/src/lib/io/channel.h index 62d0fe1df36..095e84b3dd9 100644 --- a/src/lib/io/channel.h +++ b/src/lib/io/channel.h @@ -54,6 +54,7 @@ typedef struct fr_listen fr_listen_t; #include #include #include +#include #include #include @@ -120,7 +121,7 @@ typedef struct { */ struct { fr_channel_t *ch; //!< channel where this messages was received - int32_t heap_id; //!< for the various queues + fr_heap_index_t heap_id; //!< for the various queues } channel; }; diff --git a/src/lib/io/network.c b/src/lib/io/network.c index b2cfe7b3e43..d400bc5aa98 100644 --- a/src/lib/io/network.c +++ b/src/lib/io/network.c @@ -60,7 +60,7 @@ typedef struct { * */ typedef struct { - int32_t heap_id; //!< workers are in a heap + fr_heap_index_t heap_id; //!< workers are in a heap fr_time_t cpu_time; //!< how much CPU time this worker has spent fr_time_t predicted; //!< predicted processing time for one packet @@ -330,7 +330,7 @@ void fr_network_listen_write(fr_network_t *nr, fr_listen_t *li, uint8_t const *p }, .channel = { - .heap_id = -1, + .heap_id = 0, }, .listen = li, @@ -466,7 +466,7 @@ static void fr_network_recv_reply(void *ctx, fr_channel_t *ch, fr_channel_data_t /* * Ensure that heap insert works. */ - cd->channel.heap_id = -1; + cd->channel.heap_id = 0; if (fr_heap_insert(nr->replies, cd) < 0) { fr_message_done(&cd->m); fr_assert(0 == 1); diff --git a/src/lib/io/worker.c b/src/lib/io/worker.c index 3b473148b6b..c97f6fc7924 100644 --- a/src/lib/io/worker.c +++ b/src/lib/io/worker.c @@ -472,7 +472,7 @@ static void worker_request_time_tracking_start(fr_worker_t *worker, request_t *r fr_time_tracking_yield(&request->async->tracking, now); worker->num_active++; - fr_assert(request->runnable_id < 0); + fr_assert(!fr_heap_entry_inserted(request->runnable_id)); (void) fr_heap_insert(worker->runnable, request); if (!worker->ev_cleanup) worker_max_request_timer(worker); @@ -505,7 +505,7 @@ static void worker_send_reply(fr_worker_t *worker, request_t *request, size_t si /* * If we're sending a reply, then it's no longer runnable. */ - fr_assert(request->runnable_id < 0); + fr_assert(!fr_heap_entry_inserted(request->runnable_id)); if (!size) { size = request->async->listen->app_io->default_reply_size; @@ -1170,7 +1170,7 @@ static inline CC_HINT(always_inline) void worker_run_request(fr_worker_t *worker ((request = fr_heap_pop(worker->runnable)) != NULL)) { REQUEST_VERIFY(request); - fr_assert(request->runnable_id < 0); + fr_assert(!fr_heap_entry_inserted(request->runnable_id)); /* * For real requests, if the channel is gone, diff --git a/src/lib/server/cf_file.c b/src/lib/server/cf_file.c index beed39f470d..2500719acda 100644 --- a/src/lib/server/cf_file.c +++ b/src/lib/server/cf_file.c @@ -817,8 +817,8 @@ static int cf_get_token(CONF_SECTION *parent, char const **ptr_p, fr_token_t *to } typedef struct cf_file_heap_t { - char const *filename; - int heap_id; + char const *filename; + fr_heap_index_t heap_id; } cf_file_heap_t; static int8_t filename_cmp(void const *one, void const *two) @@ -1077,7 +1077,7 @@ static int process_include(cf_stack_t *stack, CONF_SECTION *parent, char const * MEM(h = talloc_zero(frame->heap, cf_file_heap_t)); MEM(h->filename = talloc_typed_strdup(h, stack->buff[1])); - h->heap_id = -1; + h->heap_id = 0; (void) fr_heap_insert(frame->heap, h); } closedir(dir); diff --git a/src/lib/server/pool.c b/src/lib/server/pool.c index bfe6b4c4dd3..c2f1b864d39 100644 --- a/src/lib/server/pool.c +++ b/src/lib/server/pool.c @@ -51,7 +51,7 @@ static int connection_check(fr_pool_t *pool, request_t *request); struct fr_pool_connection_s { fr_pool_connection_t *prev; //!< Previous connection in list. fr_pool_connection_t *next; //!< Next connection in list. - int32_t heap_id; //!< For the next connection heap. + fr_heap_index_t heap_id; //!< For the next connection heap. time_t created; //!< Time connection was created. fr_time_t last_reserved; //!< Last time the connection was reserved. diff --git a/src/lib/server/request.c b/src/lib/server/request.c index 94eeb36ae8f..1e7d8a5e85c 100644 --- a/src/lib/server/request.c +++ b/src/lib/server/request.c @@ -197,9 +197,6 @@ static inline CC_HINT(always_inline) int request_init(char const *file, int line .flags = { .detachable = args->detachable }, - .runnable_id = -1, - .time_order_id = -1, - .alloc_file = file, .alloc_line = line }; @@ -338,8 +335,8 @@ static int _request_free(request_t *request) * if the request is freed out of * the free list. */ - request->time_order_id = -1; - request->runnable_id = -1; + request->time_order_id = 0; + request->runnable_id = 0; #endif /* diff --git a/src/lib/server/request.h b/src/lib/server/request.h index 64f8e93346a..4f05fa079d1 100644 --- a/src/lib/server/request.h +++ b/src/lib/server/request.h @@ -221,8 +221,8 @@ struct request_s { rlm_rcode_t rcode; //!< Last rcode returned by a module fr_rb_node_t dedup_node; //!< entry in the deduplication tree. - int32_t runnable_id; //!< entry in the heap of runnable packets - int32_t time_order_id; //!< entry in the heap of time ordered packets + fr_heap_index_t runnable_id; //!< entry in the heap of runnable packets + fr_heap_index_t time_order_id; //!< entry in the heap of time ordered packets uint32_t options; //!< mainly for proxying EAP-MSCHAPv2. diff --git a/src/lib/server/trunk.c b/src/lib/server/trunk.c index 1fc0cfffce1..7620cc3e6cf 100644 --- a/src/lib/server/trunk.c +++ b/src/lib/server/trunk.c @@ -102,7 +102,7 @@ struct fr_trunk_request_s { uint64_t id; //!< Trunk request ID. - int32_t heap_id; //!< Used to track the request conn->pending heap. + fr_heap_index_t heap_id; //!< Used to track the request conn->pending heap. fr_dlist_t entry; //!< Used to track the trunk request in the conn->sent ///< or trunk->backlog request. @@ -129,7 +129,7 @@ struct fr_trunk_connection_s { ///< This *MUST* be the first field in this ///< structure. - int32_t heap_id; //!< Used to track the connection in the connected + fr_heap_index_t heap_id; //!< Used to track the connection in the connected ///< heap. fr_dlist_t entry; //!< Used to track the connection in the connecting, @@ -3475,7 +3475,6 @@ static int trunk_connection_spawn(fr_trunk_t *trunk, fr_time_t now) MEM(tconn = talloc_zero(trunk, fr_trunk_connection_t)); tconn->pub.trunk = trunk; tconn->pub.state = FR_TRUNK_CONN_HALTED; /* All connections start in the halted state */ - tconn->heap_id = -1; /* Helps with asserts */ /* * Allocate a new fr_connection_t or fail. diff --git a/src/lib/util/event.c b/src/lib/util/event.c index 72078a420c9..476e7aa0c48 100644 --- a/src/lib/util/event.c +++ b/src/lib/util/event.c @@ -107,7 +107,7 @@ struct fr_event_timer { fr_event_timer_t const **parent; //!< A pointer to the parent structure containing the timer ///< event. - int32_t heap_id; //!< Where to store opaque heap data. + fr_heap_index_t heap_id; //!< Where to store opaque heap data. fr_dlist_t entry; //!< List of deferred timer events. fr_event_list_t *el; //!< Event list containing this timer. @@ -309,7 +309,7 @@ struct fr_event_pid { void *uctx; //!< Context pointer to pass to each file descriptor callback. #ifdef LOCAL_PID - int32_t heap_id; + fr_heap_index_t heap_id; #endif #ifndef NDEBUG @@ -1271,7 +1271,7 @@ int _fr_event_timer_at(NDEBUG_LOCATION_ARGS if (ctx != el) talloc_link_ctx(ctx, ev); talloc_set_destructor(ev, _event_timer_free); - ev->heap_id = -1; + ev->heap_id = 0; } else { memcpy(&ev, ev_p, sizeof(ev)); /* Not const to us */ @@ -1496,7 +1496,7 @@ int _fr_event_pid_wait(NDEBUG_LOCATION_ARGS } #else /* LOCAL_PID */ - ev->heap_id = -1; + ev->heap_id = 0; if (unlikely(fr_heap_insert(el->pids, ev) < 0)) { fr_strerror_printf("Failed adding waiter for PID %ld - %s", (long) pid, fr_strerror()); talloc_free(ev); diff --git a/src/lib/util/heap.c b/src/lib/util/heap.c index 2b33aa12190..eaa107ea8c9 100644 --- a/src/lib/util/heap.c +++ b/src/lib/util/heap.c @@ -37,62 +37,70 @@ RCSID("$Id$") */ struct fr_heap_s { - size_t size; //!< Number of nodes allocated. + unsigned int size; //!< Number of nodes allocated. size_t offset; //!< Offset of heap index in element structure. - int32_t num_elements; //!< Number of nodes used. + unsigned int num_elements; //!< Number of nodes used. - char const *type; //!< Type of elements. + char const *type; //!< Talloc type of elements. fr_heap_cmp_t cmp; //!< Comparator function. void **p; //!< Array of nodes. }; /* - * First node in a heap is element 0. Children of i are 2i+1 and - * 2i+2. These macros wrap the logic, so the code is more + * First node in a heap is element 1. Children of i are 2i and + * 2i+1. These macros wrap the logic, so the code is more * descriptive. */ -#define HEAP_PARENT(_x) (((_x) - 1 ) / 2) -#define HEAP_LEFT(_x) (2 * (_x) + 1) -/* #define HEAP_RIGHT(_x) (2 * (_x) + 2 ) */ +#define HEAP_PARENT(_x) ((_x) >> 1) +#define HEAP_LEFT(_x) (2 * (_x)) +/* #define HEAP_RIGHT(_x) (2 * (_x) + 1 ) */ #define HEAP_SWAP(_a, _b) { void *_tmp = _a; _a = _b; _b = _tmp; } -static void fr_heap_bubble(fr_heap_t *hp, int32_t child); +static void fr_heap_bubble(fr_heap_t *hp, fr_heap_index_t child); fr_heap_t *_fr_heap_alloc(TALLOC_CTX *ctx, fr_heap_cmp_t cmp, char const *type, size_t offset) { - fr_heap_t *fh; + fr_heap_t *hp; - fh = talloc_zero(ctx, fr_heap_t); - if (!fh) return NULL; + hp = talloc_zero(ctx, fr_heap_t); + if (!hp) return NULL; - fh->size = 2048; - fh->p = talloc_array(fh, void *, fh->size); - if (!fh->p) { - talloc_free(fh); + hp->size = 2048; + hp->p = talloc_array(hp, void *, hp->size); + if (!hp->p) { + talloc_free(hp); return NULL; } - fh->type = type; - fh->cmp = cmp; - fh->offset = offset; + /* + * As we're using unsigned index values + * index 0 is a special value meaning + * that the data isn't currently inserted + * into the heap. + */ + hp->p[0] = UINTPTR_MAX; + + hp->type = type; + hp->cmp = cmp; + hp->offset = offset; - return fh; + return hp; } -static inline CC_HINT(always_inline) CC_HINT(nonnull) int32_t index_get(fr_heap_t *hp, void *data) +static inline CC_HINT(always_inline, nonnull) fr_heap_index_t index_get(fr_heap_t *hp, void *data) { - return *((int32_t const *)(((uint8_t const *)data) + hp->offset)); + return *((fr_heap_index_t const *)(((uint8_t const *)data) + hp->offset)); } -static inline CC_HINT(always_inline) CC_HINT(nonnull) void index_set(fr_heap_t *hp, void *data, int32_t idx) +static inline CC_HINT(always_inline, nonnull) void index_set(fr_heap_t *hp, void *data, fr_heap_index_t idx) { - *((int32_t *)(((uint8_t *)data) + hp->offset)) = idx; + *((fr_heap_index_t *)(((uint8_t *)data) + hp->offset)) = idx; } #define OFFSET_SET(_heap, _idx) index_set(_heap, _heap->p[_idx], _idx); -#define OFFSET_RESET(_heap, _idx) index_set(_heap, _heap->p[_idx], -1); +#define OFFSET_RESET(_heap, _idx) index_set(_heap, _heap->p[_idx], 0); /** Insert a new element into the heap * @@ -115,23 +123,15 @@ static inline CC_HINT(always_inline) CC_HINT(nonnull) void index_set(fr_heap_t * */ int fr_heap_insert(fr_heap_t *hp, void *data) { - int32_t child; + fr_heap_index_t child; - /* - * On insert, the heap_id MUST be either: - * - * -1 = the node was added / removed from the heap - * and the heap code set the ID to -1 - * 0 = the node was just allocated via an "alloc_zero" - * function - */ child = index_get(hp, data); - if ((child > 0) || ((child == 0) && (hp->num_elements > 0) && (data == hp->p[0]))) { + if (fr_heap_entry_inserted(child)) { fr_strerror_const("Node is already in the heap"); return -1; } - child = hp->num_elements; + child = hp->num_elements + 1; /* Avoid using index 0 */ #ifndef TALLOC_GET_TYPE_ABORT_NOOP if (hp->type) (void)_talloc_get_type_abort(data, hp->type, __location__); @@ -140,29 +140,31 @@ int fr_heap_insert(fr_heap_t *hp, void *data) /* * Heap is full. Double it's size. */ - if ((size_t)child == hp->size) { - void **n; - size_t n_size = hp->size * 2; + if (child == hp->size) { + void **n; + unsigned int n_size; /* - * heap_id is a 32-bit signed integer. If the heap will - * grow to contain more than 2B elements, disallow + * heap_id is a 32-bit unsigned integer. If the heap will + * grow to contain more than 4B elements, disallow * integer overflow. Tho TBH, that should really never * happen. */ - if (n_size > INT32_MAX) { - if (hp->size == INT32_MAX) { + if (hp->size > (UINT_MAX - hp->size)) { + if (hp->size == UINT_MAX) { fr_strerror_const("Heap is full"); return -1; } else { - n_size = INT32_MAX; + n_size = UINT_MAX; } + } else { + n_size = hp->size * 2; } n = talloc_realloc(hp, hp->p, void *, n_size); if (!n) { - fr_strerror_printf("Failed expanding heap to %zu elements (%zu bytes)", - n_size, (n_size * sizeof(void *))); + fr_strerror_printf("Failed expanding heap to %u elements (%u bytes)", + n_size, (n_size * (unsigned int)sizeof(void *))); return -1; } hp->size = n_size; @@ -177,13 +179,15 @@ int fr_heap_insert(fr_heap_t *hp, void *data) return 0; } -static void fr_heap_bubble(fr_heap_t *hp, int32_t child) +static inline void fr_heap_bubble(fr_heap_t *hp, fr_heap_index_t child) { + if (!fr_cond_assert(child > 0)) return; + /* * Bubble up the element. */ - while (child > 0) { - int32_t parent = HEAP_PARENT(child); + while (child > 1) { + fr_heap_index_t parent = HEAP_PARENT(child); /* * Parent is smaller than the child. We're done. @@ -200,7 +204,6 @@ static void fr_heap_bubble(fr_heap_t *hp, int32_t child) OFFSET_SET(hp, child); } - /** Remove a node from the heap * * @param[in] hp The heap to extract an element from. @@ -211,7 +214,7 @@ static void fr_heap_bubble(fr_heap_t *hp, int32_t child) */ int fr_heap_extract(fr_heap_t *hp, void *data) { - int32_t parent, child, max; + fr_heap_index_t parent, child, max; /* * Extract element. @@ -221,7 +224,7 @@ int fr_heap_extract(fr_heap_t *hp, void *data) /* * Out of bounds. */ - if (unlikely((parent < 0) || (parent >= hp->num_elements))) { + if (unlikely((parent == 0) || (parent > hp->num_elements))) { fr_strerror_printf("Heap parent (%i) out of bounds (0-%i)", parent, hp->num_elements); return -1; } @@ -231,10 +234,10 @@ int fr_heap_extract(fr_heap_t *hp, void *data) parent, hp->p[parent]); return -1; } - max = hp->num_elements - 1; + max = hp->num_elements; - OFFSET_RESET(hp, parent); child = HEAP_LEFT(parent); + OFFSET_RESET(hp, parent); while (child <= max) { /* * Maybe take the right child. @@ -267,12 +270,11 @@ int fr_heap_extract(fr_heap_t *hp, void *data) return 0; } - void *fr_heap_peek(fr_heap_t *hp) { - if (!hp || (hp->num_elements == 0)) return NULL; + if (hp->num_elements == 0) return NULL; - return hp->p[0]; + return hp->p[1]; } void *fr_heap_pop(fr_heap_t *hp) @@ -281,28 +283,29 @@ void *fr_heap_pop(fr_heap_t *hp) if (hp->num_elements == 0) return NULL; - data = hp->p[0]; - (void) fr_heap_extract(hp, data); + data = hp->p[1]; + if (unlikely(fr_heap_extract(hp, data) < 0)) return NULL; return data; } - void *fr_heap_peek_tail(fr_heap_t *hp) { - if (!hp || (hp->num_elements == 0)) return NULL; + if (hp->num_elements == 0) return NULL; /* * If this is NULL, we have a problem. */ - return hp->p[hp->num_elements - 1]; + return hp->p[hp->num_elements]; } -uint32_t fr_heap_num_elements(fr_heap_t *hp) +/** Return the number of elements in the heap + * + * @param[in] hp to return the number of elements from. + */ +unsigned int fr_heap_num_elements(fr_heap_t *hp) { - if (!hp) return 0; - - return (uint32_t)hp->num_elements; + return hp->num_elements; } /** Iterate over entries in heap @@ -318,11 +321,11 @@ uint32_t fr_heap_num_elements(fr_heap_t *hp) */ void *fr_heap_iter_init(fr_heap_t *hp, fr_heap_iter_t *iter) { - *iter = 0; + *iter = 1; - if (unlikely(!hp) || (hp->num_elements == 0)) return NULL; + if (hp->num_elements == 0) return NULL; - return hp->p[0]; + return hp->p[1]; } /** Get the next entry in a heap @@ -338,9 +341,7 @@ void *fr_heap_iter_init(fr_heap_t *hp, fr_heap_iter_t *iter) */ void *fr_heap_iter_next(fr_heap_t *hp, fr_heap_iter_t *iter) { - if (unlikely(!hp)) return NULL; - - if ((*iter + 1) >= hp->num_elements) return NULL; + if ((*iter + 1) > hp->num_elements) return NULL; *iter += 1; return hp->p[*iter]; diff --git a/src/lib/util/heap.h b/src/lib/util/heap.h index b712490e551..068b10e5f87 100644 --- a/src/lib/util/heap.h +++ b/src/lib/util/heap.h @@ -34,7 +34,8 @@ extern "C" { #include #include -typedef int32_t fr_heap_iter_t; +typedef unsigned int fr_heap_index_t; +typedef unsigned int fr_heap_iter_t; /* * Return negative numbers to put 'a' at the top of the heap. @@ -72,21 +73,21 @@ fr_heap_t *_fr_heap_alloc(TALLOC_CTX *ctx, fr_heap_cmp_t cmp, char const *talloc /** Check if an entry is inserted into a heap * */ -static inline bool fr_heap_entry_inserted(int32_t heap_id) +static inline bool fr_heap_entry_inserted(fr_heap_index_t heap_idx) { - return (heap_id >= 0); + return (heap_idx > 0); } int fr_heap_insert(fr_heap_t *hp, void *data) CC_HINT(nonnull); int fr_heap_extract(fr_heap_t *hp, void *data) CC_HINT(nonnull); void *fr_heap_pop(fr_heap_t *hp) CC_HINT(nonnull); -void *fr_heap_peek(fr_heap_t *hp); -void *fr_heap_peek_tail(fr_heap_t *hp); +void *fr_heap_peek(fr_heap_t *hp) CC_HINT(nonnull); +void *fr_heap_peek_tail(fr_heap_t *hp) CC_HINT(nonnull); -uint32_t fr_heap_num_elements(fr_heap_t *hp); +uint32_t fr_heap_num_elements(fr_heap_t *hp) CC_HINT(nonnull); -void *fr_heap_iter_init(fr_heap_t *hp, fr_heap_iter_t *iter); -void *fr_heap_iter_next(fr_heap_t *hp, fr_heap_iter_t *iter); +void *fr_heap_iter_init(fr_heap_t *hp, fr_heap_iter_t *iter) CC_HINT(nonnull); +void *fr_heap_iter_next(fr_heap_t *hp, fr_heap_iter_t *iter) CC_HINT(nonnull); #ifdef __cplusplus } diff --git a/src/lib/util/heap_tests.c b/src/lib/util/heap_tests.c index 031e3f7e877..a4808dd938c 100644 --- a/src/lib/util/heap_tests.c +++ b/src/lib/util/heap_tests.c @@ -5,12 +5,12 @@ static bool fr_heap_check(fr_heap_t *hp, void *data) { - int i; + unsigned int i; if (!hp || (hp->num_elements == 0)) return false; for (i = 0; i < hp->num_elements; i++) { - if (hp->p[i] == data) { + if (hp->p[i + 1] == data) { return true; } } @@ -19,8 +19,8 @@ static bool fr_heap_check(fr_heap_t *hp, void *data) } typedef struct { - int data; - int32_t heap; /* for the heap */ + int data; + unsigned int heap; /* for the heap */ } heap_thing; @@ -81,21 +81,21 @@ static void heap_test(int skip) TEST_CASE("deletions"); { - int32_t entry; + unsigned int entry; for (i = 0; i < HEAP_TEST_SIZE / skip; i++) { entry = i * skip; - TEST_CHECK(array[entry].heap != -1); + TEST_CHECK(array[entry].heap != 0); TEST_MSG("element %i removed out of order", entry); TEST_CHECK((ret = fr_heap_extract(hp, &array[entry])) >= 0); - TEST_MSG("element %i removal failed, returned %i", entry, ret); + TEST_MSG("element %i removal failed, returned %i - %s", entry, ret, fr_strerror()); TEST_CHECK(!fr_heap_check(hp, &array[entry])); TEST_MSG("element %i removed but still in heap", entry); - TEST_CHECK(array[entry].heap == -1); + TEST_CHECK(array[entry].heap == 0); TEST_MSG("element %i removed out of order", entry); } } @@ -140,7 +140,7 @@ static void heap_test_order(void) fr_heap_t *hp; int i; heap_thing *array; - heap_thing *thing; + heap_thing *thing, *prev = NULL; int data = 0; unsigned int count = 0; int ret; @@ -175,7 +175,10 @@ static void heap_test_order(void) while ((thing = fr_heap_pop(hp))) { TEST_CHECK(thing->data >= data); - data = thing->data; + TEST_MSG("Expected data >= %i, got %i", data, thing->data); + if (thing->data >= data) data = thing->data; + TEST_CHECK(thing != prev); + prev = thing; count++; } @@ -234,7 +237,7 @@ static void heap_cycle(void) TEST_MSG("expected %i elements remaining in the heap", to_remove - i); TEST_CHECK(fr_heap_extract(hp, t) >= 0); - TEST_MSG("failed extracting %i", i); + TEST_MSG("failed extracting %i - %s", i, fr_strerror()); } /* @@ -245,13 +248,13 @@ static void heap_cycle(void) removed = 0; for (i = 0; i < HEAP_CYCLE_SIZE; i++) { - if (array[i].heap == -1) { + if (!fr_heap_entry_inserted(array[i].heap)) { TEST_CHECK((ret = fr_heap_insert(hp, &array[i])) >= 0); TEST_MSG("insert failed, returned %i - %s", ret, fr_strerror()); inserted++; } else { TEST_CHECK((ret = fr_heap_extract(hp, &array[i])) >= 0); - TEST_MSG("element %i removal failed, returned %i", i, ret); + TEST_MSG("element %i removal failed, returned %i - %s", i, ret, fr_strerror()); removed++; } } diff --git a/src/lib/util/trie.c b/src/lib/util/trie.c index a395ce65bc0..88a26d28f99 100644 --- a/src/lib/util/trie.c +++ b/src/lib/util/trie.c @@ -2813,7 +2813,7 @@ bool fr_trie_delete(fr_trie_t *ft, void const *data) * * @param[in] ft to return node count for. */ -uint32_t fr_trie_num_elements(UNUSED fr_trie_t *ft) +unsigned int fr_trie_num_elements(UNUSED fr_trie_t *ft) { return 0; } diff --git a/src/lib/util/trie.h b/src/lib/util/trie.h index bd8267126a6..8e2fee5ecd6 100644 --- a/src/lib/util/trie.h +++ b/src/lib/util/trie.h @@ -82,7 +82,7 @@ void *fr_trie_remove(fr_trie_t *ft, void const *data) CC_HINT(nonnull); bool fr_trie_delete(fr_trie_t *ft, void const *data) CC_HINT(nonnull); -uint32_t fr_trie_num_elements(fr_trie_t *ft) CC_HINT(nonnull); /* always returns 0 */ +unsigned int fr_trie_num_elements(fr_trie_t *ft) CC_HINT(nonnull); /* always returns 0 */ #ifdef __cplusplus } diff --git a/src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c b/src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c index 703559f1ce6..d7970de0bbc 100644 --- a/src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c +++ b/src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c @@ -37,7 +37,7 @@ typedef struct { rlm_cache_entry_t fields; //!< Entry data. fr_rb_node_t node; //!< Entry used for lookups. - int32_t heap_id; //!< Offset used for expiry heap. + fr_heap_index_t heap_id; //!< Offset used for expiry heap. } rlm_cache_rb_entry_t; /** Compare two entries by key @@ -143,7 +143,6 @@ static rlm_cache_entry_t *cache_entry_alloc(UNUSED rlm_cache_config_t const *con RERROR("Failed allocating cache entry"); return NULL; } - c->heap_id = -1; return (rlm_cache_entry_t *)c; } -- 2.47.3