oj 3.13.23 → 3.16.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +81 -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 +60 -92
  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 +51 -32
  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 +243 -212
  35. data/ext/oj/oj.h +83 -81
  36. data/ext/oj/parse.c +94 -148
  37. data/ext/oj/parse.h +21 -24
  38. data/ext/oj/parser.c +80 -67
  39. data/ext/oj/parser.h +7 -8
  40. data/ext/oj/rails.c +70 -92
  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 +10 -9
  47. data/ext/oj/saj2.c +37 -49
  48. data/ext/oj/saj2.h +1 -1
  49. data/ext/oj/scp.c +3 -14
  50. data/ext/oj/sparse.c +22 -70
  51. data/ext/oj/stream_writer.c +45 -41
  52. data/ext/oj/strict.c +20 -52
  53. data/ext/oj/string_writer.c +64 -38
  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. data/test/_test_active.rb +8 -9
  74. data/test/_test_active_mimic.rb +7 -8
  75. data/test/_test_mimic_rails.rb +17 -20
  76. data/test/activerecord/result_test.rb +5 -6
  77. data/test/activesupport6/encoding_test.rb +63 -28
  78. data/test/activesupport7/abstract_unit.rb +4 -1
  79. data/test/activesupport7/encoding_test.rb +72 -22
  80. data/test/files.rb +15 -15
  81. data/test/foo.rb +18 -69
  82. data/test/helper.rb +5 -8
  83. data/test/isolated/shared.rb +3 -2
  84. data/test/json_gem/json_addition_test.rb +2 -2
  85. data/test/json_gem/json_common_interface_test.rb +8 -6
  86. data/test/json_gem/json_encoding_test.rb +0 -0
  87. data/test/json_gem/json_ext_parser_test.rb +1 -0
  88. data/test/json_gem/json_fixtures_test.rb +3 -2
  89. data/test/json_gem/json_generator_test.rb +50 -33
  90. data/test/json_gem/json_generic_object_test.rb +11 -11
  91. data/test/json_gem/json_parser_test.rb +46 -46
  92. data/test/json_gem/json_string_matching_test.rb +9 -9
  93. data/test/mem.rb +13 -12
  94. data/test/perf.rb +21 -26
  95. data/test/perf_compat.rb +31 -33
  96. data/test/perf_dump.rb +28 -28
  97. data/test/perf_fast.rb +80 -82
  98. data/test/perf_file.rb +27 -29
  99. data/test/perf_object.rb +65 -69
  100. data/test/perf_once.rb +12 -11
  101. data/test/perf_parser.rb +42 -48
  102. data/test/perf_saj.rb +46 -54
  103. data/test/perf_scp.rb +57 -69
  104. data/test/perf_simple.rb +41 -39
  105. data/test/perf_strict.rb +68 -70
  106. data/test/perf_wab.rb +67 -69
  107. data/test/prec.rb +5 -5
  108. data/test/sample/change.rb +0 -1
  109. data/test/sample/dir.rb +0 -1
  110. data/test/sample/doc.rb +0 -1
  111. data/test/sample/file.rb +0 -1
  112. data/test/sample/group.rb +0 -1
  113. data/test/sample/hasprops.rb +0 -1
  114. data/test/sample/layer.rb +0 -1
  115. data/test/sample/rect.rb +0 -1
  116. data/test/sample/shape.rb +0 -1
  117. data/test/sample/text.rb +0 -1
  118. data/test/sample.rb +16 -16
  119. data/test/sample_json.rb +8 -8
  120. data/test/test_compat.rb +81 -54
  121. data/test/test_custom.rb +63 -52
  122. data/test/test_debian.rb +7 -10
  123. data/test/test_fast.rb +86 -90
  124. data/test/test_file.rb +24 -29
  125. data/test/test_gc.rb +5 -5
  126. data/test/test_generate.rb +5 -5
  127. data/test/test_hash.rb +4 -4
  128. data/test/test_integer_range.rb +9 -9
  129. data/test/test_null.rb +20 -20
  130. data/test/test_object.rb +92 -87
  131. data/test/test_parser.rb +4 -4
  132. data/test/test_parser_debug.rb +5 -5
  133. data/test/test_parser_saj.rb +27 -25
  134. data/test/test_parser_usual.rb +44 -6
  135. data/test/test_rails.rb +2 -2
  136. data/test/test_saj.rb +10 -8
  137. data/test/test_scp.rb +35 -35
  138. data/test/test_strict.rb +38 -32
  139. data/test/test_various.rb +146 -97
  140. data/test/test_wab.rb +46 -44
  141. data/test/test_writer.rb +63 -47
  142. data/test/tests.rb +7 -7
  143. data/test/tests_mimic.rb +6 -6
  144. data/test/tests_mimic_addition.rb +6 -6
  145. metadata +46 -26
  146. data/test/activesupport4/decoding_test.rb +0 -108
  147. data/test/activesupport4/encoding_test.rb +0 -531
  148. data/test/activesupport4/test_helper.rb +0 -41
  149. data/test/activesupport5/abstract_unit.rb +0 -45
  150. data/test/activesupport5/decoding_test.rb +0 -133
  151. data/test/activesupport5/encoding_test.rb +0 -500
  152. data/test/activesupport5/encoding_test_cases.rb +0 -98
  153. data/test/activesupport5/test_helper.rb +0 -72
  154. data/test/activesupport5/time_zone_test_helpers.rb +0 -39
  155. data/test/bar.rb +0 -11
  156. data/test/baz.rb +0 -16
  157. data/test/bug.rb +0 -16
  158. data/test/zoo.rb +0 -13
data/ext/oj/oj.c CHANGED
@@ -14,6 +14,7 @@
14
14
  #include "dump.h"
15
15
  #include "encode.h"
16
16
  #include "intern.h"
17
+ #include "mem.h"
17
18
  #include "odd.h"
18
19
  #include "parse.h"
19
20
  #include "rails.h"
@@ -21,7 +22,7 @@
21
22
  typedef struct _yesNoOpt {
22
23
  VALUE sym;
23
24
  char *attr;
24
- } * YesNoOpt;
25
+ } *YesNoOpt;
25
26
 
26
27
  void Init_oj();
27
28
 
@@ -32,10 +33,10 @@ ID oj_array_append_id;
32
33
  ID oj_array_end_id;
33
34
  ID oj_array_start_id;
34
35
  ID oj_as_json_id;
35
- ID oj_at_id;
36
36
  ID oj_begin_id;
37
37
  ID oj_bigdecimal_id;
38
38
  ID oj_end_id;
39
+ ID oj_eofq_id;
39
40
  ID oj_exclude_end_id;
40
41
  ID oj_error_id;
41
42
  ID oj_file_id;
@@ -50,6 +51,7 @@ ID oj_json_create_id;
50
51
  ID oj_length_id;
51
52
  ID oj_new_id;
52
53
  ID oj_parse_id;
54
+ ID oj_plus_id;
53
55
  ID oj_pos_id;
54
56
  ID oj_raw_json_id;
55
57
  ID oj_read_id;
@@ -90,9 +92,7 @@ VALUE oj_array_class_sym;
90
92
  VALUE oj_create_additions_sym;
91
93
  VALUE oj_decimal_class_sym;
