json 2.10.2 → 2.11.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b909ed90787afa31835c9926529808ca3c6b161755e1f6126b7fe203231fa0c2
4
- data.tar.gz: efd6a873e98f9e4b2b8c078210f141dfde5f3773884bd5851f228c184ff94ff7
3
+ metadata.gz: 6415f9d9c30cadde9c59fe7b2c1b6279dfe990c84184572a9d8134d52e334780
4
+ data.tar.gz: e071f46d8d893429c83b2aac3e531d28c9c332b672e9ea024de9b1a8a935e4d0
5
5
  SHA512:
6
- metadata.gz: bff39363d5d7fa2f209d5bf97a5728738058bc83600b732d95487e263a5a3901b1e18d5c42d7d2be019ac55ef069a50cedc1d9a8d22b11e6061f2eef747dc94d
7
- data.tar.gz: 693e480f8f2489e26c43eef56ad8977ab3f00fada03318a48b88ac55e2b82b15ffae92fd05dd47d86686fae39169b079f59a68fffc6efaf44ee3503a45060e30
6
+ metadata.gz: de12cb0f01d32d4003f251b63b5a4303a199548b0510dc1e4a4d29eb2cf5efc2cf1af2689bc5cd3bb3f5e86eb7b312b4bb011b718e9149050d5f2a46dd153290
7
+ data.tar.gz: 11b34643b6857bec8cca28d4fcb7f60072371227aac1b5e2f324f90f69e54f2463a8c1714ce5713e286318933433b8947d3ddf532178765f4be3375b9835eeea
data/CHANGES.md CHANGED
@@ -1,10 +1,33 @@
1
1
  # Changes
2
2
 
3
+ ### 2025-04-24 (2.11.0)
4
+
5
+ * Optimize Integer generation to be ~1.8x faster.
6
+ * Optimize Float generation to be ~10x faster.
7
+ * Fix `JSON.load` proc argument to substitute the parsed object with the return value.
8
+ This better match `Marshal.load` behavior.
9
+ * Deprecate `JSON.fast_generate` (it's not any faster, so pointless).
10
+ * Deprecate `JSON.load_default_options`.
11
+ * Deprecate `JSON.unsafe_load_default_options`.
12
+ * Deprecate `JSON.dump_default_options`.
13
+ * Deprecate `Kernel#j`
14
+ * Deprecate `Kernel#jj`
15
+ * Remove outdated `JSON.iconv`.
16
+ * Remove `Class#json_creatable?` monkey patch.
17
+ * Remove deprecated `JSON.restore` method.
18
+ * Remove deprecated `JSON.unparse` method.
19
+ * Remove deprecated `JSON.fast_unparse` method.
20
+ * Remove deprecated `JSON.pretty_unparse` method.
21
+ * Remove deprecated `JSON::UnparserError` constant.
22
+ * Remove outdated `JSON::MissingUnicodeSupport` constant.
23
+
3
24
  ### 2025-03-12 (2.10.2)
4
25
 
5
26
  * Fix a potential crash in the C extension parser.
6
27
  * Raise a ParserError on all incomplete unicode escape sequence. This was the behavior until `2.10.0` unadvertently changed it.
7
28
  * Ensure document snippets that are included in parser errors don't include truncated multibyte characters.
29
+ * Ensure parser error snippets are valid UTF-8.
30
+ * Fix `JSON::GeneratorError#detailed_message` on Ruby < 3.2
8
31
 
9
32
  ### 2025-02-10 (2.10.1)
10
33
 
@@ -3,6 +3,7 @@
3
3
 
4
4
  #include "ruby.h"
5
5
  #include "ruby/encoding.h"
6
+ #include "../vendor/jeaiii-ltoa.h"
6
7
 
7
8
  /* shims */
8
9
  /* This is the fallback definition from Ruby 3.4 */
@@ -150,6 +151,13 @@ static void fbuffer_append(FBuffer *fb, const char *newstr, unsigned long len)
150
151
  }
151
152
  }
152
153
 
154
+ /* Appends a character into a buffer. The buffer needs to have sufficient capacity, via fbuffer_inc_capa(...). */
155
+ static inline void fbuffer_append_reserved_char(FBuffer *fb, char chr)
156
+ {
157
+ fb->ptr[fb->len] = chr;
158
+ fb->len += 1;
159
+ }
160
+
153
161
  static void fbuffer_append_str(FBuffer *fb, VALUE str)
