From 11a1839ddd67457a68ce938157b3525159a198c8 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 20 Sep 2023 17:54:48 +0200 Subject: [PATCH] globals: Move remaining globals back to correct header files This undoes a lot of damage. --- HTMLparser.c | 3 +- globals.c | 38 ++++++++++++----- include/libxml/HTMLparser.h | 15 +++++++ include/libxml/globals.h | 83 ++----------------------------------- include/libxml/parser.h | 54 +++++++++++++++++------- include/libxml/tree.h | 20 +++++++++ include/libxml/xmlIO.h | 17 ++++++++ include/libxml/xmlsave.h | 20 +++++++++ parser.c | 5 +-- parserInternals.c | 5 ++- python/libxml.c | 1 + python/libxml_wrap.h | 1 + tree.c | 3 +- xmlIO.c | 3 +- xmllint.c | 12 +++--- 15 files changed, 159 insertions(+), 121 deletions(-) diff --git a/HTMLparser.c b/HTMLparser.c index c155c606..5cbd3191 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -14,18 +14,17 @@ #include #include +#include #include #include #include #include #include -#include #include #include #include #include #include -#include #include #include "private/buf.h" diff --git a/globals.c b/globals.c index 8e9fec51..cfedf6b1 100644 --- a/globals.c +++ b/globals.c @@ -19,7 +19,11 @@ #include #include #include +#include +#include +#include #include +#include #include #include @@ -80,9 +84,13 @@ struct _xmlGlobalState { #endif #define XML_OP XML_DECLARE_MEMBER -XML_GLOBALS XML_GLOBALS_ALLOC XML_GLOBALS_ERROR +XML_GLOBALS_HTML +XML_GLOBALS_IO +XML_GLOBALS_PARSER +XML_GLOBALS_SAVE +XML_GLOBALS_TREE #undef XML_OP }; @@ -389,6 +397,7 @@ void *xmlStructuredErrorContext = NULL; static void *xmlStructuredErrorContextThrDef = NULL; xmlError xmlLastError; +#ifdef LIBXML_OUTPUT_ENABLED /* * output defaults */ @@ -419,6 +428,7 @@ static const char *xmlTreeIndentStringThrDef = " "; */ int xmlSaveNoEmptyTags = 0; static int xmlSaveNoEmptyTagsThrDef = 0; +#endif /* LIBXML_OUTPUT_ENABLED */ #ifdef LIBXML_SAX1_ENABLED /** @@ -980,6 +990,7 @@ int xmlThrDefGetWarningsDefaultValue(int v) { return ret; } +#ifdef LIBXML_OUTPUT_ENABLED int xmlThrDefIndentTreeOutput(int v) { int ret; xmlMutexLock(&xmlThrDefMutex); @@ -998,6 +1009,16 @@ const char * xmlThrDefTreeIndentString(const char * v) { return ret; } +int xmlThrDefSaveNoEmptyTags(int v) { + int ret; + xmlMutexLock(&xmlThrDefMutex); + ret = xmlSaveNoEmptyTagsThrDef; + xmlSaveNoEmptyTagsThrDef = v; + xmlMutexUnlock(&xmlThrDefMutex); + return ret; +} +#endif + int xmlThrDefKeepBlanksDefaultValue(int v) { int ret; xmlMutexLock(&xmlThrDefMutex); @@ -1043,15 +1064,6 @@ int xmlThrDefPedanticParserDefaultValue(int v) { return ret; } -int xmlThrDefSaveNoEmptyTags(int v) { - int ret; - xmlMutexLock(&xmlThrDefMutex); - ret = xmlSaveNoEmptyTagsThrDef; - xmlSaveNoEmptyTagsThrDef = v; - xmlMutexUnlock(&xmlThrDefMutex); - return ret; -} - int xmlThrDefSubstituteEntitiesDefaultValue(int v) { int ret; xmlMutexLock(&xmlThrDefMutex); @@ -1138,9 +1150,13 @@ xmlThrDefOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc fun } #define XML_OP XML_DEFINE_GLOBAL_WRAPPER - XML_GLOBALS 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 */ diff --git a/include/libxml/HTMLparser.h b/include/libxml/HTMLparser.h index e43feeea..220a7121 100644 --- a/include/libxml/HTMLparser.h +++ b/include/libxml/HTMLparser.h @@ -80,6 +80,17 @@ struct _htmlEntityDesc { const char *desc; /* the description */ }; +#define XML_GLOBALS_HTML \ + XML_OP(htmlDefaultSAXHandler, xmlSAXHandlerV1, XML_DEPRECATED) + +#define XML_OP XML_DECLARE_GLOBAL +XML_GLOBALS_HTML +#undef XML_OP + +#if defined(LIBXML_THREAD_ENABLED) && !defined(XML_GLOBALS_NO_REDEFINITION) + #define htmlDefaultSAXHandler XML_GLOBAL_MACRO(htmlDefaultSAXHandler) +#endif + /* * There is only few public functions. */ @@ -316,5 +327,9 @@ XMLPUBFUN htmlStatus htmlNodeStatus(const htmlNodePtr, int) ; } #endif +#else /* LIBXML_HTML_ENABLED */ + +#define XML_GLOBALS_HTML + #endif /* LIBXML_HTML_ENABLED */ #endif /* __HTML_PARSER_H__ */ diff --git a/include/libxml/globals.h b/include/libxml/globals.h index c6f7dc9a..b7a00aca 100644 --- a/include/libxml/globals.h +++ b/include/libxml/globals.h @@ -12,8 +12,11 @@ #define __XML_GLOBALS_H #include +#include #include #include +#include +#include #ifdef __cplusplus extern "C" { @@ -83,86 +86,6 @@ xmlDllMain(void *hinstDLL, unsigned long fdwReason, #endif /** DOC_ENABLE */ -/* Declare globals with macro magic */ - -#define XML_GLOBALS_CORE \ - /* output options */ \ - XML_OP(xmlIndentTreeOutput, int, XML_EMPTY) \ - XML_OP(xmlTreeIndentString, const char *, XML_EMPTY) \ - XML_OP(xmlSaveNoEmptyTags, int, XML_EMPTY) \ - /* deprecated */ \ - XML_OP(oldXMLWDcompatibility, int, XML_DEPRECATED) \ - XML_OP(xmlBufferAllocScheme, xmlBufferAllocationScheme, XML_DEPRECATED) \ - XML_OP(xmlDefaultBufferSize, int, XML_DEPRECATED) \ - XML_OP(xmlDefaultSAXHandler, xmlSAXHandlerV1, XML_DEPRECATED) \ - XML_OP(xmlDefaultSAXLocator, xmlSAXLocator, XML_DEPRECATED) \ - XML_OP(xmlDoValidityCheckingDefaultValue, int, XML_DEPRECATED) \ - XML_OP(xmlGetWarningsDefaultValue, int, XML_DEPRECATED) \ - XML_OP(xmlKeepBlanksDefaultValue, int, XML_DEPRECATED) \ - XML_OP(xmlLineNumbersDefaultValue, int, XML_DEPRECATED) \ - XML_OP(xmlLoadExtDtdDefaultValue, int, XML_DEPRECATED) \ - XML_OP(xmlParserDebugEntities, int, XML_DEPRECATED) \ - XML_OP(xmlPedanticParserDefaultValue, int, XML_DEPRECATED) \ - XML_OP(xmlSubstituteEntitiesDefaultValue, int, XML_DEPRECATED) \ - XML_OP(xmlRegisterNodeDefaultValue, xmlRegisterNodeFunc, XML_DEPRECATED) \ - XML_OP(xmlDeregisterNodeDefaultValue, xmlDeregisterNodeFunc, \ - XML_DEPRECATED) \ - XML_OP(xmlParserInputBufferCreateFilenameValue, \ - xmlParserInputBufferCreateFilenameFunc, XML_DEPRECATED) \ - XML_OP(xmlOutputBufferCreateFilenameValue, \ - xmlOutputBufferCreateFilenameFunc, XML_DEPRECATED) - -#ifdef LIBXML_HTML_ENABLED - #define XML_GLOBALS_HTML \ - XML_OP(htmlDefaultSAXHandler, xmlSAXHandlerV1, XML_DEPRECATED) -#else - #define XML_GLOBALS_HTML -#endif - -#define XML_GLOBALS \ - XML_GLOBALS_CORE \ - XML_GLOBALS_HTML - -#define XML_OP XML_DECLARE_GLOBAL -XML_GLOBALS -#undef XML_OP - -#if defined(LIBXML_THREAD_ENABLED) && !defined(XML_GLOBALS_NO_REDEFINITION) - #define oldXMLWDcompatibility XML_GLOBAL_MACRO(oldXMLWDcompatibility) - #define xmlBufferAllocScheme XML_GLOBAL_MACRO(xmlBufferAllocScheme) - #define xmlDefaultBufferSize XML_GLOBAL_MACRO(xmlDefaultBufferSize) - #define xmlDefaultSAXHandler XML_GLOBAL_MACRO(xmlDefaultSAXHandler) - #define xmlDefaultSAXLocator XML_GLOBAL_MACRO(xmlDefaultSAXLocator) - #define xmlDoValidityCheckingDefaultValue \ - XML_GLOBAL_MACRO(xmlDoValidityCheckingDefaultValue) - #define xmlGetWarningsDefaultValue \ - XML_GLOBAL_MACRO(xmlGetWarningsDefaultValue) - #define xmlIndentTreeOutput XML_GLOBAL_MACRO(xmlIndentTreeOutput) - #define xmlTreeIndentString XML_GLOBAL_MACRO(xmlTreeIndentString) - #define xmlKeepBlanksDefaultValue XML_GLOBAL_MACRO(xmlKeepBlanksDefaultValue) - #define xmlLineNumbersDefaultValue \ - XML_GLOBAL_MACRO(xmlLineNumbersDefaultValue) - #define xmlLoadExtDtdDefaultValue XML_GLOBAL_MACRO(xmlLoadExtDtdDefaultValue) - #define xmlParserDebugEntities XML_GLOBAL_MACRO(xmlParserDebugEntities) - #define xmlPedanticParserDefaultValue \ - XML_GLOBAL_MACRO(xmlPedanticParserDefaultValue) - #define xmlSaveNoEmptyTags XML_GLOBAL_MACRO(xmlSaveNoEmptyTags) - #define xmlSubstituteEntitiesDefaultValue \ - XML_GLOBAL_MACRO(xmlSubstituteEntitiesDefaultValue) - #define xmlRegisterNodeDefaultValue \ - XML_GLOBAL_MACRO(xmlRegisterNodeDefaultValue) - #define xmlDeregisterNodeDefaultValue \ - XML_GLOBAL_MACRO(xmlDeregisterNodeDefaultValue) - #define xmlParserInputBufferCreateFilenameValue \ - XML_GLOBAL_MACRO(xmlParserInputBufferCreateFilenameValue) - #define xmlOutputBufferCreateFilenameValue \ - XML_GLOBAL_MACRO(xmlOutputBufferCreateFilenameValue) - - #ifdef LIBXML_HTML_ENABLED - #define htmlDefaultSAXHandler XML_GLOBAL_MACRO(htmlDefaultSAXHandler) - #endif -#endif - #ifdef __cplusplus } #endif diff --git a/include/libxml/parser.h b/include/libxml/parser.h index 1a567181..212f478a 100644 --- a/include/libxml/parser.h +++ b/include/libxml/parser.h @@ -19,6 +19,8 @@ #include #include #include +#include +#include #ifdef __cplusplus extern "C" { @@ -810,26 +812,48 @@ typedef xmlParserInputPtr (*xmlExternalEntityLoader) (const char *URL, * Variables */ -XMLPUBVAR const char *const -xmlParserVersion; +XMLPUBVAR const char *const xmlParserVersion; #ifdef LIBXML_THREAD_ENABLED -XMLPUBFUN const char *const * -__xmlParserVersion(void); +/* backward compatibility */ +XMLPUBFUN const char *const *__xmlParserVersion(void); #endif -#ifdef __cplusplus -} +#define XML_GLOBALS_PARSER \ + XML_OP(oldXMLWDcompatibility, int, XML_DEPRECATED) \ + XML_OP(xmlDefaultSAXHandler, xmlSAXHandlerV1, XML_DEPRECATED) \ + XML_OP(xmlDefaultSAXLocator, xmlSAXLocator, XML_DEPRECATED) \ + XML_OP(xmlDoValidityCheckingDefaultValue, int, XML_DEPRECATED) \ + XML_OP(xmlGetWarningsDefaultValue, int, XML_DEPRECATED) \ + XML_OP(xmlKeepBlanksDefaultValue, int, XML_DEPRECATED) \ + XML_OP(xmlLineNumbersDefaultValue, int, XML_DEPRECATED) \ + XML_OP(xmlLoadExtDtdDefaultValue, int, XML_DEPRECATED) \ + XML_OP(xmlParserDebugEntities, int, XML_DEPRECATED) \ + XML_OP(xmlPedanticParserDefaultValue, int, XML_DEPRECATED) \ + XML_OP(xmlSubstituteEntitiesDefaultValue, int, XML_DEPRECATED) + +#define XML_OP XML_DECLARE_GLOBAL +XML_GLOBALS_PARSER +#undef XML_OP + +#if defined(LIBXML_THREAD_ENABLED) && !defined(XML_GLOBALS_NO_REDEFINITION) + #define oldXMLWDcompatibility XML_GLOBAL_MACRO(oldXMLWDcompatibility) + #define xmlDefaultSAXHandler XML_GLOBAL_MACRO(xmlDefaultSAXHandler) + #define xmlDefaultSAXLocator XML_GLOBAL_MACRO(xmlDefaultSAXLocator) + #define xmlDoValidityCheckingDefaultValue \ + XML_GLOBAL_MACRO(xmlDoValidityCheckingDefaultValue) + #define xmlGetWarningsDefaultValue \ + XML_GLOBAL_MACRO(xmlGetWarningsDefaultValue) + #define xmlKeepBlanksDefaultValue XML_GLOBAL_MACRO(xmlKeepBlanksDefaultValue) + #define xmlLineNumbersDefaultValue \ + XML_GLOBAL_MACRO(xmlLineNumbersDefaultValue) + #define xmlLoadExtDtdDefaultValue XML_GLOBAL_MACRO(xmlLoadExtDtdDefaultValue) + #define xmlParserDebugEntities XML_GLOBAL_MACRO(xmlParserDebugEntities) + #define xmlPedanticParserDefaultValue \ + XML_GLOBAL_MACRO(xmlPedanticParserDefaultValue) + #define xmlSubstituteEntitiesDefaultValue \ + XML_GLOBAL_MACRO(xmlSubstituteEntitiesDefaultValue) #endif -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - - /* * Init/Cleanup */ diff --git a/include/libxml/tree.h b/include/libxml/tree.h index 4ef0bfd8..44fbe5d0 100644 --- a/include/libxml/tree.h +++ b/include/libxml/tree.h @@ -669,6 +669,26 @@ typedef void (*xmlDeregisterNodeFunc) (xmlNodePtr node); * Variables. */ +#define XML_GLOBALS_TREE \ + XML_OP(xmlBufferAllocScheme, xmlBufferAllocationScheme, XML_DEPRECATED) \ + XML_OP(xmlDefaultBufferSize, int, XML_DEPRECATED) \ + XML_OP(xmlRegisterNodeDefaultValue, xmlRegisterNodeFunc, XML_DEPRECATED) \ + XML_OP(xmlDeregisterNodeDefaultValue, xmlDeregisterNodeFunc, \ + XML_DEPRECATED) + +#define XML_OP XML_DECLARE_GLOBAL +XML_GLOBALS_TREE +#undef XML_OP + +#if defined(LIBXML_THREAD_ENABLED) && !defined(XML_GLOBALS_NO_REDEFINITION) + #define xmlBufferAllocScheme XML_GLOBAL_MACRO(xmlBufferAllocScheme) + #define xmlDefaultBufferSize XML_GLOBAL_MACRO(xmlDefaultBufferSize) + #define xmlRegisterNodeDefaultValue \ + XML_GLOBAL_MACRO(xmlRegisterNodeDefaultValue) + #define xmlDeregisterNodeDefaultValue \ + XML_GLOBAL_MACRO(xmlDeregisterNodeDefaultValue) +#endif + /* * Some helper functions */ diff --git a/include/libxml/xmlIO.h b/include/libxml/xmlIO.h index 0c5c6695..8e219028 100644 --- a/include/libxml/xmlIO.h +++ b/include/libxml/xmlIO.h @@ -171,6 +171,23 @@ struct _xmlOutputBuffer { }; #endif /* LIBXML_OUTPUT_ENABLED */ +#define XML_GLOBALS_IO \ + XML_OP(xmlParserInputBufferCreateFilenameValue, \ + xmlParserInputBufferCreateFilenameFunc, XML_DEPRECATED) \ + XML_OP(xmlOutputBufferCreateFilenameValue, \ + xmlOutputBufferCreateFilenameFunc, XML_DEPRECATED) + +#define XML_OP XML_DECLARE_GLOBAL +XML_GLOBALS_IO +#undef XML_OP + +#if defined(LIBXML_THREAD_ENABLED) && !defined(XML_GLOBALS_NO_REDEFINITION) + #define xmlParserInputBufferCreateFilenameValue \ + XML_GLOBAL_MACRO(xmlParserInputBufferCreateFilenameValue) + #define xmlOutputBufferCreateFilenameValue \ + XML_GLOBAL_MACRO(xmlOutputBufferCreateFilenameValue) +#endif + /* * Interfaces for input */ diff --git a/include/libxml/xmlsave.h b/include/libxml/xmlsave.h index a744b7ac..d91a05e9 100644 --- a/include/libxml/xmlsave.h +++ b/include/libxml/xmlsave.h @@ -41,6 +41,21 @@ typedef enum { typedef struct _xmlSaveCtxt xmlSaveCtxt; typedef xmlSaveCtxt *xmlSaveCtxtPtr; +#define XML_GLOBALS_SAVE \ + XML_OP(xmlIndentTreeOutput, int, XML_EMPTY) \ + XML_OP(xmlTreeIndentString, const char *, XML_EMPTY) \ + XML_OP(xmlSaveNoEmptyTags, int, XML_EMPTY) + +#define XML_OP XML_DECLARE_GLOBAL +XML_GLOBALS_SAVE +#undef XML_OP + +#if defined(LIBXML_THREAD_ENABLED) && !defined(XML_GLOBALS_NO_REDEFINITION) + #define xmlIndentTreeOutput XML_GLOBAL_MACRO(xmlIndentTreeOutput) + #define xmlTreeIndentString XML_GLOBAL_MACRO(xmlTreeIndentString) + #define xmlSaveNoEmptyTags XML_GLOBAL_MACRO(xmlSaveNoEmptyTags) +#endif + XMLPUBFUN xmlSaveCtxtPtr xmlSaveToFd (int fd, const char *encoding, @@ -82,6 +97,11 @@ XMLPUBFUN int #ifdef __cplusplus } #endif + +#else /* LIBXML_OUTPUT_ENABLED */ + +#define XML_GLOBALS_SAVE + #endif /* LIBXML_OUTPUT_ENABLED */ #endif /* __XML_XMLSAVE_H__ */ diff --git a/parser.c b/parser.c index 6ba94af2..987d07ca 100644 --- a/parser.c +++ b/parser.c @@ -51,10 +51,9 @@ #include #include #include -#include -#include -#include #include +#include +#include #include #include #include diff --git a/parserInternals.c b/parserInternals.c index 1887408b..65d301db 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -2518,7 +2518,10 @@ xmlKeepBlanksDefault(int val) { int old = xmlKeepBlanksDefaultValue; xmlKeepBlanksDefaultValue = val; - if (!val) xmlIndentTreeOutput = 1; +#ifdef LIBXML_OUTPUT_ENABLED + if (!val) + xmlIndentTreeOutput = 1; +#endif return(old); } diff --git a/python/libxml.c b/python/libxml.c index bf048006..03a11018 100644 --- a/python/libxml.c +++ b/python/libxml.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "libxml_wrap.h" #include "libxml2-py.h" diff --git a/python/libxml_wrap.h b/python/libxml_wrap.h index f4c3aee7..0fae2222 100644 --- a/python/libxml_wrap.h +++ b/python/libxml_wrap.h @@ -18,6 +18,7 @@ #include #include #include +#include #ifdef LIBXML_SCHEMAS_ENABLED #include #include diff --git a/tree.c b/tree.c index 2a7514aa..292621cf 100644 --- a/tree.c +++ b/tree.c @@ -28,15 +28,14 @@ #include #endif -#include #include +#include #include #include #include #include #include #include -#include #ifdef LIBXML_HTML_ENABLED #include #endif diff --git a/xmlIO.c b/xmlIO.c index dbcd5b5a..90379e2d 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -50,10 +50,10 @@ # endif #endif +#include #include #include #include -#include #include #include #include @@ -61,7 +61,6 @@ #ifdef LIBXML_CATALOG_ENABLED #include #endif -#include #include "private/buf.h" #include "private/enc.h" diff --git a/xmllint.c b/xmllint.c index 04aeb665..75cda75f 100644 --- a/xmllint.c +++ b/xmllint.c @@ -3135,7 +3135,6 @@ main(int argc, char **argv) { int i, acount; int files = 0; int version = 0; - const char* indent; if (argc <= 1) { usage(stderr, argv[0]); @@ -3525,11 +3524,14 @@ main(int argc, char **argv) { xmlDeregisterNodeDefault(deregisterNode); } - indent = getenv("XMLLINT_INDENT"); - if(indent != NULL) { - xmlTreeIndentString = indent; +#ifdef LIBXML_OUTPUT_ENABLED + { + const char *indent = getenv("XMLLINT_INDENT"); + if (indent != NULL) { + xmlTreeIndentString = indent; + } } - +#endif defaultEntityLoader = xmlGetExternalEntityLoader(); xmlSetExternalEntityLoader(xmllintExternalEntityLoader);