oj 3.11.0 → 3.16.5
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 +1421 -0
- data/README.md +20 -5
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +48 -38
- data/ext/oj/cache.c +329 -0
- data/ext/oj/cache.h +22 -0
- data/ext/oj/cache8.c +60 -62
- data/ext/oj/cache8.h +8 -7
- data/ext/oj/circarray.c +35 -35
- data/ext/oj/circarray.h +11 -9
- data/ext/oj/code.c +156 -174
- data/ext/oj/code.h +19 -18
- data/ext/oj/compat.c +140 -197
- data/ext/oj/custom.c +737 -879
- data/ext/oj/debug.c +126 -0
- data/ext/oj/dump.c +830 -835
- data/ext/oj/dump.h +65 -53
- data/ext/oj/dump_compat.c +566 -642
- data/ext/oj/dump_leaf.c +95 -182
- data/ext/oj/dump_object.c +518 -659
- data/ext/oj/dump_strict.c +301 -334
- data/ext/oj/encode.h +3 -4
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +27 -24
- data/ext/oj/err.h +38 -13
- data/ext/oj/extconf.rb +23 -7
- data/ext/oj/fast.c +1043 -1073
- data/ext/oj/intern.c +313 -0
- data/ext/oj/intern.h +22 -0
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +449 -423
- data/ext/oj/object.c +530 -576
- data/ext/oj/odd.c +155 -138
- data/ext/oj/odd.h +24 -22
- data/ext/oj/oj.c +1331 -993
- data/ext/oj/oj.h +306 -292
- data/ext/oj/parse.c +934 -938
- data/ext/oj/parse.h +73 -70
- data/ext/oj/parser.c +1600 -0
- data/ext/oj/parser.h +101 -0
- data/ext/oj/rails.c +795 -845
- data/ext/oj/rails.h +7 -7
- data/ext/oj/reader.c +132 -140
- data/ext/oj/reader.h +67 -78
- data/ext/oj/resolve.c +40 -59
- data/ext/oj/resolve.h +3 -2
- data/ext/oj/rxclass.c +67 -67
- data/ext/oj/rxclass.h +11 -9
- data/ext/oj/saj.c +441 -480
- data/ext/oj/saj2.c +584 -0
- data/ext/oj/saj2.h +23 -0
- data/ext/oj/scp.c +78 -111
- data/ext/oj/sparse.c +726 -730
- data/ext/oj/stream_writer.c +146 -165
- data/ext/oj/strict.c +103 -123
- data/ext/oj/string_writer.c +241 -253
- data/ext/oj/trace.c +29 -33
- data/ext/oj/trace.h +41 -11
- data/ext/oj/usual.c +1218 -0
- data/ext/oj/usual.h +69 -0
- data/ext/oj/util.c +103 -103
- data/ext/oj/util.h +3 -2
- data/ext/oj/val_stack.c +60 -49
- data/ext/oj/val_stack.h +79 -85
- data/ext/oj/validate.c +46 -0
- data/ext/oj/wab.c +307 -350
- data/lib/oj/active_support_helper.rb +1 -3
- data/lib/oj/bag.rb +8 -1
- data/lib/oj/easy_hash.rb +9 -9
- data/lib/oj/error.rb +1 -2
- data/lib/oj/json.rb +162 -150
- data/lib/oj/mimic.rb +9 -19
- data/lib/oj/saj.rb +20 -6
- data/lib/oj/schandler.rb +5 -4
- data/lib/oj/state.rb +12 -8
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +2 -0
- data/pages/Compatibility.md +1 -1
- data/pages/InstallOptions.md +20 -0
- data/pages/JsonGem.md +15 -0
- data/pages/Modes.md +8 -3
- data/pages/Options.md +43 -5
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +14 -2
- data/test/_test_active.rb +8 -9
- data/test/_test_active_mimic.rb +7 -8
- data/test/_test_mimic_rails.rb +17 -20
- data/test/activerecord/result_test.rb +12 -8
- data/test/activesupport6/encoding_test.rb +63 -28
- data/test/{activesupport5 → activesupport7}/abstract_unit.rb +16 -12
- data/test/{activesupport5 → activesupport7}/decoding_test.rb +2 -10
- data/test/{activesupport5 → activesupport7}/encoding_test.rb +86 -50
- data/test/{activesupport5 → activesupport7}/encoding_test_cases.rb +6 -0
- data/test/{activesupport5 → activesupport7}/time_zone_test_helpers.rb +8 -0
- data/test/files.rb +15 -15
- data/test/foo.rb +17 -43
- data/test/helper.rb +16 -3
- data/test/isolated/shared.rb +3 -2
- data/test/json_gem/json_addition_test.rb +2 -2
- data/test/json_gem/json_common_interface_test.rb +8 -6
- data/test/json_gem/json_encoding_test.rb +0 -0
- data/test/json_gem/json_ext_parser_test.rb +1 -0
- data/test/json_gem/json_fixtures_test.rb +3 -2
- data/test/json_gem/json_generator_test.rb +71 -41
- data/test/json_gem/json_generic_object_test.rb +11 -11
- data/test/json_gem/json_parser_test.rb +54 -47
- data/test/json_gem/json_string_matching_test.rb +9 -9
- data/test/json_gem/test_helper.rb +12 -0
- data/test/mem.rb +34 -0
- data/test/perf.rb +22 -27
- data/test/perf_compat.rb +31 -33
- data/test/perf_dump.rb +50 -0
- data/test/perf_fast.rb +80 -82
- data/test/perf_file.rb +27 -29
- data/test/perf_object.rb +65 -69
- data/test/perf_once.rb +59 -0
- data/test/perf_parser.rb +183 -0
- data/test/perf_saj.rb +46 -54
- data/test/perf_scp.rb +58 -69
- data/test/perf_simple.rb +41 -39
- data/test/perf_strict.rb +74 -82
- data/test/perf_wab.rb +67 -69
- data/test/prec.rb +5 -5
- data/test/sample/change.rb +0 -1
- data/test/sample/dir.rb +0 -1
- data/test/sample/doc.rb +0 -1
- data/test/sample/file.rb +0 -1
- data/test/sample/group.rb +0 -1
- data/test/sample/hasprops.rb +0 -1
- data/test/sample/layer.rb +0 -1
- data/test/sample/rect.rb +0 -1
- data/test/sample/shape.rb +0 -1
- data/test/sample/text.rb +0 -1
- data/test/sample.rb +16 -16
- data/test/sample_json.rb +8 -8
- data/test/test_compat.rb +97 -45
- data/test/test_custom.rb +73 -51
- data/test/test_debian.rb +7 -10
- data/test/test_fast.rb +135 -79
- data/test/test_file.rb +41 -30
- data/test/test_gc.rb +16 -5
- data/test/test_generate.rb +21 -0
- data/test/test_hash.rb +15 -5
- data/test/test_integer_range.rb +9 -9
- data/test/test_null.rb +20 -20
- data/test/test_object.rb +99 -96
- data/test/test_parser.rb +11 -0
- data/test/test_parser_debug.rb +27 -0
- data/test/test_parser_saj.rb +337 -0
- data/test/test_parser_usual.rb +251 -0
- data/test/test_rails.rb +2 -2
- data/test/test_saj.rb +10 -8
- data/test/test_scp.rb +38 -40
- data/test/test_strict.rb +40 -32
- data/test/test_various.rb +165 -84
- data/test/test_wab.rb +48 -44
- data/test/test_writer.rb +47 -47
- data/test/tests.rb +13 -5
- data/test/tests_mimic.rb +12 -3
- data/test/tests_mimic_addition.rb +12 -3
- metadata +75 -127
- data/ext/oj/hash.c +0 -135
- data/ext/oj/hash.h +0 -18
- data/ext/oj/hash_test.c +0 -484
- 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/test_helper.rb +0 -72
- data/test/bar.rb +0 -35
- data/test/baz.rb +0 -16
- data/test/zoo.rb +0 -13
data/ext/oj/scp.c
CHANGED
@@ -1,221 +1,188 @@
|
|
1
1
|
// Copyright (c) 2012 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
2
3
|
|
3
|
-
#include <
|
4
|
+
#include <math.h>
|
4
5
|
#include <stdio.h>
|
6
|
+
#include <stdlib.h>
|
5
7
|
#include <string.h>
|
6
|
-
#include <math.h>
|
7
8
|
#include <sys/types.h>
|
8
9
|
#include <unistd.h>
|
9
10
|
|
11
|
+
#include "encode.h"
|
12
|
+
#include "intern.h"
|
10
13
|
#include "oj.h"
|
11
14
|
#include "parse.h"
|
12
|
-
#include "encode.h"
|
13
15
|
|
14
|
-
static VALUE
|
15
|
-
noop_start(ParseInfo pi) {
|
16
|
+
static VALUE noop_start(ParseInfo pi) {
|
16
17
|
return Qnil;
|
17
18
|
}
|
18
19
|
|
19
|
-
static void
|
20
|
-
noop_end(ParseInfo pi) {
|
20
|
+
static void noop_end(ParseInfo pi) {
|
21
21
|
}
|
22
22
|
|
23
|
-
static void
|
24
|
-
noop_add_value(ParseInfo pi, VALUE val) {
|
23
|
+
static void noop_add_value(ParseInfo pi, VALUE val) {
|
25
24
|
}
|
26
25
|
|
27
|
-
static void
|
28
|
-
noop_add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
26
|
+
static void noop_add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
29
27
|
}
|
30
28
|
|
31
|
-
static void
|
32
|
-
noop_add_num(ParseInfo pi, NumInfo ni) {
|
29
|
+
static void noop_add_num(ParseInfo pi, NumInfo ni) {
|
33
30
|
}
|
34
31
|
|
35
|
-
static VALUE
|
36
|
-
noop_hash_key(ParseInfo pi, const char *key, size_t klen) {
|
32
|
+
static VALUE noop_hash_key(ParseInfo pi, const char *key, size_t klen) {
|
37
33
|
return Qundef;
|
38
34
|
}
|
39
35
|
|
40
|
-
static void
|
41
|
-
noop_hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
|
36
|
+
static void noop_hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
|
42
37
|
}
|
43
38
|
|
44
|
-
static void
|
45
|
-
noop_hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
|
39
|
+
static void noop_hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
|
46
40
|
}
|
47
41
|
|
48
|
-
static void
|
49
|
-
noop_hash_set_value(ParseInfo pi, Val kval, VALUE value) {
|
42
|
+
static void noop_hash_set_value(ParseInfo pi, Val kval, VALUE value) {
|
50
43
|
}
|
51
44
|
|
52
|
-
static void
|
53
|
-
noop_array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
45
|
+
static void noop_array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
54
46
|
}
|
55
47
|
|
56
|
-
static void
|
57
|
-
noop_array_append_num(ParseInfo pi, NumInfo ni) {
|
48
|
+
static void noop_array_append_num(ParseInfo pi, NumInfo ni) {
|
58
49
|
}
|
59
50
|
|
60
|
-
static void
|
61
|
-
noop_array_append_value(ParseInfo pi, VALUE value) {
|
51
|
+
static void noop_array_append_value(ParseInfo pi, VALUE value) {
|
62
52
|
}
|
63
53
|
|
64
|
-
static void
|
65
|
-
add_value(ParseInfo pi, VALUE val) {
|
54
|
+
static void add_value(ParseInfo pi, VALUE val) {
|
66
55
|
rb_funcall(pi->handler, oj_add_value_id, 1, val);
|
67
56
|
}
|
68
57
|
|
69
|
-
static void
|
70
|
-
|
71
|
-
volatile VALUE rstr = rb_str_new(str, len);
|
58
|
+
static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
59
|
+
volatile VALUE rstr = rb_str_new(str, len);
|
72
60
|
|
73
61
|
rstr = oj_encode(rstr);
|
74
62
|
rb_funcall(pi->handler, oj_add_value_id, 1, rstr);
|
75
63
|
}
|
76
64
|
|
77
|
-
static void
|
78
|
-
add_num(ParseInfo pi, NumInfo ni) {
|
65
|
+
static void add_num(ParseInfo pi, NumInfo ni) {
|
79
66
|
rb_funcall(pi->handler, oj_add_value_id, 1, oj_num_as_value(ni));
|
80
67
|
}
|
81
68
|
|
82
|
-
static VALUE
|
83
|
-
start_hash(ParseInfo pi) {
|
69
|
+
static VALUE start_hash(ParseInfo pi) {
|
84
70
|
return rb_funcall(pi->handler, oj_hash_start_id, 0);
|
85
71
|
}
|
86
72
|
|
87
|
-
static void
|
88
|
-
end_hash(ParseInfo pi) {
|
73
|
+
static void end_hash(ParseInfo pi) {
|
89
74
|
rb_funcall(pi->handler, oj_hash_end_id, 0);
|
90
75
|
}
|
91
76
|
|
92
|
-
static VALUE
|
93
|
-
start_array(ParseInfo pi) {
|
77
|
+
static VALUE start_array(ParseInfo pi) {
|
94
78
|
return rb_funcall(pi->handler, oj_array_start_id, 0);
|
95
79
|
}
|
96
80
|
|
97
|
-
static void
|
98
|
-
end_array(ParseInfo pi) {
|
81
|
+
static void end_array(ParseInfo pi) {
|
99
82
|
rb_funcall(pi->handler, oj_array_end_id, 0);
|
100
83
|
}
|
101
84
|
|
102
|
-
static VALUE
|
103
|
-
calc_hash_key(ParseInfo pi, Val kval) {
|
104
|
-
volatile VALUE rkey = kval->key_val;
|
105
|
-
|
106
|
-
if (Qundef == rkey) {
|
107
|
-
rkey = rb_str_new(kval->key, kval->klen);
|
108
|
-
rkey = oj_encode(rkey);
|
109
|
-
if (Yes == pi->options.sym_key) {
|
110
|
-
rkey = rb_str_intern(rkey);
|
111
|
-
}
|
112
|
-
}
|
113
|
-
return rkey;
|
114
|
-
}
|
115
|
-
|
116
|
-
static VALUE
|
117
|
-
hash_key(ParseInfo pi, const char *key, size_t klen) {
|
85
|
+
static VALUE hash_key(ParseInfo pi, const char *key, size_t klen) {
|
118
86
|
return rb_funcall(pi->handler, oj_hash_key_id, 1, rb_str_new(key, klen));
|
119
87
|
}
|
120
88
|
|
121
|
-
static void
|
122
|
-
|
123
|
-
volatile VALUE rstr = rb_str_new(str, len);
|
89
|
+
static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
|
90
|
+
volatile VALUE rstr = rb_str_new(str, len);
|
124
91
|
|
125
92
|
rstr = oj_encode(rstr);
|
126
|
-
rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val,
|
93
|
+
rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, kval), rstr);
|
127
94
|
}
|
128
95
|
|
129
|
-
static void
|
130
|
-
|
131
|
-
|
96
|
+
static void hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
|
97
|
+
rb_funcall(pi->handler,
|
98
|
+
oj_hash_set_id,
|
99
|
+
3,
|
100
|
+
stack_peek(&pi->stack)->val,
|
101
|
+
oj_calc_hash_key(pi, kval),
|
102
|
+
oj_num_as_value(ni));
|
132
103
|
}
|
133
104
|
|
134
|
-
static void
|
135
|
-
|
136
|
-
rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, calc_hash_key(pi, kval), value);
|
105
|
+
static void hash_set_value(ParseInfo pi, Val kval, VALUE value) {
|
106
|
+
rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, kval), value);
|
137
107
|
}
|
138
108
|
|
139
|
-
static void
|
140
|
-
|
141
|
-
volatile VALUE rstr = rb_str_new(str, len);
|
109
|
+
static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
110
|
+
volatile VALUE rstr = rb_str_new(str, len);
|
142
111
|
|
143
112
|
rstr = oj_encode(rstr);
|
144
113
|
rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, rstr);
|
145
114
|
}
|
146
115
|
|
147
|
-
static void
|
148
|
-
array_append_num(ParseInfo pi, NumInfo ni) {
|
116
|
+
static void array_append_num(ParseInfo pi, NumInfo ni) {
|
149
117
|
rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, oj_num_as_value(ni));
|
150
118
|
}
|
151
119
|
|
152
|
-
static void
|
153
|
-
array_append_value(ParseInfo pi, VALUE value) {
|
120
|
+
static void array_append_value(ParseInfo pi, VALUE value) {
|
154
121
|
rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, value);
|
155
122
|
}
|
156
123
|
|
157
124
|
VALUE
|
158
125
|
oj_sc_parse(int argc, VALUE *argv, VALUE self) {
|
159
|
-
struct _parseInfo
|
160
|
-
VALUE
|
126
|
+
struct _parseInfo pi;
|
127
|
+
VALUE input = argv[1];
|
161
128
|
|
162
129
|
parse_info_init(&pi);
|
163
130
|
pi.err_class = Qnil;
|
164
131
|
pi.max_depth = 0;
|
165
|
-
pi.options
|
132
|
+
pi.options = oj_default_options;
|
166
133
|
if (3 == argc) {
|
167
|
-
|
134
|
+
oj_parse_options(argv[2], &pi.options);
|
168
135
|
}
|
169
136
|
if (rb_block_given_p()) {
|
170
|
-
|
137
|
+
pi.proc = Qnil;
|
171
138
|
} else {
|
172
|
-
|
139
|
+
pi.proc = Qundef;
|
173
140
|
}
|
174
141
|
pi.handler = *argv;
|
175
142
|
|
176
|
-
pi.start_hash
|
177
|
-
pi.end_hash
|
178
|
-
pi.hash_key
|
143
|
+
pi.start_hash = rb_respond_to(pi.handler, oj_hash_start_id) ? start_hash : noop_start;
|
144
|
+
pi.end_hash = rb_respond_to(pi.handler, oj_hash_end_id) ? end_hash : noop_end;
|
145
|
+
pi.hash_key = rb_respond_to(pi.handler, oj_hash_key_id) ? hash_key : noop_hash_key;
|
179
146
|
pi.start_array = rb_respond_to(pi.handler, oj_array_start_id) ? start_array : noop_start;
|
180
|
-
pi.end_array
|
147
|
+
pi.end_array = rb_respond_to(pi.handler, oj_array_end_id) ? end_array : noop_end;
|
181
148
|
if (rb_respond_to(pi.handler, oj_hash_set_id)) {
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
149
|
+
pi.hash_set_value = hash_set_value;
|
150
|
+
pi.hash_set_cstr = hash_set_cstr;
|
151
|
+
pi.hash_set_num = hash_set_num;
|
152
|
+
pi.expect_value = 1;
|
186
153
|
} else {
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
154
|
+
pi.hash_set_value = noop_hash_set_value;
|
155
|
+
pi.hash_set_cstr = noop_hash_set_cstr;
|
156
|
+
pi.hash_set_num = noop_hash_set_num;
|
157
|
+
pi.expect_value = 0;
|
191
158
|
}
|
192
159
|
if (rb_respond_to(pi.handler, oj_array_append_id)) {
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
160
|
+
pi.array_append_value = array_append_value;
|
161
|
+
pi.array_append_cstr = array_append_cstr;
|
162
|
+
pi.array_append_num = array_append_num;
|
163
|
+
pi.expect_value = 1;
|
197
164
|
} else {
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
165
|
+
pi.array_append_value = noop_array_append_value;
|
166
|
+
pi.array_append_cstr = noop_array_append_cstr;
|
167
|
+
pi.array_append_num = noop_array_append_num;
|
168
|
+
pi.expect_value = 0;
|
202
169
|
}
|
203
170
|
if (rb_respond_to(pi.handler, oj_add_value_id)) {
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
171
|
+
pi.add_cstr = add_cstr;
|
172
|
+
pi.add_num = add_num;
|
173
|
+
pi.add_value = add_value;
|
174
|
+
pi.expect_value = 1;
|
208
175
|
} else {
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
176
|
+
pi.add_cstr = noop_add_cstr;
|
177
|
+
pi.add_num = noop_add_num;
|
178
|
+
pi.add_value = noop_add_value;
|
179
|
+
pi.expect_value = 0;
|
213
180
|
}
|
214
181
|
pi.has_callbacks = true;
|
215
182
|
|
216
183
|
if (T_STRING == rb_type(input)) {
|
217
|
-
|
184
|
+
return oj_pi_parse(argc - 1, argv + 1, &pi, 0, 0, 1);
|
218
185
|
} else {
|
219
|
-
|
186
|
+
return oj_pi_sparse(argc - 1, argv + 1, &pi, 0);
|
220
187
|
}
|
221
188
|
}
|