92
94
  VALUE oj_hash_class_sym;
93
- VALUE oj_in_sym;
94
95
  VALUE oj_indent_sym;
95
- VALUE oj_nanosecond_sym;
96
96
  VALUE oj_object_class_sym;
97
97
  VALUE oj_quirks_mode_sym;
98
98
  VALUE oj_safe_sym;
@@ -122,6 +122,7 @@ static VALUE escape_mode_sym;
122
122
  static VALUE integer_range_sym;
123
123
  static VALUE fast_sym;
124
124
  static VALUE float_prec_sym;
125
+ static VALUE float_format_sym;
125
126
  static VALUE float_sym;
126
127
  static VALUE huge_sym;
127
128
  static VALUE ignore_sym;
@@ -134,6 +135,7 @@ static VALUE newline_sym;
134
135
  static VALUE nilnil_sym;
135
136
  static VALUE null_sym;
136
137
  static VALUE object_sym;
138
+ static VALUE omit_null_byte_sym;
137
139
  static VALUE omit_nil_sym;
138
140
  static VALUE rails_sym;
139
141
  static VALUE raise_sym;
@@ -155,8 +157,8 @@ static VALUE word_sym;
155
157
  static VALUE xmlschema_sym;
156
158
  static VALUE xss_safe_sym;
157
159
 
158
- rb_encoding *oj_utf8_encoding = 0;
159
- int oj_utf8_encoding_index = 0;
160
+ rb_encoding *oj_utf8_encoding = 0;
161
+ int oj_utf8_encoding_index = 0;
160
162
 
161
163
  #ifdef HAVE_PTHREAD_MUTEX_INIT
162
164
  pthread_mutex_t oj_cache_mutex;
@@ -221,6 +223,7 @@ struct _options oj_default_options = {
221
223
  0, // array_size
222
224
  AutoNan, // nan_dump
223
225
  false, // omit_nil
226
+ false, // omit_null_byte
224
227
  MAX_DEPTH, // max_depth
225
228
  },
226
229
  {
@@ -229,76 +232,89 @@ struct _options oj_default_options = {
229
232
  NULL, // tail
230
233
  {'\0'}, // err
231
234
  },
232
- NULL, // ignore
235
+ NULL,
233
236
  };
234
237
 
235
238
  /* Document-method: default_options()
236
239
  * call-seq: default_options()
237
240
  *
238
241
  * Returns the default load and dump options as a Hash. The options are
239
- * - *:indent* [_Fixnum_|_String_|_nil_] number of spaces to indent each element in an JSON
240
- *document, zero or nil is no newline between JSON elements, negative indicates no newline between
241
- *top level JSON elements in a stream, a String indicates the string should be used for indentation
242
- * - *:circular* [_Boolean_|_nil_] support circular references while dumping as well as shared
243
- *references
242
+ * - *:indent* [_Fixnum_|_String_|_nil_] number of spaces to indent each element
243
+ * in an JSON document, zero or nil is no newline between JSON elements,
244
+ * negative indicates no newline between top level JSON elements in a stream,
245
+ * a String indicates the string should be used for indentation
246
+ * - *:circular* [_Boolean_|_nil_] support circular references while dumping as
247
+ * well as shared references
244
248
  * - *:auto_define* [_Boolean_|_nil_] automatically define classes if they do not exist
245
249
  * - *:symbol_keys* [_Boolean_|_nil_] use symbols instead of strings for hash keys
246
- * - *:escape_mode* [_:newline_|_:json_|_:slash_|_:xss_safe_|_:ascii_|_:unicode_xss_|_nil_] determines the
247
- *characters to escape
248
- * - *:class_cache* [_Boolean_|_nil_] cache classes for faster parsing (if dynamically modifying
249
- *classes or reloading classes then don't use this)
250
- * - *:mode* [_:object_|_:strict_|_:compat_|_:null_|_:custom_|_:rails_|_:wab_] load and dump modes
251
- *to use for JSON
250
+ * - *:escape_mode* [_:newline_|_:json_|_:slash_|_:xss_safe_|_:ascii_|_:unicode_xss_|_nil_]
251
+ * determines the characters to escape
252
+ * - *:class_cache* [_Boolean_|_nil_] cache classes for faster parsing (if dynamically
253
+ * modifying classes or reloading classes then don't use this)
254
+ * - *:mode* [_:object_|_:strict_|_:compat_|_:null_|_:custom_|_:rails_|_:wab_] load and
255
+ * dump modes to use for JSON
252
256
  * - *:time_format* [_:unix_|_:unix_zone_|_:xmlschema_|_:ruby_] time format when dumping
253
- * - *:bigdecimal_as_decimal* [_Boolean_|_nil_] dump BigDecimal as a decimal number or as a String
254
- * - *:bigdecimal_load* [_:bigdecimal_|_:float_|_:auto_|_:fast_|_:ruby_] load decimals as BigDecimal instead
255
- *of as a Float. :auto pick the most precise for the number of digits. :float should be the same as
256
- *ruby. :fast may require rounding but is must faster.
257
- * - *:compat_bigdecimal* [_true_|_false_] load decimals as BigDecimal instead of as a Float when in
258
- *compat or rails mode.
259
- * - *:create_id* [_String_|_nil_] create id for json compatible object encoding, default is
260
- *'json_class'
261
- * - *:create_additions* [_Boolean_|_nil_] if true allow creation of instances using create_id on
262
- *load.
263
- * - *:second_precision* [_Fixnum_|_nil_] number of digits after the decimal when dumping the
264
- *seconds portion of time
265
- * - *:float_precision* [_Fixnum_|_nil_] number of digits of precision when dumping floats, 0
266
- *indicates use Ruby
257
+ * - *:bigdecimal_as_decimal* [_Boolean_|_nil_] dump BigDecimal as a decimal number or
258
+ * as a String
259
+ * - *:bigdecimal_load* [_:bigdecimal_|_:float_|_:auto_|_:fast_|_:ruby_] load decimals
260
+ * as BigDecimal instead of as a Float. :auto pick the most precise for the number
261
+ * of digits. :float should be the same as ruby. :fast may require rounding but is
262
+ * must faster.
263
+ * - *:compat_bigdecimal* [_true_|_false_] load decimals as BigDecimal instead of as
264
+ * a Float when in compat or rails mode.
265
+ * - *:create_id* [_String_|_nil_] create id for json compatible object encoding,
266
+ * default is 'json_class'
267
+ * - *:create_additions* [_Boolean_|_nil_] if true allow creation of instances using
268
+ * create_id on load.
269
+ * - *:second_precision* [_Fixnum_|_nil_] number of digits after the decimal when
270
+ * dumping the seconds portion of time
271
+ * - *:float_precision* [_Fixnum_|_nil_] number of digits of precision when dumping
272
+ * floats, 0 indicates use Ruby
273
+ * - *:float_format* [_String_] the C printf format string for printing floats.
274
+ * Default follows the float_precision and will be changed if float_precision is
275
+ * changed. The string can be no more than 6 bytes.
267
276
  * - *:use_to_json* [_Boolean_|_nil_] call to_json() methods on dump, default is false
268
277
  * - *:use_as_json* [_Boolean_|_nil_] call as_json() methods on dump, default is false
269
278
  * - *:use_raw_json* [_Boolean_|_nil_] call raw_json() methods on dump, default is false
270
- * - *:nilnil* [_Boolean_|_nil_] if true a nil input to load will return nil and not raise an
271
- *Exception
279
+ * - *:nilnil* [_Boolean_|_nil_] if true a nil input to load will return nil and
280
+ * not raise an Exception
272
281
  * - *:empty_string* [_Boolean_|_nil_] if true an empty input will not raise an Exception
273
282
  * - *:allow_gc* [_Boolean_|_nil_] allow or prohibit GC during parsing, default is true (allow)
274
- * - *:quirks_mode* [_true,_|_false_|_nil_] Allow single JSON values instead of documents, default
275
- *is true (allow)
276
- * - *:allow_invalid_unicode* [_true,_|_false_|_nil_] Allow invalid unicode, default is false (don't
277
- *allow)
278
- * - *:allow_nan* [_true,_|_false_|_nil_] Allow Nan, Infinity, and -Infinity to be parsed, default
279
- *is true (allow)
280
- * - *:indent_str* [_String_|_nil_] String to use for indentation, overriding the indent option is
281
- *not nil
282
- * - *:space* [_String_|_nil_] String to use for the space after the colon in JSON object fields
283
- * - *:space_before* [_String_|_nil_] String to use before the colon separator in JSON object fields
283
+ * - *:quirks_mode* [_true,_|_false_|_nil_] Allow single JSON values instead of
284
+ * documents, default is true (allow)
285
+ * - *:allow_invalid_unicode* [_true,_|_false_|_nil_] Allow invalid unicode,
286
+ * default is false (don't allow)
287
+ * - *:allow_nan* [_true,_|_false_|_nil_] Allow Nan, Infinity, and -Infinity to
288
+ * be parsed, default is true (allow)
289
+ * - *:indent_str* [_String_|_nil_] String to use for indentation, overriding the
290
+ * indent option is not nil
291
+ * - *:space* [_String_|_nil_] String to use for the space after the colon in JSON
292
+ * object fields
293
+ * - *:space_before* [_String_|_nil_] String to use before the colon separator in
294
+ * JSON object fields
284
295
  * - *:object_nl* [_String_|_nil_] String to use after a JSON object field value
285
296
  * - *:array_nl* [_String_|_nil_] String to use after a JSON array value
286
- * - *:nan* [_:null_|_:huge_|_:word_|_:raise_|_:auto_] how to dump Infinity and NaN. :null places a
287
- *null, :huge places a huge number, :word places Infinity or NaN, :raise raises and exception, :auto
288
- *uses default for each mode.
289
- * - *:hash_class* [_Class_|_nil_] Class to use instead of Hash on load, :object_class can also be
290
- *used
297
+ * - *:nan* [_:null_|_:huge_|_:word_|_:raise_|_:auto_] how to dump Infinity and
298
+ * NaN. :null places a null, :huge places a huge number, :word places Infinity
299
+ * or NaN, :raise raises and exception, :auto uses default for each mode.
300
+ * - *:hash_class* [_Class_|_nil_] Class to use instead of Hash on load,
301
+ * :object_class can also be used
291
302
  * - *:array_class* [_Class_|_nil_] Class to use instead of Array on load
292
- * - *:omit_nil* [_true_|_false_] if true Hash and Object attributes with nil values are omitted
303
+ * - *:omit_nil* [_true_|_false_] if true Hash and Object attributes with nil
304
+ * values are omitted
305
+ * - *:omit_null_byte* [_true_|_false_] if true null bytes in strings will be
306
+ * omitted when dumping
293
307
  * - *:ignore* [_nil_|_Array_] either nil or an Array of classes to ignore when dumping
294
- * - *:ignore_under* [_Boolean_] if true then attributes that start with _ are ignored when dumping in
295
- *object or custom mode.
308
+ * - *:ignore_under* [_Boolean_] if true then attributes that start with _ are
309
+ * ignored when dumping in object or custom mode.
296
310
  * - *:cache_keys* [_Boolean_] if true then hash keys are cached if less than 35 bytes.
297
- * - *:cache_str* [_Fixnum_] maximum string value length to cache (strings less than this are cached)
311
+ * - *:cache_str* [_Fixnum_] maximum string value length to cache (strings less
312
+ * than this are cached)
298
313
  * - *:integer_range* [_Range_] Dump integers outside range as strings.
299
- * - *:trace* [_true,_|_false_] Trace all load and dump calls, default is false (trace is off)
300
- * - *:safe* [_true,_|_false_] Safe mimic breaks JSON mimic to be safer, default is false (safe is
301
- *off)
314
+ * - *:trace* [_true,_|_false_] Trace all load and dump calls, default is false
315
+ * (trace is off)
316
+ * - *:safe* [_true,_|_false_] Safe mimic breaks JSON mimic to be safer, default
317
+ * is false (safe is off)
302
318
  *
303
319
  * Return [_Hash_] all current option settings.
304
320
  */
