oj 3.7.4 → 3.13.21

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 (142) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1352 -0
  3. data/README.md +29 -8
  4. data/RELEASE_NOTES.md +61 -0
  5. data/ext/oj/buf.h +53 -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 -43
  11. data/ext/oj/circarray.h +16 -17
  12. data/ext/oj/code.c +165 -179
  13. data/ext/oj/code.h +27 -29
  14. data/ext/oj/compat.c +174 -194
  15. data/ext/oj/custom.c +809 -866
  16. data/ext/oj/debug.c +132 -0
  17. data/ext/oj/dump.c +848 -863
  18. data/ext/oj/dump.h +81 -67
  19. data/ext/oj/dump_compat.c +85 -123
  20. data/ext/oj/dump_leaf.c +100 -188
  21. data/ext/oj/dump_object.c +527 -656
  22. data/ext/oj/dump_strict.c +315 -338
  23. data/ext/oj/encode.h +7 -34
  24. data/ext/oj/encoder.c +43 -0
  25. data/ext/oj/err.c +40 -29
  26. data/ext/oj/err.h +48 -48
  27. data/ext/oj/extconf.rb +17 -4
  28. data/ext/oj/fast.c +1070 -1087
  29. data/ext/oj/intern.c +301 -0
  30. data/ext/oj/intern.h +26 -0
  31. data/ext/oj/mimic_json.c +469 -436
  32. data/ext/oj/object.c +525 -593
  33. data/ext/oj/odd.c +154 -138
  34. data/ext/oj/odd.h +37 -38
  35. data/ext/oj/oj.c +1325 -986
  36. data/ext/oj/oj.h +333 -316
  37. data/ext/oj/parse.c +1002 -846
  38. data/ext/oj/parse.h +92 -87
  39. data/ext/oj/parser.c +1557 -0
  40. data/ext/oj/parser.h +91 -0
  41. data/ext/oj/rails.c +888 -878
  42. data/ext/oj/rails.h +11 -14
  43. data/ext/oj/reader.c +141 -147
  44. data/ext/oj/reader.h +73 -89
  45. data/ext/oj/resolve.c +41 -62
  46. data/ext/oj/resolve.h +7 -9
  47. data/ext/oj/rxclass.c +71 -75
  48. data/ext/oj/rxclass.h +18 -19
  49. data/ext/oj/saj.c +443 -486
  50. data/ext/oj/saj2.c +602 -0
  51. data/ext/oj/scp.c +88 -113
  52. data/ext/oj/sparse.c +787 -709
  53. data/ext/oj/stream_writer.c +133 -159
  54. data/ext/oj/strict.c +127 -118
  55. data/ext/oj/string_writer.c +230 -249
  56. data/ext/oj/trace.c +34 -41
  57. data/ext/oj/trace.h +19 -19
  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 +59 -67
  62. data/ext/oj/val_stack.h +91 -129
  63. data/ext/oj/validate.c +46 -0
  64. data/ext/oj/wab.c +342 -353
  65. data/lib/oj/bag.rb +1 -0
  66. data/lib/oj/easy_hash.rb +5 -4
  67. data/lib/oj/error.rb +1 -1
  68. data/lib/oj/json.rb +1 -1
  69. data/lib/oj/mimic.rb +48 -14
  70. data/lib/oj/saj.rb +20 -6
  71. data/lib/oj/state.rb +8 -7
  72. data/lib/oj/version.rb +2 -2
  73. data/lib/oj.rb +0 -8
  74. data/pages/Compatibility.md +1 -1
  75. data/pages/JsonGem.md +15 -0
  76. data/pages/Modes.md +53 -46
  77. data/pages/Options.md +72 -11
  78. data/pages/Parser.md +309 -0
  79. data/pages/Rails.md +73 -22
  80. data/pages/Security.md +1 -1
  81. data/test/activerecord/result_test.rb +7 -2
  82. data/test/activesupport5/abstract_unit.rb +45 -0
  83. data/test/activesupport5/decoding_test.rb +68 -60
  84. data/test/activesupport5/encoding_test.rb +111 -96
  85. data/test/activesupport5/encoding_test_cases.rb +33 -25
  86. data/test/activesupport5/test_helper.rb +43 -21
  87. data/test/activesupport5/time_zone_test_helpers.rb +18 -3
  88. data/test/activesupport6/abstract_unit.rb +44 -0
  89. data/test/activesupport6/decoding_test.rb +133 -0
  90. data/test/activesupport6/encoding_test.rb +507 -0
  91. data/test/activesupport6/encoding_test_cases.rb +98 -0
  92. data/test/activesupport6/test_common.rb +17 -0
  93. data/test/activesupport6/test_helper.rb +163 -0
  94. data/test/activesupport6/time_zone_test_helpers.rb +39 -0
  95. data/test/activesupport7/abstract_unit.rb +49 -0
  96. data/test/activesupport7/decoding_test.rb +125 -0
  97. data/test/activesupport7/encoding_test.rb +486 -0
  98. data/test/activesupport7/encoding_test_cases.rb +104 -0
  99. data/test/activesupport7/time_zone_test_helpers.rb +47 -0
  100. data/test/bar.rb +6 -12
  101. data/test/baz.rb +16 -0
  102. data/test/bug.rb +16 -0
  103. data/test/foo.rb +69 -75
  104. data/test/helper.rb +16 -0
  105. data/test/json_gem/json_common_interface_test.rb +8 -3
  106. data/test/json_gem/json_generator_test.rb +18 -4
  107. data/test/json_gem/json_parser_test.rb +9 -0
  108. data/test/json_gem/test_helper.rb +12 -0
  109. data/test/mem.rb +33 -0
  110. data/test/perf.rb +1 -1
  111. data/test/perf_dump.rb +50 -0
  112. data/test/perf_once.rb +58 -0
  113. data/test/perf_parser.rb +189 -0
  114. data/test/perf_scp.rb +11 -10
  115. data/test/perf_strict.rb +17 -23
  116. data/test/prec.rb +23 -0
  117. data/test/sample_json.rb +1 -1
  118. data/test/test_compat.rb +46 -10
  119. data/test/test_custom.rb +147 -8
  120. data/test/test_fast.rb +62 -2
  121. data/test/test_file.rb +25 -2
  122. data/test/test_gc.rb +13 -0
  123. data/test/test_generate.rb +21 -0
  124. data/test/test_hash.rb +11 -1
  125. data/test/test_integer_range.rb +7 -2
  126. data/test/test_object.rb +85 -9
  127. data/test/test_parser.rb +27 -0
  128. data/test/test_parser_saj.rb +335 -0
  129. data/test/test_parser_usual.rb +217 -0
  130. data/test/test_rails.rb +35 -0
  131. data/test/test_saj.rb +1 -1
  132. data/test/test_scp.rb +5 -5
  133. data/test/test_strict.rb +26 -1
  134. data/test/test_various.rb +87 -65
  135. data/test/test_wab.rb +2 -0
  136. data/test/test_writer.rb +19 -2
  137. data/test/tests.rb +1 -1
  138. data/test/zoo.rb +13 -0
  139. metadata +60 -110
  140. data/ext/oj/hash.c +0 -163
  141. data/ext/oj/hash.h +0 -46
  142. data/ext/oj/hash_test.c +0 -512
