From e77ca4fb3def886ba0549f8fb027b518fbbec08e Mon Sep 17 00:00:00 2001 From: Eric Hawicz Date: Sun, 25 Oct 2026 17:46:45 -0400 Subject: [PATCH] Add Windows support for the json_tokener_local_fini() destructor. --- json_tokener.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/json_tokener.c b/json_tokener.c index 0cc2f44..eb085c5 100644 --- a/json_tokener.c +++ b/json_tokener.c @@ -1473,7 +1473,25 @@ static int json_tokener_parse_double(const char *buf, int len, double *retval) * This keeps Valgrind clean. */ #if defined(__GNUC__) || defined(__clang__) -__attribute__((destructor)) +#define JSON_TOKENER_DESTRUCTOR __attribute__((destructor)) +#elif defined(_WIN32) || defined(_WIN64) +#include + +// Windows implementation using DllMain +// Executed when FreeLibrary is called or the process exits +#define JSON_TOKENER_DESTRUCTOR \ +BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) \ +{ \ + if (ul_reason_for_call == DLL_PROCESS_DETACH) \ + { \ + json_tokener_locale_fini(); \ + } \ + return TRUE; \ +} +#endif + +#ifdef JSON_TOKENER_DESTRUCTOR +JSON_TOKENER_DESTRUCTOR static void json_tokener_locale_fini(void) { if (c_numeric_locale != (locale_t)0) @@ -1482,5 +1500,6 @@ static void json_tokener_locale_fini(void) c_numeric_locale = (locale_t)0; } } -#endif /* __GNUC__ || __clang__ */ +#endif + #endif /* HAVE_USELOCALE */