oj 3.14.2 → 3.14.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -1
  3. data/README.md +0 -1
  4. data/ext/oj/buf.h +2 -2
  5. data/ext/oj/cache.c +16 -16
  6. data/ext/oj/cache8.c +7 -7
  7. data/ext/oj/circarray.c +2 -1
  8. data/ext/oj/circarray.h +2 -2
  9. data/ext/oj/code.c +2 -2
  10. data/ext/oj/code.h +2 -2
  11. data/ext/oj/compat.c +6 -14
  12. data/ext/oj/custom.c +1 -1
  13. data/ext/oj/debug.c +3 -9
  14. data/ext/oj/dump.c +16 -16
  15. data/ext/oj/dump_compat.c +551 -576
  16. data/ext/oj/dump_leaf.c +3 -5
  17. data/ext/oj/dump_object.c +35 -36
  18. data/ext/oj/dump_strict.c +2 -4
  19. data/ext/oj/encoder.c +1 -1
  20. data/ext/oj/err.c +2 -13
  21. data/ext/oj/err.h +9 -12
  22. data/ext/oj/extconf.rb +1 -1
  23. data/ext/oj/fast.c +24 -38
  24. data/ext/oj/intern.c +38 -42
  25. data/ext/oj/intern.h +3 -7
  26. data/ext/oj/mem.c +211 -217
  27. data/ext/oj/mem.h +10 -10
  28. data/ext/oj/mimic_json.c +18 -24
  29. data/ext/oj/object.c +5 -5
  30. data/ext/oj/odd.c +2 -1
  31. data/ext/oj/odd.h +4 -4
  32. data/ext/oj/oj.c +60 -81
  33. data/ext/oj/oj.h +53 -54
  34. data/ext/oj/parse.c +55 -118
  35. data/ext/oj/parse.h +5 -10
  36. data/ext/oj/parser.c +7 -8
  37. data/ext/oj/parser.h +7 -8
  38. data/ext/oj/rails.c +28 -59
  39. data/ext/oj/reader.c +5 -9
  40. data/ext/oj/reader.h +1 -1
  41. data/ext/oj/resolve.c +3 -4
  42. data/ext/oj/rxclass.c +1 -1
  43. data/ext/oj/rxclass.h +1 -1
  44. data/ext/oj/saj.c +4 -4
  45. data/ext/oj/saj2.c +32 -49
  46. data/ext/oj/saj2.h +1 -1
  47. data/ext/oj/scp.c +3 -14
  48. data/ext/oj/sparse.c +18 -67
  49. data/ext/oj/stream_writer.c +5 -18
  50. data/ext/oj/strict.c +7 -13
  51. data/ext/oj/string_writer.c +6 -14
  52. data/ext/oj/trace.h +27 -16
  53. data/ext/oj/usual.c +62 -61
  54. data/ext/oj/usual.h +6 -6
  55. data/ext/oj/util.h +1 -1
  56. data/ext/oj/val_stack.h +4 -4
  57. data/ext/oj/wab.c +7 -9
  58. data/lib/oj/active_support_helper.rb +0 -1
  59. data/lib/oj/bag.rb +7 -1
  60. data/lib/oj/easy_hash.rb +4 -5
  61. data/lib/oj/error.rb +0 -1
  62. data/lib/oj/json.rb +4 -2
  63. data/lib/oj/mimic.rb +4 -2
  64. data/lib/oj/state.rb +8 -5
  65. data/lib/oj/version.rb +1 -2
  66. data/lib/oj.rb +0 -1
  67. data/test/_test_active.rb +0 -1
  68. data/test/_test_active_mimic.rb +0 -1
  69. data/test/_test_mimic_rails.rb +0 -1
  70. data/test/activerecord/result_test.rb +5 -6
  71. data/test/bar.rb +3 -3
  72. data/test/files.rb +1 -1
  73. data/test/foo.rb +5 -48
  74. data/test/helper.rb +1 -4
  75. data/test/isolated/shared.rb +3 -2
  76. data/test/json_gem/json_addition_test.rb +2 -2
  77. data/test/json_gem/json_common_interface_test.rb +4 -4
  78. data/test/json_gem/json_encoding_test.rb +0 -0
  79. data/test/json_gem/json_ext_parser_test.rb +1 -0
  80. data/test/json_gem/json_fixtures_test.rb +3 -2
  81. data/test/json_gem/json_generator_test.rb +43 -32
  82. data/test/json_gem/json_generic_object_test.rb +11 -11
  83. data/test/json_gem/json_parser_test.rb +46 -46
  84. data/test/json_gem/json_string_matching_test.rb +9 -9
  85. data/test/mem.rb +7 -7
  86. data/test/perf.rb +2 -2
  87. data/test/perf_compat.rb +1 -1
  88. data/test/perf_fast.rb +1 -1
  89. data/test/perf_file.rb +2 -2
  90. data/test/perf_object.rb +1 -2
  91. data/test/perf_once.rb +4 -4
  92. data/test/perf_parser.rb +1 -2
  93. data/test/perf_saj.rb +1 -2
  94. data/test/perf_scp.rb +1 -1
  95. data/test/perf_simple.rb +3 -3
  96. data/test/perf_strict.rb +1 -1
  97. data/test/perf_wab.rb +1 -1
  98. data/test/sample/change.rb +0 -1
  99. data/test/sample/dir.rb +0 -1
  100. data/test/sample/doc.rb +0 -1
  101. data/test/sample/file.rb +0 -1
  102. data/test/sample/group.rb +0 -1
  103. data/test/sample/hasprops.rb +0 -1
  104. data/test/sample/layer.rb +0 -1
  105. data/test/sample/rect.rb +0 -1
  106. data/test/sample/shape.rb +0 -1
  107. data/test/sample/text.rb +0 -1
  108. data/test/sample.rb +2 -3
  109. data/test/sample_json.rb +0 -1
  110. data/test/test_compat.rb +11 -9
  111. data/test/test_custom.rb +5 -9
  112. data/test/test_debian.rb +1 -1
  113. data/test/test_fast.rb +10 -20
  114. data/test/test_file.rb +8 -8
  115. data/test/test_integer_range.rb +2 -2
  116. data/test/test_null.rb +5 -3
  117. data/test/test_object.rb +6 -5
  118. data/test/test_parser_saj.rb +23 -21
  119. data/test/test_parser_usual.rb +3 -3
  120. data/test/test_saj.rb +2 -0
  121. data/test/test_scp.rb +6 -6
  122. data/test/test_strict.rb +6 -4
  123. data/test/test_various.rb +21 -24
  124. data/test/test_wab.rb +6 -5
  125. data/test/test_writer.rb +1 -1
  126. metadata +17 -26
  127. data/test/activesupport4/decoding_test.rb +0 -108
  128. data/test/activesupport4/encoding_test.rb +0 -531
  129. data/test/activesupport4/test_helper.rb +0 -41
  130. data/test/activesupport5/abstract_unit.rb +0 -45
  131. data/test/activesupport5/decoding_test.rb +0 -133
  132. data/test/activesupport5/encoding_test.rb +0 -500
  133. data/test/activesupport5/encoding_test_cases.rb +0 -98
  134. data/test/activesupport5/test_helper.rb +0 -72
  135. data/test/activesupport5/time_zone_test_helpers.rb +0 -39
