oj 3.10.14 → 3.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/oj/buf.h +2 -30
- data/ext/oj/cache8.h +1 -29
- data/ext/oj/circarray.c +4 -8
- data/ext/oj/circarray.h +1 -4
- data/ext/oj/code.c +3 -6
- data/ext/oj/code.h +1 -4
- data/ext/oj/compat.c +1 -4
- data/ext/oj/custom.c +1 -4
- data/ext/oj/dump.c +23 -13
- data/ext/oj/dump.h +1 -4
- data/ext/oj/dump_compat.c +1 -4
- data/ext/oj/dump_leaf.c +2 -5
- data/ext/oj/dump_object.c +1 -4
- data/ext/oj/dump_strict.c +1 -4
- data/ext/oj/encode.h +1 -29
- data/ext/oj/err.c +1 -4
- data/ext/oj/err.h +1 -29
- data/ext/oj/fast.c +14 -42
- data/ext/oj/hash.c +4 -32
- data/ext/oj/hash.h +1 -29
- data/ext/oj/hash_test.c +1 -29
- data/ext/oj/mimic_json.c +5 -6
- data/ext/oj/object.c +1 -4
- data/ext/oj/odd.c +1 -4
- data/ext/oj/odd.h +1 -4
- data/ext/oj/oj.c +24 -4
- data/ext/oj/oj.h +3 -4
- data/ext/oj/parse.c +19 -19
- data/ext/oj/parse.h +1 -4
- data/ext/oj/rails.c +1 -4
- data/ext/oj/rails.h +1 -4
- data/ext/oj/reader.c +5 -8
- data/ext/oj/reader.h +2 -5
- data/ext/oj/resolve.c +1 -4
- data/ext/oj/resolve.h +1 -4
- data/ext/oj/rxclass.c +3 -6
- data/ext/oj/rxclass.h +1 -4
- data/ext/oj/saj.c +6 -9
- data/ext/oj/scp.c +1 -4
- data/ext/oj/sparse.c +40 -23
- data/ext/oj/stream_writer.c +4 -9
- data/ext/oj/strict.c +3 -6
- data/ext/oj/string_writer.c +1 -4
- data/ext/oj/trace.c +5 -8
- data/ext/oj/trace.h +1 -4
- data/ext/oj/util.c +1 -1
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +1 -29
- data/ext/oj/val_stack.h +1 -29
- data/ext/oj/wab.c +1 -4
- data/lib/oj/mimic.rb +45 -1
- data/lib/oj/version.rb +1 -1
- data/pages/Modes.md +1 -0
- data/pages/Options.md +12 -0
- data/test/test_compat.rb +14 -1
- data/test/test_rails.rb +9 -0
- data/test/test_various.rb +1 -0
- metadata +85 -85
data/ext/oj/hash.c
CHANGED
@@ -1,32 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2011, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*
|
5
|
-
* Redistribution and use in source and binary forms, with or without
|
6
|
-
* modification, are permitted provided that the following conditions are met:
|
7
|
-
*
|
8
|
-
* - Redistributions of source code must retain the above copyright notice, this
|
9
|
-
* list of conditions and the following disclaimer.
|
10
|
-
*
|
11
|
-
* - Redistributions in binary form must reproduce the above copyright notice,
|
12
|
-
* this list of conditions and the following disclaimer in the documentation
|
13
|
-
* and/or other materials provided with the distribution.
|
14
|
-
*
|
15
|
-
* - Neither the name of Peter Ohler nor the names of its contributors may be
|
16
|
-
* used to endorse or promote products derived from this software without
|
17
|
-
* specific prior written permission.
|
18
|
-
*
|
19
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
23
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
25
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
26
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
*/
|
1
|
+
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
30
2
|
|
31
3
|
#include "hash.h"
|
32
4
|
#include <stdint.h>
|
@@ -85,7 +57,7 @@ hash_calc(const uint8_t *key, size_t len) {
|
|
85
57
|
h ^= h >> 13;
|
86
58
|
h *= M;
|
87
59
|
h ^= h >> 15;
|
88
|
-
|
60
|
+
|
89
61
|
return h;
|
90
62
|
}
|
91
63
|
|
@@ -115,7 +87,7 @@ hash_get(Hash hash, const char *key, size_t len, VALUE **slotp, VALUE def_value)
|
|
115
87
|
if (0 != slotp) {
|
116
88
|
if (0 != bucket->key) {
|
117
89
|
KeyVal b = ALLOC(struct _keyVal);
|
118
|
-
|
90
|
+
|
119
91
|
b->next = 0;
|
120
92
|
bucket->next = b;
|
121
93
|
bucket = b;
|
@@ -155,7 +127,7 @@ oj_attr_hash_get(const char *key, size_t len, ID **slotp) {
|
|
155
127
|
char*
|
156
128
|
oj_strndup(const char *s, size_t len) {
|
157
129
|
char *d = ALLOC_N(char, len + 1);
|
158
|
-
|
130
|
+
|
159
131
|
memcpy(d, s, len);
|
160
132
|
d[len] = '\0';
|
161
133
|
|
data/ext/oj/hash.h
CHANGED
@@ -1,32 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2011, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*
|
5
|
-
* Redistribution and use in source and binary forms, with or without
|
6
|
-
* modification, are permitted provided that the following conditions are met:
|
7
|
-
*
|
8
|
-
* - Redistributions of source code must retain the above copyright notice, this
|
9
|
-
* list of conditions and the following disclaimer.
|
10
|
-
*
|
11
|
-
* - Redistributions in binary form must reproduce the above copyright notice,
|
12
|
-
* this list of conditions and the following disclaimer in the documentation
|
13
|
-
* and/or other materials provided with the distribution.
|
14
|
-
*
|
15
|
-
* - Neither the name of Peter Ohler nor the names of its contributors may be
|
16
|
-
* used to endorse or promote products derived from this software without
|
17
|
-
* specific prior written permission.
|
18
|
-
*
|
19
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
23
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
25
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
26
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
*/
|
1
|
+
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
30
2
|
|
31
3
|
#ifndef OJ_HASH_H
|
32
4
|
#define OJ_HASH_H
|
data/ext/oj/hash_test.c
CHANGED
@@ -1,32 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2011, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*
|
5
|
-
* Redistribution and use in source and binary forms, with or without
|
6
|
-
* modification, are permitted provided that the following conditions are met:
|
7
|
-
*
|
8
|
-
* - Redistributions of source code must retain the above copyright notice, this
|
9
|
-
* list of conditions and the following disclaimer.
|
10
|
-
*
|
11
|
-
* - Redistributions in binary form must reproduce the above copyright notice,
|
12
|
-
* this list of conditions and the following disclaimer in the documentation
|
13
|
-
* and/or other materials provided with the distribution.
|
14
|
-
*
|
15
|
-
* - Neither the name of Peter Ohler nor the names of its contributors may be
|
16
|
-
* used to endorse or promote products derived from this software without
|
17
|
-
* specific prior written permission.
|
18
|
-
*
|
19
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
23
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
25
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
26
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
*/
|
1
|
+
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
30
2
|
|
31
3
|
// if windows, comment out the whole file. It's only a performance test.
|
32
4
|
#ifndef _WIN32
|
data/ext/oj/mimic_json.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 "oj.h"
|
7
4
|
#include "encode.h"
|
@@ -367,7 +364,6 @@ mimic_generate_core(int argc, VALUE *argv, Options copts) {
|
|
367
364
|
struct _out out;
|
368
365
|
VALUE rstr;
|
369
366
|
|
370
|
-
// TBD
|
371
367
|
memset(buf, 0, sizeof(buf));
|
372
368
|
|
373
369
|
out.buf = buf;
|
@@ -513,7 +509,6 @@ mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
|
|
513
509
|
pi.options.create_ok = No;
|
514
510
|
pi.options.allow_nan = (bang ? Yes : No);
|
515
511
|
pi.options.nilnil = No;
|
516
|
-
//pi.options.bigdec_load = FloatDec;
|
517
512
|
pi.options.bigdec_load = RubyDec;
|
518
513
|
pi.options.mode = CompatMode;
|
519
514
|
pi.max_depth = 100;
|
@@ -564,6 +559,9 @@ mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
|
|
564
559
|
pi.options.array_class = v;
|
565
560
|
}
|
566
561
|
}
|
562
|
+
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_decimal_class_sym)) {
|
563
|
+
pi.options.compat_bigdec = (oj_bigdecimal_class == rb_hash_lookup(ropts, oj_decimal_class_sym));
|
564
|
+
}
|
567
565
|
v = rb_hash_lookup(ropts, oj_max_nesting_sym);
|
568
566
|
if (Qtrue == v) {
|
569
567
|
pi.max_depth = 100;
|
@@ -688,6 +686,7 @@ static struct _options mimic_object_to_json_options = {
|
|
688
686
|
RubyTime, // time_format
|
689
687
|
No, // bigdec_as_num
|
690
688
|
RubyDec, // bigdec_load
|
689
|
+
false, // compat_bigdec
|
691
690
|
No, // to_hash
|
692
691
|
No, // to_json
|
693
692
|
No, // as_json
|
data/ext/oj/object.c
CHANGED
data/ext/oj/odd.c
CHANGED
data/ext/oj/odd.h
CHANGED
data/ext/oj/oj.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2012, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2012 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#include <stdlib.h>
|
7
4
|
#include <errno.h>
|
@@ -91,6 +88,7 @@ VALUE oj_slash_string;
|
|
91
88
|
VALUE oj_allow_nan_sym;
|
92
89
|
VALUE oj_array_class_sym;
|
93
90
|
VALUE oj_create_additions_sym;
|
91
|
+
VALUE oj_decimal_class_sym;
|
94
92
|
VALUE oj_hash_class_sym;
|
95
93
|
VALUE oj_indent_sym;
|
96
94
|
VALUE oj_object_class_sym;
|
@@ -109,6 +107,7 @@ static VALUE bigdecimal_load_sym;
|
|
109
107
|
static VALUE bigdecimal_sym;
|
110
108
|
static VALUE circular_sym;
|
111
109
|
static VALUE class_cache_sym;
|
110
|
+
static VALUE compat_bigdecimal_sym;
|
112
111
|
static VALUE compat_sym;
|
113
112
|
static VALUE create_id_sym;
|
114
113
|
static VALUE custom_sym;
|
@@ -170,6 +169,7 @@ struct _options oj_default_options = {
|
|
170
169
|
UnixTime, // time_format
|
171
170
|
NotSet, // bigdec_as_num
|
172
171
|
AutoDec, // bigdec_load
|
172
|
+
false, // compat_bigdec
|
173
173
|
No, // to_hash
|
174
174
|
No, // to_json
|
175
175
|
No, // as_json
|
@@ -232,6 +232,7 @@ struct _options oj_default_options = {
|
|
232
232
|
* - *:time_format* [_:unix_|_:unix_zone_|_:xmlschema_|_:ruby_] time format when dumping
|
233
233
|
* - *:bigdecimal_as_decimal* [_Boolean_|_nil_] dump BigDecimal as a decimal number or as a String
|
234
234
|
* - *:bigdecimal_load* [_:bigdecimal_|_:float_|_:auto_|_:fast_] load decimals as BigDecimal instead of as a Float. :auto pick the most precise for the number of digits. :float should be the same as ruby. :fast may require rounding but is must faster.
|
235
|
+
* - *:compat_bigdecimal* [_true_|_false_] load decimals as BigDecimal instead of as a Float when in compat or rails mode.
|
235
236
|
* - *:create_id* [_String_|_nil_] create id for json compatible object encoding, default is 'json_class'
|
236
237
|
* - *:create_additions* [_Boolean_|_nil_] if true allow creation of instances using create_id on load.
|
237
238
|
* - *:second_precision* [_Fixnum_|_nil_] number of digits after the decimal when dumping the seconds portion of time
|
@@ -336,6 +337,7 @@ get_def_opts(VALUE self) {
|
|
336
337
|
case AutoDec:
|
337
338
|
default: rb_hash_aset(opts, bigdecimal_load_sym, auto_sym); break;
|
338
339
|
}
|
340
|
+
rb_hash_aset(opts, compat_bigdecimal_sym, oj_default_options.compat_bigdec ? Qtrue : Qfalse);
|
339
341
|
rb_hash_aset(opts, create_id_sym, (NULL == oj_default_options.create_id) ? Qnil : rb_str_new2(oj_default_options.create_id));
|
340
342
|
rb_hash_aset(opts, oj_space_sym, (0 == oj_default_options.dump_opts.after_size) ? Qnil : rb_str_new2(oj_default_options.dump_opts.after_sep));
|
341
343
|
rb_hash_aset(opts, oj_space_before_sym, (0 == oj_default_options.dump_opts.before_size) ? Qnil : rb_str_new2(oj_default_options.dump_opts.before_sep));
|
@@ -381,6 +383,7 @@ get_def_opts(VALUE self) {
|
|
381
383
|
* - *:escape* [_:newline_|_:json_|_:xss_safe_|_:ascii_|_unicode_xss_|_nil_] mode encodes all high-bit characters as escaped sequences if :ascii, :json is standand UTF-8 JSON encoding, :newline is the same as :json but newlines are not escaped, :unicode_xss allows unicode but escapes &, <, and >, and any \u20xx characters along with some others, and :xss_safe escapes &, <, and >, and some others.
|
382
384
|
* - *:bigdecimal_as_decimal* [_Boolean_|_nil_] dump BigDecimal as a decimal number or as a String.
|
383
385
|
* - *:bigdecimal_load* [_:bigdecimal_|_:float_|_:auto_|_nil_] load decimals as BigDecimal instead of as a Float. :auto pick the most precise for the number of digits.
|
386
|
+
* - *:compat_bigdecimal* [_true_|_false_] load decimals as BigDecimal instead of as a Float in compat mode.
|
384
387
|
* - *:mode* [_:object_|_:strict_|_:compat_|_:null_|_:custom_|_:rails_|_:wab_] load and dump mode to use for JSON :strict raises an exception when a non-supported Object is encountered. :compat attempts to extract variable values from an Object using to_json() or to_hash() then it walks the Object's variables if neither is found. The :object mode ignores to_hash() and to_json() methods and encodes variables using code internal to the Oj gem. The :null mode ignores non-supported Objects and replaces them with a null. The :custom mode honors all dump options. The :rails more mimics rails and Active behavior.
|
385
388
|
* - *:time_format* [_:unix_|_:xmlschema_|_:ruby_] time format when dumping in :compat mode :unix decimal number denoting the number of seconds since 1/1/1970, :unix_zone decimal number denoting the number of seconds since 1/1/1970 plus the utc_offset in the exponent, :xmlschema date-time format taken from XML Schema as a String, :ruby Time.to_s formatted String.
|
386
389
|
* - *:create_id* [_String_|_nil_] create id for json compatible object encoding
|
@@ -584,6 +587,21 @@ oj_parse_options(VALUE ropts, Options copts) {
|
|
584
587
|
rb_raise(rb_eArgError, ":bigdecimal_load must be :bigdecimal, :float, or :auto.");
|
585
588
|
}
|
586
589
|
}
|
590
|
+
if (Qnil != (v = rb_hash_lookup(ropts, compat_bigdecimal_sym))) {
|
591
|
+
copts->compat_bigdec = (Qtrue == v);
|
592
|
+
}
|
593
|
+
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_decimal_class_sym)) {
|
594
|
+
v = rb_hash_lookup(ropts, oj_decimal_class_sym);
|
595
|
+
if (rb_cFloat == v) {
|
596
|
+
copts->compat_bigdec = FloatDec;
|
597
|
+
} else if (oj_bigdecimal_class == v) {
|
598
|
+
copts->compat_bigdec = BigDec;
|
599
|
+
} else if (Qnil == v) {
|
600
|
+
copts->compat_bigdec = AutoDec;
|
601
|
+
} else {
|
602
|
+
rb_raise(rb_eArgError, ":decimal_class must be BigDecimal, Float, or nil.");
|
603
|
+
}
|
604
|
+
}
|
587
605
|
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, create_id_sym)) {
|
588
606
|
v = rb_hash_lookup(ropts, create_id_sym);
|
589
607
|
if (Qnil == v) {
|
@@ -1652,6 +1670,7 @@ Init_oj() {
|
|
1652
1670
|
bigdecimal_sym = ID2SYM(rb_intern("bigdecimal")); rb_gc_register_address(&bigdecimal_sym);
|
1653
1671
|
circular_sym = ID2SYM(rb_intern("circular")); rb_gc_register_address(&circular_sym);
|
1654
1672
|
class_cache_sym = ID2SYM(rb_intern("class_cache")); rb_gc_register_address(&class_cache_sym);
|
1673
|
+
compat_bigdecimal_sym = ID2SYM(rb_intern("compat_bigdecimal"));rb_gc_register_address(&compat_bigdecimal_sym);
|
1655
1674
|
compat_sym = ID2SYM(rb_intern("compat")); rb_gc_register_address(&compat_sym);
|
1656
1675
|
create_id_sym = ID2SYM(rb_intern("create_id")); rb_gc_register_address(&create_id_sym);
|
1657
1676
|
custom_sym = ID2SYM(rb_intern("custom")); rb_gc_register_address(&custom_sym);
|
@@ -1677,6 +1696,7 @@ Init_oj() {
|
|
1677
1696
|
oj_array_nl_sym = ID2SYM(rb_intern("array_nl")); rb_gc_register_address(&oj_array_nl_sym);
|
1678
1697
|
oj_ascii_only_sym = ID2SYM(rb_intern("ascii_only")); rb_gc_register_address(&oj_ascii_only_sym);
|
1679
1698
|
oj_create_additions_sym = ID2SYM(rb_intern("create_additions"));rb_gc_register_address(&oj_create_additions_sym);
|
1699
|
+
oj_decimal_class_sym = ID2SYM(rb_intern("decimal_class")); rb_gc_register_address(&oj_decimal_class_sym);
|
1680
1700
|
oj_hash_class_sym = ID2SYM(rb_intern("hash_class")); rb_gc_register_address(&oj_hash_class_sym);
|
1681
1701
|
oj_indent_sym = ID2SYM(rb_intern("indent")); rb_gc_register_address(&oj_indent_sym);
|
1682
1702
|
oj_max_nesting_sym = ID2SYM(rb_intern("max_nesting")); rb_gc_register_address(&oj_max_nesting_sym);
|
data/ext/oj/oj.h
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2011, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#ifndef OJ_H
|
7
4
|
#define OJ_H
|
@@ -138,6 +135,7 @@ typedef struct _options {
|
|
138
135
|
char time_format; // TimeFormat
|
139
136
|
char bigdec_as_num; // YesNo
|
140
137
|
char bigdec_load; // BigLoad
|
138
|
+
char compat_bigdec; // boolean (0 or 1)
|
141
139
|
char to_hash; // YesNo
|
142
140
|
char to_json; // YesNo
|
143
141
|
char as_json; // YesNo
|
@@ -313,6 +311,7 @@ extern VALUE oj_array_class_sym;
|
|
313
311
|
extern VALUE oj_array_nl_sym;
|
314
312
|
extern VALUE oj_ascii_only_sym;
|
315
313
|
extern VALUE oj_create_additions_sym;
|
314
|
+
extern VALUE oj_decimal_class_sym;
|
316
315
|
extern VALUE oj_hash_class_sym;
|
317
316
|
extern VALUE oj_indent_sym;
|
318
317
|
extern VALUE oj_max_nesting_sym;
|
data/ext/oj/parse.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2013, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2013 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#include <stdlib.h>
|
7
4
|
#include <stdio.h>
|
@@ -215,18 +212,6 @@ read_escaped_str(ParseInfo pi, const char *start) {
|
|
215
212
|
case '"': buf_append(&buf, '"'); break;
|
216
213
|
case '/': buf_append(&buf, '/'); break;
|
217
214
|
case '\\': buf_append(&buf, '\\'); break;
|
218
|
-
case '\'':
|
219
|
-
// The json gem claims this is not an error despite the
|
220
|
-
// ECMA-404 indicating it is not valid.
|
221
|
-
if (CompatMode == pi->options.mode) {
|
222
|
-
buf_append(&buf, '\'');
|
223
|
-
} else {
|
224
|
-
pi->cur = s;
|
225
|
-
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "invalid escaped character");
|
226
|
-
buf_cleanup(&buf);
|
227
|
-
return;
|
228
|
-
}
|
229
|
-
break;
|
230
215
|
case 'u':
|
231
216
|
s++;
|
232
217
|
if (0 == (code = read_hex(pi, s)) && err_has(&pi->err)) {
|
@@ -266,6 +251,12 @@ read_escaped_str(ParseInfo pi, const char *start) {
|
|
266
251
|
}
|
267
252
|
break;
|
268
253
|
default:
|
254
|
+
// The json gem claims this is not an error despite the
|
255
|
+
// ECMA-404 indicating it is not valid.
|
256
|
+
if (CompatMode == pi->options.mode) {
|
257
|
+
buf_append(&buf, *s);
|
258
|
+
break;
|
259
|
+
}
|
269
260
|
pi->cur = s;
|
270
261
|
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "invalid escaped character");
|
271
262
|
buf_cleanup(&buf);
|
@@ -394,8 +385,13 @@ read_num(ParseInfo pi) {
|
|
394
385
|
ni.nan = 0;
|
395
386
|
ni.neg = 0;
|
396
387
|
ni.has_exp = 0;
|
397
|
-
|
398
|
-
|
388
|
+
if (CompatMode == pi->options.mode) {
|
389
|
+
ni.no_big = !pi->options.compat_bigdec;
|
390
|
+
ni.bigdec_load = pi->options.compat_bigdec;
|
391
|
+
} else {
|
392
|
+
ni.no_big = (FloatDec == pi->options.bigdec_load || FastDec == pi->options.bigdec_load || RubyDec == pi->options.bigdec_load);
|
393
|
+
ni.bigdec_load = pi->options.bigdec_load;
|
394
|
+
}
|
399
395
|
|
400
396
|
if ('-' == *pi->cur) {
|
401
397
|
pi->cur++;
|
@@ -520,7 +516,11 @@ read_num(ParseInfo pi) {
|
|
520
516
|
ni.nan = 1;
|
521
517
|
}
|
522
518
|
}
|
523
|
-
if (
|
519
|
+
if (CompatMode == pi->options.mode) {
|
520
|
+
if (pi->options.compat_bigdec) {
|
521
|
+
ni.big = 1;
|
522
|
+
}
|
523
|
+
} else if (BigDec == pi->options.bigdec_load) {
|
524
524
|
ni.big = 1;
|
525
525
|
}
|
526
526
|
if (0 == parent) {
|
data/ext/oj/parse.h
CHANGED
data/ext/oj/rails.c
CHANGED
data/ext/oj/rails.h
CHANGED
data/ext/oj/reader.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2011, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#include <stdlib.h>
|
7
4
|
#include <errno.h>
|
@@ -9,7 +6,7 @@
|
|
9
6
|
#include <strings.h>
|
10
7
|
#include <sys/types.h>
|
11
8
|
#if NEEDS_UIO
|
12
|
-
#include <sys/uio.h>
|
9
|
+
#include <sys/uio.h>
|
13
10
|
#endif
|
14
11
|
#include <unistd.h>
|
15
12
|
#include <time.h>
|
@@ -78,13 +75,13 @@ oj_reader_init(Reader reader, VALUE io, int fd, bool to_s) {
|
|
78
75
|
reader->io = io;
|
79
76
|
} else if (to_s) {
|
80
77
|
volatile VALUE rstr = rb_funcall(io, oj_to_s_id, 0);
|
81
|
-
|
78
|
+
|
82
79
|
reader->read_func = 0;
|
83
80
|
reader->in_str = StringValuePtr(rstr);
|
84
81
|
reader->head = (char*)reader->in_str;
|
85
82
|
reader->tail = reader->head;
|
86
83
|
reader->read_end = reader->head + RSTRING_LEN(rstr);
|
87
|
-
} else {
|
84
|
+
} else {
|
88
85
|
rb_raise(rb_eArgError, "parser io argument must be a String or respond to readpartial() or read().\n");
|
89
86
|
}
|
90
87
|
}
|
@@ -107,7 +104,7 @@ oj_reader_read(Reader reader) {
|
|
107
104
|
if (0 >= shift) { /* no space left so allocate more */
|
108
105
|
const char *old = reader->head;
|
109
106
|
size_t size = reader->end - reader->head + BUF_PAD;
|
110
|
-
|
107
|
+
|
111
108
|
if (reader->head == reader->base) {
|
112
109
|
reader->head = ALLOC_N(char, size * 2);
|
113
110
|
memcpy((char*)reader->head, old, size);
|