oj 3.10.1 → 3.11.1
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 +1 -1
- 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 +2 -5
- data/ext/oj/dump.c +24 -14
- 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 +2 -5
- 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 +9 -8
- 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 +43 -10
- data/ext/oj/oj.h +6 -5
- data/ext/oj/parse.c +124 -49
- data/ext/oj/parse.h +3 -5
- data/ext/oj/rails.c +1 -5
- 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 +56 -27
- 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/lib/oj.rb +0 -8
- data/pages/Modes.md +1 -0
- data/pages/Options.md +23 -11
- data/pages/Rails.md +39 -0
- data/test/bar.rb +21 -8
- 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 +16 -3
- data/test/test_custom.rb +11 -0
- data/test/test_object.rb +8 -0
- data/test/test_rails.rb +9 -0
- data/test/test_various.rb +2 -2
- metadata +87 -85
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 698d68ef4c5a05318046700568e3d19c9d5e40644950c76cf02d31490a4bd738
|
4
|
+
data.tar.gz: 1cff670f6587f0080108980d339f9c8cff3097bb5e7cf67a2c583e8745385b7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cfb98a97ead48a89f95af28dc364633199afb5cbe269ba07b90a26eabe77d9e59c1051731e07ff3821233bdf10d54896c2e9821786dfee2140beaac9dc8c0d2
|
7
|
+
data.tar.gz: 79173558b0cc6e4cb9852c32e7949d88396ffbb8f34cc7781f6144ade5c7ecf5cf8b24a374056ee50e8367d96ba79510cf8ba21a19acd8e52a61c8c731b44921
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# [](http://www.ohler.com/oj) gem
|
2
2
|
|
3
|
-
[](http://travis-ci.org/ohler55/oj?branch=master)
|
3
|
+
[](http://travis-ci.org/ohler55/oj?branch=master)   [](https://dependabot.com/compatibility-score.html?dependency-name=oj&package-manager=bundler&version-scheme=semver) [](https://tidelift.com/subscription/pkg/rubygems-oj?utm_source=rubygems-oj&utm_medium=referral&utm_campaign=readme)
|
4
4
|
|
5
5
|
A *fast* JSON parser and Object marshaller as a Ruby gem.
|
6
6
|
|
data/ext/oj/buf.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_BUF_H
|
32
4
|
#define OJ_BUF_H
|
@@ -78,7 +50,7 @@ buf_append_string(Buf buf, const char *s, size_t slen) {
|
|
78
50
|
memcpy(buf->tail, s, slen);
|
79
51
|
buf->tail += slen;
|
80
52
|
}
|
81
|
-
|
53
|
+
|
82
54
|
inline static void
|
83
55
|
buf_append(Buf buf, char c) {
|
84
56
|
if (buf->end <= buf->tail) {
|
data/ext/oj/cache8.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_CACHE8_H
|
32
4
|
#define OJ_CACHE8_H
|
data/ext/oj/circarray.c
CHANGED
@@ -1,21 +1,18 @@
|
|
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 "circarray.h"
|
7
4
|
|
8
5
|
CircArray
|
9
6
|
oj_circ_array_new() {
|
10
7
|
CircArray ca;
|
11
|
-
|
8
|
+
|
12
9
|
if (0 == (ca = ALLOC(struct _circArray))) {
|
13
10
|
rb_raise(rb_eNoMemError, "not enough memory\n");
|
14
11
|
}
|
15
12
|
ca->objs = ca->obj_array;
|
16
13
|
ca->size = sizeof(ca->obj_array) / sizeof(VALUE);
|
17
14
|
ca->cnt = 0;
|
18
|
-
|
15
|
+
|
19
16
|
return ca;
|
20
17
|
}
|
21
18
|
|
@@ -40,7 +37,7 @@ oj_circ_array_set(CircArray ca, VALUE obj, unsigned long id) {
|
|
40
37
|
rb_raise(rb_eNoMemError, "not enough memory\n");
|
41
38
|
}
|
42
39
|
memcpy(ca->objs, ca->obj_array, sizeof(VALUE) * ca->cnt);
|
43
|
-
} else {
|
40
|
+
} else {
|
44
41
|
REALLOC_N(ca->objs, VALUE, cnt);
|
45
42
|
}
|
46
43
|
ca->size = cnt;
|
@@ -65,4 +62,3 @@ oj_circ_array_get(CircArray ca, unsigned long id) {
|
|
65
62
|
}
|
66
63
|
return obj;
|
67
64
|
}
|
68
|
-
|
data/ext/oj/circarray.h
CHANGED
data/ext/oj/code.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2017, Peter Ohler
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2017 Peter Ohler. All rights reserved.
|
5
2
|
|
6
3
|
#include "code.h"
|
7
4
|
#include "dump.h"
|
@@ -140,7 +137,7 @@ oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
|
|
140
137
|
size_t len = strlen(classname);
|
141
138
|
size_t size = d2 * out->indent + 10 + len + out->opts->create_id_len + sep_len;
|
142
139
|
bool no_comma = true;
|
143
|
-
|
140
|
+
|
144
141
|
assure_size(out, size);
|
145
142
|
*out->cur++ = '{';
|
146
143
|
|
@@ -201,7 +198,7 @@ oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
|
|
201
198
|
char *b = buf + sizeof(buf) - 1;
|
202
199
|
int neg = 0;
|
203
200
|
long num = attrs->num;
|
204
|
-
|
201
|
+
|
205
202
|
if (0 > num) {
|
206
203
|
neg = 1;
|
207
204
|
num = -num;
|
data/ext/oj/code.h
CHANGED
data/ext/oj/compat.c
CHANGED
data/ext/oj/custom.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 <stdint.h>
|
7
4
|
#include <stdio.h>
|
@@ -1089,7 +1086,7 @@ hash_set_num(struct _parseInfo *pi, Val kval, NumInfo ni) {
|
|
1089
1086
|
// offset and then a conversion to UTC keeps makes the time
|
1090
1087
|
// match the expected value.
|
1091
1088
|
parent->val = rb_funcall2(parent->val, oj_utc_id, 0, 0);
|
1092
|
-
} else if (ni->
|
1089
|
+
} else if (ni->has_exp) {
|
1093
1090
|
int64_t t = (int64_t)(ni->i + ni->exp);
|
1094
1091
|
struct _timeInfo ti;
|
1095
1092
|
VALUE args[8];
|
data/ext/oj/dump.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
|
#include <math.h>
|
@@ -111,7 +108,7 @@ static char rails_friendly_chars[256] = "\
|
|
111
108
|
11111111111111111111111111111111\
|
112
109
|
11111111111111111111111111111111\
|
113
110
|
11111111111111111111111111111111\
|
114
|
-
|
111
|
+
11111111111111111111111111111111";
|
115
112
|
|
116
113
|
static void
|
117
114
|
raise_strict(VALUE obj) {
|
@@ -177,15 +174,20 @@ hixss_friendly_size(const uint8_t *str, size_t len) {
|
|
177
174
|
return size - len * (size_t)'0' + check;
|
178
175
|
}
|
179
176
|
|
180
|
-
inline static
|
177
|
+
inline static long
|
181
178
|
rails_xss_friendly_size(const uint8_t *str, size_t len) {
|
182
|
-
|
179
|
+
long size = 0;
|
183
180
|
size_t i = len;
|
181
|
+
uint8_t hi = 0;
|
184
182
|
|
185
183
|
for (; 0 < i; str++, i--) {
|
186
184
|
size += rails_xss_friendly_chars[*str];
|
185
|
+
hi |= *str & 0x80;
|
187
186
|
}
|
188
|
-
|
187
|
+
if (0 == hi) {
|
188
|
+
return size - len * (size_t)'0';
|
189
|
+
}
|
190
|
+
return -(size - len * (size_t)'0');
|
189
191
|
}
|
190
192
|
|
191
193
|
inline static size_t
|
@@ -252,7 +254,6 @@ dump_hex(uint8_t c, Out out) {
|
|
252
254
|
|
253
255
|
static void
|
254
256
|
raise_invalid_unicode(const char *str, int len, int pos) {
|
255
|
-
char buf[len + 1];
|
256
257
|
char c;
|
257
258
|
char code[32];
|
258
259
|
char *cp = code;
|
@@ -271,8 +272,7 @@ raise_invalid_unicode(const char *str, int len, int pos) {
|
|
271
272
|
cp--;
|
272
273
|
*cp++ = ']';
|
273
274
|
*cp = '\0';
|
274
|
-
|
275
|
-
rb_raise(oj_json_generator_error_class, "Invalid Unicode %s at %d in '%s'", code, pos, buf);
|
275
|
+
rb_raise(oj_json_generator_error_class, "Invalid Unicode %s at %d", code, pos);
|
276
276
|
}
|
277
277
|
|
278
278
|
static const char*
|
@@ -770,6 +770,7 @@ oj_dump_cstr(const char *str, size_t cnt, bool is_sym, bool escape1, Out out) {
|
|
770
770
|
size_t size;
|
771
771
|
char *cmap;
|
772
772
|
const char *orig = str;
|
773
|
+
bool has_hi = false;
|
773
774
|
|
774
775
|
switch (out->opts->escape_mode) {
|
775
776
|
case NLEsc:
|
@@ -788,10 +789,19 @@ oj_dump_cstr(const char *str, size_t cnt, bool is_sym, bool escape1, Out out) {
|
|
788
789
|
cmap = hixss_friendly_chars;
|
789
790
|
size = hixss_friendly_size((uint8_t*)str, cnt);
|
790
791
|
break;
|
791
|
-
case RailsXEsc:
|
792
|
+
case RailsXEsc: {
|
793
|
+
long sz;
|
794
|
+
|
792
795
|
cmap = rails_xss_friendly_chars;
|
793
|
-
|
796
|
+
sz = rails_xss_friendly_size((uint8_t*)str, cnt);
|
797
|
+
if (sz < 0) {
|
798
|
+
has_hi = true;
|
799
|
+
size = (size_t)-sz;
|
800
|
+
} else {
|
801
|
+
size = (size_t)sz;
|
802
|
+
}
|
794
803
|
break;
|
804
|
+
}
|
795
805
|
case RailsEsc:
|
796
806
|
cmap = rails_friendly_chars;
|
797
807
|
size = rails_friendly_size((uint8_t*)str, cnt);
|
@@ -815,7 +825,7 @@ oj_dump_cstr(const char *str, size_t cnt, bool is_sym, bool escape1, Out out) {
|
|
815
825
|
str++;
|
816
826
|
is_sym = 0; // just to make sure
|
817
827
|
}
|
818
|
-
if (cnt == size) {
|
828
|
+
if (cnt == size && !has_hi) {
|
819
829
|
if (is_sym) {
|
820
830
|
*out->cur++ = ':';
|
821
831
|
}
|
data/ext/oj/dump.h
CHANGED
data/ext/oj/dump_compat.c
CHANGED
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;
|
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"
|
@@ -618,7 +615,7 @@ dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out) {
|
|
618
615
|
vid = rb_to_id(*np);
|
619
616
|
attr = rb_id2name(vid);
|
620
617
|
if (Yes == out->opts->ignore_under && '@' == *attr && '_' == attr[1]) {
|
621
|
-
|
618
|
+
continue;
|
622
619
|
}
|
623
620
|
value = rb_ivar_get(obj, vid);
|
624
621
|
|
data/ext/oj/dump_strict.c
CHANGED
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/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
|
|