oj 2.18.3 → 3.13.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +1324 -0
  3. data/README.md +51 -204
  4. data/RELEASE_NOTES.md +61 -0
  5. data/ext/oj/buf.h +49 -72
  6. data/ext/oj/cache.c +326 -0
  7. data/ext/oj/cache.h +21 -0
  8. data/ext/oj/cache8.c +61 -64
  9. data/ext/oj/cache8.h +12 -39
  10. data/ext/oj/circarray.c +37 -68
  11. data/ext/oj/circarray.h +16 -42
  12. data/ext/oj/code.c +221 -0
  13. data/ext/oj/code.h +40 -0
  14. data/ext/oj/compat.c +231 -107
  15. data/ext/oj/custom.c +1125 -0
  16. data/ext/oj/debug.c +132 -0
  17. data/ext/oj/dump.c +935 -2513
  18. data/ext/oj/dump.h +108 -0
  19. data/ext/oj/dump_compat.c +936 -0
  20. data/ext/oj/dump_leaf.c +164 -0
  21. data/ext/oj/dump_object.c +761 -0
  22. data/ext/oj/dump_strict.c +410 -0
  23. data/ext/oj/encode.h +7 -42
  24. data/ext/oj/encoder.c +43 -0
  25. data/ext/oj/err.c +40 -54
  26. data/ext/oj/err.h +52 -46
  27. data/ext/oj/extconf.rb +21 -30
  28. data/ext/oj/fast.c +1097 -1080
  29. data/ext/oj/intern.c +301 -0
  30. data/ext/oj/intern.h +26 -0
  31. data/ext/oj/mimic_json.c +893 -0
  32. data/ext/oj/object.c +549 -620
  33. data/ext/oj/odd.c +155 -167
  34. data/ext/oj/odd.h +37 -63
  35. data/ext/oj/oj.c +1661 -2063
  36. data/ext/oj/oj.h +341 -270
  37. data/ext/oj/parse.c +974 -737
  38. data/ext/oj/parse.h +105 -97
  39. data/ext/oj/parser.c +1526 -0
  40. data/ext/oj/parser.h +90 -0
  41. data/ext/oj/rails.c +1504 -0
  42. data/ext/oj/rails.h +18 -0
  43. data/ext/oj/reader.c +141 -163
  44. data/ext/oj/reader.h +75 -113
  45. data/ext/oj/resolve.c +45 -93
  46. data/ext/oj/resolve.h +7 -34
  47. data/ext/oj/rxclass.c +143 -0
  48. data/ext/oj/rxclass.h +26 -0
  49. data/ext/oj/saj.c +447 -511
  50. data/ext/oj/saj2.c +348 -0
  51. data/ext/oj/scp.c +91 -138
  52. data/ext/oj/sparse.c +793 -644
  53. data/ext/oj/stream_writer.c +331 -0
  54. data/ext/oj/strict.c +145 -109
  55. data/ext/oj/string_writer.c +493 -0
  56. data/ext/oj/trace.c +72 -0
  57. data/ext/oj/trace.h +28 -0
  58. data/ext/oj/usual.c +1254 -0
  59. data/ext/oj/util.c +136 -0
  60. data/ext/oj/util.h +20 -0
  61. data/ext/oj/val_stack.c +62 -70
  62. data/ext/oj/val_stack.h +95 -129
  63. data/ext/oj/validate.c +51 -0
  64. data/ext/oj/wab.c +622 -0
  65. data/lib/oj/bag.rb +1 -0
  66. data/lib/oj/easy_hash.rb +17 -8
  67. data/lib/oj/error.rb +10 -11
  68. data/lib/oj/json.rb +176 -0
  69. data/lib/oj/mimic.rb +158 -19
  70. data/lib/oj/state.rb +132 -0
  71. data/lib/oj/version.rb +2 -2
  72. data/lib/oj.rb +1 -31
  73. data/pages/Advanced.md +22 -0
  74. data/pages/Compatibility.md +25 -0
  75. data/pages/Custom.md +23 -0
  76. data/pages/Encoding.md +65 -0
  77. data/pages/JsonGem.md +94 -0
  78. data/pages/Modes.md +161 -0
  79. data/pages/Options.md +327 -0
  80. data/pages/Parser.md +309 -0
  81. data/pages/Rails.md +167 -0
  82. data/pages/Security.md +20 -0
  83. data/pages/WAB.md +13 -0
  84. data/test/activerecord/result_test.rb +32 -0
  85. data/test/activesupport4/decoding_test.rb +108 -0
  86. data/test/activesupport4/encoding_test.rb +531 -0
  87. data/test/activesupport4/test_helper.rb +41 -0
  88. data/test/activesupport5/abstract_unit.rb +45 -0
  89. data/test/activesupport5/decoding_test.rb +133 -0
  90. data/test/activesupport5/encoding_test.rb +500 -0
  91. data/test/activesupport5/encoding_test_cases.rb +98 -0
  92. data/test/activesupport5/test_helper.rb +72 -0
  93. data/test/activesupport5/time_zone_test_helpers.rb +39 -0
  94. data/test/activesupport6/abstract_unit.rb +44 -0
  95. data/test/activesupport6/decoding_test.rb +133 -0
  96. data/test/activesupport6/encoding_test.rb +507 -0
  97. data/test/activesupport6/encoding_test_cases.rb +98 -0
  98. data/test/activesupport6/test_common.rb +17 -0
  99. data/test/activesupport6/test_helper.rb +163 -0
  100. data/test/activesupport6/time_zone_test_helpers.rb +39 -0
  101. data/test/activesupport7/abstract_unit.rb +49 -0
  102. data/test/activesupport7/decoding_test.rb +125 -0
  103. data/test/activesupport7/encoding_test.rb +486 -0
  104. data/test/activesupport7/encoding_test_cases.rb +104 -0
  105. data/test/activesupport7/time_zone_test_helpers.rb +47 -0
  106. data/test/bar.rb +9 -0
  107. data/test/baz.rb +16 -0
  108. data/test/bug.rb +11 -46
  109. data/test/foo.rb +69 -16
  110. data/test/helper.rb +10 -1
  111. data/test/isolated/shared.rb +12 -8
  112. data/test/isolated/test_mimic_rails_after.rb +3 -3
  113. data/test/isolated/test_mimic_rails_before.rb +3 -3
  114. data/test/json_gem/json_addition_test.rb +216 -0
  115. data/test/json_gem/json_common_interface_test.rb +153 -0
  116. data/test/json_gem/json_encoding_test.rb +107 -0
  117. data/test/json_gem/json_ext_parser_test.rb +20 -0
  118. data/test/json_gem/json_fixtures_test.rb +35 -0
  119. data/test/json_gem/json_generator_test.rb +397 -0
  120. data/test/json_gem/json_generic_object_test.rb +90 -0
  121. data/test/json_gem/json_parser_test.rb +470 -0
  122. data/test/json_gem/json_string_matching_test.rb +42 -0
  123. data/test/json_gem/test_helper.rb +26 -0
  124. data/test/mem.rb +33 -0
  125. data/test/perf.rb +1 -1
  126. data/test/perf_compat.rb +30 -28
  127. data/test/perf_dump.rb +50 -0
  128. data/test/perf_object.rb +1 -1
  129. data/test/perf_once.rb +58 -0
  130. data/test/perf_parser.rb +189 -0
  131. data/test/perf_scp.rb +11 -10
  132. data/test/perf_strict.rb +30 -19
  133. data/test/perf_wab.rb +131 -0
  134. data/test/prec.rb +23 -0
  135. data/test/sample.rb +0 -1
  136. data/test/sample_json.rb +1 -1
  137. data/test/test_compat.rb +219 -102
  138. data/test/test_custom.rb +533 -0
  139. data/test/test_fast.rb +107 -35
  140. data/test/test_file.rb +19 -25
  141. data/test/test_generate.rb +21 -0
  142. data/test/test_hash.rb +11 -1
  143. data/test/test_integer_range.rb +72 -0
  144. data/test/test_null.rb +376 -0
  145. data/test/test_object.rb +357 -70
  146. data/test/test_parser.rb +27 -0
  147. data/test/test_parser_saj.rb +245 -0
  148. data/test/test_parser_usual.rb +217 -0
  149. data/test/test_rails.rb +35 -0
  150. data/test/test_saj.rb +1 -1
  151. data/test/test_scp.rb +39 -2
  152. data/test/test_strict.rb +186 -7
  153. data/test/test_various.rb +160 -774
  154. data/test/test_wab.rb +307 -0
  155. data/test/test_writer.rb +90 -2
  156. data/test/tests.rb +24 -0
  157. data/test/tests_mimic.rb +14 -0
  158. data/test/tests_mimic_addition.rb +7 -0
  159. data/test/zoo.rb +13 -0
  160. metadata +194 -56
  161. data/ext/oj/hash.c +0 -163
  162. data/ext/oj/hash.h +0 -46
  163. data/ext/oj/hash_test.c +0 -512
  164. data/test/activesupport_datetime_test.rb +0 -23
  165. data/test/bug2.rb +0 -10
  166. data/test/bug3.rb +0 -46
  167. data/test/bug_fast.rb +0 -32
  168. data/test/bug_load.rb +0 -24
  169. data/test/crash.rb +0 -111
  170. data/test/curl/curl_oj.rb +0 -46
  171. data/test/curl/get_oj.rb +0 -24
  172. data/test/curl/just_curl.rb +0 -31
  173. data/test/curl/just_oj.rb +0 -51
  174. data/test/example.rb +0 -11
  175. data/test/io.rb +0 -48
  176. data/test/isolated/test_mimic_rails_datetime.rb +0 -27
  177. data/test/mod.rb +0 -16
  178. data/test/rails.rb +0 -50
  179. data/test/russian.rb +0 -18
  180. data/test/struct.rb +0 -29
  181. data/test/test_serializer.rb +0 -59
  182. data/test/write_timebars.rb +0 -31
