nokogiri 1.11.0.rc3-java → 1.11.0.rc4-java

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.

Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +1015 -947
  3. data/README.md +1 -1
  4. data/ext/java/nokogiri/HtmlSaxParserContext.java +1 -1
  5. data/ext/java/nokogiri/HtmlSaxPushParser.java +1 -1
  6. data/ext/java/nokogiri/XmlNode.java +4 -6
  7. data/ext/java/nokogiri/XmlReader.java +2 -2
  8. data/ext/java/nokogiri/XmlRelaxng.java +10 -3
  9. data/ext/java/nokogiri/XmlSaxParserContext.java +8 -3
  10. data/ext/java/nokogiri/XmlSchema.java +84 -24
  11. data/ext/java/nokogiri/XmlSyntaxError.java +2 -6
  12. data/ext/java/nokogiri/XmlXpathContext.java +48 -18
  13. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +51 -39
  14. data/ext/java/nokogiri/internals/NokogiriHandler.java +1 -1
  15. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +9 -2
  16. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +62 -6
  17. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +4 -2
  18. data/ext/java/nokogiri/internals/XmlDomParserContext.java +2 -2
  19. data/ext/nokogiri/depend +476 -357
  20. data/ext/nokogiri/extconf.rb +441 -321
  21. data/ext/nokogiri/html_document.c +79 -78
  22. data/ext/nokogiri/html_sax_parser_context.c +2 -2
  23. data/ext/nokogiri/nokogiri.c +34 -46
  24. data/ext/nokogiri/xml_document.c +2 -2
  25. data/ext/nokogiri/xml_node.c +1 -1
  26. data/ext/nokogiri/xml_node_set.c +1 -1
  27. data/ext/nokogiri/xml_relax_ng.c +29 -11
  28. data/ext/nokogiri/xml_sax_parser.c +2 -7
  29. data/ext/nokogiri/xml_sax_parser_context.c +2 -2
  30. data/ext/nokogiri/xml_schema.c +55 -13
  31. data/ext/nokogiri/xml_xpath_context.c +80 -4
  32. data/ext/nokogiri/xslt_stylesheet.c +1 -4
  33. data/lib/nokogiri.rb +1 -1
  34. data/lib/nokogiri/css/parser.rb +3 -3
  35. data/lib/nokogiri/css/parser.y +2 -2
  36. data/lib/nokogiri/css/xpath_visitor.rb +70 -42
  37. data/lib/nokogiri/html/document.rb +12 -26
  38. data/lib/nokogiri/nokogiri.jar +0 -0
  39. data/lib/nokogiri/version.rb +2 -149
  40. data/lib/nokogiri/version/constant.rb +5 -0
  41. data/lib/nokogiri/version/info.rb +182 -0
  42. data/lib/nokogiri/xml/document.rb +17 -7
  43. data/lib/nokogiri/xml/document_fragment.rb +4 -6
  44. data/lib/nokogiri/xml/node.rb +50 -27
  45. data/lib/nokogiri/xml/parse_options.rb +6 -0
  46. data/lib/nokogiri/xml/relax_ng.rb +6 -2
  47. data/lib/nokogiri/xml/schema.rb +12 -4
  48. data/lib/nokogiri/xml/searchable.rb +3 -1
  49. metadata +47 -73
  50. data/ext/nokogiri/html_document.h +0 -10
  51. data/ext/nokogiri/html_element_description.h +0 -10
  52. data/ext/nokogiri/html_entity_lookup.h +0 -8
  53. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  54. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  55. data/ext/nokogiri/nokogiri.h +0 -134
  56. data/ext/nokogiri/xml_attr.h +0 -9
  57. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  58. data/ext/nokogiri/xml_cdata.h +0 -9
  59. data/ext/nokogiri/xml_comment.h +0 -9
  60. data/ext/nokogiri/xml_document.h +0 -23
  61. data/ext/nokogiri/xml_document_fragment.h +0 -10
  62. data/ext/nokogiri/xml_dtd.h +0 -10
  63. data/ext/nokogiri/xml_element_content.h +0 -10
  64. data/ext/nokogiri/xml_element_decl.h +0 -9
  65. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  66. data/ext/nokogiri/xml_entity_decl.h +0 -10
  67. data/ext/nokogiri/xml_entity_reference.h +0 -9
  68. data/ext/nokogiri/xml_io.h +0 -11
  69. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  70. data/ext/nokogiri/xml_namespace.h +0 -14
  71. data/ext/nokogiri/xml_node.h +0 -13
  72. data/ext/nokogiri/xml_node_set.h +0 -12
  73. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  74. data/ext/nokogiri/xml_reader.h +0 -10
  75. data/ext/nokogiri/xml_relax_ng.h +0 -9
  76. data/ext/nokogiri/xml_sax_parser.h +0 -39
  77. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  78. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  79. data/ext/nokogiri/xml_schema.h +0 -9
  80. data/ext/nokogiri/xml_syntax_error.h +0 -13
  81. data/ext/nokogiri/xml_text.h +0 -9
  82. data/ext/nokogiri/xml_xpath_context.h +0 -10
  83. data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -1,6 +1,7 @@
