oj 3.11.0 → 3.16.5

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 (173) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1421 -0
  3. data/README.md +20 -5
  4. data/RELEASE_NOTES.md +61 -0
  5. data/ext/oj/buf.h +48 -38
  6. data/ext/oj/cache.c +329 -0
  7. data/ext/oj/cache.h +22 -0
  8. data/ext/oj/cache8.c +60 -62
  9. data/ext/oj/cache8.h +8 -7
  10. data/ext/oj/circarray.c +35 -35
  11. data/ext/oj/circarray.h +11 -9
  12. data/ext/oj/code.c +156 -174
  13. data/ext/oj/code.h +19 -18
  14. data/ext/oj/compat.c +140 -197
  15. data/ext/oj/custom.c +737 -879
  16. data/ext/oj/debug.c +126 -0
  17. data/ext/oj/dump.c +830 -835
  18. data/ext/oj/dump.h +65 -53
  19. data/ext/oj/dump_compat.c +566 -642
  20. data/ext/oj/dump_leaf.c +95 -182
  21. data/ext/oj/dump_object.c +518 -659
  22. data/ext/oj/dump_strict.c +301 -334
  23. data/ext/oj/encode.h +3 -4
  24. data/ext/oj/encoder.c +43 -0
  25. data/ext/oj/err.c +27 -24
  26. data/ext/oj/err.h +38 -13
  27. data/ext/oj/extconf.rb +23 -7
  28. data/ext/oj/fast.c +1043 -1073
  29. data/ext/oj/intern.c +313 -0
  30. data/ext/oj/intern.h +22 -0
  31. data/ext/oj/mem.c +318 -0
  32. data/ext/oj/mem.h +53 -0
  33. data/ext/oj/mimic_json.c +449 -423
  34. data/ext/oj/object.c +530 -576
  35. data/ext/oj/odd.c +155 -138
  36. data/ext/oj/odd.h +24 -22
  37. data/ext/oj/oj.c +1331 -993
  38. data/ext/oj/oj.h +306 -292
  39. data/ext/oj/parse.c +934 -938
  40. data/ext/oj/parse.h +73 -70
  41. data/ext/oj/parser.c +1600 -0
  42. data/ext/oj/parser.h +101 -0
  43. data/ext/oj/rails.c +795 -845
  44. data/ext/oj/rails.h +7 -7
  45. data/ext/oj/reader.c +132 -140
  46. data/ext/oj/reader.h +67 -78
  47. data/ext/oj/resolve.c +40 -59
  48. data/ext/oj/resolve.h +3 -2
  49. data/ext/oj/rxclass.c +67 -67
  50. data/ext/oj/rxclass.h +11 -9
  51. data/ext/oj/saj.c +441 -480
  52. data/ext/oj/saj2.c +584 -0
  53. data/ext/oj/saj2.h +23 -0
  54. data/ext/oj/scp.c +78 -111
  55. data/ext/oj/sparse.c +726 -730
  56. data/ext/oj/stream_writer.c +146 -165
  57. data/ext/oj/strict.c +103 -123
  58. data/ext/oj/string_writer.c +241 -253
  59. data/ext/oj/trace.c +29 -33
  60. data/ext/oj/trace.h +41 -11
  61. data/ext/oj/usual.c +1218 -0
  62. data/ext/oj/usual.h +69 -0
  63. data/ext/oj/util.c +103 -103
  64. data/ext/oj/util.h +3 -2
  65. data/ext/oj/val_stack.c +60 -49
  66. data/ext/oj/val_stack.h +79 -85
  67. data/ext/oj/validate.c +46 -0
  68. data/ext/oj/wab.c +307 -350
  69. data/lib/oj/active_support_helper.rb +1 -3
  70. data/lib/oj/bag.rb +8 -1
  71. data/lib/oj/easy_hash.rb +9 -9
  72. data/lib/oj/error.rb +1 -2
  73. data/lib/oj/json.rb +162 -150
  74. data/lib/oj/mimic.rb +9 -19
  75. data/lib/oj/saj.rb +20 -6
  76. data/lib/oj/schandler.rb +5 -4
  77. data/lib/oj/state.rb +12 -8
  78. data/lib/oj/version.rb +1 -2
  79. data/lib/oj.rb +2 -0
  80. data/pages/Compatibility.md +1 -1
  81. data/pages/InstallOptions.md +20 -0
  82. data/pages/JsonGem.md +15 -0
  83. data/pages/Modes.md +8 -3
  84. data/pages/Options.md +43 -5
  85. data/pages/Parser.md +309 -0
  86. data/pages/Rails.md +14 -2
  87. data/test/_test_active.rb +8 -9
  88. data/test/_test_active_mimic.rb +7 -8
  89. data/test/_test_mimic_rails.rb +17 -20
  90. data/test/activerecord/result_test.rb +12 -8
  91. data/test/activesupport6/encoding_test.rb +63 -28
  92. data/test/{activesupport5 → activesupport7}/abstract_unit.rb +16 -12
  93. data/test/{activesupport5 → activesupport7}/decoding_test.rb +2 -10
  94. data/test/{activesupport5 → activesupport7}/encoding_test.rb +86 -50
  95. data/test/{activesupport5 → activesupport7}/encoding_test_cases.rb +6 -0
  96. data/test/{activesupport5 → activesupport7}/time_zone_test_helpers.rb +8 -0
  97. data/test/files.rb +15 -15
  98. data/test/foo.rb +17 -43
  99. data/test/helper.rb +16 -3
  100. data/test/isolated/shared.rb +3 -2
  101. data/test/json_gem/json_addition_test.rb +2 -2
  102. data/test/json_gem/json_common_interface_test.rb +8 -6
  103. data/test/json_gem/json_encoding_test.rb +0 -0
  104. data/test/json_gem/json_ext_parser_test.rb +1 -0
  105. data/test/json_gem/json_fixtures_test.rb +3 -2
  106. data/test/json_gem/json_generator_test.rb +71 -41
  107. data/test/json_gem/json_generic_object_test.rb +11 -11
  108. data/test/json_gem/json_parser_test.rb +54 -47
  109. data/test/json_gem/json_string_matching_test.rb +9 -9
  110. data/test/json_gem/test_helper.rb +12 -0
  111. data/test/mem.rb +34 -0
  112. data/test/perf.rb +22 -27
  113. data/test/perf_compat.rb +31 -33
  114. data/test/perf_dump.rb +50 -0
  115. data/test/perf_fast.rb +80 -82
  116. data/test/perf_file.rb +27 -29
  117. data/test/perf_object.rb +65 -69
  118. data/test/perf_once.rb +59 -0
  119. data/test/perf_parser.rb +183 -0
  120. data/test/perf_saj.rb +46 -54
  121. data/test/perf_scp.rb +58 -69
  122. data/test/perf_simple.rb +41 -39
  123. data/test/perf_strict.rb +74 -82
  124. data/test/perf_wab.rb +67 -69
  125. data/test/prec.rb +5 -5
  126. data/test/sample/change.rb +0 -1
  127. data/test/sample/dir.rb +0 -1
  128. data/test/sample/doc.rb +0 -1
  129. data/test/sample/file.rb +0 -1
  130. data/test/sample/group.rb +0 -1
  131. data/test/sample/hasprops.rb +0 -1
  132. data/test/sample/layer.rb +0 -1
  133. data/test/sample/rect.rb +0 -1
  134. data/test/sample/shape.rb +0 -1
  135. data/test/sample/text.rb +0 -1
  136. data/test/sample.rb +16 -16
  137. data/test/sample_json.rb +8 -8
  138. data/test/test_compat.rb +97 -45
  139. data/test/test_custom.rb +73 -51
  140. data/test/test_debian.rb +7 -10
  141. data/test/test_fast.rb +135 -79
  142. data/test/test_file.rb +41 -30
  143. data/test/test_gc.rb +16 -5
  144. data/test/test_generate.rb +21 -0
  145. data/test/test_hash.rb +15 -5
  146. data/test/test_integer_range.rb +9 -9
  147. data/test/test_null.rb +20 -20
  148. data/test/test_object.rb +99 -96
  149. data/test/test_parser.rb +11 -0
  150. data/test/test_parser_debug.rb +27 -0
  151. data/test/test_parser_saj.rb +337 -0
  152. data/test/test_parser_usual.rb +251 -0
  153. data/test/test_rails.rb +2 -2
  154. data/test/test_saj.rb +10 -8
  155. data/test/test_scp.rb +38 -40
  156. data/test/test_strict.rb +40 -32
  157. data/test/test_various.rb +165 -84
  158. data/test/test_wab.rb +48 -44
  159. data/test/test_writer.rb +47 -47
  160. data/test/tests.rb +13 -5
  161. data/test/tests_mimic.rb +12 -3
  162. data/test/tests_mimic_addition.rb +12 -3
  163. metadata +75 -127
  164. data/ext/oj/hash.c +0 -135
  165. data/ext/oj/hash.h +0 -18
  166. data/ext/oj/hash_test.c +0 -484
  167. data/test/activesupport4/decoding_test.rb +0 -108
  168. data/test/activesupport4/encoding_test.rb +0 -531
  169. data/test/activesupport4/test_helper.rb +0 -41
  170. data/test/activesupport5/test_helper.rb +0 -72
  171. data/test/bar.rb +0 -35
  172. data/test/baz.rb +0 -16
  173. data/test/zoo.rb +0 -13