data/ext/oj/compat.c CHANGED
@@ -1,155 +1,279 @@
1
- /* compat.c
2
- * Copyright (c) 2012, Peter Ohler
3
- * All rights reserved.
4
- *
5
- * Redistribution and use in source and binary forms, with or without
6
- * modification, are permitted provided that the following conditions are met:
7
- *
8
- * - Redistributions of source code must retain the above copyright notice, this
9
- * list of conditions and the following disclaimer.
10
- *
11
- * - Redistributions in binary form must reproduce the above copyright notice,
12
- * this list of conditions and the following disclaimer in the documentation
13
- * and/or other materials provided with the distribution.
14
- *
15
- * - Neither the name of Peter Ohler nor the names of its contributors may be
16
- * used to endorse or promote products derived from this software without
17
- * specific prior written permission.
18
- *
19
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
- */
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.
30
3
 
31
4
  #include <stdio.h>
32
5
 
33
- #include "oj.h"
6
+ #include "encode.h"
34
7
  #include "err.h"
8
+ #include "intern.h"
9
+ #include "oj.h"
35
10
  #include "parse.h"
36
11
  #include "resolve.h"
37
- #include "hash.h"
38
- #include "encode.h"
12
+ #include "trace.h"
39
13
 
40
- static void
41
- hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
42
- const char *key = kval->key;
43
- int klen = kval->klen;
44
- Val parent = stack_peek(&pi->stack);
45
- volatile VALUE rkey = kval->key_val;
46
-
47
- if (Qundef == rkey &&
48
- 0 != pi->options.create_id &&
49
- *pi->options.create_id == *key &&
50
- (int)pi->options.create_id_len == klen &&
51
- 0 == strncmp(pi->options.create_id, key, klen)) {
52
- parent->classname = oj_strndup(str, len);
53
- parent->clen = len;
14
+ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
15
+ const char * key = kval->key;
16
+ int klen = kval->klen;
17
+ Val parent = stack_peek(&pi->stack);
18
+ volatile VALUE rkey = kval->key_val;
19
+
20
+ if (Qundef == rkey && Yes == pi->options.create_ok && NULL != pi->options.create_id &&
21
+ *pi->options.create_id == *key && (int)pi->options.create_id_len == klen &&
22
+ 0 == strncmp(pi->options.create_id, key, klen)) {
23
+ parent->classname = oj_strndup(str, len);
24
+ parent->clen = len;
54
25
  } else {
55
- volatile VALUE rstr = rb_str_new(str, len);
56
-
57
- if (Qundef == rkey) {
58
- rkey = rb_str_new(key, klen);
59
- rstr = oj_encode(rstr);
60
- rkey = oj_encode(rkey);
61
- if (Yes == pi->options.sym_key) {
62
- rkey = rb_str_intern(rkey);
63
- }
64
- }
65
- rb_hash_aset(parent->val, rkey, rstr);
26
+ volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
27
+
28
+ if (Qundef == rkey) {
29
+ if (Yes != pi->options.cache_keys) {
30
+ if (Yes == pi->options.sym_key) {
31
+ rkey = ID2SYM(rb_intern3(key, klen, oj_utf8_encoding));
32
+ } else {
33
+ rkey = rb_utf8_str_new(key, klen);
34
+ }
35
+ } else if (Yes == pi->options.sym_key) {
36
+ rkey = oj_sym_intern(key, klen);
37
+ } else {
38
+ rkey = oj_str_intern(key, klen);
39
+ }
40
+ }
41
+ if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
42
+ VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
43
+
44
+ if (Qnil != clas) {
45
+ rstr = rb_funcall(clas, oj_json_create_id, 1, rstr);
46
+ }
47
+ }
48
+ if (rb_cHash != rb_obj_class(parent->val)) {
49
+ // The rb_hash_set would still work but the unit tests for the
50
+ // json gem require the less efficient []= method be called to set
51
+ // values. Even using the store method to set the values will fail
52
+ // the unit tests.
53
+ rb_funcall(parent->val, rb_intern("[]="), 2, rkey, rstr);
54
+ } else {
55
+ rb_hash_aset(parent->val, rkey, rstr);
56
+ }
57
+ if (Yes == pi->options.trace) {
58
+ oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rstr);
59
+ }
60
+ }
61
+ }
62
+
63
+ static VALUE start_hash(ParseInfo pi) {
64
+ volatile VALUE h;
65
+
66
+ if (Qnil != pi->options.hash_class) {
67
+ h = rb_class_new_instance(0, NULL, pi->options.hash_class);
68
+ } else {
69
+ h = rb_hash_new();
70
+ }
71
+ if (Yes == pi->options.trace) {
72
+ oj_trace_parse_in("start_hash", pi, __FILE__, __LINE__);
66
73
  }
74
+ return h;
67
75
  }
