1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-01-27 14:03:36 +03:00

globals: Final fixes

This commit is contained in:
Nick Wellnhofer 2023-09-20 23:07:58 +02:00
parent d6ba403368
commit f0e8358eae

View File

@ -665,6 +665,7 @@ xmlIsMainThread(void) {
} }
#ifdef LIBXML_THREAD_ENABLED #ifdef LIBXML_THREAD_ENABLED
static void static void
xmlFreeGlobalState(void *state) xmlFreeGlobalState(void *state)
{ {
@ -848,6 +849,34 @@ xmlGetThreadLocalStorage(int allowFailure) {
return(gs); return(gs);
} }
/* Define thread-local storage accessors with macro magic */
#define XML_DEFINE_GLOBAL_WRAPPER(name, type, attrs) \
type *__##name(void) { \
if (IS_MAIN_THREAD) \
return (&name); \
else \
return (&xmlGetThreadLocalStorage(0)->gs_##name); \
}
#define XML_OP XML_DEFINE_GLOBAL_WRAPPER
XML_GLOBALS_ALLOC
XML_GLOBALS_ERROR
XML_GLOBALS_HTML
XML_GLOBALS_IO
XML_GLOBALS_PARSER
XML_GLOBALS_SAVE
XML_GLOBALS_TREE
#undef XML_OP
/* For backward compatibility */
const char *const *
__xmlParserVersion(void) {
return &xmlParserVersion;
}
#endif /* LIBXML_THREAD_ENABLED */ #endif /* LIBXML_THREAD_ENABLED */
/** /**
@ -874,7 +903,7 @@ xmlGetThreadLocalStorage(int allowFailure) {
*/ */
int int
xmlCheckThreadLocalStorage(void) { xmlCheckThreadLocalStorage(void) {
#if defined(LIBXML_THREAD_ENABLED) && !defined(XML_THREAD_LOCAL_STORAGE) #if defined(LIBXML_THREAD_ENABLED) && !defined(XML_THREAD_LOCAL)
if ((!xmlIsMainThreadInternal()) && (xmlGetThreadLocalStorage(1) == NULL)) if ((!xmlIsMainThreadInternal()) && (xmlGetThreadLocalStorage(1) == NULL))
return(-1); return(-1);
#endif #endif
@ -892,8 +921,8 @@ xmlCheckThreadLocalStorage(void) {
* *
* Returns TRUE always * Returns TRUE always
*/ */
#ifdef HAVE_POSIX_THREADS #if defined(HAVE_WIN32_THREADS) && \
#elif defined(HAVE_WIN32_THREADS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL)) (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
#if defined(LIBXML_STATIC_FOR_DLL) #if defined(LIBXML_STATIC_FOR_DLL)
int int
xmlDllMain(ATTRIBUTE_UNUSED void *hinstDLL, unsigned long fdwReason, xmlDllMain(ATTRIBUTE_UNUSED void *hinstDLL, unsigned long fdwReason,
@ -1138,32 +1167,3 @@ xmlThrDefOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc fun
return(old); return(old);
} }
/* Define thread-local storage accessors with macro magic */
#ifdef LIBXML_THREAD_ENABLED
#define XML_DEFINE_GLOBAL_WRAPPER(name, type, attrs) \
type *__##name(void) { \
if (IS_MAIN_THREAD) \
return (&name); \
else \
return (&xmlGetThreadLocalStorage(0)->gs_##name); \
}
#define XML_OP XML_DEFINE_GLOBAL_WRAPPER
XML_GLOBALS_ALLOC
XML_GLOBALS_ERROR
XML_GLOBALS_HTML
XML_GLOBALS_IO
XML_GLOBALS_PARSER
XML_GLOBALS_SAVE
XML_GLOBALS_TREE
#undef XML_OP
/* For backward compatibility */
const char *const *
__xmlParserVersion(void) {
return &xmlParserVersion;
}
#endif