oj 3.13.23 → 3.16.10

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 (178) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +86 -0
  3. data/README.md +2 -2
  4. data/ext/oj/buf.h +7 -6
  5. data/ext/oj/cache.c +29 -26
  6. data/ext/oj/cache.h +3 -2
  7. data/ext/oj/cache8.c +10 -9
  8. data/ext/oj/circarray.c +7 -5
  9. data/ext/oj/circarray.h +2 -2
  10. data/ext/oj/code.c +5 -12
  11. data/ext/oj/code.h +2 -2
  12. data/ext/oj/compat.c +20 -60
  13. data/ext/oj/custom.c +26 -59
  14. data/ext/oj/debug.c +3 -9
  15. data/ext/oj/dump.c +103 -53
  16. data/ext/oj/dump.h +1 -4
  17. data/ext/oj/dump_compat.c +557 -592
  18. data/ext/oj/dump_leaf.c +3 -5
  19. data/ext/oj/dump_object.c +42 -48
  20. data/ext/oj/dump_strict.c +10 -22
  21. data/ext/oj/encoder.c +1 -1
  22. data/ext/oj/err.c +2 -13
  23. data/ext/oj/err.h +9 -12
  24. data/ext/oj/extconf.rb +16 -7
  25. data/ext/oj/fast.c +63 -98
  26. data/ext/oj/intern.c +62 -47
  27. data/ext/oj/intern.h +3 -7
  28. data/ext/oj/mem.c +318 -0
  29. data/ext/oj/mem.h +53 -0
  30. data/ext/oj/mimic_json.c +54 -38
  31. data/ext/oj/object.c +33 -43
  32. data/ext/oj/odd.c +8 -6
  33. data/ext/oj/odd.h +4 -4
  34. data/ext/oj/oj.c +245 -216
  35. data/ext/oj/oj.h +83 -81
  36. data/ext/oj/parse.c +109 -153
  37. data/ext/oj/parse.h +21 -24
  38. data/ext/oj/parser.c +80 -67
  39. data/ext/oj/parser.h +9 -8
  40. data/ext/oj/rails.c +71 -94
  41. data/ext/oj/reader.c +9 -14
  42. data/ext/oj/reader.h +4 -2
  43. data/ext/oj/resolve.c +3 -4
  44. data/ext/oj/rxclass.c +6 -5
  45. data/ext/oj/rxclass.h +1 -1
  46. data/ext/oj/saj.c +13 -15
  47. data/ext/oj/saj2.c +37 -49
  48. data/ext/oj/saj2.h +1 -1
  49. data/ext/oj/scp.c +6 -20
  50. data/ext/oj/sparse.c +22 -70
  51. data/ext/oj/stream_writer.c +46 -48
  52. data/ext/oj/strict.c +22 -56
  53. data/ext/oj/string_writer.c +64 -40
  54. data/ext/oj/trace.h +31 -4
  55. data/ext/oj/usual.c +125 -114
  56. data/ext/oj/usual.h +7 -6
  57. data/ext/oj/util.h +1 -1
  58. data/ext/oj/val_stack.c +13 -2
  59. data/ext/oj/val_stack.h +8 -7
  60. data/ext/oj/wab.c +25 -57
  61. data/lib/oj/active_support_helper.rb +1 -3
  62. data/lib/oj/bag.rb +7 -1
  63. data/lib/oj/easy_hash.rb +4 -5
  64. data/lib/oj/error.rb +0 -1
  65. data/lib/oj/json.rb +162 -150
  66. data/lib/oj/mimic.rb +7 -7
  67. data/lib/oj/schandler.rb +5 -4
  68. data/lib/oj/state.rb +8 -5
  69. data/lib/oj/version.rb +1 -2
  70. data/lib/oj.rb +2 -0
  71. data/pages/InstallOptions.md +20 -0
  72. data/pages/Options.md +4 -0
  73. metadata +46 -121
  74. data/test/_test_active.rb +0 -76
  75. data/test/_test_active_mimic.rb +0 -96
  76. data/test/_test_mimic_rails.rb +0 -126
  77. data/test/activerecord/result_test.rb +0 -32
  78. data/test/activesupport4/decoding_test.rb +0 -108
  79. data/test/activesupport4/encoding_test.rb +0 -531
  80. data/test/activesupport4/test_helper.rb +0 -41
  81. data/test/activesupport5/abstract_unit.rb +0 -45
  82. data/test/activesupport5/decoding_test.rb +0 -133
  83. data/test/activesupport5/encoding_test.rb +0 -500
  84. data/test/activesupport5/encoding_test_cases.rb +0 -98
  85. data/test/activesupport5/test_helper.rb +0 -72
  86. data/test/activesupport5/time_zone_test_helpers.rb +0 -39
  87. data/test/activesupport6/abstract_unit.rb +0 -44
  88. data/test/activesupport6/decoding_test.rb +0 -133
  89. data/test/activesupport6/encoding_test.rb +0 -507
  90. data/test/activesupport6/encoding_test_cases.rb +0 -98
  91. data/test/activesupport6/test_common.rb +0 -17
  92. data/test/activesupport6/test_helper.rb +0 -163
  93. data/test/activesupport6/time_zone_test_helpers.rb +0 -39
  94. data/test/activesupport7/abstract_unit.rb +0 -49
  95. data/test/activesupport7/decoding_test.rb +0 -125
  96. data/test/activesupport7/encoding_test.rb +0 -486
  97. data/test/activesupport7/encoding_test_cases.rb +0 -104
  98. data/test/activesupport7/time_zone_test_helpers.rb +0 -47
  99. data/test/bar.rb +0 -11
  100. data/test/baz.rb +0 -16
  101. data/test/bug.rb +0 -16
  102. data/test/files.rb +0 -29
  103. data/test/foo.rb +0 -77
  104. data/test/helper.rb +0 -42
  105. data/test/isolated/shared.rb +0 -308
  106. data/test/isolated/test_mimic_after.rb +0 -13
  107. data/test/isolated/test_mimic_alone.rb +0 -12
  108. data/test/isolated/test_mimic_as_json.rb +0 -45
  109. data/test/isolated/test_mimic_before.rb +0 -13
  110. data/test/isolated/test_mimic_define.rb +0 -28
  111. data/test/isolated/test_mimic_rails_after.rb +0 -22
  112. data/test/isolated/test_mimic_rails_before.rb +0 -21
  113. data/test/isolated/test_mimic_redefine.rb +0 -15
  114. data/test/json_gem/json_addition_test.rb +0 -216
  115. data/test/json_gem/json_common_interface_test.rb +0 -153
  116. data/test/json_gem/json_encoding_test.rb +0 -107
  117. data/test/json_gem/json_ext_parser_test.rb +0 -20
  118. data/test/json_gem/json_fixtures_test.rb +0 -35
  119. data/test/json_gem/json_generator_test.rb +0 -396
  120. data/test/json_gem/json_generic_object_test.rb +0 -90
  121. data/test/json_gem/json_parser_test.rb +0 -477
  122. data/test/json_gem/json_string_matching_test.rb +0 -42
  123. data/test/json_gem/test_helper.rb +0 -30
  124. data/test/mem.rb +0 -33
  125. data/test/perf.rb +0 -107
  126. data/test/perf_compat.rb +0 -130
  127. data/test/perf_dump.rb +0 -50
  128. data/test/perf_fast.rb +0 -164
  129. data/test/perf_file.rb +0 -64
  130. data/test/perf_object.rb +0 -138
  131. data/test/perf_once.rb +0 -58
  132. data/test/perf_parser.rb +0 -189
  133. data/test/perf_saj.rb +0 -109
  134. data/test/perf_scp.rb +0 -152
  135. data/test/perf_simple.rb +0 -287
  136. data/test/perf_strict.rb +0 -139
  137. data/test/perf_wab.rb +0 -131
  138. data/test/prec.rb +0 -23
  139. data/test/sample/change.rb +0 -14
  140. data/test/sample/dir.rb +0 -19
  141. data/test/sample/doc.rb +0 -36
  142. data/test/sample/file.rb +0 -48
  143. data/test/sample/group.rb +0 -16
  144. data/test/sample/hasprops.rb +0 -16
  145. data/test/sample/layer.rb +0 -12
  146. data/test/sample/line.rb +0 -20
  147. data/test/sample/oval.rb +0 -10
  148. data/test/sample/rect.rb +0 -10
  149. data/test/sample/shape.rb +0 -35
  150. data/test/sample/text.rb +0 -20
  151. data/test/sample.rb +0 -54
  152. data/test/sample_json.rb +0 -37
  153. data/test/test_compat.rb +0 -540
  154. data/test/test_custom.rb +0 -544
  155. data/test/test_debian.rb +0 -53
  156. data/test/test_fast.rb +0 -530
  157. data/test/test_file.rb +0 -255
  158. data/test/test_gc.rb +0 -60
  159. data/test/test_generate.rb +0 -21
  160. data/test/test_hash.rb +0 -39
  161. data/test/test_integer_range.rb +0 -72
  162. data/test/test_null.rb +0 -376
  163. data/test/test_object.rb +0 -1025
  164. data/test/test_parser.rb +0 -11
  165. data/test/test_parser_debug.rb +0 -27
  166. data/test/test_parser_saj.rb +0 -335
  167. data/test/test_parser_usual.rb +0 -217
  168. data/test/test_rails.rb +0 -35
  169. data/test/test_saj.rb +0 -186
  170. data/test/test_scp.rb +0 -431
  171. data/test/test_strict.rb +0 -435
  172. data/test/test_various.rb +0 -752
  173. data/test/test_wab.rb +0 -309
  174. data/test/test_writer.rb +0 -380
  175. data/test/tests.rb +0 -33
  176. data/test/tests_mimic.rb +0 -23
  177. data/test/tests_mimic_addition.rb +0 -16
  178. data/test/zoo.rb +0 -13
