oj 3.7.4 → 3.11.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -4
- data/ext/oj/buf.h +6 -34
- data/ext/oj/cache8.c +3 -3
- data/ext/oj/cache8.h +5 -33
- data/ext/oj/circarray.c +5 -9
- data/ext/oj/circarray.h +5 -8
- data/ext/oj/code.c +3 -6
- data/ext/oj/code.h +7 -10
- data/ext/oj/compat.c +11 -14
- data/ext/oj/custom.c +108 -75
- data/ext/oj/dump.c +132 -92
- data/ext/oj/dump.h +6 -7
- data/ext/oj/dump_compat.c +37 -34
- data/ext/oj/dump_leaf.c +3 -6
- data/ext/oj/dump_object.c +23 -17
- data/ext/oj/dump_strict.c +7 -9
- data/ext/oj/encode.h +6 -32
- data/ext/oj/err.c +2 -5
- data/ext/oj/err.h +6 -34
- data/ext/oj/extconf.rb +6 -0
- data/ext/oj/fast.c +39 -56
- data/ext/oj/hash.c +11 -39
- data/ext/oj/hash.h +5 -33
- data/ext/oj/hash_test.c +3 -31
- data/ext/oj/mimic_json.c +65 -44
- data/ext/oj/object.c +38 -69
- data/ext/oj/odd.c +18 -17
- data/ext/oj/odd.h +6 -9
- data/ext/oj/oj.c +139 -93
- data/ext/oj/oj.h +43 -35
- data/ext/oj/parse.c +164 -60
- data/ext/oj/parse.h +30 -31
- data/ext/oj/rails.c +119 -83
- data/ext/oj/rails.h +4 -7
- data/ext/oj/reader.c +5 -8
- data/ext/oj/reader.h +7 -10
- data/ext/oj/resolve.c +4 -7
- data/ext/oj/resolve.h +4 -7
- data/ext/oj/rxclass.c +8 -11
- data/ext/oj/rxclass.h +8 -11
- data/ext/oj/saj.c +9 -12
- data/ext/oj/scp.c +4 -7
- data/ext/oj/sparse.c +67 -33
- data/ext/oj/stream_writer.c +16 -15
- data/ext/oj/strict.c +9 -12
- data/ext/oj/string_writer.c +27 -8
- data/ext/oj/trace.c +5 -8
- data/ext/oj/trace.h +9 -12
- data/ext/oj/util.c +136 -0
- data/ext/oj/util.h +19 -0
- data/ext/oj/val_stack.c +28 -36
- data/ext/oj/val_stack.h +19 -50
- data/ext/oj/wab.c +29 -29
- data/lib/oj.rb +0 -8
- data/lib/oj/json.rb +1 -1
- data/lib/oj/mimic.rb +46 -2
- data/lib/oj/version.rb +2 -2
- data/pages/Modes.md +47 -45
- data/pages/Options.md +43 -10
- data/pages/Rails.md +60 -21
- data/pages/Security.md +1 -1
- 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/bar.rb +24 -6
- data/test/baz.rb +16 -0
- data/test/foo.rb +26 -57
- data/test/helper.rb +10 -0
- data/test/json_gem/json_common_interface_test.rb +8 -3
- data/test/json_gem/json_generator_test.rb +15 -3
- data/test/json_gem/test_helper.rb +8 -0
- data/test/prec.rb +23 -0
- data/test/sample_json.rb +1 -1
- data/test/test_compat.rb +21 -10
- data/test/test_custom.rb +135 -8
- data/test/test_integer_range.rb +1 -2
- data/test/test_object.rb +35 -2
- data/test/test_rails.rb +35 -0
- data/test/test_strict.rb +24 -1
- data/test/test_various.rb +52 -63
- data/test/test_writer.rb +19 -2
- data/test/tests.rb +1 -0
- data/test/zoo.rb +13 -0
- metadata +100 -75
data/ext/oj/dump.h
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2011, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
5
2
|
|
6
|
-
#ifndef
|
7
|
-
#define
|
3
|
+
#ifndef OJ_DUMP_H
|
4
|
+
#define OJ_DUMP_H
|
8
5
|
|
9
6
|
#include <ruby.h>
|
10
7
|
|
@@ -45,6 +42,8 @@ extern void oj_dump_rails_val(VALUE obj, int depth, Out out);
|
|
45
42
|
extern void oj_dump_custom_val(VALUE obj, int depth, Out out, bool as_ok);
|
46
43
|
extern void oj_dump_wab_val(VALUE obj, int depth, Out out);
|
47
44
|
|
45
|
+
extern void oj_dump_raw_json(VALUE obj, int depth, Out out);
|
46
|
+
|
48
47
|
extern VALUE oj_add_to_json(int argc, VALUE *argv, VALUE self);
|
49
48
|
extern VALUE oj_remove_to_json(int argc, VALUE *argv, VALUE self);
|
50
49
|
|
@@ -91,4 +90,4 @@ dump_ulong(unsigned long num, Out out) {
|
|
91
90
|
*out->cur = '\0';
|
92
91
|
}
|
93
92
|
|
94
|
-
#endif /*
|
93
|
+
#endif /* OJ_DUMP_H */
|
data/ext/oj/dump_compat.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2012, 2017, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2012, 2017 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#include "code.h"
|
7
4
|
#include "dump.h"
|
@@ -64,12 +61,10 @@ dump_values_array(VALUE *values, int depth, Out out) {
|
|
64
61
|
} else {
|
65
62
|
if (out->opts->dump_opts.use) {
|
66
63
|
size = d2 * out->opts->dump_opts.indent_size + out->opts->dump_opts.array_size + 2;
|
67
|
-
} else {
|
68
|
-
size = d2 * out->indent + 3;
|
69
|
-
}
|
70
|
-
if (out->opts->dump_opts.use) {
|
71
64
|
size += out->opts->dump_opts.array_size;
|
72
65
|
size += out->opts->dump_opts.indent_size;
|
66
|
+
} else {
|
67
|
+
size = d2 * out->indent + 3;
|
73
68
|
}
|
74
69
|
for (; Qundef != *values; values++) {
|
75
70
|
assure_size(out, size);
|
@@ -80,6 +75,7 @@ dump_values_array(VALUE *values, int depth, Out out) {
|
|
80
75
|
}
|
81
76
|
if (0 < out->opts->dump_opts.indent_size) {
|
82
77
|
int i;
|
78
|
+
|
83
79
|
for (i = d2; 0 < i; i--) {
|
84
80
|
strcpy(out->cur, out->opts->dump_opts.indent_str);
|
85
81
|
out->cur += out->opts->dump_opts.indent_size;
|
@@ -155,7 +151,7 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
|
|
155
151
|
if (as_ok && !oj_use_hash_alt && rb_obj_class(a) != rb_cArray && rb_respond_to(a, oj_to_json_id)) {
|
156
152
|
dump_to_json(a, out);
|
157
153
|
return;
|
158
|
-
}
|
154
|
+
}
|
159
155
|
cnt = (int)RARRAY_LEN(a);
|
160
156
|
*out->cur++ = '[';
|
161
157
|
assure_size(out, 2);
|
@@ -190,9 +186,9 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
|
|
190
186
|
*out->cur++ = ',';
|
191
187
|
}
|
192
188
|
}
|
193
|
-
size = depth * out->indent + 1;
|
194
|
-
assure_size(out, size);
|
195
189
|
if (out->opts->dump_opts.use) {
|
190
|
+
size = out->opts->dump_opts.array_size + out->opts->dump_opts.indent_size * depth + 1;
|
191
|
+
assure_size(out, size);
|
196
192
|
if (0 < out->opts->dump_opts.array_size) {
|
197
193
|
strcpy(out->cur, out->opts->dump_opts.array_nl);
|
198
194
|
out->cur += out->opts->dump_opts.array_size;
|
@@ -206,6 +202,8 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
|
|
206
202
|
}
|
207
203
|
}
|
208
204
|
} else {
|
205
|
+
size = depth * out->indent + 1;
|
206
|
+
assure_size(out, size);
|
209
207
|
fill_indent(out, depth);
|
210
208
|
}
|
211
209
|
*out->cur++ = ']';
|
@@ -217,7 +215,7 @@ static ID _dump_id = 0;
|
|
217
215
|
|
218
216
|
static void
|
219
217
|
bigdecimal_alt(VALUE obj, int depth, Out out) {
|
220
|
-
struct
|
218
|
+
struct _attr attrs[] = {
|
221
219
|
{ "b", 1, Qnil },
|
222
220
|
{ NULL, 0, Qnil },
|
223
221
|
};
|
@@ -235,7 +233,7 @@ static ID imag_id = 0;
|
|
235
233
|
|
236
234
|
static void
|
237
235
|
complex_alt(VALUE obj, int depth, Out out) {
|
238
|
-
struct
|
236
|
+
struct _attr attrs[] = {
|
239
237
|
{ "r", 1, Qnil },
|
240
238
|
{ "i", 1, Qnil },
|
241
239
|
{ NULL, 0, Qnil },
|
@@ -258,7 +256,7 @@ static ID start_id = 0;
|
|
258
256
|
|
259
257
|
static void
|
260
258
|
date_alt(VALUE obj, int depth, Out out) {
|
261
|
-
struct
|
259
|
+
struct _attr attrs[] = {
|
262
260
|
{ "y", 1, Qnil },
|
263
261
|
{ "m", 1, Qnil },
|
264
262
|
{ "d", 1, Qnil },
|
@@ -286,7 +284,7 @@ static ID offset_id = 0;
|
|
286
284
|
|
287
285
|
static void
|
288
286
|
datetime_alt(VALUE obj, int depth, Out out) {
|
289
|
-
struct
|
287
|
+
struct _attr attrs[] = {
|
290
288
|
{ "y", 1, Qnil },
|
291
289
|
{ "m", 1, Qnil },
|
292
290
|
{ "d", 1, Qnil },
|
@@ -375,7 +373,7 @@ static ID table_id = 0;
|
|
375
373
|
|
376
374
|
static void
|
377
375
|
openstruct_alt(VALUE obj, int depth, Out out) {
|
378
|
-
struct
|
376
|
+
struct _attr attrs[] = {
|
379
377
|
{ "t", 1, Qnil },
|
380
378
|
{ NULL, 0, Qnil },
|
381
379
|
};
|
@@ -425,7 +423,7 @@ static ID denominator_id = 0;
|
|
425
423
|
|
426
424
|
static void
|
427
425
|
rational_alt(VALUE obj, int depth, Out out) {
|
428
|
-
struct
|
426
|
+
struct _attr attrs[] = {
|
429
427
|
{ "n", 1, Qnil },
|
430
428
|
{ "d", 1, Qnil },
|
431
429
|
{ NULL, 0, Qnil },
|
@@ -445,7 +443,7 @@ static ID source_id = 0;
|
|
445
443
|
|
446
444
|
static void
|
447
445
|
regexp_alt(VALUE obj, int depth, Out out) {
|
448
|
-
struct
|
446
|
+
struct _attr attrs[] = {
|
449
447
|
{ "o", 1, Qnil },
|
450
448
|
{ "s", 1, Qnil },
|
451
449
|
{ NULL, 0, Qnil },
|
@@ -462,7 +460,7 @@ regexp_alt(VALUE obj, int depth, Out out) {
|
|
462
460
|
|
463
461
|
static void
|
464
462
|
time_alt(VALUE obj, int depth, Out out) {
|
465
|
-
struct
|
463
|
+
struct _attr attrs[] = {
|
466
464
|
{ "s", 1, Qundef, 0, Qundef },
|
467
465
|
{ "n", 1, Qundef, 0, Qundef },
|
468
466
|
{ NULL, 0, Qnil },
|
@@ -471,10 +469,14 @@ time_alt(VALUE obj, int depth, Out out) {
|
|
471
469
|
long long nsec;
|
472
470
|
|
473
471
|
#ifdef HAVE_RB_TIME_TIMESPEC
|
474
|
-
{
|
472
|
+
if (16 <= sizeof(struct timespec)) {
|
475
473
|
struct timespec ts = rb_time_timespec(obj);
|
476
|
-
|
474
|
+
|
475
|
+
sec = (long long)ts.tv_sec;
|
477
476
|
nsec = ts.tv_nsec;
|
477
|
+
} else {
|
478
|
+
sec = rb_num2ll(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
|
479
|
+
nsec = rb_num2ll(rb_funcall2(obj, oj_tv_nsec_id, 0, 0));
|
478
480
|
}
|
479
481
|
#else
|
480
482
|
sec = rb_num2ll(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
|
@@ -487,7 +489,7 @@ time_alt(VALUE obj, int depth, Out out) {
|
|
487
489
|
oj_code_attrs(obj, attrs, depth, out, true);
|
488
490
|
}
|
489
491
|
|
490
|
-
struct
|
492
|
+
struct _code oj_compat_codes[] = {
|
491
493
|
{ "BigDecimal", Qnil, bigdecimal_alt, NULL, false },
|
492
494
|
{ "Complex", Qnil, complex_alt, NULL, false },
|
493
495
|
{ "Date", Qnil, date_alt, false },
|
@@ -643,7 +645,8 @@ dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
|
643
645
|
}
|
644
646
|
|
645
647
|
static int
|
646
|
-
hash_cb(VALUE key, VALUE value,
|
648
|
+
hash_cb(VALUE key, VALUE value, VALUE ov) {
|
649
|
+
Out out = (Out)ov;
|
647
650
|
int depth = out->depth;
|
648
651
|
|
649
652
|
if (out->omit_nil && Qnil == value) {
|
@@ -711,7 +714,7 @@ dump_hash(VALUE obj, int depth, Out out, bool as_ok) {
|
|
711
714
|
if (as_ok && !oj_use_hash_alt && rb_obj_class(obj) != rb_cHash && rb_respond_to(obj, oj_to_json_id)) {
|
712
715
|
dump_to_json(obj, out);
|
713
716
|
return;
|
714
|
-
}
|
717
|
+
}
|
715
718
|
cnt = (int)RHASH_SIZE(obj);
|
716
719
|
assure_size(out, 2);
|
717
720
|
if (0 == cnt) {
|
@@ -758,9 +761,12 @@ dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
|
|
758
761
|
exception_alt(obj, depth, out);
|
759
762
|
return;
|
760
763
|
}
|
764
|
+
if (Yes == out->opts->raw_json && rb_respond_to(obj, oj_raw_json_id)) {
|
765
|
+
oj_dump_raw_json(obj, depth, out);
|
766
|
+
return;
|
767
|
+
}
|
761
768
|
if (as_ok && rb_respond_to(obj, oj_to_json_id)) {
|
762
769
|
dump_to_json(obj, out);
|
763
|
-
|
764
770
|
return;
|
765
771
|
}
|
766
772
|
// Nothing else matched so encode as a JSON object with Ruby obj members
|
@@ -862,7 +868,7 @@ dump_bignum(VALUE obj, int depth, Out out, bool as_ok) {
|
|
862
868
|
// this must use to_s to pass the json gem unit tests.
|
863
869
|
volatile VALUE rs;
|
864
870
|
int cnt;
|
865
|
-
|
871
|
+
bool dump_as_string = false;
|
866
872
|
|
867
873
|
if (use_bignum_alt) {
|
868
874
|
rs = rb_big2str(obj, 10);
|
@@ -872,21 +878,18 @@ dump_bignum(VALUE obj, int depth, Out out, bool as_ok) {
|
|
872
878
|
rb_check_type(rs, T_STRING);
|
873
879
|
cnt = (int)RSTRING_LEN(rs);
|
874
880
|
|
875
|
-
|
881
|
+
if (out->opts->int_range_min != 0 || out->opts->int_range_max != 0) {
|
876
882
|
dump_as_string = true; // Bignum cannot be inside of Fixnum range
|
877
883
|
assure_size(out, cnt + 2);
|
878
884
|
*out->cur++ = '"';
|
879
|
-
|
885
|
+
} else {
|
880
886
|
assure_size(out, cnt);
|
881
|
-
|
882
|
-
|
887
|
+
}
|
883
888
|
memcpy(out->cur, rb_string_value_ptr((VALUE*)&rs), cnt);
|
884
889
|
out->cur += cnt;
|
885
|
-
|
886
|
-
if(dump_as_string) {
|
890
|
+
if (dump_as_string) {
|
887
891
|
*out->cur++ = '"';
|
888
|
-
|
889
|
-
|
892
|
+
}
|
890
893
|
*out->cur = '\0';
|
891
894
|
}
|
892
895
|
|
data/ext/oj/dump_leaf.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2012, 2017, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2012, 2017 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#include <errno.h>
|
7
4
|
|
@@ -15,7 +12,7 @@ grow(Out out, size_t len) {
|
|
15
12
|
size_t size = out->end - out->buf;
|
16
13
|
long pos = out->cur - out->buf;
|
17
14
|
char *buf;
|
18
|
-
|
15
|
+
|
19
16
|
size *= 2;
|
20
17
|
if (size <= len * 2 + pos) {
|
21
18
|
size += len;
|
@@ -227,7 +224,7 @@ oj_dump_leaf_to_json(Leaf leaf, Options copts, Out out) {
|
|
227
224
|
void
|
228
225
|
oj_write_leaf_to_file(Leaf leaf, const char *path, Options copts) {
|
229
226
|
char buf[4096];
|
230
|
-
struct
|
227
|
+
struct _out out;
|
231
228
|
size_t size;
|
232
229
|
FILE *f;
|
233
230
|
|
data/ext/oj/dump_object.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2012, 2017, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2012, 2017 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#include "dump.h"
|
7
4
|
#include "odd.h"
|
@@ -56,7 +53,7 @@ dump_data(VALUE obj, int depth, Out out, bool as_ok) {
|
|
56
53
|
}
|
57
54
|
} else {
|
58
55
|
long id = oj_check_circular(obj, out);
|
59
|
-
|
56
|
+
|
60
57
|
if (0 <= id) {
|
61
58
|
dump_obj_attrs(obj, clas, id, depth, out);
|
62
59
|
}
|
@@ -72,7 +69,7 @@ dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
|
|
72
69
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
73
70
|
const char *str = rb_string_value_ptr((VALUE*)&rstr);
|
74
71
|
int len = (int)RSTRING_LEN(rstr);
|
75
|
-
|
72
|
+
|
76
73
|
if (0 == strcasecmp("Infinity", str)) {
|
77
74
|
str = oj_nan_str(obj, out->opts->dump_opts.nan_dump, out->opts->mode, true, &len);
|
78
75
|
oj_dump_raw(str, len, out);
|
@@ -224,7 +221,8 @@ dump_sym(VALUE obj, int depth, Out out, bool as_ok) {
|
|
224
221
|
}
|
225
222
|
|
226
223
|
static int
|
227
|
-
hash_cb(VALUE key, VALUE value,
|
224
|
+
hash_cb(VALUE key, VALUE value, VALUE ov) {
|
225
|
+
Out out = (Out)ov;
|
228
226
|
int depth = out->depth;
|
229
227
|
long size = depth * out->indent + 1;
|
230
228
|
|
@@ -280,7 +278,7 @@ hash_cb(VALUE key, VALUE value, Out out) {
|
|
280
278
|
}
|
281
279
|
out->depth = depth;
|
282
280
|
*out->cur++ = ',';
|
283
|
-
|
281
|
+
|
284
282
|
return ST_CONTINUE;
|
285
283
|
}
|
286
284
|
|
@@ -348,7 +346,8 @@ dump_hash_class(VALUE obj, VALUE clas, int depth, Out out) {
|
|
348
346
|
|
349
347
|
#ifdef HAVE_RB_IVAR_FOREACH
|
350
348
|
static int
|
351
|
-
dump_attr_cb(ID key, VALUE value,
|
349
|
+
dump_attr_cb(ID key, VALUE value, VALUE ov) {
|
350
|
+
Out out = (Out)ov;
|
352
351
|
int depth = out->depth;
|
353
352
|
size_t size = depth * out->indent + 1;
|
354
353
|
const char *attr = rb_id2name(key);
|
@@ -363,6 +362,8 @@ dump_attr_cb(ID key, VALUE value, Out out) {
|
|
363
362
|
// the key name is NULL. Not an empty string but NULL.
|
364
363
|
if (NULL == attr) {
|
365
364
|
attr = "";
|
365
|
+
} else if (Yes == out->opts->ignore_under && '@' == *attr && '_' == attr[1]) {
|
366
|
+
return ST_CONTINUE;
|
366
367
|
}
|
367
368
|
if (0 == strcmp("bt", attr) || 0 == strcmp("mesg", attr)) {
|
368
369
|
return ST_CONTINUE;
|
@@ -384,7 +385,7 @@ dump_attr_cb(ID key, VALUE value, Out out) {
|
|
384
385
|
oj_dump_obj_val(value, depth, out);
|
385
386
|
out->depth = depth;
|
386
387
|
*out->cur++ = ',';
|
387
|
-
|
388
|
+
|
388
389
|
return ST_CONTINUE;
|
389
390
|
}
|
390
391
|
#endif
|
@@ -423,8 +424,8 @@ dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
|
|
423
424
|
if (odd->raw) {
|
424
425
|
v = rb_funcall(obj, *odd->attrs, 0);
|
425
426
|
if (Qundef == v || T_STRING != rb_type(v)) {
|
426
|
-
rb_raise(rb_eEncodingError, "Invalid type for raw JSON
|
427
|
-
} else {
|
427
|
+
rb_raise(rb_eEncodingError, "Invalid type for raw JSON.");
|
428
|
+
} else {
|
428
429
|
const char *s = rb_string_value_ptr((VALUE*)&v);
|
429
430
|
int len = (int)RSTRING_LEN(v);
|
430
431
|
const char *name = rb_id2name(*odd->attrs);
|
@@ -460,9 +461,11 @@ dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
|
|
460
461
|
char *n;
|
461
462
|
char *end;
|
462
463
|
ID i;
|
463
|
-
|
464
|
+
|
464
465
|
if (sizeof(nbuf) <= nlen) {
|
465
|
-
n2 = strdup(name)
|
466
|
+
if (NULL == (n2 = strdup(name))) {
|
467
|
+
rb_raise(rb_eNoMemError, "for attribute name.");
|
468
|
+
}
|
466
469
|
} else {
|
467
470
|
strcpy(n2, name);
|
468
471
|
}
|
@@ -608,9 +611,12 @@ dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out) {
|
|
608
611
|
size = d2 * out->indent + 1;
|
609
612
|
for (i = cnt; 0 < i; i--, np++) {
|
610
613
|
VALUE value;
|
611
|
-
|
614
|
+
|
612
615
|
vid = rb_to_id(*np);
|
613
616
|
attr = rb_id2name(vid);
|
617
|
+
if (Yes == out->opts->ignore_under && '@' == *attr && '_' == attr[1]) {
|
618
|
+
continue;
|
619
|
+
}
|
614
620
|
value = rb_ivar_get(obj, vid);
|
615
621
|
|
616
622
|
if (oj_dump_ignore(out->opts, value)) {
|
@@ -737,7 +743,7 @@ dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
|
|
737
743
|
#else // RSTRUCT_LEN_RETURNS_INTEGER_OBJECT
|
738
744
|
cnt = (int)RSTRUCT_LEN(obj);
|
739
745
|
#endif // RSTRUCT_LEN_RETURNS_INTEGER_OBJECT
|
740
|
-
|
746
|
+
|
741
747
|
for (i = 0; i < cnt; i++) {
|
742
748
|
v = RSTRUCT_GET(obj, i);
|
743
749
|
if (oj_dump_ignore(out->opts, v)) {
|
@@ -810,7 +816,7 @@ static DumpFunc obj_funcs[] = {
|
|
810
816
|
void
|
811
817
|
oj_dump_obj_val(VALUE obj, int depth, Out out) {
|
812
818
|
int type = rb_type(obj);
|
813
|
-
|
819
|
+
|
814
820
|
if (Yes == out->opts->trace) {
|
815
821
|
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
|
816
822
|
}
|
data/ext/oj/dump_strict.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2012, 2017, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2012, 2017 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#include <stdlib.h>
|
7
4
|
#include <time.h>
|
@@ -45,7 +42,7 @@ dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
|
45
42
|
cnt = 3;
|
46
43
|
} else {
|
47
44
|
NanDump nd = out->opts->dump_opts.nan_dump;
|
48
|
-
|
45
|
+
|
49
46
|
if (AutoNan == nd) {
|
50
47
|
nd = RaiseNan;
|
51
48
|
}
|
@@ -195,11 +192,12 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
|
|
195
192
|
}
|
196
193
|
|
197
194
|
static int
|
198
|
-
hash_cb(VALUE key, VALUE value,
|
195
|
+
hash_cb(VALUE key, VALUE value, VALUE ov) {
|
196
|
+
Out out = (Out)ov;
|
199
197
|
int depth = out->depth;
|
200
198
|
long size;
|
201
199
|
int rtype = rb_type(key);
|
202
|
-
|
200
|
+
|
203
201
|
if (rtype != T_STRING && rtype != T_SYMBOL) {
|
204
202
|
rb_raise(rb_eTypeError, "In :strict and :null mode all Hash keys must be Strings or Symbols, not %s.\n", rb_class2name(rb_obj_class(key)));
|
205
203
|
}
|
@@ -359,7 +357,7 @@ static DumpFunc strict_funcs[] = {
|
|
359
357
|
void
|
360
358
|
oj_dump_strict_val(VALUE obj, int depth, Out out) {
|
361
359
|
int type = rb_type(obj);
|
362
|
-
|
360
|
+
|
363
361
|
if (Yes == out->opts->trace) {
|
364
362
|
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
|
365
363
|
}
|
@@ -408,7 +406,7 @@ static DumpFunc null_funcs[] = {
|
|
408
406
|
void
|
409
407
|
oj_dump_null_val(VALUE obj, int depth, Out out) {
|
410
408
|
int type = rb_type(obj);
|
411
|
-
|
409
|
+
|
412
410
|
if (Yes == out->opts->trace) {
|
413
411
|
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
|
414
412
|
}
|