libxml-ruby 3.0.0-x64-mingw32 → 3.2.2-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +5 -5
  2. data/HISTORY +37 -0
  3. data/MANIFEST +34 -34
  4. data/README.rdoc +65 -36
  5. data/Rakefile +21 -3
  6. data/ext/libxml/extconf.rb +30 -26
  7. data/ext/libxml/ruby_libxml.h +0 -8
  8. data/ext/libxml/ruby_xml.c +40 -0
  9. data/ext/libxml/ruby_xml_document.c +1 -5
  10. data/ext/libxml/ruby_xml_dtd.c +6 -8
  11. data/ext/libxml/ruby_xml_encoding.c +1 -13
  12. data/ext/libxml/ruby_xml_encoding.h +0 -3
  13. data/ext/libxml/ruby_xml_error.c +1 -1
  14. data/ext/libxml/ruby_xml_error.h +1 -1
  15. data/ext/libxml/ruby_xml_io.c +14 -18
  16. data/ext/libxml/ruby_xml_io.h +1 -1
  17. data/ext/libxml/ruby_xml_node.c +16 -17
  18. data/ext/libxml/ruby_xml_parser_context.c +1 -1
  19. data/ext/libxml/ruby_xml_reader.c +7 -2
  20. data/ext/libxml/ruby_xml_schema.c +44 -66
  21. data/ext/libxml/ruby_xml_schema_element.c +15 -14
  22. data/ext/libxml/ruby_xml_schema_type.c +66 -93
  23. data/ext/libxml/ruby_xml_version.h +4 -4
  24. data/ext/libxml/ruby_xml_writer.c +189 -192
  25. data/lib/3.0/libxml_ruby.so +0 -0
  26. data/lib/libxml/schema/element.rb +0 -8
  27. data/lib/libxml/schema/type.rb +0 -8
  28. data/lib/libxml/schema.rb +0 -19
  29. data/lib/libxml-ruby.rb +30 -0
  30. data/lib/libxml.rb +3 -28
  31. data/libxml-ruby.gemspec +5 -4
  32. data/setup.rb +0 -1
  33. data/test/model/cwm_1_0.xml +11336 -0
  34. data/test/{tc_attr.rb → test_attr.rb} +18 -18
  35. data/test/{tc_attr_decl.rb → test_attr_decl.rb} +8 -8
  36. data/test/{tc_attributes.rb → test_attributes.rb} +10 -10
  37. data/test/{tc_canonicalize.rb → test_canonicalize.rb} +35 -39
  38. data/test/test_deprecated_require.rb +12 -0
  39. data/test/{tc_document.rb → test_document.rb} +31 -24
  40. data/test/test_document_write.rb +146 -0
  41. data/test/{tc_dtd.rb → test_dtd.rb} +26 -25
  42. data/test/{tc_encoding.rb → test_encoding.rb} +20 -17
  43. data/test/{tc_encoding_sax.rb → test_encoding_sax.rb} +3 -3
  44. data/test/test_error.rb +178 -0
  45. data/test/test_helper.rb +4 -11
  46. data/test/{tc_html_parser.rb → test_html_parser.rb} +31 -30
  47. data/test/test_html_parser_context.rb +23 -0
  48. data/test/test_namespace.rb +60 -0
  49. data/test/{tc_namespaces.rb → test_namespaces.rb} +29 -38
  50. data/test/{tc_node.rb → test_node.rb} +37 -31
  51. data/test/{tc_node_cdata.rb → test_node_cdata.rb} +10 -10
  52. data/test/{tc_node_comment.rb → test_node_comment.rb} +6 -6
  53. data/test/{tc_node_copy.rb → test_node_copy.rb} +3 -4
  54. data/test/{tc_node_edit.rb → test_node_edit.rb} +20 -21
  55. data/test/{tc_node_pi.rb → test_node_pi.rb} +8 -10
  56. data/test/{tc_node_text.rb → test_node_text.rb} +8 -9
  57. data/test/{tc_node_write.rb → test_node_write.rb} +16 -26
  58. data/test/test_node_xlink.rb +28 -0
  59. data/test/{tc_parser.rb → test_parser.rb} +72 -75
  60. data/test/{tc_parser_context.rb → test_parser_context.rb} +38 -44
  61. data/test/{tc_properties.rb → test_properties.rb} +5 -5
  62. data/test/test_reader.rb +364 -0
  63. data/test/{tc_relaxng.rb → test_relaxng.rb} +11 -11
  64. data/test/{tc_sax_parser.rb → test_sax_parser.rb} +38 -31
  65. data/test/{tc_schema.rb → test_schema.rb} +40 -33
  66. data/test/test_suite.rb +39 -40
  67. data/test/{tc_traversal.rb → test_traversal.rb} +4 -4
  68. data/test/{tc_writer.rb → test_writer.rb} +95 -74
  69. data/test/{tc_xinclude.rb → test_xinclude.rb} +3 -3
  70. data/test/test_xml.rb +263 -0
  71. data/test/{tc_xpath.rb → test_xpath.rb} +25 -25
  72. data/test/{tc_xpath_context.rb → test_xpath_context.rb} +5 -5
  73. data/test/{tc_xpath_expression.rb → test_xpath_expression.rb} +7 -7
  74. data/test/{tc_xpointer.rb → test_xpointer.rb} +15 -15
  75. metadata +92 -106
  76. data/lib/2.4/libxml_ruby.so +0 -0
  77. data/lib/libs/libiconv-2.dll +0 -0
  78. data/lib/libs/libxml2-2.dll +0 -0
  79. data/lib/libs/zlib1.dll +0 -0
  80. data/test/tc_deprecated_require.rb +0 -12
  81. data/test/tc_document_write.rb +0 -195
  82. data/test/tc_error.rb +0 -178
  83. data/test/tc_html_parser_context.rb +0 -23
  84. data/test/tc_namespace.rb +0 -61
  85. data/test/tc_node_xlink.rb +0 -28
  86. data/test/tc_reader.rb +0 -358
  87. data/test/tc_xml.rb +0 -225
