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.
data/README CHANGED
@@ -119,7 +119,7 @@ structure of the document is already known.
119
119
  puts "Elem3: #{elem3['attr']}"
120
120
 
121
121
  doc.find('//root_node/foo/bar').each do |node|
122
- puts "Node path: #{node.path} \t Contents: #{node}"
122
+ puts "Node path: #{node.path} \t Contents: #{node.content}"
123
123
  end
124
124
 
125
125
  And your terminal should look like:
@@ -141,4 +141,4 @@ And your terminal should look like:
141
141
 
142
142
  If you have any questions, please send email to libxml-devel@rubyforge.org.
143
143
 
144
- # $Id: README,v 1.5 2006/04/24 19:29:49 roscopeco Exp $
144
+ # $Id: README,v 1.6 2006/08/15 13:49:53 roscopeco Exp $
data/Rakefile CHANGED
@@ -98,7 +98,7 @@ rd = Rake::RDocTask.new(:doc) do |rdoc|
98
98
  rdoc.title = "Libxml-Ruby API"
99
99
  rdoc.options << '--main' << 'README'
100
100
  rdoc.rdoc_files.include('README', 'LICENSE', 'TODO')
101
- rdoc.rdoc_files.include('ext/xml/ruby_xml*.c', 'ext/xml/*.rb')
101
+ rdoc.rdoc_files.include('ext/xml/ruby_xml*.c', 'ext/xml/libxml.rb')
102
102
  rdoc.rdoc_files.include('*.rdoc')
103
103
  end
104
104
 
@@ -133,6 +133,7 @@ task :update_version do
133
133
  end
134
134
 
