ox 2.0.9 → 2.0.11

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ox might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee595cb2877fd846e3876313780517e91a3e4705
4
- data.tar.gz: 14418d0ea4f70c7b876727992546f074855ce509
3
+ metadata.gz: d43573d307b0054cf658e7b827330e1bb9be6b30
4
+ data.tar.gz: e8ab4066d5969e207b7df07ca2432324d84e33ac
5
5
  SHA512:
6
- metadata.gz: c7f39413fb9be2701c8d28d2410b78bb503656dc05132affea3dd1fa18aae54a42933225001d07b525764f0ed6d4e86bd479db47820a72b86066f3a7e6a3f8a8
7
- data.tar.gz: b8e72240a020d7e990ff4de9e24deac1243ee13c159ece51c096bcc93a7bb5a3c0c92f4d9826363fcd2b1e7a4575ee2117d2132a645bafda912e25d8dfd82d12
6
+ metadata.gz: 54bd52dcbc721e8f76068ad2f48a74ce12f558b45d8a6b0435c7cacfcacc978bd492ece4877ac7ec099ffcae53f8107a696670844e76aa4032679eaafb72c24d
7
+ data.tar.gz: f08283d2bff69dd8a6b3e73f5deded1f2a376c9c3d1f97ecf24754a855134f0430a8bd0c6a18ebd132c6d9fe1a8cfe06c7071c53324d05301e1d17ce794a5a98
data/README.md CHANGED
@@ -34,9 +34,9 @@ A fast XML parser and Object marshaller as a Ruby gem.
34
34
 
35
35
  ## <a name="release">Release Notes</a>
36
36
 
37
- ### Release 2.0.9
37
+ ### Release 2.0.11
38
38
 
39
- - Fixed bug that did not allow ISO-8859-1 characters and caused a crash.
39
+ - Added support for BigDecimals in :object mode.
40
40
 
41
41
  ## <a name="description">Description</a>
42
42
 
@@ -171,6 +171,38 @@ Ox.sax_parse(handler, io)
171
171
  # end: top
