oj 3.13.7 → 3.13.23

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 (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
data/ext/oj/strict.c CHANGED
@@ -50,13 +50,13 @@ VALUE oj_calc_hash_key(ParseInfo pi, Val parent) {
50
50
  }
51
51
 
52
52
  static void hash_end(ParseInfo pi) {
53
- if (Yes == pi->options.trace) {
53
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
54
54
  oj_trace_parse_hash_end(pi, __FILE__, __LINE__);
55
55
  }
56
56
  }
57
57
 
58
58
  static void array_end(ParseInfo pi) {
59
- if (Yes == pi->options.trace) {
59
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
60
60
  oj_trace_parse_array_end(pi, __FILE__, __LINE__);
61
61
  }
62
62
  }
@@ -66,7 +66,7 @@ static VALUE noop_hash_key(ParseInfo pi, const char *key, size_t klen) {
66
66
  }
67
67
 
68
68
  static void add_value(ParseInfo pi, VALUE val) {
69
- if (Yes == pi->options.trace) {
69
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
70
70
  oj_trace_parse_call("add_value", pi, __FILE__, __LINE__, val);
71
71
  }
72
72
  pi->stack.head->val = val;
@@ -76,7 +76,7 @@ static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig
76
76
  volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
77
77
 
78
78
  pi->stack.head->val = rstr;
79
- if (Yes == pi->options.trace) {
79
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
80
80
  oj_trace_parse_call("add_string", pi, __FILE__, __LINE__, rstr);
81
81
  }
82
82
  }
@@ -86,7 +86,7 @@ static void add_num(ParseInfo pi, NumInfo ni) {
86
86
  oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
87
87
  }
88
88
  pi->stack.head->val = oj_num_as_value(ni);
89
- if (Yes == pi->options.trace) {
89
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
90
90
  oj_trace_parse_call("add_number", pi, __FILE__, __LINE__, pi->stack.head->val);
91
91
  }
92
92
  }
@@ -95,7 +95,7 @@ static VALUE start_hash(ParseInfo pi) {
95
95
  if (Qnil != pi->options.hash_class) {
96
96
  return rb_class_new_instance(0, NULL, pi->options.hash_class);
97
97
  }
98
- if (Yes == pi->options.trace) {
98
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
99
99
  oj_trace_parse_in("start_hash", pi, __FILE__, __LINE__);
100
100
  }
101
101
  return rb_hash_new();
@@ -107,7 +107,7 @@ static void hash_set_cstr(ParseInfo pi, Val parent, const char *str, size_t len,
107
107
  rb_hash_aset(stack_peek(&pi->stack)->val,
108
108
  oj_calc_hash_key(pi, parent),
109
109
  rstr);
110
- if (Yes == pi->options.trace) {
110
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
111
111
  oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rstr);
112
112
  }
113
113
  }
@@ -122,7 +122,7 @@ static void hash_set_num(ParseInfo pi, Val parent, NumInfo ni) {
122
122
  rb_hash_aset(stack_peek(&pi->stack)->val,
123
123
  oj_calc_hash_key(pi, parent),
124
124
  v);
125
- if (Yes == pi->options.trace) {
125
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
126
126
  oj_trace_parse_call("set_number", pi, __FILE__, __LINE__, v);
127
127
  }
128
128
  }
@@ -131,13 +131,13 @@ static void hash_set_value(ParseInfo pi, Val parent, VALUE value) {
131
131
  rb_hash_aset(stack_peek(&pi->stack)->val,
132
132
  oj_calc_hash_key(pi, parent),
133
133
  value);
134
- if (Yes == pi->options.trace) {
134
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
135
135
  oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, value);
136
136
  }
137
137
  }
138
138
 
