oj 3.11.0 → 3.11.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -1
  3. data/ext/oj/buf.h +34 -38
  4. data/ext/oj/cache8.c +59 -62
  5. data/ext/oj/cache8.h +8 -7
  6. data/ext/oj/circarray.c +33 -35
  7. data/ext/oj/circarray.h +11 -9
  8. data/ext/oj/code.c +170 -174
  9. data/ext/oj/code.h +21 -20
  10. data/ext/oj/compat.c +159 -166
  11. data/ext/oj/custom.c +802 -851
  12. data/ext/oj/dump.c +766 -778
  13. data/ext/oj/dump.h +49 -51
  14. data/ext/oj/dump_compat.c +1 -0
  15. data/ext/oj/dump_leaf.c +116 -157
  16. data/ext/oj/dump_object.c +609 -628
  17. data/ext/oj/dump_strict.c +318 -327
  18. data/ext/oj/encode.h +3 -4
  19. data/ext/oj/err.c +39 -25
  20. data/ext/oj/err.h +24 -15
  21. data/ext/oj/extconf.rb +2 -1
  22. data/ext/oj/fast.c +1008 -1038
  23. data/ext/oj/hash.c +62 -66
  24. data/ext/oj/hash.h +7 -6
  25. data/ext/oj/hash_test.c +450 -443
  26. data/ext/oj/mimic_json.c +413 -402
  27. data/ext/oj/object.c +559 -528
  28. data/ext/oj/odd.c +123 -128
  29. data/ext/oj/odd.h +27 -25
  30. data/ext/oj/oj.c +1131 -924
  31. data/ext/oj/oj.h +286 -298
  32. data/ext/oj/parse.c +938 -930
  33. data/ext/oj/parse.h +70 -69
  34. data/ext/oj/rails.c +836 -839
  35. data/ext/oj/rails.h +7 -7
  36. data/ext/oj/reader.c +135 -140
  37. data/ext/oj/reader.h +66 -79
  38. data/ext/oj/resolve.c +43 -43
  39. data/ext/oj/resolve.h +3 -2
  40. data/ext/oj/rxclass.c +67 -68
  41. data/ext/oj/rxclass.h +12 -10
  42. data/ext/oj/saj.c +451 -479
  43. data/ext/oj/scp.c +93 -103
  44. data/ext/oj/sparse.c +770 -730
  45. data/ext/oj/stream_writer.c +120 -149
  46. data/ext/oj/strict.c +71 -86
  47. data/ext/oj/string_writer.c +198 -243
  48. data/ext/oj/trace.c +29 -33
  49. data/ext/oj/trace.h +14 -11
  50. data/ext/oj/util.c +103 -103
  51. data/ext/oj/util.h +3 -2
  52. data/ext/oj/val_stack.c +47 -47
  53. data/ext/oj/val_stack.h +79 -86
  54. data/ext/oj/wab.c +291 -309
  55. data/lib/oj/bag.rb +1 -0
  56. data/lib/oj/easy_hash.rb +5 -4
  57. data/lib/oj/mimic.rb +0 -12
  58. data/lib/oj/version.rb +1 -1
  59. data/test/activerecord/result_test.rb +7 -2
  60. data/test/foo.rb +35 -32
  61. data/test/helper.rb +10 -0
  62. data/test/json_gem/json_generator_test.rb +15 -3
  63. data/test/json_gem/test_helper.rb +8 -0
  64. data/test/test_compat.rb +2 -2
  65. data/test/test_generate.rb +21 -0
  66. data/test/test_hash.rb +10 -0
  67. data/test/test_scp.rb +1 -1
  68. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a9281dd44fc3a292de885df89aea20d98fc76c658a6bdc5291af8a1823c521c
4
- data.tar.gz: 2aaeeee785c97a6d11f5188fe285e2dc0cd89df24408b08f9de537e3c5f602e2
3
+ metadata.gz: 964a9272c141179cf6f61317e89bc8dab43184b0d143355dc2212b89f123ccad
4
+ data.tar.gz: 53a3b3cd773a87953cec71a649f491682b022c13d56ebcc4eb5653bc9cbb560e
5
5
  SHA512:
