oj 3.11.1 → 3.11.6
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 +34 -38
- data/ext/oj/cache8.c +59 -62
- data/ext/oj/cache8.h +8 -7
- data/ext/oj/circarray.c +33 -35
- data/ext/oj/circarray.h +11 -9
- data/ext/oj/code.c +170 -174
- data/ext/oj/code.h +21 -20
- data/ext/oj/compat.c +159 -166
- data/ext/oj/custom.c +802 -851
- data/ext/oj/dump.c +766 -778
- data/ext/oj/dump.h +49 -51
- data/ext/oj/dump_compat.c +1 -0
- data/ext/oj/dump_leaf.c +116 -157
- data/ext/oj/dump_object.c +609 -628
- data/ext/oj/dump_strict.c +318 -327
- data/ext/oj/encode.h +3 -4
- data/ext/oj/err.c +39 -25
- data/ext/oj/err.h +24 -15
- data/ext/oj/extconf.rb +2 -1
- data/ext/oj/fast.c +1042 -1041
- data/ext/oj/hash.c +62 -66
- data/ext/oj/hash.h +7 -6
- data/ext/oj/hash_test.c +450 -443
- data/ext/oj/mimic_json.c +412 -402
- data/ext/oj/object.c +559 -528
- data/ext/oj/odd.c +123 -128
- data/ext/oj/odd.h +27 -25
- data/ext/oj/oj.c +1123 -924
- data/ext/oj/oj.h +286 -298
- data/ext/oj/parse.c +938 -930
- data/ext/oj/parse.h +70 -69
- data/ext/oj/rails.c +836 -839
- data/ext/oj/rails.h +7 -7
- data/ext/oj/reader.c +135 -140
- data/ext/oj/reader.h +66 -79
- data/ext/oj/resolve.c +43 -43
- data/ext/oj/resolve.h +3 -2
- data/ext/oj/rxclass.c +67 -68
- data/ext/oj/rxclass.h +12 -10
- data/ext/oj/saj.c +451 -479
- data/ext/oj/scp.c +93 -103
- data/ext/oj/sparse.c +770 -730
- data/ext/oj/stream_writer.c +120 -149
- data/ext/oj/strict.c +71 -86
- data/ext/oj/string_writer.c +198 -243
- data/ext/oj/trace.c +29 -33
- data/ext/oj/trace.h +14 -11
- data/ext/oj/util.c +103 -103
- data/ext/oj/util.h +3 -2
- data/ext/oj/val_stack.c +47 -47
- data/ext/oj/val_stack.h +79 -86
- data/ext/oj/wab.c +291 -309
- data/lib/oj/bag.rb +1 -0
- data/lib/oj/easy_hash.rb +5 -4
- data/lib/oj/mimic.rb +0 -12
- data/lib/oj/version.rb +1 -1
- data/test/activerecord/result_test.rb +7 -2
- data/test/foo.rb +35 -32
- data/test/test_fast.rb +32 -2
- data/test/test_generate.rb +21 -0
- data/test/test_hash.rb +10 -0
- data/test/test_scp.rb +1 -1
- metadata +4 -2
data/ext/oj/dump_strict.c
CHANGED
@@ -1,431 +1,422 @@
|
|
1
1
|
// Copyright (c) 2012, 2017 Peter Ohler. All rights reserved.
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
2
3
|
|
3
|
-
#include <
|
4
|
-
#include <
|
4
|
+
#include <errno.h>
|
5
|
+
#include <math.h>
|
5
6
|
#include <stdio.h>
|
7
|
+
#include <stdlib.h>
|
6
8
|
#include <string.h>
|
7
|
-
#include <
|
9
|
+
#include <time.h>
|
8
10
|
#include <unistd.h>
|
9
|
-
#include <errno.h>
|
10
11
|
|
11
12
|
#include "dump.h"
|
12
13
|
#include "trace.h"
|
13
14
|
|
14
15
|
// Workaround in case INFINITY is not defined in math.h or if the OS is CentOS
|
15
|
-
#define OJ_INFINITY (1.0/0.0)
|
16
|
+
#define OJ_INFINITY (1.0 / 0.0)
|
16
17
|
|
17
|
-
typedef unsigned long
|
18
|
+
typedef unsigned long ulong;
|
18
19
|
|
19
|
-
static const char
|
20
|
-
static const char
|
21
|
-
static const char
|
20
|
+
static const char inf_val[] = INF_VAL;
|
21
|
+
static const char ninf_val[] = NINF_VAL;
|
22
|
+
static const char nan_val[] = NAN_VAL;
|
22
23
|
|
23
|
-
static void
|
24
|
-
|
25
|
-
|
24
|
+
static void raise_strict(VALUE obj) {
|
25
|
+
rb_raise(rb_eTypeError,
|
26
|
+
"Failed to dump %s Object to JSON in strict mode.\n",
|
27
|
+
rb_class2name(rb_obj_class(obj)));
|
26
28
|
}
|
27
29
|
|
28
30
|
// Removed dependencies on math due to problems with CentOS 5.4.
|
29
|
-
static void
|
30
|
-
|
31
|
-
char
|
32
|
-
|
33
|
-
|
34
|
-
int cnt = 0;
|
31
|
+
static void dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
32
|
+
char buf[64];
|
33
|
+
char * b;
|
34
|
+
double d = rb_num2dbl(obj);
|
35
|
+
int cnt = 0;
|
35
36
|
|
36
37
|
if (0.0 == d) {
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
b = buf;
|
39
|
+
*b++ = '0';
|
40
|
+
*b++ = '.';
|
41
|
+
*b++ = '0';
|
42
|
+
*b++ = '\0';
|
43
|
+
cnt = 3;
|
43
44
|
} else {
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
}
|
106
|
-
strncpy(buf, rb_string_value_ptr((VALUE*)&rstr), cnt);
|
107
|
-
buf[cnt] = '\0';
|
108
|
-
} else {
|
109
|
-
cnt = oj_dump_float_printf(buf, sizeof(buf), obj, d, out->opts->float_fmt);
|
110
|
-
}
|
45
|
+
NanDump nd = out->opts->dump_opts.nan_dump;
|
46
|
+
|
47
|
+
if (AutoNan == nd) {
|
48
|
+
nd = RaiseNan;
|
49
|
+
}
|
50
|
+
if (OJ_INFINITY == d) {
|
51
|
+
switch (nd) {
|
52
|
+
case RaiseNan:
|
53
|
+
case WordNan: raise_strict(obj); break;
|
54
|
+
case NullNan:
|
55
|
+
strcpy(buf, "null");
|
56
|
+
cnt = 4;
|
57
|
+
break;
|
58
|
+
case HugeNan:
|
59
|
+
default:
|
60
|
+
strcpy(buf, inf_val);
|
61
|
+
cnt = sizeof(inf_val) - 1;
|
62
|
+
break;
|
63
|
+
}
|
64
|
+
} else if (-OJ_INFINITY == d) {
|
65
|
+
switch (nd) {
|
66
|
+
case RaiseNan:
|
67
|
+
case WordNan: raise_strict(obj); break;
|
68
|
+
case NullNan:
|
69
|
+
strcpy(buf, "null");
|
70
|
+
cnt = 4;
|
71
|
+
break;
|
72
|
+
case HugeNan:
|
73
|
+
default:
|
74
|
+
strcpy(buf, ninf_val);
|
75
|
+
cnt = sizeof(ninf_val) - 1;
|
76
|
+
break;
|
77
|
+
}
|
78
|
+
} else if (isnan(d)) {
|
79
|
+
switch (nd) {
|
80
|
+
case RaiseNan:
|
81
|
+
case WordNan: raise_strict(obj); break;
|
82
|
+
case NullNan:
|
83
|
+
strcpy(buf, "null");
|
84
|
+
cnt = 4;
|
85
|
+
break;
|
86
|
+
case HugeNan:
|
87
|
+
default:
|
88
|
+
strcpy(buf, nan_val);
|
89
|
+
cnt = sizeof(nan_val) - 1;
|
90
|
+
break;
|
91
|
+
}
|
92
|
+
} else if (d == (double)(long long int)d) {
|
93
|
+
cnt = snprintf(buf, sizeof(buf), "%.1f", d);
|
94
|
+
} else if (0 == out->opts->float_prec) {
|
95
|
+
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
96
|
+
|
97
|
+
cnt = (int)RSTRING_LEN(rstr);
|
98
|
+
if ((int)sizeof(buf) <= cnt) {
|
99
|
+
cnt = sizeof(buf) - 1;
|
100
|
+
}
|
101
|
+
strncpy(buf, rb_string_value_ptr((VALUE *)&rstr), cnt);
|
102
|
+
buf[cnt] = '\0';
|
103
|
+
} else {
|
104
|
+
cnt = oj_dump_float_printf(buf, sizeof(buf), obj, d, out->opts->float_fmt);
|
105
|
+
}
|
111
106
|
}
|
112
107
|
assure_size(out, cnt);
|
113
108
|
for (b = buf; '\0' != *b; b++) {
|
114
|
-
|
109
|
+
*out->cur++ = *b;
|
115
110
|
}
|
116
111
|
*out->cur = '\0';
|
117
112
|
}
|
118
113
|
|
119
|
-
static void
|
120
|
-
|
121
|
-
|
122
|
-
int
|
123
|
-
int d2 = depth + 1;
|
114
|
+
static void dump_array(VALUE a, int depth, Out out, bool as_ok) {
|
115
|
+
size_t size;
|
116
|
+
int i, cnt;
|
117
|
+
int d2 = depth + 1;
|
124
118
|
|
125
119
|
if (Yes == out->opts->circular) {
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
120
|
+
if (0 > oj_check_circular(a, out)) {
|
121
|
+
oj_dump_nil(Qnil, 0, out, false);
|
122
|
+
return;
|
123
|
+
}
|
130
124
|
}
|
131
|
-
cnt
|
125
|
+
cnt = (int)RARRAY_LEN(a);
|
132
126
|
*out->cur++ = '[';
|
133
|
-
size
|
127
|
+
size = 2;
|
134
128
|
assure_size(out, size);
|
135
129
|
if (0 == cnt) {
|
136
|
-
|
130
|
+
*out->cur++ = ']';
|
137
131
|
} else {
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
132
|
+
if (out->opts->dump_opts.use) {
|
133
|
+
size = d2 * out->opts->dump_opts.indent_size + out->opts->dump_opts.array_size + 1;
|
134
|
+
} else {
|
135
|
+
size = d2 * out->indent + 2;
|
136
|
+
}
|
137
|
+
cnt--;
|
138
|
+
for (i = 0; i <= cnt; i++) {
|
139
|
+
assure_size(out, size);
|
140
|
+
if (out->opts->dump_opts.use) {
|
141
|
+
if (0 < out->opts->dump_opts.array_size) {
|
142
|
+
strcpy(out->cur, out->opts->dump_opts.array_nl);
|
143
|
+
out->cur += out->opts->dump_opts.array_size;
|
144
|
+
}
|
145
|
+
if (0 < out->opts->dump_opts.indent_size) {
|
146
|
+
int i;
|
147
|
+
for (i = d2; 0 < i; i--) {
|
148
|
+
strcpy(out->cur, out->opts->dump_opts.indent_str);
|
149
|
+
out->cur += out->opts->dump_opts.indent_size;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
} else {
|
153
|
+
fill_indent(out, d2);
|
154
|
+
}
|
155
|
+
if (NullMode == out->opts->mode) {
|
156
|
+
oj_dump_null_val(rb_ary_entry(a, i), d2, out);
|
157
|
+
} else {
|
158
|
+
oj_dump_strict_val(rb_ary_entry(a, i), d2, out);
|
159
|
+
}
|
160
|
+
if (i < cnt) {
|
161
|
+
*out->cur++ = ',';
|
162
|
+
}
|
163
|
+
}
|
164
|
+
size = depth * out->indent + 1;
|
165
|
+
assure_size(out, size);
|
166
|
+
if (out->opts->dump_opts.use) {
|
167
|
+
// printf("*** d2: %u indent: %u '%s'\n", d2, out->opts->dump_opts->indent_size,
|
168
|
+
// out->opts->dump_opts->indent);
|
169
|
+
if (0 < out->opts->dump_opts.array_size) {
|
170
|
+
strcpy(out->cur, out->opts->dump_opts.array_nl);
|
171
|
+
out->cur += out->opts->dump_opts.array_size;
|
172
|
+
}
|
173
|
+
if (0 < out->opts->dump_opts.indent_size) {
|
174
|
+
int i;
|
175
|
+
|
176
|
+
for (i = depth; 0 < i; i--) {
|
177
|
+
strcpy(out->cur, out->opts->dump_opts.indent_str);
|
178
|
+
out->cur += out->opts->dump_opts.indent_size;
|
179
|
+
}
|
180
|
+
}
|
181
|
+
} else {
|
182
|
+
fill_indent(out, depth);
|
183
|
+
}
|
184
|
+
*out->cur++ = ']';
|
190
185
|
}
|
191
186
|
*out->cur = '\0';
|
192
187
|
}
|
193
188
|
|
194
|
-
static int
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
int rtype = rb_type(key);
|
189
|
+
static int hash_cb(VALUE key, VALUE value, VALUE ov) {
|
190
|
+
Out out = (Out)ov;
|
191
|
+
int depth = out->depth;
|
192
|
+
long size;
|
193
|
+
int rtype = rb_type(key);
|
200
194
|
|
201
195
|
if (rtype != T_STRING && rtype != T_SYMBOL) {
|
202
|
-
|
196
|
+
rb_raise(rb_eTypeError,
|
197
|
+
"In :strict and :null mode all Hash keys must be Strings or Symbols, not %s.\n",
|
198
|
+
rb_class2name(rb_obj_class(key)));
|
203
199
|
}
|
204
200
|
if (out->omit_nil && Qnil == value) {
|
205
|
-
|
201
|
+
return ST_CONTINUE;
|
206
202
|
}
|
207
203
|
if (!out->opts->dump_opts.use) {
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
204
|
+
size = depth * out->indent + 1;
|
205
|
+
assure_size(out, size);
|
206
|
+
fill_indent(out, depth);
|
207
|
+
if (rtype == T_STRING) {
|
208
|
+
oj_dump_str(key, 0, out, false);
|
209
|
+
} else {
|
210
|
+
oj_dump_sym(key, 0, out, false);
|
211
|
+
}
|
212
|
+
*out->cur++ = ':';
|
217
213
|
} else {
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
214
|
+
size = depth * out->opts->dump_opts.indent_size + out->opts->dump_opts.hash_size + 1;
|
215
|
+
assure_size(out, size);
|
216
|
+
if (0 < out->opts->dump_opts.hash_size) {
|
217
|
+
strcpy(out->cur, out->opts->dump_opts.hash_nl);
|
218
|
+
out->cur += out->opts->dump_opts.hash_size;
|
219
|
+
}
|
220
|
+
if (0 < out->opts->dump_opts.indent_size) {
|
221
|
+
int i;
|
222
|
+
for (i = depth; 0 < i; i--) {
|
223
|
+
strcpy(out->cur, out->opts->dump_opts.indent_str);
|
224
|
+
out->cur += out->opts->dump_opts.indent_size;
|
225
|
+
}
|
226
|
+
}
|
227
|
+
if (rtype == T_STRING) {
|
228
|
+
oj_dump_str(key, 0, out, false);
|
229
|
+
} else {
|
230
|
+
oj_dump_sym(key, 0, out, false);
|
231
|
+
}
|
232
|
+
size = out->opts->dump_opts.before_size + out->opts->dump_opts.after_size + 2;
|
233
|
+
assure_size(out, size);
|
234
|
+
if (0 < out->opts->dump_opts.before_size) {
|
235
|
+
strcpy(out->cur, out->opts->dump_opts.before_sep);
|
236
|
+
out->cur += out->opts->dump_opts.before_size;
|
237
|
+
}
|
238
|
+
*out->cur++ = ':';
|
239
|
+
if (0 < out->opts->dump_opts.after_size) {
|
240
|
+
strcpy(out->cur, out->opts->dump_opts.after_sep);
|
241
|
+
out->cur += out->opts->dump_opts.after_size;
|
242
|
+
}
|
247
243
|
}
|
248
244
|
if (NullMode == out->opts->mode) {
|
249
|
-
|
245
|
+
oj_dump_null_val(value, depth, out);
|
250
246
|
} else {
|
251
|
-
|
247
|
+
oj_dump_strict_val(value, depth, out);
|
252
248
|
}
|
253
|
-
out->depth
|
249
|
+
out->depth = depth;
|
254
250
|
*out->cur++ = ',';
|
255
251
|
|
256
252
|
return ST_CONTINUE;
|
257
253
|
}
|
258
254
|
|
259
|
-
static void
|
260
|
-
|
261
|
-
|
262
|
-
size_t size;
|
255
|
+
static void dump_hash(VALUE obj, int depth, Out out, bool as_ok) {
|
256
|
+
int cnt;
|
257
|
+
size_t size;
|
263
258
|
|
264
259
|
if (Yes == out->opts->circular) {
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
260
|
+
if (0 > oj_check_circular(obj, out)) {
|
261
|
+
oj_dump_nil(Qnil, 0, out, false);
|
262
|
+
return;
|
263
|
+
}
|
269
264
|
}
|
270
|
-
cnt
|
265
|
+
cnt = (int)RHASH_SIZE(obj);
|
271
266
|
size = depth * out->indent + 2;
|
272
267
|
assure_size(out, 2);
|
273
268
|
*out->cur++ = '{';
|
274
269
|
if (0 == cnt) {
|
275
|
-
|
270
|
+
*out->cur++ = '}';
|
276
271
|
} else {
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
272
|
+
out->depth = depth + 1;
|
273
|
+
rb_hash_foreach(obj, hash_cb, (VALUE)out);
|
274
|
+
if (',' == *(out->cur - 1)) {
|
275
|
+
out->cur--; // backup to overwrite last comma
|
276
|
+
}
|
277
|
+
if (!out->opts->dump_opts.use) {
|
278
|
+
assure_size(out, size);
|
279
|
+
fill_indent(out, depth);
|
280
|
+
} else {
|
281
|
+
size = depth * out->opts->dump_opts.indent_size + out->opts->dump_opts.hash_size + 1;
|
282
|
+
assure_size(out, size);
|
283
|
+
if (0 < out->opts->dump_opts.hash_size) {
|
284
|
+
strcpy(out->cur, out->opts->dump_opts.hash_nl);
|
285
|
+
out->cur += out->opts->dump_opts.hash_size;
|
286
|
+
}
|
287
|
+
if (0 < out->opts->dump_opts.indent_size) {
|
288
|
+
int i;
|
289
|
+
|
290
|
+
for (i = depth; 0 < i; i--) {
|
291
|
+
strcpy(out->cur, out->opts->dump_opts.indent_str);
|
292
|
+
out->cur += out->opts->dump_opts.indent_size;
|
293
|
+
}
|
294
|
+
}
|
295
|
+
}
|
296
|
+
*out->cur++ = '}';
|
302
297
|
}
|
303
298
|
*out->cur = '\0';
|
304
299
|
}
|
305
300
|
|
306
|
-
static void
|
307
|
-
|
308
|
-
VALUE clas = rb_obj_class(obj);
|
301
|
+
static void dump_data_strict(VALUE obj, int depth, Out out, bool as_ok) {
|
302
|
+
VALUE clas = rb_obj_class(obj);
|
309
303
|
|
310
304
|
if (oj_bigdecimal_class == clas) {
|
311
|
-
|
305
|
+
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
312
306
|
|
313
|
-
|
307
|
+
oj_dump_raw(rb_string_value_ptr((VALUE *)&rstr), (int)RSTRING_LEN(rstr), out);
|
314
308
|
} else {
|
315
|
-
|
309
|
+
raise_strict(obj);
|
316
310
|
}
|
317
311
|
}
|
318
312
|
|
319
|
-
static void
|
320
|
-
|
321
|
-
VALUE clas = rb_obj_class(obj);
|
313
|
+
static void dump_data_null(VALUE obj, int depth, Out out, bool as_ok) {
|
314
|
+
VALUE clas = rb_obj_class(obj);
|
322
315
|
|
323
316
|
if (oj_bigdecimal_class == clas) {
|
324
|
-
|
317
|
+
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
325
318
|
|
326
|
-
|
319
|
+
oj_dump_raw(rb_string_value_ptr((VALUE *)&rstr), (int)RSTRING_LEN(rstr), out);
|
327
320
|
} else {
|
328
|
-
|
321
|
+
oj_dump_nil(Qnil, depth, out, false);
|
329
322
|
}
|
330
323
|
}
|
331
324
|
|
332
|
-
static DumpFunc
|
333
|
-
NULL,
|
334
|
-
dump_data_strict,
|
335
|
-
NULL,
|
336
|
-
NULL,
|
337
|
-
dump_float,
|
338
|
-
oj_dump_str,
|
339
|
-
NULL,
|
340
|
-
dump_array,
|
341
|
-
dump_hash,
|
342
|
-
NULL,
|
343
|
-
oj_dump_bignum,
|
344
|
-
NULL,
|
345
|
-
dump_data_strict,
|
346
|
-
NULL,
|
347
|
-
NULL,
|
348
|
-
NULL,
|
349
|
-
NULL,
|
350
|
-
oj_dump_nil,
|
351
|
-
oj_dump_true,
|
352
|
-
oj_dump_false,
|
353
|
-
oj_dump_sym,
|
354
|
-
oj_dump_fixnum,
|
325
|
+
static DumpFunc strict_funcs[] = {
|
326
|
+
NULL, // RUBY_T_NONE = 0x00,
|
327
|
+
dump_data_strict, // RUBY_T_OBJECT = 0x01,
|
328
|
+
NULL, // RUBY_T_CLASS = 0x02,
|
329
|
+
NULL, // RUBY_T_MODULE = 0x03,
|
330
|
+
dump_float, // RUBY_T_FLOAT = 0x04,
|
331
|
+
oj_dump_str, // RUBY_T_STRING = 0x05,
|
332
|
+
NULL, // RUBY_T_REGEXP = 0x06,
|
333
|
+
dump_array, // RUBY_T_ARRAY = 0x07,
|
334
|
+
dump_hash, // RUBY_T_HASH = 0x08,
|
335
|
+
NULL, // RUBY_T_STRUCT = 0x09,
|
336
|
+
oj_dump_bignum, // RUBY_T_BIGNUM = 0x0a,
|
337
|
+
NULL, // RUBY_T_FILE = 0x0b,
|
338
|
+
dump_data_strict, // RUBY_T_DATA = 0x0c,
|
339
|
+
NULL, // RUBY_T_MATCH = 0x0d,
|
340
|
+
NULL, // RUBY_T_COMPLEX = 0x0e,
|
341
|
+
NULL, // RUBY_T_RATIONAL = 0x0f,
|
342
|
+
NULL, // 0x10
|
343
|
+
oj_dump_nil, // RUBY_T_NIL = 0x11,
|
344
|
+
oj_dump_true, // RUBY_T_TRUE = 0x12,
|
345
|
+
oj_dump_false, // RUBY_T_FALSE = 0x13,
|
346
|
+
oj_dump_sym, // RUBY_T_SYMBOL = 0x14,
|
347
|
+
oj_dump_fixnum, // RUBY_T_FIXNUM = 0x15,
|
355
348
|
};
|
356
349
|
|
357
|
-
void
|
358
|
-
|
359
|
-
int type = rb_type(obj);
|
350
|
+
void oj_dump_strict_val(VALUE obj, int depth, Out out) {
|
351
|
+
int type = rb_type(obj);
|
360
352
|
|
361
353
|
if (Yes == out->opts->trace) {
|
362
|
-
|
354
|
+
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
|
363
355
|
}
|
364
356
|
if (MAX_DEPTH < depth) {
|
365
|
-
|
357
|
+
rb_raise(rb_eNoMemError, "Too deeply nested.\n");
|
366
358
|
}
|
367
359
|
if (0 < type && type <= RUBY_T_FIXNUM) {
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
360
|
+
DumpFunc f = strict_funcs[type];
|
361
|
+
|
362
|
+
if (NULL != f) {
|
363
|
+
f(obj, depth, out, false);
|
364
|
+
if (Yes == out->opts->trace) {
|
365
|
+
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
|
366
|
+
}
|
367
|
+
return;
|
368
|
+
}
|
377
369
|
}
|
378
370
|
raise_strict(obj);
|
379
371
|
}
|
380
372
|
|
381
|
-
static DumpFunc
|
382
|
-
NULL,
|
383
|
-
dump_data_null,
|
384
|
-
NULL,
|
385
|
-
NULL,
|
386
|
-
dump_float,
|
387
|
-
oj_dump_str,
|
388
|
-
NULL,
|
389
|
-
dump_array,
|
390
|
-
dump_hash,
|
391
|
-
NULL,
|
392
|
-
oj_dump_bignum,
|
393
|
-
NULL,
|
394
|
-
dump_data_null,
|
395
|
-
NULL,
|
396
|
-
NULL,
|
397
|
-
NULL,
|
398
|
-
NULL,
|
399
|
-
oj_dump_nil,
|
400
|
-
oj_dump_true,
|
401
|
-
oj_dump_false,
|
402
|
-
oj_dump_sym,
|
403
|
-
oj_dump_fixnum,
|
373
|
+
static DumpFunc null_funcs[] = {
|
374
|
+
NULL, // RUBY_T_NONE = 0x00,
|
375
|
+
dump_data_null, // RUBY_T_OBJECT = 0x01,
|
376
|
+
NULL, // RUBY_T_CLASS = 0x02,
|
377
|
+
NULL, // RUBY_T_MODULE = 0x03,
|
378
|
+
dump_float, // RUBY_T_FLOAT = 0x04,
|
379
|
+
oj_dump_str, // RUBY_T_STRING = 0x05,
|
380
|
+
NULL, // RUBY_T_REGEXP = 0x06,
|
381
|
+
dump_array, // RUBY_T_ARRAY = 0x07,
|
382
|
+
dump_hash, // RUBY_T_HASH = 0x08,
|
383
|
+
NULL, // RUBY_T_STRUCT = 0x09,
|
384
|
+
oj_dump_bignum, // RUBY_T_BIGNUM = 0x0a,
|
385
|
+
NULL, // RUBY_T_FILE = 0x0b,
|
386
|
+
dump_data_null, // RUBY_T_DATA = 0x0c,
|
387
|
+
NULL, // RUBY_T_MATCH = 0x0d,
|
388
|
+
NULL, // RUBY_T_COMPLEX = 0x0e,
|
389
|
+
NULL, // RUBY_T_RATIONAL = 0x0f,
|
390
|
+
NULL, // 0x10
|
391
|
+
oj_dump_nil, // RUBY_T_NIL = 0x11,
|
392
|
+
oj_dump_true, // RUBY_T_TRUE = 0x12,
|
393
|
+
oj_dump_false, // RUBY_T_FALSE = 0x13,
|
394
|
+
oj_dump_sym, // RUBY_T_SYMBOL = 0x14,
|
395
|
+
oj_dump_fixnum, // RUBY_T_FIXNUM = 0x15,
|
404
396
|
};
|
405
397
|
|
406
|
-
void
|
407
|
-
|
408
|
-
int type = rb_type(obj);
|
398
|
+
void oj_dump_null_val(VALUE obj, int depth, Out out) {
|
399
|
+
int type = rb_type(obj);
|
409
400
|
|
410
401
|
if (Yes == out->opts->trace) {
|
411
|
-
|
402
|
+
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
|
412
403
|
}
|
413
404
|
if (MAX_DEPTH < depth) {
|
414
|
-
|
405
|
+
rb_raise(rb_eNoMemError, "Too deeply nested.\n");
|
415
406
|
}
|
416
407
|
if (0 < type && type <= RUBY_T_FIXNUM) {
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
408
|
+
DumpFunc f = null_funcs[type];
|
409
|
+
|
410
|
+
if (NULL != f) {
|
411
|
+
f(obj, depth, out, false);
|
412
|
+
if (Yes == out->opts->trace) {
|
413
|
+
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
|
414
|
+
}
|
415
|
+
return;
|
416
|
+
}
|
426
417
|
}
|
427
418
|
oj_dump_nil(Qnil, depth, out, false);
|
428
419
|
if (Yes == out->opts->trace) {
|
429
|
-
|
420
|
+
oj_trace("dump", Qnil, __FILE__, __LINE__, depth, TraceOut);
|
430
421
|
}
|
431
422
|
}
|