data/ext/oj/oj.h CHANGED
@@ -40,9 +40,9 @@ enum st_retval { ST_CONTINUE = 0, ST_STOP = 1, ST_DELETE = 2, ST_CHECK };
40
40
  #define NAN_VAL "3.3e14159265358979323846"
41
41
 
42
42
  #if __STDC_VERSION__ >= 199901L
43
- // To avoid using ruby_snprintf with C99.
44
- #undef snprintf
45
- #include <stdio.h>
43
+ // To avoid using ruby_snprintf with C99.
44
+ #undef snprintf
45
+ #include <stdio.h>
46
46
  #endif
47
47
 
48
48
  // To avoid using ruby_nonempty_memcpy().
@@ -103,13 +103,6 @@ typedef enum {
103
103
  FILE_IO = 'f',
104
104
  } StreamWriterType;
105
105
 
106
- typedef enum {
107
- CALLER_DUMP = 'd',
108
- CALLER_TO_JSON = 't',
109
- CALLER_GENERATE = 'g',
110
- // Add the fast versions if necessary. Maybe unparse as well if needed.
111
- } DumpCaller;
112
-
113
106
  typedef struct _dumpOpts {
114
107
  bool use;
115
108
  char indent_str[16];
@@ -124,41 +117,42 @@ typedef struct _dumpOpts {
124
117
  uint8_t array_size;
125
118
  char nan_dump; // NanDump
126
119
  bool omit_nil;
120
+ bool omit_null_byte;
127
121
  int max_depth;
128
- } * DumpOpts;
122
+ } *DumpOpts;
129
123
 
