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,91 +1,117 @@
1
- #include <xml_document.h>
1
+ #include <nokogiri.h>
2
2
 
3
- static int dealloc_node_i(xmlNodePtr key, xmlNodePtr node, xmlDocPtr doc)
3
+ VALUE cNokogiriXmlDocument ;
4
+
5
+ static int
6
+ dealloc_node_i2(xmlNodePtr key, xmlNodePtr node, xmlDocPtr doc)
4
7
  {
5
- switch(node->type) {
6
- case XML_ATTRIBUTE_NODE:
7
- xmlFreePropList((xmlAttrPtr)node);
8
- break;
9
- case XML_NAMESPACE_DECL:
10
- xmlFreeNs((xmlNsPtr)node);
11
- break;
12
- case XML_DTD_NODE:
13
- xmlFreeDtd((xmlDtdPtr)node);
14
- break;
15
- default:
16
- if(node->parent == NULL) {
17
- xmlAddChild((xmlNodePtr)doc, node);
18
- }
8
+ switch (node->type) {
9
+ case XML_ATTRIBUTE_NODE:
10
+ xmlFreePropList((xmlAttrPtr)node);
11
+ break;
12
+ case XML_NAMESPACE_DECL:
13
+ xmlFreeNs((xmlNsPtr)node);
14
+ break;
15
+ case XML_DTD_NODE:
16
+ xmlFreeDtd((xmlDtdPtr)node);
17
+ break;
18
+ default:
19
+ if (node->parent == NULL) {
20
+ xmlAddChild((xmlNodePtr)doc, node);
21
+ }
19
22
  }
20
23
  return ST_CONTINUE;
21
24
  }
22
25
 
23
- static void remove_private(xmlNodePtr node)
26
+ static int
27
+ dealloc_node_i(st_data_t key, st_data_t node, st_data_t doc)
28
+ {
29
+ return dealloc_node_i2((xmlNodePtr)key, (xmlNodePtr)node, (xmlDocPtr)doc);
30
+ }
31
+
32
+ static void
33
+ remove_private(xmlNodePtr node)
24
34
  {
25
35
  xmlNodePtr child;
26
36
 
27
- for (child = node->children; child; child = child->next)
37
+ for (child = node->children; child; child = child->next) {
28
38
  remove_private(child);
39
+ }
29
40
 
30
41
  if ((node->type == XML_ELEMENT_NODE ||
31
42
  node->type == XML_XINCLUDE_START ||
32
43
  node->type == XML_XINCLUDE_END) &&
33
44
  node->properties) {
34
- for (child = (xmlNodePtr)node->properties; child; child = child->next)
45
+ for (child = (xmlNodePtr)node->properties; child; child = child->next) {
35
46
  remove_private(child);
47
+ }
36
48
  }
37
49
 
38
50
  node->_private = NULL;
39
51
  }
40
52
 
41
- static void dealloc(xmlDocPtr doc)
53
+ static void
54
+ mark(xmlDocPtr doc)
42
55
  {
43
- st_table *node_hash;
56
+ nokogiriTuplePtr tuple = (nokogiriTuplePtr)doc->_private;
57
+ if (tuple) {
58
+ rb_gc_mark(tuple->doc);
59
+ rb_gc_mark(tuple->node_cache);
60
+ }
61
+ }
44
62
 
45
- NOKOGIRI_DEBUG_START(doc);
63
+ static void
64
+ dealloc(xmlDocPtr doc)
65
+ {
66
+ st_table *node_hash;
46
67
 
47
68
  node_hash = DOC_UNLINKED_NODE_HASH(doc);
48
69
 
49
70
  st_foreach(node_hash, dealloc_node_i, (st_data_t)doc);
50
71
  st_free_table(node_hash);
51
72
 
52
- free(doc->_private);
73
+ ruby_xfree(doc->_private);
53
74
 
54
75
  /* When both Nokogiri and libxml-ruby are loaded, make sure that all nodes
55
76
  * have their _private pointers cleared. This is to avoid libxml-ruby's
56
77
  * xmlDeregisterNode callback from accessing VALUE pointers from ruby's GC
57
78
  * free context, which can result in segfaults.
58
79
  */
59
- if (xmlDeregisterNodeDefaultValue)
80
+ if (xmlDeregisterNodeDefaultValue) {
60
81
  remove_private((xmlNodePtr)doc);
82
+ }
61
83
 
62
84
  xmlFreeDoc(doc);
63
-
64
- NOKOGIRI_DEBUG_END(doc);
65
85
  }
66
86
 
67
- static void recursively_remove_namespaces_from_node(xmlNodePtr node)
87
+ static void
88
+ recursively_remove_namespaces_from_node(xmlNodePtr node)
68
89
  {
69
90
  xmlNodePtr child ;
70
91
  xmlAttrPtr property ;
71
92
 
72
93
  xmlSetNs(node, NULL);
73
94
 
74
- for (child = node->children ; child ; child = child->next)
95
+ for (child = node->children ; child ; child = child->next) {
75
96
  recursively_remove_namespaces_from_node(child);
97
+ }
76
98
 
77
99
  if (((node->type == XML_ELEMENT_NODE) ||
78
100
  (node->type == XML_XINCLUDE_START) ||
79
101
  (node->type == XML_XINCLUDE_END)) &&
80
102
  node->nsDef) {
81
- xmlFreeNsList(node->nsDef);
103
+ xmlNsPtr curr = node->nsDef;
104
+ while (curr) {
105
+ noko_xml_document_pin_namespace(curr, node->doc);
106
+ curr = curr->next;
107
+ }
82
108
  node->nsDef = NULL;
83
109
  }
84
110
 
85
111
  if (node->type == XML_ELEMENT_NODE && node->properties != NULL) {
86
112
  property = node->properties ;
87
113
  while (property != NULL) {
88
- if (property->ns) property->ns = NULL ;
114
+ if (property->ns) { property->ns = NULL ; }
89
115
  property = property->next ;
90
116
  }
91
117
  }
@@ -97,12 +123,13 @@ static void recursively_remove_namespaces_from_node(xmlNodePtr node)
97
123
  *
98
124
  * Get the url name for this document.
99
125
  */
100
- static VALUE url(VALUE self)
126
+ static VALUE
127
+ url(VALUE self)
101
128
  {
102
129
  xmlDocPtr doc;
103
130
  Data_Get_Struct(self, xmlDoc, doc);
104
131
 
105
- if(doc->URL) return NOKOGIRI_STR_NEW2(doc->URL);
132
+ if (doc->URL) { return NOKOGIRI_STR_NEW2(doc->URL); }
106
133
 
107
134
  return Qnil;
108
135
  }
@@ -113,42 +140,42 @@ static VALUE url(VALUE self)
113
140
  *
114
141
  * Set the root element on this document
115
142
  */
116
- static VALUE set_root(VALUE self, VALUE root)
143
+ static VALUE
144
+ rb_xml_document_root_set(VALUE self, VALUE rb_new_root)
117
145
  {
118
- xmlDocPtr doc;
119
- xmlNodePtr new_root;
120
- xmlNodePtr old_root;
146
+ xmlDocPtr c_document;
147
+ xmlNodePtr c_new_root = NULL, c_current_root;
121
148
 
122
- Data_Get_Struct(self, xmlDoc, doc);
123
-
124
- old_root = NULL;
125
-
126
- if(NIL_P(root)) {
127
- old_root = xmlDocGetRootElement(doc);
128
-
129
- if(old_root) {
130
- xmlUnlinkNode(old_root);
131
- nokogiri_root_node(old_root);
132
- }
149
+ Data_Get_Struct(self, xmlDoc, c_document);
133
150
 
134
- return root;
151
+ c_current_root = xmlDocGetRootElement(c_document);
152
+ if (c_current_root) {
153
+ xmlUnlinkNode(c_current_root);
154
+ noko_xml_document_pin_node(c_current_root);
135
155
  }
136
156
 
137
- Data_Get_Struct(root, xmlNode, new_root);
157
+ if (!NIL_P(rb_new_root)) {
158
+ if (!rb_obj_is_kind_of(rb_new_root, cNokogiriXmlNode)) {
159
+ rb_raise(rb_eArgError,
160
+ "expected Nokogiri::XML::Node but received %"PRIsVALUE,
161
+ rb_obj_class(rb_new_root));
162
+ }
138
163
 
164
+ Noko_Node_Get_Struct(rb_new_root, xmlNode, c_new_root);
139
165
 
140
- /* If the new root's document is not the same as the current document,
141
- * then we need to dup the node in to this document. */
142
- if(new_root->doc != doc) {
143
- old_root = xmlDocGetRootElement(doc);
144
- if (!(new_root = xmlDocCopyNode(new_root, doc, 1))) {
145
- rb_raise(rb_eRuntimeError, "Could not reparent node (xmlDocCopyNode)");
166
+ /* If the new root's document is not the same as the current document,
167
+ * then we need to dup the node in to this document. */
168
+ if (c_new_root->doc != c_document) {
169
+ c_new_root = xmlDocCopyNode(c_new_root, c_document, 1);
170
+ if (!c_new_root) {
171
+ rb_raise(rb_eRuntimeError, "Could not reparent node (xmlDocCopyNode)");
172
+ }
146
173
  }
147
174
  }
148
175
 
149
- xmlDocSetRootElement(doc, new_root);
150
- if(old_root) nokogiri_root_node(old_root);
151
- return root;
176
+ xmlDocSetRootElement(c_document, c_new_root);
177
+
178
+ return rb_new_root;
152
179
  }
153
180
 
154
181
  /*
@@ -157,17 +184,20 @@ static VALUE set_root(VALUE self, VALUE root)
157
184
  *
158
185
  * Get the root node for this document.
159
186
  */
160
- static VALUE root(VALUE self)
187
+ static VALUE
188
+ rb_xml_document_root(VALUE self)
161
189
  {
162
- xmlDocPtr doc;
163
- xmlNodePtr root;
190
+ xmlDocPtr c_document;
191
+ xmlNodePtr c_root;
164
192
 
165
- Data_Get_Struct(self, xmlDoc, doc);
193
+ Data_Get_Struct(self, xmlDoc, c_document);
166
194
 
167
- root = xmlDocGetRootElement(doc);
195
+ c_root = xmlDocGetRootElement(c_document);
196
+ if (!c_root) {
197
+ return Qnil;
198
+ }
168
199
 
169
- if(!root) return Qnil;
170
- return Nokogiri_wrap_xml_node(Qnil, root) ;
200
+ return noko_xml_node_wrap(Qnil, c_root) ;
171
201
  }
172
202
 
173
203
  /*
@@ -176,13 +206,15 @@ static VALUE root(VALUE self)
176
206
  *
177
207
  * Set the encoding string for this Document
178
208
  */
179
- static VALUE set_encoding(VALUE self, VALUE encoding)
209
+ static VALUE
210
+ set_encoding(VALUE self, VALUE encoding)
180
211
  {
181
212
  xmlDocPtr doc;
182
213
  Data_Get_Struct(self, xmlDoc, doc);
183
214
 
184
- if (doc->encoding)
185
- free((char *)(uintptr_t) doc->encoding); /* avoid gcc cast warning */
215
+ if (doc->encoding) {
216
+ xmlFree(DISCARD_CONST_QUAL_XMLCHAR(doc->encoding));
217
+ }
186
218
 
187
219
  doc->encoding = xmlStrdup((xmlChar *)StringValueCStr(encoding));
188
220
 
@@ -195,12 +227,13 @@ static VALUE set_encoding(VALUE self, VALUE encoding)
195
227
  *
196
228
  * Get the encoding for this Document
197
229
  */
198
- static VALUE encoding(VALUE self)
230
+ static VALUE
231
+ encoding(VALUE self)
199
232
  {
200
233
  xmlDocPtr doc;
201
234
  Data_Get_Struct(self, xmlDoc, doc);
202
235
 
203
- if(!doc->encoding) return Qnil;
236
+ if (!doc->encoding) { return Qnil; }
204
237
  return NOKOGIRI_STR_NEW2(doc->encoding);
205
238
  }
206
239
 
@@ -210,12 +243,13 @@ static VALUE encoding(VALUE self)
210
243
  *
211
244
  * Get the XML version for this Document
212
245
  */
213
- static VALUE version(VALUE self)
246
+ static VALUE
247
+ version(VALUE self)
214
248
  {
215
249
  xmlDocPtr doc;
216
250
  Data_Get_Struct(self, xmlDoc, doc);
217
251
 
218
- if(!doc->version) return Qnil;
252
+ if (!doc->version) { return Qnil; }
219
253
  return NOKOGIRI_STR_NEW2(doc->version);
220
254
  }
221
255
 
@@ -225,14 +259,15 @@ static VALUE version(VALUE self)
225
259
  *
226
260
  * Create a new document from an IO object
227
261
  */
228
- static VALUE read_io( VALUE klass,
229
- VALUE io,
230
- VALUE url,
231
- VALUE encoding,
232
- VALUE options )
262
+ static VALUE
263
+ read_io(VALUE klass,
264
+ VALUE io,
265
+ VALUE url,
266
+ VALUE encoding,
267
+ VALUE options)
233
268
  {
234
- const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url);
235
- const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
269
+ const char *c_url = NIL_P(url) ? NULL : StringValueCStr(url);
270
+ const char *c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
236
271
  VALUE error_list = rb_ary_new();
237
272
  VALUE document;
238
273
  xmlDocPtr doc;
@@ -241,30 +276,31 @@ static VALUE read_io( VALUE klass,
241
276
  xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
242
277
 
243
278
  doc = xmlReadIO(
244
- (xmlInputReadCallback)io_read_callback,
245
- (xmlInputCloseCallback)io_close_callback,
246
- (void *)io,
247
- c_url,
248
- c_enc,
249
- (int)NUM2INT(options)
250
- );
279
+ (xmlInputReadCallback)noko_io_read,
280
+ (xmlInputCloseCallback)noko_io_close,
281
+ (void *)io,
282
+ c_url,
283
+ c_enc,
284
+ (int)NUM2INT(options)
285
+ );
251
286
  xmlSetStructuredErrorFunc(NULL, NULL);
252
287
 
253
- if(doc == NULL) {
288
+ if (doc == NULL) {
254
289
  xmlErrorPtr error;
255
290
 
256
291
  xmlFreeDoc(doc);
257
292
 
258
293
  error = xmlGetLastError();
259
- if(error)
294
+ if (error) {
260
295
  rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
261
- else
296
+ } else {
262
297
  rb_raise(rb_eRuntimeError, "Could not parse document");
298
+ }
263
299
 
264
300
  return Qnil;
265
301
  }
266
302
 
267
- document = Nokogiri_wrap_xml_document(klass, doc);
303
+ document = noko_xml_document_wrap(klass, doc);
268
304
  rb_iv_set(document, "@errors", error_list);
269
305
  return document;
270
306
  }
@@ -275,15 +311,16 @@ static VALUE read_io( VALUE klass,
275
311
  *
276
312
  * Create a new document from a String
277
313
  */
278
- static VALUE read_memory( VALUE klass,
279
- VALUE string,
280
- VALUE url,
281
- VALUE encoding,
282
- VALUE options )
314
+ static VALUE
315
+ read_memory(VALUE klass,
316
+ VALUE string,
317
+ VALUE url,
318
+ VALUE encoding,
319
+ VALUE options)
283
320
  {
284
- const char * c_buffer = StringValuePtr(string);
285
- const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url);
286
- const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
321
+ const char *c_buffer = StringValuePtr(string);
322
+ const char *c_url = NIL_P(url) ? NULL : StringValueCStr(url);
323
+ const char *c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
287
324
  int len = (int)RSTRING_LEN(string);
288
325
  VALUE error_list = rb_ary_new();
289
326
  VALUE document;
@@ -294,21 +331,22 @@ static VALUE read_memory( VALUE klass,
294
331
  doc = xmlReadMemory(c_buffer, len, c_url, c_enc, (int)NUM2INT(options));
295
332
  xmlSetStructuredErrorFunc(NULL, NULL);
296
333
 
297
- if(doc == NULL) {
334
+ if (doc == NULL) {
298
335
  xmlErrorPtr error;
299
336
 
300
337
  xmlFreeDoc(doc);
301
338
 
302
339
  error = xmlGetLastError();
303
- if(error)
340
+ if (error) {
304
341
  rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
305
- else
342
+ } else {
306
343
  rb_raise(rb_eRuntimeError, "Could not parse document");
344
+ }
307
345
 
308
346
  return Qnil;
309
347
  }
310
348
 
311
- document = Nokogiri_wrap_xml_document(klass, doc);
349
+ document = noko_xml_document_wrap(klass, doc);
312
350
  rb_iv_set(document, "@errors", error_list);
313
351
  return document;
314
352
  }
@@ -320,26 +358,26 @@ static VALUE read_memory( VALUE klass,
320
358
  * Copy this Document. An optional depth may be passed in, but it defaults
321
359
  * to a deep copy. 0 is a shallow copy, 1 is a deep copy.
322
360
  */
323
- static VALUE duplicate_document(int argc, VALUE *argv, VALUE self)
361
+ static VALUE
362
+ duplicate_document(int argc, VALUE *argv, VALUE self)
324
363
  {
325
364
  xmlDocPtr doc, dup;
326
365
  VALUE copy;
327
366
  VALUE level;
328
- VALUE error_list;
329
367
 
330
- if(rb_scan_args(argc, argv, "01", &level) == 0)
368
+ if (rb_scan_args(argc, argv, "01", &level) == 0) {
331
369
  level = INT2NUM((long)1);
370
+ }
332
371
 
333
372
  Data_Get_Struct(self, xmlDoc, doc);
334
373
 
335
374
  dup = xmlCopyDoc(doc, (int)NUM2INT(level));
336
375
 
337
- if(dup == NULL) return Qnil;
376
+ if (dup == NULL) { return Qnil; }
338
377
 
339
378
  dup->type = doc->type;
340
- copy = Nokogiri_wrap_xml_document(rb_obj_class(self), dup);
341
- error_list = rb_iv_get(self, "@errors");
342
- rb_iv_set(copy, "@errors", error_list);
379
+ copy = noko_xml_document_wrap(rb_obj_class(self), dup);
380
+ rb_iv_set(copy, "@errors", rb_iv_get(self, "@errors"));
343
381
  return copy ;
344
382
  }
345
383
 
@@ -349,18 +387,18 @@ static VALUE duplicate_document(int argc, VALUE *argv, VALUE self)
349
387
  *
350
388
  * Create a new document with +version+ (defaults to "1.0")
351
389
  */
352
- static VALUE new(int argc, VALUE *argv, VALUE klass)
390
+ static VALUE
391
+ new (int argc, VALUE *argv, VALUE klass)
353
392
  {
354
393
  xmlDocPtr doc;
355
394
  VALUE version, rest, rb_doc ;
356
395
 
357
396
  rb_scan_args(argc, argv, "0*", &rest);
358
397
  version = rb_ary_entry(rest, (long)0);
359
- if (NIL_P(version)) version = rb_str_new2("1.0");
398
+ if (NIL_P(version)) { version = rb_str_new2("1.0"); }
360
399
 
361
400
  doc = xmlNewDoc((xmlChar *)StringValueCStr(version));
362
- rb_doc = Nokogiri_wrap_xml_document(klass, doc);
363
- rb_obj_call_init(rb_doc, argc, argv);
401
+ rb_doc = noko_xml_document_wrap_with_init_args(klass, doc, argc, argv);
364
402
  return rb_doc ;
365
403
  }
366
404
 
@@ -401,7 +439,8 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
401
439
  * please direct your browser to
402
440
  * http://tenderlovemaking.com/2009/04/23/namespaces-in-xml.html
403
441
  */
404
- VALUE remove_namespaces_bang(VALUE self)
442
+ static VALUE
443
+ remove_namespaces_bang(VALUE self)
405
444
  {
406
445
  xmlDocPtr doc ;
407
446
  Data_Get_Struct(self, xmlDoc, doc);
@@ -421,7 +460,8 @@ VALUE remove_namespaces_bang(VALUE self)
421
460
  * +external_id+, +system_id+, and +content+ set the External ID, System ID,
422
461
  * and content respectively. All of these parameters are optional.
423
462
  */
424
- static VALUE create_entity(int argc, VALUE *argv, VALUE self)
463
+ static VALUE
464
+ create_entity(int argc, VALUE *argv, VALUE self)
425
465
  {
426
466
  VALUE name;
427
467
  VALUE type;
@@ -434,52 +474,50 @@ static VALUE create_entity(int argc, VALUE *argv, VALUE self)
434
474
  Data_Get_Struct(self, xmlDoc, doc);
435
475
 
436
476
  rb_scan_args(argc, argv, "14", &name, &type, &external_id, &system_id,
437
- &content);
477
+ &content);
438
478
 
439
479
  xmlResetLastError();
440
480
  ptr = xmlAddDocEntity(
441
- doc,
442
- (xmlChar *)(NIL_P(name) ? NULL : StringValueCStr(name)),
443
- (int) (NIL_P(type) ? XML_INTERNAL_GENERAL_ENTITY : NUM2INT(type)),
444
- (xmlChar *)(NIL_P(external_id) ? NULL : StringValueCStr(external_id)),
445
- (xmlChar *)(NIL_P(system_id) ? NULL : StringValueCStr(system_id)),
446
- (xmlChar *)(NIL_P(content) ? NULL : StringValueCStr(content))
447
- );
448
-
449
- if(NULL == ptr) {
481
+ doc,
482
+ (xmlChar *)(NIL_P(name) ? NULL : StringValueCStr(name)),
483
+ (int)(NIL_P(type) ? XML_INTERNAL_GENERAL_ENTITY : NUM2INT(type)),
484
+ (xmlChar *)(NIL_P(external_id) ? NULL : StringValueCStr(external_id)),
485
+ (xmlChar *)(NIL_P(system_id) ? NULL : StringValueCStr(system_id)),
486
+ (xmlChar *)(NIL_P(content) ? NULL : StringValueCStr(content))
487
+ );
488
+
489
+ if (NULL == ptr) {
450
490
  xmlErrorPtr error = xmlGetLastError();
451
- if(error)
491
+ if (error) {
452
492
  rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
453
- else
493
+ } else {
454
494
  rb_raise(rb_eRuntimeError, "Could not create entity");
495
+ }
455
496
 
456
497
  return Qnil;
457
498
  }
458
499
 
459
- return Nokogiri_wrap_xml_node(cNokogiriXmlEntityDecl, (xmlNodePtr)ptr);
500
+ return noko_xml_node_wrap(cNokogiriXmlEntityDecl, (xmlNodePtr)ptr);
460
501
  }
461
502
 
462
- static int block_caller(void * ctx, xmlNodePtr _node, xmlNodePtr _parent)
503
+ static int
504
+ block_caller(void *ctx, xmlNodePtr c_node, xmlNodePtr c_parent_node)
463
505
  {
464
- VALUE block;
465
- VALUE node;
466
- VALUE parent;
506
+ VALUE block = (VALUE)ctx;
507
+ VALUE rb_node;
508
+ VALUE rb_parent_node;
467
509
  VALUE ret;
468
510
 
469
- if(_node->type == XML_NAMESPACE_DECL){
470
- node = Nokogiri_wrap_xml_namespace(_parent->doc, (xmlNsPtr) _node);
511
+ if (c_node->type == XML_NAMESPACE_DECL) {
512
+ rb_node = noko_xml_namespace_wrap((xmlNsPtr)c_node, c_parent_node->doc);
513
+ } else {
514
+ rb_node = noko_xml_node_wrap(Qnil, c_node);
471
515
  }
472
- else{
473
- node = Nokogiri_wrap_xml_node(Qnil, _node);
474
- }
475
- parent = _parent ? Nokogiri_wrap_xml_node(Qnil, _parent) : Qnil;
476
- block = (VALUE)ctx;
477
-
478
- ret = rb_funcall(block, rb_intern("call"), 2, node, parent);
516
+ rb_parent_node = c_parent_node ? noko_xml_node_wrap(Qnil, c_parent_node) : Qnil;
479
517
 
480
- if(Qfalse == ret || Qnil == ret) return 0;
518
+ ret = rb_funcall(block, rb_intern("call"), 2, rb_node, rb_parent_node);
481
519
 
482
- return 1;
520
+ return (Qfalse == ret || Qnil == ret) ? 0 : 1;
483
521
  }
484
522
 
485
523
  /* call-seq:
@@ -492,117 +530,160 @@ static int block_caller(void * ctx, xmlNodePtr _node, xmlNodePtr _parent)
492
530
  * The block must return a non-nil, non-false value if the +obj+ passed in
493
531
  * should be included in the canonicalized document.
494
532
  */
495
- static VALUE canonicalize(int argc, VALUE* argv, VALUE self)
533
+ static VALUE
534
+ rb_xml_document_canonicalize(int argc, VALUE *argv, VALUE self)
496
535
  {
497
- VALUE mode;
498
- VALUE incl_ns;
499
- VALUE with_comments;
500
- xmlChar **ns;
501
- long ns_len, i;
536
+ VALUE rb_mode;
537
+ VALUE rb_namespaces;
538
+ VALUE rb_comments_p;
539
+ int c_mode = 0;
540
+ xmlChar **c_namespaces;
502
541
 
503
- xmlDocPtr doc;
504
- xmlOutputBufferPtr buf;
505
- xmlC14NIsVisibleCallback cb = NULL;
506
- void * ctx = NULL;
542
+ xmlDocPtr c_doc;
543
+ xmlOutputBufferPtr c_obuf;
544
+ xmlC14NIsVisibleCallback c_callback_wrapper = NULL;
545
+ void *rb_callback = NULL;
507
546
 
508
547
  VALUE rb_cStringIO;
509
- VALUE io;
548
+ VALUE rb_io;
510
549
 
511
- rb_scan_args(argc, argv, "03", &mode, &incl_ns, &with_comments);
550
+ rb_scan_args(argc, argv, "03", &rb_mode, &rb_namespaces, &rb_comments_p);
551
+ if (!NIL_P(rb_mode)) {
552
+ Check_Type(rb_mode, T_FIXNUM);
553
+ c_mode = NUM2INT(rb_mode);
554
+ }
555
+ if (!NIL_P(rb_namespaces)) {
556
+ Check_Type(rb_namespaces, T_ARRAY);
557
+ if (c_mode == XML_C14N_1_0 || c_mode == XML_C14N_1_1) {
558
+ rb_raise(rb_eRuntimeError, "This canonicalizer does not support this operation");
559
+ }
560
+ }
512
561
 
513
- Data_Get_Struct(self, xmlDoc, doc);
562
+ Data_Get_Struct(self, xmlDoc, c_doc);
514
563
 
515
564
  rb_cStringIO = rb_const_get_at(rb_cObject, rb_intern("StringIO"));
516
- io = rb_class_new_instance(0, 0, rb_cStringIO);
517
- buf = xmlAllocOutputBuffer(NULL);
565
+ rb_io = rb_class_new_instance(0, 0, rb_cStringIO);
566
+ c_obuf = xmlAllocOutputBuffer(NULL);
518
567
 
519
- buf->writecallback = (xmlOutputWriteCallback)io_write_callback;
520
- buf->closecallback = (xmlOutputCloseCallback)io_close_callback;
521
- buf->context = (void *)io;
568
+ c_obuf->writecallback = (xmlOutputWriteCallback)noko_io_write;
569
+ c_obuf->closecallback = (xmlOutputCloseCallback)noko_io_close;
570
+ c_obuf->context = (void *)rb_io;
522
571
 
523
- if(rb_block_given_p()) {
524
- cb = block_caller;
525
- ctx = (void *)rb_block_proc();
572
+ if (rb_block_given_p()) {
573
+ c_callback_wrapper = block_caller;
574
+ rb_callback = (void *)rb_block_proc();
526
575
  }
527
576
 
528
- if(NIL_P(incl_ns)){
529
- ns = NULL;
530
- }
531
- else{
532
- Check_Type(incl_ns, T_ARRAY);
533
- ns_len = RARRAY_LEN(incl_ns);
534
- ns = calloc((size_t)ns_len+1, sizeof(xmlChar *));
535
- for (i = 0 ; i < ns_len ; i++) {
536
- VALUE entry = rb_ary_entry(incl_ns, i);
537
- ns[i] = (xmlChar*)StringValueCStr(entry);
577
+ if (NIL_P(rb_namespaces)) {
578
+ c_namespaces = NULL;
579
+ } else {
580
+ long ns_len = RARRAY_LEN(rb_namespaces);
581
+ c_namespaces = ruby_xcalloc((size_t)ns_len + 1, sizeof(xmlChar *));
582
+ for (int j = 0 ; j < ns_len ; j++) {
583
+ VALUE entry = rb_ary_entry(rb_namespaces, j);
584
+ c_namespaces[j] = (xmlChar *)StringValueCStr(entry);
538
585
  }
539
586
  }
540
587
 
588
+ xmlC14NExecute(c_doc, c_callback_wrapper, rb_callback,
589
+ c_mode,
590
+ c_namespaces,
591
+ (int)RTEST(rb_comments_p),
592
+ c_obuf);
593
+
594
+ ruby_xfree(c_namespaces);
595
+ xmlOutputBufferClose(c_obuf);
596
+
597
+ return rb_funcall(rb_io, rb_intern("string"), 0);
598
+ }
599
+
600
+ VALUE
601
+ noko_xml_document_wrap_with_init_args(VALUE klass, xmlDocPtr c_document, int argc, VALUE *argv)
602
+ {
603
+ VALUE rb_document;
604
+ nokogiriTuplePtr tuple;
605
+
606
+ if (!klass) {
607
+ klass = cNokogiriXmlDocument;
608
+ }
609
+
610
+ rb_document = Data_Wrap_Struct(klass, mark, dealloc, c_document);
541
611
 
542
- xmlC14NExecute(doc, cb, ctx,
543
- (int) (NIL_P(mode) ? 0 : NUM2INT(mode)),
544
- ns,
545
- (int) RTEST(with_comments),
546
- buf);
612
+ tuple = (nokogiriTuplePtr)ruby_xmalloc(sizeof(nokogiriTuple));
613
+ tuple->doc = rb_document;
614
+ tuple->unlinkedNodes = st_init_numtable_with_size(128);
615
+ tuple->node_cache = rb_ary_new();
616
+
617
+ c_document->_private = tuple ;
547
618
 
548
- xmlOutputBufferClose(buf);
619
+ rb_iv_set(rb_document, "@decorators", Qnil);
620
+ rb_iv_set(rb_document, "@errors", Qnil);
621
+ rb_iv_set(rb_document, "@node_cache", tuple->node_cache);
549
622
 
550
- return rb_funcall(io, rb_intern("string"), 0);
623
+ rb_obj_call_init(rb_document, argc, argv);
624
+
625
+ return rb_document ;
551
626
  }
552
627
 
553
- VALUE cNokogiriXmlDocument ;
554
- void init_xml_document()
628
+
629
+ /* deprecated. use noko_xml_document_wrap() instead. */
630
+ VALUE
631
+ Nokogiri_wrap_xml_document(VALUE klass, xmlDocPtr doc)
555
632
  {
556
- VALUE nokogiri = rb_define_module("Nokogiri");
557
- VALUE xml = rb_define_module_under(nokogiri, "XML");
558
- VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
633
+ /* TODO: deprecate this method in v2.0 */
634
+ return noko_xml_document_wrap_with_init_args(klass, doc, 0, NULL);
635
+ }
559
636
 
560
- /*
561
- * Nokogiri::XML::Document wraps an xml document.
562
- */
563
- VALUE klass = rb_define_class_under(xml, "Document", node);
564
-
565
- cNokogiriXmlDocument = klass;
566
-
567
- rb_define_singleton_method(klass, "read_memory", read_memory, 4);
568
- rb_define_singleton_method(klass, "read_io", read_io, 4);
569
- rb_define_singleton_method(klass, "new", new, -1);
570
-
571
- rb_define_method(klass, "root", root, 0);
572
- rb_define_method(klass, "root=", set_root, 1);
573
- rb_define_method(klass, "encoding", encoding, 0);
574
- rb_define_method(klass, "encoding=", set_encoding, 1);
575
- rb_define_method(klass, "version", version, 0);
576
- rb_define_method(klass, "canonicalize", canonicalize, -1);
577
- rb_define_method(klass, "dup", duplicate_document, -1);
578
- rb_define_method(klass, "url", url, 0);
579
- rb_define_method(klass, "create_entity", create_entity, -1);
580
- rb_define_method(klass, "remove_namespaces!", remove_namespaces_bang, 0);
637
+ VALUE
638
+ noko_xml_document_wrap(VALUE klass, xmlDocPtr doc)
639
+ {
640
+ return noko_xml_document_wrap_with_init_args(klass, doc, 0, NULL);
581
641
  }
582
642
 
583
643
 
584
- /* this takes klass as a param because it's used for HtmlDocument, too. */
585
- VALUE Nokogiri_wrap_xml_document(VALUE klass, xmlDocPtr doc)
644
+ void
645
+ noko_xml_document_pin_node(xmlNodePtr node)
586
646
  {
587
- nokogiriTuplePtr tuple = (nokogiriTuplePtr)malloc(sizeof(nokogiriTuple));
647
+ xmlDocPtr doc;
648
+ nokogiriTuplePtr tuple;
588
649
 
589
- VALUE rb_doc = Data_Wrap_Struct(
590
- klass ? klass : cNokogiriXmlDocument,
591
- 0,
592
- dealloc,
593
- doc
594
- );
650
+ doc = node->doc;
651
+ tuple = (nokogiriTuplePtr)doc->_private;
652
+ st_insert(tuple->unlinkedNodes, (st_data_t)node, (st_data_t)node);
653
+ }
595
654
 
596
- VALUE cache = rb_ary_new();
597
- rb_iv_set(rb_doc, "@decorators", Qnil);
598
- rb_iv_set(rb_doc, "@node_cache", cache);
599
655
 
600
- tuple->doc = rb_doc;
601
- tuple->unlinkedNodes = st_init_numtable_with_size(128);
602
- tuple->node_cache = cache;
603
- doc->_private = tuple ;
656
+ void
657
+ noko_xml_document_pin_namespace(xmlNsPtr ns, xmlDocPtr doc)
658
+ {
659
+ nokogiriTuplePtr tuple;
660
+
661
+ tuple = (nokogiriTuplePtr)doc->_private;
662
+ st_insert(tuple->unlinkedNodes, (st_data_t)ns, (st_data_t)ns);
663
+ }
604
664
 
605
- rb_obj_call_init(rb_doc, 0, NULL);
606
665
 
607
- return rb_doc ;
666
+ void
667
+ noko_init_xml_document(void)
668
+ {
669
+ assert(cNokogiriXmlNode);
670
+ /*
671
+ * Nokogiri::XML::Document wraps an xml document.
672
+ */
673
+ cNokogiriXmlDocument = rb_define_class_under(mNokogiriXml, "Document", cNokogiriXmlNode);
674
+
675
+ rb_define_singleton_method(cNokogiriXmlDocument, "read_memory", read_memory, 4);
676
+ rb_define_singleton_method(cNokogiriXmlDocument, "read_io", read_io, 4);
677
+ rb_define_singleton_method(cNokogiriXmlDocument, "new", new, -1);
678
+
679
+ rb_define_method(cNokogiriXmlDocument, "root", rb_xml_document_root, 0);
680
+ rb_define_method(cNokogiriXmlDocument, "root=", rb_xml_document_root_set, 1);
681
+ rb_define_method(cNokogiriXmlDocument, "encoding", encoding, 0);
682
+ rb_define_method(cNokogiriXmlDocument, "encoding=", set_encoding, 1);
683
+ rb_define_method(cNokogiriXmlDocument, "version", version, 0);
684
+ rb_define_method(cNokogiriXmlDocument, "canonicalize", rb_xml_document_canonicalize, -1);
685
+ rb_define_method(cNokogiriXmlDocument, "dup", duplicate_document, -1);
686
+ rb_define_method(cNokogiriXmlDocument, "url", url, 0);
687
+ rb_define_method(cNokogiriXmlDocument, "create_entity", create_entity, -1);
688
+ rb_define_method(cNokogiriXmlDocument, "remove_namespaces!", remove_namespaces_bang, 0);
608
689
  }