oj 3.11.3 → 3.11.8

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