data/ext/oj/scp.c CHANGED
@@ -1,42 +1,35 @@
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(struct _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
 
@@ -44,181 +37,163 @@ static void
44
37
  noop_hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
45
38
  }
46
39
 
47
- static void
48
- noop_hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
40
+ static void noop_hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
49
41
  }
50
42
 
51
- static void
52
- noop_hash_set_value(ParseInfo pi, Val kval, VALUE value) {
43
+ static void noop_hash_set_value(ParseInfo pi, Val kval, VALUE value) {
53
44
  }
54
45
 
55
- static void
56
- noop_array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
46
+ static void noop_array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
57
47
  }
58
48
 
59
- static void
60
- noop_array_append_num(ParseInfo pi, NumInfo ni) {
49
+ static void noop_array_append_num(ParseInfo pi, NumInfo ni) {
61
50
  }
62
51
 
63
- static void
64
- noop_array_append_value(ParseInfo pi, VALUE value) {
52
+ static void noop_array_append_value(ParseInfo pi, VALUE value) {
65
53
  }
66
54
 
67
- static void
68
- add_value(ParseInfo pi, VALUE val) {
55
+ static void add_value(ParseInfo pi, VALUE val) {
69
56
  rb_funcall(pi->handler, oj_add_value_id, 1, val);
70
57
  }
71
58
 
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);
59
+ static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
60
+ volatile VALUE rstr = rb_str_new(str, len);
75
61
 
76
62
  rstr = oj_encode(rstr);
77
63
  rb_funcall(pi->handler, oj_add_value_id, 1, rstr);
78
64
  }
79
65
 
80
- static void
81
- add_num(ParseInfo pi, NumInfo ni) {
66
+ static void add_num(ParseInfo pi, NumInfo ni) {
82
67
  rb_funcall(pi->handler, oj_add_value_id, 1, oj_num_as_value(ni));
83
68
  }
84
69
 
85
- static VALUE
86
- start_hash(ParseInfo pi) {
70
+ static VALUE start_hash(ParseInfo pi) {
87
71
  return rb_funcall(pi->handler, oj_hash_start_id, 0);
88
72
  }
89
73
 
90
- static void
91
- end_hash(ParseInfo pi) {
74
+ static void end_hash(ParseInfo pi) {
92
75
  rb_funcall(pi->handler, oj_hash_end_id, 0);
93
76
  }
94
77
 
95
- static VALUE
96
- start_array(ParseInfo pi) {
78
+ static VALUE start_array(ParseInfo pi) {
97
79
  return rb_funcall(pi->handler, oj_array_start_id, 0);
98
80
  }
99
81
 
100
- static void
101
- end_array(ParseInfo pi) {
82
+ static void end_array(ParseInfo pi) {
102
83
  rb_funcall(pi->handler, oj_array_end_id, 0);
103
84
  }
104
85
 
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(struct _ParseInfo *pi, const char *key, size_t klen) {
86
+ static VALUE hash_key(ParseInfo pi, const char *key, size_t klen) {
121
87
  return rb_funcall(pi->handler, oj_hash_key_id, 1, rb_str_new(key, klen));
122
88
  }
123
89
 
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);
90
+ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
91
+ volatile VALUE rstr = rb_str_new(str, len);
127
92
 
128
93
  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);
94
+ rb_funcall(pi->handler,
95
+ oj_hash_set_id,
96
+ 3,
97
+ stack_peek(&pi->stack)->val,
98
+ oj_calc_hash_key(pi, kval),
99
+ rstr);
130
100
  }
131
101
 
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));
102
+ static void hash_set_num(ParseInfo pi, Val kval, NumInfo ni) {
103
+ rb_funcall(pi->handler,
104
+ oj_hash_set_id,
105
+ 3,
106
+ stack_peek(&pi->stack)->val,
107
+ oj_calc_hash_key(pi, kval),
108
+ oj_num_as_value(ni));
135
109
  }
136
110
 
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);
111
+ static void hash_set_value(ParseInfo pi, Val kval, VALUE value) {
112
+ rb_funcall(pi->handler,
113
+ oj_hash_set_id,
114
+ 3,
115
+ stack_peek(&pi->stack)->val,
116
+ oj_calc_hash_key(pi, kval),
117
+ value);
140
118
  }
141
119
 
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);
120
+ static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
121
+ volatile VALUE rstr = rb_str_new(str, len);
145
122
 
