libxml-ruby 5.0.6 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/{HISTORY → CHANGELOG.md} +875 -930
  3. data/LICENSE +20 -20
  4. data/README.md +67 -0
  5. data/Rakefile +13 -34
  6. data/ext/libxml/extconf.rb +34 -20
  7. data/ext/libxml/libxml.c +2 -14
  8. data/ext/libxml/ruby_libxml.h +1 -1
  9. data/ext/libxml/ruby_xml_attr.c +27 -22
  10. data/ext/libxml/ruby_xml_attr.h +1 -0
  11. data/ext/libxml/ruby_xml_attr_decl.c +19 -12
  12. data/ext/libxml/ruby_xml_attributes.c +18 -9
  13. data/ext/libxml/ruby_xml_document.c +111 -98
  14. data/ext/libxml/ruby_xml_document.h +1 -0
  15. data/ext/libxml/ruby_xml_dtd.c +49 -19
  16. data/ext/libxml/ruby_xml_dtd.h +1 -0
  17. data/ext/libxml/ruby_xml_html_parser.c +1 -1
  18. data/ext/libxml/ruby_xml_html_parser_context.c +19 -6
  19. data/ext/libxml/ruby_xml_html_parser_context.h +1 -0
  20. data/ext/libxml/ruby_xml_input_cbg.c +45 -17
  21. data/ext/libxml/ruby_xml_io.c +3 -1
  22. data/ext/libxml/ruby_xml_namespace.c +20 -12
  23. data/ext/libxml/ruby_xml_namespace.h +1 -0
  24. data/ext/libxml/ruby_xml_namespaces.c +40 -20
  25. data/ext/libxml/ruby_xml_node.c +71 -32
  26. data/ext/libxml/ruby_xml_node.h +2 -0
  27. data/ext/libxml/ruby_xml_parser.c +1 -1
  28. data/ext/libxml/ruby_xml_parser_context.c +54 -47
  29. data/ext/libxml/ruby_xml_parser_context.h +1 -0
  30. data/ext/libxml/ruby_xml_reader.c +25 -15
  31. data/ext/libxml/ruby_xml_registry.c +31 -0
  32. data/ext/libxml/ruby_xml_registry.h +22 -0
  33. data/ext/libxml/ruby_xml_relaxng.c +21 -5
  34. data/ext/libxml/ruby_xml_relaxng.h +1 -0
  35. data/ext/libxml/ruby_xml_sax_parser.c +1 -1
  36. data/ext/libxml/ruby_xml_schema.c +18 -11
  37. data/ext/libxml/ruby_xml_schema.h +1 -0
  38. data/ext/libxml/ruby_xml_schema_attribute.c +7 -7
  39. data/ext/libxml/ruby_xml_schema_element.c +8 -8
  40. data/ext/libxml/ruby_xml_schema_facet.c +7 -7
  41. data/ext/libxml/ruby_xml_schema_type.c +12 -19
  42. data/ext/libxml/ruby_xml_version.h +4 -4
  43. data/ext/libxml/ruby_xml_writer.c +18 -6
  44. data/ext/libxml/ruby_xml_xpath.c +2 -2
  45. data/ext/libxml/ruby_xml_xpath.h +1 -1
  46. data/ext/libxml/ruby_xml_xpath_context.c +72 -26
  47. data/ext/libxml/ruby_xml_xpath_expression.c +11 -5
  48. data/ext/libxml/ruby_xml_xpath_expression.h +1 -0
  49. data/ext/libxml/ruby_xml_xpath_object.c +69 -54
  50. data/ext/libxml/ruby_xml_xpath_object.h +3 -1
  51. data/ext/vc/libxml_ruby/libxml_ruby.vcxproj +271 -0
  52. data/ext/xcode/libxml-ruby.xcodeproj/project.pbxproj +633 -0
  53. data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  54. data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  55. data/ext/xcode/libxml-ruby.xcodeproj/xcshareddata/xcschemes/libxml-ruby.xcscheme +80 -0
  56. data/lib/libxml/document.rb +0 -29
  57. data/lib/libxml/error.rb +30 -3
  58. data/lib/libxml/html_parser.rb +0 -16
  59. data/lib/libxml/node.rb +1 -3
  60. data/lib/libxml/parser.rb +0 -8
  61. data/lib/libxml/schema/attribute.rb +27 -19
  62. data/lib/libxml/schema/element.rb +20 -0
  63. data/lib/libxml/schema/type.rb +44 -21
  64. data/lib/libxml/schema.rb +47 -47
  65. data/lib/libxml-ruby.rb +30 -30
  66. data/libxml-ruby.gemspec +12 -16
  67. data/test/c14n/result/1-1-without-comments/example-1 +3 -3
  68. data/test/c14n/result/1-1-without-comments/example-2 +10 -10
  69. data/test/c14n/result/1-1-without-comments/example-3 +13 -13
  70. data/test/c14n/result/1-1-without-comments/example-4 +8 -8
  71. data/test/c14n/result/1-1-without-comments/example-5 +2 -2
  72. data/test/c14n/result/with-comments/example-1 +5 -5
  73. data/test/c14n/result/with-comments/example-2 +10 -10
  74. data/test/c14n/result/with-comments/example-3 +13 -13
  75. data/test/c14n/result/with-comments/example-4 +8 -8
  76. data/test/c14n/result/with-comments/example-5 +3 -3
  77. data/test/c14n/result/without-comments/example-1 +3 -3
  78. data/test/c14n/result/without-comments/example-2 +10 -10
  79. data/test/c14n/result/without-comments/example-3 +13 -13
  80. data/test/c14n/result/without-comments/example-4 +8 -8
  81. data/test/c14n/result/without-comments/example-5 +2 -2
  82. data/test/test_attr.rb +179 -180
  83. data/test/test_attr_decl.rb +131 -131
  84. data/test/test_attributes.rb +135 -135
  85. data/test/test_canonicalize.rb +122 -120
  86. data/test/test_document.rb +2 -4
  87. data/test/test_dtd.rb +12 -4
  88. data/test/test_encoding_sax.rb +114 -114
  89. data/test/test_error.rb +1 -1
  90. data/test/test_html_parser.rb +6 -2
  91. data/test/test_html_parser_context.rb +22 -22
  92. data/test/test_input_callbacks.rb +36 -0
  93. data/test/test_namespace.rb +1 -1
  94. data/test/test_namespaces.rb +200 -200
  95. data/test/test_node.rb +16 -0
  96. data/test/test_node_cdata.rb +50 -50
  97. data/test/test_node_comment.rb +32 -32
  98. data/test/test_node_copy.rb +40 -40
  99. data/test/test_node_edit.rb +176 -158
  100. data/test/test_node_pi.rb +37 -37
  101. data/test/test_node_text.rb +69 -69
  102. data/test/test_node_xlink.rb +28 -28
  103. data/test/test_parser.rb +5 -41
  104. data/test/test_parser_context.rb +198 -198
  105. data/test/test_properties.rb +38 -38
  106. data/test/test_reader.rb +55 -6
  107. data/test/test_relaxng.rb +59 -53
  108. data/test/test_sax_parser.rb +345 -345
  109. data/test/test_schema.rb +28 -0
  110. data/test/test_traversal.rb +152 -152
  111. data/test/test_writer.rb +0 -31
  112. data/test/test_xinclude.rb +20 -20
  113. data/test/test_xml.rb +3 -7
  114. data/test/test_xpath.rb +244 -244
  115. data/test/test_xpath_context.rb +87 -87
  116. data/test/test_xpath_expression.rb +37 -37
  117. metadata +32 -25
  118. data/README.rdoc +0 -208
  119. data/ext/libxml/extconf.h +0 -4
  120. data/ext/libxml/ruby_xml_cbg.c +0 -85
  121. data/lib/libxml/hpricot.rb +0 -78
  122. data/lib/libxml.rb +0 -5
  123. data/lib/xml/libxml.rb +0 -10
  124. data/lib/xml.rb +0 -14
  125. data/script/benchmark/depixelate +0 -634
  126. data/script/benchmark/hamlet.xml +0 -9055
  127. data/script/benchmark/parsecount +0 -170
  128. data/script/benchmark/sock_entries.xml +0 -507
  129. data/script/benchmark/throughput +0 -41
  130. data/script/test +0 -6
  131. data/test/test_deprecated_require.rb +0 -12
