oj 3.5.0 → 3.5.1

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
  SHA256:
3
- metadata.gz: 30b24a6a60285c820a9e10671a976043a9163c2e98a3c07ba16af43ad88b8e6f
4
- data.tar.gz: 90fc1a46d76296f2e226434a26b6acc0cbe16fa378173ea98700b2250ecf45ca
3
+ metadata.gz: '09deb70b3ba1d0eeac19e27fd57ef92437f44aff2bf1bcdc8d6c46f523da195e'
4
+ data.tar.gz: 0154fb4466a7f286428685e851029bb48e6d82ffb2b25cf34cf82541fd8b5c38
5
5
  SHA512:
6
- metadata.gz: 71d7f8f0c32e3183a9f228764ffacdbd94cac6497e4af07e3ede247a676b2abd3815b3c51228992429a400a0ef879b8f54a8767cfa8b3a573a9931b46ec785e0
7
- data.tar.gz: ce7fb5fa634fd8122173712faed5435bee5ec3477445d969f3a16f62ac6703dae9fee0f0476cbbfdc8852ba4a7243753d543e44f61eb286489b7a700e0e0dde5
6
+ metadata.gz: e6fe3ca939fae01ee40793c523a366bbb307db771ef26d4157c597e517610d6c627ab96ea9daa68cccd9c2c3054cc2cc46992f295e511cfb5388e664e3a3fa62
7
+ data.tar.gz: 6f013fa5478f633ee16c6f557ca565b25fa605d05d9d59ae373b78a7bd8dc216d2af938f98b249abc8df20729a33df1c5b8be85a18a50046235800007a44989d
@@ -464,6 +464,9 @@ dump_common(VALUE obj, int depth, Out out) {
464
464
  const char *s;
465
465
  int len;
466
466
 
467
+ if (Yes == out->opts->trace) {
468
+ oj_trace("to_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyIn);
469
+ }
467
470
  #if HAS_METHOD_ARITY
468
471
  if (0 == rb_obj_method_arity(obj, oj_to_json_id)) {
469
472
  rs = rb_funcall(obj, oj_to_json_id, 0);
@@ -473,6 +476,9 @@ dump_common(VALUE obj, int depth, Out out) {
473
476
  #else
474
477
  rs = rb_funcall2(obj, oj_to_json_id, out->argc, out->argv);
475
478
  #endif
479
+ if (Yes == out->opts->trace) {
480
+ oj_trace("to_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyOut);
481
+ }
476
482
  s = rb_string_value_ptr((VALUE*)&rs);
477
483
  len = (int)RSTRING_LEN(rs);
478
484
 
@@ -483,6 +489,9 @@ dump_common(VALUE obj, int depth, Out out) {
483
489
  } else if (Yes == out->opts->as_json && rb_respond_to(obj, oj_as_json_id)) {
484
490
  volatile VALUE aj;
485
491
 
492
+ if (Yes == out->opts->trace) {
493
+ oj_trace("as_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyIn);
494
+ }
486
495
  // Some classes elect to not take an options argument so check the arity
487
496
  // of as_json.
488
497
  #if HAS_METHOD_ARITY
@@ -494,6 +503,9 @@ dump_common(VALUE obj, int depth, Out out) {
494
503
  #else
495
504
  aj = rb_funcall2(obj, oj_as_json_id, out->argc, out->argv);
496
505
  #endif
506
+ if (Yes == out->opts->trace) {
507
+ oj_trace("as_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyOut);
508
+ }
497
509
  // Catch the obvious brain damaged recursive dumping.
498
510
  if (aj == obj) {
499
511
  volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
@@ -120,6 +120,9 @@ dump_to_json(VALUE obj, Out out) {
120
120
  const char *s;
121
121
  int len;
122
122
 
123
+ if (Yes == out->opts->trace) {
124
+ oj_trace("to_json", obj, __FILE__, __LINE__, 0, TraceRubyIn);
125
+ }
123
126
  #if HAS_METHOD_ARITY
124
127
  if (0 == rb_obj_method_arity(obj, oj_to_json_id)) {
125
128
  rs = rb_funcall(obj, oj_to_json_id, 0);
@@ -129,6 +132,9 @@ dump_to_json(VALUE obj, Out out) {
129
132
  #else
130
133
  rs = rb_funcall2(obj, oj_to_json_id, out->argc, out->argv);
131
134
  #endif
135
+ if (Yes == out->opts->trace) {
136
+ oj_trace("to_json", obj, __FILE__, __LINE__, 0, TraceRubyOut);
137
+ }
132
138
 
133
139
  s = rb_string_value_ptr((VALUE*)&rs);
134
140
  len = (int)RSTRING_LEN(rs);
@@ -286,8 +286,10 @@ read_escaped_str(ParseInfo pi, const char *start) {
286
286
  case NEXT_HASH_NEW:
287
287
  case NEXT_HASH_KEY:
288
288
  if (Qundef == (parent->key_val = pi->hash_key(pi, buf.head, buf_len(&buf)))) {
289
- parent->key = strdup(buf.head);
290
289
  parent->klen = buf_len(&buf);
290
+ parent->key = malloc(parent->klen + 1);
291
+ memcpy((char*)parent->key, buf.head, parent->klen);
292
+ *(char*)(parent->key + parent->klen) = '\0';
291
293
  } else {
292
294
  parent->key = "";
293
295
  parent->klen = 0;
@@ -968,6 +968,9 @@ static void
968
968
  dump_as_json(VALUE obj, int depth, Out out, bool as_ok) {
969
969
  volatile VALUE ja;
970
970
 
971
+ if (Yes == out->opts->trace) {
972
+ oj_trace("as_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyIn);
973
+ }
971
974
  // Some classes elect to not take an options argument so check the arity
972
975
  // of as_json.
973
976
  #if HAS_METHOD_ARITY
@@ -979,6 +982,9 @@ dump_as_json(VALUE obj, int depth, Out out, bool as_ok) {
979
982
  #else
980
983
  ja = rb_funcall2(obj, oj_as_json_id, out->argc, out->argv);
981
984
  #endif
985
+ if (Yes == out->opts->trace) {
986
+ oj_trace("as_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyOut);
987
+ }
982
988
 
983
989
  out->argc = 0;
984
990
  if (ja == obj || !as_ok) {
@@ -296,8 +296,10 @@ read_escaped_str(ParseInfo pi) {
296
296
  case NEXT_HASH_NEW:
297
297
  case NEXT_HASH_KEY:
298
298
  if (Qundef == (parent->key_val = pi->hash_key(pi, buf.head, buf_len(&buf)))) {
299
- parent->key = strdup(buf.head);
300
299
  parent->klen = buf_len(&buf);
300
+ parent->key = malloc(parent->klen + 1);
301
+ memcpy((char*)parent->key, buf.head, parent->klen);
302
+ *(char*)(parent->key + parent->klen) = '\0';
301
303
  } else {
302
304
  parent->key = "";
303
305
  parent->klen = 0;
@@ -15,7 +15,9 @@ fill_indent(char *indent, int depth) {
15
15
  } else if (depth < 0) {
16
16
  depth = 0;
17
17
  }
18
- memset(indent, ' ', depth);
18
+ if (0 < depth) {
19
+ memset(indent, ' ', depth);
20
+ }
19
21
  indent[depth] = '\0';
20
22
  }
21
23
 
@@ -10,9 +10,11 @@
10
10
  #include <ruby.h>
11
11
 
12
12
  typedef enum {
13
- TraceIn = '{',
14
- TraceOut = '}',
15
- TraceCall = '-',
13
+ TraceIn = '}',
14
+ TraceOut = '{',
15
+ TraceCall = '-',
16
+ TraceRubyIn = '>',
17
+ TraceRubyOut = '<',
16
18
  } TraceWhere;
17
19
 
18
20
  struct _ParseInfo;
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.5.0'
4
+ VERSION = '3.5.1'
5
5
  end
@@ -4,29 +4,33 @@ $: << '.'
4
4
  $: << '../lib'
5
5
  $: << '../ext'
6
6
 
7
+ require 'tracer'
7
8
  require 'oj'
8
9
  require 'sample'
9
10
 
10
- #obj = sample_doc(1)
11
-
12
11
  class Foo
13
12
  def initialize()
14
13
  @x = 'abc'
15
14
  @y = 123
16
15
  @a = [{}]
17
16
  end
17
+
18
+ def to_json()
19
+ '{"x":33}'
20
+ end
21
+
22
+ def as_json(options={})
23
+ { z: @a, y: @y, x: @x }
24
+ end
18
25
  end
19
26
 
27
+ Tracer.display_c_call = true
28
+ Tracer.on
29
+
20
30
  obj = Foo.new
21
- obj = {
22
- x: 'abc',
23
- y: 123,
24
- a: [{}]
25
- }
26
31
 
27
- j = Oj.dump(obj, mode: :rails, trace: true)
28
- #j = Oj.dump(obj, mode: :compat)
32
+ j = Oj.dump(obj, mode: :custom, trace: true, use_as_json: true)
29
33
 
30
- puts j
34
+ #puts j
31
35
 
32
- Oj.load(j, mode: :rails, trace: true)
36
+ #Oj.load(j, mode: :rails, trace: true)
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: 3.5.0
4
+ version: 3.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-04 00:00:00.000000000 Z
11
+ date: 2018-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler