oj 3.10.18 → 3.11.4

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