oj 3.13.7 → 3.13.11

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.
data/ext/oj/oj.c CHANGED
@@ -94,6 +94,7 @@ VALUE oj_indent_sym;
94
94
  VALUE oj_object_class_sym;
95
95
  VALUE oj_quirks_mode_sym;
96
96
  VALUE oj_safe_sym;
97
+ VALUE oj_symbolize_names_sym;
97
98
  VALUE oj_trace_sym;
98
99
 
99
100
  static VALUE allow_blank_sym;
@@ -308,106 +309,76 @@ static VALUE get_def_opts(VALUE self) {
308
309
  rb_hash_aset(opts, sec_prec_sym, INT2FIX(oj_default_options.sec_prec));
309
310
  rb_hash_aset(opts,
310
311
  circular_sym,
311
- (Yes == oj_default_options.circular)
312
- ? Qtrue
313
- : ((No == oj_default_options.circular) ? Qfalse : Qnil));
314
- rb_hash_aset(opts,
315
- class_cache_sym,
316
- (Yes == oj_default_options.class_cache)
317
- ? Qtrue
318
- : ((No == oj_default_options.class_cache) ? Qfalse : Qnil));
319
- rb_hash_aset(opts,
320
- auto_define_sym,
321
- (Yes == oj_default_options.auto_define)
322
- ? Qtrue
323
- : ((No == oj_default_options.auto_define) ? Qfalse : Qnil));
312
+ (Yes == oj_default_options.circular) ? Qtrue : ((No == oj_default_options.circular) ? Qfalse : Qnil));
313
+ rb_hash_aset(
314
+ opts,
315
+ class_cache_sym,
316
+ (Yes == oj_default_options.class_cache) ? Qtrue : ((No == oj_default_options.class_cache) ? Qfalse : Qnil));
317
+ rb_hash_aset(
318
+ opts,
319
+ auto_define_sym,
320
+ (Yes == oj_default_options.auto_define) ? Qtrue : ((No == oj_default_options.auto_define) ? Qfalse : Qnil));
324
321
  rb_hash_aset(opts,
325
322
  symbol_keys_sym,
326
- (Yes == oj_default_options.sym_key)
327
- ? Qtrue
328
- : ((No == oj_default_options.sym_key) ? Qfalse : Qnil));
329
- rb_hash_aset(opts,
330
- bigdecimal_as_decimal_sym,
331
- (Yes == oj_default_options.bigdec_as_num)
332
- ? Qtrue
333
- : ((No == oj_default_options.bigdec_as_num) ? Qfalse : Qnil));
334
- rb_hash_aset(opts,
335
- oj_create_additions_sym,
336
- (Yes == oj_default_options.create_ok)
337
- ? Qtrue
338
- : ((No == oj_default_options.create_ok) ? Qfalse : Qnil));
323
+ (Yes == oj_default_options.sym_key) ? Qtrue : ((No == oj_default_options.sym_key) ? Qfalse : Qnil));
324
+ rb_hash_aset(
325
+ opts,
326
+ bigdecimal_as_decimal_sym,
327
+ (Yes == oj_default_options.bigdec_as_num) ? Qtrue : ((No == oj_default_options.bigdec_as_num) ? Qfalse : Qnil));
328
+ rb_hash_aset(
329
+ opts,
330
+ oj_create_additions_sym,
331
+ (Yes == oj_default_options.create_ok) ? Qtrue : ((No == oj_default_options.create_ok) ? Qfalse : Qnil));
339
332
  rb_hash_aset(opts,
340
333
  use_to_json_sym,
341
- (Yes == oj_default_options.to_json)
342
- ? Qtrue
343
- : ((No == oj_default_options.to_json) ? Qfalse : Qnil));
334
+ (Yes == oj_default_options.to_json) ? Qtrue : ((No == oj_default_options.to_json) ? Qfalse : Qnil));
344
335
  rb_hash_aset(opts,
345
336
  use_to_hash_sym,
346
- (Yes == oj_default_options.to_hash)
347
- ? Qtrue
348
- : ((No == oj_default_options.to_hash) ? Qfalse : Qnil));
337
+ (Yes == oj_default_options.to_hash) ? Qtrue : ((No == oj_default_options.to_hash) ? Qfalse : Qnil));
349
338
  rb_hash_aset(opts,
350
339
  use_as_json_sym,
351
- (Yes == oj_default_options.as_json)
352
- ? Qtrue
353
- : ((No == oj_default_options.as_json) ? Qfalse : Qnil));
340
+ (Yes == oj_default_options.as_json) ? Qtrue : ((No == oj_default_options.as_json) ? Qfalse : Qnil));
354
341
  rb_hash_aset(opts,
355
342
  use_raw_json_sym,
356
- (Yes == oj_default_options.raw_json)
357
- ? Qtrue
358
- : ((No == oj_default_options.raw_json) ? Qfalse : Qnil));
343
+ (Yes == oj_default_options.raw_json) ? Qtrue : ((No == oj_default_options.raw_json) ? Qfalse : Qnil));
359
344
  rb_hash_aset(opts,
360
345
  nilnil_sym,
361
- (Yes == oj_default_options.nilnil)
362
- ? Qtrue
363
- : ((No == oj_default_options.nilnil) ? Qfalse : Qnil));
364
- rb_hash_aset(opts,
365
- empty_string_sym,
366
- (Yes == oj_default_options.empty_string)
367
- ? Qtrue
368
- : ((No == oj_default_options.empty_string) ? Qfalse : Qnil));
346
+ (Yes == oj_default_options.nilnil) ? Qtrue : ((No == oj_default_options.nilnil) ? Qfalse : Qnil));
347
+ rb_hash_aset(
348
+ opts,
349
+ empty_string_sym,
350
+ (Yes == oj_default_options.empty_string) ? Qtrue : ((No == oj_default_options.empty_string) ? Qfalse : Qnil));
369
351
  rb_hash_aset(opts,
370
352
  allow_gc_sym,
371
- (Yes == oj_default_options.allow_gc)
372
- ? Qtrue
373
- : ((No == oj_default_options.allow_gc) ? Qfalse : Qnil));
374
- rb_hash_aset(opts,
375
- oj_quirks_mode_sym,
376
- (Yes == oj_default_options.quirks_mode)
377
- ? Qtrue
378
- : ((No == oj_default_options.quirks_mode) ? Qfalse : Qnil));
379
- rb_hash_aset(opts,
380
- allow_invalid_unicode_sym,
381
- (Yes == oj_default_options.allow_invalid)
382
- ? Qtrue
383
- : ((No == oj_default_options.allow_invalid) ? Qfalse : Qnil));
384
- rb_hash_aset(opts,
385
- oj_allow_nan_sym,
386
- (Yes == oj_default_options.allow_nan)
387
- ? Qtrue
388
- : ((No == oj_default_options.allow_nan) ? Qfalse : Qnil));
353
+ (Yes == oj_default_options.allow_gc) ? Qtrue : ((No == oj_default_options.allow_gc) ? Qfalse : Qnil));
354
+ rb_hash_aset(
355
+ opts,
356
+ oj_quirks_mode_sym,
357
+ (Yes == oj_default_options.quirks_mode) ? Qtrue : ((No == oj_default_options.quirks_mode) ? Qfalse : Qnil));
358
+ rb_hash_aset(
359
+ opts,
360
+ allow_invalid_unicode_sym,
361
+ (Yes == oj_default_options.allow_invalid) ? Qtrue : ((No == oj_default_options.allow_invalid) ? Qfalse : Qnil));
362
+ rb_hash_aset(
363
+ opts,
364
+ oj_allow_nan_sym,
365
+ (Yes == oj_default_options.allow_nan) ? Qtrue : ((No == oj_default_options.allow_nan) ? Qfalse : Qnil));
389
366
  rb_hash_aset(opts,
390
367
  oj_trace_sym,
391
- (Yes == oj_default_options.trace)
392
- ? Qtrue
393
- : ((No == oj_default_options.trace) ? Qfalse : Qnil));
368
+ (Yes == oj_default_options.trace) ? Qtrue : ((No == oj_default_options.trace) ? Qfalse : Qnil));
394
369
  rb_hash_aset(opts,
395
370
  oj_safe_sym,
396
- (Yes == oj_default_options.safe)
397
- ? Qtrue
398
- : ((No == oj_default_options.safe) ? Qfalse : Qnil));
371
+ (Yes == oj_default_options.safe) ? Qtrue : ((No == oj_default_options.safe) ? Qfalse : Qnil));
399
372
  rb_hash_aset(opts, float_prec_sym, INT2FIX(oj_default_options.float_prec));
