oj 3.5.0 → 3.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/oj/custom.c +12 -0
- data/ext/oj/dump_compat.c +6 -0
- data/ext/oj/parse.c +3 -1
- data/ext/oj/rails.c +6 -0
- data/ext/oj/sparse.c +3 -1
- data/ext/oj/trace.c +3 -1
- data/ext/oj/trace.h +5 -3
- data/lib/oj/version.rb +1 -1
- data/test/foo.rb +15 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09deb70b3ba1d0eeac19e27fd57ef92437f44aff2bf1bcdc8d6c46f523da195e'
|
4
|
+
data.tar.gz: 0154fb4466a7f286428685e851029bb48e6d82ffb2b25cf34cf82541fd8b5c38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6fe3ca939fae01ee40793c523a366bbb307db771ef26d4157c597e517610d6c627ab96ea9daa68cccd9c2c3054cc2cc46992f295e511cfb5388e664e3a3fa62
|
7
|
+
data.tar.gz: 6f013fa5478f633ee16c6f557ca565b25fa605d05d9d59ae373b78a7bd8dc216d2af938f98b249abc8df20729a33df1c5b8be85a18a50046235800007a44989d
|
data/ext/oj/custom.c
CHANGED
@@ -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);
|
data/ext/oj/dump_compat.c
CHANGED
@@ -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);
|
data/ext/oj/parse.c
CHANGED
@@ -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;
|
data/ext/oj/rails.c
CHANGED
@@ -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) {
|
data/ext/oj/sparse.c
CHANGED
@@ -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;
|
data/ext/oj/trace.c
CHANGED
data/ext/oj/trace.h
CHANGED
data/lib/oj/version.rb
CHANGED
data/test/foo.rb
CHANGED
@@ -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: :
|
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.
|
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-
|
11
|
+
date: 2018-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|