data/ext/oj/compat.c CHANGED
@@ -1,295 +1,238 @@
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.
2
3
 
3
4
  #include <stdio.h>
4
5
 
5
- #include "oj.h"
6
+ #include "encode.h"
6
7
  #include "err.h"
8
+ #include "intern.h"
9
+ #include "mem.h"
10
+ #include "oj.h"
7
11
  #include "parse.h"
8
12
  #include "resolve.h"
9
- #include "hash.h"
10
- #include "encode.h"
11
13
  #include "trace.h"
12
14
 
13
- static void
14
- 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 &&
21
- Yes == pi->options.create_ok &&
22
- NULL != pi->options.create_id &&
23
- *pi->options.create_id == *key &&
24
- (int)pi->options.create_id_len == klen &&
25
- 0 == strncmp(pi->options.create_id, key, klen)) {
26
-
27
- parent->classname = oj_strndup(str, len);
28
- parent->clen = len;
15
+ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
16
+ const char *key = kval->key;
17
+ int klen = kval->klen;
18
+ Val parent = stack_peek(&pi->stack);
19
+
20
+ if (Qundef == kval->key_val && 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;
29
25
  } else {
30
- volatile VALUE rstr = rb_str_new(str, len);
31
-
32
- if (Qundef == rkey) {
33
- rkey = rb_str_new(key, klen);
34
- rstr = oj_encode(rstr);
35
- rkey = oj_encode(rkey);
36
- if (Yes == pi->options.sym_key) {
37
- rkey = rb_str_intern(rkey);
38
- }
39
- }
40
- if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
41
- VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
42
-
43
- if (Qnil != clas) {
44
- rstr = rb_funcall(clas, oj_json_create_id, 1, rstr);
45
- }
46
- }
47
- if (rb_cHash != rb_obj_class(parent->val)) {
48
- // The rb_hash_set would still work but the unit tests for the
49
- // json gem require the less efficient []= method be called to set
50
- // values. Even using the store method to set the values will fail
51
- // the unit tests.
52
- rb_funcall(parent->val, rb_intern("[]="), 2, rkey, rstr);
53
- } else {
54
- rb_hash_aset(parent->val, rkey, rstr);
55
- }
56
- if (Yes == pi->options.trace) {
57
- oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rstr);
58
- }
26
+ volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
27
+ volatile VALUE rkey = oj_calc_hash_key(pi, kval);
28
+
29
+ if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
30
+ VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
31
+
32
+ if (Qnil != clas) {
33
+ rstr = rb_funcall(clas, oj_json_create_id, 1, rstr);
34
+ }
35
+ }
36
+ if (rb_cHash != rb_obj_class(parent->val)) {
37
+ // The rb_hash_set would still work but the unit tests for the
38
+ // json gem require the less efficient []= method be called to set
39
+ // values. Even using the store method to set the values will fail
40
+ // the unit tests.
41
+ rb_funcall(parent->val, rb_intern("[]="), 2, rkey, rstr);
42
+ } else {
43
+ rb_hash_aset(parent->val, rkey, rstr);
44
+ }
45
+ TRACE_PARSE_CALL(pi->options.trace, "set_string", pi, rstr);
59
46
  }