@@ -1,13 +1,10 @@
1
1
  /* Please see the LICENSE file for copyright and distribution information */
2
2
 
3
3
  #include "ruby_libxml.h"
4
+ #include <ruby/io.h>
4
5
 
5
6
  static ID READ_METHOD;
6
- #ifdef HAVE_RB_IO_BUFWRITE
7
- #include <ruby/io.h>
8
- #else
9
7
  static ID WRITE_METHOD;
10
- #endif /* !HAVE_RB_IO_BUFWRITE */
11
8
 
12
9
  /* This method is called by libxml when it wants to read
13
10
  more data from a stream. We go with the duck typing
@@ -27,25 +24,24 @@ int rxml_read_callback(void *context, char *buffer, int len)
27
24
  return (int)size;
28
25
  }
29
26
 
30
- int rxml_write_callback(void *context, const char *buffer, int len)
27
+ int rxml_write_callback(VALUE io, const char *buffer, int len)
31
28
  {
32
- #ifndef HAVE_RB_IO_BUFWRITE
33
- VALUE io, written, string;
34
-
35
- io = (VALUE) context;
36
- string = rb_str_new(buffer, len);
37
- written = rb_funcall(io, WRITE_METHOD, 1, string);
38
-
39
- return NUM2INT(written);
40
- #else
41
- return (int)rb_io_bufwrite((VALUE) context, buffer, (size_t)len);
42
- #endif /* !HAVE_RB_IO_BUFWRITE */
29
+ if (rb_io_check_io(io) == Qnil)
30
+ {
31
+ // Could be StringIO
32
+ VALUE written, string;
33
+ string = rb_external_str_new_with_enc(buffer, strlen(buffer), rb_enc_get(io));
34
+ written = rb_funcall(io, WRITE_METHOD, 1, string);
35
+ return NUM2INT(written);
36
+ }
37
+ else
38
+ {
39
+ return (int)rb_io_bufwrite(io, buffer, (size_t)len);
40
+ }
43
41
  }
44
42
 
45
43
  void rxml_init_io(void)
46
44
  {
47
45
  READ_METHOD = rb_intern("read");
48
- #ifndef HAVE_RB_IO_BUFWRITE
49
46
  WRITE_METHOD = rb_intern("write");
50
- #endif /* !HAVE_RB_IO_BUFWRITE */
51
47
  }
@@ -4,7 +4,7 @@
4
4
  #define __RXML_IO__
5
5
 
6
6
  int rxml_read_callback(void *context, char *buffer, int len);
7
- int rxml_write_callback(void *context, const char *buffer, int len);
7
+ int rxml_write_callback(VALUE io, const char *buffer, int len);
8
8
  void rxml_init_io(void);
9
9
 
10
10
  #endif
@@ -57,7 +57,7 @@ static void rxml_node_free(xmlNodePtr xnode)
57
57
 
