oj 3.13.11 → 3.15.0

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.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +74 -0
  3. data/README.md +4 -2
  4. data/ext/oj/buf.h +11 -6
  5. data/ext/oj/cache.c +25 -24
  6. data/ext/oj/cache8.c +10 -9
  7. data/ext/oj/circarray.c +8 -6
  8. data/ext/oj/circarray.h +2 -2
  9. data/ext/oj/code.c +17 -24
  10. data/ext/oj/code.h +2 -2
  11. data/ext/oj/compat.c +17 -44
  12. data/ext/oj/custom.c +70 -141
  13. data/ext/oj/debug.c +3 -9
  14. data/ext/oj/dump.c +128 -118
  15. data/ext/oj/dump.h +12 -8
  16. data/ext/oj/dump_compat.c +564 -641
  17. data/ext/oj/dump_leaf.c +17 -63
  18. data/ext/oj/dump_object.c +70 -199
  19. data/ext/oj/dump_strict.c +22 -46
  20. data/ext/oj/encoder.c +1 -1
  21. data/ext/oj/err.c +2 -13
  22. data/ext/oj/err.h +9 -12
  23. data/ext/oj/extconf.rb +14 -5
  24. data/ext/oj/fast.c +75 -103
  25. data/ext/oj/intern.c +52 -50
  26. data/ext/oj/intern.h +4 -8
  27. data/ext/oj/mem.c +318 -0
  28. data/ext/oj/mem.h +53 -0
  29. data/ext/oj/mimic_json.c +75 -47
  30. data/ext/oj/object.c +49 -66
  31. data/ext/oj/odd.c +89 -67
  32. data/ext/oj/odd.h +15 -15
  33. data/ext/oj/oj.c +140 -99
  34. data/ext/oj/oj.h +80 -51
  35. data/ext/oj/parse.c +162 -184
  36. data/ext/oj/parse.h +7 -10
  37. data/ext/oj/parser.c +89 -34
  38. data/ext/oj/parser.h +18 -7
  39. data/ext/oj/rails.c +82 -146
  40. data/ext/oj/rails.h +1 -1
  41. data/ext/oj/reader.c +11 -12
  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 +20 -31
  47. data/ext/oj/saj2.c +329 -93
  48. data/ext/oj/saj2.h +23 -0
  49. data/ext/oj/scp.c +3 -14
  50. data/ext/oj/sparse.c +26 -70
  51. data/ext/oj/stream_writer.c +12 -22
  52. data/ext/oj/strict.c +20 -52
  53. data/ext/oj/string_writer.c +21 -21
  54. data/ext/oj/trace.h +31 -4
  55. data/ext/oj/usual.c +105 -150
  56. data/ext/oj/usual.h +68 -0
  57. data/ext/oj/util.h +1 -1
  58. data/ext/oj/val_stack.c +1 -1
  59. data/ext/oj/val_stack.h +8 -7
  60. data/ext/oj/validate.c +21 -26
  61. data/ext/oj/wab.c +31 -68
  62. data/lib/oj/active_support_helper.rb +0 -1
  63. data/lib/oj/bag.rb +7 -1
  64. data/lib/oj/easy_hash.rb +4 -5
  65. data/lib/oj/error.rb +0 -1
  66. data/lib/oj/json.rb +4 -2
  67. data/lib/oj/mimic.rb +4 -2
  68. data/lib/oj/saj.rb +20 -6
  69. data/lib/oj/state.rb +9 -6
  70. data/lib/oj/version.rb +1 -2
  71. data/lib/oj.rb +2 -0
  72. data/pages/Compatibility.md +1 -1
  73. data/pages/InstallOptions.md +20 -0
  74. data/pages/Options.md +10 -0
  75. data/test/_test_active.rb +8 -9
  76. data/test/_test_active_mimic.rb +7 -8
  77. data/test/_test_mimic_rails.rb +17 -20
  78. data/test/activerecord/result_test.rb +5 -6
  79. data/test/{activesupport5 → activesupport7}/abstract_unit.rb +16 -12
  80. data/test/{activesupport5 → activesupport7}/decoding_test.rb +2 -10
  81. data/test/{activesupport5 → activesupport7}/encoding_test.rb +20 -34
  82. data/test/{activesupport5 → activesupport7}/encoding_test_cases.rb +6 -0
  83. data/test/{activesupport5 → activesupport7}/time_zone_test_helpers.rb +8 -0
  84. data/test/files.rb +15 -15
  85. data/test/foo.rb +9 -71
  86. data/test/helper.rb +11 -8
  87. data/test/isolated/shared.rb +3 -2
  88. data/test/json_gem/json_addition_test.rb +2 -2
  89. data/test/json_gem/json_common_interface_test.rb +4 -4
  90. data/test/json_gem/json_encoding_test.rb +0 -0
  91. data/test/json_gem/json_ext_parser_test.rb +1 -0
  92. data/test/json_gem/json_fixtures_test.rb +3 -2
  93. data/test/json_gem/json_generator_test.rb +48 -36
  94. data/test/json_gem/json_generic_object_test.rb +11 -11
  95. data/test/json_gem/json_parser_test.rb +54 -47
  96. data/test/json_gem/json_string_matching_test.rb +9 -9
  97. data/test/json_gem/test_helper.rb +7 -3
  98. data/test/mem.rb +13 -12
  99. data/test/perf.rb +21 -26
  100. data/test/perf_compat.rb +31 -33
  101. data/test/perf_dump.rb +50 -0
  102. data/test/perf_fast.rb +80 -82
  103. data/test/perf_file.rb +27 -29
  104. data/test/perf_object.rb +65 -69
  105. data/test/perf_once.rb +12 -11
  106. data/test/perf_parser.rb +42 -48
  107. data/test/perf_saj.rb +46 -54
  108. data/test/perf_scp.rb +57 -69
  109. data/test/perf_simple.rb +41 -39
  110. data/test/perf_strict.rb +68 -70
  111. data/test/perf_wab.rb +67 -69
  112. data/test/prec.rb +3 -3
  113. data/test/sample/change.rb +0 -1
  114. data/test/sample/dir.rb +0 -1
  115. data/test/sample/doc.rb +0 -1
  116. data/test/sample/file.rb +0 -1
  117. data/test/sample/group.rb +0 -1
  118. data/test/sample/hasprops.rb +0 -1
  119. data/test/sample/layer.rb +0 -1
  120. data/test/sample/rect.rb +0 -1
  121. data/test/sample/shape.rb +0 -1
  122. data/test/sample/text.rb +0 -1
  123. data/test/sample.rb +16 -16
  124. data/test/sample_json.rb +8 -8
  125. data/test/test_compat.rb +76 -42
  126. data/test/test_custom.rb +72 -51
  127. data/test/test_debian.rb +7 -10
  128. data/test/test_fast.rb +86 -90
  129. data/test/test_file.rb +41 -30
  130. data/test/test_gc.rb +16 -5
  131. data/test/test_generate.rb +5 -5
  132. data/test/test_hash.rb +4 -4
  133. data/test/test_integer_range.rb +9 -9
  134. data/test/test_null.rb +20 -20
  135. data/test/test_object.rb +85 -96
  136. data/test/test_parser.rb +6 -22
  137. data/test/test_parser_debug.rb +27 -0
  138. data/test/test_parser_saj.rb +115 -23
  139. data/test/test_parser_usual.rb +6 -6
  140. data/test/test_rails.rb +2 -2
  141. data/test/test_saj.rb +10 -8
  142. data/test/test_scp.rb +37 -39
  143. data/test/test_strict.rb +30 -32
  144. data/test/test_various.rb +147 -99
  145. data/test/test_wab.rb +48 -44
  146. data/test/test_writer.rb +47 -47
  147. data/test/tests.rb +13 -4
  148. data/test/tests_mimic.rb +12 -3
  149. data/test/tests_mimic_addition.rb +12 -3
  150. metadata +33 -144
  151. data/test/activesupport4/decoding_test.rb +0 -108
  152. data/test/activesupport4/encoding_test.rb +0 -531
  153. data/test/activesupport4/test_helper.rb +0 -41
  154. data/test/activesupport5/test_helper.rb +0 -72
  155. data/test/bar.rb +0 -16
  156. data/test/baz.rb +0 -16
  157. data/test/bug.rb +0 -16
  158. data/test/zoo.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcb5f80ad6384640d44889424c39f91ee2db778b17c91b9505b5b3b4c280abf1
