зеркало из https://github.com/github/ruby.git
Assign temporary ID to anonymous ID [Bug #18250]
Dumped iseq binary can not have unnamed symbols/IDs, and ID 0 is stored instead. As `struct rb_id_table` disallows ID 0, also for the distinction, re-assign a new temporary ID based on the local variable table index when loading from the binary, as well as the parser.
This commit is contained in:
Родитель
eb301d8aec
Коммит
c14f230b26
|
@ -11554,6 +11554,7 @@ ibf_load_outer_variables(const struct ibf_load * load, ibf_offset_t outer_variab
|
|||
for (size_t i = 0; i < table_size; i++) {
|
||||
ID key = ibf_load_id(load, (ID)ibf_load_small_value(load, &reading_pos));
|
||||
VALUE value = ibf_load_small_value(load, &reading_pos);
|
||||
if (!key) key = rb_make_temporary_id(i);
|
||||
rb_id_table_insert(tbl, key, value);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ int rb_is_local_name(VALUE name);
|
|||
PUREFUNC(int rb_is_const_sym(VALUE sym));
|
||||
PUREFUNC(int rb_is_attrset_sym(VALUE sym));
|
||||
ID rb_make_internal_id(void);
|
||||
ID rb_make_temporary_id(size_t n);
|
||||
void rb_gc_free_dsymbol(VALUE);
|
||||
|
||||
#if __has_builtin(__builtin_constant_p)
|
||||
|
|
5
parse.y
5
parse.y
|
@ -13090,10 +13090,7 @@ rb_init_parse(void)
|
|||
static ID
|
||||
internal_id(struct parser_params *p)
|
||||
{
|
||||
const ID max_id = RB_ID_SERIAL_MAX & ~0xffff;
|
||||
ID id = (ID)vtable_size(p->lvtbl->args) + (ID)vtable_size(p->lvtbl->vars);
|
||||
id = max_id - id;
|
||||
return ID_STATIC_SYM | ID_INTERNAL | (id << ID_SCOPE_SHIFT);
|
||||
return rb_make_temporary_id(vtable_size(p->lvtbl->args) + vtable_size(p->lvtbl->vars));
|
||||
}
|
||||
#endif /* !RIPPER */
|
||||
|
||||
|
|
11
symbol.c
11
symbol.c
|
@ -952,6 +952,17 @@ rb_make_internal_id(void)
|
|||
return next_id_base() | ID_INTERNAL | ID_STATIC_SYM;
|
||||
}
|
||||
|
||||
ID
|
||||
rb_make_temporary_id(size_t n)
|
||||
{
|
||||
const ID max_id = RB_ID_SERIAL_MAX & ~0xffff;
|
||||
const ID id = max_id - (ID)n;
|
||||
if (id <= ruby_global_symbols.last_id) {
|
||||
rb_raise(rb_eRuntimeError, "too big to make temporary ID: %" PRIdSIZE, n);
|
||||
}
|
||||
return (id << ID_SCOPE_SHIFT) | ID_STATIC_SYM | ID_INTERNAL;
|
||||
}
|
||||
|
||||
static int
|
||||
symbols_i(st_data_t key, st_data_t value, st_data_t arg)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче