oj 3.9.2 → 3.10.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- 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 +6 -9
- data/ext/oj/custom.c +8 -7
- data/ext/oj/dump.c +33 -26
- data/ext/oj/dump.h +1 -4
- data/ext/oj/dump_compat.c +9 -14
- data/ext/oj/dump_leaf.c +2 -5
- data/ext/oj/dump_object.c +19 -15
- data/ext/oj/dump_strict.c +7 -9
- data/ext/oj/encode.h +1 -29
- data/ext/oj/err.c +1 -4
- data/ext/oj/err.h +1 -29
- data/ext/oj/extconf.rb +5 -0
- 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 +28 -10
- data/ext/oj/object.c +4 -6
- data/ext/oj/odd.c +1 -4
- data/ext/oj/odd.h +1 -4
- data/ext/oj/oj.c +74 -38
- data/ext/oj/oj.h +9 -7
- data/ext/oj/parse.c +127 -52
- data/ext/oj/parse.h +4 -5
- data/ext/oj/rails.c +38 -8
- 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 +31 -26
- 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 +10 -13
- data/lib/oj/mimic.rb +45 -1
- data/lib/oj/version.rb +1 -1
- data/lib/oj.rb +0 -8
- data/pages/Modes.md +1 -1
- data/pages/Options.md +15 -11
- data/pages/Rails.md +60 -21
- 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 +21 -11
- data/test/baz.rb +16 -0
- data/test/foo.rb +39 -8
- data/test/json_gem/json_common_interface_test.rb +8 -3
- data/test/prec.rb +23 -0
- data/test/sample_json.rb +1 -1
- data/test/test_compat.rb +14 -8
- data/test/test_custom.rb +36 -6
- data/test/test_integer_range.rb +1 -2
- data/test/test_object.rb +12 -3
- data/test/test_rails.rb +35 -0
- data/test/test_strict.rb +24 -1
- data/test/test_various.rb +42 -64
- data/test/tests.rb +1 -0
- metadata +29 -7
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
|
}
|
data/ext/oj/encode.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_ENCODE_H
|
32
4
|
#define OJ_ENCODE_H
|
data/ext/oj/err.c
CHANGED
data/ext/oj/err.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_ERR_H
|
32
4
|
#define OJ_ERR_H
|
data/ext/oj/extconf.rb
CHANGED
@@ -42,6 +42,11 @@ end
|
|
42
42
|
|
43
43
|
$CPPFLAGS += ' -Wall'
|
44
44
|
#puts "*** $CPPFLAGS: #{$CPPFLAGS}"
|
45
|
+
# Adding the __attribute__ flag only works with gcc compilers and even then it
|
46
|
+
# does not work to check args with varargs so just remove the check.
|
47
|
+
CONFIG['warnflags'].slice!(/ -Wsuggest-attribute=format/)
|
48
|
+
CONFIG['warnflags'].slice!(/ -Wdeclaration-after-statement/)
|
49
|
+
CONFIG['warnflags'].slice!(/ -Wmissing-noreturn/)
|
45
50
|
|
46
51
|
create_makefile(File.join(extension_name, extension_name))
|
47
52
|
|
data/ext/oj/fast.c
CHANGED
@@ -1,32 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2012, 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) 2012 Peter Ohler. All rights reserved.
|
30
2
|
|
31
3
|
#if !IS_WINDOWS
|
32
4
|
#include <sys/resource.h> // for getrlimit() on linux
|
@@ -121,7 +93,7 @@ VALUE oj_doc_class = Qundef;
|
|
121
93
|
#ifndef HAVE_STPCPY
|
122
94
|
char *stpcpy(char *dest, const char *src) {
|
123
95
|
size_t cnt = strlen(src);
|
124
|
-
|
96
|
+
|
125
97
|
strcpy(dest, src);
|
126
98
|
|
127
99
|
return dest + cnt;
|
@@ -322,7 +294,7 @@ leaf_fixnum_value(Leaf leaf) {
|
|
322
294
|
int64_t n = 0;
|
323
295
|
int neg = 0;
|
324
296
|
int big = 0;
|
325
|
-
|
297
|
+
|
326
298
|
if ('-' == *s) {
|
327
299
|
s++;
|
328
300
|
neg = 1;
|
@@ -337,7 +309,7 @@ leaf_fixnum_value(Leaf leaf) {
|
|
337
309
|
}
|
338
310
|
if (big) {
|
339
311
|
char c = *s;
|
340
|
-
|
312
|
+
|
341
313
|
*s = '\0';
|
342
314
|
leaf->value = rb_cstr_to_inum(leaf->str, 10, 0);
|
343
315
|
*s = c;
|
@@ -672,7 +644,7 @@ read_quoted_value(ParseInfo pi) {
|
|
672
644
|
char *value = 0;
|
673
645
|
char *h = pi->s; // head
|
674
646
|
char *t = h; // tail
|
675
|
-
|
647
|
+
|
676
648
|
h++; // skip quote character
|
677
649
|
t++;
|
678
650
|
value = h;
|
@@ -805,7 +777,7 @@ static void
|
|
805
777
|
mark_doc(void *ptr) {
|
806
778
|
if (NULL != ptr) {
|
807
779
|
Doc doc = (Doc)ptr;
|
808
|
-
|
780
|
+
|
809
781
|
rb_gc_mark(doc->self);
|
810
782
|
mark_leaf(doc->data);
|
811
783
|
}
|
@@ -820,7 +792,7 @@ parse_json(VALUE clas, char *json, bool given, bool allocated) {
|
|
820
792
|
volatile VALUE self;
|
821
793
|
|
822
794
|
// TBD are both needed? is stack allocation ever needed?
|
823
|
-
|
795
|
+
|
824
796
|
if (given) {
|
825
797
|
doc = ALLOCA_N(struct _doc, 1);
|
826
798
|
} else {
|
@@ -1226,7 +1198,7 @@ doc_open_file(VALUE clas, VALUE filename) {
|
|
1226
1198
|
fseek(f, 0, SEEK_SET);
|
1227
1199
|
if (len != fread(json, 1, len, f)) {
|
1228
1200
|
fclose(f);
|
1229
|
-
rb_raise(rb_const_get_at(Oj, rb_intern("LoadError")),
|
1201
|
+
rb_raise(rb_const_get_at(Oj, rb_intern("LoadError")),
|
1230
1202
|
"Failed to read %lu bytes from %s.", (unsigned long)len, path);
|
1231
1203
|
}
|
1232
1204
|
fclose(f);
|
@@ -1575,7 +1547,7 @@ doc_each_child(int argc, VALUE *argv, VALUE self) {
|
|
1575
1547
|
* result
|
1576
1548
|
* }
|
1577
1549
|
* #=> [3, 2, 1]
|
1578
|
-
*
|
1550
|
+
*
|
1579
1551
|
* Oj::Doc.open('[3,[2,1]]') { |doc|
|
1580
1552
|
* result = []
|
1581
1553
|
* doc.each_value('/2') { |v| result << v }
|
@@ -1708,21 +1680,21 @@ doc_not_implemented(VALUE self) {
|
|
1708
1680
|
* extracted. Once the document is closed the document can not longer be
|
1709
1681
|
* accessed. This allows the parsing and data extraction to be extremely fast
|
1710
1682
|
* compared to other JSON parses.
|
1711
|
-
*
|
1683
|
+
*
|
1712
1684
|
* An Oj::Doc class is not created directly but the _open()_ class method is
|
1713
1685
|
* used to open a document and the yield parameter to the block of the #open()
|
1714
1686
|
* call is the Doc instance. The Doc instance can be moved across, up, and
|
1715
1687
|
* down the JSON document. At each element the data associated with the
|
1716
1688
|
* element can be extracted. It is also possible to just provide a path to the
|
1717
1689
|
* data to be extracted and retrieve the data in that manner.
|
1718
|
-
*
|
1690
|
+
*
|
1719
1691
|
* For many of the methods a path is used to describe the location of an
|
1720
1692
|
* element. Paths follow a subset of the XPath syntax. The slash ('/')
|
1721
1693
|
* character is the separator. Each step in the path identifies the next
|
1722
1694
|
* branch to take through the document. A JSON object will expect a key string
|
1723
1695
|
* while an array will expect a positive index. A .. step indicates a move up
|
1724
1696
|
* the JSON document.
|
1725
|
-
*
|
1697
|
+
*
|
1726
1698
|
* @example
|
1727
1699
|
* json = %{[
|
1728
1700
|
* {
|
@@ -1736,12 +1708,12 @@ doc_not_implemented(VALUE self) {
|
|
1736
1708
|
* ]}
|
1737
1709
|
* # move and get value
|
1738
1710
|
* Oj::Doc.open(json) do |doc|
|
1739
|
-
* doc.move('/1/two')
|
1711
|
+
* doc.move('/1/two')
|
1740
1712
|
* # doc location is now at the 'two' element of the hash that is the first element of the array.
|
1741
1713
|
* doc.fetch()
|
1742
1714
|
* end
|
1743
1715
|
* #=> 2
|
1744
|
-
*
|
1716
|
+
*
|
1745
1717
|
* # Now try again using a path to Oj::Doc.fetch() directly and not using a block.
|
1746
1718
|
* doc = Oj::Doc.open(json)
|
1747
1719
|
* doc.fetch('/2/three') #=> 3
|
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"
|
@@ -199,6 +196,7 @@ mimic_dump(int argc, VALUE *argv, VALUE self) {
|
|
199
196
|
struct _out out;
|
200
197
|
struct _options copts = oj_default_options;
|
201
198
|
VALUE rstr;
|
199
|
+
VALUE active_hack[1];
|
202
200
|
|
203
201
|
copts.str_rx.head = NULL;
|
204
202
|
copts.str_rx.tail = NULL;
|
@@ -216,6 +214,7 @@ mimic_dump(int argc, VALUE *argv, VALUE self) {
|
|
216
214
|
*/
|
217
215
|
copts.dump_opts.max_depth = MAX_DEPTH; // when using dump there is no limit
|
218
216
|
out.omit_nil = copts.dump_opts.omit_nil;
|
217
|
+
|
219
218
|
if (2 <= argc) {
|
220
219
|
int limit;
|
221
220
|
|
@@ -230,7 +229,15 @@ mimic_dump(int argc, VALUE *argv, VALUE self) {
|
|
230
229
|
copts.dump_opts.max_depth = limit;
|
231
230
|
}
|
232
231
|
}
|
233
|
-
|
232
|
+
// ActiveSupport in active_support/core_ext/object/json.rb check the
|
233
|
+
// optional argument type to to_json and it the argument is a
|
234
|
+
// ::JSON::State it calls the JSON gem code otherwise it calls the active
|
235
|
+
// support encoder code. To make sure the desired branch is called a
|
236
|
+
// default ::JSON::State argument is passed in. Basically a hack to get
|
237
|
+
// around the active support hack so two wrongs make a right this time.
|
238
|
+
active_hack[0] = rb_funcall(state_class, oj_new_id, 0);
|
239
|
+
oj_dump_obj_to_json_using_params(*argv, &copts, &out, 1, active_hack);
|
240
|
+
|
234
241
|
if (0 == out.buf) {
|
235
242
|
rb_raise(rb_eNoMemError, "Not enough memory.");
|
236
243
|
}
|
@@ -503,7 +510,6 @@ mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
|
|
503
510
|
pi.options.create_ok = No;
|
504
511
|
pi.options.allow_nan = (bang ? Yes : No);
|
505
512
|
pi.options.nilnil = No;
|
506
|
-
pi.options.bigdec_load = FloatDec;
|
507
513
|
pi.options.mode = CompatMode;
|
508
514
|
pi.max_depth = 100;
|
509
515
|
|
@@ -553,6 +559,16 @@ mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
|
|
553
559
|
pi.options.array_class = v;
|
554
560
|
}
|
555
561
|
}
|
562
|
+
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_decimal_class_sym)) {
|
563
|
+
v = rb_hash_lookup(ropts, oj_decimal_class_sym);
|
564
|
+
if (rb_cFloat == v) {
|
565
|
+
pi.options.bigdec_load = FloatDec;
|
566
|
+
} else if (oj_bigdecimal_class == v) {
|
567
|
+
pi.options.bigdec_load = BigDec;
|
568
|
+
} else if (Qnil == v) {
|
569
|
+
pi.options.bigdec_load = AutoDec;
|
570
|
+
}
|
571
|
+
}
|
556
572
|
v = rb_hash_lookup(ropts, oj_max_nesting_sym);
|
557
573
|
if (Qtrue == v) {
|
558
574
|
pi.max_depth = 100;
|
@@ -676,7 +692,7 @@ static struct _options mimic_object_to_json_options = {
|
|
676
692
|
No, // class_cache
|
677
693
|
RubyTime, // time_format
|
678
694
|
No, // bigdec_as_num
|
679
|
-
|
695
|
+
RubyDec, // bigdec_load
|
680
696
|
No, // to_hash
|
681
697
|
No, // to_json
|
682
698
|
No, // as_json
|
@@ -690,12 +706,14 @@ static struct _options mimic_object_to_json_options = {
|
|
690
706
|
No, // allow_nan
|
691
707
|
No, // trace
|
692
708
|
No, // safe
|
693
|
-
|
694
|
-
|
709
|
+
false, // sec_prec_set
|
710
|
+
No, // ignore_under
|
711
|
+
0, // int_range_min
|
712
|
+
0, // int_range_max
|
695
713
|
oj_json_class,// create_id
|
696
714
|
10, // create_id_len
|
697
715
|
3, // sec_prec
|
698
|
-
|
716
|
+
0, // float_prec
|
699
717
|
"%0.16g", // float_fmt
|
700
718
|
Qnil, // hash_class
|
701
719
|
Qnil, // array_class
|
data/ext/oj/object.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 <stdint.h>
|
7
4
|
#include <stdio.h>
|
@@ -295,7 +292,7 @@ hat_num(ParseInfo pi, Val parent, Val kval, NumInfo ni) {
|
|
295
292
|
// offset and then a conversion to UTC keeps makes the time
|
296
293
|
// match the expected value.
|
297
294
|
parent->val = rb_funcall2(parent->val, oj_utc_id, 0, 0);
|
298
|
-
} else if (ni->
|
295
|
+
} else if (ni->has_exp) {
|
299
296
|
int64_t t = (int64_t)(ni->i + ni->exp);
|
300
297
|
struct _timeInfo ti;
|
301
298
|
VALUE args[8];
|
@@ -669,7 +666,8 @@ static void
|
|
669
666
|
array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
670
667
|
volatile VALUE rval = Qnil;
|
671
668
|
|
672
|
-
|
669
|
+
// orig lets us know whether the string was ^r1 or \u005er1
|
670
|
+
if (3 <= len && 0 != pi->circ_array && '^' == orig[0] && 0 == rb_array_len(stack_peek(&pi->stack)->val)) {
|
673
671
|
if ('i' == str[1]) {
|
674
672
|
long i = read_long(str + 2, len - 2);
|
675
673
|
|
data/ext/oj/odd.c
CHANGED