oj 3.9.1 → 3.16.11

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 (171) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1452 -0
  3. data/README.md +21 -6
  4. data/RELEASE_NOTES.md +61 -0
  5. data/ext/oj/buf.h +50 -68
  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 +9 -36
  10. data/ext/oj/circarray.c +38 -42
  11. data/ext/oj/circarray.h +12 -13
  12. data/ext/oj/code.c +158 -179
  13. data/ext/oj/code.h +20 -22
  14. data/ext/oj/compat.c +145 -205
  15. data/ext/oj/custom.c +740 -880
  16. data/ext/oj/debug.c +126 -0
  17. data/ext/oj/dump.c +1145 -844
  18. data/ext/oj/dump.h +71 -57
  19. data/ext/oj/dump_compat.c +575 -655
  20. data/ext/oj/dump_leaf.c +96 -186
  21. data/ext/oj/dump_object.c +533 -660
  22. data/ext/oj/dump_strict.c +306 -340
  23. data/ext/oj/encode.h +4 -33
  24. data/ext/oj/encoder.c +43 -0
  25. data/ext/oj/err.c +28 -28
  26. data/ext/oj/err.h +39 -42
  27. data/ext/oj/extconf.rb +28 -7
  28. data/ext/oj/fast.c +1052 -1113
  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 +471 -430
  34. data/ext/oj/object.c +532 -580
  35. data/ext/oj/odd.c +156 -142
  36. data/ext/oj/odd.h +25 -26
  37. data/ext/oj/oj.c +1346 -961
  38. data/ext/oj/oj.h +307 -290
  39. data/ext/oj/parse.c +954 -858
  40. data/ext/oj/parse.h +74 -72
  41. data/ext/oj/parser.c +1600 -0
  42. data/ext/oj/parser.h +103 -0
  43. data/ext/oj/rails.c +819 -836
  44. data/ext/oj/rails.h +8 -11
  45. data/ext/oj/reader.c +136 -147
  46. data/ext/oj/reader.h +69 -83
  47. data/ext/oj/resolve.c +41 -63
  48. data/ext/oj/resolve.h +4 -6
  49. data/ext/oj/rxclass.c +69 -72
  50. data/ext/oj/rxclass.h +12 -13
  51. data/ext/oj/saj.c +440 -485
  52. data/ext/oj/saj2.c +584 -0
  53. data/ext/oj/saj2.h +23 -0
  54. data/ext/oj/scp.c +79 -118
  55. data/ext/oj/simd.h +10 -0
  56. data/ext/oj/sparse.c +739 -709
  57. data/ext/oj/stream_writer.c +141 -175
  58. data/ext/oj/strict.c +103 -128
  59. data/ext/oj/string_writer.c +244 -261
  60. data/ext/oj/trace.c +34 -41
  61. data/ext/oj/trace.h +42 -15
  62. data/ext/oj/usual.c +1218 -0
  63. data/ext/oj/usual.h +69 -0
  64. data/ext/oj/util.c +107 -107
  65. data/ext/oj/util.h +4 -3
  66. data/ext/oj/val_stack.c +61 -78
  67. data/ext/oj/val_stack.h +80 -114
  68. data/ext/oj/validate.c +46 -0
  69. data/ext/oj/wab.c +316 -361
  70. data/lib/oj/active_support_helper.rb +1 -3
  71. data/lib/oj/bag.rb +8 -1
  72. data/lib/oj/easy_hash.rb +9 -9
  73. data/lib/oj/error.rb +1 -2
  74. data/lib/oj/json.rb +162 -150
  75. data/lib/oj/mimic.rb +54 -20
  76. data/lib/oj/saj.rb +20 -6
  77. data/lib/oj/schandler.rb +5 -4
  78. data/lib/oj/state.rb +12 -8
  79. data/lib/oj/version.rb +1 -2
  80. data/lib/oj.rb +2 -8
  81. data/pages/Compatibility.md +1 -1
  82. data/pages/Encoding.md +1 -1
  83. data/pages/InstallOptions.md +20 -0
  84. data/pages/JsonGem.md +15 -0
  85. data/pages/Modes.md +9 -3
  86. data/pages/Options.md +62 -12
  87. data/pages/Parser.md +309 -0
  88. data/pages/Rails.md +73 -22
  89. metadata +68 -192
  90. data/ext/oj/hash.c +0 -163
  91. data/ext/oj/hash.h +0 -46
  92. data/ext/oj/hash_test.c +0 -512
  93. data/test/_test_active.rb +0 -76
  94. data/test/_test_active_mimic.rb +0 -96
  95. data/test/_test_mimic_rails.rb +0 -126
  96. data/test/activerecord/result_test.rb +0 -27
  97. data/test/activesupport4/decoding_test.rb +0 -108
  98. data/test/activesupport4/encoding_test.rb +0 -531
  99. data/test/activesupport4/test_helper.rb +0 -41
  100. data/test/activesupport5/decoding_test.rb +0 -125
  101. data/test/activesupport5/encoding_test.rb +0 -485
  102. data/test/activesupport5/encoding_test_cases.rb +0 -90
  103. data/test/activesupport5/test_helper.rb +0 -50
  104. data/test/activesupport5/time_zone_test_helpers.rb +0 -24
  105. data/test/bar.rb +0 -25
  106. data/test/files.rb +0 -29
  107. data/test/foo.rb +0 -21
  108. data/test/helper.rb +0 -26
  109. data/test/isolated/shared.rb +0 -308
  110. data/test/isolated/test_mimic_after.rb +0 -13
  111. data/test/isolated/test_mimic_alone.rb +0 -12
  112. data/test/isolated/test_mimic_as_json.rb +0 -45
  113. data/test/isolated/test_mimic_before.rb +0 -13
  114. data/test/isolated/test_mimic_define.rb +0 -28
  115. data/test/isolated/test_mimic_rails_after.rb +0 -22
  116. data/test/isolated/test_mimic_rails_before.rb +0 -21
  117. data/test/isolated/test_mimic_redefine.rb +0 -15
  118. data/test/json_gem/json_addition_test.rb +0 -216
  119. data/test/json_gem/json_common_interface_test.rb +0 -148
  120. data/test/json_gem/json_encoding_test.rb +0 -107
  121. data/test/json_gem/json_ext_parser_test.rb +0 -20
  122. data/test/json_gem/json_fixtures_test.rb +0 -35
  123. data/test/json_gem/json_generator_test.rb +0 -383
  124. data/test/json_gem/json_generic_object_test.rb +0 -90
  125. data/test/json_gem/json_parser_test.rb +0 -470
  126. data/test/json_gem/json_string_matching_test.rb +0 -42
  127. data/test/json_gem/test_helper.rb +0 -18
  128. data/test/perf.rb +0 -107
  129. data/test/perf_compat.rb +0 -130
  130. data/test/perf_fast.rb +0 -164
  131. data/test/perf_file.rb +0 -64
  132. data/test/perf_object.rb +0 -138
  133. data/test/perf_saj.rb +0 -109
  134. data/test/perf_scp.rb +0 -151
  135. data/test/perf_simple.rb +0 -287
  136. data/test/perf_strict.rb +0 -145
  137. data/test/perf_wab.rb +0 -131
  138. data/test/sample/change.rb +0 -14
  139. data/test/sample/dir.rb +0 -19
  140. data/test/sample/doc.rb +0 -36
  141. data/test/sample/file.rb +0 -48
  142. data/test/sample/group.rb +0 -16
  143. data/test/sample/hasprops.rb +0 -16
  144. data/test/sample/layer.rb +0 -12
  145. data/test/sample/line.rb +0 -20
  146. data/test/sample/oval.rb +0 -10
  147. data/test/sample/rect.rb +0 -10
  148. data/test/sample/shape.rb +0 -35
  149. data/test/sample/text.rb +0 -20
  150. data/test/sample.rb +0 -54
  151. data/test/sample_json.rb +0 -37
  152. data/test/test_compat.rb +0 -509
  153. data/test/test_custom.rb +0 -503
  154. data/test/test_debian.rb +0 -53
  155. data/test/test_fast.rb +0 -470
  156. data/test/test_file.rb +0 -239
  157. data/test/test_gc.rb +0 -49
  158. data/test/test_hash.rb +0 -29
  159. data/test/test_integer_range.rb +0 -73
  160. data/test/test_null.rb +0 -376
  161. data/test/test_object.rb +0 -1018
  162. data/test/test_saj.rb +0 -186
  163. data/test/test_scp.rb +0 -433
  164. data/test/test_strict.rb +0 -410
  165. data/test/test_various.rb +0 -741
  166. data/test/test_wab.rb +0 -307
  167. data/test/test_writer.rb +0 -380
  168. data/test/tests.rb +0 -24
  169. data/test/tests_mimic.rb +0 -14
  170. data/test/tests_mimic_addition.rb +0 -7
  171. data/test/zoo.rb +0 -13
