ox 1.2.7 → 1.2.8

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.

@@ -36,6 +36,7 @@
36
36
  typedef struct _Cache *Cache;
37
37
 
38
38
  extern void ox_cache_new(Cache *cache);
39
+
39
40
  extern VALUE ox_cache_get(Cache cache, const char *key, VALUE **slot);
40
41
 
41
42
  extern void ox_cache_print(Cache cache);
@@ -20,6 +20,7 @@ struct _Cache8 {
20
20
  };
21
21
  };
22
22
 
23
+ static void cache8_delete(Cache8 cache, int depth);
23
24
  static void slot_print(Cache8 cache, VALUE key, unsigned int depth);
24
25
 
25
26
  void
@@ -35,6 +36,26 @@ ox_cache8_new(Cache8 *cache) {
35
36
  }
36
37
  }
37
38
 
39
+ void
40
+ ox_cache8_delete(Cache8 cache) {
41
+ cache8_delete(cache, 0);
42
+ }
43
+
44
+ static void
45
+ cache8_delete(Cache8 cache, int depth) {
46
+ Cache8 *cp;
47
+ unsigned int i;
48
+
49
+ for (i = 0, cp = cache->slots; i < SLOT_CNT; i++, cp++) {
50
+ if (0 != *cp) {
51
+ if (DEPTH - 1 != depth) {
52
+ cache8_delete(*cp, depth + 1);
53
+ }
54
+ }
55
+ }
56
+ free(cache);
57
+ }
58
+
38
59
  unsigned long