146
123
  rstr = oj_encode(rstr);
147
124
  rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, rstr);
148
125
  }
149
126
 
150
- static void
151
- array_append_num(ParseInfo pi, NumInfo ni) {
127
+ static void array_append_num(ParseInfo pi, NumInfo ni) {
152
128
  rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, oj_num_as_value(ni));
153
129
  }
154
130
 
155
- static void
156
- array_append_value(ParseInfo pi, VALUE value) {
131
+ static void array_append_value(ParseInfo pi, VALUE value) {
157
132
  rb_funcall(pi->handler, oj_array_append_id, 2, stack_peek(&pi->stack)->val, value);
158
133
  }
159
134
 
160
135
  VALUE
161
136
  oj_sc_parse(int argc, VALUE *argv, VALUE self) {
162
- struct _ParseInfo pi;
163
- VALUE input = argv[1];
137
+ struct _parseInfo pi;
138
+ VALUE input = argv[1];
164
139
 
165
140
  parse_info_init(&pi);
166
141
  pi.err_class = Qnil;
167
142
  pi.max_depth = 0;
168
- pi.options = oj_default_options;
143
+ pi.options = oj_default_options;
169
144
  if (3 == argc) {
170
- oj_parse_options(argv[2], &pi.options);
145
+ oj_parse_options(argv[2], &pi.options);
171
146
  }
172
147
  if (rb_block_given_p()) {
173
- pi.proc = Qnil;
148
+ pi.proc = Qnil;
174
149
  } else {
175
- pi.proc = Qundef;
150
+ pi.proc = Qundef;
176
151
  }
177
152
  pi.handler = *argv;
178
153
 
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;
154
+ pi.start_hash = rb_respond_to(pi.handler, oj_hash_start_id) ? start_hash : noop_start;
155
+ pi.end_hash = rb_respond_to(pi.handler, oj_hash_end_id) ? end_hash : noop_end;
156
+ pi.hash_key = rb_respond_to(pi.handler, oj_hash_key_id) ? hash_key : noop_hash_key;
182
157
  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;
158
+ pi.end_array = rb_respond_to(pi.handler, oj_array_end_id) ? end_array : noop_end;
184
159
  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;
160
+ pi.hash_set_value = hash_set_value;
161
+ pi.hash_set_cstr = hash_set_cstr;
162
+ pi.hash_set_num = hash_set_num;
163
+ pi.expect_value = 1;
189
164
  } 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;
165
+ pi.hash_set_value = noop_hash_set_value;
166
+ pi.hash_set_cstr = noop_hash_set_cstr;
167
+ pi.hash_set_num = noop_hash_set_num;
168
+ pi.expect_value = 0;
194
169
  }