6
- metadata.gz: '0787f0efdc46414a5b228aab320eb4c41242100da6f6e2598fcb6afaa08e9eeaaf0c524dce001899aac0e4015c252ef1d4dc399a6eea68bef32f18e9268f018a'
7
- data.tar.gz: 3298dbc834012e9981bda042e827b572ef17a0a1a827a8f07e4bc921df5ec940cdaa5f41f7c8f41a9571fc4fcda86c1fd81c96b214754bad33a3e15d66786cee
6
+ metadata.gz: 947dad8a5cfc4d5adb3efbd40218439c984ae6084ef304f6b3012e26e047438a03b6f149b7c224982fc8fd0a699b56fa0e6b9a174e8b00d6567dd911f601f227
7
+ data.tar.gz: 536b05addb483b631883ccfb9269c6cd93b3e988ea9845021be3e2383a708974ff4e63a9d64a1a76bd8a9934969c42aa16495eccd75e88b7cf4704f619e7b693
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # [![{}j](http://www.ohler.com/dev/images/oj_comet_64.svg)](http://www.ohler.com/oj) gem
2
2
 
3
- [![Build Status](https://img.shields.io/travis/ohler55/oj/master.svg?logo=travis)](http://travis-ci.org/ohler55/oj?branch=master) [![AppVeyor](https://img.shields.io/appveyor/ci/ohler55/oj/master.svg?logo=appveyor)](https://ci.appveyor.com/project/ohler55/oj) ![Gem](https://img.shields.io/gem/v/oj.svg) ![Gem](https://img.shields.io/gem/dt/oj.svg) [![SemVer compatibility](https://api.dependabot.com/badges/compatibility_score?dependency-name=oj&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=oj&package-manager=bundler&version-scheme=semver) [![TideLift](https://tidelift.com/badges/github/ohler55/oj)](https://tidelift.com/subscription/pkg/rubygems-oj?utm_source=rubygems-oj&utm_medium=referral&utm_campaign=readme)
3
+ [![Build Status](https://img.shields.io/travis/ohler55/oj/master.svg?logo=travis)](http://travis-ci.org/ohler55/oj?branch=master) ![Gem](https://img.shields.io/gem/v/oj.svg) ![Gem](https://img.shields.io/gem/dt/oj.svg) [![SemVer compatibility](https://api.dependabot.com/badges/compatibility_score?dependency-name=oj&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=oj&package-manager=bundler&version-scheme=semver) [![TideLift](https://tidelift.com/badges/github/ohler55/oj)](https://tidelift.com/subscription/pkg/rubygems-oj?utm_source=rubygems-oj&utm_medium=referral&utm_campaign=readme)
4
4
 
5
5
  A *fast* JSON parser and Object marshaller as a Ruby gem.
6
6
 
@@ -102,3 +102,4 @@ Follow [@peterohler on Twitter](http://twitter.com/peterohler) for announcements
102
102
  + Provide a Pull Request off the `develop` branch.
103
103
  + Report a bug
104
104
  + Suggest an idea
105
+ + Code is now formatted with the clang-format tool with the configuration file in the root of the repo.
data/ext/oj/buf.h CHANGED
@@ -1,4 +1,5 @@
1
1
  // Copyright (c) 2011 Peter Ohler. All rights reserved.
2
+ // Licensed under the MIT License. See LICENSE file in the project root for license details.
2
3
 
3
4
  #ifndef OJ_BUF_H
4
5
  #define OJ_BUF_H
@@ -6,66 +7,61 @@
6
7
  #include "ruby.h"
7
8
 
8
9
  typedef struct _buf {
9
- char *head;
10
- char *end;
11
- char *tail;
12
- char base[1024];
13
- } *Buf;
10
+ char *head;
11
+ char *end;
12
+ char *tail;
13
+ char base[1024];
14
+ } * Buf;
14
15
 
15
- inline static void
16
- buf_init(Buf buf) {
16
+ inline static void buf_init(Buf buf) {
17
17
  buf->head = buf->base;
18
- buf->end = buf->base + sizeof(buf->base) - 1;
18
+ buf->end = buf->base + sizeof(buf->base) - 1;
19
19
  buf->tail = buf->head;
20
20
  }
21
21
 
22
- inline static void
23
- buf_cleanup(Buf buf) {
22
+ inline static void buf_cleanup(Buf buf) {
24
23
  if (buf->base != buf->head) {
25
24
  xfree(buf->head);
26
25
  }
27
26
  }
28
27
 
29
- inline static size_t
30
- buf_len(Buf buf) {
28
+ inline static size_t buf_len(Buf buf) {
31
29
  return buf->tail - buf->head;
32
30
  }
33
31
 
34
- inline static void
35
- buf_append_string(Buf buf, const char *s, size_t slen) {
32
+ inline static void buf_append_string(Buf buf, const char *s, size_t slen) {
36
33
  if (buf->end <= buf->tail + slen) {
37
- size_t len = buf->end - buf->head;
38
- size_t toff = buf->tail - buf->head;
39
- size_t new_len = len + slen + len / 2;
34
+ size_t len = buf->end - buf->head;
35
+ size_t toff = buf->tail - buf->head;
36
+ size_t new_len = len + slen + len / 2;
40
37
 
41
- if (buf->base == buf->head) {
42
- buf->head = ALLOC_N(char, new_len);
43
- memcpy(buf->head, buf->base, len);
44
- } else {
45
- REALLOC_N(buf->head, char, new_len);
46
- }
47
- buf->tail = buf->head + toff;
48
- buf->end = buf->head + new_len - 1;
38
+ if (buf->base == buf->head) {
39
+ buf->head = ALLOC_N(char, new_len);
40
+ memcpy(buf->head, buf->base, len);
41
+ } else {
42
+ REALLOC_N(buf->head, char, new_len);
43
+ }
44
+ buf->tail = buf->head + toff;
45
+ buf->end = buf->head + new_len - 1;
49
46
  }
50
47
  memcpy(buf->tail, s, slen);
51
48
  buf->tail += slen;
52
49
  }
53
50
 
54
- inline static void
55
- buf_append(Buf buf, char c) {
51
+ inline static void buf_append(Buf buf, char c) {
56
52
  if (buf->end <= buf->tail) {
57
- size_t len = buf->end - buf->head;
58
- size_t toff = buf->tail - buf->head;
59
- size_t new_len = len + len / 2;
53
+ size_t len = buf->end - buf->head;
54
+ size_t toff = buf->tail - buf->head;
55
+ size_t new_len = len + len / 2;
60
56
 
61
- if (buf->base == buf->head) {
62
- buf->head = ALLOC_N(char, new_len);
63
- memcpy(buf->head, buf->base, len);
64
- } else {
65
- REALLOC_N(buf->head, char, new_len);
66
- }
67
- buf->tail = buf->head + toff;
68
- buf->end = buf->head + new_len - 1;
57
+ if (buf->base == buf->head) {
58
+ buf->head = ALLOC_N(char, new_len);
59
+ memcpy(buf->head, buf->base, len);
60
+ } else {
61
+ REALLOC_N(buf->head, char, new_len);
62
+ }
63
+ buf->tail = buf->head + toff;
64
+ buf->end = buf->head + new_len - 1;
69
65
  }
70
66
  *buf->tail = c;
71
67
  buf->tail++;
data/ext/oj/cache8.c CHANGED
@@ -1,107 +1,104 @@
1
+ // Copyright (c) 2011 Peter Ohler. All rights reserved.
2
+ // Licensed under the MIT License. See LICENSE file in the project root for license details.
3
+
4
+ #include "cache8.h"
1
5
 
2
- #include <stdlib.h>
3
6
  #include <errno.h>
7
+ #include <stdarg.h>
4
8
  #include <stdio.h>
9
+ #include <stdlib.h>
5
10
  #include <string.h>
6
- #include <stdarg.h>
7
11
 
8
12
  #include "ruby.h"
9
- #include "cache8.h"
10
13
 
11
- #define BITS 4
12
- #define MASK 0x000000000000000FULL
13
- #define SLOT_CNT 16
14
- #define DEPTH 16
14
+ #define BITS 4
15
+ #define MASK 0x000000000000000FULL
16
+ #define SLOT_CNT 16
17
+ #define DEPTH 16
15
18
 
16
19
  typedef union {
17
- struct _cache8 *child;
18
- slot_t value;
20
+ struct _cache8 *child;
21
+ slot_t value;
19
22
  } Bucket;
20
23
 
21
24
  struct _cache8 {
22
- Bucket buckets[SLOT_CNT];
25
+ Bucket buckets[SLOT_CNT];
23
26
  };
24
27
 
25
- static void cache8_delete(Cache8 cache, int depth);
26
- static void slot_print(Cache8 cache, sid_t key, unsigned int depth);
28
+ static void cache8_delete(Cache8 cache, int depth);
29
+ static void slot_print(Cache8 cache, sid_t key, unsigned int depth);
30
+
31
+ void oj_cache8_new(Cache8 *cache) {
32
+ Bucket *b;
33
+ int i;
27
34
 
28
- void
29
- oj_cache8_new(Cache8 *cache) {
30
- Bucket *b;
31
- int i;
32
-
33
35
  *cache = ALLOC(struct _cache8);
34
36
  for (i = SLOT_CNT, b = (*cache)->buckets; 0 < i; i--, b++) {
35
- b->value = 0;
37
+ b->value = 0;
36
38
  }
37
39
  }
38
40
 
39
- void
40
- oj_cache8_delete(Cache8 cache) {
41
- cache8_delete(cache, 0);
42
- }
41
+ void oj_cache8_delete(Cache8 cache) { cache8_delete(cache, 0); }
43
42
 
44
- static void
45
- cache8_delete(Cache8 cache, int depth) {
46
- Bucket *b;
47
- unsigned int i;
43
+ static void cache8_delete(Cache8 cache, int depth) {
44
+ Bucket * b;
45
+ unsigned int i;
48
46
 
49
47
  for (i = 0, b = cache->buckets; i < SLOT_CNT; i++, b++) {
50
- if (0 != b->child) {
51
- if (DEPTH - 1 != depth) {
52
- cache8_delete(b->child, depth + 1);
53
- }
54
- }
48
+ if (0 != b->child) {
49
+ if (DEPTH - 1 != depth) {
50
+ cache8_delete(b->child, depth + 1);
51
+ }
52
+ }
55
53
  }
56
54
  xfree(cache);
57
55
  }
58
56
 
59
- slot_t
60
- oj_cache8_get(Cache8 cache, sid_t key, slot_t **slot) {
61
- Bucket *b;
62
- int i;
63
- sid_t k8 = (sid_t)key;
64
- sid_t k;
65
-
57
+ slot_t oj_cache8_get(Cache8 cache, sid_t key, slot_t **slot) {
58
+ Bucket *b;
59
+ int i;
60
+ sid_t k8 = (sid_t)key;
61
+ sid_t k;
62
+
66
63
  for (i = 64 - BITS; 0 < i; i -= BITS) {
67
- k = (k8 >> i) & MASK;
68
- b = cache->buckets + k;
69
- if (0 == b->child) {
70
- oj_cache8_new(&b->child);
71
- }
72
- cache = b->child;
64
+ k = (k8 >> i) & MASK;
65
+ b = cache->buckets + k;
66
+ if (0 == b->child) {
67
+ oj_cache8_new(&b->child);
68
+ }
69
+ cache = b->child;
73
70
  }
74
71
  *slot = &(cache->buckets + (k8 & MASK))->value;
75
72
 
76
73
  return **slot;
77
74
  }
78
75
 
79
- void
80
- oj_cache8_print(Cache8 cache) {
76
+ void oj_cache8_print(Cache8 cache) {
81
77
  /*printf("-------------------------------------------\n"); */
82
78
  slot_print(cache, 0, 0);
83
79
  }
84
80
 
85
- static void
86
- slot_print(Cache8 c, sid_t key, unsigned int depth) {
87
- Bucket *b;
88
- unsigned int i;
89
- sid_t k8 = (sid_t)key;
90
- sid_t k;
81
+ static void slot_print(Cache8 c, sid_t key, unsigned int depth) {
82
+ Bucket * b;
83
+ unsigned int i;
84
+ sid_t k8 = (sid_t)key;
85
+ sid_t k;
91
86
 
92
87
  for (i = 0, b = c->buckets; i < SLOT_CNT; i++, b++) {
93
- if (0 != b->child) {
94
- k = (k8 << BITS) | i;
95
- /*printf("*** key: 0x%016llx depth: %u i: %u\n", k, depth, i); */
96
- if (DEPTH - 1 == depth) {
88
+ if (0 != b->child) {
89
+ k = (k8 << BITS) | i;
90
+ /*printf("*** key: 0x%016llx depth: %u i: %u\n", k, depth, i); */
91
+ if (DEPTH - 1 == depth) {
97
92
  #if IS_WINDOWS
98
- printf("0x%016lx: %4lu\n", (long unsigned int)k, (long unsigned int)b->value);
93
+ printf("0x%016lx: %4lu\n", (long unsigned int)k,
94
+ (long unsigned int)b->value);
99
95
  #else
100
- printf("0x%016llx: %4llu\n", (long long unsigned int)k, (long long unsigned int)b->value);
96
+ printf("0x%016llx: %4llu\n", (long long unsigned int)k,
97
+ (long long unsigned int)b->value);
101
98
  #endif
102
- } else {
103
- slot_print(b->child, k, depth + 1);
104
- }
105
- }
99
+ } else {
100
+ slot_print(b->child, k, depth + 1);
101
+ }
102
+ }
106
103
  }
107
104
  }
data/ext/oj/cache8.h CHANGED
@@ -1,4 +1,5 @@
1
1
  // Copyright (c) 2011 Peter Ohler. All rights reserved.
2
+ // Licensed under the MIT License. See LICENSE file in the project root for license details.
2
3
 
3
4
  #ifndef OJ_CACHE8_H
4
5
  #define OJ_CACHE8_H
@@ -6,15 +7,15 @@
6
7
  #include "ruby.h"
7
8
  #include "stdint.h"
8
9
 
9
- typedef struct _cache8 *Cache8;
10
- typedef uint64_t slot_t;
11
- typedef uint64_t sid_t;
10
+ typedef struct _cache8 *Cache8;
11
+ typedef uint64_t slot_t;
12
+ typedef uint64_t sid_t;
12
13
 
13
- extern void oj_cache8_new(Cache8 *cache);
14
- extern void oj_cache8_delete(Cache8 cache);
14
+ extern void oj_cache8_new(Cache8 *cache);
15
+ extern void oj_cache8_delete(Cache8 cache);
15
16
 
16
- extern slot_t oj_cache8_get(Cache8 cache, sid_t key, slot_t **slot);
17
+ extern slot_t oj_cache8_get(Cache8 cache, sid_t key, slot_t **slot);
17
18
 
18
- extern void oj_cache8_print(Cache8 cache);
19
+ extern void oj_cache8_print(Cache8 cache);
19
20
 
20
21
  #endif /* OJ_CACHE8_H */
data/ext/oj/circarray.c CHANGED
@@ -1,64 +1,62 @@
1
1
  // Copyright (c) 2012 Peter Ohler. All rights reserved.
2
+ // Licensed under the MIT License. See LICENSE file in the project root for license details.
2
3
 
3
4
  #include "circarray.h"
4
5
 
5
- CircArray
6
- oj_circ_array_new() {
7
- CircArray ca;
6
+ CircArray oj_circ_array_new() {
7
+ CircArray ca;
8
8
 
9
9
  if (0 == (ca = ALLOC(struct _circArray))) {
10
- rb_raise(rb_eNoMemError, "not enough memory\n");
10
+ rb_raise(rb_eNoMemError, "not enough memory\n");
11
11
  }
12
12
  ca->objs = ca->obj_array;
13
13
  ca->size = sizeof(ca->obj_array) / sizeof(VALUE);
14
- ca->cnt = 0;
14
+ ca->cnt = 0;
15
15
 
16
16
  return ca;
17
17
  }
18
18
 
19
- void
20
- oj_circ_array_free(CircArray ca) {
19
+ void oj_circ_array_free(CircArray ca) {
21
20
  if (ca->objs != ca->obj_array) {
22
- xfree(ca->objs);
21
+ xfree(ca->objs);
23
22
  }
24
23
  xfree(ca);
25
24
  }
26
25
 
27
- void
28
- oj_circ_array_set(CircArray ca, VALUE obj, unsigned long id) {
26
+ void oj_circ_array_set(CircArray ca, VALUE obj, unsigned long id) {
29
27
  if (0 < id && 0 != ca) {
30
- unsigned long i;
31
-
32
- if (ca->size < id) {
33
- unsigned long cnt = id + 512;
34
-
35
- if (ca->objs == ca->obj_array) {
36
- if (0 == (ca->objs = ALLOC_N(VALUE, cnt))) {
37
- rb_raise(rb_eNoMemError, "not enough memory\n");
38
- }
39
- memcpy(ca->objs, ca->obj_array, sizeof(VALUE) * ca->cnt);
40
- } else {
41
- REALLOC_N(ca->objs, VALUE, cnt);
42
- }
43
- ca->size = cnt;
44
- }
45
- id--;
46
- for (i = ca->cnt; i < id; i++) {
47
- ca->objs[i] = Qnil;
48
- }
49
- ca->objs[id] = obj;
50
- if (ca->cnt <= id) {
51
- ca->cnt = id + 1;
52
- }
28
+ unsigned long i;
29
+
30
+ if (ca->size < id) {
31
+ unsigned long cnt = id + 512;
32
+
33
+ if (ca->objs == ca->obj_array) {
34
+ if (0 == (ca->objs = ALLOC_N(VALUE, cnt))) {
35
+ rb_raise(rb_eNoMemError, "not enough memory\n");
36
+ }
37
+ memcpy(ca->objs, ca->obj_array, sizeof(VALUE) * ca->cnt);
38
+ } else {
39
+ REALLOC_N(ca->objs, VALUE, cnt);
40
+ }
41
+ ca->size = cnt;
42
+ }
43
+ id--;
44
+ for (i = ca->cnt; i < id; i++) {
45
+ ca->objs[i] = Qnil;
46
+ }
47
+ ca->objs[id] = obj;
48
+ if (ca->cnt <= id) {
49
+ ca->cnt = id + 1;
50
+ }
53
51
  }
54
52
  }
55
53
 
56
54
  VALUE
57
55
  oj_circ_array_get(CircArray ca, unsigned long id) {
58
- VALUE obj = Qnil;
56
+ VALUE obj = Qnil;
59
57
 
60
58
  if (id <= ca->cnt && 0 != ca) {
61
- obj = ca->objs[id - 1];
59
+ obj = ca->objs[id - 1];
62
60
  }
63
61
  return obj;
64
62
  }
data/ext/oj/circarray.h CHANGED
@@ -1,4 +1,6 @@
1
1
  // Copyright (c) 2012 Peter Ohler. All rights reserved.
2
+ // Licensed under the MIT License. See LICENSE file in the project root for
3
+ // license details.
2
4
 
3
5
  #ifndef OJ_CIRCARRAY_H
4
6
  #define OJ_CIRCARRAY_H
@@ -6,15 +8,15 @@
6
8
  #include "ruby.h"
7
9
 
8
10
  typedef struct _circArray {
9
- VALUE obj_array[1024];
10
- VALUE *objs;
11
- unsigned long size; // allocated size or initial array size
12
- unsigned long cnt;
13
- } *CircArray;
11
+ VALUE obj_array[1024];
12
+ VALUE * objs;
13
+ unsigned long size; // allocated size or initial array size
14
+ unsigned long cnt;
15
+ } * CircArray;
14
16
 
15
- extern CircArray oj_circ_array_new(void);
16
- extern void oj_circ_array_free(CircArray ca);
17
- extern void oj_circ_array_set(CircArray ca, VALUE obj, unsigned long id);
18
- extern VALUE oj_circ_array_get(CircArray ca, unsigned long id);
17
+ extern CircArray oj_circ_array_new(void);
18
+ extern void oj_circ_array_free(CircArray ca);
19
+ extern void oj_circ_array_set(CircArray ca, VALUE obj, unsigned long id);
20
+ extern VALUE oj_circ_array_get(CircArray ca, unsigned long id);
19
21
 
20
22
  #endif /* OJ_CIRCARRAY_H */