@@ -60,25 +60,30 @@
60
60
 
61
61
  VALUE cXMLDocument;
62
62
 
63
- void rxml_document_free(xmlDocPtr xdoc)
63
+ void rxml_document_free(void* data)
64
64
  {
65
- xdoc->_private = NULL;
65
+ xmlDocPtr xdoc = (xmlDocPtr)data;
66
+ if (!xdoc) return;
67
+ rxml_registry_unregister(xdoc);
66
68
  xmlFreeDoc(xdoc);
67
69
  }
68
70
 
71
+ const rb_data_type_t rxml_document_data_type = {
72
+ .wrap_struct_name = "LibXML::XML::Document",
73
+ .function = { .dmark = NULL, .dfree = rxml_document_free },
74
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
75
+ };
76
+
69
77
  VALUE rxml_document_wrap(xmlDocPtr xdoc)
70
78
  {
71
79
  VALUE result = Qnil;
72
80
 
73
- // Is this node is already wrapped?
74
- if (xdoc->_private != NULL)
75
- {
76
- result = (VALUE)xdoc->_private;
77
- }
78
- else
81
+ // Is this document already wrapped?
82
+ result = rxml_registry_lookup(xdoc);
83
+ if (NIL_P(result))
79
84
  {
80
- result = Data_Wrap_Struct(cXMLDocument, NULL, rxml_document_free, xdoc);
81
- xdoc->_private = (void*)result;
85
+ result = TypedData_Wrap_Struct(cXMLDocument, &rxml_document_data_type, xdoc);
86
+ rxml_registry_register(xdoc, result);
82
87
  }
83
88
 
84
89
  return result;
@@ -93,7 +98,7 @@ VALUE rxml_document_wrap(xmlDocPtr xdoc)
93
98
  */
94
99
  static VALUE rxml_document_alloc(VALUE klass)
95
100
  {
96
- return Data_Wrap_Struct(klass, NULL, rxml_document_free, NULL);
101
+ return TypedData_Wrap_Struct(klass, &rxml_document_data_type, NULL);
97
102
  }
98
103
 
99
104
  /*
@@ -124,8 +129,8 @@ static VALUE rxml_document_initialize(int argc, VALUE *argv, VALUE self)
124
129
  xdoc = xmlNewDoc((xmlChar*) StringValuePtr(xmlver));
125
130
 
126
131
  // Link the ruby object to the document and the document to the ruby object
127
- RDATA(self)->data = xdoc;
128
- xdoc->_private = (void*)self;
132
+ RTYPEDDATA_DATA(self) = xdoc;
133
+ rxml_registry_register(xdoc, self);
129
134
 
130
135
  return self;
131
136
  }
@@ -213,10 +218,10 @@ rxml_document_canonicalize(int argc, VALUE *argv, VALUE self)
213
218
  // Do stuff if ruby hash passed as argument
214
219
  if (!NIL_P(option_hash))
215
220
  {
216
- VALUE o_comments = Qnil;
217
- VALUE o_mode = Qnil;
218
- VALUE o_i_ns_prefixes = Qnil;
219
-
221
+ VALUE o_comments = Qnil;
222
+ VALUE o_mode = Qnil;
223
+ VALUE o_i_ns_prefixes = Qnil;
224
+
220
225
  Check_Type(option_hash, T_HASH);
221
226
 
222
227
  o_comments = rb_hash_aref(option_hash, ID2SYM(rb_intern("comments")));
@@ -224,7 +229,7 @@ rxml_document_canonicalize(int argc, VALUE *argv, VALUE self)
224
229
 
225
230
  o_mode = rb_hash_aref(option_hash, ID2SYM(rb_intern("mode")));
226
231
  if (!NIL_P(o_mode))
227
- {
232
+ {
228
233
  Check_Type(o_mode, T_FIXNUM);
229
234
  c14n_mode = NUM2INT(o_mode);
230
235
  //TODO: clean this up
@@ -234,25 +239,25 @@ rxml_document_canonicalize(int argc, VALUE *argv, VALUE self)
234
239
 
235
240
  o_i_ns_prefixes = rb_hash_aref(option_hash, ID2SYM(rb_intern("inclusive_ns_prefixes")));
236
241
  if (!NIL_P(o_i_ns_prefixes))
237
- {
242
+ {
238
243
  int i;
239
244
  int p = 0; //pointer array index
240
245
  VALUE *list_in = NULL;
241
246
  long list_size = 0;
242
247
 
243
- Check_Type(o_i_ns_prefixes, T_ARRAY);
248
+ Check_Type(o_i_ns_prefixes, T_ARRAY);
244
249
  list_in = RARRAY_PTR(o_i_ns_prefixes);
245
250
  list_size = RARRAY_LEN(o_i_ns_prefixes);
246
251
 
247
252
  if (list_size > 0)
248
- {
253
+ {
249
254
  for(i=0; i < list_size; ++i) {
250
255
  if (p >= C14N_NS_LIMIT) { break; }
251
256
 
252
257
  if (RTEST(list_in[i]))
253
- {
258
+ {
254
259
  if (TYPE(list_in[i]) == T_STRING)
255
- {
260
+ {
256
261
  inc_ns_prefixes_ptr[p] = (xmlChar *)StringValueCStr(list_in[i]);
257
262
  p++;
258
263
  }
@@ -270,46 +275,54 @@ rxml_document_canonicalize(int argc, VALUE *argv, VALUE self)
270
275
  //o_ns_prefixes will free at end of block
271
276
 
272
277
  o_nodes = rb_hash_aref(option_hash, ID2SYM(rb_intern("nodes")));
273
- if (!NIL_P(o_nodes))
274
- {
275
- int i;
276
- int p = 0; // index of pointer array
277
- VALUE * list_in = NULL;
278
- long node_list_size = 0;
279
-
280
- if (CLASS_OF(o_nodes) == cXMLXPathObject)
281
- {
282
- o_nodes = rb_funcall(o_nodes, rb_intern("to_a"), 0);
283
- }
284
- else
285
- {
286
- Check_Type(o_nodes, T_ARRAY);
287
- }
288
- list_in = RARRAY_PTR(o_nodes);
289
- node_list_size = RARRAY_LEN(o_nodes);
290
-
291
- for (i=0; i < node_list_size; ++i)
292
- {
293
- if (p >= C14N_NODESET_LIMIT) { break; }
294
-
295
- if (RTEST(list_in[i]))
296
- {
297
- xmlNodePtr node_ptr;
298
- Data_Get_Struct(list_in[i], xmlNode, node_ptr);
299
- node_ptr_array[p] = node_ptr;
300
- p++;
278
+ if (!NIL_P(o_nodes))
279
+ {
280
+ if (CLASS_OF(o_nodes) == cXMLXPathObject)
281
+ {
282
+ /* Use the raw xmlNodeSet directly to preserve namespace nodes
283
+ which cannot survive a roundtrip through Ruby objects */
284
+ rxml_xpath_object *rxpop;
285
+ TypedData_Get_Struct(o_nodes, rxml_xpath_object, &rxml_xpath_object_data_type, rxpop);
286
+ if (rxpop->xpop->nodesetval)
287
+ {
288
+ nodeset.nodeNr = rxpop->xpop->nodesetval->nodeNr;
289
+ nodeset.nodeMax = rxpop->xpop->nodesetval->nodeMax;
290
+ nodeset.nodeTab = rxpop->xpop->nodesetval->nodeTab;
301
291
  }
302
292
  }