4
- data.tar.gz: 85b70200f48f46019ecf1020ca8e1b8ea604bca1161120b3747a8aeac2903682
3
+ metadata.gz: 929e5766d8a556ed9590574901fe8268979fd6c165d10e1a2a8601a594dd6897
4
+ data.tar.gz: 966fedee6a16f73c004b56050474377ae48521f5858da962f0f0416b5636a4c3
5
5
  SHA512:
6
- metadata.gz: f96776be4f9431b160f1d9f588e8688fb7e0c4a431c58a10fa43a71f5a6f95781456287f40db5dfba03bb69350946ad36f246d0b59c196f9dc95218f51005f7a
7
- data.tar.gz: e106b88134f86d82b9740f3e836ecb2aaa4af7ad643b96a4600eaa09392ba5f630c402101a6fb476823c41bc127b5c3d9625c6900a033cf6f9830ca01e57d459
6
+ metadata.gz: f458f616c33c48d84cb0e1d2c1c45e8b677609c19251345328721fe3b7b6c4c5aa1fd4906da2234b60889a6e3bb45ee0371e7de7565bb6d1aa7d924e231e36dd
7
+ data.tar.gz: fbbf233fc1ce57739d2fe538c179a24282e4c043740c2b47cce29745e3847712afa7828d321b877a3c29ab7d2216e7185af9a85bb9c8eb96b6036f9e3e49c1d1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,79 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 3.15.0 - 2023-06-02
4
+
5
+ - Added `omit_null_byte` option when dumping.
6
+
7
+ ## 3.14.3 - 2023-04-07
8
+
9
+ - Fixed compat parse with optimized Hash when parsing a JSON::GenericObject.
10
+
11
+ ## 3.14.2 - 2023-02-10
12
+
13
+ - Fixed check for \0 in strings.
14
+
15
+ ## 3.14.1 - 2023-02-01
16
+
17
+ - Fixed issue with uninitialized handler for Oj::Parser::Saj.
18
+
19
+ - Fixed hang on unterminated string with a \0 byte in parse.c.
20
+
21
+ ## 3.14.0 - 2023-01-30
22
+
23
+ - Tracing is now a compile time option giving a 15 to 20% performance boost.
24
+
25
+ - Some cleanup in the fast parser.
26
+
27
+ ## 3.13.23 - 2022-11-06
28
+
29
+ - Fixed issue with Oj::Parser extension regarding GC timeing.
30
+
31
+ ## 3.13.22 - 2022-11-01
32
+
33
+ - Reorganized Oj::Parser code to allow for parser extensions in C.
34
+
35
+ ## 3.13.21 - 2022-08-19
36
+
37
+ - Bug parsing big numbers fixed in the SAJ parser.
38
+
39
+ ## 3.13.20 - 2022-08-07
40
+
41
+ - SSE4 made optional with a `--with-sse42` flag to the compile.
42
+
43
+ ## 3.13.19 - 2022-07-29
44
+
45
+ - TruffleRuby issues resolved.
46
+
47
+ ## 3.13.18 - 2022-07-25
48
+
49
+ - Fixed SSE detection at run time.
50
+
51
+ ## 3.13.17 - 2022-07-15
52
+
53
+ - Fixed Oj::Parser to detect unterminated arrays and objects.
54
+
55
+ ## 3.13.16 - 2022-07-06
56
+
57
+ - Added line and column as optional arguments to the Oj::Parser.saj parser.
58
+
59
+ ## 3.13.15 - 2022-07-03
60
+
61
+ - Fixed issue dumping NaN value in object mode.
62
+
63
+ ## 3.13.14 - 2022-06-03
64
+
65
+ - Double fclose() due to bad merger fixed by tonobo.
66
+
67
+ ## 3.13.13 - 2022-05-20
68
+
69
+ - Fixed flooding stdout with debug output when dumping.
70
+
71
+ ## 3.13.12 - 2022-05-20
72
+
73
+ - Fixed crash on no arguments to pretty_generate. Now raises an exception.
74
+ - Register all classes and globals.
75
+ - Fixed memory issue with dumping.
76
+
3
77
  ## 3.13.11 - 2022-01-05
