-
-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libxml 2.14-dev deprecations (#3241)
**What problem is this PR intended to solve?** Upstream has started to deprecate some struct members that we're accessing directly. Let's start addressing some of those issues. I'm also introducing some polyfills for libxml2 so we can always use the latest and greatest API functions. **Have you included adequate test coverage?** Refactoring. Existing coverage is adequate. **Does this change affect the behavior of either the C or the Java implementations?** Refactoring. No behavior changes. **Related upstream PRs** - [parser: implement xmlCtxtGetOptions (!262) · Merge requests · GNOME / libxml2 · GitLab](https://gitlab.gnome.org/GNOME/libxml2/-/merge_requests/262)
- Loading branch information
Showing
14 changed files
with
243 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <nokogiri.h> | ||
|
||
VALUE cNokogiriHtml4SaxParser; | ||
|
||
static ID id_start_document; | ||
|
||
static void | ||
noko_html4_sax_parser_start_document(void *ctx) | ||
{ | ||
VALUE self = NOKOGIRI_SAX_SELF(ctx); | ||
VALUE doc = rb_iv_get(self, "@document"); | ||
|
||
rb_funcall(doc, id_start_document, 0); | ||
} | ||
|
||
static VALUE | ||
noko_html4_sax_parser_initialize(VALUE self) | ||
{ | ||
xmlSAXHandlerPtr handler = noko_xml_sax_parser_unwrap(self); | ||
|
||
rb_call_super(0, NULL); | ||
|
||
handler->startDocument = noko_html4_sax_parser_start_document; | ||
|
||
return self; | ||
} | ||
|
||
void | ||
noko_init_html4_sax_parser(void) | ||
{ | ||
cNokogiriHtml4SaxParser = rb_define_class_under(mNokogiriHtml4Sax, "Parser", cNokogiriXmlSaxParser); | ||
|
||
rb_define_private_method(cNokogiriHtml4SaxParser, "initialize_native", noko_html4_sax_parser_initialize, 0); | ||
|
||
id_start_document = rb_intern("start_document"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include <nokogiri.h> | ||
|
||
#ifndef HAVE_XMLCTXTSETOPTIONS | ||
/* based on libxml2-2.14.0-dev (1d8bd126) parser.c xmlCtxtSetInternalOptions */ | ||
int | ||
xmlCtxtSetOptions(xmlParserCtxtPtr ctxt, int options) | ||
{ | ||
int keepMask = 0; | ||
int allMask; | ||
|
||
if (ctxt == NULL) { | ||
return (-1); | ||
} | ||
|
||
/* | ||
* XInclude options aren't handled by the parser. | ||
* | ||
* XML_PARSE_XINCLUDE | ||
* XML_PARSE_NOXINCNODE | ||
* XML_PARSE_NOBASEFIX | ||
*/ | ||
allMask = XML_PARSE_RECOVER | | ||
XML_PARSE_NOENT | | ||
XML_PARSE_DTDLOAD | | ||
XML_PARSE_DTDATTR | | ||
XML_PARSE_DTDVALID | | ||
XML_PARSE_NOERROR | | ||
XML_PARSE_NOWARNING | | ||
XML_PARSE_PEDANTIC | | ||
XML_PARSE_NOBLANKS | | ||
#ifdef LIBXML_SAX1_ENABLED | ||
XML_PARSE_SAX1 | | ||
#endif | ||
XML_PARSE_NONET | | ||
XML_PARSE_NODICT | | ||
XML_PARSE_NSCLEAN | | ||
XML_PARSE_NOCDATA | | ||
XML_PARSE_COMPACT | | ||
XML_PARSE_OLD10 | | ||
XML_PARSE_HUGE | | ||
XML_PARSE_OLDSAX | | ||
XML_PARSE_IGNORE_ENC | | ||
XML_PARSE_BIG_LINES; | ||
|
||
ctxt->options = (ctxt->options & keepMask) | (options & allMask); | ||
|
||
/* | ||
* For some options, struct members are historically the source | ||
* of truth. The values are initalized from global variables and | ||
* old code could also modify them directly. Several older API | ||
* functions that don't take an options argument rely on these | ||
* deprecated mechanisms. | ||
* | ||
* Once public access to struct members and the globals are | ||
* disabled, we can use the options bitmask as source of | ||
* truth, making all these struct members obsolete. | ||
* | ||
* The XML_DETECT_IDS flags is misnamed. It simply enables | ||
* loading of the external subset. | ||
*/ | ||
ctxt->recovery = (options & XML_PARSE_RECOVER) ? 1 : 0; | ||
ctxt->replaceEntities = (options & XML_PARSE_NOENT) ? 1 : 0; | ||
ctxt->loadsubset = (options & XML_PARSE_DTDLOAD) ? XML_DETECT_IDS : 0; | ||
ctxt->loadsubset |= (options & XML_PARSE_DTDATTR) ? XML_COMPLETE_ATTRS : 0; | ||
ctxt->validate = (options & XML_PARSE_DTDVALID) ? 1 : 0; | ||
ctxt->pedantic = (options & XML_PARSE_PEDANTIC) ? 1 : 0; | ||
ctxt->keepBlanks = (options & XML_PARSE_NOBLANKS) ? 0 : 1; | ||
ctxt->dictNames = (options & XML_PARSE_NODICT) ? 0 : 1; | ||
|
||
/* | ||
* Changing SAX callbacks is a bad idea. This should be fixed. | ||
*/ | ||
if (options & XML_PARSE_NOBLANKS) { | ||
ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace; | ||
} | ||
if (options & XML_PARSE_NOCDATA) { | ||
ctxt->sax->cdataBlock = NULL; | ||
} | ||
if (options & XML_PARSE_HUGE) { | ||
if (ctxt->dict != NULL) { | ||
xmlDictSetLimit(ctxt->dict, 0); | ||
} | ||
} | ||
|
||
ctxt->linenumbers = 1; | ||
|
||
return (options & ~allMask); | ||
} | ||
#endif | ||
|
||
#ifndef HAVE_XMLCTXTGETOPTIONS | ||
int | ||
xmlCtxtGetOptions(xmlParserCtxtPtr ctxt) | ||
{ | ||
return (ctxt->options); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.