oj 3.13.7 → 3.13.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +75 -0
  3. data/README.md +11 -0
  4. data/ext/oj/buf.h +4 -0
  5. data/ext/oj/circarray.c +1 -1
  6. data/ext/oj/code.c +15 -22
  7. data/ext/oj/compat.c +10 -10
  8. data/ext/oj/custom.c +66 -112
  9. data/ext/oj/dump.c +147 -184
  10. data/ext/oj/dump.h +25 -8
  11. data/ext/oj/dump_compat.c +47 -89
  12. data/ext/oj/dump_leaf.c +14 -58
  13. data/ext/oj/dump_object.c +72 -188
  14. data/ext/oj/dump_strict.c +19 -31
  15. data/ext/oj/encoder.c +43 -0
  16. data/ext/oj/extconf.rb +5 -4
  17. data/ext/oj/fast.c +36 -24
  18. data/ext/oj/intern.c +22 -12
  19. data/ext/oj/intern.h +1 -1
  20. data/ext/oj/mimic_json.c +74 -73
  21. data/ext/oj/object.c +54 -72
  22. data/ext/oj/odd.c +83 -63
  23. data/ext/oj/odd.h +13 -13
  24. data/ext/oj/oj.c +166 -175
  25. data/ext/oj/oj.h +25 -3
  26. data/ext/oj/parse.c +123 -79
  27. data/ext/oj/parse.h +2 -0
  28. data/ext/oj/parser.c +77 -21
  29. data/ext/oj/parser.h +12 -0
  30. data/ext/oj/rails.c +46 -70
  31. data/ext/oj/rails.h +1 -1
  32. data/ext/oj/reader.c +2 -0
  33. data/ext/oj/saj.c +11 -23
  34. data/ext/oj/saj2.c +333 -85
  35. data/ext/oj/saj2.h +23 -0
  36. data/ext/oj/sparse.c +4 -0
  37. data/ext/oj/stream_writer.c +3 -1
  38. data/ext/oj/strict.c +13 -13
  39. data/ext/oj/string_writer.c +12 -5
  40. data/ext/oj/usual.c +86 -131
  41. data/ext/oj/usual.h +68 -0
  42. data/ext/oj/val_stack.c +1 -1
  43. data/ext/oj/validate.c +21 -26
  44. data/ext/oj/wab.c +22 -27
  45. data/lib/oj/saj.rb +20 -6
  46. data/lib/oj/state.rb +1 -1
  47. data/lib/oj/version.rb +1 -1
  48. data/pages/Compatibility.md +1 -1
  49. data/pages/JsonGem.md +15 -0
  50. data/pages/Modes.md +6 -3
  51. data/pages/Options.md +6 -0
  52. data/pages/Rails.md +12 -0
  53. data/test/activesupport7/abstract_unit.rb +49 -0
  54. data/test/activesupport7/decoding_test.rb +125 -0
  55. data/test/activesupport7/encoding_test.rb +486 -0
  56. data/test/activesupport7/encoding_test_cases.rb +104 -0
  57. data/test/activesupport7/time_zone_test_helpers.rb +47 -0
  58. data/test/bar.rb +3 -8
  59. data/test/bug.rb +16 -0
  60. data/test/foo.rb +71 -7
  61. data/test/helper.rb +8 -2
  62. data/test/json_gem/json_generator_test.rb +5 -4
  63. data/test/json_gem/json_parser_test.rb +8 -1
  64. data/test/json_gem/test_helper.rb +7 -3
  65. data/test/perf_dump.rb +50 -0
  66. data/test/test_compat.rb +25 -0
  67. data/test/test_custom.rb +13 -2
  68. data/test/test_fast.rb +37 -7
  69. data/test/test_file.rb +23 -7
  70. data/test/test_gc.rb +11 -0
  71. data/test/test_object.rb +8 -10
  72. data/test/test_parser.rb +3 -19
  73. data/test/test_parser_debug.rb +27 -0
  74. data/test/test_parser_saj.rb +92 -2
  75. data/test/test_saj.rb +1 -1
  76. data/test/test_scp.rb +2 -4
  77. data/test/test_strict.rb +2 -0
  78. data/test/test_various.rb +32 -2
  79. data/test/test_wab.rb +2 -0
  80. data/test/tests.rb +9 -1
  81. data/test/tests_mimic.rb +9 -0
  82. data/test/tests_mimic_addition.rb +9 -0
  83. metadata +15 -115
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44e493d06f06095e80eb1af563739efca81076a8d3cfd89d02e537ada1f00a60
4
- data.tar.gz: 9502a2285781a49c8a2cec4937bb92c1b04a4c95e44b8f34fdd9a6295f0f69f4
3
+ metadata.gz: 3d2f8a01b7a59da7cd25ed3551065dddd9e31e5184989804d172c2e39cc769d6
4
+ data.tar.gz: 7211a96856ec44173fa9dcc7245e3cb2f6b7c2e22a746ef35f168126873f4c88
5
5
  SHA512:
6
- metadata.gz: fa5e096b0ec018cc964c98e108967e766454d48bbfbd7a0ec55fc86aa2e4cac1d54f2b069613823d183df128ed836c95b2b3851793243985b531bbe41b045132
7
- data.tar.gz: 22a9ded2a0442a64f4ac91e3fc5b1d0be86ea6c53dd857039a92ef515a74b6e348b3587899df5e4a78550ec8e1c4c7c06986a0b8912ef90a419e6c8ac2f65450
6
+ metadata.gz: ee3ad5cac6cac48bcf7fdf682e69770dfee08b502735cc75b84ae1635196fdcdaf2fde021e32e6d897bdc6935e111882ddc48fa5a274fe0d98ad45c2fdf68917
7
+ data.tar.gz: 3e05212fa84a2bf05954ec870ac27da7c845335b411507aa0bf5e45497403cccf4c40990f0ee8cee6d21f19163f33116bb240836795482737eaa744bc5ff6d94
data/CHANGELOG.md CHANGED
@@ -1,5 +1,80 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 3.13.23 - 2022-11-06
4
+
5
+ - Fixed issue with Oj::Parser extension regarding GC timeing.
6
+
7
+ ## 3.13.22 - 2022-11-01
8
+
9
+ - Reorganized Oj::Parser code to allow for parser extensions in C.
10
+
11
+ ## 3.13.21 - 2022-08-19
12
+
13
+ - Bug parsing big numbers fixed in the SAJ parser.
14
+
15
+ ## 3.13.20 - 2022-08-07
16
+
17
+ - SSE4 made optional with a `--with-sse42` flag to the compile.
18
+
19
+ ## 3.13.19 - 2022-07-29
20
+
21
+ - TruffleRuby issues resolved.
22
+
23
+ ## 3.13.18 - 2022-07-25
24
+
25
+ - Fixed SSE detection at run time.
26
+
27
+ ## 3.13.17 - 2022-07-15
28
+
29
+ - Fixed Oj::Parser to detect unterminated arrays and objects.
30
+
31
+ ## 3.13.16 - 2022-07-06
32
+
33
+ - Added line and column as optional arguments to the Oj::Parser.saj parser.
34
+
35
+ ## 3.13.15 - 2022-07-03
36
+
37
+ - Fixed issue dumping NaN value in object mode.
38
+
39
+ ## 3.13.14 - 2022-06-03
40
+
41
+ - Double fclose() due to bad merger fixed by tonobo.
42
+
43
+ ## 3.13.13 - 2022-05-20
44
+
45
+ - Fixed flooding stdout with debug output when dumping.
46
+
47
+ ## 3.13.12 - 2022-05-20
48
+
49
+ - Fixed crash on no arguments to pretty_generate. Now raises an exception.
50
+ - Register all classes and globals.
51
+ - Fixed memory issue with dumping.
52
+
53
+ ## 3.13.11 - 2022-01-05
54
+
55
+ - Fixed write blocking failures on writes to a slow stream with larger writes.
56
+
57
+ ## 3.13.10 - 2021-12-12
58
+
59
+ - Fixed Oj::Doc re-entrant issue with each_child.
60
+ - Fixed each_child on empty Oj::Doc.
61
+
62
+ ## 3.13.9 - 2021-10-06
63
+
64
+ - Fix mimic JSON load so that it honors the `:symbolize_names` option.
65
+
66
+ ## 3.13.8 - 2021-09-27
67
+
68
+ - Fix `Oj::Doc` behaviour for inexisting path.
69
+ ```ruby
70
+ Oj::Doc.open('{"foo":1}') do |doc|
71
+ doc.fetch('/foo/bar') # used to give `1`, now gives `nil`
72
+ doc.exists?('/foo/bar') # used to give `true`, now gives `false`
73
+ end
74
+ ```
75
+
76
+ - Fix `Oj::Parser` handling of BigDecimal. `snprint()` does not handle `%Lg` correctly but `sprintf()` does.
77
+
3
78
  ## 3.13.7 - 2021-09-16
4
79
 
5
80
  - The JSON gem allows invalid unicode so Oj, when mimicing JSON now