58
58
  void rxml_node_manage(xmlNodePtr xnode, VALUE node)
59
59
  {
60
- RDATA(node)->dfree = rxml_node_free;
60
+ RDATA(node)->dfree = (RUBY_DATA_FUNC)rxml_node_free;
61
61
  xnode->_private = (void*)node;
62
62
  }
63
63
 
@@ -83,8 +83,11 @@ void rxml_node_mark(xmlNodePtr xnode)
83
83
  {
84
84
  if (xnode->doc)
85
85
  {
86
- VALUE doc = (VALUE)xnode->doc->_private;
87
- rb_gc_mark(doc);
86
+ if (xnode->doc->_private)
87
+ {
88
+ VALUE doc = (VALUE)xnode->doc->_private;
89
+ rb_gc_mark(doc);
90
+ }
88
91
  }
89
92
  else if (xnode->parent)
90
93
  {
@@ -120,8 +123,7 @@ VALUE rxml_node_wrap(xmlNodePtr xnode)
120
123
 
121
124
  static VALUE rxml_node_alloc(VALUE klass)
122
125
  {
123
- /* Ruby is responsible for freeing this node not libxml but don't set
124
- up mark and free yet until we assign the node. */
126
+ // This node was created from Ruby so we are responsible for freeing it not libxml
125
127
  return Data_Wrap_Struct(klass, rxml_node_mark, rxml_node_free, NULL);
126
128
  }
127
129
 
@@ -308,25 +310,22 @@ static VALUE rxml_node_modify_dom(VALUE self, VALUE target,
308
310
  xtarget = rxml_get_xnode(target);
309
311
 
310
312
  if (xtarget->doc != NULL && xtarget->doc != xnode->doc)
311
- rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling XML::Document.import");
313
+ rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import");
312
314
 
313
315
  xmlUnlinkNode(xtarget);
314
316
 
315
- /* This target node could be freed here. */
317
+ // Target is about to have a parent, so stop having ruby manage it.
318
+ rxml_node_unmanage(xtarget, target);
319
+
320
+ // This target node could be freed here and be replaced by a different node
316
321
  xresult = xmlFunc(xnode, xtarget);
317
322
 
318
323
  if (!xresult)
319
- rxml_raise(&xmlLastError);
320
-
321
- /* Was the target freed? If yes, then wrap the new node */
322
- if (xresult != xtarget)
323
- {
324
- RDATA(target)->data = xresult;
325
- }
324
+ rxml_raise(&xmlLastError);
326
325
 
327
- // Target now has a parent so ruby should no longer manage its memory
328
- rxml_node_unmanage(xresult, target);
329
- xtarget->_private = NULL;
326
+ /* Assume the target was freed, we need to fix up the ruby object to point to the
327
+ newly returned node. */
328
+ RDATA(target)->data = xresult;
330
329
 
331
330
  return target;
332
331
  }
@@ -47,7 +47,7 @@ static VALUE rxml_parser_context_document(VALUE klass, VALUE document)
47
47
  int length;
48
48
 
49
49
  if (rb_obj_is_kind_of(document, cXMLDocument) == Qfalse)
50
- rb_raise(rb_eTypeError, "Must pass an XML::Document object");
50
+ rb_raise(rb_eTypeError, "Must pass an LibXML::XML::Document object");
51
51
 
52
52
  Data_Get_Struct(document, xmlDoc, xdoc);
53
53
  xmlDocDumpFormatMemoryEnc(xdoc, &buffer, &length, (const char*)xdoc->encoding, 0);
@@ -23,7 +23,7 @@
23
23
  * reader = XML::Reader.string("<foo><bar>1</bar><bar>2</bar><bar>3</bar></foo>")
24
24
  * reader.read
25
25
  * assert_equal('foo', reader.name)
26
- * assert_equal(nil, reader.value)
26
+ * assert_nil(reader.value)
27
27
  *
28
28
  * 3.times do |i|
29
29
  * reader.read
@@ -995,7 +995,12 @@ static VALUE rxml_reader_expand(VALUE self)
995
995
  }
996
996
  else
997
997
  {
998
- return rxml_node_wrap(xnode);
998
+ /* We cannot call rxml_node_wrap here because its sets up a mark function
999
+ for the node. But according to the libxml docs (http://xmlsoft.org/html/libxml-xmlreader.html#xmlTextReaderExpand)
1000
+ this is only valid until the next xmlTextReaderRead call. At that point the node is freed (from reading
1001
+ the libxml2 source code. So don't set a mark or free function, because they will get called in the next
1002
+ garbage collection run and cause a segfault.*/
1003
+ return Data_Wrap_Struct(cXMLNode, NULL, NULL, xnode);
999
1004
  }
1000
1005
  }