400
373
  rb_hash_aset(opts, cache_str_sym, INT2FIX(oj_default_options.cache_str));
401
- rb_hash_aset(opts,
402
- ignore_under_sym,
403
- (Yes == oj_default_options.ignore_under)
404
- ? Qtrue
405
- : ((No == oj_default_options.ignore_under) ? Qfalse : Qnil));
406
- rb_hash_aset(opts,
407
- cache_keys_sym,
408
- (Yes == oj_default_options.cache_keys)
409
- ? Qtrue
410
- : ((No == oj_default_options.cache_keys) ? Qfalse : Qnil));
374
+ rb_hash_aset(
375
+ opts,
376
+ ignore_under_sym,
377
+ (Yes == oj_default_options.ignore_under) ? Qtrue : ((No == oj_default_options.ignore_under) ? Qfalse : Qnil));
378
+ rb_hash_aset(
379
+ opts,
380
+ cache_keys_sym,
381
+ (Yes == oj_default_options.cache_keys) ? Qtrue : ((No == oj_default_options.cache_keys) ? Qfalse : Qnil));
411
382
  switch (oj_default_options.mode) {
412
383
  case StrictMode: rb_hash_aset(opts, mode_sym, strict_sym); break;
413
384
  case CompatMode: rb_hash_aset(opts, mode_sym, compat_sym); break;
@@ -453,30 +424,25 @@ static VALUE get_def_opts(VALUE self) {
453
424
  default: rb_hash_aset(opts, bigdecimal_load_sym, auto_sym); break;
454
425
  }
455
426
  rb_hash_aset(opts, compat_bigdecimal_sym, oj_default_options.compat_bigdec ? Qtrue : Qfalse);
427
+ rb_hash_aset(opts,
428
+ create_id_sym,
429
+ (NULL == oj_default_options.create_id) ? Qnil : rb_str_new2(oj_default_options.create_id));
456
430
  rb_hash_aset(
457
431
  opts,
458
- create_id_sym,
459
- (NULL == oj_default_options.create_id) ? Qnil : rb_str_new2(oj_default_options.create_id));
460
- rb_hash_aset(opts,
461
- oj_space_sym,
462
- (0 == oj_default_options.dump_opts.after_size)
463
- ? Qnil
464
- : rb_str_new2(oj_default_options.dump_opts.after_sep));
465
- rb_hash_aset(opts,
466
- oj_space_before_sym,
467
- (0 == oj_default_options.dump_opts.before_size)
468
- ? Qnil
469
- : rb_str_new2(oj_default_options.dump_opts.before_sep));
470
- rb_hash_aset(opts,
471
- oj_object_nl_sym,
472
- (0 == oj_default_options.dump_opts.hash_size)
473
- ? Qnil
474
- : rb_str_new2(oj_default_options.dump_opts.hash_nl));
475
- rb_hash_aset(opts,
476
- oj_array_nl_sym,
477
- (0 == oj_default_options.dump_opts.array_size)
478
- ? Qnil
479
- : rb_str_new2(oj_default_options.dump_opts.array_nl));
432
+ oj_space_sym,
433
+ (0 == oj_default_options.dump_opts.after_size) ? Qnil : rb_str_new2(oj_default_options.dump_opts.after_sep));
434
+ rb_hash_aset(
435
+ opts,
436
+ oj_space_before_sym,
437
+ (0 == oj_default_options.dump_opts.before_size) ? Qnil : rb_str_new2(oj_default_options.dump_opts.before_sep));
438
+ rb_hash_aset(
439
+ opts,
440
+ oj_object_nl_sym,
441
+ (0 == oj_default_options.dump_opts.hash_size) ? Qnil : rb_str_new2(oj_default_options.dump_opts.hash_nl));
442
+ rb_hash_aset(
443
+ opts,
444
+ oj_array_nl_sym,
445
+ (0 == oj_default_options.dump_opts.array_size) ? Qnil : rb_str_new2(oj_default_options.dump_opts.array_nl));
480
446
 
