oj 3.16.6 → 3.17.3

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 (130) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +81 -0
  3. data/README.md +0 -16
  4. data/ext/oj/compat.c +3 -3
  5. data/ext/oj/custom.c +17 -11
  6. data/ext/oj/dump.c +592 -81
  7. data/ext/oj/dump.h +9 -2
  8. data/ext/oj/dump_compat.c +15 -9
  9. data/ext/oj/dump_leaf.c +1 -1
  10. data/ext/oj/dump_object.c +32 -17
  11. data/ext/oj/dump_strict.c +20 -14
  12. data/ext/oj/extconf.rb +10 -7
  13. data/ext/oj/fast.c +40 -23
  14. data/ext/oj/intern.c +1 -1
  15. data/ext/oj/mimic_json.c +11 -7
  16. data/ext/oj/object.c +8 -8
  17. data/ext/oj/oj.c +256 -10
  18. data/ext/oj/oj.h +55 -52
  19. data/ext/oj/parse.c +243 -46
  20. data/ext/oj/parser.c +113 -37
  21. data/ext/oj/parser.h +2 -0
  22. data/ext/oj/rails.c +41 -36
  23. data/ext/oj/rxclass.c +1 -1
  24. data/ext/oj/rxclass.h +1 -1
  25. data/ext/oj/safe.c +230 -0
  26. data/ext/oj/safe.h +79 -0
  27. data/ext/oj/saj.c +13 -8
  28. data/ext/oj/scp.c +3 -6
  29. data/ext/oj/simd.h +219 -0
  30. data/ext/oj/sparse.c +6 -3
  31. data/ext/oj/stream_writer.c +3 -13
  32. data/ext/oj/strict.c +2 -4
  33. data/ext/oj/string_writer.c +5 -7
  34. data/ext/oj/usual.c +20 -7
  35. data/ext/oj/wab.c +5 -4
  36. data/lib/oj/version.rb +1 -1
  37. data/pages/Encoding.md +1 -1
  38. metadata +22 -114
  39. data/test/_test_active.rb +0 -75
  40. data/test/_test_active_mimic.rb +0 -95
  41. data/test/_test_mimic_rails.rb +0 -123
  42. data/test/activerecord/result_test.rb +0 -31
  43. data/test/activesupport6/abstract_unit.rb +0 -44
  44. data/test/activesupport6/decoding_test.rb +0 -133
  45. data/test/activesupport6/encoding_test.rb +0 -542
  46. data/test/activesupport6/encoding_test_cases.rb +0 -98
  47. data/test/activesupport6/test_common.rb +0 -17
  48. data/test/activesupport6/test_helper.rb +0 -163
  49. data/test/activesupport6/time_zone_test_helpers.rb +0 -39
  50. data/test/activesupport7/abstract_unit.rb +0 -52
  51. data/test/activesupport7/decoding_test.rb +0 -125
  52. data/test/activesupport7/encoding_test.rb +0 -536
  53. data/test/activesupport7/encoding_test_cases.rb +0 -104
  54. data/test/activesupport7/time_zone_test_helpers.rb +0 -47
  55. data/test/files.rb +0 -29
  56. data/test/foo.rb +0 -26
  57. data/test/helper.rb +0 -39
  58. data/test/isolated/shared.rb +0 -309
  59. data/test/isolated/test_mimic_after.rb +0 -13
  60. data/test/isolated/test_mimic_alone.rb +0 -12
  61. data/test/isolated/test_mimic_as_json.rb +0 -45
  62. data/test/isolated/test_mimic_before.rb +0 -13
  63. data/test/isolated/test_mimic_define.rb +0 -28
  64. data/test/isolated/test_mimic_rails_after.rb +0 -22
  65. data/test/isolated/test_mimic_rails_before.rb +0 -21
  66. data/test/isolated/test_mimic_redefine.rb +0 -15
  67. data/test/json_gem/json_addition_test.rb +0 -216
  68. data/test/json_gem/json_common_interface_test.rb +0 -155
  69. data/test/json_gem/json_encoding_test.rb +0 -107
  70. data/test/json_gem/json_ext_parser_test.rb +0 -21
  71. data/test/json_gem/json_fixtures_test.rb +0 -36
  72. data/test/json_gem/json_generator_test.rb +0 -413
  73. data/test/json_gem/json_generic_object_test.rb +0 -90
  74. data/test/json_gem/json_parser_test.rb +0 -477
  75. data/test/json_gem/json_string_matching_test.rb +0 -42
  76. data/test/json_gem/test_helper.rb +0 -30
  77. data/test/mem.rb +0 -34
  78. data/test/perf.rb +0 -102
  79. data/test/perf_compat.rb +0 -128
  80. data/test/perf_dump.rb +0 -50
  81. data/test/perf_fast.rb +0 -162
  82. data/test/perf_file.rb +0 -62
  83. data/test/perf_object.rb +0 -134
  84. data/test/perf_once.rb +0 -59
  85. data/test/perf_parser.rb +0 -183
  86. data/test/perf_saj.rb +0 -101
  87. data/test/perf_scp.rb +0 -140
  88. data/test/perf_simple.rb +0 -289
  89. data/test/perf_strict.rb +0 -137
  90. data/test/perf_wab.rb +0 -129
  91. data/test/prec.rb +0 -23
  92. data/test/sample/change.rb +0 -13
  93. data/test/sample/dir.rb +0 -18
  94. data/test/sample/doc.rb +0 -35
  95. data/test/sample/file.rb +0 -47
  96. data/test/sample/group.rb +0 -15
  97. data/test/sample/hasprops.rb +0 -15
  98. data/test/sample/layer.rb +0 -11
  99. data/test/sample/line.rb +0 -20
  100. data/test/sample/oval.rb +0 -10
  101. data/test/sample/rect.rb +0 -9
  102. data/test/sample/shape.rb +0 -34
  103. data/test/sample/text.rb +0 -19
  104. data/test/sample.rb +0 -54
  105. data/test/sample_json.rb +0 -37
  106. data/test/test_compat.rb +0 -567
  107. data/test/test_custom.rb +0 -555
  108. data/test/test_debian.rb +0 -50
  109. data/test/test_fast.rb +0 -526
  110. data/test/test_file.rb +0 -250
  111. data/test/test_gc.rb +0 -60
  112. data/test/test_generate.rb +0 -21
  113. data/test/test_hash.rb +0 -39
  114. data/test/test_integer_range.rb +0 -72
  115. data/test/test_null.rb +0 -376
  116. data/test/test_object.rb +0 -1030
  117. data/test/test_parser.rb +0 -11
  118. data/test/test_parser_debug.rb +0 -27
  119. data/test/test_parser_saj.rb +0 -337
  120. data/test/test_parser_usual.rb +0 -251
  121. data/test/test_rails.rb +0 -35
  122. data/test/test_saj.rb +0 -188
  123. data/test/test_scp.rb +0 -431
  124. data/test/test_strict.rb +0 -441
  125. data/test/test_various.rb +0 -801
  126. data/test/test_wab.rb +0 -311
  127. data/test/test_writer.rb +0 -380
  128. data/test/tests.rb +0 -33
  129. data/test/tests_mimic.rb +0 -23
  130. data/test/tests_mimic_addition.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95bab421dc901891ec12dc755e78eb02c517e34f205894c8cedeca3bc68401f6
