From c9a46a91fe43e847c0a90dcdf5fce2e4abbdf667 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 20 Dec 2023 20:11:09 +0100 Subject: [PATCH] io: Rework initialization --- include/private/io.h | 3 +++ threads.c | 2 ++ xmlIO.c | 29 +++++++++++++++++++++-------- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/include/private/io.h b/include/private/io.h index ca2c8e7e..b6de9822 100644 --- a/include/private/io.h +++ b/include/private/io.h @@ -5,6 +5,9 @@ #include #include +XML_HIDDEN void +xmlInitIOCallbacks(void); + XML_HIDDEN int __xmlIOErr(int domain, int code, const char *extra); diff --git a/threads.c b/threads.c index 651ce642..e5c14387 100644 --- a/threads.c +++ b/threads.c @@ -30,6 +30,7 @@ #include "private/dict.h" #include "private/enc.h" #include "private/globals.h" +#include "private/io.h" #include "private/memory.h" #include "private/threads.h" #include "private/xpath.h" @@ -590,6 +591,7 @@ xmlInitParser(void) { #if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) xmlInitXPathInternal(); #endif + xmlInitIOCallbacks(); xmlParserInnerInitialized = 1; } diff --git a/xmlIO.c b/xmlIO.c index 059b2288..e7eea45c 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -90,10 +90,8 @@ xmlIODefaultMatch(const char *filename); #define MAX_INPUT_CALLBACK 10 -static xmlInputCallback xmlInputCallbackTable[MAX_INPUT_CALLBACK] = { - { xmlIODefaultMatch, NULL, NULL, NULL } -}; -static int xmlInputCallbackNr = 1; +static xmlInputCallback xmlInputCallbackTable[MAX_INPUT_CALLBACK]; +static int xmlInputCallbackNr; #ifdef LIBXML_OUTPUT_ENABLED /* @@ -108,10 +106,8 @@ typedef struct _xmlOutputCallback { #define MAX_OUTPUT_CALLBACK 10 -static xmlOutputCallback xmlOutputCallbackTable[MAX_OUTPUT_CALLBACK] = { - { xmlIODefaultMatch, NULL, NULL, NULL }, -}; -static int xmlOutputCallbackNr = 1; +static xmlOutputCallback xmlOutputCallbackTable[MAX_OUTPUT_CALLBACK]; +static int xmlOutputCallbackNr; #endif /* LIBXML_OUTPUT_ENABLED */ /************************************************************************ @@ -4023,6 +4019,23 @@ xmlNoNetExternalEntityLoader(const char *URL, const char *ID, * * ************************************************************************/ +/** + * xmlInitIOCallbacks: + * + * Initialize callback tables. + */ +void +xmlInitIOCallbacks(void) +{ + xmlInputCallbackNr = 1; + xmlInputCallbackTable[0].matchcallback = xmlIODefaultMatch; + +#ifdef LIBXML_OUTPUT_ENABLED + xmlOutputCallbackNr = 1; + xmlOutputCallbackTable[0].matchcallback = xmlIODefaultMatch; +#endif +} + /** * xmlRegisterInputCallbacks: * @matchFunc: the xmlInputMatchCallback