68
76
 
69
- static void
70
- end_hash(struct _ParseInfo *pi) {
71
- Val parent = stack_peek(&pi->stack);
77
+ static void end_hash(struct _parseInfo *pi) {
78
+ Val parent = stack_peek(&pi->stack);
72
79
 
73
80
  if (0 != parent->classname) {
74
- VALUE clas;
81
+ volatile VALUE clas;
75
82
 
76
- clas = oj_name2class(pi, parent->classname, parent->clen, 0);
77
- if (Qundef != clas) { // else an error
78
- parent->val = rb_funcall(clas, oj_json_create_id, 1, parent->val);
79
- }
80
- if (0 != parent->classname) {
81
- xfree((char*)parent->classname);
82
- parent->classname = 0;
83
- }
83
+ clas = oj_name2class(pi, parent->classname, parent->clen, 0, rb_eArgError);
84
+ if (Qundef != clas) { // else an error
85
+ ID creatable = rb_intern("json_creatable?");
86
+
87
+ if (!rb_respond_to(clas, creatable) || Qtrue == rb_funcall(clas, creatable, 0)) {
88
+ parent->val = rb_funcall(clas, oj_json_create_id, 1, parent->val);
89
+ }
90
+ }
91
+ if (0 != parent->classname) {
92
+ xfree((char *)parent->classname);
93
+ parent->classname = 0;
94
+ }
95
+ }
96
+ if (Yes == pi->options.trace) {
97
+ oj_trace_parse_hash_end(pi, __FILE__, __LINE__);
84
98
  }
85
99
  }
86
100
 
87
- static VALUE
88
- calc_hash_key(ParseInfo pi, Val parent) {
89
- volatile VALUE rkey = parent->key_val;
101
+ static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
102
+ volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
103
+
104
+ if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
105
+ VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
90
106
 
91
- if (Qundef == rkey) {
92
- rkey = rb_str_new(parent->key, parent->klen);
107
+ if (Qnil != clas) {
108
+ pi->stack.head->val = rb_funcall(clas, oj_json_create_id, 1, rstr);
109
+ return;
110
+ }
93
111
  }
94
- rkey = oj_encode(rkey);
95
- if (Yes == pi->options.sym_key) {
96
- rkey = rb_str_intern(rkey);
112
+ pi->stack.head->val = rstr;
113
+ if (Yes == pi->options.trace) {
114
+ oj_trace_parse_call("add_string", pi, __FILE__, __LINE__, rstr);
97
115
  }
98
- return rkey;
99
116
  }
100
117
 
101
- static void
102
- add_num(ParseInfo pi, NumInfo ni) {
118
+ static void add_num(ParseInfo pi, NumInfo ni) {
103
119
  pi->stack.head->val = oj_num_as_value(ni);
120
+ if (Yes == pi->options.trace) {
121
+ oj_trace_parse_call("add_number", pi, __FILE__, __LINE__, pi->stack.head->val);
122
+ }
104
123
  }
105
124
 
106
- static void
107
- hash_set_num(struct _ParseInfo *pi, Val parent, NumInfo ni) {
108
- rb_hash_aset(stack_peek(&pi->stack)->val, calc_hash_key(pi, parent), oj_num_as_value(ni));
125
+ static void hash_set_num(struct _parseInfo *pi, Val parent, NumInfo ni) {
126
+ volatile VALUE rval = oj_num_as_value(ni);
127
+
128
+ if (!oj_use_hash_alt && rb_cHash != rb_obj_class(parent->val)) {
129
+ // The rb_hash_set would still work but the unit tests for the
130
+ // json gem require the less efficient []= method be called to set
131
+ // values. Even using the store method to set the values will fail
132
+ // the unit tests.
133
+ rb_funcall(stack_peek(&pi->stack)->val,
134
+ rb_intern("[]="),
135
+ 2,
136
+ oj_calc_hash_key(pi, parent),
137
+ rval);
138
+ } else {
139
+ rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), rval);
140
+ }
141
+ if (Yes == pi->options.trace) {
142
+ oj_trace_parse_call("set_number", pi, __FILE__, __LINE__, rval);
143
+ }
109
144
  }
110
145
 
111
- static void
112
- array_append_num(ParseInfo pi, NumInfo ni) {
113
- rb_ary_push(stack_peek(&pi->stack)->val, oj_num_as_value(ni));
146
+ static void hash_set_value(ParseInfo pi, Val parent, VALUE value) {
147
+ if (rb_cHash != rb_obj_class(parent->val)) {
148
+ // The rb_hash_set would still work but the unit tests for the
149
+ // json gem require the less efficient []= method be called to set
150
+ // values. Even using the store method to set the values will fail
151
+ // the unit tests.
152
+ rb_funcall(stack_peek(&pi->stack)->val,
153
+ rb_intern("[]="),
154
+ 2,
155
+ oj_calc_hash_key(pi, parent),
156
+ value);
157
+ } else {
158
+ rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), value);
159
+ }
160
+ if (Yes == pi->options.trace) {
161
+ oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, value);
162
+ }
114
163
  }