data/ext/oj/scp.c CHANGED
@@ -1,224 +1,185 @@
1
- /* scp.c
2
- * Copyright (c) 2012, Peter Ohler
3
- * All rights reserved.
4
- */
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.
5
3
 
6
- #include <stdlib.h>
4
+ #include <math.h>
7
5
  #include <stdio.h>
6
+ #include <stdlib.h>
8
7
  #include <string.h>
9
- #include <math.h>
10
8
  #include <sys/types.h>
11
9
  #include <unistd.h>
12
10
 
11
+ #include "encode.h"
12
+ #include "intern.h"
13
13
  #include "oj.h"
14
14
  #include "parse.h"
15
- #include "encode.h"
16
15
 
17
- static VALUE
18
- noop_start(ParseInfo pi) {
16
+ static VALUE noop_start(ParseInfo pi) {
19
17
  return Qnil;
20
18
  }
21
19
 
22
- static void
23
- noop_end(ParseInfo pi) {
20
+ static void noop_end(ParseInfo pi) {
24
21
  }
25
22
 
26
- static void
27
- noop_add_value(ParseInfo pi, VALUE val) {
23
+ static void noop_add_value(ParseInfo pi, VALUE val) {
28
24
  }
29
25
 
30
- static void
31
- 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) {
32
27
  }
33
28
 
34
- static void
35
- noop_add_num(ParseInfo pi, NumInfo ni) {
29
+ static void noop_add_num(ParseInfo pi, NumInfo ni) {
36
30
  }
37
31
 
38
- static VALUE
39
- 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) {
40
33
  return Qundef;
41
34
  }
42
35
 
43
- static void
44
- 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) {
45
37
  }
46
38
 
47
- static void
48
- noop_hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
39
+ static void noop_hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
49
40
  }
