nokogiri 1.11.0.rc3-java → 1.11.4-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 (187) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/LICENSE-DEPENDENCIES.md +1015 -947
  4. data/LICENSE.md +1 -1
  5. data/README.md +168 -91
  6. data/dependencies.yml +12 -12
  7. data/ext/java/nokogiri/EncodingHandler.java +76 -89
  8. data/ext/java/nokogiri/HtmlDocument.java +135 -144
  9. data/ext/java/nokogiri/HtmlElementDescription.java +102 -117
  10. data/ext/java/nokogiri/HtmlEntityLookup.java +33 -60
  11. data/ext/java/nokogiri/HtmlSaxParserContext.java +218 -222
  12. data/ext/java/nokogiri/HtmlSaxPushParser.java +162 -169
  13. data/ext/java/nokogiri/NokogiriService.java +595 -556
  14. data/ext/java/nokogiri/XmlAttr.java +118 -126
  15. data/ext/java/nokogiri/XmlAttributeDecl.java +95 -106
  16. data/ext/java/nokogiri/XmlCdata.java +35 -58
  17. data/ext/java/nokogiri/XmlComment.java +46 -67
  18. data/ext/java/nokogiri/XmlDocument.java +645 -572
  19. data/ext/java/nokogiri/XmlDocumentFragment.java +125 -137
  20. data/ext/java/nokogiri/XmlDtd.java +448 -414
  21. data/ext/java/nokogiri/XmlElement.java +23 -48
  22. data/ext/java/nokogiri/XmlElementContent.java +343 -316
  23. data/ext/java/nokogiri/XmlElementDecl.java +124 -125
  24. data/ext/java/nokogiri/XmlEntityDecl.java +119 -127
  25. data/ext/java/nokogiri/XmlEntityReference.java +49 -72
  26. data/ext/java/nokogiri/XmlNamespace.java +175 -175
  27. data/ext/java/nokogiri/XmlNode.java +1843 -1622
  28. data/ext/java/nokogiri/XmlNodeSet.java +361 -331
  29. data/ext/java/nokogiri/XmlProcessingInstruction.java +47 -69
  30. data/ext/java/nokogiri/XmlReader.java +513 -450
  31. data/ext/java/nokogiri/XmlRelaxng.java +89 -101
  32. data/ext/java/nokogiri/XmlSaxParserContext.java +328 -310
  33. data/ext/java/nokogiri/XmlSaxPushParser.java +227 -220
  34. data/ext/java/nokogiri/XmlSchema.java +335 -242
  35. data/ext/java/nokogiri/XmlSyntaxError.java +113 -119
  36. data/ext/java/nokogiri/XmlText.java +55 -76
  37. data/ext/java/nokogiri/XmlXpathContext.java +242 -210
  38. data/ext/java/nokogiri/XsltStylesheet.java +280 -269
  39. data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
  40. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +201 -190
  41. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
  42. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
  43. data/ext/java/nokogiri/internals/NokogiriDomParser.java +63 -80
  44. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
  45. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +27 -52
  46. data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -286
  47. data/ext/java/nokogiri/internals/NokogiriHelpers.java +736 -652
  48. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +184 -173
  49. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +79 -89
  50. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +64 -79
  51. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +84 -99
  52. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +48 -65
  53. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +119 -78
  54. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -54
  55. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +23 -46
  56. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +55 -72
  57. data/ext/java/nokogiri/internals/ParserContext.java +206 -211
  58. data/ext/java/nokogiri/internals/ReaderNode.java +478 -403
  59. data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -739
  60. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +31 -54
  61. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
  62. data/ext/java/nokogiri/internals/XmlDeclHandler.java +3 -34
  63. data/ext/java/nokogiri/internals/XmlDomParserContext.java +206 -207
  64. data/ext/java/nokogiri/internals/XmlSaxParser.java +22 -47
  65. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
  66. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
  67. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
  68. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
  69. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
  77. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
  78. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
  79. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
  80. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
  81. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
  82. data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
  83. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
  84. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
  85. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
  86. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
  87. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
  88. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
  89. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
  90. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
  91. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
  92. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
  93. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -574
  94. data/ext/nokogiri/depend +37 -358
  95. data/ext/nokogiri/extconf.rb +581 -374
  96. data/ext/nokogiri/html_document.c +78 -82
  97. data/ext/nokogiri/html_element_description.c +84 -71
  98. data/ext/nokogiri/html_entity_lookup.c +21 -16
  99. data/ext/nokogiri/html_sax_parser_context.c +69 -66
  100. data/ext/nokogiri/html_sax_push_parser.c +42 -34
  101. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  102. data/ext/nokogiri/nokogiri.c +192 -93
  103. data/ext/nokogiri/test_global_handlers.c +40 -0
  104. data/ext/nokogiri/xml_attr.c +15 -15
  105. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  106. data/ext/nokogiri/xml_cdata.c +13 -18
  107. data/ext/nokogiri/xml_comment.c +19 -26
  108. data/ext/nokogiri/xml_document.c +246 -188
  109. data/ext/nokogiri/xml_document_fragment.c +13 -15
  110. data/ext/nokogiri/xml_dtd.c +54 -48
  111. data/ext/nokogiri/xml_element_content.c +30 -27
  112. data/ext/nokogiri/xml_element_decl.c +22 -22
  113. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  114. data/ext/nokogiri/xml_entity_decl.c +32 -30
  115. data/ext/nokogiri/xml_entity_reference.c +16 -18
  116. data/ext/nokogiri/xml_namespace.c +56 -49
  117. data/ext/nokogiri/xml_node.c +371 -320
  118. data/ext/nokogiri/xml_node_set.c +168 -156
  119. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  120. data/ext/nokogiri/xml_reader.c +191 -157
  121. data/ext/nokogiri/xml_relax_ng.c +52 -28
  122. data/ext/nokogiri/xml_sax_parser.c +118 -118
  123. data/ext/nokogiri/xml_sax_parser_context.c +103 -86
  124. data/ext/nokogiri/xml_sax_push_parser.c +36 -27
  125. data/ext/nokogiri/xml_schema.c +95 -47
  126. data/ext/nokogiri/xml_syntax_error.c +42 -21
  127. data/ext/nokogiri/xml_text.c +13 -17
  128. data/ext/nokogiri/xml_xpath_context.c +206 -123
  129. data/ext/nokogiri/xslt_stylesheet.c +158 -161
  130. data/lib/nokogiri.rb +3 -7
  131. data/lib/nokogiri/css/parser.rb +3 -3
  132. data/lib/nokogiri/css/parser.y +2 -2
  133. data/lib/nokogiri/css/xpath_visitor.rb +70 -42
  134. data/lib/nokogiri/extension.rb +26 -0
  135. data/lib/nokogiri/html/document.rb +12 -26
  136. data/lib/nokogiri/html/document_fragment.rb +15 -15
  137. data/lib/nokogiri/nokogiri.jar +0 -0
  138. data/lib/nokogiri/version.rb +2 -149
  139. data/lib/nokogiri/version/constant.rb +5 -0
  140. data/lib/nokogiri/version/info.rb +205 -0
  141. data/lib/nokogiri/xml/document.rb +91 -35
  142. data/lib/nokogiri/xml/document_fragment.rb +4 -6
  143. data/lib/nokogiri/xml/node.rb +89 -69
  144. data/lib/nokogiri/xml/parse_options.rb +6 -0
  145. data/lib/nokogiri/xml/reader.rb +2 -9
  146. data/lib/nokogiri/xml/relax_ng.rb +6 -2
  147. data/lib/nokogiri/xml/schema.rb +12 -4
  148. data/lib/nokogiri/xml/searchable.rb +3 -1
  149. data/lib/nokogiri/xml/xpath.rb +1 -3
  150. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  151. metadata +86 -177
  152. data/ext/nokogiri/html_document.h +0 -10
  153. data/ext/nokogiri/html_element_description.h +0 -10
  154. data/ext/nokogiri/html_entity_lookup.h +0 -8
  155. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  156. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  157. data/ext/nokogiri/nokogiri.h +0 -134
  158. data/ext/nokogiri/xml_attr.h +0 -9
  159. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  160. data/ext/nokogiri/xml_cdata.h +0 -9
  161. data/ext/nokogiri/xml_comment.h +0 -9
  162. data/ext/nokogiri/xml_document.h +0 -23
  163. data/ext/nokogiri/xml_document_fragment.h +0 -10
  164. data/ext/nokogiri/xml_dtd.h +0 -10
  165. data/ext/nokogiri/xml_element_content.h +0 -10
  166. data/ext/nokogiri/xml_element_decl.h +0 -9
  167. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  168. data/ext/nokogiri/xml_entity_decl.h +0 -10
  169. data/ext/nokogiri/xml_entity_reference.h +0 -9
  170. data/ext/nokogiri/xml_io.c +0 -63
  171. data/ext/nokogiri/xml_io.h +0 -11
  172. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
  173. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  174. data/ext/nokogiri/xml_namespace.h +0 -14
  175. data/ext/nokogiri/xml_node.h +0 -13
  176. data/ext/nokogiri/xml_node_set.h +0 -12
  177. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  178. data/ext/nokogiri/xml_reader.h +0 -10
  179. data/ext/nokogiri/xml_relax_ng.h +0 -9
  180. data/ext/nokogiri/xml_sax_parser.h +0 -39
  181. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  182. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  183. data/ext/nokogiri/xml_schema.h +0 -9
  184. data/ext/nokogiri/xml_syntax_error.h +0 -13
  185. data/ext/nokogiri/xml_text.h +0 -9
  186. data/ext/nokogiri/xml_xpath_context.h +0 -10
  187. data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -1,107 +1,184 @@
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 ;
9
10
 