172
172
  ```
173
173
 
174
+ ### Yielding results immediately while SAX XML Parsing:
175
+
176
+ ```ruby
177
+ require 'stringio'
178
+ require 'ox'
179
+
180
+ class Yielder < ::Ox::Sax
181
+ def initialize(block); @yield_to = block; end
182
+ def start_element(name); @yield_to.call(name); end
183
+ end
184
+
185
+ io = StringIO.new(%{
186
+ <top name="sample">
187
+ <middle name="second">
188
+ <bottom name="third"/>
189
+ </middle>
190
+ </top>
191
+ })
192
+
193
+ proc = Proc.new { |name| puts name }
194
+ handler = Yielder.new(proc)
195
+ puts "before parse"
196
+ Ox.sax_parse(handler, io)
197
+ puts "after parse"
198
+ # outputs
199
+ # before parse
200
+ # top
201
+ # middle
202
+ # bottom
203
+ # after parse
204
+ ```
205
+
174
206
  ### Object XML format
175
207
 
176
208
  The XML format used for Object encoding follows the structure of the
@@ -739,6 +739,14 @@ dump_obj(ID aid, VALUE obj, int depth, Out out) {
739
739
  dump_date(out, obj);
740
740
  e.indent = -1;
741
741
  out->w_end(out, &e);
742
+ } else if (0 == strcmp("BigDecimal", classname)) {
743
+ VALUE rs = rb_funcall(obj, ox_to_s_id, 0);
744
+
745
+ e.type = BigDecimalCode;
746
+ out->w_start(out, &e);
747
+ dump_value(out, StringValuePtr(rs), RSTRING_LEN(rs));
748
+ e.indent = -1;
749
+ out->w_end(out, &e);
742
750
  } else {
743
751
  if (StrictEffort == out->opts->effort) {
744
752
  rb_raise(rb_eNotImpError, "Failed to dump T_DATA %s\n", classname);
@@ -30,6 +30,8 @@ dflags = {
30
30
  'HAS_RSTRUCT' => ('ruby' == type || 'ree' == type) ? 1 : 0,
31
31
  'HAS_IVAR_HELPERS' => ('ruby' == type && ('1' == version[0] && '9' == version[1]) || '2' <= version[0]) ? 1 : 0,
32
32
  'HAS_PROC_WITH_BLOCK' => ('ruby' == type && ('1' == version[0] && '9' == version[1]) || '2' <= version[0]) ? 1 : 0,
33
+ 'HAS_GC_GUARD' => ('jruby' != type && 'rubinius' != type) ? 1 : 0,
34
+ 'HAS_BIGDECIMAL' => ('jruby' != type) ? 1 : 0,
33
35
  'HAS_TOP_LEVEL_ST_H' => ('ree' == type || ('ruby' == type && '1' == version[0] && '8' == version[1])) ? 1 : 0,
34
36
  'NEEDS_UIO' => (RUBY_PLATFORM =~ /(win|w)32$/) ? 0 : 1,
35
37
  }
@@ -94,6 +94,9 @@ create_doc(PInfo pi) {
94
94
 
95
95
  helper_stack_init(&pi->helpers);
96
96
  doc = rb_obj_alloc(ox_document_clas);
97
+ #if HAS_GC_GUARD
98
+ RB_GC_GUARD(doc);
99
+ #endif
97
100
  nodes = rb_ary_new();
98
101
  rb_ivar_set(doc, ox_attributes_id, rb_hash_new());
99
102
  rb_ivar_set(doc, ox_nodes_id, nodes);
@@ -557,6 +557,13 @@ add_text(PInfo pi, char *text, int closed) {
557
557
  case BignumCode:
558
558
  h->obj = rb_cstr_to_inum(text, 10, 1);
559
559
  break;
560
+ case BigDecimalCode:
561
+ #if HAS_BIGDECIMAL
562
+ h->obj = rb_funcall(ox_bigdecimal_class, ox_new_id, 1, rb_str_new2(text));
563
+ #else
564
+ h->obj = Qnil;
565
+ #endif
566
+ break;
560
567
  default:
561
568
  h->obj = Qnil;
562
569
  break;
@@ -623,6 +630,7 @@ add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
623
630
  case Symbol64Code:
624
631
  case RegexpCode:
625
632
  case BignumCode:
633
+ case BigDecimalCode:
626
634
  case ComplexCode:
627
635
  case DateCode:
628
636
  case TimeCode:
@@ -80,6 +80,7 @@ ID ox_local_id;
80
80
  ID ox_mesg_id;
81
81
  ID ox_message_id;
82
82
  ID ox_nodes_id;
83
+ ID ox_new_id;
83
84
  ID ox_num_id;
84
85
  ID ox_parse_id;
85
86
  ID ox_read_id;
@@ -102,6 +103,7 @@ VALUE ox_zero_fixnum;
102
103
 
103
104
  VALUE ox_arg_error_class;
104
105
  VALUE ox_bag_clas;
106
+ VALUE ox_bigdecimal_class;
105
107
  VALUE ox_cdata_clas;
106
108
  VALUE ox_comment_clas;
107
109
  VALUE ox_date_class;
@@ -402,10 +404,17 @@ to_obj(VALUE self, VALUE ruby_xml) {
402
404
  xml = ALLOCA_N(char, len);
403
405
  }
404
406
  memcpy(xml, x, len);
407
+ #if HAS_GC_GUARD
408
+ rb_gc_disable();
409
+ #endif
405
410
  obj = ox_parse(xml, ox_obj_callbacks, 0, &options, &err);
406
411
  if (SMALL_XML < len) {
407
412
  xfree(xml);
408
413
  }
414
+ #if HAS_GC_GUARD
415
+ RB_GC_GUARD(obj);
416
+ rb_gc_enable();
417
+ #endif
409
418
  if (err_has(&err)) {
410
419
  ox_err_raise(&err);
411
420
  }
@@ -514,7 +523,14 @@ load(char *xml, int argc, VALUE *argv, VALUE self, VALUE encoding, Err err) {
514
523
  xml = defuse_bom(xml, &options);
515
524
  switch (options.mode) {
516
525
  case ObjMode:
526
+ #if HAS_GC_GUARD
527
+ rb_gc_disable();
528
+ #endif
517
529
  obj = ox_parse(xml, ox_obj_callbacks, 0, &options, err);
530
+ #if HAS_GC_GUARD
531
+ RB_GC_GUARD(obj);
532
+ rb_gc_enable();
533
+ #endif
518
534
  break;
519
535
  case GenMode:
520
536
  obj = ox_parse(xml, ox_gen_callbacks, 0, &options, err);
@@ -854,6 +870,7 @@ void Init_ox() {
854
870
 
855
871
  rb_require("time");
856
872
  rb_require("date");
873
+ rb_require("bigdecimal");
857
874
  rb_require("stringio");
858
875
 
859
876
  ox_at_column_id = rb_intern("@column");
@@ -886,6 +903,7 @@ void Init_ox() {
886
903
  ox_mesg_id = rb_intern("mesg");
887
904
  ox_message_id = rb_intern("message");
888
905
  ox_nodes_id = rb_intern("@nodes");
906
+ ox_new_id = rb_intern("new");
889
907
  ox_num_id = rb_intern("@num");
890
908
  ox_parse_id = rb_intern("parse");
891
909
  ox_read_id = rb_intern("read");
@@ -907,6 +925,7 @@ void Init_ox() {
907
925
  ox_arg_error_class = rb_const_get_at(Ox, rb_intern("ArgError"));
908
926
  ox_struct_class = rb_const_get(rb_cObject, rb_intern("Struct"));
909
927
  ox_stringio_class = rb_const_get(rb_cObject, rb_intern("StringIO"));
928
+ ox_bigdecimal_class = rb_const_get(rb_cObject, rb_intern("BigDecimal"));
910
929
 
911
930
  auto_define_sym = ID2SYM(rb_intern("auto_define")); rb_gc_register_address(&auto_define_sym);
912
931
  auto_sym = ID2SYM(rb_intern("auto")); rb_gc_register_address(&auto_sym);
@@ -971,5 +990,8 @@ _ox_raise_error(const char *msg, const char *xml, const char *current, const cha
971
990
  xline++;
972
991
  }
973
992
  }
993
+ #if HAS_GC_GUARD
994
+ rb_gc_enable();
995
+ #endif
974
996
  rb_raise(ox_parse_error_class, "%s at line %d, column %d [%s:%d]\n", msg, xline, col, file, line);
975
997
  }
@@ -214,6 +214,7 @@ extern ID ox_local_id;
214
214
  extern ID ox_mesg_id;
215
215
  extern ID ox_message_id;
216
216
  extern ID ox_nodes_id;
217
+ extern ID ox_new_id;
217
218
  extern ID ox_num_id;
218
219
  extern ID ox_parse_id;
219
220
  extern ID ox_read_id;
@@ -237,6 +238,7 @@ extern VALUE ox_utf8_encoding;
237
238
  extern void *ox_utf8_encoding;
238
239
  #endif
239
240
 
241
+ extern VALUE ox_bigdecimal_class;
240
242
  extern VALUE ox_date_class;
241
243
  extern VALUE ox_empty_string;
242
244
  extern VALUE ox_encoding_sym;
@@ -38,6 +38,7 @@ typedef enum {
38
38
  ClassCode = 'c',
39
39
  Symbol64Code = 'd', /* base64 encoded Symbol */
40
40
  DateCode = 'D',
41
+ BigDecimalCode = 'B',
41
42
  ExceptionCode = 'e',
42
43
  FloatCode = 'f',
43
44
  RegexpCode = 'g',
@@ -49,7 +49,7 @@ module Ox
49
49
  # Element.
50
50
  # @return [Array] all child Nodes.
51
51
  def nodes
52
- @nodes = [] if !instance_variable_defined?(:@nodes) or @nodes.nil?
52
+ return [] if !instance_variable_defined?(:@nodes) or @nodes.nil?
53
53
  @nodes
54
54
  end
55
55
 
@@ -57,8 +57,8 @@ module Ox
57
57
  # so multiple appends can be chained together.
58
58
  # @param [Node] node Node to append to the nodes array
59
59
  def <<(node)
60
- @nodes = [] if !instance_variable_defined?(:@nodes) or @nodes.nil?
61
60
  raise "argument to << must be a String or Ox::Node." unless node.is_a?(String) or node.is_a?(Node)
61
+ @nodes = [] if !instance_variable_defined?(:@nodes) or @nodes.nil?
62
62
  @nodes << node
63
63
  self
64
64
  end
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Ox
3
3
  # Current version of the module.
4
- VERSION = '2.0.9'
4
+ VERSION = '2.0.11'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ox
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.9
4
+ version: 2.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-02 00:00:00.000000000 Z
11
+ date: 2013-10-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: "A fast XML parser and object serializer that uses only standard C lib.\n
14
14
  \ \nOptimized XML (Ox), as the name implies was written to provide speed
@@ -69,7 +69,9 @@ files:
69
69
  - LICENSE
70
70
  - README.md
71
71
  homepage: http://www.ohler.com/ox
72
- licenses: []
72
+ licenses:
73
+ - MIT
74
+ - GPL-3.0
73
75
  metadata: {}
74
76
  post_install_message:
75
77
  rdoc_options:
@@ -95,3 +97,4 @@ signing_key:
95
97
  specification_version: 4
96
98
  summary: A fast XML parser and object serializer.
97
99
  test_files: []
100
+ has_rdoc: true