oj 3.13.21 → 3.13.22
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 +4 -0
- data/README.md +2 -0
- data/ext/oj/custom.c +21 -40
- data/ext/oj/fast.c +15 -13
- data/ext/oj/intern.c +6 -9
- data/ext/oj/introspect.c +96 -0
- data/ext/oj/object.c +33 -32
- data/ext/oj/oj.c +9 -1
- data/ext/oj/oj.h +3 -0
- data/ext/oj/parser.c +26 -0
- data/ext/oj/parser.h +11 -0
- data/ext/oj/saj2.c +56 -62
- data/ext/oj/saj2.h +23 -0
- data/ext/oj/usual.c +82 -129
- data/ext/oj/usual.h +68 -0
- data/ext/oj/val_stack.c +1 -1
- data/lib/oj/state.rb +1 -1
- data/lib/oj/version.rb +1 -1
- data/test/json_gem/json_generator_test.rb +3 -4
- data/test/json_gem/json_parser_test.rb +1 -3
- data/test/test_custom.rb +9 -10
- data/test/test_file.rb +3 -10
- data/test/test_gc.rb +0 -2
- data/test/test_integer_range.rb +0 -6
- data/test/test_object.rb +3 -48
- data/test/test_parser.rb +3 -19
- data/test/test_parser_debug.rb +27 -0
- data/test/test_scp.rb +2 -4
- data/test/test_various.rb +2 -3
- data/test/tests.rb +9 -0
- data/test/tests_mimic.rb +9 -0
- data/test/tests_mimic_addition.rb +9 -0
- metadata +6 -2
data/ext/oj/saj2.c
CHANGED
@@ -3,20 +3,10 @@
|
|
3
3
|
#include "cache.h"
|
4
4
|
#include "oj.h"
|
5
5
|
#include "parser.h"
|
6
|
-
|
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;
|
6
|
+
#include "saj2.h"
|
17
7
|
|
18
8
|
static VALUE get_key(ojParser p) {
|
19
|
-
|
9
|
+
Saj d = (Saj)p->ctx;
|
20
10
|
const char *key = buf_str(&p->key);
|
21
11
|
size_t len = buf_len(&p->key);
|
22
12
|
volatile VALUE rkey;
|
@@ -29,7 +19,7 @@ static VALUE get_key(ojParser p) {
|
|
29
19
|
return rkey;
|
30
20
|
}
|
31
21
|
|
32
|
-
static void push_key(
|
22
|
+
static void push_key(Saj d, VALUE key) {
|
33
23
|
if (d->klen <= (size_t)(d->tail - d->keys)) {
|
34
24
|
size_t off = d->tail - d->keys;
|
35
25
|
|
@@ -45,15 +35,15 @@ static void noop(ojParser p) {
|
|
45
35
|
}
|
46
36
|
|
47
37
|
static void open_object(ojParser p) {
|
48
|
-
rb_funcall(((
|
38
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_hash_start_id, 1, Qnil);
|
49
39
|
}
|
50
40
|
|
51
41
|
static void open_object_loc(ojParser p) {
|
52
|
-
rb_funcall(((
|
42
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_hash_start_id, 3, Qnil, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
|
53
43
|
}
|
54
44
|
|
55
45
|
static void open_object_key(ojParser p) {
|
56
|
-
|
46
|
+
Saj d = (Saj)p->ctx;
|
57
47
|
volatile VALUE key = get_key(p);
|
58
48
|
|
59
49
|
push_key(d, key);
|
@@ -61,7 +51,7 @@ static void open_object_key(ojParser p) {
|
|
61
51
|
}
|
62
52
|
|
63
53
|
static void open_object_loc_key(ojParser p) {
|
64
|
-
|
54
|
+
Saj d = (Saj)p->ctx;
|
65
55
|
volatile VALUE key = get_key(p);
|
66
56
|
|
67
57
|
push_key(d, key);
|
@@ -69,15 +59,15 @@ static void open_object_loc_key(ojParser p) {
|
|
69
59
|
}
|
70
60
|
|
71
61
|
static void open_array(ojParser p) {
|
72
|
-
rb_funcall(((
|
62
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_array_start_id, 1, Qnil);
|
73
63
|
}
|
74
64
|
|
75
65
|
static void open_array_loc(ojParser p) {
|
76
|
-
rb_funcall(((
|
66
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_array_start_id, 3, Qnil, LONG2FIX(p->line), LONG2FIX(p->cur - p->col));
|
77
67
|
}
|
78
68
|
|
79
69
|
static void open_array_key(ojParser p) {
|
80
|
-
|
70
|
+
Saj d = (Saj)p->ctx;
|
81
71
|
volatile VALUE key = get_key(p);
|
82
72
|
|
83
73
|
push_key(d, key);
|
@@ -85,7 +75,7 @@ static void open_array_key(ojParser p) {
|
|
85
75
|
}
|
86
76
|
|
87
77
|
static void open_array_loc_key(ojParser p) {
|
88
|
-
|
78
|
+
Saj d = (Saj)p->ctx;
|
89
79
|
volatile VALUE key = get_key(p);
|
90
80
|
|
91
81
|
push_key(d, key);
|
@@ -93,7 +83,7 @@ static void open_array_loc_key(ojParser p) {
|
|
93
83
|
}
|
94
84
|
|
95
85
|
static void close_object(ojParser p) {
|
96
|
-
|
86
|
+
Saj d = (Saj)p->ctx;
|
97
87
|
VALUE key = Qnil;
|
98
88
|
|
99
89
|
if (OBJECT_FUN == p->stack[p->depth]) {
|
@@ -107,7 +97,7 @@ static void close_object(ojParser p) {
|
|
107
97
|
}
|
108
98
|
|
109
99
|
static void close_object_loc(ojParser p) {
|
110
|
-
|
100
|
+
Saj d = (Saj)p->ctx;
|
111
101
|
VALUE key = Qnil;
|
112
102
|
|
113
103
|
if (OBJECT_FUN == p->stack[p->depth]) {
|
@@ -121,7 +111,7 @@ static void close_object_loc(ojParser p) {
|
|
121
111
|
}
|
122
112
|
|
123
113
|
static void close_array(ojParser p) {
|
124
|
-
|
114
|
+
Saj d = (Saj)p->ctx;
|
125
115
|
VALUE key = Qnil;
|
126
116
|
|
127
117
|
if (OBJECT_FUN == p->stack[p->depth]) {
|
@@ -135,7 +125,7 @@ static void close_array(ojParser p) {
|
|
135
125
|
}
|
136
126
|
|
137
127
|
static void close_array_loc(ojParser p) {
|
138
|
-
|
128
|
+
Saj d = (Saj)p->ctx;
|
139
129
|
VALUE key = Qnil;
|
140
130
|
|
141
131
|
if (OBJECT_FUN == p->stack[p->depth]) {
|
@@ -149,11 +139,11 @@ static void close_array_loc(ojParser p) {
|
|
149
139
|
}
|
150
140
|
|
151
141
|
static void add_null(ojParser p) {
|
152
|
-
rb_funcall(((
|
142
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, Qnil, Qnil);
|
153
143
|
}
|
154
144
|
|
155
145
|
static void add_null_loc(ojParser p) {
|
156
|
-
rb_funcall(((
|
146
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
157
147
|
oj_add_value_id,
|
158
148
|
4,
|
159
149
|
Qnil,
|
@@ -163,11 +153,11 @@ static void add_null_loc(ojParser p) {
|
|
163
153
|
}
|
164
154
|
|
165
155
|
static void add_null_key(ojParser p) {
|
166
|
-
rb_funcall(((
|
156
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, Qnil, get_key(p));
|
167
157
|
}
|
168
158
|
|
169
159
|
static void add_null_key_loc(ojParser p) {
|
170
|
-
rb_funcall(((
|
160
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
171
161
|
oj_add_value_id,
|
172
162
|
4,
|
173
163
|
Qnil,
|
@@ -177,11 +167,11 @@ static void add_null_key_loc(ojParser p) {
|
|
177
167
|
}
|
178
168
|
|
179
169
|
static void add_true(ojParser p) {
|
180
|
-
rb_funcall(((
|
170
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, Qtrue, Qnil);
|
181
171
|
}
|
182
172
|
|
183
173
|
static void add_true_loc(ojParser p) {
|
184
|
-
rb_funcall(((
|
174
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
185
175
|
oj_add_value_id,
|
186
176
|
4,
|
187
177
|
Qtrue,
|
@@ -191,11 +181,11 @@ static void add_true_loc(ojParser p) {
|
|
191
181
|
}
|
192
182
|
|
193
183
|
static void add_true_key(ojParser p) {
|
194
|
-
rb_funcall(((
|
184
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, Qtrue, get_key(p));
|
195
185
|
}
|
196
186
|
|
197
187
|
static void add_true_key_loc(ojParser p) {
|
198
|
-
rb_funcall(((
|
188
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
199
189
|
oj_add_value_id,
|
200
190
|
4,
|
201
191
|
Qtrue,
|
@@ -205,11 +195,11 @@ static void add_true_key_loc(ojParser p) {
|
|
205
195
|
}
|
206
196
|
|
207
197
|
static void add_false(ojParser p) {
|
208
|
-
rb_funcall(((
|
198
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, Qfalse, Qnil);
|
209
199
|
}
|
210
200
|
|
211
201
|
static void add_false_loc(ojParser p) {
|
212
|
-
rb_funcall(((
|
202
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
213
203
|
oj_add_value_id,
|
214
204
|
4,
|
215
205
|
Qfalse,
|
@@ -219,11 +209,11 @@ static void add_false_loc(ojParser p) {
|
|
219
209
|
}
|
220
210
|
|
221
211
|
static void add_false_key(ojParser p) {
|
222
|
-
rb_funcall(((
|
212
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, Qfalse, get_key(p));
|
223
213
|
}
|
224
214
|
|
225
215
|
static void add_false_key_loc(ojParser p) {
|
226
|
-
rb_funcall(((
|
216
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
227
217
|
oj_add_value_id,
|
228
218
|
4,
|
229
219
|
Qfalse,
|
@@ -233,11 +223,11 @@ static void add_false_key_loc(ojParser p) {
|
|
233
223
|
}
|
234
224
|
|
235
225
|
static void add_int(ojParser p) {
|
236
|
-
rb_funcall(((
|
226
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, LONG2NUM(p->num.fixnum), Qnil);
|
237
227
|
}
|
238
228
|
|
239
229
|
static void add_int_loc(ojParser p) {
|
240
|
-
rb_funcall(((
|
230
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
241
231
|
oj_add_value_id,
|
242
232
|
4,
|
243
233
|
LONG2NUM(p->num.fixnum),
|
@@ -247,11 +237,11 @@ static void add_int_loc(ojParser p) {
|
|
247
237
|
}
|
248
238
|
|
249
239
|
static void add_int_key(ojParser p) {
|
250
|
-
rb_funcall(((
|
240
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, LONG2NUM(p->num.fixnum), get_key(p));
|
251
241
|
}
|
252
242
|
|
253
243
|
static void add_int_key_loc(ojParser p) {
|
254
|
-
rb_funcall(((
|
244
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
255
245
|
oj_add_value_id,
|
256
246
|
4,
|
257
247
|
LONG2NUM(p->num.fixnum),
|
@@ -261,11 +251,11 @@ static void add_int_key_loc(ojParser p) {
|
|
261
251
|
}
|
262
252
|
|
263
253
|
static void add_float(ojParser p) {
|
264
|
-
rb_funcall(((
|
254
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, rb_float_new(p->num.dub), Qnil);
|
265
255
|
}
|
266
256
|
|
267
257
|
static void add_float_loc(ojParser p) {
|
268
|
-
rb_funcall(((
|
258
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
269
259
|
oj_add_value_id,
|
270
260
|
4,
|
271
261
|
rb_float_new(p->num.dub),
|
@@ -275,11 +265,11 @@ static void add_float_loc(ojParser p) {
|
|
275
265
|
}
|
276
266
|
|
277
267
|
static void add_float_key(ojParser p) {
|
278
|
-
rb_funcall(((
|
268
|
+
rb_funcall(((Saj)p->ctx)->handler, oj_add_value_id, 2, rb_float_new(p->num.dub), get_key(p));
|
279
269
|
}
|
280
270
|
|
281
271
|
static void add_float_key_loc(ojParser p) {
|
282
|
-
rb_funcall(((
|
272
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
283
273
|
oj_add_value_id,
|
284
274
|
4,
|
285
275
|
rb_float_new(p->num.dub),
|
@@ -289,7 +279,7 @@ static void add_float_key_loc(ojParser p) {
|
|
289
279
|
}
|
290
280
|
|
291
281
|
static void add_big(ojParser p) {
|
292
|
-
rb_funcall(((
|
282
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
293
283
|
oj_add_value_id,
|
294
284
|
2,
|
295
285
|
rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new(buf_str(&p->buf), buf_len(&p->buf))),
|
@@ -297,7 +287,7 @@ static void add_big(ojParser p) {
|
|
297
287
|
}
|
298
288
|
|
299
289
|
static void add_big_loc(ojParser p) {
|
300
|
-
rb_funcall(((
|
290
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
301
291
|
oj_add_value_id,
|
302
292
|
4,
|
303
293
|
rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new(buf_str(&p->buf), buf_len(&p->buf))),
|
@@ -307,7 +297,7 @@ static void add_big_loc(ojParser p) {
|
|
307
297
|
}
|
308
298
|
|
309
299
|
static void add_big_key(ojParser p) {
|
310
|
-
rb_funcall(((
|
300
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
311
301
|
oj_add_value_id,
|
312
302
|
2,
|
313
303
|
rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new(buf_str(&p->buf), buf_len(&p->buf))),
|
@@ -315,7 +305,7 @@ static void add_big_key(ojParser p) {
|
|
315
305
|
}
|
316
306
|
|
317
307
|
static void add_big_key_loc(ojParser p) {
|
318
|
-
rb_funcall(((
|
308
|
+
rb_funcall(((Saj)p->ctx)->handler,
|
319
309
|
oj_add_value_id,
|
320
310
|
4,
|
321
311
|
rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new(buf_str(&p->buf), buf_len(&p->buf))),
|
@@ -325,7 +315,7 @@ static void add_big_key_loc(ojParser p) {
|
|
325
315
|
}
|
326
316
|
|
327
317
|
static void add_str(ojParser p) {
|
328
|
-
|
318
|
+
Saj d = (Saj)p->ctx;
|
329
319
|
volatile VALUE rstr;
|
330
320
|
const char *str = buf_str(&p->buf);
|
331
321
|
size_t len = buf_len(&p->buf);
|
@@ -339,7 +329,7 @@ static void add_str(ojParser p) {
|
|
339
329
|
}
|
340
330
|
|
341
331
|
static void add_str_loc(ojParser p) {
|
342
|
-
|
332
|
+
Saj d = (Saj)p->ctx;
|
343
333
|
volatile VALUE rstr;
|
344
334
|
const char *str = buf_str(&p->buf);
|
345
335
|
size_t len = buf_len(&p->buf);
|
@@ -353,7 +343,7 @@ static void add_str_loc(ojParser p) {
|
|
353
343
|
}
|
354
344
|
|
355
345
|
static void add_str_key(ojParser p) {
|
356
|
-
|
346
|
+
Saj d = (Saj)p->ctx;
|
357
347
|
volatile VALUE rstr;
|
358
348
|
const char *str = buf_str(&p->buf);
|
359
349
|
size_t len = buf_len(&p->buf);
|
@@ -367,7 +357,7 @@ static void add_str_key(ojParser p) {
|
|
367
357
|
}
|
368
358
|
|
369
359
|
static void add_str_key_loc(ojParser p) {
|
370
|
-
|
360
|
+
Saj d = (Saj)p->ctx;
|
371
361
|
volatile VALUE rstr;
|
372
362
|
const char *str = buf_str(&p->buf);
|
373
363
|
size_t len = buf_len(&p->buf);
|
@@ -400,7 +390,7 @@ static void reset(ojParser p) {
|
|
400
390
|
}
|
401
391
|
|
402
392
|
static VALUE option(ojParser p, const char *key, VALUE value) {
|
403
|
-
|
393
|
+
Saj d = (Saj)p->ctx;
|
404
394
|
|
405
395
|
if (0 == strcmp(key, "handler")) {
|
406
396
|
return d->handler;
|
@@ -537,7 +527,7 @@ static VALUE option(ojParser p, const char *key, VALUE value) {
|
|
537
527
|
|
538
528
|
return INT2NUM((int)d->cache_str);
|
539
529
|
}
|
540
|
-
rb_raise(rb_eArgError, "%s is not an option for the SAJ (Simple API for JSON)
|
530
|
+
rb_raise(rb_eArgError, "%s is not an option for the SAJ (Simple API for JSON) saj", key);
|
541
531
|
|
542
532
|
return Qnil; // Never reached due to the raise but required by the compiler.
|
543
533
|
}
|
@@ -547,13 +537,13 @@ static VALUE result(ojParser p) {
|
|
547
537
|
}
|
548
538
|
|
549
539
|
static void start(ojParser p) {
|
550
|
-
|
540
|
+
Saj d = (Saj)p->ctx;
|
551
541
|
|
552
542
|
d->tail = d->keys;
|
553
543
|
}
|
554
544
|
|
555
545
|
static void dfree(ojParser p) {
|
556
|
-
|
546
|
+
Saj d = (Saj)p->ctx;
|
557
547
|
|
558
548
|
if (NULL != d->keys) {
|
559
549
|
xfree(d->keys);
|
@@ -563,10 +553,10 @@ static void dfree(ojParser p) {
|
|
563
553
|
}
|
564
554
|
|
565
555
|
static void mark(ojParser p) {
|
566
|
-
if (NULL == p->ctx) {
|
556
|
+
if (NULL == p || NULL == p->ctx) {
|
567
557
|
return;
|
568
558
|
}
|
569
|
-
|
559
|
+
Saj d = (Saj)p->ctx;
|
570
560
|
VALUE *kp;
|
571
561
|
|
572
562
|
cache_mark(d->str_cache);
|
@@ -584,9 +574,7 @@ static VALUE form_str(const char *str, size_t len) {
|
|
584
574
|
return rb_str_freeze(rb_utf8_str_new(str, len));
|
585
575
|
}
|
586
576
|
|
587
|
-
void
|
588
|
-
Delegate d = ALLOC(struct _delegate);
|
589
|
-
|
577
|
+
void oj_init_saj(ojParser p, Saj d) {
|
590
578
|
d->klen = 256;
|
591
579
|
d->keys = ALLOC_N(VALUE, d->klen);
|
592
580
|
d->tail = d->keys;
|
@@ -600,3 +588,9 @@ void oj_set_parser_saj(ojParser p) {
|
|
600
588
|
p->mark = mark;
|
601
589
|
p->start = start;
|
602
590
|
}
|
591
|
+
|
592
|
+
void oj_set_parser_saj(ojParser p) {
|
593
|
+
Saj d = ALLOC(struct _saj);
|
594
|
+
|
595
|
+
oj_init_saj(p, d);
|
596
|
+
}
|
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);
|