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/mem.c CHANGED
@@ -1,259 +1,253 @@
1
1
  // Copyright (c) 2018, Peter Ohler, All rights reserved.
2
2
 
3
+ #include "mem.h"
4
+
3
5
  #include <pthread.h>
6
+ #include <ruby.h>
4
7
  #include <stdbool.h>
5
8
  #include <stdint.h>
6
9
  #include <stdio.h>
7
10
  #include <stdlib.h>
8
11
  #include <string.h>
9
12
 
10
- #include <ruby.h>
11
-
12
- #include "mem.h"
13
-
14
13
  typedef struct _rec {
15
- struct _rec *next;
16
- const void *ptr;
17
- size_t size;
18
- const char *file;
19
- int line;
20
- bool ruby;
14
+ struct _rec *next;
15
+ const void *ptr;
16
+ size_t size;
17
+ const char *file;
18
+ int line;
19
+ bool ruby;
21
20
  } *Rec;
22
21
 
23
22
  typedef struct _rep {
24
- struct _rep *next;
25
- size_t size;
26
- const char *file;
27
- int line;
28
- int cnt;
23
+ struct _rep *next;
24
+ size_t size;
25
+ const char *file;
26
+ int line;
27
+ int cnt;
29
28
  } *Rep;
30
29
 
31
30
  #ifdef MEM_DEBUG
32
31
 
33
- static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
34
- static Rec recs = NULL;
35
- static const char mem_pad[] = "--- This is a memory pad and should not change until being freed. ---";
32
+ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
33
+ static Rec recs = NULL;
34
+ static const char mem_pad[] = "--- This is a memory pad and should not change until being freed. ---";
36
35
 