130
124
  typedef struct _options {
131
- int indent; // indention for dump, default 2
132
- char circular; // YesNo
133
- char auto_define; // YesNo
134
- char sym_key; // YesNo
135
- char escape_mode; // Escape_Mode
136
- char mode; // Mode
137
- char class_cache; // YesNo
138
- char time_format; // TimeFormat
139
- char bigdec_as_num; // YesNo
140
- char bigdec_load; // BigLoad
141
- char compat_bigdec; // boolean (0 or 1)
142
- char to_hash; // YesNo
143
- char to_json; // YesNo
144
- char as_json; // YesNo
145
- char raw_json; // YesNo
146
- char nilnil; // YesNo
147
- char empty_string; // YesNo
148
- char allow_gc; // allow GC during parse
149
- char quirks_mode; // allow single JSON values instead of documents
150
- char allow_invalid; // YesNo - allow invalid unicode
151
- char create_ok; // YesNo allow create_id
152
- char allow_nan; // YEsyNo for parsing only
153
- char trace; // YesNo
154
- char safe; // YesNo
155
- char sec_prec_set; // boolean (0 or 1)
156
- char ignore_under; // YesNo - ignore attrs starting with _ if true in object and custom modes
157
- char cache_keys; // YesNo
158
- char cache_str; // string short than or equal to this are cache
125
+ int indent; // indention for dump, default 2
126
+ char circular; // YesNo
127
+ char auto_define; // YesNo
128
+ char sym_key; // YesNo
129
+ char escape_mode; // Escape_Mode
130
+ char mode; // Mode
131
+ char class_cache; // YesNo
132
+ char time_format; // TimeFormat
133
+ char bigdec_as_num; // YesNo
134
+ char bigdec_load; // BigLoad
135
+ char compat_bigdec; // boolean (0 or 1)
136
+ char to_hash; // YesNo
137
+ char to_json; // YesNo
138
+ char as_json; // YesNo
139
+ char raw_json; // YesNo
140
+ char nilnil; // YesNo
141
+ char empty_string; // YesNo
142
+ char allow_gc; // allow GC during parse
143
+ char quirks_mode; // allow single JSON values instead of documents
144
+ char allow_invalid; // YesNo - allow invalid unicode
145
+ char create_ok; // YesNo allow create_id
146
+ char allow_nan; // YEsyNo for parsing only
147
+ char trace; // YesNo
148
+ char safe; // YesNo
149
+ char sec_prec_set; // boolean (0 or 1)
150
+ char ignore_under; // YesNo - ignore attrs starting with _ if true in object and custom modes
151
+ char cache_keys; // YesNo
152
+ char cache_str; // string short than or equal to this are cache
159
153
  int64_t int_range_min; // dump numbers below as string
160
154
  int64_t int_range_max; // dump numbers above as string
161
- const char * create_id; // 0 or string
155
+ const char *create_id; // 0 or string
162
156
  size_t create_id_len; // length of create_id
163
157
  int sec_prec; // second precision when dumping time
164
158
  char float_prec; // float precision, linked to float_fmt
@@ -167,8 +161,8 @@ typedef struct _options {
167
161
  VALUE array_class; // class to use in place of Array on load
168
162
  struct _dumpOpts dump_opts;
169
163
  struct _rxClass str_rx;
170
- VALUE * ignore; // Qnil terminated array of classes or NULL
171
- } * Options;
164
+ VALUE *ignore; // Qnil terminated array of classes or NULL
165
+ } *Options;
172
166
 
