oj 2.18.1 → 2.18.2

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: 0c4ba43d61f927e22bc0e86fcb053d0593a531f0
4
- data.tar.gz: d09686c7ff45e8c6b07fd71c7c31aa5c7920a2f3
3
+ metadata.gz: e75fe6286b1a83b703bbb5fe4ef67620471ed85c
4
+ data.tar.gz: 11c1c0a4025e7230882265540158df6ca22c8324
5
5
  SHA512:
6
- metadata.gz: 1a8f222f85bf299d92f6ea6432d2bae1f541f5ed615e18a052a7328badb430050928a363961fde7148aa66fb56f6507608fe6e17c482f003cb13230073dc58bd
7
- data.tar.gz: d65f126ff8de728d8a95048ce7f624bf51c3ea81721fb29ad27855454f8c94ba7e971676c3144330a9e93a973e443ed70698247f2c65ffb1be3fbf58863bd07f
6
+ metadata.gz: be67841c21694aeea3c687dac1e5e2c76a2069198dfc4e8edc9efc469a97489265e1814b4607740ee38814885868f6b7822cadd2ca5b5c1f3b058d2f318b951f
7
+ data.tar.gz: 53b40092ab955eed576c31a4c755583ba14ed6d1013363dbb6e8c256298c36bf0e67de9b9472be1ef1f0aa574735ba4ef417308beb283a43a698a9993ecd1d1a
@@ -830,9 +830,10 @@ static int
830
830
  hash_cb_strict(VALUE key, VALUE value, Out out) {
831
831
  int depth = out->depth;
832
832
  long size;
833
-
834
- if (rb_type(key) != T_STRING) {
835
- rb_raise(rb_eTypeError, "In :strict mode all Hash keys must be Strings, not %s.\n", rb_class2name(rb_obj_class(key)));
833
+ int rtype = rb_type(key);
834
+
835
+ if (rtype != T_STRING && rtype != T_SYMBOL) {
836
+ rb_raise(rb_eTypeError, "In :strict mode all Hash keys must be Strings or Symbols, not %s.\n", rb_class2name(rb_obj_class(key)));
836
837
  }
837
838
  if (out->omit_nil && Qnil == value) {
838
839
  return ST_CONTINUE;
@@ -843,7 +844,11 @@ hash_cb_strict(VALUE key, VALUE value, Out out) {
843
844
  grow(out, size);
844
845
  }
845
846
  fill_indent(out, depth);
846
- dump_str_comp(key, out);
847
+ if (rtype == T_STRING) {
848
+ dump_str_comp(key, out);
849
+ } else {
850
+ dump_sym_comp(key, out);
851
+ }
847
852
  *out->cur++ = ':';
848
853
  } else {
849
854
  size = depth * out->opts->dump_opts.indent_size + out->opts->dump_opts.hash_size + 1;
@@ -861,7 +866,11 @@ hash_cb_strict(VALUE key, VALUE value, Out out) {
861
866
  out->cur += out->opts->dump_opts.indent_size;
862
867
  }
863
868
  }
864
- dump_str_comp(key, out);
869
+ if (rtype == T_STRING) {
870
+ dump_str_comp(key, out);
871
+ } else {
872
+ dump_sym_comp(key, out);
873
+ }
865
874
  size = out->opts->dump_opts.before_size + out->opts->dump_opts.after_size + 2;
866
875
  if (out->end - out->cur <= size) {
867
876
  grow(out, size);
@@ -2307,8 +2316,8 @@ oj_write_obj_to_stream(VALUE obj, VALUE stream, Options copts) {
2307
2316
  out.buf = buf;
2308
2317
  out.end = buf + sizeof(buf) - BUFFER_EXTRA;
2309
2318
  out.allocated = 0;
2310
- oj_dump_obj_to_json(obj, copts, &out);
2311
2319
  out.omit_nil = copts->dump_opts.omit_nil;
2320
+ oj_dump_obj_to_json(obj, copts, &out);
2312
2321
  size = out.cur - out.buf;
2313
2322
  if (oj_stringio_class == clas) {
2314
2323
  rb_funcall(stream, oj_write_id, 1, rb_str_new(out.buf, size));
@@ -2536,8 +2545,8 @@ oj_write_leaf_to_file(Leaf leaf, const char *path, Options copts) {
2536
2545
  out.buf = buf;
2537
2546
  out.end = buf + sizeof(buf) - BUFFER_EXTRA;
2538
2547
  out.allocated = 0;
2539
- oj_dump_leaf_to_json(leaf, copts, &out);
2540
2548
  out.omit_nil = copts->dump_opts.omit_nil;
2549
+ oj_dump_leaf_to_json(leaf, copts, &out);
2541
2550
  size = out.cur - out.buf;
2542
2551
  if (0 == (f = fopen(path, "w"))) {
2543
2552
  rb_raise(rb_eIOError, "%s\n", strerror(errno));
@@ -49,6 +49,9 @@ mark(void *ptr) {
49
49
  if (Qnil != v->val && Qundef != v->val) {
50
50
  rb_gc_mark(v->val);
51
51
  }
52
+ if (Qnil != v->key_val && Qundef != v->key_val) {
53
+ rb_gc_mark(v->key_val);
54
+ }
52
55
  }
53
56
  #if USE_PTHREAD_MUTEX
54
57
  pthread_mutex_unlock(&stack->mutex);
@@ -92,6 +92,7 @@ inline static void
92
92
  stack_cleanup(ValStack stack) {
93
93
  if (stack->base != stack->head) {
94
94
  xfree(stack->head);
95
+ stack->head = NULL;
95
96
  }
96
97
  }
97
98
 
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '2.18.1'
4
+ VERSION = '2.18.2'
5
5
  end
@@ -4,16 +4,25 @@
4
4
  $: << File.join(File.dirname(__FILE__), "../lib")
5
5
  $: << File.join(File.dirname(__FILE__), "../ext")
6
6
 
7
+ require 'stringio'
7
8
  require 'oj'
9
+ require 'jsonlint'
8
10
 
9
- class A < BasicObject
10
- def initialize(data)
11
- @data = data
12
- end
13
- end
11
+ json = %|{
12
+ "id": "babrams",
13
+ "ssh_keys": [
14
+ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDMCKMvMJ2yb13pHLsIPqi2xHOBKFZKa8+FM1FUqNbIxKeq3LLw+4WiXLK60DxxS6hmOnXD+FcWNaykkGLyGQeYHxsHynsXo9BPaG/ewaAp5SDU/zAIAaex15s/zvo5l+5Pq9OwXYtFRmfezk3ImCx7SZ8sMmHiFHYD8d38XBlGX53kLSFm5HLEopEvSCRTUyTj+tPIspgYR6IvCTdXnamO9FT8Rkeqw+mqjX9sVTaLuuqwQZlRFRMslrrJbSfv+7XvyKsjOsmAlkEYRlpHbUCxUh2Hc5q2Wfm+acOHPkkUPX8kLeT2vW+Bd/9LlPi9BN0dbmazGPbf5kv02MRNQNeUrdRfdzRIOG4tUEv154msF7QdEuy9W4pv9p0z2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2xUX9a4$6LwYbCk4K6JErTDdaiZy50",
18
+ "groups": [
19
+ "devops"
20
+ ],
21
+ "shell": "\/bin\/bash",
22
+ "comment": "Ben Abrams"
23
+ }|
14
24
 
15
- a = A.new("xyz")
16
-
17
- json = Oj.dump(a, mode: :compat, use_to_json: true)
18
- #=> NoMethodError: undefined method `to_hash' for #<A:0x007fae03de1dc8>
25
+ linter = JsonLint::Linter.new
26
+ linter.check_stream(StringIO.new(json))
19
27
 
28
+ puts "errors: #{linter.errors}"
@@ -0,0 +1,20 @@
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
@@ -0,0 +1,20 @@
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
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.1
4
+ version: 2.18.2
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-01-12 00:00:00.000000000 Z
11
+ date: 2017-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -128,7 +128,9 @@ files:
128
128
  - test/isolated/test_mimic_rails_before.rb
129
129
  - test/isolated/test_mimic_rails_datetime.rb
130
130
  - test/isolated/test_mimic_redefine.rb
131
+ - test/mem.rb
131
132
  - test/mod.rb
133
+ - test/omit.rb
132
134
  - test/perf.rb
133
135
  - test/perf_compat.rb
134
136
  - test/perf_fast.rb
@@ -202,6 +204,7 @@ test_files:
202
204
  - test/write_timebars.rb
203
205
  - test/test_writer.rb
204
206
  - test/russian.rb
207
+ - test/omit.rb
205
208
  - test/test_gc.rb
206
209
  - test/_test_active_mimic.rb
207
210
  - test/test_serializer.rb
@@ -252,6 +255,7 @@ test_files:
252
255
  - test/_test_mimic_rails.rb
253
256
  - test/test_file.rb
254
257
  - test/bug.rb
258
+ - test/mem.rb
255
259
  - test/sample_json.rb
256
260
  - test/test_debian.rb
257
261
  - test/test_fast.rb