50
41
 
51
- static void
52
- noop_hash_set_value(ParseInfo pi, Val kval, VALUE value) {
42
+ static void noop_hash_set_value(ParseInfo pi, Val kval, VALUE value) {
53
43
  }
54
44
 
55
- static void
56
- 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) {
57
46
  }
58
47
 
59
- static void
60
- noop_array_append_num(ParseInfo pi, NumInfo ni) {
48
+ static void noop_array_append_num(ParseInfo pi, NumInfo ni) {
61
49
  }
62
50
 
63
- static void
64
- noop_array_append_value(ParseInfo pi, VALUE value) {
51
+ static void noop_array_append_value(ParseInfo pi, VALUE value) {
65
52
  }
66
53
 
67
- static void
68
- add_value(ParseInfo pi, VALUE val) {
54
+ static void add_value(ParseInfo pi, VALUE val) {
69
55
  rb_funcall(pi->handler, oj_add_value_id, 1, val);
70
56
  }
71
57
 
72
- static void
73
- add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
74
- 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_utf8_str_new(str, len);
75
60
 
76
- rstr = oj_encode(rstr);
77
61
  rb_funcall(pi->handler, oj_add_value_id, 1, rstr);
78
62
  }
79
63
 
80
- static void
81
- add_num(ParseInfo pi, NumInfo ni) {
64
+ static void add_num(ParseInfo pi, NumInfo ni) {
82
65
  rb_funcall(pi->handler, oj_add_value_id, 1, oj_num_as_value(ni));
83
66
  }
84
67
 
85
- static VALUE
86
- start_hash(ParseInfo pi) {
68
+ static VALUE start_hash(ParseInfo pi) {
87
69
  return rb_funcall(pi->handler, oj_hash_start_id, 0);
88
70
  }
89
71
 
90
- static void
91
- end_hash(ParseInfo pi) {
72
+ static void end_hash(ParseInfo pi) {
92
73
  rb_funcall(pi->handler, oj_hash_end_id, 0);
93
74
  }
94
75
 
95
- static VALUE
96
- start_array(ParseInfo pi) {
76
+ static VALUE start_array(ParseInfo pi) {
97
77
  return rb_funcall(pi->handler, oj_array_start_id, 0);
98
78
  }
99
79
 
100
- static void
101
- end_array(ParseInfo pi) {
80
+ static void end_array(ParseInfo pi) {
102
81
  rb_funcall(pi->handler, oj_array_end_id, 0);
103
82
  }
104
83
 
105
- static VALUE
106
- calc_hash_key(ParseInfo pi, Val kval) {
107
- volatile VALUE rkey = kval->key_val;
108
-
109
- if (Qundef == rkey) {
110
- rkey = rb_str_new(kval->key, kval->klen);
111
- rkey = oj_encode(rkey);
112
- if (Yes == pi->options.sym_key) {
113
- rkey = rb_str_intern(rkey);
114
- }
115
- }
116
- return rkey;
117
- }
118
-
119
- static VALUE
120
- hash_key(ParseInfo pi, const char *key, size_t klen) {
84
+ static VALUE hash_key(ParseInfo pi, const char *key, size_t klen) {
121
85
  return rb_funcall(pi->handler, oj_hash_key_id, 1, rb_str_new(key, klen));
122
86
  }
123
87
 
124
- static void
125
- hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
126
- volatile VALUE rstr = rb_str_new(str, len);
88
+ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
89
+ volatile VALUE rstr = rb_utf8_str_new(str, len);
127
90
 
128
- rstr = oj_encode(rstr);
129
- rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, calc_hash_key(pi, kval), rstr);
91
+ rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, kval), rstr);
130
92
  }
131
93
 
132
- static void
133
- hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
134
- rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, calc_hash_key(pi, kval), oj_num_as_value(ni));
94
+ static void hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
95
+ rb_funcall(pi->handler,
96
+ oj_hash_set_id,
97
+ 3,
98
+ stack_peek(&pi->stack)->val,
99
+ oj_calc_hash_key(pi, kval),
100
+ oj_num_as_value(ni));
135
101
  }
136
102
 
137
- static void
138
- hash_set_value(ParseInfo pi, Val kval, VALUE value) {
139
- rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, calc_hash_key(pi, kval), value);
103
+ static void hash_set_value(ParseInfo pi, Val kval, VALUE value) {
104
+ rb_funcall(pi->handler, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, kval), value);
140
105
  }
141
106
 
142
- static void
143
- array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
144
- volatile VALUE rstr = rb_str_new(str, len);
107
+ static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
108
+ volatile VALUE rstr = rb_utf8_str_new(str, len);
145
109
 
146
- rstr = oj_encode(rstr);
147
110
  rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, rstr);
