oj 2.18.2 → 2.18.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e75fe6286b1a83b703bbb5fe4ef67620471ed85c
4
- data.tar.gz: 11c1c0a4025e7230882265540158df6ca22c8324
3
+ metadata.gz: cc95283102d735d5d75c5e028656180772d68503
4
+ data.tar.gz: a50e4cafdbd11e8af300dd1aa7ff05a0904904eb
5
5
  SHA512:
6
- metadata.gz: be67841c21694aeea3c687dac1e5e2c76a2069198dfc4e8edc9efc469a97489265e1814b4607740ee38814885868f6b7822cadd2ca5b5c1f3b058d2f318b951f
7
- data.tar.gz: 53b40092ab955eed576c31a4c755583ba14ed6d1013363dbb6e8c256298c36bf0e67de9b9472be1ef1f0aa574735ba4ef417308beb283a43a698a9993ecd1d1a
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
 
@@ -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 = round(d);
747
+ d = roundl(d);
748
748
  if (0 < x) {
749
- d *= pow(10.0L, x);
749
+ d *= powl(10.0L, x);
750
750
  } else if (0 > x) {
751
- d /= pow(10.0L, -x);
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
  }
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '2.18.2'
4
+ VERSION = '2.18.3'
5
5
  end
@@ -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
@@ -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
@@ -1,28 +1,24 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
- $: << File.join(File.dirname(__FILE__), "../lib")
5
- $: << File.join(File.dirname(__FILE__), "../ext")
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
- json = %|{
12
- "id": "babrams",
13
- "ssh_keys": [
14
- "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDMCKMvMJ2yb13pHLsIPqi2xHOBKFZKa8+FM1FUqNbIxKeq3LLw+4WiXLK60DxxS6hmOnXD+FcWNaykkGLyGQeYHxsHynsXo9BPaG/ewaAp5SDU/zAIAaex15s/zvo5l+5Pq9OwXYtFRmfezk3ImCx7SZ8sMmHiFHYD8d38XBlGX53kLSFm5HLEopEvSCRTUyTj+tPIspgYR6IvCTdXnamO9FT8Rkeqw+mqjX9sVTaLuuqwQZlRFRMslrrJbSfv+7XvyKsjOsmAlkEYRlpHbUCxUh2Hc5q2Wfm+acOHPkkUPX8kLeT2vW+Bd/9LlPi9BN0dbmazGPbf5kv02MRNQNeUrdRfdzRIOG4tUEv154msF7QdEuy9W4pv9p0z2rNOqOQEw9HPhMiAkftIVGnvvGRj9+jIARIVzV5gAfVm2DQbPJClr0tGNCfzHmndt6FddawubXFPvFNrKgdC38Ts0Jzl1F3aWGHT8UyURDbezrTGpxg+Cqq4YUXIZfrrqB8nzF8qK3eMW2Tcxdy2m+fFBzQeHlozBSP55dcdjekdQrcVcwkYux4jecJ9BU++DjWtMtY93LgVL5BnHixS4ybo7loCndYkpsI6ZZm9oLVxHsjeoaM9D9iYoN28LIlALBm/dnfCh92G/H40v/X25DMIvRqcfnE31gsOCJ85A29twSC+Cw== babrams@system76.servalws",
15
- "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCy3cbPekJYHAIa8J1fOr2iIqpx/7pl4giJYAG7HCfsunRRUq3dY1KhVw1BlmMGIDzNwcuNVIfBS5HS/wREqbHMXxbwAjWrMwUofWd09CTuKJZiyTLUC5pSQWKDXZrefH/Fwd7s+YKk1s78b49zkyDcHSnKxjN+5veinzeU+vaUF9duFAJ9OsL7kTDEzOUU0zJdSdUV0hH1lnljnvk8kXHLFl9sKS3iM2LRqW4B6wOc2RbXUnx+jwNaBsq1zd73F2q3Ta7GXdtW/q4oDYl3s72oW4ySL6TZfpLCiv/7txHicZiY1eqc591CON0k/Rh7eR7XsphwkUstoUPQcBuLqQPA529zBigD7A8PBmeHISxL2qirWjR2+PrEGn1b0yu8IHHz9ZgliX83Q4WpjXvJ3REj2jfM8hiFRV3lA/ovjQrmLLV8WUAZ8updcLE5mbhZzIsC4U/HKIJS02zoggHGHZauClwwcdBtIJnJqtP803yKNPO2sDudTpvEi8GZ8n6jSXo/N8nBVId2LZa5YY/g/v5kH0akn+/E3jXhw4CICNW8yICpeJO8dGYMOp3Bs9/cRK8QYomXqgpoFlvkgzT2h4Ie6lyRgNv5QnUyAnW43O5FdBnPk/XZ3LA462VU3uOfr0AQtEJzPccpFC6OCFYWdGwZQA/r1EZQES0yRfJLpx+uZQ== babrams@babrams-Serval-WS"
16
- ],
17
- "htpasswd": "$1$i2xUX9a4$6LwYbCk4K6JErTDdaiZy50",
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
- linter = JsonLint::Linter.new
26
- linter.check_stream(StringIO.new(json))
21
+ opts = {}
27
22
 
28
- puts "errors: #{linter.errors}"
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.2
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-01 00:00:00.000000000 Z
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/perf_compat.rb
239
- - test/test_various.rb
204
+ - test/_test_active_mimic.rb
205
+ - test/_test_mimic_rails.rb
240
206
  - test/activesupport_datetime_test.rb
241
- - test/test_scp.rb
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/isolated/test_mimic_rails_after.rb
246
- - test/isolated/test_mimic_rails_datetime.rb
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/_test_mimic_rails.rb
256
- - test/test_file.rb
257
- - test/bug.rb
258
- - test/mem.rb
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/rails.rb
263
- - test/perf_file.rb
264
- - test/test_compat.rb
265
- - test/helper.rb
266
- - test/perf.rb
267
- - test/bug_fast.rb
268
- - test/perf_strict.rb
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
@@ -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
@@ -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