nokogiri 1.10.10 → 1.14.3-aarch64-linux

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 (251) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +44 -0
  3. data/LICENSE-DEPENDENCIES.md +1632 -1022
  4. data/LICENSE.md +1 -1
  5. data/README.md +185 -96
  6. data/bin/nokogiri +63 -50
  7. data/dependencies.yml +33 -66
  8. data/ext/nokogiri/depend +38 -358
  9. data/ext/nokogiri/extconf.rb +819 -421
  10. data/ext/nokogiri/gumbo.c +594 -0
  11. data/ext/nokogiri/html4_document.c +166 -0
  12. data/ext/nokogiri/html4_element_description.c +294 -0
  13. data/ext/nokogiri/html4_entity_lookup.c +37 -0
  14. data/ext/nokogiri/html4_sax_parser_context.c +114 -0
  15. data/ext/nokogiri/html4_sax_push_parser.c +95 -0
  16. data/ext/nokogiri/include/libexslt/exslt.h +108 -0
  17. data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
  18. data/ext/nokogiri/include/libexslt/exsltexports.h +63 -0
  19. data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
  20. data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
  21. data/ext/nokogiri/include/libxml2/libxml/SAX.h +204 -0
  22. data/ext/nokogiri/include/libxml2/libxml/SAX2.h +172 -0
  23. data/ext/nokogiri/include/libxml2/libxml/c14n.h +128 -0
  24. data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
  25. data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
  26. data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
  27. data/ext/nokogiri/include/libxml2/libxml/dict.h +81 -0
  28. data/ext/nokogiri/include/libxml2/libxml/encoding.h +232 -0
  29. data/ext/nokogiri/include/libxml2/libxml/entities.h +153 -0
  30. data/ext/nokogiri/include/libxml2/libxml/globals.h +499 -0
  31. data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
  32. data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
  33. data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +186 -0
  34. data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
  35. data/ext/nokogiri/include/libxml2/libxml/parser.h +1244 -0
  36. data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +656 -0
  37. data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
  38. data/ext/nokogiri/include/libxml2/libxml/relaxng.h +218 -0
  39. data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
  40. data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
  41. data/ext/nokogiri/include/libxml2/libxml/threads.h +91 -0
  42. data/ext/nokogiri/include/libxml2/libxml/tree.h +1312 -0
  43. data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
  44. data/ext/nokogiri/include/libxml2/libxml/valid.h +463 -0
  45. data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
  46. data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
  47. data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +368 -0
  48. data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
  49. data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +947 -0
  50. data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +77 -0
  51. data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +226 -0
  52. data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
  53. data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
  54. data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
  55. data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
  56. data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
  57. data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +152 -0
  58. data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
  59. data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
  60. data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +503 -0
  61. data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
  62. data/ext/nokogiri/include/libxml2/libxml/xpath.h +575 -0
  63. data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
  64. data/ext/nokogiri/include/libxml2/libxml/xpointer.h +137 -0
  65. data/ext/nokogiri/include/libxslt/attributes.h +38 -0
  66. data/ext/nokogiri/include/libxslt/documents.h +93 -0
  67. data/ext/nokogiri/include/libxslt/extensions.h +262 -0
  68. data/ext/nokogiri/include/libxslt/extra.h +72 -0
  69. data/ext/nokogiri/include/libxslt/functions.h +78 -0
  70. data/ext/nokogiri/include/libxslt/imports.h +75 -0
  71. data/ext/nokogiri/include/libxslt/keys.h +53 -0
  72. data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
  73. data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
  74. data/ext/nokogiri/include/libxslt/pattern.h +84 -0
  75. data/ext/nokogiri/include/libxslt/preproc.h +43 -0
  76. data/ext/nokogiri/include/libxslt/security.h +104 -0
  77. data/ext/nokogiri/include/libxslt/templates.h +77 -0
  78. data/ext/nokogiri/include/libxslt/transform.h +207 -0
  79. data/ext/nokogiri/include/libxslt/variables.h +118 -0
  80. data/ext/nokogiri/include/libxslt/xslt.h +110 -0
  81. data/ext/nokogiri/include/libxslt/xsltInternals.h +1982 -0
  82. data/ext/nokogiri/include/libxslt/xsltconfig.h +179 -0
  83. data/ext/nokogiri/include/libxslt/xsltexports.h +64 -0
  84. data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
  85. data/ext/nokogiri/include/libxslt/xsltutils.h +310 -0
  86. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  87. data/ext/nokogiri/nokogiri.c +228 -104
  88. data/ext/nokogiri/nokogiri.h +204 -90
  89. data/ext/nokogiri/test_global_handlers.c +40 -0
  90. data/ext/nokogiri/xml_attr.c +17 -17
  91. data/ext/nokogiri/xml_attribute_decl.c +22 -22
  92. data/ext/nokogiri/xml_cdata.c +15 -20
  93. data/ext/nokogiri/xml_comment.c +19 -26
  94. data/ext/nokogiri/xml_document.c +306 -225
  95. data/ext/nokogiri/xml_document_fragment.c +12 -16
  96. data/ext/nokogiri/xml_dtd.c +64 -58
  97. data/ext/nokogiri/xml_element_content.c +33 -28
  98. data/ext/nokogiri/xml_element_decl.c +26 -26
  99. data/ext/nokogiri/xml_encoding_handler.c +45 -20
  100. data/ext/nokogiri/xml_entity_decl.c +37 -35
  101. data/ext/nokogiri/xml_entity_reference.c +16 -18
  102. data/ext/nokogiri/xml_namespace.c +136 -61
  103. data/ext/nokogiri/xml_node.c +1344 -672
  104. data/ext/nokogiri/xml_node_set.c +178 -168
  105. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  106. data/ext/nokogiri/xml_reader.c +316 -190
  107. data/ext/nokogiri/xml_relax_ng.c +52 -30
  108. data/ext/nokogiri/xml_sax_parser.c +130 -124
  109. data/ext/nokogiri/xml_sax_parser_context.c +110 -89
  110. data/ext/nokogiri/xml_sax_push_parser.c +36 -29
  111. data/ext/nokogiri/xml_schema.c +98 -50
  112. data/ext/nokogiri/xml_syntax_error.c +42 -21
  113. data/ext/nokogiri/xml_text.c +14 -18
  114. data/ext/nokogiri/xml_xpath_context.c +263 -148
  115. data/ext/nokogiri/xslt_stylesheet.c +271 -178
  116. data/gumbo-parser/CHANGES.md +63 -0
  117. data/gumbo-parser/Makefile +111 -0
  118. data/gumbo-parser/THANKS +27 -0
  119. data/lib/nokogiri/2.7/nokogiri.so +0 -0
  120. data/lib/nokogiri/3.0/nokogiri.so +0 -0
  121. data/lib/nokogiri/3.1/nokogiri.so +0 -0
  122. data/lib/nokogiri/3.2/nokogiri.so +0 -0
  123. data/lib/nokogiri/class_resolver.rb +67 -0
  124. data/lib/nokogiri/css/node.rb +10 -8
  125. data/lib/nokogiri/css/parser.rb +397 -377
  126. data/lib/nokogiri/css/parser.y +250 -245
  127. data/lib/nokogiri/css/parser_extras.rb +54 -49
  128. data/lib/nokogiri/css/syntax_error.rb +3 -1
  129. data/lib/nokogiri/css/tokenizer.rb +5 -3
  130. data/lib/nokogiri/css/tokenizer.rex +3 -2
  131. data/lib/nokogiri/css/xpath_visitor.rb +223 -94
  132. data/lib/nokogiri/css.rb +56 -17
  133. data/lib/nokogiri/decorators/slop.rb +9 -7
  134. data/lib/nokogiri/encoding_handler.rb +57 -0
  135. data/lib/nokogiri/extension.rb +32 -0
  136. data/lib/nokogiri/gumbo.rb +15 -0
  137. data/lib/nokogiri/html.rb +38 -27
  138. data/lib/nokogiri/{html → html4}/builder.rb +4 -2
  139. data/lib/nokogiri/html4/document.rb +214 -0
  140. data/lib/nokogiri/html4/document_fragment.rb +54 -0
  141. data/lib/nokogiri/{html → html4}/element_description.rb +3 -1
  142. data/lib/nokogiri/html4/element_description_defaults.rb +572 -0
  143. data/lib/nokogiri/html4/encoding_reader.rb +121 -0
  144. data/lib/nokogiri/{html → html4}/entity_lookup.rb +4 -2
  145. data/lib/nokogiri/{html → html4}/sax/parser.rb +17 -16
  146. data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
  147. data/lib/nokogiri/{html → html4}/sax/push_parser.rb +12 -11
  148. data/lib/nokogiri/html4.rb +47 -0
  149. data/lib/nokogiri/html5/document.rb +168 -0
  150. data/lib/nokogiri/html5/document_fragment.rb +90 -0
  151. data/lib/nokogiri/html5/node.rb +98 -0
  152. data/lib/nokogiri/html5.rb +389 -0
  153. data/lib/nokogiri/jruby/dependencies.rb +3 -0
  154. data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
  155. data/lib/nokogiri/syntax_error.rb +2 -0
  156. data/lib/nokogiri/version/constant.rb +6 -0
  157. data/lib/nokogiri/version/info.rb +223 -0
  158. data/lib/nokogiri/version.rb +3 -108
  159. data/lib/nokogiri/xml/attr.rb +55 -3
  160. data/lib/nokogiri/xml/attribute_decl.rb +3 -1
  161. data/lib/nokogiri/xml/builder.rb +75 -34
  162. data/lib/nokogiri/xml/cdata.rb +3 -1
  163. data/lib/nokogiri/xml/character_data.rb +2 -0
  164. data/lib/nokogiri/xml/document.rb +312 -126
  165. data/lib/nokogiri/xml/document_fragment.rb +93 -48
  166. data/lib/nokogiri/xml/dtd.rb +4 -2
  167. data/lib/nokogiri/xml/element_content.rb +2 -0
  168. data/lib/nokogiri/xml/element_decl.rb +3 -1
  169. data/lib/nokogiri/xml/entity_decl.rb +4 -2
  170. data/lib/nokogiri/xml/entity_reference.rb +2 -0
  171. data/lib/nokogiri/xml/namespace.rb +45 -0
  172. data/lib/nokogiri/xml/node/save_options.rb +15 -8
  173. data/lib/nokogiri/xml/node.rb +1067 -406
  174. data/lib/nokogiri/xml/node_set.rb +135 -59
  175. data/lib/nokogiri/xml/notation.rb +13 -0
  176. data/lib/nokogiri/xml/parse_options.rb +145 -52
  177. data/lib/nokogiri/xml/pp/character_data.rb +9 -6
  178. data/lib/nokogiri/xml/pp/node.rb +27 -26
  179. data/lib/nokogiri/xml/pp.rb +4 -2
  180. data/lib/nokogiri/xml/processing_instruction.rb +4 -1
  181. data/lib/nokogiri/xml/reader.rb +21 -28
  182. data/lib/nokogiri/xml/relax_ng.rb +8 -2
  183. data/lib/nokogiri/xml/sax/document.rb +45 -49
  184. data/lib/nokogiri/xml/sax/parser.rb +39 -36
  185. data/lib/nokogiri/xml/sax/parser_context.rb +8 -3
  186. data/lib/nokogiri/xml/sax/push_parser.rb +6 -5
  187. data/lib/nokogiri/xml/sax.rb +6 -4
  188. data/lib/nokogiri/xml/schema.rb +19 -9
  189. data/lib/nokogiri/xml/searchable.rb +112 -72
  190. data/lib/nokogiri/xml/syntax_error.rb +6 -4
  191. data/lib/nokogiri/xml/text.rb +2 -0
  192. data/lib/nokogiri/xml/xpath/syntax_error.rb +4 -2
  193. data/lib/nokogiri/xml/xpath.rb +15 -4
  194. data/lib/nokogiri/xml/xpath_context.rb +3 -3
  195. data/lib/nokogiri/xml.rb +38 -37
  196. data/lib/nokogiri/xslt/stylesheet.rb +3 -1
  197. data/lib/nokogiri/xslt.rb +29 -20
  198. data/lib/nokogiri.rb +48 -72
  199. data/lib/xsd/xmlparser/nokogiri.rb +29 -25
  200. metadata +146 -307
  201. data/ext/nokogiri/html_document.c +0 -170
  202. data/ext/nokogiri/html_document.h +0 -10
  203. data/ext/nokogiri/html_element_description.c +0 -279
  204. data/ext/nokogiri/html_element_description.h +0 -10
  205. data/ext/nokogiri/html_entity_lookup.c +0 -32
  206. data/ext/nokogiri/html_entity_lookup.h +0 -8
  207. data/ext/nokogiri/html_sax_parser_context.c +0 -116
  208. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  209. data/ext/nokogiri/html_sax_push_parser.c +0 -87
  210. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  211. data/ext/nokogiri/xml_attr.h +0 -9
  212. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  213. data/ext/nokogiri/xml_cdata.h +0 -9
  214. data/ext/nokogiri/xml_comment.h +0 -9
  215. data/ext/nokogiri/xml_document.h +0 -23
  216. data/ext/nokogiri/xml_document_fragment.h +0 -10
  217. data/ext/nokogiri/xml_dtd.h +0 -10
  218. data/ext/nokogiri/xml_element_content.h +0 -10
  219. data/ext/nokogiri/xml_element_decl.h +0 -9
  220. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  221. data/ext/nokogiri/xml_entity_decl.h +0 -10
  222. data/ext/nokogiri/xml_entity_reference.h +0 -9
  223. data/ext/nokogiri/xml_io.c +0 -61
  224. data/ext/nokogiri/xml_io.h +0 -11
  225. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
  226. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  227. data/ext/nokogiri/xml_namespace.h +0 -14
  228. data/ext/nokogiri/xml_node.h +0 -13
  229. data/ext/nokogiri/xml_node_set.h +0 -12
  230. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  231. data/ext/nokogiri/xml_reader.h +0 -10
  232. data/ext/nokogiri/xml_relax_ng.h +0 -9
  233. data/ext/nokogiri/xml_sax_parser.h +0 -39
  234. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  235. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  236. data/ext/nokogiri/xml_schema.h +0 -9
  237. data/ext/nokogiri/xml_syntax_error.h +0 -13
  238. data/ext/nokogiri/xml_text.h +0 -9
  239. data/ext/nokogiri/xml_xpath_context.h +0 -10
  240. data/ext/nokogiri/xslt_stylesheet.h +0 -14
  241. data/lib/nokogiri/html/document.rb +0 -335
  242. data/lib/nokogiri/html/document_fragment.rb +0 -49
  243. data/lib/nokogiri/html/element_description_defaults.rb +0 -671
  244. data/lib/nokogiri/html/sax/parser_context.rb +0 -16
  245. data/patches/libxml2/0001-Revert-Do-not-URI-escape-in-server-side-includes.patch +0 -78
  246. data/patches/libxml2/0002-Remove-script-macro-support.patch +0 -40
  247. data/patches/libxml2/0003-Update-entities-to-remove-handling-of-ssi.patch +0 -44
  248. data/patches/libxml2/0004-libxml2.la-is-in-top_builddir.patch +0 -25
  249. data/patches/libxml2/0005-Fix-infinite-loop-in-xmlStringLenDecodeEntities.patch +0 -32
  250. data/ports/archives/libxml2-2.9.10.tar.gz +0 -0
  251. data/ports/archives/libxslt-1.1.34.tar.gz +0 -0
