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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +86 -0
- data/README.md +2 -2
- data/ext/oj/buf.h +7 -6
- data/ext/oj/cache.c +29 -26
- data/ext/oj/cache.h +3 -2
- data/ext/oj/cache8.c +10 -9
- data/ext/oj/circarray.c +7 -5
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +5 -12
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +20 -60
- data/ext/oj/custom.c +26 -59
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +103 -53
- data/ext/oj/dump.h +1 -4
- data/ext/oj/dump_compat.c +557 -592
- data/ext/oj/dump_leaf.c +3 -5
- data/ext/oj/dump_object.c +42 -48
- data/ext/oj/dump_strict.c +10 -22
- data/ext/oj/encoder.c +1 -1
- data/ext/oj/err.c +2 -13
- data/ext/oj/err.h +9 -12
- data/ext/oj/extconf.rb +16 -7
- data/ext/oj/fast.c +63 -98
- data/ext/oj/intern.c +62 -47
- data/ext/oj/intern.h +3 -7
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +54 -38
- data/ext/oj/object.c +33 -43
- data/ext/oj/odd.c +8 -6
- data/ext/oj/odd.h +4 -4
- data/ext/oj/oj.c +245 -216
- data/ext/oj/oj.h +83 -81
- data/ext/oj/parse.c +109 -153
- data/ext/oj/parse.h +21 -24
- data/ext/oj/parser.c +80 -67
- data/ext/oj/parser.h +9 -8
- data/ext/oj/rails.c +71 -94
- data/ext/oj/reader.c +9 -14
- data/ext/oj/reader.h +4 -2
- data/ext/oj/resolve.c +3 -4
- data/ext/oj/rxclass.c +6 -5
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +13 -15
- data/ext/oj/saj2.c +37 -49
- data/ext/oj/saj2.h +1 -1
- data/ext/oj/scp.c +6 -20
- data/ext/oj/sparse.c +22 -70
- data/ext/oj/stream_writer.c +46 -48
- data/ext/oj/strict.c +22 -56
- data/ext/oj/string_writer.c +64 -40
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +125 -114
- data/ext/oj/usual.h +7 -6
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +13 -2
- data/ext/oj/val_stack.h +8 -7
- data/ext/oj/wab.c +25 -57
- data/lib/oj/active_support_helper.rb +1 -3
- data/lib/oj/bag.rb +7 -1
- data/lib/oj/easy_hash.rb +4 -5
- data/lib/oj/error.rb +0 -1
- data/lib/oj/json.rb +162 -150
- data/lib/oj/mimic.rb +7 -7
- data/lib/oj/schandler.rb +5 -4
- data/lib/oj/state.rb +8 -5
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +2 -0
- data/pages/InstallOptions.md +20 -0
- data/pages/Options.md +4 -0
- metadata +46 -121
- data/test/_test_active.rb +0 -76
- data/test/_test_active_mimic.rb +0 -96
- data/test/_test_mimic_rails.rb +0 -126
- data/test/activerecord/result_test.rb +0 -32
- data/test/activesupport4/decoding_test.rb +0 -108
- data/test/activesupport4/encoding_test.rb +0 -531
- data/test/activesupport4/test_helper.rb +0 -41
- data/test/activesupport5/abstract_unit.rb +0 -45
- data/test/activesupport5/decoding_test.rb +0 -133
- data/test/activesupport5/encoding_test.rb +0 -500
- data/test/activesupport5/encoding_test_cases.rb +0 -98
- data/test/activesupport5/test_helper.rb +0 -72
- data/test/activesupport5/time_zone_test_helpers.rb +0 -39
- data/test/activesupport6/abstract_unit.rb +0 -44
- data/test/activesupport6/decoding_test.rb +0 -133
- data/test/activesupport6/encoding_test.rb +0 -507
- data/test/activesupport6/encoding_test_cases.rb +0 -98
- data/test/activesupport6/test_common.rb +0 -17
- data/test/activesupport6/test_helper.rb +0 -163
- data/test/activesupport6/time_zone_test_helpers.rb +0 -39
- data/test/activesupport7/abstract_unit.rb +0 -49
- data/test/activesupport7/decoding_test.rb +0 -125
- data/test/activesupport7/encoding_test.rb +0 -486
- data/test/activesupport7/encoding_test_cases.rb +0 -104
- data/test/activesupport7/time_zone_test_helpers.rb +0 -47
- data/test/bar.rb +0 -11
- data/test/baz.rb +0 -16
- data/test/bug.rb +0 -16
- data/test/files.rb +0 -29
- data/test/foo.rb +0 -77
- data/test/helper.rb +0 -42
- data/test/isolated/shared.rb +0 -308
- data/test/isolated/test_mimic_after.rb +0 -13
- data/test/isolated/test_mimic_alone.rb +0 -12
- data/test/isolated/test_mimic_as_json.rb +0 -45
- data/test/isolated/test_mimic_before.rb +0 -13
- data/test/isolated/test_mimic_define.rb +0 -28
- data/test/isolated/test_mimic_rails_after.rb +0 -22
- data/test/isolated/test_mimic_rails_before.rb +0 -21
- data/test/isolated/test_mimic_redefine.rb +0 -15
- data/test/json_gem/json_addition_test.rb +0 -216
- data/test/json_gem/json_common_interface_test.rb +0 -153
- data/test/json_gem/json_encoding_test.rb +0 -107
- data/test/json_gem/json_ext_parser_test.rb +0 -20
- data/test/json_gem/json_fixtures_test.rb +0 -35
- data/test/json_gem/json_generator_test.rb +0 -396
- data/test/json_gem/json_generic_object_test.rb +0 -90
- data/test/json_gem/json_parser_test.rb +0 -477
- data/test/json_gem/json_string_matching_test.rb +0 -42
- data/test/json_gem/test_helper.rb +0 -30
- data/test/mem.rb +0 -33
- data/test/perf.rb +0 -107
- data/test/perf_compat.rb +0 -130
- data/test/perf_dump.rb +0 -50
- data/test/perf_fast.rb +0 -164
- data/test/perf_file.rb +0 -64
- data/test/perf_object.rb +0 -138
- data/test/perf_once.rb +0 -58
- data/test/perf_parser.rb +0 -189
- data/test/perf_saj.rb +0 -109
- data/test/perf_scp.rb +0 -152
- data/test/perf_simple.rb +0 -287
- data/test/perf_strict.rb +0 -139
- data/test/perf_wab.rb +0 -131
- data/test/prec.rb +0 -23
- data/test/sample/change.rb +0 -14
- data/test/sample/dir.rb +0 -19
- data/test/sample/doc.rb +0 -36
- data/test/sample/file.rb +0 -48
- data/test/sample/group.rb +0 -16
- data/test/sample/hasprops.rb +0 -16
- data/test/sample/layer.rb +0 -12
- data/test/sample/line.rb +0 -20
- data/test/sample/oval.rb +0 -10
- data/test/sample/rect.rb +0 -10
- data/test/sample/shape.rb +0 -35
- data/test/sample/text.rb +0 -20
- data/test/sample.rb +0 -54
- data/test/sample_json.rb +0 -37
- data/test/test_compat.rb +0 -540
- data/test/test_custom.rb +0 -544
- data/test/test_debian.rb +0 -53
- data/test/test_fast.rb +0 -530
- data/test/test_file.rb +0 -255
- data/test/test_gc.rb +0 -60
- data/test/test_generate.rb +0 -21
- data/test/test_hash.rb +0 -39
- data/test/test_integer_range.rb +0 -72
- data/test/test_null.rb +0 -376
- data/test/test_object.rb +0 -1025
- data/test/test_parser.rb +0 -11
- data/test/test_parser_debug.rb +0 -27
- data/test/test_parser_saj.rb +0 -335
- data/test/test_parser_usual.rb +0 -217
- data/test/test_rails.rb +0 -35
- data/test/test_saj.rb +0 -186
- data/test/test_scp.rb +0 -431
- data/test/test_strict.rb +0 -435
- data/test/test_various.rb +0 -752
- data/test/test_wab.rb +0 -309
- data/test/test_writer.rb +0 -380
- data/test/tests.rb +0 -33
- data/test/tests_mimic.rb +0 -23
- data/test/tests_mimic_addition.rb +0 -16
- 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
|
-
} *
|
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
|
159
|
-
int
|
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,
|
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
|
240
|
-
*document, zero or nil is no newline between JSON elements,
|
241
|
-
*top level JSON elements in a stream,
|
242
|
-
*
|
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_]
|
247
|
-
*characters to escape
|
248
|
-
* - *:class_cache* [_Boolean_|_nil_] cache classes for faster parsing (if dynamically
|
249
|
-
*classes or reloading classes then don't use this)
|
250
|
-
* - *:mode* [_:object_|_:strict_|_:compat_|_:null_|_:custom_|_:rails_|_:wab_] load and
|
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
|
254
|
-
*
|
255
|
-
*
|
256
|
-
*
|
257
|
-
*
|
258
|
-
*
|
259
|
-
* - *:
|
260
|
-
*
|
261
|
-
* - *:
|
262
|
-
*
|
263
|
-
* - *:
|
264
|
-
*
|
265
|
-
* - *:
|
266
|
-
*
|
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
|
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
|
275
|
-
*is true (allow)
|
276
|
-
* - *:allow_invalid_unicode* [_true,_|_false_|_nil_] Allow invalid unicode,
|
277
|
-
*allow)
|
278
|
-
* - *:allow_nan* [_true,_|_false_|_nil_] Allow Nan, Infinity, and -Infinity to
|
279
|
-
*is true (allow)
|
280
|
-
* - *:indent_str* [_String_|_nil_] String to use for indentation, overriding the
|
281
|
-
*not nil
|
282
|
-
* - *:space* [_String_|_nil_] String to use for the space after the colon in JSON
|
283
|
-
*
|
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
|
287
|
-
*null, :huge places a huge number, :word places Infinity
|
288
|
-
*uses default for each mode.
|
289
|
-
* - *:hash_class* [_Class_|_nil_] Class to use instead of Hash on load,
|
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
|
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
|
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
|
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
|
300
|
-
*
|
301
|
-
*
|
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
|
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
|
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_]
|
490
|
-
*high-bit characters as escaped sequences if :ascii, :json
|
491
|
-
|
492
|
-
*
|
493
|
-
*
|
494
|
-
*
|
495
|
-
*
|
496
|
-
*
|
497
|
-
*
|
498
|
-
*
|
499
|
-
*
|
500
|
-
*
|
501
|
-
*
|
502
|
-
*
|
503
|
-
*Object
|
504
|
-
*
|
505
|
-
*
|
506
|
-
*
|
507
|
-
*
|
508
|
-
*
|
509
|
-
*
|
510
|
-
*
|
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
|
-
*
|
514
|
-
*
|
515
|
-
*
|
516
|
-
*
|
517
|
-
*
|
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
|
-
*
|
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,
|
536
|
-
*compat mode. :null places a null, :huge places a huge number, :word
|
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
|
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
|
-
|
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 =
|
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
|
-
|
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 =
|
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
|
-
|
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
|
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
|
-
|
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
|
1162
|
-
|
1187
|
+
fd = rb_w32_wopen(wide_path, O_RDONLY);
|
1188
|
+
OJ_FREE(wide_path);
|
1163
1189
|
}
|
1164
1190
|
#else
|
1165
|
-
fd
|
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
|
1266
|
+
struct _out *out;
|
1241
1267
|
struct _options *copts;
|
1242
1268
|
int argc;
|
1243
|
-
VALUE
|
1269
|
+
VALUE *argv;
|
1244
1270
|
};
|
1245
1271
|
|
1246
1272
|
static VALUE dump_body(VALUE a) {
|
@@ -1251,8 +1277,7 @@ static VALUE dump_body(VALUE a) {
|
|
1251
1277
|
if (0 == arg->out->buf) {
|
1252
1278
|
rb_raise(rb_eNoMemError, "Not enough memory.");
|
1253
1279
|
}
|
1254
|
-
rstr =
|
1255
|
-
rstr = oj_encode(rstr);
|
1280
|
+
rstr = rb_utf8_str_new_cstr(arg->out->buf);
|
1256
1281
|
|
1257
1282
|
return rstr;
|
1258
1283
|
}
|
@@ -1296,8 +1321,8 @@ static VALUE dump(int argc, VALUE *argv, VALUE self) {
|
|
1296
1321
|
|
1297
1322
|
oj_out_init(arg.out);
|
1298
1323
|
|
1299
|
-
arg.out->omit_nil
|
1300
|
-
arg.out->
|
1324
|
+
arg.out->omit_nil = copts.dump_opts.omit_nil;
|
1325
|
+
arg.out->omit_null_byte = copts.dump_opts.omit_null_byte;
|
1301
1326
|
|
1302
1327
|
return rb_ensure(dump_body, (VALUE)&arg, dump_ensure, (VALUE)&arg);
|
1303
1328
|
}
|
@@ -1309,17 +1334,16 @@ static VALUE dump(int argc, VALUE *argv, VALUE self) {
|
|
1309
1334
|
* will be called. The mode is set to :compat.
|
1310
1335
|
* - *obj* [_Object_] Object to serialize as an JSON document String
|
1311
1336
|
* - *options* [_Hash_]
|
1312
|
-
* - *:max_nesting* [_boolean_] It true nesting is limited to 100.
|
1313
|
-
*
|
1314
|
-
*
|
1315
|
-
*
|
1316
|
-
* - *:
|
1317
|
-
*
|
1318
|
-
* - *:
|
1319
|
-
* nil.
|
1337
|
+
* - *:max_nesting* [_Fixnum_|_boolean_] It true nesting is limited to 100.
|
1338
|
+
* If a Fixnum nesting is set to the provided value. The option to detect
|
1339
|
+
* circular references is available but is not compatible with the json gem.,
|
1340
|
+
* default is false or unlimited.
|
1341
|
+
* - *:allow_nan* [_boolean_] If true non JSON compliant words such as Nan and
|
1342
|
+
* Infinity will be used as appropriate, default is true.
|
1343
|
+
* - *:quirks_mode* [_boolean_] Allow single JSON values instead of documents, default is true (allow).
|
1344
|
+
* - *:indent* [_String_|_nil_] String to use for indentation, overriding the indent option if not nil.
|
1320
1345
|
* - *: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.
|
1346
|
+
* - *:space_before* [_String_|_nil_] String to use before the colon separator in JSON object fields.
|
1323
1347
|
* - *:object_nl* [_String_|_nil_] String to use after a JSON object field value.
|
1324
1348
|
* - *:array_nl* [_String_|_nil_] String to use after a JSON array value.
|
1325
1349
|
* - *:trace* [_Boolean_] If true trace is turned on.
|
@@ -1344,7 +1368,8 @@ static VALUE to_json(int argc, VALUE *argv, VALUE self) {
|
|
1344
1368
|
|
1345
1369
|
oj_out_init(&out);
|
1346
1370
|
|
1347
|
-
out.omit_nil
|
1371
|
+
out.omit_nil = copts.dump_opts.omit_nil;
|
1372
|
+
out.omit_null_byte = copts.dump_opts.omit_null_byte;
|
1348
1373
|
// For obj.to_json or generate nan is not allowed but if called from dump
|
1349
1374
|
// it is.
|
1350
1375
|
oj_dump_obj_to_json_using_params(*argv, &copts, &out, argc - 1, argv + 1);
|
@@ -1352,8 +1377,7 @@ static VALUE to_json(int argc, VALUE *argv, VALUE self) {
|
|
1352
1377
|
if (0 == out.buf) {
|
1353
1378
|
rb_raise(rb_eNoMemError, "Not enough memory.");
|
1354
1379
|
}
|
1355
|
-
rstr =
|
1356
|
-
rstr = oj_encode(rstr);
|
1380
|
+
rstr = rb_utf8_str_new_cstr(out.buf);
|
1357
1381
|
|
1358
1382
|
oj_out_free(&out);
|
1359
1383
|
|
@@ -1376,7 +1400,6 @@ static VALUE to_file(int argc, VALUE *argv, VALUE self) {
|
|
1376
1400
|
if (3 == argc) {
|
1377
1401
|
oj_parse_options(argv[2], &copts);
|
1378
1402
|
}
|
1379
|
-
Check_Type(*argv, T_STRING);
|
1380
1403
|
oj_write_obj_to_file(argv[1], StringValuePtr(*argv), &copts);
|
1381
1404
|
|
1382
1405
|
return Qnil;
|
@@ -1414,10 +1437,10 @@ static VALUE to_stream(int argc, VALUE *argv, VALUE self) {
|
|
1414
1437
|
*
|
1415
1438
|
* - *clas* [_Class__|_Module_] Class or Module to be made special
|
1416
1439
|
* - *create_object* [_Object_] object to call the create method on
|
1417
|
-
* - *create_method* [_Symbol_] method on the clas that will create a new instance
|
1418
|
-
* given all the member values in the order specified.
|
1419
|
-
* - *members* [_Symbol__|_String_] methods used to get the member values from
|
1420
|
-
* clas.
|
1440
|
+
* - *create_method* [_Symbol_] method on the clas that will create a new instance
|
1441
|
+
* of the clas when given all the member values in the order specified.
|
1442
|
+
* - *members* [_Symbol__|_String_] methods used to get the member values from
|
1443
|
+
* instances of the clas.
|
1421
1444
|
*/
|
1422
1445
|
static VALUE register_odd(int argc, VALUE *argv, VALUE self) {
|
1423
1446
|
if (3 > argc) {
|
@@ -1450,10 +1473,10 @@ static VALUE register_odd(int argc, VALUE *argv, VALUE self) {
|
|
1450
1473
|
*
|
1451
1474
|
* - *clas* [_Class_|_Module_] Class or Module to be made special
|
1452
1475
|
* - *create_object* [_Object_] object to call the create method on
|
1453
|
-
* - *create_method* [_Symbol_] method on the clas that will create a new instance
|
1454
|
-
*given all the member values in the order specified.
|
1455
|
-
* - *dump_method* [_Symbol_|_String_] method to call on the object being
|
1456
|
-
*raw JSON.
|
1476
|
+
* - *create_method* [_Symbol_] method on the clas that will create a new instance
|
1477
|
+
* of the clas when given all the member values in the order specified.
|
1478
|
+
* - *dump_method* [_Symbol_|_String_] method to call on the object being
|
1479
|
+
* serialized to generate the raw JSON.
|
1457
1480
|
*/
|
1458
1481
|
static VALUE register_odd_raw(int argc, VALUE *argv, VALUE self) {
|
1459
1482
|
if (3 > argc) {
|
@@ -1679,8 +1702,8 @@ extern VALUE oj_define_mimic_json(int argc, VALUE *argv, VALUE self);
|
|
1679
1702
|
* - *:space_before* [_String_] String placed before a : delimiter
|
1680
1703
|
* - *:object_nl* [_String_] String placed after a JSON object
|
1681
1704
|
* - *:array_nl* [_String_] String placed after a JSON array
|
1682
|
-
* - *:ascii_only* [_Boolean_] if not nil or false then use only ascii characters
|
1683
|
-
* Note JSON.generate does support this even if it is not documented.
|
1705
|
+
* - *:ascii_only* [_Boolean_] if not nil or false then use only ascii characters
|
1706
|
+
* in the output. Note JSON.generate does support this even if it is not documented.
|
1684
1707
|
*
|
1685
1708
|
* Returns [_String_]generated JSON.
|
1686
1709
|
*/
|
@@ -1718,12 +1741,15 @@ static VALUE protect_require(VALUE x) {
|
|
1718
1741
|
|
1719
1742
|
extern void print_all_odds(const char *label);
|
1720
1743
|
|
1721
|
-
static VALUE
|
1722
|
-
debug_odd(VALUE self, VALUE label) {
|
1744
|
+
static VALUE debug_odd(VALUE self, VALUE label) {
|
1723
1745
|
print_all_odds(RSTRING_PTR(label));
|
1724
1746
|
return Qnil;
|
1725
1747
|
}
|
1726
1748
|
|
1749
|
+
static VALUE mem_report(VALUE self) {
|
1750
|
+
oj_mem_report();
|
1751
|
+
return Qnil;
|
1752
|
+
}
|
1727
1753
|
|
1728
1754
|
/* Document-module: Oj
|
1729
1755
|
*
|
@@ -1734,8 +1760,8 @@ debug_odd(VALUE self, VALUE label) {
|
|
1734
1760
|
* global and options to methods allow additional behavior modifications. The
|
1735
1761
|
* modes are:
|
1736
1762
|
*
|
1737
|
-
* - *:strict* mode will only allow the 7 basic JSON types to be serialized.
|
1738
|
-
* will raise an Exception.
|
1763
|
+
* - *:strict* mode will only allow the 7 basic JSON types to be serialized.
|
1764
|
+
* Any other Object will raise an Exception.
|
1739
1765
|
*
|
1740
1766
|
* - *:null* mode is similar to the :strict mode except any Object that is not
|
1741
1767
|
* one of the JSON base types is replaced by a JSON null.
|
@@ -1775,7 +1801,7 @@ void Init_oj(void) {
|
|
1775
1801
|
rb_protect(protect_require, Qnil, &err);
|
1776
1802
|
rb_require("stringio");
|
1777
1803
|
oj_utf8_encoding_index = rb_enc_find_index("UTF-8");
|
1778
|
-
oj_utf8_encoding
|
1804
|
+
oj_utf8_encoding = rb_enc_from_index(oj_utf8_encoding_index);
|
1779
1805
|
|
1780
1806
|
// rb_define_module_function(Oj, "hash_test", hash_test, 0);
|
1781
1807
|
rb_define_module_function(Oj, "debug_odd", debug_odd, 1);
|
@@ -1812,49 +1838,52 @@ void Init_oj(void) {
|
|
1812
1838
|
|
1813
1839
|
rb_define_module_function(Oj, "optimize_rails", oj_optimize_rails, 0);
|
1814
1840
|
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
1818
|
-
|
1819
|
-
|
1820
|
-
|
1821
|
-
|
1822
|
-
|
1823
|
-
|
1824
|
-
|
1825
|
-
|
1826
|
-
|
1827
|
-
|
1828
|
-
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1839
|
-
|
1840
|
-
|
1841
|
-
|
1842
|
-
|
1843
|
-
|
1844
|
-
|
1845
|
-
|
1846
|
-
|
1847
|
-
|
1848
|
-
|
1849
|
-
|
1850
|
-
|
1851
|
-
|
1852
|
-
|
1853
|
-
|
1854
|
-
|
1855
|
-
|
1856
|
-
|
1857
|
-
|
1841
|
+
rb_define_module_function(Oj, "mem_report", mem_report, 0);
|
1842
|
+
|
1843
|
+
oj_add_value_id = rb_intern("add_value");
|
1844
|
+
oj_array_append_id = rb_intern("array_append");
|
1845
|
+
oj_array_end_id = rb_intern("array_end");
|
1846
|
+
oj_array_start_id = rb_intern("array_start");
|
1847
|
+
oj_as_json_id = rb_intern("as_json");
|
1848
|
+
oj_begin_id = rb_intern("begin");
|
1849
|
+
oj_bigdecimal_id = rb_intern("BigDecimal");
|
1850
|
+
oj_end_id = rb_intern("end");
|
1851
|
+
oj_eofq_id = rb_intern("eof?");
|
1852
|
+
oj_error_id = rb_intern("error");
|
1853
|
+
oj_exclude_end_id = rb_intern("exclude_end?");
|
1854
|
+
oj_file_id = rb_intern("file?");
|
1855
|
+
oj_fileno_id = rb_intern("fileno");
|
1856
|
+
oj_ftype_id = rb_intern("ftype");
|
1857
|
+
oj_hash_end_id = rb_intern("hash_end");
|
1858
|
+
oj_hash_key_id = rb_intern("hash_key");
|
1859
|
+
oj_hash_set_id = rb_intern("hash_set");
|
1860
|
+
oj_hash_start_id = rb_intern("hash_start");
|
1861
|
+
oj_iconv_id = rb_intern("iconv");
|
1862
|
+
oj_json_create_id = rb_intern("json_create");
|
1863
|
+
oj_length_id = rb_intern("length");
|
1864
|
+
oj_new_id = rb_intern("new");
|
1865
|
+
oj_parse_id = rb_intern("parse");
|
1866
|
+
oj_plus_id = rb_intern("+");
|
1867
|
+
oj_pos_id = rb_intern("pos");
|
1868
|
+
oj_raw_json_id = rb_intern("raw_json");
|
1869
|
+
oj_read_id = rb_intern("read");
|
1870
|
+
oj_readpartial_id = rb_intern("readpartial");
|
1871
|
+
oj_replace_id = rb_intern("replace");
|
1872
|
+
oj_stat_id = rb_intern("stat");
|
1873
|
+
oj_string_id = rb_intern("string");
|
1874
|
+
oj_to_h_id = rb_intern("to_h");
|
1875
|
+
oj_to_hash_id = rb_intern("to_hash");
|
1876
|
+
oj_to_json_id = rb_intern("to_json");
|
1877
|
+
oj_to_s_id = rb_intern("to_s");
|
1878
|
+
oj_to_sym_id = rb_intern("to_sym");
|
1879
|
+
oj_to_time_id = rb_intern("to_time");
|
1880
|
+
oj_tv_nsec_id = rb_intern("tv_nsec");
|
1881
|
+
oj_tv_sec_id = rb_intern("tv_sec");
|
1882
|
+
oj_tv_usec_id = rb_intern("tv_usec");
|
1883
|
+
oj_utc_id = rb_intern("utc");
|
1884
|
+
oj_utc_offset_id = rb_intern("utc_offset");
|
1885
|
+
oj_utcq_id = rb_intern("utc?");
|
1886
|
+
oj_write_id = rb_intern("write");
|
1858
1887
|
|
1859
1888
|
rb_require("oj/bag");
|
1860
1889
|
rb_require("oj/error");
|
@@ -1925,6 +1954,8 @@ void Init_oj(void) {
|
|
1925
1954
|
rb_gc_register_address(&integer_range_sym);
|
1926
1955
|
fast_sym = ID2SYM(rb_intern("fast"));
|
1927
1956
|
rb_gc_register_address(&fast_sym);
|
1957
|
+
float_format_sym = ID2SYM(rb_intern("float_format"));
|
1958
|
+
rb_gc_register_address(&float_format_sym);
|
1928
1959
|
float_prec_sym = ID2SYM(rb_intern("float_precision"));
|
1929
1960
|
rb_gc_register_address(&float_prec_sym);
|
1930
1961
|
float_sym = ID2SYM(rb_intern("float"));
|
@@ -1965,14 +1996,10 @@ void Init_oj(void) {
|
|
1965
1996
|
rb_gc_register_address(&oj_decimal_class_sym);
|
1966
1997
|
oj_hash_class_sym = ID2SYM(rb_intern("hash_class"));
|
1967
1998
|
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
1999
|
oj_indent_sym = ID2SYM(rb_intern("indent"));
|
1971
2000
|
rb_gc_register_address(&oj_indent_sym);
|
1972
2001
|
oj_max_nesting_sym = ID2SYM(rb_intern("max_nesting"));
|
1973
2002
|
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
2003
|
oj_object_class_sym = ID2SYM(rb_intern("object_class"));
|
1977
2004
|
rb_gc_register_address(&oj_object_class_sym);
|
1978
2005
|
oj_object_nl_sym = ID2SYM(rb_intern("object_nl"));
|
@@ -1981,6 +2008,8 @@ void Init_oj(void) {
|
|
1981
2008
|
rb_gc_register_address(&oj_quirks_mode_sym);
|
1982
2009
|
oj_safe_sym = ID2SYM(rb_intern("safe"));
|
1983
2010
|
rb_gc_register_address(&oj_safe_sym);
|
2011
|
+
omit_null_byte_sym = ID2SYM(rb_intern("omit_null_byte"));
|
2012
|
+
rb_gc_register_address(&omit_null_byte_sym);
|
1984
2013
|
oj_space_before_sym = ID2SYM(rb_intern("space_before"));
|
1985
2014
|
rb_gc_register_address(&oj_space_before_sym);
|
1986
2015
|
oj_space_sym = ID2SYM(rb_intern("space"));
|