oj 3.13.23 → 3.16.10
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 +86 -0
- data/README.md +2 -2
- data/ext/oj/buf.h +7 -6
- data/ext/oj/cache.c +29 -26
- data/ext/oj/cache.h +3 -2
- data/ext/oj/cache8.c +10 -9
- data/ext/oj/circarray.c +7 -5
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +5 -12
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +20 -60
- data/ext/oj/custom.c +26 -59
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +103 -53
- data/ext/oj/dump.h +1 -4
- data/ext/oj/dump_compat.c +557 -592
- data/ext/oj/dump_leaf.c +3 -5
- data/ext/oj/dump_object.c +42 -48
- data/ext/oj/dump_strict.c +10 -22
- data/ext/oj/encoder.c +1 -1
- data/ext/oj/err.c +2 -13
- data/ext/oj/err.h +9 -12
- data/ext/oj/extconf.rb +16 -7
- data/ext/oj/fast.c +63 -98
- data/ext/oj/intern.c +62 -47
- data/ext/oj/intern.h +3 -7
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +54 -38
- data/ext/oj/object.c +33 -43
- data/ext/oj/odd.c +8 -6
- data/ext/oj/odd.h +4 -4
- data/ext/oj/oj.c +245 -216
- data/ext/oj/oj.h +83 -81
- data/ext/oj/parse.c +109 -153
- data/ext/oj/parse.h +21 -24
- data/ext/oj/parser.c +80 -67
- data/ext/oj/parser.h +9 -8
- data/ext/oj/rails.c +71 -94
- data/ext/oj/reader.c +9 -14
- data/ext/oj/reader.h +4 -2
- data/ext/oj/resolve.c +3 -4
- data/ext/oj/rxclass.c +6 -5
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +13 -15
- data/ext/oj/saj2.c +37 -49
- data/ext/oj/saj2.h +1 -1
- data/ext/oj/scp.c +6 -20
- data/ext/oj/sparse.c +22 -70
- data/ext/oj/stream_writer.c +46 -48
- data/ext/oj/strict.c +22 -56
- data/ext/oj/string_writer.c +64 -40
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +125 -114
- data/ext/oj/usual.h +7 -6
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +13 -2
- data/ext/oj/val_stack.h +8 -7
- data/ext/oj/wab.c +25 -57
- data/lib/oj/active_support_helper.rb +1 -3
- data/lib/oj/bag.rb +7 -1
- data/lib/oj/easy_hash.rb +4 -5
- data/lib/oj/error.rb +0 -1
- data/lib/oj/json.rb +162 -150
- data/lib/oj/mimic.rb +7 -7
- data/lib/oj/schandler.rb +5 -4
- data/lib/oj/state.rb +8 -5
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +2 -0
- data/pages/InstallOptions.md +20 -0
- data/pages/Options.md +4 -0
- metadata +46 -121
- data/test/_test_active.rb +0 -76
- data/test/_test_active_mimic.rb +0 -96
- data/test/_test_mimic_rails.rb +0 -126
- data/test/activerecord/result_test.rb +0 -32
- data/test/activesupport4/decoding_test.rb +0 -108
- data/test/activesupport4/encoding_test.rb +0 -531
- data/test/activesupport4/test_helper.rb +0 -41
- data/test/activesupport5/abstract_unit.rb +0 -45
- data/test/activesupport5/decoding_test.rb +0 -133
- data/test/activesupport5/encoding_test.rb +0 -500
- data/test/activesupport5/encoding_test_cases.rb +0 -98
- data/test/activesupport5/test_helper.rb +0 -72
- data/test/activesupport5/time_zone_test_helpers.rb +0 -39
- data/test/activesupport6/abstract_unit.rb +0 -44
- data/test/activesupport6/decoding_test.rb +0 -133
- data/test/activesupport6/encoding_test.rb +0 -507
- data/test/activesupport6/encoding_test_cases.rb +0 -98
- data/test/activesupport6/test_common.rb +0 -17
- data/test/activesupport6/test_helper.rb +0 -163
- data/test/activesupport6/time_zone_test_helpers.rb +0 -39
- data/test/activesupport7/abstract_unit.rb +0 -49
- data/test/activesupport7/decoding_test.rb +0 -125
- data/test/activesupport7/encoding_test.rb +0 -486
- data/test/activesupport7/encoding_test_cases.rb +0 -104
- data/test/activesupport7/time_zone_test_helpers.rb +0 -47
- data/test/bar.rb +0 -11
- data/test/baz.rb +0 -16
- data/test/bug.rb +0 -16
- data/test/files.rb +0 -29
- data/test/foo.rb +0 -77
- data/test/helper.rb +0 -42
- data/test/isolated/shared.rb +0 -308
- data/test/isolated/test_mimic_after.rb +0 -13
- data/test/isolated/test_mimic_alone.rb +0 -12
- data/test/isolated/test_mimic_as_json.rb +0 -45
- data/test/isolated/test_mimic_before.rb +0 -13
- data/test/isolated/test_mimic_define.rb +0 -28
- data/test/isolated/test_mimic_rails_after.rb +0 -22
- data/test/isolated/test_mimic_rails_before.rb +0 -21
- data/test/isolated/test_mimic_redefine.rb +0 -15
- data/test/json_gem/json_addition_test.rb +0 -216
- data/test/json_gem/json_common_interface_test.rb +0 -153
- data/test/json_gem/json_encoding_test.rb +0 -107
- data/test/json_gem/json_ext_parser_test.rb +0 -20
- data/test/json_gem/json_fixtures_test.rb +0 -35
- data/test/json_gem/json_generator_test.rb +0 -396
- data/test/json_gem/json_generic_object_test.rb +0 -90
- data/test/json_gem/json_parser_test.rb +0 -477
- data/test/json_gem/json_string_matching_test.rb +0 -42
- data/test/json_gem/test_helper.rb +0 -30
- data/test/mem.rb +0 -33
- data/test/perf.rb +0 -107
- data/test/perf_compat.rb +0 -130
- data/test/perf_dump.rb +0 -50
- data/test/perf_fast.rb +0 -164
- data/test/perf_file.rb +0 -64
- data/test/perf_object.rb +0 -138
- data/test/perf_once.rb +0 -58
- data/test/perf_parser.rb +0 -189
- data/test/perf_saj.rb +0 -109
- data/test/perf_scp.rb +0 -152
- data/test/perf_simple.rb +0 -287
- data/test/perf_strict.rb +0 -139
- data/test/perf_wab.rb +0 -131
- data/test/prec.rb +0 -23
- data/test/sample/change.rb +0 -14
- data/test/sample/dir.rb +0 -19
- data/test/sample/doc.rb +0 -36
- data/test/sample/file.rb +0 -48
- data/test/sample/group.rb +0 -16
- data/test/sample/hasprops.rb +0 -16
- data/test/sample/layer.rb +0 -12
- data/test/sample/line.rb +0 -20
- data/test/sample/oval.rb +0 -10
- data/test/sample/rect.rb +0 -10
- data/test/sample/shape.rb +0 -35
- data/test/sample/text.rb +0 -20
- data/test/sample.rb +0 -54
- data/test/sample_json.rb +0 -37
- data/test/test_compat.rb +0 -540
- data/test/test_custom.rb +0 -544
- data/test/test_debian.rb +0 -53
- data/test/test_fast.rb +0 -530
- data/test/test_file.rb +0 -255
- data/test/test_gc.rb +0 -60
- data/test/test_generate.rb +0 -21
- data/test/test_hash.rb +0 -39
- data/test/test_integer_range.rb +0 -72
- data/test/test_null.rb +0 -376
- data/test/test_object.rb +0 -1025
- data/test/test_parser.rb +0 -11
- data/test/test_parser_debug.rb +0 -27
- data/test/test_parser_saj.rb +0 -335
- data/test/test_parser_usual.rb +0 -217
- data/test/test_rails.rb +0 -35
- data/test/test_saj.rb +0 -186
- data/test/test_scp.rb +0 -431
- data/test/test_strict.rb +0 -435
- data/test/test_various.rb +0 -752
- data/test/test_wab.rb +0 -309
- data/test/test_writer.rb +0 -380
- data/test/tests.rb +0 -33
- data/test/tests_mimic.rb +0 -23
- data/test/tests_mimic_addition.rb +0 -16
- data/test/zoo.rb +0 -13
data/ext/oj/compat.c
CHANGED
@@ -6,38 +6,26 @@
|
|
6
6
|
#include "encode.h"
|
7
7
|
#include "err.h"
|
8
8
|
#include "intern.h"
|
9
|
+
#include "mem.h"
|
9
10
|
#include "oj.h"
|
10
11
|
#include "parse.h"
|
11
12
|
#include "resolve.h"
|
12
13
|
#include "trace.h"
|
13
14
|
|
14
15
|
static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
|
15
|
-
const char *
|
16
|
-
int
|
17
|
-
Val
|
18
|
-
volatile VALUE rkey = kval->key_val;
|
16
|
+
const char *key = kval->key;
|
17
|
+
int klen = kval->klen;
|
18
|
+
Val parent = stack_peek(&pi->stack);
|
19
19
|
|
20
|
-
if (Qundef ==
|
20
|
+
if (Qundef == kval->key_val && Yes == pi->options.create_ok && NULL != pi->options.create_id &&
|
21
21
|
*pi->options.create_id == *key && (int)pi->options.create_id_len == klen &&
|
22
22
|
0 == strncmp(pi->options.create_id, key, klen)) {
|
23
23
|
parent->classname = oj_strndup(str, len);
|
24
24
|
parent->clen = len;
|
25
25
|
} else {
|
26
26
|
volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
|
27
|
+
volatile VALUE rkey = oj_calc_hash_key(pi, kval);
|
27
28
|
|
28
|
-
if (Qundef == rkey) {
|
29
|
-
if (Yes != pi->options.cache_keys) {
|
30
|
-
if (Yes == pi->options.sym_key) {
|
31
|
-
rkey = ID2SYM(rb_intern3(key, klen, oj_utf8_encoding));
|
32
|
-
} else {
|
33
|
-
rkey = rb_utf8_str_new(key, klen);
|
34
|
-
}
|
35
|
-
} else if (Yes == pi->options.sym_key) {
|
36
|
-
rkey = oj_sym_intern(key, klen);
|
37
|
-
} else {
|
38
|
-
rkey = oj_str_intern(key, klen);
|
39
|
-
}
|
40
|
-
}
|
41
29
|
if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
|
42
30
|
VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
|
43
31
|
|
@@ -54,9 +42,7 @@ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, c
|
|
54
42
|
} else {
|
55
43
|
rb_hash_aset(parent->val, rkey, rstr);
|
56
44
|
}
|
57
|
-
|
58
|
-
oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rstr);
|
59
|
-
}
|
45
|
+
TRACE_PARSE_CALL(pi->options.trace, "set_string", pi, rstr);
|
60
46
|
}
|
61
47
|
}
|
62
48
|
|
@@ -68,9 +54,7 @@ static VALUE start_hash(ParseInfo pi) {
|
|
68
54
|
} else {
|
69
55
|
h = rb_hash_new();
|
70
56
|
}
|
71
|
-
|
72
|
-
oj_trace_parse_in("start_hash", pi, __FILE__, __LINE__);
|
73
|
-
}
|
57
|
+
TRACE_PARSE_IN(pi->options.trace, "start_hash", pi);
|
74
58
|
return h;
|
75
59
|
}
|
76
60
|
|
@@ -89,13 +73,11 @@ static void end_hash(struct _parseInfo *pi) {
|
|
89
73
|
}
|
90
74
|
}
|
91
75
|
if (0 != parent->classname) {
|
92
|
-
|
76
|
+
OJ_R_FREE((char *)parent->classname);
|
93
77
|
parent->classname = 0;
|
94
78
|
}
|
95
79
|
}
|
96
|
-
|
97
|
-
oj_trace_parse_hash_end(pi, __FILE__, __LINE__);
|
98
|
-
}
|
80
|
+
TRACE_PARSE_HASH_END(pi->options.trace, pi);
|
99
81
|
}
|
100
82
|
|
101
83
|
static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
@@ -110,37 +92,27 @@ static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig
|
|
110
92
|
}
|
111
93
|
}
|
112
94
|
pi->stack.head->val = rstr;
|
113
|
-
|
114
|
-
oj_trace_parse_call("add_string", pi, __FILE__, __LINE__, rstr);
|
115
|
-
}
|
95
|
+
TRACE_PARSE_CALL(pi->options.trace, "add_string", pi, rstr);
|
116
96
|
}
|
117
97
|
|
118
98
|
static void add_num(ParseInfo pi, NumInfo ni) {
|
119
99
|
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
|
-
}
|
100
|
+
TRACE_PARSE_CALL(pi->options.trace, "add_number", pi, pi->stack.head->val);
|
123
101
|
}
|
124
102
|
|
125
103
|
static void hash_set_num(struct _parseInfo *pi, Val parent, NumInfo ni) {
|
126
104
|
volatile VALUE rval = oj_num_as_value(ni);
|
127
105
|
|
128
|
-
if (
|
106
|
+
if (rb_cHash != rb_obj_class(parent->val)) {
|
129
107
|
// The rb_hash_set would still work but the unit tests for the
|
130
108
|
// json gem require the less efficient []= method be called to set
|
131
109
|
// values. Even using the store method to set the values will fail
|
132
110
|
// the unit tests.
|
133
|
-
rb_funcall(stack_peek(&pi->stack)->val,
|
134
|
-
rb_intern("[]="),
|
135
|
-
2,
|
136
|
-
oj_calc_hash_key(pi, parent),
|
137
|
-
rval);
|
111
|
+
rb_funcall(stack_peek(&pi->stack)->val, rb_intern("[]="), 2, oj_calc_hash_key(pi, parent), rval);
|
138
112
|
} else {
|
139
113
|
rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), rval);
|
140
114
|
}
|
141
|
-
|
142
|
-
oj_trace_parse_call("set_number", pi, __FILE__, __LINE__, rval);
|
143
|
-
}
|
115
|
+
TRACE_PARSE_CALL(pi->options.trace, "set_number", pi, rval);
|
144
116
|
}
|
145
117
|
|
146
118
|
static void hash_set_value(ParseInfo pi, Val parent, VALUE value) {
|
@@ -149,26 +121,18 @@ static void hash_set_value(ParseInfo pi, Val parent, VALUE value) {
|
|
149
121
|
// json gem require the less efficient []= method be called to set
|
150
122
|
// values. Even using the store method to set the values will fail
|
151
123
|
// the unit tests.
|
152
|
-
rb_funcall(stack_peek(&pi->stack)->val,
|
153
|
-
rb_intern("[]="),
|
154
|
-
2,
|
155
|
-
oj_calc_hash_key(pi, parent),
|
156
|
-
value);
|
124
|
+
rb_funcall(stack_peek(&pi->stack)->val, rb_intern("[]="), 2, oj_calc_hash_key(pi, parent), value);
|
157
125
|
} else {
|
158
126
|
rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), value);
|
159
127
|
}
|
160
|
-
|
161
|
-
oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, value);
|
162
|
-
}
|
128
|
+
TRACE_PARSE_CALL(pi->options.trace, "set_value", pi, value);
|
163
129
|
}
|
164
130
|
|
165
131
|
static VALUE start_array(ParseInfo pi) {
|
166
132
|
if (Qnil != pi->options.array_class) {
|
167
133
|
return rb_class_new_instance(0, NULL, pi->options.array_class);
|
168
134
|
}
|
169
|
-
|
170
|
-
oj_trace_parse_in("start_array", pi, __FILE__, __LINE__);
|
171
|
-
}
|
135
|
+
TRACE_PARSE_IN(pi->options.trace, "start_array", pi);
|
172
136
|
return rb_ary_new();
|
173
137
|
}
|
174
138
|
|
@@ -184,9 +148,7 @@ static void array_append_num(ParseInfo pi, NumInfo ni) {
|
|
184
148
|
} else {
|
185
149
|
rb_ary_push(parent->val, rval);
|
186
150
|
}
|
187
|
-
|
188
|
-
oj_trace_parse_call("append_number", pi, __FILE__, __LINE__, rval);
|
189
|
-
}
|
151
|
+
TRACE_PARSE_CALL(pi->options.trace, "append_number", pi, rval);
|
190
152
|
}
|
191
153
|
|
192
154
|
static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
@@ -201,9 +163,7 @@ static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const c
|
|
201
163
|
}
|
202
164
|
}
|
203
165
|
rb_ary_push(stack_peek(&pi->stack)->val, rstr);
|
204
|
-
|
205
|
-
oj_trace_parse_call("append_string", pi, __FILE__, __LINE__, rstr);
|
206
|
-
}
|
166
|
+
TRACE_PARSE_CALL(pi->options.trace, "append_string", pi, rstr);
|
207
167
|
}
|
208
168
|
|
209
169
|
void oj_set_compat_callbacks(ParseInfo pi) {
|
data/ext/oj/custom.c
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
#include "encode.h"
|
10
10
|
#include "err.h"
|
11
11
|
#include "intern.h"
|
12
|
+
#include "mem.h"
|
12
13
|
#include "odd.h"
|
13
14
|
#include "oj.h"
|
14
15
|
#include "parse.h"
|
@@ -24,20 +25,20 @@ static void dump_obj_str(VALUE obj, int depth, Out out) {
|
|
24
25
|
{"s", 1, Qnil},
|
25
26
|
{NULL, 0, Qnil},
|
26
27
|
};
|
27
|
-
attrs->value =
|
28
|
+
attrs->value = oj_safe_string_convert(obj);
|
28
29
|
|
29
30
|
oj_code_attrs(obj, attrs, depth, out, Yes == out->opts->create_ok);
|
30
31
|
}
|
31
32
|
|
32
33
|
static void dump_obj_as_str(VALUE obj, int depth, Out out) {
|
33
|
-
volatile VALUE rstr =
|
34
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
34
35
|
const char *str = RSTRING_PTR(rstr);
|
35
36
|
|
36
37
|
oj_dump_cstr(str, RSTRING_LEN(rstr), 0, 0, out);
|
37
38
|
}
|
38
39
|
|
39
40
|
static void bigdecimal_dump(VALUE obj, int depth, Out out) {
|
40
|
-
volatile VALUE rstr =
|
41
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
41
42
|
const char *str = RSTRING_PTR(rstr);
|
42
43
|
int len = (int)RSTRING_LEN(rstr);
|
43
44
|
|
@@ -305,7 +306,7 @@ static int hash_cb(VALUE key, VALUE value, VALUE ov) {
|
|
305
306
|
switch (rb_type(key)) {
|
306
307
|
case T_STRING: oj_dump_str(key, 0, out, false); break;
|
307
308
|
case T_SYMBOL: oj_dump_sym(key, 0, out, false); break;
|
308
|
-
default: oj_dump_str(
|
309
|
+
default: oj_dump_str(oj_safe_string_convert(key), 0, out, false); break;
|
309
310
|
}
|
310
311
|
if (!out->opts->dump_opts.use) {
|
311
312
|
*out->cur++ = ':';
|
@@ -437,7 +438,7 @@ static void dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
|
|
437
438
|
ID i;
|
438
439
|
|
439
440
|
if (sizeof(nbuf) <= nlen) {
|
440
|
-
if (NULL == (n2 =
|
441
|
+
if (NULL == (n2 = OJ_STRDUP(name))) {
|
441
442
|
rb_raise(rb_eNoMemError, "for attribute name.");
|
442
443
|
}
|
443
444
|
} else {
|
@@ -454,7 +455,7 @@ static void dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
|
|
454
455
|
i = rb_intern(n);
|
455
456
|
v = rb_funcall(v, i, 0);
|
456
457
|
if (nbuf != n2) {
|
457
|
-
|
458
|
+
OJ_FREE(n2);
|
458
459
|
}
|
459
460
|
}
|
460
461
|
fill_indent(out, d2);
|
@@ -479,17 +480,13 @@ static VALUE dump_common(VALUE obj, int depth, Out out) {
|
|
479
480
|
const char *s;
|
480
481
|
int len;
|
481
482
|
|
482
|
-
|
483
|
-
oj_trace("to_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyIn);
|
484
|
-
}
|
483
|
+
TRACE(out->opts->trace, "to_json", obj, depth + 1, TraceRubyIn);
|
485
484
|
if (0 == rb_obj_method_arity(obj, oj_to_json_id)) {
|
486
485
|
rs = rb_funcall(obj, oj_to_json_id, 0);
|
487
486
|
} else {
|
488
487
|
rs = rb_funcall2(obj, oj_to_json_id, out->argc, out->argv);
|
489
488
|
}
|
490
|
-
|
491
|
-
oj_trace("to_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyOut);
|
492
|
-
}
|
489
|
+
TRACE(out->opts->trace, "to_json", obj, depth + 1, TraceRubyOut);
|
493
490
|
s = RSTRING_PTR(rs);
|
494
491
|
len = (int)RSTRING_LEN(rs);
|
495
492
|
|
@@ -499,9 +496,7 @@ static VALUE dump_common(VALUE obj, int depth, Out out) {
|
|
499
496
|
} else if (Yes == out->opts->as_json && rb_respond_to(obj, oj_as_json_id)) {
|
500
497
|
volatile VALUE aj;
|
501
498
|
|
502
|
-
|
503
|
-
oj_trace("as_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyIn);
|
504
|
-
}
|
499
|
+
TRACE(out->opts->trace, "as_json", obj, depth + 1, TraceRubyIn);
|
505
500
|
// Some classes elect to not take an options argument so check the arity
|
506
501
|
// of as_json.
|
507
502
|
if (0 == rb_obj_method_arity(obj, oj_as_json_id)) {
|
@@ -509,12 +504,10 @@ static VALUE dump_common(VALUE obj, int depth, Out out) {
|
|
509
504
|
} else {
|
510
505
|
aj = rb_funcall2(obj, oj_as_json_id, out->argc, out->argv);
|
511
506
|
}
|
512
|
-
|
513
|
-
oj_trace("as_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyOut);
|
514
|
-
}
|
507
|
+
TRACE(out->opts->trace, "as_json", obj, depth + 1, TraceRubyOut);
|
515
508
|
// Catch the obvious brain damaged recursive dumping.
|
516
509
|
if (aj == obj) {
|
517
|
-
volatile VALUE rstr =
|
510
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
518
511
|
|
519
512
|
oj_dump_cstr(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), false, false, out);
|
520
513
|
} else {
|
@@ -876,9 +869,7 @@ static DumpFunc custom_funcs[] = {
|
|
876
869
|
void oj_dump_custom_val(VALUE obj, int depth, Out out, bool as_ok) {
|
877
870
|
int type = rb_type(obj);
|
878
871
|
|
879
|
-
|
880
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
|
881
|
-
}
|
872
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceIn);
|
882
873
|
if (MAX_DEPTH < depth) {
|
883
874
|
rb_raise(rb_eNoMemError, "Too deeply nested.\n");
|
884
875
|
}
|
@@ -887,27 +878,22 @@ void oj_dump_custom_val(VALUE obj, int depth, Out out, bool as_ok) {
|
|
887
878
|
|
888
879
|
if (NULL != f) {
|
889
880
|
f(obj, depth, out, true);
|
890
|
-
|
891
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
|
892
|
-
}
|
881
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
|
893
882
|
return;
|
894
883
|
}
|
895
884
|
}
|
896
885
|
oj_dump_nil(Qnil, depth, out, false);
|
897
|
-
|
898
|
-
oj_trace("dump", Qnil, __FILE__, __LINE__, depth, TraceOut);
|
899
|
-
}
|
886
|
+
TRACE(out->opts->trace, "dump", Qnil, depth, TraceOut);
|
900
887
|
}
|
901
888
|
|
902
889
|
///// load functions /////
|
903
890
|
|
904
891
|
static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
|
905
|
-
const char
|
906
|
-
int
|
907
|
-
Val
|
908
|
-
volatile VALUE rkey = kval->key_val;
|
892
|
+
const char *key = kval->key;
|
893
|
+
int klen = kval->klen;
|
894
|
+
Val parent = stack_peek(&pi->stack);
|
909
895
|
|
910
|
-
if (Qundef ==
|
896
|
+
if (Qundef == kval->key_val && Yes == pi->options.create_ok && NULL != pi->options.create_id &&
|
911
897
|
*pi->options.create_id == *key && (int)pi->options.create_id_len == klen &&
|
912
898
|
0 == strncmp(pi->options.create_id, key, klen)) {
|
913
899
|
parent->clas = oj_name2class(pi, str, len, false, rb_eArgError);
|
@@ -920,15 +906,8 @@ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, c
|
|
920
906
|
}
|
921
907
|
} else {
|
922
908
|
volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
|
923
|
-
|
909
|
+
volatile VALUE rkey = oj_calc_hash_key(pi, kval);
|
924
910
|
|
925
|
-
if (Qundef == rkey) {
|
926
|
-
if (Yes == pi->options.sym_key) {
|
927
|
-
rkey = ID2SYM(rb_intern3(key, klen, oj_utf8_encoding));
|
928
|
-
} else {
|
929
|
-
rkey = rb_utf8_str_new(key, klen);
|
930
|
-
}
|
931
|
-
}
|
932
911
|
if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
|
933
912
|
VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
|
934
913
|
|
@@ -950,9 +929,7 @@ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, c
|
|
950
929
|
break;
|
951
930
|
default: break;
|
952
931
|
}
|
953
|
-
|
954
|
-
oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rstr);
|
955
|
-
}
|
932
|
+
TRACE_PARSE_CALL(pi->options.trace, "set_string", pi, rstr);
|
956
933
|
}
|
957
934
|
}
|
958
935
|
|
@@ -969,9 +946,7 @@ static void end_hash(struct _parseInfo *pi) {
|
|
969
946
|
}
|
970
947
|
parent->clas = Qundef;
|
971
948
|
}
|
972
|
-
|
973
|
-
oj_trace_parse_hash_end(pi, __FILE__, __LINE__);
|
974
|
-
}
|
949
|
+
TRACE_PARSE_HASH_END(pi->options.trace, pi);
|
975
950
|
}
|
976
951
|
|
977
952
|
static void hash_set_num(struct _parseInfo *pi, Val kval, NumInfo ni) {
|
@@ -1013,9 +988,7 @@ static void hash_set_num(struct _parseInfo *pi, Val kval, NumInfo ni) {
|
|
1013
988
|
break;
|
1014
989
|
default: break;
|
1015
990
|
}
|
1016
|
-
|
1017
|
-
oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rval);
|
1018
|
-
}
|
991
|
+
TRACE_PARSE_CALL(pi->options.trace, "set_string", pi, rval);
|
1019
992
|
}
|
1020
993
|
|
1021
994
|
static void hash_set_value(ParseInfo pi, Val kval, VALUE value) {
|
@@ -1026,9 +999,7 @@ static void hash_set_value(ParseInfo pi, Val kval, VALUE value) {
|
|
1026
999
|
case T_HASH: rb_hash_aset(parent->val, oj_calc_hash_key(pi, kval), value); break;
|
1027
1000
|
default: break;
|
1028
1001
|
}
|
1029
|
-
|
1030
|
-
oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, value);
|
1031
|
-
}
|
1002
|
+
TRACE_PARSE_CALL(pi->options.trace, "set_value", pi, value);
|
1032
1003
|
}
|
1033
1004
|
|
1034
1005
|
static void array_append_num(ParseInfo pi, NumInfo ni) {
|
@@ -1036,9 +1007,7 @@ static void array_append_num(ParseInfo pi, NumInfo ni) {
|
|
1036
1007
|
volatile VALUE rval = oj_num_as_value(ni);
|
1037
1008
|
|
1038
1009
|
rb_ary_push(parent->val, rval);
|
1039
|
-
|
1040
|
-
oj_trace_parse_call("append_number", pi, __FILE__, __LINE__, rval);
|
1041
|
-
}
|
1010
|
+
TRACE_PARSE_CALL(pi->options.trace, "append_number", pi, rval);
|
1042
1011
|
}
|
1043
1012
|
|
1044
1013
|
static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
@@ -1053,9 +1022,7 @@ static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const c
|
|
1053
1022
|
}
|
1054
1023
|
}
|
1055
1024
|
rb_ary_push(stack_peek(&pi->stack)->val, rstr);
|
1056
|
-
|
1057
|
-
oj_trace_parse_call("append_string", pi, __FILE__, __LINE__, rstr);
|
1058
|
-
}
|
1025
|
+
TRACE_PARSE_CALL(pi->options.trace, "append_string", pi, rstr);
|
1059
1026
|
}
|
1060
1027
|
|
1061
1028
|
void oj_set_custom_callbacks(ParseInfo pi) {
|
data/ext/oj/debug.c
CHANGED
@@ -30,9 +30,7 @@ static void add_int(struct _ojParser *p) {
|
|
30
30
|
switch (p->stack[p->depth]) {
|
31
31
|
case TOP_FUN: printf("*** add_int %lld at top\n", (long long)p->num.fixnum); break;
|
32
32
|
case ARRAY_FUN: printf("*** add_int %lld to array\n", (long long)p->num.fixnum); break;
|
33
|
-
case OBJECT_FUN:
|
34
|
-
printf("*** add_int %lld with '%s'\n", (long long)p->num.fixnum, buf_str(&p->key));
|
35
|
-
break;
|
33
|
+
case OBJECT_FUN: printf("*** add_int %lld with '%s'\n", (long long)p->num.fixnum, buf_str(&p->key)); break;
|
36
34
|
}
|
37
35
|
}
|
38
36
|
|
@@ -48,9 +46,7 @@ static void add_big(struct _ojParser *p) {
|
|
48
46
|
switch (p->stack[p->depth]) {
|
49
47
|
case TOP_FUN: printf("*** add_big %s at top\n", buf_str(&p->buf)); break;
|
50
48
|
case ARRAY_FUN: printf("*** add_big %s to array\n", buf_str(&p->buf)); break;
|
51
|
-
case OBJECT_FUN:
|
52
|
-
printf("*** add_big %s with '%s'\n", buf_str(&p->buf), buf_str(&p->key));
|
53
|
-
break;
|
49
|
+
case OBJECT_FUN: printf("*** add_big %s with '%s'\n", buf_str(&p->buf), buf_str(&p->key)); break;
|
54
50
|
}
|
55
51
|
}
|
56
52
|
|
@@ -58,9 +54,7 @@ static void add_str(struct _ojParser *p) {
|
|
58
54
|
switch (p->stack[p->depth]) {
|
59
55
|
case TOP_FUN: printf("*** add_str '%s' at top\n", buf_str(&p->buf)); break;
|
60
56
|
case ARRAY_FUN: printf("*** add_str '%s' to array\n", buf_str(&p->buf)); break;
|
61
|
-
case OBJECT_FUN:
|
62
|
-
printf("*** add_str '%s' with '%s'\n", buf_str(&p->buf), buf_str(&p->key));
|
63
|
-
break;
|
57
|
+
case OBJECT_FUN: printf("*** add_str '%s' with '%s'\n", buf_str(&p->buf), buf_str(&p->key)); break;
|
64
58
|
}
|
65
59
|
}
|
66
60
|
|