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/scp.c CHANGED
@@ -1,221 +1,188 @@
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
- #include <stdlib.h>
4
+ #include <math.h>
4
5
  #include <stdio.h>
6
+ #include <stdlib.h>
5
7
  #include <string.h>
6
- #include <math.h>
7
8
  #include <sys/types.h>
8
9
  #include <unistd.h>
9
10
 
11
+ #include "encode.h"
12
+ #include "intern.h"
10
13
  #include "oj.h"
11
14
  #include "parse.h"
12
- #include "encode.h"
13
15
 
14
- static VALUE
15
- noop_start(ParseInfo pi) {
16
+ static VALUE noop_start(ParseInfo pi) {
16
17
  return Qnil;
17
18
  }
18
19
 
19
- static void
20
- noop_end(ParseInfo pi) {
20
+ static void noop_end(ParseInfo pi) {
21
21
  }
22
22
 
23
- static void
24
- noop_add_value(ParseInfo pi, VALUE val) {
23
+ static void noop_add_value(ParseInfo pi, VALUE val) {
25
24
  }
26
25
 
27
- static void
28
- noop_add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
26
+ static void noop_add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
29
27
  }
30
28
 
31
- static void
32
- noop_add_num(ParseInfo pi, NumInfo ni) {
29
+ static void noop_add_num(ParseInfo pi, NumInfo ni) {
33
30
  }
34
31
 
35
- static VALUE
36
- noop_hash_key(ParseInfo pi, const char *key, size_t klen) {
32
+ static VALUE noop_hash_key(ParseInfo pi, const char *key, size_t klen) {
37
33
  return Qundef;
38
34
  }
39
35
 
40
- static void
41
- noop_hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
36
+ static void noop_hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
42
37
  }
43
38
 
44
- static void
45
- noop_hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
39
+ static void noop_hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
46
40
  }
47
41
 
48
- static void
49
- noop_hash_set_value(ParseInfo pi, Val kval, VALUE value) {
42
+ static void noop_hash_set_value(ParseInfo pi, Val kval, VALUE value) {
50
43
  }
51
44
 
52
- static void
53
- noop_array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
45
+ static void noop_array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
54
46
  }
55
47
 
56
- static void
57
- noop_array_append_num(ParseInfo pi, NumInfo ni) {
48
+ static void noop_array_append_num(ParseInfo pi, NumInfo ni) {
58
49
  }
59
50
 
60
- static void
61
- noop_array_append_value(ParseInfo pi, VALUE value) {
51
+ static void noop_array_append_value(ParseInfo pi, VALUE value) {
62
52
  }
63
53
 
64
- static void
65
- add_value(ParseInfo pi, VALUE val) {
54
+ static void add_value(ParseInfo pi, VALUE val) {
66
55
  rb_funcall(pi->handler, oj_add_value_id, 1, val);
67
56
  }
68
57
 
69
- static void
70
- add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
71
- volatile VALUE rstr = rb_str_new(str, len);
58
+ static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
59
+ volatile VALUE rstr = rb_str_new(str, len);
72
60
 
73
61
  rstr = oj_encode(rstr);
74
62
  rb_funcall(pi->handler, oj_add_value_id, 1, rstr);
75
63
  }
76
64
 
77
- static void
78
- add_num(ParseInfo pi, NumInfo ni) {
65
+ static void add_num(ParseInfo pi, NumInfo ni) {
79
66
  rb_funcall(pi->handler, oj_add_value_id, 1, oj_num_as_value(ni));
80
67
  }
81
68
 
82
- static VALUE
83
- start_hash(ParseInfo pi) {
69
+ static VALUE start_hash(ParseInfo pi) {
84
70
  return rb_funcall(pi->handler, oj_hash_start_id, 0);
85
71
  }
86
72
 
87
- static void
88
- end_hash(ParseInfo pi) {
73
+ static void end_hash(ParseInfo pi) {
89
74
  rb_funcall(pi->handler, oj_hash_end_id, 0);
90
75
  }
91
76
 
92
- static VALUE
93
- start_array(ParseInfo pi) {
77
+ static VALUE start_array(ParseInfo pi) {
94
78
  return rb_funcall(pi->handler, oj_array_start_id, 0);
95
79
  }
96
80
 
97
- static void
98
- end_array(ParseInfo pi) {
81
+ static void end_array(ParseInfo pi) {
99
82
  rb_funcall(pi->handler, oj_array_end_id, 0);
100
83
  }
101
84
 
102
- static VALUE
103
- calc_hash_key(ParseInfo pi, Val kval) {
104
- volatile VALUE rkey = kval->key_val;
105
-
106
- if (Qundef == rkey) {
107
- rkey = rb_str_new(kval->key, kval->klen);
108
- rkey = oj_encode(rkey);
109
- if (Yes == pi->options.sym_key) {
110
- rkey = rb_str_intern(rkey);
111
- }
112
- }
113
- return rkey;
114
- }
115
-
116
- static VALUE
117
- hash_key(ParseInfo pi, const char *key, size_t klen) {
85
+ static VALUE hash_key(ParseInfo pi, const char *key, size_t klen) {
118
86
  return rb_funcall(pi->handler, oj_hash_key_id, 1, rb_str_new(key, klen));
119
87
  }
120
88
 
121
- static void
122
- hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
123
- volatile VALUE rstr = rb_str_new(str, len);
89
+ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
90
+ volatile VALUE rstr = rb_str_new(str, len);
124
91
 
125
92
  rstr = oj_encode(rstr);
126
- rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, calc_hash_key(pi, kval), rstr);
93
+ rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, kval), rstr);
127
94
  }
128
95
 
129
- static void
130
- hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
131
- rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, calc_hash_key(pi, kval), oj_num_as_value(ni));
96
+ static void hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
97
+ rb_funcall(pi->handler,
98
+ oj_hash_set_id,
99
+ 3,
100
+ stack_peek(&pi->stack)->val,
101
+ oj_calc_hash_key(pi, kval),
102
+ oj_num_as_value(ni));
132
103
  }
133
104
 
134
- static void
135
- hash_set_value(ParseInfo pi, Val kval, VALUE value) {
136
- rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, calc_hash_key(pi, kval), value);
105
+ static void hash_set_value(ParseInfo pi, Val kval, VALUE value) {
106
+ rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, kval), value);
137
107
  }
138
108
 
139
- static void
140
- array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
141
- volatile VALUE rstr = rb_str_new(str, len);
109
+ static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
110
+ volatile VALUE rstr = rb_str_new(str, len);
142
111
 
143
112
  rstr = oj_encode(rstr);
144
113
  rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, rstr);
145
114
  }
146
115
 
147
- static void
148
- array_append_num(ParseInfo pi, NumInfo ni) {
116
+ static void array_append_num(ParseInfo pi, NumInfo ni) {
149
117
  rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, oj_num_as_value(ni));
150
118
  }
151
119
 
152
- static void
153
- array_append_value(ParseInfo pi, VALUE value) {
120
+ static void array_append_value(ParseInfo pi, VALUE value) {
154
121
  rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, value);
155
122
  }
156
123
 
157
124
  VALUE
158
125
  oj_sc_parse(int argc, VALUE *argv, VALUE self) {
159
- struct _parseInfo pi;
160
- VALUE input = argv[1];
126
+ struct _parseInfo pi;
127
+ VALUE input = argv[1];
161
128
 
162
129
  parse_info_init(&pi);
163
130
  pi.err_class = Qnil;
164
131
  pi.max_depth = 0;
165
- pi.options = oj_default_options;
132
+ pi.options = oj_default_options;
166
133
  if (3 == argc) {
167
- oj_parse_options(argv[2], &pi.options);
134
+ oj_parse_options(argv[2], &pi.options);
168
135
  }
169
136
  if (rb_block_given_p()) {
170
- pi.proc = Qnil;
137
+ pi.proc = Qnil;
171
138
  } else {
172
- pi.proc = Qundef;
139
+ pi.proc = Qundef;
173
140
  }
174
141
  pi.handler = *argv;
175
142
 
176
- pi.start_hash = rb_respond_to(pi.handler, oj_hash_start_id) ? start_hash : noop_start;
177
- pi.end_hash = rb_respond_to(pi.handler, oj_hash_end_id) ? end_hash : noop_end;
178
- pi.hash_key = rb_respond_to(pi.handler, oj_hash_key_id) ? hash_key : noop_hash_key;
143
+ pi.start_hash = rb_respond_to(pi.handler, oj_hash_start_id) ? start_hash : noop_start;
144
+ pi.end_hash = rb_respond_to(pi.handler, oj_hash_end_id) ? end_hash : noop_end;
145
+ pi.hash_key = rb_respond_to(pi.handler, oj_hash_key_id) ? hash_key : noop_hash_key;
179
146
  pi.start_array = rb_respond_to(pi.handler, oj_array_start_id) ? start_array : noop_start;
180
- pi.end_array = rb_respond_to(pi.handler, oj_array_end_id) ? end_array : noop_end;
147
+ pi.end_array = rb_respond_to(pi.handler, oj_array_end_id) ? end_array : noop_end;
181
148
  if (rb_respond_to(pi.handler, oj_hash_set_id)) {
182
- pi.hash_set_value = hash_set_value;
183
- pi.hash_set_cstr = hash_set_cstr;
184
- pi.hash_set_num = hash_set_num;
185
- pi.expect_value = 1;
149
+ pi.hash_set_value = hash_set_value;
150
+ pi.hash_set_cstr = hash_set_cstr;
151
+ pi.hash_set_num = hash_set_num;
152
+ pi.expect_value = 1;
186
153
  } else {
187
- pi.hash_set_value = noop_hash_set_value;
188
- pi.hash_set_cstr = noop_hash_set_cstr;
189
- pi.hash_set_num = noop_hash_set_num;
190
- pi.expect_value = 0;
154
+ pi.hash_set_value = noop_hash_set_value;
155
+ pi.hash_set_cstr = noop_hash_set_cstr;
156
+ pi.hash_set_num = noop_hash_set_num;
157
+ pi.expect_value = 0;
191
158
  }
192
159
  if (rb_respond_to(pi.handler, oj_array_append_id)) {
193
- pi.array_append_value = array_append_value;
194
- pi.array_append_cstr = array_append_cstr;
195
- pi.array_append_num = array_append_num;
196
- pi.expect_value = 1;
160
+ pi.array_append_value = array_append_value;
161
+ pi.array_append_cstr = array_append_cstr;
162
+ pi.array_append_num = array_append_num;
163
+ pi.expect_value = 1;
197
164
  } else {
198
- pi.array_append_value = noop_array_append_value;
199
- pi.array_append_cstr = noop_array_append_cstr;
200
- pi.array_append_num = noop_array_append_num;
201
- pi.expect_value = 0;
165
+ pi.array_append_value = noop_array_append_value;
166
+ pi.array_append_cstr = noop_array_append_cstr;
167
+ pi.array_append_num = noop_array_append_num;
168
+ pi.expect_value = 0;
202
169
  }
203
170
  if (rb_respond_to(pi.handler, oj_add_value_id)) {
204
- pi.add_cstr = add_cstr;
205
- pi.add_num = add_num;
206
- pi.add_value = add_value;
207
- pi.expect_value = 1;
171
+ pi.add_cstr = add_cstr;
172
+ pi.add_num = add_num;
173
+ pi.add_value = add_value;
174
+ pi.expect_value = 1;
208
175
  } else {
209
- pi.add_cstr = noop_add_cstr;
210
- pi.add_num = noop_add_num;
211
- pi.add_value = noop_add_value;
212
- pi.expect_value = 0;
176
+ pi.add_cstr = noop_add_cstr;
177
+ pi.add_num = noop_add_num;
178
+ pi.add_value = noop_add_value;
179
+ pi.expect_value = 0;
213
180
  }
214
181
  pi.has_callbacks = true;
215
182
 
216
183
  if (T_STRING == rb_type(input)) {
217
- return oj_pi_parse(argc - 1, argv + 1, &pi, 0, 0, 1);
184
+ return oj_pi_parse(argc - 1, argv + 1, &pi, 0, 0, 1);
218
185
  } else {
219
- return oj_pi_sparse(argc - 1, argv + 1, &pi, 0);
186
+ return oj_pi_sparse(argc - 1, argv + 1, &pi, 0);
220
187
  }
221
188
  }