oj 3.14.2 → 3.14.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +0 -1
- data/ext/oj/buf.h +2 -2
- data/ext/oj/cache.c +16 -16
- data/ext/oj/cache8.c +7 -7
- data/ext/oj/circarray.c +2 -1
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +2 -2
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +6 -14
- data/ext/oj/custom.c +1 -1
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +16 -16
- data/ext/oj/dump_compat.c +551 -576
- data/ext/oj/dump_leaf.c +3 -5
- data/ext/oj/dump_object.c +35 -36
- data/ext/oj/dump_strict.c +2 -4
- 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 +1 -1
- data/ext/oj/fast.c +24 -38
- data/ext/oj/intern.c +38 -42
- data/ext/oj/intern.h +3 -7
- data/ext/oj/mem.c +211 -217
- data/ext/oj/mem.h +10 -10
- data/ext/oj/mimic_json.c +18 -24
- data/ext/oj/object.c +5 -5
- data/ext/oj/odd.c +2 -1
- data/ext/oj/odd.h +4 -4
- data/ext/oj/oj.c +60 -81
- data/ext/oj/oj.h +53 -54
- data/ext/oj/parse.c +55 -118
- data/ext/oj/parse.h +5 -10
- data/ext/oj/parser.c +7 -8
- data/ext/oj/parser.h +7 -8
- data/ext/oj/rails.c +28 -59
- data/ext/oj/reader.c +5 -9
- data/ext/oj/reader.h +1 -1
- data/ext/oj/resolve.c +3 -4
- data/ext/oj/rxclass.c +1 -1
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +4 -4
- data/ext/oj/saj2.c +32 -49
- data/ext/oj/saj2.h +1 -1
- data/ext/oj/scp.c +3 -14
- data/ext/oj/sparse.c +18 -67
- data/ext/oj/stream_writer.c +5 -18
- data/ext/oj/strict.c +7 -13
- data/ext/oj/string_writer.c +6 -14
- data/ext/oj/trace.h +27 -16
- data/ext/oj/usual.c +62 -61
- data/ext/oj/usual.h +6 -6
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.h +4 -4
- data/ext/oj/wab.c +7 -9
- data/lib/oj/active_support_helper.rb +0 -1
- 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 +4 -2
- data/lib/oj/mimic.rb +4 -2
- data/lib/oj/state.rb +8 -5
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +0 -1
- data/test/_test_active.rb +0 -1
- data/test/_test_active_mimic.rb +0 -1
- data/test/_test_mimic_rails.rb +0 -1
- data/test/activerecord/result_test.rb +5 -6
- data/test/bar.rb +3 -3
- data/test/files.rb +1 -1
- data/test/foo.rb +5 -48
- data/test/helper.rb +1 -4
- 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 +4 -4
- 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 +43 -32
- data/test/json_gem/json_generic_object_test.rb +11 -11
- data/test/json_gem/json_parser_test.rb +46 -46
- data/test/json_gem/json_string_matching_test.rb +9 -9
- data/test/mem.rb +7 -7
- data/test/perf.rb +2 -2
- data/test/perf_compat.rb +1 -1
- data/test/perf_fast.rb +1 -1
- data/test/perf_file.rb +2 -2
- data/test/perf_object.rb +1 -2
- data/test/perf_once.rb +4 -4
- data/test/perf_parser.rb +1 -2
- data/test/perf_saj.rb +1 -2
- data/test/perf_scp.rb +1 -1
- data/test/perf_simple.rb +3 -3
- data/test/perf_strict.rb +1 -1
- data/test/perf_wab.rb +1 -1
- 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 +2 -3
- data/test/sample_json.rb +0 -1
- data/test/test_compat.rb +11 -9
- data/test/test_custom.rb +5 -9
- data/test/test_debian.rb +1 -1
- data/test/test_fast.rb +10 -20
- data/test/test_file.rb +8 -8
- data/test/test_integer_range.rb +2 -2
- data/test/test_null.rb +5 -3
- data/test/test_object.rb +6 -5
- data/test/test_parser_saj.rb +23 -21
- data/test/test_parser_usual.rb +3 -3
- data/test/test_saj.rb +2 -0
- data/test/test_scp.rb +6 -6
- data/test/test_strict.rb +6 -4
- data/test/test_various.rb +21 -24
- data/test/test_wab.rb +6 -5
- data/test/test_writer.rb +1 -1
- metadata +17 -26
- 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/ext/oj/sparse.c
CHANGED
@@ -7,10 +7,10 @@
|
|
7
7
|
#include <string.h>
|
8
8
|
#include <unistd.h>
|
9
9
|
|
10
|
-
#include "mem.h"
|
11
10
|
#include "buf.h"
|
12
11
|
#include "encode.h"
|
13
12
|
#include "intern.h" // for oj_strndup()
|
13
|
+
#include "mem.h"
|
14
14
|
#include "oj.h"
|
15
15
|
#include "parse.h"
|
16
16
|
#include "val_stack.h"
|
@@ -213,11 +213,7 @@ static void read_escaped_str(ParseInfo pi) {
|
|
213
213
|
}
|
214
214
|
while ('\"' != (c = reader_get(&pi->rd))) {
|
215
215
|
if ('\0' == c) {
|
216
|
-
oj_set_error_at(pi,
|
217
|
-
oj_parse_error_class,
|
218
|
-
__FILE__,
|
219
|
-
__LINE__,
|
220
|
-
"quoted string not terminated");
|
216
|
+
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "quoted string not terminated");
|
221
217
|
buf_cleanup(&buf);
|
222
218
|
return;
|
223
219
|
} else if ('\\' == c) {
|
@@ -250,11 +246,7 @@ static void read_escaped_str(ParseInfo pi) {
|
|
250
246
|
reader_backup(&pi->rd);
|
251
247
|
break;
|
252
248
|
}
|
253
|
-
oj_set_error_at(pi,
|
254
|
-
oj_parse_error_class,
|
255
|
-
__FILE__,
|
256
|
-
__LINE__,
|
257
|
-
"invalid escaped character");
|
249
|
+
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "invalid escaped character");
|
258
250
|
buf_cleanup(&buf);
|
259
251
|
return;
|
260
252
|
}
|
@@ -278,11 +270,7 @@ static void read_escaped_str(ParseInfo pi) {
|
|
278
270
|
buf_append(&buf, c);
|
279
271
|
break;
|
280
272
|
}
|
281
|
-
oj_set_error_at(pi,
|
282
|
-
oj_parse_error_class,
|
283
|
-
__FILE__,
|
284
|
-
__LINE__,
|
285
|
-
"invalid escaped character");
|
273
|
+
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "invalid escaped character");
|
286
274
|
buf_cleanup(&buf);
|
287
275
|
return;
|
288
276
|
}
|
@@ -346,11 +334,7 @@ static void read_str(ParseInfo pi) {
|
|
346
334
|
reader_protect(&pi->rd);
|
347
335
|
while ('\"' != (c = reader_get(&pi->rd))) {
|
348
336
|
if ('\0' == c) {
|
349
|
-
oj_set_error_at(pi,
|
350
|
-
oj_parse_error_class,
|
351
|
-
__FILE__,
|
352
|
-
__LINE__,
|
353
|
-
"quoted string not terminated");
|
337
|
+
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "quoted string not terminated");
|
354
338
|
return;
|
355
339
|
} else if ('\\' == c) {
|
356
340
|
reader_backup(&pi->rd);
|
@@ -430,7 +414,7 @@ static void read_num(ParseInfo pi) {
|
|
430
414
|
ni.no_big = !pi->options.compat_bigdec;
|
431
415
|
ni.bigdec_load = pi->options.compat_bigdec;
|
432
416
|
} else {
|
433
|
-
ni.no_big
|
417
|
+
ni.no_big = (FloatDec == pi->options.bigdec_load || FastDec == pi->options.bigdec_load ||
|
434
418
|
RubyDec == pi->options.bigdec_load);
|
435
419
|
ni.bigdec_load = pi->options.bigdec_load;
|
436
420
|
}
|
@@ -444,18 +428,10 @@ static void read_num(ParseInfo pi) {
|
|
444
428
|
}
|
445
429
|
if ('I' == c) {
|
446
430
|
if (No == pi->options.allow_nan) {
|
447
|
-
oj_set_error_at(pi,
|
448
|
-
oj_parse_error_class,
|
449
|
-
__FILE__,
|
450
|
-
__LINE__,
|
451
|
-
"not a number or other value");
|
431
|
+
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
|
452
432
|
return;
|
453
433
|
} else if (0 != reader_expect(&pi->rd, "nfinity")) {
|
454
|
-
oj_set_error_at(pi,
|
455
|
-
oj_parse_error_class,
|
456
|
-
__FILE__,
|
457
|
-
__LINE__,
|
458
|
-
"not a number or other value");
|
434
|
+
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
|
459
435
|
return;
|
460
436
|
}
|
461
437
|
ni.infinity = 1;
|
@@ -477,11 +453,7 @@ static void read_num(ParseInfo pi) {
|
|
477
453
|
|
478
454
|
if (0 < d) {
|
479
455
|
if (zero1 && CompatMode == pi->options.mode) {
|
480
|
-
oj_set_error_at(pi,
|
481
|
-
oj_parse_error_class,
|
482
|
-
__FILE__,
|
483
|
-
__LINE__,
|
484
|
-
"not a number");
|
456
|
+
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number");
|
485
457
|
return;
|
486
458
|
}
|
487
459
|
zero1 = false;
|
@@ -592,7 +564,7 @@ static void read_nan(ParseInfo pi) {
|
|
592
564
|
ni.no_big = !pi->options.compat_bigdec;
|
593
565
|
ni.bigdec_load = pi->options.compat_bigdec;
|
594
566
|
} else {
|
595
|
-
ni.no_big
|
567
|
+
ni.no_big = (FloatDec == pi->options.bigdec_load || FastDec == pi->options.bigdec_load ||
|
596
568
|
RubyDec == pi->options.bigdec_load);
|
597
569
|
ni.bigdec_load = pi->options.bigdec_load;
|
598
570
|
}
|
@@ -717,11 +689,7 @@ void oj_sparse2(ParseInfo pi) {
|
|
717
689
|
case '"': read_str(pi); break;
|
718
690
|
case '+':
|
719
691
|
if (CompatMode == pi->options.mode) {
|
720
|
-
oj_set_error_at(pi,
|
721
|
-
oj_parse_error_class,
|
722
|
-
__FILE__,
|
723
|
-
__LINE__,
|
724
|
-
"unexpected character");
|
692
|
+
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "unexpected character");
|
725
693
|
return;
|
726
694
|
}
|
727
695
|
pi->cur--;
|
@@ -746,11 +714,7 @@ void oj_sparse2(ParseInfo pi) {
|
|
746
714
|
reader_backup(&pi->rd);
|
747
715
|
read_num(pi);
|
748
716
|
} else {
|
749
|
-
oj_set_error_at(pi,
|
750
|
-
oj_parse_error_class,
|
751
|
-
__FILE__,
|
752
|
-
__LINE__,
|
753
|
-
"unexpected character");
|
717
|
+
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "unexpected character");
|
754
718
|
return;
|
755
719
|
}
|
756
720
|
break;
|
@@ -758,11 +722,7 @@ void oj_sparse2(ParseInfo pi) {
|
|
758
722
|
if (Yes == pi->options.allow_nan) {
|
759
723
|
read_nan(pi);
|
760
724
|
} else {
|
761
|
-
oj_set_error_at(pi,
|
762
|
-
oj_parse_error_class,
|
763
|
-
__FILE__,
|
764
|
-
__LINE__,
|
765
|
-
"unexpected character");
|
725
|
+
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "unexpected character");
|
766
726
|
return;
|
767
727
|
}
|
768
728
|
break;
|
@@ -800,8 +760,7 @@ void oj_sparse2(ParseInfo pi) {
|
|
800
760
|
ni.no_big = !pi->options.compat_bigdec;
|
801
761
|
ni.bigdec_load = pi->options.compat_bigdec;
|
802
762
|
} else {
|
803
|
-
ni.no_big = (FloatDec == pi->options.bigdec_load ||
|
804
|
-
FastDec == pi->options.bigdec_load ||
|
763
|
+
ni.no_big = (FloatDec == pi->options.bigdec_load || FastDec == pi->options.bigdec_load ||
|
805
764
|
RubyDec == pi->options.bigdec_load);
|
806
765
|
ni.bigdec_load = pi->options.bigdec_load;
|
807
766
|
}
|
@@ -814,13 +773,7 @@ void oj_sparse2(ParseInfo pi) {
|
|
814
773
|
case '/': skip_comment(pi); break;
|
815
774
|
case '\0': return;
|
816
775
|
default:
|
817
|
-
oj_set_error_at(pi,
|
818
|
-
oj_parse_error_class,
|
819
|
-
__FILE__,
|
820
|
-
__LINE__,
|
821
|
-
"unexpected character '%c' [0x%02x]",
|
822
|
-
c,
|
823
|
-
c);
|
776
|
+
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "unexpected character '%c' [0x%02x]", c, c);
|
824
777
|
return;
|
825
778
|
}
|
826
779
|
if (err_has(&pi->err)) {
|
@@ -879,8 +832,8 @@ oj_pi_sparse(int argc, VALUE *argv, ParseInfo pi, int fd) {
|
|
879
832
|
} else {
|
880
833
|
rb_raise(rb_eTypeError, "Nil is not a valid JSON source.");
|
881
834
|
}
|
882
|
-
} else if (CompatMode == pi->options.mode && T_STRING == rb_type(input) &&
|
883
|
-
|
835
|
+
} else if (CompatMode == pi->options.mode && T_STRING == rb_type(input) && No == pi->options.nilnil &&
|
836
|
+
0 == RSTRING_LEN(input)) {
|
884
837
|
rb_raise(oj_json_parser_error_class, "An empty string is not a valid JSON string.");
|
885
838
|
}
|
886
839
|
if (rb_block_given_p()) {
|
@@ -933,9 +886,7 @@ oj_pi_sparse(int argc, VALUE *argv, ParseInfo pi, int fd) {
|
|
933
886
|
switch (v->next) {
|
934
887
|
case NEXT_ARRAY_NEW:
|
935
888
|
case NEXT_ARRAY_ELEMENT:
|
936
|
-
case NEXT_ARRAY_COMMA:
|
937
|
-
oj_set_error_at(pi, err_class, __FILE__, __LINE__, "Array not terminated");
|
938
|
-
break;
|
889
|
+
case NEXT_ARRAY_COMMA: oj_set_error_at(pi, err_class, __FILE__, __LINE__, "Array not terminated"); break;
|
939
890
|
case NEXT_HASH_NEW:
|
940
891
|
case NEXT_HASH_KEY:
|
941
892
|
case NEXT_HASH_COLON:
|
data/ext/oj/stream_writer.c
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
#include <errno.h>
|
5
5
|
#include <ruby.h>
|
6
6
|
|
7
|
-
#include "mem.h"
|
8
7
|
#include "encode.h"
|
8
|
+
#include "mem.h"
|
9
9
|
|
10
10
|
extern VALUE Oj;
|
11
11
|
|
@@ -83,8 +83,8 @@ static VALUE stream_writer_new(int argc, VALUE *argv, VALUE self) {
|
|
83
83
|
if (oj_stringio_class == clas) {
|
84
84
|
type = STRING_IO;
|
85
85
|
#if !IS_WINDOWS
|
86
|
-
} else if (rb_respond_to(stream, oj_fileno_id) &&
|
87
|
-
|
86
|
+
} else if (rb_respond_to(stream, oj_fileno_id) && Qnil != (s = rb_funcall(stream, oj_fileno_id, 0)) &&
|
87
|
+
0 != (fd = FIX2INT(s))) {
|
88
88
|
type = FILE_IO;
|
89
89
|
#endif
|
90
90
|
} else if (rb_respond_to(stream, oj_write_id)) {
|
@@ -102,15 +102,10 @@ static VALUE stream_writer_new(int argc, VALUE *argv, VALUE self) {
|
|
102
102
|
rb_gc_register_address(&buffer_size_sym);
|
103
103
|
}
|
104
104
|
if (Qnil != (v = rb_hash_lookup(argv[1], buffer_size_sym))) {
|
105
|
-
#ifdef RUBY_INTEGER_UNIFICATION
|
106
105
|
if (rb_cInteger != rb_obj_class(v)) {
|
106
|
+
OJ_R_FREE(sw);
|
107
107
|
rb_raise(rb_eArgError, ":buffer size must be a Integer.");
|
108
108
|
}
|
109
|
-
#else
|
110
|
-
if (T_FIXNUM != rb_type(v)) {
|
111
|
-
rb_raise(rb_eArgError, ":buffer size must be a Integer.");
|
112
|
-
}
|
113
|
-
#endif
|
114
109
|
buf_size = FIX2INT(v);
|
115
110
|
}
|
116
111
|
oj_str_writer_init(&sw->sw, buf_size);
|
@@ -140,7 +135,6 @@ static VALUE stream_writer_new(int argc, VALUE *argv, VALUE self) {
|
|
140
135
|
static VALUE stream_writer_push_key(VALUE self, VALUE key) {
|
141
136
|
StreamWriter sw = (StreamWriter)DATA_PTR(self);
|
142
137
|
|
143
|
-
rb_check_type(key, T_STRING);
|
144
138
|
oj_str_writer_push_key(&sw->sw, StringValuePtr(key));
|
145
139
|
if (sw->flush_limit < sw->sw.out.cur - sw->sw.out.buf) {
|
146
140
|
stream_writer_write(sw);
|
@@ -165,7 +159,6 @@ static VALUE stream_writer_push_object(int argc, VALUE *argv, VALUE self) {
|
|
165
159
|
if (Qnil == argv[0]) {
|
166
160
|
oj_str_writer_push_object(&sw->sw, 0);
|
167
161
|
} else {
|
168
|
-
rb_check_type(argv[0], T_STRING);
|
169
162
|
oj_str_writer_push_object(&sw->sw, StringValuePtr(argv[0]));
|
170
163
|
}
|
171
164
|
break;
|
@@ -194,7 +187,6 @@ static VALUE stream_writer_push_array(int argc, VALUE *argv, VALUE self) {
|
|
194
187
|
if (Qnil == argv[0]) {
|
195
188
|
oj_str_writer_push_array(&sw->sw, 0);
|
196
189
|
} else {
|
197
|
-
rb_check_type(argv[0], T_STRING);
|
198
190
|
oj_str_writer_push_array(&sw->sw, StringValuePtr(argv[0]));
|
199
191
|
}
|
200
192
|
break;
|
@@ -222,7 +214,6 @@ static VALUE stream_writer_push_value(int argc, VALUE *argv, VALUE self) {
|
|
222
214
|
if (Qnil == argv[1]) {
|
223
215
|
oj_str_writer_push_value((StrWriter)DATA_PTR(self), *argv, 0);
|
224
216
|
} else {
|
225
|
-
rb_check_type(argv[1], T_STRING);
|
226
217
|
oj_str_writer_push_value((StrWriter)DATA_PTR(self), *argv, StringValuePtr(argv[1]));
|
227
218
|
}
|
228
219
|
break;
|
@@ -246,17 +237,13 @@ static VALUE stream_writer_push_value(int argc, VALUE *argv, VALUE self) {
|
|
246
237
|
static VALUE stream_writer_push_json(int argc, VALUE *argv, VALUE self) {
|
247
238
|
StreamWriter sw = (StreamWriter)DATA_PTR(self);
|
248
239
|
|
249
|
-
rb_check_type(argv[0], T_STRING);
|
250
240
|
switch (argc) {
|
251
241
|
case 1: oj_str_writer_push_json((StrWriter)DATA_PTR(self), StringValuePtr(*argv), 0); break;
|
252
242
|
case 2:
|
253
243
|
if (Qnil == argv[1]) {
|
254
244
|
oj_str_writer_push_json((StrWriter)DATA_PTR(self), StringValuePtr(*argv), 0);
|
255
245
|
} else {
|
256
|
-
|
257
|
-
oj_str_writer_push_json((StrWriter)DATA_PTR(self),
|
258
|
-
StringValuePtr(*argv),
|
259
|
-
StringValuePtr(argv[1]));
|
246
|
+
oj_str_writer_push_json((StrWriter)DATA_PTR(self), StringValuePtr(*argv), StringValuePtr(argv[1]));
|
260
247
|
}
|
261
248
|
break;
|
262
249
|
default: rb_raise(rb_eArgError, "Wrong number of argument to 'push_json'."); break;
|
data/ext/oj/strict.c
CHANGED
@@ -17,7 +17,7 @@ VALUE oj_cstr_to_value(const char *str, size_t len, size_t cache_str) {
|
|
17
17
|
volatile VALUE rstr = Qnil;
|
18
18
|
|
19
19
|
if (len < cache_str) {
|
20
|
-
|
20
|
+
rstr = oj_str_intern(str, len);
|
21
21
|
} else {
|
22
22
|
rstr = rb_str_new(str, len);
|
23
23
|
rstr = oj_encode(rstr);
|
@@ -37,14 +37,14 @@ VALUE oj_calc_hash_key(ParseInfo pi, Val parent) {
|
|
37
37
|
} else {
|
38
38
|
rkey = rb_str_new(parent->key, parent->klen);
|
39
39
|
rkey = oj_encode(rkey);
|
40
|
-
|
40
|
+
OBJ_FREEZE(rkey); // frozen when used as a Hash key anyway
|
41
41
|
}
|
42
42
|
return rkey;
|
43
43
|
}
|
44
44
|
if (Yes == pi->options.sym_key) {
|
45
|
-
|
45
|
+
rkey = oj_sym_intern(parent->key, parent->klen);
|
46
46
|
} else {
|
47
|
-
|
47
|
+
rkey = oj_str_intern(parent->key, parent->klen);
|
48
48
|
}
|
49
49
|
return rkey;
|
50
50
|
}
|
@@ -98,9 +98,7 @@ static VALUE start_hash(ParseInfo pi) {
|
|
98
98
|
static void hash_set_cstr(ParseInfo pi, Val parent, const char *str, size_t len, const char *orig) {
|
99
99
|
volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
|
100
100
|
|
101
|
-
rb_hash_aset(stack_peek(&pi->stack)->val,
|
102
|
-
oj_calc_hash_key(pi, parent),
|
103
|
-
rstr);
|
101
|
+
rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), rstr);
|
104
102
|
if (RB_UNLIKELY(Yes == pi->options.trace)) {
|
105
103
|
oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rstr);
|
106
104
|
}
|
@@ -113,18 +111,14 @@ static void hash_set_num(ParseInfo pi, Val parent, NumInfo ni) {
|
|
113
111
|
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
|
114
112
|
}
|
115
113
|
v = oj_num_as_value(ni);
|
116
|
-
rb_hash_aset(stack_peek(&pi->stack)->val,
|
117
|
-
oj_calc_hash_key(pi, parent),
|
118
|
-
v);
|
114
|
+
rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), v);
|
119
115
|
if (RB_UNLIKELY(Yes == pi->options.trace)) {
|
120
116
|
oj_trace_parse_call("set_number", pi, __FILE__, __LINE__, v);
|
121
117
|
}
|
122
118
|
}
|
123
119
|
|
124
120
|
static void hash_set_value(ParseInfo pi, Val parent, VALUE value) {
|
125
|
-
rb_hash_aset(stack_peek(&pi->stack)->val,
|
126
|
-
oj_calc_hash_key(pi, parent),
|
127
|
-
value);
|
121
|
+
rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), value);
|
128
122
|
if (RB_UNLIKELY(Yes == pi->options.trace)) {
|
129
123
|
oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, value);
|
130
124
|
}
|
data/ext/oj/string_writer.c
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
// Copyright (c) 2012, 2017 Peter Ohler. All rights reserved.
|
2
2
|
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
3
3
|
|
4
|
-
#include "mem.h"
|
5
4
|
#include "dump.h"
|
6
5
|
#include "encode.h"
|
6
|
+
#include "mem.h"
|
7
7
|
|
8
8
|
extern VALUE Oj;
|
9
9
|
|
@@ -56,10 +56,10 @@ void oj_str_writer_init(StrWriter sw, int buf_size) {
|
|
56
56
|
}
|
57
57
|
// Must be allocated. Using the out.stack_buffer results in double frees
|
58
58
|
// and I haven't figured out why yet.
|
59
|
-
sw->out.buf
|
60
|
-
sw->out.cur
|
61
|
-
sw->out.end
|
62
|
-
sw->out.allocated
|
59
|
+
sw->out.buf = OJ_R_ALLOC_N(char, buf_size);
|
60
|
+
sw->out.cur = sw->out.buf;
|
61
|
+
sw->out.end = sw->out.buf + buf_size - BUFFER_EXTRA;
|
62
|
+
sw->out.allocated = true;
|
63
63
|
|
64
64
|
*sw->out.cur = '\0';
|
65
65
|
sw->out.circ_cache = NULL;
|
@@ -281,7 +281,6 @@ static VALUE str_writer_new(int argc, VALUE *argv, VALUE self) {
|
|
281
281
|
static VALUE str_writer_push_key(VALUE self, VALUE key) {
|
282
282
|
StrWriter sw = (StrWriter)DATA_PTR(self);
|
283
283
|
|
284
|
-
rb_check_type(key, T_STRING);
|
285
284
|
oj_str_writer_push_key(sw, StringValuePtr(key));
|
286
285
|
|
287
286
|
return Qnil;
|
@@ -303,7 +302,6 @@ static VALUE str_writer_push_object(int argc, VALUE *argv, VALUE self) {
|
|
303
302
|
if (Qnil == argv[0]) {
|
304
303
|
oj_str_writer_push_object(sw, 0);
|
305
304
|
} else {
|
306
|
-
rb_check_type(argv[0], T_STRING);
|
307
305
|
oj_str_writer_push_object(sw, StringValuePtr(argv[0]));
|
308
306
|
}
|
309
307
|
break;
|
@@ -332,7 +330,6 @@ static VALUE str_writer_push_array(int argc, VALUE *argv, VALUE self) {
|
|
332
330
|
if (Qnil == argv[0]) {
|
333
331
|
oj_str_writer_push_array(sw, 0);
|
334
332
|
} else {
|
335
|
-
rb_check_type(argv[0], T_STRING);
|
336
333
|
oj_str_writer_push_array(sw, StringValuePtr(argv[0]));
|
337
334
|
}
|
338
335
|
break;
|
@@ -359,7 +356,6 @@ static VALUE str_writer_push_value(int argc, VALUE *argv, VALUE self) {
|
|
359
356
|
if (Qnil == argv[1]) {
|
360
357
|
oj_str_writer_push_value((StrWriter)DATA_PTR(self), *argv, 0);
|
361
358
|
} else {
|
362
|
-
rb_check_type(argv[1], T_STRING);
|
363
359
|
oj_str_writer_push_value((StrWriter)DATA_PTR(self), *argv, StringValuePtr(argv[1]));
|
364
360
|
}
|
365
361
|
break;
|
@@ -378,17 +374,13 @@ static VALUE str_writer_push_value(int argc, VALUE *argv, VALUE self) {
|
|
378
374
|
* - *key* [_String_] the key if adding to an object in the JSON document
|
379
375
|
*/
|
380
376
|
static VALUE str_writer_push_json(int argc, VALUE *argv, VALUE self) {
|
381
|
-
rb_check_type(argv[0], T_STRING);
|
382
377
|
switch (argc) {
|
383
378
|
case 1: oj_str_writer_push_json((StrWriter)DATA_PTR(self), StringValuePtr(*argv), 0); break;
|
384
379
|
case 2:
|
385
380
|
if (Qnil == argv[1]) {
|
386
381
|
oj_str_writer_push_json((StrWriter)DATA_PTR(self), StringValuePtr(*argv), 0);
|
387
382
|
} else {
|
388
|
-
|
389
|
-
oj_str_writer_push_json((StrWriter)DATA_PTR(self),
|
390
|
-
StringValuePtr(*argv),
|
391
|
-
StringValuePtr(argv[1]));
|
383
|
+
oj_str_writer_push_json((StrWriter)DATA_PTR(self), StringValuePtr(*argv), StringValuePtr(argv[1]));
|
392
384
|
}
|
393
385
|
break;
|
394
386
|
default: rb_raise(rb_eArgError, "Wrong number of argument to 'push_json'."); break;
|
data/ext/oj/trace.h
CHANGED
@@ -17,28 +17,39 @@ typedef enum {
|
|
17
17
|
|
18
18
|
struct _parseInfo;
|
19
19
|
|
20
|
-
extern void
|
21
|
-
oj_trace(const char *func, VALUE obj, const char *file, int line, int depth, TraceWhere where);
|
20
|
+
extern void oj_trace(const char *func, VALUE obj, const char *file, int line, int depth, TraceWhere where);
|
22
21
|
extern void oj_trace_parse_in(const char *func, struct _parseInfo *pi, const char *file, int line);
|
23
|
-
extern void
|
24
|
-
oj_trace_parse_call(const char *func, struct _parseInfo *pi, const char *file, int line, VALUE obj);
|
22
|
+
extern void oj_trace_parse_call(const char *func, struct _parseInfo *pi, const char *file, int line, VALUE obj);
|
25
23
|
extern void oj_trace_parse_hash_end(struct _parseInfo *pi, const char *file, int line);
|
26
24
|
extern void oj_trace_parse_array_end(struct _parseInfo *pi, const char *file, int line);
|
27
25
|
|
28
|
-
|
29
26
|
#ifdef OJ_ENABLE_TRACE_LOG
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
#define TRACE(option, func, obj, depth, where) \
|
28
|
+
if (RB_UNLIKELY(Yes == option)) { \
|
29
|
+
oj_trace(func, obj, __FILE__, __LINE__, depth, where); \
|
30
|
+
}
|
31
|
+
#define TRACE_PARSE_IN(option, func, pi) \
|
32
|
+
if (RB_UNLIKELY(Yes == option)) { \
|
33
|
+
oj_trace_parse_in(func, pi, __FILE__, __LINE__); \
|
34
|
+
}
|
35
|
+
#define TRACE_PARSE_CALL(option, func, pi, obj) \
|
36
|
+
if (RB_UNLIKELY(Yes == option)) { \
|
37
|
+
oj_trace_parse_call(func, pi, __FILE__, __LINE__, obj); \
|
38
|
+
}
|
39
|
+
#define TRACE_PARSE_HASH_END(option, pi) \
|
40
|
+
if (RB_UNLIKELY(Yes == option)) { \
|
41
|
+
oj_trace_parse_hash_end(pi, __FILE__, __LINE__); \
|
42
|
+
}
|
43
|
+
#define TRACE_PARSE_ARRAY_END(option, pi) \
|
44
|
+
if (RB_UNLIKELY(Yes == option)) { \
|
45
|
+
oj_trace_parse_array_end(pi, __FILE__, __LINE__); \
|
46
|
+
}
|
35
47
|
#else
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
48
|
+
#define TRACE(option, func, obj, depth, where)
|
49
|
+
#define TRACE_PARSE_IN(option, func, pi)
|
50
|
+
#define TRACE_PARSE_CALL(option, func, pi, obj)
|
51
|
+
#define TRACE_PARSE_HASH_END(option, pi)
|
52
|
+
#define TRACE_PARSE_ARRAY_END(option, pi)
|
41
53
|
#endif
|
42
54
|
|
43
|
-
|
44
55
|
#endif /* OJ_TRACE_H */
|