oj 3.13.22 → 3.14.0
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 +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +2 -1
- data/ext/oj/compat.c +10 -30
- data/ext/oj/custom.c +13 -29
- data/ext/oj/dump.c +6 -10
- data/ext/oj/dump_compat.c +9 -19
- data/ext/oj/dump_object.c +5 -11
- data/ext/oj/dump_strict.c +8 -18
- data/ext/oj/extconf.rb +10 -2
- data/ext/oj/fast.c +25 -42
- data/ext/oj/object.c +2 -6
- data/ext/oj/oj.c +2 -2
- data/ext/oj/oj.h +6 -0
- data/ext/oj/parse.c +4 -0
- data/ext/oj/parser.c +7 -3
- data/ext/oj/rails.c +10 -20
- data/ext/oj/reader.c +1 -1
- data/ext/oj/strict.c +4 -12
- data/ext/oj/trace.h +16 -0
- data/ext/oj/wab.c +9 -21
- data/lib/oj/version.rb +1 -1
- data/pages/InstallOptions.md +20 -0
- data/pages/Options.md +6 -0
- data/test/foo.rb +18 -66
- data/test/test_compat.rb +9 -0
- metadata +4 -3
- data/ext/oj/introspect.c +0 -96
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5864f273679d1441d9731976eb4f4c3cdcccaa86c877fae2aeb719cd03f45167
|
4
|
+
data.tar.gz: 815abc1a8572ce907b280ca632fd010c766ad55e581c3a59d76c0f94ede24234
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3318017139004f712665ff2fda5dcfc761b33079bb96dd1d8f5baf59d146a45956e3c58f1e700044a714ca2643d5a54196e3b306566130c9bda7242d8c688b91
|
7
|
+
data.tar.gz: f8f6f637c883ca2b4fa8c76f349940f6be3c1af524d43f3cc0ed4df27a21896f480da520b2897e191d38e50ef939139bdd242c3e3f33aa0c0e3aa8bd3a008a6b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 3.14.0 - 2022-01-30
|
4
|
+
|
5
|
+
- Tracing is now a compile time option giving a 15 to 20% performance boost.
|
6
|
+
|
7
|
+
- Some cleanup in teh fast parser.
|
8
|
+
|
9
|
+
## 3.13.23 - 2022-11-06
|
10
|
+
|
11
|
+
- Fixed issue with Oj::Parser extension regarding GC timeing.
|
12
|
+
|
3
13
|
## 3.13.22 - 2022-11-01
|
4
14
|
|
5
15
|
- Reorganized Oj::Parser code to allow for parser extensions in C.
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# [](http://www.ohler.com/oj) gem
|
2
2
|
|
3
|
-
[](https://github.com/ohler55/oj/actions/workflows/CI.yml)
|
4
4
|

|
5
5
|

|
6
6
|
[](https://dependabot.com/compatibility-score.html?dependency-name=oj&package-manager=bundler&version-scheme=semver)
|
@@ -70,6 +70,7 @@ links.
|
|
70
70
|
- [{file:Compatibility.md}](pages/Compatibility.md) lists current compatibility with Rubys and Rails.
|
71
71
|
- [{file:Advanced.md}](pages/Advanced.md) for fast parser and marshalling features.
|
72
72
|
- [{file:Security.md}](pages/Security.md) for security considerations.
|
73
|
+
- [{file:InstallOptions.md}](pages/InstallOptions.md) for install option.
|
73
74
|
|
74
75
|
## Releases
|
75
76
|
|
data/ext/oj/compat.c
CHANGED
@@ -54,9 +54,7 @@ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, c
|
|
54
54
|
} else {
|
55
55
|
rb_hash_aset(parent->val, rkey, rstr);
|
56
56
|
}
|
57
|
-
|
58
|
-
oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rstr);
|
59
|
-
}
|
57
|
+
TRACE_PARSE_CALL(pi->options.trace, "set_string", pi, rstr);
|
60
58
|
}
|
61
59
|
}
|
62
60
|
|
@@ -68,9 +66,7 @@ static VALUE start_hash(ParseInfo pi) {
|
|
68
66
|
} else {
|
69
67
|
h = rb_hash_new();
|
70
68
|
}
|
71
|
-
|
72
|
-
oj_trace_parse_in("start_hash", pi, __FILE__, __LINE__);
|
73
|
-
}
|
69
|
+
TRACE_PARSE_IN(pi->options.trace, "start_hash", pi);
|
74
70
|
return h;
|
75
71
|
}
|
76
72
|
|
@@ -93,9 +89,7 @@ static void end_hash(struct _parseInfo *pi) {
|
|
93
89
|
parent->classname = 0;
|
94
90
|
}
|
95
91
|
}
|
96
|
-
|
97
|
-
oj_trace_parse_hash_end(pi, __FILE__, __LINE__);
|
98
|
-
}
|
92
|
+
TRACE_PARSE_HASH_END(pi->options.trace, pi);
|
99
93
|
}
|
100
94
|
|
101
95
|
static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
@@ -110,16 +104,12 @@ static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig
|
|
110
104
|
}
|
111
105
|
}
|
112
106
|
pi->stack.head->val = rstr;
|
113
|
-
|
114
|
-
oj_trace_parse_call("add_string", pi, __FILE__, __LINE__, rstr);
|
115
|
-
}
|
107
|
+
TRACE_PARSE_CALL(pi->options.trace, "add_string", pi, rstr);
|
116
108
|
}
|
117
109
|
|
118
110
|
static void add_num(ParseInfo pi, NumInfo ni) {
|
119
111
|
pi->stack.head->val = oj_num_as_value(ni);
|
120
|
-
|
121
|
-
oj_trace_parse_call("add_number", pi, __FILE__, __LINE__, pi->stack.head->val);
|
122
|
-
}
|
112
|
+
TRACE_PARSE_CALL(pi->options.trace, "add_number", pi, pi->stack.head->val);
|
123
113
|
}
|
124
114
|
|
125
115
|
static void hash_set_num(struct _parseInfo *pi, Val parent, NumInfo ni) {
|
@@ -138,9 +128,7 @@ static void hash_set_num(struct _parseInfo *pi, Val parent, NumInfo ni) {
|
|
138
128
|
} else {
|
139
129
|
rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), rval);
|
140
130
|
}
|
141
|
-
|
142
|
-
oj_trace_parse_call("set_number", pi, __FILE__, __LINE__, rval);
|
143
|
-
}
|
131
|
+
TRACE_PARSE_CALL(pi->options.trace, "set_number", pi, rval);
|
144
132
|
}
|
145
133
|
|
146
134
|
static void hash_set_value(ParseInfo pi, Val parent, VALUE value) {
|
@@ -157,18 +145,14 @@ static void hash_set_value(ParseInfo pi, Val parent, VALUE value) {
|
|
157
145
|
} else {
|
158
146
|
rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), value);
|
159
147
|
}
|
160
|
-
|
161
|
-
oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, value);
|
162
|
-
}
|
148
|
+
TRACE_PARSE_CALL(pi->options.trace, "set_value", pi, value);
|
163
149
|
}
|
164
150
|
|
165
151
|
static VALUE start_array(ParseInfo pi) {
|
166
152
|
if (Qnil != pi->options.array_class) {
|
167
153
|
return rb_class_new_instance(0, NULL, pi->options.array_class);
|
168
154
|
}
|
169
|
-
|
170
|
-
oj_trace_parse_in("start_array", pi, __FILE__, __LINE__);
|
171
|
-
}
|
155
|
+
TRACE_PARSE_IN(pi->options.trace, "start_array", pi);
|
172
156
|
return rb_ary_new();
|
173
157
|
}
|
174
158
|
|
@@ -184,9 +168,7 @@ static void array_append_num(ParseInfo pi, NumInfo ni) {
|
|
184
168
|
} else {
|
185
169
|
rb_ary_push(parent->val, rval);
|
186
170
|
}
|
187
|
-
|
188
|
-
oj_trace_parse_call("append_number", pi, __FILE__, __LINE__, rval);
|
189
|
-
}
|
171
|
+
TRACE_PARSE_CALL(pi->options.trace, "append_number", pi, rval);
|
190
172
|
}
|
191
173
|
|
192
174
|
static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
@@ -201,9 +183,7 @@ static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const c
|
|
201
183
|
}
|
202
184
|
}
|
203
185
|
rb_ary_push(stack_peek(&pi->stack)->val, rstr);
|
204
|
-
|
205
|
-
oj_trace_parse_call("append_string", pi, __FILE__, __LINE__, rstr);
|
206
|
-
}
|
186
|
+
TRACE_PARSE_CALL(pi->options.trace, "append_string", pi, rstr);
|
207
187
|
}
|
208
188
|
|
209
189
|
void oj_set_compat_callbacks(ParseInfo pi) {
|
data/ext/oj/custom.c
CHANGED
@@ -24,20 +24,20 @@ static void dump_obj_str(VALUE obj, int depth, Out out) {
|
|
24
24
|
{"s", 1, Qnil},
|
25
25
|
{NULL, 0, Qnil},
|
26
26
|
};
|
27
|
-
attrs->value =
|
27
|
+
attrs->value = oj_safe_string_convert(obj);
|
28
28
|
|
29
29
|
oj_code_attrs(obj, attrs, depth, out, Yes == out->opts->create_ok);
|
30
30
|
}
|
31
31
|
|
32
32
|
static void dump_obj_as_str(VALUE obj, int depth, Out out) {
|
33
|
-
volatile VALUE rstr =
|
33
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
34
34
|
const char *str = RSTRING_PTR(rstr);
|
35
35
|
|
36
36
|
oj_dump_cstr(str, RSTRING_LEN(rstr), 0, 0, out);
|
37
37
|
}
|
38
38
|
|
39
39
|
static void bigdecimal_dump(VALUE obj, int depth, Out out) {
|
40
|
-
volatile VALUE rstr =
|
40
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
41
41
|
const char *str = RSTRING_PTR(rstr);
|
42
42
|
int len = (int)RSTRING_LEN(rstr);
|
43
43
|
|
@@ -305,7 +305,7 @@ static int hash_cb(VALUE key, VALUE value, VALUE ov) {
|
|
305
305
|
switch (rb_type(key)) {
|
306
306
|
case T_STRING: oj_dump_str(key, 0, out, false); break;
|
307
307
|
case T_SYMBOL: oj_dump_sym(key, 0, out, false); break;
|
308
|
-
default: oj_dump_str(
|
308
|
+
default: oj_dump_str(oj_safe_string_convert(key), 0, out, false); break;
|
309
309
|
}
|
310
310
|
if (!out->opts->dump_opts.use) {
|
311
311
|
*out->cur++ = ':';
|
@@ -479,17 +479,13 @@ static VALUE dump_common(VALUE obj, int depth, Out out) {
|
|
479
479
|
const char *s;
|
480
480
|
int len;
|
481
481
|
|
482
|
-
|
483
|
-
oj_trace("to_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyIn);
|
484
|
-
}
|
482
|
+
TRACE(out->opts->trace, "to_json", obj, depth + 1, TraceRubyIn);
|
485
483
|
if (0 == rb_obj_method_arity(obj, oj_to_json_id)) {
|
486
484
|
rs = rb_funcall(obj, oj_to_json_id, 0);
|
487
485
|
} else {
|
488
486
|
rs = rb_funcall2(obj, oj_to_json_id, out->argc, out->argv);
|
489
487
|
}
|
490
|
-
|
491
|
-
oj_trace("to_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyOut);
|
492
|
-
}
|
488
|
+
TRACE(out->opts->trace, "to_json", obj, depth + 1, TraceRubyOut);
|
493
489
|
s = RSTRING_PTR(rs);
|
494
490
|
len = (int)RSTRING_LEN(rs);
|
495
491
|
|
@@ -499,9 +495,7 @@ static VALUE dump_common(VALUE obj, int depth, Out out) {
|
|
499
495
|
} else if (Yes == out->opts->as_json && rb_respond_to(obj, oj_as_json_id)) {
|
500
496
|
volatile VALUE aj;
|
501
497
|
|
502
|
-
|
503
|
-
oj_trace("as_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyIn);
|
504
|
-
}
|
498
|
+
TRACE(out->opts->trace, "as_json", obj, depth + 1, TraceRubyIn);
|
505
499
|
// Some classes elect to not take an options argument so check the arity
|
506
500
|
// of as_json.
|
507
501
|
if (0 == rb_obj_method_arity(obj, oj_as_json_id)) {
|
@@ -509,12 +503,10 @@ static VALUE dump_common(VALUE obj, int depth, Out out) {
|
|
509
503
|
} else {
|
510
504
|
aj = rb_funcall2(obj, oj_as_json_id, out->argc, out->argv);
|
511
505
|
}
|
512
|
-
|
513
|
-
oj_trace("as_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyOut);
|
514
|
-
}
|
506
|
+
TRACE(out->opts->trace, "as_json", obj, depth + 1, TraceRubyOut);
|
515
507
|
// Catch the obvious brain damaged recursive dumping.
|
516
508
|
if (aj == obj) {
|
517
|
-
volatile VALUE rstr =
|
509
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
518
510
|
|
519
511
|
oj_dump_cstr(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), false, false, out);
|
520
512
|
} else {
|
@@ -876,9 +868,7 @@ static DumpFunc custom_funcs[] = {
|
|
876
868
|
void oj_dump_custom_val(VALUE obj, int depth, Out out, bool as_ok) {
|
877
869
|
int type = rb_type(obj);
|
878
870
|
|
879
|
-
|
880
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
|
881
|
-
}
|
871
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceIn);
|
882
872
|
if (MAX_DEPTH < depth) {
|
883
873
|
rb_raise(rb_eNoMemError, "Too deeply nested.\n");
|
884
874
|
}
|
@@ -887,16 +877,12 @@ void oj_dump_custom_val(VALUE obj, int depth, Out out, bool as_ok) {
|
|
887
877
|
|
888
878
|
if (NULL != f) {
|
889
879
|
f(obj, depth, out, true);
|
890
|
-
|
891
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
|
892
|
-
}
|
880
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
|
893
881
|
return;
|
894
882
|
}
|
895
883
|
}
|
896
884
|
oj_dump_nil(Qnil, depth, out, false);
|
897
|
-
|
898
|
-
oj_trace("dump", Qnil, __FILE__, __LINE__, depth, TraceOut);
|
899
|
-
}
|
885
|
+
TRACE(out->opts->trace, "dump", Qnil, depth, TraceOut);
|
900
886
|
}
|
901
887
|
|
902
888
|
///// load functions /////
|
@@ -969,9 +955,7 @@ static void end_hash(struct _parseInfo *pi) {
|
|
969
955
|
}
|
970
956
|
parent->clas = Qundef;
|
971
957
|
}
|
972
|
-
|
973
|
-
oj_trace_parse_hash_end(pi, __FILE__, __LINE__);
|
974
|
-
}
|
958
|
+
TRACE_PARSE_HASH_END(pi->options.trace, pi);
|
975
959
|
}
|
976
960
|
|
977
961
|
static void hash_set_num(struct _parseInfo *pi, Val kval, NumInfo ni) {
|
data/ext/oj/dump.c
CHANGED
@@ -463,7 +463,7 @@ void oj_dump_time(VALUE obj, Out out, int withZone) {
|
|
463
463
|
}
|
464
464
|
|
465
465
|
void oj_dump_ruby_time(VALUE obj, Out out) {
|
466
|
-
volatile VALUE rstr =
|
466
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
467
467
|
|
468
468
|
oj_dump_cstr(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), 0, 0, out);
|
469
469
|
}
|
@@ -736,13 +736,9 @@ void oj_dump_raw_json(VALUE obj, int depth, Out out) {
|
|
736
736
|
} else {
|
737
737
|
volatile VALUE jv;
|
738
738
|
|
739
|
-
|
740
|
-
oj_trace("raw_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyIn);
|
741
|
-
}
|
739
|
+
TRACE(out->opts->trace, "raw_json", obj, depth + 1, TraceRubyIn);
|
742
740
|
jv = rb_funcall(obj, oj_raw_json_id, 2, RB_INT2NUM(depth), RB_INT2NUM(out->indent));
|
743
|
-
|
744
|
-
oj_trace("raw_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyOut);
|
745
|
-
}
|
741
|
+
TRACE(out->opts->trace, "raw_json", obj, depth + 1, TraceRubyOut);
|
746
742
|
oj_dump_raw(RSTRING_PTR(jv), (size_t)RSTRING_LEN(jv), out);
|
747
743
|
}
|
748
744
|
}
|
@@ -932,7 +928,7 @@ void oj_dump_class(VALUE obj, int depth, Out out, bool as_ok) {
|
|
932
928
|
}
|
933
929
|
|
934
930
|
void oj_dump_obj_to_s(VALUE obj, Out out) {
|
935
|
-
volatile VALUE rstr =
|
931
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
936
932
|
|
937
933
|
oj_dump_cstr(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), 0, 0, out);
|
938
934
|
}
|
@@ -1173,7 +1169,7 @@ void oj_dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
|
1173
1169
|
} else if (d == (double)(long long int)d) {
|
1174
1170
|
cnt = snprintf(buf, sizeof(buf), "%.1f", d);
|
1175
1171
|
} else if (0 == out->opts->float_prec) {
|
1176
|
-
volatile VALUE rstr =
|
1172
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
1177
1173
|
|
1178
1174
|
cnt = (int)RSTRING_LEN(rstr);
|
1179
1175
|
if ((int)sizeof(buf) <= cnt) {
|
@@ -1195,7 +1191,7 @@ int oj_dump_float_printf(char *buf, size_t blen, VALUE obj, double d, const char
|
|
1195
1191
|
// Round off issues at 16 significant digits so check for obvious ones of
|
1196
1192
|
// 0001 and 9999.
|
1197
1193
|
if (17 <= cnt && (0 == strcmp("0001", buf + cnt - 4) || 0 == strcmp("9999", buf + cnt - 4))) {
|
1198
|
-
volatile VALUE rstr =
|
1194
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
1199
1195
|
|
1200
1196
|
strcpy(buf, RSTRING_PTR(rstr));
|
1201
1197
|
cnt = (int)RSTRING_LEN(rstr);
|
data/ext/oj/dump_compat.c
CHANGED
@@ -109,17 +109,13 @@ dump_to_json(VALUE obj, Out out) {
|
|
109
109
|
const char *s;
|
110
110
|
int len;
|
111
111
|
|
112
|
-
|
113
|
-
oj_trace("to_json", obj, __FILE__, __LINE__, 0, TraceRubyIn);
|
114
|
-
}
|
112
|
+
TRACE(out->opts->trace, "to_json", obj, 0, TraceRubyIn);
|
115
113
|
if (0 == rb_obj_method_arity(obj, oj_to_json_id)) {
|
116
114
|
rs = rb_funcall(obj, oj_to_json_id, 0);
|
117
115
|
} else {
|
118
116
|
rs = rb_funcall2(obj, oj_to_json_id, out->argc, out->argv);
|
119
117
|
}
|
120
|
-
|
121
|
-
oj_trace("to_json", obj, __FILE__, __LINE__, 0, TraceRubyOut);
|
122
|
-
}
|
118
|
+
TRACE(out->opts->trace, "to_json", obj, 0, TraceRubyOut);
|
123
119
|
|
124
120
|
s = RSTRING_PTR(rs);
|
125
121
|
len = (int)RSTRING_LEN(rs);
|
@@ -299,7 +295,7 @@ datetime_alt(VALUE obj, int depth, Out out) {
|
|
299
295
|
attrs[3].value = rb_funcall(obj, hour_id, 0);
|
300
296
|
attrs[4].value = rb_funcall(obj, min_id, 0);
|
301
297
|
attrs[5].value = rb_funcall(obj, sec_id, 0);
|
302
|
-
attrs[6].value =
|
298
|
+
attrs[6].value = oj_safe_string_convert(rb_funcall(obj, offset_id, 0));
|
303
299
|
attrs[7].value = rb_funcall(obj, start_id, 0);
|
304
300
|
|
305
301
|
oj_code_attrs(obj, attrs, depth, out, true);
|
@@ -606,7 +602,7 @@ dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
|
606
602
|
} else if (oj_rails_float_opt) {
|
607
603
|
cnt = oj_dump_float_printf(buf, sizeof(buf), obj, d, "%0.16g");
|
608
604
|
} else {
|
609
|
-
volatile VALUE rstr =
|
605
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
610
606
|
|
611
607
|
strcpy(buf, RSTRING_PTR(rstr));
|
612
608
|
cnt = (int)RSTRING_LEN(rstr);
|
@@ -648,7 +644,7 @@ hash_cb(VALUE key, VALUE value, VALUE ov) {
|
|
648
644
|
break;
|
649
645
|
default:
|
650
646
|
/*rb_raise(rb_eTypeError, "In :compat mode all Hash keys must be Strings or Symbols, not %s.\n", rb_class2name(rb_obj_class(key)));*/
|
651
|
-
oj_dump_str(
|
647
|
+
oj_dump_str(oj_safe_string_convert(key), 0, out, false);
|
652
648
|
break;
|
653
649
|
}
|
654
650
|
if (!out->opts->dump_opts.use) {
|
@@ -833,7 +829,7 @@ dump_bignum(VALUE obj, int depth, Out out, bool as_ok) {
|
|
833
829
|
if (use_bignum_alt) {
|
834
830
|
rs = rb_big2str(obj, 10);
|
835
831
|
} else {
|
836
|
-
rs =
|
832
|
+
rs = oj_safe_string_convert(obj);
|
837
833
|
}
|
838
834
|
rb_check_type(rs, T_STRING);
|
839
835
|
cnt = (int)RSTRING_LEN(rs);
|
@@ -893,9 +889,7 @@ void
|
|
893
889
|
oj_dump_compat_val(VALUE obj, int depth, Out out, bool as_ok) {
|
894
890
|
int type = rb_type(obj);
|
895
891
|
|
896
|
-
|
897
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
|
898
|
-
}
|
892
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceIn);
|
899
893
|
if (out->opts->dump_opts.max_depth <= depth) {
|
900
894
|
// When JSON.dump is called then an ArgumentError is expected and the
|
901
895
|
// limit is the depth inclusive. If JSON.generate is called then a
|
@@ -918,14 +912,10 @@ oj_dump_compat_val(VALUE obj, int depth, Out out, bool as_ok) {
|
|
918
912
|
|
919
913
|
if (NULL != f) {
|
920
914
|
f(obj, depth, out, as_ok);
|
921
|
-
|
922
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
|
923
|
-
}
|
915
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
|
924
916
|
return;
|
925
917
|
}
|
926
918
|
}
|
927
919
|
oj_dump_nil(Qnil, depth, out, false);
|
928
|
-
|
929
|
-
oj_trace("dump", Qnil, __FILE__, __LINE__, depth, TraceOut);
|
930
|
-
}
|
920
|
+
TRACE(out->opts->trace, "dump", Qnil, depth, TraceOut);
|
931
921
|
}
|
data/ext/oj/dump_object.c
CHANGED
@@ -30,7 +30,7 @@ static void dump_data(VALUE obj, int depth, Out out, bool as_ok) {
|
|
30
30
|
*out->cur = '\0';
|
31
31
|
} else {
|
32
32
|
if (oj_bigdecimal_class == clas) {
|
33
|
-
volatile VALUE rstr =
|
33
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
34
34
|
const char * str = RSTRING_PTR(rstr);
|
35
35
|
int len = (int)RSTRING_LEN(rstr);
|
36
36
|
|
@@ -59,7 +59,7 @@ static void dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
|
|
59
59
|
VALUE clas = rb_obj_class(obj);
|
60
60
|
|
61
61
|
if (oj_bigdecimal_class == clas) {
|
62
|
-
volatile VALUE rstr =
|
62
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
63
63
|
const char * str = RSTRING_PTR(rstr);
|
64
64
|
int len = (int)RSTRING_LEN(rstr);
|
65
65
|
|
@@ -682,9 +682,7 @@ static DumpFunc obj_funcs[] = {
|
|
682
682
|
void oj_dump_obj_val(VALUE obj, int depth, Out out) {
|
683
683
|
int type = rb_type(obj);
|
684
684
|
|
685
|
-
|
686
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
|
687
|
-
}
|
685
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceIn);
|
688
686
|
if (MAX_DEPTH < depth) {
|
689
687
|
rb_raise(rb_eNoMemError, "Too deeply nested.\n");
|
690
688
|
}
|
@@ -693,14 +691,10 @@ void oj_dump_obj_val(VALUE obj, int depth, Out out) {
|
|
693
691
|
|
694
692
|
if (NULL != f) {
|
695
693
|
f(obj, depth, out, false);
|
696
|
-
|
697
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
|
698
|
-
}
|
694
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
|
699
695
|
return;
|
700
696
|
}
|
701
697
|
}
|
702
698
|
oj_dump_nil(Qnil, depth, out, false);
|
703
|
-
|
704
|
-
oj_trace("dump", Qnil, __FILE__, __LINE__, depth, TraceOut);
|
705
|
-
}
|
699
|
+
TRACE(out->opts->trace, "dump", Qnil, depth, TraceOut);
|
706
700
|
}
|
data/ext/oj/dump_strict.c
CHANGED
@@ -92,7 +92,7 @@ static void dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
|
92
92
|
} else if (d == (double)(long long int)d) {
|
93
93
|
cnt = snprintf(buf, sizeof(buf), "%.1f", d);
|
94
94
|
} else if (0 == out->opts->float_prec) {
|
95
|
-
volatile VALUE rstr =
|
95
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
96
96
|
|
97
97
|
cnt = (int)RSTRING_LEN(rstr);
|
98
98
|
if ((int)sizeof(buf) <= cnt) {
|
@@ -290,7 +290,7 @@ static void dump_data_strict(VALUE obj, int depth, Out out, bool as_ok) {
|
|
290
290
|
VALUE clas = rb_obj_class(obj);
|
291
291
|
|
292
292
|
if (oj_bigdecimal_class == clas) {
|
293
|
-
volatile VALUE rstr =
|
293
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
294
294
|
|
295
295
|
oj_dump_raw(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), out);
|
296
296
|
} else {
|
@@ -302,7 +302,7 @@ static void dump_data_null(VALUE obj, int depth, Out out, bool as_ok) {
|
|
302
302
|
VALUE clas = rb_obj_class(obj);
|
303
303
|
|
304
304
|
if (oj_bigdecimal_class == clas) {
|
305
|
-
volatile VALUE rstr =
|
305
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
306
306
|
|
307
307
|
oj_dump_raw(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), out);
|
308
308
|
} else {
|
@@ -338,9 +338,7 @@ static DumpFunc strict_funcs[] = {
|
|
338
338
|
void oj_dump_strict_val(VALUE obj, int depth, Out out) {
|
339
339
|
int type = rb_type(obj);
|
340
340
|
|
341
|
-
|
342
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
|
343
|
-
}
|
341
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceIn);
|
344
342
|
if (MAX_DEPTH < depth) {
|
345
343
|
rb_raise(rb_eNoMemError, "Too deeply nested.\n");
|
346
344
|
}
|
@@ -349,9 +347,7 @@ void oj_dump_strict_val(VALUE obj, int depth, Out out) {
|
|
349
347
|
|
350
348
|
if (NULL != f) {
|
351
349
|
f(obj, depth, out, false);
|
352
|
-
|
353
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
|
354
|
-
}
|
350
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
|
355
351
|
return;
|
356
352
|
}
|
357
353
|
}
|
@@ -386,9 +382,7 @@ static DumpFunc null_funcs[] = {
|
|
386
382
|
void oj_dump_null_val(VALUE obj, int depth, Out out) {
|
387
383
|
int type = rb_type(obj);
|
388
384
|
|
389
|
-
|
390
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
|
391
|
-
}
|
385
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
|
392
386
|
if (MAX_DEPTH < depth) {
|
393
387
|
rb_raise(rb_eNoMemError, "Too deeply nested.\n");
|
394
388
|
}
|
@@ -397,14 +391,10 @@ void oj_dump_null_val(VALUE obj, int depth, Out out) {
|
|
397
391
|
|
398
392
|
if (NULL != f) {
|
399
393
|
f(obj, depth, out, false);
|
400
|
-
|
401
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
|
402
|
-
}
|
394
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
|
403
395
|
return;
|
404
396
|
}
|
405
397
|
}
|
406
398
|
oj_dump_nil(Qnil, depth, out, false);
|
407
|
-
|
408
|
-
oj_trace("dump", Qnil, __FILE__, __LINE__, depth, TraceOut);
|
409
|
-
}
|
399
|
+
TRACE(out->opts->trace, "dump", Qnil, depth, TraceOut);
|
410
400
|
}
|
data/ext/oj/extconf.rb
CHANGED
@@ -35,8 +35,16 @@ have_func('rb_hash_bulk_insert', 'ruby.h') unless '2' == version[0] && '6' == ve
|
|
35
35
|
dflags['OJ_DEBUG'] = true unless ENV['OJ_DEBUG'].nil?
|
36
36
|
|
37
37
|
if with_config('--with-sse42')
|
38
|
-
|
39
|
-
|
38
|
+
if try_cflags('-msse4.2')
|
39
|
+
$CPPFLAGS += ' -msse4.2'
|
40
|
+
dflags['OJ_USE_SSE4_2'] = 1
|
41
|
+
else
|
42
|
+
warn 'SSE 4.2 is not supported on this platform.'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
if enable_config('trace-log', false)
|
47
|
+
dflags['OJ_ENABLE_TRACE_LOG'] = 1
|
40
48
|
end
|
41
49
|
|
42
50
|
dflags.each do |k,v|
|