nokogiri 1.11.0 → 1.11.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/LICENSE-DEPENDENCIES.md +12 -12
- data/LICENSE.md +1 -1
- data/README.md +21 -16
- data/dependencies.yml +12 -12
- data/ext/nokogiri/depend +34 -474
- data/ext/nokogiri/extconf.rb +253 -183
- data/ext/nokogiri/html_document.c +10 -15
- data/ext/nokogiri/html_element_description.c +84 -71
- data/ext/nokogiri/html_entity_lookup.c +21 -16
- data/ext/nokogiri/html_sax_parser_context.c +67 -64
- data/ext/nokogiri/html_sax_push_parser.c +42 -34
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +190 -60
- data/ext/nokogiri/nokogiri.h +158 -75
- data/ext/nokogiri/test_global_handlers.c +40 -0
- data/ext/nokogiri/xml_attr.c +15 -15
- data/ext/nokogiri/xml_attribute_decl.c +18 -18
- data/ext/nokogiri/xml_cdata.c +13 -18
- data/ext/nokogiri/xml_comment.c +19 -26
- data/ext/nokogiri/xml_document.c +246 -188
- data/ext/nokogiri/xml_document_fragment.c +13 -15
- data/ext/nokogiri/xml_dtd.c +54 -48
- data/ext/nokogiri/xml_element_content.c +30 -27
- data/ext/nokogiri/xml_element_decl.c +22 -22
- data/ext/nokogiri/xml_encoding_handler.c +17 -11
- data/ext/nokogiri/xml_entity_decl.c +32 -30
- data/ext/nokogiri/xml_entity_reference.c +16 -18
- data/ext/nokogiri/xml_namespace.c +56 -49
- data/ext/nokogiri/xml_node.c +371 -320
- data/ext/nokogiri/xml_node_set.c +168 -156
- data/ext/nokogiri/xml_processing_instruction.c +17 -19
- data/ext/nokogiri/xml_reader.c +191 -157
- data/ext/nokogiri/xml_relax_ng.c +29 -23
- data/ext/nokogiri/xml_sax_parser.c +117 -112
- data/ext/nokogiri/xml_sax_parser_context.c +101 -84
- data/ext/nokogiri/xml_sax_push_parser.c +36 -27
- data/ext/nokogiri/xml_schema.c +48 -42
- data/ext/nokogiri/xml_syntax_error.c +42 -21
- data/ext/nokogiri/xml_text.c +13 -17
- data/ext/nokogiri/xml_xpath_context.c +134 -127
- data/ext/nokogiri/xslt_stylesheet.c +157 -157
- data/lib/nokogiri.rb +1 -22
- data/lib/nokogiri/css/parser.rb +1 -1
- data/lib/nokogiri/extension.rb +26 -0
- data/lib/nokogiri/html/document_fragment.rb +15 -15
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/version/info.rb +32 -8
- data/lib/nokogiri/xml/document.rb +74 -28
- data/lib/nokogiri/xml/node.rb +39 -42
- data/lib/nokogiri/xml/reader.rb +2 -9
- data/lib/nokogiri/xml/xpath.rb +1 -3
- data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
- data/patches/libxml2/{0002-Remove-script-macro-support.patch → 0001-Remove-script-macro-support.patch} +0 -0
- data/patches/libxml2/{0003-Update-entities-to-remove-handling-of-ssi.patch → 0002-Update-entities-to-remove-handling-of-ssi.patch} +0 -0
- data/patches/libxml2/{0004-libxml2.la-is-in-top_builddir.patch → 0003-libxml2.la-is-in-top_builddir.patch} +1 -1
- data/patches/libxml2/{0008-use-glibc-strlen.patch → 0004-use-glibc-strlen.patch} +0 -0
- data/patches/libxml2/{0009-avoid-isnan-isinf.patch → 0005-avoid-isnan-isinf.patch} +4 -4
- data/patches/libxml2/0006-update-automake-files-for-arm64.patch +2511 -0
- data/patches/libxslt/0001-update-automake-files-for-arm64.patch +2511 -0
- data/patches/libxslt/0002-Fix-xml2-config-check-in-configure-script.patch +19 -0
- data/ports/archives/libxml2-2.9.12.tar.gz +0 -0
- metadata +20 -53
- data/ext/nokogiri/html_document.h +0 -10
- data/ext/nokogiri/html_element_description.h +0 -10
- data/ext/nokogiri/html_entity_lookup.h +0 -8
- data/ext/nokogiri/html_sax_parser_context.h +0 -11
- data/ext/nokogiri/html_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_attr.h +0 -9
- data/ext/nokogiri/xml_attribute_decl.h +0 -9
- data/ext/nokogiri/xml_cdata.h +0 -9
- data/ext/nokogiri/xml_comment.h +0 -9
- data/ext/nokogiri/xml_document.h +0 -23
- data/ext/nokogiri/xml_document_fragment.h +0 -10
- data/ext/nokogiri/xml_dtd.h +0 -10
- data/ext/nokogiri/xml_element_content.h +0 -10
- data/ext/nokogiri/xml_element_decl.h +0 -9
- data/ext/nokogiri/xml_encoding_handler.h +0 -8
- data/ext/nokogiri/xml_entity_decl.h +0 -10
- data/ext/nokogiri/xml_entity_reference.h +0 -9
- data/ext/nokogiri/xml_io.c +0 -63
- data/ext/nokogiri/xml_io.h +0 -11
- data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
- data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
- data/ext/nokogiri/xml_namespace.h +0 -14
- data/ext/nokogiri/xml_node.h +0 -13
- data/ext/nokogiri/xml_node_set.h +0 -12
- data/ext/nokogiri/xml_processing_instruction.h +0 -9
- data/ext/nokogiri/xml_reader.h +0 -10
- data/ext/nokogiri/xml_relax_ng.h +0 -9
- data/ext/nokogiri/xml_sax_parser.h +0 -39
- data/ext/nokogiri/xml_sax_parser_context.h +0 -10
- data/ext/nokogiri/xml_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_schema.h +0 -9
- data/ext/nokogiri/xml_syntax_error.h +0 -13
- data/ext/nokogiri/xml_text.h +0 -9
- data/ext/nokogiri/xml_xpath_context.h +0 -10
- data/ext/nokogiri/xslt_stylesheet.h +0 -14
- data/patches/libxml2/0001-Revert-Do-not-URI-escape-in-server-side-includes.patch +0 -78
- data/patches/libxml2/0005-Fix-infinite-loop-in-xmlStringLenDecodeEntities.patch +0 -32
- data/patches/libxml2/0006-htmlParseComment-treat-as-if-it-closed-the-comment.patch +0 -73
- data/patches/libxml2/0007-use-new-htmlParseLookupCommentEnd-to-find-comment-en.patch +0 -103
- data/ports/archives/libxml2-2.9.10.tar.gz +0 -0
@@ -1,4 +1,6 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriHtmlSaxPushParser;
|
2
4
|
|
3
5
|
/*
|
4
6
|
* call-seq:
|
@@ -6,25 +8,32 @@
|
|
6
8
|
*
|
7
9
|
* Write +chunk+ to PushParser. +last_chunk+ triggers the end_document handle
|
8
10
|
*/
|
9
|
-
static VALUE
|
11
|
+
static VALUE
|
12
|
+
native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
|
10
13
|
{
|
11
14
|
xmlParserCtxtPtr ctx;
|
12
|
-
const char *
|
13
|
-
int size
|
14
|
-
|
15
|
+
const char *chunk = NULL;
|
16
|
+
int size = 0;
|
17
|
+
int status = 0;
|
18
|
+
libxmlStructuredErrorHandlerState handler_state;
|
15
19
|
|
16
20
|
Data_Get_Struct(self, xmlParserCtxt, ctx);
|
17
21
|
|
18
|
-
if(Qnil != _chunk) {
|
22
|
+
if (Qnil != _chunk) {
|
19
23
|
chunk = StringValuePtr(_chunk);
|
20
24
|
size = (int)RSTRING_LEN(_chunk);
|
21
25
|
}
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
Nokogiri_structured_error_func_save_and_set(&handler_state, NULL, NULL);
|
28
|
+
|
29
|
+
status = htmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0);
|
30
|
+
|
31
|
+
Nokogiri_structured_error_func_restore(&handler_state);
|
32
|
+
|
33
|
+
if ((status != 0) && !(ctx->options & XML_PARSE_RECOVER)) {
|
34
|
+
// TODO: there appear to be no tests for this block
|
35
|
+
xmlErrorPtr e = xmlCtxtGetLastError(ctx);
|
36
|
+
Nokogiri_error_raise(NULL, e);
|
28
37
|
}
|
29
38
|
|
30
39
|
return self;
|
@@ -36,34 +45,37 @@ static VALUE native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
|
|
36
45
|
*
|
37
46
|
* Initialize the push parser with +xml_sax+ using +filename+
|
38
47
|
*/
|
39
|
-
static VALUE
|
40
|
-
|
48
|
+
static VALUE
|
49
|
+
initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename,
|
50
|
+
VALUE encoding)
|
41
51
|
{
|
42
52
|
htmlSAXHandlerPtr sax;
|
43
|
-
const char *
|
53
|
+
const char *filename = NULL;
|
44
54
|
htmlParserCtxtPtr ctx;
|
45
55
|
xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
|
46
56
|
|
47
57
|
Data_Get_Struct(_xml_sax, xmlSAXHandler, sax);
|
48
58
|
|
49
|
-
if(_filename != Qnil) filename = StringValueCStr(_filename);
|
59
|
+
if (_filename != Qnil) { filename = StringValueCStr(_filename); }
|
50
60
|
|
51
61
|
if (!NIL_P(encoding)) {
|
52
62
|
enc = xmlParseCharEncoding(StringValueCStr(encoding));
|
53
|
-
if (enc == XML_CHAR_ENCODING_ERROR)
|
63
|
+
if (enc == XML_CHAR_ENCODING_ERROR) {
|
54
64
|
rb_raise(rb_eArgError, "Unsupported Encoding");
|
65
|
+
}
|
55
66
|
}
|
56
67
|
|
57
68
|
ctx = htmlCreatePushParserCtxt(
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
if(ctx == NULL)
|
69
|
+
sax,
|
70
|
+
NULL,
|
71
|
+
NULL,
|
72
|
+
0,
|
73
|
+
filename,
|
74
|
+
enc
|
75
|
+
);
|
76
|
+
if (ctx == NULL) {
|
66
77
|
rb_raise(rb_eRuntimeError, "Could not create a parser context");
|
78
|
+
}
|
67
79
|
|
68
80
|
ctx->userData = NOKOGIRI_SAX_TUPLE_NEW(ctx, self);
|
69
81
|
|
@@ -72,16 +84,12 @@ static VALUE initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename,
|
|
72
84
|
return self;
|
73
85
|
}
|
74
86
|
|
75
|
-
|
76
|
-
|
87
|
+
void
|
88
|
+
noko_init_html_sax_push_parser()
|
77
89
|
{
|
78
|
-
|
79
|
-
|
80
|
-
VALUE sax = rb_define_module_under(html, "SAX");
|
81
|
-
VALUE klass = rb_define_class_under(sax, "PushParser", cNokogiriXmlSaxPushParser);
|
82
|
-
|
83
|
-
cNokogiriHtmlSaxPushParser = klass;
|
90
|
+
assert(cNokogiriXmlSaxPushParser);
|
91
|
+
cNokogiriHtmlSaxPushParser = rb_define_class_under(mNokogiriHtmlSax, "PushParser", cNokogiriXmlSaxPushParser);
|
84
92
|
|
85
|
-
rb_define_private_method(
|
86
|
-
rb_define_private_method(
|
93
|
+
rb_define_private_method(cNokogiriHtmlSaxPushParser, "initialize_native", initialize_native, 3);
|
94
|
+
rb_define_private_method(cNokogiriHtmlSaxPushParser, "native_write", native_write, 2);
|
87
95
|
}
|
@@ -0,0 +1,121 @@
|
|
1
|
+
#ifndef HAVE_XMLFIRSTELEMENTCHILD
|
2
|
+
#include <nokogiri.h>
|
3
|
+
/**
|
4
|
+
* xmlFirstElementChild:
|
5
|
+
* @parent: the parent node
|
6
|
+
*
|
7
|
+
* Finds the first child node of that element which is a Element node
|
8
|
+
* Note the handling of entities references is different than in
|
9
|
+
* the W3C DOM element traversal spec since we don't have back reference
|
10
|
+
* from entities content to entities references.
|
11
|
+
*
|
12
|
+
* Returns the first element child or NULL if not available
|
13
|
+
*/
|
14
|
+
xmlNodePtr
|
15
|
+
xmlFirstElementChild(xmlNodePtr parent)
|
16
|
+
{
|
17
|
+
xmlNodePtr cur = NULL;
|
18
|
+
|
19
|
+
if (parent == NULL) {
|
20
|
+
return (NULL);
|
21
|
+
}
|
22
|
+
switch (parent->type) {
|
23
|
+
case XML_ELEMENT_NODE:
|
24
|
+
case XML_ENTITY_NODE:
|
25
|
+
case XML_DOCUMENT_NODE:
|
26
|
+
case XML_HTML_DOCUMENT_NODE:
|
27
|
+
cur = parent->children;
|
28
|
+
break;
|
29
|
+
default:
|
30
|
+
return (NULL);
|
31
|
+
}
|
32
|
+
while (cur != NULL) {
|
33
|
+
if (cur->type == XML_ELEMENT_NODE) {
|
34
|
+
return (cur);
|
35
|
+
}
|
36
|
+
cur = cur->next;
|
37
|
+
}
|
38
|
+
return (NULL);
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* xmlNextElementSibling:
|
43
|
+
* @node: the current node
|
44
|
+
*
|
45
|
+
* Finds the first closest next sibling of the node which is an
|
46
|
+
* element node.
|
47
|
+
* Note the handling of entities references is different than in
|
48
|
+
* the W3C DOM element traversal spec since we don't have back reference
|
49
|
+
* from entities content to entities references.
|
50
|
+
*
|
51
|
+
* Returns the next element sibling or NULL if not available
|
52
|
+
*/
|
53
|
+
xmlNodePtr
|
54
|
+
xmlNextElementSibling(xmlNodePtr node)
|
55
|
+
{
|
56
|
+
if (node == NULL) {
|
57
|
+
return (NULL);
|
58
|
+
}
|
59
|
+
switch (node->type) {
|
60
|
+
case XML_ELEMENT_NODE:
|
61
|
+
case XML_TEXT_NODE:
|
62
|
+
case XML_CDATA_SECTION_NODE:
|
63
|
+
case XML_ENTITY_REF_NODE:
|
64
|
+
case XML_ENTITY_NODE:
|
65
|
+
case XML_PI_NODE:
|
66
|
+
case XML_COMMENT_NODE:
|
67
|
+
case XML_DTD_NODE:
|
68
|
+
case XML_XINCLUDE_START:
|
69
|
+
case XML_XINCLUDE_END:
|
70
|
+
node = node->next;
|
71
|
+
break;
|
72
|
+
default:
|
73
|
+
return (NULL);
|
74
|
+
}
|
75
|
+
while (node != NULL) {
|
76
|
+
if (node->type == XML_ELEMENT_NODE) {
|
77
|
+
return (node);
|
78
|
+
}
|
79
|
+
node = node->next;
|
80
|
+
}
|
81
|
+
return (NULL);
|
82
|
+
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* xmlLastElementChild:
|
86
|
+
* @parent: the parent node
|
87
|
+
*
|
88
|
+
* Finds the last child node of that element which is a Element node
|
89
|
+
* Note the handling of entities references is different than in
|
90
|
+
* the W3C DOM element traversal spec since we don't have back reference
|
91
|
+
* from entities content to entities references.
|
92
|
+
*
|
93
|
+
* Returns the last element child or NULL if not available
|
94
|
+
*/
|
95
|
+
xmlNodePtr
|
96
|
+
xmlLastElementChild(xmlNodePtr parent)
|
97
|
+
{
|
98
|
+
xmlNodePtr cur = NULL;
|
99
|
+
|
100
|
+
if (parent == NULL) {
|
101
|
+
return (NULL);
|
102
|
+
}
|
103
|
+
switch (parent->type) {
|
104
|
+
case XML_ELEMENT_NODE:
|
105
|
+
case XML_ENTITY_NODE:
|
106
|
+
case XML_DOCUMENT_NODE:
|
107
|
+
case XML_HTML_DOCUMENT_NODE:
|
108
|
+
cur = parent->last;
|
109
|
+
break;
|
110
|
+
default:
|
111
|
+
return (NULL);
|
112
|
+
}
|
113
|
+
while (cur != NULL) {
|
114
|
+
if (cur->type == XML_ELEMENT_NODE) {
|
115
|
+
return (cur);
|
116
|
+
}
|
117
|
+
cur = cur->prev;
|
118
|
+
}
|
119
|
+
return (NULL);
|
120
|
+
}
|
121
|
+
#endif
|
data/ext/nokogiri/nokogiri.c
CHANGED
@@ -1,24 +1,67 @@
|
|
1
1
|
#include <nokogiri.h>
|
2
2
|
|
3
3
|
VALUE mNokogiri ;
|
4
|
-
VALUE mNokogiriXml ;
|
5
4
|
VALUE mNokogiriHtml ;
|
6
|
-
VALUE mNokogiriXslt ;
|
7
|
-
VALUE mNokogiriXmlSax ;
|
8
5
|
VALUE mNokogiriHtmlSax ;
|
6
|
+
VALUE mNokogiriXml ;
|
7
|
+
VALUE mNokogiriXmlSax ;
|
8
|
+
VALUE mNokogiriXmlXpath ;
|
9
|
+
VALUE mNokogiriXslt ;
|
10
|
+
|
11
|
+
VALUE cNokogiriSyntaxError;
|
12
|
+
VALUE cNokogiriXmlCharacterData;
|
13
|
+
VALUE cNokogiriXmlElement;
|
14
|
+
VALUE cNokogiriXmlXpathSyntaxError;
|
15
|
+
|
16
|
+
void noko_init_xml_attr();
|
17
|
+
void noko_init_xml_attribute_decl();
|
18
|
+
void noko_init_xml_cdata();
|
19
|
+
void noko_init_xml_comment();
|
20
|
+
void noko_init_xml_document();
|
21
|
+
void noko_init_xml_document_fragment();
|
22
|
+
void noko_init_xml_dtd();
|
23
|
+
void noko_init_xml_element_content();
|
24
|
+
void noko_init_xml_element_decl();
|
25
|
+
void noko_init_xml_encoding_handler();
|
26
|
+
void noko_init_xml_entity_decl();
|
27
|
+
void noko_init_xml_entity_reference();
|
28
|
+
void noko_init_xml_namespace();
|
29
|
+
void noko_init_xml_node();
|
30
|
+
void noko_init_xml_node_set();
|
31
|
+
void noko_init_xml_processing_instruction();
|
32
|
+
void noko_init_xml_reader();
|
33
|
+
void noko_init_xml_relax_ng();
|
34
|
+
void noko_init_xml_sax_parser();
|
35
|
+
void noko_init_xml_sax_parser_context();
|
36
|
+
void noko_init_xml_sax_push_parser();
|
37
|
+
void noko_init_xml_schema();
|
38
|
+
void noko_init_xml_syntax_error();
|
39
|
+
void noko_init_xml_text();
|
40
|
+
void noko_init_xml_xpath_context();
|
41
|
+
void noko_init_xslt_stylesheet();
|
42
|
+
void noko_init_html_document();
|
43
|
+
void noko_init_html_element_description();
|
44
|
+
void noko_init_html_entity_lookup();
|
45
|
+
void noko_init_html_sax_parser_context();
|
46
|
+
void noko_init_html_sax_push_parser();
|
47
|
+
void noko_init_test_global_handlers();
|
48
|
+
|
49
|
+
static ID id_read, id_write;
|
50
|
+
|
9
51
|
|
10
52
|
#ifndef HAVE_VASPRINTF
|
11
53
|
/*
|
12
54
|
* Thank you Geoffroy Couprie for this implementation of vasprintf!
|
13
55
|
*/
|
14
|
-
int
|
56
|
+
int
|
57
|
+
vasprintf(char **strp, const char *fmt, va_list ap)
|
15
58
|
{
|
16
59
|
/* Mingw32/64 have a broken vsnprintf implementation that fails when
|
17
60
|
* using a zero-byte limit in order to retrieve the required size for malloc.
|
18
61
|
* So we use a one byte buffer instead.
|
19
62
|
*/
|
20
63
|
char tmp[1];
|
21
|
-
int len = vsnprintf
|
64
|
+
int len = vsnprintf(tmp, 1, fmt, ap) + 1;
|
22
65
|
char *res = (char *)malloc((unsigned int)len);
|
23
66
|
if (res == NULL) {
|
24
67
|
return -1;
|
@@ -28,41 +71,91 @@ int vasprintf(char **strp, const char *fmt, va_list ap)
|
|
28
71
|
}
|
29
72
|
#endif
|
30
73
|
|
31
|
-
#include "ruby/util.h"
|
32
74
|
|
33
|
-
|
75
|
+
static VALUE
|
76
|
+
read_check(VALUE val)
|
77
|
+
{
|
78
|
+
VALUE *args = (VALUE *)val;
|
79
|
+
return rb_funcall(args[0], id_read, 1, args[1]);
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
static VALUE
|
84
|
+
read_failed(VALUE arg, VALUE exc)
|
85
|
+
{
|
86
|
+
return Qundef;
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
int
|
91
|
+
noko_io_read(void *ctx, char *buffer, int len)
|
92
|
+
{
|
93
|
+
VALUE string, args[2];
|
94
|
+
size_t str_len, safe_len;
|
95
|
+
|
96
|
+
args[0] = (VALUE)ctx;
|
97
|
+
args[1] = INT2NUM(len);
|
98
|
+
|
99
|
+
string = rb_rescue(read_check, (VALUE)args, read_failed, 0);
|
100
|
+
|
101
|
+
if (NIL_P(string)) { return 0; }
|
102
|
+
if (string == Qundef) { return -1; }
|
103
|
+
if (TYPE(string) != T_STRING) { return -1; }
|
104
|
+
|
105
|
+
str_len = (size_t)RSTRING_LEN(string);
|
106
|
+
safe_len = str_len > (size_t)len ? (size_t)len : str_len;
|
107
|
+
memcpy(buffer, StringValuePtr(string), safe_len);
|
108
|
+
|
109
|
+
return (int)safe_len;
|
110
|
+
}
|
111
|
+
|
112
|
+
|
113
|
+
static VALUE
|
114
|
+
write_check(VALUE val)
|
34
115
|
{
|
35
|
-
|
36
|
-
|
116
|
+
VALUE *args = (VALUE *)val;
|
117
|
+
return rb_funcall(args[0], id_write, 1, args[1]);
|
118
|
+
}
|
37
119
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
120
|
+
|
121
|
+
static VALUE
|
122
|
+
write_failed(VALUE arg, VALUE exc)
|
123
|
+
{
|
124
|
+
return Qundef;
|
42
125
|
}
|
43
126
|
|
44
|
-
|
127
|
+
|
128
|
+
int
|
129
|
+
noko_io_write(void *ctx, char *buffer, int len)
|
45
130
|
{
|
46
|
-
|
131
|
+
VALUE args[2], size;
|
132
|
+
|
133
|
+
args[0] = (VALUE)ctx;
|
134
|
+
args[1] = rb_str_new(buffer, (long)len);
|
135
|
+
|
136
|
+
size = rb_rescue(write_check, (VALUE)args, write_failed, 0);
|
47
137
|
|
48
|
-
if (
|
49
|
-
|
50
|
-
|
138
|
+
if (size == Qundef) { return -1; }
|
139
|
+
|
140
|
+
return NUM2INT(size);
|
51
141
|
}
|
52
142
|
|
53
|
-
|
143
|
+
|
144
|
+
int
|
145
|
+
noko_io_close(void *ctx)
|
54
146
|
{
|
55
|
-
|
56
|
-
|
57
|
-
(xmlMallocFunc)ruby_xmalloc,
|
58
|
-
(xmlReallocFunc)ruby_xrealloc,
|
59
|
-
ruby_strdup
|
60
|
-
);
|
147
|
+
return 0;
|
148
|
+
}
|
61
149
|
|
150
|
+
|
151
|
+
void
|
152
|
+
Init_nokogiri()
|
153
|
+
{
|
62
154
|
mNokogiri = rb_define_module("Nokogiri");
|
63
155
|
mNokogiriXml = rb_define_module_under(mNokogiri, "XML");
|
64
156
|
mNokogiriHtml = rb_define_module_under(mNokogiri, "HTML");
|
65
157
|
mNokogiriXslt = rb_define_module_under(mNokogiri, "XSLT");
|
158
|
+
mNokogiriXmlXpath = rb_define_module_under(mNokogiriXml, "XPath");
|
66
159
|
mNokogiriXmlSax = rb_define_module_under(mNokogiriXml, "SAX");
|
67
160
|
mNokogiriHtmlSax = rb_define_module_under(mNokogiriHtml, "SAX");
|
68
161
|
|
@@ -74,11 +167,11 @@ void Init_nokogiri()
|
|
74
167
|
|
75
168
|
#ifdef NOKOGIRI_PACKAGED_LIBRARIES
|
76
169
|
rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qtrue);
|
77
|
-
#ifdef NOKOGIRI_PRECOMPILED_LIBRARIES
|
170
|
+
# ifdef NOKOGIRI_PRECOMPILED_LIBRARIES
|
78
171
|
rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qtrue);
|
79
|
-
#else
|
172
|
+
# else
|
80
173
|
rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
|
81
|
-
#endif
|
174
|
+
# endif
|
82
175
|
rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATCHES), " "));
|
83
176
|
rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATCHES), " "));
|
84
177
|
#else
|
@@ -98,38 +191,75 @@ void Init_nokogiri()
|
|
98
191
|
rb_const_set(mNokogiri, rb_intern("OTHER_LIBRARY_VERSIONS"), NOKOGIRI_STR_NEW2(NOKOGIRI_OTHER_LIBRARY_VERSIONS));
|
99
192
|
#endif
|
100
193
|
|
194
|
+
#if defined(_WIN32) && !defined(NOKOGIRI_PACKAGED_LIBRARIES)
|
195
|
+
/*
|
196
|
+
* We choose *not* to do use Ruby's memory management functions with windows DLLs because of this
|
197
|
+
* issue in libxml 2.9.12:
|
198
|
+
*
|
199
|
+
* https://github.com/sparklemotion/nokogiri/issues/2241
|
200
|
+
*
|
201
|
+
* If the atexit() issue gets fixed in a future version of libxml2, then we may be able to skip
|
202
|
+
* this config only for the specific libxml2 versions 2.9.12.
|
203
|
+
*
|
204
|
+
* Alternatively, now that Ruby has a generational GC, it might be OK to let libxml2 use its
|
205
|
+
* default memory management functions (recall that this config was introduced to reduce memory
|
206
|
+
* bloat and allow Ruby to GC more often); but we should *really* test with production workloads
|
207
|
+
* before making that kind of a potentially-invasive change.
|
208
|
+
*/
|
209
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_MEMORY_MANAGEMENT"), NOKOGIRI_STR_NEW2("default"));
|
210
|
+
#else
|
211
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_MEMORY_MANAGEMENT"), NOKOGIRI_STR_NEW2("ruby"));
|
212
|
+
xmlMemSetup((xmlFreeFunc)ruby_xfree, (xmlMallocFunc)ruby_xmalloc, (xmlReallocFunc)ruby_xrealloc, ruby_strdup);
|
213
|
+
#endif
|
214
|
+
|
101
215
|
xmlInitParser();
|
102
216
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
217
|
+
cNokogiriSyntaxError = rb_define_class_under(mNokogiri, "SyntaxError", rb_eStandardError);
|
218
|
+
noko_init_xml_syntax_error();
|
219
|
+
assert(cNokogiriXmlSyntaxError);
|
220
|
+
cNokogiriXmlXpathSyntaxError = rb_define_class_under(mNokogiriXmlXpath, "SyntaxError", cNokogiriXmlSyntaxError);
|
221
|
+
|
222
|
+
noko_init_xml_element_content();
|
223
|
+
noko_init_xml_encoding_handler();
|
224
|
+
noko_init_xml_namespace();
|
225
|
+
noko_init_xml_node_set();
|
226
|
+
noko_init_xml_reader();
|
227
|
+
noko_init_xml_sax_parser();
|
228
|
+
noko_init_xml_xpath_context();
|
229
|
+
noko_init_xslt_stylesheet();
|
230
|
+
noko_init_html_element_description();
|
231
|
+
noko_init_html_entity_lookup();
|
232
|
+
|
233
|
+
noko_init_xml_schema();
|
234
|
+
noko_init_xml_relax_ng();
|
235
|
+
|
236
|
+
noko_init_xml_sax_parser_context();
|
237
|
+
noko_init_html_sax_parser_context();
|
238
|
+
|
239
|
+
noko_init_xml_sax_push_parser();
|
240
|
+
noko_init_html_sax_push_parser();
|
241
|
+
|
242
|
+
noko_init_xml_node();
|
243
|
+
noko_init_xml_attr();
|
244
|
+
noko_init_xml_attribute_decl();
|
245
|
+
noko_init_xml_dtd();
|
246
|
+
noko_init_xml_element_decl();
|
247
|
+
noko_init_xml_entity_decl();
|
248
|
+
noko_init_xml_entity_reference();
|
249
|
+
noko_init_xml_processing_instruction();
|
250
|
+
assert(cNokogiriXmlNode);
|
251
|
+
cNokogiriXmlElement = rb_define_class_under(mNokogiriXml, "Element", cNokogiriXmlNode);
|
252
|
+
cNokogiriXmlCharacterData = rb_define_class_under(mNokogiriXml, "CharacterData", cNokogiriXmlNode);
|
253
|
+
noko_init_xml_comment();
|
254
|
+
noko_init_xml_text();
|
255
|
+
noko_init_xml_cdata();
|
256
|
+
|
257
|
+
noko_init_xml_document_fragment();
|
258
|
+
noko_init_xml_document();
|
259
|
+
noko_init_html_document();
|
260
|
+
|
261
|
+
noko_init_test_global_handlers();
|
262
|
+
|
263
|
+
id_read = rb_intern("read");
|
264
|
+
id_write = rb_intern("write");
|
135
265
|
}
|