10
- #ifdef USE_INCLUDED_VASPRINTF
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
+
51
+
52
+ #ifndef HAVE_VASPRINTF
11
53
  /*
12
- * I srsly hate windows. it doesn't have vasprintf.
13
54
  * Thank you Geoffroy Couprie for this implementation of vasprintf!
14
55
  */
15
- int vasprintf (char **strp, const char *fmt, va_list ap)
56
+ int
57
+ vasprintf(char **strp, const char *fmt, va_list ap)
16
58
  {
17
59
  /* Mingw32/64 have a broken vsnprintf implementation that fails when
18
60
  * using a zero-byte limit in order to retrieve the required size for malloc.
19
61
  * So we use a one byte buffer instead.
20
62
  */
21
63
  char tmp[1];
22
- int len = vsnprintf (tmp, 1, fmt, ap) + 1;
64
+ int len = vsnprintf(tmp, 1, fmt, ap) + 1;
23
65
  char *res = (char *)malloc((unsigned int)len);
24
- if (res == NULL)
25
- return -1;
66
+ if (res == NULL) {
67
+ return -1;
68
+ }
26
69
  *strp = res;
27
70
  return vsnprintf(res, (unsigned int)len, fmt, ap);
28
71
  }
29
72
  #endif
30
73
 
31
- void vasprintf_free (void *p)
74
+
75
+ static VALUE
76
+ read_check(VALUE val)
32
77
  {
33
- free(p);
78
+ VALUE *args = (VALUE *)val;
79
+ return rb_funcall(args[0], id_read, 1, args[1]);
34
80
  }