60
47
  }
61
48
 
62
- static VALUE
63
- start_hash(ParseInfo pi) {
64
- volatile VALUE h;
49
+ static VALUE start_hash(ParseInfo pi) {
50
+ volatile VALUE h;
65
51
 
66
52
  if (Qnil != pi->options.hash_class) {
67
- h = rb_class_new_instance(0, NULL, pi->options.hash_class);
53
+ h = rb_class_new_instance(0, NULL, pi->options.hash_class);
68
54
  } else {
69
- h = rb_hash_new();
70
- }
71
- if (Yes == pi->options.trace) {
72
- oj_trace_parse_in("start_hash", pi, __FILE__, __LINE__);
55
+ h = rb_hash_new();
73
56
  }
57
+ TRACE_PARSE_IN(pi->options.trace, "start_hash", pi);
74
58
  return h;
75
59
  }
76
60
 
77
- static void
78
- end_hash(struct _parseInfo *pi) {
79
- Val parent = stack_peek(&pi->stack);
61
+ static void end_hash(struct _parseInfo *pi) {
62
+ Val parent = stack_peek(&pi->stack);
80
63
 
81
64
  if (0 != parent->classname) {
82
- volatile VALUE clas;
83
-
84
- clas = oj_name2class(pi, parent->classname, parent->clen, 0, rb_eArgError);
85
- if (Qundef != clas) { // else an error
86
- ID creatable = rb_intern("json_creatable?");
87
-
88
- if (!rb_respond_to(clas, creatable) || Qtrue == rb_funcall(clas, creatable, 0)) {
89
- parent->val = rb_funcall(clas, oj_json_create_id, 1, parent->val);
90
- }
91
- }
92
- if (0 != parent->classname) {
93
- xfree((char*)parent->classname);
94
- parent->classname = 0;
95
- }
96
- }
97
- if (Yes == pi->options.trace) {
98
- oj_trace_parse_hash_end(pi, __FILE__, __LINE__);
99
- }
65
+ volatile VALUE clas;
66
+
67
+ clas = oj_name2class(pi, parent->classname, parent->clen, 0, rb_eArgError);
68
+ if (Qundef != clas) { // else an error
69
+ ID creatable = rb_intern("json_creatable?");
70
+
71
+ if (!rb_respond_to(clas, creatable) || Qtrue == rb_funcall(clas, creatable, 0)) {
72
+ parent->val = rb_funcall(clas, oj_json_create_id, 1, parent->val);
73
+ }
74
+ }
75
+ if (0 != parent->classname) {
76
+ OJ_R_FREE((char *)parent->classname);
77
+ parent->classname = 0;
78
+ }
79
+ }
80
+ TRACE_PARSE_HASH_END(pi->options.trace, pi);
100
81
  }
101
82
 
102
- static VALUE
103
- calc_hash_key(ParseInfo pi, Val parent) {
104
- volatile VALUE rkey = parent->key_val;
105
-
106
- if (Qundef == rkey) {
107
- rkey = rb_str_new(parent->key, parent->klen);
108
- }
109
- rkey = oj_encode(rkey);
110
- if (Yes == pi->options.sym_key) {
111
- rkey = rb_str_intern(rkey);
112
- }
113
- return rkey;
114
- }
83
+ static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
84
+ volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
115
85
 
116
- static void
117
- add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
118
- volatile VALUE rstr = rb_str_new(str, len);
119
-
120
- rstr = oj_encode(rstr);
121
86
  if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
122
- VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
87
+ VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
123
88
 
124
- if (Qnil != clas) {
125
- pi->stack.head->val = rb_funcall(clas, oj_json_create_id, 1, rstr);
126
- return;
127
- }
89
+ if (Qnil != clas) {
90
+ pi->stack.head->val = rb_funcall(clas, oj_json_create_id, 1, rstr);
91
+ return;
92
+ }
128
93
  }