293
+ else
294
+ {
295
+ int i;
296
+ int p = 0;
297
+ VALUE *list_in = NULL;
298
+ long node_list_size = 0;
299
+
300
+ Check_Type(o_nodes, T_ARRAY);
301
+ list_in = RARRAY_PTR(o_nodes);
302
+ node_list_size = RARRAY_LEN(o_nodes);
303
+
304
+ for (i=0; i < node_list_size; ++i)
305
+ {
306
+ if (p >= C14N_NODESET_LIMIT) { break; }
307
+
308
+ if (RTEST(list_in[i]))
309
+ {
310
+ xmlNodePtr node_ptr;
311
+ TypedData_Get_Struct(list_in[i], xmlNode, &rxml_node_data_type, node_ptr);
312
+ node_ptr_array[p] = node_ptr;
313
+ p++;
314
+ }
315
+ }
303
316
 
304
- // Need to set values in nodeset struct
305
- nodeset.nodeNr = (node_list_size > C14N_NODESET_LIMIT ?
306
- C14N_NODESET_LIMIT :
307
- (int)node_list_size);
308
- nodeset.nodeTab = node_ptr_array;
317
+ nodeset.nodeNr = (node_list_size > C14N_NODESET_LIMIT ?
318
+ C14N_NODESET_LIMIT :
319
+ (int)node_list_size);
320
+ nodeset.nodeTab = node_ptr_array;
321
+ }
309
322
  }