4
78
 
5
79
  - Fixed write blocking failures on writes to a slow stream with larger writes.
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
 
@@ -39,16 +40,20 @@ inline static const char *buf_str(Buf buf) {
39
40
  }
40
41
 
41
42
  inline static void buf_append_string(Buf buf, const char *s, size_t slen) {
43
+ if (0 == slen) {
44
+ return;
45
+ }
46
+
42
47
  if (buf->end <= buf->tail + slen) {
43
48
  size_t len = buf->end - buf->head;
44
49
  size_t toff = buf->tail - buf->head;
45
50
  size_t new_len = len + slen + len / 2;
46
51
 
47
52
  if (buf->base == buf->head) {
48
- buf->head = ALLOC_N(char, new_len);
53
+ buf->head = OJ_R_ALLOC_N(char, new_len);
49
54
  memcpy(buf->head, buf->base, len);
50
55
  } else {
51
- REALLOC_N(buf->head, char, new_len);
56
+ OJ_R_REALLOC_N(buf->head, char, new_len);
52
57
  }
53
58
  buf->tail = buf->head + toff;
54
59
  buf->end = buf->head + new_len - 1;
@@ -64,10 +69,10 @@ inline static void buf_append(Buf buf, char c) {
64
69
  size_t new_len = len + len / 2;
65
70
 
66
71
  if (buf->base == buf->head) {
67
- buf->head = ALLOC_N(char, new_len);
72
+ buf->head = OJ_R_ALLOC_N(char, new_len);
68
73
  memcpy(buf->head, buf->base, len);
69
74
  } else {
70
- REALLOC_N(buf->head, char, new_len);
75
+ OJ_R_REALLOC_N(buf->head, char, new_len);
71
76
  }
72
77
  buf->tail = buf->head + toff;
73
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 {
@@ -268,11 +269,11 @@ void cache_free(Cache c) {
268
269
 
269
270
  for (s = c->slots[i]; NULL != s; s = next) {
270
271
  next = s->next;
271
- free(s);
272
+ OJ_FREE(s);
272
273
  }
273
274
  }
274
- free((void *)c->slots);
275
- free(c);
275
+ OJ_FREE((void *)c->slots);
276
+ OJ_FREE(c);
276
277
  }
277
278
 
278
279
  void cache_mark(Cache c) {
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
- CircArray oj_circ_array_new() {
6
+ #include "mem.h"
7
+
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() {
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;
@@ -140,21 +140,17 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
140
140
  if (with_class) {
141
141
  fill_indent(out, d2);
142
142
  *out->cur++ = '"';
143
- memcpy(out->cur, out->opts->create_id, out->opts->create_id_len);
144
- out->cur += out->opts->create_id_len;
143
+ APPEND_CHARS(out->cur, out->opts->create_id, out->opts->create_id_len);
145
144
  *out->cur++ = '"';
146
145
  if (0 < out->opts->dump_opts.before_size) {
147
- strcpy(out->cur, out->opts->dump_opts.before_sep);
148
- out->cur += out->opts->dump_opts.before_size;
146
+ APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
149
147
  }
150
148
  *out->cur++ = ':';
151
149
  if (0 < out->opts->dump_opts.after_size) {
152
- strcpy(out->cur, out->opts->dump_opts.after_sep);
153
- out->cur += out->opts->dump_opts.after_size;
150
+ APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
154
151
  }
155
152
  *out->cur++ = '"';
156
- memcpy(out->cur, classname, len);
157
- out->cur += len;
153
+ APPEND_CHARS(out->cur, classname, len);
158
154
  *out->cur++ = '"';
159
155
  no_comma = false;
160
156
  }
@@ -168,17 +164,14 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
168
164
  }
169
165
  fill_indent(out, d2);
170
166
  *out->cur++ = '"';
171
- memcpy(out->cur, attrs->name, attrs->len);
172
- out->cur += attrs->len;
167
+ APPEND_CHARS(out->cur, attrs->name, attrs->len);
173
168
  *out->cur++ = '"';
174
169
  if (0 < out->opts->dump_opts.before_size) {
175
- strcpy(out->cur, out->opts->dump_opts.before_sep);
176
- out->cur += out->opts->dump_opts.before_size;
170
+ APPEND_CHARS(out->cur, out->opts->dump_opts.before_sep, out->opts->dump_opts.before_size);
177
171
  }
178
172
  *out->cur++ = ':';
179
173
  if (0 < out->opts->dump_opts.after_size) {
180
- strcpy(out->cur, out->opts->dump_opts.after_sep);
181
- out->cur += out->opts->dump_opts.after_size;
174
+ APPEND_CHARS(out->cur, out->opts->dump_opts.after_sep, out->opts->dump_opts.after_size);
182
175
  }
183
176
  if (Qundef == attrs->value) {
184
177
  if (Qundef != attrs->time) {
@@ -190,10 +183,11 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
190
183
  default: oj_dump_time(attrs->time, out, false); break;
191
184
  }
192
185
  } else {
193
- char buf[32];
194
- char *b = buf + sizeof(buf) - 1;
195
- int neg = 0;
196
- long num = attrs->num;
186
+ char buf[32];
187
+ char *b = buf + sizeof(buf) - 1;
188
+ int neg = 0;
189
+ long num = attrs->num;
190
+ size_t cnt = 0;
197
191
 
198
192
  if (0 > num) {
199
193
  neg = 1;
@@ -212,10 +206,9 @@ void oj_code_attrs(VALUE obj, Attr attrs, int depth, Out out, bool with_class) {
212
206
  } else {
213
207
  *b = '0';
214
208
  }
215
- assure_size(out, (sizeof(buf) - (b - buf)));
216
- for (; '\0' != *b; b++) {
217
- *out->cur++ = *b;
218
- }
209
+ cnt = sizeof(buf) - (b - buf) - 1;
210
+ assure_size(out, cnt);
211
+ APPEND_CHARS(out->cur, b, cnt);
219
212
  }
220
213
  } else {
221
214
  oj_dump_compat_val(attrs->value, d3, out, true);
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);