129
94
  pi->stack.head->val = rstr;
130
- if (Yes == pi->options.trace) {
131
- oj_trace_parse_call("add_string", pi, __FILE__, __LINE__, rstr);
132
- }
95
+ TRACE_PARSE_CALL(pi->options.trace, "add_string", pi, rstr);
133
96
  }
134
97
 
135
- static void
136
- add_num(ParseInfo pi, NumInfo ni) {
98
+ static void add_num(ParseInfo pi, NumInfo ni) {
137
99
  pi->stack.head->val = oj_num_as_value(ni);
138
- if (Yes == pi->options.trace) {
139
- oj_trace_parse_call("add_number", pi, __FILE__, __LINE__, pi->stack.head->val);
140
- }
100
+ TRACE_PARSE_CALL(pi->options.trace, "add_number", pi, pi->stack.head->val);
141
101
  }
142
102
 
143
- static void
144
- hash_set_num(struct _parseInfo *pi, Val parent, NumInfo ni) {
145
- volatile VALUE rval = oj_num_as_value(ni);
103
+ static void hash_set_num(struct _parseInfo *pi, Val parent, NumInfo ni) {
104
+ volatile VALUE rval = oj_num_as_value(ni);
146
105
 
147
- if (!oj_use_hash_alt && 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, rb_intern("[]="), 2, calc_hash_key(pi, parent), rval);
106
+ if (rb_cHash != rb_obj_class(parent->val)) {
107
+ // The rb_hash_set would still work but the unit tests for the
108
+ // json gem require the less efficient []= method be called to set
109
+ // values. Even using the store method to set the values will fail
110
+ // the unit tests.
111
+ rb_funcall(stack_peek(&pi->stack)->val, rb_intern("[]="), 2, oj_calc_hash_key(pi, parent), rval);
153
112
  } else {
154
- rb_hash_aset(stack_peek(&pi->stack)->val, calc_hash_key(pi, parent), rval);
155
- }
156
- if (Yes == pi->options.trace) {
157
- oj_trace_parse_call("set_number", pi, __FILE__, __LINE__, rval);
113
+ rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), rval);
158
114
  }
115
+ TRACE_PARSE_CALL(pi->options.trace, "set_number", pi, rval);
159
116
  }
160
117
 
161
- static void
162
- hash_set_value(ParseInfo pi, Val parent, VALUE value) {
118
+ static void hash_set_value(ParseInfo pi, Val parent, VALUE value) {
163
119
  if (rb_cHash != rb_obj_class(parent->val)) {
164
- // The rb_hash_set would still work but the unit tests for the
165
- // json gem require the less efficient []= method be called to set
166
- // values. Even using the store method to set the values will fail
167
- // the unit tests.
168
- rb_funcall(stack_peek(&pi->stack)->val, rb_intern("[]="), 2, calc_hash_key(pi, parent), value);
120
+ // The rb_hash_set would still work but the unit tests for the
121
+ // json gem require the less efficient []= method be called to set
122
+ // values. Even using the store method to set the values will fail
123
+ // the unit tests.
124
+ rb_funcall(stack_peek(&pi->stack)->val, rb_intern("[]="), 2, oj_calc_hash_key(pi, parent), value);
169
125
  } else {
170
- rb_hash_aset(stack_peek(&pi->stack)->val, calc_hash_key(pi, parent), value);
171
- }
172
- if (Yes == pi->options.trace) {
173
- oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, value);
126
+ rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), value);
174
127
  }
128
+ TRACE_PARSE_CALL(pi->options.trace, "set_value", pi, value);
175
129
  }
