libxml-ruby 0.3.8 → 0.3.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- /* $Id: ruby_xml_node.h,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
1
+ /* $Id: ruby_xml_node.h,v 1.3 2006/11/20 01:22:07 roscopeco Exp $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
@@ -13,14 +13,15 @@ extern VALUE eXMLNodeUnknownType;
13
13
  typedef struct ruby_xml_node {
14
14
  xmlNodePtr node;
15
15
  VALUE xd;
16
- int is_ptr;
16
+ //int is_ptr;
17
17
  } ruby_xml_node;
18
18
 
19
19
  void ruby_xml_node_free(ruby_xml_node *rxn);
20
20
  void ruby_init_xml_node(void);
21
21
  VALUE ruby_xml_node_child_set(VALUE self, VALUE obj);
22
22
  VALUE ruby_xml_node_new(VALUE class, xmlNodePtr node);
23
- VALUE ruby_xml_node_new2(VALUE class, VALUE xd, xmlNodePtr node);
23
+ VALUE ruby_xml_node_new_ptr(VALUE class, VALUE xd, xmlNodePtr node);
24
+ VALUE ruby_xml_node_new3(VALUE class, VALUE xd, xmlNodePtr node, int ptr);
24
25
  VALUE ruby_xml_node_name_get(VALUE self);
25
26
  VALUE ruby_xml_node_property_get(VALUE self, VALUE key);
26
27
  VALUE ruby_xml_node_property_set(VALUE self, VALUE key, VALUE val);
@@ -1,4 +1,4 @@
1
- /* $Id: ruby_xml_node_set.c,v 1.3 2006/04/14 14:45:25 roscopeco Exp $ */
1
+ /* $Id: ruby_xml_node_set.c,v 1.4 2006/11/20 01:22:07 roscopeco Exp $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
@@ -32,7 +32,7 @@ ruby_xml_node_set_to_a(VALUE self) {
32
32
  set_ary = rb_ary_new();
33
33
  if (!((rxnset->node_set == NULL) || (rxnset->node_set->nodeNr == 0))) {
34
34
  for (i = 0; i < rxnset->node_set->nodeNr; i++) {
35
- nodeobj = ruby_xml_node_new2(cXMLNode, rxnset->xd, rxnset->node_set->nodeTab[i]);
35
+ nodeobj = ruby_xml_node_new_ptr(cXMLNode, rxnset->xd, rxnset->node_set->nodeTab[i]);
36
36
  rb_ary_push(set_ary, nodeobj);
37
37
  }
38
38
  }
@@ -64,7 +64,7 @@ ruby_xml_node_set_each(VALUE self) {
64
64
  nodeobj = ruby_xml_attr_new2(cXMLAttr, rxnset->xd, (xmlAttrPtr)rxnset->node_set->nodeTab[i]);
65
65
  break;
66
66
  default:
67
- nodeobj = ruby_xml_node_new2(cXMLNode, rxnset->xd, rxnset->node_set->nodeTab[i]);
67
+ nodeobj = ruby_xml_node_new_ptr(cXMLNode, rxnset->xd, rxnset->node_set->nodeTab[i]);
68
68
  }
69
69
 
70
70
  rb_yield(nodeobj);
@@ -108,7 +108,7 @@ ruby_xml_node_set_first(VALUE self) {
108
108
  nodeobj = ruby_xml_attr_new2(cXMLAttr, rxnset->xd, (xmlAttrPtr)rxnset->node_set->nodeTab[0]);
109
109
  break;
110
110
  default:
111
- nodeobj = ruby_xml_node_new2(cXMLNode, rxnset->xd, rxnset->node_set->nodeTab[0]);
111
+ nodeobj = ruby_xml_node_new_ptr(cXMLNode, rxnset->xd, rxnset->node_set->nodeTab[0]);
112
112
  }
113
113
 
114
114
  return(nodeobj);
@@ -1,7 +1,9 @@
1
- /* $Id: ruby_xml_parser.c,v 1.3 2006/03/27 20:49:19 roscopeco Exp $ */
1
+ /* $Id: ruby_xml_parser.c,v 1.5 2006/11/20 01:22:07 roscopeco Exp $ */
2
+ /* $Id: ruby_xml_parser.c,v 1.5 2006/11/20 01:22:07 roscopeco Exp $ */
2
3
 