481
447
  switch (oj_default_options.dump_opts.nan_dump) {
482
448
  case NullNan: rb_hash_aset(opts, nan_sym, null_sym); break;
@@ -584,16 +550,14 @@ static VALUE set_def_opts(VALUE self, VALUE opts) {
584
550
  return Qnil;
585
551
  }
586
552
 
587
- bool oj_hash_has_key(VALUE hash, VALUE key)
588
- {
553
+ bool oj_hash_has_key(VALUE hash, VALUE key) {
589
554
  if (Qundef == rb_hash_lookup2(hash, key, Qundef)) {
590
555
  return false;
591
556
  }
592
557
  return true;
593
558
  }
594
559
 
595
- bool set_yesno_options(VALUE key, VALUE value, Options copts)
596
- {
560
+ bool set_yesno_options(VALUE key, VALUE value, Options copts) {
597
561
  struct _yesNoOpt ynos[] = {{circular_sym, &copts->circular},
598
562
  {auto_define_sym, &copts->auto_define},
599
563
  {symbol_keys_sym, &copts->sym_key},
@@ -616,29 +580,26 @@ bool set_yesno_options(VALUE key, VALUE value, Options copts)
616
580
  {oj_create_additions_sym, &copts->create_ok},
617
581
  {cache_keys_sym, &copts->cache_keys},
618
582
  {Qnil, 0}};
619
- YesNoOpt o;
620
-
621
- for (o = ynos; 0 != o->attr; o++) {
622
- if (key == o->sym) {
623
- if (Qnil == value) {
624
- *o->attr = NotSet;
625
- } else if (Qtrue == value) {
626
- *o->attr = Yes;
627
- } else if (Qfalse == value) {
628
- *o->attr = No;
629
- } else {
630
- rb_raise(rb_eArgError,
631
- "%s must be true, false, or nil.",
632
- rb_id2name(key));
633
- }
634
- return true;
635
- }
636
- }
583
+ YesNoOpt o;
584
+
585
+ for (o = ynos; 0 != o->attr; o++) {
586
+ if (key == o->sym) {
587
+ if (Qnil == value) {
588
+ *o->attr = NotSet;
589
+ } else if (Qtrue == value) {
590
+ *o->attr = Yes;
591
+ } else if (Qfalse == value) {
592
+ *o->attr = No;
593
+ } else {
594
+ rb_raise(rb_eArgError, "%s must be true, false, or nil.", rb_id2name(key));
595
+ }
596
+ return true;
597
+ }
598
+ }
637
599
  return false;
638
600
  }
639
601
 
640
- static int parse_options_cb(VALUE k, VALUE v, VALUE opts)
641
- {
602
+ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
642
603
  Options copts = (Options)opts;
643
604
  size_t len;
644
605
 
@@ -753,8 +714,7 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts)
753
714
  } else if (rails_sym == v) {
754
715
  copts->mode = RailsMode;
755
716
  } else {
756
- rb_raise(rb_eArgError,
757
- ":mode must be :object, :strict, :compat, :null, :custom, :rails, or :wab.");
717
+ rb_raise(rb_eArgError, ":mode must be :object, :strict, :compat, :null, :custom, :rails, or :wab.");
758
718
  }
759
719
  } else if (time_format_sym == k) {
760
720
  if (unix_sym == v) {
@@ -780,8 +740,7 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts)
780
740
  } else if (unicode_xss_sym == v) {
781
741
  copts->escape_mode = JXEsc;
782
742
  } else {
783
- rb_raise(rb_eArgError,
784
- ":encoding must be :newline, :json, :xss_safe, :unicode_xss, or :ascii.");
743
+ rb_raise(rb_eArgError, ":encoding must be :newline, :json, :xss_safe, :unicode_xss, or :ascii.");
785
744
  }
786
745
  } else if (bigdecimal_load_sym == k) {
787
746
  if (Qnil == v) {
@@ -892,7 +851,6 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts)
892
851
  if (Qnil == v) {
893
852
  return ST_CONTINUE;
894
853
  }
895
-
896
854
  if (null_sym == v) {
897
855
  copts->dump_opts.nan_dump = NullNan;
898
856
  } else if (huge_sym == v) {
@@ -910,7 +868,6 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts)
910
868
  if (Qnil == v) {
911
869
  return ST_CONTINUE;
912
870
  }
913
-
914
871
  if (Qtrue == v) {
915
872
  copts->dump_opts.omit_nil = true;
916
873
  } else if (Qfalse == v) {
@@ -918,7 +875,7 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts)
918
875
  } else {
919
876
  rb_raise(rb_eArgError, ":omit_nil must be true or false.");
920
877
  }
