Skip to content

Commit f73e43a

Browse files
committed
Even static symbols can have broken references
starting from 4.0
1 parent 67dde28 commit f73e43a

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

ext/rbs_extension/legacy_location.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,11 @@ static VALUE location_end_pos(VALUE self) {
171171
static rbs_constant_id_t rbs_constant_pool_insert_ruby_symbol(VALUE symbol) {
172172
VALUE name = rb_sym2str(symbol);
173173

174-
if (RB_STATIC_SYM_P(symbol)) {
175-
// Constants inserted here will never be freed, but that's acceptable because:
176-
// 1. Most symbols passed into here will be the ones already inserted into the constant pool by `parser.c`.
177-
// 2. Methods like `add_required_child` and `add_optional_child` will usually only get called with a few different symbols.
178-
return rbs_constant_pool_insert_constant(RBS_GLOBAL_CONSTANT_POOL, (const uint8_t *) RSTRING_PTR(name), RSTRING_LEN(name));
179-
} else {
180-
// To prevent memory compaction from breaking references to strings,
181-
// strings are copied and memory managed with an owned type.
182-
uint8_t *copied_name = malloc(RSTRING_LEN(name));
183-
memcpy((void *) copied_name, RSTRING_PTR(name), RSTRING_LEN(name));
184-
return rbs_constant_pool_insert_owned(RBS_GLOBAL_CONSTANT_POOL, copied_name, RSTRING_LEN(name));
185-
}
174+
// To prevent memory compaction from breaking references to strings,
175+
// strings are copied and memory managed with an owned type.
176+
uint8_t *copied_name = malloc(RSTRING_LEN(name));
177+
memcpy((void *) copied_name, RSTRING_PTR(name), RSTRING_LEN(name));
178+
return rbs_constant_pool_insert_owned(RBS_GLOBAL_CONSTANT_POOL, copied_name, RSTRING_LEN(name));
186179
}
187180

188181
static VALUE location_add_required_child(VALUE self, VALUE name, VALUE start, VALUE end) {

0 commit comments

Comments
 (0)