nokogiri 1.13.6 → 1.16.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +43 -0
  3. data/LICENSE-DEPENDENCIES.md +830 -509
  4. data/LICENSE.md +1 -1
  5. data/README.md +21 -11
  6. data/dependencies.yml +34 -15
  7. data/ext/nokogiri/extconf.rb +167 -48
  8. data/ext/nokogiri/gumbo.c +21 -11
  9. data/ext/nokogiri/html4_document.c +3 -4
  10. data/ext/nokogiri/html4_element_description.c +20 -15
  11. data/ext/nokogiri/html4_entity_lookup.c +2 -2
  12. data/ext/nokogiri/html4_sax_parser_context.c +11 -22
  13. data/ext/nokogiri/html4_sax_push_parser.c +4 -4
  14. data/ext/nokogiri/nokogiri.c +84 -75
  15. data/ext/nokogiri/nokogiri.h +46 -16
  16. data/ext/nokogiri/test_global_handlers.c +2 -2
  17. data/ext/nokogiri/xml_attr.c +3 -3
  18. data/ext/nokogiri/xml_attribute_decl.c +5 -5
  19. data/ext/nokogiri/xml_cdata.c +31 -18
  20. data/ext/nokogiri/xml_comment.c +2 -2
  21. data/ext/nokogiri/xml_document.c +135 -38
  22. data/ext/nokogiri/xml_document_fragment.c +2 -2
  23. data/ext/nokogiri/xml_dtd.c +9 -9
  24. data/ext/nokogiri/xml_element_content.c +34 -31
  25. data/ext/nokogiri/xml_element_decl.c +10 -10
  26. data/ext/nokogiri/xml_encoding_handler.c +15 -7
  27. data/ext/nokogiri/xml_entity_decl.c +6 -6
  28. data/ext/nokogiri/xml_entity_reference.c +2 -2
  29. data/ext/nokogiri/xml_namespace.c +75 -14
  30. data/ext/nokogiri/xml_node.c +365 -87
  31. data/ext/nokogiri/xml_node_set.c +129 -111
  32. data/ext/nokogiri/xml_processing_instruction.c +2 -2
  33. data/ext/nokogiri/xml_reader.c +126 -64
  34. data/ext/nokogiri/xml_relax_ng.c +67 -82
  35. data/ext/nokogiri/xml_sax_parser.c +45 -20
  36. data/ext/nokogiri/xml_sax_parser_context.c +50 -30
  37. data/ext/nokogiri/xml_sax_push_parser.c +31 -12
  38. data/ext/nokogiri/xml_schema.c +95 -118
  39. data/ext/nokogiri/xml_syntax_error.c +4 -4
  40. data/ext/nokogiri/xml_text.c +27 -14
  41. data/ext/nokogiri/xml_xpath_context.c +213 -136
  42. data/ext/nokogiri/xslt_stylesheet.c +126 -67
  43. data/gumbo-parser/Makefile +28 -0
  44. data/gumbo-parser/src/attribute.h +1 -1
  45. data/gumbo-parser/src/error.c +10 -6
  46. data/gumbo-parser/src/error.h +1 -1
  47. data/gumbo-parser/src/foreign_attrs.c +15 -16
  48. data/gumbo-parser/src/foreign_attrs.gperf +1 -1
  49. data/gumbo-parser/src/{gumbo.h → nokogiri_gumbo.h} +1 -0
  50. data/gumbo-parser/src/parser.c +29 -10
  51. data/gumbo-parser/src/replacement.h +1 -1
  52. data/gumbo-parser/src/string_buffer.h +1 -1
  53. data/gumbo-parser/src/string_piece.c +1 -1
  54. data/gumbo-parser/src/svg_attrs.c +2 -2
  55. data/gumbo-parser/src/svg_tags.c +2 -2
  56. data/gumbo-parser/src/tag.c +2 -1
  57. data/gumbo-parser/src/tag_lookup.c +7 -7
  58. data/gumbo-parser/src/tag_lookup.gperf +1 -0
  59. data/gumbo-parser/src/tag_lookup.h +1 -1
  60. data/gumbo-parser/src/token_buffer.h +1 -1
  61. data/gumbo-parser/src/tokenizer.c +2 -1
  62. data/gumbo-parser/src/tokenizer.h +1 -1
  63. data/gumbo-parser/src/utf8.c +1 -1
  64. data/gumbo-parser/src/utf8.h +1 -1
  65. data/gumbo-parser/src/util.c +1 -3
  66. data/gumbo-parser/src/util.h +4 -0
  67. data/gumbo-parser/src/vector.h +1 -1
  68. data/lib/nokogiri/css/node.rb +2 -2
  69. data/lib/nokogiri/css/parser_extras.rb +1 -1
  70. data/lib/nokogiri/css/xpath_visitor.rb +8 -26
  71. data/lib/nokogiri/css.rb +6 -0
  72. data/lib/nokogiri/decorators/slop.rb +1 -1
  73. data/lib/nokogiri/encoding_handler.rb +57 -0
  74. data/lib/nokogiri/extension.rb +4 -3
  75. data/lib/nokogiri/html4/document.rb +3 -122
  76. data/lib/nokogiri/html4/document_fragment.rb +1 -1
  77. data/lib/nokogiri/html4/element_description_defaults.rb +1827 -365
  78. data/lib/nokogiri/html4/encoding_reader.rb +121 -0
  79. data/lib/nokogiri/html4.rb +1 -0
  80. data/lib/nokogiri/html5/document.rb +113 -36
  81. data/lib/nokogiri/html5/document_fragment.rb +10 -3
  82. data/lib/nokogiri/html5/node.rb +8 -5
  83. data/lib/nokogiri/html5.rb +74 -226
  84. data/lib/nokogiri/jruby/dependencies.rb +1 -19
  85. data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
  86. data/lib/nokogiri/version/constant.rb +1 -1
  87. data/lib/nokogiri/version/info.rb +16 -14
  88. data/lib/nokogiri/xml/attr.rb +49 -0
  89. data/lib/nokogiri/xml/attribute_decl.rb +4 -2
  90. data/lib/nokogiri/xml/builder.rb +1 -1
  91. data/lib/nokogiri/xml/document.rb +103 -56
  92. data/lib/nokogiri/xml/document_fragment.rb +50 -7
  93. data/lib/nokogiri/xml/element_content.rb +10 -2
  94. data/lib/nokogiri/xml/element_decl.rb +4 -2
  95. data/lib/nokogiri/xml/entity_decl.rb +4 -2
  96. data/lib/nokogiri/xml/namespace.rb +41 -0
  97. data/lib/nokogiri/xml/node/save_options.rb +14 -4
  98. data/lib/nokogiri/xml/node.rb +241 -70
  99. data/lib/nokogiri/xml/node_set.rb +90 -11
  100. data/lib/nokogiri/xml/parse_options.rb +129 -50
  101. data/lib/nokogiri/xml/pp/node.rb +28 -15
  102. data/lib/nokogiri/xml/processing_instruction.rb +2 -1
  103. data/lib/nokogiri/xml/reader.rb +16 -17
  104. data/lib/nokogiri/xml/sax/document.rb +1 -1
  105. data/lib/nokogiri/xml/sax/parser.rb +2 -3
  106. data/lib/nokogiri/xml/searchable.rb +21 -13
  107. data/lib/nokogiri/xml/syntax_error.rb +1 -1
  108. data/lib/nokogiri/xml.rb +1 -1
  109. data/lib/nokogiri/xslt/stylesheet.rb +29 -7
  110. data/lib/nokogiri/xslt.rb +75 -5
  111. data/lib/nokogiri.rb +15 -15
  112. data/lib/xsd/xmlparser/nokogiri.rb +4 -2
  113. data/patches/libxml2/0010-update-config.guess-and-config.sub-for-libxml2.patch +224 -0
  114. data/patches/libxml2/0011-rip-out-libxml2-s-libc_single_threaded-support.patch +30 -0
  115. data/patches/libxslt/0001-update-config.guess-and-config.sub-for-libxslt.patch +224 -0
  116. data/ports/archives/libxml2-2.12.9.tar.xz +0 -0
  117. data/ports/archives/libxslt-1.1.39.tar.xz +0 -0
  118. metadata +21 -248
  119. data/patches/libxml2/0004-use-glibc-strlen.patch +0 -53
  120. data/patches/libxml2/0005-avoid-isnan-isinf.patch +0 -81
  121. data/patches/libxml2/0006-update-automake-files-for-arm64.patch +0 -3040
  122. data/patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch +0 -61
  123. data/patches/libxslt/0001-update-automake-files-for-arm64.patch +0 -3037
  124. data/ports/archives/libxml2-2.9.14.tar.xz +0 -0
  125. data/ports/archives/libxslt-1.1.35.tar.xz +0 -0
