nokogiri 1.14.3 → 1.15.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +9 -8
  3. data/dependencies.yml +7 -6
  4. data/ext/nokogiri/extconf.rb +66 -22
  5. data/ext/nokogiri/html4_document.c +1 -2
  6. data/ext/nokogiri/html4_element_description.c +19 -14
  7. data/ext/nokogiri/html4_sax_parser_context.c +10 -16
  8. data/ext/nokogiri/html4_sax_push_parser.c +2 -2
  9. data/ext/nokogiri/nokogiri.c +46 -24
  10. data/ext/nokogiri/nokogiri.h +13 -2
  11. data/ext/nokogiri/xml_attr.c +1 -1
  12. data/ext/nokogiri/xml_cdata.c +31 -17
  13. data/ext/nokogiri/xml_comment.c +1 -1
  14. data/ext/nokogiri/xml_document.c +106 -22
  15. data/ext/nokogiri/xml_document_fragment.c +1 -1
  16. data/ext/nokogiri/xml_dtd.c +1 -1
  17. data/ext/nokogiri/xml_element_content.c +32 -29
  18. data/ext/nokogiri/xml_element_decl.c +5 -5
  19. data/ext/nokogiri/xml_encoding_handler.c +12 -4
  20. data/ext/nokogiri/xml_entity_reference.c +1 -1
  21. data/ext/nokogiri/xml_namespace.c +11 -12
  22. data/ext/nokogiri/xml_node.c +8 -8
  23. data/ext/nokogiri/xml_node_set.c +125 -105
  24. data/ext/nokogiri/xml_processing_instruction.c +1 -1
  25. data/ext/nokogiri/xml_reader.c +37 -28
  26. data/ext/nokogiri/xml_relax_ng.c +65 -78
  27. data/ext/nokogiri/xml_sax_parser.c +24 -5
  28. data/ext/nokogiri/xml_sax_parser_context.c +46 -25
  29. data/ext/nokogiri/xml_sax_push_parser.c +29 -8
  30. data/ext/nokogiri/xml_schema.c +94 -114
  31. data/ext/nokogiri/xml_text.c +27 -13
  32. data/ext/nokogiri/xml_xpath_context.c +156 -83
  33. data/ext/nokogiri/xslt_stylesheet.c +103 -50
  34. data/gumbo-parser/src/error.c +8 -4
  35. data/gumbo-parser/src/foreign_attrs.c +13 -14
  36. data/gumbo-parser/src/foreign_attrs.gperf +1 -1
  37. data/gumbo-parser/src/parser.c +13 -0
  38. data/lib/nokogiri/css/xpath_visitor.rb +2 -2
  39. data/lib/nokogiri/extension.rb +1 -1
  40. data/lib/nokogiri/html4/document_fragment.rb +1 -1
  41. data/lib/nokogiri/html4/element_description_defaults.rb +1821 -353
  42. data/lib/nokogiri/html5/document_fragment.rb +1 -1
  43. data/lib/nokogiri/html5/node.rb +5 -0
  44. data/lib/nokogiri/html5.rb +5 -2
  45. data/lib/nokogiri/jruby/nokogiri_jars.rb +9 -9
  46. data/lib/nokogiri/version/constant.rb +1 -1
  47. data/lib/nokogiri/xml/attribute_decl.rb +4 -2
  48. data/lib/nokogiri/xml/document.rb +1 -2
  49. data/lib/nokogiri/xml/document_fragment.rb +1 -1
  50. data/lib/nokogiri/xml/element_content.rb +10 -2
  51. data/lib/nokogiri/xml/element_decl.rb +4 -2
  52. data/lib/nokogiri/xml/entity_decl.rb +4 -2
  53. data/lib/nokogiri/xml/node/save_options.rb +8 -0
  54. data/lib/nokogiri/xml/node.rb +22 -13
  55. data/lib/nokogiri/xml/pp/node.rb +23 -12
  56. data/lib/nokogiri/xml/sax/document.rb +1 -1
  57. data/lib/nokogiri/xml/searchable.rb +18 -10
  58. data/lib/nokogiri/xslt.rb +73 -3
  59. data/lib/nokogiri.rb +12 -4
  60. data/lib/xsd/xmlparser/nokogiri.rb +1 -1
  61. data/patches/libxml2/0010-update-config.guess-and-config.sub-for-libxml2.patch +224 -0
  62. data/patches/libxml2/0011-rip-out-libxml2-s-libc_single_threaded-support.patch +30 -0
  63. data/patches/libxslt/0001-update-config.guess-and-config.sub-for-libxslt.patch +224 -0
  64. data/ports/archives/libxml2-2.11.6.tar.xz +0 -0
  65. data/ports/archives/libxslt-1.1.39.tar.xz +0 -0
  66. metadata +10 -8
  67. data/patches/libxslt/0001-update-automake-files-for-arm64.patch +0 -3037
  68. data/ports/archives/libxml2-2.10.4.tar.xz +0 -0
  69. data/ports/archives/libxslt-1.1.37.tar.xz +0 -0