135
135
  PKG_FILES = FileList[
136
+ 'ext/xml/*.rb',
136
137
  'ext/xml/extconf.rb',
137
138
  '[A-Z]*',
138
139
  'ext/xml/*.c',
@@ -163,7 +164,7 @@ else
163
164
  s.files = PKG_FILES.to_a
164
165
 
165
166
  #### Load-time details
166
- s.require_path = 'ext'
167
+ s.require_path = 'lib'
167
168
 
168
169
  #### Documentation and testing.
169
170
  s.has_rdoc = true
@@ -36,13 +36,15 @@ unless have_library('m', 'atan')
36
36
  $CFLAGS = saveflags
37
37
  end
38
38
 
39
- unless have_library('z', 'inflate')
39
+ unless have_library('z', 'inflate') or
40
+ have_library('zlib1', 'inflate')
40
41
  crash('need zlib')
41
42
  else
42
43
  $defs.push('-DHAVE_ZLIB_H')
43
44
  end
44
45
 
45
46
  unless have_library('iconv','iconv_open') or
47
+ have_library('iconv','libiconv_open') or
46
48
  have_library('c','iconv_open') or
47
49
  have_library('recode','iconv_open') or
48
50
  have_library('iconv')
@@ -59,9 +61,11 @@ EOL
59
61
  end
60
62
 
61
63
  unless (have_library('xml2', 'xmlParseDoc') or
64
+ have_library('libxml2', 'xmlParseDoc') or
62
65
  find_library('xml2', '/opt/lib', '/usr/local/lib', '/usr/lib')) and
63
66
  (have_header('libxml/xmlversion.h') or
64
- find_header('libxml/xmlversion.h',
67
+ find_header('libxml/xmlversion.h',
68
+ "#{CONFIG['prefix']}/include",
65
69
  '/opt/include/libxml2',
66
70
  '/usr/local/include/libxml2',
67
71
  '/usr/include/libxml2'))
@@ -89,7 +93,7 @@ if try_compile('int main() { return 0; }','-Wall')
89
93
  end
90
94
 
91
95
  $CFLAGS << ' ' << $INCFLAGS
92
- $INSTALLFILES = [["../xml/libxml.rb", "$(RUBYLIBDIR)", "../xml"]]
96
+ $INSTALLFILES = [["libxml.rb", "$(RUBYLIBDIR)", "../xml"]]
93
97
 
94
98
  create_header()
95
99
  create_makefile('xml/libxml_so')
@@ -1,4 +1,4 @@
1
- /* $Id: libxml.c,v 1.2 2006/04/17 13:30:22 roscopeco Exp $ */
1
+ /* $Id: libxml.c,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
 
@@ -62,7 +62,7 @@ Init_libxml_so(void) {
62
62
 
63
63
  rb_define_const(mXML, "XML_NAMESPACE", rb_str_new2((const char*)XML_XML_NAMESPACE));
64
64
 
65
- ruby_init_parser();
65
+ ruby_init_parser();
66
66
  ruby_init_xml_parser_context();
67
67
  ruby_init_xml_attr();
68
68
  ruby_init_xml_attribute();
@@ -6,8 +6,8 @@
6
6
  /* Don't nuke this block! It is used for automatically updating the
7
7
  * versions below. VERSION = string formatting, VERNUM = numbered
8
8
  * version for inline testing: increment both or none at all. */
9
- #define RUBY_LIBXML_VERSION "0.3.8"
10
- #define RUBY_LIBXML_VERNUM 38
9
+ #define RUBY_LIBXML_VERSION "0.3.8.2"
10
+ #define RUBY_LIBXML_VERNUM 382
11
11
  #define RUBY_LIBXML_VER_MAJ 0
12
12
  #define RUBY_LIBXML_VER_MIN 3
13
13
  #define RUBY_LIBXML_VER_MIC 8
@@ -1,13 +1,13 @@
1
- # $Id: libxml.rb,v 1.1 2006/04/17 13:30:22 roscopeco Exp $
1
+ # $Id: libxml.rb,v 1.5 2006/10/29 19:42:45 roscopeco Exp $
2
2
  # Please see the LICENSE file for copyright and distribution information
3
3
  require 'xml/libxml_so'
4
4
 
5
5
  class XML::Node::Set
6
- def empty? #:nodoc:
6
+ def empty?
7
7
  self.length <= 0
8
8
  end
9
9
 
10
- def first #:nodoc:
10
+ def first
11
11
  self.each { |n| return n }
12
12
  end
13
13
  end
@@ -16,7 +16,7 @@ class XML::Document
16
16
  include Enumerable
17
17
 
18
18
  # maybe, maybe not...
19
- def each(&blk) #:nodoc:
19
+ def each(&blk)
20
20
  find('//*').each(&blk)
21
21
  end
22
22
  end
@@ -24,7 +24,7 @@ end
24
24
  class XML::Node::Set
25
25
  # inefficient, but maybe can find a way to cache the
26
26
  # ary and dump on change?
27
- def [](i, count = nil) #:nodoc:
27
+ def [](i, count = nil)
28
28
  if count
29
29
  to_a[i,count]
30
30
  else
@@ -37,7 +37,7 @@ class XML::Node::Set
37
37
  end
38
38
  end
39
39
 
40
- module XML::SiblingEnum #:nodoc:all
40
+ module XML::SiblingEnum
41
41
  private
42
42
 
43
43
  # Iterates nodes and attributes
@@ -57,27 +57,27 @@ class XML::Node
57
57
  include Comparable
58
58
 
59
59
  # maybe these don't belong on all nodes...
60
- def each_child(&blk) #:nodoc:
60
+ def each_child(&blk)
61
61
  siblings(child, &blk)
62
62
  end
63
63
 
64
- def each_attr(&blk) #:nodoc:
64
+ def each_attr(&blk)
65
65
  siblings(properties, &blk)
66
66
  end
67
67
 
68
68
  # all siblings INCLUDING self
69
- def each_sibling(&blk) #:nodoc:
69
+ def each_sibling(&blk)
70
70
  siblings(self, &blk)
71
71
  end
72
72
 
73
73
  # I guess this is what you'd expect?
74
74
  alias :each :each_child
75
75
 
76
- def to_a #:nodoc:
76
+ def to_a
77
77
  inject([]) { |ary,n| ary << n }
78
78
  end
79
79
 
80
- def <=>(other) #:nodoc:
80
+ def <=>(other)
81
81
  to_s <=> other.to_s
82
82
  end
83
83
  end
@@ -86,22 +86,22 @@ class XML::Attr
86
86
  include XML::SiblingEnum
87
87
  include Enumerable
88
88
 
89
- def each_sibling(&blk) #:nodoc:
89
+ def each_sibling(&blk)
90
90
  siblings(self,&blk)
91
91
  end
92
92
 
93
93
  alias :each_attr :each_sibling
94
94
  alias :each :each_sibling
95
95
 
96
- def to_h #:nodoc:
96
+ def to_h
97
97
  inject({}) do |h,a| h[a.name] = a.value end
98
98
  end
99
99
 
100
- def to_a #:nodoc:
100
+ def to_a
101
101
  inject([]) do |ary,a| ary << [a.name, a.value] end
102
102
  end
103
103
 
104
- def to_s #:nodoc:
104
+ def to_s
105
105
  "#{name} = #{value}"
106
106
  end
107
107
  end
@@ -1,4 +1,4 @@
1
- /* $Id: ruby_xml_attr.c,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
1
+ /* $Id: ruby_xml_attr.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
 
@@ -9,12 +9,19 @@ VALUE cXMLAttr;
9
9
 
10
10
  void
11
11
  ruby_xml_attr_free(ruby_xml_attr *rxa) {
12
- if (rxa->attr != NULL && !rxa->is_ptr) {
13
- xmlUnlinkNode((xmlNodePtr)rxa->attr);
14
- xmlFreeNode((xmlNodePtr)rxa->attr);
15
- rxa->attr = NULL;
12
+ if (rxa->attr != NULL && // got an attr?
13
+ rxa->attr->parent == NULL && // unparented (otherwise, it gets freed with parent)
14
+ rxa->attr->doc == NULL) { // No document? (otherwise, freed with doc)
15
+ if ((int)rxa->attr->_private <= 1) {
16
+ // is null or last reference,
17
+ xmlFreeNode((xmlNodePtr)rxa->attr);
18
+ } else {
19
+ // other pointers remain
20
+ rxa->attr->_private--;
21
+ }
16
22
  }
17
23
 
24
+ rxa->attr = NULL;
18
25
  free(rxa);
19
26
  }
20
27
 
@@ -32,7 +39,7 @@ ruby_xml_attr_child_get(VALUE self) {
32
39
  if (rxa->attr->children == NULL)
33
40
  return(Qnil);
34
41
  else
35
- return(ruby_xml_node_new2(cXMLNode, rxa->xd, rxa->attr->children));
42
+ return(ruby_xml_node_new_ptr(cXMLNode, rxa->xd, rxa->attr->children));
36
43
  }
37
44
 
38
45
 
@@ -102,7 +109,7 @@ ruby_xml_attr_last_get(VALUE self) {
102
109
  if (rxa->attr->last == NULL)
103
110
  return(Qnil);
104
111
  else
105
- return(ruby_xml_node_new2(cXMLNode, rxa->xd, rxa->attr->last));
112
+ return(ruby_xml_node_new_ptr(cXMLNode, rxa->xd, rxa->attr->last));
106
113
  }
107
114
 
108
115
 
@@ -150,14 +157,7 @@ ruby_xml_attr_name_get(VALUE self) {
150
157
 
151
158
  VALUE
152
159
  ruby_xml_attr_new(VALUE class, VALUE xd, xmlAttrPtr attr) {
153
- ruby_xml_attr *rxa;
154
-
155
- rxa = ALLOC(ruby_xml_attr);
156
- rxa->attr = attr;
157
- rxa->xd = xd;
158
- rxa->is_ptr = 0;
159
- return(Data_Wrap_Struct(class, ruby_xml_attr_mark,
160
- ruby_xml_attr_free, rxa));
160
+ return(ruby_xml_attr_new2(class, xd, attr));
161
161
  }
162
162
 
163
163
 
@@ -166,9 +166,26 @@ ruby_xml_attr_new2(VALUE class, VALUE xd, xmlAttrPtr attr) {
166
166
  ruby_xml_attr *rxa;
167
167
 
168
168
  rxa = ALLOC(ruby_xml_attr);
169
- rxa->attr = xmlCopyProp(attr->parent, attr);
170
- rxa->xd = xd;
171
- rxa->is_ptr = 0;
169
+
170
+ rxa->attr = attr;
171
+ if (attr->_private) {
172
+ attr->_private++;
173
+ } else {
174
+ attr->_private = (void*)1;
175
+ }
176
+
177
+ if (NIL_P(xd)) {
178
+ rxa->xd = Qnil;
179
+ rxa->attr->doc = NULL;
180
+ } else {
181
+ /* Have to set node->doc too so we don't doublefree this node */
182
+ ruby_xml_document *xdoc;
183
+ Data_Get_Struct(xd, ruby_xml_document, xdoc);
184
+
185
+ rxa->xd = xd;
186
+ rxa->attr->doc = xdoc->doc;
187
+ }
188
+
172
189
  return(Data_Wrap_Struct(class, ruby_xml_attr_mark,
173
190
  ruby_xml_attr_free, rxa));
174
191
  }
