Skip to content

Commit

Permalink
parser: Deprecate global parser options
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nwellnhof committed Sep 20, 2023
1 parent 209516a commit db8b972
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 30 deletions.
54 changes: 28 additions & 26 deletions include/libxml/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,31 @@ XMLPUBFUN void
xmlThrDefSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler);
XMLPUBFUN void
xmlThrDefSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler);
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);
XMLPUBFUN int
XML_DEPRECATED XMLPUBFUN int
xmlThrDefDoValidityCheckingDefaultValue(int v);
XMLPUBFUN int
XML_DEPRECATED XMLPUBFUN int
xmlThrDefGetWarningsDefaultValue(int v);
XMLPUBFUN int
xmlThrDefIndentTreeOutput(int v);
XMLPUBFUN const char *
xmlThrDefTreeIndentString(const char * v);
XMLPUBFUN int
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);
Expand All @@ -91,27 +91,29 @@ xmlDllMain(void *hinstDLL, unsigned long fdwReason,

#define XML_GLOBALS_CORE \
XML_OP(xmlLastError, xmlError, XML_EMPTY) \
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(xmlStructuredError, xmlStructuredErrorFunc, XML_EMPTY) \
XML_OP(xmlStructuredErrorContext, void *, XML_EMPTY) \
XML_OP(xmlGetWarningsDefaultValue, int, 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(xmlKeepBlanksDefaultValue, int, 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_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) \
Expand Down
8 changes: 4 additions & 4 deletions include/libxml/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions python/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ def enum(type, name, value):
'xmlInitializeDict': True,
'xmlInitializePredefinedEntities': True,
'xmlIsRef': True,
'xmlKeepBlanksDefault': True,
'xmlLineNumbersDefault': True,
'xmlNamespaceParseNCName': True,
'xmlNamespaceParseNSDef': True,
'xmlNanoFTPCleanup': True,
Expand Down Expand Up @@ -354,6 +356,7 @@ def enum(type, name, value):
'xmlParseXMLDecl': True,
'xmlParserHandlePEReference': True,
'xmlParserHandleReference': True,
'xmlPedanticParserDefault': True,
'xmlRecoverDoc': True,
'xmlRecoverFile': True,
'xmlRecoverMemory': True,
Expand All @@ -368,9 +371,16 @@ def enum(type, name, value):
'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,
Expand Down

0 comments on commit db8b972

Please sign in to comment.