35
81
 
36
- #ifdef HAVE_RUBY_UTIL_H
37
- #include "ruby/util.h"
38
- #else
39
- #include "util.h"
40
- #endif
41
82
 
42
- void nokogiri_root_node(xmlNodePtr node)
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)
43
115
  {
44
- xmlDocPtr doc;
45
- nokogiriTuplePtr tuple;
116
+ VALUE *args = (VALUE *)val;
117
+ return rb_funcall(args[0], id_write, 1, args[1]);
118
+ }
46
119
 
47
- doc = node->doc;
48
- if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
49
- tuple = (nokogiriTuplePtr)doc->_private;
50
- st_insert(tuple->unlinkedNodes, (st_data_t)node, (st_data_t)node);
120
+
121
+ static VALUE
122
+ write_failed(VALUE arg, VALUE exc)
123
+ {
124
+ return Qundef;
51
125
  }
52
126
 
53
- void nokogiri_root_nsdef(xmlNsPtr ns, xmlDocPtr doc)
127
+
128
+ int
129
+ noko_io_write(void *ctx, char *buffer, int len)
54
130
  {
55
- nokogiriTuplePtr tuple;
131
+ VALUE args[2], size;
132
+
133
+ args[0] = (VALUE)ctx;
134
+ args[1] = rb_str_new(buffer, (long)len);
56
135
 
57
- if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
58
- tuple = (nokogiriTuplePtr)doc->_private;
59
- st_insert(tuple->unlinkedNodes, (st_data_t)ns, (st_data_t)ns);
136
+ size = rb_rescue(write_check, (VALUE)args, write_failed, 0);
137
+
138
+ if (size == Qundef) { return -1; }
139
+
140
+ return NUM2INT(size);
60
141
  }
