diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2025-03-29 12:36:23 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2025-03-29 12:36:23 -0400 |
commit | 22b1ab22456306877214a4d9c7bcdf0ad7a293cc (patch) | |
tree | 6f5d11a1895f86af2bf5e61e5604221b0427d269 /src | |
parent | a0d81053d3b9666c8c9879dc90e4da091db4b083 (diff) | |
download | bfs-main.tar.xz |
The thread-local scratch variables make it non-reentrant for no good
reason. I don't consider the theoretical strict-aliasing violation to
be practically relevant.
This partially reverts commit 90791fc ("list: Make SLIST_REMOVE() more
type-safe").
Diffstat (limited to 'src')
-rw-r--r-- | src/list.h | 31 |
1 files changed, 12 insertions, 19 deletions
@@ -82,11 +82,9 @@ #ifndef BFS_LIST_H #define BFS_LIST_H -#include "bfs.h" #include "diag.h" #include <stddef.h> -#include <stdint.h> #include <string.h> /** @@ -374,24 +372,19 @@ #define SLIST_REMOVE_(list, cursor, ...) \ SLIST_REMOVE__((list), (cursor), LIST_NEXT_(__VA_ARGS__)) -// Scratch variables for the type-safe SLIST_REMOVE() implementation. -// Not a pointer type due to https://github.com/llvm/llvm-project/issues/109718. -_maybe_unused -static thread_local uintptr_t slist_prev_, slist_next_; - -/** Suppress -Wunused-value. */ -_maybe_unused -static inline void *slist_cast_(uintptr_t ptr) { - return (void *)ptr; -} - #define SLIST_REMOVE__(list, cursor, next) \ - (slist_prev_ = (uintptr_t)(void *)*cursor, \ - slist_next_ = (uintptr_t)(void *)(*cursor)->next, \ - (*cursor)->next = NULL, \ - *cursor = (void *)slist_next_, \ - list->tail = *cursor ? list->tail : cursor, \ - slist_cast_(slist_prev_)) + (list->tail = (*cursor)->next ? list->tail : cursor, \ + slist_remove_(*cursor, cursor, &(*cursor)->next, sizeof(*cursor))) + +// Helper for SLIST_REMOVE() +static inline void *slist_remove_(void *ret, void *cursor, void *next, size_t size) { + // ret = *cursor; + // *cursor = ret->next; + memcpy(cursor, next, size); + // ret->next = NULL; + memset(next, 0, size); + return ret; +} /** * Pop the head off a singly-linked list. |