921
- } else if(oj_ascii_only_sym == k) {
878
+ } else if (oj_ascii_only_sym == k) {
922
879
  // This is here only for backwards compatibility with the original Oj.
923
880
  if (Qtrue == v) {
924
881
  copts->escape_mode = ASCIIEsc;
@@ -959,7 +916,7 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts)
959
916
 
960
917
  copts->ignore = ALLOC_N(VALUE, cnt + 1);
961
918
  for (i = 0; i < cnt; i++) {
962
- copts->ignore[i] = rb_ary_entry(v, i);
919
+ copts->ignore[i] = RARRAY_AREF(v, i);
963
920
  }
964
921
  copts->ignore[i] = Qnil;
965
922
  }
@@ -968,7 +925,6 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts)
968
925
  if (Qnil == v) {
969
926
  return ST_CONTINUE;
970
927
  }
971
-
972
928
  if (TYPE(v) == T_STRUCT && rb_obj_class(v) == rb_cRange) {
973
929
  VALUE min = rb_funcall(v, oj_begin_id, 0);
974
930
  VALUE max = rb_funcall(v, oj_end_id, 0);
@@ -982,8 +938,12 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts)
982
938
  } else if (Qfalse != v) {
983
939
  rb_raise(rb_eArgError, ":integer_range must be a range of Fixnum.");
984
940
  }
941
+ } else if (symbol_keys_sym == k || oj_symbolize_names_sym == k) {
942
+ if (Qnil == v) {
943
+ return ST_CONTINUE;
944
+ }
945
+ copts->sym_key = (Qtrue == v) ? Yes : No;
985
946
  }
986
-
987
947
  return ST_CONTINUE;
988
948
  }
989
949
 
@@ -1014,9 +974,7 @@ static int match_string_cb(VALUE key, VALUE value, VALUE rx) {
1014
974
  rb_raise(rb_eArgError, "%s", rc->err);
1015
975
  }
1016
976
  break;
1017
- default:
1018
- rb_raise(rb_eArgError, "for :match_string, keys must either a String or RegExp.");
1019
- break;
977
+ default: rb_raise(rb_eArgError, "for :match_string, keys must either a String or RegExp."); break;
1020
978
  }
1021
979
  return ST_CONTINUE;
1022
980
  }
@@ -1184,9 +1142,7 @@ static VALUE load_file(int argc, VALUE *argv, VALUE self) {
1184
1142
  } else if (wab_sym == v) {
1185
1143
  mode = WabMode;
1186
1144
  } else {
1187
- rb_raise(
1188
- rb_eArgError,
1189
- ":mode must be :object, :strict, :compat, :null, :custom, :rails, or :wab.");
1145
+ rb_raise(rb_eArgError, ":mode must be :object, :strict, :compat, :null, :custom, :rails, or :wab.");
1190
1146
  }
1191
1147
  }
1192
1148
  }