39
60
  ox_cache8_get(Cache8 cache, VALUE key, unsigned long **slot) {
40
61
  Cache8 *cp;
@@ -36,6 +36,8 @@
36
36
  typedef struct _Cache8 *Cache8;
37
37
 
38
38
  extern void ox_cache8_new(Cache8 *cache);
39
+ extern void ox_cache8_delete(Cache8 cache);
40
+
39
41
  extern unsigned long ox_cache8_get(Cache8 cache, VALUE key, unsigned long **slot);
40
42
 
41
43
  extern void ox_cache8_print(Cache8 cache);
@@ -125,8 +125,13 @@ obj_class_code(VALUE obj) {
125
125
  case RUBY_T_FALSE: return FalseClassCode;
126
126
  case RUBY_T_FIXNUM: return FixnumCode;
127
127
  case RUBY_T_FLOAT: return FloatCode;
128
- case RUBY_T_STRING: return (is_xml_friendly((u_char*)StringValuePtr(obj), (int)RSTRING_LEN(obj))) ? StringCode : Base64Code;
129
- case RUBY_T_SYMBOL: return SymbolCode;
128
+ case RUBY_T_STRING: return (is_xml_friendly((u_char*)StringValuePtr(obj), (int)RSTRING_LEN(obj))) ? StringCode : String64Code;
129
+ case RUBY_T_SYMBOL:
130
+ {
131
+ const char *sym = rb_id2name(SYM2ID(obj));
132
+
133
+ return (is_xml_friendly((u_char*)sym, (int)strlen(sym))) ? SymbolCode : Symbol64Code;
134
+ }
130
135
  case RUBY_T_DATA: return (rb_cTime == rb_obj_class(obj)) ? TimeCode : 0;
131
136
  case RUBY_T_STRUCT: return (rb_cRange == rb_obj_class(obj)) ? RangeCode : StructCode;
132
137
  case RUBY_T_OBJECT: return (ox_document_clas == rb_obj_class(obj) || ox_element_clas == rb_obj_class(obj)) ? RawCode : ObjectCode;
@@ -441,9 +446,11 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
441
446
  e.indent = depth * out->indent;
442
447
  }
443
448
  e.id = 0;
449
+ e.clas.len = 0;
450
+ e.clas.str = 0;
444
451
  switch (rb_type(obj)) {
445
452
  case RUBY_T_NIL:
446
- e.type = NilClassCode; e.clas.len = 0; e.clas.str = 0;
453
+ e.type = NilClassCode;
447
454
  e.closed = 1;
448
455
  out->w_start(out, &e);
449
456
  break;
@@ -452,7 +459,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
452
459
  break;
453
460
  }
454
461
  cnt = (int)RARRAY_LEN(obj);
455
- e.type = ArrayCode; e.clas.len = 5; e.clas.str = "Array";
462
+ e.type = ArrayCode;
456
463
  e.closed = (0 >= cnt);
457
464
  out->w_start(out, &e);
458
465
  if (!e.closed) {
@@ -471,7 +478,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
471
478
  break;
472
479
  }
473
480
  cnt = (int)RHASH_SIZE(obj);
474
- e.type = HashCode; e.clas.len = 4; e.clas.str = "Hash";
481
+ e.type = HashCode;
475
482
  e.closed = (0 >= cnt);
476
483
  out->w_start(out, &e);
477
484
  if (0 < cnt) {
@@ -484,24 +491,24 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
484
491
  }
485
492
  break;
486
493
  case RUBY_T_TRUE:
487
- e.type = TrueClassCode; e.clas.len = 9; e.clas.str = "TrueClass";
494
+ e.type = TrueClassCode;
488
495
  e.closed = 1;
489
496
  out->w_start(out, &e);
490
497
  break;
491
498
  case RUBY_T_FALSE:
492
- e.type = FalseClassCode; e.clas.len = 10; e.clas.str = "FalseClass";
499
+ e.type = FalseClassCode;
493
500
  e.closed = 1;
494
501
  out->w_start(out, &e);
495
502
  break;
496
503
  case RUBY_T_FIXNUM:
497
- e.type = FixnumCode; e.clas.len = 6; e.clas.str = "Fixnum";
504
+ e.type = FixnumCode;
498
505
  out->w_start(out, &e);
499
506
  dump_num(out, obj);
500
507
  e.indent = -1;
501
508
  out->w_end(out, &e);
502
509
  break;
503
510
  case RUBY_T_FLOAT:
504
- e.type = FloatCode; e.clas.len = 5; e.clas.str = "Float";
511
+ e.type = FloatCode;
505
512
  cnt = sprintf(value_buf, "%0.16g", RFLOAT_VALUE(obj)); // used sprintf due to bug in snprintf
506
513
  out->w_start(out, &e);
507
514
  dump_value(out, value_buf, cnt);
@@ -518,7 +525,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
518
525
  str = StringValuePtr(obj);
519
526
  cnt = (int)RSTRING_LEN(obj);
520
527
  if (is_xml_friendly((u_char*)str, cnt)) {
521
- e.type = StringCode; e.clas.len = 6; e.clas.str = "String";
528
+ e.type = StringCode;
522
529
  out->w_start(out, &e);
523
530
  dump_value(out, str, cnt);
524
531
  e.indent = -1;
@@ -528,7 +535,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
528
535
  char *b64 = buf64;
529
536
  unsigned long size = b64_size(cnt);
530
537
 
531
- e.type = Base64Code; e.clas.len = 6; e.clas.str = "Base64";
538
+ e.type = String64Code;
532
539
  if (sizeof(buf64) < size) {
533
540
  if (0 == (b64 = (char*)malloc(size + 1))) {
534
541
  rb_raise(rb_eNoMemError, "Failed to create string. [%d:%s]\n", ENOSPC, strerror(ENOSPC));
@@ -549,11 +556,33 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
549
556
  {
550
557
  const char *sym = rb_id2name(SYM2ID(obj));
551
558
 
552
- e.type = SymbolCode; e.clas.len = 6; e.clas.str = "Symbol";
553
- out->w_start(out, &e);
554
- dump_value(out, sym, strlen(sym));
555
- e.indent = -1;
556
- out->w_end(out, &e);
559
+ cnt = (int)strlen(sym);
560
+ if (is_xml_friendly((u_char*)sym, cnt)) {
561
+ e.type = SymbolCode;
562
+ out->w_start(out, &e);
563
+ dump_value(out, sym, cnt);
564
+ e.indent = -1;
565
+ out->w_end(out, &e);
566
+ } else {
567
+ char buf64[4096];
568
+ char *b64 = buf64;
569
+ unsigned long size = b64_size(cnt);
570
+
571
+ e.type = Symbol64Code;
572
+ if (sizeof(buf64) < size) {
573
+ if (0 == (b64 = (char*)malloc(size + 1))) {
574
+ rb_raise(rb_eNoMemError, "Failed to create string. [%d:%s]\n", ENOSPC, strerror(ENOSPC));
575
+ }
576
+ }
577
+ to_base64((u_char*)sym, cnt, b64);
578
+ out->w_start(out, &e);
579
+ dump_value(out, b64, size);
580
+ e.indent = -1;
581
+ out->w_end(out, &e);
582
+ if (buf64 != b64) {
583
+ free(b64);
584
+ }
585
+ }
557
586
  break;
558
587
  }
559
588
  case RUBY_T_DATA:
@@ -562,7 +591,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
562
591
 
563
592
  clas = rb_obj_class(obj);
564
593
  if (rb_cTime == clas) {
565
- e.type = TimeCode; e.clas.len = 4; e.clas.str = "Time";
594
+ e.type = TimeCode;
566
595
  out->w_start(out, &e);
567
596
  out->w_time(out, obj);
568
597
  e.indent = -1;
@@ -659,7 +688,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
659
688
 
660
689
  cnt = (int)RREGEXP_SRC_LEN(obj);
661
690
  #endif
662
- e.type = RegexpCode; e.clas.len = 6; e.clas.str = "Regexp";
691
+ e.type = RegexpCode;
663
692
  out->w_start(out, &e);
664
693
  if (is_xml_friendly((u_char*)s, cnt)) {
665
694
  //dump_value(out, "/", 1);
@@ -700,7 +729,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
700
729
  {
701
730
  VALUE rs = rb_big2str(obj, 10);
702
731
 
703
- e.type = BignumCode; e.clas.len = 6; e.clas.str = "Bignum";
732
+ e.type = BignumCode;
704
733
  out->w_start(out, &e);
705
734
  dump_value(out, StringValuePtr(rs), RSTRING_LEN(rs));
706
735
  e.indent = -1;
@@ -708,14 +737,14 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
708
737
  break;
709
738
  }
710
739
  case RUBY_T_COMPLEX:
711
- e.type = ComplexCode; e.clas.len = 7; e.clas.str = "Complex";
740
+ e.type = ComplexCode;
712
741
  out->w_start(out, &e);
713
742
  dump_obj(0, RCOMPLEX(obj)->real, depth + 1, out);
714
743
  dump_obj(0, RCOMPLEX(obj)->imag, depth + 1, out);
715
744
  out->w_end(out, &e);
716
745
  break;
717
746
  case RUBY_T_RATIONAL:
718
- e.type = RationalCode; e.clas.len = 8; e.clas.str = "Rational";
747
+ e.type = RationalCode;
719
748
  out->w_start(out, &e);
720
749
  dump_obj(0, RRATIONAL(obj)->num, depth + 1, out);
721
750
  dump_obj(0, RRATIONAL(obj)->den, depth + 1, out);
@@ -735,7 +764,7 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
735
764
  rb_raise(rb_eNotImpError, "Failed to dump %s Object (%02x)\n",
736
765
  rb_class2name(rb_obj_class(obj)), rb_type(obj));
737
766
  } else {
738
- e.type = NilClassCode; e.clas.len = 0; e.clas.str = 0;
767
+ e.type = NilClassCode;
739
768
  e.closed = 1;
740
769
  out->w_start(out, &e);
741
770
  }
@@ -938,6 +967,9 @@ dump_obj_to_xml(VALUE obj, Options copts, Out out) {
938
967
  dump_first_obj(obj, out);
939
968
  }
940
969
  dump_value(out, "\n", 1);
970
+ if (Yes == copts->circular) {
971
+ ox_cache8_delete(out->circ_cache);
972
+ }
941
973
  }
942
974
 
943
975
  char*
@@ -416,7 +416,7 @@ add_text(PInfo pi, char *text, int closed) {
416
416
  case TimeCode:
417
417
  pi->h->obj = parse_time(text, time_class);
418
418
  break;
419
- case Base64Code:
419
+ case String64Code:
420
420
  {
421
421
  char buf[1024];
422
422
  char *str = buf;
@@ -437,7 +437,31 @@ add_text(PInfo pi, char *text, int closed) {
437
437
  circ_array_set(pi->circ_array, v, (unsigned long)pi->h->obj);
438
438
  }
439
439
  pi->h->obj = v;
440
+ if (buf != str) {
441
+ free(str);
442
+ }
443
+ break;
444
+ }
445
+ case Symbol64Code:
446
+ {
447
+ VALUE sym;
448
+ VALUE *slot;
449
+ char buf[1024];
450
+ char *str = buf;
451
+ unsigned long str_size = b64_orig_size(text);
452
+
440
453
  if (sizeof(buf) <= str_size) {
454
+ if (0 == (str = (char*)malloc(str_size + 1))) {
455
+ rb_raise(rb_eNoMemError, "not enough memory\n");
456
+ }
457
+ }
458
+ from_base64(text, (u_char*)str);
459
+ if (Qundef == (sym = ox_cache_get(symbol_cache, str, &slot))) {
460
+ sym = ID2SYM(rb_intern(str));
461
+ *slot = sym;
462
+ }
463
+ pi->h->obj = sym;
464
+ if (buf != str) {
441
465
  free(str);
442
466
  }
443
467
  break;
@@ -531,6 +555,7 @@ add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
531
555
  case FixnumCode:
532
556
  case FloatCode:
533
557
  case SymbolCode:
558
+ case Symbol64Code:
534
559
  case RegexpCode:
535
560
  case BignumCode:
536
561
  case ComplexCode:
@@ -539,7 +564,7 @@ add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
539
564
  // value will be read in the following add_text
540
565
  h->obj = Qundef;
541
566
  break;
542
- case Base64Code:
567
+ case String64Code:
543
568
  h->obj = Qundef;
544
569
  if (0 != pi->circ_array) {
545
570
  pi->id = get_id_from_attrs(pi, attrs);
@@ -100,8 +100,9 @@ typedef enum {
100
100
  typedef enum {
101
101
  NoCode = 0,
102
102
  ArrayCode = 'a',
103
- Base64Code = 'b',
103
+ String64Code = 'b', // base64 encoded String
104
104
  ClassCode = 'c',
105
+ Symbol64Code = 'd', // base64 encoded Symbol
105
106
  FloatCode = 'f',
106
107
  RegexpCode = 'g',
107
108
  HashCode = 'h',
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Ox
3
3
  # Current version of the module.
4
- VERSION = '1.2.7'
4
+ VERSION = '1.2.8'
5
5
  end
@@ -103,6 +103,7 @@ class Func < ::Test::Unit::TestCase
103
103
 
104
104
  def test_symbol
105
105
  dump_and_load(:a_symbol, false)
106
+ dump_and_load(:<=, false)
106
107
  end
107
108
 
108
109
  def test_base64
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ox
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 2
8
- - 7
9
- version: 1.2.7
4
+ prerelease:
5
+ version: 1.2.8
10
6
  platform: ruby
11
7
  authors:
12
8
  - Peter Ohler
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-08-19 00:00:00 +09:00
13
+ date: 2011-08-22 00:00:00 +09:00
18
14
  default_executable:
19
15
  dependencies: []
20
16
 
@@ -51,10 +47,8 @@ files:
51
47
  - ext/ox/obj_load.c
52
48
  - ext/ox/ox.c
53
49
  - ext/ox/parse.c
54
- - test/big.rb
55
50
  - test/bug1.rb
56
51
  - test/bug2.rb
57
- - test/bug3.rb
58
52
  - test/cache16_test.rb
59
53
  - test/cache8_test.rb
60
54
  - test/cache_test.rb
@@ -100,21 +94,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
94
  requirements:
101
95
  - - ">="
102
96
  - !ruby/object:Gem::Version
103
- segments:
104
- - 0
105
97
  version: "0"
106
98
  required_rubygems_version: !ruby/object:Gem::Requirement
107
99
  none: false
108
100
  requirements:
109
101
  - - ">="
110
102
  - !ruby/object:Gem::Version
111
- segments:
112
- - 0
113
103
  version: "0"
114
104
  requirements: []
115
105
 
116
106
  rubyforge_project: ox
117
- rubygems_version: 1.3.7
107
+ rubygems_version: 1.6.2
118
108
  signing_key:
119
109
  specification_version: 3
120
110
  summary: A fast XML parser and object serializer.
@@ -1,24 +0,0 @@
1
- #!/usr/bin/env ruby -wW1
2
-
3
- $: << '../lib'
4
- $: << '../ext'
5
-
6
- if __FILE__ == $0
7
- while (i = ARGV.index('-I'))
8
- x,path = ARGV.slice!(i, 2)
9
- $: << path
10
- end
11
- end
12
-
13
- require 'ox'
14
-
15
- def dump(cnt = 10000)
16
- h = { }
17
- cnt.times do |i|
18
- h[i] = [i * 2, "this is #{i}"]
19
- end
20
- xml = Ox.dump(h)
21
- puts "size: #{xml.size}"
22
- end
23
-
24
- dump(200000)
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env ruby -wW1
2
-
3
- $: << '../lib'
4
- $: << '../ext'
5
-
6
- if __FILE__ == $0
7
- if (i = ARGV.index('-I'))
8
- x,path = ARGV.slice!(i, 2)
9
- $: << path
10
- end
11
- end
12
-
13
- require 'ox'
14
-
15
- def dump(cnt = 100000)
16
- cnt.times do |i|
17
- xml = Ox.dump([:inc, 1])
18
- #puts xml
19
-
20
- end
21
- end
22
-
23
- dump()