oj 3.13.17 → 3.16.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +77 -0
  3. data/README.md +4 -2
  4. data/ext/oj/buf.h +7 -6
  5. data/ext/oj/cache.c +29 -26
  6. data/ext/oj/cache.h +3 -2
  7. data/ext/oj/cache8.c +10 -9
  8. data/ext/oj/circarray.c +7 -5
  9. data/ext/oj/circarray.h +2 -2
  10. data/ext/oj/code.c +5 -12
  11. data/ext/oj/code.h +2 -2
  12. data/ext/oj/compat.c +20 -60
  13. data/ext/oj/custom.c +44 -96
  14. data/ext/oj/debug.c +3 -9
  15. data/ext/oj/dump.c +69 -39
  16. data/ext/oj/dump.h +1 -4
  17. data/ext/oj/dump_compat.c +557 -592
  18. data/ext/oj/dump_leaf.c +3 -5
  19. data/ext/oj/dump_object.c +42 -48
  20. data/ext/oj/dump_strict.c +10 -22
  21. data/ext/oj/encoder.c +1 -1
  22. data/ext/oj/err.c +2 -13
  23. data/ext/oj/err.h +9 -12
  24. data/ext/oj/extconf.rb +16 -6
  25. data/ext/oj/fast.c +76 -106
  26. data/ext/oj/intern.c +63 -51
  27. data/ext/oj/intern.h +3 -7
  28. data/ext/oj/mem.c +318 -0
  29. data/ext/oj/mem.h +53 -0
  30. data/ext/oj/mimic_json.c +43 -30
  31. data/ext/oj/object.c +61 -70
  32. data/ext/oj/odd.c +8 -6
  33. data/ext/oj/odd.h +4 -4
  34. data/ext/oj/oj.c +243 -205
  35. data/ext/oj/oj.h +82 -78
  36. data/ext/oj/parse.c +123 -188
  37. data/ext/oj/parse.h +23 -24
  38. data/ext/oj/parser.c +103 -63
  39. data/ext/oj/parser.h +19 -9
  40. data/ext/oj/rails.c +68 -92
  41. data/ext/oj/reader.c +10 -15
  42. data/ext/oj/reader.h +4 -2
  43. data/ext/oj/resolve.c +3 -4
  44. data/ext/oj/rxclass.c +6 -5
  45. data/ext/oj/rxclass.h +1 -1
  46. data/ext/oj/saj.c +10 -9
  47. data/ext/oj/saj2.c +74 -92
  48. data/ext/oj/saj2.h +23 -0
  49. data/ext/oj/scp.c +3 -14
  50. data/ext/oj/sparse.c +22 -70
  51. data/ext/oj/stream_writer.c +43 -35
  52. data/ext/oj/strict.c +20 -52
  53. data/ext/oj/string_writer.c +60 -34
  54. data/ext/oj/trace.h +31 -4
  55. data/ext/oj/usual.c +125 -150
  56. data/ext/oj/usual.h +69 -0
  57. data/ext/oj/util.h +1 -1
  58. data/ext/oj/val_stack.c +14 -3
  59. data/ext/oj/val_stack.h +8 -7
  60. data/ext/oj/wab.c +25 -57
  61. data/lib/oj/active_support_helper.rb +1 -3
  62. data/lib/oj/bag.rb +7 -1
  63. data/lib/oj/easy_hash.rb +4 -5
  64. data/lib/oj/error.rb +0 -1
  65. data/lib/oj/json.rb +162 -150
  66. data/lib/oj/mimic.rb +6 -2
  67. data/lib/oj/state.rb +9 -6
  68. data/lib/oj/version.rb +1 -2
  69. data/lib/oj.rb +2 -0
  70. data/pages/Compatibility.md +1 -1
  71. data/pages/InstallOptions.md +20 -0
  72. data/pages/Options.md +10 -0
  73. data/test/_test_active.rb +8 -9
  74. data/test/_test_active_mimic.rb +7 -8
  75. data/test/_test_mimic_rails.rb +17 -20
  76. data/test/activerecord/result_test.rb +5 -6
  77. data/test/files.rb +15 -15
  78. data/test/foo.rb +9 -72
  79. data/test/helper.rb +11 -8
  80. data/test/isolated/shared.rb +3 -2
  81. data/test/json_gem/json_addition_test.rb +2 -2
  82. data/test/json_gem/json_common_interface_test.rb +8 -6
  83. data/test/json_gem/json_encoding_test.rb +0 -0
  84. data/test/json_gem/json_ext_parser_test.rb +1 -0
  85. data/test/json_gem/json_fixtures_test.rb +3 -2
  86. data/test/json_gem/json_generator_test.rb +53 -37
  87. data/test/json_gem/json_generic_object_test.rb +11 -11
  88. data/test/json_gem/json_parser_test.rb +47 -47
  89. data/test/json_gem/json_string_matching_test.rb +9 -9
  90. data/test/json_gem/test_helper.rb +7 -3
  91. data/test/mem.rb +13 -12
  92. data/test/perf.rb +21 -26
  93. data/test/perf_compat.rb +31 -33
  94. data/test/perf_dump.rb +28 -28
  95. data/test/perf_fast.rb +80 -82
  96. data/test/perf_file.rb +27 -29
  97. data/test/perf_object.rb +65 -69
  98. data/test/perf_once.rb +12 -11
  99. data/test/perf_parser.rb +42 -48
  100. data/test/perf_saj.rb +46 -54
  101. data/test/perf_scp.rb +57 -69
  102. data/test/perf_simple.rb +41 -39
  103. data/test/perf_strict.rb +68 -70
  104. data/test/perf_wab.rb +67 -69
  105. data/test/prec.rb +5 -5
  106. data/test/sample/change.rb +0 -1
  107. data/test/sample/dir.rb +0 -1
  108. data/test/sample/doc.rb +0 -1
  109. data/test/sample/file.rb +0 -1
  110. data/test/sample/group.rb +0 -1
  111. data/test/sample/hasprops.rb +0 -1
  112. data/test/sample/layer.rb +0 -1
  113. data/test/sample/rect.rb +0 -1
  114. data/test/sample/shape.rb +0 -1
  115. data/test/sample/text.rb +0 -1
  116. data/test/sample.rb +16 -16
  117. data/test/sample_json.rb +8 -8
  118. data/test/test_compat.rb +80 -53
  119. data/test/test_custom.rb +73 -51
  120. data/test/test_debian.rb +7 -10
  121. data/test/test_fast.rb +86 -90
  122. data/test/test_file.rb +28 -35
  123. data/test/test_gc.rb +16 -5
  124. data/test/test_generate.rb +5 -5
  125. data/test/test_hash.rb +4 -4
  126. data/test/test_integer_range.rb +9 -9
  127. data/test/test_null.rb +20 -20
  128. data/test/test_object.rb +94 -96
  129. data/test/test_parser.rb +6 -22
  130. data/test/test_parser_debug.rb +27 -0
  131. data/test/test_parser_saj.rb +61 -22
  132. data/test/test_parser_usual.rb +16 -6
  133. data/test/test_rails.rb +2 -2
  134. data/test/test_saj.rb +10 -8
  135. data/test/test_scp.rb +37 -39
  136. data/test/test_strict.rb +40 -32
  137. data/test/test_various.rb +148 -100
  138. data/test/test_wab.rb +48 -44
  139. data/test/test_writer.rb +47 -47
  140. data/test/tests.rb +13 -4
  141. data/test/tests_mimic.rb +12 -3
  142. data/test/tests_mimic_addition.rb +12 -3
  143. metadata +36 -27
  144. data/test/activesupport4/decoding_test.rb +0 -108
  145. data/test/activesupport4/encoding_test.rb +0 -531
  146. data/test/activesupport4/test_helper.rb +0 -41
  147. data/test/activesupport5/abstract_unit.rb +0 -45
  148. data/test/activesupport5/decoding_test.rb +0 -133
  149. data/test/activesupport5/encoding_test.rb +0 -500
  150. data/test/activesupport5/encoding_test_cases.rb +0 -98
  151. data/test/activesupport5/test_helper.rb +0 -72
  152. data/test/activesupport5/time_zone_test_helpers.rb +0 -39
  153. data/test/bar.rb +0 -11
  154. data/test/baz.rb +0 -16
  155. data/test/bug.rb +0 -16
  156. data/test/zoo.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2ba7c6f3821ac59250c2893d01269cd45bb2ec5eb4b06babccf480a07fb8862
4
- data.tar.gz: 666b047d4ac8f5637e6b1e8ca995bceb105197eabc4664936cc72986280684c2
3
+ metadata.gz: 3a6b15904386e7010fa071ecc27b8f3a6d5023c8162ea7042fc39e29c373a20a
4
+ data.tar.gz: b862e59cff0ba3a15eadec34fe807d5893c9c1d1e9fcce01ced66ab28e642181
5
5
  SHA512:
6
- metadata.gz: 85005fe527745233220a680adf9bf3c24bb711abbe6b6758ccff236398c7f1218c9bc586eea7954388548772b17073e5540595d160948e19fffb94e535363ea4
7
- data.tar.gz: 5b8b227c2d7e8156adb1adccff99ca18a8f2735ec3b7af9f8ee3f2b747427459c497ae738fe6c941d3df6e5131342677b1e8c08f208edeb7988697f80499339d
6
+ metadata.gz: f186fb40ebcc3792b4949f81ce3b2efb22bee9dce9b44785eeca37cc27e25b79e8afa4fc5872232001d28a3d0b279fc222d5f7d2f8aaa091fe3a135246139b64
7
+ data.tar.gz: 9c1536bfc15eb3fe02e92d803417ef1ccce5084036aaf8df5ae2b61995a429ab8ae00be5e9b7c79e11839d781c67523ed5bc534df36a40b59dcc61db6551158f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,82 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 3.16.3 - 2023-12-11
4
+
5
+ - Fixed the gemspec to allow earlier versions of the bigdecimal gem.
6
+
7
+ ## 3.16.2 - 2023-12-06
8
+
9
+ - Fixed documentation formatting.
10
+
11
+ - Added option to the "usual" parser to raise an error on an empty input string.
12
+
13
+ ## 3.16.1 - 2023-09-01
14
+
15
+ - Fixed exception type on number parsing. (thank you @jasonpenny)
16
+
17
+ ## 3.16.0 - 2023-08-16
18
+
19
+ - Added the `float_format` option.
20
+
21
+ - Expanded the `max_nesting` option to allow integer values as well as
22
+ the previous boolean (true or nil).
23
+
24
+ - Skip nesting tests with Truffle Ruby in the json gem tests.
25
+
26
+ ## 3.15.1 - 2023-07-30
27
+
28
+ - Add protection against some using `require 'oj/json`, an internal file.
29
+
30
+ - Fixed non-json errors when in compat mode.
31
+
32
+ ## 3.15.0 - 2023-06-02
33
+
34
+ - Added `omit_null_byte` option when dumping.
35
+
36
+ ## 3.14.3 - 2023-04-07
37
+
38
+ - Fixed compat parse with optimized Hash when parsing a JSON::GenericObject.
39
+
40
+ ## 3.14.2 - 2023-02-10
41
+
42
+ - Fixed check for \0 in strings.
43
+
44
+ ## 3.14.1 - 2023-02-01
45
+
46
+ - Fixed issue with uninitialized handler for Oj::Parser::Saj.
47
+
48
+ - Fixed hang on unterminated string with a \0 byte in parse.c.
49
+
50
+ ## 3.14.0 - 2023-01-30
51
+
52
+ - Tracing is now a compile time option giving a 15 to 20% performance boost.
53
+
54
+ - Some cleanup in the fast parser.
55
+
56
+ ## 3.13.23 - 2022-11-06
57
+
58
+ - Fixed issue with Oj::Parser extension regarding GC timeing.
59
+
60
+ ## 3.13.22 - 2022-11-01
61
+
62
+ - Reorganized Oj::Parser code to allow for parser extensions in C.
63
+
64
+ ## 3.13.21 - 2022-08-19
65
+
66
+ - Bug parsing big numbers fixed in the SAJ parser.
67
+
68
+ ## 3.13.20 - 2022-08-07
69
+
70
+ - SSE4 made optional with a `--with-sse42` flag to the compile.
71
+
72
+ ## 3.13.19 - 2022-07-29
73
+
74
+ - TruffleRuby issues resolved.
75
+
76
+ ## 3.13.18 - 2022-07-25
77
+
78
+ - Fixed SSE detection at run time.
79
+
3
80
  ## 3.13.17 - 2022-07-15