139
139
  static VALUE start_array(ParseInfo pi) {
140
- if (Yes == pi->options.trace) {
140
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
141
141
  oj_trace_parse_in("start_array", pi, __FILE__, __LINE__);
142
142
  }
143
143
  return rb_ary_new();
@@ -147,7 +147,7 @@ static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const c
147
147
  volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
148
148
 
149
149
  rb_ary_push(stack_peek(&pi->stack)->val, rstr);
150
- if (Yes == pi->options.trace) {
150
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
151
151
  oj_trace_parse_call("append_string", pi, __FILE__, __LINE__, rstr);
152
152
  }
153
153
  }
@@ -160,14 +160,14 @@ static void array_append_num(ParseInfo pi, NumInfo ni) {
160
160
  }
161
161
  v = oj_num_as_value(ni);
162
162
  rb_ary_push(stack_peek(&pi->stack)->val, v);
163
- if (Yes == pi->options.trace) {
163
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
164
164
  oj_trace_parse_call("append_number", pi, __FILE__, __LINE__, v);
165
165
  }
166
166
  }
167
167
 
168
168
  static void array_append_value(ParseInfo pi, VALUE value) {
169
169
  rb_ary_push(stack_peek(&pi->stack)->val, value);
170
- if (Yes == pi->options.trace) {
170
+ if (RB_UNLIKELY(Yes == pi->options.trace)) {
171
171
  oj_trace_parse_call("append_value", pi, __FILE__, __LINE__, value);
172
172
  }
173
173
  }
@@ -53,10 +53,13 @@ void oj_str_writer_init(StrWriter sw, int buf_size) {
53
53
  } else if (buf_size < 1024) {
54
54
  buf_size = 1024;
55
55
  }
56
+ // Must be allocated. Using the out.stack_buffer results in double frees
57
+ // and I haven't figured out why yet.
56
58
  sw->out.buf = ALLOC_N(char, buf_size);
57
- sw->out.end = sw->out.buf + buf_size - 10;
58
- sw->out.allocated = true;
59
59
  sw->out.cur = sw->out.buf;
60
+ sw->out.end = sw->out.buf + buf_size - BUFFER_EXTRA;
61
+ sw->out.allocated = true;
62
+
60
63
  *sw->out.cur = '\0';
61
64
  sw->out.circ_cache = NULL;
62
65
  sw->out.circ_cnt = 0;
@@ -229,7 +232,9 @@ static void str_writer_free(void *ptr) {
229
232
  return;
230
233
  }
231
234
  sw = (StrWriter)ptr;
232
- xfree(sw->out.buf);
235
+
236
+ oj_out_free(&sw->out);
237
+
233
238
  xfree(sw->types);
234
239
  xfree(ptr);
235
240
  }
@@ -449,7 +454,7 @@ static VALUE str_writer_to_s(VALUE self) {
449
454
  * Returns the contents of the writer as a JSON element. If called from inside
450
455
  * an array or hash by Oj the raw buffer will be used othersize a more
451
456
  * inefficient parse of the contents and a return of the result is
452
- * completed. The parse uses the trict mode.
457
+ * completed. The parse uses the strict mode.
453
458
  *
454
459
  * *return* [_Hash_|_Array_|_String_|_Integer_|_Float_|_True_|_False_|_nil|)
455
460
  */
@@ -469,8 +474,10 @@ static VALUE str_writer_as_json(VALUE self) {
469
474
  * calling to_s() will return the JSON document. Note that calling to_s() before
470
475
  * construction is complete will return the document in it's current state.
471
476
  */
472
- void oj_string_writer_init() {
477
+ void oj_string_writer_init(void) {
473
478
  oj_string_writer_class = rb_define_class_under(Oj, "StringWriter", rb_cObject);
479
+ rb_gc_register_address(&oj_string_writer_class);
480
+ rb_undef_alloc_func(oj_string_writer_class);
474
481
  rb_define_module_function(oj_string_writer_class, "new", str_writer_new, -1);
475
482
  rb_define_method(oj_string_writer_class, "push_key", str_writer_push_key, 1);
476
483
  rb_define_method(oj_string_writer_class, "push_object", str_writer_push_object, -1);