oj 2.18.2 → 2.18.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/ext/oj/parse.c +6 -6
- data/lib/oj/version.rb +1 -1
- data/test/curl/curl_oj.rb +46 -0
- data/test/curl/get_oj.rb +24 -0
- data/test/curl/just_curl.rb +31 -0
- data/test/curl/just_oj.rb +51 -0
- data/test/foo.rb +16 -20
- metadata +64 -60
- data/test/mem.rb +0 -20
- data/test/omit.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc95283102d735d5d75c5e028656180772d68503
|
4
|
+
data.tar.gz: a50e4cafdbd11e8af300dd1aa7ff05a0904904eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9165d68d3e5d0aec5a49c1fdf436361d6051ae9b7d07493a4b5db4d38c4dc711f8ebb5a2691963b38c8db564e5616553a82d0e9d2bb4606f155d8f99d90aed2
|
7
|
+
data.tar.gz: 8c720169ce7c784c96645e7535c18f72f6dd27775a52a8d9d5d57219f12eedbbdd9d2b69521e5005505ea78a28496dc22554cdb0af62e5a7d7ceda37e6cc4274
|
data/README.md
CHANGED
@@ -153,6 +153,9 @@ Oj.default_options = {:mode => :compat }
|
|
153
153
|
* `:use_to_json` [Boolean] call to_json() methods on dump, default is
|
154
154
|
false
|
155
155
|
|
156
|
+
* `:use_as_json` [Boolean] call as_json() methods on dump, default is
|
157
|
+
false
|
158
|
+
|
156
159
|
* `:nilnil` [Boolean] if true a nil input to load will return nil and
|
157
160
|
not raise an Exception
|
158
161
|
|
@@ -167,6 +170,14 @@ Oj.default_options = {:mode => :compat }
|
|
167
170
|
number, :word places Infinity or NaN, :raise raises and exception, :auto uses
|
168
171
|
default for each mode which are :raise for :strict, :null for :null, and :word
|
169
172
|
for :compat. Default is :auto.
|
173
|
+
|
174
|
+
* `:allow_invalid_unicode` [Boolean] Allow invalid unicode, default is
|
175
|
+
false (don't allow)
|
176
|
+
|
177
|
+
* `:hash_class` [Class] Class to use instead of Hash on load
|
178
|
+
|
179
|
+
* `:omit_nil` [Boolean] If true, Hash and Object attributes with nil values
|
180
|
+
are omitted
|
170
181
|
|
171
182
|
## Releases
|
172
183
|
|
data/ext/oj/parse.c
CHANGED
@@ -732,28 +732,28 @@ oj_num_as_value(NumInfo ni) {
|
|
732
732
|
}
|
733
733
|
} else {
|
734
734
|
// All these machinations are to get rounding to work better.
|
735
|
-
double d = (double)ni->i * (double)ni->div + (double)ni->num;
|
735
|
+
long double d = (long double)ni->i * (long double)ni->div + (long double)ni->num;
|
736
736
|
int x = ni->exp - ni->di;
|
737
737
|
|
738
738
|
// Rounding sometimes cuts off the last digit even if there are only
|
739
739
|
// 15 digits. This attempts to fix those few cases where this
|
740
740
|
// occurs.
|
741
|
-
if ((double)INT64_MAX > d && (int64_t)d != (ni->i * ni->div + ni->num)) {
|
741
|
+
if ((long double)INT64_MAX > d && (int64_t)d != (ni->i * ni->div + ni->num)) {
|
742
742
|
rnum = rb_funcall(oj_bigdecimal_class, oj_new_id, 1, rb_str_new(ni->str, ni->len));
|
743
743
|
if (ni->no_big) {
|
744
744
|
rnum = rb_funcall(rnum, rb_intern("to_f"), 0);
|
745
745
|
}
|
746
746
|
} else {
|
747
|
-
d =
|
747
|
+
d = roundl(d);
|
748
748
|
if (0 < x) {
|
749
|
-
d *=
|
749
|
+
d *= powl(10.0L, x);
|
750
750
|
} else if (0 > x) {
|
751
|
-
d /=
|
751
|
+
d /= powl(10.0L, -x);
|
752
752
|
}
|
753
753
|
if (ni->neg) {
|
754
754
|
d = -d;
|
755
755
|
}
|
756
|
-
rnum = rb_float_new(d);
|
756
|
+
rnum = rb_float_new((double)d);
|
757
757
|
}
|
758
758
|
}
|
759
759
|
}
|
data/lib/oj/version.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
#$VERBOSE = true
|
5
|
+
|
6
|
+
$: << File.dirname(__FILE__)
|
7
|
+
$: << File.expand_path("../../ext")
|
8
|
+
$: << File.expand_path("../../lib")
|
9
|
+
$: << File.expand_path("../../../curb/ext")
|
10
|
+
$: << File.expand_path("../../../curb/lib")
|
11
|
+
|
12
|
+
require 'curb'
|
13
|
+
require 'oj'
|
14
|
+
|
15
|
+
$cnt = 0
|
16
|
+
|
17
|
+
$url = "localhost:7660/data.json"
|
18
|
+
|
19
|
+
begin
|
20
|
+
while true
|
21
|
+
before = GC.count
|
22
|
+
curl = Curl::Easy.new($url)
|
23
|
+
curl.ssl_verify_host = false
|
24
|
+
curl.http_get
|
25
|
+
if before != GC.count
|
26
|
+
puts " did a GC in curl #{GC.count}"
|
27
|
+
before = GC.count
|
28
|
+
end
|
29
|
+
=begin
|
30
|
+
data = Oj.load(curl.body, symbol_keys: true, mode: :strict)
|
31
|
+
puts " did a GC in Oj #{GC.count}" if before != GC.count
|
32
|
+
|
33
|
+
if data[:data].nil? or data[:data].any? { |e| e.empty? }
|
34
|
+
puts "body: #{curl.body}"
|
35
|
+
raise "FAILED"
|
36
|
+
end
|
37
|
+
=end
|
38
|
+
$cnt += 1
|
39
|
+
print "\r #{$cnt}"
|
40
|
+
end
|
41
|
+
rescue Exception => e
|
42
|
+
puts "#{e.class}: #{e.message}"
|
43
|
+
puts "url: #{$url}"
|
44
|
+
#puts "data: #{data}"
|
45
|
+
#puts "data[data]: #{data[:data]}"
|
46
|
+
end
|
data/test/curl/get_oj.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
$VERBOSE = true
|
5
|
+
|
6
|
+
$: << File.dirname(__FILE__)
|
7
|
+
$: << File.expand_path("../../ext")
|
8
|
+
$: << File.expand_path("../../lib")
|
9
|
+
|
10
|
+
require 'net/http'
|
11
|
+
require 'uri'
|
12
|
+
require 'oj'
|
13
|
+
|
14
|
+
$url = URI.parse("http://localhost:7660/data.json")
|
15
|
+
|
16
|
+
$cnt = 0
|
17
|
+
|
18
|
+
while true
|
19
|
+
response = Net::HTTP.get_response($url)
|
20
|
+
data = Oj.load(response.body, symbol_keys: true, mode: :strict)
|
21
|
+
raise "FAILED" if data[:data].any? { |e| e.empty? }
|
22
|
+
$cnt += 1
|
23
|
+
print "\r #{$cnt}"
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
#$VERBOSE = true
|
5
|
+
|
6
|
+
$: << File.dirname(__FILE__)
|
7
|
+
#$: << File.expand_path("../../../curb/ext")
|
8
|
+
#$: << File.expand_path("../../../curb/lib")
|
9
|
+
|
10
|
+
require 'curb'
|
11
|
+
|
12
|
+
$cnt = 0
|
13
|
+
$url = "localhost:7660/data.json"
|
14
|
+
|
15
|
+
begin
|
16
|
+
while true
|
17
|
+
before = GC.count
|
18
|
+
curl = Curl::Easy.new($url)
|
19
|
+
curl.ssl_verify_host = false
|
20
|
+
curl.http_get
|
21
|
+
if before != GC.count
|
22
|
+
puts " did a GC in curl #{GC.count}"
|
23
|
+
before = GC.count
|
24
|
+
end
|
25
|
+
$cnt += 1
|
26
|
+
print "\r #{$cnt}"
|
27
|
+
end
|
28
|
+
rescue Exception => e
|
29
|
+
puts "#{e.class}: #{e.message}"
|
30
|
+
puts "url: #{$url}"
|
31
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
$VERBOSE = true
|
5
|
+
|
6
|
+
$: << File.dirname(__FILE__)
|
7
|
+
$: << File.expand_path("../../ext")
|
8
|
+
$: << File.expand_path("../../lib")
|
9
|
+
|
10
|
+
require 'oj'
|
11
|
+
|
12
|
+
$json = %|
|
13
|
+
{
|
14
|
+
"data" : [ {
|
15
|
+
"action" : "login",
|
16
|
+
"event" : "user",
|
17
|
+
"field" : "login",
|
18
|
+
"value" : "foobar",
|
19
|
+
"info" : "Authenticated \\"Foo Bar\\"",
|
20
|
+
"id" : "585929918297f2740ed9f5f0",
|
21
|
+
"_metadata" : {
|
22
|
+
"version" : "1"
|
23
|
+
},
|
24
|
+
"timestamp" : "2016-12-20T07:52:33",
|
25
|
+
"key_id" : "4"
|
26
|
+
} ],
|
27
|
+
"info" : {
|
28
|
+
"view" : "partial",
|
29
|
+
"limit" : 500,
|
30
|
+
"offset" : 2000,
|
31
|
+
"results" : 500,
|
32
|
+
"ordering" : "timestamp desc,id",
|
33
|
+
"previous" : "https://api.server.com/some/path/event?calculate_total=false&draft=base&order_by=timestamp_desc&order_by=id&subdraft=none&offset=1500&limit=500",
|
34
|
+
"next" : "https://api.server.com/some/path/event?calculate_total=false&draft=base&order_by=timestamp_desc&order_by=id&subdraft=none&offset=2500&limit=500",
|
35
|
+
"draft" : "base",
|
36
|
+
"subdraft" : "none",
|
37
|
+
"total_results" : 100000
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
|
41
|
+
|
42
|
+
$cnt = 0
|
43
|
+
|
44
|
+
while true
|
45
|
+
before = GC.count
|
46
|
+
data = Oj.load($json, symbol_keys: true, mode: :strict)
|
47
|
+
puts " did a GC in Oj #{GC.count} - #{$cnt}" if before != GC.count
|
48
|
+
raise "FAILED" if data[:data].any? { |e| e.empty? }
|
49
|
+
$cnt += 1
|
50
|
+
print "\r #{$cnt}" if 0 == ($cnt % 10000)
|
51
|
+
end
|
data/test/foo.rb
CHANGED
@@ -1,28 +1,24 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: UTF-8
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
$VERBOSE = true
|
5
|
+
|
6
|
+
here = File.expand_path(File.dirname(__FILE__))
|
7
|
+
$: << File.dirname(__FILE__)
|
8
|
+
$: << File.join(File.dirname(here), 'ext')
|
9
|
+
$: << File.join(File.dirname(here), 'lib')
|
6
10
|
|
7
|
-
require 'stringio'
|
8
11
|
require 'oj'
|
9
|
-
require 'jsonlint'
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
"groups": [
|
19
|
-
"devops"
|
20
|
-
],
|
21
|
-
"shell": "\/bin\/bash",
|
22
|
-
"comment": "Ben Abrams"
|
23
|
-
}|
|
13
|
+
Oj.mimic_JSON()
|
14
|
+
|
15
|
+
class Foo
|
16
|
+
def as_json
|
17
|
+
{ foo: 'bar' }
|
18
|
+
end
|
19
|
+
end
|
24
20
|
|
25
|
-
|
26
|
-
linter.check_stream(StringIO.new(json))
|
21
|
+
opts = {}
|
27
22
|
|
28
|
-
puts
|
23
|
+
puts Foo.new.to_json
|
24
|
+
puts Foo.new.to_json(opts)
|
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.18.
|
4
|
+
version: 2.18.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -113,6 +113,10 @@ files:
|
|
113
113
|
- test/bug_fast.rb
|
114
114
|
- test/bug_load.rb
|
115
115
|
- test/crash.rb
|
116
|
+
- test/curl/curl_oj.rb
|
117
|
+
- test/curl/get_oj.rb
|
118
|
+
- test/curl/just_curl.rb
|
119
|
+
- test/curl/just_oj.rb
|
116
120
|
- test/example.rb
|
117
121
|
- test/files.rb
|
118
122
|
- test/foo.rb
|
@@ -128,9 +132,7 @@ files:
|
|
128
132
|
- test/isolated/test_mimic_rails_before.rb
|
129
133
|
- test/isolated/test_mimic_rails_datetime.rb
|
130
134
|
- test/isolated/test_mimic_redefine.rb
|
131
|
-
- test/mem.rb
|
132
135
|
- test/mod.rb
|
133
|
-
- test/omit.rb
|
134
136
|
- test/perf.rb
|
135
137
|
- test/perf_compat.rb
|
136
138
|
- test/perf_fast.rb
|
@@ -198,71 +200,73 @@ signing_key:
|
|
198
200
|
specification_version: 4
|
199
201
|
summary: A fast JSON parser and serializer.
|
200
202
|
test_files:
|
201
|
-
- test/perf_object.rb
|
202
|
-
- test/test_hash.rb
|
203
|
-
- test/bug3.rb
|
204
|
-
- test/write_timebars.rb
|
205
|
-
- test/test_writer.rb
|
206
|
-
- test/russian.rb
|
207
|
-
- test/omit.rb
|
208
|
-
- test/test_gc.rb
|
209
|
-
- test/_test_active_mimic.rb
|
210
|
-
- test/test_serializer.rb
|
211
|
-
- test/sample/file.rb
|
212
|
-
- test/sample/group.rb
|
213
|
-
- test/sample/oval.rb
|
214
|
-
- test/sample/rect.rb
|
215
|
-
- test/sample/hasprops.rb
|
216
|
-
- test/sample/layer.rb
|
217
|
-
- test/sample/text.rb
|
218
|
-
- test/sample/doc.rb
|
219
|
-
- test/sample/line.rb
|
220
|
-
- test/sample/dir.rb
|
221
|
-
- test/sample/shape.rb
|
222
|
-
- test/sample/change.rb
|
223
|
-
- test/crash.rb
|
224
|
-
- test/io.rb
|
225
|
-
- test/test_object.rb
|
226
|
-
- test/struct.rb
|
227
|
-
- test/mod.rb
|
228
|
-
- test/sample.rb
|
229
|
-
- test/perf_scp.rb
|
230
|
-
- test/bug2.rb
|
231
|
-
- test/test_saj.rb
|
232
|
-
- test/test_strict.rb
|
233
|
-
- test/perf_saj.rb
|
234
|
-
- test/perf_simple.rb
|
235
|
-
- test/perf_fast.rb
|
236
|
-
- test/example.rb
|
237
203
|
- test/_test_active.rb
|
238
|
-
- test/
|
239
|
-
- test/
|
204
|
+
- test/_test_active_mimic.rb
|
205
|
+
- test/_test_mimic_rails.rb
|
240
206
|
- test/activesupport_datetime_test.rb
|
241
|
-
- test/
|
207
|
+
- test/bug.rb
|
208
|
+
- test/bug2.rb
|
209
|
+
- test/bug3.rb
|
210
|
+
- test/bug_fast.rb
|
242
211
|
- test/bug_load.rb
|
212
|
+
- test/crash.rb
|
213
|
+
- test/curl/curl_oj.rb
|
214
|
+
- test/curl/get_oj.rb
|
215
|
+
- test/curl/just_curl.rb
|
216
|
+
- test/curl/just_oj.rb
|
217
|
+
- test/example.rb
|
243
218
|
- test/files.rb
|
244
219
|
- test/foo.rb
|
245
|
-
- test/
|
246
|
-
- test/
|
247
|
-
- test/isolated/test_mimic_redefine.rb
|
248
|
-
- test/isolated/test_mimic_as_json.rb
|
220
|
+
- test/helper.rb
|
221
|
+
- test/io.rb
|
249
222
|
- test/isolated/shared.rb
|
250
|
-
- test/isolated/test_mimic_alone.rb
|
251
223
|
- test/isolated/test_mimic_after.rb
|
224
|
+
- test/isolated/test_mimic_alone.rb
|
225
|
+
- test/isolated/test_mimic_as_json.rb
|
252
226
|
- test/isolated/test_mimic_before.rb
|
253
|
-
- test/isolated/test_mimic_rails_before.rb
|
254
227
|
- test/isolated/test_mimic_define.rb
|
255
|
-
- test/
|
256
|
-
- test/
|
257
|
-
- test/
|
258
|
-
- test/
|
228
|
+
- test/isolated/test_mimic_rails_after.rb
|
229
|
+
- test/isolated/test_mimic_rails_before.rb
|
230
|
+
- test/isolated/test_mimic_rails_datetime.rb
|
231
|
+
- test/isolated/test_mimic_redefine.rb
|
232
|
+
- test/mod.rb
|
233
|
+
- test/perf.rb
|
234
|
+
- test/perf_compat.rb
|
235
|
+
- test/perf_fast.rb
|
236
|
+
- test/perf_file.rb
|
237
|
+
- test/perf_object.rb
|
238
|
+
- test/perf_saj.rb
|
239
|
+
- test/perf_scp.rb
|
240
|
+
- test/perf_simple.rb
|
241
|
+
- test/perf_strict.rb
|
242
|
+
- test/rails.rb
|
243
|
+
- test/russian.rb
|
244
|
+
- test/sample/change.rb
|
245
|
+
- test/sample/dir.rb
|
246
|
+
- test/sample/doc.rb
|
247
|
+
- test/sample/file.rb
|
248
|
+
- test/sample/group.rb
|
249
|
+
- test/sample/hasprops.rb
|
250
|
+
- test/sample/layer.rb
|
251
|
+
- test/sample/line.rb
|
252
|
+
- test/sample/oval.rb
|
253
|
+
- test/sample/rect.rb
|
254
|
+
- test/sample/shape.rb
|
255
|
+
- test/sample/text.rb
|
256
|
+
- test/sample.rb
|
259
257
|
- test/sample_json.rb
|
258
|
+
- test/struct.rb
|
259
|
+
- test/test_compat.rb
|
260
260
|
- test/test_debian.rb
|
261
261
|
- test/test_fast.rb
|
262
|
-
- test/
|
263
|
-
- test/
|
264
|
-
- test/
|
265
|
-
- test/
|
266
|
-
- test/
|
267
|
-
- test/
|
268
|
-
- test/
|
262
|
+
- test/test_file.rb
|
263
|
+
- test/test_gc.rb
|
264
|
+
- test/test_hash.rb
|
265
|
+
- test/test_object.rb
|
266
|
+
- test/test_saj.rb
|
267
|
+
- test/test_scp.rb
|
268
|
+
- test/test_serializer.rb
|
269
|
+
- test/test_strict.rb
|
270
|
+
- test/test_various.rb
|
271
|
+
- test/test_writer.rb
|
272
|
+
- test/write_timebars.rb
|
data/test/mem.rb
DELETED
@@ -1,20 +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
|
-
|
7
|
-
require 'oj'
|
8
|
-
|
9
|
-
h = {
|
10
|
-
'a' => 1,
|
11
|
-
'b' => 2,
|
12
|
-
'c' => 3,
|
13
|
-
'd' => 4,
|
14
|
-
'e' => 5,
|
15
|
-
}
|
16
|
-
|
17
|
-
10000.times do
|
18
|
-
GC.start
|
19
|
-
Oj.dump(h)
|
20
|
-
end
|
data/test/omit.rb
DELETED
@@ -1,20 +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
|
-
|
7
|
-
require 'oj'
|
8
|
-
require 'stringio'
|
9
|
-
require 'parallel'
|
10
|
-
|
11
|
-
h = { a: 1, b: nil, c: 3 }
|
12
|
-
outputs = Parallel.map((0...30).to_a, in_process: 30) do |i|
|
13
|
-
io = StringIO.new('wb+')
|
14
|
-
Oj.to_stream(io, h, omit_nil: false)
|
15
|
-
io.string
|
16
|
-
end
|
17
|
-
|
18
|
-
outputs.each do |output|
|
19
|
-
puts output
|
20
|
-
end
|