oj 3.10.6 → 3.12.0
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 +6 -1
- data/ext/oj/buf.h +36 -68
- data/ext/oj/cache8.c +59 -62
- data/ext/oj/cache8.h +9 -36
- data/ext/oj/circarray.c +36 -42
- data/ext/oj/circarray.h +12 -13
- data/ext/oj/code.c +172 -179
- data/ext/oj/code.h +22 -24
- data/ext/oj/compat.c +168 -181
- data/ext/oj/custom.c +800 -864
- data/ext/oj/dump.c +774 -776
- data/ext/oj/dump.h +50 -55
- data/ext/oj/dump_compat.c +2 -4
- data/ext/oj/dump_leaf.c +118 -162
- data/ext/oj/dump_object.c +610 -632
- data/ext/oj/dump_strict.c +319 -331
- data/ext/oj/encode.h +4 -33
- data/ext/oj/err.c +40 -29
- data/ext/oj/err.h +25 -44
- data/ext/oj/extconf.rb +2 -1
- data/ext/oj/fast.c +1054 -1081
- data/ext/oj/hash.c +78 -95
- data/ext/oj/hash.h +10 -35
- data/ext/oj/hash_test.c +451 -472
- data/ext/oj/mimic_json.c +415 -402
- data/ext/oj/object.c +588 -532
- data/ext/oj/odd.c +124 -132
- data/ext/oj/odd.h +28 -29
- data/ext/oj/oj.c +1178 -905
- data/ext/oj/oj.h +289 -298
- data/ext/oj/parse.c +946 -870
- data/ext/oj/parse.h +81 -79
- data/ext/oj/rails.c +837 -842
- data/ext/oj/rails.h +8 -11
- data/ext/oj/reader.c +139 -147
- data/ext/oj/reader.h +68 -84
- data/ext/oj/resolve.c +44 -47
- data/ext/oj/resolve.h +4 -6
- data/ext/oj/rxclass.c +69 -73
- data/ext/oj/rxclass.h +13 -14
- data/ext/oj/saj.c +453 -484
- data/ext/oj/scp.c +88 -113
- data/ext/oj/sparse.c +783 -714
- data/ext/oj/stream_writer.c +123 -157
- data/ext/oj/strict.c +133 -106
- data/ext/oj/string_writer.c +199 -247
- data/ext/oj/trace.c +34 -41
- data/ext/oj/trace.h +15 -15
- data/ext/oj/util.c +104 -104
- data/ext/oj/util.h +4 -3
- data/ext/oj/val_stack.c +48 -76
- data/ext/oj/val_stack.h +80 -115
- data/ext/oj/wab.c +317 -328
- data/lib/oj.rb +0 -8
- data/lib/oj/bag.rb +1 -0
- data/lib/oj/easy_hash.rb +5 -4
- data/lib/oj/mimic.rb +45 -13
- data/lib/oj/version.rb +1 -1
- data/pages/Modes.md +1 -0
- data/pages/Options.md +23 -11
- data/test/activerecord/result_test.rb +7 -2
- data/test/foo.rb +8 -40
- 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/perf.rb +1 -1
- data/test/perf_scp.rb +11 -10
- data/test/perf_strict.rb +17 -23
- 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_fast.rb +32 -2
- data/test/test_generate.rb +21 -0
- data/test/test_hash.rb +10 -0
- data/test/test_rails.rb +9 -0
- data/test/test_scp.rb +1 -1
- data/test/test_various.rb +4 -2
- metadata +89 -85
data/ext/oj/odd.c
CHANGED
@@ -1,81 +1,76 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
5
|
-
|
6
|
-
#include <string.h>
|
1
|
+
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
7
3
|
|
8
4
|
#include "odd.h"
|
9
5
|
|
10
|
-
|
11
|
-
|
12
|
-
static
|
13
|
-
static
|
14
|
-
static
|
15
|
-
static ID
|
16
|
-
static ID
|
17
|
-
static ID
|
18
|
-
static ID
|
19
|
-
static
|
20
|
-
|
21
|
-
static
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
odd->
|
28
|
-
odd->
|
6
|
+
#include <string.h>
|
7
|
+
|
8
|
+
static struct _odd _odds[4]; // bump up if new initial Odd classes are added
|
9
|
+
static struct _odd *odds = _odds;
|
10
|
+
static long odd_cnt = 0;
|
11
|
+
static ID sec_id;
|
12
|
+
static ID sec_fraction_id;
|
13
|
+
static ID to_f_id;
|
14
|
+
static ID numerator_id;
|
15
|
+
static ID denominator_id;
|
16
|
+
static ID rational_id;
|
17
|
+
static VALUE rational_class;
|
18
|
+
|
19
|
+
static void set_class(Odd odd, const char *classname) {
|
20
|
+
const char **np;
|
21
|
+
ID * idp;
|
22
|
+
|
23
|
+
odd->classname = classname;
|
24
|
+
odd->clen = strlen(classname);
|
25
|
+
odd->clas = rb_const_get(rb_cObject, rb_intern(classname));
|
29
26
|
odd->create_obj = odd->clas;
|
30
|
-
odd->create_op
|
31
|
-
odd->is_module
|
32
|
-
odd->raw
|
27
|
+
odd->create_op = rb_intern("new");
|
28
|
+
odd->is_module = (T_MODULE == rb_type(odd->clas));
|
29
|
+
odd->raw = 0;
|
33
30
|
for (np = odd->attr_names, idp = odd->attrs; 0 != *np; np++, idp++) {
|
34
|
-
|
31
|
+
*idp = rb_intern(*np);
|
35
32
|
}
|
36
33
|
*idp = 0;
|
37
34
|
}
|
38
35
|
|
39
|
-
static VALUE
|
40
|
-
|
41
|
-
volatile VALUE
|
42
|
-
|
43
|
-
long
|
44
|
-
long long
|
45
|
-
long long den = rb_num2ll(rb_funcall(rfrac, denominator_id, 0));
|
36
|
+
static VALUE get_datetime_secs(VALUE obj) {
|
37
|
+
volatile VALUE rsecs = rb_funcall(obj, sec_id, 0);
|
38
|
+
volatile VALUE rfrac = rb_funcall(obj, sec_fraction_id, 0);
|
39
|
+
long sec = NUM2LONG(rsecs);
|
40
|
+
long long num = rb_num2ll(rb_funcall(rfrac, numerator_id, 0));
|
41
|
+
long long den = rb_num2ll(rb_funcall(rfrac, denominator_id, 0));
|
46
42
|
|
47
43
|
num += sec * den;
|
48
44
|
|
49
45
|
return rb_funcall(rb_cObject, rational_id, 2, rb_ll2inum(num), rb_ll2inum(den));
|
50
46
|
}
|
51
47
|
|
52
|
-
void
|
53
|
-
|
54
|
-
|
55
|
-
const char **np;
|
48
|
+
void oj_odd_init() {
|
49
|
+
Odd odd;
|
50
|
+
const char **np;
|
56
51
|
|
57
|
-
sec_id
|
52
|
+
sec_id = rb_intern("sec");
|
58
53
|
sec_fraction_id = rb_intern("sec_fraction");
|
59
|
-
to_f_id
|
60
|
-
numerator_id
|
61
|
-
denominator_id
|
62
|
-
rational_id
|
63
|
-
rational_class
|
54
|
+
to_f_id = rb_intern("to_f");
|
55
|
+
numerator_id = rb_intern("numerator");
|
56
|
+
denominator_id = rb_intern("denominator");
|
57
|
+
rational_id = rb_intern("Rational");
|
58
|
+
rational_class = rb_const_get(rb_cObject, rational_id);
|
64
59
|
|
65
60
|
memset(_odds, 0, sizeof(_odds));
|
66
61
|
odd = odds;
|
67
62
|
// Rational
|
68
|
-
np
|
63
|
+
np = odd->attr_names;
|
69
64
|
*np++ = "numerator";
|
70
65
|
*np++ = "denominator";
|
71
|
-
*np
|
66
|
+
*np = 0;
|
72
67
|
set_class(odd, "Rational");
|
73
68
|
odd->create_obj = rb_cObject;
|
74
|
-
odd->create_op
|
75
|
-
odd->attr_cnt
|
69
|
+
odd->create_op = rational_id;
|
70
|
+
odd->attr_cnt = 2;
|
76
71
|
// Date
|
77
72
|
odd++;
|
78
|
-
np
|
73
|
+
np = odd->attr_names;
|
79
74
|
*np++ = "year";
|
80
75
|
*np++ = "month";
|
81
76
|
*np++ = "day";
|
@@ -85,7 +80,7 @@ oj_odd_init() {
|
|
85
80
|
odd->attr_cnt = 4;
|
86
81
|
// DateTime
|
87
82
|
odd++;
|
88
|
-
np
|
83
|
+
np = odd->attr_names;
|
89
84
|
*np++ = "year";
|
90
85
|
*np++ = "month";
|
91
86
|
*np++ = "day";
|
@@ -96,11 +91,11 @@ oj_odd_init() {
|
|
96
91
|
*np++ = "start";
|
97
92
|
*np++ = 0;
|
98
93
|
set_class(odd, "DateTime");
|
99
|
-
odd->attr_cnt
|
94
|
+
odd->attr_cnt = 8;
|
100
95
|
odd->attrFuncs[5] = get_datetime_secs;
|
101
96
|
// Range
|
102
97
|
odd++;
|
103
|
-
np
|
98
|
+
np = odd->attr_names;
|
104
99
|
*np++ = "begin";
|
105
100
|
*np++ = "end";
|
106
101
|
*np++ = "exclude_end?";
|
@@ -111,119 +106,116 @@ oj_odd_init() {
|
|
111
106
|
odd_cnt = odd - odds + 1;
|
112
107
|
}
|
113
108
|
|
114
|
-
Odd
|
115
|
-
|
116
|
-
|
117
|
-
const char *classname = NULL;
|
109
|
+
Odd oj_get_odd(VALUE clas) {
|
110
|
+
Odd odd;
|
111
|
+
const char *classname = NULL;
|
118
112
|
|
119
113
|
for (odd = odds + odd_cnt - 1; odds <= odd; odd--) {
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
}
|
114
|
+
if (clas == odd->clas) {
|
115
|
+
return odd;
|
116
|
+
}
|
117
|
+
if (odd->is_module) {
|
118
|
+
if (NULL == classname) {
|
119
|
+
classname = rb_class2name(clas);
|
120
|
+
}
|
121
|
+
if (0 == strncmp(odd->classname, classname, odd->clen) && ':' == classname[odd->clen]) {
|
122
|
+
return odd;
|
123
|
+
}
|
124
|
+
}
|
132
125
|
}
|
133
126
|
return NULL;
|
134
127
|
}
|
135
128
|
|
136
|
-
Odd
|
137
|
-
|
138
|
-
Odd odd;
|
129
|
+
Odd oj_get_oddc(const char *classname, size_t len) {
|
130
|
+
Odd odd;
|
139
131
|
|
140
132
|
for (odd = odds + odd_cnt - 1; odds <= odd; odd--) {
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
}
|
133
|
+
if (len == odd->clen && 0 == strncmp(classname, odd->classname, len)) {
|
134
|
+
return odd;
|
135
|
+
}
|
136
|
+
if (odd->is_module && 0 == strncmp(odd->classname, classname, odd->clen) &&
|
137
|
+
':' == classname[odd->clen]) {
|
138
|
+
return odd;
|
139
|
+
}
|
149
140
|
}
|
150
141
|
return 0;
|
151
142
|
}
|
152
143
|
|
153
|
-
OddArgs
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
int i;
|
144
|
+
OddArgs oj_odd_alloc_args(Odd odd) {
|
145
|
+
OddArgs oa = ALLOC_N(struct _oddArgs, 1);
|
146
|
+
VALUE * a;
|
147
|
+
int i;
|
158
148
|
|
159
149
|
oa->odd = odd;
|
160
150
|
for (i = odd->attr_cnt, a = oa->args; 0 < i; i--, a++) {
|
161
|
-
|
151
|
+
*a = Qnil;
|
162
152
|
}
|
163
153
|
return oa;
|
164
154
|
}
|
165
155
|
|
166
|
-
void
|
167
|
-
oj_odd_free(OddArgs args) {
|
156
|
+
void oj_odd_free(OddArgs args) {
|
168
157
|
xfree(args);
|
169
158
|
}
|
170
159
|
|
171
|
-
int
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
160
|
+
int oj_odd_set_arg(OddArgs args, const char *key, size_t klen, VALUE value) {
|
161
|
+
const char **np;
|
162
|
+
VALUE * vp;
|
163
|
+
int i;
|
164
|
+
|
165
|
+
for (i = args->odd->attr_cnt, np = args->odd->attr_names, vp = args->args; 0 < i;
|
166
|
+
i--, np++, vp++) {
|
167
|
+
if (0 == strncmp(key, *np, klen) && '\0' == *((*np) + klen)) {
|
168
|
+
*vp = value;
|
169
|
+
return 0;
|
170
|
+
}
|
182
171
|
}
|
183
172
|
return -1;
|
184
173
|
}
|
185
174
|
|
186
|
-
void
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
175
|
+
void oj_reg_odd(VALUE clas,
|
176
|
+
VALUE create_object,
|
177
|
+
VALUE create_method,
|
178
|
+
int mcnt,
|
179
|
+
VALUE *members,
|
180
|
+
bool raw) {
|
181
|
+
Odd odd;
|
182
|
+
const char **np;
|
183
|
+
ID * ap;
|
184
|
+
AttrGetFunc *fp;
|
192
185
|
|
193
186
|
if (_odds == odds) {
|
194
|
-
|
187
|
+
odds = ALLOC_N(struct _odd, odd_cnt + 1);
|
195
188
|
|
196
|
-
|
189
|
+
memcpy(odds, _odds, sizeof(struct _odd) * odd_cnt);
|
197
190
|
} else {
|
198
|
-
|
191
|
+
REALLOC_N(odds, struct _odd, odd_cnt + 1);
|
199
192
|
}
|
200
|
-
odd
|
193
|
+
odd = odds + odd_cnt;
|
201
194
|
odd->clas = clas;
|
202
195
|
if (NULL == (odd->classname = strdup(rb_class2name(clas)))) {
|
203
|
-
|
196
|
+
rb_raise(rb_eNoMemError, "for attribute name.");
|
204
197
|
}
|
205
|
-
odd->clen
|
198
|
+
odd->clen = strlen(odd->classname);
|
206
199
|
odd->create_obj = create_object;
|
207
|
-
odd->create_op
|
208
|
-
odd->attr_cnt
|
209
|
-
odd->is_module
|
210
|
-
odd->raw
|
211
|
-
for (ap = odd->attrs, np = odd->attr_names, fp = odd->attrFuncs; 0 < mcnt;
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
*ap = rb_intern(*np);
|
200
|
+
odd->create_op = SYM2ID(create_method);
|
201
|
+
odd->attr_cnt = mcnt;
|
202
|
+
odd->is_module = (T_MODULE == rb_type(clas));
|
203
|
+
odd->raw = raw;
|
204
|
+
for (ap = odd->attrs, np = odd->attr_names, fp = odd->attrFuncs; 0 < mcnt;
|
205
|
+
mcnt--, ap++, np++, members++, fp++) {
|
206
|
+
*fp = 0;
|
207
|
+
switch (rb_type(*members)) {
|
208
|
+
case T_STRING:
|
209
|
+
if (NULL == (*np = strdup(rb_string_value_ptr(members)))) {
|
210
|
+
rb_raise(rb_eNoMemError, "for attribute name.");
|
211
|
+
}
|
212
|
+
break;
|
213
|
+
case T_SYMBOL: *np = rb_id2name(SYM2ID(*members)); break;
|
214
|
+
default:
|
215
|
+
rb_raise(rb_eArgError, "registered member identifiers must be Strings or Symbols.");
|
216
|
+
break;
|
217
|
+
}
|
218
|
+
*ap = rb_intern(*np);
|
227
219
|
}
|
228
220
|
*np = 0;
|
229
221
|
*ap = 0;
|
data/ext/oj/odd.h
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* All rights reserved.
|
4
|
-
*/
|
1
|
+
// Copyright (c) 2011 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
5
3
|
|
6
4
|
#ifndef OJ_ODD_H
|
7
5
|
#define OJ_ODD_H
|
@@ -10,35 +8,36 @@
|
|
10
8
|
|
11
9
|
#include "ruby.h"
|
12
10
|
|
13
|
-
#define MAX_ODD_ARGS
|
11
|
+
#define MAX_ODD_ARGS 10
|
14
12
|
|
15
|
-
typedef VALUE
|
13
|
+
typedef VALUE (*AttrGetFunc)(VALUE obj);
|
16
14
|
|
17
15
|
typedef struct _odd {
|
18
|
-
const char
|
19
|
-
size_t
|
20
|
-
VALUE
|
21
|
-
VALUE
|
22
|
-
ID
|
23
|
-
int
|
24
|
-
bool
|
25
|
-
bool
|
26
|
-
const char
|
27
|
-
ID
|
28
|
-
AttrGetFunc
|
29
|
-
} *Odd;
|
16
|
+
const char *classname;
|
17
|
+
size_t clen;
|
18
|
+
VALUE clas; // Ruby class or module
|
19
|
+
VALUE create_obj;
|
20
|
+
ID create_op;
|
21
|
+
int attr_cnt;
|
22
|
+
bool is_module;
|
23
|
+
bool raw;
|
24
|
+
const char *attr_names[MAX_ODD_ARGS]; // NULL terminated attr names
|
25
|
+
ID attrs[MAX_ODD_ARGS]; // 0 terminated attr IDs
|
26
|
+
AttrGetFunc attrFuncs[MAX_ODD_ARGS];
|
27
|
+
} * Odd;
|
30
28
|
|
31
29
|
typedef struct _oddArgs {
|
32
|
-
Odd
|
33
|
-
VALUE
|
34
|
-
} *OddArgs;
|
35
|
-
|
36
|
-
extern void
|
37
|
-
extern Odd
|
38
|
-
extern Odd
|
39
|
-
extern OddArgs
|
40
|
-
extern void
|
41
|
-
extern int
|
42
|
-
extern void
|
30
|
+
Odd odd;
|
31
|
+
VALUE args[MAX_ODD_ARGS];
|
32
|
+
} * OddArgs;
|
33
|
+
|
34
|
+
extern void oj_odd_init(void);
|
35
|
+
extern Odd oj_get_odd(VALUE clas);
|
36
|
+
extern Odd oj_get_oddc(const char *classname, size_t len);
|
37
|
+
extern OddArgs oj_odd_alloc_args(Odd odd);
|
38
|
+
extern void oj_odd_free(OddArgs args);
|
39
|
+
extern int oj_odd_set_arg(OddArgs args, const char *key, size_t klen, VALUE value);
|
40
|
+
extern void
|
41
|
+
oj_reg_odd(VALUE clas, VALUE create_object, VALUE create_method, int mcnt, VALUE *members, bool raw);
|
43
42
|
|
44
43
|
#endif /* OJ_ODD_H */
|
data/ext/oj/oj.c
CHANGED
@@ -1,367 +1,503 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
// Copyright (c) 2012 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
3
|
+
|
4
|
+
#include "oj.h"
|
5
5
|
|
6
|
-
#include <stdlib.h>
|
7
6
|
#include <errno.h>
|
7
|
+
#include <fcntl.h>
|
8
8
|
#include <stdio.h>
|
9
|
+
#include <stdlib.h>
|
9
10
|
#include <string.h>
|
10
11
|
#include <sys/types.h>
|
11
12
|
#include <unistd.h>
|
12
|
-
#include <fcntl.h>
|
13
13
|
|
14
|
-
#include "
|
15
|
-
#include "
|
14
|
+
#include "dump.h"
|
15
|
+
#include "encode.h"
|
16
16
|
#include "hash.h"
|
17
17
|
#include "odd.h"
|
18
|
-
#include "
|
18
|
+
#include "parse.h"
|
19
19
|
#include "rails.h"
|
20
|
-
#include "encode.h"
|
21
20
|
|
22
21
|
typedef struct _yesNoOpt {
|
23
|
-
VALUE
|
24
|
-
char
|
25
|
-
} *YesNoOpt;
|
22
|
+
VALUE sym;
|
23
|
+
char *attr;
|
24
|
+
} * YesNoOpt;
|
26
25
|
|
27
26
|
void Init_oj();
|
28
27
|
|
29
|
-
VALUE
|
30
|
-
|
31
|
-
ID
|
32
|
-
ID
|
33
|
-
ID
|
34
|
-
ID
|
35
|
-
ID
|
36
|
-
ID
|
37
|
-
ID
|
38
|
-
ID
|
39
|
-
ID
|
40
|
-
ID
|
41
|
-
ID
|
42
|
-
ID
|
43
|
-
ID
|
44
|
-
ID
|
45
|
-
ID
|
46
|
-
ID
|
47
|
-
ID
|
48
|
-
ID
|
49
|
-
ID
|
50
|
-
ID
|
51
|
-
ID
|
52
|
-
ID
|
53
|
-
ID
|
54
|
-
ID
|
55
|
-
ID
|
56
|
-
ID
|
57
|
-
ID
|
58
|
-
ID
|
59
|
-
ID
|
60
|
-
ID
|
61
|
-
ID
|
62
|
-
ID
|
63
|
-
ID
|
64
|
-
ID
|
65
|
-
ID
|
66
|
-
ID
|
67
|
-
ID
|
68
|
-
ID
|
69
|
-
ID
|
70
|
-
ID
|
71
|
-
ID
|
72
|
-
ID
|
73
|
-
ID
|
74
|
-
ID
|
75
|
-
|
76
|
-
|
77
|
-
VALUE
|
78
|
-
VALUE
|
79
|
-
VALUE
|
80
|
-
VALUE
|
81
|
-
VALUE
|
82
|
-
VALUE
|
83
|
-
VALUE
|
84
|
-
VALUE
|
85
|
-
VALUE
|
86
|
-
VALUE
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
VALUE
|
92
|
-
VALUE
|
93
|
-
VALUE
|
94
|
-
VALUE
|
95
|
-
VALUE
|
96
|
-
VALUE
|
97
|
-
VALUE
|
98
|
-
VALUE
|
99
|
-
VALUE
|
100
|
-
|
101
|
-
static VALUE
|
102
|
-
static VALUE
|
103
|
-
static VALUE
|
104
|
-
static VALUE
|
105
|
-
static VALUE
|
106
|
-
static VALUE
|
107
|
-
static VALUE
|
108
|
-
static VALUE
|
109
|
-
static VALUE
|
110
|
-
static VALUE
|
111
|
-
static VALUE
|
112
|
-
static VALUE
|
113
|
-
static VALUE
|
114
|
-
static VALUE
|
115
|
-
static VALUE
|
116
|
-
static VALUE
|
117
|
-
static VALUE
|
118
|
-
static VALUE
|
119
|
-
static VALUE
|
120
|
-
static VALUE
|
121
|
-
static VALUE
|
122
|
-
static VALUE
|
123
|
-
static VALUE
|
124
|
-
static VALUE
|
125
|
-
static VALUE
|
126
|
-
static VALUE
|
127
|
-
static VALUE
|
128
|
-
static VALUE
|
129
|
-
static VALUE
|
130
|
-
static VALUE
|
131
|
-
static VALUE
|
132
|
-
static VALUE
|
133
|
-
static VALUE
|
134
|
-
static VALUE
|
135
|
-
static VALUE
|
136
|
-
static VALUE
|
137
|
-
static VALUE
|
138
|
-
static VALUE
|
139
|
-
static VALUE
|
140
|
-
static VALUE
|
141
|
-
static VALUE
|
142
|
-
static VALUE
|
143
|
-
static VALUE
|
144
|
-
static VALUE
|
145
|
-
static VALUE
|
146
|
-
static VALUE
|
147
|
-
static VALUE
|
148
|
-
static VALUE
|
149
|
-
static VALUE
|
150
|
-
|
151
|
-
|
28
|
+
VALUE Oj = Qnil;
|
29
|
+
|
30
|
+
ID oj_add_value_id;
|
31
|
+
ID oj_array_append_id;
|
32
|
+
ID oj_array_end_id;
|
33
|
+
ID oj_array_start_id;
|
34
|
+
ID oj_as_json_id;
|
35
|
+
ID oj_begin_id;
|
36
|
+
ID oj_bigdecimal_id;
|
37
|
+
ID oj_end_id;
|
38
|
+
ID oj_exclude_end_id;
|
39
|
+
ID oj_error_id;
|
40
|
+
ID oj_file_id;
|
41
|
+
ID oj_fileno_id;
|
42
|
+
ID oj_ftype_id;
|
43
|
+
ID oj_has_key_id;
|
44
|
+
ID oj_hash_end_id;
|
45
|
+
ID oj_hash_key_id;
|
46
|
+
ID oj_hash_set_id;
|
47
|
+
ID oj_hash_start_id;
|
48
|
+
ID oj_iconv_id;
|
49
|
+
ID oj_instance_variables_id;
|
50
|
+
ID oj_json_create_id;
|
51
|
+
ID oj_length_id;
|
52
|
+
ID oj_new_id;
|
53
|
+
ID oj_parse_id;
|
54
|
+
ID oj_pos_id;
|
55
|
+
ID oj_raw_json_id;
|
56
|
+
ID oj_read_id;
|
57
|
+
ID oj_readpartial_id;
|
58
|
+
ID oj_replace_id;
|
59
|
+
ID oj_stat_id;
|
60
|
+
ID oj_string_id;
|
61
|
+
ID oj_to_h_id;
|
62
|
+
ID oj_to_hash_id;
|
63
|
+
ID oj_to_json_id;
|
64
|
+
ID oj_to_s_id;
|
65
|
+
ID oj_to_sym_id;
|
66
|
+
ID oj_to_time_id;
|
67
|
+
ID oj_tv_nsec_id;
|
68
|
+
ID oj_tv_sec_id;
|
69
|
+
ID oj_tv_usec_id;
|
70
|
+
ID oj_utc_id;
|
71
|
+
ID oj_utc_offset_id;
|
72
|
+
ID oj_utcq_id;
|
73
|
+
ID oj_write_id;
|
74
|
+
|
75
|
+
VALUE oj_bag_class;
|
76
|
+
VALUE oj_bigdecimal_class;
|
77
|
+
VALUE oj_cstack_class;
|
78
|
+
VALUE oj_date_class;
|
79
|
+
VALUE oj_datetime_class;
|
80
|
+
VALUE oj_enumerable_class;
|
81
|
+
VALUE oj_parse_error_class;
|
82
|
+
VALUE oj_stream_writer_class;
|
83
|
+
VALUE oj_string_writer_class;
|
84
|
+
VALUE oj_stringio_class;
|
85
|
+
VALUE oj_struct_class;
|
86
|
+
|
87
|
+
VALUE oj_slash_string;
|
88
|
+
|
89
|
+
VALUE oj_allow_nan_sym;
|
90
|
+
VALUE oj_array_class_sym;
|
91
|
+
VALUE oj_create_additions_sym;
|
92
|
+
VALUE oj_decimal_class_sym;
|
93
|
+
VALUE oj_hash_class_sym;
|
94
|
+
VALUE oj_indent_sym;
|
95
|
+
VALUE oj_object_class_sym;
|
96
|
+
VALUE oj_quirks_mode_sym;
|
97
|
+
VALUE oj_safe_sym;
|
98
|
+
VALUE oj_trace_sym;
|
99
|
+
|
100
|
+
static VALUE allow_blank_sym;
|
101
|
+
static VALUE allow_gc_sym;
|
102
|
+
static VALUE allow_invalid_unicode_sym;
|
103
|
+
static VALUE ascii_sym;
|
104
|
+
static VALUE auto_define_sym;
|
105
|
+
static VALUE auto_sym;
|
106
|
+
static VALUE bigdecimal_as_decimal_sym;
|
107
|
+
static VALUE bigdecimal_load_sym;
|
108
|
+
static VALUE bigdecimal_sym;
|
109
|
+
static VALUE cache_keys_sym;
|
110
|
+
static VALUE cache_str_sym;
|
111
|
+
static VALUE circular_sym;
|
112
|
+
static VALUE class_cache_sym;
|
113
|
+
static VALUE compat_bigdecimal_sym;
|
114
|
+
static VALUE compat_sym;
|
115
|
+
static VALUE create_id_sym;
|
116
|
+
static VALUE custom_sym;
|
117
|
+
static VALUE empty_string_sym;
|
118
|
+
static VALUE escape_mode_sym;
|
119
|
+
static VALUE integer_range_sym;
|
120
|
+
static VALUE fast_sym;
|
121
|
+
static VALUE float_prec_sym;
|
122
|
+
static VALUE float_sym;
|
123
|
+
static VALUE huge_sym;
|
124
|
+
static VALUE ignore_sym;
|
125
|
+
static VALUE ignore_under_sym;
|
126
|
+
static VALUE json_sym;
|
127
|
+
static VALUE match_string_sym;
|
128
|
+
static VALUE mode_sym;
|
129
|
+
static VALUE nan_sym;
|
130
|
+
static VALUE newline_sym;
|
131
|
+
static VALUE nilnil_sym;
|
132
|
+
static VALUE null_sym;
|
133
|
+
static VALUE object_sym;
|
134
|
+
static VALUE omit_nil_sym;
|
135
|
+
static VALUE rails_sym;
|
136
|
+
static VALUE raise_sym;
|
137
|
+
static VALUE ruby_sym;
|
138
|
+
static VALUE sec_prec_sym;
|
139
|
+
static VALUE strict_sym;
|
140
|
+
static VALUE symbol_keys_sym;
|
141
|
+
static VALUE time_format_sym;
|
142
|
+
static VALUE unicode_xss_sym;
|
143
|
+
static VALUE unix_sym;
|
144
|
+
static VALUE unix_zone_sym;
|
145
|
+
static VALUE use_as_json_sym;
|
146
|
+
static VALUE use_raw_json_sym;
|
147
|
+
static VALUE use_to_hash_sym;
|
148
|
+
static VALUE use_to_json_sym;
|
149
|
+
static VALUE wab_sym;
|
150
|
+
static VALUE word_sym;
|
151
|
+
static VALUE xmlschema_sym;
|
152
|
+
static VALUE xss_safe_sym;
|
153
|
+
|
154
|
+
rb_encoding *oj_utf8_encoding = 0;
|
152
155
|
|
153
156
|
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
154
|
-
pthread_mutex_t
|
157
|
+
pthread_mutex_t oj_cache_mutex;
|
155
158
|
#else
|
156
159
|
VALUE oj_cache_mutex = Qnil;
|
157
160
|
#endif
|
158
161
|
|
159
|
-
const char
|
160
|
-
|
161
|
-
struct _options
|
162
|
-
0,
|
163
|
-
No,
|
164
|
-
No,
|
165
|
-
No,
|
166
|
-
JSONEsc,
|
167
|
-
ObjectMode,
|
168
|
-
Yes,
|
169
|
-
UnixTime,
|
170
|
-
NotSet,
|
171
|
-
AutoDec,
|
172
|
-
|
173
|
-
No,
|
174
|
-
No,
|
175
|
-
No,
|
176
|
-
No,
|
177
|
-
|
178
|
-
Yes,
|
179
|
-
Yes,
|
180
|
-
|
181
|
-
No,
|
182
|
-
|
183
|
-
|
184
|
-
No,
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
162
|
+
const char oj_json_class[] = "json_class";
|
163
|
+
|
164
|
+
struct _options oj_default_options = {
|
165
|
+
0, // indent
|
166
|
+
No, // circular
|
167
|
+
No, // auto_define
|
168
|
+
No, // sym_key
|
169
|
+
JSONEsc, // escape_mode
|
170
|
+
ObjectMode, // mode
|
171
|
+
Yes, // class_cache
|
172
|
+
UnixTime, // time_format
|
173
|
+
NotSet, // bigdec_as_num
|
174
|
+
AutoDec, // bigdec_load
|
175
|
+
false, // compat_bigdec
|
176
|
+
No, // to_hash
|
177
|
+
No, // to_json
|
178
|
+
No, // as_json
|
179
|
+
No, // raw_json
|
180
|
+
No, // nilnil
|
181
|
+
Yes, // empty_string
|
182
|
+
Yes, // allow_gc
|
183
|
+
Yes, // quirks_mode
|
184
|
+
No, // allow_invalid
|
185
|
+
No, // create_ok
|
186
|
+
Yes, // allow_nan
|
187
|
+
No, // trace
|
188
|
+
No, // safe
|
189
|
+
false, // sec_prec_set
|
190
|
+
No, // ignore_under
|
191
|
+
Yes, // cache_keys
|
192
|
+
3, // cache_str
|
193
|
+
0, // int_range_min
|
194
|
+
0, // int_range_max
|
195
|
+
oj_json_class, // create_id
|
196
|
+
10, // create_id_len
|
197
|
+
9, // sec_prec
|
198
|
+
16, // float_prec
|
199
|
+
"%0.15g", // float_fmt
|
200
|
+
Qnil, // hash_class
|
201
|
+
Qnil, // array_class
|
202
|
+
{
|
203
|
+
// dump_opts
|
204
|
+
false, // use
|
205
|
+
"", // indent
|
206
|
+
"", // before_sep
|
207
|
+
"", // after_sep
|
208
|
+
"", // hash_nl
|
209
|
+
"", // array_nl
|
210
|
+
0, // indent_size
|
211
|
+
0, // before_size
|
212
|
+
0, // after_size
|
213
|
+
0, // hash_size
|
214
|
+
0, // array_size
|
215
|
+
AutoNan, // nan_dump
|
216
|
+
false, // omit_nil
|
217
|
+
MAX_DEPTH, // max_depth
|
211
218
|
},
|
212
|
-
{
|
213
|
-
|
214
|
-
|
215
|
-
|
219
|
+
{
|
220
|
+
// str_rx
|
221
|
+
NULL, // head
|
222
|
+
NULL, // tail
|
223
|
+
{'\0'}, // err
|
216
224
|
},
|
217
|
-
NULL,
|
225
|
+
NULL, // ignore
|
218
226
|
};
|
219
227
|
|
220
228
|
/* Document-method: default_options()
|
221
229
|
* call-seq: default_options()
|
222
230
|
*
|
223
231
|
* Returns the default load and dump options as a Hash. The options are
|
224
|
-
* - *:indent* [_Fixnum_|_String_|_nil_] number of spaces to indent each element in an JSON
|
225
|
-
*
|
232
|
+
* - *:indent* [_Fixnum_|_String_|_nil_] number of spaces to indent each element in an JSON
|
233
|
+
*document, zero or nil is no newline between JSON elements, negative indicates no newline between
|
234
|
+
*top level JSON elements in a stream, a String indicates the string should be used for indentation
|
235
|
+
* - *:circular* [_Boolean_|_nil_] support circular references while dumping as well as shared
|
236
|
+
*references
|
226
237
|
* - *:auto_define* [_Boolean_|_nil_] automatically define classes if they do not exist
|
227
238
|
* - *:symbol_keys* [_Boolean_|_nil_] use symbols instead of strings for hash keys
|
228
|
-
* - *:escape_mode* [_:newline_|_:json_|_:xss_safe_|_:ascii_|_unicode_xss_|_nil_] determines the
|
229
|
-
*
|
230
|
-
* - *:
|
239
|
+
* - *:escape_mode* [_:newline_|_:json_|_:xss_safe_|_:ascii_|_unicode_xss_|_nil_] determines the
|
240
|
+
*characters to escape
|
241
|
+
* - *:class_cache* [_Boolean_|_nil_] cache classes for faster parsing (if dynamically modifying
|
242
|
+
*classes or reloading classes then don't use this)
|
243
|
+
* - *:mode* [_:object_|_:strict_|_:compat_|_:null_|_:custom_|_:rails_|_:wab_] load and dump modes
|
244
|
+
*to use for JSON
|
231
245
|
* - *:time_format* [_:unix_|_:unix_zone_|_:xmlschema_|_:ruby_] time format when dumping
|
232
246
|
* - *:bigdecimal_as_decimal* [_Boolean_|_nil_] dump BigDecimal as a decimal number or as a String
|
233
|
-
* - *:bigdecimal_load* [_:bigdecimal_|_:float_|_:auto_] load decimals as BigDecimal instead
|
234
|
-
*
|
235
|
-
*
|
236
|
-
* - *:
|
237
|
-
*
|
247
|
+
* - *:bigdecimal_load* [_:bigdecimal_|_:float_|_:auto_|_:fast_] load decimals as BigDecimal instead
|
248
|
+
*of as a Float. :auto pick the most precise for the number of digits. :float should be the same as
|
249
|
+
*ruby. :fast may require rounding but is must faster.
|
250
|
+
* - *:compat_bigdecimal* [_true_|_false_] load decimals as BigDecimal instead of as a Float when in
|
251
|
+
*compat or rails mode.
|
252
|
+
* - *:create_id* [_String_|_nil_] create id for json compatible object encoding, default is
|
253
|
+
*'json_class'
|
254
|
+
* - *:create_additions* [_Boolean_|_nil_] if true allow creation of instances using create_id on
|
255
|
+
*load.
|
256
|
+
* - *:second_precision* [_Fixnum_|_nil_] number of digits after the decimal when dumping the
|
257
|
+
*seconds portion of time
|
258
|
+
* - *:float_precision* [_Fixnum_|_nil_] number of digits of precision when dumping floats, 0
|
259
|
+
*indicates use Ruby
|
238
260
|
* - *:use_to_json* [_Boolean_|_nil_] call to_json() methods on dump, default is false
|
239
261
|
* - *:use_as_json* [_Boolean_|_nil_] call as_json() methods on dump, default is false
|
240
262
|
* - *:use_raw_json* [_Boolean_|_nil_] call raw_json() methods on dump, default is false
|
241
|
-
* - *:nilnil* [_Boolean_|_nil_] if true a nil input to load will return nil and not raise an
|
263
|
+
* - *:nilnil* [_Boolean_|_nil_] if true a nil input to load will return nil and not raise an
|
264
|
+
*Exception
|
242
265
|
* - *:empty_string* [_Boolean_|_nil_] if true an empty input will not raise an Exception
|
243
266
|
* - *:allow_gc* [_Boolean_|_nil_] allow or prohibit GC during parsing, default is true (allow)
|
244
|
-
* - *:quirks_mode* [_true,_|_false_|_nil_] Allow single JSON values instead of documents, default
|
245
|
-
*
|
246
|
-
* - *:
|
247
|
-
*
|
267
|
+
* - *:quirks_mode* [_true,_|_false_|_nil_] Allow single JSON values instead of documents, default
|
268
|
+
*is true (allow)
|
269
|
+
* - *:allow_invalid_unicode* [_true,_|_false_|_nil_] Allow invalid unicode, default is false (don't
|
270
|
+
*allow)
|
271
|
+
* - *:allow_nan* [_true,_|_false_|_nil_] Allow Nan, Infinity, and -Infinity to be parsed, default
|
272
|
+
*is true (allow)
|
273
|
+
* - *:indent_str* [_String_|_nil_] String to use for indentation, overriding the indent option is
|
274
|
+
*not nil
|
248
275
|
* - *:space* [_String_|_nil_] String to use for the space after the colon in JSON object fields
|
249
276
|
* - *:space_before* [_String_|_nil_] String to use before the colon separator in JSON object fields
|
250
277
|
* - *:object_nl* [_String_|_nil_] String to use after a JSON object field value
|
251
278
|
* - *:array_nl* [_String_|_nil_] String to use after a JSON array value
|
252
|
-
* - *:nan* [_:null_|_:huge_|_:word_|_:raise_|_:auto_] how to dump Infinity and NaN. :null places a
|
253
|
-
*
|
279
|
+
* - *:nan* [_:null_|_:huge_|_:word_|_:raise_|_:auto_] how to dump Infinity and NaN. :null places a
|
280
|
+
*null, :huge places a huge number, :word places Infinity or NaN, :raise raises and exception, :auto
|
281
|
+
*uses default for each mode.
|
282
|
+
* - *:hash_class* [_Class_|_nil_] Class to use instead of Hash on load, :object_class can also be
|
283
|
+
*used
|
254
284
|
* - *:array_class* [_Class_|_nil_] Class to use instead of Array on load
|
255
285
|
* - *:omit_nil* [_true_|_false_] if true Hash and Object attributes with nil values are omitted
|
256
|
-
* - *:ignore* [_nil_|
|
257
|
-
* - *:ignore_under* [
|
286
|
+
* - *:ignore* [_nil_|_Array_] either nil or an Array of classes to ignore when dumping
|
287
|
+
* - *:ignore_under* [_Boolean_] if true then attributes that start with _ are ignored when dumping in
|
288
|
+
*object or custom mode.
|
289
|
+
* - *:cache_keys* [_Boolean_] if true then hash keys are cached
|
290
|
+
* - *:cache_str* [_Fixnum_] maximum string value length to cache
|
258
291
|
* - *:integer_range* [_Range_] Dump integers outside range as strings.
|
259
292
|
* - *:trace* [_true,_|_false_] Trace all load and dump calls, default is false (trace is off)
|
260
|
-
* - *:safe* [_true,_|_false_] Safe mimic breaks JSON mimic to be safer, default is false (safe is
|
293
|
+
* - *:safe* [_true,_|_false_] Safe mimic breaks JSON mimic to be safer, default is false (safe is
|
294
|
+
*off)
|
261
295
|
*
|
262
296
|
* Return [_Hash_] all current option settings.
|
263
297
|
*/
|
264
|
-
static VALUE
|
265
|
-
|
266
|
-
VALUE opts = rb_hash_new();
|
298
|
+
static VALUE get_def_opts(VALUE self) {
|
299
|
+
VALUE opts = rb_hash_new();
|
267
300
|
|
268
301
|
if (0 == oj_default_options.dump_opts.indent_size) {
|
269
|
-
|
302
|
+
rb_hash_aset(opts, oj_indent_sym, INT2FIX(oj_default_options.indent));
|
270
303
|
} else {
|
271
|
-
|
304
|
+
rb_hash_aset(opts, oj_indent_sym, rb_str_new2(oj_default_options.dump_opts.indent_str));
|
272
305
|
}
|
273
306
|
rb_hash_aset(opts, sec_prec_sym, INT2FIX(oj_default_options.sec_prec));
|
274
|
-
rb_hash_aset(opts,
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
rb_hash_aset(opts,
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
rb_hash_aset(opts,
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
rb_hash_aset(opts,
|
290
|
-
|
291
|
-
|
307
|
+
rb_hash_aset(opts,
|
308
|
+
circular_sym,
|
309
|
+
(Yes == oj_default_options.circular)
|
310
|
+
? Qtrue
|
311
|
+
: ((No == oj_default_options.circular) ? Qfalse : Qnil));
|
312
|
+
rb_hash_aset(opts,
|
313
|
+
class_cache_sym,
|
314
|
+
(Yes == oj_default_options.class_cache)
|
315
|
+
? Qtrue
|
316
|
+
: ((No == oj_default_options.class_cache) ? Qfalse : Qnil));
|
317
|
+
rb_hash_aset(opts,
|
318
|
+
auto_define_sym,
|
319
|
+
(Yes == oj_default_options.auto_define)
|
320
|
+
? Qtrue
|
321
|
+
: ((No == oj_default_options.auto_define) ? Qfalse : Qnil));
|
322
|
+
rb_hash_aset(opts,
|
323
|
+
symbol_keys_sym,
|
324
|
+
(Yes == oj_default_options.sym_key)
|
325
|
+
? Qtrue
|
326
|
+
: ((No == oj_default_options.sym_key) ? Qfalse : Qnil));
|
327
|
+
rb_hash_aset(opts,
|
328
|
+
bigdecimal_as_decimal_sym,
|
329
|
+
(Yes == oj_default_options.bigdec_as_num)
|
330
|
+
? Qtrue
|
331
|
+
: ((No == oj_default_options.bigdec_as_num) ? Qfalse : Qnil));
|
332
|
+
rb_hash_aset(opts,
|
333
|
+
oj_create_additions_sym,
|
334
|
+
(Yes == oj_default_options.create_ok)
|
335
|
+
? Qtrue
|
336
|
+
: ((No == oj_default_options.create_ok) ? Qfalse : Qnil));
|
337
|
+
rb_hash_aset(opts,
|
338
|
+
use_to_json_sym,
|
339
|
+
(Yes == oj_default_options.to_json)
|
340
|
+
? Qtrue
|
341
|
+
: ((No == oj_default_options.to_json) ? Qfalse : Qnil));
|
342
|
+
rb_hash_aset(opts,
|
343
|
+
use_to_hash_sym,
|
344
|
+
(Yes == oj_default_options.to_hash)
|
345
|
+
? Qtrue
|
346
|
+
: ((No == oj_default_options.to_hash) ? Qfalse : Qnil));
|
347
|
+
rb_hash_aset(opts,
|
348
|
+
use_as_json_sym,
|
349
|
+
(Yes == oj_default_options.as_json)
|
350
|
+
? Qtrue
|
351
|
+
: ((No == oj_default_options.as_json) ? Qfalse : Qnil));
|
352
|
+
rb_hash_aset(opts,
|
353
|
+
use_raw_json_sym,
|
354
|
+
(Yes == oj_default_options.raw_json)
|
355
|
+
? Qtrue
|
356
|
+
: ((No == oj_default_options.raw_json) ? Qfalse : Qnil));
|
357
|
+
rb_hash_aset(opts,
|
358
|
+
nilnil_sym,
|
359
|
+
(Yes == oj_default_options.nilnil)
|
360
|
+
? Qtrue
|
361
|
+
: ((No == oj_default_options.nilnil) ? Qfalse : Qnil));
|
362
|
+
rb_hash_aset(opts,
|
363
|
+
empty_string_sym,
|
364
|
+
(Yes == oj_default_options.empty_string)
|
365
|
+
? Qtrue
|
366
|
+
: ((No == oj_default_options.empty_string) ? Qfalse : Qnil));
|
367
|
+
rb_hash_aset(opts,
|
368
|
+
allow_gc_sym,
|
369
|
+
(Yes == oj_default_options.allow_gc)
|
370
|
+
? Qtrue
|
371
|
+
: ((No == oj_default_options.allow_gc) ? Qfalse : Qnil));
|
372
|
+
rb_hash_aset(opts,
|
373
|
+
oj_quirks_mode_sym,
|
374
|
+
(Yes == oj_default_options.quirks_mode)
|
375
|
+
? Qtrue
|
376
|
+
: ((No == oj_default_options.quirks_mode) ? Qfalse : Qnil));
|
377
|
+
rb_hash_aset(opts,
|
378
|
+
allow_invalid_unicode_sym,
|
379
|
+
(Yes == oj_default_options.allow_invalid)
|
380
|
+
? Qtrue
|
381
|
+
: ((No == oj_default_options.allow_invalid) ? Qfalse : Qnil));
|
382
|
+
rb_hash_aset(opts,
|
383
|
+
oj_allow_nan_sym,
|
384
|
+
(Yes == oj_default_options.allow_nan)
|
385
|
+
? Qtrue
|
386
|
+
: ((No == oj_default_options.allow_nan) ? Qfalse : Qnil));
|
387
|
+
rb_hash_aset(opts,
|
388
|
+
oj_trace_sym,
|
389
|
+
(Yes == oj_default_options.trace)
|
390
|
+
? Qtrue
|
391
|
+
: ((No == oj_default_options.trace) ? Qfalse : Qnil));
|
392
|
+
rb_hash_aset(opts,
|
393
|
+
oj_safe_sym,
|
394
|
+
(Yes == oj_default_options.safe)
|
395
|
+
? Qtrue
|
396
|
+
: ((No == oj_default_options.safe) ? Qfalse : Qnil));
|
292
397
|
rb_hash_aset(opts, float_prec_sym, INT2FIX(oj_default_options.float_prec));
|
293
|
-
rb_hash_aset(opts,
|
398
|
+
rb_hash_aset(opts, cache_str_sym, INT2FIX(oj_default_options.cache_str));
|
399
|
+
rb_hash_aset(opts,
|
400
|
+
ignore_under_sym,
|
401
|
+
(Yes == oj_default_options.ignore_under)
|
402
|
+
? Qtrue
|
403
|
+
: ((No == oj_default_options.ignore_under) ? Qfalse : Qnil));
|
404
|
+
rb_hash_aset(opts,
|
405
|
+
cache_keys_sym,
|
406
|
+
(Yes == oj_default_options.cache_keys)
|
407
|
+
? Qtrue
|
408
|
+
: ((No == oj_default_options.cache_keys) ? Qfalse : Qnil));
|
294
409
|
switch (oj_default_options.mode) {
|
295
|
-
case StrictMode:
|
296
|
-
case CompatMode:
|
297
|
-
case NullMode:
|
298
|
-
case ObjectMode:
|
299
|
-
case CustomMode:
|
300
|
-
case RailsMode:
|
301
|
-
case WabMode:
|
302
|
-
default:
|
410
|
+
case StrictMode: rb_hash_aset(opts, mode_sym, strict_sym); break;
|
411
|
+
case CompatMode: rb_hash_aset(opts, mode_sym, compat_sym); break;
|
412
|
+
case NullMode: rb_hash_aset(opts, mode_sym, null_sym); break;
|
413
|
+
case ObjectMode: rb_hash_aset(opts, mode_sym, object_sym); break;
|
414
|
+
case CustomMode: rb_hash_aset(opts, mode_sym, custom_sym); break;
|
415
|
+
case RailsMode: rb_hash_aset(opts, mode_sym, rails_sym); break;
|
416
|
+
case WabMode: rb_hash_aset(opts, mode_sym, wab_sym); break;
|
417
|
+
default: rb_hash_aset(opts, mode_sym, object_sym); break;
|
303
418
|
}
|
304
419
|
|
305
420
|
if (oj_default_options.int_range_max != 0 || oj_default_options.int_range_min != 0) {
|
306
|
-
|
307
|
-
|
308
|
-
|
421
|
+
VALUE range = rb_obj_alloc(rb_cRange);
|
422
|
+
VALUE min = LONG2FIX(oj_default_options.int_range_min);
|
423
|
+
VALUE max = LONG2FIX(oj_default_options.int_range_max);
|
309
424
|
|
310
|
-
|
311
|
-
|
312
|
-
|
425
|
+
rb_ivar_set(range, oj_begin_id, min);
|
426
|
+
rb_ivar_set(range, oj_end_id, max);
|
427
|
+
rb_hash_aset(opts, integer_range_sym, range);
|
313
428
|
} else {
|
314
|
-
|
429
|
+
rb_hash_aset(opts, integer_range_sym, Qnil);
|
315
430
|
}
|
316
431
|
switch (oj_default_options.escape_mode) {
|
317
|
-
case NLEsc:
|
318
|
-
case JSONEsc:
|
319
|
-
case XSSEsc:
|
320
|
-
case ASCIIEsc:
|
321
|
-
case JXEsc:
|
322
|
-
default:
|
432
|
+
case NLEsc: rb_hash_aset(opts, escape_mode_sym, newline_sym); break;
|
433
|
+
case JSONEsc: rb_hash_aset(opts, escape_mode_sym, json_sym); break;
|
434
|
+
case XSSEsc: rb_hash_aset(opts, escape_mode_sym, xss_safe_sym); break;
|
435
|
+
case ASCIIEsc: rb_hash_aset(opts, escape_mode_sym, ascii_sym); break;
|
436
|
+
case JXEsc: rb_hash_aset(opts, escape_mode_sym, unicode_xss_sym); break;
|
437
|
+
default: rb_hash_aset(opts, escape_mode_sym, json_sym); break;
|
323
438
|
}
|
324
439
|
switch (oj_default_options.time_format) {
|
325
|
-
case XmlTime:
|
326
|
-
case RubyTime:
|
327
|
-
case UnixZTime:
|
440
|
+
case XmlTime: rb_hash_aset(opts, time_format_sym, xmlschema_sym); break;
|
441
|
+
case RubyTime: rb_hash_aset(opts, time_format_sym, ruby_sym); break;
|
442
|
+
case UnixZTime: rb_hash_aset(opts, time_format_sym, unix_zone_sym); break;
|
328
443
|
case UnixTime:
|
329
|
-
default:
|
444
|
+
default: rb_hash_aset(opts, time_format_sym, unix_sym); break;
|
330
445
|
}
|
331
446
|
switch (oj_default_options.bigdec_load) {
|
332
|
-
case BigDec:
|
333
|
-
case FloatDec:
|
447
|
+
case BigDec: rb_hash_aset(opts, bigdecimal_load_sym, bigdecimal_sym); break;
|
448
|
+
case FloatDec: rb_hash_aset(opts, bigdecimal_load_sym, float_sym); break;
|
449
|
+
case FastDec: rb_hash_aset(opts, bigdecimal_load_sym, fast_sym); break;
|
334
450
|
case AutoDec:
|
335
|
-
default:
|
451
|
+
default: rb_hash_aset(opts, bigdecimal_load_sym, auto_sym); break;
|
336
452
|
}
|
337
|
-
rb_hash_aset(opts,
|
338
|
-
rb_hash_aset(
|
339
|
-
|
340
|
-
|
341
|
-
|
453
|
+
rb_hash_aset(opts, compat_bigdecimal_sym, oj_default_options.compat_bigdec ? Qtrue : Qfalse);
|
454
|
+
rb_hash_aset(
|
455
|
+
opts,
|
456
|
+
create_id_sym,
|
457
|
+
(NULL == oj_default_options.create_id) ? Qnil : rb_str_new2(oj_default_options.create_id));
|
458
|
+
rb_hash_aset(opts,
|
459
|
+
oj_space_sym,
|
460
|
+
(0 == oj_default_options.dump_opts.after_size)
|
461
|
+
? Qnil
|
462
|
+
: rb_str_new2(oj_default_options.dump_opts.after_sep));
|
463
|
+
rb_hash_aset(opts,
|
464
|
+
oj_space_before_sym,
|
465
|
+
(0 == oj_default_options.dump_opts.before_size)
|
466
|
+
? Qnil
|
467
|
+
: rb_str_new2(oj_default_options.dump_opts.before_sep));
|
468
|
+
rb_hash_aset(opts,
|
469
|
+
oj_object_nl_sym,
|
470
|
+
(0 == oj_default_options.dump_opts.hash_size)
|
471
|
+
? Qnil
|
472
|
+
: rb_str_new2(oj_default_options.dump_opts.hash_nl));
|
473
|
+
rb_hash_aset(opts,
|
474
|
+
oj_array_nl_sym,
|
475
|
+
(0 == oj_default_options.dump_opts.array_size)
|
476
|
+
? Qnil
|
477
|
+
: rb_str_new2(oj_default_options.dump_opts.array_nl));
|
342
478
|
|
343
479
|
switch (oj_default_options.dump_opts.nan_dump) {
|
344
|
-
case NullNan:
|
345
|
-
case RaiseNan:
|
346
|
-
case WordNan:
|
347
|
-
case HugeNan:
|
480
|
+
case NullNan: rb_hash_aset(opts, nan_sym, null_sym); break;
|
481
|
+
case RaiseNan: rb_hash_aset(opts, nan_sym, raise_sym); break;
|
482
|
+
case WordNan: rb_hash_aset(opts, nan_sym, word_sym); break;
|
483
|
+
case HugeNan: rb_hash_aset(opts, nan_sym, huge_sym); break;
|
348
484
|
case AutoNan:
|
349
|
-
default:
|
485
|
+
default: rb_hash_aset(opts, nan_sym, auto_sym); break;
|
350
486
|
}
|
351
487
|
rb_hash_aset(opts, omit_nil_sym, oj_default_options.dump_opts.omit_nil ? Qtrue : Qfalse);
|
352
488
|
rb_hash_aset(opts, oj_hash_class_sym, oj_default_options.hash_class);
|
353
489
|
rb_hash_aset(opts, oj_array_class_sym, oj_default_options.array_class);
|
354
490
|
|
355
491
|
if (NULL == oj_default_options.ignore) {
|
356
|
-
|
492
|
+
rb_hash_aset(opts, ignore_sym, Qnil);
|
357
493
|
} else {
|
358
|
-
|
359
|
-
|
494
|
+
VALUE * vp;
|
495
|
+
volatile VALUE a = rb_ary_new();
|
360
496
|
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
497
|
+
for (vp = oj_default_options.ignore; Qnil != *vp; vp++) {
|
498
|
+
rb_ary_push(a, *vp);
|
499
|
+
}
|
500
|
+
rb_hash_aset(opts, ignore_sym, a);
|
365
501
|
}
|
366
502
|
return opts;
|
367
503
|
}
|
@@ -371,434 +507,504 @@ get_def_opts(VALUE self) {
|
|
371
507
|
*
|
372
508
|
* Sets the default options for load and dump.
|
373
509
|
* - *opts* [_Hash_] options to change
|
374
|
-
* - *:indent* [_Fixnum_|_String_|_nil_] number of spaces to indent each element in a JSON
|
510
|
+
* - *:indent* [_Fixnum_|_String_|_nil_] number of spaces to indent each element in a JSON
|
511
|
+
*document or the String to use for identation.
|
375
512
|
* - :circular [_Boolean_|_nil_] support circular references while dumping.
|
376
513
|
* - *:auto_define* [_Boolean_|_nil_] automatically define classes if they do not exist.
|
377
514
|
* - *:symbol_keys* [_Boolean_|_nil_] convert hash keys to symbols.
|
378
515
|
* - *:class_cache* [_Boolean_|_nil_] cache classes for faster parsing.
|
379
|
-
* - *:escape* [_:newline_|_:json_|_:xss_safe_|_:ascii_|_unicode_xss_|_nil_] mode encodes all
|
380
|
-
*
|
381
|
-
|
382
|
-
*
|
383
|
-
*
|
516
|
+
* - *:escape* [_:newline_|_:json_|_:xss_safe_|_:ascii_|_unicode_xss_|_nil_] mode encodes all
|
517
|
+
*high-bit characters as escaped sequences if :ascii, :json is standand UTF-8 JSON encoding,
|
518
|
+
*:newline is the same as :json but newlines are not escaped, :unicode_xss allows unicode but
|
519
|
+
*escapes &, <, and >, and any \u20xx characters along with some others, and :xss_safe escapes &, <,
|
520
|
+
*and >, and some others.
|
521
|
+
* - *:bigdecimal_as_decimal* [_Boolean_|_nil_] dump BigDecimal as a decimal number or as a
|
522
|
+
*String.
|
523
|
+
* - *:bigdecimal_load* [_:bigdecimal_|_:float_|_:auto_|_nil_] load decimals as BigDecimal instead
|
524
|
+
*of as a Float. :auto pick the most precise for the number of digits.
|
525
|
+
* - *:compat_bigdecimal* [_true_|_false_] load decimals as BigDecimal instead of as a Float in
|
526
|
+
*compat mode.
|
527
|
+
* - *:mode* [_:object_|_:strict_|_:compat_|_:null_|_:custom_|_:rails_|_:wab_] load and dump mode
|
528
|
+
*to use for JSON :strict raises an exception when a non-supported Object is encountered. :compat
|
529
|
+
*attempts to extract variable values from an Object using to_json() or to_hash() then it walks the
|
530
|
+
*Object's variables if neither is found. The :object mode ignores to_hash() and to_json() methods
|
531
|
+
*and encodes variables using code internal to the Oj gem. The :null mode ignores non-supported
|
532
|
+
*Objects and replaces them with a null. The :custom mode honors all dump options. The :rails more
|
533
|
+
*mimics rails and Active behavior.
|
534
|
+
* - *:time_format* [_:unix_|_:xmlschema_|_:ruby_] time format when dumping in :compat mode :unix
|
535
|
+
*decimal number denoting the number of seconds since 1/1/1970, :unix_zone decimal number denoting
|
536
|
+
*the number of seconds since 1/1/1970 plus the utc_offset in the exponent, :xmlschema date-time
|
537
|
+
*format taken from XML Schema as a String, :ruby Time.to_s formatted String.
|
384
538
|
* - *:create_id* [_String_|_nil_] create id for json compatible object encoding
|
385
|
-
* - *:create_additions* [_Boolean_|_nil_] if true allow creation of instances using create_id on
|
386
|
-
*
|
387
|
-
* - *:
|
539
|
+
* - *:create_additions* [_Boolean_|_nil_] if true allow creation of instances using create_id on
|
540
|
+
*load.
|
541
|
+
* - *:second_precision* [_Fixnum_|_nil_] number of digits after the decimal when dumping the
|
542
|
+
*seconds portion of time.
|
543
|
+
* - *:float_precision* [_Fixnum_|_nil_] number of digits of precision when dumping floats, 0
|
544
|
+
*indicates use Ruby.
|
388
545
|
* - *:use_to_json* [_Boolean_|_nil_] call to_json() methods on dump, default is false.
|
389
546
|
* - *:use_as_json* [_Boolean_|_nil_] call as_json() methods on dump, default is false.
|
390
547
|
* - *:use_to_hash* [_Boolean_|_nil_] call to_hash() methods on dump, default is false.
|
391
548
|
* - *:use_raw_json* [_Boolean_|_nil_] call raw_json() methods on dump, default is false.
|
392
|
-
* - *:nilnil* [_Boolean_|_nil_] if true a nil input to load will return nil and not raise an
|
549
|
+
* - *:nilnil* [_Boolean_|_nil_] if true a nil input to load will return nil and not raise an
|
550
|
+
*Exception.
|
393
551
|
* - *:allow_gc* [_Boolean_|_nil_] allow or prohibit GC during parsing, default is true (allow).
|
394
|
-
* - *:quirks_mode* [_Boolean_|_nil_] allow single JSON values instead of documents, default is
|
395
|
-
*
|
552
|
+
* - *:quirks_mode* [_Boolean_|_nil_] allow single JSON values instead of documents, default is
|
553
|
+
*true (allow).
|
554
|
+
* - *:allow_invalid_unicode* [_Boolean_|_nil_] allow invalid unicode, default is false (don't
|
555
|
+
*allow).
|
396
556
|
* - *:allow_nan* [_Boolean_|_nil_] allow Nan, Infinity, and -Infinity, default is true (allow).
|
397
557
|
* - *:space* [_String_|_nil_] String to use for the space after the colon in JSON object fields.
|
398
|
-
* - *:space_before* [_String_|_nil_] String to use before the colon separator in JSON object
|
558
|
+
* - *:space_before* [_String_|_nil_] String to use before the colon separator in JSON object
|
559
|
+
*fields.
|
399
560
|
* - *:object_nl* [_String_|_nil_] String to use after a JSON object field value.
|
400
561
|
* - *:array_nl* [_String_|_nil_] String to use after a JSON array value
|
401
|
-
* - *:nan* [_:null_|_:huge_|_:word_|_:raise_] how to dump Infinity and NaN in null, strict, and
|
402
|
-
*
|
562
|
+
* - *:nan* [_:null_|_:huge_|_:word_|_:raise_] how to dump Infinity and NaN in null, strict, and
|
563
|
+
*compat mode. :null places a null, :huge places a huge number, :word places Infinity or NaN, :raise
|
564
|
+
*raises and exception, :auto uses default for each mode.
|
565
|
+
* - *:hash_class* [_Class_|_nil_] Class to use instead of Hash on load, :object_class can also be
|
566
|
+
*used.
|
403
567
|
* - *:array_class* [_Class_|_nil_] Class to use instead of Array on load.
|
404
568
|
* - *:omit_nil* [_true_|_false_] if true Hash and Object attributes with nil values are omitted.
|
405
569
|
* - *:ignore* [_nil_|Array] either nil or an Array of classes to ignore when dumping
|
406
|
-
* - *:ignore_under* [_Boolean_] if true then attributes that start with _ are ignored when
|
570
|
+
* - *:ignore_under* [_Boolean_] if true then attributes that start with _ are ignored when
|
571
|
+
*dumping in object or custom mode.
|
572
|
+
* - *:cache_keys* [_Boolean_] if true then hash keys are cached
|
573
|
+
* - *:cache_str* [_Fixnum_] maximum string vsalue length to cache
|
407
574
|
* - *:integer_range* [_Range_] Dump integers outside range as strings.
|
408
575
|
* - *:trace* [_Boolean_] turn trace on or off.
|
409
576
|
* - *:safe* [_Boolean_] turn safe mimic on or off.
|
410
577
|
*/
|
411
|
-
static VALUE
|
412
|
-
set_def_opts(VALUE self, VALUE opts) {
|
578
|
+
static VALUE set_def_opts(VALUE self, VALUE opts) {
|
413
579
|
Check_Type(opts, T_HASH);
|
414
580
|
oj_parse_options(opts, &oj_default_options);
|
415
581
|
|
416
582
|
return Qnil;
|
417
583
|
}
|
418
584
|
|
419
|
-
void
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
volatile VALUE v;
|
446
|
-
size_t len;
|
585
|
+
void oj_parse_options(VALUE ropts, Options copts) {
|
586
|
+
struct _yesNoOpt ynos[] = {{circular_sym, &copts->circular},
|
587
|
+
{auto_define_sym, &copts->auto_define},
|
588
|
+
{symbol_keys_sym, &copts->sym_key},
|
589
|
+
{class_cache_sym, &copts->class_cache},
|
590
|
+
{bigdecimal_as_decimal_sym, &copts->bigdec_as_num},
|
591
|
+
{use_to_hash_sym, &copts->to_hash},
|
592
|
+
{use_to_json_sym, &copts->to_json},
|
593
|
+
{use_as_json_sym, &copts->as_json},
|
594
|
+
{use_raw_json_sym, &copts->raw_json},
|
595
|
+
{nilnil_sym, &copts->nilnil},
|
596
|
+
{allow_blank_sym, &copts->nilnil}, // same as nilnil
|
597
|
+
{empty_string_sym, &copts->empty_string},
|
598
|
+
{allow_gc_sym, &copts->allow_gc},
|
599
|
+
{oj_quirks_mode_sym, &copts->quirks_mode},
|
600
|
+
{allow_invalid_unicode_sym, &copts->allow_invalid},
|
601
|
+
{oj_allow_nan_sym, &copts->allow_nan},
|
602
|
+
{oj_trace_sym, &copts->trace},
|
603
|
+
{oj_safe_sym, &copts->safe},
|
604
|
+
{ignore_under_sym, &copts->ignore_under},
|
605
|
+
{oj_create_additions_sym, &copts->create_ok},
|
606
|
+
{cache_keys_sym, &copts->cache_keys},
|
607
|
+
{Qnil, 0}};
|
608
|
+
YesNoOpt o;
|
609
|
+
volatile VALUE v;
|
610
|
+
size_t len;
|
447
611
|
|
448
612
|
if (T_HASH != rb_type(ropts)) {
|
449
|
-
|
613
|
+
return;
|
450
614
|
}
|
451
615
|
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_indent_sym)) {
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
616
|
+
v = rb_hash_lookup(ropts, oj_indent_sym);
|
617
|
+
switch (rb_type(v)) {
|
618
|
+
case T_NIL:
|
619
|
+
copts->dump_opts.indent_size = 0;
|
620
|
+
*copts->dump_opts.indent_str = '\0';
|
621
|
+
copts->indent = 0;
|
622
|
+
break;
|
623
|
+
case T_FIXNUM:
|
624
|
+
copts->dump_opts.indent_size = 0;
|
625
|
+
*copts->dump_opts.indent_str = '\0';
|
626
|
+
copts->indent = FIX2INT(v);
|
627
|
+
break;
|
628
|
+
case T_STRING:
|
629
|
+
if (sizeof(copts->dump_opts.indent_str) <= (len = RSTRING_LEN(v))) {
|
630
|
+
rb_raise(rb_eArgError,
|
631
|
+
"indent string is limited to %lu characters.",
|
632
|
+
(unsigned long)sizeof(copts->dump_opts.indent_str));
|
633
|
+
}
|
634
|
+
strcpy(copts->dump_opts.indent_str, StringValuePtr(v));
|
635
|
+
copts->dump_opts.indent_size = (uint8_t)len;
|
636
|
+
copts->indent = 0;
|
637
|
+
break;
|
638
|
+
default: rb_raise(rb_eTypeError, "indent must be a Fixnum, String, or nil."); break;
|
639
|
+
}
|
476
640
|
}
|
477
641
|
if (Qnil != (v = rb_hash_lookup(ropts, float_prec_sym))) {
|
478
|
-
|
642
|
+
int n;
|
643
|
+
|
644
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
645
|
+
if (rb_cInteger != rb_obj_class(v)) {
|
646
|
+
rb_raise(rb_eArgError, ":float_precision must be a Integer.");
|
647
|
+
}
|
648
|
+
#else
|
649
|
+
if (T_FIXNUM != rb_type(v)) {
|
650
|
+
rb_raise(rb_eArgError, ":float_precision must be a Fixnum.");
|
651
|
+
}
|
652
|
+
#endif
|
653
|
+
n = FIX2INT(v);
|
654
|
+
if (0 >= n) {
|
655
|
+
*copts->float_fmt = '\0';
|
656
|
+
copts->float_prec = 0;
|
657
|
+
} else {
|
658
|
+
if (20 < n) {
|
659
|
+
n = 20;
|
660
|
+
}
|
661
|
+
sprintf(copts->float_fmt, "%%0.%dg", n);
|
662
|
+
copts->float_prec = n;
|
663
|
+
}
|
664
|
+
}
|
665
|
+
if (Qnil != (v = rb_hash_lookup(ropts, cache_str_sym))) {
|
666
|
+
int n;
|
479
667
|
|
480
668
|
#ifdef RUBY_INTEGER_UNIFICATION
|
481
|
-
|
482
|
-
|
483
|
-
|
669
|
+
if (rb_cInteger != rb_obj_class(v)) {
|
670
|
+
rb_raise(rb_eArgError, ":cache_str must be a Integer.");
|
671
|
+
}
|
484
672
|
#else
|
485
|
-
|
486
|
-
|
487
|
-
|
673
|
+
if (T_FIXNUM != rb_type(v)) {
|
674
|
+
rb_raise(rb_eArgError, ":cache_str must be a Fixnum.");
|
675
|
+
}
|
488
676
|
#endif
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
copts->float_prec = n;
|
499
|
-
}
|
677
|
+
n = FIX2INT(v);
|
678
|
+
if (0 >= n) {
|
679
|
+
copts->cache_str = 0;
|
680
|
+
} else {
|
681
|
+
if (32 < n) {
|
682
|
+
n = 32;
|
683
|
+
}
|
684
|
+
copts->cache_str = (char)n;
|
685
|
+
}
|
500
686
|
}
|
501
687
|
if (Qnil != (v = rb_hash_lookup(ropts, sec_prec_sym))) {
|
502
|
-
|
688
|
+
int n;
|
503
689
|
|
504
690
|
#ifdef RUBY_INTEGER_UNIFICATION
|
505
|
-
|
506
|
-
|
507
|
-
|
691
|
+
if (rb_cInteger != rb_obj_class(v)) {
|
692
|
+
rb_raise(rb_eArgError, ":second_precision must be a Integer.");
|
693
|
+
}
|
508
694
|
#else
|
509
|
-
|
510
|
-
|
511
|
-
|
695
|
+
if (T_FIXNUM != rb_type(v)) {
|
696
|
+
rb_raise(rb_eArgError, ":second_precision must be a Fixnum.");
|
697
|
+
}
|
512
698
|
#endif
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
699
|
+
n = NUM2INT(v);
|
700
|
+
if (0 > n) {
|
701
|
+
n = 0;
|
702
|
+
copts->sec_prec_set = false;
|
703
|
+
} else if (9 < n) {
|
704
|
+
n = 9;
|
705
|
+
copts->sec_prec_set = true;
|
706
|
+
} else {
|
707
|
+
copts->sec_prec_set = true;
|
708
|
+
}
|
709
|
+
copts->sec_prec = n;
|
524
710
|
}
|
525
711
|
if (Qnil != (v = rb_hash_lookup(ropts, mode_sym))) {
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
712
|
+
if (wab_sym == v) {
|
713
|
+
copts->mode = WabMode;
|
714
|
+
} else if (object_sym == v) {
|
715
|
+
copts->mode = ObjectMode;
|
716
|
+
} else if (strict_sym == v) {
|
717
|
+
copts->mode = StrictMode;
|
718
|
+
} else if (compat_sym == v || json_sym == v) {
|
719
|
+
copts->mode = CompatMode;
|
720
|
+
} else if (null_sym == v) {
|
721
|
+
copts->mode = NullMode;
|
722
|
+
} else if (custom_sym == v) {
|
723
|
+
copts->mode = CustomMode;
|
724
|
+
} else if (rails_sym == v) {
|
725
|
+
copts->mode = RailsMode;
|
726
|
+
} else {
|
727
|
+
rb_raise(rb_eArgError,
|
728
|
+
":mode must be :object, :strict, :compat, :null, :custom, :rails, or :wab.");
|
729
|
+
}
|
543
730
|
}
|
544
731
|
if (Qnil != (v = rb_hash_lookup(ropts, time_format_sym))) {
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
732
|
+
if (unix_sym == v) {
|
733
|
+
copts->time_format = UnixTime;
|
734
|
+
} else if (unix_zone_sym == v) {
|
735
|
+
copts->time_format = UnixZTime;
|
736
|
+
} else if (xmlschema_sym == v) {
|
737
|
+
copts->time_format = XmlTime;
|
738
|
+
} else if (ruby_sym == v) {
|
739
|
+
copts->time_format = RubyTime;
|
740
|
+
} else {
|
741
|
+
rb_raise(rb_eArgError, ":time_format must be :unix, :unix_zone, :xmlschema, or :ruby.");
|
742
|
+
}
|
556
743
|
}
|
557
744
|
if (Qnil != (v = rb_hash_lookup(ropts, escape_mode_sym))) {
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
745
|
+
if (newline_sym == v) {
|
746
|
+
copts->escape_mode = NLEsc;
|
747
|
+
} else if (json_sym == v) {
|
748
|
+
copts->escape_mode = JSONEsc;
|
749
|
+
} else if (xss_safe_sym == v) {
|
750
|
+
copts->escape_mode = XSSEsc;
|
751
|
+
} else if (ascii_sym == v) {
|
752
|
+
copts->escape_mode = ASCIIEsc;
|
753
|
+
} else if (unicode_xss_sym == v) {
|
754
|
+
copts->escape_mode = JXEsc;
|
755
|
+
} else {
|
756
|
+
rb_raise(rb_eArgError,
|
757
|
+
":encoding must be :newline, :json, :xss_safe, :unicode_xss, or :ascii.");
|
758
|
+
}
|
571
759
|
}
|
572
760
|
if (Qnil != (v = rb_hash_lookup(ropts, bigdecimal_load_sym))) {
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
761
|
+
if (bigdecimal_sym == v || Qtrue == v) {
|
762
|
+
copts->bigdec_load = BigDec;
|
763
|
+
} else if (float_sym == v) {
|
764
|
+
copts->bigdec_load = FloatDec;
|
765
|
+
} else if (fast_sym == v) {
|
766
|
+
copts->bigdec_load = FastDec;
|
767
|
+
} else if (auto_sym == v || Qfalse == v) {
|
768
|
+
copts->bigdec_load = AutoDec;
|
769
|
+
} else {
|
770
|
+
rb_raise(rb_eArgError, ":bigdecimal_load must be :bigdecimal, :float, or :auto.");
|
771
|
+
}
|
772
|
+
}
|
773
|
+
if (Qnil != (v = rb_hash_lookup(ropts, compat_bigdecimal_sym))) {
|
774
|
+
copts->compat_bigdec = (Qtrue == v);
|
775
|
+
}
|
776
|
+
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_decimal_class_sym)) {
|
777
|
+
v = rb_hash_lookup(ropts, oj_decimal_class_sym);
|
778
|
+
if (rb_cFloat == v) {
|
779
|
+
copts->compat_bigdec = false;
|
780
|
+
} else if (oj_bigdecimal_class == v) {
|
781
|
+
copts->compat_bigdec = true;
|
782
|
+
} else {
|
783
|
+
rb_raise(rb_eArgError, ":decimal_class must be BigDecimal or Float.");
|
784
|
+
}
|
582
785
|
}
|
583
786
|
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, create_id_sym)) {
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
}
|
787
|
+
v = rb_hash_lookup(ropts, create_id_sym);
|
788
|
+
if (Qnil == v) {
|
789
|
+
if (oj_json_class != oj_default_options.create_id && NULL != copts->create_id) {
|
790
|
+
xfree((char *)oj_default_options.create_id);
|
791
|
+
}
|
792
|
+
copts->create_id = NULL;
|
793
|
+
copts->create_id_len = 0;
|
794
|
+
} else if (T_STRING == rb_type(v)) {
|
795
|
+
const char *str = StringValuePtr(v);
|
796
|
+
|
797
|
+
len = RSTRING_LEN(v);
|
798
|
+
if (len != copts->create_id_len || 0 != strcmp(copts->create_id, str)) {
|
799
|
+
copts->create_id = ALLOC_N(char, len + 1);
|
800
|
+
strcpy((char *)copts->create_id, str);
|
801
|
+
copts->create_id_len = len;
|
802
|
+
}
|
803
|
+
} else {
|
804
|
+
rb_raise(rb_eArgError, ":create_id must be string.");
|
805
|
+
}
|
604
806
|
}
|
605
807
|
for (o = ynos; 0 != o->attr; o++) {
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
808
|
+
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, o->sym)) {
|
809
|
+
v = rb_hash_lookup(ropts, o->sym);
|
810
|
+
if (Qnil == v) {
|
811
|
+
*o->attr = NotSet;
|
812
|
+
} else if (Qtrue == v) {
|
813
|
+
*o->attr = Yes;
|
814
|
+
} else if (Qfalse == v) {
|
815
|
+
*o->attr = No;
|
816
|
+
} else {
|
817
|
+
rb_raise(rb_eArgError,
|
818
|
+
"%s must be true, false, or nil.",
|
819
|
+
rb_id2name(SYM2ID(o->sym)));
|
820
|
+
}
|
821
|
+
}
|
618
822
|
}
|
619
823
|
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_space_sym)) {
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
824
|
+
if (Qnil == (v = rb_hash_lookup(ropts, oj_space_sym))) {
|
825
|
+
copts->dump_opts.after_size = 0;
|
826
|
+
*copts->dump_opts.after_sep = '\0';
|
827
|
+
} else {
|
828
|
+
rb_check_type(v, T_STRING);
|
829
|
+
if (sizeof(copts->dump_opts.after_sep) <= (len = RSTRING_LEN(v))) {
|
830
|
+
rb_raise(rb_eArgError,
|
831
|
+
"space string is limited to %lu characters.",
|
832
|
+
(unsigned long)sizeof(copts->dump_opts.after_sep));
|
833
|
+
}
|
834
|
+
strcpy(copts->dump_opts.after_sep, StringValuePtr(v));
|
835
|
+
copts->dump_opts.after_size = (uint8_t)len;
|
836
|
+
}
|
631
837
|
}
|
632
838
|
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_space_before_sym)) {
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
839
|
+
if (Qnil == (v = rb_hash_lookup(ropts, oj_space_before_sym))) {
|
840
|
+
copts->dump_opts.before_size = 0;
|
841
|
+
*copts->dump_opts.before_sep = '\0';
|
842
|
+
} else {
|
843
|
+
rb_check_type(v, T_STRING);
|
844
|
+
if (sizeof(copts->dump_opts.before_sep) <= (len = RSTRING_LEN(v))) {
|
845
|
+
rb_raise(rb_eArgError,
|
846
|
+
"sapce_before string is limited to %lu characters.",
|
847
|
+
(unsigned long)sizeof(copts->dump_opts.before_sep));
|
848
|
+
}
|
849
|
+
strcpy(copts->dump_opts.before_sep, StringValuePtr(v));
|
850
|
+
copts->dump_opts.before_size = (uint8_t)len;
|
851
|
+
}
|
644
852
|
}
|
645
853
|
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_object_nl_sym)) {
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
854
|
+
if (Qnil == (v = rb_hash_lookup(ropts, oj_object_nl_sym))) {
|
855
|
+
copts->dump_opts.hash_size = 0;
|
856
|
+
*copts->dump_opts.hash_nl = '\0';
|
857
|
+
} else {
|
858
|
+
rb_check_type(v, T_STRING);
|
859
|
+
if (sizeof(copts->dump_opts.hash_nl) <= (len = RSTRING_LEN(v))) {
|
860
|
+
rb_raise(rb_eArgError,
|
861
|
+
"object_nl string is limited to %lu characters.",
|
862
|
+
(unsigned long)sizeof(copts->dump_opts.hash_nl));
|
863
|
+
}
|
864
|
+
strcpy(copts->dump_opts.hash_nl, StringValuePtr(v));
|
865
|
+
copts->dump_opts.hash_size = (uint8_t)len;
|
866
|
+
}
|
657
867
|
}
|
658
868
|
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_array_nl_sym)) {
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
869
|
+
if (Qnil == (v = rb_hash_lookup(ropts, oj_array_nl_sym))) {
|
870
|
+
copts->dump_opts.array_size = 0;
|
871
|
+
*copts->dump_opts.array_nl = '\0';
|
872
|
+
} else {
|
873
|
+
rb_check_type(v, T_STRING);
|
874
|
+
if (sizeof(copts->dump_opts.array_nl) <= (len = RSTRING_LEN(v))) {
|
875
|
+
rb_raise(rb_eArgError,
|
876
|
+
"array_nl string is limited to %lu characters.",
|
877
|
+
(unsigned long)sizeof(copts->dump_opts.array_nl));
|
878
|
+
}
|
879
|
+
strcpy(copts->dump_opts.array_nl, StringValuePtr(v));
|
880
|
+
copts->dump_opts.array_size = (uint8_t)len;
|
881
|
+
}
|
670
882
|
}
|
671
883
|
if (Qnil != (v = rb_hash_lookup(ropts, nan_sym))) {
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
884
|
+
if (null_sym == v) {
|
885
|
+
copts->dump_opts.nan_dump = NullNan;
|
886
|
+
} else if (huge_sym == v) {
|
887
|
+
copts->dump_opts.nan_dump = HugeNan;
|
888
|
+
} else if (word_sym == v) {
|
889
|
+
copts->dump_opts.nan_dump = WordNan;
|
890
|
+
} else if (raise_sym == v) {
|
891
|
+
copts->dump_opts.nan_dump = RaiseNan;
|
892
|
+
} else if (auto_sym == v) {
|
893
|
+
copts->dump_opts.nan_dump = AutoNan;
|
894
|
+
} else {
|
895
|
+
rb_raise(rb_eArgError, ":nan must be :null, :huge, :word, :raise, or :auto.");
|
896
|
+
}
|
685
897
|
}
|
686
|
-
copts->dump_opts.use = (0 < copts->dump_opts.indent_size ||
|
687
|
-
|
688
|
-
|
689
|
-
0 < copts->dump_opts.hash_size ||
|
690
|
-
0 < copts->dump_opts.array_size);
|
898
|
+
copts->dump_opts.use = (0 < copts->dump_opts.indent_size || 0 < copts->dump_opts.after_size ||
|
899
|
+
0 < copts->dump_opts.before_size || 0 < copts->dump_opts.hash_size ||
|
900
|
+
0 < copts->dump_opts.array_size);
|
691
901
|
if (Qnil != (v = rb_hash_lookup(ropts, omit_nil_sym))) {
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
902
|
+
if (Qtrue == v) {
|
903
|
+
copts->dump_opts.omit_nil = true;
|
904
|
+
} else if (Qfalse == v) {
|
905
|
+
copts->dump_opts.omit_nil = false;
|
906
|
+
} else {
|
907
|
+
rb_raise(rb_eArgError, ":omit_nil must be true or false.");
|
908
|
+
}
|
699
909
|
}
|
700
910
|
// This is here only for backwards compatibility with the original Oj.
|
701
911
|
v = rb_hash_lookup(ropts, oj_ascii_only_sym);
|
702
912
|
if (Qtrue == v) {
|
703
|
-
|
913
|
+
copts->escape_mode = ASCIIEsc;
|
704
914
|
} else if (Qfalse == v) {
|
705
|
-
|
915
|
+
copts->escape_mode = JSONEsc;
|
706
916
|
}
|
707
917
|
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_hash_class_sym)) {
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
918
|
+
if (Qnil == (v = rb_hash_lookup(ropts, oj_hash_class_sym))) {
|
919
|
+
copts->hash_class = Qnil;
|
920
|
+
} else {
|
921
|
+
rb_check_type(v, T_CLASS);
|
922
|
+
copts->hash_class = v;
|
923
|
+
}
|
714
924
|
}
|
715
925
|
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_object_class_sym)) {
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
926
|
+
if (Qnil == (v = rb_hash_lookup(ropts, oj_object_class_sym))) {
|
927
|
+
copts->hash_class = Qnil;
|
928
|
+
} else {
|
929
|
+
rb_check_type(v, T_CLASS);
|
930
|
+
copts->hash_class = v;
|
931
|
+
}
|
722
932
|
}
|
723
933
|
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_array_class_sym)) {
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
934
|
+
if (Qnil == (v = rb_hash_lookup(ropts, oj_array_class_sym))) {
|
935
|
+
copts->array_class = Qnil;
|
936
|
+
} else {
|
937
|
+
rb_check_type(v, T_CLASS);
|
938
|
+
copts->array_class = v;
|
939
|
+
}
|
730
940
|
}
|
731
941
|
oj_parse_opt_match_string(&copts->str_rx, ropts);
|
732
942
|
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, ignore_sym)) {
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
943
|
+
xfree(copts->ignore);
|
944
|
+
copts->ignore = NULL;
|
945
|
+
if (Qnil != (v = rb_hash_lookup(ropts, ignore_sym))) {
|
946
|
+
int cnt;
|
947
|
+
|
948
|
+
rb_check_type(v, T_ARRAY);
|
949
|
+
cnt = (int)RARRAY_LEN(v);
|
950
|
+
if (0 < cnt) {
|
951
|
+
int i;
|
952
|
+
|
953
|
+
copts->ignore = ALLOC_N(VALUE, cnt + 1);
|
954
|
+
for (i = 0; i < cnt; i++) {
|
955
|
+
copts->ignore[i] = rb_ary_entry(v, i);
|
956
|
+
}
|
957
|
+
copts->ignore[i] = Qnil;
|
958
|
+
}
|
959
|
+
}
|
750
960
|
}
|
751
961
|
if (Qnil != (v = rb_hash_lookup(ropts, integer_range_sym))) {
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
962
|
+
if (TYPE(v) == T_STRUCT && rb_obj_class(v) == rb_cRange) {
|
963
|
+
VALUE min = rb_funcall(v, oj_begin_id, 0);
|
964
|
+
VALUE max = rb_funcall(v, oj_end_id, 0);
|
965
|
+
|
966
|
+
if (TYPE(min) != T_FIXNUM || TYPE(max) != T_FIXNUM) {
|
967
|
+
rb_raise(rb_eArgError, ":integer_range range bounds is not Fixnum.");
|
968
|
+
}
|
969
|
+
|
970
|
+
copts->int_range_min = FIX2LONG(min);
|
971
|
+
copts->int_range_max = FIX2LONG(max);
|
972
|
+
} else if (Qfalse != v) {
|
973
|
+
rb_raise(rb_eArgError, ":integer_range must be a range of Fixnum.");
|
974
|
+
}
|
765
975
|
}
|
766
976
|
}
|
767
977
|
|
768
|
-
static int
|
769
|
-
|
770
|
-
RxClass rc = (RxClass)rx;
|
978
|
+
static int match_string_cb(VALUE key, VALUE value, VALUE rx) {
|
979
|
+
RxClass rc = (RxClass)rx;
|
771
980
|
|
772
981
|
if (T_CLASS != rb_type(value)) {
|
773
|
-
|
982
|
+
rb_raise(rb_eArgError, "for :match_string, the hash values must be a Class.");
|
774
983
|
}
|
775
984
|
switch (rb_type(key)) {
|
776
|
-
case T_REGEXP:
|
777
|
-
oj_rxclass_rappend(rc, key, value);
|
778
|
-
break;
|
985
|
+
case T_REGEXP: oj_rxclass_rappend(rc, key, value); break;
|
779
986
|
case T_STRING:
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
987
|
+
if (0 != oj_rxclass_append(rc, StringValuePtr(key), value)) {
|
988
|
+
rb_raise(rb_eArgError, "%s", rc->err);
|
989
|
+
}
|
990
|
+
break;
|
784
991
|
default:
|
785
|
-
|
786
|
-
|
992
|
+
rb_raise(rb_eArgError, "for :match_string, keys must either a String or RegExp.");
|
993
|
+
break;
|
787
994
|
}
|
788
995
|
return ST_CONTINUE;
|
789
996
|
}
|
790
997
|
|
791
|
-
void
|
792
|
-
|
793
|
-
VALUE v;
|
998
|
+
void oj_parse_opt_match_string(RxClass rc, VALUE ropts) {
|
999
|
+
VALUE v;
|
794
1000
|
|
795
1001
|
if (Qnil != (v = rb_hash_lookup(ropts, match_string_sym))) {
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
1002
|
+
rb_check_type(v, T_HASH);
|
1003
|
+
// Zero out rc. Pattern are not appended but override.
|
1004
|
+
rc->head = NULL;
|
1005
|
+
rc->tail = NULL;
|
1006
|
+
*rc->err = '\0';
|
1007
|
+
rb_hash_foreach(v, match_string_cb, (VALUE)rc);
|
802
1008
|
}
|
803
1009
|
}
|
804
1010
|
|
@@ -834,54 +1040,50 @@ oj_parse_opt_match_string(RxClass rc, VALUE ropts) {
|
|
834
1040
|
*
|
835
1041
|
* Returns [_Hash_|_Array_|_String_|_Fixnum_|_Float_|_Boolean_|_nil_]
|
836
1042
|
*/
|
837
|
-
static VALUE
|
838
|
-
|
839
|
-
Mode mode = oj_default_options.mode;
|
1043
|
+
static VALUE load(int argc, VALUE *argv, VALUE self) {
|
1044
|
+
Mode mode = oj_default_options.mode;
|
840
1045
|
|
841
1046
|
if (1 > argc) {
|
842
|
-
|
1047
|
+
rb_raise(rb_eArgError, "Wrong number of arguments to load().");
|
843
1048
|
}
|
844
1049
|
if (2 <= argc) {
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
1050
|
+
VALUE ropts = argv[1];
|
1051
|
+
VALUE v;
|
1052
|
+
|
1053
|
+
if (Qnil != ropts || CompatMode != mode) {
|
1054
|
+
Check_Type(ropts, T_HASH);
|
1055
|
+
if (Qnil != (v = rb_hash_lookup(ropts, mode_sym))) {
|
1056
|
+
if (object_sym == v) {
|
1057
|
+
mode = ObjectMode;
|
1058
|
+
} else if (strict_sym == v) {
|
1059
|
+
mode = StrictMode;
|
1060
|
+
} else if (compat_sym == v || json_sym == v) {
|
1061
|
+
mode = CompatMode;
|
1062
|
+
} else if (null_sym == v) {
|
1063
|
+
mode = NullMode;
|
1064
|
+
} else if (custom_sym == v) {
|
1065
|
+
mode = CustomMode;
|
1066
|
+
} else if (rails_sym == v) {
|
1067
|
+
mode = RailsMode;
|
1068
|
+
} else if (wab_sym == v) {
|
1069
|
+
mode = WabMode;
|
1070
|
+
} else {
|
1071
|
+
rb_raise(rb_eArgError,
|
1072
|
+
":mode must be :object, :strict, :compat, :null, :custom, :rails, or "
|
1073
|
+
":wab.");
|
1074
|
+
}
|
1075
|
+
}
|
1076
|
+
}
|
870
1077
|
}
|
871
1078
|
switch (mode) {
|
872
1079
|
case StrictMode:
|
873
|
-
case NullMode:
|
874
|
-
return oj_strict_parse(argc, argv, self);
|
1080
|
+
case NullMode: return oj_strict_parse(argc, argv, self);
|
875
1081
|
case CompatMode:
|
876
|
-
case RailsMode:
|
877
|
-
|
878
|
-
case
|
879
|
-
return oj_custom_parse(argc, argv, self);
|
880
|
-
case WabMode:
|
881
|
-
return oj_wab_parse(argc, argv, self);
|
1082
|
+
case RailsMode: return oj_compat_parse(argc, argv, self);
|
1083
|
+
case CustomMode: return oj_custom_parse(argc, argv, self);
|
1084
|
+
case WabMode: return oj_wab_parse(argc, argv, self);
|
882
1085
|
case ObjectMode:
|
883
|
-
default:
|
884
|
-
break;
|
1086
|
+
default: break;
|
885
1087
|
}
|
886
1088
|
return oj_object_parse(argc, argv, self);
|
887
1089
|
}
|
@@ -920,69 +1122,61 @@ load(int argc, VALUE *argv, VALUE self) {
|
|
920
1122
|
*
|
921
1123
|
* Returns [_Object_|_Hash_|_Array_|_String_|_Fixnum_|_Float_|_Boolean_|_nil_]
|
922
1124
|
*/
|
923
|
-
static VALUE
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
struct _parseInfo pi;
|
1125
|
+
static VALUE load_file(int argc, VALUE *argv, VALUE self) {
|
1126
|
+
char * path;
|
1127
|
+
int fd;
|
1128
|
+
Mode mode = oj_default_options.mode;
|
1129
|
+
struct _parseInfo pi;
|
929
1130
|
|
930
1131
|
if (1 > argc) {
|
931
|
-
|
1132
|
+
rb_raise(rb_eArgError, "Wrong number of arguments to load().");
|
932
1133
|
}
|
933
1134
|
Check_Type(*argv, T_STRING);
|
934
1135
|
parse_info_init(&pi);
|
935
|
-
pi.options
|
936
|
-
pi.handler
|
1136
|
+
pi.options = oj_default_options;
|
1137
|
+
pi.handler = Qnil;
|
937
1138
|
pi.err_class = Qnil;
|
938
1139
|
pi.max_depth = 0;
|
939
1140
|
if (2 <= argc) {
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
1141
|
+
VALUE ropts = argv[1];
|
1142
|
+
VALUE v;
|
1143
|
+
|
1144
|
+
Check_Type(ropts, T_HASH);
|
1145
|
+
if (Qnil != (v = rb_hash_lookup(ropts, mode_sym))) {
|
1146
|
+
if (object_sym == v) {
|
1147
|
+
mode = ObjectMode;
|
1148
|
+
} else if (strict_sym == v) {
|
1149
|
+
mode = StrictMode;
|
1150
|
+
} else if (compat_sym == v || json_sym == v) {
|
1151
|
+
mode = CompatMode;
|
1152
|
+
} else if (null_sym == v) {
|
1153
|
+
mode = NullMode;
|
1154
|
+
} else if (custom_sym == v) {
|
1155
|
+
mode = CustomMode;
|
1156
|
+
} else if (rails_sym == v) {
|
1157
|
+
mode = RailsMode;
|
1158
|
+
} else if (wab_sym == v) {
|
1159
|
+
mode = WabMode;
|
1160
|
+
} else {
|
1161
|
+
rb_raise(
|
1162
|
+
rb_eArgError,
|
1163
|
+
":mode must be :object, :strict, :compat, :null, :custom, :rails, or :wab.");
|
1164
|
+
}
|
1165
|
+
}
|
963
1166
|
}
|
964
1167
|
path = StringValuePtr(*argv);
|
965
1168
|
if (0 == (fd = open(path, O_RDONLY))) {
|
966
|
-
|
1169
|
+
rb_raise(rb_eIOError, "%s", strerror(errno));
|
967
1170
|
}
|
968
1171
|
switch (mode) {
|
969
1172
|
case StrictMode:
|
970
|
-
case NullMode:
|
971
|
-
|
972
|
-
return oj_pi_sparse(argc, argv, &pi, fd);
|
973
|
-
case CustomMode:
|
974
|
-
oj_set_custom_callbacks(&pi);
|
975
|
-
return oj_pi_sparse(argc, argv, &pi, fd);
|
1173
|
+
case NullMode: oj_set_strict_callbacks(&pi); return oj_pi_sparse(argc, argv, &pi, fd);
|
1174
|
+
case CustomMode: oj_set_custom_callbacks(&pi); return oj_pi_sparse(argc, argv, &pi, fd);
|
976
1175
|
case CompatMode:
|
977
|
-
case RailsMode:
|
978
|
-
|
979
|
-
return oj_pi_sparse(argc, argv, &pi, fd);
|
980
|
-
case WabMode:
|
981
|
-
oj_set_wab_callbacks(&pi);
|
982
|
-
return oj_pi_sparse(argc, argv, &pi, fd);
|
1176
|
+
case RailsMode: oj_set_compat_callbacks(&pi); return oj_pi_sparse(argc, argv, &pi, fd);
|
1177
|
+
case WabMode: oj_set_wab_callbacks(&pi); return oj_pi_sparse(argc, argv, &pi, fd);
|
983
1178
|
case ObjectMode:
|
984
|
-
default:
|
985
|
-
break;
|
1179
|
+
default: break;
|
986
1180
|
}
|
987
1181
|
oj_set_object_callbacks(&pi);
|
988
1182
|
|
@@ -1000,18 +1194,17 @@ load_file(int argc, VALUE *argv, VALUE self) {
|
|
1000
1194
|
*
|
1001
1195
|
* Returns [_Hash_|_Array_|_String_|_Fixnum_|_Bignum_|_BigDecimal_|_nil_|_True_|_False_]
|
1002
1196
|
*/
|
1003
|
-
static VALUE
|
1004
|
-
|
1005
|
-
|
1006
|
-
VALUE args[1];
|
1197
|
+
static VALUE safe_load(VALUE self, VALUE doc) {
|
1198
|
+
struct _parseInfo pi;
|
1199
|
+
VALUE args[1];
|
1007
1200
|
|
1008
1201
|
parse_info_init(&pi);
|
1009
|
-
pi.err_class
|
1010
|
-
pi.max_depth
|
1011
|
-
pi.options
|
1202
|
+
pi.err_class = Qnil;
|
1203
|
+
pi.max_depth = 0;
|
1204
|
+
pi.options = oj_default_options;
|
1012
1205
|
pi.options.auto_define = No;
|
1013
|
-
pi.options.sym_key
|
1014
|
-
pi.options.mode
|
1206
|
+
pi.options.sym_key = No;
|
1207
|
+
pi.options.mode = StrictMode;
|
1015
1208
|
oj_set_strict_callbacks(&pi);
|
1016
1209
|
*args = doc;
|
1017
1210
|
|
@@ -1051,38 +1244,37 @@ safe_load(VALUE self, VALUE doc) {
|
|
1051
1244
|
* - *obj* [_Object_] Object to serialize as an JSON document String
|
1052
1245
|
* - *options* [_Hash_] same as default_options
|
1053
1246
|
*/
|
1054
|
-
static VALUE
|
1055
|
-
|
1056
|
-
|
1057
|
-
struct
|
1058
|
-
|
1059
|
-
VALUE rstr;
|
1247
|
+
static VALUE dump(int argc, VALUE *argv, VALUE self) {
|
1248
|
+
char buf[4096];
|
1249
|
+
struct _out out;
|
1250
|
+
struct _options copts = oj_default_options;
|
1251
|
+
VALUE rstr;
|
1060
1252
|
|
1061
1253
|
if (1 > argc) {
|
1062
|
-
|
1254
|
+
rb_raise(rb_eArgError, "wrong number of arguments (0 for 1).");
|
1063
1255
|
}
|
1064
1256
|
if (CompatMode == copts.mode) {
|
1065
|
-
|
1257
|
+
copts.dump_opts.nan_dump = WordNan;
|
1066
1258
|
}
|
1067
1259
|
if (2 == argc) {
|
1068
|
-
|
1260
|
+
oj_parse_options(argv[1], &copts);
|
1069
1261
|
}
|
1070
1262
|
if (CompatMode == copts.mode && copts.escape_mode != ASCIIEsc) {
|
1071
|
-
|
1263
|
+
copts.escape_mode = JSONEsc;
|
1072
1264
|
}
|
1073
|
-
out.buf
|
1074
|
-
out.end
|
1265
|
+
out.buf = buf;
|
1266
|
+
out.end = buf + sizeof(buf) - 10;
|
1075
1267
|
out.allocated = false;
|
1076
|
-
out.omit_nil
|
1077
|
-
out.caller
|
1078
|
-
oj_dump_obj_to_json_using_params(*argv, &copts, &out, argc - 1,argv + 1);
|
1268
|
+
out.omit_nil = copts.dump_opts.omit_nil;
|
1269
|
+
out.caller = CALLER_DUMP;
|
1270
|
+
oj_dump_obj_to_json_using_params(*argv, &copts, &out, argc - 1, argv + 1);
|
1079
1271
|
if (0 == out.buf) {
|
1080
|
-
|
1272
|
+
rb_raise(rb_eNoMemError, "Not enough memory.");
|
1081
1273
|
}
|
1082
1274
|
rstr = rb_str_new2(out.buf);
|
1083
1275
|
rstr = oj_encode(rstr);
|
1084
1276
|
if (out.allocated) {
|
1085
|
-
|
1277
|
+
xfree(out.buf);
|
1086
1278
|
}
|
1087
1279
|
return rstr;
|
1088
1280
|
}
|
@@ -1094,50 +1286,54 @@ dump(int argc, VALUE *argv, VALUE self) {
|
|
1094
1286
|
* will be called. The mode is set to :compat.
|
1095
1287
|
* - *obj* [_Object_] Object to serialize as an JSON document String
|
1096
1288
|
* - *options* [_Hash_]
|
1097
|
-
* - *:max_nesting* [_boolean_] It true nesting is limited to 100. The option to detect circular
|
1098
|
-
*
|
1099
|
-
* - *:
|
1100
|
-
*
|
1289
|
+
* - *:max_nesting* [_boolean_] It true nesting is limited to 100. The option to detect circular
|
1290
|
+
* references is available but is not compatible with the json gem., default is false
|
1291
|
+
* - *:allow_nan* [_boolean_] If true non JSON compliant words such as Nan and Infinity will be
|
1292
|
+
* used as appropriate, default is true.
|
1293
|
+
* - *:quirks_mode* [_boolean_] Allow single JSON values instead of documents, default is true
|
1294
|
+
* (allow).
|
1295
|
+
* - *:indent* [_String_|_nil_] String to use for indentation, overriding the indent option if not
|
1296
|
+
* nil.
|
1101
1297
|
* - *:space* [_String_|_nil_] String to use for the space after the colon in JSON object fields.
|
1102
|
-
* - *:space_before* [_String_|_nil_] String to use before the colon separator in JSON object
|
1298
|
+
* - *:space_before* [_String_|_nil_] String to use before the colon separator in JSON object
|
1299
|
+
* fields.
|
1103
1300
|
* - *:object_nl* [_String_|_nil_] String to use after a JSON object field value.
|
1104
1301
|
* - *:array_nl* [_String_|_nil_] String to use after a JSON array value.
|
1105
1302
|
* - *:trace* [_Boolean_] If true trace is turned on.
|
1106
1303
|
*
|
1107
1304
|
* Returns [_String_] the encoded JSON.
|
1108
1305
|
*/
|
1109
|
-
static VALUE
|
1110
|
-
|
1111
|
-
|
1112
|
-
struct
|
1113
|
-
|
1114
|
-
VALUE rstr;
|
1306
|
+
static VALUE to_json(int argc, VALUE *argv, VALUE self) {
|
1307
|
+
char buf[4096];
|
1308
|
+
struct _out out;
|
1309
|
+
struct _options copts = oj_default_options;
|
1310
|
+
VALUE rstr;
|
1115
1311
|
|
1116
1312
|
if (1 > argc) {
|
1117
|
-
|
1313
|
+
rb_raise(rb_eArgError, "wrong number of arguments (0 for 1).");
|
1118
1314
|
}
|
1119
|
-
copts.escape_mode
|
1315
|
+
copts.escape_mode = JXEsc;
|
1120
1316
|
copts.dump_opts.nan_dump = RaiseNan;
|
1121
1317
|
if (2 == argc) {
|
1122
|
-
|
1318
|
+
oj_parse_mimic_dump_options(argv[1], &copts);
|
1123
1319
|
}
|
1124
|
-
copts.mode
|
1320
|
+
copts.mode = CompatMode;
|
1125
1321
|
copts.to_json = Yes;
|
1126
|
-
out.buf
|
1127
|
-
out.end
|
1322
|
+
out.buf = buf;
|
1323
|
+
out.end = buf + sizeof(buf) - 10;
|
1128
1324
|
out.allocated = false;
|
1129
|
-
out.omit_nil
|
1325
|
+
out.omit_nil = copts.dump_opts.omit_nil;
|
1130
1326
|
// For obj.to_json or generate nan is not allowed but if called from dump
|
1131
1327
|
// it is.
|
1132
1328
|
oj_dump_obj_to_json_using_params(*argv, &copts, &out, argc - 1, argv + 1);
|
1133
1329
|
|
1134
1330
|
if (0 == out.buf) {
|
1135
|
-
|
1331
|
+
rb_raise(rb_eNoMemError, "Not enough memory.");
|
1136
1332
|
}
|
1137
1333
|
rstr = rb_str_new2(out.buf);
|
1138
1334
|
rstr = oj_encode(rstr);
|
1139
1335
|
if (out.allocated) {
|
1140
|
-
|
1336
|
+
xfree(out.buf);
|
1141
1337
|
}
|
1142
1338
|
return rstr;
|
1143
1339
|
}
|
@@ -1152,12 +1348,11 @@ to_json(int argc, VALUE *argv, VALUE self) {
|
|
1152
1348
|
* - *:indent* [_Fixnum_] format expected
|
1153
1349
|
* - *:circular* [_Boolean_] allow circular references, default: false
|
1154
1350
|
*/
|
1155
|
-
static VALUE
|
1156
|
-
|
1157
|
-
struct _options copts = oj_default_options;
|
1351
|
+
static VALUE to_file(int argc, VALUE *argv, VALUE self) {
|
1352
|
+
struct _options copts = oj_default_options;
|
1158
1353
|
|
1159
1354
|
if (3 == argc) {
|
1160
|
-
|
1355
|
+
oj_parse_options(argv[2], &copts);
|
1161
1356
|
}
|
1162
1357
|
Check_Type(*argv, T_STRING);
|
1163
1358
|
oj_write_obj_to_file(argv[1], StringValuePtr(*argv), &copts);
|
@@ -1175,12 +1370,11 @@ to_file(int argc, VALUE *argv, VALUE self) {
|
|
1175
1370
|
* - *:indent* [_Fixnum_] format expected
|
1176
1371
|
* - *:circular* [_Boolean_] allow circular references, default: false
|
1177
1372
|
*/
|
1178
|
-
static VALUE
|
1179
|
-
|
1180
|
-
struct _options copts = oj_default_options;
|
1373
|
+
static VALUE to_stream(int argc, VALUE *argv, VALUE self) {
|
1374
|
+
struct _options copts = oj_default_options;
|
1181
1375
|
|
1182
1376
|
if (3 == argc) {
|
1183
|
-
|
1377
|
+
oj_parse_options(argv[2], &copts);
|
1184
1378
|
}
|
1185
1379
|
oj_write_obj_to_stream(argv[1], *argv, &copts);
|
1186
1380
|
|
@@ -1198,25 +1392,23 @@ to_stream(int argc, VALUE *argv, VALUE self) {
|
|
1198
1392
|
*
|
1199
1393
|
* - *clas* [_Class__|_Module_] Class or Module to be made special
|
1200
1394
|
* - *create_object* [_Object_] object to call the create method on
|
1201
|
-
* - *create_method* [_Symbol_] method on the clas that will create a new instance of the clas when
|
1202
|
-
*
|
1395
|
+
* - *create_method* [_Symbol_] method on the clas that will create a new instance of the clas when
|
1396
|
+
* given all the member values in the order specified.
|
1397
|
+
* - *members* [_Symbol__|_String_] methods used to get the member values from instances of the
|
1398
|
+
* clas.
|
1203
1399
|
*/
|
1204
|
-
static VALUE
|
1205
|
-
register_odd(int argc, VALUE *argv, VALUE self) {
|
1400
|
+
static VALUE register_odd(int argc, VALUE *argv, VALUE self) {
|
1206
1401
|
if (3 > argc) {
|
1207
|
-
|
1402
|
+
rb_raise(rb_eArgError, "incorrect number of arguments.");
|
1208
1403
|
}
|
1209
1404
|
switch (rb_type(*argv)) {
|
1210
1405
|
case T_CLASS:
|
1211
|
-
case T_MODULE:
|
1212
|
-
|
1213
|
-
default:
|
1214
|
-
rb_raise(rb_eTypeError, "expected a class or module.");
|
1215
|
-
break;
|
1406
|
+
case T_MODULE: break;
|
1407
|
+
default: rb_raise(rb_eTypeError, "expected a class or module."); break;
|
1216
1408
|
}
|
1217
1409
|
Check_Type(argv[2], T_SYMBOL);
|
1218
1410
|
if (MAX_ODD_ARGS < argc - 2) {
|
1219
|
-
|
1411
|
+
rb_raise(rb_eArgError, "too many members.");
|
1220
1412
|
}
|
1221
1413
|
oj_reg_odd(argv[0], argv[1], argv[2], argc - 3, argv + 3, false);
|
1222
1414
|
|
@@ -1236,25 +1428,23 @@ register_odd(int argc, VALUE *argv, VALUE self) {
|
|
1236
1428
|
*
|
1237
1429
|
* - *clas* [_Class_|_Module_] Class or Module to be made special
|
1238
1430
|
* - *create_object* [_Object_] object to call the create method on
|
1239
|
-
* - *create_method* [_Symbol_] method on the clas that will create a new instance of the clas when
|
1240
|
-
*
|
1431
|
+
* - *create_method* [_Symbol_] method on the clas that will create a new instance of the clas when
|
1432
|
+
*given all the member values in the order specified.
|
1433
|
+
* - *dump_method* [_Symbol_|_String_] method to call on the object being serialized to generate the
|
1434
|
+
*raw JSON.
|
1241
1435
|
*/
|
1242
|
-
static VALUE
|
1243
|
-
register_odd_raw(int argc, VALUE *argv, VALUE self) {
|
1436
|
+
static VALUE register_odd_raw(int argc, VALUE *argv, VALUE self) {
|
1244
1437
|
if (3 > argc) {
|
1245
|
-
|
1438
|
+
rb_raise(rb_eArgError, "incorrect number of arguments.");
|
1246
1439
|
}
|
1247
1440
|
switch (rb_type(*argv)) {
|
1248
1441
|
case T_CLASS:
|
1249
|
-
case T_MODULE:
|
1250
|
-
|
1251
|
-
default:
|
1252
|
-
rb_raise(rb_eTypeError, "expected a class or module.");
|
1253
|
-
break;
|
1442
|
+
case T_MODULE: break;
|
1443
|
+
default: rb_raise(rb_eTypeError, "expected a class or module."); break;
|
1254
1444
|
}
|
1255
1445
|
Check_Type(argv[2], T_SYMBOL);
|
1256
1446
|
if (MAX_ODD_ARGS < argc - 2) {
|
1257
|
-
|
1447
|
+
rb_raise(rb_eArgError, "too many members.");
|
1258
1448
|
}
|
1259
1449
|
oj_reg_odd(argv[0], argv[1], argv[2], 1, argv + 3, true);
|
1260
1450
|
|
@@ -1300,7 +1490,7 @@ register_odd_raw(int argc, VALUE *argv, VALUE self) {
|
|
1300
1490
|
*
|
1301
1491
|
* Returns [_Hash_|_Array_|_String_|_Fixnum_|_Float_|_Boolean_|_nil_]
|
1302
1492
|
*/
|
1303
|
-
extern VALUE
|
1493
|
+
extern VALUE oj_strict_parse(int argc, VALUE *argv, VALUE self);
|
1304
1494
|
|
1305
1495
|
/* Document-method: compat_load
|
1306
1496
|
* call-seq: compat_load(json, options) { _|_obj, start, len_|_ }
|
@@ -1334,7 +1524,7 @@ extern VALUE oj_strict_parse(int argc, VALUE *argv, VALUE self);
|
|
1334
1524
|
*
|
1335
1525
|
* Returns [_Hash_|_Array_|_String_|_Fixnum_|_Float_|_Boolean_|_nil_]
|
1336
1526
|
*/
|
1337
|
-
extern VALUE
|
1527
|
+
extern VALUE oj_compat_parse(int argc, VALUE *argv, VALUE self);
|
1338
1528
|
|
1339
1529
|
/* Document-method: object_load
|
1340
1530
|
* call-seq: object_load(json, options) { _|_obj, start, len_|_ }
|
@@ -1364,7 +1554,7 @@ extern VALUE oj_compat_parse(int argc, VALUE *argv, VALUE self);
|
|
1364
1554
|
*
|
1365
1555
|
* Returns [_Hash_|_Array_|_String_|_Fixnum_|_Float_|_Boolean_|_nil_]
|
1366
1556
|
*/
|
1367
|
-
extern VALUE
|
1557
|
+
extern VALUE oj_object_parse(int argc, VALUE *argv, VALUE self);
|
1368
1558
|
|
1369
1559
|
/* Document-method: wab_load
|
1370
1560
|
* call-seq: wab_load(json, options) { _|_obj, start, len_|_ }
|
@@ -1399,7 +1589,7 @@ extern VALUE oj_object_parse(int argc, VALUE *argv, VALUE self);
|
|
1399
1589
|
*
|
1400
1590
|
* Returns [_Hash_|_Array_|_String_|_Fixnum_|_Float_|_Boolean_|_nil_]
|
1401
1591
|
*/
|
1402
|
-
extern VALUE
|
1592
|
+
extern VALUE oj_wab_parse(int argc, VALUE *argv, VALUE self);
|
1403
1593
|
|
1404
1594
|
/* Document-method: add_to_json
|
1405
1595
|
* call-seq: add_to_json(*args)
|
@@ -1416,7 +1606,7 @@ extern VALUE oj_wab_parse(int argc, VALUE *argv, VALUE self);
|
|
1416
1606
|
*
|
1417
1607
|
* - *args( [_Class_] zero or more classes to optimize.
|
1418
1608
|
*/
|
1419
|
-
extern VALUE
|
1609
|
+
extern VALUE oj_add_to_json(int argc, VALUE *argv, VALUE self);
|
1420
1610
|
|
1421
1611
|
/* @!method remove_to_json(*args)
|
1422
1612
|
*
|
@@ -1432,7 +1622,7 @@ extern VALUE oj_add_to_json(int argc, VALUE *argv, VALUE self);
|
|
1432
1622
|
*
|
1433
1623
|
* - *args* [_Class_] zero or more classes to optimize.
|
1434
1624
|
*/
|
1435
|
-
extern VALUE
|
1625
|
+
extern VALUE oj_remove_to_json(int argc, VALUE *argv, VALUE self);
|
1436
1626
|
|
1437
1627
|
/* Document-method: mimic_JSON
|
1438
1628
|
* call-seq: mimic_JSON()
|
@@ -1450,14 +1640,15 @@ extern VALUE oj_remove_to_json(int argc, VALUE *argv, VALUE self);
|
|
1450
1640
|
*
|
1451
1641
|
* Returns [_Module_] the JSON module.
|
1452
1642
|
*/
|
1453
|
-
extern VALUE
|
1643
|
+
extern VALUE oj_define_mimic_json(int argc, VALUE *argv, VALUE self);
|
1454
1644
|
|
1455
1645
|
/* Document-method: generate
|
1456
1646
|
* call-seq: generate(obj, opts=nil)
|
1457
1647
|
*
|
1458
1648
|
* Encode obj as a JSON String. The obj argument must be a Hash, Array, or
|
1459
1649
|
* respond to to_h or to_json. Options other than those listed such as
|
1460
|
-
* +:allow_nan+ or +:max_nesting+ are ignored.
|
1650
|
+
* +:allow_nan+ or +:max_nesting+ are ignored. Calling this method will call
|
1651
|
+
* Oj.mimic_JSON if it is not already called.
|
1461
1652
|
*
|
1462
1653
|
* - *obj* [_Object__|_Hash_|_Array_] object to convert to a JSON String
|
1463
1654
|
* - *opts* [_Hash_] options
|
@@ -1466,18 +1657,19 @@ extern VALUE oj_define_mimic_json(int argc, VALUE *argv, VALUE self);
|
|
1466
1657
|
* - *:space_before* [_String_] String placed before a : delimiter
|
1467
1658
|
* - *:object_nl* [_String_] String placed after a JSON object
|
1468
1659
|
* - *:array_nl* [_String_] String placed after a JSON array
|
1469
|
-
* - *:ascii_only* [_Boolean_] if not nil or false then use only ascii characters in the output.
|
1660
|
+
* - *:ascii_only* [_Boolean_] if not nil or false then use only ascii characters in the output.
|
1661
|
+
* Note JSON.generate does support this even if it is not documented.
|
1470
1662
|
*
|
1471
1663
|
* Returns [_String_]generated JSON.
|
1472
1664
|
*/
|
1473
|
-
extern VALUE
|
1665
|
+
extern VALUE oj_mimic_generate(int argc, VALUE *argv, VALUE self);
|
1474
1666
|
|
1475
1667
|
/* Document-module: Oj.optimize_rails()
|
1476
1668
|
*
|
1477
1669
|
* Sets the Oj as the Rails encoder and decoder. Oj::Rails.optimize is also
|
1478
1670
|
* called.
|
1479
1671
|
*/
|
1480
|
-
extern VALUE
|
1672
|
+
extern VALUE oj_optimize_rails(VALUE self);
|
1481
1673
|
|
1482
1674
|
/*
|
1483
1675
|
extern void oj_hash_test();
|
@@ -1489,8 +1681,7 @@ hash_test(VALUE self) {
|
|
1489
1681
|
}
|
1490
1682
|
*/
|
1491
1683
|
|
1492
|
-
static VALUE
|
1493
|
-
protect_require(VALUE x) {
|
1684
|
+
static VALUE protect_require(VALUE x) {
|
1494
1685
|
rb_require("time");
|
1495
1686
|
rb_require("bigdecimal");
|
1496
1687
|
return Qnil;
|
@@ -1524,9 +1715,8 @@ protect_require(VALUE x) {
|
|
1524
1715
|
*
|
1525
1716
|
* - *:wab* specifically for WAB data exchange.
|
1526
1717
|
*/
|
1527
|
-
void
|
1528
|
-
|
1529
|
-
int err = 0;
|
1718
|
+
void Init_oj() {
|
1719
|
+
int err = 0;
|
1530
1720
|
|
1531
1721
|
Oj = rb_define_module("Oj");
|
1532
1722
|
|
@@ -1541,7 +1731,7 @@ Init_oj() {
|
|
1541
1731
|
rb_require("stringio");
|
1542
1732
|
oj_utf8_encoding = rb_enc_find("UTF-8");
|
1543
1733
|
|
1544
|
-
//rb_define_module_function(Oj, "hash_test", hash_test, 0);
|
1734
|
+
// rb_define_module_function(Oj, "hash_test", hash_test, 0);
|
1545
1735
|
|
1546
1736
|
rb_define_module_function(Oj, "default_options", get_def_opts, 0);
|
1547
1737
|
rb_define_module_function(Oj, "default_options=", set_def_opts, 1);
|
@@ -1575,50 +1765,50 @@ Init_oj() {
|
|
1575
1765
|
|
1576
1766
|
rb_define_module_function(Oj, "optimize_rails", oj_optimize_rails, 0);
|
1577
1767
|
|
1578
|
-
oj_add_value_id
|
1579
|
-
oj_array_append_id
|
1580
|
-
oj_array_end_id
|
1581
|
-
oj_array_start_id
|
1582
|
-
oj_as_json_id
|
1583
|
-
oj_begin_id
|
1584
|
-
oj_bigdecimal_id
|
1585
|
-
oj_end_id
|
1586
|
-
oj_error_id
|
1587
|
-
oj_exclude_end_id
|
1588
|
-
oj_file_id
|
1589
|
-
oj_fileno_id
|
1590
|
-
oj_ftype_id
|
1591
|
-
oj_has_key_id
|
1592
|
-
oj_hash_end_id
|
1593
|
-
oj_hash_key_id
|
1594
|
-
oj_hash_set_id
|
1595
|
-
oj_hash_start_id
|
1596
|
-
oj_iconv_id
|
1768
|
+
oj_add_value_id = rb_intern("add_value");
|
1769
|
+
oj_array_append_id = rb_intern("array_append");
|
1770
|
+
oj_array_end_id = rb_intern("array_end");
|
1771
|
+
oj_array_start_id = rb_intern("array_start");
|
1772
|
+
oj_as_json_id = rb_intern("as_json");
|
1773
|
+
oj_begin_id = rb_intern("begin");
|
1774
|
+
oj_bigdecimal_id = rb_intern("BigDecimal");
|
1775
|
+
oj_end_id = rb_intern("end");
|
1776
|
+
oj_error_id = rb_intern("error");
|
1777
|
+
oj_exclude_end_id = rb_intern("exclude_end?");
|
1778
|
+
oj_file_id = rb_intern("file?");
|
1779
|
+
oj_fileno_id = rb_intern("fileno");
|
1780
|
+
oj_ftype_id = rb_intern("ftype");
|
1781
|
+
oj_has_key_id = rb_intern("has_key?");
|
1782
|
+
oj_hash_end_id = rb_intern("hash_end");
|
1783
|
+
oj_hash_key_id = rb_intern("hash_key");
|
1784
|
+
oj_hash_set_id = rb_intern("hash_set");
|
1785
|
+
oj_hash_start_id = rb_intern("hash_start");
|
1786
|
+
oj_iconv_id = rb_intern("iconv");
|
1597
1787
|
oj_instance_variables_id = rb_intern("instance_variables");
|
1598
|
-
oj_json_create_id
|
1599
|
-
oj_length_id
|
1600
|
-
oj_new_id
|
1601
|
-
oj_parse_id
|
1602
|
-
oj_pos_id
|
1603
|
-
oj_raw_json_id
|
1604
|
-
oj_read_id
|
1605
|
-
oj_readpartial_id
|
1606
|
-
oj_replace_id
|
1607
|
-
oj_stat_id
|
1608
|
-
oj_string_id
|
1609
|
-
oj_to_h_id
|
1610
|
-
oj_to_hash_id
|
1611
|
-
oj_to_json_id
|
1612
|
-
oj_to_s_id
|
1613
|
-
oj_to_sym_id
|
1614
|
-
oj_to_time_id
|
1615
|
-
oj_tv_nsec_id
|
1616
|
-
oj_tv_sec_id
|
1617
|
-
oj_tv_usec_id
|
1618
|
-
oj_utc_id
|
1619
|
-
oj_utc_offset_id
|
1620
|
-
oj_utcq_id
|
1621
|
-
oj_write_id
|
1788
|
+
oj_json_create_id = rb_intern("json_create");
|
1789
|
+
oj_length_id = rb_intern("length");
|
1790
|
+
oj_new_id = rb_intern("new");
|
1791
|
+
oj_parse_id = rb_intern("parse");
|
1792
|
+
oj_pos_id = rb_intern("pos");
|
1793
|
+
oj_raw_json_id = rb_intern("raw_json");
|
1794
|
+
oj_read_id = rb_intern("read");
|
1795
|
+
oj_readpartial_id = rb_intern("readpartial");
|
1796
|
+
oj_replace_id = rb_intern("replace");
|
1797
|
+
oj_stat_id = rb_intern("stat");
|
1798
|
+
oj_string_id = rb_intern("string");
|
1799
|
+
oj_to_h_id = rb_intern("to_h");
|
1800
|
+
oj_to_hash_id = rb_intern("to_hash");
|
1801
|
+
oj_to_json_id = rb_intern("to_json");
|
1802
|
+
oj_to_s_id = rb_intern("to_s");
|
1803
|
+
oj_to_sym_id = rb_intern("to_sym");
|
1804
|
+
oj_to_time_id = rb_intern("to_time");
|
1805
|
+
oj_tv_nsec_id = rb_intern("tv_nsec");
|
1806
|
+
oj_tv_sec_id = rb_intern("tv_sec");
|
1807
|
+
oj_tv_usec_id = rb_intern("tv_usec");
|
1808
|
+
oj_utc_id = rb_intern("utc");
|
1809
|
+
oj_utc_offset_id = rb_intern("utc_offset");
|
1810
|
+
oj_utcq_id = rb_intern("utc?");
|
1811
|
+
oj_write_id = rb_intern("write");
|
1622
1812
|
|
1623
1813
|
rb_require("oj/bag");
|
1624
1814
|
rb_require("oj/error");
|
@@ -1627,82 +1817,165 @@ Init_oj() {
|
|
1627
1817
|
rb_require("oj/schandler");
|
1628
1818
|
|
1629
1819
|
oj_bag_class = rb_const_get_at(Oj, rb_intern("Bag"));
|
1820
|
+
rb_gc_register_mark_object(oj_bag_class);
|
1630
1821
|
oj_bigdecimal_class = rb_const_get(rb_cObject, rb_intern("BigDecimal"));
|
1822
|
+
rb_gc_register_mark_object(oj_bigdecimal_class);
|
1631
1823
|
oj_date_class = rb_const_get(rb_cObject, rb_intern("Date"));
|
1824
|
+
rb_gc_register_mark_object(oj_date_class);
|
1632
1825
|
oj_datetime_class = rb_const_get(rb_cObject, rb_intern("DateTime"));
|
1826
|
+
rb_gc_register_mark_object(oj_datetime_class);
|
1633
1827
|
oj_enumerable_class = rb_const_get(rb_cObject, rb_intern("Enumerable"));
|
1828
|
+
rb_gc_register_mark_object(oj_enumerable_class);
|
1634
1829
|
oj_parse_error_class = rb_const_get_at(Oj, rb_intern("ParseError"));
|
1830
|
+
rb_gc_register_mark_object(oj_parse_error_class);
|
1635
1831
|
oj_stringio_class = rb_const_get(rb_cObject, rb_intern("StringIO"));
|
1832
|
+
rb_gc_register_mark_object(oj_stringio_class);
|
1636
1833
|
oj_struct_class = rb_const_get(rb_cObject, rb_intern("Struct"));
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1834
|
+
rb_gc_register_mark_object(oj_struct_class);
|
1835
|
+
oj_json_parser_error_class = rb_eEncodingError; // replaced if mimic is called
|
1836
|
+
oj_json_generator_error_class = rb_eEncodingError; // replaced if mimic is called
|
1837
|
+
|
1838
|
+
allow_blank_sym = ID2SYM(rb_intern("allow_blank"));
|
1839
|
+
rb_gc_register_address(&allow_blank_sym);
|
1840
|
+
allow_gc_sym = ID2SYM(rb_intern("allow_gc"));
|
1841
|
+
rb_gc_register_address(&allow_gc_sym);
|
1842
|
+
allow_invalid_unicode_sym = ID2SYM(rb_intern("allow_invalid_unicode"));
|
1843
|
+
rb_gc_register_address(&allow_invalid_unicode_sym);
|
1844
|
+
ascii_sym = ID2SYM(rb_intern("ascii"));
|
1845
|
+
rb_gc_register_address(&ascii_sym);
|
1846
|
+
auto_define_sym = ID2SYM(rb_intern("auto_define"));
|
1847
|
+
rb_gc_register_address(&auto_define_sym);
|
1848
|
+
auto_sym = ID2SYM(rb_intern("auto"));
|
1849
|
+
rb_gc_register_address(&auto_sym);
|
1850
|
+
bigdecimal_as_decimal_sym = ID2SYM(rb_intern("bigdecimal_as_decimal"));
|
1851
|
+
rb_gc_register_address(&bigdecimal_as_decimal_sym);
|
1852
|
+
bigdecimal_load_sym = ID2SYM(rb_intern("bigdecimal_load"));
|
1853
|
+
rb_gc_register_address(&bigdecimal_load_sym);
|
1854
|
+
bigdecimal_sym = ID2SYM(rb_intern("bigdecimal"));
|
1855
|
+
rb_gc_register_address(&bigdecimal_sym);
|
1856
|
+
cache_keys_sym = ID2SYM(rb_intern("cache_keys"));
|
1857
|
+
rb_gc_register_address(&cache_keys_sym);
|
1858
|
+
cache_str_sym = ID2SYM(rb_intern("cache_str"));
|
1859
|
+
rb_gc_register_address(&cache_str_sym);
|
1860
|
+
circular_sym = ID2SYM(rb_intern("circular"));
|
1861
|
+
rb_gc_register_address(&circular_sym);
|
1862
|
+
class_cache_sym = ID2SYM(rb_intern("class_cache"));
|
1863
|
+
rb_gc_register_address(&class_cache_sym);
|
1864
|
+
compat_bigdecimal_sym = ID2SYM(rb_intern("compat_bigdecimal"));
|
1865
|
+
rb_gc_register_address(&compat_bigdecimal_sym);
|
1866
|
+
compat_sym = ID2SYM(rb_intern("compat"));
|
1867
|
+
rb_gc_register_address(&compat_sym);
|
1868
|
+
create_id_sym = ID2SYM(rb_intern("create_id"));
|
1869
|
+
rb_gc_register_address(&create_id_sym);
|
1870
|
+
custom_sym = ID2SYM(rb_intern("custom"));
|
1871
|
+
rb_gc_register_address(&custom_sym);
|
1872
|
+
empty_string_sym = ID2SYM(rb_intern("empty_string"));
|
1873
|
+
rb_gc_register_address(&empty_string_sym);
|
1874
|
+
escape_mode_sym = ID2SYM(rb_intern("escape_mode"));
|
1875
|
+
rb_gc_register_address(&escape_mode_sym);
|
1876
|
+
integer_range_sym = ID2SYM(rb_intern("integer_range"));
|
1877
|
+
rb_gc_register_address(&integer_range_sym);
|
1878
|
+
fast_sym = ID2SYM(rb_intern("fast"));
|
1879
|
+
rb_gc_register_address(&fast_sym);
|
1880
|
+
float_prec_sym = ID2SYM(rb_intern("float_precision"));
|
1881
|
+
rb_gc_register_address(&float_prec_sym);
|
1882
|
+
float_sym = ID2SYM(rb_intern("float"));
|
1883
|
+
rb_gc_register_address(&float_sym);
|
1884
|
+
huge_sym = ID2SYM(rb_intern("huge"));
|
1885
|
+
rb_gc_register_address(&huge_sym);
|
1886
|
+
ignore_sym = ID2SYM(rb_intern("ignore"));
|
1887
|
+
rb_gc_register_address(&ignore_sym);
|
1888
|
+
ignore_under_sym = ID2SYM(rb_intern("ignore_under"));
|
1889
|
+
rb_gc_register_address(&ignore_under_sym);
|
1890
|
+
json_sym = ID2SYM(rb_intern("json"));
|
1891
|
+
rb_gc_register_address(&json_sym);
|
1892
|
+
match_string_sym = ID2SYM(rb_intern("match_string"));
|
1893
|
+
rb_gc_register_address(&match_string_sym);
|
1894
|
+
mode_sym = ID2SYM(rb_intern("mode"));
|
1895
|
+
rb_gc_register_address(&mode_sym);
|
1896
|
+
nan_sym = ID2SYM(rb_intern("nan"));
|
1897
|
+
rb_gc_register_address(&nan_sym);
|
1898
|
+
newline_sym = ID2SYM(rb_intern("newline"));
|
1899
|
+
rb_gc_register_address(&newline_sym);
|
1900
|
+
nilnil_sym = ID2SYM(rb_intern("nilnil"));
|
1901
|
+
rb_gc_register_address(&nilnil_sym);
|
1902
|
+
null_sym = ID2SYM(rb_intern("null"));
|
1903
|
+
rb_gc_register_address(&null_sym);
|
1904
|
+
object_sym = ID2SYM(rb_intern("object"));
|
1905
|
+
rb_gc_register_address(&object_sym);
|
1906
|
+
oj_allow_nan_sym = ID2SYM(rb_intern("allow_nan"));
|
1907
|
+
rb_gc_register_address(&oj_allow_nan_sym);
|
1908
|
+
oj_array_class_sym = ID2SYM(rb_intern("array_class"));
|
1909
|
+
rb_gc_register_address(&oj_array_class_sym);
|
1910
|
+
oj_array_nl_sym = ID2SYM(rb_intern("array_nl"));
|
1911
|
+
rb_gc_register_address(&oj_array_nl_sym);
|
1912
|
+
oj_ascii_only_sym = ID2SYM(rb_intern("ascii_only"));
|
1913
|
+
rb_gc_register_address(&oj_ascii_only_sym);
|
1914
|
+
oj_create_additions_sym = ID2SYM(rb_intern("create_additions"));
|
1915
|
+
rb_gc_register_address(&oj_create_additions_sym);
|
1916
|
+
oj_decimal_class_sym = ID2SYM(rb_intern("decimal_class"));
|
1917
|
+
rb_gc_register_address(&oj_decimal_class_sym);
|
1918
|
+
oj_hash_class_sym = ID2SYM(rb_intern("hash_class"));
|
1919
|
+
rb_gc_register_address(&oj_hash_class_sym);
|
1920
|
+
oj_indent_sym = ID2SYM(rb_intern("indent"));
|
1921
|
+
rb_gc_register_address(&oj_indent_sym);
|
1922
|
+
oj_max_nesting_sym = ID2SYM(rb_intern("max_nesting"));
|
1923
|
+
rb_gc_register_address(&oj_max_nesting_sym);
|
1924
|
+
oj_object_class_sym = ID2SYM(rb_intern("object_class"));
|
1925
|
+
rb_gc_register_address(&oj_object_class_sym);
|
1926
|
+
oj_object_nl_sym = ID2SYM(rb_intern("object_nl"));
|
1927
|
+
rb_gc_register_address(&oj_object_nl_sym);
|
1928
|
+
oj_quirks_mode_sym = ID2SYM(rb_intern("quirks_mode"));
|
1929
|
+
rb_gc_register_address(&oj_quirks_mode_sym);
|
1930
|
+
oj_safe_sym = ID2SYM(rb_intern("safe"));
|
1931
|
+
rb_gc_register_address(&oj_safe_sym);
|
1932
|
+
oj_space_before_sym = ID2SYM(rb_intern("space_before"));
|
1933
|
+
rb_gc_register_address(&oj_space_before_sym);
|
1934
|
+
oj_space_sym = ID2SYM(rb_intern("space"));
|
1935
|
+
rb_gc_register_address(&oj_space_sym);
|
1936
|
+
oj_trace_sym = ID2SYM(rb_intern("trace"));
|
1937
|
+
rb_gc_register_address(&oj_trace_sym);
|
1938
|
+
omit_nil_sym = ID2SYM(rb_intern("omit_nil"));
|
1939
|
+
rb_gc_register_address(&omit_nil_sym);
|
1940
|
+
rails_sym = ID2SYM(rb_intern("rails"));
|
1941
|
+
rb_gc_register_address(&rails_sym);
|
1942
|
+
raise_sym = ID2SYM(rb_intern("raise"));
|
1943
|
+
rb_gc_register_address(&raise_sym);
|
1944
|
+
ruby_sym = ID2SYM(rb_intern("ruby"));
|
1945
|
+
rb_gc_register_address(&ruby_sym);
|
1946
|
+
sec_prec_sym = ID2SYM(rb_intern("second_precision"));
|
1947
|
+
rb_gc_register_address(&sec_prec_sym);
|
1948
|
+
strict_sym = ID2SYM(rb_intern("strict"));
|
1949
|
+
rb_gc_register_address(&strict_sym);
|
1950
|
+
symbol_keys_sym = ID2SYM(rb_intern("symbol_keys"));
|
1951
|
+
rb_gc_register_address(&symbol_keys_sym);
|
1952
|
+
time_format_sym = ID2SYM(rb_intern("time_format"));
|
1953
|
+
rb_gc_register_address(&time_format_sym);
|
1954
|
+
unicode_xss_sym = ID2SYM(rb_intern("unicode_xss"));
|
1955
|
+
rb_gc_register_address(&unicode_xss_sym);
|
1956
|
+
unix_sym = ID2SYM(rb_intern("unix"));
|
1957
|
+
rb_gc_register_address(&unix_sym);
|
1958
|
+
unix_zone_sym = ID2SYM(rb_intern("unix_zone"));
|
1959
|
+
rb_gc_register_address(&unix_zone_sym);
|
1960
|
+
use_as_json_sym = ID2SYM(rb_intern("use_as_json"));
|
1961
|
+
rb_gc_register_address(&use_as_json_sym);
|
1962
|
+
use_raw_json_sym = ID2SYM(rb_intern("use_raw_json"));
|
1963
|
+
rb_gc_register_address(&use_raw_json_sym);
|
1964
|
+
use_to_hash_sym = ID2SYM(rb_intern("use_to_hash"));
|
1965
|
+
rb_gc_register_address(&use_to_hash_sym);
|
1966
|
+
use_to_json_sym = ID2SYM(rb_intern("use_to_json"));
|
1967
|
+
rb_gc_register_address(&use_to_json_sym);
|
1968
|
+
wab_sym = ID2SYM(rb_intern("wab"));
|
1969
|
+
rb_gc_register_address(&wab_sym);
|
1970
|
+
word_sym = ID2SYM(rb_intern("word"));
|
1971
|
+
rb_gc_register_address(&word_sym);
|
1972
|
+
xmlschema_sym = ID2SYM(rb_intern("xmlschema"));
|
1973
|
+
rb_gc_register_address(&xmlschema_sym);
|
1974
|
+
xss_safe_sym = ID2SYM(rb_intern("xss_safe"));
|
1975
|
+
rb_gc_register_address(&xss_safe_sym);
|
1976
|
+
|
1977
|
+
oj_slash_string = rb_str_new2("/");
|
1978
|
+
rb_gc_register_address(&oj_slash_string);
|
1706
1979
|
OBJ_FREEZE(oj_slash_string);
|
1707
1980
|
|
1708
1981
|
oj_default_options.mode = ObjectMode;
|
@@ -1713,7 +1986,7 @@ Init_oj() {
|
|
1713
1986
|
|
1714
1987
|
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
1715
1988
|
if (0 != (err = pthread_mutex_init(&oj_cache_mutex, 0))) {
|
1716
|
-
|
1989
|
+
rb_raise(rb_eException, "failed to initialize a mutex. %s", strerror(err));
|
1717
1990
|
}
|
1718
1991
|
#else
|
1719
1992
|
oj_cache_mutex = rb_mutex_new();
|