oj 2.2.0 → 2.2.1

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

Potentially problematic release.


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

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2acd85015af30a88c50ae38253f4595c701a6e6e
4
- data.tar.gz: 226adba1e99b118b6c3fd6e3a1d4663a9168c94c
3
+ metadata.gz: 964ef71e46a6e9c4fb8c734c520e81030a2c76e8
4
+ data.tar.gz: 31d2779214092e6b11ccdbfa5047abdb96dd0b31
5
5
  SHA512:
6
- metadata.gz: d13abbe27c0f818011a68e456d88cedb0b648641f543aa09eab20f9a43fdfd368899b51d99c732eb23ab1b405285a0f68203bd85e705f1fbbbf5d3e2c03e9bac
7
- data.tar.gz: 526a83f70809d99e54ce21c0f1905cf0a19ceb35216aad41aa4138071af8e611f2c744ce8b4fbb22f20113b46db90d8bca57ded64a10da0729112c6812fadb22
6
+ metadata.gz: aa82d27d48917343e1d1737804a84bcf578a47f2b1eef6f05fe59e2a68a1c95ebddf7307fc52dd59224f650c04245cbf98df9ab132d7562506bcc563a06becc0
7
+ data.tar.gz: dd0354a15f36b3f9337376832df8f051addfa1240eaaeba452c9d0a99a81f77c415e89ef4a1e6e677edde321384b1bd68127fa964e846f07b2e76ff7e185547c
data/README.md CHANGED
@@ -20,6 +20,10 @@ Follow [@peterohler on Twitter](http://twitter.com/#!/peterohler) for announceme
20
20
 
21
21
  [![Build Status](https://secure.travis-ci.org/ohler55/oj.png?branch=master)](http://travis-ci.org/ohler55/oj)
22
22
 
23
+ ### Current Release 2.2.1
24
+
25
+ - Made all VALUEs in parse volatile to avoid garbage collection while in use.
26
+
23
27
  ### Current Release 2.2.0
24
28
 
25
29
  - All 1.8.x versions of Ruby now have require 'rational' called.
@@ -52,8 +52,8 @@ hash_set_cstr(ParseInfo pi, const char *key, size_t klen, const char *str, size_
52
52
  }
53
53
  parent->clen = len;
54
54
  } else {
55
- VALUE rstr = rb_str_new(str, len);
56
- VALUE rkey = rb_str_new(key, klen);
55
+ volatile VALUE rstr = rb_str_new(str, len);
56
+ volatile VALUE rkey = rb_str_new(key, klen);
57
57
 
58
58
  rstr = oj_encode(rstr);
59
59
  rkey = oj_encode(rkey);
@@ -180,14 +180,14 @@ hat_num(ParseInfo pi, Val parent, const char *key, size_t klen, NumInfo ni) {
180
180
  }
181
181
 
182
182
  static int
183
- hat_value(ParseInfo pi, Val parent, const char *key, size_t klen, VALUE value) {
183
+ hat_value(ParseInfo pi, Val parent, const char *key, size_t klen, volatile VALUE value) {
184
184
  if (2 == klen && 'u' == key[1] && T_ARRAY == rb_type(value)) {
185
185
  #if HAS_RSTRUCT
186
- long len = RARRAY_LEN(value);
187
- VALUE *a = RARRAY_PTR(value);
188
- VALUE sc;
189
- volatile VALUE s;
190
- VALUE *sv;
186
+ long len = RARRAY_LEN(value);
187
+ volatile VALUE *a = RARRAY_PTR(value);
188
+ volatile VALUE sc;
189
+ volatile VALUE s;
190
+ volatile VALUE *sv;
191
191
 
192
192
  if (0 == len) {
193
193
  oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "Invalid struct data");
@@ -215,8 +215,8 @@ hat_value(ParseInfo pi, Val parent, const char *key, size_t klen, VALUE value) {
215
215
  #endif
216
216
  return 1;
217
217
  } else if (3 <= klen && '#' == key[1] && T_ARRAY == rb_type(value)) {
218
- long len = RARRAY_LEN(value);
219
- VALUE *a = RARRAY_PTR(value);
218
+ long len = RARRAY_LEN(value);
219
+ volatile VALUE *a = RARRAY_PTR(value);
220
220
 
221
221
  if (2 != len) {
222
222
  oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "invalid hash pair");
@@ -232,7 +232,7 @@ hat_value(ParseInfo pi, Val parent, const char *key, size_t klen, VALUE value) {
232
232
  static void
233
233
  copy_ivars(VALUE target, VALUE src) {
234
234
  volatile VALUE vars = rb_funcall(src, oj_instance_variables_id, 0);
235
- VALUE *np = RARRAY_PTR(vars);
235
+ volatile VALUE *np = RARRAY_PTR(vars);
236
236
  ID vid;
237
237
  int i, cnt = (int)RARRAY_LEN(vars);
238
238
  const char *attr;
@@ -520,14 +520,14 @@ array_end(ParseInfo pi) {
520
520
 
521
521
  static void
522
522
  hash_start(ParseInfo pi) {
523
- VALUE v = pi->start_hash(pi);
523
+ volatile VALUE v = pi->start_hash(pi);
524
524
 
525
525
  stack_push(&pi->stack, v, NEXT_HASH_NEW);
526
526
  }
527
527
 
528
528
  static void
529
529
  hash_end(ParseInfo pi) {
530
- Val hash = stack_peek(&pi->stack);
530
+ volatile Val hash = stack_peek(&pi->stack);
531
531
 
532
532
  // leave hash on stack until just before
533
533
  if (0 == hash) {
@@ -647,7 +647,7 @@ oj_parse2(ParseInfo pi) {
647
647
 
648
648
  VALUE
649
649
  oj_num_as_value(NumInfo ni) {
650
- VALUE rnum = Qnil;
650
+ volatile VALUE rnum = Qnil;
651
651
 
652
652
  if (ni->infinity) {
653
653
  if (ni->neg) {
@@ -720,7 +720,7 @@ protect_parse(VALUE pip) {
720
720
  VALUE
721
721
  oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json) {
722
722
  char *buf = 0;
723
- VALUE input;
723
+ volatile VALUE input;
724
724
  volatile VALUE result = Qnil;
725
725
  int line = 0;
726
726
  int free_json = 0;
@@ -737,14 +737,14 @@ oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json) {
737
737
  pi->json = json;
738
738
  free_json = 1;
739
739
  } else if (rb_type(input) == T_STRING) {
740
- pi->json = StringValuePtr(input);
740
+ pi->json = rb_string_value_cstr((VALUE*)&input);
741
741
  } else {
742
- VALUE clas = rb_obj_class(input);
743
- VALUE s;
742
+ VALUE clas = rb_obj_class(input);
743
+ volatile VALUE s;
744
744
 
745
745
  if (oj_stringio_class == clas) {
746
746
  s = rb_funcall2(input, oj_string_id, 0, 0);
747
- pi->json = StringValuePtr(s);
747
+ pi->json = rb_string_value_cstr((VALUE*)&s);
748
748
  #ifndef JRUBY_RUBY
749
749
  #if !IS_WINDOWS
750
750
  // JRuby gets confused with what is the real fileno.
@@ -771,7 +771,7 @@ oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json) {
771
771
  #endif
772
772
  } else if (rb_respond_to(input, oj_read_id)) {
773
773
  s = rb_funcall2(input, oj_read_id, 0, 0);
774
- pi->json = StringValuePtr(s);
774
+ pi->json = rb_string_value_cstr((VALUE*)&s);
775
775
  } else {
776
776
  rb_raise(rb_eArgError, "strict_parse() expected a String or IO Object.");
777
777
  }
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '2.2.0'
4
+ VERSION = '2.2.1'
5
5
  end
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
5
+ # required. That can be set in the RUBYOPT environment variable.
6
+ # export RUBYOPT=-w
7
+
8
+ $VERBOSE = true
9
+
10
+ $: << File.join(File.dirname(__FILE__), "../lib")
11
+ $: << File.join(File.dirname(__FILE__), "../ext")
12
+
13
+ require 'oj'
14
+
15
+ module One
16
+ module Two
17
+ module Three
18
+ class Empty
19
+
20
+ def initialize()
21
+ end
22
+
23
+ def eql?(o)
24
+ self.class == o.class
25
+ end
26
+ alias == eql?
27
+
28
+ def to_hash()
29
+ {'json_class' => "#{self.class.name}"}
30
+ end
31
+
32
+ def to_json(*a)
33
+ %{{"json_class":"#{self.class.name}"}}
34
+ end
35
+
36
+ def self.json_create(h)
37
+ self.new()
38
+ end
39
+ end # Empty
40
+ end # Three
41
+ end # Two
42
+ end # One
43
+
44
+ $obj = {
45
+ 'a' => 'Alpha', # string
46
+ 'b' => true, # boolean
47
+ 'c' => 12345, # number
48
+ 'd' => [ true, [false, [-123456789, nil], 3.9676, ['Something else.', false], nil]], # mix it up array
49
+ 'e' => { 'zero' => nil, 'one' => 1, 'two' => 2, 'three' => [3], 'four' => [0, 1, 2, 3, 4] }, # hash
50
+ 'f' => nil, # nil
51
+ 'g' => One::Two::Three::Empty.new(),
52
+ 'h' => { 'a' => { 'b' => { 'c' => { 'd' => {'e' => { 'f' => { 'g' => nil }}}}}}}, # deep hash, not that deep
53
+ 'i' => [[[[[[[nil]]]]]]] # deep array, again, not that deep
54
+ }
55
+
56
+ Oj.default_options = { :indent => 2, :mode => :compat }
57
+
58
+ $json = Oj.dump($obj, :mode => :compat)
59
+
60
+ 1000000.times { |i|
61
+ print(".") if (0 == i % 10000)
62
+ Oj.compat_load($json)
63
+ }
64
+
65
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
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-11-11 00:00:00.000000000 Z
11
+ date: 2013-11-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'The fastest JSON parser and object serializer. '
14
14
  email: peter@ohler.com
@@ -59,6 +59,7 @@ files:
59
59
  - test/e.rb
60
60
  - test/files.rb
61
61
  - test/foo.rb
62
+ - test/lots.rb
62
63
  - test/mj.rb
63
64
  - test/perf.rb
64
65
  - test/perf_compat.rb