176
130
 
177
- static VALUE
178
- start_array(ParseInfo pi) {
131
+ static VALUE start_array(ParseInfo pi) {
179
132
  if (Qnil != pi->options.array_class) {
180
- return rb_class_new_instance(0, NULL, pi->options.array_class);
181
- }
182
- if (Yes == pi->options.trace) {
183
- oj_trace_parse_in("start_array", pi, __FILE__, __LINE__);
133
+ return rb_class_new_instance(0, NULL, pi->options.array_class);
184
134
  }
135
+ TRACE_PARSE_IN(pi->options.trace, "start_array", pi);
185
136
  return rb_ary_new();
186
137
  }
187
138
 
188
- static void
189
- array_append_num(ParseInfo pi, NumInfo ni) {
190
- Val parent = stack_peek(&pi->stack);
191
- volatile VALUE rval = oj_num_as_value(ni);
139
+ static void array_append_num(ParseInfo pi, NumInfo ni) {
140
+ Val parent = stack_peek(&pi->stack);
141
+ volatile VALUE rval = oj_num_as_value(ni);
192
142
 
193
143
  if (!oj_use_array_alt && rb_cArray != rb_obj_class(parent->val)) {
194
- // The rb_ary_push would still work but the unit tests for the json
195
- // gem require the less efficient << method be called to push the
196
- // values.
197
- rb_funcall(parent->val, rb_intern("<<"), 1, rval);
144
+ // The rb_ary_push would still work but the unit tests for the json
145
+ // gem require the less efficient << method be called to push the
146
+ // values.
147
+ rb_funcall(parent->val, rb_intern("<<"), 1, rval);
198
148
  } else {
199
- rb_ary_push(parent->val, rval);
200
- }
201
- if (Yes == pi->options.trace) {
202
- oj_trace_parse_call("append_number", pi, __FILE__, __LINE__, rval);
149
+ rb_ary_push(parent->val, rval);
203
150
  }
151
+ TRACE_PARSE_CALL(pi->options.trace, "append_number", pi, rval);
204
152
  }
205
153
 
206
- static void
207
- array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
208
- volatile VALUE rstr = rb_str_new(str, len);
154
+ static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
155
+ volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
209
156
 
210
- rstr = oj_encode(rstr);
211
157
  if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
212
- VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
158
+ VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
213
159
 
214
- if (Qnil != clas) {
215
- rb_ary_push(stack_peek(&pi->stack)->val, rb_funcall(clas, oj_json_create_id, 1, rstr));
216
- return;
217
- }
160
+ if (Qnil != clas) {
161
+ rb_ary_push(stack_peek(&pi->stack)->val, rb_funcall(clas, oj_json_create_id, 1, rstr));
162
+ return;
163
+ }
218
164
  }
219
165
  rb_ary_push(stack_peek(&pi->stack)->val, rstr);
220
- if (Yes == pi->options.trace) {
221
- oj_trace_parse_call("append_string", pi, __FILE__, __LINE__, rstr);
222
- }
166
+ TRACE_PARSE_CALL(pi->options.trace, "append_string", pi, rstr);
223
167
  }
224
168
 