1
1
  #include <html_document.h>
2
2
 
3
3
  static ID id_encoding_found;
4
+ static ID id_to_s;
4
5
 
5
6
  /*
6
7
  * call-seq:
@@ -8,19 +9,20 @@ static ID id_encoding_found;
8
9
  *
9
10
  * Create a new document
10
11
  */
11
- static VALUE new(int argc, VALUE *argv, VALUE klass)
12
+ static VALUE
13
+ rb_html_document_s_new(int argc, VALUE *argv, VALUE klass)
12
14
  {
13
15
  VALUE uri, external_id, rest, rb_doc;
14
16
  htmlDocPtr doc;
15
17
 
16
18
  rb_scan_args(argc, argv, "0*", &rest);
17
- uri = rb_ary_entry(rest, (long)0);
19
+ uri = rb_ary_entry(rest, (long)0);
18
20
  external_id = rb_ary_entry(rest, (long)1);
19
21
 
20
22
  doc = htmlNewDoc(
21
- RTEST(uri) ? (const xmlChar *)StringValueCStr(uri) : NULL,
22
- RTEST(external_id) ? (const xmlChar *)StringValueCStr(external_id) : NULL
23
- );
23
+ RTEST(uri) ? (const xmlChar *)StringValueCStr(uri) : NULL,
24
+ RTEST(external_id) ? (const xmlChar *)StringValueCStr(external_id) : NULL
25
+ );
24
26
  rb_doc = Nokogiri_wrap_xml_document(klass, doc);
25
27
  rb_obj_call_init(rb_doc, argc, argv);
26
28
  return rb_doc ;
@@ -33,60 +35,55 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
33
35
  * Read the HTML document from +io+ with given +url+, +encoding+,
34
36
  * and +options+. See Nokogiri::HTML.parse
35
37
  */
36
- static VALUE read_io( VALUE klass,
37
- VALUE io,
38
- VALUE url,
39
- VALUE encoding,
40
- VALUE options )
38
+ static VALUE
39
+ rb_html_document_s_read_io(VALUE klass, VALUE rb_io, VALUE rb_url, VALUE rb_encoding, VALUE rb_options)
41
40
  {
42
- const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url);
43
- const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
44
- VALUE error_list = rb_ary_new();
45
- VALUE document;
46
- htmlDocPtr doc;
41
+ VALUE rb_doc;
42
+ VALUE rb_error_list = rb_ary_new();
43
+ htmlDocPtr c_doc;
44
+ const char *c_url = NIL_P(rb_url) ? NULL : StringValueCStr(rb_url);
45
+ const char *c_encoding = NIL_P(rb_encoding) ? NULL : StringValueCStr(rb_encoding);
46
+ int options = NUM2INT(rb_options);
47
+
48
+ xmlSetStructuredErrorFunc((void *)rb_error_list, Nokogiri_error_array_pusher);
49
+
50
+ c_doc = htmlReadIO(io_read_callback, io_close_callback, (void *)rb_io, c_url, c_encoding, options);
47
51
 