61
142
 
62
- void Init_nokogiri()
143
+
144
+ int
145
+ noko_io_close(void *ctx)
63
146
  {
64
- xmlMemSetup(
65
- (xmlFreeFunc)ruby_xfree,
66
- (xmlMallocFunc)ruby_xmalloc,
67
- (xmlReallocFunc)ruby_xrealloc,
68
- ruby_strdup
69
- );
147
+ return 0;
148
+ }
149
+
70
150
 
151
+ void
152
+ Init_nokogiri()
153
+ {
71
154
  mNokogiri = rb_define_module("Nokogiri");
72
155
  mNokogiriXml = rb_define_module_under(mNokogiri, "XML");
73
156
  mNokogiriHtml = rb_define_module_under(mNokogiri, "HTML");
74
157
  mNokogiriXslt = rb_define_module_under(mNokogiri, "XSLT");
158
+ mNokogiriXmlXpath = rb_define_module_under(mNokogiriXml, "XPath");
75
159
  mNokogiriXmlSax = rb_define_module_under(mNokogiriXml, "SAX");
76
160
  mNokogiriHtmlSax = rb_define_module_under(mNokogiriHtml, "SAX");
77
161
 
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), " "));
162
+ rb_const_set(mNokogiri, rb_intern("LIBXML_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION));
163
+ rb_const_set(mNokogiri, rb_intern("LIBXML_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xmlParserVersion));
164
+
165
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXSLT_DOTTED_VERSION));
166
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xsltEngineVersion));
167
+
168
+ #ifdef NOKOGIRI_PACKAGED_LIBRARIES
169
+ rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qtrue);
170
+ # ifdef NOKOGIRI_PRECOMPILED_LIBRARIES
171
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qtrue);
172
+ # else
173
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
174
+ # endif
175
+ rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATCHES), " "));
176
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATCHES), " "));
101
177
  #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);
178
+ rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qfalse);
179
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
180
+ rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), Qnil);
181
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), Qnil);
105
182
  #endif
106
183
 
107
184
  #ifdef LIBXML_ICONV_ENABLED
@@ -110,38 +187,60 @@ void Init_nokogiri()
110
187
  rb_const_set(mNokogiri, rb_intern("LIBXML_ICONV_ENABLED"), Qfalse);
111
188
  #endif
112
189
 