115
164
 
165
+ static VALUE start_array(ParseInfo pi) {
166
+ if (Qnil != pi->options.array_class) {
167
+ return rb_class_new_instance(0, NULL, pi->options.array_class);
168
+ }
169
+ if (Yes == pi->options.trace) {
170
+ oj_trace_parse_in("start_array", pi, __FILE__, __LINE__);
171
+ }
172
+ return rb_ary_new();
173
+ }
174
+
175
+ static void array_append_num(ParseInfo pi, NumInfo ni) {
176
+ Val parent = stack_peek(&pi->stack);
177
+ volatile VALUE rval = oj_num_as_value(ni);
178
+
179
+ if (!oj_use_array_alt && rb_cArray != rb_obj_class(parent->val)) {
180
+ // The rb_ary_push would still work but the unit tests for the json
181
+ // gem require the less efficient << method be called to push the
182
+ // values.
183
+ rb_funcall(parent->val, rb_intern("<<"), 1, rval);
184
+ } else {
185
+ rb_ary_push(parent->val, rval);
186
+ }
187
+ if (Yes == pi->options.trace) {
188
+ oj_trace_parse_call("append_number", pi, __FILE__, __LINE__, rval);
189
+ }
190
+ }
191
+
192
+ static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
193
+ volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
194
+
195
+ if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
196
+ VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
197
+
198
+ if (Qnil != clas) {
199
+ rb_ary_push(stack_peek(&pi->stack)->val, rb_funcall(clas, oj_json_create_id, 1, rstr));
200
+ return;
201
+ }
202
+ }
203
+ rb_ary_push(stack_peek(&pi->stack)->val, rstr);
204
+ if (Yes == pi->options.trace) {
205
+ oj_trace_parse_call("append_string", pi, __FILE__, __LINE__, rstr);
206
+ }
207
+ }
116
208
 