37
- void*
38
- oj_malloc(size_t size, const char *file, int line) {
39
- void *ptr = malloc(size + sizeof(mem_pad));
36
+ void *oj_malloc(size_t size, const char *file, int line) {
37
+ void *ptr = malloc(size + sizeof(mem_pad));
40
38
 
41
39
  if (NULL != ptr) {
42
- Rec r = (Rec)malloc(sizeof(struct _rec));
43
-
44
- if (NULL != r) {
45
- strcpy(((char*)ptr) + size, mem_pad);
46
- r->ptr = ptr;
47
- r->size = size;
48
- r->file = file;
49
- r->line = line;
40
+ Rec r = (Rec)malloc(sizeof(struct _rec));
41
+
42
+ if (NULL != r) {
43
+ strcpy(((char *)ptr) + size, mem_pad);
44
+ r->ptr = ptr;
45
+ r->size = size;
46
+ r->file = file;
47
+ r->line = line;
50
48
  r->ruby = false;
51
- pthread_mutex_lock(&lock);
52
- r->next = recs;
53
- recs = r;
54
- pthread_mutex_unlock(&lock);
55
- } else {
56
- free(ptr);
57
- ptr = NULL;
58
- }
49
+ pthread_mutex_lock(&lock);
50
+ r->next = recs;
51
+ recs = r;
52
+ pthread_mutex_unlock(&lock);
53
+ } else {
54
+ free(ptr);
55
+ ptr = NULL;
56
+ }
59
57
  }
60
58
  return ptr;
61
59
  }
62
60
 
63
- void*
64
- oj_realloc(void *orig, size_t size, const char *file, int line) {
65
- void *ptr = realloc(orig, size + sizeof(mem_pad));
66
- Rec r;
61
+ void *oj_realloc(void *orig, size_t size, const char *file, int line) {
62
+ void *ptr = realloc(orig, size + sizeof(mem_pad));
63
+ Rec r;
67
64
 
68
65
  if (NULL != ptr) {
69
- strcpy(((char*)ptr) + size, mem_pad);
70
- pthread_mutex_lock(&lock);
71
- for (r = recs; NULL != r; r = r->next) {
72
- if (orig == r->ptr) {
73
- r->ptr = ptr;
74
- r->size = size;
75
- r->file = file;
76
- r->line = line;
66
+ strcpy(((char *)ptr) + size, mem_pad);
67
+ pthread_mutex_lock(&lock);
68
+ for (r = recs; NULL != r; r = r->next) {
69
+ if (orig == r->ptr) {
70
+ r->ptr = ptr;
71
+ r->size = size;
72
+ r->file = file;
73
+ r->line = line;
77
74
  r->ruby = false;
78
- break;
79
- }
80
- }
81
- pthread_mutex_unlock(&lock);
82
- if (NULL == r) {
83
- printf("Realloc at %s:%d (%p) not allocated.\n", file, line, orig);
84
- }
75
+ break;
76
+ }
77
+ }
78
+ pthread_mutex_unlock(&lock);
79
+ if (NULL == r) {
80
+ printf("Realloc at %s:%d (%p) not allocated.\n", file, line, orig);
81
+ }
85
82
  }
86
83
  return ptr;
87
84
  }
88
85
 
89
- void*
90
- oj_calloc(size_t count, size_t size, const char *file, int line) {
91
- void *ptr;
86
+ void *oj_calloc(size_t count, size_t size, const char *file, int line) {
87
+ void *ptr;
92
88
 
93
89
  size *= count;
94
90
  if (NULL != (ptr = malloc(size + sizeof(mem_pad)))) {
95
- Rec r = (Rec)malloc(sizeof(struct _rec));
96
-
97
- if (NULL != r) {
98
- memset(ptr, 0, size);
99
- strcpy(((char*)ptr) + size, mem_pad);
100
- r->ptr = ptr;
101
- r->size = size;
102
- r->file = file;
103
- r->line = line;
91
+ Rec r = (Rec)malloc(sizeof(struct _rec));
92
+
93
+ if (NULL != r) {
94
+ memset(ptr, 0, size);
95
+ strcpy(((char *)ptr) + size, mem_pad);
96
+ r->ptr = ptr;
97
+ r->size = size;
98
+ r->file = file;
99
+ r->line = line;
104
100
  r->ruby = false;
105
- pthread_mutex_lock(&lock);
106
- r->next = recs;
107
- recs = r;
108
- pthread_mutex_unlock(&lock);
109
- } else {
110
- free(ptr);
111
- ptr = NULL;
112
- }
101
+ pthread_mutex_lock(&lock);
102
+ r->next = recs;
103
+ recs = r;
104
+ pthread_mutex_unlock(&lock);
105
+ } else {
106
+ free(ptr);
107
+ ptr = NULL;
108
+ }
113
109
  }
114
110
  return ptr;
115
111
  }
116
112
 
117
- void*
118
- oj_r_alloc(size_t size, const char *file, int line) {
119
- void *ptr = ruby_xmalloc(size + sizeof(mem_pad));
113
+ void *oj_r_alloc(size_t size, const char *file, int line) {
114
+ void *ptr = ruby_xmalloc(size + sizeof(mem_pad));
120
115
 
121
116
  if (NULL != ptr) {
122
- Rec r = (Rec)malloc(sizeof(struct _rec));
123
-
124
- if (NULL != r) {
125
- strcpy(((char*)ptr) + size, mem_pad);
126
- r->ptr = ptr;
127
- r->size = size;
128
- r->file = file;
129
- r->line = line;
117
+ Rec r = (Rec)malloc(sizeof(struct _rec));
118
+
119
+ if (NULL != r) {
120
+ strcpy(((char *)ptr) + size, mem_pad);
121
+ r->ptr = ptr;
122
+ r->size = size;
123
+ r->file = file;
124
+ r->line = line;
130
125
  r->ruby = true;
131
- pthread_mutex_lock(&lock);
132
- r->next = recs;
133
- recs = r;
134
- pthread_mutex_unlock(&lock);
135
- } else {
136
- free(ptr);
137
- ptr = NULL;
138
- }
126
+ pthread_mutex_lock(&lock);
127
+ r->next = recs;
128
+ recs = r;
129
+ pthread_mutex_unlock(&lock);
130
+ } else {
131
+ free(ptr);
132
+ ptr = NULL;
133
+ }
139
134
  }
140
135
  return ptr;
141
136
  }
142
137
 
143
- void*
144
- oj_r_realloc(void *orig, size_t size, const char *file, int line) {
145
- void *ptr = ruby_xrealloc2(orig, 1, size + sizeof(mem_pad));
146
- Rec r;
138
+ void *oj_r_realloc(void *orig, size_t size, const char *file, int line) {
139
+ void *ptr = ruby_xrealloc2(orig, 1, size + sizeof(mem_pad));
140
+ Rec r;
147
141
 
148
142
  if (NULL != ptr) {
149
- strcpy(((char*)ptr) + size, mem_pad);
150
- pthread_mutex_lock(&lock);
151
- for (r = recs; NULL != r; r = r->next) {
152
- if (orig == r->ptr) {
153
- r->ptr = ptr;
154
- r->size = size;
155
- r->file = file;
156
- r->line = line;
143
+ strcpy(((char *)ptr) + size, mem_pad);
144
+ pthread_mutex_lock(&lock);
145
+ for (r = recs; NULL != r; r = r->next) {
146
+ if (orig == r->ptr) {
147
+ r->ptr = ptr;
148
+ r->size = size;
149
+ r->file = file;
150
+ r->line = line;
157
151
  r->ruby = true;
158
- break;
159
- }
160
- }
161
- pthread_mutex_unlock(&lock);
162
- if (NULL == r) {
163
- printf("Realloc at %s:%d (%p) not allocated.\n", file, line, orig);
164
- }
152
+ break;
153
+ }
154
+ }
155
+ pthread_mutex_unlock(&lock);
156
+ if (NULL == r) {
157
+ printf("Realloc at %s:%d (%p) not allocated.\n", file, line, orig);
158
+ }
165
159
  }
166
160
  return ptr;
167
161
  }
168
162
 
169
-
170
- void
171
- oj_freed(void *ptr, const char *file, int line, bool ruby) {
163
+ void oj_freed(void *ptr, const char *file, int line, bool ruby) {
172
164
  if (NULL != ptr) {
173
- Rec r = NULL;
174
- Rec prev = NULL;
175
-
176
- pthread_mutex_lock(&lock);
177
- for (r = recs; NULL != r; r = r->next) {
178
- if (ptr == r->ptr) {
179
- if (NULL == prev) {
180
- recs = r->next;
181
- } else {
182
- prev->next = r->next;
183
- }
184
- break;
185
- }
186
- prev = r;
187
- }
188
- pthread_mutex_unlock(&lock);
189
- if (NULL == r) {
190
- printf("Free at %s:%d (%p) not allocated or already freed.\n", file, line, ptr);
191
- } else {
192
- char *pad = (char*)r->ptr + r->size;
165
+ Rec r = NULL;
166
+ Rec prev = NULL;
167
+
168
+ pthread_mutex_lock(&lock);
169
+ for (r = recs; NULL != r; r = r->next) {
170
+ if (ptr == r->ptr) {
171
+ if (NULL == prev) {
172
+ recs = r->next;
173
+ } else {
174
+ prev->next = r->next;
175
+ }
176
+ break;
177
+ }
178
+ prev = r;
179
+ }
180
+ pthread_mutex_unlock(&lock);
181
+ if (NULL == r) {
182
+ printf("Free at %s:%d (%p) not allocated or already freed.\n", file, line, ptr);
183
+ } else {
184
+ char *pad = (char *)r->ptr + r->size;
193
185
 
194
186
  if (r->ruby != ruby) {
195
187
  if (r->ruby) {
196
- printf("Memory at %s:%d (%p) allocated with Ruby allocator and freed with stdlib free.\n", file, line, ptr);
188
+ printf("Memory at %s:%d (%p) allocated with Ruby allocator and freed with stdlib free.\n",
189
+ file,
190
+ line,
191
+ ptr);
197
192
  } else {
198
- printf("Memory at %s:%d (%p) allocated with stdlib allocator and freed with Ruby free.\n", file, line, ptr);
193
+ printf("Memory at %s:%d (%p) allocated with stdlib allocator and freed with Ruby free.\n",
194
+ file,
195
+ line,
196
+ ptr);
197
+ }
198
+ }
199
+ if (0 != strcmp(mem_pad, pad)) {
200
+ uint8_t *p;
201
+ uint8_t *end = (uint8_t *)pad + sizeof(mem_pad);
202
+
203
+ printf("Memory at %s:%d (%p) write outside allocated.\n", file, line, ptr);
204
+ for (p = (uint8_t *)pad; p < end; p++) {
205
+ if (0x20 < *p && *p < 0x7f) {
206
+ printf("%c ", *p);
207
+ } else {
208
+ printf("%02x ", *(uint8_t *)p);
209
+ }
199
210
  }
211
+ printf("\n");
200
212
  }
201
- if (0 != strcmp(mem_pad, pad)) {
202
- uint8_t *p;
203
- uint8_t *end = (uint8_t*)pad + sizeof(mem_pad);
204
-
205
- printf("Memory at %s:%d (%p) write outside allocated.\n", file, line, ptr);
206
- for (p = (uint8_t*)pad; p < end; p++) {
207
- if (0x20 < *p && *p < 0x7f) {
208
- printf("%c ", *p);
209
- } else {
210
- printf("%02x ", *(uint8_t*)p);
211
- }
212
- }
213
- printf("\n");
214
- }
215
- free(r);
216
- }
213
+ free(r);
214
+ }
217
215
  }
218
216
  }
219
217
 
220
- void
221
- oj_r_free(void *ptr, const char *file, int line) {
218
+ void oj_r_free(void *ptr, const char *file, int line) {
222
219
  oj_freed(ptr, file, line, true);
223
220
  xfree(ptr);
224
221
  }
225
222
 
226
-
227
- void
228
- oj_free(void *ptr, const char *file, int line) {
223
+ void oj_free(void *ptr, const char *file, int line) {
229
224
  oj_freed(ptr, file, line, false);
230
225
  free(ptr);
231
226
  }
232
227
 
233
- char*
234
- oj_mem_strdup(const char *str, const char *file, int line) {
235
- size_t size = strlen(str) + 1;
236
- char *ptr = (char*)malloc(size + sizeof(mem_pad));
228
+ char *oj_mem_strdup(const char *str, const char *file, int line) {
229
+ size_t size = strlen(str) + 1;
230
+ char *ptr = (char *)malloc(size + sizeof(mem_pad));
237
231
 
238
232
  if (NULL != ptr) {
239
- Rec r = (Rec)malloc(sizeof(struct _rec));
240
-
241
- if (NULL != r) {
242
- strcpy(ptr, str);
243
- strcpy(((char*)ptr) + size, mem_pad);
244
- r->ptr = (void*)ptr;
245
- r->size = size;
246
- r->file = file;
247
- r->line = line;
233
+ Rec r = (Rec)malloc(sizeof(struct _rec));
234
+
235
+ if (NULL != r) {
236
+ strcpy(ptr, str);
237
+ strcpy(((char *)ptr) + size, mem_pad);
238
+ r->ptr = (void *)ptr;
239
+ r->size = size;
240
+ r->file = file;
241
+ r->line = line;
248
242
  r->ruby = false;
249
- pthread_mutex_lock(&lock);
250
- r->next = recs;
251
- recs = r;
252
- pthread_mutex_unlock(&lock);
253
- } else {
254
- free(ptr);
255
- ptr = NULL;
256
- }
243
+ pthread_mutex_lock(&lock);
244
+ r->next = recs;
245
+ recs = r;
246
+ pthread_mutex_unlock(&lock);
247
+ } else {
248
+ free(ptr);
249
+ ptr = NULL;
250
+ }
257
251
  }
258
252
  return ptr;
259
253
  }
@@ -262,52 +256,53 @@ oj_mem_strdup(const char *str, const char *file, int line) {
262
256
 
263
257
  #ifdef MEM_DEBUG
264
258
 
265
- static Rep
266
- update_reps(Rep reps, Rec r) {
267
- Rep rp = reps;
259
+ static Rep update_reps(Rep reps, Rec r) {
260
+ Rep rp = reps;
268
261
 
269
262
  for (; NULL != rp; rp = rp->next) {
270
- if (rp->line == r->line && (rp->file == r->file || 0 == strcmp(rp->file, r->file))) {
271
- rp->size += r->size;
272
- rp->cnt++;
273
- break;
274
- }
263
+ if (rp->line == r->line && (rp->file == r->file || 0 == strcmp(rp->file, r->file))) {
264
+ rp->size += r->size;
265
+ rp->cnt++;
266
+ break;
267
+ }
275
268
  }
276
- if (NULL == rp &&
277
- NULL != (rp = (Rep)malloc(sizeof(struct _rep)))) {
278
- rp->size = r->size;
279
- rp->file = r->file;
280
- rp->line = r->line;
281
- rp->cnt = 1;
282
- rp->next = reps;
283
- reps = rp;
269
+ if (NULL == rp && NULL != (rp = (Rep)malloc(sizeof(struct _rep)))) {
270
+ rp->size = r->size;
271
+ rp->file = r->file;
272
+ rp->line = r->line;
273
+ rp->cnt = 1;
274
+ rp->next = reps;
275
+ reps = rp;
284
276
  }
285
277
  return reps;
286
278
  }
287
279
 
288
- static void
289
- print_stats() {
280
+ static void print_stats() {
290
281
  printf("\n--- Memory Usage Report --------------------------------------------------------\n");
291
282
  pthread_mutex_lock(&lock);
292
283
 
293
284
  if (NULL == recs) {
294
- printf("No memory leaks\n");
285
+ printf("No memory leaks\n");
295
286
  } else {
296
- Rep reps = NULL;
297
- Rep rp;
298
- Rec r;
299
- size_t leaked = 0;
300
-
301
- for (r = recs; NULL != r; r = r->next) {
302
- reps = update_reps(reps, r);
303
- }
304
- while (NULL != (rp = reps)) {
305
- reps = rp->next;
306
- printf("%16s:%3d %8lu bytes over %d occurances allocated and not freed.\n", rp->file, rp->line, rp->size, rp->cnt);
307
- leaked += rp->size;
308
- free(rp);
309
- }
310
- printf("%lu bytes leaked\n", leaked);
287
+ Rep reps = NULL;
288
+ Rep rp;
289
+ Rec r;
290
+ size_t leaked = 0;
291
+
292
+ for (r = recs; NULL != r; r = r->next) {
293
+ reps = update_reps(reps, r);
294
+ }
295
+ while (NULL != (rp = reps)) {
296
+ reps = rp->next;
297
+ printf("%16s:%3d %8lu bytes over %d occurances allocated and not freed.\n",
298
+ rp->file,
299
+ rp->line,
300
+ rp->size,
301
+ rp->cnt);
302
+ leaked += rp->size;
303
+ free(rp);
304
+ }
305
+ printf("%lu bytes leaked\n", leaked);
311
306
  }
312
307
  pthread_mutex_unlock(&lock);
313
308
  printf("--------------------------------------------------------------------------------\n");
@@ -315,8 +310,7 @@ print_stats() {
315
310
 
316
311
  #endif
317
312
 
318
- void
319
- oj_mem_report() {
313
+ void oj_mem_report(void) {
320
314
  #ifdef MEM_DEBUG
321
315
  rb_gc();
322
316
  print_stats();
data/ext/oj/mem.h CHANGED
@@ -16,21 +16,21 @@
16
16
 
17
17
  #define OJ_R_ALLOC(type) oj_r_alloc(sizeof(type), __FILE__, __LINE__)
18
18
  #define OJ_R_ALLOC_N(type, n) (type *)oj_r_alloc(sizeof(type) * (n), __FILE__, __LINE__)
19
- #define OJ_R_REALLOC_N(ptr, type, n) ((ptr) = (type*)oj_r_realloc(ptr, (sizeof(type) * (n)), __FILE__, __LINE__))
19
+ #define OJ_R_REALLOC_N(ptr, type, n) ((ptr) = (type *)oj_r_realloc(ptr, (sizeof(type) * (n)), __FILE__, __LINE__))
20
20
  #define OJ_R_FREE(ptr) oj_r_free(ptr, __FILE__, __LINE__)
21
21
 
22
22
  #define OJ_STRDUP(str) oj_mem_strdup(str, __FILE__, __LINE__)
23
23
 
24
- extern void* oj_malloc(size_t size, const char *file, int line);
25
- extern void* oj_realloc(void *ptr, size_t size, const char *file, int line);
26
- extern void* oj_calloc(size_t count, size_t size, const char *file, int line);
27
- extern void oj_free(void *ptr, const char *file, int line);
24
+ extern void *oj_malloc(size_t size, const char *file, int line);
25
+ extern void *oj_realloc(void *ptr, size_t size, const char *file, int line);
26
+ extern void *oj_calloc(size_t count, size_t size, const char *file, int line);
27
+ extern void oj_free(void *ptr, const char *file, int line);
28
28
 
29
- extern void* oj_r_alloc(size_t size, const char *file, int line);
30
- extern void* oj_r_realloc(void *ptr, size_t size, const char *file, int line);
31
- extern void oj_r_free(void *ptr, const char *file, int line);
29
+ extern void *oj_r_alloc(size_t size, const char *file, int line);
30
+ extern void *oj_r_realloc(void *ptr, size_t size, const char *file, int line);
31
+ extern void oj_r_free(void *ptr, const char *file, int line);
32
32
 
33
- extern char* oj_mem_strdup(const char *str, const char *file, int line);
33
+ extern char *oj_mem_strdup(const char *str, const char *file, int line);
34
34
 
35
35
  #else
36
36
 
@@ -48,6 +48,6 @@ extern char* oj_mem_strdup(const char *str, const char *file, int line);
48
48
 
49
49
  #endif
50
50
 
51
- extern void oj_mem_report();
51
+ extern void oj_mem_report();
52
52
 
53
53
  #endif /* OJ_MEM_H */