@@ -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
 
@@ -32,7 +32,7 @@ new (int argc, VALUE *argv, VALUE klass)
32
32
  }
33
33
 
34
34
  void
35
- noko_init_xml_document_fragment()
35
+ noko_init_xml_document_fragment(void)
36
36
  {
37
37
  assert(cNokogiriXmlNode);
38
38
  /*
@@ -44,7 +44,7 @@ entities(VALUE self)
44
44
  xmlDtdPtr dtd;
45
45
  VALUE hash;
46
46
 
47
- Data_Get_Struct(self, xmlDtd, dtd);
47
+ Noko_Node_Get_Struct(self, xmlDtd, dtd);
48
48
 
49
49
  if (!dtd->entities) { return Qnil; }
50
50
 
@@ -67,7 +67,7 @@ notations(VALUE self)
67
67
  xmlDtdPtr dtd;
68
68
  VALUE hash;
69
69
 
70
- Data_Get_Struct(self, xmlDtd, dtd);
70
+ Noko_Node_Get_Struct(self, xmlDtd, dtd);
71
71
 
72
72
  if (!dtd->notations) { return Qnil; }
73
73
 
@@ -90,7 +90,7 @@ attributes(VALUE self)
90
90
  xmlDtdPtr dtd;
91
91
  VALUE hash;
92
92
 
93
- Data_Get_Struct(self, xmlDtd, dtd);
93
+ Noko_Node_Get_Struct(self, xmlDtd, dtd);
94
94
 
95
95
  hash = rb_hash_new();
96
96
 
@@ -113,7 +113,7 @@ elements(VALUE self)
113
113
  xmlDtdPtr dtd;
114
114
  VALUE hash;
115
115
 
116
- Data_Get_Struct(self, xmlDtd, dtd);
116
+ Noko_Node_Get_Struct(self, xmlDtd, dtd);
117
117
 
118
118
  if (!dtd->elements) { return Qnil; }
119
119
 
@@ -138,8 +138,8 @@ validate(VALUE self, VALUE document)
138
138
  xmlValidCtxtPtr ctxt;
139
139
  VALUE error_list;
140
140
 
141
- Data_Get_Struct(self, xmlDtd, dtd);
142
- Data_Get_Struct(document, xmlDoc, doc);
141
+ Noko_Node_Get_Struct(self, xmlDtd, dtd);
142
+ doc = noko_xml_document_unwrap(document);
143
143
  error_list = rb_ary_new();
144
144
 
145
145
  ctxt = xmlNewValidCtxt();
@@ -165,7 +165,7 @@ static VALUE
165
165
  system_id(VALUE self)
166
166
  {
167
167
  xmlDtdPtr dtd;
168
- Data_Get_Struct(self, xmlDtd, dtd);
168
+ Noko_Node_Get_Struct(self, xmlDtd, dtd);
169
169
 
170
170
  if (!dtd->SystemID) { return Qnil; }
171
171
 
@@ -182,7 +182,7 @@ static VALUE
182
182
  external_id(VALUE self)
183
183
  {
184
184
  xmlDtdPtr dtd;
185
- Data_Get_Struct(self, xmlDtd, dtd);
185
+ Noko_Node_Get_Struct(self, xmlDtd, dtd);
186
186
 
187
187
  if (!dtd->ExternalID) { return Qnil; }
188
188
 
@@ -190,7 +190,7 @@ external_id(VALUE self)
190
190
  }
191
191
 
192
192
  void
193
- noko_init_xml_dtd()
193
+ noko_init_xml_dtd(void)
194
194
  {
195
195
  assert(cNokogiriXmlNode);
196
196
  /*
@@ -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
- return INT2NUM((long)elem->type);
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,51 +66,56 @@ 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
- return INT2NUM((long)elem->ocur);
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);
105
+ VALUE elem = TypedData_Wrap_Struct(
106
+ cNokogiriXmlElementContent,
107
+ &element_content_data_type,
108
+ c_element_content
109
+ );
106
110
 
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);
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
  }
113
116
 
114
117
  void
115
- noko_init_xml_element_content()
118
+ noko_init_xml_element_content(void)
116
119
  {
117
120
  cNokogiriXmlElementContent = rb_define_class_under(mNokogiriXml, "ElementContent", rb_cObject);
118
121
 
@@ -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
  */
@@ -14,21 +14,21 @@ static VALUE
14
14
  element_type(VALUE self)
15
15
  {
16
16
  xmlElementPtr node;
17
- Data_Get_Struct(self, xmlElement, node);
18
- return INT2NUM((long)node->etype);
17
+ Noko_Node_Get_Struct(self, xmlElement, node);
18
+ return INT2NUM(node->etype);
19
19
  }
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)
29
29
  {
30
30
  xmlElementPtr node;
31
- Data_Get_Struct(self, xmlElement, node);
31
+ Noko_Node_Get_Struct(self, xmlElement, node);
32
32
 
33
33
  if (!node->content) { return Qnil; }
34
34
 
@@ -40,15 +40,15 @@ 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)
49
49
  {
50
50
  xmlElementPtr node;
51
- Data_Get_Struct(self, xmlElement, node);
51
+ Noko_Node_Get_Struct(self, xmlElement, node);
52
52
 
53
53
  if (!node->prefix) { return Qnil; }
54
54
 
@@ -56,7 +56,7 @@ prefix(VALUE self)
56
56
  }
