oj 2.12.12 → 2.12.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13e345b717fb9e6ce7ab0c1f7e96c23586148c16
4
- data.tar.gz: 19dd28489fcd97c301e4ea744f3b9114c3de107b
3
+ metadata.gz: 5f901c34e6bd4d7a0dec0fbff5e72e62d2ade9f9
4
+ data.tar.gz: fabea9097473451a41172f859d224d1ba45df888
5
5
  SHA512:
6
- metadata.gz: cdc08e19e3621678e07531b89831fda57c23b4b4efa1f50ec94573058e0f82864dab1cfd62b4a9bc4a97732d17fb77c49d1f88bad7c7503334cc78e15981095e
7
- data.tar.gz: 46a77fd33b9b2b2424082f84e401d39bad85da74887e35cc4450310c4b0798f490e440a4a21e2987868e0f0c07486020bf885a1ec4d85314682164d0b7537d9a
6
+ metadata.gz: fb4cc5e9d368ac919c849d97abc36cba6510437ee5934a6fa4cddb0eaa185c548baaf0589eda779ddc921b295cdbd99b65d516c957fa4dd77ba82cdfcc8e580f
7
+ data.tar.gz: b2a6822d4b6a8261040b5585a87c01f6529a3b25376bce9623ea547d4a81a1fef9075f9172bdc9de73ec4469bdb558424c3ed824519c757d7d95647d932910b6
data/README.md CHANGED
@@ -26,15 +26,17 @@ Follow [@peterohler on Twitter](http://twitter.com/#!/peterohler) for announceme
26
26
 
27
27
  [![Build Status](https://secure.travis-ci.org/ohler55/oj.png?branch=master)](http://travis-ci.org/ohler55/oj)
28
28
 
29
- ## Current Release 2.12.12
29
+ ## Future Release 2.12.13
30
30
 
31
- - Thanks to asurin for adding support for arguments to to_json() that rails uses.
31
+ - Added a check for the second argument to load() is a Hash.
32
+
33
+ - Yet another attempt to make floating point numbers display better.
32
34
 
33
- ## Release 2.12.11
35
+ - Thanks to mkillianey for getting the extconf.rb and gemspec file updated.
34
36
 
35
- - Oj::ParseError is now thrown instead of SyntaxError when there are multiple
36
- JSON documents in a string or file and there is no proc or block associated
37
- with the parse call.
37
+ ## Current Release 2.12.12
38
+
39
+ - Thanks to asurin for adding support for arguments to to_json() that rails uses.
38
40
 
39
41
  [Older release notes](http://www.ohler.com/dev/oj_misc/release_notes.html).
40
42
 
@@ -56,6 +56,6 @@ dflags.each do |k,v|
56
56
  end
57
57
  $CPPFLAGS += ' -Wall'
58
58
  #puts "*** $CPPFLAGS: #{$CPPFLAGS}"
59
- create_makefile(extension_name)
59
+ create_makefile("#{extension_name}/#{extension_name}")
60
60
 
61
61
  %x{make clean}
@@ -725,6 +725,7 @@ load(int argc, VALUE *argv, VALUE self) {
725
725
  VALUE ropts = argv[1];
726
726
  VALUE v;
727
727
 
728
+ Check_Type(ropts, T_HASH);
728
729
  if (Qnil != (v = rb_hash_lookup(ropts, mode_sym))) {
729
730
  if (object_sym == v) {
730
731
  mode = ObjectMode;
@@ -795,6 +796,7 @@ load_file(int argc, VALUE *argv, VALUE self) {
795
796
  VALUE ropts = argv[1];
796
797
  VALUE v;
797
798
 
799
+ Check_Type(ropts, T_HASH);
798
800
  if (Qnil != (v = rb_hash_lookup(ropts, mode_sym))) {
799
801
  if (object_sym == v) {
800
802
  mode = ObjectMode;
@@ -1802,8 +1804,8 @@ static struct _Options mimic_object_to_json_options = {
1802
1804
  10, // create_id_len
1803
1805
  9, // sec_prec
1804
1806
  0, // dump_opts
1805
- 16, // float_prec
1806
- "%0.16g", // float_fmt
1807
+ 15, // float_prec
1808
+ "%0.15g", // float_fmt
1807
1809
  };
1808
1810
 
1809
1811
  static VALUE
@@ -395,6 +395,7 @@ read_num(ParseInfo pi) {
395
395
  ni.i = 0;
396
396
  ni.num = 0;
397
397
  ni.div = 1;
398
+ ni.di = 0;
398
399
  ni.len = 0;
399
400
  ni.exp = 0;
400
401
  ni.dec_cnt = 0;
@@ -459,6 +460,7 @@ read_num(ParseInfo pi) {
459
460
  // TBD move size check here
460
461
  ni.num = ni.num * 10 + d;
461
462
  ni.div *= 10;
463
+ ni.di++;
462
464
  if (LONG_MAX <= ni.div || DEC_MAX < ni.dec_cnt - zero_cnt) {
463
465
  ni.big = 1;
464
466
  }
@@ -726,14 +728,19 @@ oj_num_as_value(NumInfo ni) {
726
728
  rnum = rb_funcall(rnum, rb_intern("to_f"), 0);
727
729
  }
728
730
  } else {
729
- double d = (double)ni->i + (double)ni->num * (1.0L / ni->div);
730
-
731
+ // All these machinations are to get rounding to work better.
732
+ double d = (double)ni->i * (double)ni->div + (double)ni->num;
733
+ int x = ni->exp - ni->di;
734
+
735
+ d = round(d);
736
+ if (0 < x) {
737
+ d *= pow(10.0L, x);
738
+ } else if (0 > x) {
739
+ d /= pow(10.0L, -x);
740
+ }
731
741
  if (ni->neg) {
732
742
  d = -d;
733
743
  }
734
- if (0 != ni->exp) {
735
- d *= pow(10.0L, ni->exp);
736
- }
737
744
  rnum = rb_float_new(d);
738
745
  }
739
746
  }
@@ -44,6 +44,7 @@ typedef struct _NumInfo {
44
44
  int64_t i;
45
45
  int64_t num;
46
46
  int64_t div;
47
+ int64_t di;
47
48
  const char *str;
48
49
  size_t len;
49
50
  long exp;
@@ -406,6 +406,7 @@ read_num(ParseInfo pi) {
406
406
  ni.i = 0;
407
407
  ni.num = 0;
408
408
  ni.div = 1;
409
+ ni.di = 0;
409
410
  ni.len = 0;
410
411
  ni.exp = 0;
411
412
  ni.dec_cnt = 0;
@@ -460,6 +461,7 @@ read_num(ParseInfo pi) {
460
461
  ni.dec_cnt++;
461
462
  ni.num = ni.num * 10 + d;
462
463
  ni.div *= 10;
464
+ ni.di++;
463
465
  if (LONG_MAX <= ni.div || DEC_MAX < ni.dec_cnt - zero_cnt) {
464
466
  ni.big = 1;
465
467
  }
@@ -510,6 +512,7 @@ read_nan(ParseInfo pi) {
510
512
  ni.i = 0;
511
513
  ni.num = 0;
512
514
  ni.div = 1;
515
+ ni.di = 0;
513
516
  ni.len = 0;
514
517
  ni.exp = 0;
515
518
  ni.dec_cnt = 0;
@@ -679,6 +682,7 @@ oj_sparse2(ParseInfo pi) {
679
682
  ni.i = 0;
680
683
  ni.num = 0;
681
684
  ni.div = 1;
685
+ ni.di = 0;
682
686
  ni.len = 0;
683
687
  ni.exp = 0;
684
688
  ni.dec_cnt = 0;
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '2.12.12'
4
+ VERSION = '2.12.13'
5
5
  end
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.12.12
4
+ version: 2.12.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-09 00:00:00.000000000 Z
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -171,7 +171,6 @@ rdoc_options:
171
171
  - README.md
172
172
  require_paths:
173
173
  - lib
174
- - ext
175
174
  required_ruby_version: !ruby/object:Gem::Requirement
176
175
  requirements:
177
176
  - - ">="
@@ -188,4 +187,64 @@ rubygems_version: 2.4.5
188
187
  signing_key:
189
188
  specification_version: 4
190
189
  summary: A fast JSON parser and serializer.
191
- test_files: []
190
+ test_files:
191
+ - test/_test_active.rb
192
+ - test/_test_active_mimic.rb
193
+ - test/_test_mimic_rails.rb
194
+ - test/bug.rb
195
+ - test/bug2.rb
196
+ - test/bug3.rb
197
+ - test/bug_fast.rb
198
+ - test/bug_load.rb
199
+ - test/example.rb
200
+ - test/files.rb
201
+ - test/helper.rb
202
+ - test/io.rb
203
+ - test/isolated/shared.rb
204
+ - test/isolated/test_mimic_after.rb
205
+ - test/isolated/test_mimic_alone.rb
206
+ - test/isolated/test_mimic_as_json.rb
207
+ - test/isolated/test_mimic_before.rb
208
+ - test/isolated/test_mimic_define.rb
209
+ - test/isolated/test_mimic_rails_after.rb
210
+ - test/isolated/test_mimic_rails_before.rb
211
+ - test/mod.rb
212
+ - test/perf.rb
213
+ - test/perf_compat.rb
214
+ - test/perf_fast.rb
215
+ - test/perf_file.rb
216
+ - test/perf_object.rb
217
+ - test/perf_saj.rb
218
+ - test/perf_scp.rb
219
+ - test/perf_simple.rb
220
+ - test/perf_strict.rb
221
+ - test/sample/change.rb
222
+ - test/sample/dir.rb
223
+ - test/sample/doc.rb
224
+ - test/sample/file.rb
225
+ - test/sample/group.rb
226
+ - test/sample/hasprops.rb
227
+ - test/sample/layer.rb
228
+ - test/sample/line.rb
229
+ - test/sample/oval.rb
230
+ - test/sample/rect.rb
231
+ - test/sample/shape.rb
232
+ - test/sample/text.rb
233
+ - test/sample.rb
234
+ - test/sample_json.rb
235
+ - test/struct.rb
236
+ - test/test_compat.rb
237
+ - test/test_debian.rb
238
+ - test/test_fast.rb
239
+ - test/test_file.rb
240
+ - test/test_gc.rb
241
+ - test/test_object.rb
242
+ - test/test_saj.rb
243
+ - test/test_scp.rb
244
+ - test/test_serializer.rb
245
+ - test/test_strict.rb
246
+ - test/test_various.rb
247
+ - test/test_writer.rb
248
+ - test/write_timebars.rb
249
+ - test/zip.rb
250
+ has_rdoc: true