4
- data.tar.gz: 61707536ecd3a9a558df8872a3ce7b60fc04c47dbd6d7da703bd0605cf2e73bb
3
+ metadata.gz: e7458dcdf494ef6b1b283ca86d51fba0b3102ecf5cec13f43682878c01708c80
4
+ data.tar.gz: ab8099b8b275aa5acab45a012bbc96ef0c860e041be2c4ae7d6f7cd331da1755
5
5
  SHA512:
6
- metadata.gz: a46a5aabda78c3da10739e31f403a8606de5129106dce4a8a26f84c66f3b7f63abc448944476e8780a00ba155a3f4fac00b83e92af7bfbaee9e177834351cf5d
7
- data.tar.gz: da32618ab105131c9a30527ad5d9a1624b5f229f1e0fc06fa258732af4f3b1eb21fd45a8d8980513eede69a61ac823ddb465b5d465630dd0f8928720f7ec8e3d
6
+ metadata.gz: 60d445fd27bbea120359c21d0c1b0ac1d4fbbd678c8fd28efe620706d382a2f0cc434645967c9bac0b6d08d1065fe99dc4b15e2623d98ca0e15a61eb591a993b
7
+ data.tar.gz: b7736fd3a7b27f98ef3e4df05464000849403ff33a3f82ecd6d8c51b40d0c2753d23ed14c078eb26506d504de991e35ebe68e5703225c80aab6ebbd28b7a80dc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,85 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 3.17.3 - 2026-06-04
4
+
5
+ - Fixed issue in intern.c and fast.c.
6
+
7
+ ## 3.17.2 - 2026-05-27
8
+
9
+ - Fixed multiple issues related to extreme sizes.
10
+
11
+ ## 3.17.1 - 2026-05-15
12
+
13
+ - Fixed "quoted string not terminated" error.
14
+
15
+ ## 3.17.0 - 2026-04-19
16
+
17
+ - A "safe" parser has been added as a variation of the Oj:Parser thanks to @meinac.
18
+
19
+ ## 3.16.17 - 2026-04-12
20
+
21
+ - Rails optimize for Hash and Array now overrides `as_json` for those
22
+ classes. Note that when either is optimized with `Oj.optimize_rails`
23
+ the `Array.as_json` and `Hash.as_json` will not be called.
24
+
25
+ - Add support for the rails encoder `:only` and `:except` options.
26
+
27
+ - Handle unterminated strings in usual parser (#1002)
28
+
29
+ - Fix read() not handling partial reads for large files (#1004)
30
+
31
+ - Raise error for incomplete primitive literals (#1005)
32
+
33
+ ## 3.16.16 - 2026-03-13
34
+
35
+ - Not closed arrays and objects are reported corrected in the usual parser.
36
+
37
+ ## 3.16.15 - 2026-02-05
38
+
39
+ - Fixed by putting the ostruct dependency back until a better way is found to conditionally include it.
40
+
41
+ ## 3.16.14 - 2026-02-04
42
+
43
+ - Fixed SSE issue #989.
44
+
45
+ - Removed ostruct dependency.
46
+
47
+ - Removed generic object JSON gem tests.
48
+
49
+ ## 3.16.13 - 2025-12-05
50
+
51
+ - Fixed rails encoding for Hash and Array subclasses.
52
+
53
+ ## 3.16.12 - 2025-10-29
54
+
55
+ - Fixed dump realloc bug that occurred when using the compat mode dump options.
56
+
57
+ ## 3.16.11 - 2025-05-29
58
+
59
+ - Fixed range encoding with the :circular option
60
+
61
+ ## 3.16.10 - 2025-02-24
62
+
63
+ - Changed oj_parser_type to be non-static.
64
+
65
+ - Changed ARM versions to used Neon instructions thanks to @samyron.
66
+
67
+ ## 3.16.9 - 2024-12-28
68
+
69
+ - Fixed `Oj::Parser` create_id size issue #931.
70
+
71
+ - Changed parser to be more optimized (PR from @Watson1978)
72
+
73
+ ## 3.16.8 - 2024-12-14
74
+
75
+ - Fixed StreamWriter to write to non-file IO thanks to @jscheid.
76
+
77
+ ## 3.16.7 - 2024-11-01
78
+
79
+ - Changed string_writer_as_json to allow multiple arguments.
80
+
81
+ - Fixed Global variable registration added to mimic_json and rails code thanks to @byroot.
82
+
3
83
  ## 3.16.6 - 2024-09-09
4
84
 
5
85
  - Fixed issue with Rails 7.2 that changed the order of calls to to_json and as_json.
@@ -48,6 +128,7 @@
48
128
  ## 3.14.3 - 2023-04-07
49
129
 
50
130
  - Fixed compat parse with optimized Hash when parsing a JSON::GenericObject.
131
+ - Deprecated Ruby <= 2.6.10
51
132
 
52
133
  ## 3.14.2 - 2023-02-10
53
134
 
data/README.md CHANGED
@@ -46,11 +46,6 @@ gem 'oj'
46
46
 
47
47
  See the Quickstart sections of the [Rails](pages/Rails.md) and [json](pages/JsonGem.md) docs.
48
48
 
49
- ## multi_json
50
-
51
- Code which uses [multi_json](https://github.com/intridea/multi_json)
52
- will automatically prefer Oj if it is installed.
53
-
54
49
  ## Support
55
50
 
56
51
  [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).
@@ -83,17 +78,6 @@ See [{file:CHANGELOG.md}](CHANGELOG.md) and [{file:RELEASE_NOTES.md}](RELEASE_NO
83
78
 
84
79
  - *RubyGems* *repo*: https://rubygems.org/gems/oj
85
80
 
86
- Follow [@peterohler on Twitter](http://twitter.com/peterohler) for announcements and news about the Oj gem.
87
-
88
- #### Performance Comparisons
89
-
90
- - [Oj Strict Mode Performance](http://www.ohler.com/dev/oj_misc/performance_strict.html) compares Oj strict mode parser performance to other JSON parsers.
91
-
92
- - [Oj Compat Mode Performance](http://www.ohler.com/dev/oj_misc/performance_compat.html) compares Oj compat mode parser performance to other JSON parsers.
93
-
94
- - [Oj Object Mode Performance](http://www.ohler.com/dev/oj_misc/performance_object.html) compares Oj object mode parser performance to other marshallers.
95
-
96
- - [Oj Callback Performance](http://www.ohler.com/dev/oj_misc/performance_callback.html) compares Oj callback parser performance to other JSON parsers.
97
81
 
98
82
  #### Links of Interest
99
83
 
data/ext/oj/compat.c CHANGED
@@ -27,7 +27,7 @@ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, c
27
27
  volatile VALUE rkey = oj_calc_hash_key(pi, kval);
28
28
 
29
29
  if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
30
- VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
30
+ VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, len);
31
31
 
32
32
  if (Qnil != clas) {
33
33
  rstr = rb_funcall(clas, oj_json_create_id, 1, rstr);
@@ -84,7 +84,7 @@ static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig
84
84
  volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
85
85
 
86
86
  if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
87
- VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
87
+ VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, len);
88
88
 
89
89
  if (Qnil != clas) {
90
90
  pi->stack.head->val = rb_funcall(clas, oj_json_create_id, 1, rstr);
@@ -155,7 +155,7 @@ static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const c
155
155
  volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
156
156
 
157
157
  if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
158
- VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
158
+ VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, len);
159
159
 
160
160
  if (Qnil != clas) {
161
161
  rb_ary_push(stack_peek(&pi->stack)->val, rb_funcall(clas, oj_json_create_id, 1, rstr));
data/ext/oj/custom.c CHANGED
@@ -40,7 +40,7 @@ static void dump_obj_as_str(VALUE obj, int depth, Out out) {
40
40
  static void bigdecimal_dump(VALUE obj, int depth, Out out) {
41
41
  volatile VALUE rstr = oj_safe_string_convert(obj);
42
42
  const char *str = RSTRING_PTR(rstr);
43
- int len = (int)RSTRING_LEN(rstr);
43
+ size_t len = RSTRING_LEN(rstr);
44
44
 
45
45
  if (0 == strcasecmp("Infinity", str)) {
46
46
  str = oj_nan_str(obj, out->opts->dump_opts.nan_dump, out->opts->mode, true, &len);
@@ -123,7 +123,7 @@ static void date_dump(VALUE obj, int depth, Out out) {
123
123
  case RubyTime:
124
124
  case XmlTime:
125
125
  v = rb_funcall(obj, rb_intern("iso8601"), 0);
126
- oj_dump_cstr(RSTRING_PTR(v), (int)RSTRING_LEN(v), 0, 0, out);
126
+ oj_dump_cstr(RSTRING_PTR(v), RSTRING_LEN(v), 0, 0, out);
127
127
  break;
128
128
  case UnixZTime:
129
129
  v = rb_funcall(obj, rb_intern("to_time"), 0);
@@ -287,6 +287,11 @@ static int hash_cb(VALUE key, VALUE value, VALUE ov) {
287
287
  if (out->omit_nil && Qnil == value) {
288
288
  return ST_CONTINUE;
289
289
  }
290
+ if (NULL != out->opts->dump_opts.only || NULL != out->opts->dump_opts.except) {
291
+ if (oj_key_skip(key, out->opts->dump_opts.only, out->opts->dump_opts.except)) {
292
+ return ST_CONTINUE;
293
+ }
294
+ }
290
295
  if (!out->opts->dump_opts.use) {
291
296
  assure_size(out, depth * out->indent + 1);
292
297
  fill_indent(out, depth);
@@ -405,7 +410,7 @@ static void dump_odd(VALUE obj, Odd odd, VALUE clas, int depth, Out out) {
405
410
  rb_raise(rb_eEncodingError, "Invalid type for raw JSON.\n");
406
411
  } else {
407
412
  const char *s = RSTRING_PTR(v);
408
- int len = (int)RSTRING_LEN(v);
413
+ size_t len = RSTRING_LEN(v);
409
414
  const char *name = rb_id2name(*odd->attrs);
410
415
  size_t nlen = strlen(name);
411
416
 
@@ -478,7 +483,7 @@ static VALUE dump_common(VALUE obj, int depth, Out out) {
478
483
  } else if (Yes == out->opts->to_json && rb_respond_to(obj, oj_to_json_id)) {
479
484
  volatile VALUE rs;
480
485
  const char *s;
481
- int len;
486
+ size_t len;
482
487
 
483
488
  TRACE(out->opts->trace, "to_json", obj, depth + 1, TraceRubyIn);
484
489
  if (0 == rb_obj_method_arity(obj, oj_to_json_id)) {
@@ -488,7 +493,7 @@ static VALUE dump_common(VALUE obj, int depth, Out out) {
488
493
  }
489
494
  TRACE(out->opts->trace, "to_json", obj, depth + 1, TraceRubyOut);
490
495
  s = RSTRING_PTR(rs);
491
- len = (int)RSTRING_LEN(rs);
496
+ len = RSTRING_LEN(rs);
492
497
 
493
498
  assure_size(out, len + 1);
494
499
  APPEND_CHARS(out->cur, s, len);
@@ -509,7 +514,7 @@ static VALUE dump_common(VALUE obj, int depth, Out out) {
509
514
  if (aj == obj) {
510
515
  volatile VALUE rstr = oj_safe_string_convert(obj);
511
516
 
512
- oj_dump_cstr(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), false, false, out);
517
+ oj_dump_cstr(RSTRING_PTR(rstr), RSTRING_LEN(rstr), false, false, out);
513
518
  } else {
514
519
  oj_dump_custom_val(aj, depth, out, true);
515
520
  }
@@ -676,7 +681,8 @@ static void dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
676
681
 
677
682
  static void dump_array(VALUE a, int depth, Out out, bool as_ok) {
678
683
  size_t size;
679
- int i, cnt;
684
+ size_t i;
685
+ size_t cnt;
680
686
  int d2 = depth + 1;
681
687
  long id = oj_check_circular(a, out);
682
688
 
@@ -684,7 +690,7 @@ static void dump_array(VALUE a, int depth, Out out, bool as_ok) {
684
690
  oj_dump_nil(Qnil, depth, out, false);
685
691
  return;
686
692
  }
687
- cnt = (int)RARRAY_LEN(a);
693
+ cnt = RARRAY_LEN(a);
688
694
  *out->cur++ = '[';
689
695
  assure_size(out, 2);
690
696
  if (0 == cnt) {
@@ -795,7 +801,7 @@ static void dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
795
801
  volatile VALUE s = rb_sym2str(RARRAY_AREF(ma, i));
796
802
 
797
803
  name = RSTRING_PTR(s);
798
- len = (int)RSTRING_LEN(s);
804
+ len = RSTRING_LEN(s);
799
805
  } else {
800
806
  len = snprintf(num_id, sizeof(num_id), "%d", i);
801
807
  name = num_id;
@@ -909,7 +915,7 @@ static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, c
909
915
  volatile VALUE rkey = oj_calc_hash_key(pi, kval);
910
916
 
911
917
  if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
912
- VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
918
+ VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, len);
913
919
 
914
920
  if (Qnil != clas) {
915
921
  rstr = rb_funcall(clas, oj_json_create_id, 1, rstr);
@@ -1014,7 +1020,7 @@ static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const c
1014
1020
  volatile VALUE rstr = rb_utf8_str_new(str, len);
1015
1021
 
1016
1022
  if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
1017
- VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
1023
+ VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, len);
1018
1024
 
1019
1025
  if (Qnil != clas) {
1020
1026
  rb_ary_push(stack_peek(&pi->stack)->val, rb_funcall(clas, oj_json_create_id, 1, rstr));