oj 3.7.4 → 3.13.21
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 +1352 -0
- data/README.md +29 -8
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +53 -72
- data/ext/oj/cache.c +326 -0
- data/ext/oj/cache.h +21 -0
- data/ext/oj/cache8.c +61 -64
- data/ext/oj/cache8.h +12 -39
- data/ext/oj/circarray.c +37 -43
- data/ext/oj/circarray.h +16 -17
- data/ext/oj/code.c +165 -179
- data/ext/oj/code.h +27 -29
- data/ext/oj/compat.c +174 -194
- data/ext/oj/custom.c +809 -866
- data/ext/oj/debug.c +132 -0
- data/ext/oj/dump.c +848 -863
- data/ext/oj/dump.h +81 -67
- data/ext/oj/dump_compat.c +85 -123
- data/ext/oj/dump_leaf.c +100 -188
- data/ext/oj/dump_object.c +527 -656
- data/ext/oj/dump_strict.c +315 -338
- data/ext/oj/encode.h +7 -34
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +40 -29
- data/ext/oj/err.h +48 -48
- data/ext/oj/extconf.rb +17 -4
- data/ext/oj/fast.c +1070 -1087
- data/ext/oj/intern.c +301 -0
- data/ext/oj/intern.h +26 -0
- data/ext/oj/mimic_json.c +469 -436
- data/ext/oj/object.c +525 -593
- data/ext/oj/odd.c +154 -138
- data/ext/oj/odd.h +37 -38
- data/ext/oj/oj.c +1325 -986
- data/ext/oj/oj.h +333 -316
- data/ext/oj/parse.c +1002 -846
- data/ext/oj/parse.h +92 -87
- data/ext/oj/parser.c +1557 -0
- data/ext/oj/parser.h +91 -0
- data/ext/oj/rails.c +888 -878
- data/ext/oj/rails.h +11 -14
- data/ext/oj/reader.c +141 -147
- data/ext/oj/reader.h +73 -89
- data/ext/oj/resolve.c +41 -62
- data/ext/oj/resolve.h +7 -9
- data/ext/oj/rxclass.c +71 -75
- data/ext/oj/rxclass.h +18 -19
- data/ext/oj/saj.c +443 -486
- data/ext/oj/saj2.c +602 -0
- data/ext/oj/scp.c +88 -113
- data/ext/oj/sparse.c +787 -709
- data/ext/oj/stream_writer.c +133 -159
- data/ext/oj/strict.c +127 -118
- data/ext/oj/string_writer.c +230 -249
- data/ext/oj/trace.c +34 -41
- data/ext/oj/trace.h +19 -19
- data/ext/oj/usual.c +1254 -0
- data/ext/oj/util.c +136 -0
- data/ext/oj/util.h +20 -0
- data/ext/oj/val_stack.c +59 -67
- data/ext/oj/val_stack.h +91 -129
- data/ext/oj/validate.c +46 -0
- data/ext/oj/wab.c +342 -353
- data/lib/oj/bag.rb +1 -0
- data/lib/oj/easy_hash.rb +5 -4
- data/lib/oj/error.rb +1 -1
- data/lib/oj/json.rb +1 -1
- data/lib/oj/mimic.rb +48 -14
- data/lib/oj/saj.rb +20 -6
- data/lib/oj/state.rb +8 -7
- data/lib/oj/version.rb +2 -2
- data/lib/oj.rb +0 -8
- data/pages/Compatibility.md +1 -1
- data/pages/JsonGem.md +15 -0
- data/pages/Modes.md +53 -46
- data/pages/Options.md +72 -11
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +73 -22
- data/pages/Security.md +1 -1
- data/test/activerecord/result_test.rb +7 -2
- data/test/activesupport5/abstract_unit.rb +45 -0
- data/test/activesupport5/decoding_test.rb +68 -60
- data/test/activesupport5/encoding_test.rb +111 -96
- data/test/activesupport5/encoding_test_cases.rb +33 -25
- data/test/activesupport5/test_helper.rb +43 -21
- data/test/activesupport5/time_zone_test_helpers.rb +18 -3
- data/test/activesupport6/abstract_unit.rb +44 -0
- data/test/activesupport6/decoding_test.rb +133 -0
- data/test/activesupport6/encoding_test.rb +507 -0
- data/test/activesupport6/encoding_test_cases.rb +98 -0
- data/test/activesupport6/test_common.rb +17 -0
- data/test/activesupport6/test_helper.rb +163 -0
- data/test/activesupport6/time_zone_test_helpers.rb +39 -0
- data/test/activesupport7/abstract_unit.rb +49 -0
- data/test/activesupport7/decoding_test.rb +125 -0
- data/test/activesupport7/encoding_test.rb +486 -0
- data/test/activesupport7/encoding_test_cases.rb +104 -0
- data/test/activesupport7/time_zone_test_helpers.rb +47 -0
- data/test/bar.rb +6 -12
- data/test/baz.rb +16 -0
- data/test/bug.rb +16 -0
- data/test/foo.rb +69 -75
- data/test/helper.rb +16 -0
- data/test/json_gem/json_common_interface_test.rb +8 -3
- data/test/json_gem/json_generator_test.rb +18 -4
- data/test/json_gem/json_parser_test.rb +9 -0
- data/test/json_gem/test_helper.rb +12 -0
- data/test/mem.rb +33 -0
- data/test/perf.rb +1 -1
- data/test/perf_dump.rb +50 -0
- data/test/perf_once.rb +58 -0
- data/test/perf_parser.rb +189 -0
- data/test/perf_scp.rb +11 -10
- data/test/perf_strict.rb +17 -23
- data/test/prec.rb +23 -0
- data/test/sample_json.rb +1 -1
- data/test/test_compat.rb +46 -10
- data/test/test_custom.rb +147 -8
- data/test/test_fast.rb +62 -2
- data/test/test_file.rb +25 -2
- data/test/test_gc.rb +13 -0
- data/test/test_generate.rb +21 -0
- data/test/test_hash.rb +11 -1
- data/test/test_integer_range.rb +7 -2
- data/test/test_object.rb +85 -9
- data/test/test_parser.rb +27 -0
- data/test/test_parser_saj.rb +335 -0
- data/test/test_parser_usual.rb +217 -0
- data/test/test_rails.rb +35 -0
- data/test/test_saj.rb +1 -1
- data/test/test_scp.rb +5 -5
- data/test/test_strict.rb +26 -1
- data/test/test_various.rb +87 -65
- data/test/test_wab.rb +2 -0
- data/test/test_writer.rb +19 -2
- data/test/tests.rb +1 -1
- data/test/zoo.rb +13 -0
- metadata +60 -110
- data/ext/oj/hash.c +0 -163
- data/ext/oj/hash.h +0 -46
- data/ext/oj/hash_test.c +0 -512
data/ext/oj/scp.c
CHANGED
|
@@ -1,42 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* All rights reserved.
|
|
4
|
-
*/
|
|
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.
|
|
5
3
|
|
|
6
|
-
#include <
|
|
4
|
+
#include <math.h>
|
|
7
5
|
#include <stdio.h>
|
|
6
|
+
#include <stdlib.h>
|
|
8
7
|
#include <string.h>
|
|
9
|
-
#include <math.h>
|
|
10
8
|
#include <sys/types.h>
|
|
11
9
|
#include <unistd.h>
|
|
12
10
|
|
|
11
|
+
#include "encode.h"
|
|
12
|
+
#include "intern.h"
|
|
13
13
|
#include "oj.h"
|
|
14
14
|
#include "parse.h"
|
|
15
|
-
#include "encode.h"
|
|
16
15
|
|
|
17
|
-
static VALUE
|
|
18
|
-
noop_start(ParseInfo pi) {
|
|
16
|
+
static VALUE noop_start(ParseInfo pi) {
|
|
19
17
|
return Qnil;
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
static void
|
|
23
|
-
noop_end(ParseInfo pi) {
|
|
20
|
+
static void noop_end(ParseInfo pi) {
|
|
24
21
|
}
|
|
25
22
|
|
|
26
|
-
static void
|
|
27
|
-
noop_add_value(ParseInfo pi, VALUE val) {
|
|
23
|
+
static void noop_add_value(ParseInfo pi, VALUE val) {
|
|
28
24
|
}
|
|
29
25
|
|
|
30
|
-
static void
|
|
31
|
-
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) {
|
|
32
27
|
}
|
|
33
28
|
|
|
34
|
-
static void
|
|
35
|
-
noop_add_num(ParseInfo pi, NumInfo ni) {
|
|
29
|
+
static void noop_add_num(ParseInfo pi, NumInfo ni) {
|
|
36
30
|
}
|
|
37
31
|
|
|
38
|
-
static VALUE
|
|
39
|
-
noop_hash_key(struct _ParseInfo *pi, const char *key, size_t klen) {
|
|
32
|
+
static VALUE noop_hash_key(ParseInfo pi, const char *key, size_t klen) {
|
|
40
33
|
return Qundef;
|
|
41
34
|
}
|
|
42
35
|
|
|
@@ -44,181 +37,163 @@ static void
|
|
|
44
37
|
noop_hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
|
|
45
38
|
}
|
|
46
39
|
|
|
47
|
-
static void
|
|
48
|
-
noop_hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
|
|
40
|
+
static void noop_hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
|
|
49
41
|
}
|
|
50
42
|
|
|
51
|
-
static void
|
|
52
|
-
noop_hash_set_value(ParseInfo pi, Val kval, VALUE value) {
|
|
43
|
+
static void noop_hash_set_value(ParseInfo pi, Val kval, VALUE value) {
|
|
53
44
|
}
|
|
54
45
|
|
|
55
|
-
static void
|
|
56
|
-
noop_array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
|
46
|
+
static void noop_array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
|
57
47
|
}
|
|
58
48
|
|
|
59
|
-
static void
|
|
60
|
-
noop_array_append_num(ParseInfo pi, NumInfo ni) {
|
|
49
|
+
static void noop_array_append_num(ParseInfo pi, NumInfo ni) {
|
|
61
50
|
}
|
|
62
51
|
|
|
63
|
-
static void
|
|
64
|
-
noop_array_append_value(ParseInfo pi, VALUE value) {
|
|
52
|
+
static void noop_array_append_value(ParseInfo pi, VALUE value) {
|
|
65
53
|
}
|
|
66
54
|
|
|
67
|
-
static void
|
|
68
|
-
add_value(ParseInfo pi, VALUE val) {
|
|
55
|
+
static void add_value(ParseInfo pi, VALUE val) {
|
|
69
56
|
rb_funcall(pi->handler, oj_add_value_id, 1, val);
|
|
70
57
|
}
|
|
71
58
|
|
|
72
|
-
static void
|
|
73
|
-
|
|
74
|
-
volatile VALUE rstr = rb_str_new(str, len);
|
|
59
|
+
static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
|
60
|
+
volatile VALUE rstr = rb_str_new(str, len);
|
|
75
61
|
|
|
76
62
|
rstr = oj_encode(rstr);
|
|
77
63
|
rb_funcall(pi->handler, oj_add_value_id, 1, rstr);
|
|
78
64
|
}
|
|
79
65
|
|
|
80
|
-
static void
|
|
81
|
-
add_num(ParseInfo pi, NumInfo ni) {
|
|
66
|
+
static void add_num(ParseInfo pi, NumInfo ni) {
|
|
82
67
|
rb_funcall(pi->handler, oj_add_value_id, 1, oj_num_as_value(ni));
|
|
83
68
|
}
|
|
84
69
|
|
|
85
|
-
static VALUE
|
|
86
|
-
start_hash(ParseInfo pi) {
|
|
70
|
+
static VALUE start_hash(ParseInfo pi) {
|
|
87
71
|
return rb_funcall(pi->handler, oj_hash_start_id, 0);
|
|
88
72
|
}
|
|
89
73
|
|
|
90
|
-
static void
|
|
91
|
-
end_hash(ParseInfo pi) {
|
|
74
|
+
static void end_hash(ParseInfo pi) {
|
|
92
75
|
rb_funcall(pi->handler, oj_hash_end_id, 0);
|
|
93
76
|
}
|
|
94
77
|
|
|
95
|
-
static VALUE
|
|
96
|
-
start_array(ParseInfo pi) {
|
|
78
|
+
static VALUE start_array(ParseInfo pi) {
|
|
97
79
|
return rb_funcall(pi->handler, oj_array_start_id, 0);
|
|
98
80
|
}
|
|
99
81
|
|
|
100
|
-
static void
|
|
101
|
-
end_array(ParseInfo pi) {
|
|
82
|
+
static void end_array(ParseInfo pi) {
|
|
102
83
|
rb_funcall(pi->handler, oj_array_end_id, 0);
|
|
103
84
|
}
|
|
104
85
|
|
|
105
|
-
static VALUE
|
|
106
|
-
calc_hash_key(ParseInfo pi, Val kval) {
|
|
107
|
-
volatile VALUE rkey = kval->key_val;
|
|
108
|
-
|
|
109
|
-
if (Qundef == rkey) {
|
|
110
|
-
rkey = rb_str_new(kval->key, kval->klen);
|
|
111
|
-
rkey = oj_encode(rkey);
|
|
112
|
-
if (Yes == pi->options.sym_key) {
|
|
113
|
-
rkey = rb_str_intern(rkey);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return rkey;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
static VALUE
|
|
120
|
-
hash_key(struct _ParseInfo *pi, const char *key, size_t klen) {
|
|
86
|
+
static VALUE hash_key(ParseInfo pi, const char *key, size_t klen) {
|
|
121
87
|
return rb_funcall(pi->handler, oj_hash_key_id, 1, rb_str_new(key, klen));
|
|
122
88
|
}
|
|
123
89
|
|
|
124
|
-
static void
|
|
125
|
-
|
|
126
|
-
volatile VALUE rstr = rb_str_new(str, len);
|
|
90
|
+
static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
|
|
91
|
+
volatile VALUE rstr = rb_str_new(str, len);
|
|
127
92
|
|
|
128
93
|
rstr = oj_encode(rstr);
|
|
129
|
-
rb_funcall(pi->handler,
|
|
94
|
+
rb_funcall(pi->handler,
|
|
95
|
+
oj_hash_set_id,
|
|
96
|
+
3,
|
|
97
|
+
stack_peek(&pi->stack)->val,
|
|
98
|
+
oj_calc_hash_key(pi, kval),
|
|
99
|
+
rstr);
|
|
130
100
|
}
|
|
131
101
|
|
|
132
|
-
static void
|
|
133
|
-
|
|
134
|
-
|
|
102
|
+
static void hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
|
|
103
|
+
rb_funcall(pi->handler,
|
|
104
|
+
oj_hash_set_id,
|
|
105
|
+
3,
|
|
106
|
+
stack_peek(&pi->stack)->val,
|
|
107
|
+
oj_calc_hash_key(pi, kval),
|
|
108
|
+
oj_num_as_value(ni));
|
|
135
109
|
}
|
|
136
110
|
|
|
137
|
-
static void
|
|
138
|
-
|
|
139
|
-
|
|
111
|
+
static void hash_set_value(ParseInfo pi, Val kval, VALUE value) {
|
|
112
|
+
rb_funcall(pi->handler,
|
|
113
|
+
oj_hash_set_id,
|
|
114
|
+
3,
|
|
115
|
+
stack_peek(&pi->stack)->val,
|
|
116
|
+
oj_calc_hash_key(pi, kval),
|
|
117
|
+
value);
|
|
140
118
|
}
|
|
141
119
|
|
|
142
|
-
static void
|
|
143
|
-
|
|
144
|
-
volatile VALUE rstr = rb_str_new(str, len);
|
|
120
|
+
static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
|
121
|
+
volatile VALUE rstr = rb_str_new(str, len);
|
|
145
122
|
|
|
146
123
|
rstr = oj_encode(rstr);
|
|
147
124
|
rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, rstr);
|
|
148
125
|
}
|
|
149
126
|
|
|
150
|
-
static void
|
|
151
|
-
array_append_num(ParseInfo pi, NumInfo ni) {
|
|
127
|
+
static void array_append_num(ParseInfo pi, NumInfo ni) {
|
|
152
128
|
rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, oj_num_as_value(ni));
|
|
153
129
|
}
|
|
154
130
|
|
|
155
|
-
static void
|
|
156
|
-
array_append_value(ParseInfo pi, VALUE value) {
|
|
131
|
+
static void array_append_value(ParseInfo pi, VALUE value) {
|
|
157
132
|
rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, value);
|
|
158
133
|
}
|
|
159
134
|
|
|
160
135
|
VALUE
|
|
161
136
|
oj_sc_parse(int argc, VALUE *argv, VALUE self) {
|
|
162
|
-
struct
|
|
163
|
-
VALUE
|
|
137
|
+
struct _parseInfo pi;
|
|
138
|
+
VALUE input = argv[1];
|
|
164
139
|
|
|
165
140
|
parse_info_init(&pi);
|
|
166
141
|
pi.err_class = Qnil;
|
|
167
142
|
pi.max_depth = 0;
|
|
168
|
-
pi.options
|
|
143
|
+
pi.options = oj_default_options;
|
|
169
144
|
if (3 == argc) {
|
|
170
|
-
|
|
145
|
+
oj_parse_options(argv[2], &pi.options);
|
|
171
146
|
}
|
|
172
147
|
if (rb_block_given_p()) {
|
|
173
|
-
|
|
148
|
+
pi.proc = Qnil;
|
|
174
149
|
} else {
|
|
175
|
-
|
|
150
|
+
pi.proc = Qundef;
|
|
176
151
|
}
|
|
177
152
|
pi.handler = *argv;
|
|
178
153
|
|
|
179
|
-
pi.start_hash
|
|
180
|
-
pi.end_hash
|
|
181
|
-
pi.hash_key
|
|
154
|
+
pi.start_hash = rb_respond_to(pi.handler, oj_hash_start_id) ? start_hash : noop_start;
|
|
155
|
+
pi.end_hash = rb_respond_to(pi.handler, oj_hash_end_id) ? end_hash : noop_end;
|
|
156
|
+
pi.hash_key = rb_respond_to(pi.handler, oj_hash_key_id) ? hash_key : noop_hash_key;
|
|
182
157
|
pi.start_array = rb_respond_to(pi.handler, oj_array_start_id) ? start_array : noop_start;
|
|
183
|
-
pi.end_array
|
|
158
|
+
pi.end_array = rb_respond_to(pi.handler, oj_array_end_id) ? end_array : noop_end;
|
|
184
159
|
if (rb_respond_to(pi.handler, oj_hash_set_id)) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
160
|
+
pi.hash_set_value = hash_set_value;
|
|
161
|
+
pi.hash_set_cstr = hash_set_cstr;
|
|
162
|
+
pi.hash_set_num = hash_set_num;
|
|
163
|
+
pi.expect_value = 1;
|
|
189
164
|
} else {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
165
|
+
pi.hash_set_value = noop_hash_set_value;
|
|
166
|
+
pi.hash_set_cstr = noop_hash_set_cstr;
|
|
167
|
+
pi.hash_set_num = noop_hash_set_num;
|
|
168
|
+
pi.expect_value = 0;
|
|
194
169
|
}
|
|
195
170
|
if (rb_respond_to(pi.handler, oj_array_append_id)) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
171
|
+
pi.array_append_value = array_append_value;
|
|
172
|
+
pi.array_append_cstr = array_append_cstr;
|
|
173
|
+
pi.array_append_num = array_append_num;
|
|
174
|
+
pi.expect_value = 1;
|
|
200
175
|
} else {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
176
|
+
pi.array_append_value = noop_array_append_value;
|
|
177
|
+
pi.array_append_cstr = noop_array_append_cstr;
|
|
178
|
+
pi.array_append_num = noop_array_append_num;
|
|
179
|
+
pi.expect_value = 0;
|
|
205
180
|
}
|
|
206
181
|
if (rb_respond_to(pi.handler, oj_add_value_id)) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
182
|
+
pi.add_cstr = add_cstr;
|
|
183
|
+
pi.add_num = add_num;
|
|
184
|
+
pi.add_value = add_value;
|
|
185
|
+
pi.expect_value = 1;
|
|
211
186
|
} else {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
187
|
+
pi.add_cstr = noop_add_cstr;
|
|
188
|
+
pi.add_num = noop_add_num;
|
|
189
|
+
pi.add_value = noop_add_value;
|
|
190
|
+
pi.expect_value = 0;
|
|
216
191
|
}
|
|
217
192
|
pi.has_callbacks = true;
|
|
218
193
|
|
|
219
194
|
if (T_STRING == rb_type(input)) {
|
|
220
|
-
|
|
195
|
+
return oj_pi_parse(argc - 1, argv + 1, &pi, 0, 0, 1);
|
|
221
196
|
} else {
|
|
222
|
-
|
|
197
|
+
return oj_pi_sparse(argc - 1, argv + 1, &pi, 0);
|
|
223
198
|
}
|
|
224
199
|
}
|