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
@@ -39,8 +39,9 @@ ruby_object_get(xmlNodePtr c_node)
39
39
 
40
40
 
41
41
  static void
42
- mark(xmlNodeSetPtr node_set)
42
+ xml_node_set_mark(void *data)
43
43
  {
44
+ xmlNodeSetPtr node_set = data;
44
45
  VALUE rb_node;
45
46
  int jnode;
46
47
 
@@ -52,6 +53,37 @@ mark(xmlNodeSetPtr node_set)
52
53
  }
53
54
  }
54
55
 
56
+ static void
57
+ xml_node_set_deallocate(void *data)
58
+ {
59
+ xmlNodeSetPtr node_set = data;
60
+ /*
61
+ * For reasons outlined in xml_namespace.c, here we reproduce xmlXPathFreeNodeSet() except for the
62
+ * offending call to xmlXPathNodeSetFreeNs().
63
+ */
64
+ if (node_set->nodeTab != NULL) {
65
+ xmlFree(node_set->nodeTab);
66
+ }
67
+
68
+ xmlFree(node_set);
69
+ }
70
+
71
+
72
+ static VALUE
73
+ xml_node_set_allocate(VALUE klass)
74
+ {
75
+ return noko_xml_node_set_wrap(xmlXPathNodeSetCreate(NULL), Qnil);
76
+ }
77
+
78
+ static const rb_data_type_t xml_node_set_type = {
79
+ .wrap_struct_name = "Nokogiri::XML::NodeSet",
80
+ .function = {
81
+ .dmark = xml_node_set_mark,
82
+ .dfree = xml_node_set_deallocate,
83
+ },
84
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
85
+ };
86
+
55
87
  static void
56
88
  xpath_node_set_del(xmlNodeSetPtr cur, xmlNodePtr val)
57
89
  {
@@ -81,30 +113,6 @@ xpath_node_set_del(xmlNodeSetPtr cur, xmlNodePtr val)
81
113
  }
82
114
 
83
115
 
84
- static void
85
- deallocate(xmlNodeSetPtr node_set)
86
- {
87
- /*
88
- * For reasons outlined in xml_namespace.c, here we reproduce xmlXPathFreeNodeSet() except for the
89
- * offending call to xmlXPathNodeSetFreeNs().
90
- */
91
- NOKOGIRI_DEBUG_START(node_set) ;
92
- if (node_set->nodeTab != NULL) {
93
- xmlFree(node_set->nodeTab);
94
- }
95
-
96
- xmlFree(node_set);
97
- NOKOGIRI_DEBUG_END(node_set) ;
98
- }
99
-
100
-
101
- static VALUE
102
- allocate(VALUE klass)
103
- {
104
- return noko_xml_node_set_wrap(xmlXPathNodeSetCreate(NULL), Qnil);
105
- }
106
-
107
-
108
116
  /*
109
117
  * call-seq:
110
118
  * dup
@@ -113,16 +121,16 @@ allocate(VALUE klass)
113
121
  * duplicated (similar to how Array and other Enumerable classes work).
114
122
  */
115
123
  static VALUE
116
- duplicate(VALUE self)
124
+ duplicate(VALUE rb_self)
117
125
  {
118
- xmlNodeSetPtr node_set;
126
+ xmlNodeSetPtr c_self;
119
127
  xmlNodeSetPtr dupl;
120
128
 
121
- Data_Get_Struct(self, xmlNodeSet, node_set);
129
+ TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
122
130
 
123
- dupl = xmlXPathNodeSetMerge(NULL, node_set);
131
+ dupl = xmlXPathNodeSetMerge(NULL, c_self);
124
132
 
125
- return noko_xml_node_set_wrap(dupl, rb_iv_get(self, "@document"));
133
+ return noko_xml_node_set_wrap(dupl, rb_iv_get(rb_self, "@document"));
126
134
  }
127
135
 