154
162
  {
155
163
  const char *newstr = StringValuePtr(str);
@@ -167,25 +175,48 @@ static inline void fbuffer_append_char(FBuffer *fb, char newchr)
167
175
  fb->len++;
168
176
  }
169
177
 
170
- static long fltoa(long number, char *buf)
178
+ static inline char *fbuffer_cursor(FBuffer *fb)
179
+ {
180
+ return fb->ptr + fb->len;
181
+ }
182
+
183
+ static inline void fbuffer_advance_to(FBuffer *fb, char *end)
171
184
  {
172
- static const char digits[] = "0123456789";
173
- long sign = number;
174
- char* tmp = buf;
175
-
176
- if (sign < 0) number = -number;
177
- do *tmp-- = digits[number % 10]; while (number /= 10);
178
- if (sign < 0) *tmp-- = '-';
179
- return buf - tmp;
185
+ fb->len = end - fb->ptr;
180
186
  }
181
187
 
182
- #define LONG_BUFFER_SIZE 20
188
+ /*
189
+ * Appends the decimal string representation of \a number into the buffer.
190
+ */
183
191
  static void fbuffer_append_long(FBuffer *fb, long number)
184
192
  {
185
- char buf[LONG_BUFFER_SIZE];
186
- char *buffer_end = buf + LONG_BUFFER_SIZE;
187
- long len = fltoa(number, buffer_end - 1);
188
- fbuffer_append(fb, buffer_end - len, len);
193
+ /*
194
+ * The jeaiii_ultoa() function produces digits left-to-right,
195
+ * allowing us to write directly into the buffer, but we don't know
196
+ * the number of resulting characters.
197
+ *
198
+ * We do know, however, that the `number` argument is always in the
199
+ * range 0xc000000000000000 to 0x3fffffffffffffff, or, in decimal,
200
+ * -4611686018427387904 to 4611686018427387903. The max number of chars
201
+ * generated is therefore 20 (including a potential sign character).
202
+ */
203
+
204
+ static const int MAX_CHARS_FOR_LONG = 20;
205
+
206
+ fbuffer_inc_capa(fb, MAX_CHARS_FOR_LONG);
207
+
208
+ if (number < 0) {
209
+ fbuffer_append_reserved_char(fb, '-');
210
+
211
+ /*
212
+ * Since number is always > LONG_MIN, `-number` will not overflow
213
+ * and is always the positive abs() value.
214
+ */
215
+ number = -number;
216
+ }
217
+
218
+ char *end = jeaiii_ultoa(fbuffer_cursor(fb), number);
219
+ fbuffer_advance_to(fb, end);
189
220
  }
190
221
 
191
222
  static VALUE fbuffer_finalize(FBuffer *fb)
@@ -1,5 +1,6 @@
1
1
  #include "ruby.h"
2
2
  #include "../fbuffer/fbuffer.h"
3
+ #include "../vendor/fpconv.c"
3
4
 
4
5
  #include <math.h>
5
6
  #include <ctype.h>
@@ -1054,8 +1055,9 @@ static void generate_json_float(FBuffer *buffer, struct generate_json_data *data
1054
1055
  {
1055
1056
  double value = RFLOAT_VALUE(obj);
1056
1057
  char allow_nan = state->allow_nan;
1057
- if (!allow_nan) {
1058
- if (isinf(value) || isnan(value)) {
1058
+ if (isinf(value) || isnan(value)) {
1059
+ /* for NaN and Infinity values we either raise an error or rely on Float#to_s. */
1060
+ if (!allow_nan) {
1059
1061
  if (state->strict && state->as_json) {
1060
1062
  VALUE casted_obj = rb_proc_call_with_block(state->as_json, 1, &obj, Qnil);
1061
1063
  if (casted_obj != obj) {
@@ -1067,8 +1069,24 @@ static void generate_json_float(FBuffer *buffer, struct generate_json_data *data
1067
1069
  }
1068
1070
  raise_generator_error(obj, "%"PRIsVALUE" not allowed in JSON", rb_funcall(obj, i_to_s, 0));
1069
1071
  }
1072
+
1073
+ VALUE tmp = rb_funcall(obj, i_to_s, 0);
1074
+ fbuffer_append_str(buffer, tmp);
1075
+ return;
1070
1076
  }
1071
- fbuffer_append_str(buffer, rb_funcall(obj, i_to_s, 0));
1077
+
1078
+ /* This implementation writes directly into the buffer. We reserve
1079
+ * the 24 characters that fpconv_dtoa states as its maximum, plus
1080
+ * 2 more characters for the potential ".0" suffix.
1081
+ */
1082
+ fbuffer_inc_capa(buffer, 26);
1083
+ char* d = buffer->ptr + buffer->len;
1084
+ int len = fpconv_dtoa(value, d);
1085
+
1086
+ /* fpconv_dtoa converts a float to its shortest string representation,
1087
+ * but it adds a ".0" if this is a plain integer.
1088
+ */
1089
+ buffer->len += len;
1072
1090
  }
1073
1091
 
1074
1092
  static void generate_json_fragment(FBuffer *buffer, struct generate_json_data *data, JSON_Generator_State *state, VALUE obj)
@@ -4,7 +4,6 @@ require 'mkmf'
4
4
  have_func("rb_enc_interned_str", "ruby.h") # RUBY_VERSION >= 3.0
5
5
  have_func("rb_hash_new_capa", "ruby.h") # RUBY_VERSION >= 3.2
6
6
  have_func("rb_hash_bulk_insert", "ruby.h") # Missing on TruffleRuby
7
- have_func("rb_category_warn", "ruby.h") # Missing on TruffleRuby
8
7
  have_func("strnlen", "string.h") # Missing on Solaris 10
9
8
 
10
9
  append_cflags("-std=c99")
@@ -31,28 +31,15 @@ typedef unsigned char _Bool;
31
31
  static VALUE mJSON, eNestingError, Encoding_UTF_8;
32
32
  static VALUE CNaN, CInfinity, CMinusInfinity;
33
33
 
34
- static ID i_json_creatable_p, i_json_create, i_create_id,
35
- i_chr, i_deep_const_get, i_match, i_aset, i_aref,
34
+ static ID i_chr, i_aset, i_aref,
36
35
  i_leftshift, i_new, i_try_convert, i_uminus, i_encode;
37
36
 
38
37
  static VALUE sym_max_nesting, sym_allow_nan, sym_allow_trailing_comma, sym_symbolize_names, sym_freeze,
39
- sym_create_additions, sym_create_id, sym_object_class, sym_array_class,
40
- sym_decimal_class, sym_match_string;
38
+ sym_decimal_class, sym_on_load;
41
39
 
42
40
  static int binary_encindex;
43
41
  static int utf8_encindex;
44
42
 
45
- #ifdef HAVE_RB_CATEGORY_WARN
46
- # define json_deprecated(message) rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, message)
47
- #else
48
- # define json_deprecated(message) rb_warn(message)
49
- #endif
50
-
51
- static const char deprecated_create_additions_warning[] =
52
- "JSON.load implicit support for `create_additions: true` is deprecated "
53
- "and will be removed in 3.0, use JSON.unsafe_load or explicitly "
54
- "pass `create_additions: true`";
55
-
56
43
  #ifndef HAVE_RB_HASH_BULK_INSERT
57
44
  // For TruffleRuby
58
45
  void
@@ -444,20 +431,15 @@ static int convert_UTF32_to_UTF8(char *buf, uint32_t ch)
444
431
  }
445
432
 
446
433
  typedef struct JSON_ParserStruct {
447
- VALUE create_id;
448
- VALUE object_class;
449
- VALUE array_class;
434
+ VALUE on_load_proc;
450
435
  VALUE decimal_class;
451
436
  ID decimal_method_id;
452
- VALUE match_string;
453
437
  int max_nesting;
454
438
  bool allow_nan;
455
439
  bool allow_trailing_comma;
456
440
  bool parsing_name;
457
441
  bool symbolize_names;
458
442
  bool freeze;
459
- bool create_additions;
460
- bool deprecated_create_additions;
461
443
  } JSON_ParserConfig;
462
444
 
463
445
  typedef struct JSON_ParserStateStruct {
@@ -769,18 +751,7 @@ static VALUE json_decode_float(JSON_ParserConfig *config, const char *start, con
769
751
 
770
752
  static inline VALUE json_decode_array(JSON_ParserState *state, JSON_ParserConfig *config, long count)
771
753
  {
772
- VALUE array;
773
- if (RB_UNLIKELY(config->array_class)) {
774
- array = rb_class_new_instance(0, 0, config->array_class);
775
- VALUE *items = rvalue_stack_peek(state->stack, count);
776
- long index;
777
- for (index = 0; index < count; index++) {
778
- rb_funcall(array, i_leftshift, 1, items[index]);
779
- }
780
- } else {
781
- array = rb_ary_new_from_values(count, rvalue_stack_peek(state->stack, count));
782
- }
783
-
754
+ VALUE array = rb_ary_new_from_values(count, rvalue_stack_peek(state->stack, count));
784
755
  rvalue_stack_pop(state->stack, count);
785
756
 
786
757
  if (config->freeze) {
@@ -792,41 +763,11 @@ static inline VALUE json_decode_array(JSON_ParserState *state, JSON_ParserConfig
792
763
 
793
764
  static inline VALUE json_decode_object(JSON_ParserState *state, JSON_ParserConfig *config, long count)
794
765
  {
795
- VALUE object;
796
- if (RB_UNLIKELY(config->object_class)) {
797
- object = rb_class_new_instance(0, 0, config->object_class);
798
- long index = 0;
799
- VALUE *items = rvalue_stack_peek(state->stack, count);
800
- while (index < count) {
801
- VALUE name = items[index++];
802
- VALUE value = items[index++];
803
- rb_funcall(object, i_aset, 2, name, value);
804
- }
805
- } else {
806
- object = rb_hash_new_capa(count);
807
- rb_hash_bulk_insert(count, rvalue_stack_peek(state->stack, count), object);
808
- }
766
+ VALUE object = rb_hash_new_capa(count);
767
+ rb_hash_bulk_insert(count, rvalue_stack_peek(state->stack, count), object);
809
768
 
810
769
  rvalue_stack_pop(state->stack, count);
811
770
 
812
- if (RB_UNLIKELY(config->create_additions)) {
813
- VALUE klassname;
814
- if (config->object_class) {
815
- klassname = rb_funcall(object, i_aref, 1, config->create_id);
816
- } else {
817
- klassname = rb_hash_aref(object, config->create_id);
818
- }
819
- if (!NIL_P(klassname)) {
820
- VALUE klass = rb_funcall(mJSON, i_deep_const_get, 1, klassname);
821
- if (RTEST(rb_funcall(klass, i_json_creatable_p, 0))) {
822
- if (config->deprecated_create_additions) {
823
- json_deprecated(deprecated_create_additions_warning);
824
- }
825
- object = rb_funcall(klass, i_json_create, 1, object);
826
- }
827
- }
828
- }
829
-
830
771
  if (config->freeze) {
831
772
  RB_OBJ_FREEZE(object);
832
773
  }
@@ -834,17 +775,6 @@ static inline VALUE json_decode_object(JSON_ParserState *state, JSON_ParserConfi
834
775
  return object;
835
776
  }
836
777
 
837
- static int match_i(VALUE regexp, VALUE klass, VALUE memo)
838
- {
839
- if (regexp == Qundef) return ST_STOP;
840
- if (RTEST(rb_funcall(klass, i_json_creatable_p, 0)) &&
841
- RTEST(rb_funcall(regexp, i_match, 1, rb_ary_entry(memo, 0)))) {
842
- rb_ary_push(memo, klass);
843
- return ST_STOP;
844
- }
845
- return ST_CONTINUE;
846
- }
847
-
848
778
  static inline VALUE json_decode_string(JSON_ParserState *state, JSON_ParserConfig *config, const char *start, const char *end, bool escaped, bool is_name)
849
779
  {
850
780
  VALUE string;
@@ -856,21 +786,17 @@ static inline VALUE json_decode_string(JSON_ParserState *state, JSON_ParserConfi
856
786
  string = json_string_fastpath(state, start, end, is_name, intern, symbolize);
857
787
  }
858
788
 
859
- if (RB_UNLIKELY(config->create_additions && RTEST(config->match_string))) {
860
- VALUE klass;
861
- VALUE memo = rb_ary_new2(2);
862
- rb_ary_push(memo, string);
863
- rb_hash_foreach(config->match_string, match_i, memo);
864
- klass = rb_ary_entry(memo, 1);
865
- if (RTEST(klass)) {
866
- string = rb_funcall(klass, i_json_create, 1, string);
867
- }
868
- }
869
-
870
789
  return string;
871
790
  }
872
791
 
873
- #define PUSH(result) rvalue_stack_push(state->stack, result, &state->stack_handle, &state->stack)
792
+ static inline VALUE json_push_value(JSON_ParserState *state, JSON_ParserConfig *config, VALUE value)
793
+ {
794
+ if (RB_UNLIKELY(config->on_load_proc)) {
795
+ value = rb_proc_call_with_block(config->on_load_proc, 1, &value, Qnil);
796
+ }
797
+ rvalue_stack_push(state->stack, value, &state->stack_handle, &state->stack);
798
+ return value;
799
+ }
874
800
 
875
801
  static const bool string_scan[256] = {
876
802
  // ASCII Control Characters
@@ -897,7 +823,7 @@ static inline VALUE json_parse_string(JSON_ParserState *state, JSON_ParserConfig
897
823
  case '"': {
898
824
  VALUE string = json_decode_string(state, config, start, state->cursor, escaped, is_name);
899
825
  state->cursor++;
900
- return PUSH(string);
826
+ return json_push_value(state, config, string);
901
827
  }
902
828
  case '\\': {
903
829
  state->cursor++;
@@ -931,7 +857,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config)
931
857
  case 'n':
932
858
  if ((state->end - state->cursor >= 4) && (memcmp(state->cursor, "null", 4) == 0)) {
933
859
  state->cursor += 4;
934
- return PUSH(Qnil);
860
+ return json_push_value(state, config, Qnil);
935
861
  }
936
862
 
937
863
  raise_parse_error("unexpected token at '%s'", state->cursor);
@@ -939,7 +865,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config)
939
865
  case 't':
940
866
  if ((state->end - state->cursor >= 4) && (memcmp(state->cursor, "true", 4) == 0)) {
941
867
  state->cursor += 4;
942
- return PUSH(Qtrue);
868
+ return json_push_value(state, config, Qtrue);
943
869
  }
944
870
 
945
871
  raise_parse_error("unexpected token at '%s'", state->cursor);
@@ -948,7 +874,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config)
948
874
  // Note: memcmp with a small power of two compile to an integer comparison
949
875
  if ((state->end - state->cursor >= 5) && (memcmp(state->cursor + 1, "alse", 4) == 0)) {
950
876
  state->cursor += 5;
951
- return PUSH(Qfalse);
877
+ return json_push_value(state, config, Qfalse);
952
878
  }
953
879
 
954
880
  raise_parse_error("unexpected token at '%s'", state->cursor);
@@ -957,7 +883,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config)
957
883
  // Note: memcmp with a small power of two compile to an integer comparison
958
884
  if (config->allow_nan && (state->end - state->cursor >= 3) && (memcmp(state->cursor + 1, "aN", 2) == 0)) {
959
885
  state->cursor += 3;
960
- return PUSH(CNaN);
886
+ return json_push_value(state, config, CNaN);
961
887
  }
962
888
 
963
889
  raise_parse_error("unexpected token at '%s'", state->cursor);
@@ -965,7 +891,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config)
965
891
  case 'I':
966
892
  if (config->allow_nan && (state->end - state->cursor >= 8) && (memcmp(state->cursor, "Infinity", 8) == 0)) {
967
893
  state->cursor += 8;
968
- return PUSH(CInfinity);
894
+ return json_push_value(state, config, CInfinity);
969
895
  }
970
896
 
971
897
  raise_parse_error("unexpected token at '%s'", state->cursor);
@@ -975,7 +901,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config)
975
901
  if ((state->end - state->cursor >= 9) && (memcmp(state->cursor + 1, "Infinity", 8) == 0)) {
976
902
  if (config->allow_nan) {
977
903
  state->cursor += 9;
978
- return PUSH(CMinusInfinity);
904
+ return json_push_value(state, config, CMinusInfinity);
979
905
  } else {
980
906
  raise_parse_error("unexpected token at '%s'", state->cursor);
981
907
  }
@@ -1032,9 +958,9 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config)
1032
958
  }
1033
959
 
1034
960
  if (integer) {
1035
- return PUSH(json_decode_integer(start, state->cursor));
961
+ return json_push_value(state, config, json_decode_integer(start, state->cursor));
1036
962
  }
1037
- return PUSH(json_decode_float(config, start, state->cursor));
963
+ return json_push_value(state, config, json_decode_float(config, start, state->cursor));
1038
964
  }
1039
965
  case '"': {
1040
966
  // %r{\A"[^"\\\t\n\x00]*(?:\\[bfnrtu\\/"][^"\\]*)*"}
@@ -1048,7 +974,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config)
1048
974
 
1049
975
  if ((state->cursor < state->end) && (*state->cursor == ']')) {
1050
976
  state->cursor++;
1051
- return PUSH(json_decode_array(state, config, 0));
977
+ return json_push_value(state, config, json_decode_array(state, config, 0));
1052
978
  } else {
1053
979
  state->current_nesting++;
1054
980
  if (RB_UNLIKELY(config->max_nesting && (config->max_nesting < state->current_nesting))) {
@@ -1067,7 +993,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config)
1067
993
  long count = state->stack->head - stack_head;
1068
994
  state->current_nesting--;
1069
995
  state->in_array--;
1070
- return PUSH(json_decode_array(state, config, count));
996
+ return json_push_value(state, config, json_decode_array(state, config, count));
1071
997
  }
1072
998
 
1073
999
  if (*state->cursor == ',') {
@@ -1094,7 +1020,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config)
1094
1020
 
1095
1021
  if ((state->cursor < state->end) && (*state->cursor == '}')) {
1096
1022
  state->cursor++;
1097
- return PUSH(json_decode_object(state, config, 0));
1023
+ return json_push_value(state, config, json_decode_object(state, config, 0));
1098
1024
  } else {
1099
1025
  state->current_nesting++;
1100
1026
  if (RB_UNLIKELY(config->max_nesting && (config->max_nesting < state->current_nesting))) {
@@ -1123,7 +1049,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config)
1123
1049
  state->cursor++;
1124
1050
  state->current_nesting--;
1125
1051
  long count = state->stack->head - stack_head;
1126
- return PUSH(json_decode_object(state, config, count));
1052
+ return json_push_value(state, config, json_decode_object(state, config, count));
1127
1053
  }
1128
1054
 
1129
1055
  if (*state->cursor == ',') {
@@ -1211,10 +1137,7 @@ static int parser_config_init_i(VALUE key, VALUE val, VALUE data)
1211
1137
  else if (key == sym_allow_trailing_comma) { config->allow_trailing_comma = RTEST(val); }
1212
1138
  else if (key == sym_symbolize_names) { config->symbolize_names = RTEST(val); }
1213
1139
  else if (key == sym_freeze) { config->freeze = RTEST(val); }
1214
- else if (key == sym_create_id) { config->create_id = RTEST(val) ? val : Qfalse; }
1215
- else if (key == sym_object_class) { config->object_class = RTEST(val) ? val : Qfalse; }
1216
- else if (key == sym_array_class) { config->array_class = RTEST(val) ? val : Qfalse; }
1217
- else if (key == sym_match_string) { config->match_string = RTEST(val) ? val : Qfalse; }
1140
+ else if (key == sym_on_load) { config->on_load_proc = RTEST(val) ? val : Qfalse; }
1218
1141
  else if (key == sym_decimal_class) {
1219
1142
  if (RTEST(val)) {
1220
1143
  if (rb_respond_to(val, i_try_convert)) {
@@ -1244,15 +1167,6 @@ static int parser_config_init_i(VALUE key, VALUE val, VALUE data)
1244
1167
  }
1245
1168
  }
1246
1169
  }
1247
- else if (key == sym_create_additions) {
1248
- if (NIL_P(val)) {
1249
- config->create_additions = true;
1250
- config->deprecated_create_additions = true;
1251
- } else {
1252
- config->create_additions = RTEST(val);
1253
- config->deprecated_create_additions = false;
1254
- }
1255
- }
1256
1170
 
1257
1171
  return ST_CONTINUE;
1258
1172
  }
@@ -1267,16 +1181,6 @@ static void parser_config_init(JSON_ParserConfig *config, VALUE opts)
1267
1181
  // We assume in most cases few keys are set so it's faster to go over
1268
1182
  // the provided keys than to check all possible keys.
1269
1183
  rb_hash_foreach(opts, parser_config_init_i, (VALUE)config);
1270
-
1271
- if (config->symbolize_names && config->create_additions) {
1272
- rb_raise(rb_eArgError,
1273
- "options :symbolize_names and :create_additions cannot be "
1274
- " used in conjunction");
1275
- }
1276
-
1277
- if (config->create_additions && !config->create_id) {
1278
- config->create_id = rb_funcall(mJSON, i_create_id, 0);
1279
- }
1280
1184
  }
1281
1185
 
1282
1186
  }
@@ -1301,15 +1205,6 @@ static void parser_config_init(JSON_ParserConfig *config, VALUE opts)
1301
1205
  * (keys) in a JSON object. Otherwise strings are returned, which is
1302
1206
  * also the default. It's not possible to use this option in
1303
1207
  * conjunction with the *create_additions* option.
1304
- * * *create_additions*: If set to false, the Parser doesn't create
1305
- * additions even if a matching class and create_id was found. This option
1306
- * defaults to false.
1307
- * * *object_class*: Defaults to Hash. If another type is provided, it will be used
1308
- * instead of Hash to represent JSON objects. The type must respond to
1309
- * +new+ without arguments, and return an object that respond to +[]=+.
1310
- * * *array_class*: Defaults to Array If another type is provided, it will be used
1311
- * instead of Hash to represent JSON arrays. The type must respond to
1312
- * +new+ without arguments, and return an object that respond to +<<+.
1313
1208
  * * *decimal_class*: Specifies which class to use instead of the default
1314
1209
  * (Float) when parsing decimal numbers. This class must accept a single
1315
1210
  * string argument in its constructor.
@@ -1320,11 +1215,7 @@ static VALUE cParserConfig_initialize(VALUE self, VALUE opts)
1320
1215
 
1321
1216
  parser_config_init(config, opts);
1322
1217
 
1323
- RB_OBJ_WRITTEN(self, Qundef, config->create_id);
1324
- RB_OBJ_WRITTEN(self, Qundef, config->object_class);
1325
- RB_OBJ_WRITTEN(self, Qundef, config->array_class);
1326
1218
  RB_OBJ_WRITTEN(self, Qundef, config->decimal_class);
1327
- RB_OBJ_WRITTEN(self, Qundef, config->match_string);
1328
1219
 
1329
1220
  return self;
1330
1221
  }
@@ -1387,11 +1278,8 @@ static VALUE cParser_m_parse(VALUE klass, VALUE Vsource, VALUE opts)
1387
1278
  static void JSON_ParserConfig_mark(void *ptr)
1388
1279
  {
1389
1280
  JSON_ParserConfig *config = ptr;
1390
- rb_gc_mark(config->create_id);
1391
- rb_gc_mark(config->object_class);
1392
- rb_gc_mark(config->array_class);
1281
+ rb_gc_mark(config->on_load_proc);
1393
1282
  rb_gc_mark(config->decimal_class);
1394
- rb_gc_mark(config->match_string);
1395
1283
  }
1396
1284
 
1397
1285
  static void JSON_ParserConfig_free(void *ptr)
@@ -1459,19 +1347,10 @@ void Init_parser(void)
1459
1347
  sym_allow_trailing_comma = ID2SYM(rb_intern("allow_trailing_comma"));
1460
1348
  sym_symbolize_names = ID2SYM(rb_intern("symbolize_names"));
1461
1349
  sym_freeze = ID2SYM(rb_intern("freeze"));
1462
- sym_create_additions = ID2SYM(rb_intern("create_additions"));
1463
- sym_create_id = ID2SYM(rb_intern("create_id"));
1464
- sym_object_class = ID2SYM(rb_intern("object_class"));
1465
- sym_array_class = ID2SYM(rb_intern("array_class"));
1350
+ sym_on_load = ID2SYM(rb_intern("on_load"));
1466
1351
  sym_decimal_class = ID2SYM(rb_intern("decimal_class"));
1467
- sym_match_string = ID2SYM(rb_intern("match_string"));
1468
1352
 
1469
- i_create_id = rb_intern("create_id");
1470
- i_json_creatable_p = rb_intern("json_creatable?");
1471
- i_json_create = rb_intern("json_create");
1472
1353
  i_chr = rb_intern("chr");
1473
- i_match = rb_intern("match");
1474
- i_deep_const_get = rb_intern("deep_const_get");
1475
1354
  i_aset = rb_intern("[]=");
1476
1355
  i_aref = rb_intern("[]");
1477
1356
  i_leftshift = rb_intern("<<");