173
167
  struct _out;
174
168
  typedef void (*DumpFunc)(VALUE obj, int depth, struct _out *out, bool as_ok);
@@ -178,42 +172,42 @@ typedef struct _rOpt {
178
172
  VALUE clas;
179
173
  bool on;
180
174
  DumpFunc dump;
181
- } * ROpt;
175
+ } *ROpt;
182
176
 
183
177
  typedef struct _rOptTable {
184
178
  int len;
185
179
  int alen;
186
180
  ROpt table;
187
- } * ROptTable;
181
+ } *ROptTable;
188
182
 
189
183
  typedef struct _out {
190
- char stack_buffer[4096];
191
- char * buf;
192
- char * end;
193
- char * cur;
194
- Cache8 circ_cache;
195
- slot_t circ_cnt;
196
- int indent;
197
- int depth; // used by dump_hash
198
- Options opts;
199
- uint32_t hash_cnt;
200
- bool allocated;
201
- bool omit_nil;
202
- int argc;
203
- VALUE * argv;
204
- DumpCaller caller; // used for the mimic json only
205
- ROptTable ropts;
206
- } * Out;
184
+ char stack_buffer[4096];
185
+ char *buf;
186
+ char *end;
187
+ char *cur;
188
+ Cache8 circ_cache;
189
+ slot_t circ_cnt;
190
+ int indent;
191
+ int depth; // used by dump_hash
192
+ Options opts;
193
+ uint32_t hash_cnt;
194
+ bool allocated;
195
+ bool omit_nil;
196
+ bool omit_null_byte;
197
+ int argc;
198
+ VALUE *argv;
199
+ ROptTable ropts;
200
+ } *Out;
207
201
 
