oj 2.9.3 → 2.9.4

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: 48a00c99e1a81e8db2d4d074dd75c207d35dba89
4
- data.tar.gz: a7945af118f56ce1b883ee8df51fac93c692714b
3
+ metadata.gz: 472794bb4413026604920270cbf2d91e9486184d
4
+ data.tar.gz: da2a776a8dd4e69c8b34bfbc478dbbcd11c60db3
5
5
  SHA512:
6
- metadata.gz: 7a31a3c396f291fd4c9c851b2a3d2d6ad85582abd30046251757e44f73e3146319daa543d23f707226d32507bbe55695274a08706c8a2d2546f3c1b328a69a7a
7
- data.tar.gz: 1f8979189385a752ec69bde1611728bc9d382608c251d3e59252268e6622f2dd9b6d3f37335663d041790e036802fb8871739275d247d3ba41873f3d3db378f2
6
+ metadata.gz: b4619f73d69dde844139216836a04570e2abb5103a0235e7199d3a98449c8b6f8c96385f86e627f6592d0095229d329f3f9d0b608b1eb09a9381e7b0d626f398
7
+ data.tar.gz: 2dcd720bd6e964c23f33e83227163388bc72b8294c583501bc51ef79d24b7395771f0657b5ba575ea638e2814b1fa3bdc707db8cec6d565638399befac751d03
data/README.md CHANGED
@@ -26,10 +26,9 @@ 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.9.3
29
+ ### Current Release 2.9.4
30
30
 
31
- - Fixed IO read error that showed up in IO objects that return nil instead of
32
- raising an EOF error when read is done.
31
+ - In mimic mode parse errors not match the JSON::ParserError.
33
32
 
