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/mimic_json.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
|
#include "oj.h"
|
8
8
|
#include "parse.h"
|
9
9
|
|
@@ -349,12 +349,11 @@ static VALUE mimic_load(int argc, VALUE *argv, VALUE self) {
|
|
349
349
|
static VALUE mimic_dump_load(int argc, VALUE *argv, VALUE self) {
|
350
350
|
if (1 > argc) {
|
351
351
|
rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)");
|
352
|
-
}
|
352
|
+
}
|
353
|
+
if (T_STRING == rb_type(*argv)) {
|
353
354
|
return mimic_load(argc, argv, self);
|
354
|
-
} else {
|
355
|
-
return mimic_dump(argc, argv, self);
|
356
355
|
}
|
357
|
-
return
|
356
|
+
return mimic_dump(argc, argv, self);
|
358
357
|
}
|
359
358
|
|
360
359
|
static VALUE mimic_generate_core(int argc, VALUE *argv, Options copts) {
|
@@ -368,8 +367,8 @@ static VALUE mimic_generate_core(int argc, VALUE *argv, Options copts) {
|
|
368
367
|
|
369
368
|
oj_out_init(&out);
|
370
369
|
|
371
|
-
out.omit_nil
|
372
|
-
out.caller
|
370
|
+
out.omit_nil = copts->dump_opts.omit_nil;
|
371
|
+
out.caller = CALLER_GENERATE;
|
373
372
|
// For obj.to_json or generate nan is not allowed but if called from dump
|
374
373
|
// it is.
|
375
374
|
copts->dump_opts.nan_dump = RaiseNan;
|
@@ -389,10 +388,8 @@ static VALUE mimic_generate_core(int argc, VALUE *argv, Options copts) {
|
|
389
388
|
VALUE active_hack[1];
|
390
389
|
|
391
390
|
if (Qundef == state_class) {
|
392
|
-
rb_warn(
|
393
|
-
|
394
|
-
"Call it explicitly beforehand if you want to remove this warning."
|
395
|
-
);
|
391
|
+
rb_warn("Oj::Rails.mimic_JSON was called implicitly. "
|
392
|
+
"Call it explicitly beforehand if you want to remove this warning.");
|
396
393
|
oj_define_mimic_json(0, NULL, Qnil);
|
397
394
|
}
|
398
395
|
active_hack[0] = rb_funcall(state_class, oj_new_id, 0);
|
@@ -467,7 +464,7 @@ oj_mimic_pretty_generate(int argc, VALUE *argv, VALUE self) {
|
|
467
464
|
}
|
468
465
|
if (1 == argc || Qnil == argv[1]) {
|
469
466
|
h = rb_hash_new();
|
470
|
-
} else
|
467
|
+
} else {
|
471
468
|
h = argv[1];
|
472
469
|
}
|
473
470
|
if (!oj_hash_has_key(h, oj_indent_sym)) {
|
@@ -486,10 +483,8 @@ oj_mimic_pretty_generate(int argc, VALUE *argv, VALUE self) {
|
|
486
483
|
rb_hash_aset(h, oj_array_nl_sym, rb_str_new2("\n"));
|
487
484
|
}
|
488
485
|
if (Qundef == state_class) {
|
489
|
-
rb_warn(
|
490
|
-
|
491
|
-
"Call it explicitly beforehand if you want to remove this warning."
|
492
|
-
);
|
486
|
+
rb_warn("Oj::Rails.mimic_JSON was called implicitly. "
|
487
|
+
"Call it explicitly beforehand if you want to remove this warning.");
|
493
488
|
oj_define_mimic_json(0, NULL, Qnil);
|
494
489
|
}
|
495
490
|
rargs[1] = rb_funcall(state_class, oj_new_id, 1, h);
|
@@ -658,11 +653,9 @@ static VALUE mimic_recurse_proc(VALUE self, VALUE obj) {
|
|
658
653
|
*
|
659
654
|
* - *id* [_nil_|String] new create_id
|
660
655
|
*
|
661
|
-
* Returns [_String_] the id.
|
656
|
+
* Returns [_nil_|_String_] the id.
|
662
657
|
*/
|
663
658
|
static VALUE mimic_set_create_id(VALUE self, VALUE id) {
|
664
|
-
Check_Type(id, T_STRING);
|
665
|
-
|
666
659
|
if (NULL != oj_default_options.create_id) {
|
667
660
|
if (oj_json_class != oj_default_options.create_id) {
|
668
661
|
OJ_R_FREE((char *)oj_default_options.create_id);
|
@@ -671,10 +664,11 @@ static VALUE mimic_set_create_id(VALUE self, VALUE id) {
|
|
671
664
|
oj_default_options.create_id_len = 0;
|
672
665
|
}
|
673
666
|
if (Qnil != id) {
|
674
|
-
|
667
|
+
const char *ptr = StringValueCStr(id);
|
668
|
+
size_t len = RSTRING_LEN(id) + 1;
|
675
669
|
|
676
670
|
oj_default_options.create_id = OJ_R_ALLOC_N(char, len);
|
677
|
-
strcpy((char *)oj_default_options.create_id,
|
671
|
+
strcpy((char *)oj_default_options.create_id, ptr);
|
678
672
|
oj_default_options.create_id_len = len - 1;
|
679
673
|
}
|
680
674
|
return id;
|
@@ -763,9 +757,9 @@ static VALUE mimic_object_to_json(int argc, VALUE *argv, VALUE self) {
|
|
763
757
|
|
764
758
|
oj_out_init(&out);
|
765
759
|
|
766
|
-
out.omit_nil
|
767
|
-
copts.mode
|
768
|
-
copts.to_json
|
760
|
+
out.omit_nil = copts.dump_opts.omit_nil;
|
761
|
+
copts.mode = CompatMode;
|
762
|
+
copts.to_json = No;
|
769
763
|
if (1 <= argc && Qnil != argv[0]) {
|
770
764
|
oj_parse_mimic_dump_options(argv[0], &copts);
|
771
765
|
}
|
data/ext/oj/object.c
CHANGED
@@ -270,8 +270,8 @@ static int hat_num(ParseInfo pi, Val parent, Val kval, NumInfo ni) {
|
|
270
270
|
parent->val = rb_funcall2(parent->val, oj_utc_id, 0, 0);
|
271
271
|
} else if (ni->has_exp) {
|
272
272
|
struct timespec ts;
|
273
|
-
ts.tv_sec
|
274
|
-
ts.tv_nsec
|
273
|
+
ts.tv_sec = ni->i;
|
274
|
+
ts.tv_nsec = nsec;
|
275
275
|
parent->val = rb_time_timespec_new(&ts, (int)ni->exp);
|
276
276
|
} else {
|
277
277
|
parent->val = rb_time_nano_new(ni->i, (long)nsec);
|
@@ -325,14 +325,14 @@ static int hat_value(ParseInfo pi, Val parent, const char *key, size_t klen, vol
|
|
325
325
|
sc = oj_name2struct(pi, *RARRAY_CONST_PTR(value), rb_eArgError);
|
326
326
|
}
|
327
327
|
if (sc == rb_cRange) {
|
328
|
-
|
328
|
+
parent->val = rb_class_new_instance(len - 1, RARRAY_CONST_PTR(value) + 1, rb_cRange);
|
329
329
|
} else {
|
330
330
|
// Create a properly initialized struct instance without calling the initialize method.
|
331
331
|
parent->val = rb_obj_alloc(sc);
|
332
332
|
// If the JSON array has more entries than the struct class allows, we record an error.
|
333
333
|
#ifdef RSTRUCT_LEN
|
334
334
|
#if RSTRUCT_LEN_RETURNS_INTEGER_OBJECT
|
335
|
-
|
335
|
+
slen = (int)NUM2LONG(RSTRUCT_LEN(parent->val));
|
336
336
|
#else // RSTRUCT_LEN_RETURNS_INTEGER_OBJECT
|
337
337
|
slen = (int)RSTRUCT_LEN(parent->val);
|
338
338
|
#endif // RSTRUCT_LEN_RETURNS_INTEGER_OBJECT
|
@@ -545,7 +545,7 @@ WHICH_TYPE:
|
|
545
545
|
}
|
546
546
|
} else {
|
547
547
|
if (3 <= klen && '^' == *key && '#' == key[1] && T_ARRAY == rb_type(value)) {
|
548
|
-
long
|
548
|
+
long len = RARRAY_LEN(value);
|
549
549
|
volatile const VALUE *a = RARRAY_CONST_PTR(value);
|
550
550
|
|
551
551
|
if (2 != len) {
|
data/ext/oj/odd.c
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
// Copyright (c) 2011 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 "odd.h"
|
6
5
|
|
7
6
|
#include <string.h>
|
8
7
|
|
8
|
+
#include "mem.h"
|
9
|
+
|
9
10
|
static Odd odds = NULL;
|
10
11
|
static ID sec_id;
|
11
12
|
static ID sec_fraction_id;
|
data/ext/oj/odd.h
CHANGED
@@ -14,7 +14,7 @@ typedef VALUE (*AttrGetFunc)(VALUE obj);
|
|
14
14
|
|
15
15
|
typedef struct _odd {
|
16
16
|
struct _odd *next;
|
17
|
-
const char
|
17
|
+
const char *classname;
|
18
18
|
size_t clen;
|
19
19
|
VALUE clas; // Ruby class or module
|
20
20
|
VALUE create_obj;
|
@@ -22,15 +22,15 @@ typedef struct _odd {
|
|
22
22
|
int attr_cnt;
|
23
23
|
bool is_module;
|
24
24
|
bool raw;
|
25
|
-
const char
|
25
|
+
const char *attr_names[MAX_ODD_ARGS]; // NULL terminated attr names
|
26
26
|
ID attrs[MAX_ODD_ARGS]; // 0 terminated attr IDs
|
27
27
|
AttrGetFunc attrFuncs[MAX_ODD_ARGS];
|
28
|
-
} *
|
28
|
+
} *Odd;
|
29
29
|
|
30
30
|
typedef struct _oddArgs {
|
31
31
|
Odd odd;
|
32
32
|
VALUE args[MAX_ODD_ARGS];
|
33
|
-
} *
|
33
|
+
} *OddArgs;
|
34
34
|
|
35
35
|
extern void oj_odd_init(void);
|
36
36
|
extern Odd oj_get_odd(VALUE clas);
|
data/ext/oj/oj.c
CHANGED
@@ -11,10 +11,10 @@
|
|
11
11
|
#include <sys/types.h>
|
12
12
|
#include <unistd.h>
|
13
13
|
|
14
|
-
#include "mem.h"
|
15
14
|
#include "dump.h"
|
16
15
|
#include "encode.h"
|
17
16
|
#include "intern.h"
|
17
|
+
#include "mem.h"
|
18
18
|
#include "odd.h"
|
19
19
|
#include "parse.h"
|
20
20
|
#include "rails.h"
|
@@ -22,7 +22,7 @@
|
|
22
22
|
typedef struct _yesNoOpt {
|
23
23
|
VALUE sym;
|
24
24
|
char *attr;
|
25
|
-
} *
|
25
|
+
} *YesNoOpt;
|
26
26
|
|
27
27
|
void Init_oj();
|
28
28
|
|
@@ -156,8 +156,8 @@ static VALUE word_sym;
|
|
156
156
|
static VALUE xmlschema_sym;
|
157
157
|
static VALUE xss_safe_sym;
|
158
158
|
|
159
|
-
rb_encoding *oj_utf8_encoding
|
160
|
-
int
|
159
|
+
rb_encoding *oj_utf8_encoding = 0;
|
160
|
+
int oj_utf8_encoding_index = 0;
|
161
161
|
|
162
162
|
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
163
163
|
pthread_mutex_t oj_cache_mutex;
|
@@ -465,7 +465,7 @@ static VALUE get_def_opts(VALUE self) {
|
|
465
465
|
if (NULL == oj_default_options.ignore) {
|
466
466
|
rb_hash_aset(opts, ignore_sym, Qnil);
|
467
467
|
} else {
|
468
|
-
VALUE
|
468
|
+
VALUE *vp;
|
469
469
|
volatile VALUE a = rb_ary_new();
|
470
470
|
|
471
471
|
for (vp = oj_default_options.ignore; Qnil != *vp; vp++) {
|
@@ -640,15 +640,9 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
|
|
640
640
|
} else if (float_prec_sym == k) {
|
641
641
|
int n;
|
642
642
|
|
643
|
-
#ifdef RUBY_INTEGER_UNIFICATION
|
644
643
|
if (rb_cInteger != rb_obj_class(v)) {
|
645
644
|
rb_raise(rb_eArgError, ":float_precision must be a Integer.");
|
646
645
|
}
|
647
|
-
#else
|
648
|
-
if (T_FIXNUM != rb_type(v)) {
|
649
|
-
rb_raise(rb_eArgError, ":float_precision must be a Fixnum.");
|
650
|
-
}
|
651
|
-
#endif
|
652
646
|
n = FIX2INT(v);
|
653
647
|
if (0 >= n) {
|
654
648
|
*copts->float_fmt = '\0';
|
@@ -663,15 +657,9 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
|
|
663
657
|
} else if (cache_str_sym == k || cache_string_sym == k) {
|
664
658
|
int n;
|
665
659
|
|
666
|
-
#ifdef RUBY_INTEGER_UNIFICATION
|
667
660
|
if (rb_cInteger != rb_obj_class(v)) {
|
668
661
|
rb_raise(rb_eArgError, ":cache_str must be a Integer.");
|
669
662
|
}
|
670
|
-
#else
|
671
|
-
if (T_FIXNUM != rb_type(v)) {
|
672
|
-
rb_raise(rb_eArgError, ":cache_str must be a Fixnum.");
|
673
|
-
}
|
674
|
-
#endif
|
675
663
|
n = FIX2INT(v);
|
676
664
|
if (0 >= n) {
|
677
665
|
copts->cache_str = 0;
|
@@ -684,15 +672,9 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
|
|
684
672
|
} else if (sec_prec_sym == k) {
|
685
673
|
int n;
|
686
674
|
|
687
|
-
#ifdef RUBY_INTEGER_UNIFICATION
|
688
675
|
if (rb_cInteger != rb_obj_class(v)) {
|
689
676
|
rb_raise(rb_eArgError, ":second_precision must be a Integer.");
|
690
677
|
}
|
691
|
-
#else
|
692
|
-
if (T_FIXNUM != rb_type(v)) {
|
693
|
-
rb_raise(rb_eArgError, ":second_precision must be a Fixnum.");
|
694
|
-
}
|
695
|
-
#endif
|
696
678
|
n = NUM2INT(v);
|
697
679
|
if (0 > n) {
|
698
680
|
n = 0;
|
@@ -950,7 +932,7 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
|
|
950
932
|
if (Qnil == v) {
|
951
933
|
return ST_CONTINUE;
|
952
934
|
}
|
953
|
-
|
935
|
+
copts->sym_key = (Qtrue == v) ? Yes : No;
|
954
936
|
}
|
955
937
|
return ST_CONTINUE;
|
956
938
|
}
|
@@ -1115,7 +1097,7 @@ static VALUE load(int argc, VALUE *argv, VALUE self) {
|
|
1115
1097
|
* Returns [_Object_|_Hash_|_Array_|_String_|_Fixnum_|_Float_|_Boolean_|_nil_]
|
1116
1098
|
*/
|
1117
1099
|
static VALUE load_file(int argc, VALUE *argv, VALUE self) {
|
1118
|
-
char
|
1100
|
+
char *path;
|
1119
1101
|
int fd;
|
1120
1102
|
Mode mode = oj_default_options.mode;
|
1121
1103
|
struct _parseInfo pi;
|
@@ -1123,7 +1105,7 @@ static VALUE load_file(int argc, VALUE *argv, VALUE self) {
|
|
1123
1105
|
if (1 > argc) {
|
1124
1106
|
rb_raise(rb_eArgError, "Wrong number of arguments to load().");
|
1125
1107
|
}
|
1126
|
-
|
1108
|
+
path = StringValuePtr(*argv);
|
1127
1109
|
parse_info_init(&pi);
|
1128
1110
|
pi.options = oj_default_options;
|
1129
1111
|
pi.handler = Qnil;
|
@@ -1154,16 +1136,15 @@ static VALUE load_file(int argc, VALUE *argv, VALUE self) {
|
|
1154
1136
|
}
|
1155
1137
|
}
|
1156
1138
|
}
|
1157
|
-
path = StringValuePtr(*argv);
|
1158
1139
|
#ifdef _WIN32
|
1159
1140
|
{
|
1160
1141
|
WCHAR *wide_path;
|
1161
1142
|
wide_path = rb_w32_mbstr_to_wstr(CP_UTF8, path, -1, NULL);
|
1162
|
-
fd
|
1143
|
+
fd = rb_w32_wopen(wide_path, O_RDONLY);
|
1163
1144
|
OJ_FREE(wide_path);
|
1164
1145
|
}
|
1165
1146
|
#else
|
1166
|
-
fd
|
1147
|
+
fd = open(path, O_RDONLY);
|
1167
1148
|
#endif
|
1168
1149
|
if (0 == fd) {
|
1169
1150
|
rb_raise(rb_eIOError, "%s", strerror(errno));
|
@@ -1238,10 +1219,10 @@ static VALUE safe_load(VALUE self, VALUE doc) {
|
|
1238
1219
|
*/
|
1239
1220
|
|
1240
1221
|
struct dump_arg {
|
1241
|
-
struct _out
|
1222
|
+
struct _out *out;
|
1242
1223
|
struct _options *copts;
|
1243
1224
|
int argc;
|
1244
|
-
VALUE
|
1225
|
+
VALUE *argv;
|
1245
1226
|
};
|
1246
1227
|
|
1247
1228
|
static VALUE dump_body(VALUE a) {
|
@@ -1297,8 +1278,8 @@ static VALUE dump(int argc, VALUE *argv, VALUE self) {
|
|
1297
1278
|
|
1298
1279
|
oj_out_init(arg.out);
|
1299
1280
|
|
1300
|
-
arg.out->omit_nil
|
1301
|
-
arg.out->caller
|
1281
|
+
arg.out->omit_nil = copts.dump_opts.omit_nil;
|
1282
|
+
arg.out->caller = CALLER_DUMP;
|
1302
1283
|
|
1303
1284
|
return rb_ensure(dump_body, (VALUE)&arg, dump_ensure, (VALUE)&arg);
|
1304
1285
|
}
|
@@ -1345,7 +1326,7 @@ static VALUE to_json(int argc, VALUE *argv, VALUE self) {
|
|
1345
1326
|
|
1346
1327
|
oj_out_init(&out);
|
1347
1328
|
|
1348
|
-
out.omit_nil
|
1329
|
+
out.omit_nil = copts.dump_opts.omit_nil;
|
1349
1330
|
// For obj.to_json or generate nan is not allowed but if called from dump
|
1350
1331
|
// it is.
|
1351
1332
|
oj_dump_obj_to_json_using_params(*argv, &copts, &out, argc - 1, argv + 1);
|
@@ -1377,7 +1358,6 @@ static VALUE to_file(int argc, VALUE *argv, VALUE self) {
|
|
1377
1358
|
if (3 == argc) {
|
1378
1359
|
oj_parse_options(argv[2], &copts);
|
1379
1360
|
}
|
1380
|
-
Check_Type(*argv, T_STRING);
|
1381
1361
|
oj_write_obj_to_file(argv[1], StringValuePtr(*argv), &copts);
|
1382
1362
|
|
1383
1363
|
return Qnil;
|
@@ -1719,8 +1699,7 @@ static VALUE protect_require(VALUE x) {
|
|
1719
1699
|
|
1720
1700
|
extern void print_all_odds(const char *label);
|
1721
1701
|
|
1722
|
-
static VALUE
|
1723
|
-
debug_odd(VALUE self, VALUE label) {
|
1702
|
+
static VALUE debug_odd(VALUE self, VALUE label) {
|
1724
1703
|
print_all_odds(RSTRING_PTR(label));
|
1725
1704
|
return Qnil;
|
1726
1705
|
}
|
@@ -1780,7 +1759,7 @@ void Init_oj(void) {
|
|
1780
1759
|
rb_protect(protect_require, Qnil, &err);
|
1781
1760
|
rb_require("stringio");
|
1782
1761
|
oj_utf8_encoding_index = rb_enc_find_index("UTF-8");
|
1783
|
-
oj_utf8_encoding
|
1762
|
+
oj_utf8_encoding = rb_enc_from_index(oj_utf8_encoding_index);
|
1784
1763
|
|
1785
1764
|
// rb_define_module_function(Oj, "hash_test", hash_test, 0);
|
1786
1765
|
rb_define_module_function(Oj, "debug_odd", debug_odd, 1);
|
@@ -1819,49 +1798,49 @@ void Init_oj(void) {
|
|
1819
1798
|
|
1820
1799
|
rb_define_module_function(Oj, "mem_report", mem_report, 0);
|
1821
1800
|
|
1822
|
-
oj_add_value_id
|
1823
|
-
oj_array_append_id
|
1824
|
-
oj_array_end_id
|
1825
|
-
oj_array_start_id
|
1826
|
-
oj_as_json_id
|
1827
|
-
oj_at_id
|
1828
|
-
oj_begin_id
|
1829
|
-
oj_bigdecimal_id
|
1830
|
-
oj_end_id
|
1831
|
-
oj_error_id
|
1832
|
-
oj_exclude_end_id
|
1833
|
-
oj_file_id
|
1834
|
-
oj_fileno_id
|
1835
|
-
oj_ftype_id
|
1836
|
-
oj_hash_end_id
|
1837
|
-
oj_hash_key_id
|
1838
|
-
oj_hash_set_id
|
1839
|
-
oj_hash_start_id
|
1840
|
-
oj_iconv_id
|
1841
|
-
oj_json_create_id
|
1842
|
-
oj_length_id
|
1843
|
-
oj_new_id
|
1844
|
-
oj_parse_id
|
1845
|
-
oj_pos_id
|
1846
|
-
oj_raw_json_id
|
1847
|
-
oj_read_id
|
1848
|
-
oj_readpartial_id
|
1849
|
-
oj_replace_id
|
1850
|
-
oj_stat_id
|
1851
|
-
oj_string_id
|
1852
|
-
oj_to_h_id
|
1853
|
-
oj_to_hash_id
|
1854
|
-
oj_to_json_id
|
1855
|
-
oj_to_s_id
|
1856
|
-
oj_to_sym_id
|
1857
|
-
oj_to_time_id
|
1858
|
-
oj_tv_nsec_id
|
1859
|
-
oj_tv_sec_id
|
1860
|
-
oj_tv_usec_id
|
1861
|
-
oj_utc_id
|
1862
|
-
oj_utc_offset_id
|
1863
|
-
oj_utcq_id
|
1864
|
-
oj_write_id
|
1801
|
+
oj_add_value_id = rb_intern("add_value");
|
1802
|
+
oj_array_append_id = rb_intern("array_append");
|
1803
|
+
oj_array_end_id = rb_intern("array_end");
|
1804
|
+
oj_array_start_id = rb_intern("array_start");
|
1805
|
+
oj_as_json_id = rb_intern("as_json");
|
1806
|
+
oj_at_id = rb_intern("at");
|
1807
|
+
oj_begin_id = rb_intern("begin");
|
1808
|
+
oj_bigdecimal_id = rb_intern("BigDecimal");
|
1809
|
+
oj_end_id = rb_intern("end");
|
1810
|
+
oj_error_id = rb_intern("error");
|
1811
|
+
oj_exclude_end_id = rb_intern("exclude_end?");
|
1812
|
+
oj_file_id = rb_intern("file?");
|
1813
|
+
oj_fileno_id = rb_intern("fileno");
|
1814
|
+
oj_ftype_id = rb_intern("ftype");
|
1815
|
+
oj_hash_end_id = rb_intern("hash_end");
|
1816
|
+
oj_hash_key_id = rb_intern("hash_key");
|
1817
|
+
oj_hash_set_id = rb_intern("hash_set");
|
1818
|
+
oj_hash_start_id = rb_intern("hash_start");
|
1819
|
+
oj_iconv_id = rb_intern("iconv");
|
1820
|
+
oj_json_create_id = rb_intern("json_create");
|
1821
|
+
oj_length_id = rb_intern("length");
|
1822
|
+
oj_new_id = rb_intern("new");
|
1823
|
+
oj_parse_id = rb_intern("parse");
|
1824
|
+
oj_pos_id = rb_intern("pos");
|
1825
|
+
oj_raw_json_id = rb_intern("raw_json");
|
1826
|
+
oj_read_id = rb_intern("read");
|
1827
|
+
oj_readpartial_id = rb_intern("readpartial");
|
1828
|
+
oj_replace_id = rb_intern("replace");
|
1829
|
+
oj_stat_id = rb_intern("stat");
|
1830
|
+
oj_string_id = rb_intern("string");
|
1831
|
+
oj_to_h_id = rb_intern("to_h");
|
1832
|
+
oj_to_hash_id = rb_intern("to_hash");
|
1833
|
+
oj_to_json_id = rb_intern("to_json");
|
1834
|
+
oj_to_s_id = rb_intern("to_s");
|
1835
|
+
oj_to_sym_id = rb_intern("to_sym");
|
1836
|
+
oj_to_time_id = rb_intern("to_time");
|
1837
|
+
oj_tv_nsec_id = rb_intern("tv_nsec");
|
1838
|
+
oj_tv_sec_id = rb_intern("tv_sec");
|
1839
|
+
oj_tv_usec_id = rb_intern("tv_usec");
|
1840
|
+
oj_utc_id = rb_intern("utc");
|
1841
|
+
oj_utc_offset_id = rb_intern("utc_offset");
|
1842
|
+
oj_utcq_id = rb_intern("utc?");
|
1843
|
+
oj_write_id = rb_intern("write");
|
1865
1844
|
|
1866
1845
|
rb_require("oj/bag");
|
1867
1846
|
rb_require("oj/error");
|