3
4
  /* Please see the LICENSE file for copyright and distribution information */
4
5
 
6
+ #include <stdarg.h>
5
7
  #include "libxml.h"
6
8
 
7
9
  static VALUE libxml_xmlRubyErrorProc = Qnil;
@@ -1283,12 +1285,11 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg, ...)
1283
1285
  #endif
1284
1286
 
1285
1287
  void
1286
- ruby_init_parser(void) {
1287
-
1288
+ ruby_init_parser(void) {
1288
1289
  cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
1289
1290
  eXMLParserParseError = rb_define_class_under(cXMLParser, "ParseError",
1290
1291
  rb_eRuntimeError);
1291
-
1292
+
1292
1293
  /* Constants */
1293
1294
  rb_define_const(cXMLParser, "LIBXML_VERSION",
1294
1295
  rb_str_new2(LIBXML_DOTTED_VERSION));
@@ -1413,5 +1414,10 @@ ruby_init_parser(void) {
1413
1414
  // set up error handling
1414
1415
  xmlSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
1415
1416
  xmlThrDefSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
1417
+
1418
+ // Ruby needs to know about this even though it's not exported, otherwise
1419
+ // our error proc might get garbage collected.
1420
+ rb_global_variable(&libxml_xmlRubyErrorProc);
1421
+
1416
1422
  id_call = rb_intern("call");
1417
1423
  }
@@ -1,4 +1,4 @@
1
- /* $Id: ruby_xml_parser_context.c,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
1
+ /* $Id: ruby_xml_parser_context.c,v 1.2 2006/11/20 01:22:07 roscopeco Exp $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
@@ -330,7 +330,7 @@ ruby_xml_parser_context_node_get(VALUE self) {
330
330
  if (rxpc->ctxt->node == NULL)
331
331
  return(Qnil);
332
332
  else
333
- return(ruby_xml_node_new2(cXMLNode,
333
+ return(ruby_xml_node_new_ptr(cXMLNode,
334
334
  ruby_xml_document_new(cXMLDocument, rxpc->ctxt->myDoc),
335
335
  rxpc->ctxt->node));
336
336
  }
@@ -1,4 +1,4 @@
1
- /* $Id: ruby_xml_sax_parser.c,v 1.4 2006/04/14 23:46:06 roscopeco Exp $ */
1
+ /* $Id: ruby_xml_sax_parser.c,v 1.6 2006/08/15 13:53:45 roscopeco Exp $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
@@ -39,6 +39,14 @@ ruby_xml_sax_parser_mark(ruby_xml_sax_parser *rxsp) {
39
39
  mark_handler(rxsp, xmlParserError);
40
40
  mark_handler(rxsp, xmlParserFatalError);
41
41
  mark_handler(rxsp, cdataBlock);
42
+
43
+ if (rxsp->filename && (rxsp->filename != Qnil)) {
44
+ rb_gc_mark(rxsp->filename);
45
+ }
46
+
47
+ if (rxsp->str && (rxsp->str != Qnil)) {
48
+ rb_gc_mark(rxsp->str);
49
+ }
42
50
  }
43
51
 
44
52
 
@@ -97,8 +105,8 @@ ruby_xml_sax_parser_filename_set(VALUE self, VALUE filename) {
97
105
 
98
106
  #define set_handler(self, argc, argv, handler) \
99
107
  VALUE proc; \
100
- rb_scan_args(argc, argv, "0&", &proc); \
101
108
  ruby_xml_sax_parser *rxsp; \
109
+ rb_scan_args(argc, argv, "0&", &proc); \
102
110
  Data_Get_Struct(self, ruby_xml_sax_parser, rxsp); \
103
111
  rxsp->cbp->handler = proc; \
104
112
  return(Qnil);
@@ -5,7 +5,7 @@ def test( doc2 )
5
5
  doc = XML::Document.new('1.0')
6
6
  doc.root = XML::Node.new("ccc")
7
7
  doc.root['aaa'] = 'aaa'
8
- #doc.root << doc2.root # BUG!
8
+ doc.root << doc2.root # BUG!
9
9
  doc.root << doc2.root.copy(true)
10
10
  return doc
11
11
  end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/ruby -w -I.
2
+ require "libxml_test"
3
+
4
+ $FAILS = []
5
+
6
+ def test( doc, doc2, iter )
7
+ doc.root = XML::Node.new("ccc")
8
+ iter.times { |i|
9
+ doc.root << doc2.root
10
+ doc.root << doc2.root.copy(true)
11
+ }
12
+ return doc
13
+ end
14
+
15
+ def test2(iter)
16
+ doc = XML::Document.new('1.0')
17
+ doc2 = XML::Document.new('1.0')
18
+ doc2.root = XML::Node.new("aaa")
19
+ ret = test( doc, doc2, iter )
20
+
21
+ $FAILS << iter unless ret.find('*/aaa').length == iter
22
+ end
23
+
24
+ 1000.times do |i|
25
+ puts i.to_s
26
+ test2(i)
27
+ end
28
+
29
+ puts "#{$FAILS.length} failures"
30
+ p $FAILS
31
+
32
+
@@ -1,2 +1,3 @@
1
1
  $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../ext")
2
2
  require "xml/libxml_so" unless defined?(XML)
3
+ puts "VERSION: #{XML::Parser::VERSION}"
@@ -0,0 +1,56 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'libxml_test'
4
+ require 'xml/libxml' # needs the ruby code too
5
+
6
+ class XML::Node
7
+ def first_child_element
8
+ result = nil
9
+ if self.children?
10
+ self.each_child{|node_child| result = node_child if ((result.nil?) && node_child.element?) }
11
+ end
12
+ result
13
+ end
14
+ end
15
+
16
+ #
17
+ # Method which generates crash
18
+ #
19
+ def merge(forms)
20
+ starting_form = forms.shift
21
+ forms.inject(starting_form) do |master_form,form|
22
+ master_form.find("//body").first << form.find("//body").first.first_child_element
23
+ master_form
24
+ end
25
+ end
26
+
27
+ #
28
+ # Run
29
+ # Must tell it how many times to merge a document
30
+ # On my linux box, it takes about 350 to crash it
31
+ # On my OS X box, it takes about 150
32
+ #
33
+
34
+ if (ARGV[0].to_i > 0)
35
+ count = ARGV[0].to_i
36
+ else
37
+ count = 500
38
+ end
39
+
40
+
41
+ merge_list = []
42
+
43
+ count.times do
44
+ merge_list << XML::Parser.string(File.read(File.join(File.dirname(__FILE__), 'model', 'merge_bug_data.xml'))).parse
45
+ end
46
+
47
+ result = merge(merge_list)
48
+ puts "Merged!"
49
+
50
+ #File.open(File.join(File.dirname(__FILE__), 'model', '/generated_form.xml'), "w") do |f|
51
+ # puts "Trying to write to file"
52
+ # f << result
53
+ # puts "After trying to write to file"
54
+ #end
55
+
56
+ puts "nothing left to do but print this message"
@@ -0,0 +1,58 @@
1
+ <?xml version="1.0"?>
2
+ <template>
3
+ <body>
4
+ <section>
5
+ <txt>Some Preset Data Here</txt>
6
+ <txt>Some Preset Data Here</txt>
7
+ <txt>name: quack!</txt>
8
+ <txt>Some Preset Data Here</txt>
9
+ <txt>Some Preset Data Here</txt>
10
+ <txt>Some Preset Data Here</txt>
11
+ <txt>Some Preset Data Here</txt>
12
+ <txt>city: quack!</txt>
13
+ <txt>Some Preset Data Here</txt>
14
+ <txt>Some Preset Data Here</txt>
15
+ <txt>Some Preset Data Here</txt>
16
+ <txt>Some Preset Data Here</txt>
17
+ <txt>state: quack!</txt>
18
+ <txt>Some Preset Data Here</txt>
19
+ <txt>Some Preset Data Here</txt>
20
+ <txt>Some Preset Data Here</txt>
21
+ <txt>Some Preset Data Here</txt>
22
+ <row>
23
+ <txt>year: Vroom!</txt>
24
+ <txt>make: Vroom!</txt>
25
+ <txt>model: Vroom!</txt>
26
+ </row>
27
+ <row>
28
+ <txt>year: Vroom!</txt>
29
+ <txt>make: Vroom!</txt>
30
+ <txt>model: Vroom!</txt>
31
+ </row>
32
+ <row>
33
+ <txt>year: Vroom!</txt>
34
+ <txt>make: Vroom!</txt>
35
+ <txt>model: Vroom!</txt>
36
+ </row>
37
+ <txt>Some Preset Data Here</txt>
38
+ <txt>Some Preset Data Here</txt>
39
+ <row>
40
+ <txt>year: Vroom!</txt>
41
+ <txt>make: Vroom!</txt>
42
+ <txt>model: Vroom!</txt>
43
+ </row>
44
+ <row>
45
+ <txt>year: Vroom!</txt>
46
+ <txt>make: Vroom!</txt>
47
+ <txt>model: Vroom!</txt>
48
+ </row>
49
+ <row>
50
+ <txt>year: Vroom!</txt>
51
+ <txt>make: Vroom!</txt>
52
+ <txt>model: Vroom!</txt>
53
+ </row>
54
+ <txt>Some Preset Data Here</txt>
55
+ <txt>Some Preset Data Here</txt>
56
+ </section>
57
+ </body>
58
+ </template>
@@ -1,4 +1,4 @@
1
- # $Id: tc_xml_document_write3.rb,v 1.3 2006/04/17 13:30:22 roscopeco Exp $
1
+ # $Id: tc_xml_document_write3.rb,v 1.4 2006/11/20 01:22:08 roscopeco Exp $
2
2
  require "libxml_test"
3
3
  require 'test/unit'
4
4
 
@@ -30,7 +30,7 @@ class TC_XML_Document_Write3 < Test::Unit::TestCase
30
30
  xml << "</rubynet>\n"
31
31
  pkg = @doc.root.child = XML::Node.new('pkg')
32
32
  meta = pkg.child = XML::Node.new('meta')
33
- pkgname = meta << XML::Node.new('pkgname')
33
+ assert_equal meta, meta << (pkgname = XML::Node.new('pkgname'))
34
34
  pkgname << 'libxml'
35
35
  assert_equal(xml, @doc.to_s)
36
36
  end
@@ -1,8 +1,8 @@
1
- # $Id: tc_xml_node3.rb,v 1.2 2006/04/17 13:30:22 roscopeco Exp $
1
+ # $Id: tc_xml_node3.rb,v 1.3 2006/11/20 01:22:08 roscopeco Exp $
2
2
  require "libxml_test"
3
3
  require 'test/unit'
4
4
 
5
- class TC_XML_Node2 < Test::Unit::TestCase
5
+ class TC_XML_Node3 < Test::Unit::TestCase
6
6
  def setup()
7
7
  xp = XML::Parser.new()
8
8
  str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
@@ -1,8 +1,8 @@
1
- # $Id: tc_xml_node4.rb,v 1.2 2006/04/17 13:30:19 roscopeco Exp $
1
+ # $Id: tc_xml_node4.rb,v 1.3 2006/05/10 18:02:51 roscopeco Exp $
2
2
  require "libxml_test"
3
3
  require 'test/unit'
4
4
 
5
- class TC_XML_Node2 < Test::Unit::TestCase
5
+ class TC_XML_Node4 < Test::Unit::TestCase
6
6
  def setup()
7
7
  xp = XML::Parser.new()
8
8
  str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
@@ -0,0 +1,53 @@
1
+ # $Id: tc_xml_node5.rb,v 1.1 2006/05/10 18:03:57 roscopeco Exp $
2
+ require "libxml_test"
3
+ require 'test/unit'
4
+
5
+ class TC_XML_Node5 < Test::Unit::TestCase
6
+ def setup()
7
+ xp = XML::Parser.new()
8
+ str = '<test><num>one</num><num>two</num><num>three</num></test>'
9
+ assert_equal(str, xp.string = str)
10
+ @doc = xp.parse
11
+ assert_instance_of(XML::Document, @doc)
12
+ @root = @doc.root
13
+ @num1 = @root.child
14
+ @num2 = @num1.next
15
+ @num3 = @num2.next
16
+ end
17
+
18
+ def test_libxml_node_add_next_01
19
+ @num1.next = XML::Node.new('num', 'one-and-a-half')
20
+ assert_equal '<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
21
+ @root.to_s.gsub(/\n\s*/,'')
22
+ end
23
+
24
+ def test_libxml_node_add_next_02
25
+ @num2.next = XML::Node.new('num', 'two-and-a-half')
26
+ assert_equal '<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
27
+ @root.to_s.gsub(/\n\s*/,'')
28
+ end
29
+
30
+ def test_libxml_node_add_next_03
31
+ @num3.next = XML::Node.new('num', 'four')
32
+ assert_equal '<test><num>one</num><num>two</num><num>three</num><num>four</num></test>',
33
+ @root.to_s.gsub(/\n\s*/,'')
34
+ end
35
+
36
+ def test_libxml_node_add_prev_01
37
+ @num1.prev = XML::Node.new('num', 'half')
38
+ assert_equal '<test><num>half</num><num>one</num><num>two</num><num>three</num></test>',
39
+ @root.to_s.gsub(/\n\s*/,'')
40
+ end
41
+
42
+ def test_libxml_node_add_prev_02
43
+ @num2.prev = XML::Node.new('num', 'one-and-a-half')
44
+ assert_equal '<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
45
+ @root.to_s.gsub(/\n\s*/,'')
46
+ end
47
+
48
+ def test_libxml_node_add_prev_03
49
+ @num3.prev = XML::Node.new('num', 'two-and-a-half')
50
+ assert_equal '<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
51
+ @root.to_s.gsub(/\n\s*/,'')
52
+ end
53
+ end
@@ -0,0 +1,28 @@
1
+ # $Id: tc_xml_node6.rb,v 1.2 2006/05/31 17:26:43 roscopeco Exp $
2
+ require "libxml_test"
3
+ require 'test/unit'
4
+
5
+ class TC_XML_Node6 < Test::Unit::TestCase
6
+ def setup()
7
+ xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
8
+ doc = xp.parse
9
+ @root = doc.root
10
+ assert_equal 'bar', @root['foo']
11
+ end
12
+
13
+ def teardown()
14
+ @root = nil
15
+ end
16
+
17
+ def test_xml_node_prop_get_str_sym()
18
+ assert_equal @root['foo'], @root[:foo]
19
+ assert_equal @root['uga'], @root[:uga]
20
+ end
21
+
22
+ def test_xml_node_prop_set_str_sym()
23
+ @root[:foo] = 'boo'
24
+ @root[:uga] = 'zoo'
25
+ assert_equal 'boo', @root['foo']
26
+ assert_equal 'zoo', @root['uga']
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ # $Id: tc_xml_node7.rb,v 1.2 2006/11/20 01:22:08 roscopeco Exp $
2
+ require "libxml_test"
3
+ require 'test/unit'
4
+
5
+ class TC_XML_Node7 < Test::Unit::TestCase
6
+ def setup()
7
+ xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
8
+ doc = xp.parse
9
+ @root = doc.root
10
+ assert_equal 'bar', @root['foo']
11
+ end
12
+
13
+ def teardown()
14
+ @root = nil
15
+ end
16
+
17
+ def test_xml_node_properties_traversal_bug()
18
+ prop = @root.properties
19
+ assert_instance_of XML::Attr, prop
20
+ assert_equal 'uga', prop.name
21
+ assert_equal 'booga', prop.value
22
+
23
+ prop = prop.next
24
+ assert_instance_of XML::Attr, prop
25
+ assert_equal 'foo', prop.name
26
+ assert_equal 'bar', prop.value
27
+ end
28
+ end