From ea520ca9273699fc1c77a71bbeba4b6e06ccfc6c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 22 Apr 2019 17:14:36 -0700 Subject: Prevent rb_define_(class|module) classes from moving Before this commit, classes and modules would be registered with the VM's `defined_module_hash`. The key was the ID of the class, but that meant that it was possible for hash collisions to occur. The compactor doesn't allow classes in the `defined_module_hash` to move, but if there is a conflict, then it's possible a class would be removed from the hash and not get pined. This commit changes the key / value of the hash just to be the class itself, thus preventing movement. --- class.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'class.c') diff --git a/class.c b/class.c index d0ff92b6eb..0cee5caae2 100644 --- a/class.c +++ b/class.c @@ -659,6 +659,9 @@ rb_define_class(const char *name, VALUE super) if (rb_class_real(RCLASS_SUPER(klass)) != super) { rb_raise(rb_eTypeError, "superclass mismatch for class %s", name); } + + /* Class may have been defined in Ruby and not pin-rooted */ + rb_vm_add_root_module(id, klass); return klass; } if (!super) { -- cgit v1.2.3