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
@@ -15,21 +15,28 @@ static ID IO_ATTR;
15
15
  * a document is parsed.
16
16
  */
17
17
 
18
- static void rxml_parser_context_free(xmlParserCtxtPtr ctxt)
18
+ static void rxml_parser_context_free(void* data)
19
19
  {
20
+ xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)data;
20
21
  xmlFreeParserCtxt(ctxt);
21
22
  }
22
23
 
24
+ const rb_data_type_t rxml_parser_context_type = {
25
+ "LibXML::XML::Parser::Context",
26
+ {NULL, rxml_parser_context_free, NULL},
27
+ NULL, NULL, 0
28
+ };
29
+
23
30
  static VALUE rxml_parser_context_wrap(xmlParserCtxtPtr ctxt)
24
31
  {
25
- return Data_Wrap_Struct(cXMLParserContext, NULL, rxml_parser_context_free, ctxt);
32
+ return TypedData_Wrap_Struct(cXMLParserContext, &rxml_parser_context_type, ctxt);
26
33
  }
27
34
 
28
35
 
29
36
  static VALUE rxml_parser_context_alloc(VALUE klass)
30
37
  {
31
38
  xmlParserCtxtPtr ctxt = xmlNewParserCtxt();
32
- return Data_Wrap_Struct(klass, NULL, rxml_parser_context_free, ctxt);
39
+ return TypedData_Wrap_Struct(klass, &rxml_parser_context_type, ctxt);
33
40
  }
34
41
 
35
42
  /* call-seq:
@@ -53,7 +60,7 @@ static VALUE rxml_parser_context_document(int argc, VALUE* argv, VALUE klass)
53
60
  xmlDocPtr xdoc;
54
61
  xmlChar *buffer;
55
62
  int length;
56
- Data_Get_Struct(document, xmlDoc, xdoc);
63
+ TypedData_Get_Struct(document, xmlDoc, &rxml_document_data_type, xdoc);
57
64
  xmlDocDumpFormatMemoryEnc(xdoc, &buffer, &length, (const char*)xdoc->encoding, 0);
58
65
 
59
66
  xmlParserCtxtPtr ctxt = xmlCreateDocParserCtxt(buffer);
@@ -194,7 +201,7 @@ static VALUE rxml_parser_context_io(int argc, VALUE* argv, VALUE klass)
194
201
  static VALUE rxml_parser_context_base_uri_get(VALUE self)
195
202
  {
196
203
  xmlParserCtxtPtr ctxt;
197
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
204
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
198
205
 
199
206
  if (ctxt->input && ctxt->input->filename)
200
207
  return rxml_new_cstr((const xmlChar*)ctxt->input->filename, ctxt->encoding);
@@ -211,7 +218,7 @@ static VALUE rxml_parser_context_base_uri_get(VALUE self)
211
218
  static VALUE rxml_parser_context_base_uri_set(VALUE self, VALUE url)
212
219
  {
213
220
  xmlParserCtxtPtr ctxt;
214
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
221
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
215
222
 
216
223
  Check_Type(url, T_STRING);
217
224
 
@@ -235,7 +242,7 @@ static VALUE rxml_parser_context_close(VALUE self)
235
242
  {
236
243
  xmlParserCtxtPtr ctxt;
237
244
  xmlParserInputPtr xinput;
238
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
245
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
239
246
 
240
247
  while ((xinput = inputPop(ctxt)) != NULL)
241
248
  {
@@ -253,7 +260,7 @@ static VALUE rxml_parser_context_close(VALUE self)
253
260
  static VALUE rxml_parser_context_data_directory_get(VALUE self)
254
261
  {
255
262
  xmlParserCtxtPtr ctxt;
256
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
263
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
257
264
 
258
265
  if (ctxt->directory == NULL)
259
266
  return (Qnil);
@@ -270,7 +277,7 @@ static VALUE rxml_parser_context_data_directory_get(VALUE self)
270
277
  static VALUE rxml_parser_context_depth_get(VALUE self)
271
278
  {
272
279
  xmlParserCtxtPtr ctxt;
273
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
280
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
274
281
 
275
282
  return (INT2NUM(ctxt->depth));
276
283
  }
@@ -284,7 +291,7 @@ static VALUE rxml_parser_context_depth_get(VALUE self)
284
291
  static VALUE rxml_parser_context_disable_cdata_q(VALUE self)
285
292
  {
286
293
  xmlParserCtxtPtr ctxt;
287
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
294
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
288
295
 
289
296
  /* LibXML controls this internally with the default SAX handler. */