48
- xmlResetLastError();
49
- xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
50
-
51
- doc = htmlReadIO(
52
- io_read_callback,
53
- io_close_callback,
54
- (void *)io,
55
- c_url,
56
- c_enc,
57
- (int)NUM2INT(options)
58
- );
59
52
  xmlSetStructuredErrorFunc(NULL, NULL);
60
53
 
61
54
  /*
62
55
  * If EncodingFound has occurred in EncodingReader, make sure to do
63
56
  * a cleanup and propagate the error.
64
57
  */
65
- if (rb_respond_to(io, id_encoding_found)) {
66
- VALUE encoding_found = rb_funcall(io, id_encoding_found, 0);
58
+ if (rb_respond_to(rb_io, id_encoding_found)) {
59
+ VALUE encoding_found = rb_funcall(rb_io, id_encoding_found, 0);
67
60
  if (!NIL_P(encoding_found)) {
68
- xmlFreeDoc(doc);
61
+ xmlFreeDoc(c_doc);
69
62
  rb_exc_raise(encoding_found);
70
63
  }
71
64
  }
72
65
 
73
- if(doc == NULL) {
74
- xmlErrorPtr error;
66
+ if ((c_doc == NULL) || (!(options & XML_PARSE_RECOVER) && (RARRAY_LEN(rb_error_list) > 0))) {
67
+ VALUE rb_error ;
75
68
 
76
- xmlFreeDoc(doc);
69
+ xmlFreeDoc(c_doc);
77
70
 
78
- error = xmlGetLastError();
79
- if(error)
80
- rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
81
- else
71
+ rb_error = rb_ary_entry(rb_error_list, 0);
72
+ if (rb_error == Qnil) {
82
73
  rb_raise(rb_eRuntimeError, "Could not parse document");
74
+ } else {
75
+ VALUE exception_message = rb_funcall(rb_error, id_to_s, 0);
76
+ exception_message = rb_str_concat(rb_str_new2("Parser without recover option encountered error or warning: "),
77
+ exception_message);
78
+ rb_exc_raise(rb_class_new_instance(1, &exception_message, cNokogiriXmlSyntaxError));
79
+ }
83
80
 
84
81
  return Qnil;
85
82
  }
86
83
 
87
- document = Nokogiri_wrap_xml_document(klass, doc);
88
- rb_iv_set(document, "@errors", error_list);
89
- return document;
84
+ rb_doc = Nokogiri_wrap_xml_document(klass, c_doc);
85
+ rb_iv_set(rb_doc, "@errors", rb_error_list);
86
+ return rb_doc;
90
87
  }
91
88
 
92
89
  /*
@@ -96,43 +93,45 @@ static VALUE read_io( VALUE klass,
96
93
  * Read the HTML document contained in +string+ with given +url+, +encoding+,
97
94
  * and +options+. See Nokogiri::HTML.parse
98
95
  */
99
- static VALUE read_memory( VALUE klass,
100
- VALUE string,
101
- VALUE url,
102
- VALUE encoding,
103
- VALUE options )
96
+ static VALUE
97
+ rb_html_document_s_read_memory(VALUE klass, VALUE rb_html, VALUE rb_url, VALUE rb_encoding, VALUE rb_options)
104
98
  {
105
- const char * c_buffer = StringValuePtr(string);
106
- const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url);
107
- const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
108
- int len = (int)RSTRING_LEN(string);
109
- VALUE error_list = rb_ary_new();
110
- VALUE document;
111
- htmlDocPtr doc;
99
+ VALUE rb_doc;
100
+ VALUE rb_error_list = rb_ary_new();
101
+ htmlDocPtr c_doc;
102
+ const char *c_buffer = StringValuePtr(rb_html);
103
+ const char *c_url = NIL_P(rb_url) ? NULL : StringValueCStr(rb_url);
104
+ const char *c_encoding = NIL_P(rb_encoding) ? NULL : StringValueCStr(rb_encoding);
105
+ int html_len = (int)RSTRING_LEN(rb_html);
106
+ int options = NUM2INT(rb_options);
112
107
 
113
- xmlResetLastError();
114
- xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
108
+ xmlSetStructuredErrorFunc((void *)rb_error_list, Nokogiri_error_array_pusher);
109
+
110
+ c_doc = htmlReadMemory(c_buffer, html_len, c_url, c_encoding, options);
115
111
 
116
- doc = htmlReadMemory(c_buffer, len, c_url, c_enc, (int)NUM2INT(options));
117
112
  xmlSetStructuredErrorFunc(NULL, NULL);
118
113
 
119
- if(doc == NULL) {
120
- xmlErrorPtr error;
114
+ if ((c_doc == NULL) || (!(options & XML_PARSE_RECOVER) && (RARRAY_LEN(rb_error_list) > 0))) {
115
+ VALUE rb_error ;
121
116
 
122
- xmlFreeDoc(doc);
117
+ xmlFreeDoc(c_doc);
123
118
 
124
- error = xmlGetLastError();
125
- if(error)
126
- rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
127
- else
119
+ rb_error = rb_ary_entry(rb_error_list, 0);
120
+ if (rb_error == Qnil) {
128
121
  rb_raise(rb_eRuntimeError, "Could not parse document");
122
+ } else {
123
+ VALUE exception_message = rb_funcall(rb_error, id_to_s, 0);
124
+ exception_message = rb_str_concat(rb_str_new2("Parser without recover option encountered error or warning: "),
125
+ exception_message);
126
+ rb_exc_raise(rb_class_new_instance(1, &exception_message, cNokogiriXmlSyntaxError));
127
+ }
129
128
 
130
129
  return Qnil;
131
130
  }
132
131
 
133
- document = Nokogiri_wrap_xml_document(klass, doc);
134
- rb_iv_set(document, "@errors", error_list);
135
- return document;
132
+ rb_doc = Nokogiri_wrap_xml_document(klass, c_doc);
133
+ rb_iv_set(rb_doc, "@errors", rb_error_list);
134
+ return rb_doc;
136
135
  }
137
136
 
138
137
  /*
@@ -141,7 +140,8 @@ static VALUE read_memory( VALUE klass,
141
140
  *
142
141
  * The type for this document
143
142
  */
144
- static VALUE type(VALUE self)
143
+ static VALUE
144
+ rb_html_document_type(VALUE self)
145
145
  {
146
146
  htmlDocPtr doc;
147
147
  Data_Get_Struct(self, xmlDoc, doc);
@@ -149,22 +149,23 @@ static VALUE type(VALUE self)
149
149
  }
150
150
 
151
151
  VALUE cNokogiriHtmlDocument ;
152
- void init_html_document()
153
- {
154
- VALUE nokogiri = rb_define_module("Nokogiri");
155
- VALUE html = rb_define_module_under(nokogiri, "HTML");
156
- VALUE xml = rb_define_module_under(nokogiri, "XML");
157
- VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
158
- VALUE xml_doc = rb_define_class_under(xml, "Document", node);
159
- VALUE klass = rb_define_class_under(html, "Document", xml_doc);
160
152
 
161
- cNokogiriHtmlDocument = klass;
153
+ void
154
+ init_html_document()
155
+ {
156
+ VALUE nokogiri = rb_define_module("Nokogiri");
157
+ VALUE nokogiri_xml = rb_define_module_under(nokogiri, "XML");
158
+ VALUE nokogiri_xml_node = rb_define_class_under(nokogiri_xml, "Node", rb_cObject);
159
+ VALUE nokogiri_xml_document = rb_define_class_under(nokogiri_xml, "Document", nokogiri_xml_node);
160
+ VALUE nokogiri_html = rb_define_module_under(nokogiri, "HTML");
161
+ cNokogiriHtmlDocument = rb_define_class_under(nokogiri_html, "Document", nokogiri_xml_document);
162
162
 
163
- rb_define_singleton_method(klass, "read_memory", read_memory, 4);
164
- rb_define_singleton_method(klass, "read_io", read_io, 4);
165
- rb_define_singleton_method(klass, "new", new, -1);
163
+ rb_define_singleton_method(cNokogiriHtmlDocument, "read_memory", rb_html_document_s_read_memory, 4);
164
+ rb_define_singleton_method(cNokogiriHtmlDocument, "read_io", rb_html_document_s_read_io, 4);
165
+ rb_define_singleton_method(cNokogiriHtmlDocument, "new", rb_html_document_s_new, -1);
166
166
 
167
- rb_define_method(klass, "type", type, 0);
167
+ rb_define_method(cNokogiriHtmlDocument, "type", rb_html_document_type, 0);
168
168
 
169
169
  id_encoding_found = rb_intern("encoding_found");
170
+ id_to_s = rb_intern("to_s");
170
171
  }
@@ -4,13 +4,13 @@ VALUE cNokogiriHtmlSaxParserContext ;
4
4
 
5
5
  static void deallocate(xmlParserCtxtPtr ctxt)
6
6
  {
7
- NOKOGIRI_DEBUG_START(handler);
7
+ NOKOGIRI_DEBUG_START(ctxt);
8
8
 
9
9
  ctxt->sax = NULL;
10
10
 
11
11
  htmlFreeParserCtxt(ctxt);
12
12
 
13
- NOKOGIRI_DEBUG_END(handler);
13
+ NOKOGIRI_DEBUG_END(ctxt);
14
14
  }
15
15
 
16
16
  static VALUE
@@ -7,12 +7,11 @@ VALUE mNokogiriXslt ;
7
7
  VALUE mNokogiriXmlSax ;
8
8
  VALUE mNokogiriHtmlSax ;
9
9
 
10
- #ifdef USE_INCLUDED_VASPRINTF
10
+ #ifndef HAVE_VASPRINTF
11
11
  /*
12
- * I srsly hate windows. it doesn't have vasprintf.
13
12
  * Thank you Geoffroy Couprie for this implementation of vasprintf!
14
13
  */
15
- int vasprintf (char **strp, const char *fmt, va_list ap)
14
+ int vasprintf(char **strp, const char *fmt, va_list ap)
16
15
  {
17
16
  /* Mingw32/64 have a broken vsnprintf implementation that fails when
18
17
  * using a zero-byte limit in order to retrieve the required size for malloc.
@@ -21,23 +20,15 @@ int vasprintf (char **strp, const char *fmt, va_list ap)
21
20
  char tmp[1];
22
21
  int len = vsnprintf (tmp, 1, fmt, ap) + 1;
23
22
  char *res = (char *)malloc((unsigned int)len);
24
- if (res == NULL)
25
- return -1;
23
+ if (res == NULL) {
24
+ return -1;
25
+ }
26
26
  *strp = res;
27
27
  return vsnprintf(res, (unsigned int)len, fmt, ap);
28
28
  }
29
29
  #endif
30
30
 
31
- void vasprintf_free (void *p)
32
- {
33
- free(p);
34
- }
35
-
36
- #ifdef HAVE_RUBY_UTIL_H
37
31
  #include "ruby/util.h"
38
- #else
39
- #include "util.h"
40
- #endif
41
32
 
42
33
  void nokogiri_root_node(xmlNodePtr node)
43
34
  {
@@ -45,7 +36,7 @@ void nokogiri_root_node(xmlNodePtr node)
45
36
  nokogiriTuplePtr tuple;
46
37
 
47
38
  doc = node->doc;
48
- if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
39
+ if (doc->type == XML_DOCUMENT_FRAG_NODE) { doc = doc->doc; }
49
40
  tuple = (nokogiriTuplePtr)doc->_private;
50
41
  st_insert(tuple->unlinkedNodes, (st_data_t)node, (st_data_t)node);
51
42
  }
@@ -54,7 +45,7 @@ void nokogiri_root_nsdef(xmlNsPtr ns, xmlDocPtr doc)
54
45
  {
55
46
  nokogiriTuplePtr tuple;
56
47
 
57
- if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
48
+ if (doc->type == XML_DOCUMENT_FRAG_NODE) { doc = doc->doc; }
58
49
  tuple = (nokogiriTuplePtr)doc->_private;
59
50
  st_insert(tuple->unlinkedNodes, (st_data_t)ns, (st_data_t)ns);
60
51
  }
@@ -62,10 +53,10 @@ void nokogiri_root_nsdef(xmlNsPtr ns, xmlDocPtr doc)
62
53
  void Init_nokogiri()
63
54
  {
64
55
  xmlMemSetup(
65
- (xmlFreeFunc)ruby_xfree,
66
- (xmlMallocFunc)ruby_xmalloc,
67
- (xmlReallocFunc)ruby_xrealloc,
68
- ruby_strdup
56
+ (xmlFreeFunc)ruby_xfree,
57
+ (xmlMallocFunc)ruby_xmalloc,
58
+ (xmlReallocFunc)ruby_xrealloc,
59
+ ruby_strdup
69
60
  );
70
61
 
71
62
  mNokogiri = rb_define_module("Nokogiri");
@@ -75,33 +66,26 @@ void Init_nokogiri()
75
66
  mNokogiriXmlSax = rb_define_module_under(mNokogiriXml, "SAX");
76
67
  mNokogiriHtmlSax = rb_define_module_under(mNokogiriHtml, "SAX");
77
68
 
78
- rb_const_set( mNokogiri,
79
- rb_intern("LIBXML_COMPILED_VERSION"),
80
- NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION)
81
- );
82
- rb_const_set( mNokogiri,
83
- rb_intern("LIBXML_LOADED_VERSION"),
84
- NOKOGIRI_STR_NEW2(xmlParserVersion)
85
- );
86
-
87
-
88
- rb_const_set( mNokogiri,
89
- rb_intern("LIBXSLT_COMPILED_VERSION"),
90
- NOKOGIRI_STR_NEW2(LIBXSLT_DOTTED_VERSION)
91
- );
92
- rb_const_set( mNokogiri,
93
- rb_intern("LIBXSLT_LOADED_VERSION"),
94
- NOKOGIRI_STR_NEW2(xsltEngineVersion)
95
- );
96
-
97
- #ifdef NOKOGIRI_USE_PACKAGED_LIBRARIES
98
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_USE_PACKAGED_LIBRARIES"), Qtrue);
99
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXML2_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATCHES), " "));
100
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXSLT_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATCHES), " "));
69
+ rb_const_set(mNokogiri, rb_intern("LIBXML_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION));
70
+ rb_const_set(mNokogiri, rb_intern("LIBXML_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xmlParserVersion));
71
+
72
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXSLT_DOTTED_VERSION));
73
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xsltEngineVersion));
74
+
75
+ #ifdef NOKOGIRI_PACKAGED_LIBRARIES
76
+ rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qtrue);
77
+ #ifdef NOKOGIRI_PRECOMPILED_LIBRARIES
78
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qtrue);
79
+ #else
80
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
81
+ #endif
82
+ rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATCHES), " "));
83
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATCHES), " "));
101
84
  #else
102
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_USE_PACKAGED_LIBRARIES"), Qfalse);
103
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXML2_PATCHES"), Qnil);
104
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXSLT_PATCHES"), Qnil);
85
+ rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qfalse);
86
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
87
+ rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), Qnil);
88
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), Qnil);
105
89
  #endif
106
90
 
107
91
  #ifdef LIBXML_ICONV_ENABLED
@@ -110,6 +94,10 @@ void Init_nokogiri()
110
94
  rb_const_set(mNokogiri, rb_intern("LIBXML_ICONV_ENABLED"), Qfalse);
111
95
  #endif
112
96
 
97
+ #ifdef NOKOGIRI_OTHER_LIBRARY_VERSIONS
98
+ rb_const_set(mNokogiri, rb_intern("OTHER_LIBRARY_VERSIONS"), NOKOGIRI_STR_NEW2(NOKOGIRI_OTHER_LIBRARY_VERSIONS));
99
+ #endif
100
+
113
101
  xmlInitParser();
114
102
 
115
103
  init_xml_document();
@@ -506,7 +506,7 @@ static int block_caller(void * ctx, xmlNodePtr _node, xmlNodePtr _parent)
506
506
  * The block must return a non-nil, non-false value if the +obj+ passed in
507
507
  * should be included in the canonicalized document.
508
508
  */
509
- static VALUE canonicalize(int argc, VALUE* argv, VALUE self)
509
+ static VALUE nokogiri_xml_document_canonicalize(int argc, VALUE* argv, VALUE self)
510
510
  {
511
511
  VALUE mode;
512
512
  VALUE incl_ns;
@@ -587,7 +587,7 @@ void init_xml_document()
587
587
  rb_define_method(klass, "encoding", encoding, 0);
588
588
  rb_define_method(klass, "encoding=", set_encoding, 1);
589
589
  rb_define_method(klass, "version", version, 0);
590
- rb_define_method(klass, "canonicalize", canonicalize, -1);
590
+ rb_define_method(klass, "canonicalize", nokogiri_xml_document_canonicalize, -1);
591
591
  rb_define_method(klass, "dup", duplicate_document, -1);
592
592
  rb_define_method(klass, "url", url, 0);
593
593
  rb_define_method(klass, "create_entity", create_entity, -1);
@@ -301,7 +301,7 @@ ok:
301
301
  * issue #391, where new node's prefix may become the string "default"
302
302
  * see libxml2 tree.c xmlNewReconciliedNs which implements this behavior.
303
303
  */
304
- xmlFree(reparentee->ns->prefix);
304
+ xmlFree((xmlChar*)reparentee->ns->prefix);
305
305
  reparentee->ns->prefix = NULL;
306
306
  }
307
307
  }
@@ -319,7 +319,7 @@ static VALUE slice(int argc, VALUE *argv, VALUE self)
319
319
  *
320
320
  * Return this list as an Array
321
321
  */
322
- static VALUE to_array(VALUE self, VALUE rb_node)
322
+ static VALUE to_array(VALUE self)
323
323
  {
324
324
  xmlNodeSetPtr node_set ;
325
325
  VALUE list;
@@ -53,16 +53,24 @@ static VALUE validate_document(VALUE self, VALUE document)
53
53
  *
54
54
  * Create a new RelaxNG from the contents of +string+
55
55
  */
56
- static VALUE read_memory(VALUE klass, VALUE content)
56
+ static VALUE read_memory(int argc, VALUE *argv, VALUE klass)
57
57
  {
58
- xmlRelaxNGParserCtxtPtr ctx = xmlRelaxNGNewMemParserCtxt(
59
- (const char *)StringValuePtr(content),
60
- (int)RSTRING_LEN(content)
61
- );
58
+ VALUE content;
59
+ VALUE parse_options;
60
+ xmlRelaxNGParserCtxtPtr ctx;
62
61
  xmlRelaxNGPtr schema;
63
- VALUE errors = rb_ary_new();
62
+ VALUE errors;
64
63
  VALUE rb_schema;
64
+ int scanned_args = 0;
65
+
66
+ scanned_args = rb_scan_args(argc, argv, "11", &content, &parse_options);
67
+ if (scanned_args == 1) {
68
+ parse_options = rb_const_get(rb_const_get(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
69
+ }
65
70
 
71
+ ctx = xmlRelaxNGNewMemParserCtxt((const char *)StringValuePtr(content), (int)RSTRING_LEN(content));
72
+
73
+ errors = rb_ary_new();
66
74
  xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
67
75
 
68
76
  #ifdef HAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS
@@ -90,6 +98,7 @@ static VALUE read_memory(VALUE klass, VALUE content)
90
98
 
91
99
  rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
92
100
  rb_iv_set(rb_schema, "@errors", errors);
101
+ rb_iv_set(rb_schema, "@parse_options", parse_options);
93
102
 
94
103
  return rb_schema;
95
104
  }
@@ -100,18 +109,25 @@ static VALUE read_memory(VALUE klass, VALUE content)
100
109
  *
101
110
  * Create a new RelaxNG schema from the Nokogiri::XML::Document +doc+
102
111
  */
103
- static VALUE from_document(VALUE klass, VALUE document)
112
+ static VALUE from_document(int argc, VALUE *argv, VALUE klass)
104
113
  {
114
+ VALUE document;
115
+ VALUE parse_options;
105
116
  xmlDocPtr doc;
106
117
  xmlRelaxNGParserCtxtPtr ctx;
107
118
  xmlRelaxNGPtr schema;
108
119
  VALUE errors;
109
120
  VALUE rb_schema;
121
+ int scanned_args = 0;
122
+
123
+ scanned_args = rb_scan_args(argc, argv, "11", &document, &parse_options);
110
124
 
111
125
  Data_Get_Struct(document, xmlDoc, doc);
126
+ doc = doc->doc; /* In case someone passes us a node. ugh. */
112
127
 
113
- /* In case someone passes us a node. ugh. */
114
- doc = doc->doc;
128
+ if (scanned_args == 1) {
129
+ parse_options = rb_const_get(rb_const_get(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
130
+ }
115
131
 
116
132
  ctx = xmlRelaxNGNewDocParserCtxt(doc);
117
133
 
@@ -129,6 +145,7 @@ static VALUE from_document(VALUE klass, VALUE document)
129
145
  schema = xmlRelaxNGParse(ctx);
130
146
 
131
147
  xmlSetStructuredErrorFunc(NULL, NULL);
148
+ xmlRelaxNGFreeParserCtxt(ctx);
132
149
 
133
150
  if(NULL == schema) {
134
151
  xmlErrorPtr error = xmlGetLastError();
@@ -142,6 +159,7 @@ static VALUE from_document(VALUE klass, VALUE document)
142
159
 
143
160
  rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
144
161
  rb_iv_set(rb_schema, "@errors", errors);
162
+ rb_iv_set(rb_schema, "@parse_options", parse_options);
145
163
 
146
164
  return rb_schema;
147
165
  }
@@ -155,7 +173,7 @@ void init_xml_relax_ng()
155
173
 
156
174
  cNokogiriXmlRelaxNG = klass;
157
175
 
158
- rb_define_singleton_method(klass, "read_memory", read_memory, 1);
159
- rb_define_singleton_method(klass, "from_document", from_document, 1);
176
+ rb_define_singleton_method(klass, "read_memory", read_memory, -1);
177
+ rb_define_singleton_method(klass, "from_document", from_document, -1);
160
178
  rb_define_private_method(klass, "validate_document", validate_document, 1);
161
179
  }