57
57
 
58
58
  void
59
- noko_init_xml_element_decl()
59
+ noko_init_xml_element_decl(void)
60
60
  {
61
61
  assert(cNokogiriXmlNode);
62
62
  cNokogiriXmlElementDecl = rb_define_class_under(mNokogiriXml, "ElementDecl", cNokogiriXmlNode);
@@ -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;
@@ -45,9 +53,9 @@ rb_xml_encoding_handler_s_delete(VALUE klass, VALUE name)
45
53
 
46
54
 
47
55
  /*
48
- * call-seq: Nokogiri::EncodingHandler.alias(from, to)
56
+ * call-seq: Nokogiri::EncodingHandler.alias(real_name, alias_name)
49
57
  *
50
- * Alias encoding handler with name +from+ to name +to+
58
+ * Alias encoding handler with name +real_name+ to name +alias_name+
51
59
  */
52
60
  static VALUE
53
61
  rb_xml_encoding_handler_s_alias(VALUE klass, VALUE from, VALUE to)
@@ -82,14 +90,14 @@ 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
  }
89
97
 
90
98
 
91
99
  void
92
- noko_init_xml_encoding_handler()
100
+ noko_init_xml_encoding_handler(void)
93
101
  {
94
102
  cNokogiriEncodingHandler = rb_define_class_under(mNokogiri, "EncodingHandler", rb_cObject);
95
103
 
@@ -12,7 +12,7 @@ static VALUE
12
12
  original_content(VALUE self)
13
13
  {
14
14
  xmlEntityPtr node;
15
- Data_Get_Struct(self, xmlEntity, node);
15
+ Noko_Node_Get_Struct(self, xmlEntity, node);
16
16
 
17
17
  if (!node->orig) { return Qnil; }
18
18
 
@@ -29,7 +29,7 @@ static VALUE
29
29
  get_content(VALUE self)
30
30
  {
31
31
  xmlEntityPtr node;
32
- Data_Get_Struct(self, xmlEntity, node);
32
+ Noko_Node_Get_Struct(self, xmlEntity, node);
33
33
 
34
34
  if (!node->content) { return Qnil; }
35
35
 
@@ -46,7 +46,7 @@ static VALUE
46
46
  entity_type(VALUE self)
47
47
  {
48
48
  xmlEntityPtr node;
49
- Data_Get_Struct(self, xmlEntity, node);
49
+ Noko_Node_Get_Struct(self, xmlEntity, node);
50
50
 
51
51
  return INT2NUM((int)node->etype);
52
52
  }
@@ -61,7 +61,7 @@ static VALUE
61
61
  external_id(VALUE self)
62
62
  {
63
63
  xmlEntityPtr node;
64
- Data_Get_Struct(self, xmlEntity, node);
64
+ Noko_Node_Get_Struct(self, xmlEntity, node);
65
65
 
66
66
  if (!node->ExternalID) { return Qnil; }
67
67
 
@@ -78,7 +78,7 @@ static VALUE
78
78
  system_id(VALUE self)
79
79
  {
80
80
  xmlEntityPtr node;
81
- Data_Get_Struct(self, xmlEntity, node);
81
+ Noko_Node_Get_Struct(self, xmlEntity, node);
82
82
 
83
83
  if (!node->SystemID) { return Qnil; }
84
84
 
@@ -86,7 +86,7 @@ system_id(VALUE self)
86
86
  }
87
87
 
88
88
  void
89
- noko_init_xml_entity_decl()
89
+ noko_init_xml_entity_decl(void)
90
90
  {
91
91
  assert(cNokogiriXmlNode);
92
92
  cNokogiriXmlEntityDecl = rb_define_class_under(mNokogiriXml, "EntityDecl", cNokogiriXmlNode);
@@ -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,
@@ -38,7 +38,7 @@ new (int argc, VALUE *argv, VALUE klass)
38
38
  }
39
39
 
40
40
  void
41
- noko_init_xml_entity_reference()
41
+ noko_init_xml_entity_reference(void)
42
42
  {
43
43
  assert(cNokogiriXmlNode);
44
44
  /*
@@ -25,13 +25,14 @@
25
25
  VALUE cNokogiriXmlNamespace ;
26
26
 
27
27
  static void
28
- dealloc_namespace(xmlNsPtr ns)
28
+ _xml_namespace_dealloc(void *ptr)
29
29
  {
30
30
  /*
31
31
  * this deallocator is only used for namespace nodes that are part of an xpath
32
32
  * node set. see noko_xml_namespace_wrap().
33
33
  */
34
- NOKOGIRI_DEBUG_START(ns) ;
34
+ xmlNsPtr ns = ptr;
35
+
35
36
  if (ns->href) {
36
37
  xmlFree(DISCARD_CONST_QUAL_XMLCHAR(ns->href));
37
38
  }
@@ -39,39 +40,95 @@ dealloc_namespace(xmlNsPtr ns)
39
40
  xmlFree(DISCARD_CONST_QUAL_XMLCHAR(ns->prefix));
40
41
  }
41
42
  xmlFree(ns);
42
- NOKOGIRI_DEBUG_END(ns) ;
43
43
  }
44
44
 
45
+ static void
46
+ _xml_namespace_update_references(void *ptr)
47
+ {
48
+ xmlNsPtr ns = ptr;
49
+ if (ns->_private) {
50
+ ns->_private = (void *)rb_gc_location((VALUE)ns->_private);
51
+ }
52
+ }
53
+
54
+ static const rb_data_type_t nokogiri_xml_namespace_type_with_dealloc = {
55
+ .wrap_struct_name = "Nokogiri::XML::Namespace#with_dealloc",
56
+ .function = {
57
+ .dfree = _xml_namespace_dealloc,
58
+ .dcompact = _xml_namespace_update_references,
59
+ },
60
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
61
+ };
62
+
63
+ static const rb_data_type_t nokogiri_xml_namespace_type_without_dealloc = {
64
+ .wrap_struct_name = "Nokogiri::XML::Namespace#without_dealloc",
65
+ .function = {
66
+ .dcompact = _xml_namespace_update_references,
67
+ },
68
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
69
+ };
45
70
 
46
71
  /*
47
- * call-seq:
48
- * prefix
72
+ * :call-seq:
73
+ * prefix() → String or nil
74
+ *
75
+ * Return the prefix for this Namespace, or +nil+ if there is no prefix (e.g., default namespace).
49
76
  *
50
- * Get the prefix for this namespace. Returns +nil+ if there is no prefix.
77
+ * *Example*
78
+ *
79
+ * doc = Nokogiri::XML.parse(<<~XML)
80
+ * <?xml version="1.0"?>
81
+ * <root xmlns="http://nokogiri.org/ns/default" xmlns:noko="http://nokogiri.org/ns/noko">
82
+ * <child1 foo="abc" noko:bar="def"/>
83
+ * <noko:child2 foo="qwe" noko:bar="rty"/>
84
+ * </root>
85
+ * XML
86
+ *
87
+ * doc.root.elements.first.namespace.prefix
88
+ * # => nil
89
+ *
90
+ * doc.root.elements.last.namespace.prefix
91
+ * # => "noko"
51
92
  */
52
93
  static VALUE
53
94
  prefix(VALUE self)
54
95
  {
55
96
  xmlNsPtr ns;
56
97
 
57
- Data_Get_Struct(self, xmlNs, ns);
98
+ Noko_Namespace_Get_Struct(self, xmlNs, ns);
58
99
  if (!ns->prefix) { return Qnil; }
59
100
 
60
101
  return NOKOGIRI_STR_NEW2(ns->prefix);
61
102
  }
62
103
 
63
104
  /*
64
- * call-seq:
65
- * href
105
+ * :call-seq:
106
+ * href() → String
107
+ *
108
+ * Returns the URI reference for this Namespace.
109
+ *
110
+ * *Example*
111
+ *
112
+ * doc = Nokogiri::XML.parse(<<~XML)
113
+ * <?xml version="1.0"?>
114
+ * <root xmlns="http://nokogiri.org/ns/default" xmlns:noko="http://nokogiri.org/ns/noko">
115
+ * <child1 foo="abc" noko:bar="def"/>
116
+ * <noko:child2 foo="qwe" noko:bar="rty"/>
117
+ * </root>
118
+ * XML
119
+ *
120
+ * doc.root.elements.first.namespace.href
121
+ * # => "http://nokogiri.org/ns/default"
66
122
  *
67
- * Get the href for this namespace
123
+ * doc.root.elements.last.namespace.href
124
+ * # => "http://nokogiri.org/ns/noko"
68
125
  */
69
126
  static VALUE
70
127
  href(VALUE self)
71
128
  {
72
129
  xmlNsPtr ns;
73
130
 
74
- Data_Get_Struct(self, xmlNs, ns);
131
+ Noko_Namespace_Get_Struct(self, xmlNs, ns);
75
132
  if (!ns->href) { return Qnil; }
76
133
 
77
134
  return NOKOGIRI_STR_NEW2(ns->href);
@@ -87,14 +144,18 @@ noko_xml_namespace_wrap(xmlNsPtr c_namespace, xmlDocPtr c_document)
87
144
  }
88
145
 
89
146
  if (c_document) {
90
- rb_namespace = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, 0, c_namespace);
147
+ rb_namespace = TypedData_Wrap_Struct(cNokogiriXmlNamespace,
148
+ &nokogiri_xml_namespace_type_without_dealloc,
149
+ c_namespace);
91
150
 
92
151
  if (DOC_RUBY_OBJECT_TEST(c_document)) {
93
152
  rb_iv_set(rb_namespace, "@document", DOC_RUBY_OBJECT(c_document));
94
153
  rb_ary_push(DOC_NODE_CACHE(c_document), rb_namespace);
95
154
  }
96
155
  } else {
97
- rb_namespace = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, dealloc_namespace, c_namespace);
156
+ rb_namespace = TypedData_Wrap_Struct(cNokogiriXmlNamespace,
157
+ &nokogiri_xml_namespace_type_with_dealloc,
158
+ c_namespace);
98
159
  }
99
160
 
100
161
  c_namespace->_private = (void *)rb_namespace;
@@ -109,7 +170,7 @@ noko_xml_namespace_wrap_xpath_copy(xmlNsPtr c_namespace)
109
170
  }
110
171
 
111
172
  void
112
- noko_init_xml_namespace()
173
+ noko_init_xml_namespace(void)
113
174
  {
114
175
  cNokogiriXmlNamespace = rb_define_class_under(mNokogiriXml, "Namespace", rb_cObject);
115
176