117
- void
118
- oj_set_compat_callbacks(ParseInfo pi) {
209
+ void oj_set_compat_callbacks(ParseInfo pi) {
119
210
  oj_set_strict_callbacks(pi);
120
- pi->end_hash = end_hash;
121
- pi->hash_set_cstr = hash_set_cstr;
122
- pi->add_num = add_num;
123
- pi->hash_set_num = hash_set_num;
124
- pi->array_append_num = array_append_num;
211
+ pi->start_hash = start_hash;
212
+ pi->end_hash = end_hash;
213
+ pi->hash_set_cstr = hash_set_cstr;
214
+ pi->hash_set_num = hash_set_num;
215
+ pi->hash_set_value = hash_set_value;
216
+ pi->add_num = add_num;
217
+ pi->add_cstr = add_cstr;
218
+ pi->array_append_cstr = array_append_cstr;
219
+ pi->start_array = start_array;
220
+ pi->array_append_num = array_append_num;
125
221
  }
126
222
 
127
223
  VALUE
128
224
  oj_compat_parse(int argc, VALUE *argv, VALUE self) {
129
- struct _ParseInfo pi;
225
+ struct _parseInfo pi;
226
+
227
+ parse_info_init(&pi);
228
+ pi.options = oj_default_options;
229
+ pi.handler = Qnil;
230
+ pi.err_class = Qnil;
231
+ pi.max_depth = 0;
232
+ pi.options.allow_nan = Yes;
233
+ pi.options.nilnil = Yes;
234
+ pi.options.empty_string = No;
235
+ oj_set_compat_callbacks(&pi);
236
+
237
+ if (T_STRING == rb_type(*argv)) {
238
+ return oj_pi_parse(argc, argv, &pi, 0, 0, false);
239
+ } else {
240
+ return oj_pi_sparse(argc, argv, &pi, 0);
241
+ }
242
+ }
130
243
 
131
- pi.options = oj_default_options;
132
- pi.handler = Qnil;
133
- pi.err_class = Qnil;
244
+ VALUE
245
+ oj_compat_load(int argc, VALUE *argv, VALUE self) {
246
+ struct _parseInfo pi;
247
+
248
+ parse_info_init(&pi);
249
+ pi.options = oj_default_options;
250
+ pi.handler = Qnil;
251
+ pi.err_class = Qnil;
252
+ pi.max_depth = 0;
253
+ pi.options.allow_nan = Yes;
254
+ pi.options.nilnil = Yes;
255
+ pi.options.empty_string = Yes;
134
256
  oj_set_compat_callbacks(&pi);
135
257
 
136
258
  if (T_STRING == rb_type(*argv)) {
137
- return oj_pi_parse(argc, argv, &pi, 0, 0, 1);
259
+ return oj_pi_parse(argc, argv, &pi, 0, 0, false);
138
260
  } else {
139
- return oj_pi_sparse(argc, argv, &pi, 0);
261
+ return oj_pi_sparse(argc, argv, &pi, 0);
140
262
  }
141
263
  }
142
264
 
143
265
  VALUE
144
266
  oj_compat_parse_cstr(int argc, VALUE *argv, char *json, size_t len) {
145
- struct _ParseInfo pi;
267
+ struct _parseInfo pi;
146
268
 
147
- pi.options = oj_default_options;
148
- pi.handler = Qnil;
149
- pi.err_class = Qnil;
150
- oj_set_strict_callbacks(&pi);
151
- pi.end_hash = end_hash;
152
- pi.hash_set_cstr = hash_set_cstr;
269
+ parse_info_init(&pi);
270
+ pi.options = oj_default_options;
271
+ pi.handler = Qnil;
272
+ pi.err_class = Qnil;
273
+ pi.max_depth = 0;
274
+ pi.options.allow_nan = Yes;
275
+ pi.options.nilnil = Yes;
276
+ oj_set_compat_callbacks(&pi);
153
277
 
154
- return oj_pi_parse(argc, argv, &pi, json, len, 1);
278
+ return oj_pi_parse(argc, argv, &pi, json, len, false);
155
279
  }