148
111
  }
149
112
 
150
- static void
151
- array_append_num(ParseInfo pi, NumInfo ni) {
113
+ static void array_append_num(ParseInfo pi, NumInfo ni) {
152
114
  rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, oj_num_as_value(ni));
153
115
  }
154
116
 
155
- static void
156
- array_append_value(ParseInfo pi, VALUE value) {
117
+ static void array_append_value(ParseInfo pi, VALUE value) {
157
118
  rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, value);
158
119
  }
159
120
 
160
121
  VALUE
161
122
  oj_sc_parse(int argc, VALUE *argv, VALUE self) {
162
- struct _parseInfo pi;
163
- VALUE input = argv[1];
123
+ struct _parseInfo pi;
124
+ VALUE input = argv[1];
164
125
 
165
126
  parse_info_init(&pi);
166
127
  pi.err_class = Qnil;
167
128
  pi.max_depth = 0;
168
- pi.options = oj_default_options;
129
+ pi.options = oj_default_options;
169
130
  if (3 == argc) {
170
- oj_parse_options(argv[2], &pi.options);
131
+ oj_parse_options(argv[2], &pi.options);
171
132
  }
172
133
  if (rb_block_given_p()) {
173
- pi.proc = Qnil;
134
+ pi.proc = Qnil;
174
135
  } else {
175
- pi.proc = Qundef;
136
+ pi.proc = Qundef;
176
137
  }
177
138
  pi.handler = *argv;
178
139
 
179
- pi.start_hash = rb_respond_to(pi.handler, oj_hash_start_id) ? start_hash : noop_start;
180
- pi.end_hash = rb_respond_to(pi.handler, oj_hash_end_id) ? end_hash : noop_end;
181
- pi.hash_key = rb_respond_to(pi.handler, oj_hash_key_id) ? hash_key : noop_hash_key;
140
+ pi.start_hash = rb_respond_to(pi.handler, oj_hash_start_id) ? start_hash : noop_start;
141
+ pi.end_hash = rb_respond_to(pi.handler, oj_hash_end_id) ? end_hash : noop_end;
142
+ pi.hash_key = rb_respond_to(pi.handler, oj_hash_key_id) ? hash_key : noop_hash_key;
182
143
  pi.start_array = rb_respond_to(pi.handler, oj_array_start_id) ? start_array : noop_start;
183
- pi.end_array = rb_respond_to(pi.handler, oj_array_end_id) ? end_array : noop_end;
144
+ pi.end_array = rb_respond_to(pi.handler, oj_array_end_id) ? end_array : noop_end;
184
145
  if (rb_respond_to(pi.handler, oj_hash_set_id)) {
185
- pi.hash_set_value = hash_set_value;
186
- pi.hash_set_cstr = hash_set_cstr;
187
- pi.hash_set_num = hash_set_num;
188
- pi.expect_value = 1;
146
+ pi.hash_set_value = hash_set_value;
147
+ pi.hash_set_cstr = hash_set_cstr;
148
+ pi.hash_set_num = hash_set_num;
149
+ pi.expect_value = 1;
189
150
  } else {
190
- pi.hash_set_value = noop_hash_set_value;
191
- pi.hash_set_cstr = noop_hash_set_cstr;
192
- pi.hash_set_num = noop_hash_set_num;
193
- pi.expect_value = 0;
151
+ pi.hash_set_value = noop_hash_set_value;
152
+ pi.hash_set_cstr = noop_hash_set_cstr;
153
+ pi.hash_set_num = noop_hash_set_num;
154
+ pi.expect_value = 0;
194
155
  }
195
156
  if (rb_respond_to(pi.handler, oj_array_append_id)) {
196
- pi.array_append_value = array_append_value;
197
- pi.array_append_cstr = array_append_cstr;
198
- pi.array_append_num = array_append_num;
199
- pi.expect_value = 1;
157
+ pi.array_append_value = array_append_value;
158
+ pi.array_append_cstr = array_append_cstr;
159
+ pi.array_append_num = array_append_num;
160
+ pi.expect_value = 1;
200
161
  } else {
201
- pi.array_append_value = noop_array_append_value;
202
- pi.array_append_cstr = noop_array_append_cstr;
203
- pi.array_append_num = noop_array_append_num;
204
- pi.expect_value = 0;
162
+ pi.array_append_value = noop_array_append_value;
163
+ pi.array_append_cstr = noop_array_append_cstr;
164
+ pi.array_append_num = noop_array_append_num;
165
+ pi.expect_value = 0;
205
166
  }
206
167
  if (rb_respond_to(pi.handler, oj_add_value_id)) {
207
- pi.add_cstr = add_cstr;
208
- pi.add_num = add_num;
209
- pi.add_value = add_value;
210
- pi.expect_value = 1;
168
+ pi.add_cstr = add_cstr;
169
+ pi.add_num = add_num;
170
+ pi.add_value = add_value;
171
+ pi.expect_value = 1;
211
172
  } else {
212
- pi.add_cstr = noop_add_cstr;
213
- pi.add_num = noop_add_num;
214
- pi.add_value = noop_add_value;
215
- pi.expect_value = 0;
173
+ pi.add_cstr = noop_add_cstr;
174
+ pi.add_num = noop_add_num;
175
+ pi.add_value = noop_add_value;
176
+ pi.expect_value = 0;
216
177
  }
217
178
  pi.has_callbacks = true;
218
179
 
219
180
  if (T_STRING == rb_type(input)) {
220
- return oj_pi_parse(argc - 1, argv + 1, &pi, 0, 0, 1);
181
+ return oj_pi_parse(argc - 1, argv + 1, &pi, 0, 0, 1);
221
182
  } else {
222
- return oj_pi_sparse(argc - 1, argv + 1, &pi, 0);
183
+ return oj_pi_sparse(argc - 1, argv + 1, &pi, 0);
223
184
  }
224
185
  }
data/ext/oj/simd.h ADDED
@@ -0,0 +1,10 @@
1
+ #ifndef OJ_SIMD_H
2
+ #define OJ_SIMD_H
3
+
4
+ #if defined(__ARM_NEON) || defined(__ARM_NEON__) || defined(__aarch64__) || defined(_M_ARM64)
5
+ #define HAVE_SIMD_NEON 1
6
+ #define SIMD_MINIMUM_THRESHOLD 6
7
+ #include <arm_neon.h>
8
+ #endif
9
+
10
+ #endif /* OJ_SIMD_H */