oj 3.13.17 → 3.16.3
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 +77 -0
- data/README.md +4 -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 +44 -96
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +69 -39
- 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 -6
- data/ext/oj/fast.c +76 -106
- data/ext/oj/intern.c +63 -51
- 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 +43 -30
- data/ext/oj/object.c +61 -70
- data/ext/oj/odd.c +8 -6
- data/ext/oj/odd.h +4 -4
- data/ext/oj/oj.c +243 -205
- data/ext/oj/oj.h +82 -78
- data/ext/oj/parse.c +123 -188
- data/ext/oj/parse.h +23 -24
- data/ext/oj/parser.c +103 -63
- data/ext/oj/parser.h +19 -9
- data/ext/oj/rails.c +68 -92
- data/ext/oj/reader.c +10 -15
- 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 +10 -9
- data/ext/oj/saj2.c +74 -92
- data/ext/oj/saj2.h +23 -0
- data/ext/oj/scp.c +3 -14
- data/ext/oj/sparse.c +22 -70
- data/ext/oj/stream_writer.c +43 -35
- data/ext/oj/strict.c +20 -52
- data/ext/oj/string_writer.c +60 -34
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +125 -150
- data/ext/oj/usual.h +69 -0
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +14 -3
- 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 +6 -2
- data/lib/oj/state.rb +9 -6
- 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/Options.md +10 -0
- 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 +5 -6
- data/test/files.rb +15 -15
- data/test/foo.rb +9 -72
- data/test/helper.rb +11 -8
- 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 +53 -37
- data/test/json_gem/json_generic_object_test.rb +11 -11
- data/test/json_gem/json_parser_test.rb +47 -47
- data/test/json_gem/json_string_matching_test.rb +9 -9
- data/test/json_gem/test_helper.rb +7 -3
- data/test/mem.rb +13 -12
- data/test/perf.rb +21 -26
- data/test/perf_compat.rb +31 -33
- data/test/perf_dump.rb +28 -28
- 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 +12 -11
- data/test/perf_parser.rb +42 -48
- data/test/perf_saj.rb +46 -54
- data/test/perf_scp.rb +57 -69
- data/test/perf_simple.rb +41 -39
- data/test/perf_strict.rb +68 -70
- 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 +80 -53
- data/test/test_custom.rb +73 -51
- data/test/test_debian.rb +7 -10
- data/test/test_fast.rb +86 -90
- data/test/test_file.rb +28 -35
- data/test/test_gc.rb +16 -5
- data/test/test_generate.rb +5 -5
- data/test/test_hash.rb +4 -4
- data/test/test_integer_range.rb +9 -9
- data/test/test_null.rb +20 -20
- data/test/test_object.rb +94 -96
- data/test/test_parser.rb +6 -22
- data/test/test_parser_debug.rb +27 -0
- data/test/test_parser_saj.rb +61 -22
- data/test/test_parser_usual.rb +16 -6
- data/test/test_rails.rb +2 -2
- data/test/test_saj.rb +10 -8
- data/test/test_scp.rb +37 -39
- data/test/test_strict.rb +40 -32
- data/test/test_various.rb +148 -100
- data/test/test_wab.rb +48 -44
- data/test/test_writer.rb +47 -47
- data/test/tests.rb +13 -4
- data/test/tests_mimic.rb +12 -3
- data/test/tests_mimic_addition.rb +12 -3
- metadata +36 -27
- 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/bar.rb +0 -11
- data/test/baz.rb +0 -16
- data/test/bug.rb +0 -16
- data/test/zoo.rb +0 -13
data/ext/oj/saj2.c
CHANGED
@@ -1,22 +1,14 @@
|
|
1
1
|
// Copyright (c) 2021, Peter Ohler, All rights reserved.
|
2
2
|
|
3
|
+
#include "saj2.h"
|
4
|
+
|
3
5
|
#include "cache.h"
|
6
|
+
#include "mem.h"
|
4
7
|
#include "oj.h"
|
5
8
|
#include "parser.h"
|
6
9
|
|
7
|
-
typedef struct _delegate {
|
8
|
-
VALUE handler;
|
9
|
-
VALUE *keys;
|
10
|
-
VALUE *tail;
|
11
|
-
size_t klen;
|
12
|
-
struct _cache *str_cache;
|
13
|
-
uint8_t cache_str;
|
14
|
-
bool cache_keys;
|
15
|
-
bool thread_safe;
|
16
|
-
} * Delegate;
|
17
|
-
|
18
10
|
static VALUE get_key(ojParser p) {
|
19
|
-
|
11
|
+
Saj d = (Saj)p->ctx;
|
20
12
|
const char *key = buf_str(&p->key);
|
21
13
|
size_t len = buf_len(&p->key);
|
22
14
|
volatile VALUE rkey;
|
@@ -29,12 +21,12 @@ static VALUE get_key(ojParser p) {
|
|
29
21
|
return rkey;
|
30
22
|
}
|
31
23
|
|
32
|
-
static void push_key(
|
24
|
+
static void push_key(Saj d, VALUE key) {
|
33
25
|
if (d->klen <= (size_t)(d->tail - d->keys)) {
|
34
26
|
size_t off = d->tail - d->keys;
|
35
27
|
|
36
28
|
d->klen += d->klen / 2;
|
37
|
-
|
29
|
+
OJ_R_REALLOC_N(d->keys, VALUE, d->klen);
|
38
30
|
d->tail = d->keys + off;
|
39
31
|
}
|
40
32
|
*d->tail = key;
|
@@ -45,15 +37,15 @@ static void noop(ojParser p) {
|
|
45
37
|
}
|
46
38
|
|
47
39
|
static void open_object(ojParser p) {
|
48
|
-
rb_funcall(((
|
40
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_hash_start_id, 1, Qnil);
|
49
41
|
}
|
50
42
|
|
51
43
|
static void open_object_loc(ojParser p) {
|
52
|
-
rb_funcall(((
|
44
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_hash_start_id, 3, Qnil, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
|
53
45
|
}
|
54
46
|
|
55
47
|
static void open_object_key(ojParser p) {
|
56
|
-
|
48
|
+
Saj d = (Saj)p->ctx;
|
57
49
|
volatile VALUE key = get_key(p);
|
58
50
|
|
59
51
|
push_key(d, key);
|
@@ -61,7 +53,7 @@ static void open_object_key(ojParser p) {
|
|
61
53
|
}
|
62
54
|
|
63
55
|
static void open_object_loc_key(ojParser p) {
|
64
|
-
|
56
|
+
Saj d = (Saj)p->ctx;
|
65
57
|
volatile VALUE key = get_key(p);
|
66
58
|
|
67
59
|
push_key(d, key);
|
@@ -69,15 +61,15 @@ static void open_object_loc_key(ojParser p) {
|
|
69
61
|
}
|
70
62
|
|
71
63
|
static void open_array(ojParser p) {
|
72
|
-
rb_funcall(((
|
64
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_array_start_id, 1, Qnil);
|
73
65
|
}
|
74
66
|
|
75
67
|
static void open_array_loc(ojParser p) {
|
76
|
-
rb_funcall(((
|
68
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_array_start_id, 3, Qnil, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
|
77
69
|
}
|
78
70
|
|
79
71
|
static void open_array_key(ojParser p) {
|
80
|
-
|
72
|
+
Saj d = (Saj)p->ctx;
|
81
73
|
volatile VALUE key = get_key(p);
|
82
74
|
|
83
75
|
push_key(d, key);
|
@@ -85,7 +77,7 @@ static void open_array_key(ojParser p) {
|
|
85
77
|
}
|
86
78
|
|
87
79
|
static void open_array_loc_key(ojParser p) {
|
88
|
-
|
80
|
+
Saj d = (Saj)p->ctx;
|
89
81
|
volatile VALUE key = get_key(p);
|
90
82
|
|
91
83
|
push_key(d, key);
|
@@ -93,8 +85,8 @@ static void open_array_loc_key(ojParser p) {
|
|
93
85
|
}
|
94
86
|
|
95
87
|
static void close_object(ojParser p) {
|
96
|
-
|
97
|
-
VALUE
|
88
|
+
Saj d = (Saj)p->ctx;
|
89
|
+
VALUE key = Qnil;
|
98
90
|
|
99
91
|
if (OBJECT_FUN == p->stack[p->depth]) {
|
100
92
|
d->tail--;
|
@@ -107,8 +99,8 @@ static void close_object(ojParser p) {
|
|
107
99
|
}
|
108
100
|
|
109
101
|
static void close_object_loc(ojParser p) {
|
110
|
-
|
111
|
-
VALUE
|
102
|
+
Saj d = (Saj)p->ctx;
|
103
|
+
VALUE key = Qnil;
|
112
104
|
|
113
105
|
if (OBJECT_FUN == p->stack[p->depth]) {
|
114
106
|
d->tail--;
|
@@ -121,8 +113,8 @@ static void close_object_loc(ojParser p) {
|
|
121
113
|
}
|
122
114
|
|
123
115
|
static void close_array(ojParser p) {
|
124
|
-
|
125
|
-
VALUE
|
116
|
+
Saj d = (Saj)p->ctx;
|
117
|
+
VALUE key = Qnil;
|
126
118
|
|
127
119
|
if (OBJECT_FUN == p->stack[p->depth]) {
|
128
120
|
d->tail--;
|
@@ -135,8 +127,8 @@ static void close_array(ojParser p) {
|
|
135
127
|
}
|
136
128
|
|
137
129
|
static void close_array_loc(ojParser p) {
|
138
|
-
|
139
|
-
VALUE
|
130
|
+
Saj d = (Saj)p->ctx;
|
131
|
+
VALUE key = Qnil;
|
140
132
|
|
141
133
|
if (OBJECT_FUN == p->stack[p->depth]) {
|
142
134
|
d->tail--;
|
@@ -149,25 +141,19 @@ static void close_array_loc(ojParser p) {
|
|
149
141
|
}
|
150
142
|
|
151
143
|
static void add_null(ojParser p) {
|
152
|
-
rb_funcall(((
|
144
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, Qnil, Qnil);
|
153
145
|
}
|
154
146
|
|
155
147
|
static void add_null_loc(ojParser p) {
|
156
|
-
rb_funcall(((
|
157
|
-
oj_add_value_id,
|
158
|
-
4,
|
159
|
-
Qnil,
|
160
|
-
Qnil,
|
161
|
-
LONG2FIX(p->line),
|
162
|
-
LONG2FIX(p->cur - p->col));
|
148
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 4, Qnil, Qnil, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
|
163
149
|
}
|
164
150
|
|
165
151
|
static void add_null_key(ojParser p) {
|
166
|
-
rb_funcall(((
|
152
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, Qnil, get_key(p));
|
167
153
|
}
|
168
154
|
|
169
155
|
static void add_null_key_loc(ojParser p) {
|
170
|
-
rb_funcall(((
|
156
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
171
157
|
oj_add_value_id,
|
172
158
|
4,
|
173
159
|
Qnil,
|
@@ -177,25 +163,19 @@ static void add_null_key_loc(ojParser p) {
|
|
177
163
|
}
|
178
164
|
|
179
165
|
static void add_true(ojParser p) {
|
180
|
-
rb_funcall(((
|
166
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, Qtrue, Qnil);
|
181
167
|
}
|
182
168
|
|
183
169
|
static void add_true_loc(ojParser p) {
|
184
|
-
rb_funcall(((
|
185
|
-
oj_add_value_id,
|
186
|
-
4,
|
187
|
-
Qtrue,
|
188
|
-
Qnil,
|
189
|
-
LONG2FIX(p->line),
|
190
|
-
LONG2FIX(p->cur - p->col));
|
170
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 4, Qtrue, Qnil, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
|
191
171
|
}
|
192
172
|
|
193
173
|
static void add_true_key(ojParser p) {
|
194
|
-
rb_funcall(((
|
174
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, Qtrue, get_key(p));
|
195
175
|
}
|
196
176
|
|
197
177
|
static void add_true_key_loc(ojParser p) {
|
198
|
-
rb_funcall(((
|
178
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
199
179
|
oj_add_value_id,
|
200
180
|
4,
|
201
181
|
Qtrue,
|
@@ -205,25 +185,19 @@ static void add_true_key_loc(ojParser p) {
|
|
205
185
|
}
|
206
186
|
|
207
187
|
static void add_false(ojParser p) {
|
208
|
-
rb_funcall(((
|
188
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, Qfalse, Qnil);
|
209
189
|
}
|
210
190
|
|
211
191
|
static void add_false_loc(ojParser p) {
|
212
|
-
rb_funcall(((
|
213
|
-
oj_add_value_id,
|
214
|
-
4,
|
215
|
-
Qfalse,
|
216
|
-
Qnil,
|
217
|
-
LONG2FIX(p->line),
|
218
|
-
LONG2FIX(p->cur - p->col));
|
192
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 4, Qfalse, Qnil, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
|
219
193
|
}
|
220
194
|
|
221
195
|
static void add_false_key(ojParser p) {
|
222
|
-
rb_funcall(((
|
196
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, Qfalse, get_key(p));
|
223
197
|
}
|
224
198
|
|
225
199
|
static void add_false_key_loc(ojParser p) {
|
226
|
-
rb_funcall(((
|
200
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
227
201
|
oj_add_value_id,
|
228
202
|
4,
|
229
203
|
Qfalse,
|
@@ -233,11 +207,11 @@ static void add_false_key_loc(ojParser p) {
|
|
233
207
|
}
|
234
208
|
|
235
209
|
static void add_int(ojParser p) {
|
236
|
-
rb_funcall(((
|
210
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, LONG2NUM(p->num.fixnum), Qnil);
|
237
211
|
}
|
238
212
|
|
239
213
|
static void add_int_loc(ojParser p) {
|
240
|
-
rb_funcall(((
|
214
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
241
215
|
oj_add_value_id,
|
242
216
|
4,
|
243
217
|
LONG2NUM(p->num.fixnum),
|
@@ -247,11 +221,11 @@ static void add_int_loc(ojParser p) {
|
|
247
221
|
}
|
248
222
|
|
249
223
|
static void add_int_key(ojParser p) {
|
250
|
-
rb_funcall(((
|
224
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, LONG2NUM(p->num.fixnum), get_key(p));
|
251
225
|
}
|
252
226
|
|
253
227
|
static void add_int_key_loc(ojParser p) {
|
254
|
-
rb_funcall(((
|
228
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
255
229
|
oj_add_value_id,
|
256
230
|
4,
|
257
231
|
LONG2NUM(p->num.fixnum),
|
@@ -261,11 +235,11 @@ static void add_int_key_loc(ojParser p) {
|
|
261
235
|
}
|
262
236
|
|
263
237
|
static void add_float(ojParser p) {
|
264
|
-
rb_funcall(((
|
238
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, rb_float_new(p->num.dub), Qnil);
|
265
239
|
}
|
266
240
|
|
267
241
|
static void add_float_loc(ojParser p) {
|
268
|
-
rb_funcall(((
|
242
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
269
243
|
oj_add_value_id,
|
270
244
|
4,
|
271
245
|
rb_float_new(p->num.dub),
|
@@ -275,11 +249,11 @@ static void add_float_loc(ojParser p) {
|
|
275
249
|
}
|
276
250
|
|
277
251
|
static void add_float_key(ojParser p) {
|
278
|
-
rb_funcall(((
|
252
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, rb_float_new(p->num.dub), get_key(p));
|
279
253
|
}
|
280
254
|
|
281
255
|
static void add_float_key_loc(ojParser p) {
|
282
|
-
rb_funcall(((
|
256
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
283
257
|
oj_add_value_id,
|
284
258
|
4,
|
285
259
|
rb_float_new(p->num.dub),
|
@@ -289,7 +263,7 @@ static void add_float_key_loc(ojParser p) {
|
|
289
263
|
}
|
290
264
|
|
291
265
|
static void add_big(ojParser p) {
|
292
|
-
rb_funcall((
|
266
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
293
267
|
oj_add_value_id,
|
294
268
|
2,
|
295
269
|
rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new(buf_str(&p->buf), buf_len(&p->buf))),
|
@@ -297,7 +271,7 @@ static void add_big(ojParser p) {
|
|
297
271
|
}
|
298
272
|
|
299
273
|
static void add_big_loc(ojParser p) {
|
300
|
-
rb_funcall((
|
274
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
301
275
|
oj_add_value_id,
|
302
276
|
4,
|
303
277
|
rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new(buf_str(&p->buf), buf_len(&p->buf))),
|
@@ -307,7 +281,7 @@ static void add_big_loc(ojParser p) {
|
|
307
281
|
}
|
308
282
|
|
309
283
|
static void add_big_key(ojParser p) {
|
310
|
-
rb_funcall((
|
284
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
311
285
|
oj_add_value_id,
|
312
286
|
2,
|
313
287
|
rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new(buf_str(&p->buf), buf_len(&p->buf))),
|
@@ -315,7 +289,7 @@ static void add_big_key(ojParser p) {
|
|
315
289
|
}
|
316
290
|
|
317
291
|
static void add_big_key_loc(ojParser p) {
|
318
|
-
rb_funcall((
|
292
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
319
293
|
oj_add_value_id,
|
320
294
|
4,
|
321
295
|
rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new(buf_str(&p->buf), buf_len(&p->buf))),
|
@@ -325,7 +299,7 @@ static void add_big_key_loc(ojParser p) {
|
|
325
299
|
}
|
326
300
|
|
327
301
|
static void add_str(ojParser p) {
|
328
|
-
|
302
|
+
Saj d = (Saj)p->ctx;
|
329
303
|
volatile VALUE rstr;
|
330
304
|
const char *str = buf_str(&p->buf);
|
331
305
|
size_t len = buf_len(&p->buf);
|
@@ -339,7 +313,7 @@ static void add_str(ojParser p) {
|
|
339
313
|
}
|
340
314
|
|
341
315
|
static void add_str_loc(ojParser p) {
|
342
|
-
|
316
|
+
Saj d = (Saj)p->ctx;
|
343
317
|
volatile VALUE rstr;
|
344
318
|
const char *str = buf_str(&p->buf);
|
345
319
|
size_t len = buf_len(&p->buf);
|
@@ -353,7 +327,7 @@ static void add_str_loc(ojParser p) {
|
|
353
327
|
}
|
354
328
|
|
355
329
|
static void add_str_key(ojParser p) {
|
356
|
-
|
330
|
+
Saj d = (Saj)p->ctx;
|
357
331
|
volatile VALUE rstr;
|
358
332
|
const char *str = buf_str(&p->buf);
|
359
333
|
size_t len = buf_len(&p->buf);
|
@@ -367,7 +341,7 @@ static void add_str_key(ojParser p) {
|
|
367
341
|
}
|
368
342
|
|
369
343
|
static void add_str_key_loc(ojParser p) {
|
370
|
-
|
344
|
+
Saj d = (Saj)p->ctx;
|
371
345
|
volatile VALUE rstr;
|
372
346
|
const char *str = buf_str(&p->buf);
|
373
347
|
size_t len = buf_len(&p->buf);
|
@@ -400,7 +374,7 @@ static void reset(ojParser p) {
|
|
400
374
|
}
|
401
375
|
|
402
376
|
static VALUE option(ojParser p, const char *key, VALUE value) {
|
403
|
-
|
377
|
+
Saj d = (Saj)p->ctx;
|
404
378
|
|
405
379
|
if (0 == strcmp(key, "handler")) {
|
406
380
|
return d->handler;
|
@@ -537,7 +511,7 @@ static VALUE option(ojParser p, const char *key, VALUE value) {
|
|
537
511
|
|
538
512
|
return INT2NUM((int)d->cache_str);
|
539
513
|
}
|
540
|
-
rb_raise(rb_eArgError, "%s is not an option for the SAJ (Simple API for JSON)
|
514
|
+
rb_raise(rb_eArgError, "%s is not an option for the SAJ (Simple API for JSON) saj", key);
|
541
515
|
|
542
516
|
return Qnil; // Never reached due to the raise but required by the compiler.
|
543
517
|
}
|
@@ -547,27 +521,27 @@ static VALUE result(ojParser p) {
|
|
547
521
|
}
|
548
522
|
|
549
523
|
static void start(ojParser p) {
|
550
|
-
|
524
|
+
Saj d = (Saj)p->ctx;
|
551
525
|
|
552
526
|
d->tail = d->keys;
|
553
527
|
}
|
554
528
|
|
555
529
|
static void dfree(ojParser p) {
|
556
|
-
|
530
|
+
Saj d = (Saj)p->ctx;
|
557
531
|
|
558
532
|
if (NULL != d->keys) {
|
559
|
-
|
533
|
+
OJ_R_FREE(d->keys);
|
560
534
|
}
|
561
535
|
cache_free(d->str_cache);
|
562
|
-
|
536
|
+
OJ_R_FREE(p->ctx);
|
563
537
|
}
|
564
538
|
|
565
539
|
static void mark(ojParser p) {
|
566
|
-
if (NULL == p->ctx) {
|
540
|
+
if (NULL == p || NULL == p->ctx) {
|
567
541
|
return;
|
568
542
|
}
|
569
|
-
|
570
|
-
VALUE
|
543
|
+
Saj d = (Saj)p->ctx;
|
544
|
+
VALUE *kp;
|
571
545
|
|
572
546
|
cache_mark(d->str_cache);
|
573
547
|
if (Qnil != d->handler) {
|
@@ -584,13 +558,15 @@ static VALUE form_str(const char *str, size_t len) {
|
|
584
558
|
return rb_str_freeze(rb_utf8_str_new(str, len));
|
585
559
|
}
|
586
560
|
|
587
|
-
void
|
588
|
-
|
589
|
-
|
590
|
-
d->
|
591
|
-
d->
|
592
|
-
d->
|
593
|
-
d->
|
561
|
+
void oj_init_saj(ojParser p, Saj d) {
|
562
|
+
d->klen = 256;
|
563
|
+
d->keys = OJ_R_ALLOC_N(VALUE, d->klen);
|
564
|
+
d->tail = d->keys;
|
565
|
+
d->handler = Qnil;
|
566
|
+
d->str_cache = cache_create(0, form_str, true, false);
|
567
|
+
d->cache_str = 16;
|
568
|
+
d->cache_keys = true;
|
569
|
+
d->thread_safe = false;
|
594
570
|
|
595
571
|
p->ctx = (void *)d;
|
596
572
|
reset(p);
|
@@ -600,3 +576,9 @@ void oj_set_parser_saj(ojParser p) {
|
|
600
576
|
p->mark = mark;
|
601
577
|
p->start = start;
|
602
578
|
}
|
579
|
+
|
580
|
+
void oj_set_parser_saj(ojParser p) {
|
581
|
+
Saj d = OJ_R_ALLOC(struct _saj);
|
582
|
+
|
583
|
+
oj_init_saj(p, d);
|
584
|
+
}
|
data/ext/oj/saj2.h
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
// Copyright (c) 2021, Peter Ohler, All rights reserved.
|
2
|
+
|
3
|
+
#include <ruby.h>
|
4
|
+
#include <stdbool.h>
|
5
|
+
|
6
|
+
struct _cache;
|
7
|
+
struct _ojParser;
|
8
|
+
|
9
|
+
typedef struct _saj {
|
10
|
+
VALUE handler;
|
11
|
+
VALUE *keys;
|
12
|
+
VALUE *tail;
|
13
|
+
size_t klen;
|
14
|
+
struct _cache *str_cache;
|
15
|
+
uint8_t cache_str;
|
16
|
+
bool cache_keys;
|
17
|
+
bool thread_safe;
|
18
|
+
} *Saj;
|
19
|
+
|
20
|
+
// Initialize the parser with the SAJ delegate. If the SAJ delegate is wrapped
|
21
|
+
// then this function is called first and then the parser functions can be
|
22
|
+
// replaced.
|
23
|
+
extern void oj_init_saj(struct _ojParser *p, Saj d);
|
data/ext/oj/scp.c
CHANGED
@@ -33,8 +33,7 @@ static VALUE noop_hash_key(ParseInfo pi, const char *key, size_t klen) {
|
|
33
33
|
return Qundef;
|
34
34
|
}
|
35
35
|
|
36
|
-
static void
|
37
|
-
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) {
|
38
37
|
}
|
39
38
|
|
40
39
|
static void noop_hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
|
@@ -91,12 +90,7 @@ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, c
|
|
91
90
|
volatile VALUE rstr = rb_str_new(str, len);
|
92
91
|
|
93
92
|
rstr = oj_encode(rstr);
|
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);
|
93
|
+
rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, kval), rstr);
|
100
94
|
}
|
101
95
|
|
102
96
|
static void hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
|
@@ -109,12 +103,7 @@ static void hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
|
|
109
103
|
}
|
110
104
|
|
111
105
|
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);
|
106
|
+
rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, kval), value);
|
118
107
|
}
|
119
108
|
|
120
109
|
static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|