128
136
  /*
@@ -132,13 +140,13 @@ duplicate(VALUE self)
132
140
  * Get the length of the node set
133
141
  */
134
142
  static VALUE
135
- length(VALUE self)
143
+ length(VALUE rb_self)
136
144
  {
137
- xmlNodeSetPtr node_set;
145
+ xmlNodeSetPtr c_self;
138
146
 
139
- Data_Get_Struct(self, xmlNodeSet, node_set);
147
+ TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
140
148
 
141
- return node_set ? INT2NUM(node_set->nodeNr) : INT2NUM(0);
149
+ return c_self ? INT2NUM(c_self->nodeNr) : INT2NUM(0);
142
150
  }
143
151
 
144
152
  /*
@@ -148,19 +156,19 @@ length(VALUE self)
148
156
  * Append +node+ to the NodeSet.
149
157
  */
150
158
  static VALUE
151
- push(VALUE self, VALUE rb_node)
159
+ push(VALUE rb_self, VALUE rb_node)
152
160
  {
153
- xmlNodeSetPtr node_set;
161
+ xmlNodeSetPtr c_self;
154
162
  xmlNodePtr node;
155
163
 
156
164
  Check_Node_Set_Node_Type(rb_node);
157
165
 
158
- Data_Get_Struct(self, xmlNodeSet, node_set);
159
- Data_Get_Struct(rb_node, xmlNode, node);
166
+ TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
167
+ Noko_Node_Get_Struct(rb_node, xmlNode, node);
160
168
 
161
- xmlXPathNodeSetAdd(node_set, node);
169
+ xmlXPathNodeSetAdd(c_self, node);
162
170
 
163
- return self;
171
+ return rb_self;
164
172
  }
165
173
 
166
174
  /*
@@ -171,18 +179,18 @@ push(VALUE self, VALUE rb_node)
171
179
  * if found, otherwise returns nil.
172
180
  */
173
181
  static VALUE