310
323
  }//option_hash
311
324
 
312
- Data_Get_Struct(self, xmlDoc, xdoc);
325
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
313
326
  xmlC14NDocDumpMemory(xdoc,
314
327
  (nodeset.nodeNr == 0 ? NULL : &nodeset),
315
328
  c14n_mode,
@@ -339,7 +352,7 @@ static VALUE rxml_document_compression_get(VALUE self)
339
352
  xmlDocPtr xdoc;
340
353
 
341
354
  int compmode;
342
- Data_Get_Struct(self, xmlDoc, xdoc);
355
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
343
356
 
344
357
  compmode = xmlGetDocCompressMode(xdoc);
345
358
  if (compmode == -1)
@@ -365,7 +378,7 @@ static VALUE rxml_document_compression_set(VALUE self, VALUE num)
365
378
 
366
379
  int compmode;
367
380
  Check_Type(num, T_FIXNUM);
368
- Data_Get_Struct(self, xmlDoc, xdoc);
381
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
369
382
 
370
383
  if (xdoc == NULL)
371
384
  {
@@ -398,7 +411,7 @@ static VALUE rxml_document_compression_q(VALUE self)
398
411
  #ifdef HAVE_ZLIB_H
399
412
  xmlDocPtr xdoc;
400
413
 
401
- Data_Get_Struct(self, xmlDoc, xdoc);
414
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
402
415
 
403
416
  if (xdoc->compression != -1)
404
417
  return(Qtrue);
@@ -419,7 +432,7 @@ static VALUE rxml_document_compression_q(VALUE self)
419
432
  static VALUE rxml_document_child_get(VALUE self)
420
433
  {
421
434
  xmlDocPtr xdoc;
422
- Data_Get_Struct(self, xmlDoc, xdoc);
435
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
423
436
 
424
437
  if (xdoc->children == NULL)
425
438
  return (Qnil);
@@ -436,7 +449,7 @@ static VALUE rxml_document_child_get(VALUE self)
436
449
  static VALUE rxml_document_child_q(VALUE self)
437
450
  {
438
451
  xmlDocPtr xdoc;
439
- Data_Get_Struct(self, xmlDoc, xdoc);
452
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
440
453
 
441
454
  if (xdoc->children == NULL)
442
455
  return (Qfalse);
@@ -456,7 +469,7 @@ static VALUE rxml_document_debug(VALUE self)
456
469
  {
457
470
  #ifdef LIBXML_DEBUG_ENABLED
458
471
  xmlDocPtr xdoc;
459
- Data_Get_Struct(self, xmlDoc, xdoc);
472
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
460
473
  xmlDebugDumpDocument(NULL, xdoc);
461
474
  return Qtrue;
462
475
  #else
@@ -475,7 +488,7 @@ static VALUE rxml_document_encoding_get(VALUE self)
475
488
  {
476
489
  xmlDocPtr xdoc;
477
490
  const char *xencoding;
478
- Data_Get_Struct(self, xmlDoc, xdoc);
491
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
479
492
 
480
493
  xencoding = (const char*)xdoc->encoding;
481
494
  return INT2NUM(xmlParseCharEncoding(xencoding));
@@ -493,7 +506,7 @@ static VALUE rxml_document_rb_encoding_get(VALUE self)
493
506
  {
494
507
  xmlDocPtr xdoc;
495
508
  rb_encoding* rbencoding;
496
- Data_Get_Struct(self, xmlDoc, xdoc);
509
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
497
510
 
498
511
  rbencoding = rxml_xml_encoding_to_rb_encoding(mXMLEncoding, xmlParseCharEncoding((const char*)xdoc->encoding));
499
512
  return rb_enc_from_encoding(rbencoding);
@@ -510,7 +523,7 @@ static VALUE rxml_document_encoding_set(VALUE self, VALUE encoding)
510
523
  xmlDocPtr xdoc;
511
524
  const char* xencoding = xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(encoding));
512
525
 
513
- Data_Get_Struct(self, xmlDoc, xdoc);
526
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
514
527
 
515
528
  if (xdoc->encoding != NULL)
516
529
  xmlFree((xmlChar *) xdoc->encoding);
@@ -536,8 +549,8 @@ static VALUE rxml_document_import(VALUE self, VALUE node)
536
549
  xmlDocPtr xdoc;
537
550
  xmlNodePtr xnode, xresult;
538
551
 
539
- Data_Get_Struct(self, xmlDoc, xdoc);
540
- Data_Get_Struct(node, xmlNode, xnode);
552
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
553
+ TypedData_Get_Struct(node, xmlNode, &rxml_node_data_type, xnode);
541
554
 
542
555
  xresult = xmlDocCopyNode(xnode, xdoc, 1);
543
556
 
@@ -557,7 +570,7 @@ static VALUE rxml_document_last_get(VALUE self)
557
570
  {
558
571
  xmlDocPtr xdoc;
559
572
 
560
- Data_Get_Struct(self, xmlDoc, xdoc);
573
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
561
574
 
562
575
  if (xdoc->last == NULL)
563
576
  return (Qnil);
@@ -575,7 +588,7 @@ static VALUE rxml_document_last_q(VALUE self)
575
588
  {
576
589
  xmlDocPtr xdoc;
577
590
 
578
- Data_Get_Struct(self, xmlDoc, xdoc);
591
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
579
592
 
580
593
  if (xdoc->last == NULL)
581
594
  return (Qfalse);
@@ -593,7 +606,7 @@ static VALUE rxml_document_next_get(VALUE self)
593
606
  {
594
607
  xmlDocPtr xdoc;
595
608
 
596
- Data_Get_Struct(self, xmlDoc, xdoc);
609
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
597
610
 
598
611
  if (xdoc->next == NULL)
599
612
  return (Qnil);
@@ -611,7 +624,7 @@ static VALUE rxml_document_next_q(VALUE self)
611
624
  {
612
625
  xmlDocPtr xdoc;
613
626
 
614
- Data_Get_Struct(self, xmlDoc, xdoc);
627
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
615
628
 
616
629
  if (xdoc->next == NULL)
617
630
  return (Qfalse);
@@ -627,9 +640,9 @@ static VALUE rxml_document_next_q(VALUE self)
627
640
  */
628
641
  static VALUE rxml_document_node_type(VALUE self)
629
642
  {
630
- xmlNodePtr xnode;
631
- Data_Get_Struct(self, xmlNode, xnode);
632
- return (INT2NUM(xnode->type));
643
+ xmlDocPtr xdoc;
644
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
645
+ return (INT2NUM(xdoc->type));
633
646
  }
634
647
 
635
648
  /*
@@ -642,7 +655,7 @@ static VALUE rxml_document_parent_get(VALUE self)
642
655
  {
643
656
  xmlDocPtr xdoc;
644
657
 
645
- Data_Get_Struct(self, xmlDoc, xdoc);
658
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
646
659
 
647
660
  if (xdoc->parent == NULL)
648
661
  return (Qnil);
@@ -660,7 +673,7 @@ static VALUE rxml_document_parent_q(VALUE self)
660
673
  {
661
674
  xmlDocPtr xdoc;
662
675
 
663
- Data_Get_Struct(self, xmlDoc, xdoc);
676
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
664
677
 
665
678
  if (xdoc->parent == NULL)
666
679
  return (Qfalse);
@@ -678,7 +691,7 @@ static VALUE rxml_document_prev_get(VALUE self)
678
691
  {
679
692
  xmlDocPtr xdoc;
680
693
 
681
- Data_Get_Struct(self, xmlDoc, xdoc);
694
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
682
695
 
683
696
  if (xdoc->prev == NULL)
684
697
  return (Qnil);
@@ -696,7 +709,7 @@ static VALUE rxml_document_prev_q(VALUE self)
696
709
  {
697
710
  xmlDocPtr xdoc;
698
711
 
699
- Data_Get_Struct(self, xmlDoc, xdoc);
712
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
700
713
 
701
714
  if (xdoc->prev == NULL)
702
715
  return (Qfalse);
@@ -715,7 +728,7 @@ static VALUE rxml_document_root_get(VALUE self)
715
728
  xmlDocPtr xdoc;
716
729
  xmlNodePtr root;
717
730
 
718
- Data_Get_Struct(self, xmlDoc, xdoc);
731
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
719
732
  root = xmlDocGetRootElement(xdoc);
720
733
 
721
734
  if (root == NULL)
@@ -738,8 +751,8 @@ static VALUE rxml_document_root_set(VALUE self, VALUE node)
738
751
  if (rb_obj_is_kind_of(node, cXMLNode) == Qfalse)
739
752
  rb_raise(rb_eTypeError, "must pass an XML::Node type object");
740
753
 
741
- Data_Get_Struct(self, xmlDoc, xdoc);
742
- Data_Get_Struct(node, xmlNode, xnode);
754
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
755
+ TypedData_Get_Struct(node, xmlNode, &rxml_node_data_type, xnode);
743
756
 
744
757
  if (xnode->doc != NULL && xnode->doc != xdoc)
745
758
  rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import");
@@ -784,7 +797,7 @@ static VALUE rxml_document_save(int argc, VALUE *argv, VALUE self)
784
797
  Check_Type(filename, T_STRING);
785
798
  xfilename = StringValuePtr(filename);
786
799
 
787
- Data_Get_Struct(self, xmlDoc, xdoc);
800
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
788
801
  xencoding = xdoc->encoding;
789
802
 
790
803
  if (!NIL_P(options))
@@ -823,7 +836,7 @@ static VALUE rxml_document_standalone_q(VALUE self)
823
836
  {
824
837
  xmlDocPtr xdoc;
825
838
 
826
- Data_Get_Struct(self, xmlDoc, xdoc);
839
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
827
840
  if (xdoc->standalone)
828
841
  return (Qtrue);
829
842
  else
@@ -877,7 +890,7 @@ static VALUE rxml_document_to_s(int argc, VALUE *argv, VALUE self)
877
890
  }
878
891
  }
879
892
 
880
- Data_Get_Struct(self, xmlDoc, xdoc);
893
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
881
894
  xmlDocDumpFormatMemoryEnc(xdoc, &buffer, &length, (const char*)xencoding, indent);
882
895
 
883
896
  result = rxml_new_cstr(buffer, xencoding);
@@ -895,7 +908,7 @@ static VALUE rxml_document_url_get(VALUE self)
895
908
  {
896
909
  xmlDocPtr xdoc;
897
910
 
898
- Data_Get_Struct(self, xmlDoc, xdoc);
911
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
899
912
  if (xdoc->URL == NULL)
900
913
  return (Qnil);
901
914
  else
@@ -912,7 +925,7 @@ static VALUE rxml_document_version_get(VALUE self)
912
925
  {
913
926
  xmlDocPtr xdoc;
914
927
 
915
- Data_Get_Struct(self, xmlDoc, xdoc);
928
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
916
929
  if (xdoc->version == NULL)
917
930
  return (Qnil);
918
931
  else
@@ -928,9 +941,9 @@ static VALUE rxml_document_version_get(VALUE self)
928
941
  static VALUE rxml_document_xhtml_q(VALUE self)
929
942
  {
930
943
  xmlDocPtr xdoc;
931
- xmlDtdPtr xdtd;
932
- Data_Get_Struct(self, xmlDoc, xdoc);
933
- xdtd = xmlGetIntSubset(xdoc);
944
+ xmlDtdPtr xdtd;
945
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
946
+ xdtd = xmlGetIntSubset(xdoc);
934
947
  if (xdtd != NULL && xmlIsXHTML(xdtd->SystemID, xdtd->ExternalID) > 0)
935
948
  return (Qtrue);
936
949
  else
@@ -950,7 +963,7 @@ static VALUE rxml_document_xinclude(VALUE self)
950
963
 
951
964
  int ret;
952
965
 
953
- Data_Get_Struct(self, xmlDoc, xdoc);
966
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
954
967
  ret = xmlXIncludeProcess(xdoc);
955
968
  if (ret >= 0)
956
969
  {
@@ -979,7 +992,7 @@ static VALUE rxml_document_order_elements(VALUE self)
979
992
  {
980
993
  xmlDocPtr xdoc;
981
994
 
982
- Data_Get_Struct(self, xmlDoc, xdoc);
995
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
983
996
  return LONG2FIX(xmlXPathOrderDocElems(xdoc));
984
997
  }
985
998
 
@@ -998,8 +1011,8 @@ static VALUE rxml_document_validate_schema(VALUE self, VALUE schema)
998
1011
  xmlSchemaPtr xschema;
999
1012
  int is_invalid;
1000
1013
 
1001
- Data_Get_Struct(self, xmlDoc, xdoc);
1002
- Data_Get_Struct(schema, xmlSchema, xschema);
1014
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
1015
+ TypedData_Get_Struct(schema, xmlSchema, &rxml_schema_type, xschema);
1003
1016
 
1004
1017
  vptr = xmlSchemaNewValidCtxt(xschema);
1005
1018
 
@@ -1031,8 +1044,8 @@ static VALUE rxml_document_validate_relaxng(VALUE self, VALUE relaxng)
1031
1044
  xmlRelaxNGPtr xrelaxng;
1032
1045
  int is_invalid;
1033
1046
 
1034
- Data_Get_Struct(self, xmlDoc, xdoc);
1035
- Data_Get_Struct(relaxng, xmlRelaxNG, xrelaxng);
1047
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
1048
+ TypedData_Get_Struct(relaxng, xmlRelaxNG, &rxml_relaxng_data_type, xrelaxng);
1036
1049
 
1037
1050
  vptr = xmlRelaxNGNewValidCtxt(xrelaxng);
1038
1051
 
@@ -1063,8 +1076,8 @@ static VALUE rxml_document_validate_dtd(VALUE self, VALUE dtd)
1063
1076
  xmlDocPtr xdoc;
1064
1077
  xmlDtdPtr xdtd;
1065
1078
 
1066
- Data_Get_Struct(self, xmlDoc, xdoc);
1067
- Data_Get_Struct(dtd, xmlDtd, xdtd);
1079
+ TypedData_Get_Struct(self, xmlDoc, &rxml_document_data_type, xdoc);
1080
+ TypedData_Get_Struct(dtd, xmlDtd, &rxml_dtd_data_type, xdtd);
1068
1081
 
1069
1082
  /* Setup context */
1070
1083
  memset(&ctxt, 0, sizeof(xmlValidCtxt));
@@ -4,6 +4,7 @@
4
4
  #define __RXML_DOCUMENT__
5
5
 
6
6
  extern VALUE cXMLDocument;
7
+ extern const rb_data_type_t rxml_document_data_type;
7
8
  void rxml_init_document(void);
8
9
  VALUE rxml_document_wrap(xmlDocPtr xnode);
9
10
 
@@ -28,31 +28,52 @@
28
28
  * instance.validate(dtd)
29
29
  */
30
30
 
31
+ #ifndef TYPED_DATA_EMBEDDED
32
+ #define TYPED_DATA_EMBEDDED ((VALUE)1)
33
+ #endif
34
+
31
35
  VALUE cXMLDtd;
32
36
 
33
- void rxml_dtd_free(xmlDtdPtr xdtd)
37
+ static void rxml_dtd_free(void* data)
34
38
  {
39
+ xmlDtdPtr xdtd = (xmlDtdPtr)data;
40
+ if (!xdtd) return;
35
41
  if (xdtd->doc == NULL && xdtd->parent == NULL)
36
42
  xmlFreeDtd(xdtd);
37
43
  }
38
44
 
39
- void rxml_dtd_mark(xmlDtdPtr xdtd)
45
+ static void rxml_dtd_mark(void* data)
40
46
  {
47
+ xmlDtdPtr xdtd = (xmlDtdPtr)data;
41
48
  if (xdtd && xdtd->doc)
42
49
  {
43
- VALUE doc = (VALUE)xdtd->doc->_private;
44
- rb_gc_mark(doc);
50
+ VALUE doc = rxml_registry_lookup(xdtd->doc);
51
+ if (!NIL_P(doc))
52
+ rb_gc_mark(doc);
45
53
  }
46
54
  }
47
55
 
56
+ const rb_data_type_t rxml_dtd_data_type = {
57
+ .wrap_struct_name = "LibXML::XML::Dtd",
58
+ .function = { .dmark = rxml_dtd_mark, .dfree = NULL },
59
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
60
+ };
61
+
62
+ static const rb_data_type_t rxml_dtd_managed_data_type = {
63
+ .wrap_struct_name = "LibXML::XML::Dtd (managed)",
64
+ .function = { .dmark = rxml_dtd_mark, .dfree = rxml_dtd_free },
65
+ .parent = &rxml_dtd_data_type,
66
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
67
+ };
68
+
48
69
  static VALUE rxml_dtd_alloc(VALUE klass)
49
70
  {
50
- return Data_Wrap_Struct(klass, rxml_dtd_mark, rxml_dtd_free, NULL);
71
+ return TypedData_Wrap_Struct(klass, &rxml_dtd_managed_data_type, NULL);
51
72
  }
52
73
 
53
74
  VALUE rxml_dtd_wrap(xmlDtdPtr xdtd)
54
75
  {
55
- return Data_Wrap_Struct(cXMLDtd, NULL, NULL, xdtd);
76
+ return TypedData_Wrap_Struct(cXMLDtd, &rxml_dtd_data_type, xdtd);
56
77
  }
57
78
 
58
79
  /*
@@ -64,7 +85,7 @@ VALUE rxml_dtd_wrap(xmlDtdPtr xdtd)
64
85
  static VALUE rxml_dtd_external_id_get(VALUE self)
65
86
  {
66
87
  xmlDtdPtr xdtd;
67
- Data_Get_Struct(self, xmlDtd, xdtd);
88
+ TypedData_Get_Struct(self, xmlDtd, &rxml_dtd_data_type, xdtd);
68
89
 
69
90
 
70
91
  if (xdtd->ExternalID == NULL)
@@ -82,7 +103,7 @@ static VALUE rxml_dtd_external_id_get(VALUE self)
82
103
  static VALUE rxml_dtd_name_get(VALUE self)
83
104
  {
84
105
  xmlDtdPtr xdtd;
85
- Data_Get_Struct(self, xmlDtd, xdtd);
106
+ TypedData_Get_Struct(self, xmlDtd, &rxml_dtd_data_type, xdtd);
86
107
 
87
108
 
88
109
  if (xdtd->name == NULL)
@@ -101,7 +122,7 @@ static VALUE rxml_dtd_name_get(VALUE self)
101
122
  static VALUE rxml_dtd_uri_get(VALUE self)
102
123
  {
103
124
  xmlDtdPtr xdtd;
104
- Data_Get_Struct(self, xmlDtd, xdtd);
125
+ TypedData_Get_Struct(self, xmlDtd, &rxml_dtd_data_type, xdtd);
105
126
 
106
127
  if (xdtd->SystemID == NULL)
107
128
  return (Qnil);
@@ -118,7 +139,7 @@ static VALUE rxml_dtd_uri_get(VALUE self)
118
139
  static VALUE rxml_dtd_type(VALUE self)
119
140
  {
120
141
  xmlDtdPtr xdtd;
121
- Data_Get_Struct(self, xmlDtd, xdtd);
142
+ TypedData_Get_Struct(self, xmlDtd, &rxml_dtd_data_type, xdtd);
122
143
  return (INT2NUM(xdtd->type));
123
144
  }
124
145
 
@@ -162,11 +183,17 @@ static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
162
183
  VALUE name, doc, internal;
163
184
  rb_scan_args(argc, argv, "23", &external, &system, &name, &doc, &internal);
164
185
 
165
- Check_Type(external, T_STRING);
166
- xpublic = (const xmlChar*) StringValuePtr(external);
186
+ if (external != Qnil)
187
+ {
188
+ Check_Type(external, T_STRING);
189
+ xpublic = (const xmlChar*) StringValuePtr(external);
190
+ }
167
191
 
168
- Check_Type(system, T_STRING);
169
- xsystem = (const xmlChar*) StringValuePtr(system);
192
+ if (system != Qnil)
193
+ {
194
+ Check_Type(system, T_STRING);
195
+ xsystem = (const xmlChar*) StringValuePtr(system);
196
+ }
170
197
 
171
198
  if (name != Qnil)
172
199
  {
@@ -178,7 +205,7 @@ static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
178
205
  {
179
206
  if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse)
180
207
  rb_raise(rb_eTypeError, "Must pass an LibXML::XML::Document object");
181
- Data_Get_Struct(doc, xmlDoc, xdoc);
208
+ TypedData_Get_Struct(doc, xmlDoc, &rxml_document_data_type, xdoc);
182
209
  }
183
210
 
184
211
  if (internal == Qnil || internal == Qfalse)
@@ -190,8 +217,11 @@ static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
190
217
  rxml_raise(xmlGetLastError());
191
218
 
192
219
  /* The document will free the dtd so Ruby should not */
193
- RDATA(self)->dfree = NULL;
194
- DATA_PTR(self) = xdtd;
220
+ {
221
+ VALUE *type_ptr = (VALUE *)&RTYPEDDATA(self)->type;
222
+ *type_ptr = (*type_ptr & TYPED_DATA_EMBEDDED) | (VALUE)&rxml_dtd_data_type;
223
+ }
224
+ RTYPEDDATA_DATA(self) = xdtd;
195
225
 
196
226
  xmlSetTreeDoc((xmlNodePtr) xdtd, xdoc);
197
227
  }
@@ -209,7 +239,7 @@ static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
209
239
  if (xdtd == NULL)
210
240
  rxml_raise(xmlGetLastError());
211
241
 
212
- DATA_PTR(self) = xdtd;
242
+ RTYPEDDATA_DATA(self) = xdtd;
213
243
 
214
244
  xmlSetTreeDoc((xmlNodePtr) xdtd, NULL);
215
245
  break;
@@ -234,7 +264,7 @@ static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
234
264
 
235
265
  xmlFree(new_string);
236
266
 
237
- DATA_PTR(self) = xdtd;
267
+ RTYPEDDATA_DATA(self) = xdtd;
238
268
  break;
239
269
  }
240
270
  default:
@@ -2,6 +2,7 @@
2
2
  #define __RXML_DTD__
3
3
 
4
4
  extern VALUE cXMLDtd;
5
+ extern const rb_data_type_t rxml_dtd_data_type;
5
6
 
6
7
  void rxml_init_dtd(void);
7
8
  VALUE rxml_dtd_wrap(xmlDtdPtr xdtd);
@@ -64,7 +64,7 @@ static VALUE rxml_html_parser_parse(VALUE self)
64
64
  xmlParserCtxtPtr ctxt;
65
65
  VALUE context = rb_ivar_get(self, CONTEXT_ATTR);
66
66
 
67
- Data_Get_Struct(context, xmlParserCtxt, ctxt);
67
+ TypedData_Get_Struct(context, xmlParserCtxt, &rxml_html_parser_context_type, ctxt);
68
68
 
69
69
  if (htmlParseDocument(ctxt) == -1 && ! ctxt->recovery)
70
70
  {