1001
1006
 
@@ -8,7 +8,6 @@
8
8
  #include "ruby_xml_schema_attribute.h"
9
9
  #include "ruby_xml_schema_facet.h"
10
10
 
11
-
12
11
  /*
13
12
  * Document-class: LibXML::XML::Schema
14
13
  *
@@ -152,7 +151,6 @@ static VALUE rxml_schema_id(VALUE self)
152
151
  QNIL_OR_STRING(xschema->id)
153
152
  }
154
153
 
155
-
156
154
  static VALUE rxml_schema_document(VALUE self)
157
155
  {
158
156
  xmlSchemaPtr xschema;
@@ -162,21 +160,20 @@ static VALUE rxml_schema_document(VALUE self)
162
160
  return rxml_node_wrap(xmlDocGetRootElement(xschema->doc));
163
161
  }
164
162
 
165
- static void storeNs(xmlSchemaImportPtr import, VALUE self, xmlChar *nsname)
163
+ static void scan_namespaces(xmlSchemaImportPtr ximport, VALUE array, xmlChar *nsname)
166
164
  {
167
- VALUE schemas;
168
165
  xmlNodePtr xnode;
169
166
  xmlNsPtr xns;
170
167
 
171
- schemas = rb_iv_get(self, "@namespaces");
172
- if (import->doc) {
173
- xnode = xmlDocGetRootElement(import->doc);
174
-
168
+ if (ximport->doc)
169
+ {
170
+ xnode = xmlDocGetRootElement(ximport->doc);
175
171
  xns = xnode->nsDef;
176
172
 
177
- while (xns) {
178
- VALUE anamespace = rxml_namespace_wrap(xns);
179
- rb_ary_push(schemas, anamespace);
173
+ while (xns)
174
+ {
175
+ VALUE namespace = rxml_namespace_wrap(xns);
176
+ rb_ary_push(array, namespace);
180
177
  xns = xns->next;
181
178
  }
182
179
  }
@@ -184,95 +181,76 @@ static void storeNs(xmlSchemaImportPtr import, VALUE self, xmlChar *nsname)
184
181
 
185
182
  static VALUE rxml_schema_namespaces(VALUE self)
186
183
  {
187
- VALUE schemas;
184
+ VALUE result;
188
185
  xmlSchemaPtr xschema;
189
186
 
190
187
  Data_Get_Struct(self, xmlSchema, xschema);
191
188
 
192
- if (rb_iv_get(self, "@namespaces") == Qnil) {
193
- schemas = rb_ary_new();
194
- rb_iv_set(self, "@namespaces", schemas);
195
- xmlHashScan(xschema->schemasImports, (xmlHashScanner) storeNs, (void *)self);
196
- }
189
+ result = rb_ary_new();
190
+ xmlHashScan(xschema->schemasImports, (xmlHashScanner)scan_namespaces, (void *)result);
197
191
 
198
- return rb_iv_get(self, "@namespaces");
192
+ return result;
199
193
  }
200
194
 
201
- static void storeType(xmlSchemaTypePtr type, VALUE self, xmlChar *name)
195
+ static void scan_element(xmlSchemaElementPtr xelement, VALUE hash, xmlChar *name)
202
196
  {
203
- VALUE types;
204
- VALUE rtype;
205
-
206
- types = rb_iv_get(self, "@types");
207
- rtype = rxml_wrap_schema_type(type);
208
-
209
- rb_hash_aset(types, rb_str_new2((const char*)name), rtype);
197
+ VALUE element = rxml_wrap_schema_element(xelement);
198
+ rb_hash_aset(hash, rb_str_new2((const char*)name), element);
210
199
  }
211
200
 
212
- static VALUE rxml_schema_collect_types(VALUE self);
213
-
214
- static VALUE rxml_schema_types(VALUE self)
201
+ static VALUE rxml_schema_elements(VALUE self)
215
202
  {
216
- VALUE types;
203
+ VALUE result = rb_hash_new();
217
204
  xmlSchemaPtr xschema;
218
205
 
219
206
  Data_Get_Struct(self, xmlSchema, xschema);
207
+ xmlHashScan(xschema->elemDecl, (xmlHashScanner)scan_element, (void *)result);
220
208
 
221
- if (rb_iv_get(self, "@types") == Qnil) {
222
- types = rb_hash_new();
223
- rb_iv_set(self, "@types", types);
224
- rxml_schema_collect_types(self);
225
- if(xschema != NULL && xschema->typeDecl != NULL)
226
- xmlHashScan(xschema->typeDecl, (xmlHashScanner) storeType, (void *)self);
227
- }
228
-
229
- return rb_iv_get(self, "@types");
209
+ return result;
230
210
  }
231
211
 
232
- static void storeElement(xmlSchemaElementPtr element, VALUE self, xmlChar *name)
212
+ static void scan_type(xmlSchemaTypePtr xtype, VALUE hash, xmlChar *name)
233
213
  {
234
- VALUE elements;
235
- VALUE relement;
236
-
237
- elements = rb_iv_get(self, "@elements");
238
- relement = rxml_wrap_schema_element(element);
239
- rb_hash_aset(elements, rb_str_new2((const char*)name), relement);
214
+ VALUE type = rxml_wrap_schema_type(xtype);
215
+ rb_hash_aset(hash, rb_str_new2((const char*)name), type);
240
216
  }
241
217
 
242
- static VALUE rxml_schema_elements(VALUE self)
218
+ static VALUE rxml_schema_types(VALUE self)
243
219
  {
244
- VALUE elements;
245
- xmlSchemaPtr xschema;
220
+ VALUE result = rb_hash_new();
221
+ xmlSchemaPtr xschema;
246
222
 
247
- Data_Get_Struct(self, xmlSchema, xschema);
223
+ Data_Get_Struct(self, xmlSchema, xschema);
248
224
 
249
- if (rb_iv_get(self, "@elements") == Qnil) {
250
- elements = rb_hash_new();
251
- rb_iv_set(self, "@elements", elements);
252
- xmlHashScan(xschema->elemDecl, (xmlHashScanner) storeElement, (void *)self);
253
- }
225
+ if (xschema != NULL && xschema->typeDecl != NULL)
226
+ {
227
+ xmlHashScan(xschema->typeDecl, (xmlHashScanner)scan_type, (void *)result);
228
+ }
254
229
 
255
- return rb_iv_get(self, "@elements");
230
+ return result;
256
231
  }
257
232
 
258
- static void collectSchemaTypes(xmlSchemaImportPtr import, VALUE self)
233
+ static void collect_imported_types(xmlSchemaImportPtr import, VALUE result)
259
234
  {
260
- if (import->imported && import->schema) {
261
- xmlHashScan(import->schema->typeDecl, (xmlHashScanner) storeType, (void *)self);
235
+ if (import->imported && import->schema)
236
+ {
237
+ xmlHashScan(import->schema->typeDecl, (xmlHashScanner)scan_type, (void *)result);
262
238
  }
263
239
  }
264
240
 
265
- static VALUE rxml_schema_collect_types(VALUE self)
241
+ static VALUE rxml_schema_imported_types(VALUE self)
266
242
  {
267
243
  xmlSchemaPtr xschema;
244
+ VALUE result = rb_hash_new();
268
245
 
269
246
  Data_Get_Struct(self, xmlSchema, xschema);
270
247
 
271
- if(xschema){
272
- xmlHashScan(xschema->schemasImports, (xmlHashScanner) collectSchemaTypes, (void *)self);
248
+ if (xschema)
249
+ {
250
+ xmlHashScan(xschema->schemasImports, (xmlHashScanner)collect_imported_types, (void *)result);
273
251
  }
274
252
 
275
- return Qnil;
253
+ return result;
276
254
  }
277
255
 
278
256
  void rxml_init_schema(void)
@@ -288,10 +266,10 @@ void rxml_init_schema(void)
288
266
  rb_define_method(cXMLSchema, "version", rxml_schema_version, 0);
289
267
  rb_define_method(cXMLSchema, "document", rxml_schema_document, 0);
290
268
 
291
- rb_define_method(cXMLSchema, "_namespaces", rxml_schema_namespaces, 0);
292
- rb_define_method(cXMLSchema, "_collect_types", rxml_schema_collect_types, 0);
293
- rb_define_method(cXMLSchema, "types", rxml_schema_types, 0);
294
269
  rb_define_method(cXMLSchema, "elements", rxml_schema_elements, 0);
270
+ rb_define_method(cXMLSchema, "imported_types", rxml_schema_imported_types, 0);
271
+ rb_define_method(cXMLSchema, "namespaces", rxml_schema_namespaces, 0);
272
+ rb_define_method(cXMLSchema, "types", rxml_schema_types, 0);
295
273
 
296
274
  rxml_init_schema_facet();
297
275
  rxml_init_schema_element();
@@ -64,22 +64,25 @@ static VALUE rxml_schema_element_value(VALUE self)
64
64
  QNIL_OR_STRING(xelem->value)
65
65
  }
66
66
 
67
- static VALUE rxml_schema_element_min_occurs(VALUE self)
68
- {
69
- return rb_iv_get(self, "@min");
70
- }
71
-
72
- static VALUE rxml_schema_element_max_occurs(VALUE self)
73
- {
74
- return rb_iv_get(self, "@max");
75
- }
76
-
77
67
  static VALUE rxml_schema_element_annot(VALUE self)
78
68
  {
79
- return rb_iv_get(self, "@annotation");
69
+ VALUE result = Qnil;
70
+ xmlSchemaElementPtr xelem;
71
+
72
+ Data_Get_Struct(self, xmlSchemaElement, xelem);
73
+
74
+ if (xelem != NULL && xelem->annot != NULL && xelem->annot->content != NULL)
75
+ {
76
+ xmlChar *content = xmlNodeGetContent(xelem->annot->content);
77
+ if (content)
78
+ {
79
+ result = rxml_new_cstr(content, NULL);
80
+ xmlFree(content);
81
+ }
82
+ }
83
+ return result;
80
84
  }
81
85
 
82
-
83
86
  void rxml_init_schema_element(void)
84
87
  {
85
88
  cXMLSchemaElement = rb_define_class_under(cXMLSchema, "Element", rb_cObject);
@@ -88,7 +91,5 @@ void rxml_init_schema_element(void)
88
91
  rb_define_method(cXMLSchemaElement, "type", rxml_schema_element_type, 0);
89
92
  rb_define_method(cXMLSchemaElement, "node", rxml_schema_element_node, 0);
90
93
  rb_define_method(cXMLSchemaElement, "value", rxml_schema_element_value, 0);
91
- rb_define_method(cXMLSchemaElement, "min_occurs", rxml_schema_element_min_occurs, 0);
92
- rb_define_method(cXMLSchemaElement, "max_occurs", rxml_schema_element_max_occurs, 0);
93
94
  rb_define_method(cXMLSchemaElement, "annotation", rxml_schema_element_annot, 0);
94
95
  }
@@ -50,28 +50,22 @@ static VALUE rxml_schema_type_base(VALUE self)
50
50
  static VALUE rxml_schema_type_facets(VALUE self)
51
51
  {
52
52
  xmlSchemaTypePtr xtype;
53
- xmlSchemaFacetPtr facet;
54
- VALUE facets;
55
- VALUE rfacet;
53
+ xmlSchemaFacetPtr xfacet;
54
+ VALUE result = rb_ary_new();
55
+ VALUE facet;
56
56
 
57
- facets = rb_iv_get(self, "@facets");
58
-
59
- if (facets == Qnil) {
60
- facets = rb_ary_new();
61
- Data_Get_Struct(self, xmlSchemaType, xtype);
62
-
63
- facet = xtype->facets;
57
+ Data_Get_Struct(self, xmlSchemaType, xtype);
64
58
 
65
- while (facet != NULL) {
66
- rfacet = rxml_wrap_schema_facet((xmlSchemaFacetPtr) facet);
67
- rb_ary_push(facets, rfacet);
68
- facet = facet->next;
69
- }
59
+ xfacet = xtype->facets;
70
60
 
71
- rb_iv_set(self, "@facets", facets);
61
+ while (xfacet != NULL)
62
+ {
63
+ facet = rxml_wrap_schema_facet((xmlSchemaFacetPtr)xfacet);
64
+ rb_ary_push(result, facet);
65
+ xfacet = xfacet->next;
72
66
  }
73
67
 
74
- return facets;
68
+ return result;
75
69
  }
76
70
 
77
71
  static VALUE rxml_schema_type_node(VALUE self)
@@ -95,67 +89,60 @@ static VALUE rxml_schema_type_kind(VALUE self)
95
89
  return INT2NUM(xtype->type);
96
90
  }
97
91
 
98
- static VALUE get_annotation(xmlSchemaAnnotPtr annot)
99
- {
100
- if(annot != NULL && annot->content != NULL && annot->content->content != NULL)
101
- return rb_str_new2((const char *) annot->content->content);
102
- else
103
- return Qnil;
104
- }
105
-
106
92
  static VALUE rxml_schema_type_annot(VALUE self)
107
93
  {
94
+ VALUE result = Qnil;
108
95
  xmlSchemaTypePtr xtype;
109
96
 
110
97
  Data_Get_Struct(self, xmlSchemaType, xtype);
111
98
 
112
- if(xtype != NULL && xtype->annot != NULL)
113
- return get_annotation(xtype->annot);
114
- else
115
- return Qnil;
99
+ if(xtype != NULL && xtype->annot != NULL && xtype->annot->content != NULL)
100
+ {
101
+ xmlChar *content = xmlNodeGetContent(xtype->annot->content);
102
+ if (content)
103
+ {
104
+ result = rxml_new_cstr(content, NULL);
105
+ xmlFree(content);
106
+ }
107
+ }
108
+ return result;
116
109
  }
117
110
 
118
- static void rxmlSchemaCollectElements(xmlSchemaParticlePtr particle, VALUE self)
111
+ static void rxmlSchemaCollectElements(xmlSchemaParticlePtr xparticle, VALUE hash)
119
112
  {
120
- VALUE elements;
121
- VALUE relement;
122
- xmlSchemaTreeItemPtr term;
113
+ VALUE element;
114
+ xmlSchemaTreeItemPtr xterm;
123
115
 
124
- if (particle == NULL)
116
+ if (xparticle == NULL)
125
117
  return;
126
118
 
127
- term = particle->children;
128
-
129
- if (term != NULL) {
130
- elements = rb_iv_get(self, "@elements");
119
+ xterm = xparticle->children;
131
120
 
132
- switch (term->type) {
121
+ if (xterm != NULL)
122
+ {
123
+ switch (xterm->type)
124
+ {
133
125
  case XML_SCHEMA_TYPE_ELEMENT:
134
- relement = rxml_wrap_schema_element((xmlSchemaElementPtr) term);
126
+ element = rxml_wrap_schema_element((xmlSchemaElementPtr)xterm);
127
+ rb_iv_set(element, "@min", INT2NUM(xparticle->minOccurs));
135
128
 
136
-
137
- rb_iv_set(relement, "@min", INT2NUM(particle->minOccurs));
138
-
139
- if (particle->maxOccurs >= UNBOUNDED)
140
- rb_iv_set(relement, "@max", rb_const_get(rb_path2class("Float"), rb_intern("INFINITY")));
129
+ if (xparticle->maxOccurs >= UNBOUNDED)
130
+ rb_iv_set(element, "@max", rb_const_get(rb_path2class("Float"), rb_intern("INFINITY")));
141
131
  else
142
- rb_iv_set(relement, "@max", INT2NUM(particle->maxOccurs));
132
+ rb_iv_set(element, "@max", INT2NUM(xparticle->maxOccurs));
143
133
 
144
- if (particle->annot != NULL)
134
+ if (xparticle->annot != NULL)
145
135
  {
146
- xmlChar *content;
147
-
148
- content = xmlNodeGetContent(particle->annot->content);
136
+ xmlChar *content = xmlNodeGetContent(xparticle->annot->content);
149
137
 
150
138
  if (content != NULL)
151
139
  {
152
- rb_iv_set(relement, "@annotation", rb_str_new2((const char *) content));
140
+ rb_iv_set(element, "@annotation", rb_str_new2((const char *) content));
153
141
  xmlFree(content);
154
142
  }
155
143
  }
156
144
 
157
- rb_hash_aset(elements, rb_str_new2((const char *) ((xmlSchemaElementPtr) term)->name), relement);
158
-
145
+ rb_hash_aset(hash, rb_str_new2((const char *) ((xmlSchemaElementPtr)xterm)->name), element);
159
146
  break;
160
147
 
161
148
  case XML_SCHEMA_TYPE_SEQUENCE:
@@ -171,71 +158,57 @@ static void rxmlSchemaCollectElements(xmlSchemaParticlePtr particle, VALUE self)
171
158
  break;
172
159
 
173
160
  default:
174
-
175
161
  return;
176
162
  }
177
163
  }
178
164
 
179
- if (term &&
180
- ((term->type == XML_SCHEMA_TYPE_SEQUENCE) ||
181
- (term->type == XML_SCHEMA_TYPE_CHOICE) ||
182
- (term->type == XML_SCHEMA_TYPE_ALL)) &&
183
- (term->children != NULL)) {
184
-
185
- rxmlSchemaCollectElements((xmlSchemaParticlePtr) term->children, self);
165
+ if (xterm &&
166
+ ((xterm->type == XML_SCHEMA_TYPE_SEQUENCE) || (xterm->type == XML_SCHEMA_TYPE_CHOICE) || (xterm->type == XML_SCHEMA_TYPE_ALL)) &&
167
+ (xterm->children != NULL))
168
+ {
169
+ rxmlSchemaCollectElements((xmlSchemaParticlePtr)xterm->children, hash);
186
170
  }
187
171
 
188
- if (particle->next != NULL)
189
- rxmlSchemaCollectElements((xmlSchemaParticlePtr) particle->next, self);
172
+ if (xparticle->next != NULL)
173
+ {
174
+ rxmlSchemaCollectElements((xmlSchemaParticlePtr)xparticle->next, hash);
175
+ }
190
176
  }
191
177
 
192
- static VALUE
193
- rxml_schema_type_elements(VALUE self)
178
+ static VALUE rxml_schema_type_elements(VALUE self)
194
179
  {
195
- VALUE elements;
180
+ VALUE result = rb_hash_new();
196
181
  xmlSchemaTypePtr xtype;
197
182
 
198
183
  Data_Get_Struct(self, xmlSchemaType, xtype);
184
+ rxmlSchemaCollectElements((xmlSchemaParticlePtr) xtype->subtypes, result);
199
185
 
200
- if (rb_iv_get(self, "@elements") == Qnil) {
201
- elements = rb_hash_new();
202
- rb_iv_set(self, "@elements", elements);
203
- rxmlSchemaCollectElements((xmlSchemaParticlePtr) xtype->subtypes, self);
204
- }
205
-
206
- return rb_iv_get(self, "@elements");
186
+ return result;
207
187
  }
208
188
 
209
- static VALUE
210
- rxml_schema_type_attributes(VALUE self)
189
+ static VALUE rxml_schema_type_attributes(VALUE self)
211
190
  {
212
- VALUE attributes;
191
+ VALUE result = rb_ary_new();
213
192
  xmlSchemaTypePtr xtype;
214
- xmlSchemaAttributeUsePtr use;
215
- xmlSchemaItemListPtr uses;
193
+ xmlSchemaAttributeUsePtr xuse;
194
+ xmlSchemaItemListPtr xuses;
216
195
  int i;
217
196
 
218
197
  Data_Get_Struct(self, xmlSchemaType, xtype);
219
-
220
- if (rb_iv_get(self, "@attributes") == Qnil) {
221
- attributes = rb_ary_new();
222
- rb_iv_set(self, "@attributes", attributes);
223
-
224
- uses = xtype->attrUses;
225
-
226
- if ((uses == NULL) || (uses->nbItems == 0))
227
- return rb_iv_get(self, "@attributes");
228
-
229
- for (i = 0; i < uses->nbItems; i++) {
230
- use = (xmlSchemaAttributeUsePtr) uses->items[i];
231
- rb_ary_push(attributes, rxml_wrap_schema_attribute(use));
198
+ xuses = xtype->attrUses;
199
+
200
+ if (xuses != NULL)
201
+ {
202
+ for (i = 0; i < xuses->nbItems; i++)
203
+ {
204
+ xuse = (xmlSchemaAttributeUsePtr)xuses->items[i];
205
+ rb_ary_push(result, rxml_wrap_schema_attribute(xuse));
232
206
  }
233
207
  }
234
208
 
235
- return rb_iv_get(self, "@attributes");
209
+ return result;
236
210
  }
237
211
 
238
-
239
212
  void rxml_init_schema_type(void)
240
213
  {
241
214
  /* Add in infinity support for ruby 1.8.7 */
@@ -1,9 +1,9 @@
1
1
  /* Don't nuke this block! It is used for automatically updating the
2
2
  * versions below. VERSION = string formatting, VERNUM = numbered
3
3
  * version for inline testing: increment both or none at all.*/
4
- #define RUBY_LIBXML_VERSION "3.0.0"
5
- #define RUBY_LIBXML_VERNUM 300
4
+ #define RUBY_LIBXML_VERSION "3.2.2"
5
+ #define RUBY_LIBXML_VERNUM 321
6
6
  #define RUBY_LIBXML_VER_MAJ 3
7
- #define RUBY_LIBXML_VER_MIN 0
8
- #define RUBY_LIBXML_VER_MIC 0
7
+ #define RUBY_LIBXML_VER_MIN 2
8
+ #define RUBY_LIBXML_VER_MIC 2
9
9
  #define RUBY_LIBXML_VER_PATCH 0