From 22b1ab22456306877214a4d9c7bcdf0ad7a293cc Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 29 Mar 2025 12:36:23 -0400 Subject: list: Switch back to the memcpy()/memset() SLIST_REMOVE() implementation 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"). --- src/list.h | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/list.h b/src/list.h index 15c37a8..276c610 100644 --- a/src/list.h +++ b/src/list.h @@ -82,11 +82,9 @@ #ifndef BFS_LIST_H #define BFS_LIST_H -#include "bfs.h" #include "diag.h" #include -#include #include /** @@ -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. -- cgit v1.2.3