174
- delete (VALUE self, VALUE rb_node)
182
+ delete (VALUE rb_self, VALUE rb_node)
175
183
  {
176
- xmlNodeSetPtr node_set;
184
+ xmlNodeSetPtr c_self;
177
185
  xmlNodePtr node;
178
186
 
179
187
  Check_Node_Set_Node_Type(rb_node);
180
188
 
181
- Data_Get_Struct(self, xmlNodeSet, node_set);
182
- Data_Get_Struct(rb_node, xmlNode, node);
189
+ TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
190
+ Noko_Node_Get_Struct(rb_node, xmlNode, node);
183
191
 
184
- if (xmlXPathNodeSetContains(node_set, node)) {
185
- xpath_node_set_del(node_set, node);
192
+ if (xmlXPathNodeSetContains(c_self, node)) {
193
+ xpath_node_set_del(c_self, node);
186
194
  return rb_node;
187
195
  }
188
196
  return Qnil ;
@@ -196,20 +204,20 @@ delete (VALUE self, VALUE rb_node)
196
204
  * Set Intersection — Returns a new NodeSet containing nodes common to the two NodeSets.
197
205
  */
198
206
  static VALUE
199
- intersection(VALUE self, VALUE rb_other)
207
+ intersection(VALUE rb_self, VALUE rb_other)
200
208
  {
201
- xmlNodeSetPtr node_set, other ;
209
+ xmlNodeSetPtr c_self, c_other ;
202
210
  xmlNodeSetPtr intersection;
203
211
 
204
212
  if (!rb_obj_is_kind_of(rb_other, cNokogiriXmlNodeSet)) {
205
213
  rb_raise(rb_eArgError, "node_set must be a Nokogiri::XML::NodeSet");
206
214
  }
207
215
 
208
- Data_Get_Struct(self, xmlNodeSet, node_set);
209
- Data_Get_Struct(rb_other, xmlNodeSet, other);
216
+ TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
217
+ TypedData_Get_Struct(rb_other, xmlNodeSet, &xml_node_set_type, c_other);
210
218
 
211
- intersection = xmlXPathIntersection(node_set, other);
212
- return noko_xml_node_set_wrap(intersection, rb_iv_get(self, "@document"));
219
+ intersection = xmlXPathIntersection(c_self, c_other);
220
+ return noko_xml_node_set_wrap(intersection, rb_iv_get(rb_self, "@document"));
213
221
  }
214
222
 
215
223
 
@@ -220,17 +228,17 @@ intersection(VALUE self, VALUE rb_other)
220
228
  * Returns true if any member of node set equals +node+.
221
229
  */
222
230
  static VALUE
223
- include_eh(VALUE self, VALUE rb_node)
231
+ include_eh(VALUE rb_self, VALUE rb_node)
224
232
  {
225
- xmlNodeSetPtr node_set;
233
+ xmlNodeSetPtr c_self;
226
234
  xmlNodePtr node;
227
235
 
228
236
  Check_Node_Set_Node_Type(rb_node);
229
237
 
230
- Data_Get_Struct(self, xmlNodeSet, node_set);
231
- Data_Get_Struct(rb_node, xmlNode, node);
238
+ TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
239
+ Noko_Node_Get_Struct(rb_node, xmlNode, node);
232
240
 
233
- return (xmlXPathNodeSetContains(node_set, node) ? Qtrue : Qfalse);
241
+ return (xmlXPathNodeSetContains(c_self, node) ? Qtrue : Qfalse);
234
242
  }
235
243
 
236
244
 
@@ -242,22 +250,22 @@ include_eh(VALUE self, VALUE rb_node)
242
250
  * set.
243
251
  */
244
252
  static VALUE
245
- rb_xml_node_set_union(VALUE rb_node_set, VALUE rb_other)
253
+ rb_xml_node_set_union(VALUE rb_self, VALUE rb_other)
246
254
  {
247
- xmlNodeSetPtr c_node_set, c_other;
255
+ xmlNodeSetPtr c_self, c_other;
248
256
  xmlNodeSetPtr c_new_node_set;
249
257
 
250
258
  if (!rb_obj_is_kind_of(rb_other, cNokogiriXmlNodeSet)) {
251
259
  rb_raise(rb_eArgError, "node_set must be a Nokogiri::XML::NodeSet");
252
260
  }
253
261
 
254
- Data_Get_Struct(rb_node_set, xmlNodeSet, c_node_set);
255
- Data_Get_Struct(rb_other, xmlNodeSet, c_other);
262
+ TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
263
+ TypedData_Get_Struct(rb_other, xmlNodeSet, &xml_node_set_type, c_other);
256
264
 
257
- c_new_node_set = xmlXPathNodeSetMerge(NULL, c_node_set);
265
+ c_new_node_set = xmlXPathNodeSetMerge(NULL, c_self);
258
266
  c_new_node_set = xmlXPathNodeSetMerge(c_new_node_set, c_other);
259
267
 
260
- return noko_xml_node_set_wrap(c_new_node_set, rb_iv_get(rb_node_set, "@document"));
268
+ return noko_xml_node_set_wrap(c_new_node_set, rb_iv_get(rb_self, "@document"));
261
269
  }
262
270
 
263
271
  /*
@@ -268,9 +276,9 @@ rb_xml_node_set_union(VALUE rb_node_set, VALUE rb_other)
268
276
  * each item that also appears in +node_set+
269
277
  */
270
278
  static VALUE
271
- minus(VALUE self, VALUE rb_other)
279
+ minus(VALUE rb_self, VALUE rb_other)
272
280
  {
273
- xmlNodeSetPtr node_set, other;
281
+ xmlNodeSetPtr c_self, c_other;
274
282
  xmlNodeSetPtr new;
275
283
  int j ;
276
284
 
@@ -278,55 +286,55 @@ minus(VALUE self, VALUE rb_other)
278
286
  rb_raise(rb_eArgError, "node_set must be a Nokogiri::XML::NodeSet");
279
287
  }
280
288
 
281
- Data_Get_Struct(self, xmlNodeSet, node_set);
282
- Data_Get_Struct(rb_other, xmlNodeSet, other);
289
+ TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
290
+ TypedData_Get_Struct(rb_other, xmlNodeSet, &xml_node_set_type, c_other);
283
291
 
284
- new = xmlXPathNodeSetMerge(NULL, node_set);
285
- for (j = 0 ; j < other->nodeNr ; ++j) {
286
- xpath_node_set_del(new, other->nodeTab[j]);
292
+ new = xmlXPathNodeSetMerge(NULL, c_self);
293
+ for (j = 0 ; j < c_other->nodeNr ; ++j) {
294
+ xpath_node_set_del(new, c_other->nodeTab[j]);
287
295
  }
288
296
 
289
- return noko_xml_node_set_wrap(new, rb_iv_get(self, "@document"));
297
+ return noko_xml_node_set_wrap(new, rb_iv_get(rb_self, "@document"));
290
298
  }
291
299
 
292
300
 
293
301
  static VALUE
294
- index_at(VALUE self, long offset)
302
+ index_at(VALUE rb_self, long offset)
295
303
  {
296
- xmlNodeSetPtr node_set;
304
+ xmlNodeSetPtr c_self;
297
305
 
298
- Data_Get_Struct(self, xmlNodeSet, node_set);
306
+ TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
299
307
 
300
- if (offset >= node_set->nodeNr || abs((int)offset) > node_set->nodeNr) {
308
+ if (offset >= c_self->nodeNr || abs((int)offset) > c_self->nodeNr) {
301
309
  return Qnil;
302
310
  }
303
311
 
304
- if (offset < 0) { offset += node_set->nodeNr ; }
312
+ if (offset < 0) { offset += c_self->nodeNr ; }
305
313
 
306
- return noko_xml_node_wrap_node_set_result(node_set->nodeTab[offset], self);
314
+ return noko_xml_node_wrap_node_set_result(c_self->nodeTab[offset], rb_self);
307
315
  }
308
316
 
309
317
  static VALUE
310
- subseq(VALUE self, long beg, long len)
318
+ subseq(VALUE rb_self, long beg, long len)
311
319
  {
312
320
  long j;
313
- xmlNodeSetPtr node_set;
321
+ xmlNodeSetPtr c_self;
314
322
  xmlNodeSetPtr new_set ;
315
323
 
316
- Data_Get_Struct(self, xmlNodeSet, node_set);
324
+ TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
317
325
 
318
- if (beg > node_set->nodeNr) { return Qnil ; }
326
+ if (beg > c_self->nodeNr) { return Qnil ; }
319
327
  if (beg < 0 || len < 0) { return Qnil ; }
320
328
 
321
- if ((beg + len) > node_set->nodeNr) {
322
- len = node_set->nodeNr - beg ;
329
+ if ((beg + len) > c_self->nodeNr) {
330
+ len = c_self->nodeNr - beg ;
323
331
  }
324
332
 
325
333
  new_set = xmlXPathNodeSetCreate(NULL);
326
334
  for (j = beg ; j < beg + len ; ++j) {
327
- xmlXPathNodeSetAddUnique(new_set, node_set->nodeTab[j]);
335
+ xmlXPathNodeSetAddUnique(new_set, c_self->nodeTab[j]);
328
336
  }
329
- return noko_xml_node_set_wrap(new_set, rb_iv_get(self, "@document"));
337
+ return noko_xml_node_set_wrap(new_set, rb_iv_get(rb_self, "@document"));
330
338
  }
331
339
 
332
340
  /*
@@ -345,21 +353,21 @@ subseq(VALUE self, long beg, long len)
345
353
  * nil if the +index+ (or +start+) are out of range.
346
354
  */
347
355
  static VALUE
348
- slice(int argc, VALUE *argv, VALUE self)
356
+ slice(int argc, VALUE *argv, VALUE rb_self)
349
357
  {
350
358
  VALUE arg ;
351
359
  long beg, len ;
352
- xmlNodeSetPtr node_set;
360
+ xmlNodeSetPtr c_self;
353
361
 
354
- Data_Get_Struct(self, xmlNodeSet, node_set);
362
+ TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
355
363
 
356
364
  if (argc == 2) {
357
365
  beg = NUM2LONG(argv[0]);
358
366
  len = NUM2LONG(argv[1]);
359
367
  if (beg < 0) {
360
- beg += node_set->nodeNr ;
368
+ beg += c_self->nodeNr ;
361
369
  }
362
- return subseq(self, beg, len);
370
+ return subseq(rb_self, beg, len);
363
371
  }
364
372
 
365
373
  if (argc != 1) {
@@ -368,20 +376,20 @@ slice(int argc, VALUE *argv, VALUE self)
368
376
  arg = argv[0];
369
377
 
370
378
  if (FIXNUM_P(arg)) {
371
- return index_at(self, FIX2LONG(arg));
379
+ return index_at(rb_self, FIX2LONG(arg));
372
380
  }
373
381
 
374
382
  /* if arg is Range */
375
- switch (rb_range_beg_len(arg, &beg, &len, (long)node_set->nodeNr, 0)) {
383
+ switch (rb_range_beg_len(arg, &beg, &len, (long)c_self->nodeNr, 0)) {
376
384
  case Qfalse:
377
385
  break;
378
386
  case Qnil:
379
387
  return Qnil;
380
388
  default:
381
- return subseq(self, beg, len);
389
+ return subseq(rb_self, beg, len);
382
390
  }
383
391
 
384
- return index_at(self, NUM2LONG(arg));
392
+ return index_at(rb_self, NUM2LONG(arg));
385
393
  }
386
394
 
387
395
 
@@ -392,17 +400,17 @@ slice(int argc, VALUE *argv, VALUE self)
392
400
  * Return this list as an Array
393
401
  */
394
402
  static VALUE
395
- to_array(VALUE self)
403
+ to_array(VALUE rb_self)
396
404
  {
397
- xmlNodeSetPtr node_set ;
405
+ xmlNodeSetPtr c_self ;
398
406
  VALUE list;
399
407
  int i;
400
408
 
401
- Data_Get_Struct(self, xmlNodeSet, node_set);
409
+ TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
402
410
 
403
- list = rb_ary_new2(node_set->nodeNr);
404
- for (i = 0; i < node_set->nodeNr; i++) {
405
- VALUE elt = noko_xml_node_wrap_node_set_result(node_set->nodeTab[i], self);
411
+ list = rb_ary_new2(c_self->nodeNr);
412
+ for (i = 0; i < c_self->nodeNr; i++) {
413
+ VALUE elt = noko_xml_node_wrap_node_set_result(c_self->nodeTab[i], rb_self);
406
414
  rb_ary_push(list, elt);
407
415
  }
408
416
 
@@ -416,25 +424,25 @@ to_array(VALUE self)
416
424
  * Unlink this NodeSet and all Node objects it contains from their current context.
417
425
  */
418
426
  static VALUE
419
- unlink_nodeset(VALUE self)
427
+ unlink_nodeset(VALUE rb_self)
420
428
  {
421
- xmlNodeSetPtr node_set;
429
+ xmlNodeSetPtr c_self;
422
430
  int j, nodeNr ;
423
431
 
424
- Data_Get_Struct(self, xmlNodeSet, node_set);
432
+ TypedData_Get_Struct(rb_self, xmlNodeSet, &xml_node_set_type, c_self);
425
433
 
426
- nodeNr = node_set->nodeNr ;
434
+ nodeNr = c_self->nodeNr ;
427
435
  for (j = 0 ; j < nodeNr ; j++) {
428
- if (! NOKOGIRI_NAMESPACE_EH(node_set->nodeTab[j])) {
436
+ if (! NOKOGIRI_NAMESPACE_EH(c_self->nodeTab[j])) {
429
437
  VALUE node ;
430
438
  xmlNodePtr node_ptr;
431
- node = noko_xml_node_wrap(Qnil, node_set->nodeTab[j]);
439
+ node = noko_xml_node_wrap(Qnil, c_self->nodeTab[j]);
432
440
  rb_funcall(node, rb_intern("unlink"), 0); /* modifies the C struct out from under the object */
433
- Data_Get_Struct(node, xmlNode, node_ptr);
434
- node_set->nodeTab[j] = node_ptr ;
441
+ Noko_Node_Get_Struct(node, xmlNode, node_ptr);
442
+ c_self->nodeTab[j] = node_ptr ;
435
443
  }
436
444
  }
437
- return self ;
445
+ return rb_self ;
438
446
  }
439
447
 
440
448
 
@@ -448,7 +456,7 @@ noko_xml_node_set_wrap(xmlNodeSetPtr c_node_set, VALUE document)
448
456
  c_node_set = xmlXPathNodeSetCreate(NULL);
449
457
  }
450
458
 
451
- rb_node_set = Data_Wrap_Struct(cNokogiriXmlNodeSet, mark, deallocate, c_node_set);
459
+ rb_node_set = TypedData_Wrap_Struct(cNokogiriXmlNodeSet, &xml_node_set_type, c_node_set);
452
460
 
453
461
  if (!NIL_P(document)) {
454
462
  rb_iv_set(rb_node_set, "@document", document);
@@ -463,6 +471,7 @@ noko_xml_node_set_wrap(xmlNodeSetPtr c_node_set, VALUE document)
463
471
  return rb_node_set ;
464
472
  }
465
473
 
474
+
466
475
  VALUE
467
476
  noko_xml_node_wrap_node_set_result(xmlNodePtr node, VALUE node_set)
468
477
  {
@@ -474,12 +483,21 @@ noko_xml_node_wrap_node_set_result(xmlNodePtr node, VALUE node_set)
474
483
  }
475
484
 
476
485
 
486
+ xmlNodeSetPtr
487
+ noko_xml_node_set_unwrap(VALUE rb_node_set)
488
+ {
489
+ xmlNodeSetPtr c_node_set;
490
+ TypedData_Get_Struct(rb_node_set, xmlNodeSet, &xml_node_set_type, c_node_set);
491
+ return c_node_set;
492
+ }
493
+
494
+
477
495
  void
478
496
  noko_init_xml_node_set(void)
479
497
  {
480
498
  cNokogiriXmlNodeSet = rb_define_class_under(mNokogiriXml, "NodeSet", rb_cObject);
481
499
 
482
- rb_define_alloc_func(cNokogiriXmlNodeSet, allocate);
500
+ rb_define_alloc_func(cNokogiriXmlNodeSet, xml_node_set_allocate);
483
501
 
484
502
  rb_define_method(cNokogiriXmlNodeSet, "length", length, 0);
485
503
  rb_define_method(cNokogiriXmlNodeSet, "[]", slice, -1);
@@ -22,7 +22,7 @@ new (int argc, VALUE *argv, VALUE klass)
22
22
 
23
23
  rb_scan_args(argc, argv, "3*", &document, &name, &content, &rest);
24
24
 
25
- Data_Get_Struct(document, xmlDoc, xml_doc);
25
+ xml_doc = noko_xml_document_unwrap(document);
26
26
 
27
27
  node = xmlNewDocPI(
28
28
  xml_doc,
@@ -41,7 +41,7 @@ new (int argc, VALUE *argv, VALUE klass)
41
41
  }
42
42
 
43
43
  void
44
- noko_init_xml_processing_instruction()
44
+ noko_init_xml_processing_instruction(void)
45
45
  {
46
46
  assert(cNokogiriXmlNode);
47
47
  /*