@@ -51,8 +51,9 @@ remove_private(xmlNodePtr node)
51
51
  }
52
52
 
53
53
  static void
54
- mark(xmlDocPtr doc)
54
+ mark(void *data)
55
55
  {
56
+ xmlDocPtr doc = (xmlDocPtr)data;
56
57
  nokogiriTuplePtr tuple = (nokogiriTuplePtr)doc->_private;
57
58
  if (tuple) {
58
59
  rb_gc_mark(tuple->doc);
@@ -61,8 +62,9 @@ mark(xmlDocPtr doc)
61
62
  }
62
63
 
63
64
  static void
64
- dealloc(xmlDocPtr doc)
65
+ dealloc(void *data)
65
66
  {
67
+ xmlDocPtr doc = (xmlDocPtr)data;
66
68
  st_table *node_hash;
67
69
 
68
70
  node_hash = DOC_UNLINKED_NODE_HASH(doc);
@@ -72,18 +74,71 @@ dealloc(xmlDocPtr doc)
72
74
 
73
75
  ruby_xfree(doc->_private);
74
76
 
75
- /* When both Nokogiri and libxml-ruby are loaded, make sure that all nodes
76
- * have their _private pointers cleared. This is to avoid libxml-ruby's
77
- * xmlDeregisterNode callback from accessing VALUE pointers from ruby's GC
78
- * free context, which can result in segfaults.
77
+ #pragma GCC diagnostic push
78
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations" // xmlDeregisterNodeDefault is deprecated as of libxml2 2.11.0
79
+ /*
80
+ * libxml-ruby < 3.0.0 uses xmlDeregisterNodeDefault. If the user is using one of those older
81
+ * versions, the registered callback from libxml-ruby will access the _private pointers set by
82
+ * nokogiri, which will result in segfaults.
83
+ *
84
+ * To avoid this, we need to clear the _private pointers from all nodes in this document tree
85
+ * before that callback gets invoked.
86
+ *
87
+ * libxml-ruby 3.0.0 was released in 2017-02, so at some point we can probably safely remove this
88
+ * safeguard (though probably pairing with a runtime check on the libxml-ruby version).
79
89
  */
80
90
  if (xmlDeregisterNodeDefaultValue) {
81
91
  remove_private((xmlNodePtr)doc);
82
92
  }
93
+ #pragma GCC diagnostic pop
83
94
 
84
95
  xmlFreeDoc(doc);
85
96
  }
86
97
 
98
+ static size_t
99
+ memsize_node(const xmlNodePtr node)
100
+ {
101
+ /* note we don't count namespace definitions, just going for a good-enough number here */
102
+ xmlNodePtr child;
103
+ xmlAttrPtr property;
104
+ size_t memsize = 0;
105
+
106
+ memsize += xmlStrlen(node->name);
107
+
108
+ if (node->type == XML_ELEMENT_NODE) {
109
+ for (property = node->properties; property; property = property->next) {
110
+ memsize += sizeof(xmlAttr) + memsize_node((xmlNodePtr)property);
111
+ }
112
+ }
113
+ if (node->type == XML_TEXT_NODE) {
114
+ memsize += xmlStrlen(node->content);
115
+ }
116
+ for (child = node->children; child; child = child->next) {
117
+ memsize += sizeof(xmlNode) + memsize_node(child);
118
+ }
119
+ return memsize;
120
+ }
121
+
122
+ static size_t
123
+ memsize(const void *data)
124
+ {
125
+ xmlDocPtr doc = (const xmlDocPtr)data;
126
+ size_t memsize = sizeof(xmlDoc);
127
+ /* This may not account for all memory use */
128
+ memsize += memsize_node((xmlNodePtr)doc);
129
+ return memsize;
130
+ }
131
+
132
+ static const rb_data_type_t noko_xml_document_data_type = {
133
+ .wrap_struct_name = "Nokogiri::XML::Document",
134
+ .function = {
135
+ .dmark = mark,
136
+ .dfree = dealloc,
137
+ .dsize = memsize,
138
+ },
139
+ // .flags = RUBY_TYPED_FREE_IMMEDIATELY, // TODO see https://github.com/sparklemotion/nokogiri/issues/2822
140
+ };
141
+
87
142
  static void
88
143
  recursively_remove_namespaces_from_node(xmlNodePtr node)
89
144
  {
@@ -126,8 +181,7 @@ recursively_remove_namespaces_from_node(xmlNodePtr node)
126
181
  static VALUE
127
182
  url(VALUE self)
128
183
  {
129
- xmlDocPtr doc;
130
- Data_Get_Struct(self, xmlDoc, doc);
184
+ xmlDocPtr doc = noko_xml_document_unwrap(self);
131
185
 
132
186
  if (doc->URL) { return NOKOGIRI_STR_NEW2(doc->URL); }
133
187
 
@@ -146,7 +200,7 @@ rb_xml_document_root_set(VALUE self, VALUE rb_new_root)
146
200
  xmlDocPtr c_document;
147
201
  xmlNodePtr c_new_root = NULL, c_current_root;
148
202
 
149
- Data_Get_Struct(self, xmlDoc, c_document);
203
+ c_document = noko_xml_document_unwrap(self);
150
204
 
151
205
  c_current_root = xmlDocGetRootElement(c_document);
152
206
  if (c_current_root) {
@@ -190,7 +244,7 @@ rb_xml_document_root(VALUE self)
190
244
  xmlDocPtr c_document;
191
245
  xmlNodePtr c_root;
192
246
 
193
- Data_Get_Struct(self, xmlDoc, c_document);
247
+ c_document = noko_xml_document_unwrap(self);
194
248
 
195
249
  c_root = xmlDocGetRootElement(c_document);
196
250
  if (!c_root) {
@@ -209,8 +263,7 @@ rb_xml_document_root(VALUE self)
209
263
  static VALUE
210
264
  set_encoding(VALUE self, VALUE encoding)
211
265
  {
212
- xmlDocPtr doc;
213
- Data_Get_Struct(self, xmlDoc, doc);
266
+ xmlDocPtr doc = noko_xml_document_unwrap(self);
214
267
 
215
268
  if (doc->encoding) {
216
269
  xmlFree(DISCARD_CONST_QUAL_XMLCHAR(doc->encoding));
@@ -230,8 +283,7 @@ set_encoding(VALUE self, VALUE encoding)
230
283
  static VALUE
231
284
  encoding(VALUE self)
232
285
  {
233
- xmlDocPtr doc;
234
- Data_Get_Struct(self, xmlDoc, doc);
286
+ xmlDocPtr doc = noko_xml_document_unwrap(self);
235
287
 
236
288
  if (!doc->encoding) { return Qnil; }
237
289
  return NOKOGIRI_STR_NEW2(doc->encoding);
@@ -246,8 +298,7 @@ encoding(VALUE self)
246
298
  static VALUE
247
299
  version(VALUE self)
248
300
  {
249
- xmlDocPtr doc;
250
- Data_Get_Struct(self, xmlDoc, doc);
301
+ xmlDocPtr doc = noko_xml_document_unwrap(self);
251
302
 
252
303
  if (!doc->version) { return Qnil; }
253
304
  return NOKOGIRI_STR_NEW2(doc->version);
@@ -369,7 +420,7 @@ duplicate_document(int argc, VALUE *argv, VALUE self)
369
420
  level = INT2NUM((long)1);
370
421
  }
371
422
 
372
- Data_Get_Struct(self, xmlDoc, doc);
423
+ doc = noko_xml_document_unwrap(self);
373
424
 
374
425
  dup = xmlCopyDoc(doc, (int)NUM2INT(level));
375
426
 
@@ -442,8 +493,7 @@ new (int argc, VALUE *argv, VALUE klass)
442
493
  static VALUE
443
494
  remove_namespaces_bang(VALUE self)
444
495
  {
445
- xmlDocPtr doc ;
446
- Data_Get_Struct(self, xmlDoc, doc);
496
+ xmlDocPtr doc = noko_xml_document_unwrap(self);
447
497
 
448
498
  recursively_remove_namespaces_from_node((xmlNodePtr)doc);
449
499
  return self;
@@ -471,7 +521,7 @@ create_entity(int argc, VALUE *argv, VALUE self)
471
521
  xmlEntityPtr ptr;
472
522
  xmlDocPtr doc ;
473
523
 
474
- Data_Get_Struct(self, xmlDoc, doc);
524
+ doc = noko_xml_document_unwrap(self);
475
525
 
476
526
  rb_scan_args(argc, argv, "14", &name, &type, &external_id, &system_id,
477
527
  &content);
@@ -559,7 +609,7 @@ rb_xml_document_canonicalize(int argc, VALUE *argv, VALUE self)
559
609
  }
560
610
  }
561
611
 
562
- Data_Get_Struct(self, xmlDoc, c_doc);
612
+ c_doc = noko_xml_document_unwrap(self);
563
613
 
564
614
  rb_cStringIO = rb_const_get_at(rb_cObject, rb_intern("StringIO"));
565
615
  rb_io = rb_class_new_instance(0, 0, rb_cStringIO);
@@ -607,7 +657,7 @@ noko_xml_document_wrap_with_init_args(VALUE klass, xmlDocPtr c_document, int arg
607
657
  klass = cNokogiriXmlDocument;
608
658
  }
609
659
 
610
- rb_document = Data_Wrap_Struct(klass, mark, dealloc, c_document);
660
+ rb_document = TypedData_Wrap_Struct(klass, &noko_xml_document_data_type, c_document);
611
661
 
612
662
  tuple = (nokogiriTuplePtr)ruby_xmalloc(sizeof(nokogiriTuple));
613
663
  tuple->doc = rb_document;
@@ -640,6 +690,40 @@ noko_xml_document_wrap(VALUE klass, xmlDocPtr doc)
640
690
  return noko_xml_document_wrap_with_init_args(klass, doc, 0, NULL);
641
691
  }
642
692
 
693
+ xmlDocPtr
694
+ noko_xml_document_unwrap(VALUE rb_document)
695
+ {
696
+ xmlDocPtr c_document;
697
+ TypedData_Get_Struct(rb_document, xmlDoc, &noko_xml_document_data_type, c_document);
698
+ return c_document;
699
+ }
700
+
701
+ /* Schema creation will remove and deallocate "blank" nodes.
702
+ * If those blank nodes have been exposed to Ruby, they could get freed
703
+ * out from under the VALUE pointer. This function checks to see if any of
704
+ * those nodes have been exposed to Ruby, and if so we should raise an exception.
705
+ */
706
+ int
707
+ noko_xml_document_has_wrapped_blank_nodes_p(xmlDocPtr c_document)
708
+ {
709
+ VALUE cache = DOC_NODE_CACHE(c_document);
710
+
711
+ if (NIL_P(cache)) {
712
+ return 0;
713
+ }
714
+
715
+ for (long jnode = 0; jnode < RARRAY_LEN(cache); jnode++) {
716
+ xmlNodePtr node;
717
+ VALUE element = rb_ary_entry(cache, jnode);
718
+
719
+ Noko_Node_Get_Struct(element, xmlNode, node);
720
+ if (xmlIsBlankNode(node)) {
721
+ return 1;
722
+ }
723
+ }
724
+
725
+ return 0;
726
+ }
643
727
 
644
728
  void
645
729
  noko_xml_document_pin_node(xmlNodePtr node)
@@ -19,7 +19,7 @@ new (int argc, VALUE *argv, VALUE klass)
19
19
 
20
20
  rb_scan_args(argc, argv, "1*", &document, &rest);
21
21
 
22
- Data_Get_Struct(document, xmlDoc, xml_doc);
22
+ xml_doc = noko_xml_document_unwrap(document);
23
23
 
24
24
  node = xmlNewDocFragment(xml_doc->doc);
25
25
 
@@ -139,7 +139,7 @@ validate(VALUE self, VALUE document)
139
139
  VALUE error_list;
140
140
 
141
141
  Noko_Node_Get_Struct(self, xmlDtd, dtd);
142
- Noko_Node_Get_Struct(document, xmlDoc, doc);
142
+ doc = noko_xml_document_unwrap(document);
143
143
  error_list = rb_ary_new();
144
144
 
145
145
  ctxt = xmlNewValidCtxt();
@@ -2,17 +2,22 @@
2
2
 
3
3
  VALUE cNokogiriXmlElementContent;
4
4
 
5
+ static const rb_data_type_t element_content_data_type = {
6
+ .wrap_struct_name = "Nokogiri::XML::ElementContent",
7
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
8
+ };
9
+
5
10
  /*
6
11
  * call-seq:
7
- * name
12
+ * name → String
8
13
  *
9
- * Get the require element +name+
14
+ * [Returns] The content element's +name+
10
15
  */
11
16
  static VALUE
12
17
  get_name(VALUE self)
13
18
  {
14
19
  xmlElementContentPtr elem;
15
- Data_Get_Struct(self, xmlElementContent, elem);
20
+ TypedData_Get_Struct(self, xmlElementContent, &element_content_data_type, elem);
16
21
 
17
22
  if (!elem->name) { return Qnil; }
18
23
  return NOKOGIRI_STR_NEW2(elem->name);
@@ -20,47 +25,40 @@ get_name(VALUE self)
20
25
 
21
26
  /*
22
27
  * call-seq:
23
- * type
28
+ * type → Integer
24
29
  *
25
- * Get the element content +type+. Possible values are PCDATA, ELEMENT, SEQ,
26
- * or OR.
30
+ * [Returns] The content element's +type+. Possible values are +PCDATA+, +ELEMENT+, +SEQ+, or +OR+.
27
31
  */
28
32
  static VALUE
29
33
  get_type(VALUE self)
30
34
  {
31
35
  xmlElementContentPtr elem;
32
- Data_Get_Struct(self, xmlElementContent, elem);
36
+ TypedData_Get_Struct(self, xmlElementContent, &element_content_data_type, elem);
33
37
 
34
38
  return INT2NUM(elem->type);
35
39
  }
36
40
 
37
41
  /*
38
- * call-seq:
39
- * c1
40
- *
41
42
  * Get the first child.
42
43
  */
43
44
  static VALUE
44
45
  get_c1(VALUE self)
45
46
  {
46
47
  xmlElementContentPtr elem;
47
- Data_Get_Struct(self, xmlElementContent, elem);
48
+ TypedData_Get_Struct(self, xmlElementContent, &element_content_data_type, elem);
48
49
 
49
50
  if (!elem->c1) { return Qnil; }
50
51
  return noko_xml_element_content_wrap(rb_iv_get(self, "@document"), elem->c1);
51
52
  }
52
53
 
53
54
  /*
54
- * call-seq:
55
- * c2
56
- *
57
- * Get the first child.
55
+ * Get the second child.
58
56
  */
59
57
  static VALUE
60
58
  get_c2(VALUE self)
61
59
  {
62
60
  xmlElementContentPtr elem;
63
- Data_Get_Struct(self, xmlElementContent, elem);
61
+ TypedData_Get_Struct(self, xmlElementContent, &element_content_data_type, elem);
64
62
 
65
63
  if (!elem->c2) { return Qnil; }
66
64
  return noko_xml_element_content_wrap(rb_iv_get(self, "@document"), elem->c2);
@@ -68,45 +66,50 @@ get_c2(VALUE self)
68
66
 
69
67
  /*
70
68
  * call-seq:
71
- * occur
69
+ * occur → Integer
72
70
  *
73
- * Get the element content +occur+ flag. Possible values are ONCE, OPT, MULT
74
- * or PLUS.
71
+ * [Returns] The content element's +occur+ flag. Possible values are +ONCE+, +OPT+, +MULT+ or +PLUS+.
75
72
  */
76
73
  static VALUE
77
74
  get_occur(VALUE self)
78
75
  {
79
76
  xmlElementContentPtr elem;
80
- Data_Get_Struct(self, xmlElementContent, elem);
77
+ TypedData_Get_Struct(self, xmlElementContent, &element_content_data_type, elem);
81
78
 
82
79
  return INT2NUM(elem->ocur);
83
80
  }
84
81
 
85
82
  /*
86
83
  * call-seq:
87
- * prefix
84
+ * prefix → String
88
85
  *
89
- * Get the element content namespace +prefix+.
86
+ * [Returns] The content element's namespace +prefix+.
90
87
  */
91
88
  static VALUE
92
89
  get_prefix(VALUE self)
93
90
  {
94
91
  xmlElementContentPtr elem;
95
- Data_Get_Struct(self, xmlElementContent, elem);
92
+ TypedData_Get_Struct(self, xmlElementContent, &element_content_data_type, elem);
96
93
 
97
94
  if (!elem->prefix) { return Qnil; }
98
95
 
99
96
  return NOKOGIRI_STR_NEW2(elem->prefix);
100
97
  }
101
98
 
99
+ /*
100
+ * create a Nokogiri::XML::ElementContent object around an +element+.
101
+ */
102
102
  VALUE
103
- noko_xml_element_content_wrap(VALUE doc, xmlElementContentPtr element)
103
+ noko_xml_element_content_wrap(VALUE rb_document, xmlElementContentPtr c_element_content)
104
104
  {
105
- VALUE elem = Data_Wrap_Struct(cNokogiriXmlElementContent, 0, 0, element);
106
-
107
- /* Setting the document is necessary so that this does not get GC'd until */
108
- /* the document is GC'd */
109
- rb_iv_set(elem, "@document", doc);
105
+ VALUE elem = TypedData_Wrap_Struct(
106
+ cNokogiriXmlElementContent,
107
+ &element_content_data_type,
108
+ c_element_content
109
+ );
110
+
111
+ /* keep a handle on the document for GC marking */
112
+ rb_iv_set(elem, "@document", rb_document);
110
113
 
111
114
  return elem;
112
115
  }
@@ -6,7 +6,7 @@ static ID id_document;
6
6
 
7
7
  /*
8
8
  * call-seq:
9
- * element_type
9
+ * element_type → Integer
10
10
  *
11
11
  * The element_type
12
12
  */
@@ -20,9 +20,9 @@ element_type(VALUE self)
20
20
 
21
21
  /*
22
22
  * call-seq:
23
- * content
23
+ * content → Nokogiri::XML::ElementContent
24
24
  *
25
- * The allowed content for this ElementDecl
25
+ * [Returns] The root of this element declaration's content tree.
26
26
  */
27
27
  static VALUE
28
28
  content(VALUE self)
@@ -40,9 +40,9 @@ content(VALUE self)
40
40
 
41
41
  /*
42
42
  * call-seq:
43
- * prefix
43
+ * prefix → String
44
44
  *
45
- * The namespace prefix for this ElementDecl
45
+ * [Returns] The namespace +prefix+ for this element declaration.
46
46
  */
47
47
  static VALUE
48
48
  prefix(VALUE self)
@@ -2,14 +2,22 @@
2
2
 
3
3
  VALUE cNokogiriEncodingHandler;
4
4
 
5
-
6
5
  static void
7
- _xml_encoding_handler_dealloc(xmlCharEncodingHandlerPtr c_handler)
6
+ xml_encoding_handler_dealloc(void *data)
8
7
  {
9
8
  /* make sure iconv handlers are cleaned up and freed */
9
+ xmlCharEncodingHandlerPtr c_handler = data;
10
10
  xmlCharEncCloseFunc(c_handler);
11
11
  }
12
12
 
13
+ static const rb_data_type_t xml_encoding_handler_type = {
14
+ .wrap_struct_name = "Nokogiri::EncodingHandler",
15
+ .function = {
16
+ .dfree = xml_encoding_handler_dealloc,
17
+ },
18
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
19
+ };
20
+
13
21
 
14
22
  /*
15
23
  * call-seq: Nokogiri::EncodingHandler.[](name)
@@ -23,7 +31,7 @@ rb_xml_encoding_handler_s_get(VALUE klass, VALUE key)
23
31
 
24
32
  handler = xmlFindCharEncodingHandler(StringValueCStr(key));
25
33
  if (handler) {
26
- return Data_Wrap_Struct(klass, NULL, _xml_encoding_handler_dealloc, handler);
34
+ return TypedData_Wrap_Struct(klass, &xml_encoding_handler_type, handler);
27
35
  }
28
36
 
29
37
  return Qnil;
@@ -82,7 +90,7 @@ rb_xml_encoding_handler_name(VALUE self)
82
90
  {
83
91
  xmlCharEncodingHandlerPtr handler;
84
92
 
85
- Data_Get_Struct(self, xmlCharEncodingHandler, handler);
93
+ TypedData_Get_Struct(self, xmlCharEncodingHandler, &xml_encoding_handler_type, handler);
86
94
 
87
95
  return NOKOGIRI_STR_NEW2(handler->name);
88
96
  }
@@ -20,7 +20,7 @@ new (int argc, VALUE *argv, VALUE klass)
20
20
 
21
21
  rb_scan_args(argc, argv, "2*", &document, &name, &rest);
22
22
 
23
- Data_Get_Struct(document, xmlDoc, xml_doc);
23
+ xml_doc = noko_xml_document_unwrap(document);
24
24
 
25
25
  node = xmlNewReference(
26
26
  xml_doc,
@@ -56,21 +56,20 @@ _xml_namespace_update_references(void *ptr)
56
56
  #endif
57
57
 
58
58
  static const rb_data_type_t nokogiri_xml_namespace_type_with_dealloc = {
59
- "Nokogiri/XMLNamespace/WithDealloc",
60
- {0, _xml_namespace_dealloc, 0, _xml_namespace_update_references},
61
- 0, 0,
62
- #ifdef RUBY_TYPED_FREE_IMMEDIATELY
63
- RUBY_TYPED_FREE_IMMEDIATELY,
64
- #endif
59
+ .wrap_struct_name = "Nokogiri::XML::Namespace#with_dealloc",
60
+ .function = {
61
+ .dfree = _xml_namespace_dealloc,
62
+ .dcompact = _xml_namespace_update_references,
63
+ },
64
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
65
65
  };
66
66
 
67
67
  static const rb_data_type_t nokogiri_xml_namespace_type_without_dealloc = {
68
- "Nokogiri/XMLNamespace/WithoutDealloc",
69
- {0, 0, 0, _xml_namespace_update_references},
70
- 0, 0,
71
- #ifdef RUBY_TYPED_FREE_IMMEDIATELY
72
- RUBY_TYPED_FREE_IMMEDIATELY,
73
- #endif
68
+ .wrap_struct_name = "Nokogiri::XML::Namespace#without_dealloc",
69
+ .function = {
70
+ .dcompact = _xml_namespace_update_references,
71
+ },
72
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
74
73
  };
75
74
 
76
75
  /*
@@ -43,12 +43,12 @@ _xml_node_update_references(void *ptr)
43
43
  #endif
44
44
 
45
45
  static const rb_data_type_t nokogiri_node_type = {
46
- "Nokogiri/XMLNode",
47
- {_xml_node_mark, 0, 0, _xml_node_update_references},
48
- 0, 0,
49
- #ifdef RUBY_TYPED_FREE_IMMEDIATELY
50
- RUBY_TYPED_FREE_IMMEDIATELY,
51
- #endif
46
+ .wrap_struct_name = "Nokogiri::XML::Node",
47
+ .function = {
48
+ .dmark = _xml_node_mark,
49
+ .dcompact = _xml_node_update_references,
50
+ },
51
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
52
52
  };
53
53
 
54
54
  static void
@@ -350,7 +350,7 @@ ok:
350
350
 
351
351
  xmlUnlinkNode(original_reparentee);
352
352
 
353
- if (prf != xmlAddPrevSibling && prf != xmlAddNextSibling
353
+ if (prf != xmlAddPrevSibling && prf != xmlAddNextSibling && prf != xmlAddChild
354
354
  && reparentee->type == XML_TEXT_NODE && pivot->next && pivot->next->type == XML_TEXT_NODE) {
355
355
  /*
356
356
  * libxml merges text nodes in a right-to-left fashion, meaning that if
@@ -984,7 +984,7 @@ duplicate_node(int argc, VALUE *argv, VALUE self)
984
984
  if (n_args < 2) {
985
985
  new_parent_doc = node->doc;
986
986
  } else {
987
- Data_Get_Struct(r_new_parent_doc, xmlDoc, new_parent_doc);
987
+ new_parent_doc = noko_xml_document_unwrap(r_new_parent_doc);
988
988
  }
989
989
 
990
990
  dup = xmlDocCopyNode(node, new_parent_doc, level);