34
33
  [Older release notes](http://www.ohler.com/dev/oj_misc/release_notes.html).
35
34
 
@@ -158,6 +157,8 @@ parsing.
158
157
 
159
158
  [Need for Speed](http://www.ohler.com/dev/need_for_speed/need_for_speed.html) for an overview of how Oj::Doc was designed.
160
159
 
160
+ *OjC, a C JSON parser*: https://www.ohler.com/ojc also at https://github.com/ohler55/ojc
161
+
161
162
  ### License:
162
163
 
163
164
  Copyright (c) 2012, Peter Ohler
@@ -1708,7 +1708,7 @@ define_mimic_json(int argc, VALUE *argv, VALUE self) {
1708
1708
  }
1709
1709
  if (rb_const_defined_at(mimic, rb_intern("Ext"))) {
1710
1710
  ext = rb_const_get_at(mimic, rb_intern("Ext"));
1711
- } else {
1711
+ } else {
1712
1712
  ext = rb_define_module_under(mimic, "Ext");
1713
1713
  }
1714
1714
  if (!rb_const_defined_at(ext, rb_intern("Parser"))) {
@@ -1761,6 +1761,9 @@ define_mimic_json(int argc, VALUE *argv, VALUE self) {
1761
1761
  space_sym = ID2SYM(rb_intern("space")); rb_gc_register_address(&space_sym);
1762
1762
  symbolize_names_sym = ID2SYM(rb_intern("symbolize_names")); rb_gc_register_address(&symbolize_names_sym);
1763
1763
 
1764
+ if (!rb_const_defined_at(mimic, rb_intern("ParserError"))) {
1765
+ rb_define_const(mimic, "ParserError", oj_parse_error_class);
1766
+ }
1764
1767
  oj_default_options.mode = CompatMode;
1765
1768
  oj_default_options.escape_mode = ASCIIEsc;
1766
1769
  oj_default_options.nilnil = Yes;
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '2.9.3'
4
+ VERSION = '2.9.4'
5
5
  end
@@ -6,7 +6,7 @@ $: << File.join(File.dirname(__FILE__), "../lib")
6
6
  $: << File.join(File.dirname(__FILE__), "../ext")
7
7
 
8
8
  require 'optparse'
9
- require 'yajl'
9
+ #require 'yajl'
10
10
  require 'perf'
11
11
  require 'json'
12
12
  require 'json/ext'
@@ -14,7 +14,7 @@ require 'oj'
14
14
 
15
15
  $verbose = false
16
16
  $indent = 0
17
- $iter = 10000
17
+ $iter = 100000
18
18
  $gets = 0
19
19
  $fetch = false
20
20
  $write = false
@@ -71,7 +71,7 @@ end
71
71
 
72
72
  # Verify that all packages dump and load correctly and return the same Object as the original.
73
73
  capture_error('Oj::Doc', $obj, 'load', 'dump') { |o| Oj::Doc.open(Oj.dump(o, :mode => :strict)) { |f| f.fetch() } }
74
- capture_error('Yajl', $obj, 'encode', 'parse') { |o| Yajl::Parser.parse(Yajl::Encoder.encode(o)) }
74
+ #capture_error('Yajl', $obj, 'encode', 'parse') { |o| Yajl::Parser.parse(Yajl::Encoder.encode(o)) }
75
75
  capture_error('JSON::Ext', $obj, 'generate', 'parse') { |o| JSON.generator = JSON::Ext::Generator; JSON::Ext::Parser.new(JSON.generate(o)).parse }
76
76
 
77
77
  if $verbose
@@ -82,7 +82,7 @@ puts '-' * 80
82
82
  puts "Parse Performance"
83
83
  perf = Perf.new()
84
84
  perf.add('Oj::Doc', 'parse') { Oj::Doc.open($json) {|f| } } unless $failed.has_key?('Oj::Doc')
85
- perf.add('Yajl', 'parse') { Yajl::Parser.parse($json) } unless $failed.has_key?('Yajl')
85
+ #perf.add('Yajl', 'parse') { Yajl::Parser.parse($json) } unless $failed.has_key?('Yajl')
86
86
  perf.add('JSON::Ext', 'parse') { JSON::Ext::Parser.new($json).parse } unless $failed.has_key?('JSON::Ext')
87
87
  perf.run($iter)
88
88
 
@@ -91,7 +91,7 @@ puts "JSON generation Performance"
91
91
  Oj::Doc.open($json) do |doc|
92
92
  perf = Perf.new()
93
93
  perf.add('Oj::Doc', 'dump') { doc.dump() }
94
- perf.add('Yajl', 'encode') { Yajl::Encoder.encode($obj) }
94
+ # perf.add('Yajl', 'encode') { Yajl::Encoder.encode($obj) }
95
95
  perf.add('JSON::Ext', 'fast_generate') { JSON.fast_generate($obj) }
96
96
  perf.before('JSON::Ext') { JSON.generator = JSON::Ext::Generator }
97
97
  perf.run($iter)
@@ -102,7 +102,7 @@ if 0 < $gets
102
102
  puts "Parse and get all values Performance"
103
103
  perf = Perf.new()
104
104
  perf.add('Oj::Doc', 'parse') { Oj::Doc.open($json) {|f| $gets.times { f.each_value() {} } } } unless $failed.has_key?('Oj::Doc')
105
- perf.add('Yajl', 'parse') { $gets.times { dig(Yajl::Parser.parse($json)) {} } } unless $failed.has_key?('Yajl')
105
+ # perf.add('Yajl', 'parse') { $gets.times { dig(Yajl::Parser.parse($json)) {} } } unless $failed.has_key?('Yajl')
106
106
  perf.add('JSON::Ext', 'parse') { $gets.times { dig(JSON::Ext::Parser.new($json).parse) {} } } unless $failed.has_key?('JSON::Ext')
107
107
  perf.run($iter)
108
108
  end
@@ -134,7 +134,7 @@ if $write
134
134
  Oj::Doc.open($json) do |doc|
135
135
  perf = Perf.new()
136
136
  perf.add('Oj::Doc', 'dump') { doc.dump(nil, 'oj.json') }
137
- perf.add('Yajl', 'encode') { File.open('yajl.json', 'w') { |f| Yajl::Encoder.encode($obj, f) } }
137
+ # perf.add('Yajl', 'encode') { File.open('yajl.json', 'w') { |f| Yajl::Encoder.encode($obj, f) } }
138
138
  perf.add('JSON::Ext', 'fast_generate') { File.open('json_ext.json', 'w') { |f| f.write(JSON.fast_generate($obj)) } }
139
139
  perf.before('JSON::Ext') { JSON.generator = JSON::Ext::Generator }
140
140
  perf.run($iter)
@@ -145,13 +145,13 @@ if $read
145
145
  puts '-' * 80
146
146
  puts "JSON read from file Performance"
147
147
  Oj::Doc.open($json) { |doc| doc.dump(nil, 'oj.json') }
148
- File.open('yajl.json', 'w') { |f| Yajl::Encoder.encode($obj, f) }
148
+ # File.open('yajl.json', 'w') { |f| Yajl::Encoder.encode($obj, f) }
149
149
  JSON.generator = JSON::Ext::Generator
150
150
  File.open('json_ext.json', 'w') { |f| f.write(JSON.fast_generate($obj)) }
151
151
  Oj::Doc.open($json) do |doc|
152
152
  perf = Perf.new()
153
153
  perf.add('Oj::Doc', 'open_file') { ::Oj::Doc.open_file('oj.json') }
154
- perf.add('Yajl', 'decode') { Yajl::decoder.decode(File.read('yajl.json')) }
154
+ # perf.add('Yajl', 'decode') { Yajl::decoder.decode(File.read('yajl.json')) }
155
155
  perf.add('JSON::Ext', '') { JSON.parse(File.read('json_ext.json')) }
156
156
  perf.before('JSON::Ext') { JSON.parser = JSON::Ext::Parser }
157
157
  perf.run($iter)
@@ -64,6 +64,7 @@ end
64
64
  $json = Oj.dump($obj)
65
65
  $obj_json = Oj.dump($obj, :mode => :object)
66
66
  #puts "*** size: #{$obj_json.size}"
67
+ #puts "*** #{$obj_json}"
67
68
  $failed = {} # key is same as String used in tests later
68
69
 
69
70
  def capture_error(tag, orig, load_key, dump_key, &blk)
@@ -203,4 +203,17 @@ class Mimic < ::Test::Unit::TestCase
203
203
  end
204
204
  end
205
205
 
206
+ # exception check
207
+ def test_exception
208
+ json = %{["a":1]}
209
+ begin
210
+ obj = JSON.parse(json)
211
+
212
+ rescue JSON::ParserError => je
213
+ assert(true)
214
+ return
215
+ end
216
+ assert(false, "*** expected an JSON::ParserError")
217
+ end
218
+
206
219
  end # Mimic
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby -wW1
2
+
3
+ $: << '.'
4
+ $: << '../lib'
5
+ $: << '../ext'
6
+
7
+ if __FILE__ == $0
8
+ if (i = ARGV.index('-I'))
9
+ x,path = ARGV.slice!(i, 2)
10
+ $: << path
11
+ end
12
+ end
13
+
14
+ require 'optparse'
15
+ require 'oj'
16
+ require 'perf'
17
+
18
+ $indent = 0
19
+ $iter = 1
20
+
21
+ opts = OptionParser.new
22
+
23
+ opts.on("-c", "--count [Int]", Integer, "iterations") { |i| $iter = i }
24
+ opts.on("-i", "--indent [Int]", Integer, "indent") { |i| $indent = i }
25
+
26
+ opts.on("-h", "--help", "Show this display") { puts opts; Process.exit!(0) }
27
+ files = opts.parse(ARGV)
28
+
29
+ $levels = [ "ERROR", "WARN", "INFO", "DEBUG", "TRACE" ]
30
+ $entry = {
31
+ "bar" => "0",
32
+ "level" => "INFO",
33
+ "message" => "A message",
34
+ "msgType" => 1,
35
+ "source" => "Test",
36
+ "thread" => "main",
37
+ "version" => 1,
38
+ "when" => 1400000000000000000,
39
+ }
40
+
41
+ Oj.default_options = { :mode => :strict, :indent => $indent }
42
+
43
+ filename = 'log.json'
44
+ File.open(filename, "w") { |f|
45
+ $iter.times do |i|
46
+ $entry["bar"] = (1_400_000_000_000 + i * 200) / 1000
47
+ $entry["when"] = 1_400_000_000_000_000_000 + i * 100_000_000
48
+ $entry["message"] = "This is log message number #{i} out of #{$iter} entries."
49
+ $entry["level"] = $levels[i % $levels.size]
50
+ Oj.to_stream(f, $entry, :indent => $indent)
51
+ if 0 == $indent
52
+ f.flush()
53
+ f.write("\n")
54
+ end
55
+ end
56
+ }
57
+
58
+ $cnt = 0
59
+ perf = Perf.new()
60
+ perf.add('Oj.load_file', '') { Oj.load_file(filename) { |o| $cnt += 1 } }
61
+ perf.run(1)
62
+
63
+ puts "*** read #{$cnt} entries"
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.9.3
4
+ version: 2.9.4
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-05-15 00:00:00.000000000 Z
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'The fastest JSON parser and object serializer. '
14
14
  email: peter@ohler.com
@@ -106,6 +106,7 @@ files:
106
106
  - test/test_strictx.rb
107
107
  - test/test_writer.rb
108
108
  - test/tests.rb
109
+ - test/write_fake_log.rb
109
110
  - test/x.rb
110
111
  homepage: http://www.ohler.com/oj
111
112
  licenses: