Prevent Dynamic -> Static symbols from moving

If a dynamic symbol has been converted to a static symbol, it gets added
to the global ID list and should no longer move.  C extensions can pass
symbols to rb_sym2id and those symbols should no longer be movable.
When the symbol is passed to rb_sym2id, the `id` member is set, so we
can use its existence to prevent movement.
This commit is contained in:
Aaron Patterson 2019-05-17 17:08:31 +03:00
parent 0723c107f4
commit ea3e7e2685
No known key found for this signature in database
GPG Key ID: 953170BCB4FFAFC6

5
gc.c
View File

@ -7256,6 +7256,10 @@ gc_is_moveable_obj(rb_objspace_t *objspace, VALUE obj)
case T_ZOMBIE: case T_ZOMBIE:
return FALSE; return FALSE;
break; break;
case T_SYMBOL:
if (DYNAMIC_SYM_P(obj) && (RSYMBOL(obj)->id & ~ID_SCOPE_MASK)) {
return FALSE;
}
case T_STRING: case T_STRING:
case T_OBJECT: case T_OBJECT:
case T_FLOAT: case T_FLOAT:
@ -7266,7 +7270,6 @@ gc_is_moveable_obj(rb_objspace_t *objspace, VALUE obj)
case T_MODULE: case T_MODULE:
case T_REGEXP: case T_REGEXP:
case T_DATA: case T_DATA:
case T_SYMBOL:
case T_MATCH: case T_MATCH:
case T_STRUCT: case T_STRUCT:
case T_HASH: case T_HASH: