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.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -1
  3. data/ext/oj/buf.h +36 -68
  4. data/ext/oj/cache8.c +59 -62
  5. data/ext/oj/cache8.h +9 -36
  6. data/ext/oj/circarray.c +36 -42
  7. data/ext/oj/circarray.h +12 -13
  8. data/ext/oj/code.c +172 -179
  9. data/ext/oj/code.h +22 -24
  10. data/ext/oj/compat.c +168 -181
  11. data/ext/oj/custom.c +800 -864
  12. data/ext/oj/dump.c +774 -776
  13. data/ext/oj/dump.h +50 -55
  14. data/ext/oj/dump_compat.c +2 -4
  15. data/ext/oj/dump_leaf.c +118 -162
  16. data/ext/oj/dump_object.c +610 -632
  17. data/ext/oj/dump_strict.c +319 -331
  18. data/ext/oj/encode.h +4 -33
  19. data/ext/oj/err.c +40 -29
  20. data/ext/oj/err.h +25 -44
  21. data/ext/oj/extconf.rb +2 -1
  22. data/ext/oj/fast.c +1054 -1081
  23. data/ext/oj/hash.c +78 -95
  24. data/ext/oj/hash.h +10 -35
  25. data/ext/oj/hash_test.c +451 -472
  26. data/ext/oj/mimic_json.c +415 -402
  27. data/ext/oj/object.c +588 -532
  28. data/ext/oj/odd.c +124 -132
  29. data/ext/oj/odd.h +28 -29
  30. data/ext/oj/oj.c +1178 -905
  31. data/ext/oj/oj.h +289 -298
  32. data/ext/oj/parse.c +946 -870
  33. data/ext/oj/parse.h +81 -79
  34. data/ext/oj/rails.c +837 -842
  35. data/ext/oj/rails.h +8 -11
  36. data/ext/oj/reader.c +139 -147
  37. data/ext/oj/reader.h +68 -84
  38. data/ext/oj/resolve.c +44 -47
  39. data/ext/oj/resolve.h +4 -6
  40. data/ext/oj/rxclass.c +69 -73
  41. data/ext/oj/rxclass.h +13 -14
  42. data/ext/oj/saj.c +453 -484
  43. data/ext/oj/scp.c +88 -113
  44. data/ext/oj/sparse.c +783 -714
  45. data/ext/oj/stream_writer.c +123 -157
  46. data/ext/oj/strict.c +133 -106
  47. data/ext/oj/string_writer.c +199 -247
  48. data/ext/oj/trace.c +34 -41
  49. data/ext/oj/trace.h +15 -15
  50. data/ext/oj/util.c +104 -104
  51. data/ext/oj/util.h +4 -3
  52. data/ext/oj/val_stack.c +48 -76
  53. data/ext/oj/val_stack.h +80 -115
  54. data/ext/oj/wab.c +317 -328
  55. data/lib/oj.rb +0 -8
  56. data/lib/oj/bag.rb +1 -0
  57. data/lib/oj/easy_hash.rb +5 -4
  58. data/lib/oj/mimic.rb +45 -13
  59. data/lib/oj/version.rb +1 -1
  60. data/pages/Modes.md +1 -0
  61. data/pages/Options.md +23 -11
  62. data/test/activerecord/result_test.rb +7 -2
  63. data/test/foo.rb +8 -40
  64. data/test/helper.rb +10 -0
  65. data/test/json_gem/json_common_interface_test.rb +8 -3
  66. data/test/json_gem/json_generator_test.rb +15 -3
  67. data/test/json_gem/test_helper.rb +8 -0
  68. data/test/perf.rb +1 -1
  69. data/test/perf_scp.rb +11 -10
  70. data/test/perf_strict.rb +17 -23
  71. data/test/prec.rb +23 -0
  72. data/test/sample_json.rb +1 -1
  73. data/test/test_compat.rb +16 -3
  74. data/test/test_custom.rb +11 -0
  75. data/test/test_fast.rb +32 -2
  76. data/test/test_generate.rb +21 -0
  77. data/test/test_hash.rb +10 -0
  78. data/test/test_rails.rb +9 -0
  79. data/test/test_scp.rb +1 -1
  80. data/test/test_various.rb +4 -2
  81. metadata +89 -85