@@ -1,12 +1,11 @@
1
- #include <xml_node_set.h>
2
- #include <xml_namespace.h>
3
- #include <libxml/xpathInternals.h>
1
+ #include <nokogiri.h>
4
2
 
5
- static ID decorate ;
6
- static void xpath_node_set_del(xmlNodeSetPtr cur, xmlNodePtr val);
3
+ VALUE cNokogiriXmlNodeSet ;
7
4
 
5
+ static ID decorate ;
8
6
 
9
- static void Check_Node_Set_Node_Type(VALUE node)
7
+ static void
8
+ Check_Node_Set_Node_Type(VALUE node)
10
9
  {
11
10
  if (!(rb_obj_is_kind_of(node, cNokogiriXmlNode) ||
12
11
  rb_obj_is_kind_of(node, cNokogiriXmlNamespace))) {
@@ -15,34 +14,92 @@ static void Check_Node_Set_Node_Type(VALUE node)
15
14
  }
16
15
 
17
16
 
18
- static void deallocate(xmlNodeSetPtr node_set)
17
+ static
18
+ VALUE
19
+ ruby_object_get(xmlNodePtr c_node)
20
+ {
21
+ /* see xmlElementType in libxml2 tree.h */
22
+ switch (c_node->type) {
23
+ case XML_NAMESPACE_DECL:
24
+ /* _private is later in the namespace struct */
25
+ return (VALUE)(((xmlNsPtr)c_node)->_private);
26
+
27
+ case XML_DOCUMENT_NODE:
28
+ case XML_HTML_DOCUMENT_NODE:
29
+ /* in documents we use _private to store a tuple */
30
+ if (DOC_RUBY_OBJECT_TEST(((xmlDocPtr)c_node))) {
31
+ return DOC_RUBY_OBJECT((xmlDocPtr)c_node);
32
+ }
33
+ return (VALUE)NULL;
34
+
35
+ default:
36
+ return (VALUE)(c_node->_private);
37
+ }
38
+ }
39
+
40
+
41
+ static void
42
+ mark(xmlNodeSetPtr node_set)
43
+ {
44
+ VALUE rb_node;
45
+ int jnode;
46
+
47
+ for (jnode = 0; jnode < node_set->nodeNr; jnode++) {
48
+ rb_node = ruby_object_get(node_set->nodeTab[jnode]);
49
+ if (rb_node) {
50
+ rb_gc_mark(rb_node);
51
+ }
52
+ }
53
+ }
54
+
55
+ static void
56
+ xpath_node_set_del(xmlNodeSetPtr cur, xmlNodePtr val)
57
+ {
58
+ /*
59
+ * For reasons outlined in xml_namespace.c, here we reproduce xmlXPathNodeSetDel() except for the
60
+ * offending call to xmlXPathNodeSetFreeNs().
61
+ */
62
+ int i;
63
+
64
+ if (cur == NULL) { return; }
65
+ if (val == NULL) { return; }
66
+
67
+ /*
68
+ * find node in nodeTab
69
+ */
70
+ for (i = 0; i < cur->nodeNr; i++)
71
+ if (cur->nodeTab[i] == val) { break; }
72
+
73
+ if (i >= cur->nodeNr) { /* not found */
74
+ return;
75
+ }
76
+ cur->nodeNr--;
77
+ for (; i < cur->nodeNr; i++) {
78
+ cur->nodeTab[i] = cur->nodeTab[i + 1];
79
+ }
80
+ cur->nodeTab[cur->nodeNr] = NULL;
81
+ }
82
+
83
+
84
+ static void
85
+ deallocate(xmlNodeSetPtr node_set)
19
86
  {
20
87
  /*
21
- *
22
- * since xpath queries return copies of the xmlNs structs,
23
- * xmlXPathFreeNodeSet() frees those xmlNs structs that are in the
24
- * NodeSet.
25
- *
26
- * this is bad if someone is still trying to use the Namespace object wrapped
27
- * around the xmlNs, so we need to avoid that.
28
- *
29
- * here we reproduce xmlXPathFreeNodeSet() without the xmlNs logic.
30
- *
31
- * this doesn't cause a leak because Namespace objects that are in an XPath
32
- * query NodeSet are given their own lifecycle in
33
- * Nokogiri_wrap_xml_namespace().
88
+ * For reasons outlined in xml_namespace.c, here we reproduce xmlXPathFreeNodeSet() except for the
89
+ * offending call to xmlXPathNodeSetFreeNs().
34
90
  */
35
- NOKOGIRI_DEBUG_START(node_set) ;
36
- if (node_set->nodeTab != NULL)
91
+ if (node_set->nodeTab != NULL) {
37
92
  xmlFree(node_set->nodeTab);
93
+ }
38
94
 
39
95
  xmlFree(node_set);
40
- NOKOGIRI_DEBUG_END(node_set) ;
41
96
  }
42
97
 
43
- static VALUE allocate(VALUE klass)
98
+
99
+ static VALUE
100
+ allocate(VALUE klass)
44
101
  {
45
- return Nokogiri_wrap_xml_node_set(xmlXPathNodeSetCreate(NULL), Qnil);
102
+ return noko_xml_node_set_wrap(xmlXPathNodeSetCreate(NULL), Qnil);
46
103
  }
47
104
 
48
105
 
@@ -53,7 +110,8 @@ static VALUE allocate(VALUE klass)
53
110
  * Duplicate this NodeSet. Note that the Nodes contained in the NodeSet are not
54
111
  * duplicated (similar to how Array and other Enumerable classes work).
55
112
  */
56
- static VALUE duplicate(VALUE self)
113
+ static VALUE
114
+ duplicate(VALUE self)
57
115
  {
58
116
  xmlNodeSetPtr node_set;
59
117
  xmlNodeSetPtr dupl;
@@ -62,7 +120,7 @@ static VALUE duplicate(VALUE self)
62
120
 
63
121
  dupl = xmlXPathNodeSetMerge(NULL, node_set);
64
122
 
65
- return Nokogiri_wrap_xml_node_set(dupl, rb_iv_get(self, "@document"));
123
+ return noko_xml_node_set_wrap(dupl, rb_iv_get(self, "@document"));
66
124
  }
67
125
 
68
126
  /*
@@ -71,7 +129,8 @@ static VALUE duplicate(VALUE self)
71
129
  *
72
130
  * Get the length of the node set
73
131
  */
74
- static VALUE length(VALUE self)
132
+ static VALUE
133
+ length(VALUE self)
75
134
  {
76
135
  xmlNodeSetPtr node_set;
77
136
 
@@ -86,7 +145,8 @@ static VALUE length(VALUE self)
86
145
  *
87
146
  * Append +node+ to the NodeSet.
88
147
  */
89
- static VALUE push(VALUE self, VALUE rb_node)
148
+ static VALUE
149
+ push(VALUE self, VALUE rb_node)
90
150
  {
91
151
  xmlNodeSetPtr node_set;
92
152
  xmlNodePtr node;
@@ -94,7 +154,7 @@ static VALUE push(VALUE self, VALUE rb_node)
94
154
  Check_Node_Set_Node_Type(rb_node);
95
155
 
96
156
  Data_Get_Struct(self, xmlNodeSet, node_set);
97
- Data_Get_Struct(rb_node, xmlNode, node);
157
+ Noko_Node_Get_Struct(rb_node, xmlNode, node);
98
158
 
99
159
  xmlXPathNodeSetAdd(node_set, node);
100
160
 
@@ -109,7 +169,7 @@ static VALUE push(VALUE self, VALUE rb_node)
109
169
  * if found, otherwise returns nil.
110
170
  */
111
171
  static VALUE
112
- delete(VALUE self, VALUE rb_node)
172
+ delete (VALUE self, VALUE rb_node)
113
173
  {
114
174
  xmlNodeSetPtr node_set;
115
175
  xmlNodePtr node;
@@ -117,7 +177,7 @@ delete(VALUE self, VALUE rb_node)
117
177
  Check_Node_Set_Node_Type(rb_node);
118
178
 
119
179
  Data_Get_Struct(self, xmlNodeSet, node_set);
120
- Data_Get_Struct(rb_node, xmlNode, node);
180
+ Noko_Node_Get_Struct(rb_node, xmlNode, node);
121
181
 
122
182
  if (xmlXPathNodeSetContains(node_set, node)) {
123
183
  xpath_node_set_del(node_set, node);
@@ -133,19 +193,21 @@ delete(VALUE self, VALUE rb_node)
133
193
  *
134
194
  * Set Intersection — Returns a new NodeSet containing nodes common to the two NodeSets.
135
195
  */
136
- static VALUE intersection(VALUE self, VALUE rb_other)
196
+ static VALUE
197
+ intersection(VALUE self, VALUE rb_other)
137
198
  {
138
199
  xmlNodeSetPtr node_set, other ;
139
200
  xmlNodeSetPtr intersection;
140
201
 
141
- if(!rb_obj_is_kind_of(rb_other, cNokogiriXmlNodeSet))
202
+ if (!rb_obj_is_kind_of(rb_other, cNokogiriXmlNodeSet)) {
142
203
  rb_raise(rb_eArgError, "node_set must be a Nokogiri::XML::NodeSet");
204
+ }
143
205
 
144
206
  Data_Get_Struct(self, xmlNodeSet, node_set);
145
207
  Data_Get_Struct(rb_other, xmlNodeSet, other);
146
208
 
147
209
  intersection = xmlXPathIntersection(node_set, other);
148
- return Nokogiri_wrap_xml_node_set(intersection, rb_iv_get(self, "@document"));
210
+ return noko_xml_node_set_wrap(intersection, rb_iv_get(self, "@document"));
149
211
  }
150
212
 
151
213
 
@@ -155,7 +217,8 @@ static VALUE intersection(VALUE self, VALUE rb_other)
155
217
  *
156
218
  * Returns true if any member of node set equals +node+.
157
219
  */
158
- static VALUE include_eh(VALUE self, VALUE rb_node)
220
+ static VALUE
221
+ include_eh(VALUE self, VALUE rb_node)
159
222
  {
160
223
  xmlNodeSetPtr node_set;
161
224
  xmlNodePtr node;
@@ -163,7 +226,7 @@ static VALUE include_eh(VALUE self, VALUE rb_node)
163
226
  Check_Node_Set_Node_Type(rb_node);
164
227
 
165
228
  Data_Get_Struct(self, xmlNodeSet, node_set);
166
- Data_Get_Struct(rb_node, xmlNode, node);
229
+ Noko_Node_Get_Struct(rb_node, xmlNode, node);
167
230
 
168
231
  return (xmlXPathNodeSetContains(node_set, node) ? Qtrue : Qfalse);
169
232
  }
@@ -176,21 +239,23 @@ static VALUE include_eh(VALUE self, VALUE rb_node)
176
239
  * Returns a new set built by merging the set and the elements of the given
177
240
  * set.
178
241
  */
179
- static VALUE set_union(VALUE self, VALUE rb_other)
242
+ static VALUE
243
+ rb_xml_node_set_union(VALUE rb_node_set, VALUE rb_other)
180
244
  {
181
- xmlNodeSetPtr node_set, other;
182
- xmlNodeSetPtr new;
245
+ xmlNodeSetPtr c_node_set, c_other;
246
+ xmlNodeSetPtr c_new_node_set;
183
247
 
184
- if(!rb_obj_is_kind_of(rb_other, cNokogiriXmlNodeSet))
248
+ if (!rb_obj_is_kind_of(rb_other, cNokogiriXmlNodeSet)) {
185
249
  rb_raise(rb_eArgError, "node_set must be a Nokogiri::XML::NodeSet");
250
+ }
186
251
 
187
- Data_Get_Struct(self, xmlNodeSet, node_set);
188
- Data_Get_Struct(rb_other, xmlNodeSet, other);
252
+ Data_Get_Struct(rb_node_set, xmlNodeSet, c_node_set);
253
+ Data_Get_Struct(rb_other, xmlNodeSet, c_other);
189
254
 
190
- new = xmlXPathNodeSetMerge(NULL, node_set);
191
- new = xmlXPathNodeSetMerge(new, other);
255
+ c_new_node_set = xmlXPathNodeSetMerge(NULL, c_node_set);
256
+ c_new_node_set = xmlXPathNodeSetMerge(c_new_node_set, c_other);
192
257
 
193
- return Nokogiri_wrap_xml_node_set(new, rb_iv_get(self, "@document"));
258
+ return noko_xml_node_set_wrap(c_new_node_set, rb_iv_get(rb_node_set, "@document"));
194
259
  }
195
260
 
196
261
  /*
@@ -200,14 +265,16 @@ static VALUE set_union(VALUE self, VALUE rb_other)
200
265
  * Difference - returns a new NodeSet that is a copy of this NodeSet, removing
201
266
  * each item that also appears in +node_set+
202
267
  */
203
- static VALUE minus(VALUE self, VALUE rb_other)
268
+ static VALUE
269
+ minus(VALUE self, VALUE rb_other)
204
270
  {
205
271
  xmlNodeSetPtr node_set, other;
206
272
  xmlNodeSetPtr new;
207
273
  int j ;
208
274
 
209
- if(!rb_obj_is_kind_of(rb_other, cNokogiriXmlNodeSet))
275
+ if (!rb_obj_is_kind_of(rb_other, cNokogiriXmlNodeSet)) {
210
276
  rb_raise(rb_eArgError, "node_set must be a Nokogiri::XML::NodeSet");
277
+ }
211
278
 
212
279
  Data_Get_Struct(self, xmlNodeSet, node_set);
213
280
  Data_Get_Struct(rb_other, xmlNodeSet, other);
@@ -217,11 +284,12 @@ static VALUE minus(VALUE self, VALUE rb_other)
217
284
  xpath_node_set_del(new, other->nodeTab[j]);
218
285
  }
219
286
 
220
- return Nokogiri_wrap_xml_node_set(new, rb_iv_get(self, "@document"));
287
+ return noko_xml_node_set_wrap(new, rb_iv_get(self, "@document"));
221
288
  }
222
289
 
223
290
 
224
- static VALUE index_at(VALUE self, long offset)
291
+ static VALUE
292
+ index_at(VALUE self, long offset)
225
293
  {
226
294
  xmlNodeSetPtr node_set;
227
295
 
@@ -233,10 +301,11 @@ static VALUE index_at(VALUE self, long offset)
233
301
 
234
302
  if (offset < 0) { offset += node_set->nodeNr ; }
235
303
 
236
- return Nokogiri_wrap_xml_node_set_node(node_set->nodeTab[offset], self);
304
+ return noko_xml_node_wrap_node_set_result(node_set->nodeTab[offset], self);
237
305
  }
238
306
 
239
- static VALUE subseq(VALUE self, long beg, long len)
307
+ static VALUE
308
+ subseq(VALUE self, long beg, long len)
240
309
  {
241
310
  long j;
242
311
  xmlNodeSetPtr node_set;
@@ -244,18 +313,18 @@ static VALUE subseq(VALUE self, long beg, long len)
244
313
 
245
314
  Data_Get_Struct(self, xmlNodeSet, node_set);
246
315
 
247
- if (beg > node_set->nodeNr) return Qnil ;
248
- if (beg < 0 || len < 0) return Qnil ;
316
+ if (beg > node_set->nodeNr) { return Qnil ; }
317
+ if (beg < 0 || len < 0) { return Qnil ; }
249
318
 
250
319
  if ((beg + len) > node_set->nodeNr) {
251
320
  len = node_set->nodeNr - beg ;
252
321
  }
253
322
 
254
323
  new_set = xmlXPathNodeSetCreate(NULL);
255
- for (j = beg ; j < beg+len ; ++j) {
324
+ for (j = beg ; j < beg + len ; ++j) {
256
325
  xmlXPathNodeSetAddUnique(new_set, node_set->nodeTab[j]);
257
326
  }
258
- return Nokogiri_wrap_xml_node_set(new_set, rb_iv_get(self, "@document"));
327
+ return noko_xml_node_set_wrap(new_set, rb_iv_get(self, "@document"));
259
328
  }
260
329
 
261
330
  /*
@@ -273,7 +342,8 @@ static VALUE subseq(VALUE self, long beg, long len)
273
342
  * count backward from the end of the +node_set+ (-1 is the last node). Returns
274
343
  * nil if the +index+ (or +start+) are out of range.
275
344
  */
276
- static VALUE slice(int argc, VALUE *argv, VALUE self)
345
+ static VALUE
346
+ slice(int argc, VALUE *argv, VALUE self)
277
347
  {
278
348
  VALUE arg ;
279
349
  long beg, len ;
@@ -301,12 +371,12 @@ static VALUE slice(int argc, VALUE *argv, VALUE self)
301
371
 
302
372
  /* if arg is Range */
303
373
  switch (rb_range_beg_len(arg, &beg, &len, (long)node_set->nodeNr, 0)) {
304
- case Qfalse:
305
- break;
306
- case Qnil:
307
- return Qnil;
308
- default:
309
- return subseq(self, beg, len);
374
+ case Qfalse:
375
+ break;
376
+ case Qnil:
377
+ return Qnil;
378
+ default:
379
+ return subseq(self, beg, len);
310
380
  }
311
381
 
312
382
  return index_at(self, NUM2LONG(arg));
@@ -319,7 +389,8 @@ static VALUE slice(int argc, VALUE *argv, VALUE self)
319
389
  *
320
390
  * Return this list as an Array
321
391
  */
322
- static VALUE to_array(VALUE self, VALUE rb_node)
392
+ static VALUE
393
+ to_array(VALUE self)
323
394
  {
324
395
  xmlNodeSetPtr node_set ;
325
396
  VALUE list;
@@ -328,9 +399,9 @@ static VALUE to_array(VALUE self, VALUE rb_node)
328
399
  Data_Get_Struct(self, xmlNodeSet, node_set);
329
400
 
330
401
  list = rb_ary_new2(node_set->nodeNr);
331
- for(i = 0; i < node_set->nodeNr; i++) {
332
- VALUE elt = Nokogiri_wrap_xml_node_set_node(node_set->nodeTab[i], self);
333
- rb_ary_push( list, elt );
402
+ for (i = 0; i < node_set->nodeNr; i++) {
403
+ VALUE elt = noko_xml_node_wrap_node_set_result(node_set->nodeTab[i], self);
404
+ rb_ary_push(list, elt);
334
405
  }
335
406
 
336
407
  return list;
@@ -342,7 +413,8 @@ static VALUE to_array(VALUE self, VALUE rb_node)
342
413
  *
343
414
  * Unlink this NodeSet and all Node objects it contains from their current context.
344
415
  */
345
- static VALUE unlink_nodeset(VALUE self)
416
+ static VALUE
417
+ unlink_nodeset(VALUE self)
346
418
  {
347
419
  xmlNodeSetPtr node_set;
348
420
  int j, nodeNr ;
@@ -354,9 +426,9 @@ static VALUE unlink_nodeset(VALUE self)
354
426
  if (! NOKOGIRI_NAMESPACE_EH(node_set->nodeTab[j])) {
355
427
  VALUE node ;
356
428
  xmlNodePtr node_ptr;
357
- node = Nokogiri_wrap_xml_node(Qnil, node_set->nodeTab[j]);
429
+ node = noko_xml_node_wrap(Qnil, node_set->nodeTab[j]);
358
430
  rb_funcall(node, rb_intern("unlink"), 0); /* modifies the C struct out from under the object */
359
- Data_Get_Struct(node, xmlNode, node_ptr);
431
+ Noko_Node_Get_Struct(node, xmlNode, node_ptr);
360
432
  node_set->nodeTab[j] = node_ptr ;
361
433
  }
362
434
  }
@@ -364,123 +436,61 @@ static VALUE unlink_nodeset(VALUE self)
364
436
  }
365
437
 
366
438
 
367
- static void reify_node_set_namespaces(VALUE self)
439
+ VALUE
440
+ noko_xml_node_set_wrap(xmlNodeSetPtr c_node_set, VALUE document)
368
441
  {
369
- /*
370
- * as mentioned in deallocate() above, xmlNs structs returned in an XPath
371
- * NodeSet are duplicates, and we don't clean them up at deallocate() time.
372
- *
373
- * as a result, we need to make sure the Ruby manages this memory. we do this
374
- * by forcing the creation of a Ruby object wrapped around the xmlNs.
375
- *
376
- * we also have to make sure that the NodeSet has a reference to the
377
- * Namespace object, otherwise GC will kick in and the Namespace won't be
378
- * marked.
379
- *
380
- * we *could* do this safely with *all* the nodes in the NodeSet, but we only
381
- * *need* to do it for xmlNs structs, and so you get the code we have here.
382
- */
383
- int j ;
384
- xmlNodeSetPtr node_set ;
385
- VALUE namespace_cache ;
386
-
387
- Data_Get_Struct(self, xmlNodeSet, node_set);
388
-
389
- namespace_cache = rb_iv_get(self, "@namespace_cache");
442
+ int j;
443
+ VALUE rb_node_set ;
390
444
 
391
- for (j = 0 ; j < node_set->nodeNr ; j++) {
392
- if (NOKOGIRI_NAMESPACE_EH(node_set->nodeTab[j])) {
393
- rb_ary_push(namespace_cache, Nokogiri_wrap_xml_node_set_node(node_set->nodeTab[j], self));
394
- }
445
+ if (c_node_set == NULL) {
446
+ c_node_set = xmlXPathNodeSetCreate(NULL);
395
447
  }
396
- }
397
-
398
448
 
399
- VALUE Nokogiri_wrap_xml_node_set(xmlNodeSetPtr node_set, VALUE document)
400
- {
401
- VALUE new_set ;
402
-
403
- if (node_set == NULL) {
404
- node_set = xmlXPathNodeSetCreate(NULL);
405
- }
406
-
407
- new_set = Data_Wrap_Struct(cNokogiriXmlNodeSet, 0, deallocate, node_set);
449
+ rb_node_set = Data_Wrap_Struct(cNokogiriXmlNodeSet, mark, deallocate, c_node_set);
408
450
 
409
451
  if (!NIL_P(document)) {
410
- rb_iv_set(new_set, "@document", document);
411
- rb_funcall(document, decorate, 1, new_set);
452
+ rb_iv_set(rb_node_set, "@document", document);
453
+ rb_funcall(document, decorate, 1, rb_node_set);
412
454
  }
413
455
 
414
- rb_iv_set(new_set, "@namespace_cache", rb_ary_new());
415
- reify_node_set_namespaces(new_set);
456
+ /* make sure we create ruby objects for all the results, so they'll be marked during the GC mark phase */
457
+ for (j = 0 ; j < c_node_set->nodeNr ; j++) {
458
+ noko_xml_node_wrap_node_set_result(c_node_set->nodeTab[j], rb_node_set);
459
+ }
416
460
 
417
- return new_set ;
461
+ return rb_node_set ;
418
462
  }
419
463
 
420
- VALUE Nokogiri_wrap_xml_node_set_node(xmlNodePtr node, VALUE node_set)
464
+ VALUE
465
+ noko_xml_node_wrap_node_set_result(xmlNodePtr node, VALUE node_set)
421
466
  {
422
- xmlDocPtr document ;
423
-
424
467
  if (NOKOGIRI_NAMESPACE_EH(node)) {
425
- Data_Get_Struct(rb_iv_get(node_set, "@document"), xmlDoc, document);
426
- return Nokogiri_wrap_xml_namespace(document, (xmlNsPtr)node);
468
+ return noko_xml_namespace_wrap_xpath_copy((xmlNsPtr)node);
427
469
  } else {
428
- return Nokogiri_wrap_xml_node(Qnil, node);
470
+ return noko_xml_node_wrap(Qnil, node);
429
471
  }
430
472
  }
431
473
 
432
474
 
433
- static void xpath_node_set_del(xmlNodeSetPtr cur, xmlNodePtr val)
434
- {
435
- /*
436
- * as mentioned a few times above, we do not want to free xmlNs structs
437
- * outside of the Namespace lifecycle.
438
- *
439
- * xmlXPathNodeSetDel() frees xmlNs structs, and so here we reproduce that
440
- * function with the xmlNs logic.
441
- */
442
- int i;
443
-
444
- if (cur == NULL) return;
445
- if (val == NULL) return;
446
-
447
- /*
448
- * find node in nodeTab
449
- */
450
- for (i = 0;i < cur->nodeNr;i++)
451
- if (cur->nodeTab[i] == val) break;
452
-
453
- if (i >= cur->nodeNr) { /* not found */
454
- return;
455
- }
456
- cur->nodeNr--;
457
- for (;i < cur->nodeNr;i++)
458
- cur->nodeTab[i] = cur->nodeTab[i + 1];
459
- cur->nodeTab[cur->nodeNr] = NULL;
460
- }
461
-
462
-
463
- VALUE cNokogiriXmlNodeSet ;
464
- void init_xml_node_set(void)
475
+ void
476
+ noko_init_xml_node_set(void)
465
477
  {
466
- VALUE nokogiri = rb_define_module("Nokogiri");
467
- VALUE xml = rb_define_module_under(nokogiri, "XML");
468
- VALUE klass = rb_define_class_under(xml, "NodeSet", rb_cObject);
469
- cNokogiriXmlNodeSet = klass;
470
-
471
- rb_define_alloc_func(klass, allocate);
472
- rb_define_method(klass, "length", length, 0);
473
- rb_define_method(klass, "[]", slice, -1);
474
- rb_define_method(klass, "slice", slice, -1);
475
- rb_define_method(klass, "push", push, 1);
476
- rb_define_method(klass, "|", set_union, 1);
477
- rb_define_method(klass, "-", minus, 1);
478
- rb_define_method(klass, "unlink", unlink_nodeset, 0);
479
- rb_define_method(klass, "to_a", to_array, 0);
480
- rb_define_method(klass, "dup", duplicate, 0);
481
- rb_define_method(klass, "delete", delete, 1);
482
- rb_define_method(klass, "&", intersection, 1);
483
- rb_define_method(klass, "include?", include_eh, 1);
478
+ cNokogiriXmlNodeSet = rb_define_class_under(mNokogiriXml, "NodeSet", rb_cObject);
479
+
480
+ rb_define_alloc_func(cNokogiriXmlNodeSet, allocate);
481
+
482
+ rb_define_method(cNokogiriXmlNodeSet, "length", length, 0);
483
+ rb_define_method(cNokogiriXmlNodeSet, "[]", slice, -1);
484
+ rb_define_method(cNokogiriXmlNodeSet, "slice", slice, -1);
485
+ rb_define_method(cNokogiriXmlNodeSet, "push", push, 1);
486
+ rb_define_method(cNokogiriXmlNodeSet, "|", rb_xml_node_set_union, 1);
487
+ rb_define_method(cNokogiriXmlNodeSet, "-", minus, 1);
488
+ rb_define_method(cNokogiriXmlNodeSet, "unlink", unlink_nodeset, 0);
489
+ rb_define_method(cNokogiriXmlNodeSet, "to_a", to_array, 0);
490
+ rb_define_method(cNokogiriXmlNodeSet, "dup", duplicate, 0);
491
+ rb_define_method(cNokogiriXmlNodeSet, "delete", delete, 1);
492
+ rb_define_method(cNokogiriXmlNodeSet, "&", intersection, 1);
493
+ rb_define_method(cNokogiriXmlNodeSet, "include?", include_eh, 1);
484
494
 
485
495
  decorate = rb_intern("decorate");
486
496
  }
@@ -1,4 +1,6 @@
1
- #include <xml_processing_instruction.h>
1
+ #include <nokogiri.h>
2
+
3
+ VALUE cNokogiriXmlProcessingInstruction;
2
4
 
3
5
  /*
4
6
  * call-seq:
@@ -7,7 +9,8 @@
7
9
  * Create a new ProcessingInstruction element on the +document+ with +name+
8
10
  * and +content+
9
11
  */
10
- static VALUE new(int argc, VALUE *argv, VALUE klass)
12
+ static VALUE
13
+ new (int argc, VALUE *argv, VALUE klass)
11
14
  {
12
15
  xmlDocPtr xml_doc;
13
16
  xmlNodePtr node;
@@ -22,35 +25,30 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
22
25
  Data_Get_Struct(document, xmlDoc, xml_doc);
23
26
 
24
27
  node = xmlNewDocPI(
25
- xml_doc,
26
- (const xmlChar *)StringValueCStr(name),
27
- (const xmlChar *)StringValueCStr(content)
28
- );
28
+ xml_doc,
29
+ (const xmlChar *)StringValueCStr(name),
30
+ (const xmlChar *)StringValueCStr(content)
31
+ );
29
32
 
30
- nokogiri_root_node(node);
33
+ noko_xml_document_pin_node(node);
31
34
 
32
- rb_node = Nokogiri_wrap_xml_node(klass, node);
35
+ rb_node = noko_xml_node_wrap(klass, node);
33
36
  rb_obj_call_init(rb_node, argc, argv);
34
37
 
35
- if(rb_block_given_p()) rb_yield(rb_node);
38
+ if (rb_block_given_p()) { rb_yield(rb_node); }
36
39
 
37
40
  return rb_node;
38
41
  }
39
42
 
40
- VALUE cNokogiriXmlProcessingInstruction;
41
- void init_xml_processing_instruction()
43
+ void
44
+ noko_init_xml_processing_instruction(void)
42
45
  {
43
- VALUE nokogiri = rb_define_module("Nokogiri");
44
- VALUE xml = rb_define_module_under(nokogiri, "XML");
45
- VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
46
-
46
+ assert(cNokogiriXmlNode);
47
47
  /*
48
48
  * ProcessingInstruction represents a ProcessingInstruction node in an xml
49
49
  * document.
50
50
  */
51
- VALUE klass = rb_define_class_under(xml, "ProcessingInstruction", node);
52
-
53
- cNokogiriXmlProcessingInstruction = klass;
51
+ cNokogiriXmlProcessingInstruction = rb_define_class_under(mNokogiriXml, "ProcessingInstruction", cNokogiriXmlNode);
54
52
 
55
- rb_define_singleton_method(klass, "new", new, -1);
53
+ rb_define_singleton_method(cNokogiriXmlProcessingInstruction, "new", new, -1);
56
54
  }