From db8b9722cb2a1f7dca7374ec38ecaa4936ab3869 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 20 Sep 2023 13:56:16 +0200 Subject: [PATCH] parser: Deprecate global parser options Note that setting global options has no effect anyway when using any of the modern parser API functions which take an option argument like xmlReadMemory or when using xmlCtxtUseOptions. Global options only have an effect when using old API functions xmlParse* or xmlSAXParse* or when using an xmlParserCtxt without calling xmlCtxtUseOptions. Unfortunately, many downstream projects still modify global parser options often without realizing that it has no effect. If necessary, switch to the modern API. Then you can safely remove all code that changes global options. Here's a list of deprecated functions and global variables together with the corresponding parser options. - xmlSubstituteEntitiesDefault, xmlSubstituteEntitiesDefaultValue Parser option XML_PARSE_NOENT - xmlKeepBlanksDefault, xmlKeepBlanksDefaultValue Inverse of parser option XML_PARSE_NOBLANKS - xmlPedanticParserDefault, xmlPedanticParserDefaultValue Parser option XML_PARSE_PEDANTIC - xmlLineNumbersDefault, xmlLineNumbersDefaultValue Always enabled by new API - xmlDoValidityCheckingDefaultValue Parser option XML_PARSE_DTDVALID - xmlGetWarningsDefaultValue Inverse of parser option XML_PARSE_NOWARNING - xmlLoadExtDtdDefaultValue Parser options XML_PARSE_DTDLOAD and XML_PARSE_DTDATTR --- include/libxml/globals.h | 56 +++++++++++++++++++++------------------- include/libxml/parser.h | 8 +++--- python/generator.py | 10 +++++++ 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/include/libxml/globals.h b/include/libxml/globals.h index 4cf17790..051dc112 100644 --- a/include/libxml/globals.h +++ b/include/libxml/globals.h @@ -40,31 +40,31 @@ XMLPUBFUN void xmlThrDefSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler); XMLPUBFUN void xmlThrDefSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler); -XML_DEPRECATED XMLPUBFUN xmlBufferAllocationScheme -xmlThrDefBufferAllocScheme(xmlBufferAllocationScheme v); -XML_DEPRECATED XMLPUBFUN int -xmlThrDefDefaultBufferSize(int v); -XMLPUBFUN int -xmlThrDefDoValidityCheckingDefaultValue(int v); -XMLPUBFUN int -xmlThrDefGetWarningsDefaultValue(int v); XMLPUBFUN int xmlThrDefIndentTreeOutput(int v); XMLPUBFUN const char * xmlThrDefTreeIndentString(const char * v); XMLPUBFUN int +xmlThrDefSaveNoEmptyTags(int v); +XML_DEPRECATED XMLPUBFUN xmlBufferAllocationScheme +xmlThrDefBufferAllocScheme(xmlBufferAllocationScheme v); +XML_DEPRECATED XMLPUBFUN int +xmlThrDefDefaultBufferSize(int v); +XML_DEPRECATED XMLPUBFUN int +xmlThrDefDoValidityCheckingDefaultValue(int v); +XML_DEPRECATED XMLPUBFUN int +xmlThrDefGetWarningsDefaultValue(int v); +XML_DEPRECATED XMLPUBFUN int xmlThrDefKeepBlanksDefaultValue(int v); XML_DEPRECATED XMLPUBFUN int xmlThrDefLineNumbersDefaultValue(int v); -XMLPUBFUN int +XML_DEPRECATED XMLPUBFUN int xmlThrDefLoadExtDtdDefaultValue(int v); -XMLPUBFUN int +XML_DEPRECATED XMLPUBFUN int xmlThrDefParserDebugEntities(int v); XML_DEPRECATED XMLPUBFUN int xmlThrDefPedanticParserDefaultValue(int v); -XMLPUBFUN int -xmlThrDefSaveNoEmptyTags(int v); -XMLPUBFUN int +XML_DEPRECATED XMLPUBFUN int xmlThrDefSubstituteEntitiesDefaultValue(int v); XMLPUBFUN xmlRegisterNodeFunc xmlThrDefRegisterNodeDefault(xmlRegisterNodeFunc func); @@ -91,27 +91,29 @@ xmlDllMain(void *hinstDLL, unsigned long fdwReason, #define XML_GLOBALS_CORE \ XML_OP(xmlLastError, xmlError, XML_EMPTY) \ + XML_OP(xmlGenericError, xmlGenericErrorFunc, XML_EMPTY) \ + XML_OP(xmlGenericErrorContext, void *, XML_EMPTY) \ + XML_OP(xmlStructuredError, xmlStructuredErrorFunc, XML_EMPTY) \ + XML_OP(xmlStructuredErrorContext, void *, XML_EMPTY) \ + XML_OP(xmlParserVersion, const char *, XML_EMPTY) \ + /* 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_EMPTY) \ - XML_OP(xmlGenericError, xmlGenericErrorFunc, XML_EMPTY) \ - XML_OP(xmlStructuredError, xmlStructuredErrorFunc, XML_EMPTY) \ - XML_OP(xmlGenericErrorContext, void *, XML_EMPTY) \ - XML_OP(xmlStructuredErrorContext, void *, XML_EMPTY) \ - XML_OP(xmlGetWarningsDefaultValue, int, XML_EMPTY) \ - XML_OP(xmlIndentTreeOutput, int, XML_EMPTY) \ - XML_OP(xmlTreeIndentString, const char *, XML_EMPTY) \ - XML_OP(xmlKeepBlanksDefaultValue, int, XML_EMPTY) \ + 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_EMPTY) \ - XML_OP(xmlParserDebugEntities, int, XML_EMPTY) \ - XML_OP(xmlParserVersion, const char *, XML_EMPTY) \ + XML_OP(xmlLoadExtDtdDefaultValue, int, XML_DEPRECATED) \ + XML_OP(xmlParserDebugEntities, int, XML_DEPRECATED) \ XML_OP(xmlPedanticParserDefaultValue, int, XML_DEPRECATED) \ - XML_OP(xmlSaveNoEmptyTags, int, XML_EMPTY) \ - XML_OP(xmlSubstituteEntitiesDefaultValue, int, XML_EMPTY) \ + XML_OP(xmlSubstituteEntitiesDefaultValue, int, XML_DEPRECATED) \ XML_OP(xmlRegisterNodeDefaultValue, xmlRegisterNodeFunc, XML_DEPRECATED) \ XML_OP(xmlDeregisterNodeDefaultValue, xmlDeregisterNodeFunc, \ XML_DEPRECATED) \ diff --git a/include/libxml/parser.h b/include/libxml/parser.h index 5afb3767..2b03fd40 100644 --- a/include/libxml/parser.h +++ b/include/libxml/parser.h @@ -850,15 +850,15 @@ XMLPUBFUN xmlDocPtr xmlParseMemory (const char *buffer, int size); #endif /* LIBXML_SAX1_ENABLED */ -XMLPUBFUN int +XML_DEPRECATED XMLPUBFUN int xmlSubstituteEntitiesDefault(int val); -XMLPUBFUN int +XML_DEPRECATED XMLPUBFUN int xmlKeepBlanksDefault (int val); XMLPUBFUN void xmlStopParser (xmlParserCtxtPtr ctxt); -XMLPUBFUN int +XML_DEPRECATED XMLPUBFUN int xmlPedanticParserDefault(int val); -XMLPUBFUN int +XML_DEPRECATED XMLPUBFUN int xmlLineNumbersDefault (int val); #ifdef LIBXML_SAX1_ENABLED diff --git a/python/generator.py b/python/generator.py index 3a5db228..5697cc2a 100755 --- a/python/generator.py +++ b/python/generator.py @@ -310,6 +310,8 @@ deprecated_funcs = { 'xmlInitializeDict': True, 'xmlInitializePredefinedEntities': True, 'xmlIsRef': True, + 'xmlKeepBlanksDefault': True, + 'xmlLineNumbersDefault': True, 'xmlNamespaceParseNCName': True, 'xmlNamespaceParseNSDef': True, 'xmlNanoFTPCleanup': True, @@ -354,6 +356,7 @@ deprecated_funcs = { 'xmlParseXMLDecl': True, 'xmlParserHandlePEReference': True, 'xmlParserHandleReference': True, + 'xmlPedanticParserDefault': True, 'xmlRecoverDoc': True, 'xmlRecoverFile': True, 'xmlRecoverMemory': True, @@ -368,9 +371,16 @@ deprecated_funcs = { 'xmlSkipBlankChars': True, 'xmlStringDecodeEntities': True, 'xmlStringLenDecodeEntities': True, + 'xmlSubstituteEntitiesDefault': True, 'xmlThrDefDefaultBufferSize': True, + 'xmlThrDefDoValidityCheckingDefaultValue': True, + 'xmlThrDefGetWarningsDefaultValue': True, + 'xmlThrDefKeepBlanksDefaultValue': True, 'xmlThrDefLineNumbersDefaultValue': True, + 'xmlThrDefLoadExtDtdDefaultValue': True, + 'xmlThrDefParserDebugEntities': True, 'xmlThrDefPedanticParserDefaultValue': True, + 'xmlThrDefSubstituteEntitiesDefaultValue': True, 'xmlXPathInit': True, 'xmlXPtrEvalRangePredicate': True, 'xmlXPtrNewCollapsedRange': True,