190
+ #ifdef NOKOGIRI_OTHER_LIBRARY_VERSIONS
191
+ rb_const_set(mNokogiri, rb_intern("OTHER_LIBRARY_VERSIONS"), NOKOGIRI_STR_NEW2(NOKOGIRI_OTHER_LIBRARY_VERSIONS));
192
+ #endif
193
+
194
+ xmlMemSetup((xmlFreeFunc)ruby_xfree, (xmlMallocFunc)ruby_xmalloc, (xmlReallocFunc)ruby_xrealloc, ruby_strdup);
195
+
113
196
  xmlInitParser();
114
197
 
115
- init_xml_document();
116
- init_html_document();
117
- init_xml_node();
118
- init_xml_document_fragment();
119
- init_xml_text();
120
- init_xml_cdata();
121
- init_xml_processing_instruction();
122
- init_xml_attr();
123
- init_xml_entity_reference();
124
- init_xml_comment();
125
- init_xml_node_set();
126
- init_xml_xpath_context();
127
- init_xml_sax_parser_context();
128
- init_xml_sax_parser();
129
- init_xml_sax_push_parser();
130
- init_xml_reader();
131
- init_xml_dtd();
132
- init_xml_element_content();
133
- init_xml_attribute_decl();
134
- init_xml_element_decl();
135
- init_xml_entity_decl();
136
- init_xml_namespace();
137
- init_html_sax_parser_context();
138
- init_html_sax_push_parser();
139
- init_xslt_stylesheet();
140
- init_xml_syntax_error();
141
- init_html_entity_lookup();
142
- init_html_element_description();
143
- init_xml_schema();
144
- init_xml_relax_ng();
145
- init_nokogiri_io();
146
- init_xml_encoding_handler();
198
+ cNokogiriSyntaxError = rb_define_class_under(mNokogiri, "SyntaxError", rb_eStandardError);
199
+ noko_init_xml_syntax_error();
200
+ assert(cNokogiriXmlSyntaxError);
201
+ cNokogiriXmlXpathSyntaxError = rb_define_class_under(mNokogiriXmlXpath, "SyntaxError", cNokogiriXmlSyntaxError);
202
+
203
+ noko_init_xml_element_content();
204
+ noko_init_xml_encoding_handler();
205
+ noko_init_xml_namespace();
206
+ noko_init_xml_node_set();
207
+ noko_init_xml_reader();
208
+ noko_init_xml_sax_parser();
209
+ noko_init_xml_xpath_context();
210
+ noko_init_xslt_stylesheet();
211
+ noko_init_html_element_description();
212
+ noko_init_html_entity_lookup();
213
+
214
+ noko_init_xml_schema();
215
+ noko_init_xml_relax_ng();
216
+
217
+ noko_init_xml_sax_parser_context();
218
+ noko_init_html_sax_parser_context();
219
+
220
+ noko_init_xml_sax_push_parser();
221
+ noko_init_html_sax_push_parser();
222
+
223
+ noko_init_xml_node();
224
+ noko_init_xml_attr();
225
+ noko_init_xml_attribute_decl();
226
+ noko_init_xml_dtd();
227
+ noko_init_xml_element_decl();
228
+ noko_init_xml_entity_decl();
229
+ noko_init_xml_entity_reference();
230
+ noko_init_xml_processing_instruction();
231
+ assert(cNokogiriXmlNode);
232
+ cNokogiriXmlElement = rb_define_class_under(mNokogiriXml, "Element", cNokogiriXmlNode);
233
+ cNokogiriXmlCharacterData = rb_define_class_under(mNokogiriXml, "CharacterData", cNokogiriXmlNode);
234
+ noko_init_xml_comment();
235
+ noko_init_xml_text();
236
+ noko_init_xml_cdata();
237
+
238
+ noko_init_xml_document_fragment();
239
+ noko_init_xml_document();
240
+ noko_init_html_document();
241
+
242
+ noko_init_test_global_handlers();
243
+
244
+ id_read = rb_intern("read");
245
+ id_write = rb_intern("write");
147
246
  }