208
202
  typedef struct _strWriter {
209
203
  struct _out out;
210
204
  struct _options opts;
211
205
  int depth;
212
- char * types; // DumpType
213
- char * types_end;
206
+ char *types; // DumpType
207
+ char *types_end;
214
208
  int keyWritten;
215
209
 
216
- } * StrWriter;
210
+ } *StrWriter;
217
211
 
218
212
  typedef struct _streamWriter {
219
213
  struct _strWriter sw;
@@ -221,7 +215,7 @@ typedef struct _streamWriter {
221
215
  VALUE stream;
222
216
  int fd;
223
217
  int flush_limit; // indicator of when to flush
224
- } * StreamWriter;
218
+ } *StreamWriter;
225
219
 
226
220
  enum { NO_VAL = 0x00, STR_VAL = 0x01, COL_VAL = 0x02, RUBY_VAL = 0x03 };
227
221
 
@@ -232,14 +226,14 @@ typedef struct _leaf {
232
226
  size_t index; // array index, 0 is not set
233
227
  };
234
228
  union {
235
- char * str; // pointer to location in json string or allocated
229
+ char *str; // pointer to location in json string or allocated
236
230
  struct _leaf *elements; // array and hash elements
237
231
  VALUE value;
238
232
  };
239
233
  uint8_t rtype;
240
234
  uint8_t parent_type;
241
235
  uint8_t value_type;
242
- } * Leaf;
236
+ } *Leaf;
243
237
 
244
238
  extern VALUE oj_saj_parse(int argc, VALUE *argv, VALUE self);
245
239
  extern VALUE oj_sc_parse(int argc, VALUE *argv, VALUE self);
@@ -260,13 +254,15 @@ extern VALUE oj_custom_parse_cstr(int argc, VALUE *argv, char *json, size_t len)
260
254
  extern bool oj_hash_has_key(VALUE hash, VALUE key);
261
255
  extern void oj_parse_options(VALUE ropts, Options copts);
262
256
 
263
- extern void oj_dump_obj_to_json(VALUE obj, Options copts, Out out);
264
- extern void
265
- oj_dump_obj_to_json_using_params(VALUE obj, Options copts, Out out, int argc, VALUE *argv);
266
- extern void oj_write_obj_to_file(VALUE obj, const char *path, Options copts);
267
- extern void oj_write_obj_to_stream(VALUE obj, VALUE stream, Options copts);
268
- extern void oj_dump_leaf_to_json(Leaf leaf, Options copts, Out out);
269
- extern void oj_write_leaf_to_file(Leaf leaf, const char *path, Options copts);
257
+ extern void oj_dump_obj_to_json(VALUE obj, Options copts, Out out);
258
+ extern void oj_dump_obj_to_json_using_params(VALUE obj, Options copts, Out out, int argc, VALUE *argv);
259
+ extern void oj_write_obj_to_file(VALUE obj, const char *path, Options copts);
260
+ extern void oj_write_obj_to_stream(VALUE obj, VALUE stream, Options copts);
261
+ extern void oj_dump_leaf_to_json(Leaf leaf, Options copts, Out out);
262
+ extern void oj_write_leaf_to_file(Leaf leaf, const char *path, Options copts);
263
+ extern char *oj_longlong_to_string(long long num, bool negative, char *buf);
264
+
265
+ extern StrWriter oj_str_writer_unwrap(VALUE writer);
270
266
 