data/README.md CHANGED
@@ -43,6 +43,15 @@ or in Bundler:
43
43
  gem 'oj'
44
44
  ```
45
45
 
46
+ ## Rails and json quickstart
47
+
48
+ See the Quickstart sections of the [Rails](pages/Rails.md) and [json](pages/JsonGem.md) docs.
49
+
50
+ ## multi_json
51
+
52
+ Code which uses [multi_json](https://github.com/intridea/multi_json)
53
+ will automatically prefer Oj if it is installed.
54
+
46
55
  ## Support
47
56
 
48
57
  [Get supported Oj with a Tidelift Subscription.](https://tidelift.com/subscription/pkg/rubygems-oj?utm_source=rubygems-oj&utm_medium=referral&utm_campaign=readme) Security updates are [supported](https://tidelift.com/security).
@@ -100,6 +109,8 @@ Follow [@peterohler on Twitter](http://twitter.com/peterohler) for announcements
100
109
 
101
110
  - *Agoo-C, a high performance C web server supporting GraphQL on GitHub*: https://github.com/ohler55/agoo-c
102
111
 
112
+ - *oj-introspect, an example of creating an Oj parser extension in C*: https://github.com/meinac/oj-introspect
113
+
103
114
  #### Contributing
104
115
 
105
116
  + Provide a Pull Request off the `develop` branch.
data/ext/oj/buf.h CHANGED
@@ -39,6 +39,10 @@ inline static const char *buf_str(Buf buf) {
39
39
  }
40
40
 
41
41
  inline static void buf_append_string(Buf buf, const char *s, size_t slen) {
42
+ if (0 == slen) {
43
+ return;
44
+ }
45
+
42
46
  if (buf->end <= buf->tail + slen) {
43
47
  size_t len = buf->end - buf->head;
44
48
  size_t toff = buf->tail - buf->head;
data/ext/oj/circarray.c CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  #include "circarray.h"
5
5
 
6
- CircArray oj_circ_array_new() {
6
+ CircArray oj_circ_array_new(void) {
7
7
  CircArray ca;
8
8
 
9
9
  if (0 == (ca = ALLOC(struct _circArray))) {
data/ext/oj/code.c CHANGED
@@ -140,21 +140,17 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
140
140
  if (with_class) {
141
141
  fill_indent(out, d2);
142
142
  *out->cur++ = '"';
143
- memcpy(out->cur, out->opts->create_id, out->opts->create_id_len);
144
- out->cur += out->opts->create_id_len;
143
+ APPEND_CHARS(out->cur, out->opts->create_id, out->opts->create_id_len);
145
144
  *out->cur++ = '"';
146
145
  if (0 < out->opts->dump_opts.before_size) {
147
- strcpy(out->cur, out->opts->dump_opts.before_sep);
148
- out->cur += out->opts->dump_opts.before_size;
146
+ APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
149
147
  }
150
148
  *out->cur++ = ':';
151
149
  if (0 < out->opts->dump_opts.after_size) {
152
- strcpy(out->cur, out->opts->dump_opts.after_sep);
153
- out->cur += out->opts->dump_opts.after_size;
150
+ APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
154
151
  }
155
152
  *out->cur++ = '"';
156
- memcpy(out->cur, classname, len);
157
- out->cur += len;
153
+ APPEND_CHARS(out->cur, classname, len);
158
154
  *out->cur++ = '"';
159
155
  no_comma = false;
160
156
  }
@@ -168,17 +164,14 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
168
164
  }
169
165
  fill_indent(out, d2);
170
166
  *out->cur++ = '"';
171
- memcpy(out->cur, attrs->name, attrs->len);
172
- out->cur += attrs->len;
167
+ APPEND_CHARS(out->cur, attrs->name, attrs->len);
173
168
  *out->cur++ = '"';
174
169
  if (0 < out->opts->dump_opts.before_size) {
175
- strcpy(out->cur, out->opts->dump_opts.before_sep);
176
- out->cur += out->opts->dump_opts.before_size;
170
+ APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
177
171
  }
178
172
  *out->cur++ = ':';
179
173
  if (0 < out->opts->dump_opts.after_size) {
180
- strcpy(out->cur, out->opts->dump_opts.after_sep);
181
- out->cur += out->opts->dump_opts.after_size;
174
+ APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
182
175
  }
183
176
  if (Qundef == attrs->value) {
184
177
  if (Qundef != attrs->time) {
@@ -190,10 +183,11 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
190
183
  default: oj_dump_time(attrs->time, out, false); break;
191
184
  }
192
185
  } else {
193
- char buf[32];
194
- char *b = buf + sizeof(buf) - 1;
195
- int neg = 0;
196
- long num = attrs->num;
186
+ char buf[32];
187
+ char *b = buf + sizeof(buf) - 1;
188
+ int neg = 0;
189
+ long num = attrs->num;
190
+ size_t cnt = 0;
197
191
 
198
192
  if (0 > num) {
199
193
  neg = 1;
@@ -212,10 +206,9 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
212
206
  } else {
213
207
  *b = '0';
214
208
  }
215
- assure_size(out, (sizeof(buf) - (b - buf)));
216
- for (; '\0' != *b; b++) {
217
- *out->cur++ = *b;
218
- }
209
+ cnt = sizeof(buf) - (b - buf) - 1;
210
+ assure_size(out, cnt);
211
+ APPEND_CHARS(out->cur, b, cnt);
219
212
  }
220
213
  } else {
221
214
  oj_dump_compat_val(attrs->value, d3, out, true);
data/ext/oj/compat.c CHANGED
@@ -54,7 +54,7 @@ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, c
54
54
  } else {
55
55
  rb_hash_aset(parent->val, rkey, rstr);
56
56
  }
57
- if (Yes == pi->options.trace) {
57
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
58
58
  oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rstr);
59
59
  }
60
60
  }
@@ -68,7 +68,7 @@ static VALUE start_hash(ParseInfo pi) {
68
68
  } else {
69
69
  h = rb_hash_new();
70
70
  }
71
- if (Yes == pi->options.trace) {
71
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
72
72
  oj_trace_parse_in("start_hash", pi, __FILE__, __LINE__);
73
73
  }
74
74
  return h;
@@ -93,7 +93,7 @@ static void end_hash(struct _parseInfo *pi) {
93
93
  parent->classname = 0;
94
94
  }
95
95
  }
96
- if (Yes == pi->options.trace) {
96
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
97
97
  oj_trace_parse_hash_end(pi, __FILE__, __LINE__);
98
98
  }
99
99
  }
@@ -110,14 +110,14 @@ static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig
110
110
  }
111
111
  }
112
112
  pi->stack.head->val = rstr;
113
- if (Yes == pi->options.trace) {
113
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
114
114
  oj_trace_parse_call("add_string", pi, __FILE__, __LINE__, rstr);
115
115
  }
116
116
  }
117
117
 
118
118
  static void add_num(ParseInfo pi, NumInfo ni) {
119
119
  pi->stack.head->val = oj_num_as_value(ni);
120
- if (Yes == pi->options.trace) {
120
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
121
121
  oj_trace_parse_call("add_number", pi, __FILE__, __LINE__, pi->stack.head->val);
122
122
  }
123
123
  }
@@ -138,7 +138,7 @@ static void hash_set_num(struct _parseInfo *pi, Val parent, NumInfo ni) {
138
138
  } else {
139
139
  rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), rval);
140
140
  }
141
- if (Yes == pi->options.trace) {
141
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
142
142
  oj_trace_parse_call("set_number", pi, __FILE__, __LINE__, rval);
143
143
  }
144
144
  }
@@ -157,7 +157,7 @@ static void hash_set_value(ParseInfo pi, Val parent, VALUE value) {
157
157
  } else {
158
158
  rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), value);
159
159
  }
160
- if (Yes == pi->options.trace) {
160
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
161
161
  oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, value);
162
162
  }
163
163
  }
@@ -166,7 +166,7 @@ static VALUE start_array(ParseInfo pi) {
166
166
  if (Qnil != pi->options.array_class) {
167
167
  return rb_class_new_instance(0, NULL, pi->options.array_class);
168
168
  }
169
- if (Yes == pi->options.trace) {
169
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
170
170
  oj_trace_parse_in("start_array", pi, __FILE__, __LINE__);
171
171
  }
172
172
  return rb_ary_new();
@@ -184,7 +184,7 @@ static void array_append_num(ParseInfo pi, NumInfo ni) {
184
184
  } else {
185
185
  rb_ary_push(parent->val, rval);
186
186
  }
187
- if (Yes == pi->options.trace) {
187
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
188
188
  oj_trace_parse_call("append_number", pi, __FILE__, __LINE__, rval);
189
189
  }
190
190
  }
@@ -201,7 +201,7 @@ static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const c
201
201
  }
202
202
  }
203
203
  rb_ary_push(stack_peek(&pi->stack)->val, rstr);
204
- if (Yes == pi->options.trace) {
204
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
205
205
  oj_trace_parse_call("append_string", pi, __FILE__, __LINE__, rstr);
206
206
  }
207
207
  }