oj 3.13.11 → 3.13.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -0
  3. data/README.md +2 -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 +62 -108
  9. data/ext/oj/dump.c +85 -97
  10. data/ext/oj/dump.h +12 -8
  11. data/ext/oj/dump_compat.c +46 -88
  12. data/ext/oj/dump_leaf.c +14 -58
  13. data/ext/oj/dump_object.c +33 -156
  14. data/ext/oj/dump_strict.c +17 -29
  15. data/ext/oj/extconf.rb +5 -4
  16. data/ext/oj/fast.c +24 -22
  17. data/ext/oj/intern.c +15 -11
  18. data/ext/oj/intern.h +1 -1
  19. data/ext/oj/mimic_json.c +44 -32
  20. data/ext/oj/object.c +42 -41
  21. data/ext/oj/odd.c +83 -63
  22. data/ext/oj/odd.h +13 -13
  23. data/ext/oj/oj.c +57 -22
  24. data/ext/oj/oj.h +24 -3
  25. data/ext/oj/parse.c +114 -78
  26. data/ext/oj/parse.h +2 -0
  27. data/ext/oj/parser.c +77 -21
  28. data/ext/oj/parser.h +12 -0
  29. data/ext/oj/rails.c +41 -65
  30. data/ext/oj/rails.h +1 -1
  31. data/ext/oj/reader.c +2 -0
  32. data/ext/oj/saj.c +11 -23
  33. data/ext/oj/saj2.c +333 -85
  34. data/ext/oj/saj2.h +23 -0
  35. data/ext/oj/sparse.c +4 -0
  36. data/ext/oj/stream_writer.c +3 -1
  37. data/ext/oj/strict.c +13 -13
  38. data/ext/oj/string_writer.c +12 -5
  39. data/ext/oj/usual.c +82 -129
  40. data/ext/oj/usual.h +68 -0
  41. data/ext/oj/val_stack.c +1 -1
  42. data/ext/oj/validate.c +21 -26
  43. data/ext/oj/wab.c +21 -26
  44. data/lib/oj/saj.rb +20 -6
  45. data/lib/oj/state.rb +1 -1
  46. data/lib/oj/version.rb +1 -1
  47. data/pages/Compatibility.md +1 -1
  48. data/pages/Options.md +6 -0
  49. data/test/activesupport7/abstract_unit.rb +49 -0
  50. data/test/activesupport7/decoding_test.rb +125 -0
  51. data/test/activesupport7/encoding_test.rb +486 -0
  52. data/test/activesupport7/encoding_test_cases.rb +104 -0
  53. data/test/activesupport7/time_zone_test_helpers.rb +47 -0
  54. data/test/bar.rb +3 -8
  55. data/test/foo.rb +3 -3
  56. data/test/helper.rb +8 -2
  57. data/test/json_gem/json_generator_test.rb +5 -4
  58. data/test/json_gem/json_parser_test.rb +8 -1
  59. data/test/json_gem/test_helper.rb +7 -3
  60. data/test/perf_dump.rb +50 -0
  61. data/test/test_compat.rb +25 -0
  62. data/test/test_custom.rb +13 -2
  63. data/test/test_file.rb +23 -7
  64. data/test/test_gc.rb +11 -0
  65. data/test/test_object.rb +8 -10
  66. data/test/test_parser.rb +3 -19
  67. data/test/test_parser_debug.rb +27 -0
  68. data/test/test_parser_saj.rb +92 -2
  69. data/test/test_scp.rb +2 -4
  70. data/test/test_strict.rb +2 -0
  71. data/test/test_various.rb +8 -3
  72. data/test/test_wab.rb +2 -0
  73. data/test/tests.rb +9 -0
  74. data/test/tests_mimic.rb +9 -0
  75. data/test/tests_mimic_addition.rb +9 -0
  76. metadata +13 -116
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcb5f80ad6384640d44889424c39f91ee2db778b17c91b9505b5b3b4c280abf1
4
- data.tar.gz: 85b70200f48f46019ecf1020ca8e1b8ea604bca1161120b3747a8aeac2903682
3
+ metadata.gz: 3d2f8a01b7a59da7cd25ed3551065dddd9e31e5184989804d172c2e39cc769d6
4
+ data.tar.gz: 7211a96856ec44173fa9dcc7245e3cb2f6b7c2e22a746ef35f168126873f4c88
5
5
  SHA512:
6
- metadata.gz: f96776be4f9431b160f1d9f588e8688fb7e0c4a431c58a10fa43a71f5a6f95781456287f40db5dfba03bb69350946ad36f246d0b59c196f9dc95218f51005f7a
7
- data.tar.gz: e106b88134f86d82b9740f3e836ecb2aaa4af7ad643b96a4600eaa09392ba5f630c402101a6fb476823c41bc127b5c3d9625c6900a033cf6f9830ca01e57d459
6
+ metadata.gz: ee3ad5cac6cac48bcf7fdf682e69770dfee08b502735cc75b84ae1635196fdcdaf2fde021e32e6d897bdc6935e111882ddc48fa5a274fe0d98ad45c2fdf68917
7
+ data.tar.gz: 3e05212fa84a2bf05954ec870ac27da7c845335b411507aa0bf5e45497403cccf4c40990f0ee8cee6d21f19163f33116bb240836795482737eaa744bc5ff6d94
data/CHANGELOG.md CHANGED
@@ -1,5 +1,55 @@
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
+
3
53
  ## 3.13.11 - 2022-01-05
4
54
 
5
55
  - Fixed write blocking failures on writes to a slow stream with larger writes.
data/README.md CHANGED
@@ -109,6 +109,8 @@ Follow [@peterohler on Twitter](http://twitter.com/peterohler) for announcements
109
109
 
110
110
  - *Agoo-C, a high performance C web server supporting GraphQL on GitHub*: https://github.com/ohler55/agoo-c
111
111
 
112
+ - *oj-introspect, an example of creating an Oj parser extension in C*: https://github.com/meinac/oj-introspect
113
+
112
114
  #### Contributing
113
115
 
114
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
  }