4
81
 
5
82
  - Fixed Oj::Parser to detect unterminated arrays and objects.
data/README.md CHANGED
@@ -1,9 +1,8 @@
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/github/workflow/status/ohler55/oj/CI?logo=github)](https://github.com/ohler55/oj/actions/workflows/CI.yml)
3
+ [![CI](https://github.com/ohler55/oj/actions/workflows/CI.yml/badge.svg)](https://github.com/ohler55/oj/actions/workflows/CI.yml)
4
4
  ![Gem](https://img.shields.io/gem/v/oj.svg)
5
5
  ![Gem](https://img.shields.io/gem/dt/oj.svg)
6
- [![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)
7
6
  [![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)
8
7
 
9
8
  A *fast* JSON parser and Object marshaller as a Ruby gem.
@@ -70,6 +69,7 @@ links.
70
69
  - [{file:Compatibility.md}](pages/Compatibility.md) lists current compatibility with Rubys and Rails.
71
70
  - [{file:Advanced.md}](pages/Advanced.md) for fast parser and marshalling features.
72
71
  - [{file:Security.md}](pages/Security.md) for security considerations.
72
+ - [{file:InstallOptions.md}](pages/InstallOptions.md) for install option.
73
73
 
74
74
  ## Releases
75
75
 
@@ -109,6 +109,8 @@ Follow [@peterohler on Twitter](http://twitter.com/peterohler) for announcements
109
109
 
110
110
  - *Agoo-C, a high performance C web server supporting GraphQL on GitHub*: https://github.com/ohler55/agoo-c
111
111
 
112
+ - *oj-introspect, an example of creating an Oj parser extension in C*: https://github.com/meinac/oj-introspect
113
+
112
114
  #### Contributing
113
115
 
114
116
  + Provide a Pull Request off the `develop` branch.
data/ext/oj/buf.h CHANGED
@@ -4,6 +4,7 @@
4
4
  #ifndef OJ_BUF_H
5
5
  #define OJ_BUF_H
6
6
 
7
+ #include "mem.h"
7
8
  #include "ruby.h"
8
9
 
9
10
  typedef struct _buf {
@@ -11,7 +12,7 @@ typedef struct _buf {
11
12
  char *end;
12
13
  char *tail;
13
14
  char base[1024];
14
- } * Buf;
15
+ } *Buf;
15
16
 
16
17
  inline static void buf_init(Buf buf) {
17
18
  buf->head = buf->base;
@@ -25,7 +26,7 @@ inline static void buf_reset(Buf buf) {
25
26
 
26
27
  inline static void buf_cleanup(Buf buf) {
27
28
  if (buf->base != buf->head) {
28
- xfree(buf->head);
29
+ OJ_R_FREE(buf->head);
29
30
  }
30
31
  }
31
32
 
@@ -49,10 +50,10 @@ inline static void buf_append_string(Buf buf, const char *s, size_t slen) {
49
50
  size_t new_len = len + slen + len / 2;
50
51
 
51
52
  if (buf->base == buf->head) {
52
- buf->head = ALLOC_N(char, new_len);
53
+ buf->head = OJ_R_ALLOC_N(char, new_len);
53
54
  memcpy(buf->head, buf->base, len);
54
55
  } else {
55
- REALLOC_N(buf->head, char, new_len);
56
+ OJ_R_REALLOC_N(buf->head, char, new_len);
56
57
  }
57
58
  buf->tail = buf->head + toff;
58
59
  buf->end = buf->head + new_len - 1;
@@ -68,10 +69,10 @@ inline static void buf_append(Buf buf, char c) {
68
69
  size_t new_len = len + len / 2;
69
70
 
70
71
  if (buf->base == buf->head) {
71
- buf->head = ALLOC_N(char, new_len);
72
+ buf->head = OJ_R_ALLOC_N(char, new_len);
72
73
  memcpy(buf->head, buf->base, len);
73
74
  } else {
74
- REALLOC_N(buf->head, char, new_len);
75
+ OJ_R_REALLOC_N(buf->head, char, new_len);
75
76
  }
76
77
  buf->tail = buf->head + toff;
77
78
  buf->end = buf->head + new_len - 1;
data/ext/oj/cache.c CHANGED
@@ -7,6 +7,7 @@
7
7
  #include <stdlib.h>
8
8
 
9
9
  #include "cache.h"
10
+ #include "mem.h"
10
11
 
11
12
  // The stdlib calloc, realloc, and free are used instead of the Ruby ALLOC,
12
13
  // ALLOC_N, REALLOC, and xfree since the later could trigger a GC which will
@@ -28,16 +29,16 @@
28
29
  #define M 0x5bd1e995
29
30
 
30
31
  typedef struct _slot {
31
- struct _slot * next;
32
+ struct _slot *next;
32
33
  VALUE val;
33
34
  uint64_t hash;
34
35
  volatile uint32_t use_cnt;
35
36
  uint8_t klen;
36
37
  char key[CACHE_MAX_KEY];
37
- } * Slot;
38
+ } *Slot;
38
39
 
39
40
  typedef struct _cache {
40
- volatile Slot * slots;
41
+ volatile Slot *slots;
41
42
  volatile size_t cnt;
42
43
  VALUE (*form)(const char *str, size_t len);
43
44
  uint64_t size;
@@ -52,7 +53,7 @@ typedef struct _cache {
52
53
  #endif
53
54
  uint8_t xrate;
54
55
  bool mark;
55
- } * Cache;
56
+ } *Cache;
56
57
 
57
58
  void cache_set_form(Cache c, VALUE (*form)(const char *str, size_t len)) {
58
59
  c->form = form;
@@ -94,13 +95,13 @@ static uint64_t hash_calc(const uint8_t *key, size_t len) {
94
95
 
95
96
  static void rehash(Cache c) {
96
97
  uint64_t osize;
97
- Slot * end;
98
- Slot * sp;
98
+ Slot *end;
99
+ Slot *sp;
99
100
 
100
101
  osize = c->size;
101
102
  c->size = osize * 4;
102
103
  c->mask = c->size - 1;
103
- c->slots = realloc((void *)c->slots, sizeof(Slot) * c->size);
104
+ c->slots = OJ_REALLOC((void *)c->slots, sizeof(Slot) * c->size);
104
105
  memset((Slot *)c->slots + osize, 0, sizeof(Slot) * osize * 3);
105
106
  end = (Slot *)c->slots + osize;
106
107
  for (sp = (Slot *)c->slots; sp < end; sp++) {
@@ -110,7 +111,7 @@ static void rehash(Cache c) {
110
111
  *sp = NULL;
111
112
  for (; NULL != s; s = next) {
112
113
  uint64_t h = s->hash & c->mask;
113
- Slot * bucket = (Slot *)c->slots + h;
114
+ Slot *bucket = (Slot *)c->slots + h;
114
115
 
115
116
  next = s->next;
116
117
  s->next = *bucket;
@@ -121,14 +122,14 @@ static void rehash(Cache c) {
121
122
 
122
123
  static VALUE lockless_intern(Cache c, const char *key, size_t len) {
123
124
  uint64_t h = hash_calc((const uint8_t *)key, len);
124
- Slot * bucket = (Slot *)c->slots + (h & c->mask);
125
+ Slot *bucket = (Slot *)c->slots + (h & c->mask);
125
126
  Slot b;
126
127
  volatile VALUE rkey;
127
128
 
128
129
  while (REUSE_MAX < c->rcnt) {
129
130
  if (NULL != (b = c->reuse)) {
130
131
  c->reuse = b->next;
131
- free(b);
132
+ OJ_FREE(b);
132
133
  c->rcnt--;
133
134
  } else {
134
135
  // An accounting error occured somewhere so correct it.
@@ -143,7 +144,7 @@ static VALUE lockless_intern(Cache c, const char *key, size_t len) {
143
144
  }
144
145
  rkey = c->form(key, len);
145
146
  if (NULL == (b = c->reuse)) {
146
- b = calloc(1, sizeof(struct _slot));
147
+ b = OJ_CALLOC(1, sizeof(struct _slot));
147
148
  } else {
148
149
  c->reuse = b->next;
149
150
  c->rcnt--;
@@ -165,7 +166,7 @@ static VALUE lockless_intern(Cache c, const char *key, size_t len) {
165
166
 
166
167
  static VALUE locking_intern(Cache c, const char *key, size_t len) {
167
168
  uint64_t h;
168
- Slot * bucket;
169
+ Slot *bucket;
169
170
  Slot b;
170
171
  uint64_t old_size;
171
172
  volatile VALUE rkey;
@@ -174,7 +175,7 @@ static VALUE locking_intern(Cache c, const char *key, size_t len) {
174
175
  while (REUSE_MAX < c->rcnt) {
175
176
  if (NULL != (b = c->reuse)) {
176
177
  c->reuse = b->next;
177
- free(b);
178
+ OJ_FREE(b);
178
179
  c->rcnt--;
179
180
  } else {
180
181
  // An accounting error occured somewhere so correct it.
@@ -200,7 +201,7 @@ static VALUE locking_intern(Cache c, const char *key, size_t len) {
200
201
  }
201
202
  CACHE_UNLOCK(c);
202
203
  if (NULL == b) {
203
- b = calloc(1, sizeof(struct _slot));
204
+ b = OJ_CALLOC(1, sizeof(struct _slot));
204
205
  }
205
206
  rkey = c->form(key, len);
206
207
  b->hash = h;
@@ -228,7 +229,7 @@ static VALUE locking_intern(Cache c, const char *key, size_t len) {
228
229
  }
229
230
 
230
231
  Cache cache_create(size_t size, VALUE (*form)(const char *str, size_t len), bool mark, bool locking) {
231
- Cache c = calloc(1, sizeof(struct _cache));
232
+ Cache c = OJ_CALLOC(1, sizeof(struct _cache));
232
233
  int shift = 0;
233
234
 
234
235
  for (; REHASH_LIMIT < size; size /= 2, shift++) {
@@ -241,12 +242,12 @@ Cache cache_create(size_t size, VALUE (*form)(const char *str, size_t len), bool
241
242
  #else
242
243
  c->mutex = rb_mutex_new();
243
244
  #endif
244
- c->size = 1 << shift;
245
- c->mask = c->size - 1;
246
- c->slots = calloc(c->size, sizeof(Slot));
247
- c->form = form;
248
- c->xrate = 1; // low
249
- c->mark = mark;
245
+ c->size = 1 << shift;
246
+ c->mask = c->size - 1;
247
+ c->slots = OJ_CALLOC(c->size, sizeof(Slot));
248
+ c->form = form;
249
+ c->xrate = 1; // low
250
+ c->mark = mark;
250
251
  if (locking) {
251
252
  c->intern = locking_intern;
252
253
  } else {
@@ -259,7 +260,8 @@ void cache_set_expunge_rate(Cache c, int rate) {
259
260
  c->xrate = (uint8_t)rate;
260
261
  }
261
262
 
262
- void cache_free(Cache c) {
263
+ void cache_free(void *data) {
264
+ Cache c = (Cache)data;
263
265
  uint64_t i;
264
266
 
265
267
  for (i = 0; i < c->size; i++) {
@@ -268,14 +270,15 @@ void cache_free(Cache c) {
268
270
 
269
271
  for (s = c->slots[i]; NULL != s; s = next) {
270
272
  next = s->next;
271
- free(s);
273
+ OJ_FREE(s);
272
274
  }
273
275
  }
274
- free((void *)c->slots);
275
- free(c);
276
+ OJ_FREE((void *)c->slots);
277
+ OJ_FREE(c);
276
278
  }
277
279
 
278
- void cache_mark(Cache c) {
280
+ void cache_mark(void *data) {
281
+ Cache c = (Cache)data;
279
282
  uint64_t i;
280
283
 
281
284
  #if !HAVE_PTHREAD_MUTEX_INIT
data/ext/oj/cache.h CHANGED
@@ -10,10 +10,11 @@
10
10
  #define CACHE_MAX_KEY 35
11
11
 
12
12
  struct _cache;
13
+ typedef struct _cache *Cache;
13
14
 
14
15
  extern struct _cache *cache_create(size_t size, VALUE (*form)(const char *str, size_t len), bool mark, bool locking);
15
- extern void cache_free(struct _cache *c);
16
- extern void cache_mark(struct _cache *c);
16
+ extern void cache_free(void *data);
17
+ extern void cache_mark(void *data);
17
18
  extern void cache_set_form(struct _cache *c, VALUE (*form)(const char *str, size_t len));
18
19
  extern VALUE cache_intern(struct _cache *c, const char *key, size_t len);
19
20
  extern void cache_set_expunge_rate(struct _cache *c, int rate);
data/ext/oj/cache8.c CHANGED
@@ -9,6 +9,7 @@
9
9
  #include <stdlib.h>
10
10
  #include <string.h>
11
11
 
12
+ #include "mem.h"
12
13
  #include "ruby.h"
13
14
 
14
15
  #define BITS 4
@@ -32,16 +33,18 @@ void oj_cache8_new(Cache8 *cache) {
32
33
  Bucket *b;
33
34
  int i;
34
35
 
35
- *cache = ALLOC(struct _cache8);
36
+ *cache = OJ_R_ALLOC(struct _cache8);
36
37
  for (i = SLOT_CNT, b = (*cache)->buckets; 0 < i; i--, b++) {
37
38
  b->value = 0;
38
39
  }
39
40
  }
40
41
 
41
- void oj_cache8_delete(Cache8 cache) { cache8_delete(cache, 0); }
42
+ void oj_cache8_delete(Cache8 cache) {
43
+ cache8_delete(cache, 0);
44
+ }
42
45
 
43
46
  static void cache8_delete(Cache8 cache, int depth) {
44
- Bucket * b;
47
+ Bucket *b;
45
48
  unsigned int i;
46
49
 
47
50
  for (i = 0, b = cache->buckets; i < SLOT_CNT; i++, b++) {
@@ -51,7 +54,7 @@ static void cache8_delete(Cache8 cache, int depth) {
51
54
  }
52
55
  }
53
56
  }
54
- xfree(cache);
57
+ OJ_R_FREE(cache);
55
58
  }
56
59
 
57
60
  slot_t oj_cache8_get(Cache8 cache, sid_t key, slot_t **slot) {
@@ -79,7 +82,7 @@ void oj_cache8_print(Cache8 cache) {
79
82
  }
80
83
 
81
84
  static void slot_print(Cache8 c, sid_t key, unsigned int depth) {
82
- Bucket * b;
85
+ Bucket *b;
83
86
  unsigned int i;
84
87
  sid_t k8 = (sid_t)key;
85
88
  sid_t k;
@@ -90,11 +93,9 @@ static void slot_print(Cache8 c, sid_t key, unsigned int depth) {
90
93
  /*printf("*** key: 0x%016llx depth: %u i: %u\n", k, depth, i); */
91
94
  if (DEPTH - 1 == depth) {
92
95
  #if IS_WINDOWS
93
- printf("0x%016lx: %4lu\n", (long unsigned int)k,
94
- (long unsigned int)b->value);
96
+ printf("0x%016lx: %4lu\n", (long unsigned int)k, (long unsigned int)b->value);
95
97
  #else
96
- printf("0x%016llx: %4llu\n", (long long unsigned int)k,
97
- (long long unsigned int)b->value);
98
+ printf("0x%016llx: %4llu\n", (long long unsigned int)k, (long long unsigned int)b->value);
98
99
  #endif
99
100
  } else {
100
101
  slot_print(b->child, k, depth + 1);
data/ext/oj/circarray.c CHANGED
@@ -3,10 +3,12 @@
3
3
 
4
4
  #include "circarray.h"
5
5
 
6
+ #include "mem.h"
7
+
6
8
  CircArray oj_circ_array_new(void) {
7
9
  CircArray ca;
8
10
 
9
- if (0 == (ca = ALLOC(struct _circArray))) {
11
+ if (0 == (ca = OJ_R_ALLOC(struct _circArray))) {
10
12
  rb_raise(rb_eNoMemError, "not enough memory\n");
11
13
  }
12
14
  ca->objs = ca->obj_array;
@@ -18,9 +20,9 @@ CircArray oj_circ_array_new(void) {
18
20
 
19
21
  void oj_circ_array_free(CircArray ca) {
20
22
  if (ca->objs != ca->obj_array) {
21
- xfree(ca->objs);
23
+ OJ_R_FREE(ca->objs);
22
24
  }
23
- xfree(ca);
25
+ OJ_R_FREE(ca);
24
26
  }
25
27
 
26
28
  void oj_circ_array_set(CircArray ca, VALUE obj, unsigned long id) {
@@ -31,12 +33,12 @@ void oj_circ_array_set(CircArray ca, VALUE obj, unsigned long id) {
31
33
  unsigned long cnt = id + 512;
32
34
 
33
35
  if (ca->objs == ca->obj_array) {
34
- if (0 == (ca->objs = ALLOC_N(VALUE, cnt))) {
36
+ if (0 == (ca->objs = OJ_R_ALLOC_N(VALUE, cnt))) {
35
37
  rb_raise(rb_eNoMemError, "not enough memory\n");
36
38
  }
37
39
  memcpy(ca->objs, ca->obj_array, sizeof(VALUE) * ca->cnt);
38
40
  } else {
39
- REALLOC_N(ca->objs, VALUE, cnt);
41
+ OJ_R_REALLOC_N(ca->objs, VALUE, cnt);
40
42
  }
41
43
  ca->size = cnt;
42
44
  }
data/ext/oj/circarray.h CHANGED
@@ -9,10 +9,10 @@
9
9
 
10
10
  typedef struct _circArray {
11
11
  VALUE obj_array[1024];
12
- VALUE * objs;
12
+ VALUE* objs;
13
13
  unsigned long size; // allocated size or initial array size
14
14
  unsigned long cnt;
15
- } * CircArray;
15
+ }* CircArray;
16
16
 
17
17
  extern CircArray oj_circ_array_new(void);
18
18
  extern void oj_circ_array_free(CircArray ca);
data/ext/oj/code.c CHANGED
@@ -18,8 +18,8 @@ inline static VALUE resolve_classname(VALUE mod, const char *classname) {
18
18
  static VALUE path2class(const char *name) {
19
19
  char class_name[1024];
20
20
  VALUE clas;
21
- char * end = class_name + sizeof(class_name) - 1;
22
- char * s;
21
+ char *end = class_name + sizeof(class_name) - 1;
22
+ char *s;
23
23
  const char *n = name;
24
24
 
25
25
  clas = rb_cObject;
@@ -185,24 +185,17 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
185
185
  } else {
186
186
  char buf[32];
187
187
  char *b = buf + sizeof(buf) - 1;
188
- int neg = 0;
188
+ bool neg = false;
189
189
  long num = attrs->num;
190
190
  size_t cnt = 0;
191
191
 
192
192
  if (0 > num) {
193
- neg = 1;
193
+ neg = true;
194
194
  num = -num;
195
195
  }
196
196
  *b-- = '\0';
197
197
  if (0 < num) {
198
- for (; 0 < num; num /= 10, b--) {
199
- *b = (num % 10) + '0';
200
- }
201
- if (neg) {
202
- *b = '-';
203
- } else {
204
- b++;
205
- }
198
+ b = oj_longlong_to_string(num, neg, b);
206
199
  } else {
207
200
  *b = '0';
208
201
  }
data/ext/oj/code.h CHANGED
@@ -17,7 +17,7 @@ typedef struct _code {
17
17
  EncodeFunc encode;
18
18
  DecodeFunc decode;
19
19
  bool active; // For compat mode.
20
- } * Code;
20
+ } *Code;
21
21
 
22
22
  // Used by encode functions.
23
23
  typedef struct _attr {
@@ -26,7 +26,7 @@ typedef struct _attr {
26
26
  VALUE value;
27
27
  long num;
28
28
  VALUE time;
29
- } * Attr;
29
+ } *Attr;
30
30
 
31
31
  extern bool oj_code_dump(Code codes, VALUE obj, int depth, Out out);
32
32
  extern VALUE oj_code_load(Code codes, VALUE clas, VALUE args);