@@ -1264,16 +1220,15 @@ static VALUE safe_load(VALUE self, VALUE doc) {
1264
1220
  */
1265
1221
 
1266
1222
  struct dump_arg {
1267
- struct _out *out;
1223
+ struct _out * out;
1268
1224
  struct _options *copts;
1269
- int argc;
1270
- VALUE *argv;
1225
+ int argc;
1226
+ VALUE * argv;
1271
1227
  };
1272
1228
 
1273
- static VALUE dump_body(VALUE a)
1274
- {
1229
+ static VALUE dump_body(VALUE a) {
1275
1230
  volatile struct dump_arg *arg = (void *)a;
1276
- VALUE rstr;
1231
+ VALUE rstr;
1277
1232
 
1278
1233
  oj_dump_obj_to_json_using_params(*arg->argv, arg->copts, arg->out, arg->argc - 1, arg->argv + 1);
1279
1234
  if (0 == arg->out->buf) {
@@ -1285,8 +1240,7 @@ static VALUE dump_body(VALUE a)
1285
1240
  return rstr;
1286
1241
  }
1287
1242
 
1288
- static VALUE dump_ensure(VALUE a)
1289
- {
1243
+ static VALUE dump_ensure(VALUE a) {
1290
1244
  volatile struct dump_arg *arg = (void *)a;
1291
1245
 
1292
1246
  if (arg->out->allocated) {
@@ -1320,10 +1274,10 @@ static VALUE dump(int argc, VALUE *argv, VALUE self) {
1320
1274
  if (CompatMode == copts.mode && copts.escape_mode != ASCIIEsc) {
1321
1275
  copts.escape_mode = JSONEsc;
1322
1276
  }
1323
- arg.out = &out;
1277
+ arg.out = &out;
1324
1278
  arg.copts = &copts;
1325
- arg.argc = argc;
1326
- arg.argv = argv;
1279
+ arg.argc = argc;
1280
+ arg.argv = argv;
1327
1281
 
1328
1282
  arg.out->buf = buf;
1329
1283
  arg.out->end = buf + sizeof(buf) - 10;
@@ -2015,6 +1969,8 @@ void Init_oj() {
2015
1969
  rb_gc_register_address(&strict_sym);
2016
1970
  symbol_keys_sym = ID2SYM(rb_intern("symbol_keys"));
2017
1971
  rb_gc_register_address(&symbol_keys_sym);
1972
+ oj_symbolize_names_sym = ID2SYM(rb_intern("symbolize_names"));
1973
+ rb_gc_register_address(&oj_symbolize_names_sym);
2018
1974
  time_format_sym = ID2SYM(rb_intern("time_format"));
2019
1975
  rb_gc_register_address(&time_format_sym);
2020
1976
  unicode_xss_sym = ID2SYM(rb_intern("unicode_xss"));
data/ext/oj/oj.h CHANGED
@@ -311,6 +311,7 @@ extern VALUE oj_object_nl_sym;
311
311
  extern VALUE oj_quirks_mode_sym;
312
312
  extern VALUE oj_space_before_sym;
313
313
  extern VALUE oj_space_sym;
314
+ extern VALUE oj_symbolize_names_sym;
314
315
  extern VALUE oj_trace_sym;
315
316
 
316
317
  extern VALUE oj_slash_string;
data/ext/oj/parse.c CHANGED
@@ -904,9 +904,17 @@ void oj_set_error_at(ParseInfo pi,
904
904
  char * end = p + sizeof(msg) - 2;
905
905
  char * start;
906
906
  Val vp;
907
+ int mlen;
907
908
 
908
909
  va_start(ap, format);
909
- p += vsnprintf(msg, sizeof(msg) - 1, format, ap);
910
+ mlen = vsnprintf(msg, sizeof(msg) - 1, format, ap);
911
+ if (0 < mlen) {
912
+ if (sizeof(msg) - 2 < (size_t)mlen) {
913
+ p = end - 2;
914
+ } else {
915
+ p += mlen;
916
+ }
917
+ }
910
918
  va_end(ap);
911
919
  pi->err.clas = err_clas;
912
920
  if (p + 3 < end) {
data/ext/oj/rails.c CHANGED
@@ -157,7 +157,7 @@ static void dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
157
157
  assure_size(out, 2);
158
158
  *out->cur++ = '{';
159
159
  for (i = 0; i < cnt; i++) {
160
- volatile VALUE s = rb_sym2str(rb_ary_entry(ma, i));
160
+ volatile VALUE s = rb_sym2str(RARRAY_AREF(ma, i));
161
161
 
162
162
  name = RSTRING_PTR(s);
163
163
  len = (int)RSTRING_LEN(s);
@@ -383,7 +383,7 @@ static StrLen columns_array(VALUE rcols, int *ccnt) {
383
383
  *ccnt = cnt;
384
384
  cols = ALLOC_N(struct _strLen, cnt);
385
385
  for (i = 0, cp = cols; i < cnt; i++, cp++) {
386
- v = rb_ary_entry(rcols, i);
386
+ v = RARRAY_AREF(rcols, i);
387
387
  if (T_STRING != rb_type(v)) {
388
388
  v = rb_funcall(v, oj_to_s_id, 0);
389
389
  }
@@ -420,7 +420,7 @@ static void dump_row(VALUE row, StrLen cols, int ccnt, int depth, Out out) {
420
420
  }
421
421
  oj_dump_cstr(cols->str, cols->len, 0, 0, out);
422
422
  *out->cur++ = ':';
423
- dump_rails_val(rb_ary_entry(row, i), depth, out, true);
423
+ dump_rails_val(RARRAY_AREF(row, i), depth, out, true);
424
424
  if (i < ccnt - 1) {
425
425
  *out->cur++ = ',';
426
426
  }
@@ -490,7 +490,7 @@ static void dump_activerecord_result(VALUE obj, int depth, Out out, bool as_ok)
490
490
  } else {
491
491
  fill_indent(out, d2);
492
492
  }
493
- dump_row(rb_ary_entry(rows, i), cols, ccnt, d2, out);
493
+ dump_row(RARRAY_AREF(rows, i), cols, ccnt, d2, out);
494
494
  if (i < rcnt - 1) {
495
495
  *out->cur++ = ',';
496
496
  }
@@ -1281,7 +1281,7 @@ static void dump_array(VALUE a, int depth, Out out, bool as_ok) {
1281
1281
  } else {
1282
1282
  fill_indent(out, d2);
1283
1283
  }
1284
- dump_rails_val(rb_ary_entry(a, i), d2, out, true);
1284
+ dump_rails_val(RARRAY_AREF(a, i), d2, out, true);
1285
1285
  if (i < cnt) {
1286
1286
  *out->cur++ = ',';
1287
1287
  }
data/ext/oj/usual.c CHANGED
@@ -537,7 +537,7 @@ static void add_float_key(ojParser p) {
537
537
  static void add_float_as_big(ojParser p) {
538
538
  char buf[64];
539
539
 
540
- // fails on ubuntu
540
+ // snprintf fails on ubuntu and macOS for long double
541
541
  // snprintf(buf, sizeof(buf), "%Lg", p->num.dub);
542
542
  sprintf(buf, "%Lg", p->num.dub);
543
543
  push(p, rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new2(buf)));
@@ -546,7 +546,9 @@ static void add_float_as_big(ojParser p) {
546
546
  static void add_float_as_big_key(ojParser p) {
547
547
  char buf[64];
548
548
 
549
- snprintf(buf, sizeof(buf), "%Lg", p->num.dub);
549
+ // snprintf fails on ubuntu and macOS for long double
550
+ // snprintf(buf, sizeof(buf), "%Lg", p->num.dub);
551
+ sprintf(buf, "%Lg", p->num.dub);
550
552
  push_key(p);
551
553
  push2(p, rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new2(buf)));
552
554
  }
data/ext/oj/wab.c CHANGED
@@ -128,7 +128,7 @@ static void dump_array(VALUE a, int depth, Out out, bool as_ok) {
128
128
  for (i = 0; i <= cnt; i++) {
129
129
  assure_size(out, size);
130
130
  fill_indent(out, d2);
131
- oj_dump_wab_val(rb_ary_entry(a, i), d2, out);
131
+ oj_dump_wab_val(RARRAY_AREF(a, i), d2, out);
132
132
  if (i < cnt) {
133
133
  *out->cur++ = ',';
134
134
  }
data/lib/oj/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.13.7'
4
+ VERSION = '3.13.11'
5
5
  end
data/pages/JsonGem.md CHANGED
@@ -1,3 +1,18 @@
1
+ # JSON Quickstart
2
+
3
+ To have Oj universally "take over" many methods on the JSON constant (`load`, `parse`, etc.) with
4
+ their faster Oj counterparts, in a mode that is compatible with the json gem:
5
+
6
+ ```ruby
7
+ Oj.mimic_JSON()
8
+ ```
9
+
10
+ If the project does not already use the json gem, `JSON` will become available.
11
+ If the project does require the json gem, `Oj.mimic_JSON()` should be invoked after the
12
+ json gem has been required.
13
+
14
+ For more details and options, read on...
15
+
1
16
  # Oj JSON Gem Compatibility
2
17
 
3
18
  The `:compat` mode mimics the json gem. The json gem is built around the use
data/pages/Modes.md CHANGED
@@ -39,7 +39,8 @@ if a non-native type is encountered instead of raising an Exception.
39
39
  The `:compat` mode mimics the json gem. The json gem is built around the use
40
40
  of the `to_json(*)` method defined for a class. Oj attempts to provide the
41
41
  same functionality by being a drop in replacement with a few
42
- exceptions. [{file:JsonGem.md}](JsonGem.md) includes more details on
42
+ exceptions. To universally replace many `JSON` methods with their faster Oj counterparts,
43
+ simply run `Oj.mimic_json`. [{file:JsonGem.md}](JsonGem.md) includes more details on
43
44
  compatibility and use.
44
45
 
45
46
  ## :rails Mode
@@ -108,11 +109,11 @@ information.
108
109
  | :float_precision | Fixnum | x | x | | | | x | |
109
110
  | :hash_class | Class | | | x | x | | x | |
110
111
  | :ignore | Array | | | | | x | x | |
111
- | :indent | Integer | x | x | 3 | 4 | x | x | x |
112
+ | :indent | Integer | x | x | 4 | 4 | x | x | x |
112
113
  | :indent_str | String | | | x | x | | x | |
113
114
  | :integer_range | Range | x | x | x | x | x | x | x |
114
115
  | :match_string | Hash | | | x | x | | x | |
115
- | :max_nesting | Fixnum | 4 | 4 | x | | 5 | 4 | |
116
+ | :max_nesting | Fixnum | 5 | 5 | x | | 5 | 5 | |
116
117
  | :mode | Symbol | - | - | - | - | - | - | |
117
118
  | :nan | Symbol | | | | | | x | |
118
119
  | :nilnil | Boolean | | | | | | x | |
@@ -140,6 +141,8 @@ information.
140
141
  3. By default the bigdecimal_as decimal is not set and the default encoding
141
142
  for Rails is as a string. Setting the value to true will encode a
142
143
  BigDecimal as a number which breaks compatibility.
144
+ Note: after version 3.11.3 both `Oj.generate` and `JSON.generate`
145
+ will not honour this option in Rails Mode, detais on https://github.com/ohler55/oj/pull/716.
143
146
 
144
147
  4. The integer indent value in the default options will be honored by since
145
148
  the json gem expects a String type the indent in calls to 'to_json()',
data/pages/Rails.md CHANGED
@@ -1,3 +1,15 @@
1
+ # Rails Quickstart
2
+
3
+ To universally replace Rails' use of the json gem with Oj, and also
4
+ have Oj "take over" many methods on the JSON constant (`load`, `parse`, etc.) with
5
+ their faster Oj counterparts, add this to an initializer:
6
+
7
+ ```ruby
8
+ Oj.optimize_rails()
9
+ ```
10
+
11
+ For more details and options, read on...
12
+
1
13
  # Oj Rails Compatibility
2
14
 
3
15
  The `:rails` mode mimics the ActiveSupport version 5 encoder. Rails and
data/test/bug.rb ADDED
@@ -0,0 +1,16 @@
1
+ $: << '.'
2
+ $: << File.join(File.dirname(__FILE__), "../lib")
3
+ $: << File.join(File.dirname(__FILE__), "../ext")
4
+
5
+
6
+ #require 'bundler/setup'
7
+ require 'oj'
8
+ require 'active_support'
9
+ require 'active_support/time_with_zone'
10
+ require 'tzinfo'
11
+
12
+ puts ActiveSupport::TimeWithZone
13
+
14
+ json = File.read('./bug.json')
15
+
16
+ Oj.load(json)