oj 3.7.4 → 3.11.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -4
- data/ext/oj/buf.h +6 -34
- data/ext/oj/cache8.c +3 -3
- data/ext/oj/cache8.h +5 -33
- data/ext/oj/circarray.c +5 -9
- data/ext/oj/circarray.h +5 -8
- data/ext/oj/code.c +3 -6
- data/ext/oj/code.h +7 -10
- data/ext/oj/compat.c +11 -14
- data/ext/oj/custom.c +108 -75
- data/ext/oj/dump.c +132 -92
- data/ext/oj/dump.h +6 -7
- data/ext/oj/dump_compat.c +37 -34
- data/ext/oj/dump_leaf.c +3 -6
- data/ext/oj/dump_object.c +23 -17
- data/ext/oj/dump_strict.c +7 -9
- data/ext/oj/encode.h +6 -32
- data/ext/oj/err.c +2 -5
- data/ext/oj/err.h +6 -34
- data/ext/oj/extconf.rb +6 -0
- data/ext/oj/fast.c +39 -56
- data/ext/oj/hash.c +11 -39
- data/ext/oj/hash.h +5 -33
- data/ext/oj/hash_test.c +3 -31
- data/ext/oj/mimic_json.c +65 -44
- data/ext/oj/object.c +38 -69
- data/ext/oj/odd.c +18 -17
- data/ext/oj/odd.h +6 -9
- data/ext/oj/oj.c +139 -93
- data/ext/oj/oj.h +43 -35
- data/ext/oj/parse.c +164 -60
- data/ext/oj/parse.h +30 -31
- data/ext/oj/rails.c +119 -83
- data/ext/oj/rails.h +4 -7
- data/ext/oj/reader.c +5 -8
- data/ext/oj/reader.h +7 -10
- data/ext/oj/resolve.c +4 -7
- data/ext/oj/resolve.h +4 -7
- data/ext/oj/rxclass.c +8 -11
- data/ext/oj/rxclass.h +8 -11
- data/ext/oj/saj.c +9 -12
- data/ext/oj/scp.c +4 -7
- data/ext/oj/sparse.c +67 -33
- data/ext/oj/stream_writer.c +16 -15
- data/ext/oj/strict.c +9 -12
- data/ext/oj/string_writer.c +27 -8
- data/ext/oj/trace.c +5 -8
- data/ext/oj/trace.h +9 -12
- data/ext/oj/util.c +136 -0
- data/ext/oj/util.h +19 -0
- data/ext/oj/val_stack.c +28 -36
- data/ext/oj/val_stack.h +19 -50
- data/ext/oj/wab.c +29 -29
- data/lib/oj.rb +0 -8
- data/lib/oj/json.rb +1 -1
- data/lib/oj/mimic.rb +46 -2
- data/lib/oj/version.rb +2 -2
- data/pages/Modes.md +47 -45
- data/pages/Options.md +43 -10
- data/pages/Rails.md +60 -21
- data/pages/Security.md +1 -1
- data/test/activesupport5/abstract_unit.rb +45 -0
- data/test/activesupport5/decoding_test.rb +68 -60
- data/test/activesupport5/encoding_test.rb +111 -96
- data/test/activesupport5/encoding_test_cases.rb +33 -25
- data/test/activesupport5/test_helper.rb +43 -21
- data/test/activesupport5/time_zone_test_helpers.rb +18 -3
- data/test/activesupport6/abstract_unit.rb +44 -0
- data/test/activesupport6/decoding_test.rb +133 -0
- data/test/activesupport6/encoding_test.rb +507 -0
- data/test/activesupport6/encoding_test_cases.rb +98 -0
- data/test/activesupport6/test_common.rb +17 -0
- data/test/activesupport6/test_helper.rb +163 -0
- data/test/activesupport6/time_zone_test_helpers.rb +39 -0
- data/test/bar.rb +24 -6
- data/test/baz.rb +16 -0
- data/test/foo.rb +26 -57
- data/test/helper.rb +10 -0
- data/test/json_gem/json_common_interface_test.rb +8 -3
- data/test/json_gem/json_generator_test.rb +15 -3
- data/test/json_gem/test_helper.rb +8 -0
- data/test/prec.rb +23 -0
- data/test/sample_json.rb +1 -1
- data/test/test_compat.rb +21 -10
- data/test/test_custom.rb +135 -8
- data/test/test_integer_range.rb +1 -2
- data/test/test_object.rb +35 -2
- data/test/test_rails.rb +35 -0
- data/test/test_strict.rb +24 -1
- data/test/test_various.rb +52 -63
- data/test/test_writer.rb +19 -2
- data/test/tests.rb +1 -0
- data/test/zoo.rb +13 -0
- metadata +100 -75
data/ext/oj/val_stack.c
CHANGED
@@ -1,34 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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.
|
2
|
+
|
3
|
+
#include <string.h>
|
30
4
|
|
31
5
|
#include "oj.h"
|
6
|
+
#include "odd.h"
|
32
7
|
#include "val_stack.h"
|
33
8
|
|
34
9
|
static void
|
@@ -39,7 +14,7 @@ mark(void *ptr) {
|
|
39
14
|
if (0 == ptr) {
|
40
15
|
return;
|
41
16
|
}
|
42
|
-
#
|
17
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
43
18
|
pthread_mutex_lock(&stack->mutex);
|
44
19
|
#else
|
45
20
|
rb_mutex_lock(stack->mutex);
|
@@ -52,8 +27,18 @@ mark(void *ptr) {
|
|
52
27
|
if (Qnil != v->key_val && Qundef != v->key_val) {
|
53
28
|
rb_gc_mark(v->key_val);
|
54
29
|
}
|
30
|
+
if (NULL != v->odd_args) {
|
31
|
+
VALUE *a;
|
32
|
+
int i;
|
33
|
+
|
34
|
+
for (i = v->odd_args->odd->attr_cnt, a = v->odd_args->args; 0 < i; i--, a++) {
|
35
|
+
if (Qnil != *a) {
|
36
|
+
rb_gc_mark(*a);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
55
40
|
}
|
56
|
-
#
|
41
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
57
42
|
pthread_mutex_unlock(&stack->mutex);
|
58
43
|
#else
|
59
44
|
rb_mutex_unlock(stack->mutex);
|
@@ -62,21 +47,28 @@ mark(void *ptr) {
|
|
62
47
|
|
63
48
|
VALUE
|
64
49
|
oj_stack_init(ValStack stack) {
|
65
|
-
#
|
66
|
-
|
50
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
51
|
+
int err;
|
52
|
+
|
53
|
+
if (0 != (err = pthread_mutex_init(&stack->mutex, 0))) {
|
54
|
+
rb_raise(rb_eException, "failed to initialize a mutex. %s", strerror(err));
|
55
|
+
}
|
67
56
|
#else
|
68
57
|
stack->mutex = rb_mutex_new();
|
69
58
|
#endif
|
70
59
|
stack->head = stack->base;
|
71
|
-
stack->end = stack->base + sizeof(stack->base) / sizeof(struct
|
60
|
+
stack->end = stack->base + sizeof(stack->base) / sizeof(struct _val);
|
72
61
|
stack->tail = stack->head;
|
73
62
|
stack->head->val = Qundef;
|
74
|
-
stack->head->key =
|
63
|
+
stack->head->key = NULL;
|
75
64
|
stack->head->key_val = Qundef;
|
76
|
-
stack->head->classname =
|
65
|
+
stack->head->classname = NULL;
|
66
|
+
stack->head->odd_args = NULL;
|
67
|
+
stack->head->clas = Qundef;
|
77
68
|
stack->head->klen = 0;
|
78
69
|
stack->head->clen = 0;
|
79
70
|
stack->head->next = NEXT_NONE;
|
71
|
+
|
80
72
|
return Data_Wrap_Struct(oj_cstack_class, mark, 0, stack);
|
81
73
|
}
|
82
74
|
|
data/ext/oj/val_stack.h
CHANGED
@@ -1,40 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
-
*/
|
30
|
-
|
31
|
-
#ifndef __OJ_VAL_STACK_H__
|
32
|
-
#define __OJ_VAL_STACK_H__
|
1
|
+
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
2
|
+
|
3
|
+
#ifndef OJ_VAL_STACK_H
|
4
|
+
#define OJ_VAL_STACK_H
|
33
5
|
|
34
6
|
#include "ruby.h"
|
35
7
|
#include "odd.h"
|
36
8
|
#include <stdint.h>
|
37
|
-
#
|
9
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
38
10
|
#include <pthread.h>
|
39
11
|
#endif
|
40
12
|
|
@@ -52,18 +24,14 @@ typedef enum {
|
|
52
24
|
NEXT_HASH_COMMA = 'n',
|
53
25
|
} ValNext;
|
54
26
|
|
55
|
-
typedef struct
|
27
|
+
typedef struct _val {
|
56
28
|
volatile VALUE val;
|
57
29
|
const char *key;
|
58
30
|
char karray[32];
|
59
31
|
volatile VALUE key_val;
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
VALUE clas;
|
64
|
-
};
|
65
|
-
OddArgs odd_args;
|
66
|
-
};
|
32
|
+
const char *classname;
|
33
|
+
VALUE clas;
|
34
|
+
OddArgs odd_args;
|
67
35
|
uint16_t klen;
|
68
36
|
uint16_t clen;
|
69
37
|
char next; // ValNext
|
@@ -71,12 +39,12 @@ typedef struct _Val {
|
|
71
39
|
char kalloc;
|
72
40
|
} *Val;
|
73
41
|
|
74
|
-
typedef struct
|
75
|
-
struct
|
42
|
+
typedef struct _valStack {
|
43
|
+
struct _val base[STACK_INC];
|
76
44
|
Val head; // current stack
|
77
45
|
Val end; // stack end
|
78
46
|
Val tail; // pointer to one past last element name on stack
|
79
|
-
#
|
47
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
80
48
|
pthread_mutex_t mutex;
|
81
49
|
#else
|
82
50
|
VALUE mutex;
|
@@ -109,12 +77,12 @@ stack_push(ValStack stack, VALUE val, ValNext next) {
|
|
109
77
|
// A realloc can trigger a GC so make sure it happens outside the lock
|
110
78
|
// but lock before changing pointers.
|
111
79
|
if (stack->base == stack->head) {
|
112
|
-
head = ALLOC_N(struct
|
113
|
-
memcpy(head, stack->base, sizeof(struct
|
80
|
+
head = ALLOC_N(struct _val, len + STACK_INC);
|
81
|
+
memcpy(head, stack->base, sizeof(struct _val) * len);
|
114
82
|
} else {
|
115
|
-
REALLOC_N(head, struct
|
83
|
+
REALLOC_N(head, struct _val, len + STACK_INC);
|
116
84
|
}
|
117
|
-
#
|
85
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
118
86
|
pthread_mutex_lock(&stack->mutex);
|
119
87
|
#else
|
120
88
|
rb_mutex_lock(stack->mutex);
|
@@ -122,7 +90,7 @@ stack_push(ValStack stack, VALUE val, ValNext next) {
|
|
122
90
|
stack->head = head;
|
123
91
|
stack->tail = stack->head + toff;
|
124
92
|
stack->end = stack->head + len + STACK_INC;
|
125
|
-
#
|
93
|
+
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
126
94
|
pthread_mutex_unlock(&stack->mutex);
|
127
95
|
#else
|
128
96
|
rb_mutex_unlock(stack->mutex);
|
@@ -132,6 +100,7 @@ stack_push(ValStack stack, VALUE val, ValNext next) {
|
|
132
100
|
stack->tail->next = next;
|
133
101
|
stack->tail->classname = NULL;
|
134
102
|
stack->tail->clas = Qundef;
|
103
|
+
stack->tail->odd_args = NULL;
|
135
104
|
stack->tail->key = 0;
|
136
105
|
stack->tail->key_val = Qundef;
|
137
106
|
stack->tail->clen = 0;
|
@@ -185,4 +154,4 @@ stack_pop(ValStack stack) {
|
|
185
154
|
|
186
155
|
extern const char* oj_stack_next_string(ValNext n);
|
187
156
|
|
188
|
-
#endif /*
|
157
|
+
#endif /* OJ_VAL_STACK_H */
|
data/ext/oj/wab.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 <stdio.h>
|
@@ -15,6 +12,7 @@
|
|
15
12
|
#include "encode.h"
|
16
13
|
#include "dump.h"
|
17
14
|
#include "trace.h"
|
15
|
+
#include "util.h"
|
18
16
|
|
19
17
|
// Workaround in case INFINITY is not defined in math.h or if the OS is CentOS
|
20
18
|
#define OJ_INFINITY (1.0/0.0)
|
@@ -147,11 +145,12 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
|
|
147
145
|
}
|
148
146
|
|
149
147
|
static int
|
150
|
-
hash_cb(VALUE key, VALUE value,
|
148
|
+
hash_cb(VALUE key, VALUE value, VALUE ov) {
|
149
|
+
Out out = (Out)ov;
|
151
150
|
int depth = out->depth;
|
152
151
|
long size;
|
153
152
|
int rtype = rb_type(key);
|
154
|
-
|
153
|
+
|
155
154
|
if (rtype != T_SYMBOL) {
|
156
155
|
rb_raise(rb_eTypeError, "In :wab mode all Hash keys must be Symbols, not %s.\n", rb_class2name(rb_obj_class(key)));
|
157
156
|
}
|
@@ -193,17 +192,21 @@ dump_hash(VALUE obj, int depth, Out out, bool as_ok) {
|
|
193
192
|
|
194
193
|
static void
|
195
194
|
dump_time(VALUE obj, Out out) {
|
196
|
-
char
|
197
|
-
struct
|
198
|
-
int
|
199
|
-
time_t
|
200
|
-
long long
|
195
|
+
char buf[64];
|
196
|
+
struct _timeInfo ti;
|
197
|
+
int len;
|
198
|
+
time_t sec;
|
199
|
+
long long nsec;
|
201
200
|
|
202
201
|
#ifdef HAVE_RB_TIME_TIMESPEC
|
203
|
-
{
|
202
|
+
if (16 <= sizeof(struct timespec)) {
|
204
203
|
struct timespec ts = rb_time_timespec(obj);
|
204
|
+
|
205
205
|
sec = ts.tv_sec;
|
206
206
|
nsec = ts.tv_nsec;
|
207
|
+
} else {
|
208
|
+
sec = rb_num2ll(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
|
209
|
+
nsec = rb_num2ll(rb_funcall2(obj, oj_tv_nsec_id, 0, 0));
|
207
210
|
}
|
208
211
|
#else
|
209
212
|
sec = rb_num2ll(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
|
@@ -212,11 +215,9 @@ dump_time(VALUE obj, Out out) {
|
|
212
215
|
|
213
216
|
assure_size(out, 36);
|
214
217
|
// 2012-01-05T23:58:07.123456000Z
|
215
|
-
|
218
|
+
sec_as_time(sec, &ti);
|
216
219
|
|
217
|
-
len = sprintf(buf, "%04d-%02d-%02dT%02d:%02d:%02d.%09ldZ",
|
218
|
-
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
219
|
-
tm->tm_hour, tm->tm_min, tm->tm_sec, (long)nsec);
|
220
|
+
len = sprintf(buf, "%04d-%02d-%02dT%02d:%02d:%02d.%09ldZ", ti.year, ti.mon, ti.day, ti.hour, ti.min, ti.sec, (long)nsec);
|
220
221
|
oj_dump_cstr(buf, len, 0, 0, out);
|
221
222
|
}
|
222
223
|
|
@@ -267,7 +268,7 @@ static DumpFunc wab_funcs[] = {
|
|
267
268
|
void
|
268
269
|
oj_dump_wab_val(VALUE obj, int depth, Out out) {
|
269
270
|
int type = rb_type(obj);
|
270
|
-
|
271
|
+
|
271
272
|
if (Yes == out->opts->trace) {
|
272
273
|
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
|
273
274
|
}
|
@@ -291,21 +292,21 @@ oj_dump_wab_val(VALUE obj, int depth, Out out) {
|
|
291
292
|
///// load functions /////
|
292
293
|
|
293
294
|
static void
|
294
|
-
hash_end(
|
295
|
+
hash_end(ParseInfo pi) {
|
295
296
|
if (Yes == pi->options.trace) {
|
296
297
|
oj_trace_parse_hash_end(pi, __FILE__, __LINE__);
|
297
298
|
}
|
298
299
|
}
|
299
300
|
|
300
301
|
static void
|
301
|
-
array_end(
|
302
|
+
array_end(ParseInfo pi) {
|
302
303
|
if (Yes == pi->options.trace) {
|
303
304
|
oj_trace_parse_array_end(pi, __FILE__, __LINE__);
|
304
305
|
}
|
305
306
|
}
|
306
307
|
|
307
308
|
static VALUE
|
308
|
-
noop_hash_key(
|
309
|
+
noop_hash_key(ParseInfo pi, const char *key, size_t klen) {
|
309
310
|
return Qundef;
|
310
311
|
}
|
311
312
|
|
@@ -321,7 +322,7 @@ add_value(ParseInfo pi, VALUE val) {
|
|
321
322
|
static bool
|
322
323
|
uuid_check(const char *str, int len) {
|
323
324
|
int i;
|
324
|
-
|
325
|
+
|
325
326
|
for (i = 0; i < 8; i++, str++) {
|
326
327
|
if ('x' != hex_chars[*(uint8_t*)str]) {
|
327
328
|
return false;
|
@@ -377,7 +378,7 @@ time_parse(const char *s, int len) {
|
|
377
378
|
long nsecs = 0;
|
378
379
|
int i;
|
379
380
|
time_t secs;
|
380
|
-
|
381
|
+
|
381
382
|
memset(&tm, 0, sizeof(tm));
|
382
383
|
if ('-' == *s) {
|
383
384
|
s++;
|
@@ -441,7 +442,7 @@ protect_uri(VALUE rstr) {
|
|
441
442
|
static VALUE
|
442
443
|
cstr_to_rstr(const char *str, size_t len) {
|
443
444
|
volatile VALUE v = Qnil;
|
444
|
-
|
445
|
+
|
445
446
|
if (30 == len && '-' == str[4] && '-' == str[7] && 'T' == str[10] && ':' == str[13] && ':' == str[16] && '.' == str[19] && 'Z' == str[29]) {
|
446
447
|
if (Qnil != (v = time_parse(str, (int)len))) {
|
447
448
|
return v;
|
@@ -516,9 +517,9 @@ hash_set_cstr(ParseInfo pi, Val parent, const char *str, size_t len, const char
|
|
516
517
|
}
|
517
518
|
|
518
519
|
static void
|
519
|
-
hash_set_num(
|
520
|
+
hash_set_num(ParseInfo pi, Val parent, NumInfo ni) {
|
520
521
|
volatile VALUE rval = Qnil;
|
521
|
-
|
522
|
+
|
522
523
|
if (ni->infinity || ni->nan) {
|
523
524
|
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
|
524
525
|
}
|
@@ -548,7 +549,7 @@ start_array(ParseInfo pi) {
|
|
548
549
|
static void
|
549
550
|
array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
550
551
|
volatile VALUE rval = cstr_to_rstr(str, len);
|
551
|
-
|
552
|
+
|
552
553
|
rb_ary_push(stack_peek(&pi->stack)->val, rval);
|
553
554
|
if (Yes == pi->options.trace) {
|
554
555
|
oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, rval);
|
@@ -598,7 +599,7 @@ oj_set_wab_callbacks(ParseInfo pi) {
|
|
598
599
|
|
599
600
|
VALUE
|
600
601
|
oj_wab_parse(int argc, VALUE *argv, VALUE self) {
|
601
|
-
struct
|
602
|
+
struct _parseInfo pi;
|
602
603
|
|
603
604
|
parse_info_init(&pi);
|
604
605
|
pi.options = oj_default_options;
|
@@ -615,7 +616,7 @@ oj_wab_parse(int argc, VALUE *argv, VALUE self) {
|
|
615
616
|
|
616
617
|
VALUE
|
617
618
|
oj_wab_parse_cstr(int argc, VALUE *argv, char *json, size_t len) {
|
618
|
-
struct
|
619
|
+
struct _parseInfo pi;
|
619
620
|
|
620
621
|
parse_info_init(&pi);
|
621
622
|
pi.options = oj_default_options;
|
@@ -625,4 +626,3 @@ oj_wab_parse_cstr(int argc, VALUE *argv, char *json, size_t len) {
|
|
625
626
|
|
626
627
|
return oj_pi_parse(argc, argv, &pi, json, len, true);
|
627
628
|
}
|
628
|
-
|
data/lib/oj.rb
CHANGED
@@ -2,14 +2,6 @@
|
|
2
2
|
module Oj
|
3
3
|
end
|
4
4
|
|
5
|
-
begin
|
6
|
-
# This require exists to get around Rubinius failing to load bigdecimal from
|
7
|
-
# the C extension.
|
8
|
-
require 'bigdecimal'
|
9
|
-
rescue Exception
|
10
|
-
# ignore
|
11
|
-
end
|
12
|
-
|
13
5
|
require 'oj/version'
|
14
6
|
require 'oj/bag'
|
15
7
|
require 'oj/easy_hash'
|
data/lib/oj/json.rb
CHANGED
data/lib/oj/mimic.rb
CHANGED
@@ -8,6 +8,50 @@ end
|
|
8
8
|
|
9
9
|
module Oj
|
10
10
|
|
11
|
+
##
|
12
|
+
# Custom mode can be used to emulate the compat mode with some minor
|
13
|
+
# differences. These are the options that setup the custom mode to be like
|
14
|
+
# the compat mode.
|
15
|
+
CUSTOM_MIMIC_JSON_OPTIONS = {
|
16
|
+
allow_gc: true,
|
17
|
+
allow_invalid_unicode: false,
|
18
|
+
allow_nan: false,
|
19
|
+
array_class: nil,
|
20
|
+
array_nl: nil,
|
21
|
+
auto_define: false,
|
22
|
+
bigdecimal_as_decimal: false,
|
23
|
+
bigdecimal_load: :auto,
|
24
|
+
circular: false,
|
25
|
+
class_cache: false,
|
26
|
+
create_additions: false,
|
27
|
+
create_id: "json_class",
|
28
|
+
empty_string: false,
|
29
|
+
escape_mode: :unicode_xss,
|
30
|
+
float_precision: 0,
|
31
|
+
hash_class: nil,
|
32
|
+
ignore: nil,
|
33
|
+
ignore_under: false,
|
34
|
+
indent: 0,
|
35
|
+
integer_range: nil,
|
36
|
+
mode: :custom,
|
37
|
+
nan: :raise,
|
38
|
+
nilnil: false,
|
39
|
+
object_nl: nil,
|
40
|
+
omit_nil: false,
|
41
|
+
quirks_mode: true,
|
42
|
+
safe: false,
|
43
|
+
second_precision: 3,
|
44
|
+
space: nil,
|
45
|
+
space_before: nil,
|
46
|
+
symbol_keys: false,
|
47
|
+
time_format: :ruby,
|
48
|
+
trace: false,
|
49
|
+
use_as_json: false,
|
50
|
+
use_raw_json: false,
|
51
|
+
use_to_hash: false,
|
52
|
+
use_to_json: true,
|
53
|
+
}
|
54
|
+
|
11
55
|
# A bit hack-ish but does the trick. The JSON.dump_default_options is a Hash
|
12
56
|
# but in mimic we use a C struct to store defaults. This class creates a view
|
13
57
|
# onto that struct.
|
@@ -31,14 +75,14 @@ module Oj
|
|
31
75
|
end
|
32
76
|
|
33
77
|
# Loads mimic-ed JSON paths. Used by Oj.mimic_JSON().
|
34
|
-
# @param
|
78
|
+
# @param mimic_paths [Array] additional paths to add to the Ruby loaded features.
|
35
79
|
def self.mimic_loaded(mimic_paths=[])
|
36
80
|
$LOAD_PATH.each do |d|
|
37
81
|
next unless File.exist?(d)
|
38
82
|
|
39
83
|
jfile = File.join(d, 'json.rb')
|
40
84
|
$LOADED_FEATURES << jfile unless $LOADED_FEATURES.include?(jfile) if File.exist?(jfile)
|
41
|
-
|
85
|
+
|
42
86
|
Dir.glob(File.join(d, 'json', '**', '*.rb')).each do |file|
|
43
87
|
# allow json/add/xxx to be loaded. User can override with Oj.add_to_json(xxx).
|
44
88
|
$LOADED_FEATURES << file unless $LOADED_FEATURES.include?(file) unless file.include?('add')
|