290
297
  if (ctxt->sax && ctxt->sax->cdataBlock)
@@ -302,7 +309,7 @@ static VALUE rxml_parser_context_disable_cdata_q(VALUE self)
302
309
  static VALUE rxml_parser_context_disable_cdata_set(VALUE self, VALUE value)
303
310
  {
304
311
  xmlParserCtxtPtr ctxt;
305
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
312
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
306
313
 
307
314
  if (ctxt->sax == NULL)
308
315
  rb_raise(rb_eRuntimeError, "Sax handler is not yet set");
@@ -326,7 +333,7 @@ static VALUE rxml_parser_context_disable_cdata_set(VALUE self, VALUE value)
326
333
  static VALUE rxml_parser_context_disable_sax_q(VALUE self)
327
334
  {
328
335
  xmlParserCtxtPtr ctxt;
329
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
336
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
330
337
 
331
338
  if (ctxt->disableSAX)
332
339
  return (Qtrue);
@@ -343,7 +350,7 @@ static VALUE rxml_parser_context_disable_sax_q(VALUE self)
343
350
  static VALUE rxml_parser_context_docbook_q(VALUE self)
344
351
  {
345
352
  xmlParserCtxtPtr ctxt;
346
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
353
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
347
354
 
348
355
  if (ctxt->html == 2) // TODO check this
349
356
  return (Qtrue);
@@ -361,7 +368,7 @@ static VALUE rxml_parser_context_docbook_q(VALUE self)
361
368
  static VALUE rxml_parser_context_encoding_get(VALUE self)
362
369
  {
363
370
  xmlParserCtxtPtr ctxt;
364
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
371
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
365
372
  return INT2NUM(xmlParseCharEncoding((const char*)ctxt->encoding));
366
373
  }
367
374
 
@@ -381,7 +388,7 @@ static VALUE rxml_parser_context_encoding_set(VALUE self, VALUE encoding)
381
388
  if (!hdlr)
382
389
  rb_raise(rb_eArgError, "Unknown encoding: %i", NUM2INT(encoding));
383
390
 
384
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
391
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
385
392
  result = xmlSwitchToEncoding(ctxt, hdlr);
386
393
 
387
394
  if (result != 0)
@@ -403,7 +410,7 @@ static VALUE rxml_parser_context_encoding_set(VALUE self, VALUE encoding)
403
410
  static VALUE rxml_parser_context_errno_get(VALUE self)
404
411
  {
405
412
  xmlParserCtxtPtr ctxt;
406
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
413
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
407
414
 
408
415
  return (INT2NUM(ctxt->errNo));
409
416
  }
@@ -417,7 +424,7 @@ static VALUE rxml_parser_context_errno_get(VALUE self)
417
424
  static VALUE rxml_parser_context_html_q(VALUE self)
418
425
  {
419
426
  xmlParserCtxtPtr ctxt;
420
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
427
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
421
428
 
422
429
  if (ctxt->html == 1)
423
430
  return (Qtrue);
@@ -436,7 +443,7 @@ static VALUE rxml_parser_context_io_max_num_streams_get(VALUE self)
436
443
  {
437
444
  // TODO alias to max_streams and dep this?
438
445
  xmlParserCtxtPtr ctxt;
439
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
446
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
440
447
 
441
448
  return (INT2NUM(ctxt->inputMax));
442
449
  }
@@ -451,7 +458,7 @@ static VALUE rxml_parser_context_io_max_num_streams_get(VALUE self)
451
458
  static VALUE rxml_parser_context_io_num_streams_get(VALUE self)
452
459
  {
453
460
  xmlParserCtxtPtr ctxt;
454
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
461
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
455
462
 
456
463
  return (INT2NUM(ctxt->inputNr));
457
464
  }
@@ -466,7 +473,7 @@ static VALUE rxml_parser_context_io_num_streams_get(VALUE self)
466
473
  static VALUE rxml_parser_context_keep_blanks_q(VALUE self)
467
474
  {
468
475
  xmlParserCtxtPtr ctxt;
469
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
476
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
470
477
 
471
478
  if (ctxt->keepBlanks)
472
479
  return (Qtrue);
@@ -483,7 +490,7 @@ static VALUE rxml_parser_context_keep_blanks_q(VALUE self)
483
490
  static VALUE rxml_parser_context_name_depth_get(VALUE self)
484
491
  {
485
492
  xmlParserCtxtPtr ctxt;
486
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
493
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
487
494
 
488
495
  return (INT2NUM(ctxt->nameNr));
489
496
  }
@@ -497,7 +504,7 @@ static VALUE rxml_parser_context_name_depth_get(VALUE self)
497
504
  static VALUE rxml_parser_context_name_depth_max_get(VALUE self)
498
505
  {
499
506
  xmlParserCtxtPtr ctxt;
500
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
507
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
501
508
 
502
509
  return (INT2NUM(ctxt->nameMax));
503
510
  }
@@ -511,7 +518,7 @@ static VALUE rxml_parser_context_name_depth_max_get(VALUE self)
511
518
  static VALUE rxml_parser_context_name_node_get(VALUE self)
512
519
  {
513
520
  xmlParserCtxtPtr ctxt;
514
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
521
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
515
522
 
516
523
  if (ctxt->name == NULL)
517
524
  return (Qnil);
@@ -531,7 +538,7 @@ static VALUE rxml_parser_context_name_tab_get(VALUE self)
531
538
  xmlParserCtxtPtr ctxt;
532
539
  VALUE tab_ary;
533
540
 
534
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
541
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
535
542
 
536
543
  if (ctxt->nameTab == NULL)
537
544
  return (Qnil);
@@ -558,7 +565,7 @@ static VALUE rxml_parser_context_name_tab_get(VALUE self)
558
565
  static VALUE rxml_parser_context_node_depth_get(VALUE self)
559
566
  {
560
567
  xmlParserCtxtPtr ctxt;
561
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
568
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
562
569
 
563
570
  return (INT2NUM(ctxt->nodeNr));
564
571
  }
@@ -572,7 +579,7 @@ static VALUE rxml_parser_context_node_depth_get(VALUE self)
572
579
  static VALUE rxml_parser_context_node_get(VALUE self)
573
580
  {
574
581
  xmlParserCtxtPtr ctxt;
575
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
582
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
576
583
 
577
584
  if (ctxt->node == NULL)
578
585
  return (Qnil);
@@ -589,7 +596,7 @@ static VALUE rxml_parser_context_node_get(VALUE self)
589
596
  static VALUE rxml_parser_context_node_depth_max_get(VALUE self)
590
597
  {
591
598
  xmlParserCtxtPtr ctxt;
592
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
599
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
593
600
 
594
601
  return (INT2NUM(ctxt->nodeMax));
595
602
  }
@@ -603,7 +610,7 @@ static VALUE rxml_parser_context_node_depth_max_get(VALUE self)
603
610
  static VALUE rxml_parser_context_num_chars_get(VALUE self)
604
611
  {
605
612
  xmlParserCtxtPtr ctxt;
606
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
613
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
607
614
 
608
615
  return (LONG2NUM(ctxt->nbChars));
609
616
  }
@@ -619,7 +626,7 @@ static VALUE rxml_parser_context_num_chars_get(VALUE self)
619
626
  static VALUE rxml_parser_context_options_get(VALUE self)
620
627
  {
621
628
  xmlParserCtxtPtr ctxt;
622
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
629
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
623
630
 
624
631
  return INT2NUM(ctxt->options);
625
632
  }
@@ -638,7 +645,7 @@ static VALUE rxml_parser_context_options_set(VALUE self, VALUE options)
638
645
  xmlParserCtxtPtr ctxt;
639
646
  Check_Type(options, T_FIXNUM);
640
647
 
641
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
648
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
642
649
  xmlCtxtUseOptions(ctxt, NUM2INT(options));
643
650
 
644
651
  return self;
@@ -654,7 +661,7 @@ static VALUE rxml_parser_context_options_set(VALUE self, VALUE options)
654
661
  static VALUE rxml_parser_context_recovery_q(VALUE self)
655
662
  {
656
663
  xmlParserCtxtPtr ctxt;
657
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
664
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
658
665
 
659
666
  if (ctxt->recovery)
660
667
  return (Qtrue);
@@ -672,7 +679,7 @@ static VALUE rxml_parser_context_recovery_q(VALUE self)
672
679
  static VALUE rxml_parser_context_recovery_set(VALUE self, VALUE value)
673
680
  {
674
681
  xmlParserCtxtPtr ctxt;
675
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
682
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
676
683
 
677
684
  if (value == Qfalse)
678
685
  {
@@ -696,7 +703,7 @@ static VALUE rxml_parser_context_recovery_set(VALUE self, VALUE value)
696
703
  static VALUE rxml_parser_context_replace_entities_q(VALUE self)
697
704
  {
698
705
  xmlParserCtxtPtr ctxt;
699
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
706
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
700
707
 
701
708
  if (ctxt->replaceEntities)
702
709
  return (Qtrue);
@@ -714,7 +721,7 @@ static VALUE rxml_parser_context_replace_entities_q(VALUE self)
714
721
  static VALUE rxml_parser_context_replace_entities_set(VALUE self, VALUE value)
715
722
  {
716
723
  xmlParserCtxtPtr ctxt;
717
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
724
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
718
725
 
719
726
  if (value == Qfalse)
720
727
  {
@@ -737,7 +744,7 @@ static VALUE rxml_parser_context_replace_entities_set(VALUE self, VALUE value)
737
744
  static VALUE rxml_parser_context_space_depth_get(VALUE self)
738
745
  {
739
746
  xmlParserCtxtPtr ctxt;
740
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
747
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
741
748
 
742
749
  return (INT2NUM(ctxt->spaceNr));
743
750
  }
@@ -751,7 +758,7 @@ static VALUE rxml_parser_context_space_depth_get(VALUE self)
751
758
  static VALUE rxml_parser_context_space_depth_max_get(VALUE self)
752
759
  {
753
760
  xmlParserCtxtPtr ctxt;
754
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
761
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
755
762
 
756
763
  return (INT2NUM(ctxt->spaceMax));
757
764
  }
@@ -766,7 +773,7 @@ static VALUE rxml_parser_context_space_depth_max_get(VALUE self)
766
773
  static VALUE rxml_parser_context_subset_external_q(VALUE self)
767
774
  {
768
775
  xmlParserCtxtPtr ctxt;
769
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
776
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
770
777
 
771
778
  if (ctxt->inSubset == 2)
772
779
  return (Qtrue);
@@ -784,7 +791,7 @@ static VALUE rxml_parser_context_subset_external_q(VALUE self)
784
791
  static VALUE rxml_parser_context_subset_internal_q(VALUE self)
785
792
  {
786
793
  xmlParserCtxtPtr ctxt;
787
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
794
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
788
795
 
789
796
  if (ctxt->inSubset == 1)
790
797
  return (Qtrue);
@@ -803,7 +810,7 @@ static VALUE rxml_parser_context_subset_internal_q(VALUE self)
803
810
  static VALUE rxml_parser_context_subset_name_get(VALUE self)
804
811
  {
805
812
  xmlParserCtxtPtr ctxt;
806
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
813
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
807
814
 
808
815
  if (ctxt->intSubName == NULL)
809
816
  return (Qnil);
@@ -822,7 +829,7 @@ static VALUE rxml_parser_context_subset_name_get(VALUE self)
822
829
  static VALUE rxml_parser_context_subset_external_uri_get(VALUE self)
823
830
  {
824
831
  xmlParserCtxtPtr ctxt;
825
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
832
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
826
833
 
827
834
  if (ctxt->extSubURI == NULL)
828
835
  return (Qnil);
@@ -841,7 +848,7 @@ static VALUE rxml_parser_context_subset_external_uri_get(VALUE self)
841
848
  static VALUE rxml_parser_context_subset_external_system_id_get(VALUE self)
842
849
  {
843
850
  xmlParserCtxtPtr ctxt;
844
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
851
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
845
852
 
846
853
  if (ctxt->extSubSystem == NULL)
847
854
  return (Qnil);
@@ -858,7 +865,7 @@ static VALUE rxml_parser_context_subset_external_system_id_get(VALUE self)
858
865
  static VALUE rxml_parser_context_standalone_q(VALUE self)
859
866
  {
860
867
  xmlParserCtxtPtr ctxt;
861
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
868
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
862
869
 
863
870
  if (ctxt->standalone)
864
871
  return (Qtrue);
@@ -875,7 +882,7 @@ static VALUE rxml_parser_context_standalone_q(VALUE self)
875
882
  static VALUE rxml_parser_context_stats_q(VALUE self)
876
883
  {
877
884
  xmlParserCtxtPtr ctxt;
878
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
885
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
879
886
 
880
887
  if (ctxt->record_info)
881
888
  return (Qtrue);
@@ -892,7 +899,7 @@ static VALUE rxml_parser_context_stats_q(VALUE self)
892
899
  static VALUE rxml_parser_context_valid_q(VALUE self)
893
900
  {
894
901
  xmlParserCtxtPtr ctxt;
895
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
902
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
896
903
 
897
904
  if (ctxt->valid)
898
905
  return (Qtrue);
@@ -909,7 +916,7 @@ static VALUE rxml_parser_context_valid_q(VALUE self)
909
916
  static VALUE rxml_parser_context_validate_q(VALUE self)
910
917
  {
911
918
  xmlParserCtxtPtr ctxt;
912
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
919
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
913
920
 
914
921
  if (ctxt->validate)
915
922
  return (Qtrue);
@@ -926,7 +933,7 @@ static VALUE rxml_parser_context_validate_q(VALUE self)
926
933
  static VALUE rxml_parser_context_version_get(VALUE self)
927
934
  {
928
935
  xmlParserCtxtPtr ctxt;
929
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
936
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
930
937
 
931
938
  if (ctxt->version == NULL)
932
939
  return (Qnil);
@@ -943,7 +950,7 @@ static VALUE rxml_parser_context_version_get(VALUE self)
943
950
  static VALUE rxml_parser_context_well_formed_q(VALUE self)
944
951
  {
945
952
  xmlParserCtxtPtr ctxt;
946
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
953
+ TypedData_Get_Struct(self, xmlParserCtxt, &rxml_parser_context_type, ctxt);
947
954
 
948
955
  if (ctxt->wellFormed)
949
956
  return (Qtrue);
@@ -4,6 +4,7 @@
4
4
  #define __RXML_PARSER_CONTEXT__
5
5
 
6
6
  extern VALUE cXMLParserContext;
7
+ extern const rb_data_type_t rxml_parser_context_type;
7
8
 
8
9
  void rxml_init_parser_context(void);
9
10
 
@@ -9,6 +9,7 @@
9
9
  #include <libxml/xmlreader.h>
10
10
  #include <libxml/xmlschemas.h>
11
11
 
12
+
12
13
  /*
13
14
  * Document-class: LibXML::XML::Reader
14
15
  *
@@ -59,28 +60,40 @@ static ID ENCODING_SYMBOL;
59
60
  static ID IO_ATTR;
60
61
  static ID OPTIONS_SYMBOL;
61
62
 
62
- static void rxml_reader_free(xmlTextReaderPtr xreader)
63
+ static void rxml_reader_free(void* data)
63
64
  {
65
+ xmlTextReaderPtr xreader = (xmlTextReaderPtr)data;
64
66
  xmlFreeTextReader(xreader);
65
67
  }
66
68
 
67
- static void rxml_reader_mark(xmlTextReaderPtr xreader)
69
+ static void rxml_reader_mark(void* data)
68
70
  {
71
+ xmlTextReaderPtr xreader = (xmlTextReaderPtr)data;
69
72
  xmlDocPtr xdoc = xmlTextReaderCurrentDoc(xreader);
70
- VALUE doc = (VALUE)xdoc->_private;
71
- rb_gc_mark(doc);
73
+ if (xdoc)
74
+ {
75
+ VALUE doc = rxml_registry_lookup(xdoc);
76
+ if (!NIL_P(doc))
77
+ rb_gc_mark(doc);
78
+ }
72
79
  }
73
80
 
81
+ static const rb_data_type_t rxml_reader_data_type = {
82
+ .wrap_struct_name = "LibXML::XML::Reader",
83
+ .function = { .dmark = rxml_reader_mark, .dfree = rxml_reader_free },
84
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
85
+ };
86
+
74
87
  static VALUE rxml_reader_wrap(xmlTextReaderPtr xreader)
75
88
  {
76
- return Data_Wrap_Struct(cXMLReader, NULL, rxml_reader_free, xreader);
89
+ return TypedData_Wrap_Struct(cXMLReader, &rxml_reader_data_type, xreader);
77
90
  }
78
91
 
79
92
 
80
93
  static xmlTextReaderPtr rxml_text_reader_get(VALUE obj)
81
94
  {
82
95
  xmlTextReaderPtr xreader;
83
- Data_Get_Struct(obj, xmlTextReader, xreader);
96
+ TypedData_Get_Struct(obj, xmlTextReader, &rxml_reader_data_type, xreader);
84
97
  return xreader;
85
98
  }
86
99
 
@@ -95,7 +108,7 @@ VALUE rxml_reader_document(VALUE klass, VALUE doc)
95
108
  xmlDocPtr xdoc;
96
109
  xmlTextReaderPtr xreader;
97
110
 
98
- Data_Get_Struct(doc, xmlDoc, xdoc);
111
+ TypedData_Get_Struct(doc, xmlDoc, &rxml_document_data_type, xdoc);
99
112
 
100
113
  xreader = xmlReaderWalker(xdoc);
101
114
 
@@ -606,7 +619,7 @@ static VALUE rxml_reader_relax_ng_validate(VALUE self, VALUE rng)
606
619
  xmlTextReaderPtr xreader = rxml_text_reader_get(self);
607
620
  xmlRelaxNGPtr xrelax;
608
621
  int status;
609
- Data_Get_Struct(rng, xmlRelaxNG, xrelax);
622
+ TypedData_Get_Struct(rng, xmlRelaxNG, &rxml_relaxng_data_type, xrelax);
610
623
 
611
624
  status = xmlTextReaderRelaxNGSetSchema(xreader, xrelax);
612
625
  return (status == 0 ? Qtrue : Qfalse);
@@ -631,7 +644,7 @@ rxml_reader_schema_validate(VALUE self, VALUE xsd)
631
644
  xmlSchemaPtr xschema;
632
645
  int status;
633
646
 
634
- Data_Get_Struct(xsd, xmlSchema, xschema);
647
+ TypedData_Get_Struct(xsd, xmlSchema, &rxml_schema_type, xschema);
635
648
  status = xmlTextReaderSetSchema(xreader, xschema);
636
649
  return (status == 0 ? Qtrue : Qfalse);
637
650
  }
@@ -997,12 +1010,12 @@ static VALUE rxml_reader_expand(VALUE self)
997
1010
  }
998
1011
  else
999
1012
  {
1000
- /* We cannot call rxml_node_wrap here because its sets up a mark function
1013
+ /* We cannot call rxml_node_wrap here because it sets up a mark function
1001
1014
  for the node. But according to the libxml docs (http://xmlsoft.org/html/libxml-xmlreader.html#xmlTextReaderExpand)
1002
1015
  this is only valid until the next xmlTextReaderRead call. At that point the node is freed (from reading
1003
- the libxml2 source code. So don't set a mark or free function, because they will get called in the next
1016
+ the libxml2 source code). So don't set a mark or free function, because they will get called in the next
1004
1017
  garbage collection run and cause a segfault.*/
1005
- return Data_Wrap_Struct(cXMLNode, NULL, NULL, xnode);
1018
+ return TypedData_Wrap_Struct(cXMLNode, &rxml_node_unmanaged_data_type, xnode);
1006
1019
  }
1007
1020
  }
1008
1021
 
@@ -1027,9 +1040,6 @@ static VALUE rxml_reader_doc(VALUE self)
1027
1040
 
1028
1041
  result = rxml_document_wrap(xdoc);
1029
1042
 
1030
- // And now hook in a mark function to keep the document alive as long as the reader is valid
1031
- RDATA(self)->dmark = (RUBY_DATA_FUNC)rxml_reader_mark;
1032
-
1033
1043
  return result;
1034
1044
  }
1035
1045
 
@@ -0,0 +1,31 @@
1
+ /* Please see the LICENSE file for copyright and distribution information */
2
+
3
+ #include "ruby_libxml.h"
4
+ #include "ruby_xml_registry.h"
5
+
6
+ #include <ruby/st.h>
7
+
8
+ static st_table *rxml_registry;
9
+
10
+ void rxml_init_registry(void)
11
+ {
12
+ rxml_registry = st_init_numtable();
13
+ }
14
+
15
+ void rxml_registry_register(void *ptr, VALUE obj)
16
+ {
17
+ st_insert(rxml_registry, (st_data_t)ptr, (st_data_t)obj);
18
+ }
19
+
20
+ void rxml_registry_unregister(void *ptr)
21
+ {
22
+ st_delete(rxml_registry, (st_data_t *)&ptr, NULL);
23
+ }
24
+
25
+ VALUE rxml_registry_lookup(void *ptr)
26
+ {
27
+ st_data_t val;
28
+ if (st_lookup(rxml_registry, (st_data_t)ptr, &val))
29
+ return (VALUE)val;
30
+ return Qnil;
31
+ }
@@ -0,0 +1,22 @@
1
+ /* Please see the LICENSE file for copyright and distribution information */
2
+
3
+ #ifndef __RXML_REGISTRY__
4
+ #define __RXML_REGISTRY__
5
+
6
+ /* Pointer-to-VALUE registry for mapping C structs (xmlDocPtr, xmlNodePtr,
7
+ etc.) back to their Ruby wrappers.
8
+
9
+ The registry is a global st_table keyed by C pointer address. It is NOT a
10
+ GC root -- entries do not prevent garbage collection. Objects stay alive
11
+ through the normal mark chains (mark functions look up the registry instead
12
+ of reading _private).
13
+
14
+ Registered pointers MUST be unregistered before the underlying C struct is
15
+ freed, typically in the wrapper's dfree function. */
16
+
17
+ void rxml_init_registry(void);
18
+ void rxml_registry_register(void *ptr, VALUE obj);
19
+ void rxml_registry_unregister(void *ptr);
20
+ VALUE rxml_registry_lookup(void *ptr); /* Qnil on miss */
21
+
22
+ #endif
@@ -34,11 +34,18 @@
34
34
 
35
35
  VALUE cXMLRelaxNG;
36
36
 
37
- static void rxml_relaxng_free(xmlRelaxNGPtr xrelaxng)
37
+ static void rxml_relaxng_free(void* data)
38
38
  {
39
+ xmlRelaxNGPtr xrelaxng = (xmlRelaxNGPtr)data;
39
40
  xmlRelaxNGFree(xrelaxng);
40
41
  }
41
42
 
43
+ const rb_data_type_t rxml_relaxng_data_type = {
44
+ .wrap_struct_name = "LibXML::XML::RelaxNG",
45
+ .function = { .dmark = NULL, .dfree = rxml_relaxng_free },
46
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
47
+ };
48
+
42
49
  /*
43
50
  * call-seq:
44
51
  * XML::Relaxng.new(relaxng_uri) -> relaxng
@@ -56,7 +63,10 @@ static VALUE rxml_relaxng_init_from_uri(VALUE class, VALUE uri)
56
63
  xrelaxng = xmlRelaxNGParse(xparser);
57
64
  xmlRelaxNGFreeParserCtxt(xparser);
58
65
 
59
- return Data_Wrap_Struct(cXMLRelaxNG, NULL, rxml_relaxng_free, xrelaxng);
66
+ if (!xrelaxng)
67
+ rxml_raise(xmlGetLastError());
68
+
69
+ return TypedData_Wrap_Struct(cXMLRelaxNG, &rxml_relaxng_data_type, xrelaxng);
60
70
  }
61
71
 
62
72
  /*
@@ -71,13 +81,16 @@ static VALUE rxml_relaxng_init_from_document(VALUE class, VALUE document)
71
81
  xmlRelaxNGPtr xrelaxng;
72
82
  xmlRelaxNGParserCtxtPtr xparser;
73
83
 
74
- Data_Get_Struct(document, xmlDoc, xdoc);
84
+ TypedData_Get_Struct(document, xmlDoc, &rxml_document_data_type, xdoc);
75
85
 
76
86
  xparser = xmlRelaxNGNewDocParserCtxt(xdoc);
77
87
  xrelaxng = xmlRelaxNGParse(xparser);
78
88
  xmlRelaxNGFreeParserCtxt(xparser);
79
89
 
80
- return Data_Wrap_Struct(cXMLRelaxNG, NULL, rxml_relaxng_free, xrelaxng);
90
+ if (!xrelaxng)
91
+ rxml_raise(xmlGetLastError());
92
+
93
+ return TypedData_Wrap_Struct(cXMLRelaxNG, &rxml_relaxng_data_type, xrelaxng);
81
94
  }
82
95
 
83
96
  /*
@@ -97,7 +110,10 @@ static VALUE rxml_relaxng_init_from_string(VALUE self, VALUE relaxng_str)
97
110
  xrelaxng = xmlRelaxNGParse(xparser);
98
111
  xmlRelaxNGFreeParserCtxt(xparser);
99
112
 
100
- return Data_Wrap_Struct(cXMLRelaxNG, NULL, rxml_relaxng_free, xrelaxng);
113
+ if (!xrelaxng)
114
+ rxml_raise(xmlGetLastError());
115
+
116
+ return TypedData_Wrap_Struct(cXMLRelaxNG, &rxml_relaxng_data_type, xrelaxng);
101
117
  }
102
118
 
103
119
  void rxml_init_relaxng(void)
@@ -2,6 +2,7 @@
2
2
  #define __RXML_RELAXNG__
3
3
 
4
4
  extern VALUE cXMLRelaxNG;
5
+ extern const rb_data_type_t rxml_relaxng_data_type;
5
6
 
6
7
  void rxml_init_relaxng(void);
7
8
  #endif
@@ -76,7 +76,7 @@ static VALUE rxml_sax_parser_parse(VALUE self)
76
76
  {
77
77
  VALUE context = rb_ivar_get(self, CONTEXT_ATTR);
78
78
  xmlParserCtxtPtr ctxt;
79
- Data_Get_Struct(context, xmlParserCtxt, ctxt);
79
+ TypedData_Get_Struct(context, xmlParserCtxt, &rxml_parser_context_type, ctxt);
80
80
 
81
81
  ctxt->sax2 = 1;
82
82
  ctxt->userData = (void*)rb_ivar_get(self, CALLBACKS_ATTR);