data/ext/oj/odd.c CHANGED
@@ -1,81 +1,76 @@
1
- /* odd.c
2
- * Copyright (c) 2011, Peter Ohler
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
- static struct _odd _odds[4]; // bump up if new initial Odd classes are added
11
- static struct _odd *odds = _odds;
12
- static long odd_cnt = 0;
13
- static ID sec_id;
14
- static ID sec_fraction_id;
15
- static ID to_f_id;
16
- static ID numerator_id;
17
- static ID denominator_id;
18
- static ID rational_id;
19
- static VALUE rational_class;
20
-
21
- static void
22
- set_class(Odd odd, const char *classname) {
23
- const char **np;
24
- ID *idp;
25
-
26
- odd->classname = classname;
27
- odd->clen = strlen(classname);
28
- odd->clas = rb_const_get(rb_cObject, rb_intern(classname));
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 = rb_intern("new");
31
- odd->is_module = (T_MODULE == rb_type(odd->clas));
32
- odd->raw = 0;
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
- *idp = rb_intern(*np);
31
+ *idp = rb_intern(*np);
35
32
  }
36
33
  *idp = 0;
37
34
  }
38
35
 
39
- static VALUE
40
- get_datetime_secs(VALUE obj) {
41
- volatile VALUE rsecs = rb_funcall(obj, sec_id, 0);
42
- volatile VALUE rfrac = rb_funcall(obj, sec_fraction_id, 0);
43
- long sec = NUM2LONG(rsecs);
44
- long long num = rb_num2ll(rb_funcall(rfrac, numerator_id, 0));
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
- oj_odd_init() {
54
- Odd odd;
55
- const char **np;
48
+ void oj_odd_init() {
49
+ Odd odd;
50
+ const char **np;
56
51
 
57
- sec_id = rb_intern("sec");
52
+ sec_id = rb_intern("sec");
58
53
  sec_fraction_id = rb_intern("sec_fraction");
59
- to_f_id = rb_intern("to_f");
60
- numerator_id = rb_intern("numerator");
61
- denominator_id = rb_intern("denominator");
62
- rational_id = rb_intern("Rational");
63
- rational_class = rb_const_get(rb_cObject, rational_id);
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 = odd->attr_names;
63
+ np = odd->attr_names;
69
64
  *np++ = "numerator";
70
65
  *np++ = "denominator";
71
- *np = 0;
66
+ *np = 0;
72
67
  set_class(odd, "Rational");
73
68
  odd->create_obj = rb_cObject;
74
- odd->create_op = rational_id;
75
- odd->attr_cnt = 2;
69
+ odd->create_op = rational_id;
70
+ odd->attr_cnt = 2;
76
71
  // Date
77
72
  odd++;
78
- np = odd->attr_names;
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 = odd->attr_names;
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 = 8;
94
+ odd->attr_cnt = 8;
100
95
  odd->attrFuncs[5] = get_datetime_secs;
101
96
  // Range
102
97
  odd++;
103
- np = odd->attr_names;
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
- oj_get_odd(VALUE clas) {
116
- Odd odd;
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
- if (clas == odd->clas) {
121
- return odd;
122
- }
123
- if (odd->is_module) {
124
- if (NULL == classname) {
125
- classname = rb_class2name(clas);
126
- }
127
- if (0 == strncmp(odd->classname, classname, odd->clen) &&
128
- ':' == classname[odd->clen]) {
129
- return odd;
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
- oj_get_oddc(const char *classname, size_t len) {
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
- if (len == odd->clen && 0 == strncmp(classname, odd->classname, len)) {
142
- return odd;
143
- }
144
- if (odd->is_module &&
145
- 0 == strncmp(odd->classname, classname, odd->clen) &&
146
- ':' == classname[odd->clen]) {
147
- return odd;
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
- oj_odd_alloc_args(Odd odd) {
155
- OddArgs oa = ALLOC_N(struct _oddArgs, 1);
156
- VALUE *a;
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
- *a = Qnil;
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
- oj_odd_set_arg(OddArgs args, const char *key, size_t klen, VALUE value) {
173
- const char **np;
174
- VALUE *vp;
175
- int i;
176
-
177
- for (i = args->odd->attr_cnt, np = args->odd->attr_names, vp = args->args; 0 < i; i--, np++, vp++) {
178
- if (0 == strncmp(key, *np, klen) && '\0' == *((*np) + klen)) {
179
- *vp = value;
180
- return 0;
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
- oj_reg_odd(VALUE clas, VALUE create_object, VALUE create_method, int mcnt, VALUE *members, bool raw) {
188
- Odd odd;
189
- const char **np;
190
- ID *ap;
191
- AttrGetFunc *fp;
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
- odds = ALLOC_N(struct _odd, odd_cnt + 1);
187
+ odds = ALLOC_N(struct _odd, odd_cnt + 1);
195
188
 
196
- memcpy(odds, _odds, sizeof(struct _odd) * odd_cnt);
189
+ memcpy(odds, _odds, sizeof(struct _odd) * odd_cnt);
197
190
  } else {
198
- REALLOC_N(odds, struct _odd, odd_cnt + 1);
191
+ REALLOC_N(odds, struct _odd, odd_cnt + 1);
199
192
  }
200
- odd = odds + odd_cnt;
193
+ odd = odds + odd_cnt;
201
194
  odd->clas = clas;
202
195
  if (NULL == (odd->classname = strdup(rb_class2name(clas)))) {
203
- rb_raise(rb_eNoMemError, "for attribute name.");
196
+ rb_raise(rb_eNoMemError, "for attribute name.");
204
197
  }
205
- odd->clen = strlen(odd->classname);
198
+ odd->clen = strlen(odd->classname);
206
199
  odd->create_obj = create_object;
207
- odd->create_op = SYM2ID(create_method);
208
- odd->attr_cnt = mcnt;
209
- odd->is_module = (T_MODULE == rb_type(clas));
210
- odd->raw = raw;
211
- for (ap = odd->attrs, np = odd->attr_names, fp = odd->attrFuncs; 0 < mcnt; mcnt--, ap++, np++, members++, fp++) {
212
- *fp = 0;
213
- switch (rb_type(*members)) {
214
- case T_STRING:
215
- if (NULL == (*np = strdup(rb_string_value_ptr(members)))) {
216
- rb_raise(rb_eNoMemError, "for attribute name.");
217
- }
218
- break;
219
- case T_SYMBOL:
220
- *np = rb_id2name(SYM2ID(*members));
221
- break;
222
- default:
223
- rb_raise(rb_eArgError, "registered member identifiers must be Strings or Symbols.");
224
- break;
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
- /* odd.h
2
- * Copyright (c) 2011, Peter Ohler
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 10
11
+ #define MAX_ODD_ARGS 10
14
12
 
15
- typedef VALUE (*AttrGetFunc)(VALUE obj);
13
+ typedef VALUE (*AttrGetFunc)(VALUE obj);
16
14
 
17
15
  typedef struct _odd {
18
- const char *classname;
19
- size_t clen;
20
- VALUE clas; // Ruby class or module
21
- VALUE create_obj;
22
- ID create_op;
23
- int attr_cnt;
24
- bool is_module;
25
- bool raw;
26
- const char *attr_names[MAX_ODD_ARGS]; // NULL terminated attr names
27
- ID attrs[MAX_ODD_ARGS]; // 0 terminated attr IDs
28
- AttrGetFunc attrFuncs[MAX_ODD_ARGS];
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 odd;
33
- VALUE args[MAX_ODD_ARGS];
34
- } *OddArgs;
35
-
36
- extern void oj_odd_init(void);
37
- extern Odd oj_get_odd(VALUE clas);
38
- extern Odd oj_get_oddc(const char *classname, size_t len);
39
- extern OddArgs oj_odd_alloc_args(Odd odd);
40
- extern void oj_odd_free(OddArgs args);
41
- extern int oj_odd_set_arg(OddArgs args, const char *key, size_t klen, VALUE value);
42
- extern void oj_reg_odd(VALUE clas, VALUE create_object, VALUE create_method, int mcnt, VALUE *members, bool raw);
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
- /* oj.c
2
- * Copyright (c) 2012, Peter Ohler
3
- * All rights reserved.
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 "oj.h"
15
- #include "parse.h"
14
+ #include "dump.h"
15
+ #include "encode.h"
16
16
  #include "hash.h"
17
17
  #include "odd.h"
18
- #include "dump.h"
18
+ #include "parse.h"
19
19
  #include "rails.h"
20
- #include "encode.h"
21
20
 
22
21
  typedef struct _yesNoOpt {
23
- VALUE sym;
24
- char *attr;
25
- } *YesNoOpt;
22
+ VALUE sym;
23
+ char *attr;
24
+ } * YesNoOpt;
26
25
 
27
26
  void Init_oj();
28
27
 
29
- VALUE Oj = Qnil;
30
-
31
- ID oj_add_value_id;
32
- ID oj_array_append_id;
33
- ID oj_array_end_id;
34
- ID oj_array_start_id;
35
- ID oj_as_json_id;
36
- ID oj_begin_id;
37
- ID oj_bigdecimal_id;
38
- ID oj_end_id;
39
- ID oj_exclude_end_id;
40
- ID oj_error_id;
41
- ID oj_file_id;
42
- ID oj_fileno_id;
43
- ID oj_ftype_id;
44
- ID oj_has_key_id;
45
- ID oj_hash_end_id;
46
- ID oj_hash_key_id;
47
- ID oj_hash_set_id;
48
- ID oj_hash_start_id;
49
- ID oj_iconv_id;
50
- ID oj_instance_variables_id;
51
- ID oj_json_create_id;
52
- ID oj_length_id;
53
- ID oj_new_id;
54
- ID oj_parse_id;
55
- ID oj_pos_id;
56
- ID oj_raw_json_id;
57
- ID oj_read_id;
58
- ID oj_readpartial_id;
59
- ID oj_replace_id;
60
- ID oj_stat_id;
61
- ID oj_string_id;
62
- ID oj_to_h_id;
63
- ID oj_to_hash_id;
64
- ID oj_to_json_id;
65
- ID oj_to_s_id;
66
- ID oj_to_sym_id;
67
- ID oj_to_time_id;
68
- ID oj_tv_nsec_id;
69
- ID oj_tv_sec_id;
70
- ID oj_tv_usec_id;
71
- ID oj_utc_id;
72
- ID oj_utc_offset_id;
73
- ID oj_utcq_id;
74
- ID oj_write_id;
75
-
76
-
77
- VALUE oj_bag_class;
78
- VALUE oj_bigdecimal_class;
79
- VALUE oj_cstack_class;
80
- VALUE oj_date_class;
81
- VALUE oj_datetime_class;
82
- VALUE oj_enumerable_class;
83
- VALUE oj_parse_error_class;
84
- VALUE oj_stream_writer_class;
85
- VALUE oj_string_writer_class;
86
- VALUE oj_stringio_class;
87
- VALUE oj_struct_class;
88
-
89
- VALUE oj_slash_string;
90
-
91
- VALUE oj_allow_nan_sym;
92
- VALUE oj_array_class_sym;
93
- VALUE oj_create_additions_sym;
94
- VALUE oj_hash_class_sym;
95
- VALUE oj_indent_sym;
96
- VALUE oj_object_class_sym;
97
- VALUE oj_quirks_mode_sym;
98
- VALUE oj_safe_sym;
99
- VALUE oj_trace_sym;
100
-
101
- static VALUE allow_blank_sym;
102
- static VALUE allow_gc_sym;
103
- static VALUE allow_invalid_unicode_sym;
104
- static VALUE ascii_sym;
105
- static VALUE auto_define_sym;
106
- static VALUE auto_sym;
107
- static VALUE bigdecimal_as_decimal_sym;
108
- static VALUE bigdecimal_load_sym;
109
- static VALUE bigdecimal_sym;
110
- static VALUE circular_sym;
111
- static VALUE class_cache_sym;
112
- static VALUE compat_sym;
113
- static VALUE create_id_sym;
114
- static VALUE custom_sym;
115
- static VALUE empty_string_sym;
116
- static VALUE escape_mode_sym;
117
- static VALUE integer_range_sym;
118
- static VALUE float_prec_sym;
119
- static VALUE float_sym;
120
- static VALUE huge_sym;
121
- static VALUE ignore_sym;
122
- static VALUE ignore_under_sym;
123
- static VALUE json_sym;
124
- static VALUE match_string_sym;
125
- static VALUE mode_sym;
126
- static VALUE nan_sym;
127
- static VALUE newline_sym;
128
- static VALUE nilnil_sym;
129
- static VALUE null_sym;
130
- static VALUE object_sym;
131
- static VALUE omit_nil_sym;
132
- static VALUE rails_sym;
133
- static VALUE raise_sym;
134
- static VALUE ruby_sym;
135
- static VALUE sec_prec_sym;
136
- static VALUE strict_sym;
137
- static VALUE symbol_keys_sym;
138
- static VALUE time_format_sym;
139
- static VALUE unicode_xss_sym;
140
- static VALUE unix_sym;
141
- static VALUE unix_zone_sym;
142
- static VALUE use_as_json_sym;
143
- static VALUE use_raw_json_sym;
144
- static VALUE use_to_hash_sym;
145
- static VALUE use_to_json_sym;
146
- static VALUE wab_sym;
147
- static VALUE word_sym;
148
- static VALUE xmlschema_sym;
149
- static VALUE xss_safe_sym;
150
-
151
- rb_encoding *oj_utf8_encoding = 0;
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 oj_cache_mutex;
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 oj_json_class[] = "json_class";
160
-
161
- struct _options oj_default_options = {
162
- 0, // indent
163
- No, // circular
164
- No, // auto_define
165
- No, // sym_key
166
- JSONEsc, // escape_mode
167
- ObjectMode, // mode
168
- Yes, // class_cache
169
- UnixTime, // time_format
170
- NotSet, // bigdec_as_num
171
- AutoDec, // bigdec_load
172
- No, // to_hash
173
- No, // to_json
174
- No, // as_json
175
- No, // raw_json
176
- No, // nilnil
177
- Yes, // empty_string
178
- Yes, // allow_gc
179
- Yes, // quirks_mode
180
- No, // allow_invalid
181
- No, // create_ok
182
- Yes, // allow_nan
183
- No, // trace
184
- No, // safe
185
- false, // sec_prec_set
186
- No, // ignore_under
187
- 0, // int_range_min
188
- 0, // int_range_max
189
- oj_json_class, // create_id
190
- 10, // create_id_len
191
- 9, // sec_prec
192
- 16, // float_prec
193
- "%0.15g", // float_fmt
194
- Qnil, // hash_class
195
- Qnil, // array_class
196
- { // dump_opts
197
- false, //use
198
- "", // indent
199
- "", // before_sep
200
- "", // after_sep
201
- "", // hash_nl
202
- "", // array_nl
203
- 0, // indent_size
204
- 0, // before_size
205
- 0, // after_size
206
- 0, // hash_size
207
- 0, // array_size
208
- AutoNan,// nan_dump
209
- false, // omit_nil
210
- MAX_DEPTH, // max_depth
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
- { // str_rx
213
- NULL, // head
214
- NULL, // tail
215
- { '\0' }, // err
219
+ {
220
+ // str_rx
221
+ NULL, // head
222
+ NULL, // tail
223
+ {'\0'}, // err
216
224
  },
217
- NULL, // ignore
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 document, zero or nil is no newline between JSON elements, negative indicates no newline between top level JSON elements in a stream, a String indicates the string should be used for indentation
225
- * - *:circular* [_Boolean_|_nil_] support circular references while dumping
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 characters to escape
229
- * - *:class_cache* [_Boolean_|_nil_] cache classes for faster parsing (if dynamically modifying classes or reloading classes then don't use this)
230
- * - *:mode* [_:object_|_:strict_|_:compat_|_:null_|_:custom_|_:rails_|_:wab_] load and dump modes to use for JSON
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 of as a Float. :auto pick the most precise for the number of digits.
234
- * - *:create_id* [_String_|_nil_] create id for json compatible object encoding, default is 'json_class'
235
- * - *:create_additions* [_Boolean_|_nil_] if true allow creation of instances using create_id on load.
236
- * - *:second_precision* [_Fixnum_|_nil_] number of digits after the decimal when dumping the seconds portion of time
237
- * - *:float_precision* [_Fixnum_|_nil_] number of digits of precision when dumping floats, 0 indicates use Ruby
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 Exception
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 is true (allow)
245
- * - *:allow_invalid_unicode* [_true,_|_false_|_nil_] Allow invalid unicode, default is false (don't allow)
246
- * - *:allow_nan* [_true,_|_false_|_nil_] Allow Nan, Infinity, and -Infinity to be parsed, default is true (allow)
247
- * - *:indent_str* [_String_|_nil_] String to use for indentation, overriding the indent option is not nil
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 null, :huge places a huge number, :word places Infinity or NaN, :raise raises and exception, :auto uses default for each mode.
253
- * - *:hash_class* [_Class_|_nil_] Class to use instead of Hash on load, :object_class can also be used
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_|Array] either nil or an Array of classes to ignore when dumping
257
- * - *:ignore_under* [Boolean] if true then attributes that start with _ are ignored when dumping in object or custom mode.
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 off)
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
- get_def_opts(VALUE self) {
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
- rb_hash_aset(opts, oj_indent_sym, INT2FIX(oj_default_options.indent));
302
+ rb_hash_aset(opts, oj_indent_sym, INT2FIX(oj_default_options.indent));
270
303
  } else {
271
- rb_hash_aset(opts, oj_indent_sym, rb_str_new2(oj_default_options.dump_opts.indent_str));
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, circular_sym, (Yes == oj_default_options.circular) ? Qtrue : ((No == oj_default_options.circular) ? Qfalse : Qnil));
275
- rb_hash_aset(opts, class_cache_sym, (Yes == oj_default_options.class_cache) ? Qtrue : ((No == oj_default_options.class_cache) ? Qfalse : Qnil));
276
- rb_hash_aset(opts, auto_define_sym, (Yes == oj_default_options.auto_define) ? Qtrue : ((No == oj_default_options.auto_define) ? Qfalse : Qnil));
277
- rb_hash_aset(opts, symbol_keys_sym, (Yes == oj_default_options.sym_key) ? Qtrue : ((No == oj_default_options.sym_key) ? Qfalse : Qnil));
278
- rb_hash_aset(opts, bigdecimal_as_decimal_sym, (Yes == oj_default_options.bigdec_as_num) ? Qtrue : ((No == oj_default_options.bigdec_as_num) ? Qfalse : Qnil));
279
- rb_hash_aset(opts, oj_create_additions_sym, (Yes == oj_default_options.create_ok) ? Qtrue : ((No == oj_default_options.create_ok) ? Qfalse : Qnil));
280
- rb_hash_aset(opts, use_to_json_sym, (Yes == oj_default_options.to_json) ? Qtrue : ((No == oj_default_options.to_json) ? Qfalse : Qnil));
281
- rb_hash_aset(opts, use_to_hash_sym, (Yes == oj_default_options.to_hash) ? Qtrue : ((No == oj_default_options.to_hash) ? Qfalse : Qnil));
282
- rb_hash_aset(opts, use_as_json_sym, (Yes == oj_default_options.as_json) ? Qtrue : ((No == oj_default_options.as_json) ? Qfalse : Qnil));
283
- rb_hash_aset(opts, use_raw_json_sym, (Yes == oj_default_options.raw_json) ? Qtrue : ((No == oj_default_options.raw_json) ? Qfalse : Qnil));
284
- rb_hash_aset(opts, nilnil_sym, (Yes == oj_default_options.nilnil) ? Qtrue : ((No == oj_default_options.nilnil) ? Qfalse : Qnil));
285
- rb_hash_aset(opts, empty_string_sym, (Yes == oj_default_options.empty_string) ? Qtrue : ((No == oj_default_options.empty_string) ? Qfalse : Qnil));
286
- rb_hash_aset(opts, allow_gc_sym, (Yes == oj_default_options.allow_gc) ? Qtrue : ((No == oj_default_options.allow_gc) ? Qfalse : Qnil));
287
- rb_hash_aset(opts, oj_quirks_mode_sym, (Yes == oj_default_options.quirks_mode) ? Qtrue : ((No == oj_default_options.quirks_mode) ? Qfalse : Qnil));
288
- rb_hash_aset(opts, allow_invalid_unicode_sym, (Yes == oj_default_options.allow_invalid) ? Qtrue : ((No == oj_default_options.allow_invalid) ? Qfalse : Qnil));
289
- rb_hash_aset(opts, oj_allow_nan_sym, (Yes == oj_default_options.allow_nan) ? Qtrue : ((No == oj_default_options.allow_nan) ? Qfalse : Qnil));
290
- rb_hash_aset(opts, oj_trace_sym, (Yes == oj_default_options.trace) ? Qtrue : ((No == oj_default_options.trace) ? Qfalse : Qnil));
291
- rb_hash_aset(opts, oj_safe_sym, (Yes == oj_default_options.safe) ? Qtrue : ((No == oj_default_options.safe) ? Qfalse : Qnil));
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, ignore_under_sym, (Yes == oj_default_options.ignore_under) ? Qtrue : ((No == oj_default_options.ignore_under) ? Qfalse : Qnil));
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: rb_hash_aset(opts, mode_sym, strict_sym); break;
296
- case CompatMode: rb_hash_aset(opts, mode_sym, compat_sym); break;
297
- case NullMode: rb_hash_aset(opts, mode_sym, null_sym); break;
298
- case ObjectMode: rb_hash_aset(opts, mode_sym, object_sym); break;
299
- case CustomMode: rb_hash_aset(opts, mode_sym, custom_sym); break;
300
- case RailsMode: rb_hash_aset(opts, mode_sym, rails_sym); break;
301
- case WabMode: rb_hash_aset(opts, mode_sym, wab_sym); break;
302
- default: rb_hash_aset(opts, mode_sym, object_sym); break;
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
- VALUE range = rb_obj_alloc(rb_cRange);
307
- VALUE min = LONG2FIX(oj_default_options.int_range_min);
308
- VALUE max = LONG2FIX(oj_default_options.int_range_max);
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
- rb_ivar_set(range, oj_begin_id, min);
311
- rb_ivar_set(range, oj_end_id, max);
312
- rb_hash_aset(opts, integer_range_sym, range);
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
- rb_hash_aset(opts, integer_range_sym, Qnil);
429
+ rb_hash_aset(opts, integer_range_sym, Qnil);
315
430
  }
316
431
  switch (oj_default_options.escape_mode) {
317
- case NLEsc: rb_hash_aset(opts, escape_mode_sym, newline_sym); break;
318
- case JSONEsc: rb_hash_aset(opts, escape_mode_sym, json_sym); break;
319
- case XSSEsc: rb_hash_aset(opts, escape_mode_sym, xss_safe_sym); break;
320
- case ASCIIEsc: rb_hash_aset(opts, escape_mode_sym, ascii_sym); break;
321
- case JXEsc: rb_hash_aset(opts, escape_mode_sym, unicode_xss_sym); break;
322
- default: rb_hash_aset(opts, escape_mode_sym, json_sym); break;
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: rb_hash_aset(opts, time_format_sym, xmlschema_sym); break;
326
- case RubyTime: rb_hash_aset(opts, time_format_sym, ruby_sym); break;
327
- case UnixZTime: rb_hash_aset(opts, time_format_sym, unix_zone_sym); break;
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: rb_hash_aset(opts, time_format_sym, unix_sym); break;
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: rb_hash_aset(opts, bigdecimal_load_sym, bigdecimal_sym);break;
333
- case FloatDec: rb_hash_aset(opts, bigdecimal_load_sym, float_sym); break;
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: rb_hash_aset(opts, bigdecimal_load_sym, auto_sym); break;
451
+ default: rb_hash_aset(opts, bigdecimal_load_sym, auto_sym); break;
336
452
  }
337
- rb_hash_aset(opts, create_id_sym, (NULL == oj_default_options.create_id) ? Qnil : rb_str_new2(oj_default_options.create_id));
338
- rb_hash_aset(opts, oj_space_sym, (0 == oj_default_options.dump_opts.after_size) ? Qnil : rb_str_new2(oj_default_options.dump_opts.after_sep));
339
- rb_hash_aset(opts, oj_space_before_sym, (0 == oj_default_options.dump_opts.before_size) ? Qnil : rb_str_new2(oj_default_options.dump_opts.before_sep));
340
- rb_hash_aset(opts, oj_object_nl_sym, (0 == oj_default_options.dump_opts.hash_size) ? Qnil : rb_str_new2(oj_default_options.dump_opts.hash_nl));
341
- rb_hash_aset(opts, oj_array_nl_sym, (0 == oj_default_options.dump_opts.array_size) ? Qnil : rb_str_new2(oj_default_options.dump_opts.array_nl));
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: rb_hash_aset(opts, nan_sym, null_sym); break;
345
- case RaiseNan: rb_hash_aset(opts, nan_sym, raise_sym); break;
346
- case WordNan: rb_hash_aset(opts, nan_sym, word_sym); break;
347
- case HugeNan: rb_hash_aset(opts, nan_sym, huge_sym); break;
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: rb_hash_aset(opts, nan_sym, auto_sym); break;
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
- rb_hash_aset(opts, ignore_sym, Qnil);
492
+ rb_hash_aset(opts, ignore_sym, Qnil);
357
493
  } else {
358
- VALUE *vp;
359
- volatile VALUE a = rb_ary_new();
494
+ VALUE * vp;
495
+ volatile VALUE a = rb_ary_new();
360
496
 
361
- for (vp = oj_default_options.ignore; Qnil != *vp; vp++) {
362
- rb_ary_push(a, *vp);
363
- }
364
- rb_hash_aset(opts, ignore_sym, a);
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 document or the String to use for identation.
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 high-bit characters as escaped sequences if :ascii, :json is standand UTF-8 JSON encoding, :newline is the same as :json but newlines are not escaped, :unicode_xss allows unicode but escapes &, <, and >, and any \u20xx characters along with some others, and :xss_safe escapes &, <, and >, and some others.
380
- * - *:bigdecimal_as_decimal* [_Boolean_|_nil_] dump BigDecimal as a decimal number or as a String.
381
- * - *:bigdecimal_load* [_:bigdecimal_|_:float_|_:auto_|_nil_] load decimals as BigDecimal instead of as a Float. :auto pick the most precise for the number of digits.
382
- * - *:mode* [_:object_|_:strict_|_:compat_|_:null_|_:custom_|_:rails_|_:wab_] load and dump mode to use for JSON :strict raises an exception when a non-supported Object is encountered. :compat attempts to extract variable values from an Object using to_json() or to_hash() then it walks the Object's variables if neither is found. The :object mode ignores to_hash() and to_json() methods and encodes variables using code internal to the Oj gem. The :null mode ignores non-supported Objects and replaces them with a null. The :custom mode honors all dump options. The :rails more mimics rails and Active behavior.
383
- * - *:time_format* [_:unix_|_:xmlschema_|_:ruby_] time format when dumping in :compat mode :unix decimal number denoting the number of seconds since 1/1/1970, :unix_zone decimal number denoting the number of seconds since 1/1/1970 plus the utc_offset in the exponent, :xmlschema date-time format taken from XML Schema as a String, :ruby Time.to_s formatted String.
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 load.
386
- * - *:second_precision* [_Fixnum_|_nil_] number of digits after the decimal when dumping the seconds portion of time.
387
- * - *:float_precision* [_Fixnum_|_nil_] number of digits of precision when dumping floats, 0 indicates use Ruby.
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 Exception.
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 true (allow).
395
- * - *:allow_invalid_unicode* [_Boolean_|_nil_] allow invalid unicode, default is false (don't allow).
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 fields.
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 compat mode. :null places a null, :huge places a huge number, :word places Infinity or NaN, :raise raises and exception, :auto uses default for each mode.
402
- * - *:hash_class* [_Class_|_nil_] Class to use instead of Hash on load, :object_class can also be used.
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 dumping in object or custom mode.
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
- oj_parse_options(VALUE ropts, Options copts) {
421
- struct _yesNoOpt ynos[] = {
422
- { circular_sym, &copts->circular },
423
- { auto_define_sym, &copts->auto_define },
424
- { symbol_keys_sym, &copts->sym_key },
425
- { class_cache_sym, &copts->class_cache },
426
- { bigdecimal_as_decimal_sym, &copts->bigdec_as_num },
427
- { use_to_hash_sym, &copts->to_hash },
428
- { use_to_json_sym, &copts->to_json },
429
- { use_as_json_sym, &copts->as_json },
430
- { use_raw_json_sym, &copts->raw_json },
431
- { nilnil_sym, &copts->nilnil },
432
- { allow_blank_sym, &copts->nilnil }, // same as nilnil
433
- { empty_string_sym, &copts->empty_string },
434
- { allow_gc_sym, &copts->allow_gc },
435
- { oj_quirks_mode_sym, &copts->quirks_mode },
436
- { allow_invalid_unicode_sym, &copts->allow_invalid },
437
- { oj_allow_nan_sym, &copts->allow_nan },
438
- { oj_trace_sym, &copts->trace },
439
- { oj_safe_sym, &copts->safe },
440
- { ignore_under_sym, &copts->ignore_under },
441
- { oj_create_additions_sym, &copts->create_ok },
442
- { Qnil, 0 }
443
- };
444
- YesNoOpt o;
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
- return;
613
+ return;
450
614
  }
451
615
  if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_indent_sym)) {
452
- v = rb_hash_lookup(ropts, oj_indent_sym);
453
- switch (rb_type(v)) {
454
- case T_NIL:
455
- copts->dump_opts.indent_size = 0;
456
- *copts->dump_opts.indent_str = '\0';
457
- copts->indent = 0;
458
- break;
459
- case T_FIXNUM:
460
- copts->dump_opts.indent_size = 0;
461
- *copts->dump_opts.indent_str = '\0';
462
- copts->indent = FIX2INT(v);
463
- break;
464
- case T_STRING:
465
- if (sizeof(copts->dump_opts.indent_str) <= (len = RSTRING_LEN(v))) {
466
- rb_raise(rb_eArgError, "indent string is limited to %lu characters.", (unsigned long)sizeof(copts->dump_opts.indent_str));
467
- }
468
- strcpy(copts->dump_opts.indent_str, StringValuePtr(v));
469
- copts->dump_opts.indent_size = (uint8_t)len;
470
- copts->indent = 0;
471
- break;
472
- default:
473
- rb_raise(rb_eTypeError, "indent must be a Fixnum, String, or nil.");
474
- break;
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
- int n;
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
- if (rb_cInteger != rb_obj_class(v)) {
482
- rb_raise(rb_eArgError, ":float_precision must be a Integer.");
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
- if (T_FIXNUM != rb_type(v)) {
486
- rb_raise(rb_eArgError, ":float_precision must be a Fixnum.");
487
- }
673
+ if (T_FIXNUM != rb_type(v)) {
674
+ rb_raise(rb_eArgError, ":cache_str must be a Fixnum.");
675
+ }
488
676
  #endif
489
- n = FIX2INT(v);
490
- if (0 >= n) {
491
- *copts->float_fmt = '\0';
492
- copts->float_prec = 0;
493
- } else {
494
- if (20 < n) {
495
- n = 20;
496
- }
497
- sprintf(copts->float_fmt, "%%0.%dg", n);
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
- int n;
688
+ int n;
503
689
 
504
690
  #ifdef RUBY_INTEGER_UNIFICATION
505
- if (rb_cInteger != rb_obj_class(v)) {
506
- rb_raise(rb_eArgError, ":second_precision must be a Integer.");
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
- if (T_FIXNUM != rb_type(v)) {
510
- rb_raise(rb_eArgError, ":second_precision must be a Fixnum.");
511
- }
695
+ if (T_FIXNUM != rb_type(v)) {
696
+ rb_raise(rb_eArgError, ":second_precision must be a Fixnum.");
697
+ }
512
698
  #endif
513
- n = NUM2INT(v);
514
- if (0 > n) {
515
- n = 0;
516
- copts->sec_prec_set = false;
517
- } else if (9 < n) {
518
- n = 9;
519
- copts->sec_prec_set = true;
520
- } else {
521
- copts->sec_prec_set = true;
522
- }
523
- copts->sec_prec = n;
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
- if (wab_sym == v) {
527
- copts->mode = WabMode;
528
- } else if (object_sym == v) {
529
- copts->mode = ObjectMode;
530
- } else if (strict_sym == v) {
531
- copts->mode = StrictMode;
532
- } else if (compat_sym == v || json_sym == v) {
533
- copts->mode = CompatMode;
534
- } else if (null_sym == v) {
535
- copts->mode = NullMode;
536
- } else if (custom_sym == v) {
537
- copts->mode = CustomMode;
538
- } else if (rails_sym == v) {
539
- copts->mode = RailsMode;
540
- } else {
541
- rb_raise(rb_eArgError, ":mode must be :object, :strict, :compat, :null, :custom, :rails, or :wab.");
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
- if (unix_sym == v) {
546
- copts->time_format = UnixTime;
547
- } else if (unix_zone_sym == v) {
548
- copts->time_format = UnixZTime;
549
- } else if (xmlschema_sym == v) {
550
- copts->time_format = XmlTime;
551
- } else if (ruby_sym == v) {
552
- copts->time_format = RubyTime;
553
- } else {
554
- rb_raise(rb_eArgError, ":time_format must be :unix, :unix_zone, :xmlschema, or :ruby.");
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
- if (newline_sym == v) {
559
- copts->escape_mode = NLEsc;
560
- } else if (json_sym == v) {
561
- copts->escape_mode = JSONEsc;
562
- } else if (xss_safe_sym == v) {
563
- copts->escape_mode = XSSEsc;
564
- } else if (ascii_sym == v) {
565
- copts->escape_mode = ASCIIEsc;
566
- } else if (unicode_xss_sym == v) {
567
- copts->escape_mode = JXEsc;
568
- } else {
569
- rb_raise(rb_eArgError, ":encoding must be :newline, :json, :xss_safe, :unicode_xss, or :ascii.");
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
- if (bigdecimal_sym == v || Qtrue == v) {
574
- copts->bigdec_load = BigDec;
575
- } else if (float_sym == v) {
576
- copts->bigdec_load = FloatDec;
577
- } else if (auto_sym == v || Qfalse == v) {
578
- copts->bigdec_load = AutoDec;
579
- } else {
580
- rb_raise(rb_eArgError, ":bigdecimal_load must be :bigdecimal, :float, or :auto.");
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
- v = rb_hash_lookup(ropts, create_id_sym);
585
- if (Qnil == v) {
586
- if (oj_json_class != oj_default_options.create_id && NULL != copts->create_id) {
587
- xfree((char*)oj_default_options.create_id);
588
- }
589
- copts->create_id = NULL;
590
- copts->create_id_len = 0;
591
- } else if (T_STRING == rb_type(v)) {
592
- const char *str = StringValuePtr(v);
593
-
594
- len = RSTRING_LEN(v);
595
- if (len != copts->create_id_len ||
596
- 0 != strcmp(copts->create_id, str)) {
597
- copts->create_id = ALLOC_N(char, len + 1);
598
- strcpy((char*)copts->create_id, str);
599
- copts->create_id_len = len;
600
- }
601
- } else {
602
- rb_raise(rb_eArgError, ":create_id must be string.");
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
- if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, o->sym)) {
607
- v = rb_hash_lookup(ropts, o->sym);
608
- if (Qnil == v) {
609
- *o->attr = NotSet;
610
- } else if (Qtrue == v) {
611
- *o->attr = Yes;
612
- } else if (Qfalse == v) {
613
- *o->attr = No;
614
- } else {
615
- rb_raise(rb_eArgError, "%s must be true, false, or nil.", rb_id2name(SYM2ID(o->sym)));
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
- if (Qnil == (v = rb_hash_lookup(ropts, oj_space_sym))) {
621
- copts->dump_opts.after_size = 0;
622
- *copts->dump_opts.after_sep = '\0';
623
- } else {
624
- rb_check_type(v, T_STRING);
625
- if (sizeof(copts->dump_opts.after_sep) <= (len = RSTRING_LEN(v))) {
626
- rb_raise(rb_eArgError, "space string is limited to %lu characters.", (unsigned long)sizeof(copts->dump_opts.after_sep));
627
- }
628
- strcpy(copts->dump_opts.after_sep, StringValuePtr(v));
629
- copts->dump_opts.after_size = (uint8_t)len;
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
- if (Qnil == (v = rb_hash_lookup(ropts, oj_space_before_sym))) {
634
- copts->dump_opts.before_size = 0;
635
- *copts->dump_opts.before_sep = '\0';
636
- } else {
637
- rb_check_type(v, T_STRING);
638
- if (sizeof(copts->dump_opts.before_sep) <= (len = RSTRING_LEN(v))) {
639
- rb_raise(rb_eArgError, "sapce_before string is limited to %lu characters.", (unsigned long)sizeof(copts->dump_opts.before_sep));
640
- }
641
- strcpy(copts->dump_opts.before_sep, StringValuePtr(v));
642
- copts->dump_opts.before_size = (uint8_t)len;
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
- if (Qnil == (v = rb_hash_lookup(ropts, oj_object_nl_sym))) {
647
- copts->dump_opts.hash_size = 0;
648
- *copts->dump_opts.hash_nl = '\0';
649
- } else {
650
- rb_check_type(v, T_STRING);
651
- if (sizeof(copts->dump_opts.hash_nl) <= (len = RSTRING_LEN(v))) {
652
- rb_raise(rb_eArgError, "object_nl string is limited to %lu characters.", (unsigned long)sizeof(copts->dump_opts.hash_nl));
653
- }
654
- strcpy(copts->dump_opts.hash_nl, StringValuePtr(v));
655
- copts->dump_opts.hash_size = (uint8_t)len;
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
- if (Qnil == (v = rb_hash_lookup(ropts, oj_array_nl_sym))) {
660
- copts->dump_opts.array_size = 0;
661
- *copts->dump_opts.array_nl = '\0';
662
- } else {
663
- rb_check_type(v, T_STRING);
664
- if (sizeof(copts->dump_opts.array_nl) <= (len = RSTRING_LEN(v))) {
665
- rb_raise(rb_eArgError, "array_nl string is limited to %lu characters.", (unsigned long)sizeof(copts->dump_opts.array_nl));
666
- }
667
- strcpy(copts->dump_opts.array_nl, StringValuePtr(v));
668
- copts->dump_opts.array_size = (uint8_t)len;
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
- if (null_sym == v) {
673
- copts->dump_opts.nan_dump = NullNan;
674
- } else if (huge_sym == v) {
675
- copts->dump_opts.nan_dump = HugeNan;
676
- } else if (word_sym == v) {
677
- copts->dump_opts.nan_dump = WordNan;
678
- } else if (raise_sym == v) {
679
- copts->dump_opts.nan_dump = RaiseNan;
680
- } else if (auto_sym == v) {
681
- copts->dump_opts.nan_dump = AutoNan;
682
- } else {
683
- rb_raise(rb_eArgError, ":nan must be :null, :huge, :word, :raise, or :auto.");
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
- 0 < copts->dump_opts.after_size ||
688
- 0 < copts->dump_opts.before_size ||
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
- if (Qtrue == v) {
693
- copts->dump_opts.omit_nil = true;
694
- } else if (Qfalse == v) {
695
- copts->dump_opts.omit_nil = false;
696
- } else {
697
- rb_raise(rb_eArgError, ":omit_nil must be true or false.");
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
- copts->escape_mode = ASCIIEsc;
913
+ copts->escape_mode = ASCIIEsc;
704
914
  } else if (Qfalse == v) {
705
- copts->escape_mode = JSONEsc;
915
+ copts->escape_mode = JSONEsc;
706
916
  }
707
917
  if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_hash_class_sym)) {
708
- if (Qnil == (v = rb_hash_lookup(ropts, oj_hash_class_sym))) {
709
- copts->hash_class = Qnil;
710
- } else {
711
- rb_check_type(v, T_CLASS);
712
- copts->hash_class = v;
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
- if (Qnil == (v = rb_hash_lookup(ropts, oj_object_class_sym))) {
717
- copts->hash_class = Qnil;
718
- } else {
719
- rb_check_type(v, T_CLASS);
720
- copts->hash_class = v;
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
- if (Qnil == (v = rb_hash_lookup(ropts, oj_array_class_sym))) {
725
- copts->array_class = Qnil;
726
- } else {
727
- rb_check_type(v, T_CLASS);
728
- copts->array_class = v;
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
- xfree(copts->ignore);
734
- copts->ignore = NULL;
735
- if (Qnil != (v = rb_hash_lookup(ropts, ignore_sym))) {
736
- int cnt;
737
-
738
- rb_check_type(v, T_ARRAY);
739
- cnt = (int)RARRAY_LEN(v);
740
- if (0 < cnt) {
741
- int i;
742
-
743
- copts->ignore = ALLOC_N(VALUE, cnt + 1);
744
- for (i = 0; i < cnt; i++) {
745
- copts->ignore[i] = rb_ary_entry(v, i);
746
- }
747
- copts->ignore[i] = Qnil;
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
- if (TYPE(v) == T_STRUCT && rb_obj_class(v) == rb_cRange) {
753
- VALUE min = rb_funcall(v, oj_begin_id, 0);
754
- VALUE max = rb_funcall(v, oj_end_id, 0);
755
-
756
- if (TYPE(min) != T_FIXNUM || TYPE(max) != T_FIXNUM) {
757
- rb_raise(rb_eArgError, ":integer_range range bounds is not Fixnum.");
758
- }
759
-
760
- copts->int_range_min = FIX2LONG(min);
761
- copts->int_range_max = FIX2LONG(max);
762
- } else if (Qfalse != v) {
763
- rb_raise(rb_eArgError, ":integer_range must be a range of Fixnum.");
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
- match_string_cb(VALUE key, VALUE value, VALUE rx) {
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
- rb_raise(rb_eArgError, "for :match_string, the hash values must be a Class.");
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
- if (0 != oj_rxclass_append(rc, StringValuePtr(key), value)) {
781
- rb_raise(rb_eArgError, "%s", rc->err);
782
- }
783
- break;
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
- rb_raise(rb_eArgError, "for :match_string, keys must either a String or RegExp.");
786
- break;
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
- oj_parse_opt_match_string(RxClass rc, VALUE ropts) {
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
- rb_check_type(v, T_HASH);
797
- // Zero out rc. Pattern are not appended but override.
798
- rc->head = NULL;
799
- rc->tail = NULL;
800
- *rc->err = '\0';
801
- rb_hash_foreach(v, match_string_cb, (VALUE)rc);
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
- load(int argc, VALUE *argv, VALUE self) {
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
- rb_raise(rb_eArgError, "Wrong number of arguments to load().");
1047
+ rb_raise(rb_eArgError, "Wrong number of arguments to load().");
843
1048
  }
844
1049
  if (2 <= argc) {
845
- VALUE ropts = argv[1];
846
- VALUE v;
847
-
848
- if (Qnil != ropts || CompatMode != mode) {
849
- Check_Type(ropts, T_HASH);
850
- if (Qnil != (v = rb_hash_lookup(ropts, mode_sym))) {
851
- if (object_sym == v) {
852
- mode = ObjectMode;
853
- } else if (strict_sym == v) {
854
- mode = StrictMode;
855
- } else if (compat_sym == v || json_sym == v) {
856
- mode = CompatMode;
857
- } else if (null_sym == v) {
858
- mode = NullMode;
859
- } else if (custom_sym == v) {
860
- mode = CustomMode;
861
- } else if (rails_sym == v) {
862
- mode = RailsMode;
863
- } else if (wab_sym == v) {
864
- mode = WabMode;
865
- } else {
866
- rb_raise(rb_eArgError, ":mode must be :object, :strict, :compat, :null, :custom, :rails, or :wab.");
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
- return oj_compat_parse(argc, argv, self);
878
- case CustomMode:
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
- load_file(int argc, VALUE *argv, VALUE self) {
925
- char *path;
926
- int fd;
927
- Mode mode = oj_default_options.mode;
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
- rb_raise(rb_eArgError, "Wrong number of arguments to load().");
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 = oj_default_options;
936
- pi.handler = Qnil;
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
- VALUE ropts = argv[1];
941
- VALUE v;
942
-
943
- Check_Type(ropts, T_HASH);
944
- if (Qnil != (v = rb_hash_lookup(ropts, mode_sym))) {
945
- if (object_sym == v) {
946
- mode = ObjectMode;
947
- } else if (strict_sym == v) {
948
- mode = StrictMode;
949
- } else if (compat_sym == v || json_sym == v) {
950
- mode = CompatMode;
951
- } else if (null_sym == v) {
952
- mode = NullMode;
953
- } else if (custom_sym == v) {
954
- mode = CustomMode;
955
- } else if (rails_sym == v) {
956
- mode = RailsMode;
957
- } else if (wab_sym == v) {
958
- mode = WabMode;
959
- } else {
960
- rb_raise(rb_eArgError, ":mode must be :object, :strict, :compat, :null, :custom, :rails, or :wab.");
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
- rb_raise(rb_eIOError, "%s", strerror(errno));
1169
+ rb_raise(rb_eIOError, "%s", strerror(errno));
967
1170
  }
968
1171
  switch (mode) {
969
1172
  case StrictMode:
970
- case NullMode:
971
- oj_set_strict_callbacks(&pi);
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
- oj_set_compat_callbacks(&pi);
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
- safe_load(VALUE self, VALUE doc) {
1005
- struct _parseInfo pi;
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 = Qnil;
1010
- pi.max_depth = 0;
1011
- pi.options = oj_default_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 = No;
1014
- pi.options.mode = StrictMode;
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
- dump(int argc, VALUE *argv, VALUE self) {
1056
- char buf[4096];
1057
- struct _out out;
1058
- struct _options copts = oj_default_options;
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
- rb_raise(rb_eArgError, "wrong number of arguments (0 for 1).");
1254
+ rb_raise(rb_eArgError, "wrong number of arguments (0 for 1).");
1063
1255
  }
1064
1256
  if (CompatMode == copts.mode) {
1065
- copts.dump_opts.nan_dump = WordNan;
1257
+ copts.dump_opts.nan_dump = WordNan;
1066
1258
  }
1067
1259
  if (2 == argc) {
1068
- oj_parse_options(argv[1], &copts);
1260
+ oj_parse_options(argv[1], &copts);
1069
1261
  }
1070
1262
  if (CompatMode == copts.mode && copts.escape_mode != ASCIIEsc) {
1071
- copts.escape_mode = JSONEsc;
1263
+ copts.escape_mode = JSONEsc;
1072
1264
  }
1073
- out.buf = buf;
1074
- out.end = buf + sizeof(buf) - 10;
1265
+ out.buf = buf;
1266
+ out.end = buf + sizeof(buf) - 10;
1075
1267
  out.allocated = false;
1076
- out.omit_nil = copts.dump_opts.omit_nil;
1077
- out.caller = CALLER_DUMP;
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
- rb_raise(rb_eNoMemError, "Not enough memory.");
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
- xfree(out.buf);
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 references is available but is not compatible with the json gem., default is false
1098
- * - *:allow_nan* [_boolean_] If true non JSON compliant words such as Nan and Infinity will be used as appropriate, default is true.
1099
- * - *:quirks_mode* [_boolean_] Allow single JSON values instead of documents, default is true (allow).
1100
- * - *:indent* [_String_|_nil_] String to use for indentation, overriding the indent option if not nil.
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 fields.
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
- to_json(int argc, VALUE *argv, VALUE self) {
1111
- char buf[4096];
1112
- struct _out out;
1113
- struct _options copts = oj_default_options;
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
- rb_raise(rb_eArgError, "wrong number of arguments (0 for 1).");
1313
+ rb_raise(rb_eArgError, "wrong number of arguments (0 for 1).");
1118
1314
  }
1119
- copts.escape_mode = JXEsc;
1315
+ copts.escape_mode = JXEsc;
1120
1316
  copts.dump_opts.nan_dump = RaiseNan;
1121
1317
  if (2 == argc) {
1122
- oj_parse_mimic_dump_options(argv[1], &copts);
1318
+ oj_parse_mimic_dump_options(argv[1], &copts);
1123
1319
  }
1124
- copts.mode = CompatMode;
1320
+ copts.mode = CompatMode;
1125
1321
  copts.to_json = Yes;
1126
- out.buf = buf;
1127
- out.end = buf + sizeof(buf) - 10;
1322
+ out.buf = buf;
1323
+ out.end = buf + sizeof(buf) - 10;
1128
1324
  out.allocated = false;
1129
- out.omit_nil = copts.dump_opts.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
- rb_raise(rb_eNoMemError, "Not enough memory.");
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
- xfree(out.buf);
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
- to_file(int argc, VALUE *argv, VALUE self) {
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
- oj_parse_options(argv[2], &copts);
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
- to_stream(int argc, VALUE *argv, VALUE self) {
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
- oj_parse_options(argv[2], &copts);
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 given all the member values in the order specified.
1202
- * - *members* [_Symbol__|_String_] methods used to get the member values from instances of the clas.
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
- rb_raise(rb_eArgError, "incorrect number of arguments.");
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
- break;
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
- rb_raise(rb_eArgError, "too many members.");
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 given all the member values in the order specified.
1240
- * - *dump_method* [_Symbol_|_String_] method to call on the object being serialized to generate the raw JSON.
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
- rb_raise(rb_eArgError, "incorrect number of arguments.");
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
- break;
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
- rb_raise(rb_eArgError, "too many members.");
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 oj_strict_parse(int argc, VALUE *argv, VALUE self);
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 oj_compat_parse(int argc, VALUE *argv, VALUE self);
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 oj_object_parse(int argc, VALUE *argv, VALUE self);
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 oj_wab_parse(int argc, VALUE *argv, VALUE self);
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 oj_add_to_json(int argc, VALUE *argv, VALUE self);
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 oj_remove_to_json(int argc, VALUE *argv, VALUE self);
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 oj_define_mimic_json(int argc, VALUE *argv, VALUE self);
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. Note JSON.generate does support this even if it is not documented.
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 oj_mimic_generate(int argc, VALUE *argv, VALUE self);
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 oj_optimize_rails(VALUE self);
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
- Init_oj() {
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 = rb_intern("add_value");
1579
- oj_array_append_id = rb_intern("array_append");
1580
- oj_array_end_id = rb_intern("array_end");
1581
- oj_array_start_id = rb_intern("array_start");
1582
- oj_as_json_id = rb_intern("as_json");
1583
- oj_begin_id = rb_intern("begin");
1584
- oj_bigdecimal_id = rb_intern("BigDecimal");
1585
- oj_end_id = rb_intern("end");
1586
- oj_error_id = rb_intern("error");
1587
- oj_exclude_end_id = rb_intern("exclude_end?");
1588
- oj_file_id = rb_intern("file?");
1589
- oj_fileno_id = rb_intern("fileno");
1590
- oj_ftype_id = rb_intern("ftype");
1591
- oj_has_key_id = rb_intern("has_key?");
1592
- oj_hash_end_id = rb_intern("hash_end");
1593
- oj_hash_key_id = rb_intern("hash_key");
1594
- oj_hash_set_id = rb_intern("hash_set");
1595
- oj_hash_start_id = rb_intern("hash_start");
1596
- oj_iconv_id = rb_intern("iconv");
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 = rb_intern("json_create");
1599
- oj_length_id = rb_intern("length");
1600
- oj_new_id = rb_intern("new");
1601
- oj_parse_id = rb_intern("parse");
1602
- oj_pos_id = rb_intern("pos");
1603
- oj_raw_json_id = rb_intern("raw_json");
1604
- oj_read_id = rb_intern("read");
1605
- oj_readpartial_id = rb_intern("readpartial");
1606
- oj_replace_id = rb_intern("replace");
1607
- oj_stat_id = rb_intern("stat");
1608
- oj_string_id = rb_intern("string");
1609
- oj_to_h_id = rb_intern("to_h");
1610
- oj_to_hash_id = rb_intern("to_hash");
1611
- oj_to_json_id = rb_intern("to_json");
1612
- oj_to_s_id = rb_intern("to_s");
1613
- oj_to_sym_id = rb_intern("to_sym");
1614
- oj_to_time_id = rb_intern("to_time");
1615
- oj_tv_nsec_id = rb_intern("tv_nsec");
1616
- oj_tv_sec_id = rb_intern("tv_sec");
1617
- oj_tv_usec_id = rb_intern("tv_usec");
1618
- oj_utc_id = rb_intern("utc");
1619
- oj_utc_offset_id = rb_intern("utc_offset");
1620
- oj_utcq_id = rb_intern("utc?");
1621
- oj_write_id = rb_intern("write");
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
- oj_json_parser_error_class = rb_eEncodingError; // replaced if mimic is called
1638
- oj_json_generator_error_class = rb_eEncodingError; // replaced if mimic is called
1639
-
1640
- allow_blank_sym = ID2SYM(rb_intern("allow_blank")); rb_gc_register_address(&allow_blank_sym);
1641
- allow_gc_sym = ID2SYM(rb_intern("allow_gc")); rb_gc_register_address(&allow_gc_sym);
1642
- allow_invalid_unicode_sym = ID2SYM(rb_intern("allow_invalid_unicode"));rb_gc_register_address(&allow_invalid_unicode_sym);
1643
- ascii_sym = ID2SYM(rb_intern("ascii")); rb_gc_register_address(&ascii_sym);
1644
- auto_define_sym = ID2SYM(rb_intern("auto_define")); rb_gc_register_address(&auto_define_sym);
1645
- auto_sym = ID2SYM(rb_intern("auto")); rb_gc_register_address(&auto_sym);
1646
- bigdecimal_as_decimal_sym = ID2SYM(rb_intern("bigdecimal_as_decimal"));rb_gc_register_address(&bigdecimal_as_decimal_sym);
1647
- bigdecimal_load_sym = ID2SYM(rb_intern("bigdecimal_load")); rb_gc_register_address(&bigdecimal_load_sym);
1648
- bigdecimal_sym = ID2SYM(rb_intern("bigdecimal")); rb_gc_register_address(&bigdecimal_sym);
1649
- circular_sym = ID2SYM(rb_intern("circular")); rb_gc_register_address(&circular_sym);
1650
- class_cache_sym = ID2SYM(rb_intern("class_cache")); rb_gc_register_address(&class_cache_sym);
1651
- compat_sym = ID2SYM(rb_intern("compat")); rb_gc_register_address(&compat_sym);
1652
- create_id_sym = ID2SYM(rb_intern("create_id")); rb_gc_register_address(&create_id_sym);
1653
- custom_sym = ID2SYM(rb_intern("custom")); rb_gc_register_address(&custom_sym);
1654
- empty_string_sym = ID2SYM(rb_intern("empty_string")); rb_gc_register_address(&empty_string_sym);
1655
- escape_mode_sym = ID2SYM(rb_intern("escape_mode")); rb_gc_register_address(&escape_mode_sym);
1656
- integer_range_sym = ID2SYM(rb_intern("integer_range")); rb_gc_register_address(&integer_range_sym);
1657
- float_prec_sym = ID2SYM(rb_intern("float_precision")); rb_gc_register_address(&float_prec_sym);
1658
- float_sym = ID2SYM(rb_intern("float")); rb_gc_register_address(&float_sym);
1659
- huge_sym = ID2SYM(rb_intern("huge")); rb_gc_register_address(&huge_sym);
1660
- ignore_sym = ID2SYM(rb_intern("ignore")); rb_gc_register_address(&ignore_sym);
1661
- ignore_under_sym = ID2SYM(rb_intern("ignore_under")); rb_gc_register_address(&ignore_under_sym);
1662
- json_sym = ID2SYM(rb_intern("json")); rb_gc_register_address(&json_sym);
1663
- match_string_sym = ID2SYM(rb_intern("match_string")); rb_gc_register_address(&match_string_sym);
1664
- mode_sym = ID2SYM(rb_intern("mode")); rb_gc_register_address(&mode_sym);
1665
- nan_sym = ID2SYM(rb_intern("nan")); rb_gc_register_address(&nan_sym);
1666
- newline_sym = ID2SYM(rb_intern("newline")); rb_gc_register_address(&newline_sym);
1667
- nilnil_sym = ID2SYM(rb_intern("nilnil")); rb_gc_register_address(&nilnil_sym);
1668
- null_sym = ID2SYM(rb_intern("null")); rb_gc_register_address(&null_sym);
1669
- object_sym = ID2SYM(rb_intern("object")); rb_gc_register_address(&object_sym);
1670
- oj_allow_nan_sym = ID2SYM(rb_intern("allow_nan")); rb_gc_register_address(&oj_allow_nan_sym);
1671
- oj_array_class_sym = ID2SYM(rb_intern("array_class")); rb_gc_register_address(&oj_array_class_sym);
1672
- oj_array_nl_sym = ID2SYM(rb_intern("array_nl")); rb_gc_register_address(&oj_array_nl_sym);
1673
- oj_ascii_only_sym = ID2SYM(rb_intern("ascii_only")); rb_gc_register_address(&oj_ascii_only_sym);
1674
- oj_create_additions_sym = ID2SYM(rb_intern("create_additions"));rb_gc_register_address(&oj_create_additions_sym);
1675
- oj_hash_class_sym = ID2SYM(rb_intern("hash_class")); rb_gc_register_address(&oj_hash_class_sym);
1676
- oj_indent_sym = ID2SYM(rb_intern("indent")); rb_gc_register_address(&oj_indent_sym);
1677
- oj_max_nesting_sym = ID2SYM(rb_intern("max_nesting")); rb_gc_register_address(&oj_max_nesting_sym);
1678
- oj_object_class_sym = ID2SYM(rb_intern("object_class")); rb_gc_register_address(&oj_object_class_sym);
1679
- oj_object_nl_sym = ID2SYM(rb_intern("object_nl")); rb_gc_register_address(&oj_object_nl_sym);
1680
- oj_quirks_mode_sym = ID2SYM(rb_intern("quirks_mode")); rb_gc_register_address(&oj_quirks_mode_sym);
1681
- oj_safe_sym = ID2SYM(rb_intern("safe")); rb_gc_register_address(&oj_safe_sym);
1682
- oj_space_before_sym = ID2SYM(rb_intern("space_before")); rb_gc_register_address(&oj_space_before_sym);
1683
- oj_space_sym = ID2SYM(rb_intern("space")); rb_gc_register_address(&oj_space_sym);
1684
- oj_trace_sym = ID2SYM(rb_intern("trace")); rb_gc_register_address(&oj_trace_sym);
1685
- omit_nil_sym = ID2SYM(rb_intern("omit_nil")); rb_gc_register_address(&omit_nil_sym);
1686
- rails_sym = ID2SYM(rb_intern("rails")); rb_gc_register_address(&rails_sym);
1687
- raise_sym = ID2SYM(rb_intern("raise")); rb_gc_register_address(&raise_sym);
1688
- ruby_sym = ID2SYM(rb_intern("ruby")); rb_gc_register_address(&ruby_sym);
1689
- sec_prec_sym = ID2SYM(rb_intern("second_precision")); rb_gc_register_address(&sec_prec_sym);
1690
- strict_sym = ID2SYM(rb_intern("strict")); rb_gc_register_address(&strict_sym);
1691
- symbol_keys_sym = ID2SYM(rb_intern("symbol_keys")); rb_gc_register_address(&symbol_keys_sym);
1692
- time_format_sym = ID2SYM(rb_intern("time_format")); rb_gc_register_address(&time_format_sym);
1693
- unicode_xss_sym = ID2SYM(rb_intern("unicode_xss")); rb_gc_register_address(&unicode_xss_sym);
1694
- unix_sym = ID2SYM(rb_intern("unix")); rb_gc_register_address(&unix_sym);
1695
- unix_zone_sym = ID2SYM(rb_intern("unix_zone")); rb_gc_register_address(&unix_zone_sym);
1696
- use_as_json_sym = ID2SYM(rb_intern("use_as_json")); rb_gc_register_address(&use_as_json_sym);
1697
- use_raw_json_sym = ID2SYM(rb_intern("use_raw_json")); rb_gc_register_address(&use_raw_json_sym);
1698
- use_to_hash_sym = ID2SYM(rb_intern("use_to_hash")); rb_gc_register_address(&use_to_hash_sym);
1699
- use_to_json_sym = ID2SYM(rb_intern("use_to_json")); rb_gc_register_address(&use_to_json_sym);
1700
- wab_sym = ID2SYM(rb_intern("wab")); rb_gc_register_address(&wab_sym);
1701
- word_sym = ID2SYM(rb_intern("word")); rb_gc_register_address(&word_sym);
1702
- xmlschema_sym = ID2SYM(rb_intern("xmlschema")); rb_gc_register_address(&xmlschema_sym);
1703
- xss_safe_sym = ID2SYM(rb_intern("xss_safe")); rb_gc_register_address(&xss_safe_sym);
1704
-
1705
- oj_slash_string = rb_str_new2("/"); rb_gc_register_address(&oj_slash_string);
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
- rb_raise(rb_eException, "failed to initialize a mutex. %s", strerror(err));
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();