oj 3.11.2 → 3.11.7

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