@@ -0,0 +1,40 @@
1
+ #include <nokogiri.h>
2
+
3
+ static VALUE foreign_error_handler_block = Qnil;
4
+
5
+ static void
6
+ foreign_error_handler(void *user_data, xmlErrorPtr c_error)
7
+ {
8
+ rb_funcall(foreign_error_handler_block, rb_intern("call"), 0);
9
+ }
10
+
11
+ /*
12
+ * call-seq:
13
+ * __foreign_error_handler { ... } -> nil
14
+ *
15
+ * Override libxml2's global error handlers to call the block. This method thus has very little
16
+ * value except to test that Nokogiri is properly setting error handlers elsewhere in the code. See
17
+ * test/helper.rb for how this is being used.
18
+ */
19
+ static VALUE
20
+ rb_foreign_error_handler(VALUE klass)
21
+ {
22
+ rb_need_block();
23
+ foreign_error_handler_block = rb_block_proc();
24
+ xmlSetStructuredErrorFunc(NULL, foreign_error_handler);
25
+ return Qnil;
26
+ }
27
+
28
+ /*
29
+ * Document-module: Nokogiri::Test
30
+ *
31
+ * The Nokogiri::Test module should only be used for testing Nokogiri.
32
+ * Do NOT use this outside of the Nokogiri test suite.
33
+ */
34
+ void
35
+ noko_init_test_global_handlers()
36
+ {
37
+ VALUE mNokogiriTest = rb_define_module_under(mNokogiri, "Test");
38
+
39
+ rb_define_singleton_method(mNokogiriTest, "__foreign_error_handler", rb_foreign_error_handler, 0);
40
+ }
@@ -1,4 +1,6 @@
1
- #include <xml_attr.h>
1
+ #include <nokogiri.h>
2
+
3
+ VALUE cNokogiriXmlAttr;
2
4
 
3
5
  /*
4
6
  * call-seq:
@@ -7,7 +9,8 @@
7
9
  * Set the value for this Attr to +content+. Use `nil` to remove the value
8
10
  * (e.g., a HTML boolean attribute).
9
11
  */