195
170
  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;
171
+ pi.array_append_value = array_append_value;
172
+ pi.array_append_cstr = array_append_cstr;
173
+ pi.array_append_num = array_append_num;
174
+ pi.expect_value = 1;
200
175
  } 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;
176
+ pi.array_append_value = noop_array_append_value;
177
+ pi.array_append_cstr = noop_array_append_cstr;
178
+ pi.array_append_num = noop_array_append_num;
179
+ pi.expect_value = 0;
205
180
  }
206
181
  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;
182
+ pi.add_cstr = add_cstr;
183
+ pi.add_num = add_num;
184
+ pi.add_value = add_value;
185
+ pi.expect_value = 1;
211
186
  } 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;
187
+ pi.add_cstr = noop_add_cstr;
188
+ pi.add_num = noop_add_num;
189
+ pi.add_value = noop_add_value;
190
+ pi.expect_value = 0;
216
191
  }
217
192
  pi.has_callbacks = true;
218
193
 
219
194
  if (T_STRING == rb_type(input)) {
220
- return oj_pi_parse(argc - 1, argv + 1, &pi, 0, 0, 1);
195
+ return oj_pi_parse(argc - 1, argv + 1, &pi, 0, 0, 1);
221
196
  } else {
222
- return oj_pi_sparse(argc - 1, argv + 1, &pi, 0);
197
+ return oj_pi_sparse(argc - 1, argv + 1, &pi, 0);
223
198
  }
224
199
  }