prism 0.24.0 → 0.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/BSDmakefile +58 -0
- data/CHANGELOG.md +50 -1
- data/Makefile +5 -2
- data/README.md +45 -6
- data/config.yml +499 -4
- data/docs/build_system.md +31 -0
- data/docs/configuration.md +2 -0
- data/docs/cruby_compilation.md +1 -1
- data/docs/parser_translation.md +14 -9
- data/docs/releasing.md +2 -2
- data/docs/ripper_translation.md +50 -0
- data/docs/ruby_api.md +1 -0
- data/docs/serialization.md +26 -5
- data/ext/prism/api_node.c +911 -815
- data/ext/prism/api_pack.c +9 -0
- data/ext/prism/extconf.rb +27 -11
- data/ext/prism/extension.c +313 -66
- data/ext/prism/extension.h +5 -4
- data/include/prism/ast.h +213 -64
- data/include/prism/defines.h +106 -2
- data/include/prism/diagnostic.h +134 -71
- data/include/prism/encoding.h +22 -4
- data/include/prism/node.h +93 -0
- data/include/prism/options.h +82 -7
- data/include/prism/pack.h +11 -0
- data/include/prism/parser.h +198 -53
- data/include/prism/prettyprint.h +8 -0
- data/include/prism/static_literals.h +118 -0
- data/include/prism/util/pm_buffer.h +65 -2
- data/include/prism/util/pm_constant_pool.h +18 -1
- data/include/prism/util/pm_integer.h +119 -0
- data/include/prism/util/pm_list.h +1 -1
- data/include/prism/util/pm_newline_list.h +8 -0
- data/include/prism/util/pm_string.h +26 -2
- data/include/prism/version.h +2 -2
- data/include/prism.h +59 -1
- data/lib/prism/compiler.rb +8 -1
- data/lib/prism/debug.rb +46 -3
- data/lib/prism/desugar_compiler.rb +1 -1
- data/lib/prism/dispatcher.rb +29 -0
- data/lib/prism/dot_visitor.rb +87 -16
- data/lib/prism/dsl.rb +24 -12
- data/lib/prism/ffi.rb +67 -12
- data/lib/prism/lex_compat.rb +17 -15
- data/lib/prism/mutation_compiler.rb +11 -0
- data/lib/prism/node.rb +2096 -2499
- data/lib/prism/node_ext.rb +77 -29
- data/lib/prism/pack.rb +4 -0
- data/lib/prism/parse_result/comments.rb +34 -17
- data/lib/prism/parse_result/newlines.rb +3 -1
- data/lib/prism/parse_result.rb +78 -32
- data/lib/prism/pattern.rb +16 -4
- data/lib/prism/polyfill/string.rb +12 -0
- data/lib/prism/serialize.rb +439 -102
- data/lib/prism/translation/parser/compiler.rb +152 -50
- data/lib/prism/translation/parser/lexer.rb +103 -22
- data/lib/prism/translation/parser/rubocop.rb +41 -13
- data/lib/prism/translation/parser.rb +119 -7
- data/lib/prism/translation/parser33.rb +1 -1
- data/lib/prism/translation/parser34.rb +1 -1
- data/lib/prism/translation/ripper/sexp.rb +125 -0
- data/lib/prism/translation/ripper/shim.rb +5 -0
- data/lib/prism/translation/ripper.rb +3212 -462
- data/lib/prism/translation/ruby_parser.rb +35 -18
- data/lib/prism/translation.rb +3 -1
- data/lib/prism/visitor.rb +10 -0
- data/lib/prism.rb +8 -2
- data/prism.gemspec +33 -4
- data/rbi/prism/compiler.rbi +14 -0
- data/rbi/prism/desugar_compiler.rbi +5 -0
- data/rbi/prism/mutation_compiler.rbi +5 -0
- data/rbi/prism/node.rbi +8221 -0
- data/rbi/prism/node_ext.rbi +102 -0
- data/rbi/prism/parse_result.rbi +304 -0
- data/rbi/prism/translation/parser/compiler.rbi +13 -0
- data/rbi/prism/translation/ripper/ripper_compiler.rbi +5 -0
- data/rbi/prism/translation/ripper.rbi +25 -0
- data/rbi/prism/translation/ruby_parser.rbi +11 -0
- data/rbi/prism/visitor.rbi +470 -0
- data/rbi/prism.rbi +39 -7749
- data/sig/prism/compiler.rbs +9 -0
- data/sig/prism/dispatcher.rbs +16 -0
- data/sig/prism/dot_visitor.rbs +6 -0
- data/sig/prism/dsl.rbs +462 -0
- data/sig/prism/mutation_compiler.rbs +158 -0
- data/sig/prism/node.rbs +3529 -0
- data/sig/prism/node_ext.rbs +78 -0
- data/sig/prism/pack.rbs +43 -0
- data/sig/prism/parse_result.rbs +127 -0
- data/sig/prism/pattern.rbs +13 -0
- data/sig/prism/serialize.rbs +7 -0
- data/sig/prism/visitor.rbs +168 -0
- data/sig/prism.rbs +188 -4767
- data/src/diagnostic.c +575 -230
- data/src/encoding.c +211 -108
- data/src/node.c +7526 -447
- data/src/options.c +36 -12
- data/src/pack.c +33 -17
- data/src/prettyprint.c +1294 -1385
- data/src/prism.c +3628 -1099
- data/src/regexp.c +17 -2
- data/src/serialize.c +47 -28
- data/src/static_literals.c +552 -0
- data/src/token_type.c +1 -0
- data/src/util/pm_buffer.c +147 -20
- data/src/util/pm_char.c +4 -4
- data/src/util/pm_constant_pool.c +35 -11
- data/src/util/pm_integer.c +629 -0
- data/src/util/pm_list.c +1 -1
- data/src/util/pm_newline_list.c +14 -5
- data/src/util/pm_string.c +134 -5
- data/src/util/pm_string_list.c +2 -2
- metadata +35 -6
- data/docs/ripper.md +0 -36
- data/rbi/prism_static.rbi +0 -207
- data/sig/prism_static.rbs +0 -201
data/src/util/pm_buffer.c
CHANGED
@@ -16,7 +16,7 @@ pm_buffer_init_capacity(pm_buffer_t *buffer, size_t capacity) {
|
|
16
16
|
buffer->length = 0;
|
17
17
|
buffer->capacity = capacity;
|
18
18
|
|
19
|
-
buffer->value = (char *)
|
19
|
+
buffer->value = (char *) xmalloc(capacity);
|
20
20
|
return buffer->value != NULL;
|
21
21
|
}
|
22
22
|
|
@@ -32,7 +32,7 @@ pm_buffer_init(pm_buffer_t *buffer) {
|
|
32
32
|
* Return the value of the buffer.
|
33
33
|
*/
|
34
34
|
char *
|
35
|
-
pm_buffer_value(pm_buffer_t *buffer) {
|
35
|
+
pm_buffer_value(const pm_buffer_t *buffer) {
|
36
36
|
return buffer->value;
|
37
37
|
}
|
38
38
|
|
@@ -40,14 +40,14 @@ pm_buffer_value(pm_buffer_t *buffer) {
|
|
40
40
|
* Return the length of the buffer.
|
41
41
|
*/
|
42
42
|
size_t
|
43
|
-
pm_buffer_length(pm_buffer_t *buffer) {
|
43
|
+
pm_buffer_length(const pm_buffer_t *buffer) {
|
44
44
|
return buffer->length;
|
45
45
|
}
|
46
46
|
|
47
47
|
/**
|
48
48
|
* Append the given amount of space to the buffer.
|
49
49
|
*/
|
50
|
-
static inline
|
50
|
+
static inline bool
|
51
51
|
pm_buffer_append_length(pm_buffer_t *buffer, size_t length) {
|
52
52
|
size_t next_length = buffer->length + length;
|
53
53
|
|
@@ -60,10 +60,12 @@ pm_buffer_append_length(pm_buffer_t *buffer, size_t length) {
|
|
60
60
|
buffer->capacity *= 2;
|
61
61
|
}
|
62
62
|
|
63
|
-
buffer->value =
|
63
|
+
buffer->value = xrealloc(buffer->value, buffer->capacity);
|
64
|
+
if (buffer->value == NULL) return false;
|
64
65
|
}
|
65
66
|
|
66
67
|
buffer->length = next_length;
|
68
|
+
return true;
|
67
69
|
}
|
68
70
|
|
69
71
|
/**
|
@@ -72,8 +74,9 @@ pm_buffer_append_length(pm_buffer_t *buffer, size_t length) {
|
|
72
74
|
static inline void
|
73
75
|
pm_buffer_append(pm_buffer_t *buffer, const void *source, size_t length) {
|
74
76
|
size_t cursor = buffer->length;
|
75
|
-
pm_buffer_append_length(buffer, length)
|
76
|
-
|
77
|
+
if (pm_buffer_append_length(buffer, length)) {
|
78
|
+
memcpy(buffer->value + cursor, source, length);
|
79
|
+
}
|
77
80
|
}
|
78
81
|
|
79
82
|
/**
|
@@ -82,8 +85,9 @@ pm_buffer_append(pm_buffer_t *buffer, const void *source, size_t length) {
|
|
82
85
|
void
|
83
86
|
pm_buffer_append_zeroes(pm_buffer_t *buffer, size_t length) {
|
84
87
|
size_t cursor = buffer->length;
|
85
|
-
pm_buffer_append_length(buffer, length)
|
86
|
-
|
88
|
+
if (pm_buffer_append_length(buffer, length)) {
|
89
|
+
memset(buffer->value + cursor, 0, length);
|
90
|
+
}
|
87
91
|
}
|
88
92
|
|
89
93
|
/**
|
@@ -100,13 +104,12 @@ pm_buffer_append_format(pm_buffer_t *buffer, const char *format, ...) {
|
|
100
104
|
size_t length = (size_t) (result + 1);
|
101
105
|
|
102
106
|
size_t cursor = buffer->length;
|
103
|
-
pm_buffer_append_length(buffer, length)
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
buffer->length--;
|
107
|
+
if (pm_buffer_append_length(buffer, length)) {
|
108
|
+
va_start(arguments, format);
|
109
|
+
vsnprintf(buffer->value + cursor, length, format, arguments);
|
110
|
+
va_end(arguments);
|
111
|
+
buffer->length--;
|
112
|
+
}
|
110
113
|
}
|
111
114
|
|
112
115
|
/**
|
@@ -160,15 +163,95 @@ pm_buffer_append_varsint(pm_buffer_t *buffer, int32_t value) {
|
|
160
163
|
pm_buffer_append_varuint(buffer, unsigned_int);
|
161
164
|
}
|
162
165
|
|
166
|
+
/**
|
167
|
+
* Append a double to the buffer.
|
168
|
+
*/
|
169
|
+
void
|
170
|
+
pm_buffer_append_double(pm_buffer_t *buffer, double value) {
|
171
|
+
const void *source = &value;
|
172
|
+
pm_buffer_append(buffer, source, sizeof(double));
|
173
|
+
}
|
174
|
+
|
175
|
+
/**
|
176
|
+
* Append a slice of source code to the buffer.
|
177
|
+
*/
|
178
|
+
void
|
179
|
+
pm_buffer_append_source(pm_buffer_t *buffer, const uint8_t *source, size_t length, pm_buffer_escaping_t escaping) {
|
180
|
+
for (size_t index = 0; index < length; index++) {
|
181
|
+
const uint8_t byte = source[index];
|
182
|
+
|
183
|
+
if ((byte <= 0x06) || (byte >= 0x0E && byte <= 0x1F) || (byte >= 0x7F)) {
|
184
|
+
if (escaping == PM_BUFFER_ESCAPING_RUBY) {
|
185
|
+
pm_buffer_append_format(buffer, "\\x%02X", byte);
|
186
|
+
} else {
|
187
|
+
pm_buffer_append_format(buffer, "\\u%04X", byte);
|
188
|
+
}
|
189
|
+
} else {
|
190
|
+
switch (byte) {
|
191
|
+
case '\a':
|
192
|
+
if (escaping == PM_BUFFER_ESCAPING_RUBY) {
|
193
|
+
pm_buffer_append_string(buffer, "\\a", 2);
|
194
|
+
} else {
|
195
|
+
pm_buffer_append_format(buffer, "\\u%04X", byte);
|
196
|
+
}
|
197
|
+
break;
|
198
|
+
case '\b':
|
199
|
+
pm_buffer_append_string(buffer, "\\b", 2);
|
200
|
+
break;
|
201
|
+
case '\t':
|
202
|
+
pm_buffer_append_string(buffer, "\\t", 2);
|
203
|
+
break;
|
204
|
+
case '\n':
|
205
|
+
pm_buffer_append_string(buffer, "\\n", 2);
|
206
|
+
break;
|
207
|
+
case '\v':
|
208
|
+
if (escaping == PM_BUFFER_ESCAPING_RUBY) {
|
209
|
+
pm_buffer_append_string(buffer, "\\v", 2);
|
210
|
+
} else {
|
211
|
+
pm_buffer_append_format(buffer, "\\u%04X", byte);
|
212
|
+
}
|
213
|
+
break;
|
214
|
+
case '\f':
|
215
|
+
pm_buffer_append_string(buffer, "\\f", 2);
|
216
|
+
break;
|
217
|
+
case '\r':
|
218
|
+
pm_buffer_append_string(buffer, "\\r", 2);
|
219
|
+
break;
|
220
|
+
case '"':
|
221
|
+
pm_buffer_append_string(buffer, "\\\"", 2);
|
222
|
+
break;
|
223
|
+
case '#': {
|
224
|
+
if (escaping == PM_BUFFER_ESCAPING_RUBY && index + 1 < length) {
|
225
|
+
const uint8_t next_byte = source[index + 1];
|
226
|
+
if (next_byte == '{' || next_byte == '@' || next_byte == '$') {
|
227
|
+
pm_buffer_append_byte(buffer, '\\');
|
228
|
+
}
|
229
|
+
}
|
230
|
+
|
231
|
+
pm_buffer_append_byte(buffer, '#');
|
232
|
+
break;
|
233
|
+
}
|
234
|
+
case '\\':
|
235
|
+
pm_buffer_append_string(buffer, "\\\\", 2);
|
236
|
+
break;
|
237
|
+
default:
|
238
|
+
pm_buffer_append_byte(buffer, byte);
|
239
|
+
break;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
}
|
243
|
+
}
|
244
|
+
|
163
245
|
/**
|
164
246
|
* Prepend the given string to the buffer.
|
165
247
|
*/
|
166
248
|
void
|
167
249
|
pm_buffer_prepend_string(pm_buffer_t *buffer, const char *value, size_t length) {
|
168
250
|
size_t cursor = buffer->length;
|
169
|
-
pm_buffer_append_length(buffer, length)
|
170
|
-
|
171
|
-
|
251
|
+
if (pm_buffer_append_length(buffer, length)) {
|
252
|
+
memmove(buffer->value + length, buffer->value, cursor);
|
253
|
+
memcpy(buffer->value, value, length);
|
254
|
+
}
|
172
255
|
}
|
173
256
|
|
174
257
|
/**
|
@@ -181,10 +264,54 @@ pm_buffer_concat(pm_buffer_t *destination, const pm_buffer_t *source) {
|
|
181
264
|
}
|
182
265
|
}
|
183
266
|
|
267
|
+
/**
|
268
|
+
* Clear the buffer by reducing its size to 0. This does not free the allocated
|
269
|
+
* memory, but it does allow the buffer to be reused.
|
270
|
+
*/
|
271
|
+
void
|
272
|
+
pm_buffer_clear(pm_buffer_t *buffer) {
|
273
|
+
buffer->length = 0;
|
274
|
+
}
|
275
|
+
|
276
|
+
/**
|
277
|
+
* Strip the whitespace from the end of the buffer.
|
278
|
+
*/
|
279
|
+
void
|
280
|
+
pm_buffer_rstrip(pm_buffer_t *buffer) {
|
281
|
+
while (buffer->length > 0 && pm_char_is_whitespace((uint8_t) buffer->value[buffer->length - 1])) {
|
282
|
+
buffer->length--;
|
283
|
+
}
|
284
|
+
}
|
285
|
+
|
286
|
+
/**
|
287
|
+
* Checks if the buffer includes the given value.
|
288
|
+
*/
|
289
|
+
size_t
|
290
|
+
pm_buffer_index(const pm_buffer_t *buffer, char value) {
|
291
|
+
const char *first = memchr(buffer->value, value, buffer->length);
|
292
|
+
return (first == NULL) ? SIZE_MAX : (size_t) (first - buffer->value);
|
293
|
+
}
|
294
|
+
|
295
|
+
/**
|
296
|
+
* Insert the given string into the buffer at the given index.
|
297
|
+
*/
|
298
|
+
void
|
299
|
+
pm_buffer_insert(pm_buffer_t *buffer, size_t index, const char *value, size_t length) {
|
300
|
+
assert(index <= buffer->length);
|
301
|
+
|
302
|
+
if (index == buffer->length) {
|
303
|
+
pm_buffer_append_string(buffer, value, length);
|
304
|
+
} else {
|
305
|
+
pm_buffer_append_zeroes(buffer, length);
|
306
|
+
memmove(buffer->value + index + length, buffer->value + index, buffer->length - length - index);
|
307
|
+
memcpy(buffer->value + index, value, length);
|
308
|
+
}
|
309
|
+
}
|
310
|
+
|
184
311
|
/**
|
185
312
|
* Free the memory associated with the buffer.
|
186
313
|
*/
|
187
314
|
void
|
188
315
|
pm_buffer_free(pm_buffer_t *buffer) {
|
189
|
-
|
316
|
+
xfree(buffer->value);
|
190
317
|
}
|
data/src/util/pm_char.c
CHANGED
@@ -19,10 +19,10 @@ static const uint8_t pm_byte_table[256] = {
|
|
19
19
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
|
20
20
|
3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 2x
|
21
21
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3x
|
22
|
-
0,
|
23
|
-
|
24
|
-
0,
|
25
|
-
|
22
|
+
0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // 4x
|
23
|
+
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, // 5x
|
24
|
+
0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // 6x
|
25
|
+
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, // 7x
|
26
26
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
|
27
27
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
|
28
28
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Ax
|
data/src/util/pm_constant_pool.c
CHANGED
@@ -10,6 +10,18 @@ pm_constant_id_list_init(pm_constant_id_list_t *list) {
|
|
10
10
|
list->capacity = 0;
|
11
11
|
}
|
12
12
|
|
13
|
+
/**
|
14
|
+
* Initialize a list of constant ids with a given capacity.
|
15
|
+
*/
|
16
|
+
void
|
17
|
+
pm_constant_id_list_init_capacity(pm_constant_id_list_t *list, size_t capacity) {
|
18
|
+
list->ids = xcalloc(capacity, sizeof(pm_constant_id_t));
|
19
|
+
if (list->ids == NULL) abort();
|
20
|
+
|
21
|
+
list->size = 0;
|
22
|
+
list->capacity = capacity;
|
23
|
+
}
|
24
|
+
|
13
25
|
/**
|
14
26
|
* Append a constant id to a list of constant ids. Returns false if any
|
15
27
|
* potential reallocations fail.
|
@@ -18,7 +30,7 @@ bool
|
|
18
30
|
pm_constant_id_list_append(pm_constant_id_list_t *list, pm_constant_id_t id) {
|
19
31
|
if (list->size >= list->capacity) {
|
20
32
|
list->capacity = list->capacity == 0 ? 8 : list->capacity * 2;
|
21
|
-
list->ids = (pm_constant_id_t *)
|
33
|
+
list->ids = (pm_constant_id_t *) xrealloc(list->ids, sizeof(pm_constant_id_t) * list->capacity);
|
22
34
|
if (list->ids == NULL) return false;
|
23
35
|
}
|
24
36
|
|
@@ -26,6 +38,18 @@ pm_constant_id_list_append(pm_constant_id_list_t *list, pm_constant_id_t id) {
|
|
26
38
|
return true;
|
27
39
|
}
|
28
40
|
|
41
|
+
/**
|
42
|
+
* Insert a constant id into a list of constant ids at the specified index.
|
43
|
+
*/
|
44
|
+
void
|
45
|
+
pm_constant_id_list_insert(pm_constant_id_list_t *list, size_t index, pm_constant_id_t id) {
|
46
|
+
assert(index < list->capacity);
|
47
|
+
assert(list->ids[index] == PM_CONSTANT_ID_UNSET);
|
48
|
+
|
49
|
+
list->ids[index] = id;
|
50
|
+
list->size++;
|
51
|
+
}
|
52
|
+
|
29
53
|
/**
|
30
54
|
* Checks if the current constant id list includes the given constant id.
|
31
55
|
*/
|
@@ -51,7 +75,7 @@ pm_constant_id_list_memsize(pm_constant_id_list_t *list) {
|
|
51
75
|
void
|
52
76
|
pm_constant_id_list_free(pm_constant_id_list_t *list) {
|
53
77
|
if (list->ids != NULL) {
|
54
|
-
|
78
|
+
xfree(list->ids);
|
55
79
|
}
|
56
80
|
}
|
57
81
|
|
@@ -111,7 +135,7 @@ pm_constant_pool_resize(pm_constant_pool_t *pool) {
|
|
111
135
|
const uint32_t mask = next_capacity - 1;
|
112
136
|
const size_t element_size = sizeof(pm_constant_pool_bucket_t) + sizeof(pm_constant_t);
|
113
137
|
|
114
|
-
void *next =
|
138
|
+
void *next = xcalloc(next_capacity, element_size);
|
115
139
|
if (next == NULL) return false;
|
116
140
|
|
117
141
|
pm_constant_pool_bucket_t *next_buckets = next;
|
@@ -145,7 +169,7 @@ pm_constant_pool_resize(pm_constant_pool_t *pool) {
|
|
145
169
|
|
146
170
|
// pool->constants and pool->buckets are allocated out of the same chunk
|
147
171
|
// of memory, with the buckets coming first.
|
148
|
-
|
172
|
+
xfree(pool->buckets);
|
149
173
|
pool->constants = next_constants;
|
150
174
|
pool->buckets = next_buckets;
|
151
175
|
pool->capacity = next_capacity;
|
@@ -162,7 +186,7 @@ pm_constant_pool_init(pm_constant_pool_t *pool, uint32_t capacity) {
|
|
162
186
|
|
163
187
|
capacity = next_power_of_two(capacity);
|
164
188
|
const size_t element_size = sizeof(pm_constant_pool_bucket_t) + sizeof(pm_constant_t);
|
165
|
-
void *memory =
|
189
|
+
void *memory = xcalloc(capacity, element_size);
|
166
190
|
if (memory == NULL) return false;
|
167
191
|
|
168
192
|
pool->buckets = memory;
|
@@ -237,12 +261,12 @@ pm_constant_pool_insert(pm_constant_pool_t *pool, const uint8_t *start, size_t l
|
|
237
261
|
// an existing constant, then either way we don't want the given
|
238
262
|
// memory. Either it's duplicated with the existing constant or
|
239
263
|
// it's not necessary because we have a shared version.
|
240
|
-
|
264
|
+
xfree((void *) start);
|
241
265
|
} else if (bucket->type == PM_CONSTANT_POOL_BUCKET_OWNED) {
|
242
266
|
// If we're attempting to insert a shared constant and the
|
243
267
|
// existing constant is owned, then we can free the owned
|
244
268
|
// constant and replace it with the shared constant.
|
245
|
-
|
269
|
+
xfree((void *) constant->start);
|
246
270
|
constant->start = start;
|
247
271
|
bucket->type = (unsigned int) (PM_CONSTANT_POOL_BUCKET_DEFAULT & 0x3);
|
248
272
|
}
|
@@ -253,7 +277,7 @@ pm_constant_pool_insert(pm_constant_pool_t *pool, const uint8_t *start, size_t l
|
|
253
277
|
index = (index + 1) & mask;
|
254
278
|
}
|
255
279
|
|
256
|
-
// IDs are allocated starting at 1, since the value 0 denotes a non-
|
280
|
+
// IDs are allocated starting at 1, since the value 0 denotes a non-existent
|
257
281
|
// constant.
|
258
282
|
uint32_t id = ++pool->size;
|
259
283
|
assert(pool->size < ((uint32_t) (1 << 30)));
|
@@ -287,7 +311,7 @@ pm_constant_pool_insert_shared(pm_constant_pool_t *pool, const uint8_t *start, s
|
|
287
311
|
* potential calls to resize fail.
|
288
312
|
*/
|
289
313
|
pm_constant_id_t
|
290
|
-
pm_constant_pool_insert_owned(pm_constant_pool_t *pool,
|
314
|
+
pm_constant_pool_insert_owned(pm_constant_pool_t *pool, uint8_t *start, size_t length) {
|
291
315
|
return pm_constant_pool_insert(pool, start, length, PM_CONSTANT_POOL_BUCKET_OWNED);
|
292
316
|
}
|
293
317
|
|
@@ -314,9 +338,9 @@ pm_constant_pool_free(pm_constant_pool_t *pool) {
|
|
314
338
|
// If an id is set on this constant, then we know we have content here.
|
315
339
|
if (bucket->id != PM_CONSTANT_ID_UNSET && bucket->type == PM_CONSTANT_POOL_BUCKET_OWNED) {
|
316
340
|
pm_constant_t *constant = &pool->constants[bucket->id - 1];
|
317
|
-
|
341
|
+
xfree((void *) constant->start);
|
318
342
|
}
|
319
343
|
}
|
320
344
|
|
321
|
-
|
345
|
+
xfree(pool->buckets);
|
322
346
|
}
|