225
- void
226
- oj_set_compat_callbacks(ParseInfo pi) {
169
+ void oj_set_compat_callbacks(ParseInfo pi) {
227
170
  oj_set_strict_callbacks(pi);
228
- pi->start_hash = start_hash;
229
- pi->end_hash = end_hash;
230
- pi->hash_set_cstr = hash_set_cstr;
231
- pi->hash_set_num = hash_set_num;
232
- pi->hash_set_value = hash_set_value;
233
- pi->add_num = add_num;
234
- pi->add_cstr = add_cstr;
171
+ pi->start_hash = start_hash;
172
+ pi->end_hash = end_hash;
173
+ pi->hash_set_cstr = hash_set_cstr;
174
+ pi->hash_set_num = hash_set_num;
175
+ pi->hash_set_value = hash_set_value;
176
+ pi->add_num = add_num;
177
+ pi->add_cstr = add_cstr;
235
178
  pi->array_append_cstr = array_append_cstr;
236
- pi->start_array = start_array;
237
- pi->array_append_num = array_append_num;
179
+ pi->start_array = start_array;
180
+ pi->array_append_num = array_append_num;
238
181
  }
239
182
 
240
183
  VALUE
241
184
  oj_compat_parse(int argc, VALUE *argv, VALUE self) {
242
- struct _parseInfo pi;
185
+ struct _parseInfo pi;
243
186
 
244
187
  parse_info_init(&pi);
245
- pi.options = oj_default_options;
246
- pi.handler = Qnil;
247
- pi.err_class = Qnil;
248
- pi.max_depth = 0;
249
- pi.options.allow_nan = Yes;
250
- pi.options.nilnil = Yes;
188
+ pi.options = oj_default_options;
189
+ pi.handler = Qnil;
190
+ pi.err_class = Qnil;
191
+ pi.max_depth = 0;
192
+ pi.options.allow_nan = Yes;
193
+ pi.options.nilnil = Yes;
251
194
  pi.options.empty_string = No;
252
195
  oj_set_compat_callbacks(&pi);
253
196
 
254
197
  if (T_STRING == rb_type(*argv)) {
255
- return oj_pi_parse(argc, argv, &pi, 0, 0, false);
198
+ return oj_pi_parse(argc, argv, &pi, 0, 0, false);
256
199
  } else {
257
- return oj_pi_sparse(argc, argv, &pi, 0);
200
+ return oj_pi_sparse(argc, argv, &pi, 0);
258
201
  }
259
202
  }
260
203
 
261
204
  VALUE
262
205
  oj_compat_load(int argc, VALUE *argv, VALUE self) {
263
- struct _parseInfo pi;
206
+ struct _parseInfo pi;
264
207
 
265
208
  parse_info_init(&pi);
266
- pi.options = oj_default_options;
267
- pi.handler = Qnil;
268
- pi.err_class = Qnil;
269
- pi.max_depth = 0;
270
- pi.options.allow_nan = Yes;
271
- pi.options.nilnil = Yes;
209
+ pi.options = oj_default_options;
210
+ pi.handler = Qnil;
211
+ pi.err_class = Qnil;
212
+ pi.max_depth = 0;
213
+ pi.options.allow_nan = Yes;
214
+ pi.options.nilnil = Yes;
272
215
  pi.options.empty_string = Yes;
273
216
  oj_set_compat_callbacks(&pi);
274
217
 
275
218
  if (T_STRING == rb_type(*argv)) {
276
- return oj_pi_parse(argc, argv, &pi, 0, 0, false);
219
+ return oj_pi_parse(argc, argv, &pi, 0, 0, false);
277
220
  } else {
278
- return oj_pi_sparse(argc, argv, &pi, 0);
221
+ return oj_pi_sparse(argc, argv, &pi, 0);
279
222
  }
280
223
  }
281
224
 
282
225
  VALUE
283
226
  oj_compat_parse_cstr(int argc, VALUE *argv, char *json, size_t len) {
284
- struct _parseInfo pi;
227
+ struct _parseInfo pi;
285
228
 
286
229
  parse_info_init(&pi);
287
- pi.options = oj_default_options;
288
- pi.handler = Qnil;
289
- pi.err_class = Qnil;
290
- pi.max_depth = 0;
230
+ pi.options = oj_default_options;
231
+ pi.handler = Qnil;
232
+ pi.err_class = Qnil;
233
+ pi.max_depth = 0;
291
234
  pi.options.allow_nan = Yes;
292
- pi.options.nilnil = Yes;
235
+ pi.options.nilnil = Yes;
293
236
  oj_set_compat_callbacks(&pi);
294
237
 
295
238
  return oj_pi_parse(argc, argv, &pi, json, len, false);