data/ext/oj/usual.c CHANGED
@@ -1,10 +1,11 @@
1
1
  // Copyright (c) 2021, Peter Ohler, All rights reserved.
2
2
 
3
- #include "mem.h"
3
+ #include "usual.h"
4
+
4
5
  #include "cache.h"
6
+ #include "mem.h"
5
7
  #include "oj.h"
6
8
  #include "parser.h"
7
- #include "usual.h"
8
9
 
9
10
  // The Usual delegate builds Ruby objects during parsing. It makes use of
10
11
  // three stacks. The first is the value stack. This is where parsed values are
@@ -90,8 +91,8 @@ static VALUE resolve_classname(VALUE mod, const char *classname, bool auto_defin
90
91
  static VALUE resolve_classpath(const char *name, size_t len, bool auto_define) {
91
92
  char class_name[1024];
92
93
  VALUE clas;
93
- char * end = class_name + sizeof(class_name) - 1;
94
- char * s;
94
+ char *end = class_name + sizeof(class_name) - 1;
95
+ char *s;
95
96
  const char *n = name;
96
97
 
97
98
  clas = rb_cObject;
@@ -186,7 +187,7 @@ static ID get_attr_id(ojParser p, Key kp) {
186
187
  }
187
188
 
188
189
  static void push_key(ojParser p) {
189
- Usual d = (Usual)p->ctx;
190
+ Usual d = (Usual)p->ctx;
190
191
  size_t klen = buf_len(&p->key);
191
192
  const char *key = buf_str(&p->key);
192
193
 
@@ -270,14 +271,14 @@ static void open_array_key(ojParser p) {
270
271
  }
271
272
 
272
273
  static void close_object(ojParser p) {
273
- VALUE * vp;
274
- Usual d = (Usual)p->ctx;
274
+ VALUE *vp;
275
+ Usual d = (Usual)p->ctx;
275
276
 
276
277
  d->ctail--;
277
278
 
278
279
  Col c = d->ctail;
279
280
  Key kp = d->khead + c->ki;
280
- VALUE * head = d->vhead + c->vi + 1;
281
+ VALUE *head = d->vhead + c->vi + 1;
281
282
  volatile VALUE obj = rb_hash_new();
282
283
 
283
284
  #if HAVE_RB_HASH_BULK_INSERT
@@ -303,14 +304,14 @@ static void close_object(ojParser p) {
303
304
  }
304
305
 
305
306
  static void close_object_class(ojParser p) {
306
- VALUE * vp;
307
- Usual d = (Usual)p->ctx;
307
+ VALUE *vp;
308
+ Usual d = (Usual)p->ctx;
308
309
 
309
310
  d->ctail--;
310
311
 
311
312
  Col c = d->ctail;
312
313
  Key kp = d->khead + c->ki;
313
- VALUE * head = d->vhead + c->vi + 1;
314
+ VALUE *head = d->vhead + c->vi + 1;
314
315
  volatile VALUE obj = rb_class_new_instance(0, NULL, d->hash_class);
315
316
 
316
317
  for (vp = head; kp < d->ktail; kp++, vp += 2) {
@@ -326,14 +327,14 @@ static void close_object_class(ojParser p) {
326
327
  }
327
328
 
328
329
  static void close_object_create(ojParser p) {
329
- VALUE * vp;
330
- Usual d = (Usual)p->ctx;
330
+ VALUE *vp;
331
+ Usual d = (Usual)p->ctx;
331
332
 
332
333
  d->ctail--;
333
334
 
334
335
  Col c = d->ctail;
335
336
  Key kp = d->khead + c->ki;
336
- VALUE * head = d->vhead + c->vi;
337
+ VALUE *head = d->vhead + c->vi;
337
338
  volatile VALUE obj;
338
339
 
339
340
  if (Qundef == *head) {
@@ -409,7 +410,7 @@ static void close_array(ojParser p) {
409
410
  Usual d = (Usual)p->ctx;
410
411
 
411
412
  d->ctail--;
412
- VALUE * head = d->vhead + d->ctail->vi + 1;
413
+ VALUE *head = d->vhead + d->ctail->vi + 1;
413
414
  volatile VALUE a = rb_ary_new_from_values(d->vtail - head, head);
414
415
 
415
416
  d->vtail = head;
@@ -418,11 +419,11 @@ static void close_array(ojParser p) {
418
419
  }
419
420
 
420
421
  static void close_array_class(ojParser p) {
421
- VALUE * vp;
422
- Usual d = (Usual)p->ctx;
422
+ VALUE *vp;
423
+ Usual d = (Usual)p->ctx;
423
424
 
424
425
  d->ctail--;
425
- VALUE * head = d->vhead + d->ctail->vi + 1;
426
+ VALUE *head = d->vhead + d->ctail->vi + 1;
426
427
  volatile VALUE a = rb_class_new_instance(0, NULL, d->array_class);
427
428
 
428
429
  for (vp = head; vp < d->vtail; vp++) {
@@ -532,9 +533,9 @@ static void add_big_as_ruby_key(ojParser p) {
532
533
  }
533
534
 
534
535
  static void add_str(ojParser p) {
535
- Usual d = (Usual)p->ctx;
536
+ Usual d = (Usual)p->ctx;
536
537
  volatile VALUE rstr;
537
- const char * str = buf_str(&p->buf);
538
+ const char *str = buf_str(&p->buf);
538
539
  size_t len = buf_len(&p->buf);
539
540
 
540
541
  if (len < d->cache_str) {
@@ -546,9 +547,9 @@ static void add_str(ojParser p) {
546
547
  }
547
548
 
548
549
  static void add_str_key(ojParser p) {
549
- Usual d = (Usual)p->ctx;
550
+ Usual d = (Usual)p->ctx;
550
551
  volatile VALUE rstr;
551
- const char * str = buf_str(&p->buf);
552
+ const char *str = buf_str(&p->buf);
552
553
  size_t len = buf_len(&p->buf);
553
554
 
554
555
  if (len < d->cache_str) {
@@ -561,11 +562,11 @@ static void add_str_key(ojParser p) {
561
562
  }
562
563
 
563
564
  static void add_str_key_create(ojParser p) {
564
- Usual d = (Usual)p->ctx;
565
+ Usual d = (Usual)p->ctx;
565
566
  volatile VALUE rstr;
566
- const char * str = buf_str(&p->buf);
567
+ const char *str = buf_str(&p->buf);
567
568
  size_t len = buf_len(&p->buf);
568
- const char * key = buf_str(&p->key);
569
+ const char *key = buf_str(&p->key);
569
570
  size_t klen = buf_len(&p->key);
570
571
 
571
572
  if (klen == (size_t)d->create_id_len && 0 == strncmp(d->create_id, key, klen)) {
@@ -634,8 +635,8 @@ static void mark(ojParser p) {
634
635
  if (NULL == p || NULL == p->ctx) {
635
636
  return;
636
637
  }
637
- Usual d = (Usual)p->ctx;
638
- VALUE * vp;
638
+ Usual d = (Usual)p->ctx;
639
+ VALUE *vp;
639
640
 
640
641
  if (NULL == d) {
641
642
  return;
@@ -729,7 +730,7 @@ static VALUE opt_cache_strings(ojParser p, VALUE value) {
729
730
 
730
731
  static VALUE opt_cache_strings_set(ojParser p, VALUE value) {
731
732
  Usual d = (Usual)p->ctx;
732
- int limit = NUM2INT(value);
733
+ int limit = NUM2INT(value);
733
734
 
734
735
  if (CACHE_MAX_KEY < limit) {
735
736
  limit = CACHE_MAX_KEY;
@@ -749,7 +750,7 @@ static VALUE opt_cache_expunge(ojParser p, VALUE value) {
749
750
 
750
751
  static VALUE opt_cache_expunge_set(ojParser p, VALUE value) {
751
752
  Usual d = (Usual)p->ctx;
752
- int rate = NUM2INT(value);
753
+ int rate = NUM2INT(value);
753
754
 
754
755
  if (rate < 0) {
755
756
  rate = 0;
@@ -773,7 +774,7 @@ static VALUE opt_capacity(ojParser p, VALUE value) {
773
774
 
774
775
  static VALUE opt_capacity_set(ojParser p, VALUE value) {
775
776
  Usual d = (Usual)p->ctx;
776
- long cap = NUM2LONG(value);
777
+ long cap = NUM2LONG(value);
777
778
 
778
779
  if (d->vend - d->vhead < cap) {
779
780
  long pos = d->vtail - d->vhead;
@@ -871,7 +872,7 @@ static VALUE opt_decimal(ojParser p, VALUE value) {
871
872
  }
872
873
 
873
874
  static VALUE opt_decimal_set(ojParser p, VALUE value) {
874
- const char * mode;
875
+ const char *mode;
875
876
  volatile VALUE s;
876
877
 
877
878
  switch (rb_type(value)) {
@@ -987,8 +988,8 @@ static VALUE opt_missing_class(ojParser p, VALUE value) {
987
988
  }
988
989
 
989
990
  static VALUE opt_missing_class_set(ojParser p, VALUE value) {
990
- Usual d = (Usual)p->ctx;
991
- const char * mode;
991
+ Usual d = (Usual)p->ctx;
992
+ const char *mode;
992
993
  volatile VALUE s;
993
994
 
994
995
  switch (rb_type(value)) {
@@ -1068,33 +1069,33 @@ static VALUE opt_symbol_keys_set(ojParser p, VALUE value) {
1068
1069
  static VALUE option(ojParser p, const char *key, VALUE value) {
1069
1070
  struct opt *op;
1070
1071
  struct opt opts[] = {
1071
- {.name = "array_class", .func = opt_array_class},
1072
- {.name = "array_class=", .func = opt_array_class_set},
1073
- {.name = "cache_keys", .func = opt_cache_keys},
1074
- {.name = "cache_keys=", .func = opt_cache_keys_set},
1075
- {.name = "cache_strings", .func = opt_cache_strings},
1076
- {.name = "cache_strings=", .func = opt_cache_strings_set},
1077
- {.name = "cache_expunge", .func = opt_cache_expunge},
1078
- {.name = "cache_expunge=", .func = opt_cache_expunge_set},
1079
- {.name = "capacity", .func = opt_capacity},
1080
- {.name = "capacity=", .func = opt_capacity_set},
1081
- {.name = "class_cache", .func = opt_class_cache},
1082
- {.name = "class_cache=", .func = opt_class_cache_set},
1083
- {.name = "create_id", .func = opt_create_id},
1084
- {.name = "create_id=", .func = opt_create_id_set},
1085
- {.name = "decimal", .func = opt_decimal},
1086
- {.name = "decimal=", .func = opt_decimal_set},
1087
- {.name = "hash_class", .func = opt_hash_class},
1088
- {.name = "hash_class=", .func = opt_hash_class_set},
1089
- {.name = "ignore_json_create", .func = opt_ignore_json_create},
1090
- {.name = "ignore_json_create=", .func = opt_ignore_json_create_set},
1091
- {.name = "missing_class", .func = opt_missing_class},
1092
- {.name = "missing_class=", .func = opt_missing_class_set},
1093
- {.name = "omit_null", .func = opt_omit_null},
1094
- {.name = "omit_null=", .func = opt_omit_null_set},
1095
- {.name = "symbol_keys", .func = opt_symbol_keys},
1096
- {.name = "symbol_keys=", .func = opt_symbol_keys_set},
1097
- {.name = NULL},
1072
+ {.name = "array_class", .func = opt_array_class},
1073
+ {.name = "array_class=", .func = opt_array_class_set},
1074
+ {.name = "cache_keys", .func = opt_cache_keys},
1075
+ {.name = "cache_keys=", .func = opt_cache_keys_set},
1076
+ {.name = "cache_strings", .func = opt_cache_strings},
1077
+ {.name = "cache_strings=", .func = opt_cache_strings_set},
1078
+ {.name = "cache_expunge", .func = opt_cache_expunge},
1079
+ {.name = "cache_expunge=", .func = opt_cache_expunge_set},
1080
+ {.name = "capacity", .func = opt_capacity},
1081
+ {.name = "capacity=", .func = opt_capacity_set},
1082
+ {.name = "class_cache", .func = opt_class_cache},
1083
+ {.name = "class_cache=", .func = opt_class_cache_set},
1084
+ {.name = "create_id", .func = opt_create_id},
1085
+ {.name = "create_id=", .func = opt_create_id_set},
1086
+ {.name = "decimal", .func = opt_decimal},
1087
+ {.name = "decimal=", .func = opt_decimal_set},
1088
+ {.name = "hash_class", .func = opt_hash_class},
1089
+ {.name = "hash_class=", .func = opt_hash_class_set},
1090
+ {.name = "ignore_json_create", .func = opt_ignore_json_create},
1091
+ {.name = "ignore_json_create=", .func = opt_ignore_json_create_set},
1092
+ {.name = "missing_class", .func = opt_missing_class},
1093
+ {.name = "missing_class=", .func = opt_missing_class_set},
1094
+ {.name = "omit_null", .func = opt_omit_null},
1095
+ {.name = "omit_null=", .func = opt_omit_null_set},
1096
+ {.name = "symbol_keys", .func = opt_symbol_keys},
1097
+ {.name = "symbol_keys=", .func = opt_symbol_keys_set},
1098
+ {.name = NULL},
1098
1099
  };
1099
1100
 
1100
1101
  for (op = opts; NULL != op->name; op++) {
@@ -1110,7 +1111,7 @@ static VALUE option(ojParser p, const char *key, VALUE value) {
1110
1111
  ///// the set up //////////////////////////////////////////////////////////////
1111
1112
 
1112
1113
  void oj_init_usual(ojParser p, Usual d) {
1113
- int cap = 4096;
1114
+ int cap = 4096;
1114
1115
 
1115
1116
  d->vhead = OJ_R_ALLOC_N(VALUE, cap);
1116
1117
  d->vend = d->vhead + cap;
data/ext/oj/usual.h CHANGED
@@ -13,7 +13,7 @@ struct _ojParser;
13
13
  typedef struct _col {
14
14
  long vi; // value stack index
15
15
  long ki; // key stack index if an hash else -1 for an array
16
- } * Col;
16
+ } *Col;
17
17
 
18
18
  typedef union _key {
19
19
  struct {
@@ -22,9 +22,9 @@ typedef union _key {
22
22
  };
23
23
  struct {
24
24
  int16_t xlen; // should be the same as len
25
- char * key;
25
+ char *key;
26
26
  };
27
- } * Key;
27
+ } *Key;
28
28
 
29
29
  #define MISS_AUTO 'A'
30
30
  #define MISS_RAISE 'R'
@@ -43,7 +43,7 @@ typedef struct _usual {
43
43
  Key ktail;
44
44
  Key kend;
45
45
 
46
- VALUE (*get_key)(ojParser p, Key kp);
46
+ VALUE (*get_key)(struct _ojParser *p, Key kp);
47
47
  struct _cache *key_cache; // same as str_cache or sym_cache
48
48
  struct _cache *str_cache;
49
49
  struct _cache *sym_cache;
@@ -53,14 +53,14 @@ typedef struct _usual {
53
53
  VALUE array_class;
54
54
  VALUE hash_class;
55
55
 
56
- char * create_id;
56
+ char *create_id;
57
57
  uint8_t create_id_len;
58
58
  uint8_t cache_str;
59
59
  uint8_t cache_xrate;
60
60
  uint8_t miss_class;
61
61
  bool cache_keys;
62
62
  bool ignore_json_create;
63
- } * Usual;
63
+ } *Usual;
64
64
 
65
65
  // Initialize the parser with the usual delegate. If the usual delegate is
66
66
  // wrapped then this function is called first and then the parser functions
data/ext/oj/util.h CHANGED
@@ -13,7 +13,7 @@ typedef struct _timeInfo {
13
13
  int day;
14
14
  int mon;
15
15
  int year;
16
- } * TimeInfo;
16
+ }* TimeInfo;
17
17
 
18
18
  extern void sec_as_time(int64_t secs, TimeInfo ti);
19
19
 
data/ext/oj/val_stack.h CHANGED
@@ -29,10 +29,10 @@ typedef enum {
29
29
 
30
30
  typedef struct _val {
31
31
  volatile VALUE val;
32
- const char * key;
32
+ const char *key;
33
33
  char karray[32];
34
34
  volatile VALUE key_val;
35
- const char * classname;
35
+ const char *classname;
36
36
  VALUE clas;
37
37
  OddArgs odd_args;
38
38
  uint16_t klen;
@@ -40,7 +40,7 @@ typedef struct _val {
40
40
  char next; // ValNext
41
41
  char k1; // first original character in the key
42
42
  char kalloc;
43
- } * Val;
43
+ } *Val;
44
44
 
45
45
  typedef struct _valStack {
46
46
  struct _val base[STACK_INC];
@@ -53,7 +53,7 @@ typedef struct _valStack {
53
53
  VALUE mutex;
54
54
  #endif
55
55
 
56
- } * ValStack;
56
+ } *ValStack;
57
57
 
58
58
  extern VALUE oj_stack_init(ValStack stack);
59
59
 
data/ext/oj/wab.c CHANGED
@@ -76,15 +76,13 @@ static VALUE resolve_uri_http_class(void) {
76
76
  }
77
77
 
78
78
  static void raise_wab(VALUE obj) {
79
- rb_raise(rb_eTypeError,
80
- "Failed to dump %s Object to JSON in wab mode.\n",
81
- rb_class2name(rb_obj_class(obj)));
79
+ rb_raise(rb_eTypeError, "Failed to dump %s Object to JSON in wab mode.\n", rb_class2name(rb_obj_class(obj)));
82
80
  }
83
81
 
84
82
  // Removed dependencies on math due to problems with CentOS 5.4.
85
83
  static void dump_float(VALUE obj, int depth, Out out, bool as_ok) {
86
84
  char buf[64];
87
- char * b;
85
+ char *b;
88
86
  double d = rb_num2dbl(obj);
89
87
  int cnt = 0;
90
88
 
@@ -299,7 +297,7 @@ static VALUE calc_hash_key(ParseInfo pi, Val parent) {
299
297
  #if HAVE_RB_ENC_INTERNED_STR
300
298
  rkey = rb_enc_interned_str(parent->key, parent->klen, oj_utf8_encoding);
301
299
  #else
302
- rkey = rb_utf8_str_new(parent->key, parent->klen);
300
+ rkey = rb_utf8_str_new(parent->key, parent->klen);
303
301
  rkey = rb_str_intern(rkey);
304
302
  OBJ_FREEZE(rkey);
305
303
  #endif
@@ -446,14 +444,14 @@ static VALUE protect_uri(VALUE rstr) {
446
444
  static VALUE cstr_to_rstr(ParseInfo pi, const char *str, size_t len) {
447
445
  volatile VALUE v = Qnil;
448
446
 
449
- if (30 == len && '-' == str[4] && '-' == str[7] && 'T' == str[10] && ':' == str[13] &&
450
- ':' == str[16] && '.' == str[19] && 'Z' == str[29]) {
447
+ if (30 == len && '-' == str[4] && '-' == str[7] && 'T' == str[10] && ':' == str[13] && ':' == str[16] &&
448
+ '.' == str[19] && 'Z' == str[29]) {
451
449
  if (Qnil != (v = time_parse(str, (int)len))) {
452
450
  return v;
453
451
  }
454
452
  }
455
- if (36 == len && '-' == str[8] && '-' == str[13] && '-' == str[18] && '-' == str[23] &&
456
- uuid_check(str, (int)len) && Qnil != resolve_wab_uuid_class()) {
453
+ if (36 == len && '-' == str[8] && '-' == str[13] && '-' == str[18] && '-' == str[23] && uuid_check(str, (int)len) &&
454
+ Qnil != resolve_wab_uuid_class()) {
457
455
  return rb_funcall(wab_uuid_clas, oj_new_id, 1, rb_str_new(str, len));
458
456
  }
459
457
  if (7 < len && 0 == strncasecmp("http://", str, 7)) {
@@ -1,4 +1,3 @@
1
-
2
1
  require 'active_support/time'
3
2
 
4
3
  module Oj
data/lib/oj/bag.rb CHANGED
@@ -15,7 +15,7 @@ module Oj
15
15
  # @example Oj::Bag.new(:@x => 42, :@y => 57)
16
16
  # @param [Hash] args instance variable symbols and their values
17
17
  def initialize(args = {})
18
- args.each do |k,v|
18
+ args.each do |k, v|
19
19
  self.instance_variable_set(k, v)
20
20
  end
21
21
  end
@@ -26,6 +26,7 @@ module Oj
26
26
  # variable reader, otherwise false.
27
27
  def respond_to?(m)
28
28
  return true if super
29
+
29
30
  instance_variables.include?(:"@#{m}")
30
31
  end
31
32
 
@@ -37,8 +38,10 @@ module Oj
37
38
  # @raise [NoMethodError] if the instance variable is not defined.
38
39
  def method_missing(m, *args, &block)
39
40
  raise ArgumentError.new("wrong number of arguments (#{args.size} for 0) to method #{m}") unless args.nil? or args.empty?
41
+
40
42
  at_m = :"@#{m}"
41
43
  raise NoMethodError.new("undefined method #{m}", m) unless instance_variable_defined?(at_m)
44
+
42
45
  instance_variable_get(at_m)
43
46
  end
44
47
 
@@ -47,9 +50,11 @@ module Oj
47
50
  # @return [Boolean] true if each variable and value are the same, otherwise false.
48
51
  def eql?(other)
49
52
  return false if (other.nil? or self.class != other.class)
53
+
50
54
  ova = other.instance_variables
51
55
  iv = instance_variables
52
56
  return false if ova.size != iv.size
57
+
53
58
  iv.all? { |vid| instance_variable_get(vid) != other.instance_variable_get(vid) }
54
59
  end
55
60
  alias == eql?
@@ -65,6 +70,7 @@ module Oj
65
70
  classname = classname.to_s unless classname.is_a?(String)
66
71
  tokens = classname.split('::').map(&:to_sym)
67
72
  raise NameError.new("Invalid classname '#{classname}") if tokens.empty?
73
+
68
74
  m = Object
69
75
  tokens[0..-2].each do |sym|
70
76
  if m.const_defined?(sym)
data/lib/oj/easy_hash.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  module Oj
3
2
 
4
3
  # A Hash subclass that normalizes the hash keys to allow lookup by the
@@ -6,10 +5,6 @@ module Oj
6
5
  # that match the keys.
7
6
  class EasyHash < Hash
8
7
 
9
- # Initializes the instance to an empty Hash.
10
- def initialize()
11
- end
12
-
13
8
  # Replaces the Object.respond_to?() method.
14
9
  # @param [Symbol] m method symbol
15
10
  # @param [Boolean] include_all whether to include private and protected methods in the search
@@ -19,12 +14,14 @@ module Oj
19
14
  return true if super
20
15
  return true if has_key?(m)
21
16
  return true if has_key?(m.to_s)
17
+
22
18
  has_key?(m.to_sym)
23
19
  end
24
20
 
25
21
  def [](key)
26
22
  return fetch(key, nil) if has_key?(key)
27
23
  return fetch(key.to_s, nil) if has_key?(key.to_s)
24
+
28
25
  fetch(key.to_sym, nil)
29
26
  end
30
27
 
@@ -36,9 +33,11 @@ module Oj
36
33
  def method_missing(m, *args, &block)
37
34
  if m.to_s.end_with?('=')
38
35
  raise ArgumentError.new("wrong number of arguments (#{args.size} for 1 with #{m}) to method #{m}") if args.nil? or 1 != args.length
36
+
39
37
  m = m[0..-2]
40
38
  return store(m.to_s, args[0]) if has_key?(m.to_s)
41
39
  return store(m.to_sym, args[0]) if has_key?(m.to_sym)
40
+
42
41
  return store(m, args[0])
43
42
  else
44
43
  raise ArgumentError.new("wrong number of arguments (#{args.size} for 0 with #{m}) to method #{m}") unless args.nil? or args.empty?
data/lib/oj/error.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  module Oj
3
2
 
4
3
  # Inherit Error class from StandardError.
data/lib/oj/json.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  require 'ostruct'
3
2
  require 'oj/state'
4
3
 
@@ -51,7 +50,7 @@ module JSON
51
50
 
52
51
  def self.dump_default_options=(h)
53
52
  m = Oj::MimicDumpOption.new
54
- h.each do |k,v|
53
+ h.each do |k, v|
55
54
  m[k] = v
56
55
  end
57
56
  end
@@ -76,16 +75,19 @@ module JSON
76
75
  class Parser
77
76
  def initialize(src)
78
77
  raise TypeError.new("already initialized") unless @source.nil?
78
+
79
79
  @source = src
80
80
  end
81
81
 
82
82
  def source()
83
83
  raise TypeError.new("already initialized") if @source.nil?
84
+
84
85
  @source
85
86
  end
86
87
 
87
88
  def parse()
88
89
  raise TypeError.new("already initialized") if @source.nil?
90
+
89
91
  JSON.parse(@source)
90
92
  end
91
93
 
data/lib/oj/mimic.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  require 'bigdecimal'
3
2
  begin
4
3
  require 'ostruct'
@@ -64,6 +63,8 @@ module Oj
64
63
  self.store(:allow_nan, true)
65
64
  self.store(:quirks_mode, oo[:quirks_mode])
66
65
  self.store(:ascii_only, (:ascii == oo[:escape_mode]))
66
+
67
+ super
67
68
  end
68
69
 
69
70
  def []=(key, value)
@@ -102,6 +103,7 @@ module Oj
102
103
  def as_json(*)
103
104
  name = self.class.name.to_s
104
105
  raise JSON::JSONError, "Only named structs are supported!" if 0 == name.length
106
+
105
107
  { JSON.create_id => name, 't' => table }
106
108
  end
107
109
  end
@@ -232,6 +234,7 @@ module Oj
232
234
  def as_json(*)
233
235
  name = self.class.name.to_s
234
236
  raise JSON::JSONError, "Only named structs are supported!" if 0 == name.length
237
+
235
238
  { JSON.create_id => name, 'v' => values }
236
239
  end
237
240
  end
@@ -273,7 +276,6 @@ module Oj
273
276
  end
274
277
  end
275
278
  end
276
-
277
279
  end # self.mimic_loaded
278
280
 
279
281
  end # Oj
data/lib/oj/state.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  module JSON
3
2
  module Ext
4
3
  module Generator
@@ -59,6 +58,7 @@ module JSON
59
58
 
60
59
  def configure(opts)
61
60
  raise TypeError.new('expected a Hash') unless opts.respond_to?(:to_h)
61
+
62
62
  @attrs.merge!(opts.to_h)
63
63
  end
64
64
 
@@ -84,6 +84,7 @@ module JSON
84
84
  return true if super
85
85
  return true if has_key?(key)
86
86
  return true if has_key?(key.to_s)
87
+
87
88
  has_key?(key.to_sym)
88
89
  end
89
90
 
@@ -113,15 +114,17 @@ module JSON
113
114
  def method_missing(m, *args, &block)
114
115
  if m.to_s.end_with?('=')
115
116
  raise ArgumentError.new("wrong number of arguments (#{args.size} for 1 with #{m}) to method #{m}") if args.nil? or 1 != args.length
117
+
116
118
  m = m.to_s[0..-2]
117
119
  m = m.to_sym
118
120
  return @attrs.store(m, args[0])
119
- end
120
- if @attrs.has_key?(m.to_sym)
121
+ end
122
+ if @attrs.has_key?(m.to_sym)
121
123
  raise ArgumentError.new("wrong number of arguments (#{args.size} for 0 with #{m}) to method #{m}") unless args.nil? or args.empty?
124
+
122
125
  return @attrs[m.to_sym]
123
- end
124
- return @attrs.send(m, *args, &block)
126
+ end
127
+ return @attrs.send(m, *args, &block)
125
128
  end
126
129
 
127
130
  end # State
data/lib/oj/version.rb CHANGED
@@ -1,5 +1,4 @@
1
-
2
1
  module Oj
3
2
  # Current version of the module.
4
- VERSION = '3.14.2'
3
+ VERSION = '3.14.3'
5
4
  end
data/lib/oj.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  module Oj
3
2
  end
4
3
 
data/test/_test_active.rb CHANGED
@@ -71,6 +71,5 @@ class ActiveTest < Minitest::Test
71
71
 
72
72
  # Array of instances as json. (not Oj)
73
73
  assert_equal(%|[{"id":1,"first_name":"John","last_name":"Smith","email":"john@example.com"},{"id":2,"first_name":"Joan","last_name":"Smith","email":"joan@example.com"}]|, User.all.to_json)
74
-
75
74
  end
76
75
  end
@@ -91,6 +91,5 @@ class ActiveTest < Minitest::Test
91
91
  }
92
92
  ]
93
93
  |, User.all.to_json)
94
-
95
94
  end
96
95
  end
@@ -95,7 +95,6 @@ class MimicRails < Minitest::Test
95
95
  puts "*** category.as_json() #{category.as_json()}"
96
96
  puts "*** JSON.dump(serializer) #{JSON.dump(category)}"
97
97
  puts "*** Oj.dump(serializer) #{Oj.dump(category)}"
98
-
99
98
  end
100
99
 
101
100
  def test_dump_object_array