@@ -374,6 +390,7 @@ static VALUE get_def_opts(VALUE self) {
374
390
  oj_safe_sym,
375
391
  (Yes == oj_default_options.safe) ? Qtrue : ((No == oj_default_options.safe) ? Qfalse : Qnil));
376
392
  rb_hash_aset(opts, float_prec_sym, INT2FIX(oj_default_options.float_prec));
393
+ rb_hash_aset(opts, float_format_sym, rb_str_new_cstr(oj_default_options.float_fmt));
377
394
  rb_hash_aset(opts, cache_str_sym, INT2FIX(oj_default_options.cache_str));
378
395
  rb_hash_aset(
379
396
  opts,
@@ -383,6 +400,7 @@ static VALUE get_def_opts(VALUE self) {
383
400
  opts,
384
401
  cache_keys_sym,
385
402
  (Yes == oj_default_options.cache_keys) ? Qtrue : ((No == oj_default_options.cache_keys) ? Qfalse : Qnil));
403
+
386
404
  switch (oj_default_options.mode) {
387
405
  case StrictMode: rb_hash_aset(opts, mode_sym, strict_sym); break;
388
406
  case CompatMode: rb_hash_aset(opts, mode_sym, compat_sym); break;
@@ -458,13 +476,14 @@ static VALUE get_def_opts(VALUE self) {
458
476
  default: rb_hash_aset(opts, nan_sym, auto_sym); break;
459
477
  }
460
478
  rb_hash_aset(opts, omit_nil_sym, oj_default_options.dump_opts.omit_nil ? Qtrue : Qfalse);
479
+ rb_hash_aset(opts, omit_null_byte_sym, oj_default_options.dump_opts.omit_null_byte ? Qtrue : Qfalse);
461
480
  rb_hash_aset(opts, oj_hash_class_sym, oj_default_options.hash_class);
462
481
  rb_hash_aset(opts, oj_array_class_sym, oj_default_options.array_class);
463
482
 
464
483
  if (NULL == oj_default_options.ignore) {
465
484
  rb_hash_aset(opts, ignore_sym, Qnil);
466
485
  } else {
467
- VALUE * vp;
486
+ VALUE *vp;
468
487
  volatile VALUE a = rb_ary_new();
469
488
 
470
489
  for (vp = oj_default_options.ignore; Qnil != *vp; vp++) {
@@ -480,68 +499,67 @@ static VALUE get_def_opts(VALUE self) {
480
499
  *
481
500
  * Sets the default options for load and dump.
482
501
  * - *opts* [_Hash_] options to change
483
- * - *:indent* [_Fixnum_|_String_|_nil_] number of spaces to indent each element in a JSON
484
- *document or the String to use for indentation.
502
+ * - *:indent* [_Fixnum_|_String_|_nil_] number of spaces to indent each element
503
+ * in a JSON document or the String to use for indentation.
485
504
  * - :circular [_Boolean_|_nil_] support circular references while dumping.
486
505
  * - *:auto_define* [_Boolean_|_nil_] automatically define classes if they do not exist.
487
506
  * - *:symbol_keys* [_Boolean_|_nil_] convert hash keys to symbols.
488
507
  * - *:class_cache* [_Boolean_|_nil_] cache classes for faster parsing.
489
- * - *:escape* [_:newline_|_:json_|_:xss_safe_|_:ascii_|_unicode_xss_|_nil_] mode encodes all
490
- *high-bit characters as escaped sequences if :ascii, :json is standand UTF-8 JSON encoding,
491
- *:newline is the same as :json but newlines are not escaped, :unicode_xss allows unicode but
492
- *escapes &, <, and >, and any \u20xx characters along with some others, and :xss_safe escapes &, <,
493
- *and >, and some others.
494
- * - *:bigdecimal_as_decimal* [_Boolean_|_nil_] dump BigDecimal as a decimal number or as a
495
- *String.
496
- * - *:bigdecimal_load* [_:bigdecimal_|_:float_|_:auto_|_nil_] load decimals as BigDecimal instead
497
- *of as a Float. :auto pick the most precise for the number of digits.
498
- * - *:compat_bigdecimal* [_true_|_false_] load decimals as BigDecimal instead of as a Float in
499
- *compat mode.
500
- * - *:mode* [_:object_|_:strict_|_:compat_|_:null_|_:custom_|_:rails_|_:wab_] load and dump mode
501
- *to use for JSON :strict raises an exception when a non-supported Object is encountered. :compat
502
- *attempts to extract variable values from an Object using to_json() or to_hash() then it walks the
503
- *Object's variables if neither is found. The :object mode ignores to_hash() and to_json() methods
504
- *and encodes variables using code internal to the Oj gem. The :null mode ignores non-supported
505
- *Objects and replaces them with a null. The :custom mode honors all dump options. The :rails more
506
- *mimics rails and Active behavior.
507
- * - *:time_format* [_:unix_|_:xmlschema_|_:ruby_] time format when dumping in :compat mode :unix
508
- *decimal number denoting the number of seconds since 1/1/1970, :unix_zone decimal number denoting
509
- *the number of seconds since 1/1/1970 plus the utc_offset in the exponent, :xmlschema date-time
510
- *format taken from XML Schema as a String, :ruby Time.to_s formatted String.
508
+ * - *:escape* [_:newline_|_:json_|_:xss_safe_|_:ascii_|_unicode_xss_|_nil_]
509
+ * mode encodes all high-bit characters as escaped sequences if :ascii, :json
510
+ * is standand UTF-8 JSON encoding, :newline is the same as :json but newlines
511
+ * are not escaped, :unicode_xss allows unicode but escapes &, <, and >, and
512
+ * any \u20xx characters along with some others, and :xss_safe escapes &, <,
513
+ * and >, and some others.
514
+ * - *:bigdecimal_as_decimal* [_Boolean_|_nil_] dump BigDecimal as a decimal
515
+ * number or as a String.
516
+ * - *:bigdecimal_load* [_:bigdecimal_|_:float_|_:auto_|_nil_] load decimals as
517
+ * BigDecimal instead of as a Float. :auto pick the most precise for the number of digits.
518
+ * - *:compat_bigdecimal* [_true_|_false_] load decimals as BigDecimal instead
519
+ * of as a Float in compat mode.
520
+ * - *:mode* [_:object_|_:strict_|_:compat_|_:null_|_:custom_|_:rails_|_:wab_] load
521
+ * and dump mode to use for JSON :strict raises an exception when a non-supported
522
+ * Object is encountered. :compat attempts to extract variable values from an
523
+ * Object using to_json() or to_hash() then it walks the Object's variables if
524
+ * neither is found. The :object mode ignores to_hash() and to_json() methods
525
+ * and encodes variables using code internal to the Oj gem. The :null mode
526
+ * ignores non-supported Objects and replaces them with a null. The :custom
527
+ * mode honors all dump options. The :rails more mimics rails and Active behavior.
528
+ * - *:time_format* [_:unix_|_:xmlschema_|_:ruby_] time format when dumping in :compat
529
+ * mode :unix decimal number denoting the number of seconds since 1/1/1970,
530
+ * :unix_zone decimal number denoting the number of seconds since 1/1/1970
531
+ * plus the utc_offset in the exponent, :xmlschema date-time format taken
532
+ * from XML Schema as a String, :ruby Time.to_s formatted String.
511
533
  * - *:create_id* [_String_|_nil_] create id for json compatible object encoding
512
- * - *:create_additions* [_Boolean_|_nil_] if true allow creation of instances using create_id on
513
- *load.
514
- * - *:second_precision* [_Fixnum_|_nil_] number of digits after the decimal when dumping the
515
- *seconds portion of time.
516
- * - *:float_precision* [_Fixnum_|_nil_] number of digits of precision when dumping floats, 0
517
- *indicates use Ruby.
534
+ * - *:create_additions* [_Boolean_|_nil_] if true allow creation of instances using create_id on load.
535
+ * - *:second_precision* [_Fixnum_|_nil_] number of digits after the decimal
536
+ * when dumping the seconds portion of time.
537
+ * - *:float_format* [_String_] the C printf format string for printing floats.
538
+ * Default follows the float_precision and will be changed if float_precision
539
+ * is changed. The string can be no more than 6 bytes.
540
+ * - *:float_precision* [_Fixnum_|_nil_] number of digits of precision when dumping floats, 0 indicates use Ruby.
518
541
  * - *:use_to_json* [_Boolean_|_nil_] call to_json() methods on dump, default is false.
519
542
  * - *:use_as_json* [_Boolean_|_nil_] call as_json() methods on dump, default is false.
520
543
  * - *:use_to_hash* [_Boolean_|_nil_] call to_hash() methods on dump, default is false.
521
544
  * - *:use_raw_json* [_Boolean_|_nil_] call raw_json() methods on dump, default is false.
522
- * - *:nilnil* [_Boolean_|_nil_] if true a nil input to load will return nil and not raise an
523
- *Exception.
545
+ * - *:nilnil* [_Boolean_|_nil_] if true a nil input to load will return nil and not raise an Exception.
524
546
  * - *:allow_gc* [_Boolean_|_nil_] allow or prohibit GC during parsing, default is true (allow).
525
- * - *:quirks_mode* [_Boolean_|_nil_] allow single JSON values instead of documents, default is
526
- *true (allow).
527
- * - *:allow_invalid_unicode* [_Boolean_|_nil_] allow invalid unicode, default is false (don't
528
- *allow).
547
+ * - *:quirks_mode* [_Boolean_|_nil_] allow single JSON values instead of documents, default is true (allow).
548
+ * - *:allow_invalid_unicode* [_Boolean_|_nil_] allow invalid unicode, default is false (don't allow).
529
549
  * - *:allow_nan* [_Boolean_|_nil_] allow Nan, Infinity, and -Infinity, default is true (allow).
530
550
  * - *:space* [_String_|_nil_] String to use for the space after the colon in JSON object fields.
531
- * - *:space_before* [_String_|_nil_] String to use before the colon separator in JSON object
532
- *fields.
551
+ * - *:space_before* [_String_|_nil_] String to use before the colon separator in JSON object fields.
533
552
  * - *:object_nl* [_String_|_nil_] String to use after a JSON object field value.
534
553
  * - *:array_nl* [_String_|_nil_] String to use after a JSON array value
535
- * - *:nan* [_:null_|_:huge_|_:word_|_:raise_] how to dump Infinity and NaN in null, strict, and
536
- *compat mode. :null places a null, :huge places a huge number, :word places Infinity or NaN, :raise
537
- *raises and exception, :auto uses default for each mode.
538
- * - *:hash_class* [_Class_|_nil_] Class to use instead of Hash on load, :object_class can also be
539
- *used.
554
+ * - *:nan* [_:null_|_:huge_|_:word_|_:raise_] how to dump Infinity and NaN in null,
555
+ * strict, and compat mode. :null places a null, :huge places a huge number, :word
556
+ * places Infinity or NaN, :raise raises and exception, :auto uses default for each mode.
557
+ * - *:hash_class* [_Class_|_nil_] Class to use instead of Hash on load, :object_class can also be used.
540
558
  * - *:array_class* [_Class_|_nil_] Class to use instead of Array on load.
541
559
  * - *:omit_nil* [_true_|_false_] if true Hash and Object attributes with nil values are omitted.
542
560
  * - *:ignore* [_nil_|Array] either nil or an Array of classes to ignore when dumping
543
- * - *:ignore_under* [_Boolean_] if true then attributes that start with _ are ignored when
544
- *dumping in object or custom mode.
561
+ * - *:ignore_under* [_Boolean_] if true then attributes that start with _ are
562
+ * ignored when dumping in object or custom mode.
545
563
  * - *:cache_keys* [_Boolean_] if true then hash keys are cached
546
564
  * - *:cache_str* [_Fixnum_] maximum string value length to cache (strings less than this are cached)
547
565
  * - *:integer_range* [_Range_] Dump integers outside range as strings.
@@ -611,7 +629,6 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
611
629
  if (set_yesno_options(k, v, copts)) {
612
630
  return ST_CONTINUE;
613
631
  }
614
-
615
632
  if (oj_indent_sym == k) {
616
633
  switch (rb_type(v)) {
617
634
  case T_NIL:
@@ -639,15 +656,9 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
639
656
  } else if (float_prec_sym == k) {
640
657
  int n;
641
658
 
642
- #ifdef RUBY_INTEGER_UNIFICATION
643
659
  if (rb_cInteger != rb_obj_class(v)) {
644
660
  rb_raise(rb_eArgError, ":float_precision must be a Integer.");
645
661
  }
646
- #else
647
- if (T_FIXNUM != rb_type(v)) {
648
- rb_raise(rb_eArgError, ":float_precision must be a Fixnum.");
649
- }
650
- #endif
651
662
  n = FIX2INT(v);
652
663
  if (0 >= n) {
653
664
  *copts->float_fmt = '\0';
@@ -662,15 +673,9 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
662
673
  } else if (cache_str_sym == k || cache_string_sym == k) {
663
674
  int n;
664
675
 
665
- #ifdef RUBY_INTEGER_UNIFICATION
666
676
  if (rb_cInteger != rb_obj_class(v)) {
667
677
  rb_raise(rb_eArgError, ":cache_str must be a Integer.");
668
678
  }
669
- #else
670
- if (T_FIXNUM != rb_type(v)) {
671
- rb_raise(rb_eArgError, ":cache_str must be a Fixnum.");
672
- }
673
- #endif
674
679
  n = FIX2INT(v);
675
680
  if (0 >= n) {
676
681
  copts->cache_str = 0;
@@ -683,15 +688,9 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
683
688
  } else if (sec_prec_sym == k) {
684
689
  int n;
685
690
 
686
- #ifdef RUBY_INTEGER_UNIFICATION
687
691
  if (rb_cInteger != rb_obj_class(v)) {
688
692
  rb_raise(rb_eArgError, ":second_precision must be a Integer.");
689
693
  }
690
- #else
691
- if (T_FIXNUM != rb_type(v)) {
692
- rb_raise(rb_eArgError, ":second_precision must be a Fixnum.");
693
- }
694
- #endif
695
694
  n = NUM2INT(v);
696
695
  if (0 > n) {
697
696
  n = 0;
@@ -769,7 +768,6 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
769
768
  if (Qnil == v) {
770
769
  return ST_CONTINUE;
771
770
  }
772
-
773
771
  copts->compat_bigdec = (Qtrue == v);
774
772
  } else if (oj_decimal_class_sym == k) {
775
773
  if (rb_cFloat == v) {
@@ -782,7 +780,7 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
782
780
  } else if (create_id_sym == k) {
783
781
  if (Qnil == v) {
784
782
  if (oj_json_class != oj_default_options.create_id && NULL != copts->create_id) {
785
- xfree((char *)oj_default_options.create_id);
783
+ OJ_R_FREE((char *)oj_default_options.create_id);
786
784
  }
787
785
  copts->create_id = NULL;
788
786
  copts->create_id_len = 0;
@@ -791,7 +789,7 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
791
789
 
792
790
  len = RSTRING_LEN(v);
793
791
  if (len != copts->create_id_len || 0 != strcmp(copts->create_id, str)) {
794
- copts->create_id = ALLOC_N(char, len + 1);
792
+ copts->create_id = OJ_R_ALLOC_N(char, len + 1);
795
793
  strcpy((char *)copts->create_id, str);
796
794
  copts->create_id_len = len;
797
795
  }
@@ -882,6 +880,17 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
882
880
  } else {
883
881
  rb_raise(rb_eArgError, ":omit_nil must be true or false.");
884
882
  }
883
+ } else if (omit_null_byte_sym == k) {
884
+ if (Qnil == v) {
885
+ return ST_CONTINUE;
886
+ }
887
+ if (Qtrue == v) {
888
+ copts->dump_opts.omit_null_byte = true;
889
+ } else if (Qfalse == v) {
890
+ copts->dump_opts.omit_null_byte = false;
891
+ } else {
892
+ rb_raise(rb_eArgError, ":omit_null_byte must be true or false.");
893
+ }
885
894
  } else if (oj_ascii_only_sym == k) {
886
895
  // This is here only for backwards compatibility with the original Oj.
887
896
  if (Qtrue == v) {
@@ -911,7 +920,7 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
911
920
  copts->array_class = v;
912
921
  }
913
922
  } else if (ignore_sym == k) {
914
- xfree(copts->ignore);
923
+ OJ_R_FREE(copts->ignore);
915
924
  copts->ignore = NULL;
916
925
  if (Qnil != v) {
917
926
  int cnt;
@@ -921,7 +930,7 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
921
930
  if (0 < cnt) {
922
931
  int i;
923
932
 
924
- copts->ignore = ALLOC_N(VALUE, cnt + 1);
933
+ copts->ignore = OJ_R_ALLOC_N(VALUE, cnt + 1);
925
934
  for (i = 0; i < cnt; i++) {
926
935
  copts->ignore[i] = RARRAY_AREF(v, i);
927
936
  }
@@ -949,7 +958,26 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
949
958
  if (Qnil == v) {
950
959
  return ST_CONTINUE;
951
960
  }
952
- copts->sym_key = (Qtrue == v) ? Yes : No;
961
+ copts->sym_key = (Qtrue == v) ? Yes : No;
962
+
963
+ } else if (oj_max_nesting_sym == k) {
964
+ if (Qtrue == v) {
965
+ copts->dump_opts.max_depth = 100;
966
+ } else if (Qfalse == v || Qnil == v) {
967
+ copts->dump_opts.max_depth = MAX_DEPTH;
968
+ } else if (T_FIXNUM == rb_type(v)) {
969
+ copts->dump_opts.max_depth = NUM2INT(v);
970
+ if (0 >= copts->dump_opts.max_depth) {
971
+ copts->dump_opts.max_depth = MAX_DEPTH;
972
+ }
973
+ }
974
+ } else if (float_format_sym == k) {
975
+ rb_check_type(v, T_STRING);
976
+ if (6 < (int)RSTRING_LEN(v)) {
977
+ rb_raise(rb_eArgError, ":float_format must be 6 bytes or less.");
978
+ }
979
+ strncpy(copts->float_fmt, RSTRING_PTR(v), (size_t)RSTRING_LEN(v));
980
+ copts->float_fmt[RSTRING_LEN(v)] = '\0';
953
981
  }
954
982
  return ST_CONTINUE;
955
983
  }
@@ -958,7 +986,6 @@ void oj_parse_options(VALUE ropts, Options copts) {
958
986
  if (T_HASH != rb_type(ropts)) {
959
987
  return;
960
988
  }
961
-
962
989
  rb_hash_foreach(ropts, parse_options_cb, (VALUE)copts);
963
990
  oj_parse_opt_match_string(&copts->str_rx, ropts);
964
991
 
@@ -1114,7 +1141,7 @@ static VALUE load(int argc, VALUE *argv, VALUE self) {
1114
1141
  * Returns [_Object_|_Hash_|_Array_|_String_|_Fixnum_|_Float_|_Boolean_|_nil_]
1115
1142
  */
1116
1143
  static VALUE load_file(int argc, VALUE *argv, VALUE self) {
1117
- char * path;
1144
+ char *path;
1118
1145
  int fd;
1119
1146
  Mode mode = oj_default_options.mode;
1120
1147
  struct _parseInfo pi;
@@ -1122,7 +1149,7 @@ static VALUE load_file(int argc, VALUE *argv, VALUE self) {
1122
1149
  if (1 > argc) {
1123
1150
  rb_raise(rb_eArgError, "Wrong number of arguments to load().");
1124
1151
  }
1125
- Check_Type(*argv, T_STRING);
1152
+ path = StringValuePtr(*argv);
1126
1153
  parse_info_init(&pi);
1127
1154
  pi.options = oj_default_options;
1128
1155
  pi.handler = Qnil;
@@ -1153,16 +1180,15 @@ static VALUE load_file(int argc, VALUE *argv, VALUE self) {
1153
1180
  }
1154
1181
  }
1155
1182
  }
1156
- path = StringValuePtr(*argv);
1157
1183
  #ifdef _WIN32
1158
1184
  {
1159
1185
  WCHAR *wide_path;
1160
1186
  wide_path = rb_w32_mbstr_to_wstr(CP_UTF8, path, -1, NULL);
1161
- fd = rb_w32_wopen(wide_path, O_RDONLY);
1162
- free(wide_path);
1187
+ fd = rb_w32_wopen(wide_path, O_RDONLY);
1188
+ OJ_FREE(wide_path);
1163
1189
  }
1164
1190
  #else
1165
- fd = open(path, O_RDONLY);
1191
+ fd = open(path, O_RDONLY);
1166
1192
  #endif
1167
1193
  if (0 == fd) {
1168
1194
  rb_raise(rb_eIOError, "%s", strerror(errno));
@@ -1237,10 +1263,10 @@ static VALUE safe_load(VALUE self, VALUE doc) {
1237
1263
  */
1238
1264
 
1239
1265
  struct dump_arg {
1240
- struct _out * out;
1266
+ struct _out *out;
1241
1267
  struct _options *copts;
1242
1268
  int argc;
1243
- VALUE * argv;
1269
+ VALUE *argv;
1244
1270
  };
1245
1271
 
1246
1272
  static VALUE dump_body(VALUE a) {
@@ -1296,8 +1322,8 @@ static VALUE dump(int argc, VALUE *argv, VALUE self) {
1296
1322
 
1297
1323
  oj_out_init(arg.out);
1298
1324
 
1299
- arg.out->omit_nil = copts.dump_opts.omit_nil;
1300
- arg.out->caller = CALLER_DUMP;
1325
+ arg.out->omit_nil = copts.dump_opts.omit_nil;
1326
+ arg.out->omit_null_byte = copts.dump_opts.omit_null_byte;
1301
1327
 
1302
1328
  return rb_ensure(dump_body, (VALUE)&arg, dump_ensure, (VALUE)&arg);
1303
1329
  }
@@ -1309,17 +1335,16 @@ static VALUE dump(int argc, VALUE *argv, VALUE self) {
1309
1335
  * will be called. The mode is set to :compat.
1310
1336
  * - *obj* [_Object_] Object to serialize as an JSON document String
1311
1337
  * - *options* [_Hash_]
1312
- * - *:max_nesting* [_boolean_] It true nesting is limited to 100. The option to detect circular
1313
- * references is available but is not compatible with the json gem., default is false
1314
- * - *:allow_nan* [_boolean_] If true non JSON compliant words such as Nan and Infinity will be
1315
- * used as appropriate, default is true.
1316
- * - *:quirks_mode* [_boolean_] Allow single JSON values instead of documents, default is true
1317
- * (allow).
1318
- * - *:indent* [_String_|_nil_] String to use for indentation, overriding the indent option if not
1319
- * nil.
1338
+ * - *:max_nesting* [_Fixnum_|_boolean_] It true nesting is limited to 100.
1339
+ * If a Fixnum nesting is set to the provided value. The option to detect
1340
+ * circular references is available but is not compatible with the json gem.,
1341
+ * default is false or unlimited.
1342
+ * - *:allow_nan* [_boolean_] If true non JSON compliant words such as Nan and
1343
+ * Infinity will be used as appropriate, default is true.
1344
+ * - *:quirks_mode* [_boolean_] Allow single JSON values instead of documents, default is true (allow).
1345
+ * - *:indent* [_String_|_nil_] String to use for indentation, overriding the indent option if not nil.
1320
1346
  * - *:space* [_String_|_nil_] String to use for the space after the colon in JSON object fields.
1321
- * - *:space_before* [_String_|_nil_] String to use before the colon separator in JSON object
1322
- * fields.
1347
+ * - *:space_before* [_String_|_nil_] String to use before the colon separator in JSON object fields.
1323
1348
  * - *:object_nl* [_String_|_nil_] String to use after a JSON object field value.
1324
1349
  * - *:array_nl* [_String_|_nil_] String to use after a JSON array value.
1325
1350
  * - *:trace* [_Boolean_] If true trace is turned on.
@@ -1344,7 +1369,8 @@ static VALUE to_json(int argc, VALUE *argv, VALUE self) {
1344
1369
 
1345
1370
  oj_out_init(&out);
1346
1371
 
1347
- out.omit_nil = copts.dump_opts.omit_nil;
1372
+ out.omit_nil = copts.dump_opts.omit_nil;
1373
+ out.omit_null_byte = copts.dump_opts.omit_null_byte;
1348
1374
  // For obj.to_json or generate nan is not allowed but if called from dump
1349
1375
  // it is.
1350
1376
  oj_dump_obj_to_json_using_params(*argv, &copts, &out, argc - 1, argv + 1);
@@ -1376,7 +1402,6 @@ static VALUE to_file(int argc, VALUE *argv, VALUE self) {
1376
1402
  if (3 == argc) {
1377
1403
  oj_parse_options(argv[2], &copts);
1378
1404
  }
1379
- Check_Type(*argv, T_STRING);
1380
1405
  oj_write_obj_to_file(argv[1], StringValuePtr(*argv), &copts);
1381
1406
 
1382
1407
  return Qnil;
@@ -1414,10 +1439,10 @@ static VALUE to_stream(int argc, VALUE *argv, VALUE self) {
1414
1439
  *
1415
1440
  * - *clas* [_Class__|_Module_] Class or Module to be made special
1416
1441
  * - *create_object* [_Object_] object to call the create method on
1417
- * - *create_method* [_Symbol_] method on the clas that will create a new instance of the clas when
1418
- * given all the member values in the order specified.
1419
- * - *members* [_Symbol__|_String_] methods used to get the member values from instances of the
1420
- * clas.
1442
+ * - *create_method* [_Symbol_] method on the clas that will create a new instance
1443
+ * of the clas when given all the member values in the order specified.
1444
+ * - *members* [_Symbol__|_String_] methods used to get the member values from
1445
+ * instances of the clas.
1421
1446
  */
1422
1447
  static VALUE register_odd(int argc, VALUE *argv, VALUE self) {
1423
1448
  if (3 > argc) {
@@ -1450,10 +1475,10 @@ static VALUE register_odd(int argc, VALUE *argv, VALUE self) {
1450
1475
  *
1451
1476
  * - *clas* [_Class_|_Module_] Class or Module to be made special
1452
1477
  * - *create_object* [_Object_] object to call the create method on
1453
- * - *create_method* [_Symbol_] method on the clas that will create a new instance of the clas when
1454
- *given all the member values in the order specified.
1455
- * - *dump_method* [_Symbol_|_String_] method to call on the object being serialized to generate the
1456
- *raw JSON.
1478
+ * - *create_method* [_Symbol_] method on the clas that will create a new instance
1479
+ * of the clas when given all the member values in the order specified.
1480
+ * - *dump_method* [_Symbol_|_String_] method to call on the object being
1481
+ * serialized to generate the raw JSON.
1457
1482
  */
1458
1483
  static VALUE register_odd_raw(int argc, VALUE *argv, VALUE self) {
1459
1484
  if (3 > argc) {
@@ -1679,8 +1704,8 @@ extern VALUE oj_define_mimic_json(int argc, VALUE *argv, VALUE self);
1679
1704
  * - *:space_before* [_String_] String placed before a : delimiter
1680
1705
  * - *:object_nl* [_String_] String placed after a JSON object
1681
1706
  * - *:array_nl* [_String_] String placed after a JSON array
1682
- * - *:ascii_only* [_Boolean_] if not nil or false then use only ascii characters in the output.
1683
- * Note JSON.generate does support this even if it is not documented.
1707
+ * - *:ascii_only* [_Boolean_] if not nil or false then use only ascii characters
1708
+ * in the output. Note JSON.generate does support this even if it is not documented.
1684
1709
  *
1685
1710
  * Returns [_String_]generated JSON.
1686
1711
  */
@@ -1718,12 +1743,15 @@ static VALUE protect_require(VALUE x) {
1718
1743
 
1719
1744
  extern void print_all_odds(const char *label);
1720
1745
 
1721
- static VALUE
1722
- debug_odd(VALUE self, VALUE label) {
1746
+ static VALUE debug_odd(VALUE self, VALUE label) {
1723
1747
  print_all_odds(RSTRING_PTR(label));
1724
1748
  return Qnil;
1725
1749
  }
1726
1750
 
1751
+ static VALUE mem_report(VALUE self) {
1752
+ oj_mem_report();
1753
+ return Qnil;
1754
+ }
1727
1755
 
1728
1756
  /* Document-module: Oj
1729
1757
  *
@@ -1734,8 +1762,8 @@ debug_odd(VALUE self, VALUE label) {
1734
1762
  * global and options to methods allow additional behavior modifications. The
1735
1763
  * modes are:
1736
1764
  *
1737
- * - *:strict* mode will only allow the 7 basic JSON types to be serialized. Any other Object
1738
- * will raise an Exception.
1765
+ * - *:strict* mode will only allow the 7 basic JSON types to be serialized.
1766
+ * Any other Object will raise an Exception.
1739
1767
  *
1740
1768
  * - *:null* mode is similar to the :strict mode except any Object that is not
1741
1769
  * one of the JSON base types is replaced by a JSON null.
@@ -1775,7 +1803,7 @@ void Init_oj(void) {
1775
1803
  rb_protect(protect_require, Qnil, &err);
1776
1804
  rb_require("stringio");
1777
1805
  oj_utf8_encoding_index = rb_enc_find_index("UTF-8");
1778
- oj_utf8_encoding = rb_enc_from_index(oj_utf8_encoding_index);
1806
+ oj_utf8_encoding = rb_enc_from_index(oj_utf8_encoding_index);
1779
1807
 
1780
1808
  // rb_define_module_function(Oj, "hash_test", hash_test, 0);
1781
1809
  rb_define_module_function(Oj, "debug_odd", debug_odd, 1);
@@ -1812,49 +1840,52 @@ void Init_oj(void) {
1812
1840
 
1813
1841
  rb_define_module_function(Oj, "optimize_rails", oj_optimize_rails, 0);
1814
1842
 
1815
- oj_add_value_id = rb_intern("add_value");
1816
- oj_array_append_id = rb_intern("array_append");
1817
- oj_array_end_id = rb_intern("array_end");
1818
- oj_array_start_id = rb_intern("array_start");
1819
- oj_as_json_id = rb_intern("as_json");
1820
- oj_at_id = rb_intern("at");
1821
- oj_begin_id = rb_intern("begin");
1822
- oj_bigdecimal_id = rb_intern("BigDecimal");
1823
- oj_end_id = rb_intern("end");
1824
- oj_error_id = rb_intern("error");
1825
- oj_exclude_end_id = rb_intern("exclude_end?");
1826
- oj_file_id = rb_intern("file?");
1827
- oj_fileno_id = rb_intern("fileno");
1828
- oj_ftype_id = rb_intern("ftype");
1829
- oj_hash_end_id = rb_intern("hash_end");
1830
- oj_hash_key_id = rb_intern("hash_key");
1831
- oj_hash_set_id = rb_intern("hash_set");
1832
- oj_hash_start_id = rb_intern("hash_start");
1833
- oj_iconv_id = rb_intern("iconv");
1834
- oj_json_create_id = rb_intern("json_create");
1835
- oj_length_id = rb_intern("length");
1836
- oj_new_id = rb_intern("new");
1837
- oj_parse_id = rb_intern("parse");
1838
- oj_pos_id = rb_intern("pos");
1839
- oj_raw_json_id = rb_intern("raw_json");
1840
- oj_read_id = rb_intern("read");
1841
- oj_readpartial_id = rb_intern("readpartial");
1842
- oj_replace_id = rb_intern("replace");
1843
- oj_stat_id = rb_intern("stat");
1844
- oj_string_id = rb_intern("string");
1845
- oj_to_h_id = rb_intern("to_h");
1846
- oj_to_hash_id = rb_intern("to_hash");
1847
- oj_to_json_id = rb_intern("to_json");
1848
- oj_to_s_id = rb_intern("to_s");
1849
- oj_to_sym_id = rb_intern("to_sym");
1850
- oj_to_time_id = rb_intern("to_time");
1851
- oj_tv_nsec_id = rb_intern("tv_nsec");
1852
- oj_tv_sec_id = rb_intern("tv_sec");
1853
- oj_tv_usec_id = rb_intern("tv_usec");
1854
- oj_utc_id = rb_intern("utc");
1855
- oj_utc_offset_id = rb_intern("utc_offset");
1856
- oj_utcq_id = rb_intern("utc?");
1857
- oj_write_id = rb_intern("write");
1843
+ rb_define_module_function(Oj, "mem_report", mem_report, 0);
1844
+
1845
+ oj_add_value_id = rb_intern("add_value");
1846
+ oj_array_append_id = rb_intern("array_append");
1847
+ oj_array_end_id = rb_intern("array_end");
1848
+ oj_array_start_id = rb_intern("array_start");
1849
+ oj_as_json_id = rb_intern("as_json");
1850
+ oj_begin_id = rb_intern("begin");
1851
+ oj_bigdecimal_id = rb_intern("BigDecimal");
1852
+ oj_end_id = rb_intern("end");
1853
+ oj_eofq_id = rb_intern("eof?");
1854
+ oj_error_id = rb_intern("error");
1855
+ oj_exclude_end_id = rb_intern("exclude_end?");
1856
+ oj_file_id = rb_intern("file?");
1857
+ oj_fileno_id = rb_intern("fileno");
1858
+ oj_ftype_id = rb_intern("ftype");
1859
+ oj_hash_end_id = rb_intern("hash_end");
1860
+ oj_hash_key_id = rb_intern("hash_key");
1861
+ oj_hash_set_id = rb_intern("hash_set");
1862
+ oj_hash_start_id = rb_intern("hash_start");
1863
+ oj_iconv_id = rb_intern("iconv");
1864
+ oj_json_create_id = rb_intern("json_create");
1865
+ oj_length_id = rb_intern("length");
1866
+ oj_new_id = rb_intern("new");
1867
+ oj_parse_id = rb_intern("parse");
1868
+ oj_plus_id = rb_intern("+");
1869
+ oj_pos_id = rb_intern("pos");
1870
+ oj_raw_json_id = rb_intern("raw_json");
1871
+ oj_read_id = rb_intern("read");
1872
+ oj_readpartial_id = rb_intern("readpartial");
1873
+ oj_replace_id = rb_intern("replace");
1874
+ oj_stat_id = rb_intern("stat");
1875
+ oj_string_id = rb_intern("string");
1876
+ oj_to_h_id = rb_intern("to_h");
1877
+ oj_to_hash_id = rb_intern("to_hash");
1878
+ oj_to_json_id = rb_intern("to_json");
1879
+ oj_to_s_id = rb_intern("to_s");
1880
+ oj_to_sym_id = rb_intern("to_sym");
1881
+ oj_to_time_id = rb_intern("to_time");
1882
+ oj_tv_nsec_id = rb_intern("tv_nsec");
1883
+ oj_tv_sec_id = rb_intern("tv_sec");
1884
+ oj_tv_usec_id = rb_intern("tv_usec");
1885
+ oj_utc_id = rb_intern("utc");
1886
+ oj_utc_offset_id = rb_intern("utc_offset");
1887
+ oj_utcq_id = rb_intern("utc?");
1888
+ oj_write_id = rb_intern("write");
1858
1889
 
1859
1890
  rb_require("oj/bag");
1860
1891
  rb_require("oj/error");
@@ -1925,6 +1956,8 @@ void Init_oj(void) {
1925
1956
  rb_gc_register_address(&integer_range_sym);
1926
1957
  fast_sym = ID2SYM(rb_intern("fast"));
1927
1958
  rb_gc_register_address(&fast_sym);
1959
+ float_format_sym = ID2SYM(rb_intern("float_format"));
1960
+ rb_gc_register_address(&float_format_sym);
1928
1961
  float_prec_sym = ID2SYM(rb_intern("float_precision"));
1929
1962
  rb_gc_register_address(&float_prec_sym);
1930
1963
  float_sym = ID2SYM(rb_intern("float"));
@@ -1965,14 +1998,10 @@ void Init_oj(void) {
1965
1998
  rb_gc_register_address(&oj_decimal_class_sym);
1966
1999
  oj_hash_class_sym = ID2SYM(rb_intern("hash_class"));
1967
2000
  rb_gc_register_address(&oj_hash_class_sym);
1968
- oj_in_sym = ID2SYM(rb_intern("in"));
1969
- rb_gc_register_address(&oj_in_sym);
1970
2001
  oj_indent_sym = ID2SYM(rb_intern("indent"));
1971
2002
  rb_gc_register_address(&oj_indent_sym);
1972
2003
  oj_max_nesting_sym = ID2SYM(rb_intern("max_nesting"));
1973
2004
  rb_gc_register_address(&oj_max_nesting_sym);
1974
- oj_nanosecond_sym = ID2SYM(rb_intern("nanosecond"));
1975
- rb_gc_register_address(&oj_nanosecond_sym);
1976
2005
  oj_object_class_sym = ID2SYM(rb_intern("object_class"));
1977
2006
  rb_gc_register_address(&oj_object_class_sym);
1978
2007
  oj_object_nl_sym = ID2SYM(rb_intern("object_nl"));
@@ -1981,6 +2010,8 @@ void Init_oj(void) {
1981
2010
  rb_gc_register_address(&oj_quirks_mode_sym);
1982
2011
  oj_safe_sym = ID2SYM(rb_intern("safe"));
1983
2012
  rb_gc_register_address(&oj_safe_sym);
2013
+ omit_null_byte_sym = ID2SYM(rb_intern("omit_null_byte"));
2014
+ rb_gc_register_address(&omit_null_byte_sym);
1984
2015
  oj_space_before_sym = ID2SYM(rb_intern("space_before"));
1985
2016
  rb_gc_register_address(&oj_space_before_sym);
1986
2017
  oj_space_sym = ID2SYM(rb_intern("space"));