From a51867fb3a1385e768d9708df2b8730d34453a0b Mon Sep 17 00:00:00 2001 From: Netanel Haber <58652339+netanel-haber@users.noreply.github.com> Date: Tue, 10 Feb 2026 23:30:15 +0200 Subject: [PATCH] error on unsafe TLS: MSVC DLL builds and unsupported compilers __declspec(thread) is broken in DLLs loaded via LoadLibrary (PE/COFF loader allocates TLS slots once at process startup). Error at compile time if SNAKEPATH_FLUENT is used in an MSVC DLL build (_WINDLL). Also replace the silent non-thread-safe fallback with a hard error when no TLS mechanism is available. Co-Authored-By: Claude Opus 4.6 (1M context) --- snakepath.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/snakepath.h b/snakepath.h index eb1f6ce..6f3b0d3 100644 --- a/snakepath.h +++ b/snakepath.h @@ -2674,16 +2674,20 @@ bool sp_walk(const SpPath *p, bool top_down, bool follow_symlinks, /* ============ Fluent API Implementation ============ */ #ifdef SNAKEPATH_FLUENT +#if defined(_MSC_VER) && defined(_WINDLL) +#error "snakepath fluent API uses __declspec(thread) which is unsafe in DLLs loaded via LoadLibrary" +#endif + #if defined(__cplusplus) && __cplusplus >= 201103L #define SP_TLS thread_local #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__) #define SP_TLS _Thread_local -#elif defined(_MSC_VER) - #define SP_TLS __declspec(thread) #elif defined(__GNUC__) || defined(__clang__) #define SP_TLS __thread +#elif defined(_MSC_VER) + #define SP_TLS __declspec(thread) #else - #error "No thread-local storage support" + #error "snakepath fluent API requires thread-local storage (__thread, _Thread_local, or __declspec(thread))" #endif static SP_TLS SpPath sp_priv_f_ctx;