271
267
  extern void oj_str_writer_push_key(StrWriter sw, const char *key);
272
268
  extern void oj_str_writer_push_object(StrWriter sw, const char *key);
@@ -293,7 +289,7 @@ extern VALUE oj_rails_encode(int argc, VALUE *argv, VALUE self);
293
289
 
294
290
  extern VALUE Oj;
295
291
  extern struct _options oj_default_options;
296
- extern rb_encoding * oj_utf8_encoding;
292
+ extern rb_encoding *oj_utf8_encoding;
297
293
  extern int oj_utf8_encoding_index;
298
294
 
299
295
  extern VALUE oj_bag_class;
@@ -317,13 +313,12 @@ extern VALUE oj_ascii_only_sym;
317
313
  extern VALUE oj_create_additions_sym;
318
314
  extern VALUE oj_decimal_class_sym;
319
315
  extern VALUE oj_hash_class_sym;
320
- extern VALUE oj_in_sym;
321
316
  extern VALUE oj_indent_sym;
322
- extern VALUE oj_nanosecond_sym;
323
317
  extern VALUE oj_max_nesting_sym;
324
318
  extern VALUE oj_object_class_sym;
325
319
  extern VALUE oj_object_nl_sym;
326
320
  extern VALUE oj_quirks_mode_sym;
321
+ extern VALUE oj_skip_null_byte_sym;
327
322
  extern VALUE oj_space_before_sym;
328
323
  extern VALUE oj_space_sym;
329
324
  extern VALUE oj_symbolize_names_sym;
@@ -336,10 +331,10 @@ extern ID oj_array_append_id;
336
331
  extern ID oj_array_end_id;
337
332
  extern ID oj_array_start_id;
338
333
  extern ID oj_as_json_id;
339
- extern ID oj_at_id;
340
334
  extern ID oj_begin_id;
341
335
  extern ID oj_bigdecimal_id;
342
336
  extern ID oj_end_id;
337
+ extern ID oj_eofq_id;
343
338
  extern ID oj_error_id;
344
339
  extern ID oj_exclude_end_id;
345
340
  extern ID oj_file_id;
@@ -354,6 +349,7 @@ extern ID oj_json_create_id;
354
349
  extern ID oj_length_id;
355
350
  extern ID oj_new_id;
356
351
  extern ID oj_parse_id;
352
+ extern ID oj_plus_id;
357
353
  extern ID oj_pos_id;
358
354
  extern ID oj_read_id;
359
355
  extern ID oj_readpartial_id;
@@ -379,10 +375,16 @@ extern bool oj_use_hash_alt;
379
375
  extern bool oj_use_array_alt;
380
376
  extern bool string_writer_optimized;
381
377
 
378
+ static inline VALUE oj_safe_string_convert(VALUE obj) {
379
+ VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
380
+ StringValue(rstr);
381
+ return rstr;
382
+ }
383
+
382
384
  #define APPEND_CHARS(buffer, chars, size) \
383
- { \
384
- memcpy(buffer, chars, size); \
385
- buffer += size; \
385
+ { \
386
+ memcpy(buffer, chars, size); \
387
+ buffer += size; \
386
388
  }
387
389
 
388
390
  #ifdef HAVE_PTHREAD_MUTEX_INIT