10
- static VALUE set_value(VALUE self, VALUE content)
12
+ static VALUE
13
+ set_value(VALUE self, VALUE content)
11
14
  {
12
15
  xmlAttrPtr attr;
13
16
  xmlChar *value;
@@ -49,7 +52,8 @@ static VALUE set_value(VALUE self, VALUE content)
49
52
  *
50
53
  * Create a new Attr element on the +document+ with +name+
51
54
  */
52
- static VALUE new(int argc, VALUE *argv, VALUE klass)
55
+ static VALUE
56
+ new (int argc, VALUE *argv, VALUE klass)
53
57
  {
54
58
  xmlDocPtr xml_doc;
55
59
  VALUE document;
@@ -72,9 +76,9 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
72
76
  NULL
73
77
  );
74
78
 
75
- nokogiri_root_node((xmlNodePtr)node);
79
+ noko_xml_document_pin_node((xmlNodePtr)node);
76
80
 
77
- rb_node = Nokogiri_wrap_xml_node(klass, (xmlNodePtr)node);
81
+ rb_node = noko_xml_node_wrap(klass, (xmlNodePtr)node);
78
82
  rb_obj_call_init(rb_node, argc, argv);
79
83
 
80
84
  if (rb_block_given_p()) {
@@ -84,20 +88,16 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
84
88
  return rb_node;
85
89
  }
86
90
 
87
- VALUE cNokogiriXmlAttr;
88
- void init_xml_attr()
91
+ void
92
+ noko_init_xml_attr()
89
93
  {
90
- VALUE nokogiri = rb_define_module("Nokogiri");
91
- VALUE xml = rb_define_module_under(nokogiri, "XML");
92
- VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
93
-
94
+ assert(cNokogiriXmlNode);
94
95
  /*
95
96
  * Attr represents a Attr node in an xml document.
96
97
  */
97
- VALUE klass = rb_define_class_under(xml, "Attr", node);
98
+ cNokogiriXmlAttr = rb_define_class_under(mNokogiriXml, "Attr", cNokogiriXmlNode);
98
99
 
99
- cNokogiriXmlAttr = klass;
100
+ rb_define_singleton_method(cNokogiriXmlAttr, "new", new, -1);
100
101
 
101
- rb_define_singleton_method(klass, "new", new, -1);
102
- rb_define_method(klass, "value=", set_value, 1);
102
+ rb_define_method(cNokogiriXmlAttr, "value=", set_value, 1);
103
103
  }
@@ -1,4 +1,6 @@
1
- #include <xml_attribute_decl.h>
1
+ #include <nokogiri.h>
2
+
3
+ VALUE cNokogiriXmlAttributeDecl;
2
4
 
3
5
  /*
4
6
  * call-seq:
@@ -6,7 +8,8 @@
6
8
  *
7
9
  * The attribute_type for this AttributeDecl
8
10
  */
9
- static VALUE attribute_type(VALUE self)
11
+ static VALUE
12
+ attribute_type(VALUE self)
10
13
  {
11
14
  xmlAttributePtr node;
12
15
  Data_Get_Struct(self, xmlAttribute, node);
@@ -19,12 +22,13 @@ static VALUE attribute_type(VALUE self)
19
22
  *
20
23
  * The default value
21
24
  */
22
- static VALUE default_value(VALUE self)
25
+ static VALUE
26
+ default_value(VALUE self)
23
27
  {
24
28
  xmlAttributePtr node;
25
29
  Data_Get_Struct(self, xmlAttribute, node);
26
30
 
27
- if(node->defaultValue) return NOKOGIRI_STR_NEW2(node->defaultValue);
31
+ if (node->defaultValue) { return NOKOGIRI_STR_NEW2(node->defaultValue); }
28
32
  return Qnil;
29
33
  }
30
34
 
@@ -34,7 +38,8 @@ static VALUE default_value(VALUE self)
34
38
  *
35
39
  * An enumeration of possible values
36
40
  */
37
- static VALUE enumeration(VALUE self)
41
+ static VALUE
42
+ enumeration(VALUE self)
38
43
  {
39
44
  xmlAttributePtr node;
40
45
  xmlEnumerationPtr enm;
@@ -45,7 +50,7 @@ static VALUE enumeration(VALUE self)
45
50
  list = rb_ary_new();
46
51
  enm = node->tree;
47
52
 
48
- while(enm) {
53
+ while (enm) {
49
54
  rb_ary_push(list, NOKOGIRI_STR_NEW2(enm->name));
50
55
  enm = enm->next;
51
56
  }
@@ -53,18 +58,13 @@ static VALUE enumeration(VALUE self)
53
58
  return list;
54
59
  }
55
60
 
56
- VALUE cNokogiriXmlAttributeDecl;
57
-
58
- void init_xml_attribute_decl()
61
+ void
62
+ noko_init_xml_attribute_decl()
59
63
  {
60
- VALUE nokogiri = rb_define_module("Nokogiri");
61
- VALUE xml = rb_define_module_under(nokogiri, "XML");
62
- VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
63
- VALUE klass = rb_define_class_under(xml, "AttributeDecl", node);
64
-
65
- cNokogiriXmlAttributeDecl = klass;
64
+ assert(cNokogiriXmlNode);
65
+ cNokogiriXmlAttributeDecl = rb_define_class_under(mNokogiriXml, "AttributeDecl", cNokogiriXmlNode);
66
66
 
67
- rb_define_method(klass, "attribute_type", attribute_type, 0);
68
- rb_define_method(klass, "default", default_value, 0);
69
- rb_define_method(klass, "enumeration", enumeration, 0);
67
+ rb_define_method(cNokogiriXmlAttributeDecl, "attribute_type", attribute_type, 0);
68
+ rb_define_method(cNokogiriXmlAttributeDecl, "default", default_value, 0);
69
+ rb_define_method(cNokogiriXmlAttributeDecl, "enumeration", enumeration, 0);
70
70
  }