@@ -216,7 +233,6 @@ ruby_xml_attr_next_q(VALUE self) {
216
233
  */
217
234
  VALUE
218
235
  ruby_xml_attr_node_type_name(VALUE self) {
219
- /* I think libxml2's naming convention blows monkey ass */
220
236
  return(rb_str_new2("attribute"));
221
237
  }
222
238
 
@@ -269,7 +285,7 @@ ruby_xml_attr_parent_get(VALUE self) {
269
285
  if (rxa->attr->parent == NULL)
270
286
  return(Qnil);
271
287
  else
272
- return(ruby_xml_node_new2(cXMLNode, rxa->xd, rxa->attr->parent));
288
+ return(ruby_xml_node_new_ptr(cXMLNode, rxa->xd, rxa->attr->parent));
273
289
  }
274
290
 
275
291
 
@@ -1,4 +1,4 @@
1
- /* $Id: ruby_xml_attr.h,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
1
+ /* $Id: ruby_xml_attr.h,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
 
@@ -10,7 +10,7 @@ extern VALUE cXMLAttr;
10
10
  typedef struct ruby_xml_attr {
11
11
  xmlAttrPtr attr;
12
12
  VALUE xd;
13
- int is_ptr;
13
+ //int is_ptr;
14
14
  } ruby_xml_attr;
15
15
 
16
16
  void ruby_xml_attr_free(ruby_xml_attr *rxn);
@@ -1,4 +1,4 @@
1
- /* $Id: ruby_xml_attribute.c,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
1
+ /* $Id: ruby_xml_attribute.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
 
@@ -16,7 +16,7 @@ ruby_xml_attribute_child_get(VALUE self) {
16
16
  if (rxa->attribute->children == NULL)
17
17
  return(Qnil);
18
18
  else
19
- return(ruby_xml_node_new2(cXMLNode, rxa->xd, rxa->attribute->children));
19
+ return(ruby_xml_node_new_ptr(cXMLNode, rxa->xd, rxa->attribute->children));
20
20
  }
21
21
 
22
22
 
@@ -74,7 +74,7 @@ ruby_xml_attribute_last_get(VALUE self) {
74
74
  if (rxa->attribute->last == NULL)
75
75
  return(Qnil);
76
76
  else
77
- return(ruby_xml_node_new2(cXMLNode, rxa->xd, rxa->attribute->last));
77
+ return(ruby_xml_node_new_ptr(cXMLNode, rxa->xd, rxa->attribute->last));
78
78
  }
79
79
 
80
80
 
@@ -147,7 +147,7 @@ ruby_xml_attribute_next_get(VALUE self) {
147
147
  if (rxa->attribute->next == NULL)
148
148
  return(Qnil);
149
149
  else
150
- return(ruby_xml_node_new2(cXMLNode, rxa->xd, rxa->attribute->next));
150
+ return(ruby_xml_node_new_ptr(cXMLNode, rxa->xd, rxa->attribute->next));
151
151
  }
152
152
 
153
153
 
@@ -187,7 +187,7 @@ ruby_xml_attribute_prev_get(VALUE self) {
187
187
  if (rxa->attribute->prev == NULL)
188
188
  return(Qnil);
189
189
  else
190
- return(ruby_xml_node_new2(cXMLNode, rxa->xd, rxa->attribute->prev));
190
+ return(ruby_xml_node_new_ptr(cXMLNode, rxa->xd, rxa->attribute->prev));
191
191
  }
192
192
 
193
193
  VALUE
@@ -1,7 +1,8 @@
1
- /* $Id: ruby_xml_document.c,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
1
+ /* $Id: ruby_xml_document.c,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
 
5
+ #include <stdarg.h>
5
6
  #include "libxml.h"
6
7
  #include "ruby_xml_document.h"
7
8
 
@@ -104,7 +105,7 @@ ruby_xml_document_child_get(VALUE self) {
104
105
  if (rxd->doc->children == NULL)
105
106
  return(Qnil);
106
107
 
107
- node = ruby_xml_node_new2(cXMLNode, self, rxd->doc->children);
108
+ node = ruby_xml_node_new_ptr(cXMLNode, self, rxd->doc->children);
108
109
  Data_Get_Struct(node, ruby_xml_node, rxn);
109
110
  rxn->xd = self;
110
111
  return(node);
@@ -493,7 +494,7 @@ ruby_xml_document_last_get(VALUE self) {
493
494
  if (rxd->doc->last == NULL)
494
495
  return(Qnil);
495
496
 
496
- node = ruby_xml_node_new2(cXMLNode, self, rxd->doc->last);
497
+ node = ruby_xml_node_new_ptr(cXMLNode, self, rxd->doc->last);
497
498
  Data_Get_Struct(node, ruby_xml_node, rxn);
498
499
  rxn->xd = self;
499
500
  return(node);
@@ -622,7 +623,7 @@ ruby_xml_document_next_get(VALUE self) {
622
623
  if (rxd->doc->next == NULL)
623
624
  return(Qnil);
624
625
 
625
- node = ruby_xml_node_new2(cXMLNode, self, rxd->doc->next);
626
+ node = ruby_xml_node_new_ptr(cXMLNode, self, rxd->doc->next);
626
627
  Data_Get_Struct(node, ruby_xml_node, rxn);
627
628
  rxn->xd = self;
628
629
  return(node);
@@ -664,7 +665,7 @@ ruby_xml_document_parent_get(VALUE self) {
664
665
  if (rxd->doc->parent == NULL)
665
666
  return(Qnil);
666
667
 
667
- node = ruby_xml_node_new2(cXMLNode, self, rxd->doc->parent);
668
+ node = ruby_xml_node_new_ptr(cXMLNode, self, rxd->doc->parent);
668
669
  Data_Get_Struct(node, ruby_xml_node, rxn);
669
670
  rxn->xd = self;
670
671
  return(node);
@@ -706,7 +707,7 @@ ruby_xml_document_prev_get(VALUE self) {
706
707
  if (rxd->doc->prev == NULL)
707
708
  return(Qnil);
708
709
 
709
- node = ruby_xml_node_new2(cXMLNode, self, rxd->doc->prev);
710
+ node = ruby_xml_node_new_ptr(cXMLNode, self, rxd->doc->prev);
710
711
  Data_Get_Struct(node, ruby_xml_node, rxn);
711
712
  rxn->xd = self;
712
713
  return(node);
@@ -764,7 +765,6 @@ ruby_xml_document_property_set(VALUE self, VALUE key, VALUE val) {
764
765
  VALUE
765
766
  ruby_xml_document_root_get(VALUE self) {
766
767
  ruby_xml_document *rxd;
767
- ruby_xml_node *rxn;
768
768
  VALUE node;
769
769
  xmlNodePtr root;
770
770
 
@@ -774,9 +774,7 @@ ruby_xml_document_root_get(VALUE self) {
774
774
  if (root == NULL)
775
775
  return(Qnil);
776
776
 
777
- node = ruby_xml_node_new2(cXMLNode, self, root);
778
- Data_Get_Struct(node, ruby_xml_node, rxn);
779
- rxn->xd = self;
777
+ node = ruby_xml_node_new_ptr(cXMLNode, self, root);
780
778
  return(node);
781
779
  }
782
780
 
@@ -804,7 +802,7 @@ ruby_xml_document_root_set(VALUE self, VALUE node) {
804
802
  if (root == NULL)
805
803
  return(Qnil);
806
804
 
807
- retnode = ruby_xml_node_new2(cXMLNode, self, root);
805
+ retnode = ruby_xml_node_new_ptr(cXMLNode, self, root);
808
806
  return(retnode);
809
807
  }
810
808