oj 3.11.5 → 3.16.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1421 -0
- data/README.md +19 -5
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +20 -6
- data/ext/oj/cache.c +329 -0
- data/ext/oj/cache.h +22 -0
- data/ext/oj/cache8.c +10 -9
- data/ext/oj/circarray.c +8 -6
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +19 -33
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +27 -77
- data/ext/oj/custom.c +86 -179
- data/ext/oj/debug.c +126 -0
- data/ext/oj/dump.c +256 -249
- data/ext/oj/dump.h +26 -12
- data/ext/oj/dump_compat.c +565 -642
- data/ext/oj/dump_leaf.c +17 -63
- data/ext/oj/dump_object.c +65 -187
- data/ext/oj/dump_strict.c +27 -51
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +2 -13
- data/ext/oj/err.h +24 -8
- data/ext/oj/extconf.rb +21 -6
- data/ext/oj/fast.c +149 -149
- data/ext/oj/intern.c +313 -0
- data/ext/oj/intern.h +22 -0
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +121 -106
- data/ext/oj/object.c +85 -162
- data/ext/oj/odd.c +89 -67
- data/ext/oj/odd.h +15 -15
- data/ext/oj/oj.c +542 -411
- data/ext/oj/oj.h +99 -73
- data/ext/oj/parse.c +175 -187
- data/ext/oj/parse.h +26 -24
- data/ext/oj/parser.c +1600 -0
- data/ext/oj/parser.h +101 -0
- data/ext/oj/rails.c +112 -159
- data/ext/oj/rails.h +1 -1
- data/ext/oj/reader.c +11 -14
- data/ext/oj/reader.h +4 -2
- data/ext/oj/resolve.c +5 -24
- data/ext/oj/rxclass.c +7 -6
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +22 -33
- data/ext/oj/saj2.c +584 -0
- data/ext/oj/saj2.h +23 -0
- data/ext/oj/scp.c +5 -28
- data/ext/oj/sparse.c +28 -72
- data/ext/oj/stream_writer.c +50 -40
- data/ext/oj/strict.c +56 -61
- data/ext/oj/string_writer.c +72 -39
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +1218 -0
- data/ext/oj/usual.h +69 -0
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +14 -3
- data/ext/oj/val_stack.h +8 -7
- data/ext/oj/validate.c +46 -0
- data/ext/oj/wab.c +63 -88
- 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 +1 -2
- data/lib/oj/json.rb +162 -150
- data/lib/oj/mimic.rb +9 -7
- data/lib/oj/saj.rb +20 -6
- data/lib/oj/schandler.rb +5 -4
- data/lib/oj/state.rb +12 -8
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +2 -0
- data/pages/Compatibility.md +1 -1
- data/pages/InstallOptions.md +20 -0
- data/pages/JsonGem.md +15 -0
- data/pages/Modes.md +8 -3
- data/pages/Options.md +43 -5
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +14 -2
- data/test/_test_active.rb +8 -9
- data/test/_test_active_mimic.rb +7 -8
- data/test/_test_mimic_rails.rb +17 -20
- data/test/activerecord/result_test.rb +5 -6
- data/test/activesupport6/encoding_test.rb +63 -28
- data/test/{activesupport5 → activesupport7}/abstract_unit.rb +16 -12
- data/test/{activesupport5 → activesupport7}/decoding_test.rb +2 -10
- data/test/{activesupport5 → activesupport7}/encoding_test.rb +86 -50
- data/test/{activesupport5 → activesupport7}/encoding_test_cases.rb +6 -0
- data/test/{activesupport5 → activesupport7}/time_zone_test_helpers.rb +8 -0
- data/test/files.rb +15 -15
- data/test/foo.rb +16 -45
- data/test/helper.rb +11 -8
- data/test/isolated/shared.rb +3 -2
- data/test/json_gem/json_addition_test.rb +2 -2
- data/test/json_gem/json_common_interface_test.rb +8 -6
- data/test/json_gem/json_encoding_test.rb +0 -0
- data/test/json_gem/json_ext_parser_test.rb +1 -0
- data/test/json_gem/json_fixtures_test.rb +3 -2
- data/test/json_gem/json_generator_test.rb +56 -38
- data/test/json_gem/json_generic_object_test.rb +11 -11
- data/test/json_gem/json_parser_test.rb +54 -47
- data/test/json_gem/json_string_matching_test.rb +9 -9
- data/test/json_gem/test_helper.rb +7 -3
- data/test/mem.rb +34 -0
- data/test/perf.rb +22 -27
- data/test/perf_compat.rb +31 -33
- data/test/perf_dump.rb +50 -0
- data/test/perf_fast.rb +80 -82
- data/test/perf_file.rb +27 -29
- data/test/perf_object.rb +65 -69
- data/test/perf_once.rb +59 -0
- data/test/perf_parser.rb +183 -0
- data/test/perf_saj.rb +46 -54
- data/test/perf_scp.rb +58 -69
- data/test/perf_simple.rb +41 -39
- data/test/perf_strict.rb +74 -82
- data/test/perf_wab.rb +67 -69
- data/test/prec.rb +5 -5
- data/test/sample/change.rb +0 -1
- data/test/sample/dir.rb +0 -1
- data/test/sample/doc.rb +0 -1
- data/test/sample/file.rb +0 -1
- data/test/sample/group.rb +0 -1
- data/test/sample/hasprops.rb +0 -1
- data/test/sample/layer.rb +0 -1
- data/test/sample/rect.rb +0 -1
- data/test/sample/shape.rb +0 -1
- data/test/sample/text.rb +0 -1
- data/test/sample.rb +16 -16
- data/test/sample_json.rb +8 -8
- data/test/test_compat.rb +95 -43
- data/test/test_custom.rb +73 -51
- data/test/test_debian.rb +7 -10
- data/test/test_fast.rb +135 -79
- data/test/test_file.rb +41 -30
- data/test/test_gc.rb +16 -5
- data/test/test_generate.rb +5 -5
- data/test/test_hash.rb +5 -5
- data/test/test_integer_range.rb +9 -9
- data/test/test_null.rb +20 -20
- data/test/test_object.rb +99 -96
- data/test/test_parser.rb +11 -0
- data/test/test_parser_debug.rb +27 -0
- data/test/test_parser_saj.rb +337 -0
- data/test/test_parser_usual.rb +251 -0
- data/test/test_rails.rb +2 -2
- data/test/test_saj.rb +10 -8
- data/test/test_scp.rb +37 -39
- data/test/test_strict.rb +40 -32
- data/test/test_various.rb +165 -84
- data/test/test_wab.rb +48 -44
- data/test/test_writer.rb +47 -47
- data/test/tests.rb +13 -5
- data/test/tests_mimic.rb +12 -3
- data/test/tests_mimic_addition.rb +12 -3
- metadata +74 -128
- data/ext/oj/hash.c +0 -131
- data/ext/oj/hash.h +0 -19
- data/ext/oj/hash_test.c +0 -491
- 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/test_helper.rb +0 -72
- data/test/bar.rb +0 -35
- data/test/baz.rb +0 -16
- data/test/zoo.rb +0 -13
data/ext/oj/mimic_json.c
CHANGED
@@ -3,11 +3,10 @@
|
|
3
3
|
|
4
4
|
#include "dump.h"
|
5
5
|
#include "encode.h"
|
6
|
+
#include "mem.h"
|
6
7
|
#include "oj.h"
|
7
8
|
#include "parse.h"
|
8
9
|
|
9
|
-
static VALUE symbolize_names_sym = Qundef;
|
10
|
-
|
11
10
|
extern const char oj_json_class[];
|
12
11
|
|
13
12
|
VALUE oj_array_nl_sym;
|
@@ -200,7 +199,6 @@ static int mimic_limit_arg(VALUE a) {
|
|
200
199
|
* Returns [_String_] a JSON string.
|
201
200
|
*/
|
202
201
|
static VALUE mimic_dump(int argc, VALUE *argv, VALUE self) {
|
203
|
-
char buf[4096];
|
204
202
|
struct _out out;
|
205
203
|
struct _options copts = oj_default_options;
|
206
204
|
VALUE rstr;
|
@@ -208,10 +206,9 @@ static VALUE mimic_dump(int argc, VALUE *argv, VALUE self) {
|
|
208
206
|
|
209
207
|
copts.str_rx.head = NULL;
|
210
208
|
copts.str_rx.tail = NULL;
|
211
|
-
|
212
|
-
out
|
213
|
-
|
214
|
-
out.caller = CALLER_DUMP;
|
209
|
+
|
210
|
+
oj_out_init(&out);
|
211
|
+
|
215
212
|
copts.escape_mode = JXEsc;
|
216
213
|
copts.mode = CompatMode;
|
217
214
|
|
@@ -259,9 +256,9 @@ static VALUE mimic_dump(int argc, VALUE *argv, VALUE self) {
|
|
259
256
|
rb_funcall2(io, oj_write_id, 1, args);
|
260
257
|
rstr = io;
|
261
258
|
}
|
262
|
-
|
263
|
-
|
264
|
-
|
259
|
+
|
260
|
+
oj_out_free(&out);
|
261
|
+
|
265
262
|
return rstr;
|
266
263
|
}
|
267
264
|
|
@@ -274,7 +271,7 @@ static int mimic_walk(VALUE key, VALUE obj, VALUE proc) {
|
|
274
271
|
size_t i;
|
275
272
|
|
276
273
|
for (i = 0; i < cnt; i++) {
|
277
|
-
mimic_walk(Qnil,
|
274
|
+
mimic_walk(Qnil, RARRAY_AREF(obj, i), proc);
|
278
275
|
}
|
279
276
|
break;
|
280
277
|
}
|
@@ -351,26 +348,25 @@ static VALUE mimic_load(int argc, VALUE *argv, VALUE self) {
|
|
351
348
|
static VALUE mimic_dump_load(int argc, VALUE *argv, VALUE self) {
|
352
349
|
if (1 > argc) {
|
353
350
|
rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)");
|
354
|
-
}
|
351
|
+
}
|
352
|
+
if (T_STRING == rb_type(*argv)) {
|
355
353
|
return mimic_load(argc, argv, self);
|
356
|
-
} else {
|
357
|
-
return mimic_dump(argc, argv, self);
|
358
354
|
}
|
359
|
-
return
|
355
|
+
return mimic_dump(argc, argv, self);
|
360
356
|
}
|
361
357
|
|
362
358
|
static VALUE mimic_generate_core(int argc, VALUE *argv, Options copts) {
|
363
|
-
char buf[4096];
|
364
359
|
struct _out out;
|
365
360
|
VALUE rstr;
|
366
361
|
|
367
|
-
|
362
|
+
if (0 == argc) {
|
363
|
+
rb_raise(rb_eArgError, "wrong number of arguments (0))");
|
364
|
+
}
|
365
|
+
memset(out.stack_buffer, 0, sizeof(out.stack_buffer));
|
366
|
+
|
367
|
+
oj_out_init(&out);
|
368
368
|
|
369
|
-
out.
|
370
|
-
out.end = buf + sizeof(buf) - 10;
|
371
|
-
out.allocated = false;
|
372
|
-
out.omit_nil = copts->dump_opts.omit_nil;
|
373
|
-
out.caller = CALLER_GENERATE;
|
369
|
+
out.omit_nil = copts->dump_opts.omit_nil;
|
374
370
|
// For obj.to_json or generate nan is not allowed but if called from dump
|
375
371
|
// it is.
|
376
372
|
copts->dump_opts.nan_dump = RaiseNan;
|
@@ -389,9 +385,11 @@ static VALUE mimic_generate_core(int argc, VALUE *argv, Options copts) {
|
|
389
385
|
} else {
|
390
386
|
VALUE active_hack[1];
|
391
387
|
|
392
|
-
|
393
|
-
|
394
|
-
|
388
|
+
if (Qundef == state_class) {
|
389
|
+
rb_warn("Oj::Rails.mimic_JSON was called implicitly. "
|
390
|
+
"Call it explicitly beforehand if you want to remove this warning.");
|
391
|
+
oj_define_mimic_json(0, NULL, Qnil);
|
392
|
+
}
|
395
393
|
active_hack[0] = rb_funcall(state_class, oj_new_id, 0);
|
396
394
|
oj_dump_obj_to_json_using_params(*argv, copts, &out, 1, active_hack);
|
397
395
|
}
|
@@ -400,9 +398,9 @@ static VALUE mimic_generate_core(int argc, VALUE *argv, Options copts) {
|
|
400
398
|
}
|
401
399
|
rstr = rb_str_new2(out.buf);
|
402
400
|
rstr = oj_encode(rstr);
|
403
|
-
|
404
|
-
|
405
|
-
|
401
|
+
|
402
|
+
oj_out_free(&out);
|
403
|
+
|
406
404
|
return rstr;
|
407
405
|
}
|
408
406
|
|
@@ -427,7 +425,7 @@ static VALUE mimic_generate_core(int argc, VALUE *argv, Options copts) {
|
|
427
425
|
* - *:object_nl* [_String_] String placed after a JSON object
|
428
426
|
* - *:array_nl* [_String_] String placed after a JSON array
|
429
427
|
* - *:ascii_only* [_Boolean_] if not nil or false then use only ascii characters in the output.
|
430
|
-
*
|
428
|
+
* Note JSON.generate does support this even if it is not documented.
|
431
429
|
*
|
432
430
|
* Returns [_String_] generated JSON.
|
433
431
|
*/
|
@@ -459,28 +457,33 @@ oj_mimic_pretty_generate(int argc, VALUE *argv, VALUE self) {
|
|
459
457
|
// a Hash. I haven't dug deep enough to find out why but using a State
|
460
458
|
// instance and not a Hash gives the desired behavior.
|
461
459
|
*rargs = *argv;
|
462
|
-
if (
|
460
|
+
if (0 == argc) {
|
461
|
+
rb_raise(rb_eArgError, "wrong number of arguments (0))");
|
462
|
+
}
|
463
|
+
if (1 == argc || Qnil == argv[1]) {
|
463
464
|
h = rb_hash_new();
|
464
465
|
} else {
|
465
466
|
h = argv[1];
|
466
467
|
}
|
467
|
-
if (
|
468
|
+
if (!oj_hash_has_key(h, oj_indent_sym)) {
|
468
469
|
rb_hash_aset(h, oj_indent_sym, rb_str_new2(" "));
|
469
470
|
}
|
470
|
-
if (
|
471
|
+
if (!oj_hash_has_key(h, oj_space_before_sym)) {
|
471
472
|
rb_hash_aset(h, oj_space_before_sym, rb_str_new2(""));
|
472
473
|
}
|
473
|
-
if (
|
474
|
+
if (!oj_hash_has_key(h, oj_space_sym)) {
|
474
475
|
rb_hash_aset(h, oj_space_sym, rb_str_new2(" "));
|
475
476
|
}
|
476
|
-
if (
|
477
|
+
if (!oj_hash_has_key(h, oj_object_nl_sym)) {
|
477
478
|
rb_hash_aset(h, oj_object_nl_sym, rb_str_new2("\n"));
|
478
479
|
}
|
479
|
-
if (
|
480
|
+
if (!oj_hash_has_key(h, oj_array_nl_sym)) {
|
480
481
|
rb_hash_aset(h, oj_array_nl_sym, rb_str_new2("\n"));
|
481
482
|
}
|
482
483
|
if (Qundef == state_class) {
|
483
|
-
|
484
|
+
rb_warn("Oj::Rails.mimic_JSON was called implicitly. "
|
485
|
+
"Call it explicitly beforehand if you want to remove this warning.");
|
486
|
+
oj_define_mimic_json(0, NULL, Qnil);
|
484
487
|
}
|
485
488
|
rargs[1] = rb_funcall(state_class, oj_new_id, 1, h);
|
486
489
|
|
@@ -501,6 +504,44 @@ oj_mimic_pretty_generate(int argc, VALUE *argv, VALUE self) {
|
|
501
504
|
return mimic_generate_core(2, rargs, &copts);
|
502
505
|
}
|
503
506
|
|
507
|
+
static int parse_options_cb(VALUE k, VALUE v, VALUE info) {
|
508
|
+
struct _parseInfo *pi = (struct _parseInfo *)info;
|
509
|
+
|
510
|
+
if (oj_symbolize_names_sym == k) {
|
511
|
+
pi->options.sym_key = (Qtrue == v) ? Yes : No;
|
512
|
+
} else if (oj_quirks_mode_sym == k) {
|
513
|
+
pi->options.quirks_mode = (Qtrue == v) ? Yes : No;
|
514
|
+
} else if (oj_create_additions_sym == k) {
|
515
|
+
pi->options.create_ok = (Qtrue == v) ? Yes : No;
|
516
|
+
} else if (oj_allow_nan_sym == k) {
|
517
|
+
pi->options.allow_nan = (Qtrue == v) ? Yes : No;
|
518
|
+
} else if (oj_hash_class_sym == k) {
|
519
|
+
if (Qnil == v) {
|
520
|
+
pi->options.hash_class = Qnil;
|
521
|
+
} else {
|
522
|
+
rb_check_type(v, T_CLASS);
|
523
|
+
pi->options.hash_class = v;
|
524
|
+
}
|
525
|
+
} else if (oj_object_class_sym == k) {
|
526
|
+
if (Qnil == v) {
|
527
|
+
pi->options.hash_class = Qnil;
|
528
|
+
} else {
|
529
|
+
rb_check_type(v, T_CLASS);
|
530
|
+
pi->options.hash_class = v;
|
531
|
+
}
|
532
|
+
} else if (oj_array_class_sym == k) {
|
533
|
+
if (Qnil == v) {
|
534
|
+
pi->options.array_class = Qnil;
|
535
|
+
} else {
|
536
|
+
rb_check_type(v, T_CLASS);
|
537
|
+
pi->options.array_class = v;
|
538
|
+
}
|
539
|
+
} else if (oj_decimal_class_sym == k) {
|
540
|
+
pi->options.compat_bigdec = (oj_bigdecimal_class == v);
|
541
|
+
}
|
542
|
+
return ST_CONTINUE;
|
543
|
+
}
|
544
|
+
|
504
545
|
static VALUE mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
|
505
546
|
struct _parseInfo pi;
|
506
547
|
VALUE ropts;
|
@@ -516,7 +557,7 @@ static VALUE mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
|
|
516
557
|
pi.options = oj_default_options;
|
517
558
|
pi.options.auto_define = No;
|
518
559
|
pi.options.quirks_mode = Yes;
|
519
|
-
pi.options.allow_invalid =
|
560
|
+
pi.options.allow_invalid = Yes;
|
520
561
|
pi.options.empty_string = No;
|
521
562
|
pi.options.create_ok = No;
|
522
563
|
pi.options.allow_nan = (bang ? Yes : No);
|
@@ -531,51 +572,7 @@ static VALUE mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
|
|
531
572
|
if (T_HASH != rb_type(ropts)) {
|
532
573
|
rb_raise(rb_eArgError, "options must be a hash.");
|
533
574
|
}
|
534
|
-
|
535
|
-
symbolize_names_sym = ID2SYM(rb_intern("symbolize_names"));
|
536
|
-
rb_gc_register_address(&symbolize_names_sym);
|
537
|
-
}
|
538
|
-
if (Qnil != (v = rb_hash_lookup(ropts, symbolize_names_sym))) {
|
539
|
-
pi.options.sym_key = (Qtrue == v) ? Yes : No;
|
540
|
-
}
|
541
|
-
if (Qnil != (v = rb_hash_lookup(ropts, oj_quirks_mode_sym))) {
|
542
|
-
pi.options.quirks_mode = (Qtrue == v) ? Yes : No;
|
543
|
-
}
|
544
|
-
if (Qnil != (v = rb_hash_lookup(ropts, oj_create_additions_sym))) {
|
545
|
-
pi.options.create_ok = (Qtrue == v) ? Yes : No;
|
546
|
-
}
|
547
|
-
if (Qnil != (v = rb_hash_lookup(ropts, oj_allow_nan_sym))) {
|
548
|
-
pi.options.allow_nan = (Qtrue == v) ? Yes : No;
|
549
|
-
}
|
550
|
-
|
551
|
-
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_hash_class_sym)) {
|
552
|
-
if (Qnil == (v = rb_hash_lookup(ropts, oj_hash_class_sym))) {
|
553
|
-
pi.options.hash_class = Qnil;
|
554
|
-
} else {
|
555
|
-
rb_check_type(v, T_CLASS);
|
556
|
-
pi.options.hash_class = v;
|
557
|
-
}
|
558
|
-
}
|
559
|
-
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_object_class_sym)) {
|
560
|
-
if (Qnil == (v = rb_hash_lookup(ropts, oj_object_class_sym))) {
|
561
|
-
pi.options.hash_class = Qnil;
|
562
|
-
} else {
|
563
|
-
rb_check_type(v, T_CLASS);
|
564
|
-
pi.options.hash_class = v;
|
565
|
-
}
|
566
|
-
}
|
567
|
-
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_array_class_sym)) {
|
568
|
-
if (Qnil == (v = rb_hash_lookup(ropts, oj_array_class_sym))) {
|
569
|
-
pi.options.array_class = Qnil;
|
570
|
-
} else {
|
571
|
-
rb_check_type(v, T_CLASS);
|
572
|
-
pi.options.array_class = v;
|
573
|
-
}
|
574
|
-
}
|
575
|
-
if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, oj_decimal_class_sym)) {
|
576
|
-
pi.options.compat_bigdec = (oj_bigdecimal_class ==
|
577
|
-
rb_hash_lookup(ropts, oj_decimal_class_sym));
|
578
|
-
}
|
575
|
+
rb_hash_foreach(ropts, parse_options_cb, (VALUE)&pi);
|
579
576
|
v = rb_hash_lookup(ropts, oj_max_nesting_sym);
|
580
577
|
if (Qtrue == v) {
|
581
578
|
pi.max_depth = 100;
|
@@ -608,9 +605,9 @@ static VALUE mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
|
|
608
605
|
* - *source* [_String_|IO] source to parse
|
609
606
|
* - *opts* [_Hash_] options
|
610
607
|
* - *:symbolize* [Boolean] _names flag indicating JSON object keys should be Symbols instead of
|
611
|
-
*
|
608
|
+
* Strings
|
612
609
|
* - *:create_additions* [Boolean] flag indicating a key matching +create_id+ in a JSON object
|
613
|
-
*
|
610
|
+
* should trigger the creation of Ruby Object
|
614
611
|
*
|
615
612
|
* Returns [Object]
|
616
613
|
* @see create_id=
|
@@ -653,23 +650,22 @@ static VALUE mimic_recurse_proc(VALUE self, VALUE obj) {
|
|
653
650
|
*
|
654
651
|
* - *id* [_nil_|String] new create_id
|
655
652
|
*
|
656
|
-
* Returns [_String_] the id.
|
653
|
+
* Returns [_nil_|_String_] the id.
|
657
654
|
*/
|
658
655
|
static VALUE mimic_set_create_id(VALUE self, VALUE id) {
|
659
|
-
Check_Type(id, T_STRING);
|
660
|
-
|
661
656
|
if (NULL != oj_default_options.create_id) {
|
662
657
|
if (oj_json_class != oj_default_options.create_id) {
|
663
|
-
|
658
|
+
OJ_R_FREE((char *)oj_default_options.create_id);
|
664
659
|
}
|
665
660
|
oj_default_options.create_id = NULL;
|
666
661
|
oj_default_options.create_id_len = 0;
|
667
662
|
}
|
668
663
|
if (Qnil != id) {
|
669
|
-
|
664
|
+
const char *ptr = StringValueCStr(id);
|
665
|
+
size_t len = RSTRING_LEN(id) + 1;
|
670
666
|
|
671
|
-
oj_default_options.create_id =
|
672
|
-
strcpy((char *)oj_default_options.create_id,
|
667
|
+
oj_default_options.create_id = OJ_R_ALLOC_N(char, len);
|
668
|
+
strcpy((char *)oj_default_options.create_id, ptr);
|
673
669
|
oj_default_options.create_id_len = len - 1;
|
674
670
|
}
|
675
671
|
return id;
|
@@ -682,7 +678,7 @@ static VALUE mimic_set_create_id(VALUE self, VALUE id) {
|
|
682
678
|
*/
|
683
679
|
static VALUE mimic_create_id(VALUE self) {
|
684
680
|
if (NULL != oj_default_options.create_id) {
|
685
|
-
return
|
681
|
+
return rb_utf8_str_new(oj_default_options.create_id, oj_default_options.create_id_len);
|
686
682
|
}
|
687
683
|
return rb_str_new_cstr(oj_json_class);
|
688
684
|
}
|
@@ -706,13 +702,15 @@ static struct _options mimic_object_to_json_options = {0, // indent
|
|
706
702
|
No, // empty_string
|
707
703
|
Yes, // allow_gc
|
708
704
|
Yes, // quirks_mode
|
709
|
-
|
705
|
+
Yes, // allow_invalid
|
710
706
|
No, // create_ok
|
711
707
|
No, // allow_nan
|
712
708
|
No, // trace
|
713
709
|
No, // safe
|
714
710
|
false, // sec_prec_set
|
715
711
|
No, // ignore_under
|
712
|
+
Yes, // cache_keys
|
713
|
+
0, // cache_str
|
716
714
|
0, // int_range_min
|
717
715
|
0, // int_range_max
|
718
716
|
oj_json_class, // create_id
|
@@ -737,6 +735,7 @@ static struct _options mimic_object_to_json_options = {0, // indent
|
|
737
735
|
0, // array_size
|
738
736
|
RaiseNan, // nan_dump
|
739
737
|
false, // omit_nil
|
738
|
+
false, // omit_null_byte
|
740
739
|
100, // max_depth
|
741
740
|
},
|
742
741
|
{
|
@@ -747,19 +746,18 @@ static struct _options mimic_object_to_json_options = {0, // indent
|
|
747
746
|
}};
|
748
747
|
|
749
748
|
static VALUE mimic_object_to_json(int argc, VALUE *argv, VALUE self) {
|
750
|
-
char buf[4096];
|
751
749
|
struct _out out;
|
752
750
|
VALUE rstr;
|
753
751
|
struct _options copts = oj_default_options;
|
754
752
|
|
755
753
|
copts.str_rx.head = NULL;
|
756
754
|
copts.str_rx.tail = NULL;
|
757
|
-
|
758
|
-
out
|
759
|
-
|
760
|
-
out.omit_nil
|
761
|
-
copts.mode
|
762
|
-
copts.to_json
|
755
|
+
|
756
|
+
oj_out_init(&out);
|
757
|
+
|
758
|
+
out.omit_nil = copts.dump_opts.omit_nil;
|
759
|
+
copts.mode = CompatMode;
|
760
|
+
copts.to_json = No;
|
763
761
|
if (1 <= argc && Qnil != argv[0]) {
|
764
762
|
oj_parse_mimic_dump_options(argv[0], &copts);
|
765
763
|
}
|
@@ -772,9 +770,9 @@ static VALUE mimic_object_to_json(int argc, VALUE *argv, VALUE self) {
|
|
772
770
|
}
|
773
771
|
rstr = rb_str_new2(out.buf);
|
774
772
|
rstr = oj_encode(rstr);
|
775
|
-
|
776
|
-
|
777
|
-
|
773
|
+
|
774
|
+
oj_out_free(&out);
|
775
|
+
|
778
776
|
return rstr;
|
779
777
|
}
|
780
778
|
|
@@ -791,28 +789,48 @@ void oj_mimic_json_methods(VALUE json) {
|
|
791
789
|
VALUE json_error;
|
792
790
|
VALUE generator;
|
793
791
|
VALUE ext;
|
792
|
+
VALUE verbose;
|
793
|
+
|
794
|
+
// rb_undef_method doesn't work for modules or maybe sometimes
|
795
|
+
// doesn't. Anyway setting verbose should hide the warning.
|
796
|
+
verbose = rb_gv_get("$VERBOSE");
|
797
|
+
rb_gv_set("$VERBOSE", Qfalse);
|
794
798
|
|
799
|
+
rb_undef_method(json, "create_id=");
|
795
800
|
rb_define_module_function(json, "create_id=", mimic_set_create_id, 1);
|
801
|
+
rb_undef_method(json, "create_id");
|
796
802
|
rb_define_module_function(json, "create_id", mimic_create_id, 0);
|
797
803
|
|
804
|
+
rb_undef_method(json, "dump");
|
798
805
|
rb_define_module_function(json, "dump", mimic_dump, -1);
|
806
|
+
rb_undef_method(json, "load");
|
799
807
|
rb_define_module_function(json, "load", mimic_load, -1);
|
800
808
|
rb_define_module_function(json, "restore", mimic_load, -1);
|
809
|
+
rb_undef_method(json, "recurse_proc");
|
801
810
|
rb_define_module_function(json, "recurse_proc", mimic_recurse_proc, 1);
|
811
|
+
rb_undef_method(json, "[]");
|
802
812
|
rb_define_module_function(json, "[]", mimic_dump_load, -1);
|
803
813
|
|
814
|
+
rb_undef_method(json, "generate");
|
804
815
|
rb_define_module_function(json, "generate", oj_mimic_generate, -1);
|
816
|
+
rb_undef_method(json, "fast_generate");
|
805
817
|
rb_define_module_function(json, "fast_generate", oj_mimic_generate, -1);
|
818
|
+
rb_undef_method(json, "pretty_generate");
|
806
819
|
rb_define_module_function(json, "pretty_generate", oj_mimic_pretty_generate, -1);
|
807
820
|
// For older versions of JSON, the deprecated unparse methods.
|
821
|
+
rb_undef_method(json, "unparse");
|
808
822
|
rb_define_module_function(json, "unparse", oj_mimic_generate, -1);
|
809
823
|
rb_define_module_function(json, "fast_unparse", oj_mimic_generate, -1);
|
810
824
|
rb_define_module_function(json, "pretty_unparse", oj_mimic_pretty_generate, -1);
|
811
825
|
|
826
|
+
rb_undef_method(json, "parse");
|
812
827
|
rb_define_module_function(json, "parse", oj_mimic_parse, -1);
|
828
|
+
rb_undef_method(json, "parse!");
|
813
829
|
rb_define_module_function(json, "parse!", mimic_parse_bang, -1);
|
814
830
|
|
831
|
+
rb_undef_method(json, "state");
|
815
832
|
rb_define_module_function(json, "state", mimic_state, 0);
|
833
|
+
rb_gv_set("$VERBOSE", verbose);
|
816
834
|
|
817
835
|
if (rb_const_defined_at(json, rb_intern("JSONError"))) {
|
818
836
|
json_error = rb_const_get(json, rb_intern("JSONError"));
|
@@ -851,9 +869,6 @@ void oj_mimic_json_methods(VALUE json) {
|
|
851
869
|
// Pull in the JSON::State mimic file.
|
852
870
|
state_class = rb_const_get_at(generator, rb_intern("State"));
|
853
871
|
rb_gc_register_mark_object(state_class);
|
854
|
-
|
855
|
-
symbolize_names_sym = ID2SYM(rb_intern("symbolize_names"));
|
856
|
-
rb_gc_register_address(&symbolize_names_sym);
|
857
872
|
}
|
858
873
|
|
859
874
|
/* Document-module: JSON
|