oj 3.13.11 → 3.13.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/ext/oj/circarray.c +1 -1
- data/ext/oj/code.c +15 -22
- data/ext/oj/custom.c +28 -55
- data/ext/oj/dump.c +66 -87
- data/ext/oj/dump.h +12 -8
- data/ext/oj/dump_compat.c +43 -80
- data/ext/oj/dump_leaf.c +14 -58
- data/ext/oj/dump_object.c +28 -96
- data/ext/oj/dump_strict.c +12 -24
- data/ext/oj/fast.c +9 -9
- data/ext/oj/intern.c +9 -2
- data/ext/oj/intern.h +1 -1
- data/ext/oj/mimic_json.c +25 -23
- data/ext/oj/odd.c +83 -63
- data/ext/oj/odd.h +13 -13
- data/ext/oj/oj.c +28 -16
- data/ext/oj/oj.h +20 -2
- data/ext/oj/parse.c +3 -2
- data/ext/oj/parser.c +10 -15
- data/ext/oj/rails.c +38 -57
- data/ext/oj/rails.h +1 -1
- data/ext/oj/reader.c +2 -0
- data/ext/oj/saj.c +11 -23
- data/ext/oj/stream_writer.c +3 -1
- data/ext/oj/string_writer.c +12 -5
- data/ext/oj/wab.c +8 -8
- data/lib/oj/version.rb +1 -1
- data/test/bar.rb +1 -8
- data/test/foo.rb +3 -3
- data/test/perf_dump.rb +50 -0
- data/test/test_object.rb +12 -7
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7a88552e986523c822f5122a3ae557833daa68a31b606afd53d6a187b188e4b
|
4
|
+
data.tar.gz: b58d251e6020e4400322a37f2bfcbf1423578892bb9c6571ff07b782b248cbd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb0cd1c01c4cdaed0a21d31b27b02dafb222f104ac5698f146ed9bcf58325c3bdf99d8308f6638e7100fab14caeb46d103abb896d16d2dfcf5cdde1081b7838a
|
7
|
+
data.tar.gz: 1ebd2819902faba5ebddf98a384ee27b1d35820d8beaae42bc254809245d3bdfeefec587769aea7c5a63ca85625bc93e543c9d3b1d127f8c88c44f9c39117d0e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 3.13.12 - 2022-05-20
|
4
|
+
|
5
|
+
- Fixed crash on no arguments to pretty_generate. Now raises an exception.
|
6
|
+
- Register all classes and globals.
|
7
|
+
- Fixed memory issue with dumping.
|
8
|
+
|
3
9
|
## 3.13.11 - 2022-01-05
|
4
10
|
|
5
11
|
- Fixed write blocking failures on writes to a slow stream with larger writes.
|
data/ext/oj/circarray.c
CHANGED
data/ext/oj/code.c
CHANGED
@@ -140,21 +140,17 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
|
|
140
140
|
if (with_class) {
|
141
141
|
fill_indent(out, d2);
|
142
142
|
*out->cur++ = '"';
|
143
|
-
|
144
|
-
out->cur += out->opts->create_id_len;
|
143
|
+
APPEND_CHARS(out->cur, out->opts->create_id, out->opts->create_id_len);
|
145
144
|
*out->cur++ = '"';
|
146
145
|
if (0 < out->opts->dump_opts.before_size) {
|
147
|
-
|
148
|
-
out->cur += out->opts->dump_opts.before_size;
|
146
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
|
149
147
|
}
|
150
148
|
*out->cur++ = ':';
|
151
149
|
if (0 < out->opts->dump_opts.after_size) {
|
152
|
-
|
153
|
-
out->cur += out->opts->dump_opts.after_size;
|
150
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
|
154
151
|
}
|
155
152
|
*out->cur++ = '"';
|
156
|
-
|
157
|
-
out->cur += len;
|
153
|
+
APPEND_CHARS(out->cur, classname, len);
|
158
154
|
*out->cur++ = '"';
|
159
155
|
no_comma = false;
|
160
156
|
}
|
@@ -168,17 +164,14 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
|
|
168
164
|
}
|
169
165
|
fill_indent(out, d2);
|
170
166
|
*out->cur++ = '"';
|
171
|
-
|
172
|
-
out->cur += attrs->len;
|
167
|
+
APPEND_CHARS(out->cur, attrs->name, attrs->len);
|
173
168
|
*out->cur++ = '"';
|
174
169
|
if (0 < out->opts->dump_opts.before_size) {
|
175
|
-
|
176
|
-
out->cur += out->opts->dump_opts.before_size;
|
170
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
|
177
171
|
}
|
178
172
|
*out->cur++ = ':';
|
179
173
|
if (0 < out->opts->dump_opts.after_size) {
|
180
|
-
|
181
|
-
out->cur += out->opts->dump_opts.after_size;
|
174
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
|
182
175
|
}
|
183
176
|
if (Qundef == attrs->value) {
|
184
177
|
if (Qundef != attrs->time) {
|
@@ -190,10 +183,11 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
|
|
190
183
|
default: oj_dump_time(attrs->time, out, false); break;
|
191
184
|
}
|
192
185
|
} else {
|
193
|
-
char
|
194
|
-
char
|
195
|
-
int
|
196
|
-
long
|
186
|
+
char buf[32];
|
187
|
+
char *b = buf + sizeof(buf) - 1;
|
188
|
+
int neg = 0;
|
189
|
+
long num = attrs->num;
|
190
|
+
size_t cnt = 0;
|
197
191
|
|
198
192
|
if (0 > num) {
|
199
193
|
neg = 1;
|
@@ -212,10 +206,9 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
|
|
212
206
|
} else {
|
213
207
|
*b = '0';
|
214
208
|
}
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
}
|
209
|
+
cnt = sizeof(buf) - (b - buf) - 1;
|
210
|
+
assure_size(out, cnt);
|
211
|
+
APPEND_CHARS(out->cur, b, cnt);
|
219
212
|
}
|
220
213
|
} else {
|
221
214
|
oj_dump_compat_val(attrs->value, d3, out, true);
|
data/ext/oj/custom.c
CHANGED
@@ -295,15 +295,13 @@ static int hash_cb(VALUE key, VALUE value, VALUE ov) {
|
|
295
295
|
assure_size(out,
|
296
296
|
depth * out->opts->dump_opts.indent_size + out->opts->dump_opts.hash_size + 1);
|
297
297
|
if (0 < out->opts->dump_opts.hash_size) {
|
298
|
-
|
299
|
-
out->cur += out->opts->dump_opts.hash_size;
|
298
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.hash_nl, out->opts->dump_opts.hash_size);
|
300
299
|
}
|
301
300
|
if (0 < out->opts->dump_opts.indent_size) {
|
302
301
|
int i;
|
303
302
|
|
304
303
|
for (i = depth; 0 < i; i--) {
|
305
|
-
|
306
|
-
out->cur += out->opts->dump_opts.indent_size;
|
304
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.indent_str, out->opts->dump_opts.indent_size);
|
307
305
|
}
|
308
306
|
}
|
309
307
|
}
|
@@ -317,13 +315,11 @@ static int hash_cb(VALUE key, VALUE value, VALUE ov) {
|
|
317
315
|
} else {
|
318
316
|
assure_size(out, out->opts->dump_opts.before_size + out->opts->dump_opts.after_size + 2);
|
319
317
|
if (0 < out->opts->dump_opts.before_size) {
|
320
|
-
|
321
|
-
out->cur += out->opts->dump_opts.before_size;
|
318
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
|
322
319
|
}
|
323
320
|
*out->cur++ = ':';
|
324
321
|
if (0 < out->opts->dump_opts.after_size) {
|
325
|
-
|
326
|
-
out->cur += out->opts->dump_opts.after_size;
|
322
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
|
327
323
|
}
|
328
324
|
}
|
329
325
|
oj_dump_custom_val(value, depth, out, true);
|
@@ -344,8 +340,7 @@ static void dump_hash(VALUE obj, int depth, Out out, bool as_ok) {
|
|
344
340
|
cnt = (int)RHASH_SIZE(obj);
|
345
341
|
assure_size(out, 2);
|
346
342
|
if (0 == cnt) {
|
347
|
-
|
348
|
-
*out->cur++ = '}';
|
343
|
+
APPEND_CHARS(out->cur, "{}", 2);
|
349
344
|
} else {
|
350
345
|
*out->cur++ = '{';
|
351
346
|
out->depth = depth + 1;
|
@@ -361,15 +356,13 @@ static void dump_hash(VALUE obj, int depth, Out out, bool as_ok) {
|
|
361
356
|
out,
|
362
357
|
depth * out->opts->dump_opts.indent_size + out->opts->dump_opts.hash_size + 1);
|
363
358
|
if (0 < out->opts->dump_opts.hash_size) {
|
364
|
-
|
365
|
-
out->cur += out->opts->dump_opts.hash_size;
|
359
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.hash_nl, out->opts->dump_opts.hash_size);
|
366
360
|
}
|
367
361
|
if (0 < out->opts->dump_opts.indent_size) {
|
368
362
|
int i;
|
369
363
|
|
370
364
|
for (i = depth; 0 < i; i--) {
|
371
|
-
|
372
|
-
out->cur += out->opts->dump_opts.indent_size;
|
365
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.indent_str, out->opts->dump_opts.indent_size);
|
373
366
|
}
|
374
367
|
}
|
375
368
|
}
|
@@ -397,23 +390,18 @@ static void dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
|
|
397
390
|
assure_size(out, size);
|
398
391
|
fill_indent(out, d2);
|
399
392
|
*out->cur++ = '"';
|
400
|
-
|
401
|
-
out->cur += out->opts->create_id_len;
|
393
|
+
APPEND_CHARS(out->cur, out->opts->create_id, out->opts->create_id_len);
|
402
394
|
*out->cur++ = '"';
|
403
395
|
if (0 < out->opts->dump_opts.before_size) {
|
404
|
-
|
405
|
-
out->cur += out->opts->dump_opts.before_size;
|
396
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
|
406
397
|
}
|
407
398
|
*out->cur++ = ':';
|
408
399
|
if (0 < out->opts->dump_opts.after_size) {
|
409
|
-
|
410
|
-
out->cur += out->opts->dump_opts.after_size;
|
400
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
|
411
401
|
}
|
412
402
|
*out->cur++ = '"';
|
413
|
-
|
414
|
-
out->cur
|
415
|
-
*out->cur++ = '"';
|
416
|
-
*out->cur++ = ',';
|
403
|
+
APPEND_CHARS(out->cur, classname, clen);
|
404
|
+
APPEND_CHARS(out->cur, "\",", 2);
|
417
405
|
}
|
418
406
|
if (odd->raw) {
|
419
407
|
v = rb_funcall(obj, *odd->attrs, 0);
|
@@ -429,12 +417,9 @@ static void dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
|
|
429
417
|
assure_size(out, size);
|
430
418
|
fill_indent(out, d2);
|
431
419
|
*out->cur++ = '"';
|
432
|
-
|
433
|
-
out->cur
|
434
|
-
|
435
|
-
*out->cur++ = ':';
|
436
|
-
memcpy(out->cur, s, len);
|
437
|
-
out->cur += len;
|
420
|
+
APPEND_CHARS(out->cur, name, nlen);
|
421
|
+
APPEND_CHARS(out->cur, "\":", 2);
|
422
|
+
APPEND_CHARS(out->cur, s, len);
|
438
423
|
*out->cur = '\0';
|
439
424
|
}
|
440
425
|
} else {
|
@@ -514,8 +499,7 @@ static VALUE dump_common(VALUE obj, int depth, Out out) {
|
|
514
499
|
len = (int)RSTRING_LEN(rs);
|
515
500
|
|
516
501
|
assure_size(out, len + 1);
|
517
|
-
|
518
|
-
out->cur += len;
|
502
|
+
APPEND_CHARS(out->cur, s, len);
|
519
503
|
*out->cur = '\0';
|
520
504
|
} else if (Yes == out->opts->as_json && rb_respond_to(obj, oj_as_json_id)) {
|
521
505
|
volatile VALUE aj;
|
@@ -633,21 +617,17 @@ static void dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out)
|
|
633
617
|
assure_size(out, size);
|
634
618
|
fill_indent(out, d2);
|
635
619
|
*out->cur++ = '"';
|
636
|
-
|
637
|
-
out->cur += out->opts->create_id_len;
|
620
|
+
APPEND_CHARS(out->cur, out->opts->create_id, out->opts->create_id_len);
|
638
621
|
*out->cur++ = '"';
|
639
622
|
if (0 < out->opts->dump_opts.before_size) {
|
640
|
-
|
641
|
-
out->cur += out->opts->dump_opts.before_size;
|
623
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
|
642
624
|
}
|
643
625
|
*out->cur++ = ':';
|
644
626
|
if (0 < out->opts->dump_opts.after_size) {
|
645
|
-
|
646
|
-
out->cur += out->opts->dump_opts.after_size;
|
627
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
|
647
628
|
}
|
648
629
|
*out->cur++ = '"';
|
649
|
-
|
650
|
-
out->cur += len;
|
630
|
+
APPEND_CHARS(out->cur, classname, len);
|
651
631
|
*out->cur++ = '"';
|
652
632
|
class_written = true;
|
653
633
|
}
|
@@ -731,19 +711,17 @@ static void dump_array(VALUE a, int depth, Out out, bool as_ok) {
|
|
731
711
|
} else {
|
732
712
|
size = d2 * out->indent + 2;
|
733
713
|
}
|
714
|
+
assure_size(out, size * cnt);
|
734
715
|
cnt--;
|
735
716
|
for (i = 0; i <= cnt; i++) {
|
736
|
-
assure_size(out, size);
|
737
717
|
if (out->opts->dump_opts.use) {
|
738
718
|
if (0 < out->opts->dump_opts.array_size) {
|
739
|
-
|
740
|
-
out->cur += out->opts->dump_opts.array_size;
|
719
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.array_nl, out->opts->dump_opts.array_size);
|
741
720
|
}
|
742
721
|
if (0 < out->opts->dump_opts.indent_size) {
|
743
722
|
int i;
|
744
723
|
for (i = d2; 0 < i; i--) {
|
745
|
-
|
746
|
-
out->cur += out->opts->dump_opts.indent_size;
|
724
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.indent_str, out->opts->dump_opts.indent_size);
|
747
725
|
}
|
748
726
|
}
|
749
727
|
} else {
|
@@ -758,15 +736,13 @@ static void dump_array(VALUE a, int depth, Out out, bool as_ok) {
|
|
758
736
|
assure_size(out, size);
|
759
737
|
if (out->opts->dump_opts.use) {
|
760
738
|
if (0 < out->opts->dump_opts.array_size) {
|
761
|
-
|
762
|
-
out->cur += out->opts->dump_opts.array_size;
|
739
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.array_nl, out->opts->dump_opts.array_size);
|
763
740
|
}
|
764
741
|
if (0 < out->opts->dump_opts.indent_size) {
|
765
742
|
int i;
|
766
743
|
|
767
744
|
for (i = depth; 0 < i; i--) {
|
768
|
-
|
769
|
-
out->cur += out->opts->dump_opts.indent_size;
|
745
|
+
APPEND_CHARS(out->cur, out->opts->dump_opts.indent_str, out->opts->dump_opts.indent_size);
|
770
746
|
}
|
771
747
|
}
|
772
748
|
} else {
|
@@ -800,8 +776,7 @@ static void dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
|
|
800
776
|
*out->cur++ = '"';
|
801
777
|
oj_dump_custom_val(rb_funcall(obj, oj_begin_id, 0), d3, out, false);
|
802
778
|
assure_size(out, 3);
|
803
|
-
|
804
|
-
*out->cur++ = '.';
|
779
|
+
APPEND_CHARS(out->cur, "..", 2);
|
805
780
|
if (Qtrue == rb_funcall(obj, oj_exclude_end_id, 0)) {
|
806
781
|
*out->cur++ = '.';
|
807
782
|
}
|
@@ -844,10 +819,8 @@ static void dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
|
|
844
819
|
assure_size(out, size + len + 3);
|
845
820
|
fill_indent(out, d3);
|
846
821
|
*out->cur++ = '"';
|
847
|
-
|
848
|
-
out->cur
|
849
|
-
*out->cur++ = '"';
|
850
|
-
*out->cur++ = ':';
|
822
|
+
APPEND_CHARS(out->cur, name, len);
|
823
|
+
APPEND_CHARS(out->cur, "\":", 2);
|
851
824
|
oj_dump_custom_val(v, d3, out, true);
|
852
825
|
*out->cur++ = ',';
|
853
826
|
}
|