oj 2.9.4 → 2.9.5
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 +4 -4
- data/README.md +17 -1
- data/ext/oj/dump.c +2 -1
- data/ext/oj/oj.c +54 -3
- data/ext/oj/parse.c +15 -8
- data/ext/oj/parse.h +1 -0
- data/ext/oj/reader.c +3 -2
- data/ext/oj/scp.c +5 -6
- data/lib/oj/mimic.rb +2 -2
- data/lib/oj/version.rb +1 -1
- data/test/_test_mimic_rails.rb +31 -0
- data/test/helper.rb +27 -0
- data/test/{test_mimic.rb → isolated/shared.rb} +69 -50
- data/test/isolated/test_mimic_after.rb +13 -0
- data/test/isolated/test_mimic_alone.rb +12 -0
- data/test/isolated/test_mimic_before.rb +13 -0
- data/test/isolated/test_mimic_define.rb +28 -0
- data/test/isolated/test_mimic_rails_after.rb +19 -0
- data/test/isolated/test_mimic_rails_before.rb +19 -0
- data/test/test_compat.rb +50 -64
- data/test/test_debian.rb +53 -0
- data/test/test_fast.rb +13 -13
- data/test/test_file.rb +45 -58
- data/test/test_gc.rb +22 -24
- data/test/test_object.rb +100 -114
- data/test/test_saj.rb +16 -14
- data/test/test_scp.rb +21 -14
- data/test/test_strict.rb +9 -23
- data/test/{tests.rb → test_various.rb} +96 -129
- data/test/test_writer.rb +10 -12
- data/test/zip.rb +34 -0
- metadata +57 -18
- data/test/a.rb +0 -38
- data/test/bug.rb +0 -17
- data/test/debian_test.rb +0 -90
- data/test/e.rb +0 -12
- data/test/foo.rb +0 -24
- data/test/lots.rb +0 -68
- data/test/mj.rb +0 -48
- data/test/perf_str.rb +0 -38
- data/test/perf_strictx.rb +0 -97
- data/test/test_mimic_after.rb +0 -35
- data/test/test_strictx.rb +0 -58
- data/test/write_fake_log.rb +0 -63
- data/test/x.rb +0 -59
data/test/zip.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
$: << File.dirname(__FILE__)
|
5
|
+
|
6
|
+
require 'helper'
|
7
|
+
|
8
|
+
require 'zlib'
|
9
|
+
|
10
|
+
File.open('test.json.gz', 'r') do |file|
|
11
|
+
Zlib::GzipReader.wrap(file) do |f2|
|
12
|
+
puts "*** f2: #{f2}"
|
13
|
+
Oj.load(f2) do |val|
|
14
|
+
puts val
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
=begin
|
20
|
+
And a json file with the following contents (then gzipped):
|
21
|
+
|
22
|
+
{"a":2}
|
23
|
+
{"b":2}
|
24
|
+
The output is:
|
25
|
+
|
26
|
+
{"a"=>2}
|
27
|
+
{"b"=>2}
|
28
|
+
bin/test:8:in `load': undefined method `new' for #<EOFError: end of file reached> (NoMethodError)
|
29
|
+
from bin/test:8:in `block (2 levels) in <main>'
|
30
|
+
from bin/test:7:in `wrap'
|
31
|
+
from bin/test:7:in `block in <main>'
|
32
|
+
from bin/test:6:in `open'
|
33
|
+
from bin/test:6:in `<main>'
|
34
|
+
=end
|
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.9.
|
4
|
+
version: 2.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
12
|
-
dependencies:
|
11
|
+
date: 2014-06-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake-compiler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4'
|
13
55
|
description: 'The fastest JSON parser and object serializer. '
|
14
56
|
email: peter@ohler.com
|
15
57
|
executables: []
|
@@ -59,14 +101,16 @@ files:
|
|
59
101
|
- lib/oj/saj.rb
|
60
102
|
- lib/oj/schandler.rb
|
61
103
|
- lib/oj/version.rb
|
62
|
-
- test/
|
63
|
-
- test/bug.rb
|
64
|
-
- test/debian_test.rb
|
65
|
-
- test/e.rb
|
104
|
+
- test/_test_mimic_rails.rb
|
66
105
|
- test/files.rb
|
67
|
-
- test/
|
68
|
-
- test/
|
69
|
-
- test/
|
106
|
+
- test/helper.rb
|
107
|
+
- test/isolated/shared.rb
|
108
|
+
- test/isolated/test_mimic_after.rb
|
109
|
+
- test/isolated/test_mimic_alone.rb
|
110
|
+
- test/isolated/test_mimic_before.rb
|
111
|
+
- test/isolated/test_mimic_define.rb
|
112
|
+
- test/isolated/test_mimic_rails_after.rb
|
113
|
+
- test/isolated/test_mimic_rails_before.rb
|
70
114
|
- test/perf.rb
|
71
115
|
- test/perf_compat.rb
|
72
116
|
- test/perf_fast.rb
|
@@ -75,9 +119,7 @@ files:
|
|
75
119
|
- test/perf_saj.rb
|
76
120
|
- test/perf_scp.rb
|
77
121
|
- test/perf_simple.rb
|
78
|
-
- test/perf_str.rb
|
79
122
|
- test/perf_strict.rb
|
80
|
-
- test/perf_strictx.rb
|
81
123
|
- test/sample.rb
|
82
124
|
- test/sample/change.rb
|
83
125
|
- test/sample/dir.rb
|
@@ -94,20 +136,17 @@ files:
|
|
94
136
|
- test/sample_json.rb
|
95
137
|
- test/struct.rb
|
96
138
|
- test/test_compat.rb
|
139
|
+
- test/test_debian.rb
|
97
140
|
- test/test_fast.rb
|
98
141
|
- test/test_file.rb
|
99
142
|
- test/test_gc.rb
|
100
|
-
- test/test_mimic.rb
|
101
|
-
- test/test_mimic_after.rb
|
102
143
|
- test/test_object.rb
|
103
144
|
- test/test_saj.rb
|
104
145
|
- test/test_scp.rb
|
105
146
|
- test/test_strict.rb
|
106
|
-
- test/
|
147
|
+
- test/test_various.rb
|
107
148
|
- test/test_writer.rb
|
108
|
-
- test/
|
109
|
-
- test/write_fake_log.rb
|
110
|
-
- test/x.rb
|
149
|
+
- test/zip.rb
|
111
150
|
homepage: http://www.ohler.com/oj
|
112
151
|
licenses:
|
113
152
|
- MIT
|
data/test/a.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby -wW1
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.dirname(__FILE__)
|
5
|
-
$: << File.join(File.dirname(__FILE__), "../lib")
|
6
|
-
$: << File.join(File.dirname(__FILE__), "../ext")
|
7
|
-
|
8
|
-
require 'pp'
|
9
|
-
require 'oj'
|
10
|
-
require 'perf'
|
11
|
-
|
12
|
-
obj = [[1],[2],[3],[4],[5],[6],[7],[8],[9]]
|
13
|
-
obj = [[],[],[],[],[],[],[],[],[]]
|
14
|
-
obj = {
|
15
|
-
'a' => 'Alpha', # string
|
16
|
-
'b' => true, # boolean
|
17
|
-
'c' => 12345, # number
|
18
|
-
'd' => [ true, [false, [12345, nil], 3.967, ['something', false], nil]], # mix it up array
|
19
|
-
'e' => { 'one' => 1, 'two' => 2 }, # hash
|
20
|
-
'f' => nil, # nil
|
21
|
-
'g' => 12345678901234567890123456789, # big number
|
22
|
-
'h' => { 'a' => { 'b' => { 'c' => { 'd' => {'e' => { 'f' => { 'g' => nil }}}}}}}, # deep hash, not that deep
|
23
|
-
'i' => [[[[[[[nil]]]]]]] # deep array, again, not that deep
|
24
|
-
}
|
25
|
-
|
26
|
-
json = Oj.dump(obj, mode: :compat)
|
27
|
-
|
28
|
-
puts json
|
29
|
-
#pp Oj.saj_parse(nil, json)
|
30
|
-
pp Oj.t_parse(json)
|
31
|
-
|
32
|
-
if true
|
33
|
-
perf = Perf.new()
|
34
|
-
perf.add('SAJ', 'oj') { Oj.saj_parse(nil, json) }
|
35
|
-
perf.add('T', 'oj') { Oj.t_parse(json) }
|
36
|
-
perf.add('load', 'oj') { Oj.load(json) }
|
37
|
-
perf.run(10000)
|
38
|
-
end
|
data/test/bug.rb
DELETED
@@ -1,17 +0,0 @@
|
|
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
|
-
obj = Oj.load_file('bug.json', :mode => :object)
|
16
|
-
|
17
|
-
puts Oj.dump(obj, :mode => :object, :indent => 0)
|
data/test/debian_test.rb
DELETED
@@ -1,90 +0,0 @@
|
|
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 'test/unit'
|
14
|
-
require 'stringio'
|
15
|
-
require 'date'
|
16
|
-
require 'bigdecimal'
|
17
|
-
require 'oj'
|
18
|
-
|
19
|
-
$ruby = RUBY_DESCRIPTION.split(' ')[0]
|
20
|
-
$ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
|
21
|
-
|
22
|
-
def hash_eql(h1, h2)
|
23
|
-
return false if h1.size != h2.size
|
24
|
-
h1.keys.each do |k|
|
25
|
-
return false unless h1[k] == h2[k]
|
26
|
-
end
|
27
|
-
true
|
28
|
-
end
|
29
|
-
|
30
|
-
class Jam
|
31
|
-
attr_accessor :x, :y
|
32
|
-
|
33
|
-
def initialize(x, y)
|
34
|
-
@x = x
|
35
|
-
@y = y
|
36
|
-
end
|
37
|
-
|
38
|
-
def eql?(o)
|
39
|
-
self.class == o.class && @x == o.x && @y == o.y
|
40
|
-
end
|
41
|
-
alias == eql?
|
42
|
-
|
43
|
-
end# Jam
|
44
|
-
|
45
|
-
# contributed by sauliusg to fix as_json
|
46
|
-
class Orange < Jam
|
47
|
-
def initialize(x, y)
|
48
|
-
super
|
49
|
-
end
|
50
|
-
|
51
|
-
def as_json()
|
52
|
-
puts "Orange.as_json called"
|
53
|
-
{ :json_class => self.class,
|
54
|
-
:x => @x,
|
55
|
-
:y => @y }
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.json_create(h)
|
59
|
-
puts "Orange.json_create"
|
60
|
-
self.new(h['x'], h['y'])
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
class DebJuice < ::Test::Unit::TestCase
|
65
|
-
|
66
|
-
def test_class_hash
|
67
|
-
Oj.hash_test()
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_as_json_object_compat_hash_cached
|
71
|
-
Oj.default_options = { :mode => :compat, :class_cache => true }
|
72
|
-
obj = Orange.new(true, 58)
|
73
|
-
puts "dumping compat with cache"
|
74
|
-
json = Oj.dump(obj, :indent => 2)
|
75
|
-
assert(!json.nil?)
|
76
|
-
dump_and_load(obj, true)
|
77
|
-
end
|
78
|
-
|
79
|
-
def dump_and_load(obj, trace=false)
|
80
|
-
puts "dumping"
|
81
|
-
json = Oj.dump(obj, :indent => 2)
|
82
|
-
puts json if trace
|
83
|
-
puts "loading"
|
84
|
-
loaded = Oj.load(json);
|
85
|
-
puts "done"
|
86
|
-
assert_equal(obj, loaded)
|
87
|
-
loaded
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
data/test/e.rb
DELETED
data/test/foo.rb
DELETED
@@ -1,24 +0,0 @@
|
|
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
|
-
class Foo < String
|
16
|
-
def initialize(str, safe)
|
17
|
-
super(str)
|
18
|
-
@safe = safe
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
f = Foo.new("z")
|
23
|
-
|
24
|
-
puts f
|
data/test/lots.rb
DELETED
@@ -1,68 +0,0 @@
|
|
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
|
-
$obj = [$obj]*10000
|
57
|
-
|
58
|
-
Oj.default_options = { :indent => 2, :mode => :compat }
|
59
|
-
|
60
|
-
$json = Oj.dump($obj, :mode => :compat)
|
61
|
-
|
62
|
-
$result = nil
|
63
|
-
100.times { |i|
|
64
|
-
print(".") if (0 == i % 10)
|
65
|
-
$result = Oj.compat_load($json)
|
66
|
-
}
|
67
|
-
|
68
|
-
|
data/test/mj.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.join(File.dirname(__FILE__), "../lib")
|
5
|
-
$: << File.join(File.dirname(__FILE__), "../ext")
|
6
|
-
# $: << File.join(File.dirname(__FILE__), "../../multi_json/lib")
|
7
|
-
|
8
|
-
require 'multi_json'
|
9
|
-
require 'benchmark'
|
10
|
-
require 'yajl'
|
11
|
-
require 'json'
|
12
|
-
require 'oj'
|
13
|
-
|
14
|
-
iter = 1_000_000
|
15
|
-
iter = 100_000
|
16
|
-
|
17
|
-
json = %({"k1":"val1","k2":"val2","k3":"val3"})
|
18
|
-
obj = { k1: "val1", k2: "val2", k3: "val3" }
|
19
|
-
|
20
|
-
puts "Benchmarks for different JSON handlers with MultiJson."
|
21
|
-
puts " Ruby #{RUBY_VERSION}"
|
22
|
-
puts " #{iter} iterations"
|
23
|
-
|
24
|
-
MultiJson.engine = :oj
|
25
|
-
dt = Benchmark.realtime { iter.times { MultiJson.decode(json) }}
|
26
|
-
et = Benchmark.realtime { iter.times { MultiJson.encode(obj) }}
|
27
|
-
puts " Oj decode: #{dt} encode: #{et}"
|
28
|
-
|
29
|
-
MultiJson.engine = :yajl
|
30
|
-
dt = Benchmark.realtime { iter.times { MultiJson.decode(json) }}
|
31
|
-
et = Benchmark.realtime { iter.times { MultiJson.encode(obj) }}
|
32
|
-
puts " Yajl decode: #{dt} encode: #{et}"
|
33
|
-
|
34
|
-
MultiJson.engine = :json_gem
|
35
|
-
dt = Benchmark.realtime { iter.times { MultiJson.decode(json) }}
|
36
|
-
et = Benchmark.realtime { iter.times { MultiJson.encode(obj) }}
|
37
|
-
puts " Json decode: #{dt} encode: #{et}"
|
38
|
-
|
39
|
-
Oj.default_options = { :mode => :compat, :time_format => :ruby }
|
40
|
-
dt = Benchmark.realtime { iter.times { Oj.load(json) }}
|
41
|
-
et = Benchmark.realtime { iter.times { Oj.dump(obj) }}
|
42
|
-
puts "Raw Oj decode: #{dt} encode: #{et}"
|
43
|
-
|
44
|
-
ye = Yajl::Encoder.new
|
45
|
-
dt = Benchmark.realtime { iter.times { Yajl::Parser.parse(json) }}
|
46
|
-
et = Benchmark.realtime { iter.times { Yajl::Encoder.encode(obj) }}
|
47
|
-
e2 = Benchmark.realtime { iter.times { ye.encode(obj) }}
|
48
|
-
puts "Raw Yajl decode: #{dt} encode: #{et}, encoder: #{e2}"
|